本文整理汇总了Python中ion.util.enhanced_resource_registry_client.EnhancedResourceRegistryClient.find_object方法的典型用法代码示例。如果您正苦于以下问题:Python EnhancedResourceRegistryClient.find_object方法的具体用法?Python EnhancedResourceRegistryClient.find_object怎么用?Python EnhancedResourceRegistryClient.find_object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ion.util.enhanced_resource_registry_client.EnhancedResourceRegistryClient
的用法示例。
在下文中一共展示了EnhancedResourceRegistryClient.find_object方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DeploymentPlanner
# 需要导入模块: from ion.util.enhanced_resource_registry_client import EnhancedResourceRegistryClient [as 别名]
# 或者: from ion.util.enhanced_resource_registry_client.EnhancedResourceRegistryClient import find_object [as 别名]
class DeploymentPlanner(object):
"""
A deployment activator validates that a set of devices will map to a set of sites in one unique way
its primary purpose is to prepare( ) after which you'll be able to access what associations must be made (and unmade)
"""
def __init__(self, clients=None, enhanced_rr=None):
self.clients = clients
self.enhanced_rr = enhanced_rr
if not enhanced_rr:
self.enhanced_rr = EnhancedResourceRegistryClient(self.clients.resource_registry)
self.outil = ObservatoryUtil(self, enhanced_rr=self.enhanced_rr)
#self.resource_collector= DeploymentResourceCollector(self.clients, self.enhanced_rr)
#self.resource_collector = resource_collector.create(self.deployment_obj)
def _find_top_site_device(self, deployment_id):
top_site = ''
top_device = ''
#retrieve the site tree information using the OUTIL functions; site info as well has site children
deploy_items_objs, _ = self.clients.resource_registry.find_subjects(predicate=PRED.hasDeployment, object=deployment_id, id_only=False)
log.debug("site_ids associated to this deployment: %s", deploy_items_objs)
for obj in deploy_items_objs:
rsrc_type = obj.type_
log.debug("resource type associated to this deployment:: %s", rsrc_type)
if RT.PlatformDevice == rsrc_type or RT.InstrumentDevice == rsrc_type:
top_device = obj
elif RT.PlatformSite == rsrc_type or RT.InstrumentSite == rsrc_type:
top_site = obj
else:
log.error('Deployment may only link to devices and sites. Deployment: %s', str(self.deployment_obj))
if not top_device or not top_site:
log.error('Deployment must associate to both site and device. Deployment: %s', str(self.deployment_obj))
raise BadRequest('Deployment must associate to both site and device. Deployment: %s', str(self.deployment_obj))
return top_site, top_device
def _find_pairs_to_remove(self):
#figure out if any of the devices in the new mapping are already mapped and need to be removed
pairs_to_remove = []
pairs_to_ignore = []
for (s, d) in self.match_list:
rm_pair, ignore_pair = self._find_existing_relationship(s, d)
if rm_pair:
pairs_to_remove.append(rm_pair)
if ignore_pair:
pairs_to_ignore.append(ignore_pair)
log.info("Pairs to ignore (will be removed from add list): %s", pairs_to_ignore)
# make sure that anything being removed is not also being added
self.match_list = filter(lambda x: x not in pairs_to_ignore, self.match_list)
log.info("Pairs to remove: %s", pairs_to_remove)
self.remove_list = pairs_to_remove
def _find_existing_relationship(self, site_id, device_id, site_type=None, device_type=None):
# look for an existing relationship between the site_id and another device.
# if this site/device pair already exists, we leave it alone
assert(type("") == type(site_id) == type(device_id))
log.debug("checking %s/%s pair for deployment", site_type, device_type)
#return a pair that should be REMOVED, or None
if site_type is None and site_id in self.site_resources:
site_type = self.site_resources[site_id].type_
if device_type is None and device_id in self.device_resources:
device_type = self.device_resources[device_id].type_
log.debug("checking existing %s hasDevice %s links", site_type, device_type)
ret_remove = None
ret_ignore = None
try:
found_device_id = self.enhanced_rr.find_object(site_id, PRED.hasDevice, device_type, True)
if found_device_id == device_id:
ret_ignore = (site_id, device_id)
else:
ret_remove = (site_id, found_device_id)
log.warning("%s '%s' already hasDevice %s", site_type, site_id, device_type)
except NotFound:
pass
return ret_remove, ret_ignore
def _get_site_ref_designator_map(self):
# create a map of site ids to their reference designator codes to facilitate matching
site_ref_designator_map = {}
for id, site_obj in self.site_resources.iteritems():
#.........这里部分代码省略.........
示例2: AgentConfigurationBuilder
# 需要导入模块: from ion.util.enhanced_resource_registry_client import EnhancedResourceRegistryClient [as 别名]
# 或者: from ion.util.enhanced_resource_registry_client.EnhancedResourceRegistryClient import find_object [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]
示例3: AgentConfigurationBuilder
# 需要导入模块: from ion.util.enhanced_resource_registry_client import EnhancedResourceRegistryClient [as 别名]
# 或者: from ion.util.enhanced_resource_registry_client.EnhancedResourceRegistryClient import find_object [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
示例4: AgentConfigurationBuilder
# 需要导入模块: from ion.util.enhanced_resource_registry_client import EnhancedResourceRegistryClient [as 别名]
# 或者: from ion.util.enhanced_resource_registry_client.EnhancedResourceRegistryClient import find_object [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]