use of org.kie.server.controller.api.model.KieServerInstance 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();
}
}
Aggregations