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