Search in sources :

Example 1 with KieServerInstanceManager

use of org.kie.server.controller.impl.KieServerInstanceManager in project kie-wb-common by kiegroup.

the class RuntimeManagementServiceCDITest method getContainersByContainerSpec_returnsContainerSpecData.

@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);
    // Setup mocks
    KieServerTemplateStorage templateStorageMock = createMockStorageWithOneTemplate(serverTemplate);
    KieServerInstanceManager instanceMangerMock = mock(KieServerInstanceManager.class);
    when(instanceMangerMock.getContainers(serverInstanceKey)).thenReturn(containersInServerInstance);
    // Setup tested object
    runtimeManagementService.setTemplateStorage(templateStorageMock);
    runtimeManagementService.setKieServerInstanceManager(instanceMangerMock);
    specManagementService.setTemplateStorage(templateStorageMock);
    specManagementService.setKieServerInstanceManager(instanceMangerMock);
    // Tested method
    ContainerSpecData containerSpecData = runtimeManagementServiceCDI.getContainersByContainerSpec(templateId, containerSpecId);
    assertThat(containerSpecData.getContainers()).contains(container);
    assertThat(containerSpecData.getContainerSpec()).isEqualTo(containerSpec);
}
Also used : Container(org.kie.server.controller.api.model.runtime.Container) ServerTemplateKey(org.kie.server.controller.api.model.spec.ServerTemplateKey) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) ContainerSpec(org.kie.server.controller.api.model.spec.ContainerSpec) KieServerInstanceManager(org.kie.server.controller.impl.KieServerInstanceManager) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ReleaseId(org.kie.server.api.model.ReleaseId) ServerInstanceKey(org.kie.server.controller.api.model.runtime.ServerInstanceKey) ContainerSpecData(org.kie.workbench.common.screens.server.management.model.ContainerSpecData) KieServerTemplateStorage(org.kie.server.controller.api.storage.KieServerTemplateStorage) Test(org.junit.Test)

Example 2 with KieServerInstanceManager

use of org.kie.server.controller.impl.KieServerInstanceManager in project kie-wb-common by kiegroup.

the class RuntimeManagementServiceCDITest method getContainersByServerInstance_returnsListOfContainers_whenInstanceWithIdExists.

@Test
public void getContainersByServerInstance_returnsListOfContainers_whenInstanceWithIdExists() {
    final String templateId = "templateId";
    final String templateName = "templateName";
    final String serverInstanceId = "serverInstanceId";
    ServerInstanceKey serverInstanceKey = new ServerInstanceKey(templateId, templateName, serverInstanceId, "dummyUrl");
    ServerTemplate serverTemplate = new ServerTemplate(templateId, templateName, Collections.emptyList(), Collections.emptyMap(), Collections.emptyList(), Collections.singletonList(serverInstanceKey));
    final List<Container> containersInServerInstance = Arrays.asList(new Container(), new Container());
    KieServerTemplateStorage templateStorageMock = createMockStorageWithOneTemplate(serverTemplate);
    // Instance with 2 dummy containers
    KieServerInstanceManager instanceMangerMock = mock(KieServerInstanceManager.class);
    when(instanceMangerMock.getContainers(eq(serverInstanceKey))).thenReturn(containersInServerInstance);
    runtimeManagementService.setTemplateStorage(templateStorageMock);
    runtimeManagementService.setKieServerInstanceManager(instanceMangerMock);
    specManagementService.setTemplateStorage(templateStorageMock);
    specManagementService.setKieServerInstanceManager(instanceMangerMock);
    Collection<Container> containers = runtimeManagementServiceCDI.getContainersByServerInstance(templateId, serverInstanceId);
    assertThat(containers).as("Should return list of containers from server instance id").hasSameSizeAs(containersInServerInstance);
}
Also used : Container(org.kie.server.controller.api.model.runtime.Container) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) KieServerInstanceManager(org.kie.server.controller.impl.KieServerInstanceManager) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ServerInstanceKey(org.kie.server.controller.api.model.runtime.ServerInstanceKey) KieServerTemplateStorage(org.kie.server.controller.api.storage.KieServerTemplateStorage) Test(org.junit.Test)

Aggregations

CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Test (org.junit.Test)2 Container (org.kie.server.controller.api.model.runtime.Container)2 ServerInstanceKey (org.kie.server.controller.api.model.runtime.ServerInstanceKey)2 ServerTemplate (org.kie.server.controller.api.model.spec.ServerTemplate)2 KieServerTemplateStorage (org.kie.server.controller.api.storage.KieServerTemplateStorage)2 KieServerInstanceManager (org.kie.server.controller.impl.KieServerInstanceManager)2 ReleaseId (org.kie.server.api.model.ReleaseId)1 ContainerSpec (org.kie.server.controller.api.model.spec.ContainerSpec)1 ServerTemplateKey (org.kie.server.controller.api.model.spec.ServerTemplateKey)1 ContainerSpecData (org.kie.workbench.common.screens.server.management.model.ContainerSpecData)1