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());
}
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();
}
}
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);
}
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());
}
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());
}
Aggregations