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