Example #1
0
def load_module(module_dict, okapi_url, tenant, modules_root, db_conf, node,
                okapi_proc):
    module_exec = module_dict["exec"].replace('[[MODULES_ROOT]]',
                                              modules_root).replace(
                                                  '[[DB_CONF]]', db_conf)
    module_md = module_dict["md"].replace('[[MODULES_ROOT]]', modules_root)
    print("DEBUG: module_exec: %s, module_md: %s" % (module_exec, module_md))
    with open(module_md, 'r') as md_file:
        md_dict = json.load(md_file)
    module_id = md_dict["id"]
    dd_dict = module_loader.make_deployment_descriptor(module_id, module_exec,
                                                       None, node)
    try:
        module_loader.load_module(okapi_url=okapi_url, module_descriptor=md_dict, deployment_descriptor=dd_dict,\
                tenant=tenant, admin_tenant=None, admin_token=None)
    except Exception as e:
        print("Error loading module %s: %s" % (module_id, e))
        print("Killing Okapi")
        okapi_proc.terminate()
        sys.exit(1)
Example #2
0
	def revive_jobs(self):
		"""
			Fetches all jobs from DB that are in state "new" or "running", and
			recreates the objects from its pickled representation.

			returns  : list of alive, unqueued jobs
		"""
		results=upqdb.UpqDB().query("SELECT * FROM upqueue WHERE status = 1 OR status = 2")
		jobs = []
		for res in results:
			job=res['jobname']
			modclass=module_loader.load_module(job)
			obj=modclass(job, json.loads(res['jobdata']))
			obj.jobid = res['jobid']
			obj.thread = "Thread-revived-UpqJob"
			jobs.append(obj)
		logger.debug("revived jobs='%s'", jobs)
		return jobs
Example #3
0
    def revive_jobs(self):
        """
			Fetches all jobs from DB that are in state "new" or "running", and
			recreates the objects from its pickled representation.

			returns  : list of alive, unqueued jobs
		"""
        results = upqdb.UpqDB().query(
            "SELECT * FROM upqueue WHERE status = 1 OR status = 2")
        jobs = []
        for res in results:
            job = res['jobname']
            modclass = module_loader.load_module(job)
            obj = modclass(job, json.loads(res['jobdata']))
            obj.jobid = res['jobid']
            obj.thread = "Thread-revived-UpqJob"
            jobs.append(obj)
        logger.debug("revived jobs='%s'", jobs)
        return jobs
Example #4
0
	def new_job(self, jobname, params):
		"""
		creates a new job and initializes by command array
		for example
			jobname="notify"
			params={ "syslog": "", "mail": "user@server1,user@server2" }
		"""
		# parse first word to find job
		jobs = upqconfig.UpqConfig().jobs
		try:
			if jobs.has_key(jobname):
				upqjob_class = module_loader.load_module(jobname)
				upqjob = upqjob_class(jobname, params)
				self.logger.debug(upqjob)
				return upqjob
			else:
				self.logger.error("(%s) job not found: %s"%(jobname, params))
		except Exception:
			self.logger.error("(%s) couldn't load module: %s" % (jobname, traceback.format_exc(100)))
		return None
Example #5
0
    def new_job(self, jobname, params):
        """
		creates a new job and initializes by command array
		for example
			jobname="notify"
			params={ "syslog": "", "mail": "user@server1,user@server2" }
		"""
        # parse first word to find job
        jobs = upqconfig.UpqConfig().jobs
        try:
            if jobs.has_key(jobname):
                upqjob_class = module_loader.load_module(jobname)
                upqjob = upqjob_class(jobname, params)
                self.logger.debug(upqjob)
                return upqjob
            else:
                self.logger.error("(%s) job not found: %s" % (jobname, params))
        except Exception:
            self.logger.error("(%s) couldn't load module: %s" %
                              (jobname, traceback.format_exc(100)))
        return None