Search in sources :

Example 6 with Artifact

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

the class GraphNormalizerTest method artifactNormalization.

@Test
public void artifactNormalization() {
    ServiceGraph graph = new ServiceGraph(ARTIFACT, logMock());
    EntityId nodeId = ToscaStructure.NODE_TEMPLATES.descend("test-node");
    Entity nodeEntity = graph.getEntityOrThrow(nodeId);
    WebApplication webApplication = new TypeWrapper().wrapEntity((MappingEntity) nodeEntity, WebApplication.class);
    Artifact artifact = webApplication.getArtifacts().iterator().next();
    assertEquals("test-artifact", artifact.getEntityName());
    assertEquals("test-artifact-file", artifact.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) WebApplication(org.opentosca.toscana.model.node.WebApplication) Artifact(org.opentosca.toscana.model.artifact.Artifact) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 7 with Artifact

use of org.opentosca.toscana.model.artifact.Artifact 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());
}
Also used : WebServer(org.opentosca.toscana.model.node.WebServer) Operation(org.opentosca.toscana.model.operation.Operation) 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)

Example 8 with Artifact

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

the class NodeConvertTest method java.

@Test
public void java() {
    EffectiveModel model = new EffectiveModelFactory().create(JAVA, logMock());
    JavaApplication app = (JavaApplication) model.getNodeMap().get("app");
    assertEquals("test-vm_options", app.getVmOptions().get());
    assertEquals("test-arguments", app.getArguments().get());
    Artifact artifact = app.getJar();
    assertEquals("test-artifact-path", artifact.getFilePath());
    JavaRuntime jre = (JavaRuntime) model.getNodeMap().get("jre");
    assertEquals("1.8", jre.getComponentVersion().get());
}
Also used : JavaRuntime(org.opentosca.toscana.model.node.custom.JavaRuntime) JavaApplication(org.opentosca.toscana.model.node.custom.JavaApplication) 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)

Example 9 with Artifact

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

the class TransformModelNodeVisitor method visit.

@Override
public void visit(MysqlDatabase node) {
    try {
        String nodeName = toAlphanumerical(node.getEntityName());
        // get the compute where the dbms this node is hosted on, is hosted on
        Compute compute = getCompute(node);
        String serverName = toAlphanumerical(compute.getEntityName());
        String dbName = node.getDatabaseName();
        String masterUser = node.getUser().orElseThrow(() -> new IllegalArgumentException("Database user not set"));
        String masterPassword = node.getPassword().orElseThrow(() -> new IllegalArgumentException("Database " + "password not set"));
        Integer port = node.getPort().orElseThrow(() -> new IllegalArgumentException("Database port not set"));
        // check what values should be taken
        ComputeCapability hostedOnComputeCapability = compute.getHost();
        CapabilityMapper capabilityMapper = createCapabilityMapper();
        String dBInstanceClass = capabilityMapper.mapComputeCapabilityToInstanceType(hostedOnComputeCapability, CapabilityMapper.RDS_DISTINCTION);
        Integer allocatedStorage = capabilityMapper.mapComputeCapabilityToRDSAllocatedStorage(hostedOnComputeCapability);
        // SSD
        String storageType = "gp2";
        String securityGroupName = nodeName + SECURITY_GROUP;
        SecurityGroup securityGroup = cfnModule.resource(SecurityGroup.class, securityGroupName).groupDescription("Open database " + dbName + " for access to group " + serverName + SECURITY_GROUP);
        Set<Compute> hostsOfConnectedTo = getHostsOfConnectedTo(node);
        for (Compute hostOfConnectedTo : hostsOfConnectedTo) {
            securityGroup.ingress(ingress -> ingress.sourceSecurityGroupName(cfnModule.ref(toAlphanumerical(hostOfConnectedTo.getEntityName()) + SECURITY_GROUP)), PROTOCOL_TCP, port);
        }
        cfnModule.resource(DBInstance.class, nodeName).engine("MySQL").dBName(dbName).masterUsername(masterUser).masterUserPassword(masterPassword).dBInstanceClass(dBInstanceClass).allocatedStorage(allocatedStorage).storageType(storageType).vPCSecurityGroups(cfnModule.fnGetAtt(securityGroupName, "GroupId"));
        // handle sql artifact
        for (Artifact artifact : node.getArtifacts()) {
            String relPath = artifact.getFilePath();
            if (relPath.endsWith(".sql")) {
                String sql = cfnModule.getFileAccess().read(artifact.getFilePath());
                String computeName = createSqlCompute(node, sql);
                securityGroup.ingress(ingress -> ingress.sourceSecurityGroupName(cfnModule.ref(toAlphanumerical(computeName) + SECURITY_GROUP)), PROTOCOL_TCP, port);
            }
        }
    } catch (Exception e) {
        logger.error("Error while creating MysqlDatabase resource.");
        throw new TransformationFailureException("Failed at MysqlDatabase node " + node.getEntityName(), e);
    }
}
Also used : TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) Compute(org.opentosca.toscana.model.node.Compute) SecurityGroup(com.scaleset.cfbuilder.ec2.SecurityGroup) CapabilityMapper(org.opentosca.toscana.plugins.cloudformation.mapper.CapabilityMapper) Artifact(org.opentosca.toscana.model.artifact.Artifact) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) SdkClientException(com.amazonaws.SdkClientException) ComputeCapability(org.opentosca.toscana.model.capability.ComputeCapability)

Example 10 with Artifact

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

the class NodeVisitor method getScripts.

private void getScripts(RootNode node, Application application) {
    StandardLifecycle lifecycle = node.getStandardLifecycle();
    Optional<Operation> configureOptional = lifecycle.getConfigure();
    // get configure script
    if (configureOptional.isPresent()) {
        Optional<Artifact> configureArtifact = configureOptional.get().getArtifact();
        configureArtifact.ifPresent(artifact -> application.addExecuteFile(artifact.getFilePath(), node));
    }
    // get create script
    Optional<Operation> createOptional = lifecycle.getCreate();
    if (createOptional.isPresent()) {
        Optional<Artifact> createArtifact = createOptional.get().getArtifact();
        createArtifact.ifPresent(artifact -> application.addExecuteFile(artifact.getFilePath(), node));
    }
}
Also used : StandardLifecycle(org.opentosca.toscana.model.operation.StandardLifecycle) Operation(org.opentosca.toscana.model.operation.Operation) Artifact(org.opentosca.toscana.model.artifact.Artifact)

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