def executeCommand(self, command): clusterName = command['clusterName'] commandId = command['commandId'] hostname = command['hostname'] params = command['hostLevelParams'] clusterHostInfo = command['clusterHostInfo'] roleCommand = command['roleCommand'] serviceName = command['serviceName'] configurations = command['configurations'] result = [] logger.info("Executing command with id = " + str(commandId) +\ " for role = " + command['role'] + " of " +\ "cluster " + clusterName) logger.debug(pprint.pformat(command)) taskId = command['taskId'] # Preparing 'IN_PROGRESS' report self.commandInProgress = { 'role': command['role'], 'actionId': commandId, 'taskId': taskId, 'clusterName': clusterName, 'serviceName': serviceName, 'tmpout': self.tmpdir + os.sep + 'output-' + str(taskId) + '.txt', 'tmperr': self.tmpdir + os.sep + 'errors-' + str(taskId) + '.txt', 'roleCommand': roleCommand } # running command if command['commandType'] == ActionQueue.EXECUTION_COMMAND: if command['roleCommand'] == ActionQueue.UPGRADE_STATUS: commandresult = self.upgradeExecutor.perform_stack_upgrade(command, self.commandInProgress['tmpout'], self.commandInProgress['tmperr']) else: commandresult = self.puppetExecutor.runCommand(command, self.commandInProgress['tmpout'], self.commandInProgress['tmperr']) # dumping results self.commandInProgress = None status = "COMPLETED" if commandresult['exitcode'] != 0: status = "FAILED" # assume some puppet plumbing to run these commands roleResult = {'role': command['role'], 'actionId': commandId, 'taskId': command['taskId'], 'stdout': commandresult['stdout'], 'clusterName': clusterName, 'stderr': commandresult['stderr'], 'exitCode': commandresult['exitcode'], 'serviceName': serviceName, 'status': status, 'roleCommand': roleCommand} if roleResult['stdout'] == '': roleResult['stdout'] = 'None' if roleResult['stderr'] == '': roleResult['stderr'] = 'None' # let ambari know that configuration tags were applied if status == 'COMPLETED': configHandler = ActualConfigHandler(self.config) if command.has_key('configurationTags'): configHandler.write_actual(command['configurationTags']) roleResult['configurationTags'] = command['configurationTags'] if command.has_key('roleCommand') and command['roleCommand'] == 'START': configHandler.copy_to_component(command['role']) roleResult['configurationTags'] = configHandler.read_actual_component(command['role']) result.append(roleResult) return result
def executeCommand(self, command): clusterName = command['clusterName'] commandId = command['commandId'] hostname = command['hostname'] params = command['hostLevelParams'] clusterHostInfo = command['clusterHostInfo'] roleCommand = command['roleCommand'] serviceName = command['serviceName'] configurations = command['configurations'] result = [] logger.info("Executing command with id = " + str(commandId) +\ " for role = " + command['role'] + " of " +\ "cluster " + clusterName) logger.debug(pprint.pformat(command)) taskId = command['taskId'] # Preparing 'IN_PROGRESS' report self.commandInProgress = { 'role': command['role'], 'actionId': commandId, 'taskId': taskId, 'clusterName': clusterName, 'serviceName': serviceName, 'tmpout': self.tmpdir + os.sep + 'output-' + str(taskId) + '.txt', 'tmperr': self.tmpdir + os.sep + 'errors-' + str(taskId) + '.txt', 'roleCommand': roleCommand } # running command if command['commandType'] == ActionQueue.EXECUTION_COMMAND: if command['roleCommand'] == ActionQueue.UPGRADE_STATUS: commandresult = self.upgradeExecutor.perform_stack_upgrade( command, self.commandInProgress['tmpout'], self.commandInProgress['tmperr']) else: commandresult = self.puppetExecutor.runCommand( command, self.commandInProgress['tmpout'], self.commandInProgress['tmperr']) # dumping results self.commandInProgress = None status = "COMPLETED" if commandresult['exitcode'] != 0: status = "FAILED" # assume some puppet plumbing to run these commands roleResult = { 'role': command['role'], 'actionId': commandId, 'taskId': command['taskId'], 'stdout': commandresult['stdout'], 'clusterName': clusterName, 'stderr': commandresult['stderr'], 'exitCode': commandresult['exitcode'], 'serviceName': serviceName, 'status': status, 'roleCommand': roleCommand } if roleResult['stdout'] == '': roleResult['stdout'] = 'None' if roleResult['stderr'] == '': roleResult['stderr'] = 'None' # let ambari know that configuration tags were applied if status == 'COMPLETED': configHandler = ActualConfigHandler(self.config) if command.has_key('configurationTags'): configHandler.write_actual(command['configurationTags']) roleResult['configurationTags'] = command['configurationTags'] if command.has_key( 'roleCommand') and command['roleCommand'] == 'START': configHandler.copy_to_component(command['role']) roleResult[ 'configurationTags'] = configHandler.read_actual_component( command['role']) result.append(roleResult) return result
def execute_command(self, command): ''' Executes commands of type EXECUTION_COMMAND ''' clusterName = command['clusterName'] commandId = command['commandId'] logger.info("Executing command with id = " + str(commandId) +\ " for role = " + command['role'] + " of " +\ "cluster " + clusterName) logger.debug(pprint.pformat(command)) taskId = command['taskId'] # 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', 'status': self.IN_PROGRESS_STATUS }) self.commandStatuses.put_command_status(command, in_progress_status) # TODO: Add CustomServiceOrchestrator call somewhere here # running command # Create a new instance of executor for the current thread puppetExecutor = PuppetExecutor.PuppetExecutor( self.config.get('puppet', 'puppetmodules'), self.config.get('puppet', 'puppet_home'), self.config.get('puppet', 'facter_home'), self.config.get('agent', 'prefix'), self.config) commandresult = puppetExecutor.runCommand(command, in_progress_status['tmpout'], in_progress_status['tmperr']) # dumping results status = self.COMPLETED_STATUS if commandresult['exitcode'] != 0: status = self.FAILED_STATUS roleResult = self.commandStatuses.generate_report_template(command) # assume some puppet plumbing to run these commands roleResult.update({ 'stdout': commandresult['stdout'], 'stderr': commandresult['stderr'], 'exitCode': commandresult['exitcode'], 'status': status, }) if roleResult['stdout'] == '': roleResult['stdout'] = 'None' if roleResult['stderr'] == '': roleResult['stderr'] = 'None' # let ambari know that configuration tags were applied if status == self.COMPLETED_STATUS: configHandler = ActualConfigHandler(self.config) if command.has_key('configurationTags'): configHandler.write_actual(command['configurationTags']) roleResult['configurationTags'] = command['configurationTags'] component = { 'serviceName': command['serviceName'], 'componentName': command['role'] } if command.has_key('roleCommand') and \ (command['roleCommand'] == self.ROLE_COMMAND_START or \ (command['roleCommand'] == self.ROLE_COMMAND_INSTALL \ and component in LiveStatus.CLIENT_COMPONENTS)): configHandler.copy_to_component(command['role']) roleResult[ 'configurationTags'] = configHandler.read_actual_component( command['role']) self.commandStatuses.put_command_status(command, roleResult)
def execute_command(self, command): ''' Executes commands of type EXECUTION_COMMAND ''' clusterName = command['clusterName'] commandId = command['commandId'] command_format = self.determine_command_format_version(command) message = "Executing command with id = {commandId} for role = {role} of " \ "cluster {cluster}. Command format={command_format}".format( commandId = str(commandId), role=command['role'], cluster=clusterName, command_format=command_format) logger.info(message) logger.debug(pprint.pformat(command)) taskId = command['taskId'] # 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 }) self.commandStatuses.put_command_status(command, in_progress_status) # running command if command_format == self.COMMAND_FORMAT_V1: # Create a new instance of executor for the current thread puppetExecutor = PuppetExecutor.PuppetExecutor( self.config.get('puppet', 'puppetmodules'), self.config.get('puppet', 'puppet_home'), self.config.get('puppet', 'facter_home'), self.config.get('agent', 'prefix'), self.config) commandresult = puppetExecutor.runCommand( command, in_progress_status['tmpout'], in_progress_status['tmperr']) else: commandresult = self.customServiceOrchestrator.runCommand( command, in_progress_status['tmpout'], in_progress_status['tmperr']) # dumping results status = self.COMPLETED_STATUS if commandresult['exitcode'] != 0: status = self.FAILED_STATUS roleResult = self.commandStatuses.generate_report_template(command) # assume some puppet plumbing to run these commands roleResult.update({ 'stdout': commandresult['stdout'], 'stderr': commandresult['stderr'], 'exitCode': commandresult['exitcode'], 'status': status, }) 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 ambari know that configuration tags were applied if status == self.COMPLETED_STATUS: configHandler = ActualConfigHandler(self.config) if command.has_key('configurationTags'): configHandler.write_actual(command['configurationTags']) roleResult['configurationTags'] = command['configurationTags'] component = { 'serviceName': command['serviceName'], 'componentName': command['role'] } if command.has_key('roleCommand') and \ (command['roleCommand'] == self.ROLE_COMMAND_START or \ (command['roleCommand'] == self.ROLE_COMMAND_INSTALL \ and component in LiveStatus.CLIENT_COMPONENTS) or \ (command['roleCommand'] == self.ROLE_COMMAND_CUSTOM_COMMAND and \ command['hostLevelParams'].has_key('custom_command') and \ command['hostLevelParams']['custom_command'] == self.CUSTOM_COMMAND_RESTART)): configHandler.copy_to_component(command['role']) roleResult[ 'configurationTags'] = configHandler.read_actual_component( command['role']) self.commandStatuses.put_command_status(command, roleResult)