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


Python bootstrap.IonObject类代码示例

本文整理汇总了Python中pyon.core.bootstrap.IonObject的典型用法代码示例。如果您正苦于以下问题:Python IonObject类的具体用法?Python IonObject怎么用?Python IonObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_create_counter_proposal

    def test_create_counter_proposal(self):

        with self.assertRaises(BadRequest) as cm:
            consumer_accept_sap = Negotiation.create_counter_proposal(proposal_status=ProposalStatusEnum.INITIAL)
        self.assertIn('The negotiation parameter must be a valid Negotiation object',cm.exception.message)

        negotiation_handler = Negotiation(self)

        sap = IonObject(OT.EnrollmentProposal,consumer=self.actor_identity._id, provider=self.org._id )

        negotiation = Mock()
        negotiation._id = '456'
        negotiation.type_ = RT.Negotiation
        negotiation.proposals = [sap]

        self.mock_read.return_value = negotiation
        self.mock_create.return_value = ['456', 2]

        neg_id = negotiation_handler.create_negotiation(sap)

        sap.negotiation_id = neg_id

        consumer_accept_sap = Negotiation.create_counter_proposal(negotiation, proposal_status=ProposalStatusEnum.COUNTER,
                originator=ProposalOriginatorEnum.PROVIDER)

        self.assertEqual(consumer_accept_sap.negotiation_id, negotiation._id)
        self.assertEqual(len(negotiation.proposals),1)
        self.assertEqual(consumer_accept_sap.sequence_num, len(negotiation.proposals))
        self.assertEqual(consumer_accept_sap.proposal_status, ProposalStatusEnum.COUNTER)
        self.assertEqual(consumer_accept_sap.originator, ProposalOriginatorEnum.PROVIDER)
开发者ID:ateranishi,项目名称:pyon,代码行数:30,代码来源:test_negotiation.py

示例2: test_get_valid_resource_commitment

    def test_get_valid_resource_commitment(self):
        from pyon.util.containers import get_ion_ts_millis

        # create ION org and an actor
        ion_org = IonObject(RT.Org, name='ION')
        ion_org_id, _ = self.rr.create(ion_org)
        ion_org._id = ion_org_id
        actor = IonObject(RT.ActorIdentity, name='actor1')
        actor_id, _ = self.rr.create(actor)

        # create an expired commitment in the org
        ts = get_ion_ts_millis() - 50000
        com_obj = IonObject(RT.Commitment, provider=ion_org_id, consumer=actor_id, commitment=True, expiration=ts)
        com_id, _ = self.rr.create(com_obj)
        id = self.rr.create_association(ion_org_id, PRED.hasCommitment, com_id)
        c = get_valid_resource_commitments(ion_org_id, actor_id)
        #verify that the commitment is not returned
        self.assertIsNone(c)

        # create a commitment that has not expired yet
        ts = get_ion_ts_millis() + 50000
        com_obj = IonObject(RT.Commitment, provider=ion_org_id, consumer=actor_id, commitment=True, expiration=ts)
        com_id, _ = self.rr.create(com_obj)
        id = self.rr.create_association(ion_org_id, PRED.hasCommitment, com_id)
        c = get_valid_resource_commitments(ion_org_id, actor_id)

        #verify that the commitment is returned
        self.assertIsNotNone(c)
开发者ID:ooici,项目名称:pyon,代码行数:28,代码来源:test_governance.py

示例3: create_extended_resource_container

    def create_extended_resource_container(self, extended_resource_type, resource_id, computed_resource_type=None,
                                           ext_associations=None, ext_exclude=None):

        if not self.service_provider or not self.resource_registry:
            raise Inconsistent("This class is not initialized properly")

        if extended_resource_type not in getextends(OT.ResourceContainer):
            raise BadRequest('Requested resource %s is not extended from %s' % ( extended_resource_type, OT.ResourceContainer) )

        if computed_resource_type and computed_resource_type not in getextends(OT.ComputedAttributes):
            raise BadRequest('Requested resource %s is not extended from %s' % ( computed_resource_type, OT.ComputedAttributes) )

        resource_object = self.resource_registry.read(resource_id)
        if not resource_object:
            raise NotFound("Resource %s does not exist" % resource_id)

        res_container = IonObject(extended_resource_type)
        res_container._id = resource_object._id
        res_container.resource = resource_object

        self.set_container_field_values(res_container, ext_exclude)

        self.set_computed_attributes(res_container, computed_resource_type, ext_exclude)

        self.set_extended_associations(res_container, ext_associations, ext_exclude)

        res_container.ts_created = get_ion_ts()

        return res_container
