Пример #1
0
    def start_agent(self, agent_instance_id, resource_id):
        if not agent_instance_id or not resource_id:
            log.warn("Could not %s agent %s for device %s", self.op, agent_instance_id, resource_id)
            return

        res_obj = self.rr.read(resource_id)

        log.info('Starting agent...')
        if res_obj.type_ == RT.ExternalDatasetAgentInstance or res_obj == RT.ExternalDataset:
            dams = DataAcquisitionManagementServiceProcessClient(process=self)
            dams.start_external_dataset_agent_instance(agent_instance_id)
        elif res_obj.type_ == RT.InstrumentDevice:
            ims = InstrumentManagementServiceClient()
            ims.start_instrument_agent_instance(agent_instance_id)
        elif res_obj.type_ == RT.PlatformDevice:
            ims = InstrumentManagementServiceClient()
            ims.start_platform_agent_instance(agent_instance_id)
        else:
            BadRequest("Attempt to start unsupported agent type: %s", res_obj.type_)
        log.info('Agent started!')

        activate = self.CFG.get("activate", True)
        if activate:
            log.info('Activating agent...')
            client = ResourceAgentClient(resource_id, process=self)
            client.execute_agent(AgentCommand(command=ResourceAgentEvent.INITIALIZE))
            client.execute_agent(AgentCommand(command=ResourceAgentEvent.GO_ACTIVE))
            client.execute_agent(AgentCommand(command=ResourceAgentEvent.RUN))
            client.execute_resource(command=AgentCommand(command=DriverEvent.START_AUTOSAMPLE))

            log.info('Agent active!')
Пример #2
0
    def start_agent(self, agent_instance_id, resource_id):
        if not agent_instance_id or not resource_id:
            log.warn("Could not op=%s agent %s for device %s", self.op, agent_instance_id, resource_id)
            return

        res_obj = self.rr.read(resource_id)
        ai_obj = self.rr.read(agent_instance_id)

        try:
            client = ResourceAgentClient(resource_id, process=self)
            if self.force:
                log.warn("Agent for resource %s seems running - continuing", resource_id)
                if self.autoclean:
                    self.cleanup_agent(agent_instance_id, resource_id)
            else:
                log.warn("Agent for resource %s seems running", resource_id)
                return
        except NotFound:
            pass  # This is expected

        log.info('Starting agent...')
        if ai_obj.type_ == RT.ExternalDatasetAgentInstance:
            dams = DataAcquisitionManagementServiceProcessClient(process=self)
            dams.start_external_dataset_agent_instance(agent_instance_id, headers=self._get_system_actor_headers(),
                                                       timeout=self.timeout)
        elif ai_obj.type_ == RT.InstrumentAgentInstance:
            ims = InstrumentManagementServiceProcessClient(process=self)
            ims.start_instrument_agent_instance(agent_instance_id, headers=self._get_system_actor_headers(),
                                                timeout=self.timeout)
        elif ai_obj.type_ == RT.PlatformAgentInstance:
            ims = InstrumentManagementServiceProcessClient(process=self)
            ims.start_platform_agent_instance(agent_instance_id, headers=self._get_system_actor_headers(),
                                              timeout=self.timeout)
        else:
            BadRequest("Attempt to start unsupported agent type: %s", ai_obj.type_)
        log.info('Agent started!')

        activate = self.CFG.get("activate", True)
        if activate:
            log.info('Activating agent...')
            client = ResourceAgentClient(resource_id, process=self)
            client.execute_agent(AgentCommand(command=ResourceAgentEvent.INITIALIZE),
                                 headers=self._get_system_actor_headers(), timeout=self.timeout)
            client.execute_agent(AgentCommand(command=ResourceAgentEvent.GO_ACTIVE),
                                 headers=self._get_system_actor_headers(), timeout=self.timeout)
            client.execute_agent(AgentCommand(command=ResourceAgentEvent.RUN),
                                 headers=self._get_system_actor_headers(), timeout=self.timeout)
            client.execute_resource(command=AgentCommand(command=DriverEvent.START_AUTOSAMPLE),
                                    headers=self._get_system_actor_headers(), timeout=self.timeout)

            log.info('Agent in auto-sample mode!')
