def execute_status_command(self, command):
    '''
    Executes commands of type STATUS_COMMAND
    '''
    try:
      cluster = command['clusterName']
      service = command['serviceName']
      component = command['componentName']
      reportResult = CommandStatusDict.shouldReportResult(command)
      component_status = self.customServiceOrchestrator.requestComponentStatus(command)

      result = {"componentName": component,
                "msg": "",
                "clusterName": cluster,
                "serviceName": service,
                "reportResult": reportResult,
                "roleCommand": command['roleCommand']
      }

      if 'configurations' in component_status:
        result['configurations'] = component_status['configurations']
      if Constants.EXIT_CODE in component_status:
        result['status'] = component_status[Constants.EXIT_CODE]
        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, reportResult)
    except Exception, err:
      traceback.print_exc()
      logger.warn(err)
Example #2
0
    def execute_status_command(self, command):
        '''
    Executes commands of type STATUS_COMMAND
    '''
        try:
            cluster = command['clusterName']
            service = command['serviceName']
            component = command['componentName']
            reportResult = CommandStatusDict.shouldReportResult(command)
            component_status = None
            if self.docker_mode:
                component_status = self.dockerManager.query_status(command)
            elif self.yarn_docker_mode:
                component_status = self.yarnDockerManager.query_status(command)
            else:
                component_status = self.customServiceOrchestrator.requestComponentStatus(
                    command)

            result = {
                "componentName": component,
                "msg": "",
                "clusterName": cluster,
                "serviceName": service,
                "reportResult": reportResult,
                "roleCommand": command['roleCommand']
            }

            if 'configurations' in component_status:
                result['configurations'] = component_status['configurations']
            if Constants.EXIT_CODE in component_status:
                result['status'] = component_status[Constants.EXIT_CODE]
                logger.debug("Got live status for component " + component + \
                             " of service " + str(service) + \
                             " of cluster " + str(cluster))
                logger.debug(pprint.pformat(result))
            if 'ip' in component_status:
                result['ip'] = component_status['ip']
            if 'hostname' in component_status:
                result['hostname'] = component_status['hostname']

            if result is not None:
                logger.debug("result of execute_status_command: " +
                             str(result))
                self.commandStatuses.put_command_status(
                    command, result, reportResult)
        except Exception, err:
            traceback.print_exc()
            logger.warn(err)
  def execute_command(self, command):
    '''
    Executes commands of type  EXECUTION_COMMAND
    '''
    clusterName = command['clusterName']
    commandId = command['commandId']

    message = "Executing command with id = {commandId} for role = {role} of " \
              "cluster {cluster}".format(
      commandId=str(commandId), role=command['role'],
      cluster=clusterName)
    logger.info(message)
    logger.debug(pprint.pformat(command))

    taskId = command['taskId']

    # if auto generated then do not report result
    reportResult = CommandStatusDict.shouldReportResult(command)

    # Preparing 'IN_PROGRESS' report
    in_progress_status = self.commandStatuses.generate_report_template(command)
    in_progress_status.update({
      'tmpout': self.tmpdir + os.sep + 'output-' + str(taskId) + '.txt',
      'tmperr': self.tmpdir + os.sep + 'errors-' + str(taskId) + '.txt',
      'structuredOut': self.tmpdir + os.sep + 'structured-out-' + str(
        taskId) + '.json',
      'status': self.IN_PROGRESS_STATUS,
      'reportResult': reportResult
    })
    self.commandStatuses.put_command_status(command, in_progress_status, reportResult)

    store_config = False
    if ActionQueue.STORE_APPLIED_CONFIG in command['commandParams']:
      store_config = 'true' == command['commandParams'][ActionQueue.STORE_APPLIED_CONFIG]
    store_command = False
    if 'roleParams' in command and ActionQueue.AUTO_RESTART in command['roleParams']:
      store_command = 'true' == command['roleParams'][ActionQueue.AUTO_RESTART]

    if store_command:
      logger.info("Component has indicated auto-restart. Saving details from START command.")

    # running command
    commandresult = self.customServiceOrchestrator.runCommand(command,
                                                              in_progress_status[
                                                                'tmpout'],
                                                              in_progress_status[
                                                                'tmperr'],
                                                              True,
                                                              store_config or store_command)
    # If command is STOP then set flag to indicate stop has been triggered.
    # In future we might check status of STOP command and take other measures
    # if graceful STOP fails (like force kill the processes)
    if command['roleCommand'] == 'STOP':
      self.controller.appGracefulStopTriggered = True

    # dumping results
    status = self.COMPLETED_STATUS
    if commandresult[Constants.EXIT_CODE] != 0:
      status = self.FAILED_STATUS
    roleResult = self.commandStatuses.generate_report_template(command)
    roleResult.update({
      'stdout': commandresult['stdout'],
      'stderr': commandresult['stderr'],
      Constants.EXIT_CODE: commandresult[Constants.EXIT_CODE],
      'status': status,
      'reportResult': reportResult
    })
    if roleResult['stdout'] == '':
      roleResult['stdout'] = 'None'
    if roleResult['stderr'] == '':
      roleResult['stderr'] = 'None'

    if 'structuredOut' in commandresult:
      roleResult['structuredOut'] = str(commandresult['structuredOut'])
    else:
      roleResult['structuredOut'] = ''
      # let server know that configuration tags were applied
    if status == self.COMPLETED_STATUS:
      if 'configurationTags' in command:
        roleResult['configurationTags'] = command['configurationTags']
      if Constants.ALLOCATED_PORTS in commandresult:
        roleResult['allocatedPorts'] = commandresult[Constants.ALLOCATED_PORTS]
      if Constants.FOLDERS in commandresult:
        roleResult['folders'] = commandresult[Constants.FOLDERS]
    self.commandStatuses.put_command_status(command, roleResult, reportResult)
