Search in sources :

Example 1 with NotDirectoryException

use of org.uberfire.java.nio.file.NotDirectoryException 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 2 with NotDirectoryException

use of org.uberfire.java.nio.file.NotDirectoryException in project kie-wb-common by kiegroup.

the class ServerTemplateVFSStorage method load.

@Override
public List<ServerTemplate> load() {
    logger.debug("About to load all available server templates...");
    final List<ServerTemplate> result = new ArrayList<ServerTemplate>();
    final Path dir = buildPath(null);
    try {
        ioService.startBatch(dir.getFileSystem());
        for (final Path registeredServer : ioService.newDirectoryStream(dir)) {
            try {
                ServerTemplate serverTemplate = readServerTemplate(registeredServer);
                logger.debug("Found server template {}", serverTemplate);
                result.add(serverTemplate);
            } catch (final Exception ignore) {
                ioService.delete(registeredServer);
            }
        }
        logger.debug("All found server templates {}", result);
        return result;
    } catch (final NotDirectoryException ignore) {
        logger.debug("No directory found {}, returning empty result", dir);
        return result;
    } finally {
        ioService.endBatch();
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) NotDirectoryException(org.uberfire.java.nio.file.NotDirectoryException) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) ArrayList(java.util.ArrayList) NotDirectoryException(org.uberfire.java.nio.file.NotDirectoryException)

Example 3 with NotDirectoryException

use of org.uberfire.java.nio.file.NotDirectoryException in project kie-wb-common by kiegroup.

the class ServerTemplateVFSStorage method loadKeys.

@Override
public List<ServerTemplateKey> loadKeys() {
    logger.debug("About to load all available server templates (as keys only)...");
    final List<ServerTemplateKey> result = new ArrayList<ServerTemplateKey>();
    final Path dir = buildPath(null);
    try {
        ioService.startBatch(dir.getFileSystem());
        for (final Path registeredServer : ioService.newDirectoryStream(dir)) {
            try {
                ServerTemplate serverTemplate = readServerTemplate(registeredServer);
                logger.debug("Found server template {}, taking its short key version...");
                result.add(new ServerTemplateKey(serverTemplate.getId(), serverTemplate.getName()));
            } catch (final Exception ignore) {
                ioService.delete(registeredServer);
            }
        }
        logger.debug("All found server template keys {}", result);
        return result;
    } catch (final NotDirectoryException ignore) {
        logger.debug("No directory found {}, returning empty result", dir);
        return result;
    } finally {
        ioService.endBatch();
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) ServerTemplateKey(org.kie.server.controller.api.model.spec.ServerTemplateKey) NotDirectoryException(org.uberfire.java.nio.file.NotDirectoryException) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) ArrayList(java.util.ArrayList) NotDirectoryException(org.uberfire.java.nio.file.NotDirectoryException)

Aggregations

ServerTemplate (org.kie.server.controller.api.model.spec.ServerTemplate)3 NotDirectoryException (org.uberfire.java.nio.file.NotDirectoryException)3 Path (org.uberfire.java.nio.file.Path)3 ArrayList (java.util.ArrayList)2 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 ServerTemplateKey (org.kie.server.controller.api.model.spec.ServerTemplateKey)1 IOException (org.uberfire.java.nio.IOException)1 DirectoryStream (org.uberfire.java.nio.file.DirectoryStream)1