Exemple #1
0
  def init(self, env, serverStartTime, testingMode = False, objectStoreTestingPopulationHookFn = None):
    try:
      self.minutesBeforeMostRecentCompletionStatusBecomesUnknown = 49 * 60
      self.curDateTimeOverrideForTesting = None
      self.serverStartTime = serverStartTime
      if self.jobExecutor is not None:
        #for testing we init multiple times. We need to stop the thread running in this case
        self.jobExecutor.stopThreadRunning()
        if self.jobExecutor.isAlive():
          self.jobExecutor.join()
        self.jobExecutor = None
      super(appObjClass, self).init(env, serverStartTime, testingMode, serverinfoapiprefix='')
      resetJobsData(self)

      self.userforjobs = readFromEnviroment(env, 'APIAPP_USERFORJOBS', None, None)
      self.groupforjobs = readFromEnviroment(env, 'APIAPP_GROUPFORJOBS', None, None)
      skipUserCheck = readFromEnviroment(env, 'APIAPP_SKIPUSERCHECK', False, [False, True])
      self.jobExecutor = JobExecutorClass(self, skipUserCheck)

      #When we are testing we will launch the loop iterations manually
      if not testingMode:
        self.jobExecutor.start()

      objectStoreConfigJSON = readFromEnviroment(env, 'APIAPP_OBJECTSTORECONFIG', '{}', None)
      objectStoreConfigDict = None
      try:
        if objectStoreConfigJSON != '{}':
          objectStoreConfigDict = json.loads(objectStoreConfigJSON)
      except Exception as err:
        print(err) # for the repr
        print(str(err)) # for just the message
        print(err.args) # the arguments that the exception has been called with.
        raise(InvalidObjectStoreConfigInvalidJSONException)

      fns = {
        'getCurDateTime': self.getCurDateTime
      }
      self.objectStore = createObjectStoreInstance(objectStoreConfigDict, fns)

      if testingMode:
        if objectStoreTestingPopulationHookFn is not None:
          # Give our tests the chance to inject some base data
          objectStoreTestingPopulationHookFn(objectStore = self.objectStore)

      appObj.appData['jobsData'].loadFromObjectStore()
    except Exception as a:
      self.stopThread()
      raise a
Exemple #2
0
    def init(self, env, serverStartTime, testingMode=False):
        self.serverStartTime = serverStartTime
        if self.jobExecutor is not None:
            #for testing we init multiple times. We need to stop the thread running in this case
            self.jobExecutor.stopThreadRunning()
            if self.jobExecutor.isAlive():
                self.jobExecutor.join()
            self.jobExecutor = None
        super(appObjClass, self).init(env)
        resetJobsData(self)
        self.userforjobs = self.globalParamObject.readFromEnviroment(
            env, 'APIAPP_USERFORJOBS', None, MissingUserForJobsException, None)
        self.groupforjobs = self.globalParamObject.readFromEnviroment(
            env, 'APIAPP_GROUPFORJOBS', None, MissingGroupForJobsException,
            None)
        skipUserCheck = self.globalParamObject.readFromEnviroment(
            env, 'APIAPP_SKIPUSERCHECK', False, MissingGroupForJobsException,
            None)
        self.jobExecutor = JobExecutorClass(self, skipUserCheck)

        #When we are testing we will launch the loop iterations manually
        if not testingMode:
            self.jobExecutor.start()
Exemple #3
0
    def init(self, env, serverStartTime, testingMode=False):
        self.minutesBeforeMostRecentCompletionStatusBecomesUnknown = 49 * 60
        self.curDateTimeOverrideForTesting = None
        self.serverStartTime = serverStartTime
        if self.jobExecutor is not None:
            #for testing we init multiple times. We need to stop the thread running in this case
            self.jobExecutor.stopThreadRunning()
            if self.jobExecutor.isAlive():
                self.jobExecutor.join()
            self.jobExecutor = None
        super(appObjClass, self).init(env)
        resetJobsData(self)

        self.userforjobs = readFromEnviroment(env, 'APIAPP_USERFORJOBS', None,
                                              None)
        self.groupforjobs = readFromEnviroment(env, 'APIAPP_GROUPFORJOBS',
                                               None, None)
        skipUserCheck = readFromEnviroment(env, 'APIAPP_SKIPUSERCHECK', False,
                                           [False, True])
        self.jobExecutor = JobExecutorClass(self, skipUserCheck)

        #When we are testing we will launch the loop iterations manually
        if not testingMode:
            self.jobExecutor.start()
