Example #1
0
    def announced(self, state, announce):
        state.descriptor = announce.payload['descriptor']
        state.factory = applications.lookup_agent(state.descriptor.type_name)
        state.keep_allocated = False

        if not check_categories(state.agent, state.factory.categories):
            self._refuse()
            return

        resc = state.descriptor.extract_resources()
        agent_id = state.descriptor.doc_id
        partner = agent_id and state.agent.find_partner(agent_id)
        if partner and partner.allocation_id:
            cost = 0
            delta = state.agent.get_allocation_delta(
                partner.allocation_id, **resc)
            if delta:
                alloc = state.agent.premodify_allocation(
                    partner.allocation_id, **delta)
            else:
                alloc = state.agent.get_allocation(partner.allocation_id)
                state.keep_allocated = True
        else:
            cost = 10
            alloc = state.agent.preallocate_resource(**resc)

        if alloc is None:
            self._refuse()
            return

        state.alloc_id = alloc.id

        bid = message.Bid()
        bid.payload = dict(cost=cost)
        state.medium.bid(bid)
Example #2
0
 def check_requirements(self, state, doc):
     agnt = applications.lookup_agent(doc.type_name)
     ret = check_categories(self, agnt.categories)
     if not ret:
         msg = "Categoryies doesn't match"
         self.error(msg)
         raise CategoryError(msg)
     return doc
Example #3
0
File: agency.py Project: f3at/feat
 def actually_start_agent(self, descriptor, **kwargs):
     """
     This method will be run only on the master agency.
     """
     factory = IAgentFactory(applications.lookup_agent(descriptor.type_name))
     if factory.standalone:
         return self.start_standalone_agent(descriptor, factory, **kwargs)
     else:
         return self.start_agent_locally(descriptor, **kwargs)
Example #4
0
 def extract_resources(self):
     if self.resources:
         resp = dict()
         for name, value in self.resources.iteritems():
             if resource.IAllocatedResource.providedBy(value):
                 value = value.extract_init_arguments()
             resp[name] = value
         return resp
     else:
         return applications.lookup_agent(self.type_name).resources
Example #5
0
    def _update_agent_filter(self):
        agent_objects = [applications.lookup_agent(t)
                         for t in self.filter_type]
        self.filter_id = []

        def is_in_filter(aa):
            return type(aa.get_agent()) in agent_objects

        for agency in self._agencies:
            self.filter_id += [x.get_agent_id()
                               for x in agency._agents
                               if is_in_filter(x)]
Example #6
0
 def initiate(self, state, desc, **kwargs):
     state.descriptor = desc
     state.max_retries = kwargs.pop('_max_retries', 3)
     state.keywords = kwargs
     state.factory = applications.lookup_agent(state.descriptor.type_name)
     # we are setting shard=None here first, because of the logic in
     # Host Agent which prevents it from changing the shard field if it
     # has been set to sth meaningfull (not in [None, 'lobby'])
     f = self.fiber_succeed(state.agent)
     f.add_callback(state.descriptor.set_shard, None)
     f.add_callback(self._store_descriptor)
     f.add_callback(fiber.drop_param, self._retry)
     return f
Example #7
0
    def get_cmd_line(desc):
        python_path = ":".join(sys.path)
        path = os.environ.get("PATH", "")

        command = os.path.join(configure.bindir, 'feat')
        args = ['-X', '--agent-id', str(desc.doc_id)]
        agent = applications.lookup_agent(desc.type_name)
        if agent and agent.application.name != 'feat':
            app = agent.application
            args += ['--application', '.'.join([app.module, app.name])]

        env = dict(PYTHONPATH=python_path, FEAT_DEBUG='5', PATH=path)
        return command, args, env
Example #8
0
    def _load_log_categories(self, hostname):
        jour = self._reader

        log_categories = LogCategoriesStore()
        log_categories.append()
        categories = yield jour.get_log_categories(hostname=hostname)
        for category in categories:
            names = yield jour.get_log_names(category)
            names_store = gtk.ListStore(str)
            names_store.append()
            for name in names:
                names_store.append((name, ))
                if applications.lookup_agent(category):
                    self.agents_store.identify_agent(name, category)
            log_categories.append((category, names_store))
        defer.returnValue(log_categories)
Example #9
0
File: common.py Project: f3at/feat
 def revert_overrides_config(self):
     if not hasattr(self, 'overriden_configs'):
         return
     for key, value in self.overriden_configs.iteritems():
         factory = applications.lookup_agent(key)
         factory.configuration_doc_id = value
Example #10
0
File: common.py Project: f3at/feat
 def override_config(self, agent_type, config):
     if not hasattr(self, 'overriden_configs'):
         self.overriden_configs = dict()
     factory = applications.lookup_agent(agent_type)
     self.overriden_configs[agent_type] = factory.configuration_doc_id
     factory.configuration_doc_id = config.doc_id
Example #11
0
 def _get_factory(self, state):
     return applications.lookup_agent(state.descriptor.type_name)
Example #12
0
 def _determine_factory(self, state):
     state.factory = applications.lookup_agent(state.descriptor.type_name)