Search in sources :

Example 91 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class SpecOnlyConfigArranger method orderFeatures.

public List<ResolvedFeature> orderFeatures(ConfigModelStack stack) throws ProvisioningException {
    this.specFeatures = stack.specFeatures;
    this.features = stack.features;
    try {
        doOrder(stack.rt);
    } catch (ProvisioningException e) {
        throw new ProvisioningException(Errors.failedToBuildConfigSpec(stack.id.getModel(), stack.id.getName()), e);
    }
    return orderedFeatures;
}
Also used : ProvisioningException(org.jboss.galleon.ProvisioningException)

Example 92 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class LegacyGalleon1FeaturePackInstaller method install.

@Override
public void install(Universe<?> universe, FeaturePackLocation.FPID fpid, Path fpZip) throws ProvisioningException {
    final LegacyGalleon1Universe mvnUni = (LegacyGalleon1Universe) universe;
    final ChannelSpec channel = fpid.getChannel();
    final LegacyGalleon1Producer producer = mvnUni.getProducer(channel.getProducer());
    // make sure the channel exists
    producer.getChannel(channel.getName());
    if (!(mvnUni.artifactResolver instanceof RepositoryArtifactInstaller)) {
        throw new ProvisioningException(mvnUni.artifactResolver.getClass().getName() + " is not an instance of " + LegacyGalleon1RepositoryManager.class.getName());
    }
    ((RepositoryArtifactInstaller) mvnUni.artifactResolver).install(LegacyGalleon1Universe.toMavenCoords(fpid.getLocation()), fpZip);
}
Also used : ProvisioningException(org.jboss.galleon.ProvisioningException) RepositoryArtifactInstaller(org.jboss.galleon.repo.RepositoryArtifactInstaller) ChannelSpec(org.jboss.galleon.universe.FeaturePackLocation.ChannelSpec)

Example 93 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class LegacyGalleon1RepositoryManager method install.

public void install(String coords, Path artifact) throws ProvisioningException {
    try {
        final Path path = getArtifactPath(coords);
        Files.createDirectories(path.getParent());
        if (Files.isDirectory(artifact)) {
            ZipUtils.zip(artifact, path);
        } else {
            Files.copy(artifact, path, StandardCopyOption.REPLACE_EXISTING);
        }
    } catch (IOException ex) {
        throw new ProvisioningException("Failed to install artifact " + coords + " to " + artifact, ex);
    }
}
Also used : Path(java.nio.file.Path) ProvisioningException(org.jboss.galleon.ProvisioningException) IOException(java.io.IOException)

Example 94 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class StateHistoryUtils method addNewUndoConfig.

public static void addNewUndoConfig(Path installDir, Path stagedDir, Map<String, Boolean> undoTasks, MessageWriter log) throws ProvisioningException {
    final Path installedConfig = PathsUtils.getProvisioningXml(installDir);
    if (!Files.exists(installedConfig)) {
        return;
    }
    final Path stagedHistoryDir = PathsUtils.getStateHistoryDir(stagedDir);
    mkdirs(stagedHistoryDir);
    final Path installedHistoryDir = PathsUtils.getStateHistoryDir(installDir);
    List<String> installedHistory = Collections.emptyList();
    if (Files.exists(installedHistoryDir)) {
        final Path installHistoryList = installedHistoryDir.resolve(Constants.HISTORY_LIST);
        if (Files.exists(installHistoryList)) {
            try {
                installedHistory = Files.readAllLines(installHistoryList);
            } catch (IOException e) {
                throw new ProvisioningException(Errors.readFile(installHistoryList), e);
            }
        }
    }
    final int historyLimit = installedHistory.isEmpty() ? STATE_HISTORY_LIMIT : Integer.parseInt(installedHistory.get(0));
    final String newStateId = UUID.randomUUID().toString();
    try (BufferedWriter writer = Files.newBufferedWriter(stagedHistoryDir.resolve(Constants.HISTORY_LIST))) {
        writer.write(String.valueOf(historyLimit));
        writer.newLine();
        if (!installedHistory.isEmpty()) {
            int offset = installedHistory.size() - historyLimit + 1;
            if (offset < 1) {
                offset = 1;
            }
            int missingStates = 0;
            while (offset < installedHistory.size()) {
                final String stateId = installedHistory.get(offset++);
                final Path stateFile = installedHistoryDir.resolve(stateId);
                if (!Files.exists(stateFile)) {
                    ++missingStates;
                    continue;
                }
                IoUtils.copy(stateFile, stagedHistoryDir.resolve(stateId));
                writer.write(stateId);
                writer.newLine();
            }
            if (missingStates > 0) {
                log.error("The state history of the current installation is corrupted referencing " + missingStates + " missing states!");
            }
        }
        if (historyLimit > 0) {
            writer.write(newStateId);
        }
    } catch (IOException e) {
        throw new ProvisioningException(Errors.writeFile(stagedHistoryDir.resolve(Constants.HISTORY_LIST)), e);
    }
    final Path stateDir = stagedHistoryDir.resolve(newStateId);
    try {
        Files.createDirectory(stateDir);
    } catch (IOException e) {
        throw new ProvisioningException(Errors.mkdirs(stateDir));
    }
    try {
        IoUtils.copy(installedConfig, stateDir.resolve(Constants.PROVISIONING_XML));
    } catch (IOException e) {
        throw new ProvisioningException(Errors.copyFile(installedConfig, stateDir.resolve(Constants.PROVISIONING_XML)), e);
    }
    if (!undoTasks.isEmpty()) {
        log.verbose("Persisting undo tasks: ");
        try (BufferedWriter writer = Files.newBufferedWriter(stateDir.resolve(Constants.UNDO_TASKS))) {
            for (Map.Entry<String, Boolean> entry : undoTasks.entrySet()) {
                final String action = entry.getValue() ? Constants.KEEP : Constants.REMOVE;
                log.verbose(" - %s %s", entry.getKey(), action);
                writer.write(entry.getKey());
                writer.newLine();
                writer.write(action);
                writer.newLine();
            }
        } catch (IOException e) {
            throw new ProvisioningException(Errors.writeFile(stateDir.resolve(Constants.UNDO_TASKS)), e);
        }
    }
}
Also used : Path(java.nio.file.Path) ProvisioningException(org.jboss.galleon.ProvisioningException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) BufferedWriter(java.io.BufferedWriter)