Пример #3
0
    def _stop_agent(self, eda_instance_id, resource_id):
        try:
            client = ResourceAgentClient(resource_id, process=self)
        except NotFound:
            log.warn("Agent for resource %s seems not running", resource_id)

        log.info('Stopping agent...')
        dams = DataAcquisitionManagementServiceProcessClient(process=self)
        try:
            dams.stop_external_dataset_agent_instance(eda_instance_id)
        except NotFound:
            log.warn("Agent for resource %s not found", resource_id)

        log.info('Agent stopped!')
    def setUp(self):
        # Start container

        logging.disable(logging.ERROR)
        self._start_container()
        self.container.start_rel_from_url('res/deploy/r2deploy.yml')
        # simulate preloading
        preload_ion_params(self.container)
        logging.disable(logging.NOTSET)

        #Instantiate a process to represent the test
        process=VisualizationServiceTestProcess()

        # Now create client to DataProductManagementService
        self.rrclient = ResourceRegistryServiceProcessClient(node=self.container.node, process=process)
        self.damsclient = DataAcquisitionManagementServiceProcessClient(node=self.container.node, process=process)
        self.pubsubclient =  PubsubManagementServiceProcessClient(node=self.container.node, process=process)
        self.ingestclient = IngestionManagementServiceProcessClient(node=self.container.node, process=process)
        self.imsclient = InstrumentManagementServiceProcessClient(node=self.container.node, process=process)
        self.dataproductclient = DataProductManagementServiceProcessClient(node=self.container.node, process=process)
        self.dataprocessclient = DataProcessManagementServiceProcessClient(node=self.container.node, process=process)
        self.datasetclient =  DatasetManagementServiceProcessClient(node=self.container.node, process=process)
        self.workflowclient = WorkflowManagementServiceProcessClient(node=self.container.node, process=process)
        self.process_dispatcher = ProcessDispatcherServiceProcessClient(node=self.container.node, process=process)
        self.data_retriever = DataRetrieverServiceProcessClient(node=self.container.node, process=process)
        self.vis_client = VisualizationServiceProcessClient(node=self.container.node, process=process)

        self.ctd_stream_def = SBE37_CDM_stream_definition()
Пример #5
0
    def _start_agent(self, eda_instance_id, resource_id):
        log.info('Starting agent...')
        dams = DataAcquisitionManagementServiceProcessClient(process=self)
        dams.start_external_dataset_agent_instance(eda_instance_id)
        log.info('Agent started!')

        activate = self.CFG.get("activate", True)
        if activate:
            log.info('Activating agent...')
            client = ResourceAgentClient(resource_id, process=self)
            client.execute_agent(AgentCommand(command=ResourceAgentEvent.INITIALIZE))
            client.execute_agent(AgentCommand(command=ResourceAgentEvent.GO_ACTIVE))
            client.execute_agent(AgentCommand(command=ResourceAgentEvent.RUN))
            client.execute_resource(command=AgentCommand(command=DriverEvent.START_AUTOSAMPLE))

            log.info('Agent active!')
Пример #6
0
    def _stop_agent(self, agent_instance_id, resource_id):
        if not agent_instance_id or not resource_id:
            log.warn("Could not %s agent %s for device %s", self.op, agent_instance_id, resource_id)
            return

        try:
            client = ResourceAgentClient(resource_id, process=self)
        except NotFound:
            log.warn("Agent for resource %s seems not running", resource_id)

        log.info('Stopping agent...')
        dams = DataAcquisitionManagementServiceProcessClient(process=self)
        try:
            dams.stop_external_dataset_agent_instance(agent_instance_id)
        except NotFound:
            log.warn("Agent for resource %s not found", resource_id)

        log.info('Agent stopped!')
Пример #7
0
    def stop_agent(self, agent_instance_id, resource_id):
        res_obj = self.rr.read(resource_id)

        if not agent_instance_id or not resource_id:
            log.warn("Could not %s agent %s for device %s", self.op, agent_instance_id, resource_id)
            return

        try:
            client = ResourceAgentClient(resource_id, process=self)
        except NotFound:
            log.warn("Agent for resource %s seems not running", resource_id)

        log.info('Stopping agent...')

        if res_obj.type_ == RT.ExternalDatasetAgentInstance or res_obj == RT.ExternalDataset:
            dams = DataAcquisitionManagementServiceProcessClient(process=self)
            try:
                dams.stop_external_dataset_agent_instance(agent_instance_id,
                                                          headers=self._get_system_actor_headers(), timeout=self.timeout)
            except NotFound:
                log.warn("Agent for resource %s not found", resource_id)
        elif res_obj.type_ == RT.InstrumentDevice:
            ims = InstrumentManagementServiceProcessClient(process=self)
            try:
                ims.stop_instrument_agent_instance(agent_instance_id,
                                                   headers=self._get_system_actor_headers(), timeout=self.timeout)
            except NotFound:
                log.warn("Agent for resource %s not found", resource_id)
        elif res_obj.type_ == RT.PlatformDevice:
            ims = InstrumentManagementServiceProcessClient(process=self)
            try:
                ims.stop_platform_agent_instance(agent_instance_id,
                                                 headers=self._get_system_actor_headers(), timeout=self.timeout)
            except NotFound:
                log.warn("Agent for resource %s not found", resource_id)
        else:
            BadRequest("Attempt to start unsupported agent type: %s", res_obj.type_)

        log.info('Agent stopped!')