开发者ID:swarbhanu,项目名称:pyon,代码行数:29,代码来源:resource.py

示例4: create_test_col

 def create_test_col(level=0, ot=dict, no_ion=False):
     if level == 0:
         return get_value(0, 15, uvals)
     if ot == dict:
         res_dict = {}
         num_kinds = 1 if do_ion and no_ion else (1 if do_dict else 0) + (1 if do_list else 0)
         for i in xrange(breadth / num_kinds):
             if do_ion and not no_ion:
                 key = get_key()
                 res_obj = IonObject(restype, name="TestObject %s.%s" % (level, key))
                 res_obj.addl = create_test_col(level-1, dict, no_ion=True)
                 res_dict[key] = res_obj
             else:
                 if do_dict:
                     res_dict[get_key()] = create_test_col(level-1, dict)
                 if do_list:
                     res_dict[get_key()] = create_test_col(level-1, list)
         return res_dict
     elif ot == list:
         res_list = []
         num_kinds = 1 if do_ion and no_ion else (1 if do_dict else 0) + (1 if do_list else 0)
         for i in xrange(breadth / num_kinds):
             if do_ion and not no_ion:
                 res_obj = IonObject(restype, name="TestObject %s.%s" % (level, random.randint(1000, 9999)))
                 res_obj.addl = create_test_col(level-1, dict, no_ion=True)
                 res_list.append(res_obj)
             else:
                 if do_dict:
                     res_list.append(create_test_col(level-1, dict))
                 if do_list:
                     res_list.append(create_test_col(level-1, list))
         return res_list
     elif ot == "IonObject":
         res_obj = IonObject(restype, name="TestObject %s.%s" % (level, random.randint(1000, 9999)))
         return res_obj
开发者ID:edwardhunter,项目名称:scioncc,代码行数:35,代码来源:test_objperf.py

示例5: has_valid_resource_commitments

def has_valid_resource_commitments(actor_id, resource_id):
    '''
    Returns a ResourceCommitmentStatus object indicating the commitment status between this resource/actor
    Can only have an exclusive commitment if actor already has a shared commitment.
    @param actor_id:
    @param resource_id:
    @return:
    '''
    ret_status = IonObject(OT.ResourceCommitmentStatus)
    commitments = get_valid_resource_commitments(resource_id, actor_id)
    if commitments is None:
        #No commitments were found between this resource_id and actor_id - so return default object with
        #fields set to False
        return ret_status

    ret_status.shared = True

    for com in commitments:
        if com.commitment.exclusive == True:
            #Found an exclusive commitment
            ret_status.exclusive = True
            return ret_status

    #Only a shared commitment was found
    return ret_status
开发者ID:jamie-cyber1,项目名称:pyon,代码行数:25,代码来源:__init__.py

示例6: fun

 def fun():
     #ret = Mock()
     ret = IonObject(impl.iontype)
     ret.name = "sample %s" % impl.iontype
     ret.description = "description of sample %s" % impl.iontype
     for k, v in resource_params.iteritems():
         setattr(ret, k, v)
     return ret
开发者ID:tgiguere,项目名称:coi-services,代码行数:8,代码来源:resource_impl_metatest.py

示例7: fun

 def fun():
     #ret = Mock()
     self.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
开发者ID:ooici-eoi,项目名称:coi-services,代码行数:9,代码来源:resource_impl_metatest.py

示例8: obtain_agent_calculation

    def obtain_agent_calculation(self, device_id, result_container):
        ret = IonObject(result_container)

        h_agent, reason = self.get_device_agent(device_id)
        if None is h_agent:
            ret.status = ComputedValueAvailability.NOTAVAILABLE
            ret.reason = reason
        else:
            ret.status = ComputedValueAvailability.PROVIDED

        return h_agent, ret
开发者ID:oldpatricka,项目名称:coi-services,代码行数:11,代码来源:status_builder.py

