当前位置: 首页>>代码示例>>Python>>正文


Python EnhancedResourceRegistryClient.find_objects方法代码示例

本文整理汇总了Python中ion.util.enhanced_resource_registry_client.EnhancedResourceRegistryClient.find_objects方法的典型用法代码示例。如果您正苦于以下问题:Python EnhancedResourceRegistryClient.find_objects方法的具体用法?Python EnhancedResourceRegistryClient.find_objects怎么用?Python EnhancedResourceRegistryClient.find_objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ion.util.enhanced_resource_registry_client.EnhancedResourceRegistryClient的用法示例。


在下文中一共展示了EnhancedResourceRegistryClient.find_objects方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: AgentConfigurationBuilder

# 需要导入模块: from ion.util.enhanced_resource_registry_client import EnhancedResourceRegistryClient [as 别名]
# 或者: from ion.util.enhanced_resource_registry_client.EnhancedResourceRegistryClient import find_objects [as 别名]

#.........这里部分代码省略.........
        if 'agent' not in agent_config:
            agent_config['agent'] = {'resource_id': device_obj._id}
        elif 'resource_id' not in agent_config.get('agent'):
            agent_config['agent']['resource_id'] = device_obj._id


        log.debug("add egg URI if available")
        if agent_obj.driver_uri:
            agent_config['driver_config']['process_type'] = (DriverProcessType.EGG,)
            agent_config['driver_config']['dvr_egg'] = agent_obj.driver_uri
        else:
            agent_config['driver_config']['process_type'] = (DriverProcessType.PYTHON_MODULE,)


        if log.isEnabledFor(logging.INFO):
            tree = self._summarize_children(agent_config)
            log.info("Children of %s are %s", self.agent_instance_obj.name, tree)

        self.generated_config = True

        return agent_config


    def record_launch_parameters(self, agent_config):
        """
        record process id of the launch
        """
        #self.RR2.update(self.agent_instance_obj)

        log.debug('completed agent start')

    def _collect_deployment(self, device_id=None):

        deployment_objs = self.RR2.find_objects(device_id, PRED.hasDeployment, RT.Deployment)

        # find current deployment using time constraints
        current_time =  int( calendar.timegm(time.gmtime()) )

        for d in deployment_objs:
            # find deployment start and end time
            time_constraint = None
            for constraint in d.constraint_list:
                if constraint.type_ == OT.TemporalBounds:
                    if time_constraint:
                        log.warn('deployment %s has more than one time constraint (using first)', d.name)
                    else:
                        time_constraint = constraint
            if time_constraint:
                # a time constraint was provided, check if the current time is in this window
                if int(time_constraint.start_datetime) < current_time < int(time_constraint.end_datetime) :
                    log.debug('_collect_deployment found current deployment start time: %s, end time: %s   current time:  %s    deployment: %s ',
                              time_constraint.start_datetime, time_constraint.end_datetime, current_time, d)
                    return d

        return None

    def _validate_reference_designator(self, port_assignments):
        #validate that each reference designator is valid / parseable
        # otherwise the platform cannot pull out the port number for power mgmt
        if not port_assignments:
            return

        if not isinstance(port_assignments, dict):
            log.error('Deployment for device has invalid port assignments.  device id: %s ', self._get_device()._id)
            return
开发者ID:Bobfrat,项目名称:coi-services,代码行数:69,代码来源:agent_configuration_builder.py

示例2: AgentConfigurationBuilder

# 需要导入模块: from ion.util.enhanced_resource_registry_client import EnhancedResourceRegistryClient [as 别名]
# 或者: from ion.util.enhanced_resource_registry_client.EnhancedResourceRegistryClient import find_objects [as 别名]

