示例#1
0
 def __new__(cls, name, bases, attr_dict):
     cmapper = get_mapper(_namespace_mapper_domain)
     for k, v in attr_dict.items():
         if isinstance(v, (ComponentGroup, MultiComponent, MultiComponentGroup)):
             mapped_class = cmapper[v.__class__]
             attr_dict[k] = v.clone(clone_into_class=mapped_class)
     newbie = super(NamespaceModelMeta, cls).__new__(cls, name, bases, attr_dict)
     process_modifiers(newbie)
     return newbie
示例#2
0
文件: agent.py 项目: haxsaw/actuator
    def _perform_task(self, task, logfile=None):
        task.fix_arguments()
        if isinstance(task, (NullTask, StructuralTask)):
            task.perform()
        else:
            cmapper = get_mapper(_agent_domain)
            processor = cmapper[task.__class__]()
#             task.get_task_role().fix_arguments()
#             task_host = task.get_task_host()
            task_host = self._get_run_host(task)
            if task_host is not None:
                msg = "Task {} being run on {}".format(task.name, task_host)
                if logfile:
                    logfile.write("{}\n".format(msg))
                hlist = [task_host]
            else:
                raise ExecutionException("We need a default execution host")
            kwargs = processor.make_args(task, hlist)
            kwargs["forks"] = 1
            kwargs["timeout"] = 20
            if logfile:
                logfile.write(">>>Params:\n{}\n".format(json.dumps(kwargs)))
            
#             msg = json.dumps(kwargs)
#             runner_file = find_file(json_runner.__file__)
#             args = [sys.executable,
#                     runner_file]
#             proc = subprocess32.Popen(args, stdin=subprocess32.PIPE,
#                                       stdout=subprocess32.PIPE,
#                                       stderr=subprocess32.PIPE)
#             proc.stdin.write(msg)
#             proc.stdin.flush()
#             proc.stdin.close()
#             reply = proc.stdout.read()
#             proc.wait()
#             if logfile:
#                 logfile.write(">>>Result:\n{}\n".format(reply))
#             result = json.loads(reply)
            
            runner = Runner(**kwargs)
            result = runner.run()
            
            if logfile:
                logfile.write(">>>Result:\n{}\n".format(json.dumps(result)))
            processor.result_check(task, result, logfile=logfile)
        return
示例#3
0
 def compute_model(self, infra_mi):
     all_resources = set(infra_mi.components())
     self.logger.info("%d components to provision" % len(all_resources))
     dependencies = []
     rsrc_task_map = {}
         
     #first, generate tasks for all the components
     class_mapper = get_mapper(_rt_domain)
     for rsrc in all_resources:
         rsrc.fix_arguments()
         task_class = class_mapper.get(rsrc.__class__)
         if task_class is None:
             raise ProvisionerException("Unable to find a task class for resource {}, class {}"
                                        .format(rsrc.name, rsrc.__class__.__name__))
         task = task_class(rsrc, repeat_count=1)
         rsrc_task_map[rsrc] = task
     
     #next, find all the dependencies between components, and hence tasks
     for rsrc, task in rsrc_task_map.items():
         for d in task.depends_on_list():
             if d not in rsrc_task_map:
                 raise ProvisionerException("Resource {} says it depends on {}, "
                                            "but the latter isn't in the "
                                            "list of all components"
                                            .format(rsrc.name, d.name))
             dtask = rsrc_task_map[d]
             dependencies.append(dtask | task)
             
     self.logger.info("%d resource dependencies" % len(dependencies))
             
     #now we can make a config class with these tasks and dependencies
     class ProvConfig(ConfigModel):
         for task in rsrc_task_map.values():
             exec "%s_%d = task" % (string.translate(task.name, self.no_punc),
                                    id(task))
         del task
         with_dependencies(*dependencies)
         
     return ProvConfig()