@Test(expected = InternalErrorException.class) public void testControlWebServerWaitForException() { final CommandOutput execData = mock(CommandOutput.class); final ExecReturnCode execDataReturnCode = mock(ExecReturnCode.class); when(execDataReturnCode.wasSuccessful()).thenReturn(true); when(execData.getReturnCode()).thenReturn(execDataReturnCode); final JsonControlWebServer jsonControlWebServer = new JsonControlWebServer("start"); when(Config.mockWebServerControlService.controlWebServer(any(ControlWebServerRequest.class), any(User.class))).thenReturn(execData); when(Config.mockWebServerControlService.waitForState(any(ControlWebServerRequest.class), anyLong())).thenReturn(false); webServerServiceRest.controlWebServer(Identifier.id(1l, WebServer.class), jsonControlWebServer, Config.mockAuthenticatedUser, true, 120L); }
@Override public Response controlWebServer(final Identifier<WebServer> aWebServerId, final JsonControlWebServer aWebServerToControl, final AuthenticatedUser aUser, final Boolean wait, Long waitTimeout) { LOGGER.debug("Control Web Server requested: {} {} by user {}", aWebServerId, aWebServerToControl, aUser.getUser().getId()); final ControlWebServerRequest controlWebServerRequest = new ControlWebServerRequest(aWebServerId, aWebServerToControl.toControlOperation()); final CommandOutput commandOutput = webServerControlService.controlWebServer( controlWebServerRequest, aUser.getUser()); if (Boolean.TRUE.equals(wait)) { waitTimeout = waitTimeout == null ? DEFAULT_WAIT_TIMEOUT : waitTimeout * 1000; } if (Boolean.TRUE.equals(wait) && commandOutput.getReturnCode().wasSuccessful() && webServerControlService.waitForState(controlWebServerRequest, waitTimeout)) { return ResponseBuilder.ok(commandOutput.getStandardOutput()); } else if (!Boolean.TRUE.equals(wait) && commandOutput.getReturnCode().wasSuccessful()) { return ResponseBuilder.ok(commandOutput.getStandardOutput()); } else { final String standardError = commandOutput.getStandardError(); final String standardOut = commandOutput.getStandardOutput(); String errMessage = null != standardError && !standardError.isEmpty() ? standardError : standardOut; LOGGER.error("Control Operation Unsuccessful: {}", errMessage); throw new InternalErrorException(FaultType.CONTROL_OPERATION_UNSUCCESSFUL, CommandOutputReturnCode.fromReturnCode(commandOutput.getReturnCode().getReturnCode()).getDesc()); } }
WebServerServiceRestImpl implements WebServerServiceRest { @Override public Response controlWebServer(final Identifier<WebServer> aWebServerId, final JsonControlWebServer aWebServerToControl, final AuthenticatedUser aUser, final Boolean wait, Long waitTimeout) { LOGGER.debug("Control Web Server requested: {} {} by user {}", aWebServerId, aWebServerToControl, aUser.getUser().getId()); final ControlWebServerRequest controlWebServerRequest = new ControlWebServerRequest(aWebServerId, aWebServerToControl.toControlOperation()); final CommandOutput commandOutput = webServerControlService.controlWebServer( controlWebServerRequest, aUser.getUser()); if (Boolean.TRUE.equals(wait)) { waitTimeout = waitTimeout == null ? DEFAULT_WAIT_TIMEOUT : waitTimeout * 1000; } if (Boolean.TRUE.equals(wait) && commandOutput.getReturnCode().wasSuccessful() && webServerControlService.waitForState(controlWebServerRequest, waitTimeout)) { return ResponseBuilder.ok(commandOutput.getStandardOutput()); } else if (!Boolean.TRUE.equals(wait) && commandOutput.getReturnCode().wasSuccessful()) { return ResponseBuilder.ok(commandOutput.getStandardOutput()); } else { final String standardError = commandOutput.getStandardError(); final String standardOut = commandOutput.getStandardOutput(); String errMessage = null != standardError && !standardError.isEmpty() ? standardError : standardOut; LOGGER.error("Control Operation Unsuccessful: {}", errMessage); throw new InternalErrorException(FaultType.CONTROL_OPERATION_UNSUCCESSFUL, CommandOutputReturnCode.fromReturnCode(commandOutput.getReturnCode().getReturnCode()).getDesc()); } } }
WebServerServiceRestImpl implements WebServerServiceRest { @Override public Response controlWebServer(final Identifier<WebServer> aWebServerId, final JsonControlWebServer aWebServerToControl, final AuthenticatedUser aUser, final Boolean wait, Long waitTimeout) { LOGGER.debug("Control Web Server requested: {} {} by user {}", aWebServerId, aWebServerToControl, aUser.getUser().getId()); final ControlWebServerRequest controlWebServerRequest = new ControlWebServerRequest(aWebServerId, aWebServerToControl.toControlOperation()); final CommandOutput commandOutput = webServerControlService.controlWebServer( controlWebServerRequest, aUser.getUser()); if (Boolean.TRUE.equals(wait)) { waitTimeout = waitTimeout == null ? DEFAULT_WAIT_TIMEOUT : waitTimeout * 1000; } if (Boolean.TRUE.equals(wait) && commandOutput.getReturnCode().wasSuccessful() && webServerControlService.waitForState(controlWebServerRequest, waitTimeout)) { return ResponseBuilder.ok(commandOutput.getStandardOutput()); } else if (!Boolean.TRUE.equals(wait) && commandOutput.getReturnCode().wasSuccessful()) { return ResponseBuilder.ok(commandOutput.getStandardOutput()); } else { final String standardError = commandOutput.getStandardError(); final String standardOut = commandOutput.getStandardOutput(); String errMessage = null != standardError && !standardError.isEmpty() ? standardError : standardOut; LOGGER.error("Control Operation Unsuccessful: {}", errMessage); throw new InternalErrorException(FaultType.CONTROL_OPERATION_UNSUCCESSFUL, CommandOutputReturnCode.fromReturnCode(commandOutput.getReturnCode().getReturnCode()).getDesc()); } } WebServerServiceRestImpl(final WebServerService theWebServerService,
                                    final WebServerControlService theWebServerControlService,
                                    final WebServerCommandService theWebServerCommandService,
                                    final ResourceService theResourceService, GroupService groupService,
                                    final BinaryDistributionService binaryDistributionService,
                                    final HistoryFacadeService historyFacadeService
                                    ); }
