示例#1
0
文件: sd.py 项目: XroLLla/watcher
    def execute(self, orign_model):
        current_model = orign_model

        if orign_model is None:
            raise exception.ClusterStateNotDefined()

        migration = self.check_threshold(current_model)
        LOG.warning(migration)
        if migration:
            hosts_load = self.get_hosts_load(current_model)
            min_sd = 1
            for vm_host in migration:
                vm_load = self.calculate_migration_case(
                    hosts_load, vm_host['vm'], vm_host['s_host'],
                    vm_host['host'])
                weighted_sd = self.calculate_weighted_sd(
                    self.metrics, vm_load[:-1])
                if weighted_sd < min_sd:
                    min_sd = weighted_sd
                    hosts_load = vm_load[-1]
                    self.migrate(current_model, vm_host['vm'],
                                 vm_host['s_host'], vm_host['host'])

                for metric, value in zip(self.metrics, vm_load[:-1]):
                    if value < float(self.thresholds[metric]):
                        break
        self.solution.model = current_model
        self.solution.efficacy = 100
        return self.solution
示例#2
0
    def calculate_score_vm(self, vm, cluster_data_model):
        """Calculate Score of virtual machine

        :param vm: the virtual machine
        :param cluster_data_model: the cluster model
        :return: score
        """
        if cluster_data_model is None:
            raise exception.ClusterStateNotDefined()

        vm_cpu_utilization = self.ceilometer. \
            statistic_aggregation(
                resource_id=vm.uuid,
                meter_name=self.INSTANCE_CPU_USAGE_METRIC_NAME,
                period="7200",
                aggregate='avg'
            )
        if vm_cpu_utilization is None:
            LOG.error(
                _LE("No values returned by %(resource_id)s "
                    "for %(metric_name)s"),
                resource_id=vm.uuid,
                metric_name=self.INSTANCE_CPU_USAGE_METRIC_NAME,
            )
            vm_cpu_utilization = 100

        cpu_capacity = cluster_data_model.get_resource_from_id(
            resource.ResourceType.cpu_cores).get_capacity(vm)

        total_cores_used = cpu_capacity * (vm_cpu_utilization / 100.0)

        return self.calculate_weight(cluster_data_model, vm, total_cores_used,
                                     0, 0)
示例#3
0
    def pre_execute(self):
        LOG.debug("Initializing Uniform Airflow Strategy")

        if not self.compute_model:
            raise wexc.ClusterStateNotDefined()

        LOG.debug(self.compute_model.to_string())
示例#4
0
    def pre_execute(self):
        LOG.debug("Initializing Outlet temperature strategy")

        if not self.compute_model:
            raise wexc.ClusterStateNotDefined()

        LOG.debug(self.compute_model.to_string())
示例#5
0
    def execute(self, original_model):
        LOG.debug("Initializing Outlet temperature strategy")

        if original_model is None:
            raise wexc.ClusterStateNotDefined()

        current_model = original_model
        hosts_need_release, hosts_target = self.group_hosts_by_outlet_temp(
            current_model)

        if len(hosts_need_release) == 0:
            # TODO(zhenzanz): return something right if there's no hot servers
            LOG.debug("No hosts require optimization")
            return self.solution

        if len(hosts_target) == 0:
            LOG.warning(_LE("No hosts under outlet temp threshold found"))
            return self.solution

        # choose the server with highest outlet t
        hosts_need_release = sorted(hosts_need_release,
                                    reverse=True,
                                    key=lambda x: (x["outlet_temp"]))

        vm_to_migrate = self.choose_vm_to_migrate(current_model,
                                                  hosts_need_release)
        # calculate the vm's cpu cores,memory,disk needs
        if vm_to_migrate is None:
            return self.solution

        mig_src_hypervisor, vm_src = vm_to_migrate
        dest_servers = self.filter_dest_servers(current_model, hosts_target,
                                                vm_src)
        # sort the filtered result by outlet temp
        # pick up the lowest one as dest server
        if len(dest_servers) == 0:
            # TODO(zhenzanz): maybe to warn that there's no resource
            # for instance.
            LOG.info(_LE("No proper target host could be found"))
            return self.solution

        dest_servers = sorted(dest_servers, key=lambda x: (x["outlet_temp"]))
        # always use the host with lowerest outlet temperature
        mig_dst_hypervisor = dest_servers[0]['hv']
        # generate solution to migrate the vm to the dest server,
        if current_model.get_mapping().migrate_vm(vm_src, mig_src_hypervisor,
                                                  mig_dst_hypervisor):
            parameters = {
                'migration_type': 'live',
                'src_hypervisor': mig_src_hypervisor.uuid,
                'dst_hypervisor': mig_dst_hypervisor.uuid
            }
            self.solution.add_action(action_type=self.MIGRATION,
                                     resource_id=vm_src.uuid,
                                     input_parameters=parameters)

        self.solution.model = current_model

        return self.solution
    def pre_execute(self):
        if not self.compute_model:
            raise exception.ClusterStateNotDefined()

        if self.compute_model.stale:
            raise exception.ClusterStateStale()

        LOG.debug(self.compute_model.to_string())