Пример #8
0
    def stop_agent(self, agent_instance_id, resource_id):
        if not agent_instance_id or not resource_id:
            return

        res_obj = self.rr.read(resource_id)
        ai_obj = self.rr.read(agent_instance_id)

        try:
            client = ResourceAgentClient(resource_id, process=self)
        except NotFound:
            if self.force:
                log.warn("Agent for resource %s seems not running - continuing", resource_id)
            else:
                log.info("Agent for resource %s seems not running", resource_id)
                return

        log.info('Stopping agent...')

        if ai_obj.type_ == RT.ExternalDatasetAgentInstance:
            dams = DataAcquisitionManagementServiceProcessClient(process=self)
            try:
                dams.stop_external_dataset_agent_instance(agent_instance_id,
                                                          headers=self._get_system_actor_headers(), timeout=self.timeout)
                log.info('Agent stopped!')
            except NotFound:
                log.warn("Agent for resource %s not found", resource_id)
                if self.autoclean:
                    self.cleanup_agent(agent_instance_id, resource_id)
            except Exception:
                if self.autoclean:
                    self.cleanup_agent(agent_instance_id, resource_id)
                raise
        elif ai_obj.type_ == RT.InstrumentAgentInstance:
            ims = InstrumentManagementServiceProcessClient(process=self)
            try:
                ims.stop_instrument_agent_instance(agent_instance_id,
                                                   headers=self._get_system_actor_headers(), timeout=self.timeout)
                log.info('Agent stopped!')
            except NotFound:
                log.warn("Agent for resource %s not found", resource_id)
                if self.autoclean:
                    self.cleanup_agent(agent_instance_id, resource_id)
            except Exception:
                if self.autoclean:
                    self.cleanup_agent(agent_instance_id, resource_id)
                raise
        elif ai_obj.type_ == RT.PlatformAgentInstance:
            ims = InstrumentManagementServiceProcessClient(process=self)
            try:
                ims.stop_platform_agent_instance(agent_instance_id,
                                                 headers=self._get_system_actor_headers(), timeout=self.timeout)
                log.info('Agent stopped!')
            except NotFound:
                log.warn("Agent for resource %s not found", resource_id)
                if self.autoclean:
                    self.cleanup_agent(agent_instance_id, resource_id)
            except Exception:
                if self.autoclean:
                    self.cleanup_agent(agent_instance_id, resource_id)
                raise
        else:
            BadRequest("Attempt to stop unsupported agent type: %s", ai_obj.type_)
 def on_init(self):
     self.ims_client = InstrumentManagementServiceProcessClient(process=self)
     self.dams_client = DataAcquisitionManagementServiceProcessClient(process=self)
