@Test public void testDeployConf() throws CommandFailureException, IOException { final Jvm jvm = mock(Jvm.class); when(jvm.getHostName()).thenReturn("localhost"); when(jvm.getState()).thenReturn(JvmState.JVM_STOPPED); when(Config.jvmPersistenceService.findJvmByExactName(eq("jvm-1"))).thenReturn(jvm); final CommandOutput execData = mock(CommandOutput.class); when(execData.getReturnCode()).thenReturn(new ExecReturnCode(0)); when(Config.applicationPersistenceService.getResourceTemplate(eq("hct"), eq("hct.xml"), eq("jvm-1"), eq("hct-group"))).thenReturn("Test template"); when(Config.applicationPersistenceService.findApplication(eq("hct"), eq("hct-group"), eq("jvm-1"))).thenReturn(Config.mockApplication); when(Config.applicationPersistenceService.getMetaData(anyString(), anyString(), anyString(), anyString())).thenReturn(META_DATA_TEST_VALUES); when(Config.jvmPersistenceService.findJvm(eq("jvm-1"), eq("hct-group"))).thenReturn(jvm); ResourceTemplateMetaData mockMetaData = mock(ResourceTemplateMetaData.class); when(mockMetaData.getDeployFileName()).thenReturn("hct.xml"); when(mockMetaData.getDeployPath()).thenReturn("./test/deploy-path/conf/CatalinaSSL/localhost"); when(mockMetaData.getContentType()).thenReturn(MediaType.APPLICATION_XML); when(Config.mockResourceService.getTokenizedMetaData(anyString(), any(Object.class), anyString())).thenReturn(mockMetaData); when(Config.mockResourceService.generateResourceFile(anyString(), anyString(), any(ResourceGroup.class), any(), any(ResourceGeneratorType.class))).thenReturn("{\"deployPath\":\"./test/deploy-path/conf/CatalinaSSL/localhost\",\"contentType\":\"text/xml\",\"entity\":{\"type\":\"APPLICATION\",\"target\":\"soarcom-hct\",\"group\":\"soarcom-616\",\"parentName\":null,\"deployToJvms\":true},\"templateName\":\"hctXmlTemplate.tpl\",\"deployFileName\":\"hct.xml\"}"); when(Config.mockResourceService.generateAndDeployFile(any(ResourceIdentifier.class), anyString(), anyString(), anyString())).thenReturn(execData); when(mockMetaData.isHotDeploy()).thenReturn(false); when(Config.mockResourceService.getResourceContent(any(ResourceIdentifier.class))).thenReturn(new ResourceContent("{\"test\":\"meta data\"}", "test resource content")); when(Config.mockResourceService.getTokenizedMetaData(anyString(), anyObject(), anyString())).thenReturn(mockMetaData); CommandOutput retExecData = applicationService.deployConf("hct", "hct-group", "jvm-1", "hct.xml", mock(ResourceGroup.class), testUser); assertTrue(retExecData.getReturnCode().wasSuccessful()); when(Config.mockApplication.isSecure()).thenReturn(false); retExecData = applicationService.deployConf("hct", "hct-group", "jvm-1", "hct.xml", mock(ResourceGroup.class), testUser); assertTrue(retExecData.getReturnCode().wasSuccessful()); when(Config.mockApplication.isSecure()).thenReturn(true); retExecData = applicationService.deployConf("hct", "hct-group", "jvm-1", "hct.xml", mock(ResourceGroup.class), testUser); assertTrue(retExecData.getReturnCode().wasSuccessful()); when(execData.getReturnCode()).thenReturn(new ExecReturnCode(1)); when(execData.getStandardError()).thenReturn("REMOTE COMMAND FAILURE"); try { applicationService.deployConf("hct", "hct-group", "jvm-1", "hct.xml", mock(ResourceGroup.class), testUser); } catch (DeployApplicationConfException ee) { assertEquals("REMOTE COMMAND FAILURE", ee.getMessage()); } try { applicationService.deployConf("hct", "hct-group", "jvm-1", "hct.xml", mock(ResourceGroup.class), testUser); } catch (DeployApplicationConfException ee) { assertTrue(ee.getCause() instanceof CommandFailureException); } }
@Override @Transactional public CommandOutput deployConf(final String appName, final String groupName, final String jvmName, final String resourceTemplateName, ResourceGroup resourceGroup, User user) { String lockKey = generateKey(groupName, jvmName, appName, resourceTemplateName); try { binaryDistributionLockManager.writeLock(lockKey); ResourceIdentifier resourceIdentifier = new ResourceIdentifier.Builder() .setResourceName(resourceTemplateName) .setGroupName(groupName) .setWebAppName(appName) .setJvmName(jvmName) .build(); final Jvm jvm = jvmPersistenceService.findJvmByExactName(jvmName); checkJvmStateBeforeDeploy(jvm, resourceIdentifier); String hostName = jvm.getHostName(); Group group = groupPersistenceService.getGroup(groupName); historyFacadeService.write(hostName, group, "Deploying application resource " + resourceTemplateName, EventType.USER_ACTION_INFO, user.getId()); return resourceService.generateAndDeployFile(resourceIdentifier, appName + "-" + jvmName, resourceTemplateName, jvm.getHostName()); } catch (ResourceFileGeneratorException e) { LOGGER.error("Fail to generate the resource file {}", resourceTemplateName, e); throw new DeployApplicationConfException(e); } finally { binaryDistributionLockManager.writeUnlock(lockKey); } }
ApplicationServiceImpl implements ApplicationService { @Override @Transactional public CommandOutput deployConf(final String appName, final String groupName, final String jvmName, final String resourceTemplateName, ResourceGroup resourceGroup, User user) { String lockKey = generateKey(groupName, jvmName, appName, resourceTemplateName); try { binaryDistributionLockManager.writeLock(lockKey); ResourceIdentifier resourceIdentifier = new ResourceIdentifier.Builder() .setResourceName(resourceTemplateName) .setGroupName(groupName) .setWebAppName(appName) .setJvmName(jvmName) .build(); final Jvm jvm = jvmPersistenceService.findJvmByExactName(jvmName); checkJvmStateBeforeDeploy(jvm, resourceIdentifier); String hostName = jvm.getHostName(); Group group = groupPersistenceService.getGroup(groupName); historyFacadeService.write(hostName, group, "Deploying application resource " + resourceTemplateName, EventType.USER_ACTION_INFO, user.getId()); return resourceService.generateAndDeployFile(resourceIdentifier, appName + "-" + jvmName, resourceTemplateName, jvm.getHostName()); } catch (ResourceFileGeneratorException e) { LOGGER.error("Fail to generate the resource file {}", resourceTemplateName, e); throw new DeployApplicationConfException(e); } finally { binaryDistributionLockManager.writeUnlock(lockKey); } } }
ApplicationServiceImpl implements ApplicationService { @Override @Transactional public CommandOutput deployConf(final String appName, final String groupName, final String jvmName, final String resourceTemplateName, ResourceGroup resourceGroup, User user) { String lockKey = generateKey(groupName, jvmName, appName, resourceTemplateName); try { binaryDistributionLockManager.writeLock(lockKey); ResourceIdentifier resourceIdentifier = new ResourceIdentifier.Builder() .setResourceName(resourceTemplateName) .setGroupName(groupName) .setWebAppName(appName) .setJvmName(jvmName) .build(); final Jvm jvm = jvmPersistenceService.findJvmByExactName(jvmName); checkJvmStateBeforeDeploy(jvm, resourceIdentifier); String hostName = jvm.getHostName(); Group group = groupPersistenceService.getGroup(groupName); historyFacadeService.write(hostName, group, "Deploying application resource " + resourceTemplateName, EventType.USER_ACTION_INFO, user.getId()); return resourceService.generateAndDeployFile(resourceIdentifier, appName + "-" + jvmName, resourceTemplateName, jvm.getHostName()); } catch (ResourceFileGeneratorException e) { LOGGER.error("Fail to generate the resource file {}", resourceTemplateName, e); throw new DeployApplicationConfException(e); } finally { binaryDistributionLockManager.writeUnlock(lockKey); } } ApplicationServiceImpl(final ApplicationPersistenceService applicationPersistenceService,
                                  final JvmPersistenceService jvmPersistenceService,
                                  final GroupPersistenceService groupPersistenceService,
                                  final ResourceService resourceService,
                                  final BinaryDistributionService binaryDistributionService,
                                  final HistoryFacadeService historyFacadeService,
                                  final BinaryDistributionLockManager binaryDistributionLockManager); }