示例#7
0
    def pre_execute(self):
        LOG.info(_LI("Initializing Server Consolidation"))
        if not self.compute_model:
            raise exception.ClusterStateNotDefined()

        if len(self.compute_model.get_all_compute_nodes()) == 0:
            raise exception.ClusterEmpty()

        LOG.debug(self.compute_model.to_string())
示例#8
0
    def pre_execute(self):
        LOG.debug("Initializing Noisy Neighbor strategy")

        if not self.compute_model:
            raise wexc.ClusterStateNotDefined()

        if self.compute_model.stale:
            raise wexc.ClusterStateStale()

        LOG.debug(self.compute_model.to_string())
示例#9
0
    def pre_execute(self):
        """Pre-execution phase

        This can be used to fetch some pre-requisites or data.
        """
        LOG.info(_LI("Initializing Workload Balance Strategy"))

        if not self.compute_model:
            raise wexc.ClusterStateNotDefined()

        LOG.debug(self.compute_model.to_string())
示例#10
0
    def pre_execute(self):
        LOG.info(_LI("Initializing Workload Stabilization"))

        if not self.compute_model:
            raise exception.ClusterStateNotDefined()

        self.weights = self.input_parameters.weights
        self.metrics = self.input_parameters.metrics
        self.thresholds = self.input_parameters.thresholds
        self.host_choice = self.input_parameters.host_choice
        self.instance_metrics = self.input_parameters.instance_metrics
        self.retry_count = self.input_parameters.retry_count
示例#11
0
    def pre_execute(self):
        """Pre-execution phase

        This can be used to fetch some pre-requisites or data.
        """
        LOG.info("Initializing Saving Energy Strategy")

        if not self.compute_model:
            raise wexc.ClusterStateNotDefined()

        if self.compute_model.stale:
            raise wexc.ClusterStateStale()

        LOG.debug(self.compute_model.to_string())
示例#12
0
文件: base.py 项目: akinsWin/watcher
    def compute_model(self):
        """Cluster data model

        :returns: Cluster data model the strategy is executed on
        :rtype model: :py:class:`~.ModelRoot` instance
        """
        if self._compute_model is None:
            collector = self.collector_manager.get_cluster_model_collector(
                'compute', osc=self.osc)
            self._compute_model = self.audit_scope_handler.get_scoped_model(
                collector.get_latest_cluster_data_model())

        if not self._compute_model:
            raise exception.ClusterStateNotDefined()

        return self._compute_model
示例#13
0
    def _pre_execute(self):
        """Base Pre-execution phase

         This will perform basic pre execution operations most strategies
         should perform.
        """

        LOG.info("Initializing " + self.get_display_name())

        if not self.compute_model:
            raise exception.ClusterStateNotDefined()

        if self.compute_model.stale:
            raise exception.ClusterStateStale()

        LOG.debug(self.compute_model.to_string())
示例#14
0
    def execute(self, original_model):
        LOG.info(_LI("Initializing Sercon Consolidation"))

        if original_model is None:
            raise exception.ClusterStateNotDefined()

        # todo(jed) clone model
        current_model = original_model

        self.efficacy = 100
        unsuccessful_migration = 0

        first_migration = True
        size_cluster = len(current_model.get_all_hypervisors())
        if size_cluster == 0:
            raise exception.ClusterEmpty()

        self.compute_attempts(size_cluster)

        for hypervisor_id in current_model.get_all_hypervisors():
            hypervisor = current_model.get_hypervisor_from_id(hypervisor_id)
            count = current_model.get_mapping(). \
                get_node_vms_from_id(hypervisor_id)
            if len(count) == 0:
                if hypervisor.state == hyper_state.HypervisorState.ONLINE:
                    self.add_change_service_state(
                        hypervisor_id,
                        hyper_state.HypervisorState.OFFLINE.value)

        while self.get_allowed_migration_attempts() >= unsuccessful_migration:
            if not first_migration:
                self.efficacy = self.calculate_migration_efficacy()
                if self.efficacy < float(self.target_efficacy):
                    break
            first_migration = False
            score = []

            score = self.score_of_nodes(current_model, score)
            ''' sort compute nodes by Score decreasing ''' ''
            sorted_score = sorted(score, reverse=True, key=lambda x: (x[1]))
            LOG.debug("Hypervisor(s) BFD {0}".format(sorted_score))
            ''' get Node to be released '''
            if len(score) == 0:
                LOG.warning(
                    _LW("The workloads of the compute nodes"
                        " of the cluster is zero"))
                break

            node_to_release, vm_score = self.node_and_vm_score(
                sorted_score, score, current_model)
            ''' sort VMs by Score '''
            sorted_vms = sorted(vm_score, reverse=True, key=lambda x: (x[1]))
            # BFD: Best Fit Decrease
            LOG.debug("VM(s) BFD {0}".format(sorted_vms))

            migrations = self.calculate_num_migrations(sorted_vms,
                                                       current_model,
                                                       node_to_release,
                                                       sorted_score)

            unsuccessful_migration = self.unsuccessful_migration_actualization(
                migrations, unsuccessful_migration)
        infos = {
            "number_of_migrations": self.number_of_migrations,
            "number_of_nodes_released": self.number_of_released_nodes,
            "efficacy": self.efficacy
        }
        LOG.debug(infos)
        self.solution.model = current_model
        self.solution.efficacy = self.efficacy
        return self.solution