class AgentManagementService(BaseAgentManagementService):
    """The Agent Management Service is the service that manages Agent Definitions, Agent Instance
    configurations and running Agents in the system.

    @see https://confluence.oceanobservatories.org/display/syseng/CIAD+COI+OV+Agent+Management+Service
    """
    def on_init(self):
        self.ims_client = InstrumentManagementServiceProcessClient(process=self)
        self.dams_client = DataAcquisitionManagementServiceProcessClient(process=self)

    def create_agent_definition(self, agent_definition=None):
        """Creates an Agent Definition resource from the parameter AgentDefinition object.

        @param agent_definition    AgentDefinition
        @retval agent_definition_id    str
        @throws BadRequest    if object passed has _id or _rev attribute
        """
        atype, ainst, svc_client = self._get_agent_type(agent_definition)
        if atype == AT_INSTUMENT_AGENT:
            res = self.ims_client.create_instrument_agent(agent_definition)
        elif atype == AT_PLATFORM_AGENT:
            res = self.ims_client.create_platform_agent(agent_definition)
        elif atype == AT_EXTDATASET_AGENT:
            res = self.dams_client.create_external_dataset_agent(agent_definition)
        else:
            raise BadRequest("Unknown agent type: %s" % atype)
        return res

    def update_agent_definition(self, agent_definition=None):
        """Updates an existing Agent Definition resource.

        @param agent_definition    AgentDefinition
        @throws BadRequest    if object does not have _id or _rev attribute
        @throws NotFound    object with specified id does not exist
        @throws Conflict    object not based on latest persisted object version
        """
        atype, ainst, svc_client = self._get_agent_type(agent_definition)
        if atype == AT_INSTUMENT_AGENT:
            res = self.ims_client.update_instrument_agent(agent_definition)
        elif atype == AT_PLATFORM_AGENT:
            res = self.ims_client.update_platform_agent(agent_definition)
        elif atype == AT_EXTDATASET_AGENT:
            res = self.dams_client.update_external_dataset_agent(agent_definition)
        else:
            raise BadRequest("Unknown agent type: %s" % atype)
        return res


    def read_agent_definition(self, agent_definition_id=''):
        """Returns an existing Agent Definition resource.

        @param agent_definition_id    str
        @retval agent_definition    AgentDefinition
        @throws NotFound    object with specified id does not exist
        """
        atype, ainst, svc_client = self._get_agent_type(agent_definition_id)
        if atype == AT_INSTUMENT_AGENT:
            res = self.ims_client.read_instrument_agent(agent_definition_id)
        elif atype == AT_PLATFORM_AGENT:
            res = self.ims_client.read_platform_agent(agent_definition_id)
        elif atype == AT_EXTDATASET_AGENT:
            res = self.dams_client.read_external_dataset_agent(agent_definition_id)
        else:
            raise BadRequest("Unknown agent type: %s" % atype)
        return res

    def delete_agent_definition(self, agent_definition_id=''):
        """Deletes an existing Agent Definition resource.

        @param agent_definition_id    str
        @throws NotFound    object with specified id does not exist
        """
        atype, ainst, svc_client = self._get_agent_type(agent_definition_id)
        if atype == AT_INSTUMENT_AGENT:
            res = self.ims_client.delete_instrument_agent(agent_definition_id)
        elif atype == AT_PLATFORM_AGENT:
            res = self.ims_client.delete_platform_agent(agent_definition_id)
        elif atype == AT_EXTDATASET_AGENT:
            res = self.dams_client.delete_external_dataset_agent(agent_definition_id)
        else:
            raise BadRequest("Unknown agent type: %s" % atype)
        return res


    def create_agent_instance(self, agent_instance=None):
        """Creates an Agent Instance resource from the parameter AgentInstance object.

        @param agent_instance    AgentInstance
        @retval agent_instance_id    str
        @throws BadRequest    if object passed has _id or _rev attribute
        """
        atype, ainst, svc_client = self._get_agent_type(agent_instance)
        if atype == AT_INSTUMENT_AGENT:
            res = self.ims_client.create_instrument_agent_instance_(agent_instance)
        elif atype == AT_PLATFORM_AGENT:
            res = self.ims_client.create_platform_agent_instance(agent_instance)
        elif atype == AT_EXTDATASET_AGENT:
            res = self.dams_client.create_external_dataset_agent_instance(agent_instance)
        else:
            raise BadRequest("Unknown agent type: %s" % atype)
        return res

    def update_agent_instance(self, agent_instance=None):
        """Updates an existing Agent Instance resource.

        @param agent_instance    AgentInstance
        @throws BadRequest    if object does not have _id or _rev attribute
        @throws NotFound    object with specified id does not exist
        @throws Conflict    object not based on latest persisted object version
        """
        atype, ainst, svc_client = self._get_agent_type(agent_instance)
        if atype == AT_INSTUMENT_AGENT:
            res = self.ims_client.update_instrument_agent_instance(agent_instance)
        elif atype == AT_PLATFORM_AGENT:
            res = self.ims_client.update_platform_agent_instance(agent_instance)
        elif atype == AT_EXTDATASET_AGENT:
            res = self.dams_client.update_data_source_agent_instance(agent_instance)
        else:
            raise BadRequest("Unknown agent type: %s" % atype)
        return res

    def read_agent_instance(self, agent_instance_id=''):
        """Returns an existing Agent Instance resource.

        @param agent_instance_id    str
        @retval agent_instance    AgentInstance
        @throws NotFound    object with specified id does not exist
        """
        atype, ainst, svc_client = self._get_agent_type(agent_instance_id)
        if atype == AT_INSTUMENT_AGENT:
            res = self.ims_client.read_instrument_agent_instance(agent_instance_id)
        elif atype == AT_PLATFORM_AGENT:
            res = self.ims_client.read_platform_agent_instance(agent_instance_id)
        elif atype == AT_EXTDATASET_AGENT:
            res = self.dams_client.read_external_dataset_agent_instance(agent_instance_id)
        else:
            raise BadRequest("Unknown agent type: %s" % atype)
        return res

    def delete_agent_instance(self, agent_instance_id=''):
        """Deletes an existing Agent Instance resource.

        @param agent_instance_id    str
        @throws NotFound    object with specified id does not exist
        """
        atype, ainst, svc_client = self._get_agent_type(agent_instance_id)
        if atype == AT_INSTUMENT_AGENT:
            res = self.ims_client.delete_instrument_agent_instance(agent_instance_id)
        elif atype == AT_PLATFORM_AGENT:
            res = self.ims_client.delete_platform_agent_instance(agent_instance_id)
        elif atype == AT_EXTDATASET_AGENT:
            res = self.dams_client.delete_external_dataset_agent_instance(agent_instance_id)
        else:
            raise BadRequest("Unknown agent type: %s" % atype)
        return res

    def start_agent_instance(self, agent_instance_id=''):
        """Start the given Agent Instance. Delegates to the type specific service.

        @param agent_instance_id    str
        @retval process_id    str
        @throws NotFound    object with specified id does not exist
        """
        atype, ainst, svc_client = self._get_agent_type(agent_instance_id)
        if atype == AT_INSTUMENT_AGENT:
            res = self.ims_client.start_instrument_agent_instance(agent_instance_id)
        elif atype == AT_PLATFORM_AGENT:
            res = self.ims_client.start_platform_agent_instance(agent_instance_id)
        elif atype == AT_EXTDATASET_AGENT:
            res = self.dams_client.start_external_dataset_agent_instance(agent_instance_id)
        else:
            raise BadRequest("Unknown agent type: %s" % atype)
        return res

    def stop_agent_instance(self, agent_instance_id=''):
        """Stop the given Agent Instance. Delegates to the type specific service.

        @param agent_instance_id    str
        @throws NotFound    object with specified id does not exist
        """
        atype, ainst, svc_client = self._get_agent_type(agent_instance_id)
        if atype == AT_INSTUMENT_AGENT:
            res = self.ims_client.stop_instrument_agent_instance(agent_instance_id)
        elif atype == AT_PLATFORM_AGENT:
            res = self.ims_client.stop_platform_agent_instance(agent_instance_id)
        elif atype == AT_EXTDATASET_AGENT:
            res = self.dams_client.stop_external_dataset_agent_instance(agent_instance_id)
        else:
            raise BadRequest("Unknown agent type: %s" % atype)
        return res

    def _get_agent_type(self, agent=''):
        if isinstance(agent, str):
            res_obj = self.clients.resource_registry.read(agent)
        elif isinstance(agent, AgentInstance) or isinstance(agent, AgentDefinition):
            res_obj = agent
        else:
            raise BadRequest("Resource must be AgentInstance or AgentDefinition, is: %s" % agent.type_)

        atype = None
        svc_client = None
        is_instance = res_obj.type_.endswith("Instance")
        if isinstance(res_obj, InstrumentAgentInstance) or isinstance(res_obj, InstrumentAgent):
            atype = AT_INSTUMENT_AGENT
            svc_client = self.ims_client
        elif isinstance(res_obj, PlatformAgentInstance) or isinstance(res_obj, PlatformAgent):
            atype = AT_PLATFORM_AGENT
            svc_client = self.ims_client
        elif isinstance(res_obj, ExternalDatasetAgentInstance) or isinstance(res_obj, ExternalDatasetAgent):
            atype = AT_EXTDATASET_AGENT
            svc_client = self.dams_client
        else:
            raise BadRequest("Resource must is unknown AgentInstance: %s" % res_obj.type_)
        return atype, res_obj, svc_client