@Test public void getContainersByContainerSpec_returnsContainerSpecData() { final String templateId = "templateId", templateName = "templateName", serverInstanceId = "serverInstanceId", containerName = "containerName1", group = "g1", artifact = "a1", version = "1", containerSpecId = String.join(":", group, artifact, version); final ReleaseId releaseId = new ReleaseId(group, artifact, version); ServerInstanceKey serverInstanceKey = new ServerInstanceKey(templateId, null, serverInstanceId, null); Container container = new Container(containerSpecId, containerName, serverInstanceKey, Collections.emptyList(), releaseId, null); ContainerSpec containerSpec = new ContainerSpec( containerSpecId, containerName, new ServerTemplateKey(templateId, templateName), releaseId, KieContainerStatus.STARTED, Collections.emptyMap() ); ServerTemplate serverTemplate = new ServerTemplate( templateId, templateName, Collections.emptyList(), Collections.emptyMap(), Collections.singletonList(containerSpec), Collections.singletonList(serverInstanceKey) ); final List<Container> containersInServerInstance = Collections.singletonList(container); KieServerTemplateStorage templateStorageMock = createMockStorageWithOneTemplate(serverTemplate); KieServerInstanceManager instanceMangerMock = mock(KieServerInstanceManager.class); when(instanceMangerMock.getContainers(serverTemplate, containerSpec)) .thenReturn(containersInServerInstance); runtimeManagementService.setTemplateStorage(templateStorageMock); runtimeManagementService.setKieServerInstanceManager(instanceMangerMock); specManagementService.setTemplateStorage(templateStorageMock); specManagementService.setKieServerInstanceManager(instanceMangerMock); ContainerSpecData containerSpecData = runtimeManagementServiceCDI.getContainersByContainerSpec(templateId, containerSpecId); assertThat(containerSpecData.getContainers()).contains(container); assertThat(containerSpecData.getContainerSpec()).isEqualTo(containerSpec); }
@Override public ContainerSpecData getContainersByContainerSpec(final String serverTemplateId, final String containerSpecId) { final ServerTemplate serverTemplate = specManagementService.getServerTemplate(serverTemplateId); if (serverTemplate == null) { throw new RuntimeException("Server template with id " + serverTemplateId + " not found"); } final ContainerSpec containerSpec = serverTemplate.getContainerSpec(containerSpecId); if (containerSpec == null) { throw new RuntimeException("Container with id " + containerSpecId + " not found"); } final ContainerList containerList = service.getContainers(serverTemplate, containerSpec); final List<Container> containers = Arrays.asList(containerList.getContainers()); return new ContainerSpecData(containerSpec, containers); }
RuntimeManagementServiceCDI implements RuntimeManagementService { @Override public ContainerSpecData getContainersByContainerSpec(final String serverTemplateId, final String containerSpecId) { final ServerTemplate serverTemplate = specManagementService.getServerTemplate(serverTemplateId); if (serverTemplate == null) { throw new RuntimeException("Server template with id " + serverTemplateId + " not found"); } final ContainerSpec containerSpec = serverTemplate.getContainerSpec(containerSpecId); if (containerSpec == null) { throw new RuntimeException("Container with id " + containerSpecId + " not found"); } final ContainerList containerList = service.getContainers(serverTemplate, containerSpec); final List<Container> containers = Arrays.asList(containerList.getContainers()); return new ContainerSpecData(containerSpec, containers); } }
RuntimeManagementServiceCDI implements RuntimeManagementService { @Override public ContainerSpecData getContainersByContainerSpec(final String serverTemplateId, final String containerSpecId) { final ServerTemplate serverTemplate = specManagementService.getServerTemplate(serverTemplateId); if (serverTemplate == null) { throw new RuntimeException("Server template with id " + serverTemplateId + " not found"); } final ContainerSpec containerSpec = serverTemplate.getContainerSpec(containerSpecId); if (containerSpec == null) { throw new RuntimeException("Container with id " + containerSpecId + " not found"); } final ContainerList containerList = service.getContainers(serverTemplate, containerSpec); final List<Container> containers = Arrays.asList(containerList.getContainers()); return new ContainerSpecData(containerSpec, containers); }  }
RuntimeManagementServiceCDI implements RuntimeManagementService { @Override public ContainerSpecData getContainersByContainerSpec(final String serverTemplateId, final String containerSpecId) { final ServerTemplate serverTemplate = specManagementService.getServerTemplate(serverTemplateId); if (serverTemplate == null) { throw new RuntimeException("Server template with id " + serverTemplateId + " not found"); } final ContainerSpec containerSpec = serverTemplate.getContainerSpec(containerSpecId); if (containerSpec == null) { throw new RuntimeException("Container with id " + containerSpecId + " not found"); } final ContainerList containerList = service.getContainers(serverTemplate, containerSpec); final List<Container> containers = Arrays.asList(containerList.getContainers()); return new ContainerSpecData(containerSpec, containers); }  @Override Collection<Container> getContainersByServerInstance(final String serverTemplateId,
                                                               final String serverInstanceId); @Override ContainerSpecData getContainersByContainerSpec(final String serverTemplateId,
                                                          final String containerSpecId); }
RuntimeManagementServiceCDI implements RuntimeManagementService { @Override public ContainerSpecData getContainersByContainerSpec(final String serverTemplateId, final String containerSpecId) { final ServerTemplate serverTemplate = specManagementService.getServerTemplate(serverTemplateId); if (serverTemplate == null) { throw new RuntimeException("Server template with id " + serverTemplateId + " not found"); } final ContainerSpec containerSpec = serverTemplate.getContainerSpec(containerSpecId); if (containerSpec == null) { throw new RuntimeException("Container with id " + containerSpecId + " not found"); } final ContainerList containerList = service.getContainers(serverTemplate, containerSpec); final List<Container> containers = Arrays.asList(containerList.getContainers()); return new ContainerSpecData(containerSpec, containers); }  @Override Collection<Container> getContainersByServerInstance(final String serverTemplateId,
                                                               final String serverInstanceId); @Override ContainerSpecData getContainersByContainerSpec(final String serverTemplateId,
                                                          final String containerSpecId);  }