Search in sources :

Example 11 with TransformationFailureException

use of org.opentosca.toscana.plugins.util.TransformationFailureException in project TOSCAna by StuPro-TOSCAna.

the class TransformHandler method createDockerfiles.

/**
 *     Creates the Dockerfiles (that means the dockerfile and all its dependesies get written to disk)
 */
private void createDockerfiles() {
    ConnectionGraph connectionGraph = new ConnectionGraph(lifecycle.stacks);
    lifecycle.stacks.forEach(e -> {
        logger.info("Creating Dockerfile for {}", e);
        try {
            e.buildToDockerfile(connectionGraph, lifecycle.getContext(), baseImageMapper);
        } catch (IOException ex) {
            ex.printStackTrace();
            throw new TransformationFailureException("Transformation Failed", ex);
        }
    });
}
Also used : TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) IOException(java.io.IOException) ConnectionGraph(org.opentosca.toscana.plugins.kubernetes.model.transform.ConnectionGraph)

Example 12 with TransformationFailureException

use of org.opentosca.toscana.plugins.util.TransformationFailureException in project TOSCAna by StuPro-TOSCAna.

the class TransformHandler method buildDockerImages.

/**
 *     Builds all Dockerimages of the stack and exports the images as a tar archive.
 */
private void buildDockerImages() {
    instantiateImageBuilders();
    logger.info("Building Docker images");
    imageBuilders.forEach((stack, builder) -> {
        logger.info("Building {}", stack);
        try {
            builder.buildImage();
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new TransformationFailureException("Transformation Failed, while building a docker image for " + stack, ex);
        }
    });
    storeDockerImages();
}
Also used : TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException)

Example 13 with TransformationFailureException

use of org.opentosca.toscana.plugins.util.TransformationFailureException in project TOSCAna by StuPro-TOSCAna.

the class TransformHandler method storeDockerImages.

private void storeDockerImages() {
    logger.info("Storing Docker images");
    imageBuilders.forEach((stack, builder) -> {
        logger.info("Storing {}", stack);
        try {
            builder.storeImage();
            stack.setDockerImageTag(builder.getTag());
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new TransformationFailureException("Transformation Failed, while storing a docker image for " + stack, ex);
        }
    });
}
Also used : TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException)

Example 14 with TransformationFailureException

use of org.opentosca.toscana.plugins.util.TransformationFailureException in project TOSCAna by StuPro-TOSCAna.

the class DockerfileBuildingVisitor method copyArtifactsOfLifecycleOperation.

/**
 *     This method copies the the artifact of the lifecycle operation into the Dockerfile working directory (including its dependencies)
 *     <p>
 *     It will also write the Run and Copy commands into the Dockerfile
 *     <p>
 *     Properties of the Operations will get mapped as Environment variables (ENV command)
 */
private void copyArtifactsOfLifecycleOperation(String nodeName, String opName, Optional<Operation> optionalOperation, String[] ignoredLifecycles, boolean isStartup) throws IOException {
    // Skip ignored lifecycles
    if (Arrays.asList(ignoredLifecycles).contains(opName)) {
        return;
    }
    // Add the artifacts if they are present
    if (optionalOperation.isPresent()) {
        // Set the properties as environment variables
        optionalOperation.get().getInputs().forEach(e -> {
            if (e.getValue().isPresent()) {
                logger.info("Adding Environment Variable {}:{}", e.getKey(), e.getValue().get());
                builder.env(e.getKey(), e.getValue().get());
            }
        });
        logger.debug("{} - {} is present", nodeName, opName);
        Operation operation = optionalOperation.get();
        // Copy all Dependencies
        for (String e : operation.getDependencies()) {
            String filename = determineFilename(e);
            builder.copyFromCsar(e, nodeName, filename);
        }
        if (operation.getArtifact().isPresent()) {
            String path = operation.getArtifact().get().getFilePath();
            // Ignore SQL files since their handled elsewhere (for MySQL)
            if (path.endsWith(".sql")) {
                return;
            }
            // this is the case if a script contains "sudo "
            if (needsSudo(path) && !sudoInstalled) {
                // Install sudo, currently only works with Debian based systems
                Optional<String> sudocmd = SudoUtils.getSudoInstallCommand(this.baseImage);
                if (sudocmd.isPresent()) {
                    builder.run(sudocmd.get());
                    sudoInstalled = true;
                } else {
                    throw new TransformationFailureException("Cannot determine Sudo install command for base image '" + this.baseImage + "'");
                }
            }
            builder.copyFromCsar(path, nodeName, nodeName + "-" + opName);
            String command = "sh " + nodeName + "-" + opName;
            // the building procedure
            if (!isStartup) {
                builder.run(command);
            } else {
                startCommands.add(command);
            }
        }
    }
}
Also used : TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) Operation(org.opentosca.toscana.model.operation.Operation)

Example 15 with TransformationFailureException

use of org.opentosca.toscana.plugins.util.TransformationFailureException in project TOSCAna by StuPro-TOSCAna.

the class DockerfileBuildingVisitor method visit.

@Override
public void visit(JavaApplication node) {
    handleDefault(node, new String[] {});
    // Copy over jar and add command to entrypoint
    String jarPath = node.getJar().getFilePath();
    try {
        builder.copyFromCsar(jarPath, "", node.getEntityName() + ".jar");
    } catch (IOException e) {
        throw new TransformationFailureException(String.format("Copying jar artifact for node '%s' failed!", node.getEntityName()), e);
    }
    startCommands.add(String.format("java %s -jar %s.jar %s", node.getVmOptions().orElse(""), node.getEntityName(), node.getArguments().orElse("")));
}
Also used : TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) IOException(java.io.IOException)

Aggregations

TransformationFailureException (org.opentosca.toscana.plugins.util.TransformationFailureException)22 IOException (java.io.IOException)10 SdkClientException (com.amazonaws.SdkClientException)8 Compute (org.opentosca.toscana.model.node.Compute)8 SecurityGroup (com.scaleset.cfbuilder.ec2.SecurityGroup)6 Artifact (org.opentosca.toscana.model.artifact.Artifact)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ArrayList (java.util.ArrayList)3 JSONException (org.json.JSONException)3 RootNode (org.opentosca.toscana.model.node.RootNode)3 CFNCommand (com.scaleset.cfbuilder.ec2.metadata.CFNCommand)2 CFNPackage (com.scaleset.cfbuilder.ec2.metadata.CFNPackage)2 ComputeCapability (org.opentosca.toscana.model.capability.ComputeCapability)2 EndpointCapability (org.opentosca.toscana.model.capability.EndpointCapability)2 WebApplication (org.opentosca.toscana.model.node.WebApplication)2 Operation (org.opentosca.toscana.model.operation.Operation)2 Instance (com.scaleset.cfbuilder.ec2.Instance)1 CFNInit (com.scaleset.cfbuilder.ec2.metadata.CFNInit)1 DBInstance (com.scaleset.cfbuilder.rds.DBInstance)1 FileNotFoundException (java.io.FileNotFoundException)1