@Test @SuppressWarnings("unchecked") public void testUpdateWebServer() { when(Config.mockWebServerPersistenceService.getWebServer(any(Identifier.class))).thenReturn(mockWebServer); when(mockWebServer.getName()).thenReturn("oldName"); when(mockWebServer.getState()).thenReturn(WebServerReachableState.WS_NEW); when(Config.mockJvmPersistenceService.findJvmByExactName("newWebServerName")).thenThrow(new NoResultException()); when(Config.mockWebServerPersistenceService.findWebServerByName("newWebServerName")).thenThrow(new NoResultException()); UpdateWebServerRequest req = new UpdateWebServerRequest(new Identifier(1L), groupIds, "newWebServerName", "hostName", 80, 443, new Path("https: final JpaGroup jpaGroup = new JpaGroup(); jpaGroup.setId(1L); final List<JpaGroup> jpaGroupList = new ArrayList<>(); jpaGroupList.add(jpaGroup); when(Config.mockGroupPersistenceService.findGroups(anyList())).thenReturn(jpaGroupList); final JpaWebServer mockJpaWebServer = mock(JpaWebServer.class); when(mockJpaWebServer.getGroups()).thenReturn(jpaGroupList); when(mockJpaWebServer.getId()).thenReturn(2L); when(Config.mockWebServerPersistenceService.findWebServer(anyLong())).thenReturn(mockJpaWebServer); when(Config.mockWebServerPersistenceService.updateWebServer(mockJpaWebServer)).thenReturn(mockJpaWebServer); wsService.updateWebServer(req, new User("user")); verify(Config.mockWebServerPersistenceService).updateWebServer(mockJpaWebServer); }
@Override @Transactional public WebServer updateWebServer(final UpdateWebServerRequest anUpdateWebServerCommand, final User anUpdatingUser) { anUpdateWebServerCommand.validate(); WebServer originalWebServer = getWebServer(anUpdateWebServerCommand.getId()); if (!anUpdateWebServerCommand.getNewName().equalsIgnoreCase(originalWebServer.getName()) && !WebServerReachableState.WS_NEW.equals(originalWebServer.getState())) { throw new WebServerServiceException(MessageFormat.format("Web Server {0} is in {1} state, can only rename new web servers", originalWebServer.getName(), originalWebServer.getState().toStateLabel())); } if (!originalWebServer.getName().equalsIgnoreCase(anUpdateWebServerCommand.getNewName())) { validateUpdateWebServer(anUpdateWebServerCommand); } final List<Long> groupIdList = new ArrayList<>(); for (Identifier<Group> id : anUpdateWebServerCommand.getNewGroupIds()) { groupIdList.add(id.getId()); } final JpaWebServer jpaWebServer = webServerPersistenceService.findWebServer(anUpdateWebServerCommand.getId().getId()); final List<JpaGroup> jpaGroupList = groupPersistenceService.findGroups(groupIdList); jpaWebServer.setGroups(jpaGroupList); jpaWebServer.setName(anUpdateWebServerCommand.getNewName()); jpaWebServer.setHost(anUpdateWebServerCommand.getNewHost()); jpaWebServer.setPort(anUpdateWebServerCommand.getNewPort()); jpaWebServer.setHttpsPort(anUpdateWebServerCommand.getNewHttpsPort()); jpaWebServer.setStatusPath(anUpdateWebServerCommand.getNewStatusPath().getPath()); final JpaMedia jpaApacheHttpdMedia = anUpdateWebServerCommand.getApacheHttpdMediaId() == null ? null : mediaService.find(Long.valueOf(anUpdateWebServerCommand.getApacheHttpdMediaId())); jpaWebServer.setApacheHttpdMedia(jpaApacheHttpdMedia); final JpaWebServer updatedWebServer = webServerPersistenceService.updateWebServer(jpaWebServer); updateWebServerGroups(updatedWebServer); return new JpaWebServerBuilder(updatedWebServer).build(); }
WebServerServiceImpl implements WebServerService { @Override @Transactional public WebServer updateWebServer(final UpdateWebServerRequest anUpdateWebServerCommand, final User anUpdatingUser) { anUpdateWebServerCommand.validate(); WebServer originalWebServer = getWebServer(anUpdateWebServerCommand.getId()); if (!anUpdateWebServerCommand.getNewName().equalsIgnoreCase(originalWebServer.getName()) && !WebServerReachableState.WS_NEW.equals(originalWebServer.getState())) { throw new WebServerServiceException(MessageFormat.format("Web Server {0} is in {1} state, can only rename new web servers", originalWebServer.getName(), originalWebServer.getState().toStateLabel())); } if (!originalWebServer.getName().equalsIgnoreCase(anUpdateWebServerCommand.getNewName())) { validateUpdateWebServer(anUpdateWebServerCommand); } final List<Long> groupIdList = new ArrayList<>(); for (Identifier<Group> id : anUpdateWebServerCommand.getNewGroupIds()) { groupIdList.add(id.getId()); } final JpaWebServer jpaWebServer = webServerPersistenceService.findWebServer(anUpdateWebServerCommand.getId().getId()); final List<JpaGroup> jpaGroupList = groupPersistenceService.findGroups(groupIdList); jpaWebServer.setGroups(jpaGroupList); jpaWebServer.setName(anUpdateWebServerCommand.getNewName()); jpaWebServer.setHost(anUpdateWebServerCommand.getNewHost()); jpaWebServer.setPort(anUpdateWebServerCommand.getNewPort()); jpaWebServer.setHttpsPort(anUpdateWebServerCommand.getNewHttpsPort()); jpaWebServer.setStatusPath(anUpdateWebServerCommand.getNewStatusPath().getPath()); final JpaMedia jpaApacheHttpdMedia = anUpdateWebServerCommand.getApacheHttpdMediaId() == null ? null : mediaService.find(Long.valueOf(anUpdateWebServerCommand.getApacheHttpdMediaId())); jpaWebServer.setApacheHttpdMedia(jpaApacheHttpdMedia); final JpaWebServer updatedWebServer = webServerPersistenceService.updateWebServer(jpaWebServer); updateWebServerGroups(updatedWebServer); return new JpaWebServerBuilder(updatedWebServer).build(); } }
WebServerServiceImpl implements WebServerService { @Override @Transactional public WebServer updateWebServer(final UpdateWebServerRequest anUpdateWebServerCommand, final User anUpdatingUser) { anUpdateWebServerCommand.validate(); WebServer originalWebServer = getWebServer(anUpdateWebServerCommand.getId()); if (!anUpdateWebServerCommand.getNewName().equalsIgnoreCase(originalWebServer.getName()) && !WebServerReachableState.WS_NEW.equals(originalWebServer.getState())) { throw new WebServerServiceException(MessageFormat.format("Web Server {0} is in {1} state, can only rename new web servers", originalWebServer.getName(), originalWebServer.getState().toStateLabel())); } if (!originalWebServer.getName().equalsIgnoreCase(anUpdateWebServerCommand.getNewName())) { validateUpdateWebServer(anUpdateWebServerCommand); } final List<Long> groupIdList = new ArrayList<>(); for (Identifier<Group> id : anUpdateWebServerCommand.getNewGroupIds()) { groupIdList.add(id.getId()); } final JpaWebServer jpaWebServer = webServerPersistenceService.findWebServer(anUpdateWebServerCommand.getId().getId()); final List<JpaGroup> jpaGroupList = groupPersistenceService.findGroups(groupIdList); jpaWebServer.setGroups(jpaGroupList); jpaWebServer.setName(anUpdateWebServerCommand.getNewName()); jpaWebServer.setHost(anUpdateWebServerCommand.getNewHost()); jpaWebServer.setPort(anUpdateWebServerCommand.getNewPort()); jpaWebServer.setHttpsPort(anUpdateWebServerCommand.getNewHttpsPort()); jpaWebServer.setStatusPath(anUpdateWebServerCommand.getNewStatusPath().getPath()); final JpaMedia jpaApacheHttpdMedia = anUpdateWebServerCommand.getApacheHttpdMediaId() == null ? null : mediaService.find(Long.valueOf(anUpdateWebServerCommand.getApacheHttpdMediaId())); jpaWebServer.setApacheHttpdMedia(jpaApacheHttpdMedia); final JpaWebServer updatedWebServer = webServerPersistenceService.updateWebServer(jpaWebServer); updateWebServerGroups(updatedWebServer); return new JpaWebServerBuilder(updatedWebServer).build(); } WebServerServiceImpl(final WebServerPersistenceService webServerPersistenceService,
                                final ResourceService resourceService,
                                @Qualifier("webServerInMemoryStateManagerService")
                                final InMemoryStateManagerService<Identifier<WebServer>, WebServerReachableState> inMemoryStateManagerService,
                                final String templatePath,
                                final BinaryDistributionLockManager binaryDistributionLockManager); }
WebServerServiceImpl implements WebServerService { @Override @Transactional public WebServer updateWebServer(final UpdateWebServerRequest anUpdateWebServerCommand, final User anUpdatingUser) { anUpdateWebServerCommand.validate(); WebServer originalWebServer = getWebServer(anUpdateWebServerCommand.getId()); if (!anUpdateWebServerCommand.getNewName().equalsIgnoreCase(originalWebServer.getName()) && !WebServerReachableState.WS_NEW.equals(originalWebServer.getState())) { throw new WebServerServiceException(MessageFormat.format("Web Server {0} is in {1} state, can only rename new web servers", originalWebServer.getName(), originalWebServer.getState().toStateLabel())); } if (!originalWebServer.getName().equalsIgnoreCase(anUpdateWebServerCommand.getNewName())) { validateUpdateWebServer(anUpdateWebServerCommand); } final List<Long> groupIdList = new ArrayList<>(); for (Identifier<Group> id : anUpdateWebServerCommand.getNewGroupIds()) { groupIdList.add(id.getId()); } final JpaWebServer jpaWebServer = webServerPersistenceService.findWebServer(anUpdateWebServerCommand.getId().getId()); final List<JpaGroup> jpaGroupList = groupPersistenceService.findGroups(groupIdList); jpaWebServer.setGroups(jpaGroupList); jpaWebServer.setName(anUpdateWebServerCommand.getNewName()); jpaWebServer.setHost(anUpdateWebServerCommand.getNewHost()); jpaWebServer.setPort(anUpdateWebServerCommand.getNewPort()); jpaWebServer.setHttpsPort(anUpdateWebServerCommand.getNewHttpsPort()); jpaWebServer.setStatusPath(anUpdateWebServerCommand.getNewStatusPath().getPath()); final JpaMedia jpaApacheHttpdMedia = anUpdateWebServerCommand.getApacheHttpdMediaId() == null ? null : mediaService.find(Long.valueOf(anUpdateWebServerCommand.getApacheHttpdMediaId())); jpaWebServer.setApacheHttpdMedia(jpaApacheHttpdMedia); final JpaWebServer updatedWebServer = webServerPersistenceService.updateWebServer(jpaWebServer); updateWebServerGroups(updatedWebServer); return new JpaWebServerBuilder(updatedWebServer).build(); } WebServerServiceImpl(final WebServerPersistenceService webServerPersistenceService,
                                final ResourceService resourceService,
                                @Qualifier("webServerInMemoryStateManagerService")
                                final InMemoryStateManagerService<Identifier<WebServer>, WebServerReachableState> inMemoryStateManagerService,
                                final String templatePath,
                                final BinaryDistributionLockManager binaryDistributionLockManager); @Override @Transactional WebServer createWebServer(final CreateWebServerRequest createWebServerRequest,
                                     final User aCreatingUser); @Override @Transactional(readOnly = true) WebServer getWebServer(final Identifier<WebServer> aWebServerId); @Override @Transactional(readOnly = true) WebServer getWebServer(final String aWebServerName); @Override @Transactional(readOnly = true) List<WebServer> getWebServers(); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) List<WebServer> getWebServersPropagationNew(); @Override @Transactional(readOnly = true) List<WebServer> findWebServers(final Identifier<Group> aGroupId); @Override @Transactional WebServer updateWebServer(final UpdateWebServerRequest anUpdateWebServerCommand,
                                     final User anUpdatingUser); @Override @Transactional void deleteWebServer(final Identifier<WebServer> id, final boolean hardDelete, final User user); @Override boolean isStarted(WebServer webServer); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void updateState(final Identifier<WebServer> id, final WebServerReachableState state, final String errorStatus); @Override String generateInstallServiceScript(WebServer webServer); @Override @Transactional(readOnly = true) List<String> getResourceTemplateNames(String webServerName); @Override @Transactional(readOnly = true) String getResourceTemplate(final String webServerName, final String resourceTemplateName,
                                      final boolean tokensReplaced, final ResourceGroup resourceGroup); @Override String getResourceTemplateMetaData(String aWebServerName, String resourceTemplateName); @Override @Transactional void uploadWebServerConfig(WebServer webServer, String templateName, String templateContent, String metaDataStr, String groupName, User user); @Override @Transactional String updateResourceTemplate(final String wsName, final String resourceTemplateName, final String template); @Override @Transactional(readOnly = true) String previewResourceTemplate(final String fileName, final String webServerName, final String groupName, final String template); @Override @Transactional(readOnly = true) Long getWebServerStartedCount(final String groupName); @Override @Transactional(readOnly = true) Long getWebServerCount(final String groupName); @Override Long getWebServerStoppedCount(final String groupName); @Override WebServer generateAndDeployFile(String webServerName, String fileName, User user); }
WebServerServiceImpl implements WebServerService { @Override @Transactional public WebServer updateWebServer(final UpdateWebServerRequest anUpdateWebServerCommand, final User anUpdatingUser) { anUpdateWebServerCommand.validate(); WebServer originalWebServer = getWebServer(anUpdateWebServerCommand.getId()); if (!anUpdateWebServerCommand.getNewName().equalsIgnoreCase(originalWebServer.getName()) && !WebServerReachableState.WS_NEW.equals(originalWebServer.getState())) { throw new WebServerServiceException(MessageFormat.format("Web Server {0} is in {1} state, can only rename new web servers", originalWebServer.getName(), originalWebServer.getState().toStateLabel())); } if (!originalWebServer.getName().equalsIgnoreCase(anUpdateWebServerCommand.getNewName())) { validateUpdateWebServer(anUpdateWebServerCommand); } final List<Long> groupIdList = new ArrayList<>(); for (Identifier<Group> id : anUpdateWebServerCommand.getNewGroupIds()) { groupIdList.add(id.getId()); } final JpaWebServer jpaWebServer = webServerPersistenceService.findWebServer(anUpdateWebServerCommand.getId().getId()); final List<JpaGroup> jpaGroupList = groupPersistenceService.findGroups(groupIdList); jpaWebServer.setGroups(jpaGroupList); jpaWebServer.setName(anUpdateWebServerCommand.getNewName()); jpaWebServer.setHost(anUpdateWebServerCommand.getNewHost()); jpaWebServer.setPort(anUpdateWebServerCommand.getNewPort()); jpaWebServer.setHttpsPort(anUpdateWebServerCommand.getNewHttpsPort()); jpaWebServer.setStatusPath(anUpdateWebServerCommand.getNewStatusPath().getPath()); final JpaMedia jpaApacheHttpdMedia = anUpdateWebServerCommand.getApacheHttpdMediaId() == null ? null : mediaService.find(Long.valueOf(anUpdateWebServerCommand.getApacheHttpdMediaId())); jpaWebServer.setApacheHttpdMedia(jpaApacheHttpdMedia); final JpaWebServer updatedWebServer = webServerPersistenceService.updateWebServer(jpaWebServer); updateWebServerGroups(updatedWebServer); return new JpaWebServerBuilder(updatedWebServer).build(); } WebServerServiceImpl(final WebServerPersistenceService webServerPersistenceService,
                                final ResourceService resourceService,
                                @Qualifier("webServerInMemoryStateManagerService")
                                final InMemoryStateManagerService<Identifier<WebServer>, WebServerReachableState> inMemoryStateManagerService,
                                final String templatePath,
                                final BinaryDistributionLockManager binaryDistributionLockManager); @Override @Transactional WebServer createWebServer(final CreateWebServerRequest createWebServerRequest,
                                     final User aCreatingUser); @Override @Transactional(readOnly = true) WebServer getWebServer(final Identifier<WebServer> aWebServerId); @Override @Transactional(readOnly = true) WebServer getWebServer(final String aWebServerName); @Override @Transactional(readOnly = true) List<WebServer> getWebServers(); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) List<WebServer> getWebServersPropagationNew(); @Override @Transactional(readOnly = true) List<WebServer> findWebServers(final Identifier<Group> aGroupId); @Override @Transactional WebServer updateWebServer(final UpdateWebServerRequest anUpdateWebServerCommand,
                                     final User anUpdatingUser); @Override @Transactional void deleteWebServer(final Identifier<WebServer> id, final boolean hardDelete, final User user); @Override boolean isStarted(WebServer webServer); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void updateState(final Identifier<WebServer> id, final WebServerReachableState state, final String errorStatus); @Override String generateInstallServiceScript(WebServer webServer); @Override @Transactional(readOnly = true) List<String> getResourceTemplateNames(String webServerName); @Override @Transactional(readOnly = true) String getResourceTemplate(final String webServerName, final String resourceTemplateName,
                                      final boolean tokensReplaced, final ResourceGroup resourceGroup); @Override String getResourceTemplateMetaData(String aWebServerName, String resourceTemplateName); @Override @Transactional void uploadWebServerConfig(WebServer webServer, String templateName, String templateContent, String metaDataStr, String groupName, User user); @Override @Transactional String updateResourceTemplate(final String wsName, final String resourceTemplateName, final String template); @Override @Transactional(readOnly = true) String previewResourceTemplate(final String fileName, final String webServerName, final String groupName, final String template); @Override @Transactional(readOnly = true) Long getWebServerStartedCount(final String groupName); @Override @Transactional(readOnly = true) Long getWebServerCount(final String groupName); @Override Long getWebServerStoppedCount(final String groupName); @Override WebServer generateAndDeployFile(String webServerName, String fileName, User user); static final String INSTALL_SERVICE_SCRIPT_NAME; }