示例9: execute_resource

    def execute_resource(self, resource_id='', command=None):
        """
        """

        if not command:
            iex = BadRequest('Execute argument "command" not set.')
            self._on_command_error('execute_resource', None, None, None, iex)
            raise iex

        # Grab command syntax.
        id = command.command_id
        cmd = command.command
        args = command.args or []
        kwargs = command.kwargs or {}

        if not command.command:
            iex = BadRequest('Command name not set.')
            self._on_command_error('execute_resource', cmd, args, kwargs, iex)
            raise iex

        # Construct a command result object.
        cmd_result = IonObject("AgentCommandResult",
                               command_id=id,
                               command=cmd,
                               ts_execute=get_ion_ts(),
                               status=0)

        try:
            result = self._fsm.on_event(
                ResourceAgentEvent.EXECUTE_RESOURCE, cmd, *args, **kwargs)
            cmd_result.result = result
            self._on_command('execute_resource', cmd, args, kwargs, result)

        except FSMStateError as ex:
            iex = Conflict(*(ex.args))
            self._on_command_error('execute_resource', cmd, args, kwargs, iex)
            raise iex

        except FSMCommandUnknownError as ex:
            iex = BadRequest(*(ex.args))
            self._on_command_error('execute_resource', cmd, args, kwargs, iex)
            raise iex

        except IonException as iex:
            self._on_command_error('execute_resource', cmd, args, kwargs, iex)
            raise iex

        except Exception as ex:
            iex = ServerError(*(ex.args))
            self._on_command_error('execute_resource', cmd, args, kwargs, iex)
            raise iex

        return cmd_result
开发者ID:seman,项目名称:pyon,代码行数:53,代码来源:agent.py

示例10: create_extended_resource_container

    def create_extended_resource_container(self, extended_resource_type, resource_id, computed_resource_type=None,
                                           ext_associations=None, ext_exclude=None):

        overall_start_time = time.time()

        if not isinstance(resource_id, types.StringType):
            raise Inconsistent("The parameter resource_id is not a single resource id string")

        if not self.service_provider or not self._rr:
            raise Inconsistent("This class is not initialized properly")

        if extended_resource_type not in getextends(OT.ResourceContainer):
            raise BadRequest('The requested resource %s is not extended from %s' % (extended_resource_type, OT.ResourceContainer))

        if computed_resource_type and computed_resource_type not in getextends(OT.ComputedAttributes):
            raise BadRequest('The requested resource %s is not extended from %s' % (computed_resource_type, OT.ComputedAttributes))

        resource_object = self._rr.read(resource_id)

        if not resource_object:
            raise NotFound("The Resource %s does not exist" % resource_id)

        res_container = IonObject(extended_resource_type)

        # @TODO - replace with object level decorators and raise exceptions
        if not hasattr(res_container, 'origin_resource_type'):
            log.error('The requested resource %s does not contain a properly set origin_resource_type field.' , extended_resource_type)
            #raise Inconsistent('The requested resource %s does not contain a properly set origin_resource_type field.' % extended_resource_type)

        if hasattr(res_container, 'origin_resource_type') and res_container.origin_resource_type != resource_object.type_\
        and not issubtype(resource_object.type_, res_container.origin_resource_type):
            log.error('The origin_resource_type of the requested resource %s(%s) does not match the type of the specified resource id(%s).' % (
                extended_resource_type, res_container.origin_resource_type, resource_object.type_))
            #raise Inconsistent('The origin_resource_type of the requested resource %s(%s) does not match the type of the specified resource id(%s).' % (extended_resource_type, res_container.origin_resource_type, resource_object.type_))

        res_container._id = resource_object._id
        res_container.resource = resource_object

        self.set_container_lcstate_info(res_container)

        self.set_container_field_values(res_container, ext_exclude)

        self.set_computed_attributes(res_container, computed_resource_type, ext_exclude)

        self.set_extended_associations(res_container, ext_associations, ext_exclude)

        res_container.ts_created = get_ion_ts()

        overall_stop_time = time.time()

        log.debug("Time to process extended resource container %s %f secs", extended_resource_type, overall_stop_time - overall_start_time )

        return res_container
开发者ID:daf,项目名称:pyon,代码行数:53,代码来源:resource.py

