コード例 #1
0
 def __init__(self):
     #self.utilityInstance = Utility.Instance()
     self.Global = Global()
     self.myClass = self.__class__.__name__
     self.myModuleLogger = logging.getLogger('uConnect.' + str(__name__) +
                                             '.' + self.myClass)
コード例 #2
0
    def processJob(**keyWordArgs):
        '''
            1. Validating the argument using schema
            2. Update job "Executing"
            3. Execute Job
            4. Update Job Status "Completed"
        '''
        from com.port8.core.globals import Global
        from com.port8.core.utils import Utility
        from com.port8.core.infrautils import InfraUtility
        from com.port8.core.validation import Validation
        from com.port8.core.schedutility import SchedUtility

        import os, json, sys, time, inspect

        try:
            Global = Global()
            InfraUtil = InfraUtility()
            Utility = Utility()
            Validation = Validation()
            ShcedUtil = SchedUtility()

            Infra = ShcedUtil.InfraUtil.setInfra('Scheduler')

            logger = Infra.getInfraLogger('Scheduler')
            myProcessJobSchema = Infra.jsonSchema['Main']['process_job_schema']
            logger.debug(
                'Job Schema will be used for validation >> {schema}'.format(
                    schema=myProcessJobSchema))

            myKeyWordArgs = Utility.getACopy(keyWordArgs)
            myCurrentTime = time.time()
            myResponse = Utility.getResponseTemplate()
            logger.debug(
                'argument received >> {args}'.format(args=myKeyWordArgs))

            #validating argumnet (using json schema validator)
            Validation.validateArguments(myKeyWordArgs, myProcessJobSchema)
            logger.debug('arguments validated >>'.format(args=myKeyWordArgs))

            # building data for this run & persisiting data
            myJobCriteria = ' JobId = ' + repr(myKeyWordArgs['jobid'])

            myStartEventResult = ShcedUtil.processJobStartEvent(
                myKeyWordArgs['jobid'])

            #executing job
            logger.info('Executing .... : {arg}'.format(arg=myKeyWordArgs))

            myResult = InfraUtil.callFunc(**myKeyWordArgs['func_call'])
            myResult['Data'].update(
                {'ElapsedSecs': round(time.time() - myCurrentTime, 5)})

            logger.info('jobid {jobid} execution results: {result}'.format(
                jobid=myKeyWordArgs['jobid'], result=myResult))

            myFinishEventResult = ShcedUtil.processJobFinishEvent(
                myKeyWordArgs['jobid'], myResult)

            if myResult['Status'] == Global.Success:
                # calling job completed event
                if myFinishEventResult['Status'] == Global.Success:
                    Utility.buildResponse(myResponse, Global.Success,
                                          Global.Success,
                                          {'result': myFinishEventResult})
                else:
                    raise processJobError(
                        'Error returned from calling job finish event {error}'.
                        format(error=myFinishEventResult['Message']))
            else:
                raise processJobError(
                    'Error returned from job processing {error}'.format(
                        error=myResult['Message']))

            #building response

            return myResponse

        except Exception as err:
            # log the error and let the error to be raised to scheduler to ensure we have error being reported back to scheduler

            myErrorMsg, myTraceback = Utility.getErrorTraceback()
            logger.error(Global.DefPrefix4Error * Global.DefPrefixCount,
                         myErrorMsg)
            logger.error(Global.DefPrefix4Error * Global.DefPrefixCount,
                         myTraceback)
            Utility.buildResponse(myResponse, Global.UnSuccess, myErrorMsg)

            if 'myCurrentTime' in locals():
                myElapsedSecs = round(time.time() - myCurrentTime, 5)
            else:
                myElapsedSecs = round(time.time() - myCurrentTime, 5)

            myResponse['Data'].update({'ElapsedSecs': myElapsedSecs})
            myDbResult = ShcedUtil.processJobFinishEvent(
                myKeyWordArgs['jobid'], myResponse)

            raise err
コード例 #3
0
ファイル: factory.py プロジェクト: myuconnect/Port8
 def __init__(self):
     #self.util = Utility.Instance()
     self.globals = Global()
     self.util = Utility()
     self.infra = RestInfra()
     self.logger = self.infra.logger
コード例 #4
0
ファイル: utility.py プロジェクト: myuconnect/Port8
 def __init__(self):
     self.globals = Global()
     self.myClass = self.__class__.__name__
     self.myPythonFile = os.path.basename(__file__)