Exemple #4
0
class appObjClass(appObj):
    jobExecutor = None
    userforjobs = None
    groupforjobs = None
    serverStartTime = None

    def init(self, env, serverStartTime, testingMode=False):
        self.serverStartTime = serverStartTime
        if self.jobExecutor is not None:
            #for testing we init multiple times. We need to stop the thread running in this case
            self.jobExecutor.stopThreadRunning()
            if self.jobExecutor.isAlive():
                self.jobExecutor.join()
            self.jobExecutor = None
        super(appObjClass, self).init(env)
        resetJobsData(self)
        self.userforjobs = self.globalParamObject.readFromEnviroment(
            env, 'APIAPP_USERFORJOBS', None, MissingUserForJobsException, None)
        self.groupforjobs = self.globalParamObject.readFromEnviroment(
            env, 'APIAPP_GROUPFORJOBS', None, MissingGroupForJobsException,
            None)
        skipUserCheck = self.globalParamObject.readFromEnviroment(
            env, 'APIAPP_SKIPUSERCHECK', False, MissingGroupForJobsException,
            None)
        self.jobExecutor = JobExecutorClass(self, skipUserCheck)

        #When we are testing we will launch the loop iterations manually
        if not testingMode:
            self.jobExecutor.start()

    def initOnce(self):
        super(appObjClass, self).initOnce()
        registerMainApi(self)
        registerJobsApi(self)
        registerJobExecutionsApi(self)

    def getServerInfoModel(self):
        serverInfoServerModel = appObj.flastRestPlusAPIObject.model(
            'ServerInfoServer', {
                'DefaultUserTimezone':
                fields.String(
                    default='Europe/London',
                    description=
                    'Timezone used by client to display times. (All API'
                    's use UTC so client must convert)'),
                'ServerDatetime':
                fields.DateTime(dt_format=u'iso8601',
                                description='Current server date time'),
                'ServerStartupTime':
                fields.DateTime(dt_format=u'iso8601',
                                description='Time the dockJob server started'),
                'TotalJobExecutions':
                fields.Integer(
                    default='0',
                    description='Number to jobs executed since server started')
            })

        return appObj.flastRestPlusAPIObject.model(
            'ServerInfo', {
                'Server': fields.Nested(serverInfoServerModel),
                'Jobs': fields.Nested(getJobServerInfoModel(appObj))
            })

        #curDateTime must be in UTC
    def getServerInfoJSON(self, curDateTime):
        if (curDateTime.tzinfo != pytz.utc):
            raise self.NotUTCException
        self.serverObj['ServerDatetime'] = curDateTime.isoformat()
        self.serverObj['ServerStartupTime'] = self.serverStartTime.isoformat()
        self.serverObj['TotalJobExecutions'] = self.jobExecutor.totalExecutions
        return {
            'Server': self.serverObj,
            'Jobs': self.appData['jobsData'].getJobServerInfo()
        }
        #return json.dumps({'Server': self.serverObj, 'Jobs': jobsObj})

    def stopThread(self):
        if self.jobExecutor is None:
            return
        if not self.jobExecutor.isAlive():
            return
        self.jobExecutor.stopThreadRunning()
        self.jobExecutor.join()

    #override exit gracefully to stop worker thread
    def exit_gracefully(self, signum, frame):
        self.stopThread()
        super(appObjClass, self).exit_gracefully(signum, frame)
