Search in sources :

Example 1 with TargetArtifact

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");
    }
}
Also used : TargetArtifact(org.opentosca.toscana.core.transformation.artifacts.TargetArtifact) IOException(java.io.IOException)

Example 2 with TargetArtifact

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;
}
Also used : TargetArtifact(org.opentosca.toscana.core.transformation.artifacts.TargetArtifact) File(java.io.File) Date(java.util.Date)

Example 3 with TargetArtifact

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

Example 4 with TargetArtifact

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();
}
Also used : TargetArtifact(org.opentosca.toscana.core.transformation.artifacts.TargetArtifact) Random(java.util.Random) File(java.io.File) Test(org.junit.Test) BaseSpringTest(org.opentosca.toscana.core.BaseSpringTest)

Example 5 with TargetArtifact

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));
}
Also used : TargetArtifact(org.opentosca.toscana.core.transformation.artifacts.TargetArtifact) Test(org.junit.Test) BaseSpringTest(org.opentosca.toscana.core.BaseSpringTest)

Aggregations

TargetArtifact (org.opentosca.toscana.core.transformation.artifacts.TargetArtifact)6 File (java.io.File)3 Test (org.junit.Test)2 BaseSpringTest (org.opentosca.toscana.core.BaseSpringTest)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Date (java.util.Date)1 Random (java.util.Random)1 CsarNotFoundException (org.opentosca.toscana.api.exceptions.CsarNotFoundException)1 IllegalTransformationStateException (org.opentosca.toscana.api.exceptions.IllegalTransformationStateException)1 TransformationNotFoundException (org.opentosca.toscana.api.exceptions.TransformationNotFoundException)1 Csar (org.opentosca.toscana.core.csar.Csar)1 Transformation (org.opentosca.toscana.core.transformation.Transformation)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1