Search in sources :

Example 6 with ServerTemplate

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

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

the class ServerTemplateVFSStorage method load.

@Override
public ServerTemplate load(final String identifier) {
    logger.debug("About to load server template for {}", identifier);
    final Path path = buildPath(identifier);
    ServerTemplate serverTemplate = readServerTemplate(path);
    logger.debug("Server template loaded {}", serverTemplate);
    return serverTemplate;
}
Also used : Path(org.uberfire.java.nio.file.Path) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate)

Example 8 with ServerTemplate

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

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

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

Aggregations

ServerTemplate (org.kie.server.controller.api.model.spec.ServerTemplate)61 Test (org.junit.Test)49 ContainerSpec (org.kie.server.controller.api.model.spec.ContainerSpec)24 ServerTemplateKey (org.kie.server.controller.api.model.spec.ServerTemplateKey)12 ServerInstanceKey (org.kie.server.controller.api.model.runtime.ServerInstanceKey)11 RuleConfig (org.kie.server.controller.api.model.spec.RuleConfig)10 ArrayList (java.util.ArrayList)9 Capability (org.kie.server.controller.api.model.spec.Capability)9 ContainerConfig (org.kie.server.controller.api.model.spec.ContainerConfig)9 Path (org.uberfire.java.nio.file.Path)9 ReleaseId (org.kie.server.api.model.ReleaseId)8 ProcessConfig (org.kie.server.controller.api.model.spec.ProcessConfig)8 Command (org.uberfire.mvp.Command)7 ParameterizedCommand (org.uberfire.mvp.ParameterizedCommand)7 Matchers.anyString (org.mockito.Matchers.anyString)6 HashMap (java.util.HashMap)5 List (java.util.List)5 Container (org.kie.server.controller.api.model.runtime.Container)5 ValidateExistingContainerCallback (org.kie.workbench.common.screens.projecteditor.client.editor.DeploymentScreenPopupViewImpl.ValidateExistingContainerCallback)5 ServerTemplateSelected (org.kie.workbench.common.screens.server.management.client.events.ServerTemplateSelected)5