@Test public void testUpgradeContainerWhenContainerSpecStatusIsStarted() { final List<Container> fakeResult = new ArrayList<Container>() {{ add(container); }}; doReturn(fakeResult).when(kieServerInstanceManager).upgradeContainer(any(ServerTemplate.class), any(ContainerSpec.class)); containerSpec.setStatus(KieContainerStatus.STARTED); final ReleaseId initial = containerSpec.getReleasedId(); final ReleaseId upgradeTo = new ReleaseId("org.kie", "kie-server-kjar", "2.0"); ruleCapabilitiesService.upgradeContainer(containerSpec, upgradeTo); verify(kieServerInstanceManager).upgradeContainer(any(ServerTemplate.class), any(ContainerSpec.class)); final ServerTemplate updated = specManagementService.getServerTemplate(serverTemplate.getId()); final Collection<ContainerSpec> containerSpecs = updated.getContainersSpec(); assertNotNull(containerSpecs); assertEquals(1, containerSpecs.size()); ContainerSpec updatedContainer = containerSpecs.iterator().next(); assertNotNull(updatedContainer); assertNotNull(updatedContainer.getReleasedId()); assertNotEquals(initial, updatedContainer.getReleasedId()); assertEquals(upgradeTo, updatedContainer.getReleasedId()); assertEquals(updatedContainer.getStatus(), KieContainerStatus.STARTED); }
@Override public void upgradeContainer(final ContainerSpecKey containerSpecKey, ReleaseId releaseId) { ServerTemplate serverTemplate = templateStorage.load(containerSpecKey.getServerTemplateKey().getId()); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + containerSpecKey.getServerTemplateKey().getId()); } ContainerSpec containerSpec = serverTemplate.getContainerSpec(containerSpecKey.getId()); if (containerSpec == null) { throw new KieServerControllerIllegalArgumentException("No container spec found for id " + containerSpecKey.getId()); } if (releaseId.getGroupId() == null) { releaseId.setGroupId(containerSpec.getReleasedId().getGroupId()); } if (releaseId.getArtifactId() == null) { releaseId.setArtifactId(containerSpec.getReleasedId().getArtifactId()); } final List<Container> containers; containerSpec.setReleasedId(releaseId); if (containerSpec.getStatus() == KieContainerStatus.STARTED) { containers = kieServerInstanceManager.upgradeContainer(serverTemplate, containerSpec); } else { containers = kieServerInstanceManager.startContainer(serverTemplate, containerSpec); } containerSpec.setStatus(KieContainerStatus.STARTED); templateStorage.update(serverTemplate); notificationService.notify(serverTemplate, containerSpec, containers); }
RuleCapabilitiesServiceImpl implements RuleCapabilitiesService { @Override public void upgradeContainer(final ContainerSpecKey containerSpecKey, ReleaseId releaseId) { ServerTemplate serverTemplate = templateStorage.load(containerSpecKey.getServerTemplateKey().getId()); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + containerSpecKey.getServerTemplateKey().getId()); } ContainerSpec containerSpec = serverTemplate.getContainerSpec(containerSpecKey.getId()); if (containerSpec == null) { throw new KieServerControllerIllegalArgumentException("No container spec found for id " + containerSpecKey.getId()); } if (releaseId.getGroupId() == null) { releaseId.setGroupId(containerSpec.getReleasedId().getGroupId()); } if (releaseId.getArtifactId() == null) { releaseId.setArtifactId(containerSpec.getReleasedId().getArtifactId()); } final List<Container> containers; containerSpec.setReleasedId(releaseId); if (containerSpec.getStatus() == KieContainerStatus.STARTED) { containers = kieServerInstanceManager.upgradeContainer(serverTemplate, containerSpec); } else { containers = kieServerInstanceManager.startContainer(serverTemplate, containerSpec); } containerSpec.setStatus(KieContainerStatus.STARTED); templateStorage.update(serverTemplate); notificationService.notify(serverTemplate, containerSpec, containers); } }
RuleCapabilitiesServiceImpl implements RuleCapabilitiesService { @Override public void upgradeContainer(final ContainerSpecKey containerSpecKey, ReleaseId releaseId) { ServerTemplate serverTemplate = templateStorage.load(containerSpecKey.getServerTemplateKey().getId()); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + containerSpecKey.getServerTemplateKey().getId()); } ContainerSpec containerSpec = serverTemplate.getContainerSpec(containerSpecKey.getId()); if (containerSpec == null) { throw new KieServerControllerIllegalArgumentException("No container spec found for id " + containerSpecKey.getId()); } if (releaseId.getGroupId() == null) { releaseId.setGroupId(containerSpec.getReleasedId().getGroupId()); } if (releaseId.getArtifactId() == null) { releaseId.setArtifactId(containerSpec.getReleasedId().getArtifactId()); } final List<Container> containers; containerSpec.setReleasedId(releaseId); if (containerSpec.getStatus() == KieContainerStatus.STARTED) { containers = kieServerInstanceManager.upgradeContainer(serverTemplate, containerSpec); } else { containers = kieServerInstanceManager.startContainer(serverTemplate, containerSpec); } containerSpec.setStatus(KieContainerStatus.STARTED); templateStorage.update(serverTemplate); notificationService.notify(serverTemplate, containerSpec, containers); }  }
RuleCapabilitiesServiceImpl implements RuleCapabilitiesService { @Override public void upgradeContainer(final ContainerSpecKey containerSpecKey, ReleaseId releaseId) { ServerTemplate serverTemplate = templateStorage.load(containerSpecKey.getServerTemplateKey().getId()); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + containerSpecKey.getServerTemplateKey().getId()); } ContainerSpec containerSpec = serverTemplate.getContainerSpec(containerSpecKey.getId()); if (containerSpec == null) { throw new KieServerControllerIllegalArgumentException("No container spec found for id " + containerSpecKey.getId()); } if (releaseId.getGroupId() == null) { releaseId.setGroupId(containerSpec.getReleasedId().getGroupId()); } if (releaseId.getArtifactId() == null) { releaseId.setArtifactId(containerSpec.getReleasedId().getArtifactId()); } final List<Container> containers; containerSpec.setReleasedId(releaseId); if (containerSpec.getStatus() == KieContainerStatus.STARTED) { containers = kieServerInstanceManager.upgradeContainer(serverTemplate, containerSpec); } else { containers = kieServerInstanceManager.startContainer(serverTemplate, containerSpec); } containerSpec.setStatus(KieContainerStatus.STARTED); templateStorage.update(serverTemplate); notificationService.notify(serverTemplate, containerSpec, containers); }  @Override void scanNow(final ContainerSpecKey containerSpecKey); @Override void startScanner(final ContainerSpecKey containerSpecKey,
                             final Long interval); @Override void stopScanner(final ContainerSpecKey containerSpecKey); @Override void upgradeContainer(final ContainerSpecKey containerSpecKey,
                                 ReleaseId releaseId); KieServerTemplateStorage getTemplateStorage(); void setTemplateStorage(KieServerTemplateStorage templateStorage); KieServerInstanceManager getKieServerInstanceManager(); void setKieServerInstanceManager(KieServerInstanceManager kieServerInstanceManager); NotificationService getNotificationService(); void setNotificationService(NotificationService notificationService); }
