Search in sources :

Example 1 with KieServerInstance

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

Aggregations

KieContainerResource (org.kie.server.api.model.KieContainerResource)1 KieServerInstance (org.kie.server.controller.api.model.KieServerInstance)1 KieServerInstanceInfo (org.kie.server.controller.api.model.KieServerInstanceInfo)1 KieServerSetup (org.kie.server.controller.api.model.KieServerSetup)1 Capability (org.kie.server.controller.api.model.spec.Capability)1 ContainerConfig (org.kie.server.controller.api.model.spec.ContainerConfig)1 ContainerSpec (org.kie.server.controller.api.model.spec.ContainerSpec)1 ServerTemplate (org.kie.server.controller.api.model.spec.ServerTemplate)1 IOException (org.uberfire.java.nio.IOException)1 DirectoryStream (org.uberfire.java.nio.file.DirectoryStream)1 NotDirectoryException (org.uberfire.java.nio.file.NotDirectoryException)1 Path (org.uberfire.java.nio.file.Path)1