예제 #1
0
 def start_policy_checker_si(self):
     LOG.debug("Start active_policy check for policy %s on service instance %s" % (
         self.policy.name, self.service_instance.name))
     while not self.is_stopped:
         LOG.debug("Locking policy checking from %s" % self.policy.name)
         self.lock.acquire()
         LOG.debug("Locked policy checking from %s" % self.policy.name)
         action = self.policy.action
         if action.scaling_adjustment > 0:
             if (len(self.service_instance.units) + action.scaling_adjustment) > self.service_instance.size.get(
                     'max'):
                 LOG.warning(
                     'Check upscaling - Maximum number of unit exceeded for service instance: %s' % self.service_instance.name)
                 LOG.debug("Release Policy lock by %s" % self.policy.name)
                 self.lock.release()
                 time.sleep(self.policy.period)
                 continue
         if action.scaling_adjustment < 0:
             if (len(self.service_instance.units) + action.scaling_adjustment) < self.service_instance.size.get(
                     'min'):
                 LOG.warning(
                     'Check downscaling - Minimum number of unit exceeded for service instance: %s' % self.service_instance.name)
                 LOG.debug("Release Policy lock by %s" % self.policy.name)
                 self.lock.release()
                 time.sleep(self.policy.period)
                 continue
         if self.service_instance.state != 'UPDATING' and self.check_alarm_si():
             LOG.debug('Execute action: %s' % repr(self.policy.action))
             if action.adjustment_type == 'ChangeInCapacity':
                 self.service_instance.state = 'UPDATING'
                 self.topology.state = 'UPDATING'
                 if action.scaling_adjustment > 0:
                     if (len(
                             self.service_instance.units) + action.scaling_adjustment) <= self.service_instance.size.get(
                             'max'):
                         for i in range(action.scaling_adjustment):
                             _hostname = '%s-%s' % (
                                 self.service_instance.name, str(len(self.service_instance.units) + 1))
                             _state = 'DEFINED'
                             new_unit = Unit(hostname=_hostname, state=_state)
                             new_unit.service_instance_id = self.service_instance.id
                             self.service_instance.units.append(new_unit)
                             self.db.persist(new_unit)
                     else:
                         LOG.warning(
                             'Maximum number of unit exceeded for service instance: %s' % self.service_instance.name)
                 else:
                     if (len(
                             self.service_instance.units) + action.scaling_adjustment) >= self.service_instance.size.get(
                             'min'):
                         for i in range(-action.scaling_adjustment):
                             removed_unit = self.remove_unit(self.topology, self.service_instance)
                             self.db.remove(removed_unit)
                     else:
                         LOG.warning(
                             'Minimum number of unit exceeded for service instance: %s' % self.service_instance.name)
                 topology = self.db.update(self.topology)
                 template = self.template_manager.get_template(self.topology)
                 # LOG.debug("Send update to heat template with: \n%s" % template)
                 try:
                     self.heat_client.update(stack_id=self.topology.ext_id, template=template)
                     self.wait_until_final_state()
                     if not self.topology.state == 'DEPLOYED':
                         LOG.error(
                             "ERROR: Something went wrong. Seems to be an error. Topology state -> %s" % self.topology.state)
                         self.lock.release()
                         return
                 except:
                     self.is_stopped = True
                     self.lock.release()
             LOG.info('Sleeping (cooldown) for %s seconds' % self.policy.action.cooldown)
             time.sleep(self.policy.action.cooldown)
         LOG.debug("Release Policy lock from %s" % self.policy.name)
         self.lock.release()
         LOG.info('Sleeping (evaluation period) for %s seconds' % self.policy.period)
         time.sleep(self.policy.period)
