Search in sources :

Example 1 with ServerTemplateMigration

use of org.kie.workbench.common.screens.server.management.backend.storage.migration.ServerTemplateMigration 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 2 with ServerTemplateMigration

use of org.kie.workbench.common.screens.server.management.backend.storage.migration.ServerTemplateMigration in project kie-wb-common by kiegroup.

the class ServerTemplateMigrationTest method testMigrationOfServerTemplateOnly.

@Test
public void testMigrationOfServerTemplateOnly() throws Exception {
    String serverTemplateId = "kie_server";
    String oldServerTemplateContent = IOUtils.toString(this.getClass().getResourceAsStream("/kie-server-6.3-info-just-server.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);
    assertEquals(0, capabilities.size());
    // verify server instances (previously known as managedInstances)
    Collection<ServerInstanceKey> instances = fromStorage.getServerInstanceKeys();
    assertNotNull(instances);
    assertEquals(0, instances.size());
    // verify containers
    Collection<ContainerSpec> containerSpecs = fromStorage.getContainersSpec();
    assertNotNull(containerSpecs);
    assertEquals(0, containerSpecs.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) Test(org.junit.Test)

Example 3 with ServerTemplateMigration

use of org.kie.workbench.common.screens.server.management.backend.storage.migration.ServerTemplateMigration in project kie-wb-common by kiegroup.

the class ServerTemplateMigrationTest method testMigrationOfOldServerTemplateWithInstances.

@Test
public void testMigrationOfOldServerTemplateWithInstances() throws Exception {
    String serverTemplateId = "kie_server";
    String oldServerTemplateContent = IOUtils.toString(this.getClass().getResourceAsStream("/kie-server-6.3-info-with-instances.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(0, containerSpecs.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) Test(org.junit.Test)

Example 4 with ServerTemplateMigration

use of org.kie.workbench.common.screens.server.management.backend.storage.migration.ServerTemplateMigration in project kie-wb-common by kiegroup.

the class ServerTemplateMigrationTest method testMigrationOfOldServerTemplateWithContainers.

@Test
public void testMigrationOfOldServerTemplateWithContainers() throws Exception {
    String serverTemplateId = "kie_server";
    String oldServerTemplateContent = IOUtils.toString(this.getClass().getResourceAsStream("/kie-server-6.3-info-with-containers.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);
    assertEquals(0, capabilities.size());
    // verify server instances (previously known as managedInstances)
    Collection<ServerInstanceKey> instances = fromStorage.getServerInstanceKeys();
    assertNotNull(instances);
    assertEquals(0, instances.size());
    // verify containers
    Collection<ContainerSpec> containerSpecs = fromStorage.getContainersSpec();
    assertNotNull(containerSpecs);
    assertEquals(1, containerSpecs.size());
    Iterator<ContainerSpec> iterator = containerSpecs.iterator();
    // first container spec...
    ContainerSpec spec = iterator.next();
    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)

Aggregations

Test (org.junit.Test)4 ServerInstanceKey (org.kie.server.controller.api.model.runtime.ServerInstanceKey)4 ContainerSpec (org.kie.server.controller.api.model.spec.ContainerSpec)4 ServerTemplate (org.kie.server.controller.api.model.spec.ServerTemplate)4 ServerTemplateMigration (org.kie.workbench.common.screens.server.management.backend.storage.migration.ServerTemplateMigration)4 Path (org.uberfire.java.nio.file.Path)4 ReleaseId (org.kie.server.api.model.ReleaseId)2