@Test public void testVerificationOfBehaviorForSuccess() throws Exception { final ControlJvmRequest controlCommand = mock(ControlJvmRequest.class); final Jvm jvm = mock(Jvm.class); final String jvmName = "mockJvmName"; String jvmHost = "mockJvmHost"; when(jvm.getJvmName()).thenReturn(jvmName); when(jvm.getHostName()).thenReturn(jvmHost); final Identifier<Jvm> jvmId = mock(Identifier.class); final JvmControlOperation controlOperation = JvmControlOperation.STOP; final CommandOutput mockExecData = mock(CommandOutput.class); when(jvm.getId()).thenReturn(Identifier.<Jvm>id(1L)); when(controlCommand.getJvmId()).thenReturn(jvmId); when(controlCommand.getControlOperation()).thenReturn(controlOperation); when(Config.mockJvmPersistenceService.getJvm(jvmId)).thenReturn(jvm); when(mockExecData.getReturnCode()).thenReturn(new ExecReturnCode(0)); when(Config.mockJvmCommandFactory.executeCommand(any(Jvm.class), any(JvmControlOperation.class))).thenReturn(new RemoteCommandReturnInfo(0, "", "")); jvmControlService.controlJvm(controlCommand, user); verify(Config.mockJvmPersistenceService, times(1)).getJvm(eq(jvmId)); verify(Config.mockJvmCommandFactory).executeCommand(any(Jvm.class), any(JvmControlOperation.class)); verify(Config.mockJvmStateService, times(1)).updateState(any(Jvm.class), any(JvmState.class)); verify(Config.mockHistoryFacadeService).write(anyString(), anyList(), anyString(), any(EventType.class), anyString()); when(Config.mockJvmCommandFactory.executeCommand(any(Jvm.class), any(JvmControlOperation.class))).thenReturn(new RemoteCommandReturnInfo(ExecReturnCode.JWALA_EXIT_CODE_ABNORMAL_SUCCESS, "Abnormal success", "")); CommandOutput returnOutput = jvmControlService.controlJvm(controlCommand, user); assertTrue(returnOutput.getReturnCode().getWasSuccessful()); when(jvm.getState()).thenReturn(JvmState.JVM_STARTED); when(Config.mockJvmCommandFactory.executeCommand(any(Jvm.class), any(JvmControlOperation.class))).thenReturn(new RemoteCommandReturnInfo(ExecReturnCode.JWALA_EXIT_CODE_NO_OP, "No op", "")); returnOutput = jvmControlService.controlJvm(controlCommand, user); assertFalse(returnOutput.getReturnCode().getWasSuccessful()); when(Config.mockRemoteCommandExecutorService.executeCommand(any(RemoteExecCommand.class))).thenReturn(new RemoteCommandReturnInfo(ExecReturnCode.JWALA_EXIT_CODE_FAST_FAIL, "", "Fast Fail")); try { jvmControlService.controlJvm(controlCommand, user); } catch (ExternalSystemErrorException ee) { assertEquals(ee.getMessageResponseStatus(), FaultType.FAST_FAIL); } when(Config.mockRemoteCommandExecutorService.executeCommand(any(RemoteExecCommand.class))).thenReturn(new RemoteCommandReturnInfo(ExecReturnCode.JWALA_EXIT_NO_SUCH_SERVICE, "", "No such service")); try { jvmControlService.controlJvm(controlCommand, user); } catch (ExternalSystemErrorException ee) { assertEquals(ee.getMessageResponseStatus(), FaultType.REMOTE_COMMAND_FAILURE); } when(Config.mockJvmCommandFactory.executeCommand(any(Jvm.class), any(JvmControlOperation.class))).thenReturn(new RemoteCommandReturnInfo(ExecReturnCode.JWALA_EXIT_PROCESS_KILLED, "", "Process killed")); returnOutput = jvmControlService.controlJvm(controlCommand, user); assertEquals("FORCED STOPPED", returnOutput.getStandardOutput()); when(Config.mockRemoteCommandExecutorService.executeCommand(any(RemoteExecCommand.class))).thenReturn(new RemoteCommandReturnInfo(88, "", "Process default error")); try { jvmControlService.controlJvm(controlCommand, user); } catch (ExternalSystemErrorException ee) { assertEquals(ee.getMessageResponseStatus(), FaultType.REMOTE_COMMAND_FAILURE); } when(controlCommand.getControlOperation()).thenReturn(JvmControlOperation.HEAP_DUMP); when(Config.mockJvmCommandFactory.executeCommand(any(Jvm.class), any(JvmControlOperation.class))).thenReturn(new RemoteCommandReturnInfo(ExecReturnCode.JWALA_EXIT_CODE_ABNORMAL_SUCCESS, "Abnormal success", "")); returnOutput = jvmControlService.controlJvm(controlCommand, user); assertFalse(returnOutput.getReturnCode().getWasSuccessful()); when(controlCommand.getControlOperation()).thenReturn(JvmControlOperation.START); when(Config.mockJvmCommandFactory.executeCommand(any(Jvm.class), any(JvmControlOperation.class))).thenReturn(new RemoteCommandReturnInfo(88, "The requested service has already been started", "")); returnOutput = jvmControlService.controlJvm(controlCommand, user); assertFalse(returnOutput.getReturnCode().getWasSuccessful()); }
@Override public CommandOutput controlJvm(final ControlJvmRequest controlJvmRequest, final User aUser) { final JvmControlOperation controlOperation = controlJvmRequest.getControlOperation(); LOGGER.debug("Control JVM request operation = {}", controlOperation.toString()); final Jvm jvm = jvmPersistenceService.getJvm(controlJvmRequest.getJvmId()); try { final String historyMessage = controlJvmRequest.getMessage() == null ? controlOperation.name() : controlJvmRequest.getMessage(); historyFacadeService.write(getServerName(jvm), new ArrayList<>(jvm.getGroups()), historyMessage, EventType.USER_ACTION_INFO, aUser.getId()); RemoteCommandReturnInfo remoteCommandReturnInfo = jvmCommandFactory.executeCommand(jvm, controlJvmRequest.getControlOperation()); CommandOutput commandOutput = new CommandOutput(new ExecReturnCode(remoteCommandReturnInfo.retCode), remoteCommandReturnInfo.standardOuput, remoteCommandReturnInfo.errorOupout); final String standardOutput = commandOutput.getStandardOutput(); final ExecReturnCode returnCode = commandOutput.getReturnCode(); if (StringUtils.isNotEmpty(standardOutput) && (JvmControlOperation.START.equals(controlOperation) || JvmControlOperation.STOP.equals(controlOperation))) { commandOutput.cleanStandardOutput(); LOGGER.info("shell command output is {}", standardOutput); } else if (StringUtils.isNoneBlank(standardOutput) && JvmControlOperation.HEAP_DUMP.equals(controlOperation) && returnCode.wasSuccessful()) { commandOutput.cleanHeapDumpStandardOutput(); } LOGGER.debug("JvmCommand output return code = {}", returnCode); if (returnCode.wasSuccessful()) { if (JvmControlOperation.STOP.equals(controlOperation)) { LOGGER.debug("Updating state to {}...", JvmState.JVM_STOPPED); jvmStateService.updateState(jvm, JvmState.JVM_STOPPED); LOGGER.debug("State successfully updated to {}", JvmState.JVM_STOPPED); } } else { String commandOutputReturnDescription = CommandOutputReturnCode.fromReturnCode(returnCode.getReturnCode()).getDesc(); switch (returnCode.getReturnCode()) { case ExecReturnCode.JWALA_EXIT_PROCESS_KILLED: commandOutput = new CommandOutput(new ExecReturnCode(0), FORCED_STOPPED, commandOutput.getStandardError()); jvmStateService.updateState(jvm, JvmState.FORCED_STOPPED); break; case ExecReturnCode.JWALA_EXIT_CODE_ABNORMAL_SUCCESS: int retCode = 0; switch (controlJvmRequest.getControlOperation()) { case START: commandOutputReturnDescription = MSG_SERVICE_ALREADY_STARTED; break; case STOP: commandOutputReturnDescription = MSG_SERVICE_ALREADY_STOPPED; break; default: retCode = returnCode.getReturnCode(); break; } sendMessageToActionEventLog(aUser, jvm, commandOutputReturnDescription); if (retCode == 0) { commandOutput = new CommandOutput(new ExecReturnCode(retCode), commandOutputReturnDescription, null); } break; case ExecReturnCode.JWALA_EXIT_CODE_NO_OP: if (controlOperation.equals(JvmControlOperation.START) || controlOperation.equals(JvmControlOperation.STOP)) { sendMessageToActionEventLog(aUser, jvm, commandOutputReturnDescription); } else { final String errorMsg = getCommandErrorMessage(commandOutput, returnCode, commandOutputReturnDescription); sendMessageToActionEventLog(aUser, jvm, errorMsg); } break; default: final String errorMsg = getCommandErrorMessage(commandOutput, returnCode, commandOutputReturnDescription); sendMessageToActionEventLog(aUser, jvm, errorMsg); break; } } return commandOutput; } catch (final RemoteCommandExecutorServiceException e) { LOGGER.error(e.getMessage(), e); historyFacadeService.write(getServerName(jvm), new ArrayList<>(jvm.getGroups()), e.getMessage(), EventType.SYSTEM_ERROR, aUser.getId()); throw new InternalErrorException(FaultType.REMOTE_COMMAND_FAILURE, "CommandFailureException when attempting to control a JVM: " + controlJvmRequest, e); } }
JvmControlServiceImpl implements JvmControlService { @Override public CommandOutput controlJvm(final ControlJvmRequest controlJvmRequest, final User aUser) { final JvmControlOperation controlOperation = controlJvmRequest.getControlOperation(); LOGGER.debug("Control JVM request operation = {}", controlOperation.toString()); final Jvm jvm = jvmPersistenceService.getJvm(controlJvmRequest.getJvmId()); try { final String historyMessage = controlJvmRequest.getMessage() == null ? controlOperation.name() : controlJvmRequest.getMessage(); historyFacadeService.write(getServerName(jvm), new ArrayList<>(jvm.getGroups()), historyMessage, EventType.USER_ACTION_INFO, aUser.getId()); RemoteCommandReturnInfo remoteCommandReturnInfo = jvmCommandFactory.executeCommand(jvm, controlJvmRequest.getControlOperation()); CommandOutput commandOutput = new CommandOutput(new ExecReturnCode(remoteCommandReturnInfo.retCode), remoteCommandReturnInfo.standardOuput, remoteCommandReturnInfo.errorOupout); final String standardOutput = commandOutput.getStandardOutput(); final ExecReturnCode returnCode = commandOutput.getReturnCode(); if (StringUtils.isNotEmpty(standardOutput) && (JvmControlOperation.START.equals(controlOperation) || JvmControlOperation.STOP.equals(controlOperation))) { commandOutput.cleanStandardOutput(); LOGGER.info("shell command output is {}", standardOutput); } else if (StringUtils.isNoneBlank(standardOutput) && JvmControlOperation.HEAP_DUMP.equals(controlOperation) && returnCode.wasSuccessful()) { commandOutput.cleanHeapDumpStandardOutput(); } LOGGER.debug("JvmCommand output return code = {}", returnCode); if (returnCode.wasSuccessful()) { if (JvmControlOperation.STOP.equals(controlOperation)) { LOGGER.debug("Updating state to {}...", JvmState.JVM_STOPPED); jvmStateService.updateState(jvm, JvmState.JVM_STOPPED); LOGGER.debug("State successfully updated to {}", JvmState.JVM_STOPPED); } } else { String commandOutputReturnDescription = CommandOutputReturnCode.fromReturnCode(returnCode.getReturnCode()).getDesc(); switch (returnCode.getReturnCode()) { case ExecReturnCode.JWALA_EXIT_PROCESS_KILLED: commandOutput = new CommandOutput(new ExecReturnCode(0), FORCED_STOPPED, commandOutput.getStandardError()); jvmStateService.updateState(jvm, JvmState.FORCED_STOPPED); break; case ExecReturnCode.JWALA_EXIT_CODE_ABNORMAL_SUCCESS: int retCode = 0; switch (controlJvmRequest.getControlOperation()) { case START: commandOutputReturnDescription = MSG_SERVICE_ALREADY_STARTED; break; case STOP: commandOutputReturnDescription = MSG_SERVICE_ALREADY_STOPPED; break; default: retCode = returnCode.getReturnCode(); break; } sendMessageToActionEventLog(aUser, jvm, commandOutputReturnDescription); if (retCode == 0) { commandOutput = new CommandOutput(new ExecReturnCode(retCode), commandOutputReturnDescription, null); } break; case ExecReturnCode.JWALA_EXIT_CODE_NO_OP: if (controlOperation.equals(JvmControlOperation.START) || controlOperation.equals(JvmControlOperation.STOP)) { sendMessageToActionEventLog(aUser, jvm, commandOutputReturnDescription); } else { final String errorMsg = getCommandErrorMessage(commandOutput, returnCode, commandOutputReturnDescription); sendMessageToActionEventLog(aUser, jvm, errorMsg); } break; default: final String errorMsg = getCommandErrorMessage(commandOutput, returnCode, commandOutputReturnDescription); sendMessageToActionEventLog(aUser, jvm, errorMsg); break; } } return commandOutput; } catch (final RemoteCommandExecutorServiceException e) { LOGGER.error(e.getMessage(), e); historyFacadeService.write(getServerName(jvm), new ArrayList<>(jvm.getGroups()), e.getMessage(), EventType.SYSTEM_ERROR, aUser.getId()); throw new InternalErrorException(FaultType.REMOTE_COMMAND_FAILURE, "CommandFailureException when attempting to control a JVM: " + controlJvmRequest, e); } } }
JvmControlServiceImpl implements JvmControlService { @Override public CommandOutput controlJvm(final ControlJvmRequest controlJvmRequest, final User aUser) { final JvmControlOperation controlOperation = controlJvmRequest.getControlOperation(); LOGGER.debug("Control JVM request operation = {}", controlOperation.toString()); final Jvm jvm = jvmPersistenceService.getJvm(controlJvmRequest.getJvmId()); try { final String historyMessage = controlJvmRequest.getMessage() == null ? controlOperation.name() : controlJvmRequest.getMessage(); historyFacadeService.write(getServerName(jvm), new ArrayList<>(jvm.getGroups()), historyMessage, EventType.USER_ACTION_INFO, aUser.getId()); RemoteCommandReturnInfo remoteCommandReturnInfo = jvmCommandFactory.executeCommand(jvm, controlJvmRequest.getControlOperation()); CommandOutput commandOutput = new CommandOutput(new ExecReturnCode(remoteCommandReturnInfo.retCode), remoteCommandReturnInfo.standardOuput, remoteCommandReturnInfo.errorOupout); final String standardOutput = commandOutput.getStandardOutput(); final ExecReturnCode returnCode = commandOutput.getReturnCode(); if (StringUtils.isNotEmpty(standardOutput) && (JvmControlOperation.START.equals(controlOperation) || JvmControlOperation.STOP.equals(controlOperation))) { commandOutput.cleanStandardOutput(); LOGGER.info("shell command output is {}", standardOutput); } else if (StringUtils.isNoneBlank(standardOutput) && JvmControlOperation.HEAP_DUMP.equals(controlOperation) && returnCode.wasSuccessful()) { commandOutput.cleanHeapDumpStandardOutput(); } LOGGER.debug("JvmCommand output return code = {}", returnCode); if (returnCode.wasSuccessful()) { if (JvmControlOperation.STOP.equals(controlOperation)) { LOGGER.debug("Updating state to {}...", JvmState.JVM_STOPPED); jvmStateService.updateState(jvm, JvmState.JVM_STOPPED); LOGGER.debug("State successfully updated to {}", JvmState.JVM_STOPPED); } } else { String commandOutputReturnDescription = CommandOutputReturnCode.fromReturnCode(returnCode.getReturnCode()).getDesc(); switch (returnCode.getReturnCode()) { case ExecReturnCode.JWALA_EXIT_PROCESS_KILLED: commandOutput = new CommandOutput(new ExecReturnCode(0), FORCED_STOPPED, commandOutput.getStandardError()); jvmStateService.updateState(jvm, JvmState.FORCED_STOPPED); break; case ExecReturnCode.JWALA_EXIT_CODE_ABNORMAL_SUCCESS: int retCode = 0; switch (controlJvmRequest.getControlOperation()) { case START: commandOutputReturnDescription = MSG_SERVICE_ALREADY_STARTED; break; case STOP: commandOutputReturnDescription = MSG_SERVICE_ALREADY_STOPPED; break; default: retCode = returnCode.getReturnCode(); break; } sendMessageToActionEventLog(aUser, jvm, commandOutputReturnDescription); if (retCode == 0) { commandOutput = new CommandOutput(new ExecReturnCode(retCode), commandOutputReturnDescription, null); } break; case ExecReturnCode.JWALA_EXIT_CODE_NO_OP: if (controlOperation.equals(JvmControlOperation.START) || controlOperation.equals(JvmControlOperation.STOP)) { sendMessageToActionEventLog(aUser, jvm, commandOutputReturnDescription); } else { final String errorMsg = getCommandErrorMessage(commandOutput, returnCode, commandOutputReturnDescription); sendMessageToActionEventLog(aUser, jvm, errorMsg); } break; default: final String errorMsg = getCommandErrorMessage(commandOutput, returnCode, commandOutputReturnDescription); sendMessageToActionEventLog(aUser, jvm, errorMsg); break; } } return commandOutput; } catch (final RemoteCommandExecutorServiceException e) { LOGGER.error(e.getMessage(), e); historyFacadeService.write(getServerName(jvm), new ArrayList<>(jvm.getGroups()), e.getMessage(), EventType.SYSTEM_ERROR, aUser.getId()); throw new InternalErrorException(FaultType.REMOTE_COMMAND_FAILURE, "CommandFailureException when attempting to control a JVM: " + controlJvmRequest, e); } } JvmControlServiceImpl(final JvmPersistenceService jvmPersistenceService,
                                 final JvmStateService jvmStateService,
                                 final HistoryFacadeService historyFacadeService); }
