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
Exemple #2
0
    def from_dictionary(cls, dictionary, previous_phase=None):
        phase = Phase()
        phase.duration_seconds = ConfigurationHelper.dict_value_or_default(dictionary, "duration_seconds", 60)
        phase.min_value = ConfigurationHelper.dict_value_or_default(dictionary, "min_value", 0)
        phase.max_value = ConfigurationHelper.dict_value_or_default(dictionary, "max_value", 100)
        if "start_time" in dictionary or previous_phase is None:
            start_time_string = ConfigurationHelper.dict_value_or_fail(
                dictionary,
                "start_time",
                "The first phase has to have a start_time attribute!"
            )
            phase.start_time = dateutil.parser.parse(start_time_string)
        else:
            phase.start_time = cls.calculate_start_time_depending_on_previous_phase(previous_phase)

        return phase
    def from_dictionary(cls, global_write_interval, dictionary):
        resource = ConfigurationResource()
        resource.write_interval = ConfigurationHelper.dict_value_or_default(
            dictionary, "write_interval", global_write_interval)
        resource.metric_name = ConfigurationHelper.dict_value_or_fail(
            dictionary, "metric_name",
            "Metric name missing in resource configuration!")
        resource.metric_value_template = ConfigurationHelper.dict_value_or_default(
            dictionary, "metric_value_template", None)
        resource.service_type = ConfigurationHelper.dict_value_or_fail(
            dictionary, "service_type",
            "Service type missing in resource configuration!")
        resource.instance_uuid = ConfigurationHelper.dict_value_or_default(
            dictionary, "instance_uuid", cls.GENERATE_UUID_KEYWORD)
        if resource.instance_uuid == cls.GENERATE_UUID_KEYWORD:
            resource.instance_uuid = cls.generate_uuid()
        elif resource.instance_uuid == cls.NO_UUID_KEYWORD:
            resource.instance_uuid = ""

        resource.instance_name = ConfigurationHelper.dict_value_or_default(
            dictionary, "instance_name", None)
        phases_dictionary = ConfigurationHelper.dict_value_or_fail(
            dictionary, "phases",
            "There are no phases defined for a resource!")
        previous_phase = None
        for phase_dictionary in phases_dictionary:
            phase = Phase.from_dictionary(phase_dictionary,
                                          previous_phase=previous_phase)
            previous_phase = phase
            resource.phases.append(phase)

        return resource
Exemple #4
0
    def from_dictionary(cls, dictionary, previous_phase=None):
        phase = Phase()
        phase.duration_seconds = ConfigurationHelper.dict_value_or_default(
            dictionary, "duration_seconds", 60)
        phase.min_value = ConfigurationHelper.dict_value_or_default(
            dictionary, "min_value", 0)
        phase.max_value = ConfigurationHelper.dict_value_or_default(
            dictionary, "max_value", 100)
        if "start_time" in dictionary or previous_phase is None:
            start_time_string = ConfigurationHelper.dict_value_or_fail(
                dictionary, "start_time",
                "The first phase has to have a start_time attribute!")
            phase.start_time = dateutil.parser.parse(start_time_string)
        else:
            phase.start_time = cls.calculate_start_time_depending_on_previous_phase(
                previous_phase)

        return phase
    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_dictionary(cls, global_write_interval, dictionary):
        resource = ConfigurationResource()
        resource.write_interval = ConfigurationHelper.dict_value_or_default(dictionary, "write_interval", global_write_interval)
        resource.metric_name = ConfigurationHelper.dict_value_or_fail(
            dictionary,
            "metric_name",
            "Metric name missing in resource configuration!"
        )
        resource.metric_value_template = ConfigurationHelper.dict_value_or_default(
            dictionary,
            "metric_value_template",
            None
        )
        resource.service_type = ConfigurationHelper.dict_value_or_fail(
            dictionary,
            "service_type",
            "Service type missing in resource configuration!"
        )
        resource.instance_uuid = ConfigurationHelper.dict_value_or_default(
            dictionary,
            "instance_uuid",
            cls.GENERATE_UUID_KEYWORD
        )
        if resource.instance_uuid == cls.GENERATE_UUID_KEYWORD:
            resource.instance_uuid = cls.generate_uuid()
        elif resource.instance_uuid == cls.NO_UUID_KEYWORD:
            resource.instance_uuid = ""

        resource.instance_name = ConfigurationHelper.dict_value_or_default(
            dictionary,
            "instance_name",
            None
        )
        phases_dictionary = ConfigurationHelper.dict_value_or_fail(
            dictionary,
            "phases",
            "There are no phases defined for a resource!"
        )
        previous_phase = None
        for phase_dictionary in phases_dictionary:
            phase = Phase.from_dictionary(phase_dictionary, previous_phase=previous_phase)
            previous_phase = phase
            resource.phases.append(phase)

        return resource