예제 #2
0
 def start_policy_checker_si(self):
     LOG.debug(
         "Start active_policy check for policy %s on service instance %s" %
         (self.policy.name, self.service_instance.name))
     while not self.is_stopped:
         LOG.debug("Locking policy checking from %s" % self.policy.name)
         self.lock.acquire()
         LOG.debug("Locked policy checking from %s" % self.policy.name)
         action = self.policy.action
         if action.scaling_adjustment > 0:
             if (len(self.service_instance.units) +
                     action.scaling_adjustment
                 ) > self.service_instance.size.get('max'):
                 LOG.warning(
                     'Check upscaling - Maximum number of unit exceeded for service instance: %s'
                     % self.service_instance.name)
                 LOG.debug("Release Policy lock by %s" % self.policy.name)
                 self.lock.release()
                 time.sleep(self.policy.period)
                 continue
         if action.scaling_adjustment < 0:
             if (len(self.service_instance.units) +
                     action.scaling_adjustment
                 ) < self.service_instance.size.get('min'):
                 LOG.warning(
                     'Check downscaling - Minimum number of unit exceeded for service instance: %s'
                     % self.service_instance.name)
                 LOG.debug("Release Policy lock by %s" % self.policy.name)
                 self.lock.release()
                 time.sleep(self.policy.period)
                 continue
         if self.service_instance.state != 'UPDATING' and self.check_alarm_si(
         ):
             LOG.debug('Execute action: %s' % repr(self.policy.action))
             if action.adjustment_type == 'ChangeInCapacity':
                 self.service_instance.state = 'UPDATING'
                 self.topology.state = 'UPDATING'
                 if action.scaling_adjustment > 0:
                     if (len(self.service_instance.units) +
                             action.scaling_adjustment
                         ) <= self.service_instance.size.get('max'):
                         for i in range(action.scaling_adjustment):
                             _hostname = '%s-%s' % (
                                 self.service_instance.name,
                                 str(len(self.service_instance.units) + 1))
                             _state = 'DEFINED'
                             new_unit = Unit(hostname=_hostname,
                                             state=_state)
                             new_unit.service_instance_id = self.service_instance.id
                             self.service_instance.units.append(new_unit)
                             self.db.persist(new_unit)
                     else:
                         LOG.warning(
                             'Maximum number of unit exceeded for service instance: %s'
                             % self.service_instance.name)
                 else:
                     if (len(self.service_instance.units) +
                             action.scaling_adjustment
                         ) >= self.service_instance.size.get('min'):
                         for i in range(-action.scaling_adjustment):
                             removed_unit = self.remove_unit(
                                 self.topology, self.service_instance)
                             self.db.remove(removed_unit)
                     else:
                         LOG.warning(
                             'Minimum number of unit exceeded for service instance: %s'
                             % self.service_instance.name)
                 topology = self.db.update(self.topology)
                 template = self.template_manager.get_template(
                     self.topology)
                 # LOG.debug("Send update to heat template with: \n%s" % template)
                 try:
                     self.heat_client.update(stack_id=self.topology.ext_id,
                                             template=template)
                     self.wait_until_final_state()
                     if not self.topology.state == 'DEPLOYED':
                         LOG.error(
                             "ERROR: Something went wrong. Seems to be an error. Topology state -> %s"
                             % self.topology.state)
                         self.lock.release()
                         return
                 except:
                     self.is_stopped = True
                     self.lock.release()
             LOG.info('Sleeping (cooldown) for %s seconds' %
                      self.policy.action.cooldown)
             time.sleep(self.policy.action.cooldown)
         LOG.debug("Release Policy lock from %s" % self.policy.name)
         self.lock.release()
         LOG.info('Sleeping (evaluation period) for %s seconds' %
                  self.policy.period)
         time.sleep(self.policy.period)
 def update(self, new_topology, old_topology):
     conf = sys_util().get_sys_conf()
     db = FactoryAgent().get_agent(conf['database_manager'])
     updated_topology = old_topology
     updated_topology.name = new_topology.name
     #check for additional service instances and add them to the list of new instances
     appended_service_instances = []
     for new_service_instance in new_topology.service_instances:
         is_found = False
         for updated_service_instance in updated_topology.service_instances:
             if new_service_instance.name == updated_service_instance.name:
                 is_found = True
                 break
         if not is_found:
             appended_service_instances.append(new_service_instance)
     #check for removed service instances and add it to the list of removed instances
     removed_service_instances = []
     for updated_service_instance in updated_topology.service_instances:
         is_found = False
         for new_service_instance in new_topology.service_instances:
             if new_service_instance.name == updated_service_instance.name:
                 is_found = True
                 break
         if not is_found:
             removed_service_instances.append(updated_service_instance)
     #remove removed service instances
     for removed_service_instance in removed_service_instances:
         updated_topology.service_instances.remove(removed_service_instance)
         logger.debug('Removed ServiceInstance \"%s\" from Topology \"%s\".' % (removed_service_instance.name, updated_topology.name))
     #append additional service instances
     for appended_service_instance in appended_service_instances:
         appended_service_instance.topology_id = updated_topology.id
         updated_topology.service_instances.append(appended_service_instance)
         if appended_service_instance.policies is not None:
             for policy in appended_service_instance.policies:
                 db.persist(policy)
         db.persist(appended_service_instance)
         logger.debug('Appended ServiceInstance \"%s\" to Topology \"%s\".' % (appended_service_instance.name, updated_topology.name))
     #Update all values for each service instance
     for updated_service_instance in updated_topology.service_instances:
         for new_service_instance in new_topology.service_instances:
             if updated_service_instance.name == new_service_instance.name:
                 updated_service_instance.size = new_service_instance.size
                 updated_service_instance.configuration = new_service_instance.configuration
                 updated_service_instance.policies = new_service_instance.policies
                 #updated_service_instance.service_type = new_service_instance.service_type
                 if new_service_instance.service_type and updated_service_instance.service_type != new_service_instance.service_type:
                     logger.warning("Cannot update service_type for %s->%s. Not Implemented." % (updated_topology.name, updated_service_instance.name))
                 if new_service_instance.adapter and updated_service_instance.adapter != new_service_instance.adapter:
                     logger.warning("Cannot update adapter for %s->%s. Not Implemented." % (updated_topology.name, updated_service_instance.name))
                 #updated_service_instance.flavor = new_service_instance.flavor
                 if new_service_instance.flavor and updated_service_instance.flavor.name != new_service_instance.flavor.name:
                     logger.warning("Cannot update flavor for %s->%s. Not Implemented." % (updated_topology.name, updated_service_instance.name))
                 #updated_service_instance.image = new_service_instance.image
                 if new_service_instance.image and updated_service_instance.image.name != new_service_instance.image.name:
                     logger.warning("Cannot update image for %s->%s. Not Implemented." % (updated_topology.name, updated_service_instance.name))
                 #updated_service_instance.networks = new_service_instance.networks
                 if new_service_instance.networks is not None:
                     logger.warning("Cannot update networks for %s->%s. Not Implemented." % (updated_topology.name, updated_service_instance.name))
                 #updated_service_instance.requirements = new_service_instance.requirements
                 if new_service_instance.requirements is not None:
                     logger.warning("Cannot update networks for %s->%s. Not Implemented." % (updated_topology.name, updated_service_instance.name))
                 #updated_service_instance.user_data = new_service_instance.user_data
                 if new_service_instance.user_data is not None:
                     logger.warning("Cannot update user_data for %s->%s. Not Implemented." % (updated_topology.name, updated_service_instance.name))
                 if new_service_instance.key and updated_service_instance.key.name != new_service_instance.key.name:
                     logger.warning("Cannot update key for %s->%s without replacement." % (updated_topology.name, updated_service_instance.name))
     #Add or remove units according to minimal or maximal size
     for updated_service_instance in updated_topology.service_instances:
         if updated_service_instance not in appended_service_instances:
             if len(updated_service_instance.units) < updated_service_instance.size.get('min'):
                 for i in range(updated_service_instance.size.get('min') - len(updated_service_instance.units)):
                     _hostname = '%s-%s' % (
                         updated_service_instance.name, str(len(updated_service_instance.units) + 1))
                     _state = 'DEFINED'
                     new_unit = Unit(hostname=_hostname, state=_state)
                     new_unit.service_instance_id = updated_service_instance.id
                     updated_service_instance.units.append(new_unit)
                     db.persist(new_unit)
             if len(updated_service_instance.units) > updated_service_instance.size.get('max'):
                 for i in range(len(updated_service_instance.units) - updated_service_instance.size.get('max')):
                     removed_unit = updated_service_instance.units.pop(len(updated_service_instance.units) - 1)
                     db.remove(removed_unit)
     return updated_topology