JvmControlServiceImpl implements JvmControlService { @Override public CommandOutput controlJvm(final ControlJvmRequest controlJvmRequest, final User aUser) { final JvmControlOperation controlOperation = controlJvmRequest.getControlOperation(); LOGGER.debug("Control JVM request operation = {}", controlOperation.toString()); final Jvm jvm = jvmPersistenceService.getJvm(controlJvmRequest.getJvmId()); try { final String historyMessage = controlJvmRequest.getMessage() == null ? controlOperation.name() : controlJvmRequest.getMessage(); historyFacadeService.write(getServerName(jvm), new ArrayList<>(jvm.getGroups()), historyMessage, EventType.USER_ACTION_INFO, aUser.getId()); RemoteCommandReturnInfo remoteCommandReturnInfo = jvmCommandFactory.executeCommand(jvm, controlJvmRequest.getControlOperation()); CommandOutput commandOutput = new CommandOutput(new ExecReturnCode(remoteCommandReturnInfo.retCode), remoteCommandReturnInfo.standardOuput, remoteCommandReturnInfo.errorOupout); final String standardOutput = commandOutput.getStandardOutput(); final ExecReturnCode returnCode = commandOutput.getReturnCode(); if (StringUtils.isNotEmpty(standardOutput) && (JvmControlOperation.START.equals(controlOperation) || JvmControlOperation.STOP.equals(controlOperation))) { commandOutput.cleanStandardOutput(); LOGGER.info("shell command output is {}", standardOutput); } else if (StringUtils.isNoneBlank(standardOutput) && JvmControlOperation.HEAP_DUMP.equals(controlOperation) && returnCode.wasSuccessful()) { commandOutput.cleanHeapDumpStandardOutput(); } LOGGER.debug("JvmCommand output return code = {}", returnCode); if (returnCode.wasSuccessful()) { if (JvmControlOperation.STOP.equals(controlOperation)) { LOGGER.debug("Updating state to {}...", JvmState.JVM_STOPPED); jvmStateService.updateState(jvm, JvmState.JVM_STOPPED); LOGGER.debug("State successfully updated to {}", JvmState.JVM_STOPPED); } } else { String commandOutputReturnDescription = CommandOutputReturnCode.fromReturnCode(returnCode.getReturnCode()).getDesc(); switch (returnCode.getReturnCode()) { case ExecReturnCode.JWALA_EXIT_PROCESS_KILLED: commandOutput = new CommandOutput(new ExecReturnCode(0), FORCED_STOPPED, commandOutput.getStandardError()); jvmStateService.updateState(jvm, JvmState.FORCED_STOPPED); break; case ExecReturnCode.JWALA_EXIT_CODE_ABNORMAL_SUCCESS: int retCode = 0; switch (controlJvmRequest.getControlOperation()) { case START: commandOutputReturnDescription = MSG_SERVICE_ALREADY_STARTED; break; case STOP: commandOutputReturnDescription = MSG_SERVICE_ALREADY_STOPPED; break; default: retCode = returnCode.getReturnCode(); break; } sendMessageToActionEventLog(aUser, jvm, commandOutputReturnDescription); if (retCode == 0) { commandOutput = new CommandOutput(new ExecReturnCode(retCode), commandOutputReturnDescription, null); } break; case ExecReturnCode.JWALA_EXIT_CODE_NO_OP: if (controlOperation.equals(JvmControlOperation.START) || controlOperation.equals(JvmControlOperation.STOP)) { sendMessageToActionEventLog(aUser, jvm, commandOutputReturnDescription); } else { final String errorMsg = getCommandErrorMessage(commandOutput, returnCode, commandOutputReturnDescription); sendMessageToActionEventLog(aUser, jvm, errorMsg); } break; default: final String errorMsg = getCommandErrorMessage(commandOutput, returnCode, commandOutputReturnDescription); sendMessageToActionEventLog(aUser, jvm, errorMsg); break; } } return commandOutput; } catch (final RemoteCommandExecutorServiceException e) { LOGGER.error(e.getMessage(), e); historyFacadeService.write(getServerName(jvm), new ArrayList<>(jvm.getGroups()), e.getMessage(), EventType.SYSTEM_ERROR, aUser.getId()); throw new InternalErrorException(FaultType.REMOTE_COMMAND_FAILURE, "CommandFailureException when attempting to control a JVM: " + controlJvmRequest, e); } } JvmControlServiceImpl(final JvmPersistenceService jvmPersistenceService,
                                 final JvmStateService jvmStateService,
                                 final HistoryFacadeService historyFacadeService); @Override CommandOutput controlJvm(final ControlJvmRequest controlJvmRequest, final User aUser); @Override CommandOutput controlJvmSynchronously(final ControlJvmRequest controlJvmRequest, final long timeout,
                                                 final User user); @Override CommandOutput secureCopyFile(final ControlJvmRequest secureCopyRequest, final String sourcePath,
                                        final String destPath, String userId, boolean overwrite); @Override CommandOutput executeChangeFileModeCommand(final Jvm jvm, final String modifiedPermissions, final String targetAbsoluteDir, final String targetFile); @Override CommandOutput executeCreateDirectoryCommand(final Jvm jvm, final String dirAbsolutePath); @Override CommandOutput executeCheckFileExistsCommand(final Jvm jvm, final String filename); @Override CommandOutput executeBackUpCommand(final Jvm jvm, final String filename); void setJvmCommandFactory(JvmCommandFactory jvmCommandFactory); }