Exemple #5
0
class appObjClass(parAppObj):
  jobExecutor = None
  userforjobs = None
  groupforjobs = None
  serverStartTime = None
  curDateTimeOverrideForTesting = None
  minutesBeforeMostRecentCompletionStatusBecomesUnknown = None
  objectStore = None

  def init(self, env, serverStartTime, testingMode = False, objectStoreTestingPopulationHookFn = None):
    try:
      self.minutesBeforeMostRecentCompletionStatusBecomesUnknown = 49 * 60
      self.curDateTimeOverrideForTesting = None
      self.serverStartTime = serverStartTime
      if self.jobExecutor is not None:
        #for testing we init multiple times. We need to stop the thread running in this case
        self.jobExecutor.stopThreadRunning()
        if self.jobExecutor.isAlive():
          self.jobExecutor.join()
        self.jobExecutor = None
      super(appObjClass, self).init(env, serverStartTime, testingMode, serverinfoapiprefix='')
      resetJobsData(self)

      self.userforjobs = readFromEnviroment(env, 'APIAPP_USERFORJOBS', None, None)
      self.groupforjobs = readFromEnviroment(env, 'APIAPP_GROUPFORJOBS', None, None)
      skipUserCheck = readFromEnviroment(env, 'APIAPP_SKIPUSERCHECK', False, [False, True])
      self.jobExecutor = JobExecutorClass(self, skipUserCheck)

      #When we are testing we will launch the loop iterations manually
      if not testingMode:
        self.jobExecutor.start()

      objectStoreConfigJSON = readFromEnviroment(env, 'APIAPP_OBJECTSTORECONFIG', '{}', None)
      objectStoreConfigDict = None
      try:
        if objectStoreConfigJSON != '{}':
          objectStoreConfigDict = json.loads(objectStoreConfigJSON)
      except Exception as err:
        print(err) # for the repr
        print(str(err)) # for just the message
        print(err.args) # the arguments that the exception has been called with.
        raise(InvalidObjectStoreConfigInvalidJSONException)

      fns = {
        'getCurDateTime': self.getCurDateTime
      }
      self.objectStore = createObjectStoreInstance(objectStoreConfigDict, fns)

      if testingMode:
        if objectStoreTestingPopulationHookFn is not None:
          # Give our tests the chance to inject some base data
          objectStoreTestingPopulationHookFn(objectStore = self.objectStore)

      appObj.appData['jobsData'].loadFromObjectStore()
    except Exception as a:
      self.stopThread()
      raise a


  def initOnce(self):
    super(appObjClass, self).initOnce()
    registerMainApi(self)
    registerJobsApi(self)
    registerJobExecutionsApi(self)

  def setTestingDateTime(self, val):
    self.curDateTimeOverrideForTesting = val
  def getCurDateTime(self):
    if self.curDateTimeOverrideForTesting is None:
      return datetime.datetime.now(pytz.timezone("UTC"))
    return self.curDateTimeOverrideForTesting

  def getServerInfoModel(self):
    serverInfoServerModel = appObj.flastRestPlusAPIObject.model('ServerInfoServer', {
      'DefaultUserTimezone': fields.String(default='Europe/London', description='Timezone used by client to display times. (All API''s use UTC so client must convert)'),
      'ServerDatetime': fields.DateTime(dt_format=u'iso8601', description='Current server date time'),
      'ServerStartupTime': fields.DateTime(dt_format=u'iso8601', description='Time the dockJob server started'),
      'TotalJobExecutions': fields.Integer(default='0',description='Number to jobs executed since server started'),
      'MinutesBeforeMostRecentCompletionStatusBecomesUnknown': fields.Integer(default='0',description='Default number of minutes a job has not been run before a job is considered to have Unknown status.')
    })

    return appObj.flastRestPlusAPIObject.model('ServerInfo', {
      'Server': fields.Nested(serverInfoServerModel),
      'Jobs': fields.Nested(getJobServerInfoModel(appObj))
    })

  #curDateTime must be in UTC
  def getServerInfoJSON(self, curDateTime):
    if (curDateTime.tzinfo != pytz.utc):
      raise self.NotUTCException
    self.serverObj['ServerDatetime'] = curDateTime.isoformat()
    self.serverObj['ServerStartupTime'] = self.serverStartTime.isoformat()
    self.serverObj['TotalJobExecutions'] = self.jobExecutor.totalExecutions
    self.serverObj['MinutesBeforeMostRecentCompletionStatusBecomesUnknown'] = self.minutesBeforeMostRecentCompletionStatusBecomesUnknown
    return {'Server': self.serverObj, 'Jobs': self.appData['jobsData'].getJobServerInfo()}
    #return json.dumps({'Server': self.serverObj, 'Jobs': jobsObj})

  def stopThread(self):
    if self.jobExecutor is None:
      return
    if not self.jobExecutor.isAlive():
      return
    self.jobExecutor.stopThreadRunning()
    self.jobExecutor.join()

  #override exit gracefully to stop worker thread
  def exit_gracefully(self, signum, frame):
    self.stopThread()
    super(appObjClass, self).exit_gracefully(signum, frame)