예제 #4
0
 def update(self, new_topology, old_topology):
     conf = sys_util().get_sys_conf()
     db = FactoryAgent().get_agent(conf['database_manager'])
     updated_topology = old_topology
     updated_topology.name = new_topology.name
     #check for additional service instances and add them to the list of new instances
     appended_service_instances = []
     for new_service_instance in new_topology.service_instances:
         is_found = False
         for updated_service_instance in updated_topology.service_instances:
             if new_service_instance.name == updated_service_instance.name:
                 is_found = True
                 break
         if not is_found:
             appended_service_instances.append(new_service_instance)
     #check for removed service instances and add it to the list of removed instances
     removed_service_instances = []
     for updated_service_instance in updated_topology.service_instances:
         is_found = False
         for new_service_instance in new_topology.service_instances:
             if new_service_instance.name == updated_service_instance.name:
                 is_found = True
                 break
         if not is_found:
             removed_service_instances.append(updated_service_instance)
     #remove removed service instances
     for removed_service_instance in removed_service_instances:
         updated_topology.service_instances.remove(removed_service_instance)
         LOG.debug('Removed ServiceInstance \"%s\" from Topology \"%s\".' %
                   (removed_service_instance.name, updated_topology.name))
     #append additional service instances
     for appended_service_instance in appended_service_instances:
         appended_service_instance.topology_id = updated_topology.id
         updated_topology.service_instances.append(
             appended_service_instance)
         if appended_service_instance.policies is not None:
             for policy in appended_service_instance.policies:
                 db.persist(policy)
         db.persist(appended_service_instance)
         LOG.debug('Appended ServiceInstance \"%s\" to Topology \"%s\".' %
                   (appended_service_instance.name, updated_topology.name))
     #Update all values for each service instance
     for updated_service_instance in updated_topology.service_instances:
         for new_service_instance in new_topology.service_instances:
             if updated_service_instance.name == new_service_instance.name:
                 updated_service_instance.size = new_service_instance.size
                 updated_service_instance.configuration = new_service_instance.configuration
                 updated_service_instance.policies = new_service_instance.policies
                 #updated_service_instance.service_type = new_service_instance.service_type
                 if new_service_instance.service_type and updated_service_instance.service_type != new_service_instance.service_type:
                     LOG.warning(
                         "Cannot update service_type for %s->%s. Not Implemented."
                         % (updated_topology.name,
                            updated_service_instance.name))
                 if new_service_instance.adapter and updated_service_instance.adapter != new_service_instance.adapter:
                     LOG.warning(
                         "Cannot update adapter for %s->%s. Not Implemented."
                         % (updated_topology.name,
                            updated_service_instance.name))
                 #updated_service_instance.flavor = new_service_instance.flavor
                 if new_service_instance.flavor and updated_service_instance.flavor.name != new_service_instance.flavor.name:
                     LOG.warning(
                         "Cannot update flavor for %s->%s. Not Implemented."
                         % (updated_topology.name,
                            updated_service_instance.name))
                 #updated_service_instance.image = new_service_instance.image
                 if new_service_instance.image and updated_service_instance.image.name != new_service_instance.image.name:
                     LOG.warning(
                         "Cannot update image for %s->%s. Not Implemented."
                         % (updated_topology.name,
                            updated_service_instance.name))
                 #updated_service_instance.networks = new_service_instance.networks
                 if new_service_instance.networks is not None:
                     LOG.warning(
                         "Cannot update networks for %s->%s. Not Implemented."
                         % (updated_topology.name,
                            updated_service_instance.name))
                 #updated_service_instance.requirements = new_service_instance.requirements
                 if new_service_instance.requirements is not None:
                     LOG.warning(
                         "Cannot update networks for %s->%s. Not Implemented."
                         % (updated_topology.name,
                            updated_service_instance.name))
                 #updated_service_instance.user_data = new_service_instance.user_data
                 if new_service_instance.user_data is not None:
                     LOG.warning(
                         "Cannot update user_data for %s->%s. Not Implemented."
                         % (updated_topology.name,
                            updated_service_instance.name))
                 if new_service_instance.key and updated_service_instance.key.name != new_service_instance.key.name:
                     LOG.warning(
                         "Cannot update key for %s->%s without replacement."
                         % (updated_topology.name,
                            updated_service_instance.name))
     #Add or remove units according to minimal or maximal size
     for updated_service_instance in updated_topology.service_instances:
         if updated_service_instance not in appended_service_instances:
             if len(updated_service_instance.units
                    ) < updated_service_instance.size.get('min'):
                 for i in range(
                         updated_service_instance.size.get('min') -
                         len(updated_service_instance.units)):
                     _hostname = '%s-%s' % (
                         updated_service_instance.name,
                         str(len(updated_service_instance.units) + 1))
                     _state = 'DEFINED'
                     new_unit = Unit(hostname=_hostname, state=_state)
                     new_unit.service_instance_id = updated_service_instance.id
                     updated_service_instance.units.append(new_unit)
                     db.persist(new_unit)
             if len(updated_service_instance.units
                    ) > updated_service_instance.size.get('max'):
                 for i in range(
                         len(updated_service_instance.units) -
                         updated_service_instance.size.get('max')):
                     removed_unit = updated_service_instance.units.pop(
                         len(updated_service_instance.units) - 1)
                     db.remove(removed_unit)
     return updated_topology