Example 95 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class StateHistoryUtils method removeLastUndoConfig.

public static void removeLastUndoConfig(Path installDir, Path stagedDir, MessageWriter log) throws ProvisioningException {
    final Path installedConfig = PathsUtils.getProvisioningXml(installDir);
    if (!Files.exists(installedConfig)) {
        return;
    }
    final Path installedHistoryDir = PathsUtils.getStateHistoryDir(installDir);
    List<String> installedHistory = Collections.emptyList();
    if (Files.exists(installedHistoryDir)) {
        final Path installHistoryList = installedHistoryDir.resolve(Constants.HISTORY_LIST);
        if (Files.exists(installHistoryList)) {
            try {
                installedHistory = Files.readAllLines(installHistoryList);
            } catch (IOException e) {
                throw new ProvisioningException(Errors.readFile(installHistoryList), e);
            }
        }
    }
    if (installedHistory.size() < 2) {
        return;
    }
    final Path stagedHistoryDir = PathsUtils.getStateHistoryDir(stagedDir);
    mkdirs(stagedHistoryDir);
    final int historyLimit = installedHistory.isEmpty() ? STATE_HISTORY_LIMIT : Integer.parseInt(installedHistory.get(0));
    try (BufferedWriter writer = Files.newBufferedWriter(stagedHistoryDir.resolve(Constants.HISTORY_LIST))) {
        writer.write(String.valueOf(historyLimit));
        writer.newLine();
        if (!installedHistory.isEmpty()) {
            int offset = installedHistory.size() - historyLimit - 1;
            if (offset < 1) {
                offset = 1;
            }
            int missingStates = 0;
            while (offset < installedHistory.size() - 1) {
                final String stateId = installedHistory.get(offset++);
                final Path stateDir = installedHistoryDir.resolve(stateId);
                if (!Files.exists(stateDir)) {
                    ++missingStates;
                    continue;
                }
                IoUtils.copy(stateDir, stagedHistoryDir.resolve(stateId));
                writer.write(stateId);
                writer.newLine();
            }
            if (missingStates > 0) {
                log.error("The state history of the current installation is corrupted referencing " + missingStates + " missing states!");
            }
        }
    } catch (IOException e) {
        throw new ProvisioningException(Errors.writeFile(stagedHistoryDir.resolve(Constants.HISTORY_LIST)), e);
    }
}
Also used : Path(java.nio.file.Path) ProvisioningException(org.jboss.galleon.ProvisioningException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Aggregations

ProvisioningException (org.jboss.galleon.ProvisioningException)101 IOException (java.io.IOException)45 Path (java.nio.file.Path)35 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)24 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)15 XMLStreamException (javax.xml.stream.XMLStreamException)13 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)10 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)10 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)9 ProvisioningManager (org.jboss.galleon.ProvisioningManager)9 BufferedReader (java.io.BufferedReader)8 HashMap (java.util.HashMap)8 ConfigId (org.jboss.galleon.config.ConfigId)8 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)8 ProducerSpec (org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 Map (java.util.Map)7 FeatureContainerPathConsumer (org.jboss.galleon.cli.path.FeatureContainerPathConsumer)7 BufferedWriter (java.io.BufferedWriter)6