Search in sources :

Example 1 with Capability

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

the class BuildExecutorTest method testMakeConfigsWhenServerTemplateDoesNotHaveProcessCapability.

@Test
public void testMakeConfigsWhenServerTemplateDoesNotHaveProcessCapability() {
    final ServerTemplate serverTemplate = mock(ServerTemplate.class);
    final RuleConfig ruleConfig = mock(RuleConfig.class);
    doReturn(ruleConfig).when(buildExecutor).makeRuleConfig();
    final Map<Capability, ContainerConfig> configs = buildExecutor.makeConfigs(serverTemplate, new HashMap<>());
    assertTrue(configs.keySet().contains(Capability.RULE));
    assertTrue(configs.values().contains(ruleConfig));
    assertEquals(1, configs.size());
}
Also used : ContainerConfig(org.kie.server.controller.api.model.spec.ContainerConfig) Capability(org.kie.server.controller.api.model.spec.Capability) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) RuleConfig(org.kie.server.controller.api.model.spec.RuleConfig) Test(org.junit.Test)

Example 2 with Capability

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

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

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

the class BuildExecutorTest method testMakeConfigsWhenServerTemplateHasProcessCapabilityWithStrategy.

@Test
public void testMakeConfigsWhenServerTemplateHasProcessCapabilityWithStrategy() {
    final ServerTemplate serverTemplate = mock(ServerTemplate.class);
    final RuleConfig ruleConfig = mock(RuleConfig.class);
    doReturn(ruleConfig).when(buildExecutor).makeRuleConfig();
    doReturn(true).when(buildExecutor).hasProcessCapability(any());
    Map<String, String> params = new HashMap<>();
    params.put("RuntimeStrategy", RuntimeStrategy.PER_PROCESS_INSTANCE.name());
    final Map<Capability, ContainerConfig> configs = buildExecutor.makeConfigs(serverTemplate, params);
    assertTrue(configs.keySet().contains(Capability.RULE));
    assertTrue(configs.keySet().contains(Capability.PROCESS));
    assertTrue(configs.values().contains(ruleConfig));
    assertEquals(2, configs.size());
    ProcessConfig processConf = (ProcessConfig) configs.get(Capability.PROCESS);
    assertEquals(RuntimeStrategy.PER_PROCESS_INSTANCE.name(), processConf.getRuntimeStrategy());
}
Also used : ContainerConfig(org.kie.server.controller.api.model.spec.ContainerConfig) Capability(org.kie.server.controller.api.model.spec.Capability) ProcessConfig(org.kie.server.controller.api.model.spec.ProcessConfig) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) HashMap(java.util.HashMap) RuleConfig(org.kie.server.controller.api.model.spec.RuleConfig) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 5 with Capability

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

the class BuildExecutorTest method testMakeConfigsWhenServerTemplateHasProcessCapabilityWithDefaultStrategy.

@Test
public void testMakeConfigsWhenServerTemplateHasProcessCapabilityWithDefaultStrategy() {
    final ServerTemplate serverTemplate = mock(ServerTemplate.class);
    final RuleConfig ruleConfig = mock(RuleConfig.class);
    doReturn(ruleConfig).when(buildExecutor).makeRuleConfig();
    doReturn(true).when(buildExecutor).hasProcessCapability(any());
    Map<String, String> params = new HashMap<>();
    final Map<Capability, ContainerConfig> configs = buildExecutor.makeConfigs(serverTemplate, params);
    assertTrue(configs.keySet().contains(Capability.RULE));
    assertTrue(configs.keySet().contains(Capability.PROCESS));
    assertTrue(configs.values().contains(ruleConfig));
    assertEquals(2, configs.size());
    ProcessConfig processConf = (ProcessConfig) configs.get(Capability.PROCESS);
    assertEquals(RuntimeStrategy.SINGLETON.name(), processConf.getRuntimeStrategy());
}
Also used : ContainerConfig(org.kie.server.controller.api.model.spec.ContainerConfig) Capability(org.kie.server.controller.api.model.spec.Capability) ProcessConfig(org.kie.server.controller.api.model.spec.ProcessConfig) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) HashMap(java.util.HashMap) RuleConfig(org.kie.server.controller.api.model.spec.RuleConfig) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

Capability (org.kie.server.controller.api.model.spec.Capability)10 ContainerConfig (org.kie.server.controller.api.model.spec.ContainerConfig)10 ServerTemplate (org.kie.server.controller.api.model.spec.ServerTemplate)9 RuleConfig (org.kie.server.controller.api.model.spec.RuleConfig)7 ContainerSpec (org.kie.server.controller.api.model.spec.ContainerSpec)6 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 ProcessConfig (org.kie.server.controller.api.model.spec.ProcessConfig)4 ReleaseId (org.kie.server.api.model.ReleaseId)3 ServerTemplateKey (org.kie.server.controller.api.model.spec.ServerTemplateKey)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Container (org.kie.server.controller.api.model.runtime.Container)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Event (javax.enterprise.event.Event)1