WebServerServiceRestImpl implements WebServerServiceRest { @Override public Response controlWebServer(final Identifier<WebServer> aWebServerId, final JsonControlWebServer aWebServerToControl, final AuthenticatedUser aUser, final Boolean wait, Long waitTimeout) { LOGGER.debug("Control Web Server requested: {} {} by user {}", aWebServerId, aWebServerToControl, aUser.getUser().getId()); final ControlWebServerRequest controlWebServerRequest = new ControlWebServerRequest(aWebServerId, aWebServerToControl.toControlOperation()); final CommandOutput commandOutput = webServerControlService.controlWebServer( controlWebServerRequest, aUser.getUser()); if (Boolean.TRUE.equals(wait)) { waitTimeout = waitTimeout == null ? DEFAULT_WAIT_TIMEOUT : waitTimeout * 1000; } if (Boolean.TRUE.equals(wait) && commandOutput.getReturnCode().wasSuccessful() && webServerControlService.waitForState(controlWebServerRequest, waitTimeout)) { return ResponseBuilder.ok(commandOutput.getStandardOutput()); } else if (!Boolean.TRUE.equals(wait) && commandOutput.getReturnCode().wasSuccessful()) { return ResponseBuilder.ok(commandOutput.getStandardOutput()); } else { final String standardError = commandOutput.getStandardError(); final String standardOut = commandOutput.getStandardOutput(); String errMessage = null != standardError && !standardError.isEmpty() ? standardError : standardOut; LOGGER.error("Control Operation Unsuccessful: {}", errMessage); throw new InternalErrorException(FaultType.CONTROL_OPERATION_UNSUCCESSFUL, CommandOutputReturnCode.fromReturnCode(commandOutput.getReturnCode().getReturnCode()).getDesc()); } } WebServerServiceRestImpl(final WebServerService theWebServerService,
                                    final WebServerControlService theWebServerControlService,
                                    final WebServerCommandService theWebServerCommandService,
                                    final ResourceService theResourceService, GroupService groupService,
                                    final BinaryDistributionService binaryDistributionService,
                                    final HistoryFacadeService historyFacadeService
                                    ); @Override Response getWebServers(final Identifier<Group> aGroupId); @Override Response getWebServer(final Identifier<WebServer> aWsId); @Override Response createWebServer(final JsonCreateWebServer aWebServerToCreate, final AuthenticatedUser aUser); @Override Response updateWebServer(final JsonUpdateWebServer aWebServerToCreate, final AuthenticatedUser aUser); @Override Response deleteWebServer(final Identifier<WebServer> id, boolean hardDelete, final AuthenticatedUser authUser); @Override Response controlWebServer(final Identifier<WebServer> aWebServerId,
                                     final JsonControlWebServer aWebServerToControl, final AuthenticatedUser aUser,
                                     final Boolean wait, Long waitTimeout); @Override Response generateConfig(final String webServerName); @Override Response generateAndDeployConfig(final String aWebServerName, final String resourceFileName, final AuthenticatedUser user); @Override Response generateAndDeployWebServer(final String aWebServerName, final AuthenticatedUser aUser); @Override Response getHttpdConfig(Identifier<WebServer> aWebServerId); @Override Response getResourceNames(final String wsName); @Override Response getResourceTemplate(final String wsName, final String resourceTemplateName,
                                        final boolean tokensReplaced); @Override Response updateResourceTemplate(final String wsName, final String resourceTemplateName, final String content); @Override Response previewResourceTemplate(final String webServerName, final String fileName, final String groupName, String template); }
