public void setup( final ServerTemplate serverTemplate, final ContainerSpec firstContainerSpec ) { view.clear(); this.serverTemplate = serverTemplate; view.setTemplate( serverTemplate.getId(), serverTemplate.getName() ); view.setProcessCapability( serverTemplate.getCapabilities().contains( Capability.PROCESS.toString() ) ); view.setRulesCapability( serverTemplate.getCapabilities().contains( Capability.RULE.toString() ) ); view.setPlanningCapability( serverTemplate.getCapabilities().contains( Capability.PLANNING.toString() ) ); if ( firstContainerSpec != null ) { addContainer( firstContainerSpec ); for ( final ContainerSpec containerSpec : serverTemplate.getContainersSpec() ) { if ( !containerSpec.getId().equals( firstContainerSpec.getId() ) ) { addContainer( containerSpec ); } } containerSpecSelectedEvent.fire( new ContainerSpecSelected( firstContainerSpec ) ); } for ( final ServerInstanceKey serverInstanceKey : serverTemplate.getServerInstanceKeys() ) { addServerInstance( serverInstanceKey ); } }
@Override public synchronized void copyServerTemplate(String serverTemplateId, String newServerTemplateId, String newServerTemplateName) { final ServerTemplate serverTemplate = templateStorage.load(serverTemplateId); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + serverTemplateId); } final Map<Capability, ServerConfig> configMap = new HashMap<Capability, ServerConfig>(serverTemplate.getConfigs().size()); for (final Map.Entry<Capability, ServerConfig> entry : serverTemplate.getConfigs().entrySet()) { configMap.put(entry.getKey(), copy(entry.getValue())); } final Collection<ContainerSpec> containerSpecs = new ArrayList<ContainerSpec>(serverTemplate.getContainersSpec().size()); for (final ContainerSpec entry : serverTemplate.getContainersSpec()) { containerSpecs.add(copy(entry, newServerTemplateId, newServerTemplateName)); } final ServerTemplate copy = new ServerTemplate(newServerTemplateId, newServerTemplateName, serverTemplate.getCapabilities(), configMap, containerSpecs); templateStorage.store(copy); }
protected KieServicesClient createClientForTemplate(ServerTemplate serverTemplate, ClassLoader classLoader, CredentialsProvider credentialsProvider) { if (serverTemplate.getServerInstanceKeys() == null || serverTemplate.getServerInstanceKeys().isEmpty()) { return null; for (ServerInstanceKey serverInstanceKey : serverTemplate.getServerInstanceKeys()) { endpoints.append(serverInstanceKey.getUrl() + "|"); if (serverTemplate.getCapabilities().contains(Capability.PROCESS.name())) { mappedCapabilities.add(KieServerConstants.CAPABILITY_BPM); mappedCapabilities.add(KieServerConstants.CAPABILITY_BPM_UI); mappedCapabilities.add(KieServerConstants.CAPABILITY_CASE); if (serverTemplate.getCapabilities().contains(Capability.RULE.name())) { mappedCapabilities.add(KieServerConstants.CAPABILITY_BRM); if (serverTemplate.getCapabilities().contains(Capability.PLANNING.name())) { mappedCapabilities.add(KieServerConstants.CAPABILITY_BRP);
@Test public void testCreateServerTemplate() { ServerTemplate serverTemplate = new ServerTemplate(); serverTemplate.setName("test server"); serverTemplate.setId(UUID.randomUUID().toString()); specManagementService.saveServerTemplate(serverTemplate); ServerTemplateKeyList existing = specManagementService.listServerTemplateKeys(); assertNotNull(existing); assertEquals(1, existing.getServerTemplates().length); org.kie.server.controller.api.model.spec.ServerTemplateKey saved = existing.getServerTemplates()[0]; assertEquals(serverTemplate.getName(), saved.getName()); assertEquals(serverTemplate.getId(), saved.getId()); }
@Test public void testServerTemplateUpdatedWithServerInstance() { final String serverTemplateId = "id1"; final ServerTemplate st1 = new ServerTemplate(serverTemplateId, "kie-server-template1"); st1.addServerInstance(new ServerInstanceKey()); when(specManagementService.listServerTemplates()).thenReturn(new ServerTemplateList(singletonList(st1))); serverTemplateSelectorMenuBuilder.onServerTemplateUpdated(new ServerTemplateUpdated(st1)); verifyNoMoreInteractions(view); }
@Test public void testDeleteServerInstance() { final ServerTemplate serverTemplate = new ServerTemplate("serverTemplateId", "serverTemplateName"); final ServerInstanceKey serverInstanceKey = new ServerInstanceKey(serverTemplate.getId(), "serverName", "serverInstanceId", "url"); serverTemplate.addServerInstance(serverInstanceKey); specManagementService.saveServerTemplate(serverTemplate); when(kieServerInstanceManager.isAlive(serverInstanceKey)).thenReturn(false); specManagementService.deleteServerInstance(serverInstanceKey); final ServerTemplate updatedServerTemplate = specManagementService.getServerTemplate(serverTemplate.getId()); assertEquals(0, updatedServerTemplate.getServerInstanceKeys().size()); }
ServerTemplate fromStorage = templateStorage.load(serverTemplate.getId()); assertNotNull(fromStorage); assertEquals(serverTemplate.getId(), fromStorage.getId()); assertEquals(serverTemplate.getName(), fromStorage.getName()); newContainerSpec.setServerTemplateKey(new ServerTemplateKey(serverTemplate.getId(), serverTemplate.getName())); newContainerSpec.setReleasedId(new ReleaseId("org.kie", "kie-server-kjar", "3.0")); newContainerSpec.setStatus(KieContainerStatus.STARTED); fromStorage.addContainerSpec(newContainerSpec); fromStorage.addServerInstance(ModelFactory.newServerInstanceKey(serverTemplate.getId(), "http://localhost:8080/server")); ServerTemplate template = templateStorage.load(serverTemplate.getId()); assertNotNull(template); assertEquals(serverTemplate.getId(), template.getId()); assertEquals(serverTemplate.getName(), template.getName()); Collection<ServerInstanceKey> instances = template.getServerInstanceKeys(); assertNotNull(instances); assertEquals(1, instances.size()); assertEquals(serverTemplate.getId(), serverInstanceKey.getServerTemplateId()); assertEquals(serverTemplate.getId()+"@localhost:8080", serverInstanceKey.getServerName()); assertEquals(serverTemplate.getId() + "@localhost:8080", serverInstanceKey.getServerInstanceId()); assertEquals("http://localhost:8080/server", serverInstanceKey.getUrl());
final ServerTemplate serverTemplate1 = new ServerTemplate(serverTemplateId1, serverTemplateId1); serverTemplate1.addServerInstance(serverInstance1); serverTemplate1.addContainerSpec(containerSpec); final ServerTemplate serverTemplate2 = new ServerTemplate(serverTemplateId2, serverTemplateId2); serverTemplate2.addServerInstance(serverInstance2); serverTemplate2.addContainerSpec(containerSpec);
@Test public void testSetupCapabilities() { final ServerTemplate serverTemplate = new ServerTemplate( "ServerTemplateKeyId", "ServerTemplateKeyName" ); serverTemplate.getCapabilities().add( Capability.PROCESS.toString() ); serverTemplate.getCapabilities().add( Capability.PLANNING.toString() ); serverTemplate.getCapabilities().add( Capability.RULE.toString() ); presenter.setup( serverTemplate, null ); assertEquals( serverTemplate, presenter.getCurrentServerTemplate() ); verify( view ).clear(); verify( view ).setTemplate( serverTemplate.getId(), serverTemplate.getName() ); verify( view ).setProcessCapability( true ); verify( view ).setRulesCapability( true ); verify( view ).setPlanningCapability( true ); }
@Test public void testSetup() { final ServerTemplate serverTemplate = new ServerTemplate( "ServerTemplateKeyId", "ServerTemplateKeyName" ); final ServerInstanceKey serverInstanceKey = new ServerInstanceKey( "serverTemplateId", "serverName", "serverInstanceId", "url" ); serverTemplate.addServerInstance( serverInstanceKey ); 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 ); verify( view ).setTemplate( serverTemplate.getId(), serverTemplate.getName() ); verify( view ).setProcessCapability( false ); verify( view ).setRulesCapability( false );
@Override public synchronized void saveServerTemplate(ServerTemplate serverTemplate) { if (templateStorage.exists(serverTemplate.getId())) { templateStorage.update(serverTemplate); } else { templateStorage.store(serverTemplate); } notificationService.notify(new ServerTemplateUpdated(serverTemplate)); Collection<ContainerSpec> containerSpecs = serverTemplate.getContainersSpec(); if (containerSpecs != null && !containerSpecs.isEmpty()) { for (ContainerSpec containerSpec : containerSpecs) { if (containerSpec.getStatus().equals(KieContainerStatus.STARTED)) { List<Container> containers = kieServerInstanceManager.startContainer(serverTemplate, containerSpec); notificationService.notify(serverTemplate, containerSpec, containers); } } } }
@Override @SuppressWarnings("PMD.AvoidMultipleUnaryOperators") public int hashCode() { int result = serverTemplate == null ? 0 : serverTemplate.getId().hashCode(); result = ~~result; return result; }
CredentialsProvider credentialsProvider) { if (serverTemplate.getServerInstanceKeys() == null || serverTemplate.getServerInstanceKeys().isEmpty()) { return null; for (ServerInstanceKey serverInstanceKey : serverTemplate.getServerInstanceKeys()) { endpoints.append(serverInstanceKey.getUrl() + "|"); if (serverTemplate.getCapabilities().contains(Capability.PROCESS.name())) { mappedCapabilities.add(KieServerConstants.CAPABILITY_BPM); mappedCapabilities.add(KieServerConstants.CAPABILITY_BPM_UI); mappedCapabilities.add(KieServerConstants.CAPABILITY_CASE); if (serverTemplate.getCapabilities().contains(Capability.RULE.name())) { mappedCapabilities.add(KieServerConstants.CAPABILITY_BRM); if (serverTemplate.getCapabilities().contains(Capability.PLANNING.name())) { mappedCapabilities.add(KieServerConstants.CAPABILITY_BRP); serverTemplate.getId());
@Test public void testOnServerTemplateUpdated() { final ServerTemplate serverTemplate = new ServerTemplate( "ServerTemplateKeyId", "ServerTemplateKeyName" ); presenter.onServerTemplateUpdated( new ServerTemplateUpdated( serverTemplate ) ); verify( view ).addTemplate( serverTemplate.getId(), serverTemplate.getName() ); }
@Test public void testComplete() { 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 String successMessage = "SUCCESS"; verify( newContainerFormPresenter ).buildContainerSpec( eq( serverTemplate.getId() ), anyMap() );
@Before public void setup() { when(specManagementService.listServerTemplates()).thenReturn(new ServerTemplateList(Arrays.asList(new ServerTemplate("", "")))); specManagementServiceCaller = new CallerMock<>(specManagementService); presenter = new RemoteDataSetDefAttributesEditor(queryTarget, serverTemplates, dataSource, dbSQL, view, specManagementServiceCaller); when(serverTemplates.newEntry(anyString(), anyString())).thenReturn(Mockito.mock(Entry.class)); when(queryTarget.newEntry(anyString(), anyString())).thenReturn(Mockito.mock(Entry.class)); }
@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 testGetContainersByTemplate() { when(kieServerInstanceManager.getContainers(any(), any())).thenReturn(singletonList(container)); org.kie.server.controller.api.model.runtime.ServerInstanceKey instanceKey = new ServerInstanceKey("instanceId", "test server", serverTemplate.getId(), "http://fake.url.org"); serverTemplate.addServerInstance(instanceKey); specManagementService.saveServerTemplate(serverTemplate); ContainerList containers = runtimeManagementService.getContainers(serverTemplate, containerSpec); assertNotNull(containers); assertEquals(1, containers.getContainers().length); assertEquals(container, containers.getContainers()[0]); verify(kieServerInstanceManager).getContainers(any(), any()); }
public boolean hasServerInstanceId(String serverInstanceId) { for (ServerInstanceKey instance : getServerInstanceKeys()) { if (instance.getServerInstanceId().equals(serverInstanceId)) { return true; } } return false; }