Search in sources :

Example 6 with Compute

use of org.opentosca.toscana.model.node.Compute in project TOSCAna by StuPro-TOSCAna.

the class LinkResolverTest method resolveRequirementLink.

@Test
public void resolveRequirementLink() {
    EffectiveModel model = new EffectiveModelFactory().create(REQUIREMENT, logMock());
    WebServer node = (WebServer) model.getNodeMap().get("test-node1");
    HostRequirement requirement = node.getHost();
    assertNotNull(requirement);
    Set<Compute> fulfillers = requirement.getFulfillers();
    assertEquals(1, fulfillers.size());
    Compute fulfiller = fulfillers.iterator().next();
    assertEquals("test-node2", fulfiller.getEntityName());
}
Also used : WebServer(org.opentosca.toscana.model.node.WebServer) HostRequirement(org.opentosca.toscana.model.requirement.HostRequirement) Compute(org.opentosca.toscana.model.node.Compute) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 7 with Compute

use of org.opentosca.toscana.model.node.Compute in project TOSCAna by StuPro-TOSCAna.

the class ScalableCapabilityTest method scalableTest.

@Test
public void scalableTest() {
    EffectiveModel model = new EffectiveModelFactory().create(TestTemplates.Capabilities.SCALABLE, logMock());
    Compute compute = (Compute) model.getNodes().iterator().next();
    ScalableCapability scalable = compute.getScalable();
    assertEquals(5, (int) scalable.getMinInstances());
    assertEquals(7, (int) scalable.getDefaultInstances().get());
    assertEquals(Integer.MAX_VALUE, (int) scalable.getMaxInstances());
}
Also used : ScalableCapability(org.opentosca.toscana.model.capability.ScalableCapability) Compute(org.opentosca.toscana.model.node.Compute) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 8 with Compute

use of org.opentosca.toscana.model.node.Compute in project TOSCAna by StuPro-TOSCAna.

the class Pod method getPods.

/**
 *     @param stacks The List of NodeStacks to group in Pods
 *     @return a List Containing the given NodeStacks grouped in Pods
 */
public static List<Pod> getPods(Collection<NodeStack> stacks) {
    // Group Node Stacks
    Map<Compute, List<NodeStack>> stackMap = new HashMap<>();
    for (NodeStack stack : stacks) {
        Compute computeNode = stack.getComputeNode();
        stackMap.computeIfAbsent(computeNode, k -> new ArrayList<>());
        stackMap.get(computeNode).add(stack);
    }
    // Convert NodeStacks to Pods
    List<Pod> pods = new ArrayList<>();
    stackMap.forEach((k, v) -> pods.add(new Pod(v, k)));
    return pods;
}
Also used : HashMap(java.util.HashMap) Compute(org.opentosca.toscana.model.node.Compute) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) NodeStack(org.opentosca.toscana.plugins.kubernetes.util.NodeStack)

Example 9 with Compute

use of org.opentosca.toscana.model.node.Compute in project TOSCAna by StuPro-TOSCAna.

the class CloudFormationVisitorExtension method getHostsOfConnectedTo.

protected Set<Compute> getHostsOfConnectedTo(RootNode node) {
    Set<Compute> connected = new HashSet<>();
    Set<RootRelationship> incomingEdges = topology.incomingEdgesOf(node);
    for (RootRelationship incomingEdge : incomingEdges) {
        RootNode source = topology.getEdgeSource(incomingEdge);
        if (source instanceof WebApplication) {
            WebApplication webApplication = (WebApplication) source;
            Compute compute = getCompute(webApplication);
            connected.add(compute);
        }
    }
    return connected;
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) Compute(org.opentosca.toscana.model.node.Compute) WebApplication(org.opentosca.toscana.model.node.WebApplication) HashSet(java.util.HashSet) RootRelationship(org.opentosca.toscana.model.relation.RootRelationship)

Example 10 with Compute

use of org.opentosca.toscana.model.node.Compute in project TOSCAna by StuPro-TOSCAna.

the class PrepareModelNodeVisitor method visit.

