Search in sources :

Example 6 with ServerInstanceKey

use of org.kie.server.controller.api.model.runtime.ServerInstanceKey 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 7 with ServerInstanceKey

use of org.kie.server.controller.api.model.runtime.ServerInstanceKey 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)

Example 8 with ServerInstanceKey

use of org.kie.server.controller.api.model.runtime.ServerInstanceKey in project kie-wb-common by kiegroup.

the class ServerTemplateMigrationTest method testMigrationOfOldServerTemplate.

@Test
public void testMigrationOfOldServerTemplate() throws Exception {
    String serverTemplateId = "kie_server";
    String oldServerTemplateContent = IOUtils.toString(this.getClass().getResourceAsStream("/kie-server-6.3-info.xml"));
    assertNotNull(oldServerTemplateContent);
    Path path = buildPath(serverTemplateId);
    assertNotNull(path);
    // let's store it in the old way -info.xml file
    ioService.write(path, oldServerTemplateContent);
    ServerTemplateMigration templateMigration = new ServerTemplateMigration();
    templateMigration.migrate(path.getParent(), ioService, xstream, templateStorage);
    boolean exists = templateStorage.exists(serverTemplateId);
    assertTrue(exists);
    ServerTemplate fromStorage = templateStorage.load(serverTemplateId);
    assertNotNull(fromStorage);
    // verify server template
    assertEquals(serverTemplateId, fromStorage.getId());
    assertEquals("kie server name", fromStorage.getName());
    Collection<String> capabilities = fromStorage.getCapabilities();
    assertNotNull(capabilities);
    assertTrue(capabilities.contains("KieServer"));
    assertTrue(capabilities.contains("BRM"));
    assertTrue(capabilities.contains("BPM"));
    // verify server instances (previously known as managedInstances)
    Collection<ServerInstanceKey> instances = fromStorage.getServerInstanceKeys();
    assertNotNull(instances);
    assertEquals(1, instances.size());
    ServerInstanceKey serverInstanceKey = instances.iterator().next();
    assertNotNull(serverInstanceKey);
    assertEquals(serverTemplateId, serverInstanceKey.getServerTemplateId());
    assertEquals("kie_server@localhost:8180", serverInstanceKey.getServerName());
    assertEquals("kie_server@localhost:8180", serverInstanceKey.getServerInstanceId());
    assertEquals("http://localhost:8180/kie-server/services/rest/server", serverInstanceKey.getUrl());
    // verify containers
    Collection<ContainerSpec> containerSpecs = fromStorage.getContainersSpec();
    assertNotNull(containerSpecs);
    assertEquals(3, containerSpecs.size());
    Map<String, ContainerSpec> containersById = mapContainers(containerSpecs);
    assertTrue(containersById.containsKey("project-1"));
    assertTrue(containersById.containsKey("project-2"));
    assertTrue(containersById.containsKey("project-3"));
    // first container spec...
    ContainerSpec spec = containersById.get("project-2");
    assertNotNull(spec);
    assertEquals("project-2", spec.getId());
    assertEquals(new ReleaseId("org.kie.server", "project-2", "1.0.0"), spec.getReleasedId());
    assertEquals(serverTemplateId, spec.getServerTemplateKey().getId());
    assertEquals("kie server name", spec.getServerTemplateKey().getName());
    assertEquals(KieContainerStatus.STARTED, spec.getStatus());
    assertEquals(0, spec.getConfigs().size());
    // second container spec
    spec = containersById.get("project-3");
    assertNotNull(spec);
    assertEquals("project-3", spec.getId());
    assertEquals(new ReleaseId("org.kie.server", "project-3", "1.0.0"), spec.getReleasedId());
    assertEquals(serverTemplateId, spec.getServerTemplateKey().getId());
    assertEquals("kie server name", spec.getServerTemplateKey().getName());
    assertEquals(KieContainerStatus.STOPPED, spec.getStatus());
    assertEquals(0, spec.getConfigs().size());
    // third container spec
    spec = containersById.get("project-1");
    assertNotNull(spec);
    assertEquals("project-1", spec.getId());
    assertEquals(new ReleaseId("org.kie.server", "project-1", "1.0.0"), spec.getReleasedId());
    assertEquals(serverTemplateId, spec.getServerTemplateKey().getId());
    assertEquals("kie server name", spec.getServerTemplateKey().getName());
    assertEquals(KieContainerStatus.STARTED, spec.getStatus());
    assertEquals(0, spec.getConfigs().size());
}
Also used : Path(org.uberfire.java.nio.file.Path) ServerTemplateMigration(org.kie.workbench.common.screens.server.management.backend.storage.migration.ServerTemplateMigration) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) ContainerSpec(org.kie.server.controller.api.model.spec.ContainerSpec) ServerInstanceKey(org.kie.server.controller.api.model.runtime.ServerInstanceKey) ReleaseId(org.kie.server.api.model.ReleaseId) Test(org.junit.Test)