ApplicationServiceImpl implements ApplicationService { @Override @Transactional public CommandOutput deployConf(final String appName, final String groupName, final String jvmName, final String resourceTemplateName, ResourceGroup resourceGroup, User user) { String lockKey = generateKey(groupName, jvmName, appName, resourceTemplateName); try { binaryDistributionLockManager.writeLock(lockKey); ResourceIdentifier resourceIdentifier = new ResourceIdentifier.Builder() .setResourceName(resourceTemplateName) .setGroupName(groupName) .setWebAppName(appName) .setJvmName(jvmName) .build(); final Jvm jvm = jvmPersistenceService.findJvmByExactName(jvmName); checkJvmStateBeforeDeploy(jvm, resourceIdentifier); String hostName = jvm.getHostName(); Group group = groupPersistenceService.getGroup(groupName); historyFacadeService.write(hostName, group, "Deploying application resource " + resourceTemplateName, EventType.USER_ACTION_INFO, user.getId()); return resourceService.generateAndDeployFile(resourceIdentifier, appName + "-" + jvmName, resourceTemplateName, jvm.getHostName()); } catch (ResourceFileGeneratorException e) { LOGGER.error("Fail to generate the resource file {}", resourceTemplateName, e); throw new DeployApplicationConfException(e); } finally { binaryDistributionLockManager.writeUnlock(lockKey); } } ApplicationServiceImpl(final ApplicationPersistenceService applicationPersistenceService,
                                  final JvmPersistenceService jvmPersistenceService,
                                  final GroupPersistenceService groupPersistenceService,
                                  final ResourceService resourceService,
                                  final BinaryDistributionService binaryDistributionService,
                                  final HistoryFacadeService historyFacadeService,
                                  final BinaryDistributionLockManager binaryDistributionLockManager); @Transactional(readOnly = true) @Override Application getApplication(Identifier<Application> aApplicationId); @Transactional(readOnly = true) @Override Application getApplication(final String name); @Transactional(readOnly = true) @Override List<Application> getApplications(); @Transactional(readOnly = true) @Override List<Application> findApplications(Identifier<Group> groupId); @Transactional(readOnly = true) @Override List<Application> findApplicationsByJvmId(Identifier<Jvm> jvmId); @Transactional @Override Application updateApplication(UpdateApplicationRequest updateApplicationRequest, User anUpdatingUser); @Transactional @Override Application createApplication(final CreateApplicationRequest createApplicationRequest,
                                         final User aCreatingUser); @Transactional @Override void removeApplication(Identifier<Application> anAppIdToRemove, User user); @Override @Transactional(readOnly = true) List<String> getResourceTemplateNames(final String appName, final String jvmName); @Override @Transactional String updateResourceTemplate(final String appName, final String resourceTemplateName, final String template, final String jvmName, final String groupName); @Override @Transactional // TODO: Have an option to do a hot deploy or not. CommandOutput deployConf(final String appName, final String groupName, final String jvmName,
                                    final String resourceTemplateName, ResourceGroup resourceGroup, User user); @Override @Transactional JpaApplicationConfigTemplate uploadAppTemplate(UploadAppTemplateRequest uploadAppTemplateRequest); @Override @Transactional String previewResourceTemplate(String fileName, String appName, String groupName, String jvmName, String template, ResourceGroup resourceGroup); @Override @Transactional void copyApplicationWarToGroupHosts(Application application); @Override void deployApplicationResourcesToGroupHosts(String groupName, Application app, ResourceGroup resourceGroup); @Override @Transactional void copyApplicationWarToHost(Application application, String hostName); @Override void deployConf(final String appName, final String hostName, final User user); }