Example #4
0
    def execute_command(self, command):
        '''
    Executes commands of type  EXECUTION_COMMAND
    '''
        clusterName = command['clusterName']
        commandId = command['commandId']

        message = "Executing command with id = {commandId} for role = {role} of " \
                  "cluster {cluster}".format(
          commandId=str(commandId), role=command['role'],
          cluster=clusterName)
        logger.info(message)
        logger.debug(pprint.pformat(command))

        taskId = command['taskId']

        # if auto generated then do not report result
        reportResult = CommandStatusDict.shouldReportResult(command)

        # Preparing 'IN_PROGRESS' report
        in_progress_status = self.commandStatuses.generate_report_template(
            command)
        in_progress_status.update({
            'tmpout':
            self.tmpdir + os.sep + 'output-' + str(taskId) + '.txt',
            'tmperr':
            self.tmpdir + os.sep + 'errors-' + str(taskId) + '.txt',
            'structuredOut':
            self.tmpdir + os.sep + 'structured-out-' + str(taskId) + '.json',
            'status':
            self.IN_PROGRESS_STATUS,
            'reportResult':
            reportResult
        })
        self.commandStatuses.put_command_status(command, in_progress_status,
                                                reportResult)

        store_config = False
        if ActionQueue.STORE_APPLIED_CONFIG in command['commandParams']:
            store_config = 'true' == command['commandParams'][
                ActionQueue.STORE_APPLIED_CONFIG]
        store_command = False
        if 'roleParams' in command and ActionQueue.AUTO_RESTART in command[
                'roleParams']:
            logger.info(
                "Component has indicated auto-restart. Saving details from START command."
            )
            store_command = 'true' == command['roleParams'][
                ActionQueue.AUTO_RESTART]

        # running command
        commandresult = self.customServiceOrchestrator.runCommand(
            command, in_progress_status['tmpout'],
            in_progress_status['tmperr'], True, store_config or store_command)
        # dumping results
        status = self.COMPLETED_STATUS
        if commandresult[Constants.EXIT_CODE] != 0:
            status = self.FAILED_STATUS
        roleResult = self.commandStatuses.generate_report_template(command)
        roleResult.update({
            'stdout':
            commandresult['stdout'],
            'stderr':
            commandresult['stderr'],
            Constants.EXIT_CODE:
            commandresult[Constants.EXIT_CODE],
            'status':
            status,
            'reportResult':
            reportResult
        })
        if roleResult['stdout'] == '':
            roleResult['stdout'] = 'None'
        if roleResult['stderr'] == '':
            roleResult['stderr'] = 'None'

        if 'structuredOut' in commandresult:
            roleResult['structuredOut'] = str(commandresult['structuredOut'])
        else:
            roleResult['structuredOut'] = ''
            # let server know that configuration tags were applied
        if status == self.COMPLETED_STATUS:
            if 'configurationTags' in command:
                roleResult['configurationTags'] = command['configurationTags']
            if Constants.ALLOCATED_PORTS in commandresult:
                roleResult['allocatedPorts'] = commandresult[
                    Constants.ALLOCATED_PORTS]
            if Constants.FOLDERS in commandresult:
                roleResult['folders'] = commandresult[Constants.FOLDERS]
        self.commandStatuses.put_command_status(command, roleResult,
                                                reportResult)
