Search in sources :

Example 1 with Artifact

use of org.opentosca.toscana.model.artifact.Artifact 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 2 with Artifact

use of org.opentosca.toscana.model.artifact.Artifact in project TOSCAna by StuPro-TOSCAna.

the class LinkResolver method resolveRepositories.

private static void resolveRepositories(ServiceGraph graph) {
    logger.debug(LogFormat.indent(1, "repositories"));
    Map<String, RootNode> nodes = new TypeWrapper().wrapNodes(graph);
    for (RootNode node : nodes.values()) {
        for (Artifact artifact : node.getArtifacts()) {
            MappingEntity artifactEntity = artifact.getBackingEntity();
            Optional<Entity> repository = artifactEntity.getChild(Artifact.REPOSITORY.name);
            if (repository.isPresent()) {
                String url = ((ScalarEntity) repository.get()).getValue();
                EntityId targetId = ToscaStructure.REPOSITORIES.descend(url);
                Optional<Entity> target = graph.getEntity(targetId);
                target.ifPresent(baseEntity -> {
                    logger.debug(LogFormat.pointAt(2, repository.get().getId(), baseEntity.getId()));
                    graph.replaceEntity(repository.get(), baseEntity);
                });
            }
        }
    }
}
Also used : EntityId(org.opentosca.toscana.model.EntityId) RootNode(org.opentosca.toscana.model.node.RootNode) ScalarEntity(org.opentosca.toscana.core.parse.model.ScalarEntity) Entity(org.opentosca.toscana.core.parse.model.Entity) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity) ScalarEntity(org.opentosca.toscana.core.parse.model.ScalarEntity) Artifact(org.opentosca.toscana.model.artifact.Artifact) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity)

Example 3 with Artifact

use of org.opentosca.toscana.model.artifact.Artifact 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 4 with Artifact

use of org.opentosca.toscana.model.artifact.Artifact 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());
}
Also used : EntityId(org.opentosca.toscana.model.EntityId) ScalarEntity(org.opentosca.toscana.core.parse.model.ScalarEntity) Entity(org.opentosca.toscana.core.parse.model.Entity) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity) ServiceGraph(org.opentosca.toscana.core.parse.model.ServiceGraph) Operation(org.opentosca.toscana.model.operation.Operation) Artifact(org.opentosca.toscana.model.artifact.Artifact) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 5 with Artifact

use of org.opentosca.toscana.model.artifact.Artifact in project TOSCAna by StuPro-TOSCAna.

the class LinkResolverTest method resolveRepositoryLink.

@Test
public void resolveRepositoryLink() {
    EffectiveModel model = new EffectiveModelFactory().create(REPOSITORY, logMock());
    WebServer node = (WebServer) model.getNodeMap().get("test-node");
    Set<Artifact> artifacts = node.getArtifacts();
    Artifact artifact = artifacts.iterator().next();
    assertNotNull(artifact);
    Optional<Repository> repo = artifact.getRepository();
    assertTrue(repo.isPresent());
    assertEquals("http://test.repo.com/", repo.get().getUrl());
}
Also used : Repository(org.opentosca.toscana.model.artifact.Repository) WebServer(org.opentosca.toscana.model.node.WebServer) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) Artifact(org.opentosca.toscana.model.artifact.Artifact) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Aggregations

Artifact (org.opentosca.toscana.model.artifact.Artifact)11 Test (org.junit.Test)5 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)5 Operation (org.opentosca.toscana.model.operation.Operation)5 Entity (org.opentosca.toscana.core.parse.model.Entity)3 MappingEntity (org.opentosca.toscana.core.parse.model.MappingEntity)3 ScalarEntity (org.opentosca.toscana.core.parse.model.ScalarEntity)3 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)3 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)3 EntityId (org.opentosca.toscana.model.EntityId)3 RootNode (org.opentosca.toscana.model.node.RootNode)3 TransformationFailureException (org.opentosca.toscana.plugins.util.TransformationFailureException)3 ServiceGraph (org.opentosca.toscana.core.parse.model.ServiceGraph)2 WebApplication (org.opentosca.toscana.model.node.WebApplication)2 WebServer (org.opentosca.toscana.model.node.WebServer)2 JavaApplication (org.opentosca.toscana.model.node.custom.JavaApplication)2 SdkClientException (com.amazonaws.SdkClientException)1 SecurityGroup (com.scaleset.cfbuilder.ec2.SecurityGroup)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1