예제 #5
0
    def start_policy_checker_si(self):
        logger.debug(
            "Start active_policy check for policy %s on service instance %s"
            % (self.policy.name, self.service_instance.name)
        )
        while not self.is_stopped:
            logger.debug("Locking policy checking from %s" % self.policy.name)
            self.lock.acquire()
            logger.debug("Locked policy checking from %s" % self.policy.name)
            action = self.policy.action
            if action.scaling_adjustment > 0:
                if (len(self.service_instance.units) + action.scaling_adjustment) > self.service_instance.size.get(
                    "max"
                ):
                    logger.warning(
                        "Check upscaling - Maximum number of unit exceeded for service instance: %s"
                        % self.service_instance.name
                    )
                    logger.debug("Release Policy lock by %s" % self.policy.name)
                    self.lock.release()
                    time.sleep(self.policy.period)
                    continue
            if action.scaling_adjustment < 0:
                if (len(self.service_instance.units) + action.scaling_adjustment) < self.service_instance.size.get(
                    "min"
                ):
                    logger.warning(
                        "Check downscaling - Minimum number of unit exceeded for service instance: %s"
                        % self.service_instance.name
                    )
                    logger.debug("Release Policy lock by %s" % self.policy.name)
                    self.lock.release()
                    time.sleep(self.policy.period)
                    continue
            if self.service_instance.state != "UPDATING" and self.check_alarm_si():
                logger.debug("Execute action: %s" % repr(self.policy.action))
                if action.adjustment_type == "ChangeInCapacity":
                    self.service_instance.state = "UPDATING"
                    self.topology.state = "UPDATING"
                    if action.scaling_adjustment > 0:
                        logger.info("executing scaling out action ")
                        info = {
                            "so_id": "idnotusefulhere",
                            "sm_name": "imsaas",
                            "so_phase": "update",
                            "phase_event": "start",
                            "response_time": 0,
                            "tenant": "mcntub",
                        }
                        self.start_time = time.time()
                        info_json = json.dumps(info)
                        glogger.debug(info_json)
                        if (
                            len(self.service_instance.units) + action.scaling_adjustment
                        ) <= self.service_instance.size.get("max"):
                            for i in range(action.scaling_adjustment):
                                _hostname = "%s-%s" % (
                                    self.service_instance.name,
                                    str(len(self.service_instance.units) + 1),
                                )
                                _state = "DEFINED"
                                new_unit = Unit(hostname=_hostname, state=_state)
                                new_unit.service_instance_id = self.service_instance.id
                                self.service_instance.units.append(new_unit)
                                self.db.persist(new_unit)
                        else:
                            logger.warning(
                                "Maximum number of unit exceeded for service instance: %s" % self.service_instance.name
                            )
                    else:
                        logger.info("executing scaling in action ")
                        if (
                            len(self.service_instance.units) + action.scaling_adjustment
                        ) >= self.service_instance.size.get("min"):
                            for i in range(-action.scaling_adjustment):
                                removed_unit = self.remove_unit(self.topology, self.service_instance)
                                self.db.remove(removed_unit)
                        else:
                            logger.warning(
                                "Minimum number of unit exceeded for service instance: %s" % self.service_instance.name
                            )
                    topology = self.db.update(self.topology)
                    template = self.template_manager.get_template(self.topology)
                    # logger.debug("Send update to heat template with: \n%s" % template)
                    if action.scaling_adjustment <= 0:
                        logger.info("provisioning the unit after scaling in operation")
                        self.configure_after_scaling(removed_unit)
                    try:
                        logger.info("updating the heat template including new units")
                        self.heat_client.update(stack_id=self.topology.ext_id, template=template)
                        self.wait_until_final_state()
                        logger.info("wait until final state function executed")
                        if self.topology.state not in ["DEPLOYED", "UPDATED"]:
                            logger.error(
                                "ERROR: Something went wrong. Seems to be an error. Topology state -> %s"
                                % self.topology.state
                            )
                            self.lock.release()
                            return
                    except:
                        self.is_stopped = True
                        self.lock.release()
                    logger.info("entering provisioning phase")
                    if action.scaling_adjustment > 0:
                        logger.info("provisioning new unit after scaling out operation")
                        # adding relations between newly added unit and existing units from dependent services
                        self.configure_new_unit(new_unit)

                logger.info("Sleeping (cooldown) for %s seconds" % self.policy.action.cooldown)
                time.sleep(self.policy.action.cooldown)
            logger.debug("Release Policy lock from %s" % self.policy.name)
            self.lock.release()
            logger.info("Sleeping (evaluation period) for %s seconds" % self.policy.period)
            time.sleep(self.policy.period)