Example 9 with ServerInstanceKey

use of org.kie.server.controller.api.model.runtime.ServerInstanceKey in project kie-wb-common by kiegroup.

the class ServerTemplateVFSStorageTest method testStoreAndLoadServerTemplates.

@Test
public void testStoreAndLoadServerTemplates() {
    templateStorage.store(serverTemplate);
    Collection<ServerTemplateKey> templateKeys = templateStorage.loadKeys();
    assertNotNull(templateKeys);
    assertEquals(1, templateKeys.size());
    ServerTemplateKey templateKey = templateKeys.iterator().next();
    assertNotNull(templateKey);
    assertEquals(serverTemplate.getId(), templateKey.getId());
    assertEquals(serverTemplate.getName(), templateKey.getName());
    Collection<ServerTemplate> templates = templateStorage.load();
    assertNotNull(templates);
    assertEquals(1, templates.size());
    ServerTemplate template = templates.iterator().next();
    assertNotNull(template);
    assertEquals(serverTemplate.getId(), template.getId());
    assertEquals(serverTemplate.getName(), template.getName());
    Collection<ServerInstanceKey> instances = template.getServerInstanceKeys();
    assertNotNull(instances);
    assertEquals(0, instances.size());
    Collection<ContainerSpec> containerSpecs = template.getContainersSpec();
    assertNotNull(containerSpecs);
    assertEquals(1, containerSpecs.size());
    ContainerSpec spec = containerSpecs.iterator().next();
    assertNotNull(spec);
    assertEquals(containerSpec.getId(), spec.getId());
    assertEquals(containerSpec.getReleasedId(), spec.getReleasedId());
    assertEquals(containerSpec.getServerTemplateKey().getId(), spec.getServerTemplateKey().getId());
    assertEquals(containerSpec.getServerTemplateKey().getName(), spec.getServerTemplateKey().getName());
    assertEquals(containerSpec.getConfigs().size(), spec.getConfigs().size());
    assertTrue(spec.getConfigs().containsKey(Capability.RULE));
    assertTrue(spec.getConfigs().containsKey(Capability.PROCESS));
    RuleConfig ruleConfig = (RuleConfig) spec.getConfigs().get(Capability.RULE);
    assertNotNull(ruleConfig);
    assertEquals(this.ruleConfig.getPollInterval(), ruleConfig.getPollInterval());
    assertEquals(this.ruleConfig.getScannerStatus(), ruleConfig.getScannerStatus());
    ProcessConfig processConfig = (ProcessConfig) spec.getConfigs().get(Capability.PROCESS);
    assertNotNull(processConfig);
    assertEquals(this.processConfig.getKBase(), processConfig.getKBase());
    assertEquals(this.processConfig.getKSession(), processConfig.getKSession());
    assertEquals(this.processConfig.getMergeMode(), processConfig.getMergeMode());
    assertEquals(this.processConfig.getRuntimeStrategy(), processConfig.getRuntimeStrategy());
}
Also used : ServerTemplateKey(org.kie.server.controller.api.model.spec.ServerTemplateKey) ProcessConfig(org.kie.server.controller.api.model.spec.ProcessConfig) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) ContainerSpec(org.kie.server.controller.api.model.spec.ContainerSpec) ServerInstanceKey(org.kie.server.controller.api.model.runtime.ServerInstanceKey) RuleConfig(org.kie.server.controller.api.model.spec.RuleConfig) Test(org.junit.Test)

Example 10 with ServerInstanceKey

use of org.kie.server.controller.api.model.runtime.ServerInstanceKey in project kie-wb-common by kiegroup.

the class ServerTemplateVFSStorageTest method testStoreServerTemplate.

