示例#1
0
 def execute_status_command(self, command):
     '''
 Executes commands of type STATUS_COMMAND
 '''
     try:
         cluster = command['clusterName']
         service = command['serviceName']
         component = command['componentName']
         configurations = command['configurations']
         if configurations.has_key('global'):
             globalConfig = configurations['global']
         else:
             globalConfig = {}
         livestatus = LiveStatus(cluster, service, component, globalConfig,
                                 self.config)
         result = livestatus.build()
         logger.debug("Got live status for component " + component + \
                      " of service " + str(service) + \
                      " of cluster " + str(cluster))
         logger.debug(pprint.pformat(result))
         if result is not None:
             self.commandStatuses.put_command_status(command, result)
     except Exception, err:
         traceback.print_exc()
         logger.warn(err)
示例#2
0
  def execute_status_command(self, command):
    '''
    Executes commands of type STATUS_COMMAND
    '''
    try:
      cluster = command['clusterName']
      service = command['serviceName']
      component = command['componentName']
      configurations = command['configurations']
      if configurations.has_key('global'):
        globalConfig = configurations['global']
      else:
        globalConfig = {}

      command_format = self.determine_command_format_version(command)

      livestatus = LiveStatus(cluster, service, component,
                              globalConfig, self.config)
      component_status = None
      if command_format == self.COMMAND_FORMAT_V2:
        # For custom services, responsibility to determine service status is
        # delegated to python scripts
        component_status = self.customServiceOrchestrator.requestComponentStatus(
          command)

      result = livestatus.build(forsed_component_status=component_status)
      logger.debug("Got live status for component " + component + \
                   " of service " + str(service) + \
                   " of cluster " + str(cluster))
      logger.debug(pprint.pformat(result))
      if result is not None:
        self.commandStatuses.put_command_status(command, result)
    except Exception, err:
      traceback.print_exc()
      logger.warn(err)
示例#3
0
    def execute_status_command(self, command):
        '''
    Executes commands of type STATUS_COMMAND
    '''
        try:
            cluster = command['clusterName']
            service = command['serviceName']
            component = command['componentName']
            configurations = command['configurations']
            if configurations.has_key('global'):
                globalConfig = configurations['global']
            else:
                globalConfig = {}

            livestatus = LiveStatus(cluster, service, component, globalConfig,
                                    self.config, self.configTags)

            component_extra = None

            # For custom services, responsibility to determine service status is
            # delegated to python scripts
            component_status_result = self.customServiceOrchestrator.requestComponentStatus(
                command)
            component_security_status_result = self.customServiceOrchestrator.requestComponentSecurityState(
                command)

            if component_status_result['exitcode'] == 0:
                component_status = LiveStatus.LIVE_STATUS
            else:
                component_status = LiveStatus.DEAD_STATUS

            if component_status_result.has_key('structuredOut'):
                component_extra = component_status_result['structuredOut']

            result = livestatus.build(forsed_component_status=component_status)

            # Add security state to the result
            result['securityState'] = component_security_status_result

            if component_extra is not None and len(component_extra) != 0:
                if component_extra.has_key('alerts'):
                    result['alerts'] = component_extra['alerts']
                    del component_extra['alerts']

                result['extra'] = component_extra

            logger.debug("Got live status for component " + component + \
                         " of service " + str(service) + \
                         " of cluster " + str(cluster))

            logger.debug(pprint.pformat(result))
            if result is not None:
                self.commandStatuses.put_command_status(command, result)
        except Exception, err:
            traceback.print_exc()
            logger.warn(err)
