use of org.opentosca.toscana.core.parse.InvalidCsarException in project TOSCAna by StuPro-TOSCAna.
the class CustomTypeInjector method inject.
/**
* Injects TOSCAna type definitions into service templates, if necessary
*/
public void inject(Csar csar) {
// - minor changes have to be made in order to inject other types
try {
File serviceTemplate = csar.getTemplate();
String templateContent = FileUtils.readFileToString(serviceTemplate);
List<String> template = Lists.newArrayList(templateContent.split("\n"));
for (Map.Entry<String, InputStream> definition : NODE_TYPE_DEFINITIONS.entrySet()) {
if (isRequired(definition.getKey(), templateContent)) {
template = inject(template, definition.getValue(), "node_types:");
}
}
FileUtils.writeLines(serviceTemplate, template);
} catch (InvalidCsarException | IOException e) {
logger.error("Failed to inject custom types into csar", e);
}
}
use of org.opentosca.toscana.core.parse.InvalidCsarException in project TOSCAna by StuPro-TOSCAna.
the class EntrypointDetector method findEntryPoint.
/**
* Note: Entry points are currently only top level .yaml files.
* An entry point specified in the tosca metadata file is currently ignored
*
* @param csarRoot the file denoting the csar root dir
* @return the entry point yaml file of given csar
* @throws InvalidCsarException if no or more than one top level yaml file was found in given csar
*/
File findEntryPoint(File csarRoot) throws InvalidCsarException {
File[] entryPoints = csarRoot.listFiles((file, s) -> s.matches(".*\\.ya?ml$"));
if (entryPoints == null) {
logger.error(String.format("Given directory '%s' does not exist", csarRoot));
throw new InvalidCsarException(log);
}
if (entryPoints.length == 1) {
File entryPoint = entryPoints[0].getAbsoluteFile();
logger.debug("Detected entry point of CSAR is '{}'", entryPoint.getName());
return entryPoint;
} else if (entryPoints.length > 1) {
logger.warn("Parsing failed: more than one top level yaml file encountered in given csar");
throw new InvalidCsarException(log);
} else {
logger.error("Parsing failed: no top level yaml file encountered in given csar");
throw new InvalidCsarException(log);
}
}
use of org.opentosca.toscana.core.parse.InvalidCsarException in project TOSCAna by StuPro-TOSCAna.
the class TransformationFilesystemDao method createTransformation.
private Transformation createTransformation(Csar csar, Platform platform) {
try {
Log log = getLog(csar, platform);
EffectiveModel model = effectiveModelFactory.create(csar.getTemplate(), log);
return new TransformationImpl(csar, platform, getLog(csar, platform), model);
} catch (InvalidCsarException e) {
throw new IllegalStateException("Failed to create csar. Should not have happened - csar upload should have" + "already failed", e);
}
}
use of org.opentosca.toscana.core.parse.InvalidCsarException in project TOSCAna by StuPro-TOSCAna.
the class CsarImpl method wineryValidate.
private boolean wineryValidate() {
LifecyclePhase phase = getLifecyclePhase(Csar.Phase.VALIDATE);
phase.setState(LifecyclePhase.State.EXECUTING);
logger.info("Validating csar '{}'", identifier);
logger.debug(" > Validating TOSCA template", identifier);
try {
Reader.getReader().parse(Paths.get(this.contentDir.toString()), Paths.get(getTemplate().toString()));
logger.info("Template validation successful");
phase.setState(LifecyclePhase.State.DONE);
return true;
} catch (InvalidCsarException e) {
logger.error("Template validation failed");
phase.setState(LifecyclePhase.State.FAILED);
return false;
} catch (MultiException e) {
logger.error("Template validation failed", e);
phase.setState(LifecyclePhase.State.FAILED);
return false;
}
}
Aggregations