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