示例#4
0
  def execute_status_command(self, command):
    '''
    Executes commands of type STATUS_COMMAND
    '''
    try:
      cluster = command['clusterName']
      service = command['serviceName']
      component = command['componentName']
      configurations = command['configurations']
      if configurations.has_key('global'):
        globalConfig = configurations['global']
      else:
        globalConfig = {}

      livestatus = LiveStatus(cluster, service, component,
                              globalConfig, self.config, self.configTags)

      component_extra = None

      # For custom services, responsibility to determine service status is
      # delegated to python scripts
      component_status_result = self.customServiceOrchestrator.requestComponentStatus(command)
      component_security_status_result = self.customServiceOrchestrator.requestComponentSecurityState(command)

      if component_status_result['exitcode'] == 0:
        component_status = LiveStatus.LIVE_STATUS
      else:
        component_status = LiveStatus.DEAD_STATUS

      if component_status_result.has_key('structuredOut'):
        component_extra = component_status_result['structuredOut']

      result = livestatus.build(forsed_component_status= component_status)

      # Add security state to the result
      result['securityState'] = component_security_status_result

      if component_extra is not None and len(component_extra) != 0:
        if component_extra.has_key('alerts'):
          result['alerts'] = component_extra['alerts']
          del component_extra['alerts']

        result['extra'] = component_extra

      logger.debug("Got live status for component " + component + \
                   " of service " + str(service) + \
                   " of cluster " + str(cluster))

      logger.debug(pprint.pformat(result))
      if result is not None:
        self.commandStatuses.put_command_status(command, result)
    except Exception, err:
      traceback.print_exc()
      logger.warn(err)
    def run(self):
        result = []
        while not self.stopped():
            while not self.commandQueue.empty():
                command = self.commandQueue.get()
                logger.debug("Took an element of Queue: " +
                             pprint.pformat(command))
                if command['commandType'] == self.EXECUTION_COMMAND:
                    try:
                        #pass a copy of action since we don't want anything to change in the
                        #action dict
                        result = self.executeCommand(command)

                    except Exception, err:
                        traceback.print_exc()
                        logger.warn(err)
                        pass

                    for entry in result:
                        self.resultQueue.put((command['commandType'], entry))

                elif command['commandType'] == self.STATUS_COMMAND:
                    try:
                        cluster = command['clusterName']
                        service = command['serviceName']
                        component = command['componentName']
                        configurations = command['configurations']
                        if configurations.has_key('global'):
                            globalConfig = configurations['global']
                        else:
                            globalConfig = {}
                        livestatus = LiveStatus(cluster, service, component,
                                                globalConfig, self.config)
                        result = livestatus.build()
                        logger.debug("Got live status for component " + component +\
                                     " of service " + str(service) +\
                                     " of cluster " + str(cluster))
                        logger.debug(pprint.pformat(result))
                        if result is not None:
                            self.resultQueue.put(
                                (ActionQueue.STATUS_COMMAND, result))

                    except Exception, err:
                        traceback.print_exc()
                        logger.warn(err)
                    pass
  def run(self):
    result = []
    while not self.stopped():
      while not self.commandQueue.empty():
        command = self.commandQueue.get()
        logger.debug("Took an element of Queue: " + pprint.pformat(command))
        if command['commandType'] == self.EXECUTION_COMMAND:
          try:
            #pass a copy of action since we don't want anything to change in the
            #action dict
            result = self.executeCommand(command)

          except Exception, err:
            traceback.print_exc()
            logger.warn(err)
            pass

          for entry in result:
            self.resultQueue.put((command['commandType'], entry))

        elif command['commandType'] == self.STATUS_COMMAND:
          try:
            cluster = command['clusterName']
            service = command['serviceName']
            component = command['componentName']
            configurations = command['configurations']
            if configurations.has_key('global'):
              globalConfig = configurations['global']
            else:
              globalConfig = {}
            livestatus = LiveStatus(cluster, service, component,
              globalConfig, self.config)
            result = livestatus.build()
            logger.debug("Got live status for component " + component +\
                         " of service " + str(service) +\
                         " of cluster " + str(cluster))
            logger.debug(pprint.pformat(result))
            if result is not None:
              self.resultQueue.put((ActionQueue.STATUS_COMMAND, result))

          except Exception, err:
            traceback.print_exc()
            logger.warn(err)
          pass
示例#7
0
    def process_status_command_result(self, result):
        '''
    Executes commands of type STATUS_COMMAND
    '''
        try:
            command, component_status_result = result
            cluster = command['clusterName']
            service = command['serviceName']
            component = command['componentName']
            configurations = command['configurations']
            if configurations.has_key('global'):
                globalConfig = configurations['global']
            else:
                globalConfig = {}

            if not Script.config:
                logger.debug(
                    'Setting Script.config to last status command configuration'
                )
                Script.config = command

            livestatus = LiveStatus(cluster, service, component, globalConfig,
                                    self.config, self.configTags)

            component_extra = None

            if component_status_result['exitcode'] == 0:
                component_status = LiveStatus.LIVE_STATUS
                if self.controller.recovery_manager.enabled() \
                  and self.controller.recovery_manager.configured_for_recovery(component):
                    self.controller.recovery_manager.update_current_status(
                        component, component_status)
            else:
                component_status = LiveStatus.DEAD_STATUS
                if self.controller.recovery_manager.enabled() \
                  and self.controller.recovery_manager.configured_for_recovery(component):
                    if (self.controller.recovery_manager.get_current_status(
                            component) !=
                            self.controller.recovery_manager.INSTALL_FAILED):
                        self.controller.recovery_manager.update_current_status(
                            component, component_status)

            request_execution_cmd = self.controller.recovery_manager.requires_recovery(component) and \
                                      not self.controller.recovery_manager.command_exists(component, ActionQueue.EXECUTION_COMMAND)

            if 'structuredOut' in component_status_result:
                component_extra = component_status_result['structuredOut']

            result = livestatus.build(component_status=component_status)
            if self.controller.recovery_manager.enabled():
                result['sendExecCmdDet'] = str(request_execution_cmd)

            if component_extra is not None and len(component_extra) != 0:
                if component_extra.has_key('alerts'):
                    result['alerts'] = component_extra['alerts']
                    del component_extra['alerts']

                result['extra'] = component_extra

            logger.debug("Got live status for component " + component + \
                         " of service " + str(service) + \
                         " of cluster " + str(cluster))

            logger.debug(pprint.pformat(result))
            if result is not None:
                self.commandStatuses.put_command_status(command, result)
        except Exception, err:
            traceback.print_exc()
            logger.warn(err)
