Search in sources :

Example 1 with InvalidCsarException

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);
    }
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) InvalidCsarException(org.opentosca.toscana.core.parse.InvalidCsarException)

Example 2 with InvalidCsarException

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);
    }
}
Also used : File(java.io.File) InvalidCsarException(org.opentosca.toscana.core.parse.InvalidCsarException)

Example 3 with InvalidCsarException

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);
    }
}
Also used : Log(org.opentosca.toscana.core.transformation.logging.Log) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) InvalidCsarException(org.opentosca.toscana.core.parse.InvalidCsarException)

Example 4 with InvalidCsarException

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;
    }
}
Also used : MultiException(org.eclipse.winery.yaml.common.exception.MultiException) LifecyclePhase(org.opentosca.toscana.core.plugin.lifecycle.LifecyclePhase) InvalidCsarException(org.opentosca.toscana.core.parse.InvalidCsarException)

Aggregations

InvalidCsarException (org.opentosca.toscana.core.parse.InvalidCsarException)4 File (java.io.File)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MultiException (org.eclipse.winery.yaml.common.exception.MultiException)1 LifecyclePhase (org.opentosca.toscana.core.plugin.lifecycle.LifecyclePhase)1 Log (org.opentosca.toscana.core.transformation.logging.Log)1 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)1