Example #1
0
 def test_form_dpe_name(self):
     test_case = ClaraUtils.form_dpe_name("192.168.0.1", ClaraLang.JAVA)
     self.assertTrue(ClaraUtils.is_dpe_name(test_case))
     self.assertEqual(test_case, "192.168.0.1_java")
     test_case = ClaraUtils.form_dpe_name("192.168.0.1", ClaraLang.JAVA, 8181)
     self.assertTrue(ClaraUtils.is_dpe_name(test_case))
     self.assertEqual(test_case, "192.168.0.1%8181_java")
Example #2
0
    def send(self, msg):
        """Sends xMsgMessage object to a Clara component

        Args:
            msg (xMsgMessage): xMsg transient message object
        """
        proxy_address = ProxyAddress(ClaraUtils.get_dpe_host(msg.topic),
                                     ClaraUtils.get_dpe_port(msg.topic))
        conn = self.get_connection(proxy_address)
        self.publish(conn, msg)
Example #3
0
    def sync_send(self, msg, timeout):
        """Sends xMsgMessage object to an xMsg actor synchronously

        Args:
            msg (xMsgMessage): xMsg transient message object
            timeout (int): response message timeout in seconds
        """
        proxy_address = ProxyAddress(ClaraUtils.get_dpe_host(msg.topic),
                                     ClaraUtils.get_dpe_port(msg.topic))
        conn = self.get_connection(proxy_address)
        self.sync_publish(conn, msg, timeout)
    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))
Example #5
0
    def test_compose_canonical_name(self):
        test1 = "192.168.0.1_java:some_container:some_engine"
        test_case = ClaraUtils.decompose_canonical_name(test1)
        expected1 = ["192.168.0.1", xMsgConstants.DEFAULT_PORT,
                     "java", "some_container", "some_engine"]
        self.assertEqual(test_case, expected1)

        test2 = "192.168.0.1%2222_java:some_container:some_engine"
        test_case = ClaraUtils.decompose_canonical_name(test2)
        expected2 = ["192.168.0.1", 2222,
                     "java", "some_container", "some_engine"]
        self.assertEqual(test_case, expected2)
    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))
Example #7
0
 def get_data(self):
     return ClaraUtils.build_data(CConstants.START_SERVICE,
                                  self.__service_name,
                                  self.__service.name(),
                                  self.__class_path,
                                  self.__poolsize,
                                  self.description,
                                  self.__initial_state)
    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))
    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))
Example #10
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)
    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))
    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)
Example #13
0
    def listen(self, topic, callback):
        """This method simply calls xMsg subscribe method passing the reference
        to user provided callback method.

        Args:
            topic (xMsgTopic): Topic of subscription
            callback (xMsgCallBack): User provided callback object
        Returns:
            xMsgSubscription
        """
        proxy_address = ProxyAddress(ClaraUtils.get_dpe_host(topic))
        handler = self.subscribe(proxy_address, topic, callback)
        return handler
    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)
Example #15
0
    def stop_service(self, request):
        """Stops a running Clara service

        Args:
            request (RequestParser): Request received from Orchestrator to
                stop a Service
        """
        container_name = request.next_string()
        engine_name = request.next_string()
        service_name = ClaraUtils.form_service_name(container_name,
                                                    engine_name)
        if container_name in self.my_containers:
            try:
                self.my_containers[container_name].remove_service(service_name)

            except Exception as e:
                raise Exception("Could not stop service %s: %s " %
                                (service_name, e))

        else:
            raise Exception("Could not stop service %s: missing container " %
                            service_name)
    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))
Example #17
0
 def test_get_mem_usage(self):
     test_case = ClaraUtils.get_mem_usage()
     self.assertIsInstance(test_case, float)
     self.assertGreater(test_case, 0.0)
Example #18
0
 def test_form_service_name(self):
     test_case = ClaraUtils.form_service_name("192.168.0.1_java:some_container",
                                              "some_engine")
     self.assertTrue(ClaraUtils.is_service_name(test_case))
     self.assertEqual(test_case,
                      "192.168.0.1_java:some_container:some_engine")
Example #19
0
def __get_dpe_topic(component_name):
    return str(ClaraUtils.get_dpe_name(component_name))
Example #20
0
 def get_data(self):
     return ClaraUtils.build_data(CConstants.START_CONTAINER,
                                  self.__container.name(),
                                  self.__poolsize,
                                  self.description)
 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)
 def _get_clara_base(self, fe_host):
     return ClaraBase(self.name,
                      ClaraUtils.localhost(),
                      xMsgConstants.DEFAULT_PORT,
                      xMsgUtil.host_to_ip(fe_host),
                      xMsgConstants.REGISTRAR_PORT)
Example #23
0
 def get_output_data_types(self):
     return ClaraUtils.build_data_types(EngineDataType.STRING())
 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