@Test public void testCopyApplicationWarToGroupHosts() throws IOException { Jvm mockJvm = mock(Jvm.class); when(mockJvm.getHostName()).thenReturn("mock-hostname"); Group mockGroup = mock(Group.class); when(mockGroup.getId()).thenReturn(new Identifier<Group>(999L)); when(mockGroup.getJvms()).thenReturn(Collections.singleton(mockJvm)); Application mockApplicationForCopy = mock(Application.class); when(mockApplicationForCopy.getGroup()).thenReturn(mockGroup); when(mockApplicationForCopy.getWarPath()).thenReturn("./src/test/resources/archive/test_archive.war"); when(mockApplicationForCopy.getWarName()).thenReturn("mock-application-war-name"); when(mockApplicationForCopy.getName()).thenReturn("mock-application-name"); when(mockApplicationForCopy.isUnpackWar()).thenReturn(false); when(Config.mockGroupPersistenceService.getGroup(any(Identifier.class))).thenReturn(mockGroup); when(Config.binaryDistributionControlService.createDirectory(anyString(), anyString())).thenReturn(new CommandOutput(new ExecReturnCode(0), "Create directory succeeded", "")); when(Config.binaryDistributionControlService.secureCopyFile(anyString(), anyString(), anyString())).thenReturn(new CommandOutput(new ExecReturnCode(0), "Secure copy succeeded", "")); ResourceTemplateMetaData mockResourceTemplateMetaData = mock(ResourceTemplateMetaData.class); when(mockResourceTemplateMetaData.getDeployPath()).thenReturn("C:/deploy/path"); when(Config.mockResourceService.getResourceContent(any(ResourceIdentifier.class))).thenReturn(new ResourceContent("C:/deploy/path", "content")); when(Config.mockResourceService.getTokenizedMetaData(anyString(), any(Application.class), anyString())).thenReturn(mockResourceTemplateMetaData); applicationService.copyApplicationWarToGroupHosts(mockApplicationForCopy); verify(Config.binaryDistributionService, never()).distributeUnzip(anyString()); }
@Override @Transactional public void copyApplicationWarToGroupHosts(Application application) { Group group = groupPersistenceService.getGroup(application.getGroup().getId()); final Set<Jvm> theJvms = group.getJvms(); if (theJvms != null && !theJvms.isEmpty()) { Set<String> hostNames = new HashSet<>(); for (Jvm jvm : theJvms) { final String host = jvm.getHostName().toLowerCase(Locale.US); if (!hostNames.contains(host)) { hostNames.add(host); } } copyAndExecuteCommand(application, hostNames); } }
ApplicationServiceImpl implements ApplicationService { @Override @Transactional public void copyApplicationWarToGroupHosts(Application application) { Group group = groupPersistenceService.getGroup(application.getGroup().getId()); final Set<Jvm> theJvms = group.getJvms(); if (theJvms != null && !theJvms.isEmpty()) { Set<String> hostNames = new HashSet<>(); for (Jvm jvm : theJvms) { final String host = jvm.getHostName().toLowerCase(Locale.US); if (!hostNames.contains(host)) { hostNames.add(host); } } copyAndExecuteCommand(application, hostNames); } } }
ApplicationServiceImpl implements ApplicationService { @Override @Transactional public void copyApplicationWarToGroupHosts(Application application) { Group group = groupPersistenceService.getGroup(application.getGroup().getId()); final Set<Jvm> theJvms = group.getJvms(); if (theJvms != null && !theJvms.isEmpty()) { Set<String> hostNames = new HashSet<>(); for (Jvm jvm : theJvms) { final String host = jvm.getHostName().toLowerCase(Locale.US); if (!hostNames.contains(host)) { hostNames.add(host); } } copyAndExecuteCommand(application, hostNames); } } 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 void copyApplicationWarToGroupHosts(Application application) { Group group = groupPersistenceService.getGroup(application.getGroup().getId()); final Set<Jvm> theJvms = group.getJvms(); if (theJvms != null && !theJvms.isEmpty()) { Set<String> hostNames = new HashSet<>(); for (Jvm jvm : theJvms) { final String host = jvm.getHostName().toLowerCase(Locale.US); if (!hostNames.contains(host)) { hostNames.add(host); } } copyAndExecuteCommand(application, hostNames); } } 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 void copyApplicationWarToGroupHosts(Application application) { Group group = groupPersistenceService.getGroup(application.getGroup().getId()); final Set<Jvm> theJvms = group.getJvms(); if (theJvms != null && !theJvms.isEmpty()) { Set<String> hostNames = new HashSet<>(); for (Jvm jvm : theJvms) { final String host = jvm.getHostName().toLowerCase(Locale.US); if (!hostNames.contains(host)) { hostNames.add(host); } } copyAndExecuteCommand(application, hostNames); } } 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);  }