private ContainerSpec copy(final ContainerSpec origin, final String newServerTemplateId, final String newServerTemplateName) { final Map<Capability, ContainerConfig> configMap = origin.getConfigs(); for (Map.Entry<Capability, ContainerConfig> entry : origin.getConfigs().entrySet()) { configMap.put(entry.getKey(), copy(entry.getValue())); } return new ContainerSpec(origin.getId(), origin.getContainerName(), new ServerTemplateKey(newServerTemplateId, newServerTemplateName), new ReleaseId(origin.getReleasedId()), origin.getStatus(), configMap); }
public static ContainerSpec newContainerSpec() { final ContainerSpec spec = new ContainerSpec(); spec.setId("id"); spec.setContainerName("name"); spec.setStatus(KieContainerStatus.STARTED); spec.setReleasedId(new ReleaseId("groupId", "artifactId", "1.0")); return spec; }
private void addContainer( final ContainerSpec containerSpec ) { view.addContainer( containerSpec.getServerTemplateKey().getId(), containerSpec.getId(), containerSpec.getContainerName(), new Command() { @Override public void execute() { containerSpecSelectedEvent.fire( new ContainerSpecSelected( containerSpec ) ); } } ); }
ContainerSpec containerSpec = new ContainerSpec(); containerSpec.setId("test container"); containerSpec.setServerTemplateKey(new ServerTemplateKey(serverTemplate.getId(), serverTemplate.getName())); containerSpec.setReleasedId(new ReleaseId("org.kie", "kie-server-kjar", "1.0")); containerSpec.setStatus(KieContainerStatus.STOPPED); containerSpec.setConfigs(configs); assertNotNull(container); assertEquals(containerSpec.getId(), container.getId()); assertEquals(containerSpec.getStatus(), container.getStatus()); assertEquals(containerSpec.getServerTemplateKey(), container.getServerTemplateKey()); assertEquals(containerSpec.getReleasedId(), container.getReleasedId()); assertNotNull(container.getConfigs()); assertEquals(containerSpec.getConfigs().size(), container.getConfigs().size()); assertNotNull(container); assertEquals(containerSpec.getId(), container.getId()); assertEquals(containerSpec.getStatus(), container.getStatus()); assertEquals(containerSpec.getServerTemplateKey(), container.getServerTemplateKey()); assertEquals(containerSpec.getReleasedId(), container.getReleasedId()); assertNotNull(container.getConfigs()); assertEquals(containerSpec.getConfigs().size(), container.getConfigs().size());
@Test public void testContainerSpecSerialization() { final ContainerSpec spec = new ContainerSpec(); spec.setId("id"); spec.setContainerName("name"); spec.setStatus(KieContainerStatus.STARTED); spec.setReleasedId(new ReleaseId("groupId", "artifactId", "1.0")); "kSession", "mergeMode"); spec.addConfig(Capability.PROCESS, processConfig); final RuleConfig ruleConfig = new RuleConfig(1L, KieScannerStatus.SCANNING); spec.addConfig(Capability.RULE, ruleConfig); final String specContent = WebSocketUtils.marshal(spec); assertEquals(spec, specResult); assertEquals(spec.getId(), specResult.getId()); assertEquals(spec.getStatus(), specResult.getStatus()); assertEquals(spec.getContainerName(), specResult.getContainerName()); assertEquals(spec.getReleasedId(), specResult.getReleasedId());
containerSpec = new ContainerSpec(); containerSpec.setId("test container"); containerSpec.setServerTemplateKey(new ServerTemplateKey(serverTemplate.getId(), serverTemplate.getName())); containerSpec.setReleasedId(new ReleaseId("org.kie", "kie-server-kjar", "1.0")); containerSpec.setStatus(KieContainerStatus.STOPPED); containerSpec.setConfigs(configs); container.setServerInstanceId(serverTemplate.getId()); container.setServerTemplateId(serverTemplate.getId()); container.setResolvedReleasedId(containerSpec.getReleasedId()); container.setContainerName(containerSpec.getContainerName()); container.setContainerSpecId(containerSpec.getId()); container.setUrl("http://fake.server.net/kie-server");
assertNotNull(spec); assertEquals(containerSpec.getId(), spec.getId()); assertEquals(containerSpec.getReleasedId(), spec.getReleasedId()); assertEquals(containerSpec.getServerTemplateKey().getId(), spec.getServerTemplateKey().getId()); assertEquals(containerSpec.getServerTemplateKey().getName(), spec.getServerTemplateKey().getName()); assertEquals(containerSpec.getConfigs().size(), spec.getConfigs().size()); assertTrue(spec.getConfigs().containsKey(Capability.RULE)); assertTrue(spec.getConfigs().containsKey(Capability.PROCESS)); RuleConfig ruleConfig = (RuleConfig) spec.getConfigs().get(Capability.RULE); assertNotNull(ruleConfig); assertEquals(this.ruleConfig.getPollInterval(), ruleConfig.getPollInterval()); assertEquals(this.ruleConfig.getScannerStatus(), ruleConfig.getScannerStatus()); ProcessConfig processConfig = (ProcessConfig) spec.getConfigs().get(Capability.PROCESS); assertNotNull(processConfig); assertEquals(this.processConfig.getKBase(), processConfig.getKBase());
@Before public void prepare() { returnedContainers.clear(); serverTemplate = new ServerTemplate(); serverTemplate.setName("test server"); serverTemplate.setId(UUID.randomUUID().toString()); containerSpec = new ContainerSpec(); containerSpec.setId("test container"); containerSpec.setServerTemplateKey(new ServerTemplateKey(serverTemplate.getId(), serverTemplate.getName())); containerSpec.setReleasedId(new ReleaseId("org.kie", "kie-server-kjar", "1.0")); containerSpec.setStatus(KieContainerStatus.STOPPED); containerSpec.setConfigs(new HashMap<Capability, ContainerConfig>()); serverTemplate.addContainerSpec(containerSpec); this.kieServerInstanceManager = new AsyncKieServerInstanceManager(notificationService, containerUpdateEvent, executor) { @Override protected List<Container> callRemoteKieServerOperation(ServerTemplate serverTemplate, ContainerSpec containerSpec, RemoteKieServerOperation operation) { return returnedContainers; } }; this.kieServerInstanceManager.setExecutor(executor); }
public void deleteContainerSpec(String containerSpecId) { if (containersSpec == null) { return; } Iterator<ContainerSpec> iterator = containersSpec.iterator(); while(iterator.hasNext()) { ContainerSpec spec = iterator.next(); if (containerSpecId.equals(spec.getId())) { iterator.remove(); } } }
private void remoteUpgradeContainer(final KieServicesClient client, final Container container, final ContainerSpec containerSpec) { final ServiceResponse<ReleaseId> response = client.updateReleaseId(containerSpec.getId(), containerSpec.getReleasedId()); if (response.getType() != ServiceResponse.ResponseType.SUCCESS) { log("Container {} failed to upgrade on server instance {} due to {}", containerSpec.getId(), container.getUrl(), response.getMsg()); } collectContainerInfo(containerSpec, client, container); }
final ContainerSpec containerSpec = new ContainerSpec( "containerId", "containerName", serverTemplate, releaseId, KieContainerStatus.CREATING, null ); serverTemplate.addContainerSpec( containerSpec ); final ContainerSpec containerSpec1 = new ContainerSpec( "containerId1", "containerName1", serverTemplate, new ReleaseId( "org.kie", "container2", "1.0.0" ), KieContainerStatus.CREATING, null ); serverTemplate.addContainerSpec( containerSpec1 ); eq( containerSpec.getServerTemplateKey().getId() ), eq( containerSpec.getId() ), eq( containerSpec.getContainerName() ), any( Command.class ) ); eq( containerSpec1.getServerTemplateKey().getId() ), eq( containerSpec1.getId() ), eq( containerSpec1.getContainerName() ), any( Command.class ) );
@Test public void testContainerSpecUpdated() { handler.accept(new ContainerSpecUpdated(new ServerTemplate(), new ContainerSpec(), new ArrayList<>())); verify(eventHandler).onContainerSpecUpdated(any()); verifyNoMoreInteractions(eventHandler); } }
@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 public synchronized void updateContainerSpec(final String serverTemplateId, final String containerId, final ContainerSpec containerSpec) { ServerTemplate serverTemplate = templateStorage.load(serverTemplateId); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + serverTemplateId); } if (!containerSpec.getId().equals(containerId)) { throw new KieServerControllerException("Cannot update container " + containerSpec.getId() + " on container " + containerId); } if (!serverTemplate.hasContainerSpec(containerSpec.getId())) { throw new KieServerControllerIllegalArgumentException("Server template with id " + serverTemplateId + " has no container with id " + containerSpec.getId()); } if (!serverTemplate.hasMatchingId(containerSpec.getServerTemplateKey())) { throw new KieServerControllerException("Cannot change container template key during update."); } // make sure correct server template is set containerSpec.setServerTemplateKey(new ServerTemplateKey(serverTemplate.getId(), serverTemplate.getName())); ContainerSpec currentVersion = serverTemplate.getContainerSpec(containerSpec.getId()); serverTemplate.deleteContainerSpec(currentVersion.getId()); serverTemplate.addContainerSpec(containerSpec); templateStorage.update(serverTemplate); notificationService.notify(new ServerTemplateUpdated(serverTemplate)); // in case container was started before it was update or update comes with status started update container in running servers if (currentVersion.getStatus().equals(KieContainerStatus.STARTED) || containerSpec.getStatus().equals(KieContainerStatus.STARTED)) { List<Container> containers = kieServerInstanceManager.upgradeAndStartContainer(serverTemplate, containerSpec); notificationService.notify(serverTemplate, containerSpec, containers); } }
@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); }
protected List<Container> callRemoteKieServerOperation(ServerTemplate serverTemplate, ContainerSpec containerSpec, RemoteKieServerOperation operation) { List<Container> containers = new ArrayList<org.kie.server.controller.api.model.runtime.Container>(); if (serverTemplate.getServerInstanceKeys() == null || serverTemplate.getServerInstanceKeys().isEmpty() || containerSpec == null) { return containers; } for (ServerInstanceKey instanceUrl : serverTemplate.getServerInstanceKeys()) { Container container = new Container(); container.setContainerSpecId(containerSpec.getId()); container.setServerTemplateId(serverTemplate.getId()); container.setServerInstanceId(instanceUrl.getServerInstanceId()); container.setUrl(instanceUrl.getUrl() + "/containers/" + containerSpec.getId()); container.setStatus(containerSpec.getStatus()); try { final KieServicesClient client = getClient(instanceUrl.getUrl()); operation.doOperation(client, container); containers.add(container); } catch (Exception e) { logger.debug("Unable to connect to {}", instanceUrl); } } return containers; }
final ServerTemplate serverTemplate = new ServerTemplate( "ServerTemplateId", "ServerTemplateName" ); serverTemplate.getCapabilities().add( Capability.PROCESS.toString() ); final ContainerSpec containerSpec = new ContainerSpec(); containerSpec.setId( "containerSpecId" ); when( newContainerFormPresenter.buildContainerSpec( eq( serverTemplate.getId() ), anyMap() ) ).thenReturn( containerSpec ); when( newContainerFormPresenter.getServerTemplate() ).thenReturn( serverTemplate ); final ServerTemplateSelected serverEvent = serverTemplateEventCaptor.getValue(); assertEquals( serverTemplate, serverEvent.getServerTemplateKey() ); assertEquals( containerSpec.getId(), serverEvent.getContainerId() );
@Override public void execute() { specManagementService.call(new RemoteCallback<Void>() { @Override public void callback(final Void response) { notification.fire(new NotificationEvent(view.getRemoveContainerSuccessMessage(), NotificationEvent.NotificationType.SUCCESS)); serverTemplateSelectedEvent.fire(new ServerTemplateSelected(containerSpec.getServerTemplateKey())); } }, new ErrorCallback<Object>() { @Override public boolean error(final Object o, final Throwable throwable) { notification.fire(new NotificationEvent(view.getRemoveContainerErrorMessage(), NotificationEvent.NotificationType.ERROR)); serverTemplateSelectedEvent.fire(new ServerTemplateSelected(containerSpec.getServerTemplateKey())); return false; } }).deleteContainerSpec(containerSpec.getServerTemplateKey().getId(), containerSpec.getId()); } });
times(times)).setContainerName(containerSpec.getContainerName()); verify(view, times(times)).setGroupIp(containerSpec.getReleasedId().getGroupId()); verify(view, times(times)).setArtifactId(containerSpec.getReleasedId().getArtifactId()); verify(containerRulesConfigPresenter, times(times)).setVersion(releaseId.getVersion()); (ProcessConfig) containerSpec.getConfigs().get(Capability.PROCESS)); verify(containerRulesConfigPresenter, times(times)).setup(containerSpec, (RuleConfig) containerSpec.getConfigs().get(Capability.RULE));
@Override public synchronized void saveContainerSpec(String serverTemplateId, ContainerSpec containerSpec) { ServerTemplate serverTemplate = templateStorage.load(serverTemplateId); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + serverTemplateId); } if (serverTemplate.hasContainerSpec(containerSpec.getId())) { throw new KieServerControllerException("Server template with id " + serverTemplateId + " associated already with container " + containerSpec.getId()); } // make sure correct server template is set containerSpec.setServerTemplateKey(new ServerTemplateKey(serverTemplate.getId(), serverTemplate.getName())); serverTemplate.addContainerSpec(containerSpec); templateStorage.update(serverTemplate); notificationService.notify(new ServerTemplateUpdated(serverTemplate)); if (containerSpec.getStatus().equals(KieContainerStatus.STARTED)) { List<Container> containers = kieServerInstanceManager.startContainer(serverTemplate, containerSpec); notificationService.notify(serverTemplate, containerSpec, containers); } }