use of org.opentosca.toscana.core.transformation.artifacts.TargetArtifact in project TOSCAna by StuPro-TOSCAna.
the class ExecutionTask method serveArtifact.
private void serveArtifact() {
if (transformationRootDir.listFiles().length != 0) {
try {
logger.info("Compressing transformation artifacts");
TargetArtifact artifact = artifactService.serveArtifact(transformation);
transformation.setTargetArtifact(artifact);
logger.info("Artifact archive ready for download");
} catch (IOException e) {
logger.error("Failed to serve artifact archive for transformation {}/{}", csarId, platformId, e);
failed = true;
}
} else {
failed = true;
logger.error("Logfile missing! Not compressing target artifacts: Transformation generated no output files");
}
}
use of org.opentosca.toscana.core.transformation.artifacts.TargetArtifact in project TOSCAna by StuPro-TOSCAna.
the class TransformationFilesystemDao method createTargetArtifact.
@Override
public TargetArtifact createTargetArtifact(Transformation transformation) {
String csarId = transformation.getCsar().getIdentifier();
String platformId = transformation.getPlatform().id;
String failed = transformation.getState() == TransformationState.ERROR ? FAILED : "";
String filename = csarId + "-" + platformId + "_" + FORMAT.format(new Date(currentTimeMillis())) + failed + ".zip";
File outfile = new File(getRootDir(transformation), filename);
TargetArtifact artifact = new TargetArtifact(outfile);
transformation.setTargetArtifact(artifact);
return artifact;
}
use of org.opentosca.toscana.core.transformation.artifacts.TargetArtifact in project TOSCAna by StuPro-TOSCAna.
the class TransformationFilesystemDao method readTargetArtifactFromDisk.
private void readTargetArtifactFromDisk(Transformation transformation) {
File[] files = getRootDir(transformation).listFiles();
for (File file : files) {
String fileName = file.getName();
if (fileName.matches(ARTIFACT_FAILED_REGEX)) {
transformation.setState(TransformationState.ERROR);
transformation.setTargetArtifact(new TargetArtifact(file));
break;
} else if (fileName.matches(ARTIFACT_SUCCESSFUL_REGEX)) {
transformation.setState(TransformationState.DONE);
transformation.setTargetArtifact(new TargetArtifact(file));
break;
}
}
}
use of org.opentosca.toscana.core.transformation.artifacts.TargetArtifact in project TOSCAna by StuPro-TOSCAna.
the class TransformationControllerTest method retrieveArtifact.
// </editor-fold>
// <editor-fold desc="Test Artifact Retrieval">
@Test
public void retrieveArtifact() throws Exception {
preInitNonCreationTests();
File dummyFile = new File(tmpdir, "test.bin");
dummyFile.delete();
byte[] data = ByteArrayUtils.generateRandomByteArray(new Random(123), 2048);
FileUtils.writeByteArrayToFile(dummyFile, data);
when(csarService.getCsar(VALID_CSAR_NAME).get().getTransformation(VALID_PLATFORM_NAME).get().getTargetArtifact()).thenReturn(Optional.of(new TargetArtifact(dummyFile)));
mvc.perform(get(GET_ARTIFACTS_VALID_URL)).andExpect(status().is(200)).andExpect(content().contentType("application/octet-stream")).andExpect(content().bytes(data)).andReturn();
}
use of org.opentosca.toscana.core.transformation.artifacts.TargetArtifact in project TOSCAna by StuPro-TOSCAna.
the class TransformationServiceImplTest method startTransformationWithArtifacts.
@Test(timeout = TEST_EXECUTION_TIMEOUT_MS)
public void startTransformationWithArtifacts() throws Exception {
Transformation transformation = startTransformationInternal(TransformationState.DONE, PASSING_WRITING_DUMMY.getPlatform());
Optional<TargetArtifact> targetArtifactOptional = transformation.getTargetArtifact();
assertTrue(targetArtifactOptional.isPresent());
TargetArtifact targetArtifact = targetArtifactOptional.get();
assertFalse(targetArtifact.name.matches(TransformationFilesystemDao.ARTIFACT_FAILED_REGEX));
}
Aggregations