@Test public void testDeployApplicationResourcesToGroupHosts() throws IOException { reset(Config.mockResourceService); Jvm mockJvm = mock(Jvm.class); when(mockJvm.getHostName()).thenReturn("mock-hostname"); Group mockGroup = mock(Group.class); when(mockGroup.getName()).thenReturn("mock-group-name"); when(mockGroup.getId()).thenReturn(new Identifier<Group>(999L)); Application mockApplicationForDeploy = mock(Application.class); when(mockApplicationForDeploy.getGroup()).thenReturn(mockGroup); when(mockApplicationForDeploy.getWarPath()).thenReturn("./src/test/resources/archive/test_archive.war"); when(mockApplicationForDeploy.getWarName()).thenReturn("mock-application-war-name"); when(mockApplicationForDeploy.getName()).thenReturn("mock-application-name"); when(mockApplicationForDeploy.isUnpackWar()).thenReturn(false); ResourceGroup mockResourceGroup = mock(ResourceGroup.class); Entity mockEntity = mock(Entity.class); when(mockEntity.getDeployToJvms()).thenReturn(false); ResourceTemplateMetaData mockResourceTemplateMetaData = mock(ResourceTemplateMetaData.class); when(mockResourceTemplateMetaData.getEntity()).thenReturn(mockEntity); when(Config.mockGroupPersistenceService.getGroupAppsResourceTemplateNames(anyString())).thenReturn(Collections.singletonList("mock-application-resource")); when(Config.mockGroupPersistenceService.getGroupAppResourceTemplateMetaData(anyString(), anyString(), anyString())).thenReturn("{\"fake\":\"meta-data\"}"); when(Config.mockResourceService.getTokenizedMetaData(anyString(), anyObject(), anyString())).thenReturn(mockResourceTemplateMetaData); when(Config.mockResourceService.generateAndDeployFile(any(ResourceIdentifier.class), anyString(), anyString(), anyString())).thenReturn(new CommandOutput(new ExecReturnCode(0), "Generate and deploy succeeded", "")); when(Config.jvmPersistenceService.getJvmsByGroupName(anyString())).thenReturn(Collections.singletonList(mockJvm)); applicationService.deployApplicationResourcesToGroupHosts("mock-group-name", mockApplicationForDeploy, mockResourceGroup); verify(Config.mockResourceService, times(1)).generateAndDeployFile(any(ResourceIdentifier.class), anyString(), anyString(), anyString()); }
@Override public void deployApplicationResourcesToGroupHosts(String groupName, Application app, ResourceGroup resourceGroup) { List<String> appResourcesNames = groupPersistenceService.getGroupAppsResourceTemplateNames(groupName); final List<Jvm> jvms = jvmPersistenceService.getJvmsByGroupName(groupName); if (null != appResourcesNames && !appResourcesNames.isEmpty()) { for (String resourceTemplateName : appResourcesNames) { String metaDataStr = groupPersistenceService.getGroupAppResourceTemplateMetaData(groupName, resourceTemplateName, app.getName()); try { ResourceTemplateMetaData metaData = resourceService.getTokenizedMetaData(resourceTemplateName, app, metaDataStr); if (jvms != null && !jvms.isEmpty() && !metaData.getEntity().getDeployToJvms()) { Set<String> hostNames = new HashSet<>(); for (Jvm jvm : jvms) { final String host = jvm.getHostName().toLowerCase(Locale.US); if (!hostNames.contains(host)) { hostNames.add(host); executeDeployGroupAppTemplate(groupName, resourceTemplateName, app, jvm.getHostName()); } } } } catch (IOException e) { LOGGER.error("Failed to map meta data for template {} in group {}", resourceTemplateName, groupName, e); throw new InternalErrorException(FaultType.BAD_STREAM, "Failed to read meta data for template " + resourceTemplateName + " in group " + groupName, e); } } } }
ApplicationServiceImpl implements ApplicationService { @Override public void deployApplicationResourcesToGroupHosts(String groupName, Application app, ResourceGroup resourceGroup) { List<String> appResourcesNames = groupPersistenceService.getGroupAppsResourceTemplateNames(groupName); final List<Jvm> jvms = jvmPersistenceService.getJvmsByGroupName(groupName); if (null != appResourcesNames && !appResourcesNames.isEmpty()) { for (String resourceTemplateName : appResourcesNames) { String metaDataStr = groupPersistenceService.getGroupAppResourceTemplateMetaData(groupName, resourceTemplateName, app.getName()); try { ResourceTemplateMetaData metaData = resourceService.getTokenizedMetaData(resourceTemplateName, app, metaDataStr); if (jvms != null && !jvms.isEmpty() && !metaData.getEntity().getDeployToJvms()) { Set<String> hostNames = new HashSet<>(); for (Jvm jvm : jvms) { final String host = jvm.getHostName().toLowerCase(Locale.US); if (!hostNames.contains(host)) { hostNames.add(host); executeDeployGroupAppTemplate(groupName, resourceTemplateName, app, jvm.getHostName()); } } } } catch (IOException e) { LOGGER.error("Failed to map meta data for template {} in group {}", resourceTemplateName, groupName, e); throw new InternalErrorException(FaultType.BAD_STREAM, "Failed to read meta data for template " + resourceTemplateName + " in group " + groupName, e); } } } } }
ApplicationServiceImpl implements ApplicationService { @Override public void deployApplicationResourcesToGroupHosts(String groupName, Application app, ResourceGroup resourceGroup) { List<String> appResourcesNames = groupPersistenceService.getGroupAppsResourceTemplateNames(groupName); final List<Jvm> jvms = jvmPersistenceService.getJvmsByGroupName(groupName); if (null != appResourcesNames && !appResourcesNames.isEmpty()) { for (String resourceTemplateName : appResourcesNames) { String metaDataStr = groupPersistenceService.getGroupAppResourceTemplateMetaData(groupName, resourceTemplateName, app.getName()); try { ResourceTemplateMetaData metaData = resourceService.getTokenizedMetaData(resourceTemplateName, app, metaDataStr); if (jvms != null && !jvms.isEmpty() && !metaData.getEntity().getDeployToJvms()) { Set<String> hostNames = new HashSet<>(); for (Jvm jvm : jvms) { final String host = jvm.getHostName().toLowerCase(Locale.US); if (!hostNames.contains(host)) { hostNames.add(host); executeDeployGroupAppTemplate(groupName, resourceTemplateName, app, jvm.getHostName()); } } } } catch (IOException e) { LOGGER.error("Failed to map meta data for template {} in group {}", resourceTemplateName, groupName, e); throw new InternalErrorException(FaultType.BAD_STREAM, "Failed to read meta data for template " + resourceTemplateName + " in group " + groupName, e); } } } } 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 public void deployApplicationResourcesToGroupHosts(String groupName, Application app, ResourceGroup resourceGroup) { List<String> appResourcesNames = groupPersistenceService.getGroupAppsResourceTemplateNames(groupName); final List<Jvm> jvms = jvmPersistenceService.getJvmsByGroupName(groupName); if (null != appResourcesNames && !appResourcesNames.isEmpty()) { for (String resourceTemplateName : appResourcesNames) { String metaDataStr = groupPersistenceService.getGroupAppResourceTemplateMetaData(groupName, resourceTemplateName, app.getName()); try { ResourceTemplateMetaData metaData = resourceService.getTokenizedMetaData(resourceTemplateName, app, metaDataStr); if (jvms != null && !jvms.isEmpty() && !metaData.getEntity().getDeployToJvms()) { Set<String> hostNames = new HashSet<>(); for (Jvm jvm : jvms) { final String host = jvm.getHostName().toLowerCase(Locale.US); if (!hostNames.contains(host)) { hostNames.add(host); executeDeployGroupAppTemplate(groupName, resourceTemplateName, app, jvm.getHostName()); } } } } catch (IOException e) { LOGGER.error("Failed to map meta data for template {} in group {}", resourceTemplateName, groupName, e); throw new InternalErrorException(FaultType.BAD_STREAM, "Failed to read meta data for template " + resourceTemplateName + " in group " + groupName, e); } } } } 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 public void deployApplicationResourcesToGroupHosts(String groupName, Application app, ResourceGroup resourceGroup) { List<String> appResourcesNames = groupPersistenceService.getGroupAppsResourceTemplateNames(groupName); final List<Jvm> jvms = jvmPersistenceService.getJvmsByGroupName(groupName); if (null != appResourcesNames && !appResourcesNames.isEmpty()) { for (String resourceTemplateName : appResourcesNames) { String metaDataStr = groupPersistenceService.getGroupAppResourceTemplateMetaData(groupName, resourceTemplateName, app.getName()); try { ResourceTemplateMetaData metaData = resourceService.getTokenizedMetaData(resourceTemplateName, app, metaDataStr); if (jvms != null && !jvms.isEmpty() && !metaData.getEntity().getDeployToJvms()) { Set<String> hostNames = new HashSet<>(); for (Jvm jvm : jvms) { final String host = jvm.getHostName().toLowerCase(Locale.US); if (!hostNames.contains(host)) { hostNames.add(host); executeDeployGroupAppTemplate(groupName, resourceTemplateName, app, jvm.getHostName()); } } } } catch (IOException e) { LOGGER.error("Failed to map meta data for template {} in group {}", resourceTemplateName, groupName, e); throw new InternalErrorException(FaultType.BAD_STREAM, "Failed to read meta data for template " + resourceTemplateName + " in group " + groupName, e); } } } } 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);  }