def test_init(self):
        host_ip = self.VALID_IP
        port = self.MAX_ALLOWED_PORT
        endpoint = ServiceEndpoint(host_ip, port)
        assert endpoint.host_ip == host_ip
        assert endpoint.port == port

        port = self.MIN_ALLOWED_PORT
        endpoint = ServiceEndpoint(host_ip, port)
        assert endpoint.host_ip == host_ip
        assert endpoint.port == port
Example #2
0
    def run(self):
        self.init_env()
        self.init_arguments()
        config = self.parse_config()

        rabbit_mq_endpoint = ServiceEndpoint.from_string(self.RABBIT_MQ_ENDPOINT)
        self._connection = pika.BlockingConnection(
            pika.ConnectionParameters(host=rabbit_mq_endpoint.host_ip, port=rabbit_mq_endpoint.port)
        )
        self._channel = self._connection.channel()

        self.delete_queue()
        self.create_rabbit_mq_queues(self._rabbitmq_endpoint_argument)

        self._scaling_action_sender = RabbitMQScalingActionSender(
            rabbit_mq_endpoint,
            self.RABBITMQ_SCALING_REQUEST_QUEUE_NAME
        )

        content = self.create_content()
        self.send_content(content)
        time.sleep(2)
        self.check_if_content_in_queue(content)

        self._scaling_action_sender.close()
    def run(self):
        self.init_env()
        self.init_arguments()
        config = self.parse_config()

        rabbit_mq_endpoint = ServiceEndpoint.from_string(self.RABBIT_MQ_ENDPOINT)
        self._connection = pika.BlockingConnection(
            pika.ConnectionParameters(host=rabbit_mq_endpoint.host_ip, port=rabbit_mq_endpoint.port)
        )
        self._channel = self._connection.channel()

        self.delete_queue()
        self.create_rabbit_mq_queues(self._rabbitmq_endpoint_argument)

        self._task_receiver = RabbitMQExecutedTaskReceiver(
            rabbit_mq_endpoint,
            self.RABBITMQ_SCALING_RESPONSE_QUEUE_NAME
        )

        self.receive_empty()
        self.write_content_to_queue()
        time.sleep(2)
        self.receive_content()

        self._task_receiver.close()
Example #4
0
    def create_communication_queues(self):
        communication_type = CommunicationType.InterProcessQueue
        service_endpoint = None
        if self._command_line_arguments.rabbitmq_endpoint is not None:
            communication_type = CommunicationType.RabbitMQ
            service_endpoint = ServiceEndpoint.from_string(self._command_line_arguments.rabbitmq_endpoint)

        self._message_sender_receiver_factory = ScalingMessageSenderReceiverFactory(communication_type)
        self._message_sender_receiver_factory.initialize_connection(service_endpoint=service_endpoint)
        self._scaling_engine_metrics_communication_queue = Queue()