コード例 #5
0
ファイル: environment.py プロジェクト: myuconnect/Port8
    def __init__(self):

        self.Global = Global()
        self.lPad = 50
        self.rPad = 1
        self.__initFile = self.Global.InitFile
        self.__initKeys = self.Global.InitKeys
        self.__bootStrapKey = self.Global.BootStrapKey
        self.__bootStrapFileKey = self.Global.BootStrapFileKey
        self.__logLocKey = self.Global.LogLocKey
        self.__envDetails = {}

        if 'PYTHONPATH' not in os.environ:
            print('missing PYTHONPATH environment variable, terminating !!!')
            sys.exit(-1)
        else:
            self.__envDetails.update({'PYTHONPATH': os.environ['PYTHONPATH']})
        #fi

        print('Current OS : [{os}]'.format(os=self.getOsInfo()))
        print("Initializing ...")

        # searching init file
        # 1. search in current directory, 2. search in pythonpath, 3. search in APP_CONFIG dir
        print('searching init file')
        if not self.isFileExists(self.__initFile):
            if not (self.isFileExists(
                    os.path.join(self.__envDetails['PYTHONPATH'],
                                 self.__initFile))):
                if not (self.isFileExists(
                        os.path.join(self.__envDetails['APP_CONFIG'],
                                     self.__initFile))):
                    print(
                        "Bootstrap error; missing init.json, terminating !!!")
                    sys.exit(-1)
                else:
                    self.__initFile = os.path.join(
                        self.__envDetails['APP_CONFIG'], self.__initFile)
                    print('init file [{file}] found'.format(
                        file=self.__initFile))
            else:
                self.__initFile = os.path.join(self.__envDetails['PYTHONPATH'],
                                               self.__initFile)
                print('init file [{file}] found'.format(file=self.__initFile))

        # Loading init file
        #print('bootstraping init file')
        self.__initData = json.load(open(self.__initFile))

        # ensure all required key found in int file
        if not all(key in self.__initData.keys() for key in self.__initKeys):
            print("Missing required keys in init file, terminating !!!")
            sys.exit(-1)
        #fi

        # building environment key details (APP_NAME, {APP}_HOME, {APP}_CONFIG)
        self.__envDetails.update({'APP_NAME': self.__initData['AppName']})
        self.__envDetails.update({
            ''.join([self.__initData['AppName'], '_HOME']):
            self.__initData['AppHome']
        })
        if 'CONFIG_LOC' in self.__initData:
            self.__envDetails.update({
                ''.join([self.__initData['AppName'], '_CONFIG']):
                ''.join([self.__initData['AppHome'], '/config'])
            })

        self.__envDetails.update({
            ''.join([self.__initData['AppName'], '_CONFIG']):
            ''.join([self.__initData['AppHome'], '/config'])
        })
        self.__envDetails.update(
            {'ENVIRONMENT': self.__initData['Environment'].upper()})

        self.__envDetails.update({
            'APP_CONFIG_KEY':
            ''.join([self.__initData['AppName'], '_CONFIG'])
        })
        self.__envDetails.update(
            {'APP_HOME_KEY': ''.join([self.__initData['AppName'], '_HOME'])})
        self.__envDetails.update(
            {self.__logLocKey: self.__initData[self.__logLocKey]})

        # Set all environment variable if not set
        if not all(env in os.environ for env in self.__envDetails.keys()):
            print("app environment key is not set, building ...")
            #print("Setting environment...........................".ljust(self.lPad),end='')
            # app home
            self.setInitEnv()
        #fi

        #validating LOG file location
        self.validateLogDir()

        # Validating bootstrap
        try:
            # validating if bootstrap key/file exists
            if self.__bootStrapKey in self.__initData and \
                self.isFileExists( \
                    os.path.join( \
                     self.getEnv(''.join([self.__initData['AppName'],'_CONFIG'])), self.__initData[self.__bootStrapKey])):

                # will update the __envDetials and update the environment variable as well
                bootStrapFile = os.path.join(
                    self.getEnv(''.join(
                        [self.__initData['AppName'], '_CONFIG'])),
                    self.__initData[self.__bootStrapKey])

                self.__envDetails.update(
                    {self.__bootStrapFileKey: bootStrapFile})
                os.environ[self.__bootStrapFileKey] = self.__envDetails[
                    self.__bootStrapFileKey]

                print("[OK]")
            else:
                print("[unable to locate bootstrap file]")
                sys.exit(-1)

        except Exception as err:
            print("bootstrap error, terminating !!!")
            raise
            sys.exit(-1)
コード例 #6
0
ファイル: loggingP8.py プロジェクト: myuconnect/Port8
 def __init__(self):
     self.env = Environment()
     self.Global = Global()
     self.Utility = Utility()