WebServerServiceRestImpl implements WebServerServiceRest { @Override public Response controlWebServer(final Identifier<WebServer> aWebServerId, final JsonControlWebServer aWebServerToControl, final AuthenticatedUser aUser, final Boolean wait, Long waitTimeout) { LOGGER.debug("Control Web Server requested: {} {} by user {}", aWebServerId, aWebServerToControl, aUser.getUser().getId()); final ControlWebServerRequest controlWebServerRequest = new ControlWebServerRequest(aWebServerId, aWebServerToControl.toControlOperation()); final CommandOutput commandOutput = webServerControlService.controlWebServer( controlWebServerRequest, aUser.getUser()); if (Boolean.TRUE.equals(wait)) { waitTimeout = waitTimeout == null ? DEFAULT_WAIT_TIMEOUT : waitTimeout * 1000; } if (Boolean.TRUE.equals(wait) && commandOutput.getReturnCode().wasSuccessful() && webServerControlService.waitForState(controlWebServerRequest, waitTimeout)) { return ResponseBuilder.ok(commandOutput.getStandardOutput()); } else if (!Boolean.TRUE.equals(wait) && commandOutput.getReturnCode().wasSuccessful()) { return ResponseBuilder.ok(commandOutput.getStandardOutput()); } else { final String standardError = commandOutput.getStandardError(); final String standardOut = commandOutput.getStandardOutput(); String errMessage = null != standardError && !standardError.isEmpty() ? standardError : standardOut; LOGGER.error("Control Operation Unsuccessful: {}", errMessage); throw new InternalErrorException(FaultType.CONTROL_OPERATION_UNSUCCESSFUL, CommandOutputReturnCode.fromReturnCode(commandOutput.getReturnCode().getReturnCode()).getDesc()); } } WebServerServiceRestImpl(final WebServerService theWebServerService,
                                    final WebServerControlService theWebServerControlService,
                                    final WebServerCommandService theWebServerCommandService,
                                    final ResourceService theResourceService, GroupService groupService,
                                    final BinaryDistributionService binaryDistributionService,
                                    final HistoryFacadeService historyFacadeService
                                    ); @Override Response getWebServers(final Identifier<Group> aGroupId); @Override Response getWebServer(final Identifier<WebServer> aWsId); @Override Response createWebServer(final JsonCreateWebServer aWebServerToCreate, final AuthenticatedUser aUser); @Override Response updateWebServer(final JsonUpdateWebServer aWebServerToCreate, final AuthenticatedUser aUser); @Override Response deleteWebServer(final Identifier<WebServer> id, boolean hardDelete, final AuthenticatedUser authUser); @Override Response controlWebServer(final Identifier<WebServer> aWebServerId,
                                     final JsonControlWebServer aWebServerToControl, final AuthenticatedUser aUser,
                                     final Boolean wait, Long waitTimeout); @Override Response generateConfig(final String webServerName); @Override Response generateAndDeployConfig(final String aWebServerName, final String resourceFileName, final AuthenticatedUser user); @Override Response generateAndDeployWebServer(final String aWebServerName, final AuthenticatedUser aUser); @Override Response getHttpdConfig(Identifier<WebServer> aWebServerId); @Override Response getResourceNames(final String wsName); @Override Response getResourceTemplate(final String wsName, final String resourceTemplateName,
                                        final boolean tokensReplaced); @Override Response updateResourceTemplate(final String wsName, final String resourceTemplateName, final String content); @Override Response previewResourceTemplate(final String webServerName, final String fileName, final String groupName, String template);  }