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