public void onServerTemplateUpdated(@Observes final ServerTemplateUpdated serverTemplateUpdated) { if (serverTemplateUpdated != null && serverTemplateUpdated.getServerTemplate() != null) { final ServerTemplate serverTemplate = serverTemplateUpdated.getServerTemplate(); if (!serverTemplates.contains(serverTemplate.getId())) { addTemplate(serverTemplate); } } else { logger.warn("Illegal event argument."); } }
@Override public synchronized void updateServerTemplateConfig(String serverTemplateId, Capability capability, ServerConfig serverTemplateConfig) { ServerTemplate serverTemplate = templateStorage.load(serverTemplateId); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + serverTemplateId); } Map<Capability, ServerConfig> configs = serverTemplate.getConfigs(); configs.put(capability, serverTemplateConfig); serverTemplate.setConfigs(configs); templateStorage.update(serverTemplate); notificationService.notify(new ServerTemplateUpdated(serverTemplate)); }
@Test public void testOnServerTemplateUpdated() { final ServerTemplate serverTemplate = new ServerTemplate( "ServerTemplateId", "ServerTemplateName" ); presenter.onServerTemplateUpdated( new ServerTemplateUpdated( serverTemplate ) ); final ArgumentCaptor<Collection> serverTemplateKeysCaptor = ArgumentCaptor.forClass( Collection.class ); verify( navigationPresenter ).setup( eq( serverTemplate ), serverTemplateKeysCaptor.capture() ); final Collection<ServerTemplateKey> serverTemplateKeys = serverTemplateKeysCaptor.getValue(); assertEquals( 1, serverTemplateKeys.size() ); assertTrue( serverTemplateKeys.contains( serverTemplate ) ); final ArgumentCaptor<ServerTemplateSelected> templateSelectedCaptor = ArgumentCaptor.forClass( ServerTemplateSelected.class ); verify( serverTemplateSelectedEvent ).fire( templateSelectedCaptor.capture() ); assertEquals( serverTemplate, templateSelectedCaptor.getValue().getServerTemplateKey() ); }
@Test public void testServerTemplateUpdated() { handler.accept(new ServerTemplateUpdated(new ServerTemplate())); verify(eventHandler).onServerTemplateUpdated(any()); verifyNoMoreInteractions(eventHandler); }
public void onServerTemplateDeleted(@Observes ServerTemplateUpdated serverTemplateUpdated) { buildClientsForServer(serverTemplateUpdated.getServerTemplate()); }
protected void notifyOnDisconnect(ServerInstanceKey serverInstanceKey, ServerTemplate serverTemplate) { notificationService.notify(new ServerInstanceDeleted(serverInstanceKey.getServerInstanceId())); notificationService.notify(new ServerTemplateUpdated(serverTemplate)); notificationService.notify(new ServerInstanceDisconnected(serverInstanceKey.getServerInstanceId())); }
public void onServerTemplateUpdated(@Observes ServerTemplateUpdated serverTemplateUpdated) { buildClientsForServer(serverTemplateUpdated.getServerTemplate()); }
@Test public void testServerTemplateUpdatedWithoutServerInstance() { final String serverTemplateId = "id1"; final ServerTemplate st1 = new ServerTemplate(serverTemplateId, "kie-server-template1"); when(specManagementService.listServerTemplates()).thenReturn(new ServerTemplateList(singletonList(st1))); serverTemplateSelectorMenuBuilder.onServerTemplateUpdated(new ServerTemplateUpdated(st1)); verify(specManagementService).listServerTemplates(); verify(view).removeAllServerTemplates(); verify(view, never()).addServerTemplate(serverTemplateId); verify(view).setVisible(false); verify(view).getSelectedServerTemplate(); verify(view).clearSelectedServerTemplate(); verifyNoMoreInteractions(view); }
public void onServerTemplateUpdated( @Observes final ServerTemplateUpdated serverTemplateUpdated ) { if ( serverTemplateUpdated != null && serverTemplateUpdated.getServerTemplate() != null ) { final ServerTemplate serverTemplate = serverTemplateUpdated.getServerTemplate(); if ( isEmpty ) { setup( new ArrayList<ServerTemplateKey>() {{ add( serverTemplate ); }}, serverTemplate.getId() ); } } else { logger.warn( "Illegal event argument." ); } }
@Test public void testServerTemplateUpdatedWithoutServerInstance() { final String serverTemplateId = "id1"; final ServerTemplate st1 = new ServerTemplate(serverTemplateId, "kie-server-template1"); when(specManagementService.listServerTemplates()).thenReturn(new ServerTemplateList(singletonList(st1))); serverTemplateSelectorMenuBuilder.onServerTemplateUpdated(new ServerTemplateUpdated(st1)); verify(specManagementService).listServerTemplates(); verify(view).removeAllServerTemplates(); verify(view, never()).addServerTemplate(serverTemplateId); verify(view).setVisible(false); verify(view).getSelectedServerTemplate(); verify(view).clearSelectedServerTemplate(); verifyNoMoreInteractions(view); }
public void onServerTemplateUpdated(@Observes final ServerTemplateUpdated serverTemplateUpdated) { if (serverTemplateUpdated.getServerTemplate().getServerInstanceKeys().isEmpty()) { loadServerTemplates(); } }
@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); }
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 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); }
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); } } }
@Override public synchronized void updateContainerConfig(final String serverTemplateId, final String containerSpecId, final Capability capability, final ContainerConfig containerConfig) { final ServerTemplate serverTemplate = templateStorage.load(serverTemplateId); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + serverTemplateId); } final ContainerSpec containerSpec = serverTemplate.getContainerSpec(containerSpecId); if (containerSpec == null) { throw new KieServerControllerIllegalArgumentException("No container spec found for id " + containerSpecId + " within server template with id " + serverTemplateId); } final List<Container> affectedContainers = updateContainerConfig(capability, containerConfig, serverTemplate, containerSpec); if (affectedContainers.isEmpty()) { logInfo("Update of container configuration resulted in no changes to containers running on kie-servers"); } affectedContainers.forEach(ac -> { logDebug("Container {} on server {} was affected by a change in the scanner", ac.getContainerSpecId(), ac.getServerInstanceKey()); }); containerSpec.getConfigs().put(capability, containerConfig); templateStorage.update(serverTemplate); notificationService.notify(new ServerTemplateUpdated(serverTemplate)); }
@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); } } } }
@Test public void testOnServerTemplateUpdated() { final ServerTemplate serverTemplate = new ServerTemplate( "ServerTemplateKeyId", "ServerTemplateKeyName" ); presenter.onServerTemplateUpdated( new ServerTemplateUpdated( serverTemplate ) ); verify( view ).addTemplate( serverTemplate.getId(), serverTemplate.getName() ); }
@Override public synchronized void deleteContainerSpec(String serverTemplateId, String containerSpecId) { ServerTemplate serverTemplate = templateStorage.load(serverTemplateId); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + serverTemplateId); } if (serverTemplate.hasContainerSpec(containerSpecId)) { ContainerSpec containerSpec = serverTemplate.getContainerSpec(containerSpecId); kieServerInstanceManager.stopContainer(serverTemplate, containerSpec); serverTemplate.deleteContainerSpec(containerSpecId); templateStorage.update(serverTemplate); notificationService.notify(new ServerTemplateUpdated(serverTemplate)); } else { throw new KieServerControllerIllegalArgumentException("Container " + containerSpecId + " not found"); } }
@Test public void testServerTemplateUpdated() throws Exception { final ServerTemplateUpdated event = new ServerTemplateUpdated(new ServerTemplate()); notificationService.notify(event); verify(endpoint, timeout(TIMEOUT)).sendObject(new KieServerControllerNotification(event)); }