Search in sources :

Example 96 with ProvisioningException

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

the class StateHistoryUtils method writeStateHistoryLimit.

public static int writeStateHistoryLimit(Path installDir, int limit, MessageWriter log) throws ProvisioningException {
    if (limit < 0) {
        throw new ProvisioningException("State history limit can not be a negative value: " + limit);
    }
    final Path installedHistoryDir = PathsUtils.getStateHistoryDir(installDir);
    if (!Files.exists(installedHistoryDir)) {
        mkdirs(installedHistoryDir);
    }
    final Path installedHistoryList = installedHistoryDir.resolve(Constants.HISTORY_LIST);
    List<String> installedHistory = Collections.emptyList();
    if (Files.exists(installedHistoryList)) {
        try {
            installedHistory = Files.readAllLines(installedHistoryList);
        } catch (IOException e) {
            throw new ProvisioningException(Errors.readFile(installedHistoryList), e);
        }
    }
    try (BufferedWriter writer = Files.newBufferedWriter(installedHistoryList)) {
        writer.write(String.valueOf(limit));
        writer.newLine();
        int offset = installedHistory.size() - limit;
        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;
            }
            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.readFile(installedHistoryList), e);
    }
    return STATE_HISTORY_LIMIT;
}
Also used : Path(java.nio.file.Path) ProvisioningException(org.jboss.galleon.ProvisioningException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 97 with ProvisioningException

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

the class StateHistoryUtils method isUndoAvailable.

public static boolean isUndoAvailable(Path installDir, MessageWriter log) throws ProvisioningException {
    final Path installedHistoryDir = PathsUtils.getStateHistoryDir(installDir);
    if (!Files.exists(installedHistoryDir)) {
        return false;
    }
    final Path installedHistoryList = PathsUtils.getStateHistoryFile(installDir);
    if (!Files.exists(installedHistoryList)) {
        return false;
    }
    final List<String> installedHistory;
    try {
        installedHistory = Files.readAllLines(installedHistoryList);
    } catch (IOException e) {
        throw new ProvisioningException(Errors.readFile(installedHistoryList), e);
    }
    if (installedHistory.size() < 2) {
        return false;
    }
    int i = installedHistory.size() - 1;
    do {
        if (Files.exists(installedHistoryDir.resolve(installedHistory.get(i--)))) {
            return true;
        }
        log.error("The state history of the current installation is corrupted referencing missing states!");
    } while (i >= 1);
    return false;
}
Also used : Path(java.nio.file.Path) ProvisioningException(org.jboss.galleon.ProvisioningException) IOException(java.io.IOException)

Example 98 with ProvisioningException

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

the class ProvisionedConfigXmlWriter method toElement.

protected ElementNode toElement(ProvisionedConfig config, String ns) throws XMLStreamException {
    final ElementNode configE = addElement(null, Element.CONFIG.getLocalName(), ns);
    if (config.getName() != null) {
        addAttribute(configE, Attribute.NAME, config.getName());
    }
    if (config.getModel() != null) {
        addAttribute(configE, Attribute.MODEL, config.getModel());
    }
    if (config.hasProperties()) {
        final ElementNode propsE = addElement(configE, Element.PROPS.getLocalName(), ns);
        for (Map.Entry<String, String> entry : config.getProperties().entrySet()) {
            final ElementNode propE = addElement(propsE, Element.PROP.getLocalName(), ns);
            addAttribute(propE, Attribute.NAME, entry.getKey());
            addAttribute(propE, Attribute.VALUE, entry.getValue());
        }
    }
    if (config.hasLayers()) {
        final ElementNode propsE = addElement(configE, Element.LAYERS.getLocalName(), ns);
        for (ConfigId layerId : config.getLayers()) {
            final ElementNode propE = addElement(propsE, Element.LAYER.getLocalName(), ns);
            if (layerId.getModel() != null) {
                addAttribute(propE, Attribute.MODEL, layerId.getModel());
            }
            addAttribute(propE, Attribute.NAME, layerId.getName());
        }
    }
    if (config.hasFeatures()) {
        try {
            config.handle(new XmlConfigHandler(configE));
        } catch (ProvisioningException e) {
            throw new XMLStreamException("Failed to marshal ProvisionedConfig", e);
        }
    }
    return configE;
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) ProvisioningException(org.jboss.galleon.ProvisioningException) ConfigId(org.jboss.galleon.config.ConfigId) ElementNode(org.jboss.galleon.xml.util.ElementNode) Map(java.util.Map)

Example 99 with ProvisioningException

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

the class XmlParsers method parseConfigLayerSpec.

public static ConfigLayerSpec parseConfigLayerSpec(Reader reader, String model) throws ProvisioningException {
    ConfigLayerSpec.Builder builder = ConfigLayerSpec.builder();
    builder.setModel(model);
    try {
        parse(reader, builder);
    } catch (XMLStreamException e) {
        throw new ProvisioningException("Failed to parse config layer spec", e);
    }
    return builder.build();
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) ProvisioningException(org.jboss.galleon.ProvisioningException) ConfigLayerSpec(org.jboss.galleon.spec.ConfigLayerSpec)

Example 100 with ProvisioningException

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

the class FeaturePackDepsConfigBuilder method removeFeaturePackDep.

@SuppressWarnings("unchecked")
public B removeFeaturePackDep(FeaturePackLocation fpl) throws ProvisioningException {
    fpl = resolveUniverseSpec(fpl);
    final ProducerSpec producer = fpl.getProducer();
    final FeaturePackConfig fpDep = fpDeps.get(producer);
    if (fpDep == null) {
        throw new ProvisioningException(Errors.unknownFeaturePack(fpl.getFPID()));
    }
    if (!fpDep.getLocation().getFPID().equals(fpl.getFPID())) {
        throw new ProvisioningException(Errors.unknownFeaturePack(fpl.getFPID()));
    }
    if (fpDeps.size() == 1) {
        fpDeps = Collections.emptyMap();
    } else {
        fpDeps = CollectionUtils.remove(fpDeps, producer);
    }
    updateOriginMappings(producer);
    return (B) this;
}
Also used : ProducerSpec(org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec) ProvisioningException(org.jboss.galleon.ProvisioningException)

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