RuleCapabilitiesServiceImpl implements RuleCapabilitiesService { @Override public void upgradeContainer(final ContainerSpecKey containerSpecKey, ReleaseId releaseId) { ServerTemplate serverTemplate = templateStorage.load(containerSpecKey.getServerTemplateKey().getId()); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + containerSpecKey.getServerTemplateKey().getId()); } ContainerSpec containerSpec = serverTemplate.getContainerSpec(containerSpecKey.getId()); if (containerSpec == null) { throw new KieServerControllerIllegalArgumentException("No container spec found for id " + containerSpecKey.getId()); } if (releaseId.getGroupId() == null) { releaseId.setGroupId(containerSpec.getReleasedId().getGroupId()); } if (releaseId.getArtifactId() == null) { releaseId.setArtifactId(containerSpec.getReleasedId().getArtifactId()); } final List<Container> containers; containerSpec.setReleasedId(releaseId); if (containerSpec.getStatus() == KieContainerStatus.STARTED) { containers = kieServerInstanceManager.upgradeContainer(serverTemplate, containerSpec); } else { containers = kieServerInstanceManager.startContainer(serverTemplate, containerSpec); } containerSpec.setStatus(KieContainerStatus.STARTED); templateStorage.update(serverTemplate); notificationService.notify(serverTemplate, containerSpec, containers); }  @Override void scanNow(final ContainerSpecKey containerSpecKey); @Override void startScanner(final ContainerSpecKey containerSpecKey,
                             final Long interval); @Override void stopScanner(final ContainerSpecKey containerSpecKey); @Override void upgradeContainer(final ContainerSpecKey containerSpecKey,
                                 ReleaseId releaseId); KieServerTemplateStorage getTemplateStorage(); void setTemplateStorage(KieServerTemplateStorage templateStorage); KieServerInstanceManager getKieServerInstanceManager(); void setKieServerInstanceManager(KieServerInstanceManager kieServerInstanceManager); NotificationService getNotificationService(); void setNotificationService(NotificationService notificationService);  }