示例#8
0
    def execute_status_command(self, command):
        '''
    Executes commands of type STATUS_COMMAND
    '''
        try:
            cluster = command['clusterName']
            service = command['serviceName']
            component = command['componentName']
            configurations = command['configurations']
            if configurations.has_key('global'):
                globalConfig = configurations['global']
            else:
                globalConfig = {}

            livestatus = LiveStatus(cluster, service, component, globalConfig,
                                    self.config, self.configTags)

            component_extra = None

            # For custom services, responsibility to determine service status is
            # delegated to python scripts
            component_status_result = self.customServiceOrchestrator.requestComponentStatus(
                command)
            component_security_status_result = self.customServiceOrchestrator.requestComponentSecurityState(
                command)

            if component_status_result['exitcode'] == 0:
                component_status = LiveStatus.LIVE_STATUS
                if self.controller.recovery_manager.enabled() \
                  and self.controller.recovery_manager.configured_for_recovery(component):
                    self.controller.recovery_manager.update_current_status(
                        component, component_status)
            else:
                component_status = LiveStatus.DEAD_STATUS
                if self.controller.recovery_manager.enabled() \
                  and self.controller.recovery_manager.configured_for_recovery(component):
                    if (self.controller.recovery_manager.get_current_status(
                            component) !=
                            self.controller.recovery_manager.INSTALL_FAILED):
                        self.controller.recovery_manager.update_current_status(
                            component, component_status)

            request_execution_cmd = self.controller.recovery_manager.requires_recovery(component) and \
                                      not self.controller.recovery_manager.command_exists(component, ActionQueue.EXECUTION_COMMAND)

            if 'structuredOut' in component_status_result:
                component_extra = component_status_result['structuredOut']

            result = livestatus.build(component_status=component_status)
            if self.controller.recovery_manager.enabled():
                result['sendExecCmdDet'] = str(request_execution_cmd)

            # Add security state to the result
            result['securityState'] = component_security_status_result

            if component_extra is not None and len(component_extra) != 0:
                if component_extra.has_key('alerts'):
                    result['alerts'] = component_extra['alerts']
                    del component_extra['alerts']

                result['extra'] = component_extra

            logger.debug("Got live status for component " + component + \
                         " of service " + str(service) + \
                         " of cluster " + str(cluster))

            logger.debug(pprint.pformat(result))
            if result is not None:
                self.commandStatuses.put_command_status(command, result)
        except Exception, err:
            traceback.print_exc()
            logger.warn(err)
示例#9
0
  def execute_status_command(self, command):
    '''
    Executes commands of type STATUS_COMMAND
    '''
    try:
      cluster = command['clusterName']
      service = command['serviceName']
      component = command['componentName']
      configurations = command['configurations']
      if configurations.has_key('global'):
        globalConfig = configurations['global']
      else:
        globalConfig = {}

      livestatus = LiveStatus(cluster, service, component,
                              globalConfig, self.config, self.configTags)

      component_extra = None

      # For custom services, responsibility to determine service status is
      # delegated to python scripts
      component_status_result = self.customServiceOrchestrator.requestComponentStatus(command)
      component_security_status_result = self.customServiceOrchestrator.requestComponentSecurityState(command)

      if component_status_result['exitcode'] == 0:
        component_status = LiveStatus.LIVE_STATUS
        if self.controller.recovery_manager.enabled() \
          and self.controller.recovery_manager.configured_for_recovery(component):
          self.controller.recovery_manager.update_current_status(component, component_status)
      else:
        component_status = LiveStatus.DEAD_STATUS
        if self.controller.recovery_manager.enabled() \
          and self.controller.recovery_manager.configured_for_recovery(component):
          if (self.controller.recovery_manager.get_current_status(component) != self.controller.recovery_manager.INSTALL_FAILED):
            self.controller.recovery_manager.update_current_status(component, component_status)

      request_execution_cmd = self.controller.recovery_manager.requires_recovery(component) and \
                                not self.controller.recovery_manager.command_exists(component, ActionQueue.EXECUTION_COMMAND)

      if 'structuredOut' in component_status_result:
        component_extra = component_status_result['structuredOut']

      result = livestatus.build(component_status=component_status)
      if self.controller.recovery_manager.enabled():
        result['sendExecCmdDet'] = str(request_execution_cmd)

      # Add security state to the result
      result['securityState'] = component_security_status_result

      if component_extra is not None and len(component_extra) != 0:
        if component_extra.has_key('alerts'):
          result['alerts'] = component_extra['alerts']
          del component_extra['alerts']

        result['extra'] = component_extra

      logger.debug("Got live status for component " + component + \
                   " of service " + str(service) + \
                   " of cluster " + str(cluster))

      logger.debug(pprint.pformat(result))
      if result is not None:
        self.commandStatuses.put_command_status(command, result)
    except Exception, err:
      traceback.print_exc()
      logger.warn(err)