示例11: obtain_agent_calculation

    def obtain_agent_calculation(self, device_id, result_container):
        ret = IonObject(result_container)
        a_client = None
        try:
            a_client = self.obtain_agent_handle(device_id)
            ret.status = ComputedValueAvailability.PROVIDED
        except NotFound:
            ret.status = ComputedValueAvailability.NOTAVAILABLE
            ret.reason = "Could not connect to instrument agent instance -- may not be running"
        except Exception as e:
            raise e

        return a_client, ret
开发者ID:jamie-cyber1,项目名称:coi-services,代码行数:13,代码来源:status_builder.py

示例12: _execute

    def _execute(self, cprefix, command):
        if not command:
            raise iex.BadRequest("execute argument 'command' not present")
        if not command.command:
            raise iex.BadRequest("command not set")

        cmd_res = IonObject("AgentCommandResult", command_id=command.command_id, command=command.command)
        cmd_func = getattr(self, cprefix + str(command.command), None)
        if cmd_func:
            cmd_res.ts_execute = get_ion_ts()
            try:
                res = cmd_func(*command.args, **command.kwargs)
                cmd_res.status = 0
                cmd_res.result = res
            except iex.IonException as ex:
                # TODO: Distinguish application vs. uncaught exception
                cmd_res.status = getattr(ex, 'status_code', -1)
                cmd_res.result = str(ex)
                log.warn("Agent command %s failed with trace=%s" % (command.command, traceback.format_exc()))
        else:
            log.info("Agent command not supported: %s" % (command.command))
            ex = iex.NotFound("Command not supported: %s" % command.command)
            cmd_res.status = iex.NotFound.status_code
            cmd_res.result = str(ex)

        sub_type = "%s.%s" % (command.command, cmd_res.status)
        post_event = self._event_publisher._create_event(event_type=self.COMMAND_EVENT_TYPE,
                                origin=self.resource_id, origin_type=self.ORIGIN_TYPE,
                                sub_type=sub_type, command=command, result=cmd_res)
        post_event = self._post_execute_event_hook(post_event)
        success = self._event_publisher._publish_event(post_event, origin=post_event.origin)

        return cmd_res
开发者ID:swarbhanu,项目名称:pyon,代码行数:33,代码来源:agent.py

示例13: _start_raw_ingestion

    def _start_raw_ingestion(self):
        dpsc_cli = DataProductManagementServiceClient()
        rrclient = ResourceRegistryServiceClient()
        RR2 = EnhancedResourceRegistryClient(rrclient)

        # Generic time-series data domain creation
        tdom, sdom = time_series_domain()

        dp_obj = IonObject(RT.DataProduct,
            name='DP1',
            description='some new dp',
            temporal_domain = tdom.dump(),
            spatial_domain = sdom.dump())

        dp_obj.geospatial_bounds.geospatial_latitude_limit_north = 10.0
        dp_obj.geospatial_bounds.geospatial_latitude_limit_south = -10.0
        dp_obj.geospatial_bounds.geospatial_longitude_limit_east = 10.0
        dp_obj.geospatial_bounds.geospatial_longitude_limit_west = -10.0
        dp_obj.ooi_product_name = "PRODNAME"

        #------------------------------------------------------------------------------------------------
        # Create a set of ParameterContext objects to define the parameters in the coverage, add each to the ParameterDictionary
        #------------------------------------------------------------------------------------------------

        log.info("Create data product... raw stream id: %s", self._raw_stream_id)
        dp_id = dpsc_cli.create_data_product_(data_product= dp_obj)
        dataset_id = self.create_dataset(self._raw_stream_pdict_id)
        RR2.assign_stream_definition_to_data_product_with_has_stream_definition(self._raw_stream_def_id, dp_id)
        RR2.assign_stream_to_data_product_with_has_stream(self._raw_stream_id, dp_id)
        RR2.assign_dataset_to_data_product_with_has_dataset(dataset_id, dp_id)
        self._raw_dataset_id = dataset_id

        log.info("Create data product...Complete")

        # Assert that the data product has an associated stream at this stage
        stream_ids, _ = rrclient.find_objects(dp_id, PRED.hasStream, RT.Stream, True)
        self.assertNotEquals(len(stream_ids), 0)

        # Assert that the data product has an associated stream def at this stage
        stream_ids, _ = rrclient.find_objects(dp_id, PRED.hasStreamDefinition, RT.StreamDefinition, True)
        self.assertNotEquals(len(stream_ids), 0)

        log.info("Activate data product persistence")
        dpsc_cli.activate_data_product_persistence(dp_id)

        log.info("Read data product")
        dp_obj = dpsc_cli.read_data_product(dp_id)
        self.assertIsNotNone(dp_obj)
        self.assertEquals(dp_obj.geospatial_point_center.lat, 0.0)
        log.debug('Created data product %s', dp_obj)