ApplicationServiceImpl implements ApplicationService { @Override @Transactional public CommandOutput deployConf(final String appName, final String groupName, final String jvmName, final String resourceTemplateName, ResourceGroup resourceGroup, User user) { String lockKey = generateKey(groupName, jvmName, appName, resourceTemplateName); try { binaryDistributionLockManager.writeLock(lockKey); ResourceIdentifier resourceIdentifier = new ResourceIdentifier.Builder() .setResourceName(resourceTemplateName) .setGroupName(groupName) .setWebAppName(appName) .setJvmName(jvmName) .build(); final Jvm jvm = jvmPersistenceService.findJvmByExactName(jvmName); checkJvmStateBeforeDeploy(jvm, resourceIdentifier); String hostName = jvm.getHostName(); Group group = groupPersistenceService.getGroup(groupName); historyFacadeService.write(hostName, group, "Deploying application resource " + resourceTemplateName, EventType.USER_ACTION_INFO, user.getId()); return resourceService.generateAndDeployFile(resourceIdentifier, appName + "-" + jvmName, resourceTemplateName, jvm.getHostName()); } catch (ResourceFileGeneratorException e) { LOGGER.error("Fail to generate the resource file {}", resourceTemplateName, e); throw new DeployApplicationConfException(e); } finally { binaryDistributionLockManager.writeUnlock(lockKey); } } ApplicationServiceImpl(final ApplicationPersistenceService applicationPersistenceService,
                                  final JvmPersistenceService jvmPersistenceService,
                                  final GroupPersistenceService groupPersistenceService,
                                  final ResourceService resourceService,
                                  final BinaryDistributionService binaryDistributionService,
                                  final HistoryFacadeService historyFacadeService,
                                  final BinaryDistributionLockManager binaryDistributionLockManager); @Transactional(readOnly = true) @Override Application getApplication(Identifier<Application> aApplicationId); @Transactional(readOnly = true) @Override Application getApplication(final String name); @Transactional(readOnly = true) @Override List<Application> getApplications(); @Transactional(readOnly = true) @Override List<Application> findApplications(Identifier<Group> groupId); @Transactional(readOnly = true) @Override List<Application> findApplicationsByJvmId(Identifier<Jvm> jvmId); @Transactional @Override Application updateApplication(UpdateApplicationRequest updateApplicationRequest, User anUpdatingUser); @Transactional @Override Application createApplication(final CreateApplicationRequest createApplicationRequest,
                                         final User aCreatingUser); @Transactional @Override void removeApplication(Identifier<Application> anAppIdToRemove, User user); @Override @Transactional(readOnly = true) List<String> getResourceTemplateNames(final String appName, final String jvmName); @Override @Transactional String updateResourceTemplate(final String appName, final String resourceTemplateName, final String template, final String jvmName, final String groupName); @Override @Transactional // TODO: Have an option to do a hot deploy or not. CommandOutput deployConf(final String appName, final String groupName, final String jvmName,
                                    final String resourceTemplateName, ResourceGroup resourceGroup, User user); @Override @Transactional JpaApplicationConfigTemplate uploadAppTemplate(UploadAppTemplateRequest uploadAppTemplateRequest); @Override @Transactional String previewResourceTemplate(String fileName, String appName, String groupName, String jvmName, String template, ResourceGroup resourceGroup); @Override @Transactional void copyApplicationWarToGroupHosts(Application application); @Override void deployApplicationResourcesToGroupHosts(String groupName, Application app, ResourceGroup resourceGroup); @Override @Transactional void copyApplicationWarToHost(Application application, String hostName); @Override void deployConf(final String appName, final String hostName, final User user);  }