Example #5
0
    def create_communication_queues(self):
        communication_type = CommunicationType.InterProcessQueue
        service_endpoint = None
        if self._command_line_arguments.rabbitmq_endpoint is not None:
            communication_type = CommunicationType.RabbitMQ
            service_endpoint = ServiceEndpoint.from_string(
                self._command_line_arguments.rabbitmq_endpoint)

        self._message_sender_receiver_factory = ScalingMessageSenderReceiverFactory(
            communication_type)
        self._message_sender_receiver_factory.initialize_connection(
            service_endpoint=service_endpoint)
        self._scaling_engine_metrics_communication_queue = Queue()
    def from_json(cls, json_string):
        parsed_json = json.loads(json_string)

        configuration = MetricsGeneratorConfiguration()
        configuration.metrics_path = ConfigurationHelper.dict_value_or_default(parsed_json, "metrics_base_path", cls.DEFAULT_METRICS_PATH)
        configuration.services_path = ConfigurationHelper.dict_value_or_default(parsed_json, "services_base_path", cls.DEFAULT_SERVICES_PATH)
        configuration.write_interval = ConfigurationHelper.dict_value_or_default(parsed_json, "write_interval", cls.DEFAULT_WRITE_INTERVAL)
        etcd_endpoint_string = ConfigurationHelper.dict_value_or_default(parsed_json, "etcd_endpoint", cls.DEFAULT_ETCD_ENDPOINT)
        configuration.etcd_endpoint = ServiceEndpoint.from_string(etcd_endpoint_string)

        resource_dictionaries = ConfigurationHelper.dict_value_or_default(parsed_json, "resources", [])
        configuration.resources = []
        for resource_dictionary in resource_dictionaries:
            resource = ConfigurationResource.from_dictionary(configuration.write_interval, resource_dictionary)
            configuration.resources.append(resource)
        return configuration
    def from_json(cls, json_string):
        parsed_json = json.loads(json_string)

        configuration = MetricsGeneratorConfiguration()
        configuration.metrics_path = ConfigurationHelper.dict_value_or_default(
            parsed_json, "metrics_base_path", cls.DEFAULT_METRICS_PATH)
        configuration.services_path = ConfigurationHelper.dict_value_or_default(
            parsed_json, "services_base_path", cls.DEFAULT_SERVICES_PATH)
        configuration.write_interval = ConfigurationHelper.dict_value_or_default(
            parsed_json, "write_interval", cls.DEFAULT_WRITE_INTERVAL)
        etcd_endpoint_string = ConfigurationHelper.dict_value_or_default(
            parsed_json, "etcd_endpoint", cls.DEFAULT_ETCD_ENDPOINT)
        configuration.etcd_endpoint = ServiceEndpoint.from_string(
            etcd_endpoint_string)

        resource_dictionaries = ConfigurationHelper.dict_value_or_default(
            parsed_json, "resources", [])
        configuration.resources = []
        for resource_dictionary in resource_dictionaries:
            resource = ConfigurationResource.from_dictionary(
                configuration.write_interval, resource_dictionary)
            configuration.resources.append(resource)
        return configuration
    def run(self):
        self.init_env()
        self.init_arguments()
        config = self.parse_config()

        rabbit_mq_endpoint = ServiceEndpoint.from_string(
            self.RABBIT_MQ_ENDPOINT)
        self._connection = pika.BlockingConnection(
            pika.ConnectionParameters(host=rabbit_mq_endpoint.host_ip,
                                      port=rabbit_mq_endpoint.port))
        self._channel = self._connection.channel()

        self.delete_queue()
        self.create_rabbit_mq_queues(self._rabbitmq_endpoint_argument)

        self._task_receiver = RabbitMQExecutedTaskReceiver(
            rabbit_mq_endpoint, self.RABBITMQ_SCALING_RESPONSE_QUEUE_NAME)

        self.receive_empty()
        self.write_content_to_queue()
        time.sleep(2)
        self.receive_content()

        self._task_receiver.close()
 def test_from_string_empty(self):
     with pytest.raises(ValueError):
         ServiceEndpoint.from_string("")
         assert False
 def test_init_with_minus_port(self):
     with pytest.raises(ValueError):
         host_ip = self.VALID_IP
         port = -1
         endpoint = ServiceEndpoint(host_ip, port)
         assert False
 def test_from_string_missing_ip(self):
     with pytest.raises(ValueError):
         ServiceEndpoint.from_string(":" + str(self.MAX_ALLOWED_PORT))
         assert False
 def test_from_string_missing_port(self):
     with pytest.raises(ValueError):
         ServiceEndpoint.from_string(self.VALID_IP)
         assert False
 def test_from_string(self):
     endpoint = ServiceEndpoint.from_string(self.VALID_IP + ":" +
                                            str(self.MIN_ALLOWED_PORT))
     assert endpoint.host_ip == self.VALID_IP
     assert endpoint.port == self.MIN_ALLOWED_PORT
 def test_from_string_empty(self):
     with pytest.raises(ValueError):
         ServiceEndpoint.from_string("")
         assert False
 def test_init_with_invalid_ip(self):
     with pytest.raises(ValueError):
         host_ip = ""
         port = self.MAX_ALLOWED_PORT
         endpoint = ServiceEndpoint(host_ip, port)
         assert False
 def test_init_with_too_large_port(self):
     with pytest.raises(ValueError):
         host_ip = self.VALID_IP
         port = self.MAX_ALLOWED_PORT + 1
         endpoint = ServiceEndpoint(host_ip, port)
         assert False
 def test_from_string(self):
     endpoint = ServiceEndpoint.from_string(self.VALID_IP + ":" + str(self.MIN_ALLOWED_PORT))
     assert endpoint.host_ip == self.VALID_IP
     assert endpoint.port == self.MIN_ALLOWED_PORT
 def test_from_string_missing_ip(self):
     with pytest.raises(ValueError):
         ServiceEndpoint.from_string(":" + str(self.MAX_ALLOWED_PORT))
         assert False
 def test_from_string_missing_port(self):
     with pytest.raises(ValueError):
         ServiceEndpoint.from_string(self.VALID_IP)
         assert False