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); }
@Test public void testContainerSpecUpdated() { handler.accept(new ContainerSpecUpdated(new ServerTemplate(), new ContainerSpec(), new ArrayList<>())); verify(eventHandler).onContainerSpecUpdated(any()); verifyNoMoreInteractions(eventHandler); } }
private ContainerSpec makeContainerSpec(final String containerId, final String containerAlias, final ServerTemplate serverTemplate, final Map<String, String> parameters) { final ReleaseId releaseId = makeReleaseId(); final KieContainerStatus status = KieContainerStatus.STOPPED; final ServerTemplateKey serverTemplateKey = new ServerTemplateKey(serverTemplate.getId(), serverTemplate.getId()); return new ContainerSpec(containerId, containerAlias, serverTemplateKey, releaseId, status, makeConfigs(serverTemplate, parameters)); }
public void onServerTemplateUpdated(@Observes ServerTemplateUpdated serverTemplateUpdated) { if (deployToServerTemplate.compareAndSet(true, false)) { final GAV gav = newProject.getMainModule().getPom().getGav(); final String containerId = gav.getArtifactId() + "_" + gav.getVersion(); final ReleaseId releaseId = new ReleaseId(gav.getGroupId(), gav.getArtifactId(), gav.getVersion()); final ContainerSpec containerSpec = new ContainerSpec(containerId, gav.getArtifactId(), serverTemplateUpdated.getServerTemplate(), releaseId, KieContainerStatus.STARTED, new HashMap<>()); LOGGER.info("Creating Kie Server container with id: {} for Server Template: {}", containerId, serverTemplateUpdated.getServerTemplate().getId()); specManagementService.saveContainerSpec(serverTemplateUpdated.getServerTemplate().getId(), containerSpec); } } }
public void onServerTemplateUpdated(@Observes ServerTemplateUpdated serverTemplateUpdated) { if (deployToServerTemplate.compareAndSet(true, false)) { final GAV gav = newProject.getMainModule().getPom().getGav(); final String containerId = gav.getArtifactId() + "_" + gav.getVersion(); final ReleaseId releaseId = new ReleaseId(gav.getGroupId(), gav.getArtifactId(), gav.getVersion()); final ContainerSpec containerSpec = new ContainerSpec(containerId, gav.getArtifactId(), serverTemplateUpdated.getServerTemplate(), releaseId, KieContainerStatus.STARTED, new HashMap<>()); LOGGER.info("Creating Kie Server container with id: {} for Server Template: {}", containerId, serverTemplateUpdated.getServerTemplate().getId()); specManagementService.saveContainerSpec(serverTemplateUpdated.getServerTemplate().getId(), containerSpec); } } }
@Test public void testOnServerInstanceUpdated() { final ContainerCardPresenter cardPresenter = mock( ContainerCardPresenter.class ); when( cardPresenter.getView() ).thenReturn( mock( ContainerCardPresenter.View.class ) ); when( presenterProvider.get() ).thenReturn( cardPresenter ); final ServerInstance serverInstance = new ServerInstance( "templateId", "serverName", "serverInstanceId", "url", "1.0", Collections.<Message>emptyList(), Collections.<Container>emptyList() ); final Container container = new Container( "containerSpecId", "containerName", serverInstance, Collections.<Message>emptyList(), null, null ); container.setStatus( KieContainerStatus.STARTED ); final Container containerToBeRemoved = new Container( "containerToBeRemovedSpecId", "containerToBeRemovedName", serverInstance, Collections.<Message>emptyList(), null, null ); containerToBeRemoved.setStatus( KieContainerStatus.STARTED ); serverInstance.addContainer( container ); presenter.setup( new ContainerSpec(), Arrays.asList( container, containerToBeRemoved ) ); presenter.onServerInstanceUpdated( new ServerInstanceUpdated( serverInstance ) ); //One container updated, one removed verify( cardPresenter ).updateContent( serverInstance, container ); verify( cardPresenter ).delete(); final ArgumentCaptor<Container> containerCaptor = ArgumentCaptor.forClass( Container.class ); verify( cardPresenter, times( 2 ) ).setup( eq( container.getServerInstanceKey() ), containerCaptor.capture() ); final List<Container> containers = containerCaptor.getAllValues(); assertEquals( 2, containers.size() ); assertEquals( container, containers.get( 0 ) ); assertEquals( containerToBeRemoved, containers.get( 1 ) ); }
@Test public void testOnDelete() { final ContainerCardPresenter cardPresenter = mock( ContainerCardPresenter.class ); when( cardPresenter.getView() ).thenReturn( mock( ContainerCardPresenter.View.class ) ); when( presenterProvider.get() ).thenReturn( cardPresenter ); final ServerInstanceKey serverInstanceKey = new ServerInstanceKey( "templateId", "serverName", "serverInstanceId", "url" ); final Container container = new Container( "containerSpecId", "containerName", serverInstanceKey, Collections.<Message>emptyList(), null, null ); container.setStatus( KieContainerStatus.STARTED ); presenter.setup( new ContainerSpec(), Collections.singletonList( container ) ); verify( view ).clear(); verify( cardPresenter ).setup( container.getServerInstanceKey(), container ); verify( view ).addCard( any( IsWidget.class ) ); presenter.onDelete( new ServerInstanceDeleted( serverInstanceKey.getServerInstanceId() ) ); verify( cardPresenter ).delete(); presenter.onDelete( new ServerInstanceDeleted( "randomKey" ) ); verify( cardPresenter ).delete(); }
@Test public void testRefreshOnContainerUpdateEventWithDifferentContainerSpec() { final ContainerSpec containerSpecEvent = new ContainerSpec(); containerSpecEvent.setReleasedId(new ReleaseId("org", "kie", "1.0")); final ContainerUpdateEvent updateEvent = new ContainerUpdateEvent(null, containerSpecEvent, null, null, ContainerRuntimeOperation.START_CONTAINER); presenter.refreshOnContainerUpdateEvent(updateEvent); verify(presenter, never()).refresh(); }
@Test public void testOnServerInstanceUpdatedDuplicatedContainerName() { final ContainerCardPresenter cardPresenter = mock( ContainerCardPresenter.class ); when( cardPresenter.getView() ).thenReturn( mock( ContainerCardPresenter.View.class ) ); when( presenterProvider.get() ).thenReturn( cardPresenter ); final ServerInstance serverInstance = new ServerInstance( "templateId", "serverName", "serverInstanceId", "url", "1.0", Collections.<Message>emptyList(), Collections.<Container>emptyList() ); final Container container = new Container( "containerSpecId", "containerName", serverInstance, Collections.<Message>emptyList(), null, null ); container.setStatus( KieContainerStatus.STARTED ); final Container container2 = new Container( "containerSpecId2", "containerName", serverInstance, Collections.<Message>emptyList(), null, null ); container2.setStatus( KieContainerStatus.STARTED ); final Container containerToBeRemoved = new Container( "containerToBeRemovedSpecId", "containerToBeRemovedName", serverInstance, Collections.<Message>emptyList(), null, null ); containerToBeRemoved.setStatus( KieContainerStatus.STARTED ); serverInstance.addContainer( container ); serverInstance.addContainer( container2 ); presenter.setup( new ContainerSpec(), Arrays.asList( container, container2, containerToBeRemoved ) ); presenter.onServerInstanceUpdated( new ServerInstanceUpdated( serverInstance ) ); //One container updated, one removed verify( cardPresenter ).updateContent( serverInstance, container ); verify( cardPresenter ).updateContent( serverInstance, container2 ); verify( cardPresenter ).delete(); final ArgumentCaptor<Container> containerCaptor = ArgumentCaptor.forClass( Container.class ); verify( cardPresenter, times( 3 ) ).setup( eq( container.getServerInstanceKey() ), containerCaptor.capture() ); final List<Container> containers = containerCaptor.getAllValues(); assertEquals( 3, containers.size() ); assertEquals( container, containers.get( 0 ) ); assertEquals( container2, containers.get( 1 ) ); assertEquals( containerToBeRemoved, containers.get( 2 ) ); }
public ContainerSpec buildContainerSpec(final String serverTemplateId, final Map<Capability, ContainerConfig> configs) { return new ContainerSpec(view.getContainerName(), view.getContainerAlias(), new ServerTemplateKey(serverTemplateId, null), new ReleaseId(view.getGroupId(), view.getArtifactId(), view.getVersion()), view.isStartContainer() ? KieContainerStatus.STARTED : KieContainerStatus.STOPPED, configs); }
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 );
@Test public void testContainerSpecUpdated() throws Exception { final ServerTemplate serverTemplate = new ServerTemplate(); final ContainerSpec containerSpec = new ContainerSpec(); final ArrayList<Container> containers = new ArrayList<>(); final ContainerSpecUpdated event = new ContainerSpecUpdated(serverTemplate, containerSpec, containers); notificationService.notify(serverTemplate, containerSpec, containers); verify(endpoint, timeout(TIMEOUT)).sendObject(new KieServerControllerNotification(event)); } }
@Test public void testLoadContainersOnlyOnSelectedContainerEvent() { ContainerSpec containerSpec1 = new ContainerSpec("containerId1", "containerName", serverTemplateKey, releaseId, KieContainerStatus.STOPPED, new HashMap<Capability, ContainerConfig>()); presenter.setContainerSpec(containerSpec1); presenter.loadContainers(containerSpecData); verifyLoad(true, 0); presenter.setContainerSpec(containerSpec); presenter.loadContainers(containerSpecData); verifyLoad(true, 1); }
newServerInstance.addContainer( newContainer ); presenter.setup( new ContainerSpec( "containerSpecId", "containerName", new ServerTemplateKey( "templateId", "templateId" ), new ReleaseId(), KieContainerStatus.STARTED, Collections.<Capability, ContainerConfig>emptyMap() ), Arrays.asList( existingContainer ) );
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; }
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; }
@Parameterized.Parameters(name = "{index}: {0}") public static Collection<Object[]> data() { Collection<Object[]> parameterData = new ArrayList<Object[]>(Arrays.asList(new Object[][]{ {new ServerInstanceConnected(new ServerInstance())}, {new ServerInstanceDisconnected("serverId")}, {new ServerInstanceDeleted("serverId")}, {new ServerInstanceUpdated(new ServerInstance())}, {new ServerTemplateUpdated(new ServerTemplate())}, {new ServerTemplateDeleted("serverTemplateId")}, {new ContainerSpecUpdated(new ServerTemplate(), new ContainerSpec(), new ArrayList<>())} } )); return parameterData; }
@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); }
@Test public void testCommandWithDomainArguments() { final ContainerSpec containerSpec = new ContainerSpec(); containerSpec.setId(CONTAINER_SPEC_ID); containerSpec.setContainerName(CONTAINER_SPEC_NAME); KieServerControllerDescriptorCommand command = new KieServerControllerDescriptorCommand(SpecManagementService.class.getName(), "saveContainerSpec", null, null, "templateId", containerSpec); final String content = WebSocketUtils.marshal(command); LOGGER.debug("JSON content\n{}", content); KieServerControllerServiceResponse response = service.executeCommand(WebSocketUtils.unmarshal(content, KieServerControllerDescriptorCommand.class)); assertNotNull(response); assertEquals(response.getMsg(), SUCCESS, response.getType()); assertNull(response.getResult()); }
containerSpec = new ContainerSpec(); containerSpec.setId("test container"); containerSpec.setServerTemplateKey(new ServerTemplateKey(serverTemplate.getId(), serverTemplate.getName()));