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