本文整理汇总了Python中pyon.public.IonObject类的典型用法代码示例。如果您正苦于以下问题:Python IonObject类的具体用法?Python IonObject怎么用?Python IonObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IonObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_type_interface
def _get_type_interface(self, res_type):
"""
Creates a merge of params and commands up the type inheritance chain.
Note: Entire param and command entries if subtypes replace their super types definition.
"""
res_interface = dict(params={}, commands={})
base_types = IonObject(res_type)._get_extends()
base_types.insert(0, res_type)
for rt in reversed(base_types):
type_interface = self.resource_interface.get(rt, None)
if not type_interface:
continue
for tpar, tval in type_interface.iteritems():
if tpar in res_interface:
rval = res_interface[tpar]
if isinstance(rval, dict):
rval.update(tval)
else:
res_interface[tpar] = tval
else:
res_interface[tpar] = dict(tval) if isinstance(tval, dict) else tval
return res_interface
示例2: get_user_notifications
def get_user_notifications(self, user_id=''):
'''
Get the notification request objects that are subscribed to by the user
@param user_id str
@retval notifications list of NotificationRequest objects
'''
user = self.clients.resource_registry.read(user_id)
if not user:
return None
if not user.name:
raise BadRequest("Please assign a name to the resource. Example: resource.name = \'Irene\' for UNS to "
"be able to fetch the related notifications")
if self.event_processor.user_info.has_key(user.name):
notifications = self.event_processor.user_info[user.name]['notifications']
ret = IonObject(OT.ComputedListValue)
if notifications:
ret.value = notifications
ret.status = ComputedValueAvailability.PROVIDED
else:
ret.status = ComputedValueAvailability.NOTAVAILABLE
return ret
else:
return None
示例3: _convert_negotiations_to_requests
def _convert_negotiations_to_requests(self, negotiations=None, user_info_id='', org_id=''):
assert isinstance(negotiations, list)
orgs,_ = self.clients.resource_registry.find_resources(restype=RT.Org)
ret_list = []
for neg in negotiations:
request = IonObject(OT.OrgUserNegotiationRequest, ts_updated=neg.ts_updated, negotiation_id=neg._id,
negotiation_type=NegotiationTypeEnum._str_map[neg.negotiation_type],
negotiation_status=NegotiationStatusEnum._str_map[neg.negotiation_status],
originator=ProposalOriginatorEnum._str_map[neg.proposals[-1].originator],
request_type=neg.proposals[-1].type_,
description=neg.description, reason=neg.reason,
user_id=user_info_id)
# since this is a proxy for the Negotiation object, simulate its id to help the UI deal with it
request._id = neg._id
org_request = [ o for o in orgs if o._id == neg.proposals[-1].provider ]
if org_request:
request.org_id = org_request[0]._id
request.name = org_request[0].name
ret_list.append(request)
return ret_list
示例4: get_is_persisted
def get_is_persisted(self, data_product_id=''):
# Returns True if data product is currently being persisted
ret = IonObject(OT.ComputedIntValue)
ret.value = self.is_persisted(data_product_id)
ret.status = ComputedValueAvailability.PROVIDED
return ret
示例5: _get_computed_events
def _get_computed_events(self, events, add_usernames=True, include_events=False):
"""
Get events for use in extended resource computed attribute
@retval ComputedListValue with value list of 4-tuple with Event objects
"""
events = events or []
ret = IonObject(OT.ComputedEventListValue)
ret.value = events
ret.computed_list = [get_event_computed_attributes(event, include_event=include_events) for event in events]
ret.status = ComputedValueAvailability.PROVIDED
if add_usernames:
try:
actor_ids = {evt.actor_id for evt in events if evt.actor_id}
log.debug("Looking up UserInfo for actors: %s" % actor_ids)
if actor_ids:
userinfo_list, assoc_list = self.clients.resource_registry.find_objects_mult(actor_ids,
predicate=PRED.hasInfo,
id_only=False)
actor_map = {assoc.s: uinfo for uinfo, assoc in zip(userinfo_list, assoc_list)}
for evt, evt_cmp in zip(events, ret.computed_list):
ui = actor_map.get(evt.actor_id, None)
if ui:
evt_cmp["event_summary"] += " [%s %s]" % (ui.contact.individual_names_given, ui.contact.individual_name_family)
except Exception as ex:
log.exception("Cannot find user names for event actor_ids")
return ret
示例6: run_reverse_transform
def run_reverse_transform(self):
''' Runs a reverse transform example and displays the results of performing the transform
'''
tms_cli = TransformManagementServiceClient(node=self.container.node)
procd_cli = ProcessDispatcherServiceClient(node=self.container.node)
#-------------------------------
# Process Definition
#-------------------------------
process_definition = IonObject(RT.ProcessDefinition, name='transform_process_definition')
process_definition.executable = {
'module': 'ion.processes.data.transforms.transform_example',
'class':'ReverseTransform'
}
process_definition_id = procd_cli.create_process_definition(process_definition)
#-------------------------------
# Execute Transform
#-------------------------------
input = [1,2,3,4]
retval = tms_cli.execute_transform(process_definition_id=process_definition_id,
data=[1,2,3,4],
configuration={})
log.debug('Transform Input: %s', input)
log.debug('Transform Output: %s', retval)
示例7: test_createDataProduct_and_DataProducer_with_id_BadRequest
def test_createDataProduct_and_DataProducer_with_id_BadRequest(self):
# setup
self.resource_registry.find_resources.return_value = ([], 'do not care')
self.resource_registry.create.return_value = ('SOME_RR_ID1', 'Version_1')
self.data_acquisition_management.create_data_producer.side_effect = BadRequest("Create cannot create document with ID: ")
# Data Product
dpt_obj = IonObject(RT.DataProduct,
name='DPT_X',
description='some new data product')
# Data Producer
dpr_obj = IonObject(RT.DataProducer,
name='DP_X',
description='some new data producer')
dpr_obj._id = "SOME_OTHER_RR_ID"
# test call
with self.assertRaises(BadRequest) as cm:
dp_id = self.data_product_management_service.create_data_product(dpt_obj, dpr_obj)
# check results
self.resource_registry.find_resources.assert_called_once_with(RT.DataProduct, None, dpt_obj.name, True)
self.resource_registry.create.assert_called_once_with(dpt_obj)
self.data_acquisition_management.create_data_producer.assert_called_once_with(dpr_obj)
ex = cm.exception
self.assertEqual(ex.message, "Create cannot create document with ID: ")
示例8: create_resource_commitment
def create_resource_commitment(self, org_id="", actor_id="", resource_id="", exclusive=False, expiration=0):
"""Creates a Commitment for the specified resource for a specified actor within
the specified Org. Once shared, the resource is committed to the actor.
"""
org_obj = self._validate_resource_id("org_id", org_id, RT.Org, optional=True)
actor_obj = self._validate_resource_id("actor_id", actor_id, RT.ActorIdentity)
resource_obj = self._validate_resource_id("resource_id", resource_id)
if org_id:
# Check that resource is shared in Org?
pass
res_commitment = IonObject(OT.ResourceCommitment, resource_id=resource_id, exclusive=exclusive)
commitment = IonObject(RT.Commitment, name="", provider=org_id, consumer=actor_id, commitment=res_commitment,
description="Resource Commitment", expiration=str(expiration))
commitment._id, commitment._rev = self.rr.create(commitment)
# Creating associations to all related objects
self.rr.create_association(actor_id, PRED.hasCommitment, commitment._id)
self.rr.create_association(commitment._id, PRED.hasTarget, resource_id)
if org_id:
self.rr.create_association(org_id, PRED.hasCommitment, commitment._id)
self.event_pub.publish_event(event_type=OT.ResourceCommitmentCreatedEvent,
origin=org_id, origin_type="Org", sub_type=resource_obj.type_,
description="The resource has been committed by the Org",
resource_id=resource_id, org_name=org_obj.name,
commitment_id=commitment._id, commitment_type=commitment.commitment.type_)
return commitment._id
示例9: _create_association
def _create_association(self, subject=None, predicate=None, obj=None, support_bulk=False):
"""
Create an association between two IonObjects with a given predicate.
Supports bulk mode
"""
if self.bulk and support_bulk:
if not subject or not predicate or not obj:
raise BadRequest("Association must have all elements set: %s/%s/%s" % (subject, predicate, obj))
if isinstance(subject, basestring):
subject = self._get_resource_obj(subject)
if "_id" not in subject:
raise BadRequest("Subject id not available")
subject_id = subject._id
st = subject.type_
if isinstance(obj, basestring):
obj = self._get_resource_obj(obj)
if "_id" not in obj:
raise BadRequest("Object id not available")
object_id = obj._id
ot = obj.type_
assoc_id = create_unique_association_id()
assoc_obj = IonObject("Association",
s=subject_id, st=st,
p=predicate,
o=object_id, ot=ot,
ts=get_ion_ts())
assoc_obj._id = assoc_id
self.bulk_associations[assoc_id] = assoc_obj
return assoc_id, '1-norev'
else:
return self.rr.create_association(subject, predicate, obj)
示例10: acquire_resource
def acquire_resource(self, sap=None):
"""Creates a Commitment Resource for the specified resource for a specified user withing the specified Org as defined in the
proposal. Once shared, the resource is committed to the user. Throws a NotFound exception if none of the ids are found.
@param proposal AcquireResourceProposal
@retval commitment_id str
@throws NotFound object with specified id does not exist
"""
param_objects = self._validate_parameters(org_id=sap.provider, user_id=sap.consumer, resource_id=sap.resource)
if sap.type_ == OT.AcquireResourceExclusiveProposal:
exclusive = True
else:
exclusive = False
res_commitment = IonObject(OT.ResourceCommitment, resource_id=sap.resource, exclusive=exclusive)
commitment = IonObject(RT.Commitment, name='', provider=sap.provider, consumer=sap.consumer, commitment=res_commitment,
description='Resource Commitment', expiration=sap.expiration)
commitment_id, commitment_rev = self.clients.resource_registry.create(commitment)
commitment._id = commitment_id
commitment._rev = commitment_rev
#Creating associations to all objects
self.clients.resource_registry.create_association(sap.provider, PRED.hasCommitment, commitment_id)
self.clients.resource_registry.create_association(sap.consumer, PRED.hasCommitment, commitment_id)
self.clients.resource_registry.create_association(sap.resource, PRED.hasCommitment, commitment_id)
self.clients.resource_registry.create_association(sap.negotiation_id, PRED.hasContract, commitment_id)
#TODO - publish some kind of event for creating a commitment
return commitment_id
示例11: get_data_ingestion_datetime
def get_data_ingestion_datetime(self, data_product_id=''):
# Returns a temporal bounds object of the earliest/most recent values ingested into in the data product
ret = IonObject(OT.ComputedStringValue)
ret.value = ""
ret.status = ComputedValueAvailability.NOTAVAILABLE
ret.reason = "FIXME. also, should datetime be stored as a string?"
return ret
示例12: get_data_datetime
def get_data_datetime(self, data_product_id=''):
# Returns a temporal bounds object of the span of data product life span (may exist without getting a granule)
ret = IonObject(OT.ComputedStringValue)
ret.value = ""
ret.status = ComputedValueAvailability.NOTAVAILABLE
ret.reason = "FIXME. also, should datetime be stored as a string?"
return ret
示例13: get_data_url
def get_data_url(self, data_product_id=''):
# The unique pointer to this set of data
ret = IonObject(OT.ComputedStringValue)
ret.value = ""
ret.status = ComputedValueAvailability.NOTAVAILABLE
ret.reason = "FIXME."
return ret
示例14: fun
def fun():
#ret = Mock()
log.debug("Creating sample %s", iontype)
ret = IonObject(iontype)
ret.name = "sample %s" % iontype
ret.description = "description of sample %s" % iontype
for k, v in resource_params.iteritems():
setattr(ret, k, v)
return ret
示例15: get_data_contents_updated
def get_data_contents_updated(self, data_product_id=''):
# the datetime when the contents of the data were last modified in any way.
# This is distinct from modifications to the data product attributes
ret = IonObject(OT.ComputedStringValue)
ret.value = ""
ret.status = ComputedValueAvailability.NOTAVAILABLE
ret.reason = "FIXME. also, should datetime be stored as a string?"
return ret