use of org.opentosca.toscana.model.operation.Operation in project TOSCAna by StuPro-TOSCAna.
the class DockerfileBuildingVisitor method visit.
@Override
public void visit(MysqlDatabase node) {
builder.env(ENV_KEY_MYSQL_DATABASE, node.getDatabaseName());
if (node.getUser().isPresent() && !node.getUser().get().equals("root")) {
builder.env(ENV_KEY_MYSQL_USER, node.getUser().get());
builder.env(ENV_KEY_MYSQL_PASSWORD, node.getPassword().orElse(""));
if (!node.getPassword().isPresent()) {
builder.env(ENV_KEY_MYSQL_ALLOW_EMPTY_PASSWORD, "true");
}
}
handleDefault(node, new String[] {});
List<Optional<Operation>> lifecycles = new ArrayList<>();
lifecycles.add(node.getStandardLifecycle().getConfigure());
lifecycles.add(node.getStandardLifecycle().getCreate());
if (lifecycles.stream().anyMatch(Optional::isPresent)) {
builder.workdir("/docker-entrypoint-initdb.d");
lifecycles.forEach(e -> {
if (e.isPresent()) {
Operation operation = e.get();
Optional<Artifact> artifact = operation.getArtifact();
if (artifact.isPresent()) {
String path = artifact.get().getFilePath();
if (path.endsWith(".sql")) {
String filename = determineFilename(path);
try {
builder.copyFromCsar(path, "", filename);
} catch (IOException ex) {
logger.error("Copying dependencies of node {} has failed!", node.getEntityName(), ex);
throw new TransformationFailureException("Copying dependencies failed", ex);
}
}
}
}
});
builder.workdir(TOSCANA_ROOT_WORKDIR_PATH);
}
}
use of org.opentosca.toscana.model.operation.Operation in project TOSCAna by StuPro-TOSCAna.
the class GraphNormalizerTest method operationNormalization.
@Test
public void operationNormalization() {
ServiceGraph graph = new ServiceGraph(OPERATION, logMock());
EntityId lifecycleId = ToscaStructure.NODE_TEMPLATES.descend("test-node").descend(RootNode.INTERFACES.name).descend(RootNode.STANDARD_LIFECYCLE.name);
EntityId createId = lifecycleId.descend(StandardLifecycle.CREATE.name);
Entity createEntity = graph.getEntity(createId).get();
Operation create = new TypeWrapper().wrapEntity((MappingEntity) createEntity, Operation.class);
assertTrue(create.getArtifact().isPresent());
Artifact createArtifact = create.getArtifact().get();
assertEquals("test-artifact", createArtifact.getFilePath());
EntityId startId = lifecycleId.descend(StandardLifecycle.START.name);
Entity startEntity = graph.getEntity(startId).get();
Operation start = new TypeWrapper().wrapEntity((MappingEntity) startEntity, Operation.class);
assertTrue(start.getArtifact().isPresent());
Artifact startArtifact = start.getArtifact().get();
assertEquals("test-artifact2", startArtifact.getFilePath());
}
use of org.opentosca.toscana.model.operation.Operation 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.model.operation.Operation in project TOSCAna by StuPro-TOSCAna.
the class LinkResolverTest method resolveImplementationLink.
@Test
public void resolveImplementationLink() {
EffectiveModel model = new EffectiveModelFactory().create(ARTIFACT, logMock());
WebServer node = (WebServer) model.getNodeMap().get("test-node");
Optional<Operation> create = node.getStandardLifecycle().getCreate();
assertTrue(create.isPresent());
Optional<Artifact> artifact = create.get().getArtifact();
assertTrue(artifact.isPresent());
assertEquals("test-file", artifact.get().getFilePath());
}
use of org.opentosca.toscana.model.operation.Operation in project TOSCAna by StuPro-TOSCAna.
the class OperationHandler method handleConfigure.
/**
* Handles a configure operation.
*
* @param node which the operation belongs to
* @param computeHostName alphanumerical name of the Compute host of node
*/
public void handleConfigure(RootNode node, String computeHostName) {
if (node.getStandardLifecycle().getConfigure().isPresent()) {
Operation configure = node.getStandardLifecycle().getConfigure().get();
handleOperation(configure, computeHostName, CONFIG_CONFIGURE);
}
}
Aggregations