Search in sources :

Example 1 with ContainerSpec

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

the class RuntimeManagementServiceCDI method getContainersByContainerSpec.

@Override
public ContainerSpecData getContainersByContainerSpec(final String serverTemplateId, final String containerSpecId) {
    final ServerTemplate serverTemplate = specManagementService.getServerTemplate(serverTemplateId);
    final ContainerSpec containerSpec = serverTemplate.getContainerSpec(containerSpecId);
    final ServerInstanceKeyList instances = service.getServerInstances(serverTemplateId);
    if (instances.getServerInstanceKeys() == null) {
        return null;
    }
    final List<Container> containers = Arrays.stream(instances.getServerInstanceKeys()).flatMap(serverInstanceKey -> Arrays.asList(service.getContainers(serverInstanceKey).getContainers()).stream()).filter(container -> containerSpecId.equals(container.getContainerSpecId())).collect(Collectors.toList());
    return new ContainerSpecData(containerSpec, containers);
}
Also used : Arrays(java.util.Arrays) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) Collection(java.util.Collection) ContainerSpec(org.kie.server.controller.api.model.spec.ContainerSpec) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) List(java.util.List) Service(org.jboss.errai.bus.server.annotations.Service) Container(org.kie.server.controller.api.model.runtime.Container) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ContainerSpecData(org.kie.workbench.common.screens.server.management.model.ContainerSpecData) Any(javax.enterprise.inject.Any) ServerInstanceKeyList(org.kie.server.controller.api.model.runtime.ServerInstanceKeyList) Collections(java.util.Collections) RuntimeManagementService(org.kie.workbench.common.screens.server.management.service.RuntimeManagementService) Container(org.kie.server.controller.api.model.runtime.Container) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) ContainerSpec(org.kie.server.controller.api.model.spec.ContainerSpec) ServerInstanceKeyList(org.kie.server.controller.api.model.runtime.ServerInstanceKeyList) ContainerSpecData(org.kie.workbench.common.screens.server.management.model.ContainerSpecData)

Example 2 with ContainerSpec

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

the class ServerTemplateMigration method migrate.

public static void migrate(Path dir, IOService ioService, XStream xs, KieServerTemplateStorage templateStorage) {
    logger.debug("Attempting to find and migrate 6.2 type kie server templates inside directory '{}'...", dir);
    try {
        ioService.startBatch(dir.getFileSystem());
        for (final Path path : ioService.newDirectoryStream(dir, new DirectoryStream.Filter<Path>() {

            @Override
            public boolean accept(Path entry) throws IOException {
                return entry.toString().endsWith("-info.xml");
            }
        })) {
            logger.debug("Found 6.2 type kie server template file '{}', migrating it...", path);
            try {
                final KieServerInstance kieServerInstance = (KieServerInstance) xs.fromXML(ioService.readAllString(path));
                logger.debug("Loaded KieServerInstance {}", kieServerInstance);
                ServerTemplate serverTemplate = new ServerTemplate();
                serverTemplate.setId(kieServerInstance.getIdentifier());
                serverTemplate.setName(kieServerInstance.getName());
                KieServerSetup serverSetup = kieServerInstance.getKieServerSetup();
                if (serverSetup != null) {
                    Set<KieContainerResource> containerResources = kieServerInstance.getKieServerSetup().getContainers();
                    logger.debug("Server with id {} has containers {}", kieServerInstance.getIdentifier(), containerResources);
                    if (containerResources != null) {
                        for (KieContainerResource containerRef : containerResources) {
                            ContainerSpec containerSpec = new ContainerSpec(containerRef.getContainerId(), containerRef.getContainerId(), serverTemplate, containerRef.getReleaseId(), containerRef.getStatus(), new HashMap<Capability, ContainerConfig>());
                            logger.debug("Migrating container '{}' to container spec '{}'", containerRef, containerSpec);
                            serverTemplate.addContainerSpec(containerSpec);
                        }
                    }
                }
                Set<KieServerInstanceInfo> instanceInfos = kieServerInstance.getManagedInstances();
                if (instanceInfos != null) {
                    logger.debug("Server with id {} has server instances {}", kieServerInstance.getIdentifier(), instanceInfos);
                    for (KieServerInstanceInfo instanceInfo : instanceInfos) {
                        logger.debug("Migrating server instance '{}'", instanceInfo);
                        serverTemplate.addServerInstance(ModelFactory.newServerInstanceKey(serverTemplate.getId(), instanceInfo.getLocation()));
                        serverTemplate.setCapabilities(instanceInfo.getCapabilities());
                    }
                }
                logger.debug("About to store migrated server template {}", serverTemplate);
                // store migrated information
                templateStorage.store(serverTemplate);
                logger.info("Server template {} migrated successfully, removing old version...", serverTemplate);
                // delete old to do not attempt second time migration
                try {
                    ioService.startBatch(path.getFileSystem());
                    ioService.delete(path);
                } finally {
                    ioService.endBatch();
                }
                logger.debug("Old version of server template '{}' has been removed", kieServerInstance);
            } catch (Exception ex) {
                logger.error("Error while migrating old version (6.2.) of kie server instance from path {}", path, ex);
            }
        }
    } catch (final NotDirectoryException ignore) {
        logger.debug("No directory found, ignoring migration of kie server templates");
    } finally {
        ioService.endBatch();
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) KieServerSetup(org.kie.server.controller.api.model.KieServerSetup) Capability(org.kie.server.controller.api.model.spec.Capability) ContainerSpec(org.kie.server.controller.api.model.spec.ContainerSpec) DirectoryStream(org.uberfire.java.nio.file.DirectoryStream) IOException(org.uberfire.java.nio.IOException) NotDirectoryException(org.uberfire.java.nio.file.NotDirectoryException) IOException(org.uberfire.java.nio.IOException) ContainerConfig(org.kie.server.controller.api.model.spec.ContainerConfig) NotDirectoryException(org.uberfire.java.nio.file.NotDirectoryException) KieServerInstance(org.kie.server.controller.api.model.KieServerInstance) KieServerInstanceInfo(org.kie.server.controller.api.model.KieServerInstanceInfo) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) KieContainerResource(org.kie.server.api.model.KieContainerResource)