#.........这里部分代码省略.........
        Collect related resources to this agent instance

        Returns a dict of objects necessary to start this instance, keyed on the values of self._lookup_means()
            PRED.hasAgentInstance   -> device_obj
            PRED.hasModel           -> model_obj
            PRED.hasAgentDefinition -> agent_obj
            RT.ProcessDefinition    -> process_def_obj

        """
        assert self.agent_instance_obj

        lookup_means = self._lookup_means()

        assert lookup_means
        assert PRED.hasAgentInstance in lookup_means
        assert PRED.hasModel in lookup_means
        assert PRED.hasAgentDefinition in lookup_means
        #assert PRED.hasProcessDefinition in lookup_means

        lu = lookup_means

        ret = {}

        log.debug("retrieve the associated device")
        device_obj = self.RR2.find_subject(subject_type=lu[PRED.hasAgentInstance],
                                           predicate=PRED.hasAgentInstance,
                                           object=self.agent_instance_obj._id)

        ret[lu[PRED.hasAgentInstance]]= device_obj
        device_id = device_obj._id

        log.debug("%s '%s' connected to %s '%s' (L4-CI-SA-RQ-363)",
                  lu[PRED.hasAgentInstance],
                  str(device_id),
                  type(self.agent_instance_obj).__name__,
                  str(self.agent_instance_obj._id))

#        log.debug("retrieve the model associated with the device")
#        model_obj = self.RR2.find_object(subject=device_id,
#                                         predicate=PRED.hasModel,
#                                         object_type=lu[PRED.hasModel])
#
#        ret[lu[PRED.hasModel]] = model_obj
#        model_id = model_obj

        #retrive the stream info for this model
        #todo: add stream info to the platofrom model create
        #        streams_dict = platform_models_objs[0].custom_attributes['streams']
        #        if not streams_dict:
        #            raise BadRequest("Device model does not contain stream configuation used in launching the agent. Model: '%s", str(platform_models_objs[0]) )
        #TODO: get the agent from the instance not from the model!!!!!!!
        log.debug("retrieve the agent associated with the model")
        agent_obj = self.RR2.find_object(subject=self.agent_instance_obj._id,
                                         predicate=PRED.hasAgentDefinition,
                                         object_type=lu[PRED.hasAgentDefinition])

        ret[lu[PRED.hasAgentDefinition]] = agent_obj
        agent_id = agent_obj._id

        if not agent_obj.stream_configurations:
            raise BadRequest("Agent '%s' does not contain stream configuration used in launching" %
                             str(agent_obj) )

        log.debug("retrieve the process definition associated with this agent")
        process_def_obj = self.RR2.find_object(subject=agent_id,
                                               predicate=PRED.hasProcessDefinition,
                                               object_type=RT.ProcessDefinition)


        ret[RT.ProcessDefinition] = process_def_obj

        #retrieve the output products
        data_product_ids = self.RR2.find_objects(device_id, PRED.hasOutputProduct, RT.DataProduct, id_only=True)

        if not data_product_ids:
            raise NotFound("No output Data Products attached to this Device " + str(device_id))

        #retrieve the streams assoc with each defined output product
        for product_id in data_product_ids:
            self.RR2.find_stream_id_of_data_product_using_has_stream(product_id)  # check one stream per product
            self.RR2.find_dataset_id_of_data_product_using_has_dataset(product_id) # check one dataset per product

        self.associated_objects = ret


    def _get_device(self):
        self._check_associations()
        return self.associated_objects[self._lookup_means()[PRED.hasAgentInstance]]

#    def _get_model(self):
#        self._check_associations()
#        return self.associated_objects[self._lookup_means()[PRED.hasModel]]

    def _get_agent(self):
        self._check_associations()
        return self.associated_objects[self._lookup_means()[PRED.hasAgentDefinition]]

    def _get_process_definition(self):
        self._check_associations()
        return self.associated_objects[RT.ProcessDefinition]
开发者ID:oldpatricka,项目名称:coi-services,代码行数:104,代码来源:agent_configuration_builder.py

示例3: TestRollups

# 需要导入模块: from ion.util.enhanced_resource_registry_client import EnhancedResourceRegistryClient [as 别名]
# 或者: from ion.util.enhanced_resource_registry_client.EnhancedResourceRegistryClient import find_objects [as 别名]

#.........这里部分代码省略.........
            (pst[7], ist[4]),
            (pst[6], pst[8]),
            (pst[8], ist[5]),
            (pst[8], ist[6]),
        ]

        has_device = [
            (pst[2], pdv[2]),
            (pst[1], pdv[1]),
            (ist[1], idv[1]),
            (pst[3], pdv[3]),
            (pdv[3], idv[2]),
            (pdv[3], idv[3]),
            (ist[2], idv[2]),
            (ist[3], idv[3]),
            (pst[4], pdv[4]),
            (pdv[4], pdv[5]),
            (pdv[5], pdv[6]),
            (pdv[5], pdv[7]),
            (pdv[7], idv[4]),
            (pst[6], pdv[5]),
            (pst[7], pdv[6]),
            (pst[8], pdv[7]),
            (ist[5], idv[4]),
            (pdv[8], pdv[9]),
            (pdv[9], pdv[10]),
            (pdv[10], idv[5]),
            (pdv[9], pdv[11]),
            (pdv[11], idv[6]),
        ]

        for (s, o) in has_site:
            self.RR2.create_association(s, PRED.hasSite, o)
            self.assertIn(o, self.RR2.find_objects(s, PRED.hasSite, None, id_only=True))

        for (s, o) in has_device:
            self.RR2.create_association(s, PRED.hasDevice, o)
            self.assertIn(o, self.RR2.find_objects(s, PRED.hasDevice, None, id_only=True))

        self.assertEqual(pdv[1], self.RR2.find_platform_device_id_of_platform_site_using_has_device(pst[1]))


        # preparing to create fake agents, shortcut to status names
        o = DeviceStatusType.STATUS_OK
        w = DeviceStatusType.STATUS_WARNING
        c = DeviceStatusType.STATUS_CRITICAL

        # expected status for instruments and platforms
        idv_stat = ["ignore", c, o, w, o, w, c]

        # make the fake instrument agents, with their statuses
        for i, id in idv.iteritems():
            idv_agent = FakeAgent()
            idv_agent.set_agent("aggstatus", ms({AggregateStatusType.AGGREGATE_DATA: idv_stat[i]}))
            device_agents[id] = idv_agent


        # create fake agents for platforms

        pdv1_agent = FakeAgent()
        pdv1_agent.set_agent("aggstatus", ms())
        pdv1_agent.set_agent("child_agg_status", {})
        device_agents[pdv[1]] = pdv1_agent

        pdv2_agent = FakeAgent()
        pdv2_agent.set_agent("aggstatus", ms({AggregateStatusType.AGGREGATE_DATA: DeviceStatusType.STATUS_WARNING}))
开发者ID:Bobfrat,项目名称:coi-services,代码行数:70,代码来源:test_rollups.py

示例4: TestEnhancedResourceRegistryClient

# 需要导入模块: from ion.util.enhanced_resource_registry_client import EnhancedResourceRegistryClient [as 别名]
# 或者: from ion.util.enhanced_resource_registry_client.EnhancedResourceRegistryClient import find_objects [as 别名]

#.........这里部分代码省略.........
        except Exception as e:
            raise e

        #self.rr.read.assert_called_with("111", "")
        self.rr.retire.assert_called_once_with("111")


    def test_retire_bad_wrongtype(self):
        """
        test resource read (passthru)
        """
        # get objects
        myret = self.sample_resource()

        #configure Mock
        self.rr.read.return_value = myret

        self.assertRaises(BadRequest, self.RR2.retire, "111", RT.PlatformDevice)
        self.rr.read.assert_called_once_with("111")


    def test_pluck_delete(self):
        """
        test delete
        """
        # get objects

        myret = self.sample_resource()

        #configure Mock
        self.rr.read.return_value = myret
        self.rr.delete.return_value = None
        self.rr.find_resources.return_value = None
        self.rr.find_objects.return_value = (["2"], ["2"])
        self.rr.find_subjects.return_value = (["3"], ["3"])

        self.RR2.pluck_delete("111", RT.InstrumentDevice)

        self.rr.delete.assert_called_once_with("111")


    def test_advance_lcs(self):
        """
        call RR when the transition ISN'T retire
        """
        self.RR2.advance_lcs("111", LCE.PLAN)
        self.rr.execute_lifecycle_transition.assert_called_once_with(resource_id="111", transition_event=LCE.PLAN)

        self.RR2.advance_lcs("222", LCE.RETIRE)
        self.rr.retire.assert_called_once_with("222")


    def test_delete_association(self):
        self.rr.get_association.return_value = "111"
        self.RR2.delete_association("a", "b", "c")
        self.rr.delete_association.assert_called_once_with("111")


    def test_delete_all_object_associations(self):
        self.rr.find_associations.return_value = ["111"]
        self.RR2.delete_object_associations("x")
        self.rr.delete_association.assert_called_once_with("111")


    def test_delete_all_subject_associations(self):
        self.rr.find_associations.return_value = ["111"]
开发者ID:Bobfrat,项目名称:coi-services,代码行数:70,代码来源:test_enhanced_resource_registry_client.py

示例5: AgentConfigurationBuilder

# 需要导入模块: from ion.util.enhanced_resource_registry_client import EnhancedResourceRegistryClient [as 别名]
# 或者: from ion.util.enhanced_resource_registry_client.EnhancedResourceRegistryClient import find_objects [as 别名]

#.........这里部分代码省略.........

        Returns a dict of objects necessary to start this instance, keyed on the values of self._lookup_means()
            PRED.hasAgentInstance   -> device_obj
            PRED.hasModel           -> model_obj
            PRED.hasAgentDefinition -> agent_obj
            RT.ProcessDefinition    -> process_def_obj

        """
        assert self.agent_instance_obj

        lookup_means = self._lookup_means()

        assert lookup_means
        assert PRED.hasAgentInstance in lookup_means
        assert PRED.hasModel in lookup_means
        assert PRED.hasAgentDefinition in lookup_means
        # assert PRED.hasProcessDefinition in lookup_means

        lu = lookup_means

        ret = {}

        log.debug("retrieve the associated device")
        device_obj = self.RR2.find_subject(
            subject_type=lu[PRED.hasAgentInstance], predicate=PRED.hasAgentInstance, object=self.agent_instance_obj._id
        )

        ret[lu[PRED.hasAgentInstance]] = device_obj
        device_id = device_obj._id

        log.debug(
            "%s '%s' connected to %s '%s' (L4-CI-SA-RQ-363)",
            lu[PRED.hasAgentInstance],
            str(device_id),
            type(self.agent_instance_obj).__name__,
            str(self.agent_instance_obj._id),
        )

        #        log.debug("retrieve the model associated with the device")
        #        model_obj = self.RR2.find_object(subject=device_id,
        #                                         predicate=PRED.hasModel,
        #                                         object_type=lu[PRED.hasModel])
        #
        #        ret[lu[PRED.hasModel]] = model_obj
        #        model_id = model_obj

        # retrive the stream info for this model
        # todo: add stream info to the platofrom model create
        #        streams_dict = platform_models_objs[0].custom_attributes['streams']
        #        if not streams_dict:
        #            raise BadRequest("Device model does not contain stream configuation used in launching the agent. Model: '%s", str(platform_models_objs[0]) )
        # TODO: get the agent from the instance not from the model!!!!!!!
        log.debug("retrieve the agent associated with the model")
        agent_obj = self.RR2.find_object(
            subject=self.agent_instance_obj._id,
            predicate=PRED.hasAgentDefinition,
            object_type=lu[PRED.hasAgentDefinition],
        )

        ret[lu[PRED.hasAgentDefinition]] = agent_obj
        agent_id = agent_obj._id

        if not agent_obj.stream_configurations:
            raise BadRequest("Agent '%s' does not contain stream configuration used in launching" % str(agent_obj))

        log.debug("retrieve the process definition associated with this agent")
        process_def_obj = self.RR2.find_object(
            subject=agent_id, predicate=PRED.hasProcessDefinition, object_type=RT.ProcessDefinition
        )

        ret[RT.ProcessDefinition] = process_def_obj

        # retrieve the output products
        data_product_ids, _ = self.RR2.find_objects(device_id, PRED.hasOutputProduct, RT.DataProduct, id_only=True)

        if not data_product_ids:
            raise NotFound("No output Data Products attached to this Device " + str(device_id))

        # retrieve the streams assoc with each defined output product
        for product_id in data_product_ids:
            self.RR2.find_stream_id_of_data_product(product_id)  # check one stream per product
            self.RR2.find_dataset_id_of_data_product(product_id)  # check one dataset per product

        self.associated_objects = ret

    def _get_device(self):
        self._check_associations()
        return self.associated_objects[self._lookup_means()[PRED.hasAgentInstance]]

    #    def _get_model(self):
    #        self._check_associations()
    #        return self.associated_objects[self._lookup_means()[PRED.hasModel]]

    def _get_agent(self):
        self._check_associations()
        return self.associated_objects[self._lookup_means()[PRED.hasAgentDefinition]]

    def _get_process_definition(self):
        self._check_associations()
        return self.associated_objects[RT.ProcessDefinition]
