Ejemplo n.º 1
0
    def deploy_service(self, service_name, class_path, pool_size=1,
                       description=CConstants.UNDEFINED,
                       initial_state=CConstants.UNDEFINED):
        """Sends request to DPE to deploy given service

        Args:
            service_name (String): service name in canonical form
            class_path (String): class path to given service
            pool_size (int): available pool size for service execution
            description (String): short description of what the service does
            initial_state (String): initial state for service
        """
        if not ClaraUtils.is_service_name(service_name):
            raise ValueError("Bad Service name")

        dpe = ClaraUtils.get_dpe_name(service_name)
        container_name = ClaraUtils.get_container_canonical_name(service_name)
        engine_name = ClaraUtils.get_engine_name(service_name)

        topic = ClaraUtils.build_topic(CConstants.DPE, dpe)
        data = ClaraUtils.build_data(CConstants.START_SERVICE,
                                     container_name,
                                     engine_name,
                                     class_path,
                                     pool_size,
                                     description,
                                     initial_state)

        self.base.send(self._create_request(topic, data))
Ejemplo n.º 2
0
    def execute_service(self, service_name, user_data):
        """Sends request to Service to execute with given data

        Args:
            service_name (String): service name in canonical form
            user_data (EngineData): engine data parameter for service exec
        """
        topic = ClaraUtils.build_topic(CConstants.SERVICE, service_name)
        user_data.metadata.action = xMsgMeta.EXECUTE
        self.base.send(self.base.serialize(topic, user_data, self.datatypes))
Ejemplo n.º 3
0
    def exit_dpe(self, dpe_name):
        """Sends message to DPE and requesting to stop

        Args:
            dpe_name (String): name of the dpe to stop
        """
        if not ClaraUtils.is_dpe_name(dpe_name):
            raise MalformedCanonicalName("Malformed DPE name: %s" % dpe_name)

        topic = ClaraUtils.build_topic(CConstants.DPE, dpe_name)
        self.base.send(xMsgMessage(topic, CConstants.DPE_EXIT))
Ejemplo n.º 4
0
    def _start(self):
        proxy_process = subprocess.Popen(['px_proxy'])

        try:
            topic = ClaraUtils.build_topic(CConstants.DPE, self.myname)
            self.subscription_handler = self.listen(topic, _DpeCallBack(self))
            xMsgUtil.keep_alive()

        except KeyboardInterrupt:
            self._exit()
            self.stop_listening(self.subscription_handler)
            os.kill(proxy_process.pid, signal.SIGINT)
Ejemplo n.º 5
0
    def configure_service(self, service_name, config_data):
        """Sends configuration request to specified clara service

        Args:
            service_name (String): service name in canonical form
            config_data (EngineData): configuration data
        """
        topic = ClaraUtils.build_topic(CConstants.SERVICE, service_name)

        config_data.metadata.action = xMsgMeta.CONFIGURE

        msg = self.base.serialize(topic, config_data, self.datatypes)
        self.base.send(msg)
Ejemplo n.º 6
0
    def exit_container(self, container_name):
        """Sends message to Container and requesting to stop

        Args:
            container_name (String): name of the container to stop
        """
        if not ClaraUtils.is_container_name(container_name):
            raise ValueError("Bad Container name")

        dpe = ClaraUtils.get_dpe_name(container_name)
        name = ClaraUtils.get_container_name(container_name)

        topic = ClaraUtils.build_topic(CConstants.DPE, dpe)
        data = ClaraUtils.build_data(CConstants.STOP_CONTAINER, name)

        self.base.send(self._create_request(topic, data))
Ejemplo n.º 7
0
    def execute_composition(self, composition, input_data):
        """Sends request to Service to execute with given data

        Args:
            composition (String): service composition for execution
            input_data (EngineData): input data parameter for service execution
        """
        topic = ClaraUtils.build_topic(CConstants.SERVICE,
                                       composition.first_service())
        meta = xMsgMeta()
        meta.MergeFrom(input_data.metadata)
        meta.action = xMsgMeta.EXECUTE
        meta.composition = str(composition)
        input_data.metadata = meta

        message = self.base.serialize(topic, input_data, self.datatypes)
        self.base.send(message)
Ejemplo n.º 8
0
    def remove_service(self, service_name):
        """Sends request to DPE to remove given service

        Args:
            service_name (String): service name in canonical form
        """
        if not ClaraUtils.is_service_name(service_name):
            raise ValueError("Bad Service name")
        dpe_name = ClaraUtils.get_dpe_name(service_name)
        container_name = ClaraUtils.get_container_name(service_name)
        engine_name = ClaraUtils.get_engine_name(service_name)

        topic = ClaraUtils.build_topic(CConstants.DPE, dpe_name)
        data = ClaraUtils.build_data(CConstants.STOP_SERVICE,
                                     container_name,
                                     engine_name)

        self.base.send(self._create_request(topic, data))
Ejemplo n.º 9
0
    def deploy_container(self, container_name, pool_size=2,
                         description="Undefined"):
        """ Sends request to DPE to deploy given container

        Args:
            container_name (String): container name in canonical form
            pool_size (int): pool size for the given container
            description (String): short description for the container
        """
        if not ClaraUtils.is_container_name(container_name):
            raise ValueError("Bad Container name")

        dpe = ClaraUtils.get_dpe_name(container_name)
        name = ClaraUtils.get_container_name(container_name)

        topic = ClaraUtils.build_topic(CConstants.DPE, dpe)
        data = ClaraUtils.build_data(CConstants.START_CONTAINER,
                                     name, pool_size, description)

        self.base.send(self._create_request(topic, data))
Ejemplo n.º 10
0
 def configure_service_done_reporting_start(self, service_name,
                                            event_count):
     topic = ClaraUtils.build_topic(CConstants.SERVICE, service_name)
     data = ClaraUtils.build_data(ReportType.DONE, str(event_count))
     msg = self._create_request(topic, data)
     self.base.send(msg)
Ejemplo n.º 11
0
 def _put_engine_data(self, data, receiver):
     topic = ClaraUtils.build_topic(CConstants.SERVICE, receiver)
     msg = self.serialize(topic, data,
                          self._engine_object.get_output_data_types())
     self._report.increment_bytes_sent(sys.getsizeof(msg))
     return msg