JvmControlServiceImpl implements JvmControlService { @Override public CommandOutput controlJvm(final ControlJvmRequest controlJvmRequest, final User aUser) { final JvmControlOperation controlOperation = controlJvmRequest.getControlOperation(); LOGGER.debug("Control JVM request operation = {}", controlOperation.toString()); final Jvm jvm = jvmPersistenceService.getJvm(controlJvmRequest.getJvmId()); try { final String historyMessage = controlJvmRequest.getMessage() == null ? controlOperation.name() : controlJvmRequest.getMessage(); historyFacadeService.write(getServerName(jvm), new ArrayList<>(jvm.getGroups()), historyMessage, EventType.USER_ACTION_INFO, aUser.getId()); RemoteCommandReturnInfo remoteCommandReturnInfo = jvmCommandFactory.executeCommand(jvm, controlJvmRequest.getControlOperation()); CommandOutput commandOutput = new CommandOutput(new ExecReturnCode(remoteCommandReturnInfo.retCode), remoteCommandReturnInfo.standardOuput, remoteCommandReturnInfo.errorOupout); final String standardOutput = commandOutput.getStandardOutput(); final ExecReturnCode returnCode = commandOutput.getReturnCode(); if (StringUtils.isNotEmpty(standardOutput) && (JvmControlOperation.START.equals(controlOperation) || JvmControlOperation.STOP.equals(controlOperation))) { commandOutput.cleanStandardOutput(); LOGGER.info("shell command output is {}", standardOutput); } else if (StringUtils.isNoneBlank(standardOutput) && JvmControlOperation.HEAP_DUMP.equals(controlOperation) && returnCode.wasSuccessful()) { commandOutput.cleanHeapDumpStandardOutput(); } LOGGER.debug("JvmCommand output return code = {}", returnCode); if (returnCode.wasSuccessful()) { if (JvmControlOperation.STOP.equals(controlOperation)) { LOGGER.debug("Updating state to {}...", JvmState.JVM_STOPPED); jvmStateService.updateState(jvm, JvmState.JVM_STOPPED); LOGGER.debug("State successfully updated to {}", JvmState.JVM_STOPPED); } } else { String commandOutputReturnDescription = CommandOutputReturnCode.fromReturnCode(returnCode.getReturnCode()).getDesc(); switch (returnCode.getReturnCode()) { case ExecReturnCode.JWALA_EXIT_PROCESS_KILLED: commandOutput = new CommandOutput(new ExecReturnCode(0), FORCED_STOPPED, commandOutput.getStandardError()); jvmStateService.updateState(jvm, JvmState.FORCED_STOPPED); break; case ExecReturnCode.JWALA_EXIT_CODE_ABNORMAL_SUCCESS: int retCode = 0; switch (controlJvmRequest.getControlOperation()) { case START: commandOutputReturnDescription = MSG_SERVICE_ALREADY_STARTED; break; case STOP: commandOutputReturnDescription = MSG_SERVICE_ALREADY_STOPPED; break; default: retCode = returnCode.getReturnCode(); break; } sendMessageToActionEventLog(aUser, jvm, commandOutputReturnDescription); if (retCode == 0) { commandOutput = new CommandOutput(new ExecReturnCode(retCode), commandOutputReturnDescription, null); } break; case ExecReturnCode.JWALA_EXIT_CODE_NO_OP: if (controlOperation.equals(JvmControlOperation.START) || controlOperation.equals(JvmControlOperation.STOP)) { sendMessageToActionEventLog(aUser, jvm, commandOutputReturnDescription); } else { final String errorMsg = getCommandErrorMessage(commandOutput, returnCode, commandOutputReturnDescription); sendMessageToActionEventLog(aUser, jvm, errorMsg); } break; default: final String errorMsg = getCommandErrorMessage(commandOutput, returnCode, commandOutputReturnDescription); sendMessageToActionEventLog(aUser, jvm, errorMsg); break; } } return commandOutput; } catch (final RemoteCommandExecutorServiceException e) { LOGGER.error(e.getMessage(), e); historyFacadeService.write(getServerName(jvm), new ArrayList<>(jvm.getGroups()), e.getMessage(), EventType.SYSTEM_ERROR, aUser.getId()); throw new InternalErrorException(FaultType.REMOTE_COMMAND_FAILURE, "CommandFailureException when attempting to control a JVM: " + controlJvmRequest, e); } } JvmControlServiceImpl(final JvmPersistenceService jvmPersistenceService,
                                 final JvmStateService jvmStateService,
                                 final HistoryFacadeService historyFacadeService); @Override CommandOutput controlJvm(final ControlJvmRequest controlJvmRequest, final User aUser); @Override CommandOutput controlJvmSynchronously(final ControlJvmRequest controlJvmRequest, final long timeout,
                                                 final User user); @Override CommandOutput secureCopyFile(final ControlJvmRequest secureCopyRequest, final String sourcePath,
                                        final String destPath, String userId, boolean overwrite); @Override CommandOutput executeChangeFileModeCommand(final Jvm jvm, final String modifiedPermissions, final String targetAbsoluteDir, final String targetFile); @Override CommandOutput executeCreateDirectoryCommand(final Jvm jvm, final String dirAbsolutePath); @Override CommandOutput executeCheckFileExistsCommand(final Jvm jvm, final String filename); @Override CommandOutput executeBackUpCommand(final Jvm jvm, final String filename); void setJvmCommandFactory(JvmCommandFactory jvmCommandFactory);  }