Search in sources :

Example 1 with LifecyclePhase

use of org.opentosca.toscana.core.plugin.lifecycle.LifecyclePhase in project TOSCAna by StuPro-TOSCAna.

the class CsarFilesystemDao method readFromDisk.

/**
 *     Reads csars from disks post: csarMap reflects contents of DATA_DIR on disk
 */
private void readFromDisk() {
    csarMap.clear();
    dataDir.mkdir();
    logger.info("Reading CSARs from repository");
    File[] files = dataDir.listFiles();
    for (File file : files) {
        if (isCsarDir(file)) {
            String id = file.getName();
            new File(getRootDir(id), id + ".log").delete();
            CsarImpl csar = new CsarImpl(getRootDir(id), id, getLog(id));
            LifecyclePhase unzip = csar.getLifecyclePhase(Csar.Phase.UNZIP);
            if (csar.getContentDir().listFiles().length != 0) {
                unzip.setState(LifecyclePhase.State.DONE);
                csar.validate();
            } else {
                unzip.setState(LifecyclePhase.State.FAILED);
            }
            csarMap.put(csar.getIdentifier(), csar);
            List<Transformation> transformations = transformationDao.find(csar);
            csar.setTransformations(transformations);
            csar.getLog().close();
        }
    }
    logger.info("Found {} CSARs in repository", csarMap.size());
}
Also used : Transformation(org.opentosca.toscana.core.transformation.Transformation) File(java.io.File) LifecyclePhase(org.opentosca.toscana.core.plugin.lifecycle.LifecyclePhase)

Example 2 with LifecyclePhase

use of org.opentosca.toscana.core.plugin.lifecycle.LifecyclePhase in project TOSCAna by StuPro-TOSCAna.

the class CsarImpl method parseValidate.

private boolean parseValidate() {
    LifecyclePhase phase = getLifecyclePhase(Csar.Phase.PARSE);
    phase.setState(LifecyclePhase.State.EXECUTING);
    logger.info("  > Constructing model from TOSCA template");
    try {
        new EffectiveModelFactory().create(this);
        logger.info("Model construction successful");
        phase.setState(LifecyclePhase.State.DONE);
        return true;
    } catch (Exception e) {
        logger.error("Model construction failed", this.identifier, e);
        phase.setState(LifecyclePhase.State.FAILED);
        return false;
    }
}
Also used : EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) MultiException(org.eclipse.winery.yaml.common.exception.MultiException) InvalidCsarException(org.opentosca.toscana.core.parse.InvalidCsarException) LifecyclePhase(org.opentosca.toscana.core.plugin.lifecycle.LifecyclePhase)

Example 3 with LifecyclePhase

use of org.opentosca.toscana.core.plugin.lifecycle.LifecyclePhase in project TOSCAna by StuPro-TOSCAna.

the class CustomNodeTypeIT method customNodeTypeTest.

@Test
public void customNodeTypeTest() throws FileNotFoundException, CsarIdNotUniqueException {
    File csarFile = TestCsars.VALID_TASKTRANSLATOR;
    InputStream stream = new FileInputStream(csarFile);
    Csar csar = service.submitCsar("csarId", stream);
    LifecyclePhase phase = csar.getLifecyclePhase(Csar.Phase.VALIDATE);
    assertEquals(LifecyclePhase.State.DONE, phase.getState());
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) LifecyclePhase(org.opentosca.toscana.core.plugin.lifecycle.LifecyclePhase) BaseSpringTest(org.opentosca.toscana.core.BaseSpringTest) Test(org.junit.Test)

Example 4 with LifecyclePhase

use of org.opentosca.toscana.core.plugin.lifecycle.LifecyclePhase in project TOSCAna by StuPro-TOSCAna.

the class CsarFilesystemDao method unzip.

private void unzip(String identifier, InputStream inputStream, Csar csar, File csarDir) {
    Logger logger = csar.getLog().getLogger(getClass());
    File contentDir = new File(csarDir, CsarImpl.CONTENT_DIR);
    LifecyclePhase unzipPhase = csar.getLifecyclePhase(Csar.Phase.UNZIP);
    unzipPhase.setState(LifecyclePhase.State.EXECUTING);
    ZipInputStream zipIn = new ZipInputStream(inputStream);
    try {
        boolean success = ZipUtility.unzip(zipIn, contentDir.getPath());
        if (success) {
            logger.info("Extracted csar '{}' into '{}'", identifier, contentDir.getPath());
            unzipPhase.setState(LifecyclePhase.State.DONE);
        } else {
            logger.error("Extracting failed: Submitted file is not a valid .zip file");
            unzipPhase.setState(LifecyclePhase.State.FAILED);
        }
    } catch (IOException e) {
        logger.error("Failed to extract csar with identifier '{}'", identifier, e);
        unzipPhase.setState(LifecyclePhase.State.FAILED);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) IOException(java.io.IOException) Logger(org.slf4j.Logger) File(java.io.File) LifecyclePhase(org.opentosca.toscana.core.plugin.lifecycle.LifecyclePhase)

Example 5 with LifecyclePhase

use of org.opentosca.toscana.core.plugin.lifecycle.LifecyclePhase in project TOSCAna by StuPro-TOSCAna.

the class CsarImpl method initLifecyclePhases.

private List<LifecyclePhase> initLifecyclePhases() {
    List<LifecyclePhase> phases = new ArrayList<>();
    for (Phase phaseName : Phase.values()) {
        LifecyclePhase phase = new LifecyclePhase(phaseName.getName(), this, log.getLogger(LifecyclePhase.class));
        phases.add(phase);
    }
    return phases;
}
Also used : LifecyclePhase(org.opentosca.toscana.core.plugin.lifecycle.LifecyclePhase) ArrayList(java.util.ArrayList) LifecyclePhase(org.opentosca.toscana.core.plugin.lifecycle.LifecyclePhase)

Aggregations

LifecyclePhase (org.opentosca.toscana.core.plugin.lifecycle.LifecyclePhase)6 File (java.io.File)3 MultiException (org.eclipse.winery.yaml.common.exception.MultiException)2 InvalidCsarException (org.opentosca.toscana.core.parse.InvalidCsarException)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 ZipInputStream (java.util.zip.ZipInputStream)1 Test (org.junit.Test)1 BaseSpringTest (org.opentosca.toscana.core.BaseSpringTest)1 Transformation (org.opentosca.toscana.core.transformation.Transformation)1 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)1 Logger (org.slf4j.Logger)1