@Test
public void testStoreServerTemplate() {
    templateStorage.store(serverTemplate);
    boolean exists = templateStorage.exists(serverTemplate.getId());
    assertTrue(exists);
    ServerTemplate fromStorage = templateStorage.load(serverTemplate.getId());
    assertNotNull(fromStorage);
    assertEquals(serverTemplate.getId(), fromStorage.getId());
    assertEquals(serverTemplate.getName(), fromStorage.getName());
    Collection<ServerInstanceKey> instances = fromStorage.getServerInstanceKeys();
    assertNotNull(instances);
    assertEquals(0, instances.size());
    Collection<ContainerSpec> containerSpecs = fromStorage.getContainersSpec();
    assertNotNull(containerSpecs);
    assertEquals(1, containerSpecs.size());
    ContainerSpec spec = containerSpecs.iterator().next();
    assertNotNull(spec);
    assertEquals(containerSpec.getId(), spec.getId());
    assertEquals(containerSpec.getReleasedId(), spec.getReleasedId());
    assertEquals(containerSpec.getServerTemplateKey().getId(), spec.getServerTemplateKey().getId());
    assertEquals(containerSpec.getServerTemplateKey().getName(), spec.getServerTemplateKey().getName());
    assertEquals(containerSpec.getConfigs().size(), spec.getConfigs().size());
    assertTrue(spec.getConfigs().containsKey(Capability.RULE));
    assertTrue(spec.getConfigs().containsKey(Capability.PROCESS));
    RuleConfig ruleConfig = (RuleConfig) spec.getConfigs().get(Capability.RULE);
    assertNotNull(ruleConfig);
    assertEquals(this.ruleConfig.getPollInterval(), ruleConfig.getPollInterval());
    assertEquals(this.ruleConfig.getScannerStatus(), ruleConfig.getScannerStatus());
    ProcessConfig processConfig = (ProcessConfig) spec.getConfigs().get(Capability.PROCESS);
    assertNotNull(processConfig);
    assertEquals(this.processConfig.getKBase(), processConfig.getKBase());
    assertEquals(this.processConfig.getKSession(), processConfig.getKSession());
    assertEquals(this.processConfig.getMergeMode(), processConfig.getMergeMode());
    assertEquals(this.processConfig.getRuntimeStrategy(), processConfig.getRuntimeStrategy());
}
Also used : ProcessConfig(org.kie.server.controller.api.model.spec.ProcessConfig) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) ContainerSpec(org.kie.server.controller.api.model.spec.ContainerSpec) ServerInstanceKey(org.kie.server.controller.api.model.runtime.ServerInstanceKey) RuleConfig(org.kie.server.controller.api.model.spec.RuleConfig) Test(org.junit.Test)

Aggregations

ServerInstanceKey (org.kie.server.controller.api.model.runtime.ServerInstanceKey)32 Test (org.junit.Test)28 Container (org.kie.server.controller.api.model.runtime.Container)12 ContainerSpec (org.kie.server.controller.api.model.spec.ContainerSpec)11 ServerTemplate (org.kie.server.controller.api.model.spec.ServerTemplate)11 ReleaseId (org.kie.server.api.model.ReleaseId)7 ServerInstanceSelected (org.kie.workbench.common.screens.server.management.client.events.ServerInstanceSelected)7 ArrayList (java.util.ArrayList)5 ServerTemplateKey (org.kie.server.controller.api.model.spec.ServerTemplateKey)5 NotificationEvent (org.uberfire.workbench.events.NotificationEvent)5 ServerTemplateMigration (org.kie.workbench.common.screens.server.management.backend.storage.migration.ServerTemplateMigration)4 ContainerUpdateEvent (org.kie.workbench.common.screens.server.management.model.ContainerUpdateEvent)4 Path (org.uberfire.java.nio.file.Path)4 Message (org.kie.server.api.model.Message)3 ServerInstanceDeleted (org.kie.server.controller.api.model.events.ServerInstanceDeleted)3 ProcessConfig (org.kie.server.controller.api.model.spec.ProcessConfig)3 RuleConfig (org.kie.server.controller.api.model.spec.RuleConfig)3 ContainerSpecSelected (org.kie.workbench.common.screens.server.management.client.events.ContainerSpecSelected)3 Command (org.uberfire.mvp.Command)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2