Example 3 with ContainerSpec

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

the class AsyncKieServerInstanceManagerTest method prepare.

@Before
public void prepare() {
    returnedContainers.clear();
    serverTemplate = new ServerTemplate();
    serverTemplate.setName("test server");
    serverTemplate.setId(UUID.randomUUID().toString());
    containerSpec = new ContainerSpec();
    containerSpec.setId("test container");
    containerSpec.setServerTemplateKey(new ServerTemplateKey(serverTemplate.getId(), serverTemplate.getName()));
    containerSpec.setReleasedId(new ReleaseId("org.kie", "kie-server-kjar", "1.0"));
    containerSpec.setStatus(KieContainerStatus.STOPPED);
    containerSpec.setConfigs(new HashMap<Capability, ContainerConfig>());
    serverTemplate.addContainerSpec(containerSpec);
    this.kieServerInstanceManager = new AsyncKieServerInstanceManager(notificationService, containerUpdateEvent, executor) {

        @Override
        protected List<Container> callRemoteKieServerOperation(ServerTemplate serverTemplate, ContainerSpec containerSpec, RemoteKieServerOperation operation) {
            return returnedContainers;
        }
    };
    this.kieServerInstanceManager.setExecutor(executor);
}
Also used : ContainerConfig(org.kie.server.controller.api.model.spec.ContainerConfig) ServerTemplateKey(org.kie.server.controller.api.model.spec.ServerTemplateKey) Capability(org.kie.server.controller.api.model.spec.Capability) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) ContainerSpec(org.kie.server.controller.api.model.spec.ContainerSpec) ArrayList(java.util.ArrayList) List(java.util.List) ReleaseId(org.kie.server.api.model.ReleaseId) Before(org.junit.Before)

Example 4 with ContainerSpec

use of org.kie.server.controller.api.model.spec.ContainerSpec 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 5 with ContainerSpec

use of org.kie.server.controller.api.model.spec.ContainerSpec 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");
}
Also used : ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) ContainerSpec(org.kie.server.controller.api.model.spec.ContainerSpec) Test(org.junit.Test)

Aggregations

ContainerSpec (org.kie.server.controller.api.model.spec.ContainerSpec)33 ServerTemplate (org.kie.server.controller.api.model.spec.ServerTemplate)22 Test (org.junit.Test)20 ReleaseId (org.kie.server.api.model.ReleaseId)13 ServerInstanceKey (org.kie.server.controller.api.model.runtime.ServerInstanceKey)11 ServerTemplateKey (org.kie.server.controller.api.model.spec.ServerTemplateKey)10 RuleConfig (org.kie.server.controller.api.model.spec.RuleConfig)8 Container (org.kie.server.controller.api.model.runtime.Container)7 Capability (org.kie.server.controller.api.model.spec.Capability)7 ContainerConfig (org.kie.server.controller.api.model.spec.ContainerConfig)7 ProcessConfig (org.kie.server.controller.api.model.spec.ProcessConfig)6 HashMap (java.util.HashMap)5 Path (org.uberfire.java.nio.file.Path)5 ServerTemplateMigration (org.kie.workbench.common.screens.server.management.backend.storage.migration.ServerTemplateMigration)4 ServerTemplateSelected (org.kie.workbench.common.screens.server.management.client.events.ServerTemplateSelected)4 NotificationEvent (org.uberfire.workbench.events.NotificationEvent)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 GAV (org.guvnor.common.services.project.model.GAV)3 ServerTemplateList (org.kie.server.controller.api.model.spec.ServerTemplateList)3