开发者ID:newbrough,项目名称:coi-services,代码行数:104,代码来源:agent_configuration_builder.py

示例6: RollXBuilder

# 需要导入模块: from ion.util.enhanced_resource_registry_client import EnhancedResourceRegistryClient [as 别名]
# 或者: from ion.util.enhanced_resource_registry_client.EnhancedResourceRegistryClient import find_objects [as 别名]
class RollXBuilder(object):
    """
    for rollups and rolldowns
    """

    def __init__(self, process=None):
        """
        the process should be the "self" of a service instance
        """
        assert process
        self.process = process
        self.RR2 = EnhancedResourceRegistryClient(self.process.clients.resource_registry)

    def get_toplevel_platformsite(self, site_id):
        if not self.RR2.has_cached_predicate(PRED.hasSite):
            self.RR2.cache_predicate(PRED.hasSite)

        parent_ids = self.RR2.find_platform_site_ids_by_platform_site_using_has_site(site_id)

        if 0 == len(parent_ids):
            return site_id  # assume this to be the top level

        return self.get_toplevel_platformsite(parent_ids[0])

    def get_parent_network_nodes(self, site_id):
        """
        return the parent nodes of this network node, including the given node
        """
        if not self.RR2.has_cached_predicate(PRED.hasNetworkParent):
            self.RR2.cache_predicate(PRED.hasNetworkParent)

        def get_h(acc, some_id):
            acc.append(some_id)
            parent_ids = self.RR2.find_platform_device_ids_of_platform_device_using_has_network_parent(site_id)
            if 0 == len(parent_ids):
                return acc
            return get_h(acc, parent_ids[0])

        return get_h([], site_id)

    def get_toplevel_network_node(self, device_id):
        if not self.RR2.has_cached_predicate(PRED.hasNetworkParent):
            self.RR2.cache_predicate(PRED.hasNetworkParent)

        parent_ids = self.RR2.find_platform_device_ids_of_platform_device_using_has_network_parent(device_id)

        if 0 == len(parent_ids):
            # it can only be the network parent if it has this association
            if 0 < len(self.RR2.find_platform_device_ids_by_platform_device_using_has_network_parent(device_id)):
                return device_id  # assume this to be top level
            else:
                return None

        return self.get_toplevel_network_node(parent_ids[0])

    def get_site_hierarchy(self, site_id, site_val_fn):
        """
        return (child_sites, site_ancestors)
        where child_sites is a dict mapping all child site ids to the value of site_val_fn(child_site_id)
          and site_ancestors is a dict mapping all site ids to a list of their hasSite children.
        """

        if not self.RR2.has_cached_predicate(PRED.hasSite):
            self.RR2.cache_predicate(PRED.hasSite)

        full_list = [site_id]
        acc = {}

        def _get_ancestors_h(s_id):
            s_child_ids = self.RR2.find_objects(s_id, PRED.hasSite, id_only=True)
            if s_child_ids:
                acc[s_id] = s_child_ids
            for scid in s_child_ids:
                _get_ancestors_h(scid)
                full_list.append(scid)

        _get_ancestors_h(site_id)

        return dict([(s, site_val_fn(s)) for s in full_list]), acc

    def get_network_hierarchy(self, device_id, device_val_fn):
        """
        return (child_devices, device_ancestors)
        where child_devices is a dict mapping all child device ids to the value of device_val_fn(child_device_id)
          and device_ancestors is a dict mapping all device ids to a list of their children as per
        """

        if not self.RR2.has_cached_predicate(PRED.hasNetworkParent):
            self.RR2.cache_predicate(PRED.hasNetworkParent)

        full_list = [device_id]
        acc = {}

        def _get_ancestors_h(d_id):
            d_child_ids = self.RR2.find_subjects(d_id, PRED.hasNetworkParent, id_only=True)
            if d_child_ids:
                acc[d_id] = d_child_ids
            for dcid in d_child_ids:
                _get_ancestors_h(dcid)
                full_list.append(dcid)
#.........这里部分代码省略.........
开发者ID:edwardhunter2,项目名称:coi-services,代码行数:103,代码来源:rollx_builder.py


注:本文中的ion.util.enhanced_resource_registry_client.EnhancedResourceRegistryClient.find_objects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。