Search in sources :

Example 6 with TransformationFailureException

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

the class BuildpackDetector method detectBuildpackAdditions.

/**
 *     checks the application suffix e.g. .php and add defined buildpacks
 *     currently only php is supported
 */
public void detectBuildpackAdditions() {
    if (applicationSuffix != null) {
        logger.info("Application suffix is: " + applicationSuffix);
        if (applicationSuffix.equalsIgnoreCase("php")) {
            try {
                logger.debug("Add PHP buildpacks");
                addBuildpackAdditonsPHP();
            } catch (JSONException | IOException e) {
                throw new TransformationFailureException("Fail to add buildpacks", e);
            }
        // TODO: expand with more languages
        }
    }
}
Also used : TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 7 with TransformationFailureException

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

the class NodeVisitor method visit.

/**
 *     a MysqlDatabase is a service in CloudFoundry
 *     Therefore the service will be added to the application where the source of the connects to relationship is
 */
@Override
public void visit(MysqlDatabase node) {
    /*
        create service
        ignore password and port
         */
    logger.debug("Visit Mysql Database");
    Set<RootNode> sourceNodes = getSourcesOfConnectsTo(node);
    Set<Application> belongingApplication = getSourceApplications(sourceNodes);
    if (CollectionUtils.isEmpty(belongingApplication)) {
        logger.error("No source node of connects to relationship of MysqlDatabase {} was found", node.getEntityName());
        throw new TransformationFailureException("Could not find source of database");
    }
    handleStandardLifecycle(node, false, myApp);
    logger.debug("Add MYSQL service to application");
    belongingApplication.forEach(app -> app.addService(node.getEntityName(), ServiceTypes.MYSQL));
    // current application is a dummy application
    myApp.applicationIsNotReal(belongingApplication);
    // check artifacts and add paths to application
    for (Artifact artifact : node.getArtifacts()) {
        String path = artifact.getFilePath();
        myApp.addFilePath(path);
        logger.debug("Add artifact path {} to application", path);
        if (path.endsWith("sql")) {
            myApp.addConfigMysql(node.getEntityName(), path);
            logger.info("Found a SQL script in artifact paths. Will execute it with python script in deployment phase");
        }
    }
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application) WebApplication(org.opentosca.toscana.model.node.WebApplication) JavaApplication(org.opentosca.toscana.model.node.custom.JavaApplication) Artifact(org.opentosca.toscana.model.artifact.Artifact)

Example 8 with TransformationFailureException

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

the class CloudFormationPluginTest method testLamp.

@Test(expected = TransformationFailureException.class)
public void testLamp() {
    try {
        Set<RootNode> nodes = lamp.getNodes();
        // visit compute nodes first
        for (VisitableNode node : nodes) {
            if (node instanceof Compute) {
                node.accept(cfnNodeVisitor);
            }
        }
        for (VisitableNode node : nodes) {
            if (!(node instanceof Compute)) {
                node.accept(cfnNodeVisitor);
            }
        }
        System.err.println(cfnModule.toString());
    } catch (TransformationFailureException tfe) {
        // provided so this test can pass
        if (!(tfe.getCause() instanceof SdkClientException)) {
            throw tfe;
        }
        logger.debug("Passed without internet connection / credentials provided");
    }
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) VisitableNode(org.opentosca.toscana.model.visitor.VisitableNode) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) SdkClientException(com.amazonaws.SdkClientException) Compute(org.opentosca.toscana.model.node.Compute) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 9 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(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);
    }
}
Also used : Optional(java.util.Optional) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) ArrayList(java.util.ArrayList) Operation(org.opentosca.toscana.model.operation.Operation) IOException(java.io.IOException) Artifact(org.opentosca.toscana.model.artifact.Artifact)

Example 10 with TransformationFailureException

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

the class ImageMappingVisitor method visit.

@Override
public void visit(DockerApplication node) {
    this.requiresBuilding = false;
    this.baseImage = node.getStandardLifecycle().getCreate().orElseThrow(() -> new TransformationFailureException(NO_CREATE_ERROR_MESSAGE)).getArtifact().orElseThrow(() -> new TransformationFailureException(String.format(NO_IMAGE_PATH_ERROR_MESSAGE, node.getEntityName()))).getFilePath();
    if (this.baseImage == null) {
        throw new TransformationFailureException(String.format(NO_IMAGE_PATH_ERROR_MESSAGE, node.getEntityName()));
    }
// TODO implement check if the docker application has children.
}
Also used : TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException)

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