Example #5
0
    def execute_command(self, command):
        '''
    Executes commands of type  EXECUTION_COMMAND
    '''
        clusterName = command['clusterName']
        commandId = command['commandId']
        if 'package' in command:
            self.componentPackage = command['package']
        else:
            self.componentPackage = ''

        logger.info("Package received: " + self.componentPackage)

        message = "Executing command with id = {commandId} for role = {role} of " \
                  "cluster {cluster}".format(
          commandId=str(commandId), role=command['role'],
          cluster=clusterName)
        logger.info(message)
        logger.debug(pprint.pformat(command))

        taskId = command['taskId']

        # if auto generated then do not report result
        reportResult = CommandStatusDict.shouldReportResult(command)

        # Preparing 'IN_PROGRESS' report
        in_progress_status = self.commandStatuses.generate_report_template(
            command)
        in_progress_status.update({
            'tmpout':
            self.tmpdir + os.sep + 'output-' + str(taskId) + '.txt',
            'tmperr':
            self.tmpdir + os.sep + 'errors-' + str(taskId) + '.txt',
            'structuredOut':
            self.tmpdir + os.sep + 'structured-out-' + str(taskId) + '.json',
            'status':
            self.IN_PROGRESS_STATUS,
            'reportResult':
            reportResult
        })
        self.commandStatuses.put_command_status(command, in_progress_status,
                                                reportResult)

        store_config = False
        if ActionQueue.STORE_APPLIED_CONFIG in command['commandParams']:
            store_config = 'true' == command['commandParams'][
                ActionQueue.STORE_APPLIED_CONFIG]
        store_command = False
        if 'roleParams' in command and command[
                'roleParams'] is not None and ActionQueue.AUTO_RESTART in command[
                    'roleParams']:
            store_command = 'true' == command['roleParams'][
                ActionQueue.AUTO_RESTART]

        if store_command:
            logger.info(
                "Component has indicated auto-restart. Saving details from START command."
            )

        logger.info("Running command: " + str(command))

        if 'configurations' in command and 'yarnDockerMode' in command and command[
                'yarnDockerMode'] == True:
            self.yarn_docker_mode = True
            commandresult = self.yarnDockerManager.execute_command(
                command, store_config or store_command)
        elif 'configurations' in command and 'docker' in command[
                'configurations']:
            self.docker_mode = True
            commandresult = self.dockerManager.execute_command(
                command, store_config or store_command)
        else:
            # running command
            commandresult = self.customServiceOrchestrator.runCommand(
                command, in_progress_status['tmpout'],
                in_progress_status['tmperr'], True, store_config
                or store_command)
        # If command is STOP then set flag to indicate stop has been triggered.
        # In future we might check status of STOP command and take other measures
        # if graceful STOP fails (like force kill the processes)
        if command['roleCommand'] == 'STOP':
            logger.info("Stop command received")
            self.controller.appGracefulStopTriggered = True

        # dumping results
        status = self.COMPLETED_STATUS
        if commandresult[Constants.EXIT_CODE] != 0:
            status = self.FAILED_STATUS
        roleResult = self.commandStatuses.generate_report_template(command)
        roleResult.update({
            'stdout':
            commandresult['stdout'],
            'stderr':
            commandresult['stderr'],
            Constants.EXIT_CODE:
            commandresult[Constants.EXIT_CODE],
            'status':
            status,
            'reportResult':
            reportResult
        })
        if roleResult['stdout'] == '':
            roleResult['stdout'] = 'None'
        if roleResult['stderr'] == '':
            roleResult['stderr'] = 'None'

        if 'structuredOut' in commandresult:
            roleResult['structuredOut'] = str(commandresult['structuredOut'])
        else:
            roleResult['structuredOut'] = ''
            # let server know that configuration tags were applied
        if status == self.COMPLETED_STATUS:
            if 'configurationTags' in command:
                roleResult['configurationTags'] = command['configurationTags']
            if Constants.ALLOCATED_PORTS in commandresult:
                roleResult['allocatedPorts'] = commandresult[
                    Constants.ALLOCATED_PORTS]
            if Constants.FOLDERS in commandresult:
                roleResult['folders'] = commandresult[Constants.FOLDERS]
        self.commandStatuses.put_command_status(command, roleResult,
                                                reportResult)