@Override
public void visit(MysqlDatabase node) {
    // if certain values aren't given, fill them
    if (node.getPassword().isPresent()) {
        // password needs to be at least 8 characters long
        String password = node.getPassword().get();
        if (password.length() < minPWLength) {
            logger.warn("Database password too short, creating new random password");
            node.setPassword(randomString(minPWLength));
        }
    } else {
        logger.warn("No database password given, creating new random password");
        node.setPassword(randomString(minPWLength));
    }
    if (!node.getUser().isPresent()) {
        logger.warn("User not set, setting to default");
        node.setUser(DEFAULT_DB_USER);
    }
    if (!node.getPort().isPresent()) {
        logger.warn("Database port not set, setting to default");
        node.setPort(DEFAULT_DB_PORT);
    }
    // check if Mysql is the only node hosted on his compute node
    Compute compute = getCompute(node);
    if (topology.incomingEdgesOf(compute).stream().filter(relation -> relation instanceof HostedOn).collect(Collectors.toSet()).size() == 1) {
        // means our dbms is the only one hosted on this compute
        // means we can set the private address as reference the database endpoint
        Fn databaseEndpointFn = Fn.fnGetAtt(toAlphanumerical(node.getEntityName()), AWS_ENDPOINT_REFERENCE);
        String databaseEndpoint = databaseEndpointFn.toString(true);
        cfnModule.putFn(databaseEndpoint, databaseEndpointFn);
        compute.setPrivateAddress(databaseEndpoint);
        compute.setPublicAddress(databaseEndpoint);
        logger.debug("Set private address and public address of '{}' to reference MysqlDatabase '{}'", compute.getEntityName(), node.getEntityName());
        // also the underlying compute should not get mapped to an ec2
        cfnModule.removeComputeToEc2(compute);
        logger.debug("Removing Compute '{}' to be transformed", compute.getEntityName());
    }
}
Also used : Compute(org.opentosca.toscana.model.node.Compute) HostedOn(org.opentosca.toscana.model.relation.HostedOn) NodeVisitor(org.opentosca.toscana.model.visitor.NodeVisitor) Collectors(java.util.stream.Collectors) SecureRandom(java.security.SecureRandom) Port(org.opentosca.toscana.model.datatype.Port) Fn(com.scaleset.cfbuilder.core.Fn) MysqlDatabase(org.opentosca.toscana.model.node.MysqlDatabase) CloudFormationLifecycle.toAlphanumerical(org.opentosca.toscana.plugins.cloudformation.CloudFormationLifecycle.toAlphanumerical) TransformationContext(org.opentosca.toscana.core.transformation.TransformationContext) WebApplication(org.opentosca.toscana.model.node.WebApplication) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) CloudFormationModule(org.opentosca.toscana.plugins.cloudformation.CloudFormationModule) HostedOn(org.opentosca.toscana.model.relation.HostedOn) Compute(org.opentosca.toscana.model.node.Compute) Fn(com.scaleset.cfbuilder.core.Fn)

Aggregations

Compute (org.opentosca.toscana.model.node.Compute)15 SdkClientException (com.amazonaws.SdkClientException)8 TransformationFailureException (org.opentosca.toscana.plugins.util.TransformationFailureException)8 SecurityGroup (com.scaleset.cfbuilder.ec2.SecurityGroup)6 RootNode (org.opentosca.toscana.model.node.RootNode)4 WebApplication (org.opentosca.toscana.model.node.WebApplication)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)3 MysqlDatabase (org.opentosca.toscana.model.node.MysqlDatabase)3 Fn (com.scaleset.cfbuilder.core.Fn)2 CFNCommand (com.scaleset.cfbuilder.ec2.metadata.CFNCommand)2 CFNPackage (com.scaleset.cfbuilder.ec2.metadata.CFNPackage)2 List (java.util.List)2 TransformationContext (org.opentosca.toscana.core.transformation.TransformationContext)2 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)2 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)2 Artifact (org.opentosca.toscana.model.artifact.Artifact)2 ComputeCapability (org.opentosca.toscana.model.capability.ComputeCapability)2 EndpointCapability (org.opentosca.toscana.model.capability.EndpointCapability)2