use of org.kie.server.controller.api.model.spec.ServerTemplate 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);
}
use of org.kie.server.controller.api.model.spec.ServerTemplate in project kie-wb-common by kiegroup.
the class SpecManagementServiceCDITest method testValidContainerIdWhenContainerIdIsValidInTheThirdAttempt.
@Test
public void testValidContainerIdWhenContainerIdIsValidInTheThirdAttempt() {
final SpecManagementServiceCDI service = spy(new SpecManagementServiceCDI());
final ServerTemplate template = mock(ServerTemplate.class);
final ContainerSpec containerSpec = mock(ContainerSpec.class);
when(template.getContainerSpec("org.jbpm:Evaluation:1.0")).thenReturn(containerSpec);
when(template.getContainerSpec("org.jbpm:Evaluation:1.0-2")).thenReturn(containerSpec);
when(template.getContainerSpec("org.jbpm:Evaluation:1.0-3")).thenReturn(null);
doReturn(template).when(service).getServerTemplate("templateId");
final String containerId = service.validContainerId("templateId", "org.jbpm:Evaluation:1.0");
assertEquals(containerId, "org.jbpm:Evaluation:1.0-3");
}
use of org.kie.server.controller.api.model.spec.ServerTemplate 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());
}
use of org.kie.server.controller.api.model.spec.ServerTemplate in project kie-wb-common by kiegroup.
the class ServerTemplateVFSStorageTest method testEmptyLoadServerTemplate.
@Test
public void testEmptyLoadServerTemplate() {
ServerTemplate template = templateStorage.load("not existing");
assertNull(template);
}
use of org.kie.server.controller.api.model.spec.ServerTemplate 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());
}
Aggregations