@Test(expected = WebServerServiceException.class) public void testCreateWebServersValidateJvmNameConflict() { System.setProperty(ApplicationProperties.PROPERTIES_ROOT_PATH, "./src/test/resources"); when(mockWebServer.getState()).thenReturn(WebServerReachableState.WS_NEW); when(Config.mockWebServerPersistenceService.createWebServer(any(WebServer.class), anyString())).thenReturn(mockWebServer); when(Config.mockJvmPersistenceService.findJvmByExactName(anyString())).thenReturn(Config.mockJvm); CreateWebServerRequest cmd = new CreateWebServerRequest(mockWebServer.getGroupIds(), mockWebServer.getName(), mockWebServer.getHost(), mockWebServer.getPort(), mockWebServer.getHttpsPort(), mockWebServer.getStatusPath(), mockWebServer.getState(), "apacheHttpdMediaId"); final WebServer webServer = wsService.createWebServer(cmd, testUser); assertEquals(new Identifier<WebServer>(1L), webServer.getId()); assertEquals(group.getId(), webServer.getGroups().iterator().next().getId()); assertEquals("the-ws-name", webServer.getName()); assertEquals("the-ws-group-name", webServer.getGroups().iterator().next().getName()); assertEquals("the-ws-hostname", webServer.getHost()); assertEquals(WebServerReachableState.WS_NEW, Config.inMemService.get(webServer.getId())); System.clearProperty(ApplicationProperties.PROPERTIES_ROOT_PATH); }
@Override @Transactional public WebServer createWebServer(final CreateWebServerRequest createWebServerRequest, final User aCreatingUser) { createWebServerRequest.validate(); validateCreateWebServer(createWebServerRequest); final List<Long> groupIdList = new ArrayList<>(); for (Identifier<Group> id : createWebServerRequest.getGroups()) { groupIdList.add(id.getId()); } final JpaWebServer jpaWebServer = new JpaWebServer(); final List<JpaGroup> jpaGroupList = groupPersistenceService.findGroups(groupIdList); jpaWebServer.setGroups(jpaGroupList); jpaWebServer.setName(createWebServerRequest.getName()); jpaWebServer.setHost(createWebServerRequest.getHost()); jpaWebServer.setPort(createWebServerRequest.getPort()); jpaWebServer.setHttpsPort(createWebServerRequest.getHttpsPort()); jpaWebServer.setStatusPath(createWebServerRequest.getStatusPath().getPath()); jpaWebServer.setState(createWebServerRequest.getState()); final JpaMedia jpaApacheHttpdMedia = createWebServerRequest.getApacheHttpdMediaId() == null ? null : mediaService.find(Long.valueOf(createWebServerRequest.getApacheHttpdMediaId())); jpaWebServer.setApacheHttpdMedia(jpaApacheHttpdMedia); final JpaWebServer createdJpaWebServer = webServerPersistenceService.createWebServer(jpaWebServer); for (JpaGroup wsGroup : jpaGroupList) { final List<JpaWebServer> webServers = wsGroup.getWebServers(); webServers.add(createdJpaWebServer); wsGroup.setWebServers(webServers); } inMemoryStateManagerService.put(new Identifier<>(createdJpaWebServer.getId()), createdJpaWebServer.getState()); return new JpaWebServerBuilder(createdJpaWebServer).build(); }
WebServerServiceImpl implements WebServerService { @Override @Transactional public WebServer createWebServer(final CreateWebServerRequest createWebServerRequest, final User aCreatingUser) { createWebServerRequest.validate(); validateCreateWebServer(createWebServerRequest); final List<Long> groupIdList = new ArrayList<>(); for (Identifier<Group> id : createWebServerRequest.getGroups()) { groupIdList.add(id.getId()); } final JpaWebServer jpaWebServer = new JpaWebServer(); final List<JpaGroup> jpaGroupList = groupPersistenceService.findGroups(groupIdList); jpaWebServer.setGroups(jpaGroupList); jpaWebServer.setName(createWebServerRequest.getName()); jpaWebServer.setHost(createWebServerRequest.getHost()); jpaWebServer.setPort(createWebServerRequest.getPort()); jpaWebServer.setHttpsPort(createWebServerRequest.getHttpsPort()); jpaWebServer.setStatusPath(createWebServerRequest.getStatusPath().getPath()); jpaWebServer.setState(createWebServerRequest.getState()); final JpaMedia jpaApacheHttpdMedia = createWebServerRequest.getApacheHttpdMediaId() == null ? null : mediaService.find(Long.valueOf(createWebServerRequest.getApacheHttpdMediaId())); jpaWebServer.setApacheHttpdMedia(jpaApacheHttpdMedia); final JpaWebServer createdJpaWebServer = webServerPersistenceService.createWebServer(jpaWebServer); for (JpaGroup wsGroup : jpaGroupList) { final List<JpaWebServer> webServers = wsGroup.getWebServers(); webServers.add(createdJpaWebServer); wsGroup.setWebServers(webServers); } inMemoryStateManagerService.put(new Identifier<>(createdJpaWebServer.getId()), createdJpaWebServer.getState()); return new JpaWebServerBuilder(createdJpaWebServer).build(); } }
WebServerServiceImpl implements WebServerService { @Override @Transactional public WebServer createWebServer(final CreateWebServerRequest createWebServerRequest, final User aCreatingUser) { createWebServerRequest.validate(); validateCreateWebServer(createWebServerRequest); final List<Long> groupIdList = new ArrayList<>(); for (Identifier<Group> id : createWebServerRequest.getGroups()) { groupIdList.add(id.getId()); } final JpaWebServer jpaWebServer = new JpaWebServer(); final List<JpaGroup> jpaGroupList = groupPersistenceService.findGroups(groupIdList); jpaWebServer.setGroups(jpaGroupList); jpaWebServer.setName(createWebServerRequest.getName()); jpaWebServer.setHost(createWebServerRequest.getHost()); jpaWebServer.setPort(createWebServerRequest.getPort()); jpaWebServer.setHttpsPort(createWebServerRequest.getHttpsPort()); jpaWebServer.setStatusPath(createWebServerRequest.getStatusPath().getPath()); jpaWebServer.setState(createWebServerRequest.getState()); final JpaMedia jpaApacheHttpdMedia = createWebServerRequest.getApacheHttpdMediaId() == null ? null : mediaService.find(Long.valueOf(createWebServerRequest.getApacheHttpdMediaId())); jpaWebServer.setApacheHttpdMedia(jpaApacheHttpdMedia); final JpaWebServer createdJpaWebServer = webServerPersistenceService.createWebServer(jpaWebServer); for (JpaGroup wsGroup : jpaGroupList) { final List<JpaWebServer> webServers = wsGroup.getWebServers(); webServers.add(createdJpaWebServer); wsGroup.setWebServers(webServers); } inMemoryStateManagerService.put(new Identifier<>(createdJpaWebServer.getId()), createdJpaWebServer.getState()); return new JpaWebServerBuilder(createdJpaWebServer).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 createWebServer(final CreateWebServerRequest createWebServerRequest, final User aCreatingUser) { createWebServerRequest.validate(); validateCreateWebServer(createWebServerRequest); final List<Long> groupIdList = new ArrayList<>(); for (Identifier<Group> id : createWebServerRequest.getGroups()) { groupIdList.add(id.getId()); } final JpaWebServer jpaWebServer = new JpaWebServer(); final List<JpaGroup> jpaGroupList = groupPersistenceService.findGroups(groupIdList); jpaWebServer.setGroups(jpaGroupList); jpaWebServer.setName(createWebServerRequest.getName()); jpaWebServer.setHost(createWebServerRequest.getHost()); jpaWebServer.setPort(createWebServerRequest.getPort()); jpaWebServer.setHttpsPort(createWebServerRequest.getHttpsPort()); jpaWebServer.setStatusPath(createWebServerRequest.getStatusPath().getPath()); jpaWebServer.setState(createWebServerRequest.getState()); final JpaMedia jpaApacheHttpdMedia = createWebServerRequest.getApacheHttpdMediaId() == null ? null : mediaService.find(Long.valueOf(createWebServerRequest.getApacheHttpdMediaId())); jpaWebServer.setApacheHttpdMedia(jpaApacheHttpdMedia); final JpaWebServer createdJpaWebServer = webServerPersistenceService.createWebServer(jpaWebServer); for (JpaGroup wsGroup : jpaGroupList) { final List<JpaWebServer> webServers = wsGroup.getWebServers(); webServers.add(createdJpaWebServer); wsGroup.setWebServers(webServers); } inMemoryStateManagerService.put(new Identifier<>(createdJpaWebServer.getId()), createdJpaWebServer.getState()); return new JpaWebServerBuilder(createdJpaWebServer).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 createWebServer(final CreateWebServerRequest createWebServerRequest, final User aCreatingUser) { createWebServerRequest.validate(); validateCreateWebServer(createWebServerRequest); final List<Long> groupIdList = new ArrayList<>(); for (Identifier<Group> id : createWebServerRequest.getGroups()) { groupIdList.add(id.getId()); } final JpaWebServer jpaWebServer = new JpaWebServer(); final List<JpaGroup> jpaGroupList = groupPersistenceService.findGroups(groupIdList); jpaWebServer.setGroups(jpaGroupList); jpaWebServer.setName(createWebServerRequest.getName()); jpaWebServer.setHost(createWebServerRequest.getHost()); jpaWebServer.setPort(createWebServerRequest.getPort()); jpaWebServer.setHttpsPort(createWebServerRequest.getHttpsPort()); jpaWebServer.setStatusPath(createWebServerRequest.getStatusPath().getPath()); jpaWebServer.setState(createWebServerRequest.getState()); final JpaMedia jpaApacheHttpdMedia = createWebServerRequest.getApacheHttpdMediaId() == null ? null : mediaService.find(Long.valueOf(createWebServerRequest.getApacheHttpdMediaId())); jpaWebServer.setApacheHttpdMedia(jpaApacheHttpdMedia); final JpaWebServer createdJpaWebServer = webServerPersistenceService.createWebServer(jpaWebServer); for (JpaGroup wsGroup : jpaGroupList) { final List<JpaWebServer> webServers = wsGroup.getWebServers(); webServers.add(createdJpaWebServer); wsGroup.setWebServers(webServers); } inMemoryStateManagerService.put(new Identifier<>(createdJpaWebServer.getId()), createdJpaWebServer.getState()); return new JpaWebServerBuilder(createdJpaWebServer).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; }