开发者ID:MatthewArrott,项目名称:coi-services,代码行数:50,代码来源:test_high_volume.py

示例14: _execute

    def _execute(self, cprefix, command):
        if not command:
            raise iex.BadRequest("execute argument 'command' not present")
        if not command.command:
            raise iex.BadRequest("command not set")

        cmd_res = IonObject("AgentCommandResult", command_id=command.command_id, command=command.command)
        cmd_func = getattr(self, cprefix + str(command.command), None)
        if cmd_func:
            cmd_res.ts_execute = get_ion_ts()
            try:
                res = cmd_func(*command.args, **command.kwargs)
                cmd_res.status = 0
                cmd_res.result = res
            except Exception as ex:
                # TODO: Distinguish application vs. uncaught exception
                cmd_res.status = getattr(ex, 'status_code', -1)
                cmd_res.result = str(ex)
                log.info("Agent function failed with ex=%s msg=%s" % (type(ex), str(ex)))
        else:
            log.info("Agent command not supported: %s" % (command.command))
            ex = iex.NotFound("Command not supported: %s" % command.command)
            cmd_res.status = iex.NotFound.status_code
            cmd_res.result = str(ex)
        return cmd_res
开发者ID:tgiguere,项目名称:pyon,代码行数:25,代码来源:agent.py

示例15: test_crud_list_obj

    def test_crud_list_obj(self):
        """ crud batch operations using lists of objects where possible """
        obj1 = IonObject(RT.InstrumentDevice, name='SBE37IMDevice', description="SBE37IMDevice", serial_number="12345" )
        obj2 = IonObject(RT.Observatory, name='mount spaghetti', description='covered with snow')
        objs = [obj1,obj2]
        tuples = self.repo.insert('sample', objs)

        for t in tuples:
            self.assertTrue(t[0])
            self.assertTrue(t[1] is not None)

        ids = [ tuples[0][1], tuples[1][1], 'howdy' ]
        tuples = self.repo.read('sample', ids)
        self.assertTrue(tuples[0][0])
        self.assertTrue(tuples[1][0])
        self.assertFalse(tuples[2][0])

        obj3 = tuples[0][2]
        obj4 = tuples[1][2]
        obj3.name = 'no longer SBE'
        obj4.description = 'no more snow'
        obj1._id = 'abc123'
        objs = [ obj3, obj4, obj1 ]
        tuples = self.repo.update('sample', objs)
        self.assertTrue(tuples[0][0])
        self.assertTrue(tuples[1][0])
        self.assertFalse(tuples[2][0])

        tuples = self.repo.read('sample', objs)
        self.assertTrue(tuples[0][0])
        self.assertTrue(tuples[1][0])
        self.assertFalse(tuples[2][0])
        obj5 = tuples[0][2]
        obj6 = tuples[1][2]
        for key in ['_id', 'name', 'description', 'serial_number']:
            self.assertEqual(obj3.__dict__[key],obj5.__dict__[key], msg='objects do not have the same '+key)

        objs = [ obj4, obj5 ]  # 4 has obsolete _rev
        tuples = self.repo.delete('sample', objs)
        self.assertFalse(tuples[0][0])
        self.assertTrue(tuples[1][0], msg='failed: '+str(tuples[1][2]) +'\nobj: ' + repr(obj5.__dict__))

        objs = [ obj5, obj6 ]  # 5 is already deleted
        tuples = self.repo.delete('sample', objs)
        self.assertFalse(tuples[0][0])
        self.assertTrue(tuples[1][0], msg='failed: '+str(tuples[1][2]) +'\nobj: ' + repr(obj5.__dict__))
开发者ID:daf,项目名称:pyon,代码行数:46,代码来源:test_repository_crud.py


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