Search in sources :

Example 1 with OsCapability

use of org.opentosca.toscana.model.capability.OsCapability in project TOSCAna by StuPro-TOSCAna.

the class TransformModelNodeVisitor method visit.

@Override
public void visit(Compute node) {
    try {
        if (cfnModule.checkComputeToEc2(node)) {
            logger.debug("Compute '{}' will be transformed to EC2", node.getEntityName());
            String nodeName = toAlphanumerical(node.getEntityName());
            // default security group the EC2 Instance
            SecurityGroup webServerSecurityGroup = cfnModule.resource(SecurityGroup.class, nodeName + SECURITY_GROUP).groupDescription("Enables ports for " + nodeName + ".");
            // open endpoint port
            node.getEndpoint().getPort().ifPresent(port -> webServerSecurityGroup.ingress(ingress -> ingress.cidrIp(IP_OPEN), PROTOCOL_TCP, port.port));
            // check what image id should be taken
            CapabilityMapper capabilityMapper = createCapabilityMapper();
            OsCapability computeOs = node.getOs();
            String imageId = capabilityMapper.mapOsCapabilityToImageId(computeOs);
            ComputeCapability computeCompute = node.getHost();
            String instanceType = capabilityMapper.mapComputeCapabilityToInstanceType(computeCompute, CapabilityMapper.EC2_DISTINCTION);
            // create CFN init and store it
            CFNInit init = new CFNInit(CONFIG_SETS);
            cfnModule.putCFNInit(nodeName, init);
            cfnModule.resource(Instance.class, nodeName).securityGroupIds(webServerSecurityGroup).imageId(imageId).instanceType(instanceType);
            capabilityMapper.mapDiskSize(computeCompute, cfnModule, nodeName);
            // Add Reference to keyName if KeyPair needed and open Port 22 (Allows SSH access)
            if (cfnModule.hasKeyPair()) {
                Instance instance = (Instance) cfnModule.getResource(nodeName);
                instance.keyName(cfnModule.getKeyNameVar());
                webServerSecurityGroup.ingress(ingress -> ingress.cidrIp(IP_OPEN), PROTOCOL_TCP, 22);
            }
        } else {
            logger.debug("Compute '{}' will not be transformed to EC2", node.getEntityName());
        }
    } catch (SdkClientException se) {
        logger.error("SDKClient failed, no valid credentials or no internet connection");
        throw new TransformationFailureException("Failed", se);
    } catch (Exception e) {
        logger.error("Error while creating EC2Instance resource.");
        throw new TransformationFailureException("Failed at Compute node " + node.getEntityName(), e);
    }
}
Also used : Apache(org.opentosca.toscana.model.node.Apache) EndpointCapability(org.opentosca.toscana.model.capability.EndpointCapability) CFNInit(com.scaleset.cfbuilder.ec2.metadata.CFNInit) CONFIG_CONFIGURE(org.opentosca.toscana.plugins.cloudformation.CloudFormationModule.CONFIG_CONFIGURE) CapabilityMapper(org.opentosca.toscana.plugins.cloudformation.mapper.CapabilityMapper) SECURITY_GROUP(org.opentosca.toscana.plugins.cloudformation.CloudFormationModule.SECURITY_GROUP) ArrayList(java.util.ArrayList) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) CFNPackage(com.scaleset.cfbuilder.ec2.metadata.CFNPackage) MysqlDatabase(org.opentosca.toscana.model.node.MysqlDatabase) CFNCommand(com.scaleset.cfbuilder.ec2.metadata.CFNCommand) CONFIG_CREATE(org.opentosca.toscana.plugins.cloudformation.CloudFormationModule.CONFIG_CREATE) CONFIG_SETS(org.opentosca.toscana.plugins.cloudformation.CloudFormationModule.CONFIG_SETS) MysqlDbms(org.opentosca.toscana.model.node.MysqlDbms) APACHE_RESTART_COMMAND(org.opentosca.toscana.plugins.cloudformation.handler.OperationHandler.APACHE_RESTART_COMMAND) WebApplication(org.opentosca.toscana.model.node.WebApplication) FILEPATH_NODEJS_CREATE(org.opentosca.toscana.plugins.cloudformation.CloudFormationModule.FILEPATH_NODEJS_CREATE) APACHE_ENV_IMPORT(org.opentosca.toscana.plugins.cloudformation.handler.EnvironmentHandler.APACHE_ENV_IMPORT) Artifact(org.opentosca.toscana.model.artifact.Artifact) Compute(org.opentosca.toscana.model.node.Compute) ComputeCapability(org.opentosca.toscana.model.capability.ComputeCapability) Database(org.opentosca.toscana.model.node.Database) OperationHandler(org.opentosca.toscana.plugins.cloudformation.handler.OperationHandler) SecurityGroup(com.scaleset.cfbuilder.ec2.SecurityGroup) Dbms(org.opentosca.toscana.model.node.Dbms) Nodejs(org.opentosca.toscana.model.node.Nodejs) Instance(com.scaleset.cfbuilder.ec2.Instance) Set(java.util.Set) OsCapability(org.opentosca.toscana.model.capability.OsCapability) StrictNodeVisitor(org.opentosca.toscana.model.visitor.StrictNodeVisitor) List(java.util.List) SdkClientException(com.amazonaws.SdkClientException) CloudFormationLifecycle.toAlphanumerical(org.opentosca.toscana.plugins.cloudformation.CloudFormationLifecycle.toAlphanumerical) TransformationContext(org.opentosca.toscana.core.transformation.TransformationContext) DBInstance(com.scaleset.cfbuilder.rds.DBInstance) CONFIG_START(org.opentosca.toscana.plugins.cloudformation.CloudFormationModule.CONFIG_START) CloudFormationModule(org.opentosca.toscana.plugins.cloudformation.CloudFormationModule) SdkClientException(com.amazonaws.SdkClientException) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) Instance(com.scaleset.cfbuilder.ec2.Instance) DBInstance(com.scaleset.cfbuilder.rds.DBInstance) OsCapability(org.opentosca.toscana.model.capability.OsCapability) CFNInit(com.scaleset.cfbuilder.ec2.metadata.CFNInit) SecurityGroup(com.scaleset.cfbuilder.ec2.SecurityGroup) CapabilityMapper(org.opentosca.toscana.plugins.cloudformation.mapper.CapabilityMapper) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) SdkClientException(com.amazonaws.SdkClientException) ComputeCapability(org.opentosca.toscana.model.capability.ComputeCapability)

Example 2 with OsCapability

use of org.opentosca.toscana.model.capability.OsCapability in project TOSCAna by StuPro-TOSCAna.

the class EffectiveModelSetterTest method setEnumTest.

@Test
public void setEnumTest() {
    OsCapability os = compute.getOs();
    OsCapability.Distribution expected = OsCapability.Distribution.FEDORA;
    os.setDistribution(expected);
    Optional<OsCapability.Distribution> result = os.getDistribution();
    assertTrue(result.isPresent());
    assertEquals(expected, result.get());
}
Also used : OsCapability(org.opentosca.toscana.model.capability.OsCapability) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 3 with OsCapability

use of org.opentosca.toscana.model.capability.OsCapability in project TOSCAna by StuPro-TOSCAna.

the class CheckModelNodeVisitor method visit.

@Override
public void visit(Compute node) {
    List<OsCapability.Type> supportedTypes = Lists.newArrayList(OsCapability.Type.LINUX);
    // might grow but for now only linux
    List<OsCapability.Distribution> supportedDistributions = Lists.newArrayList(OsCapability.Distribution.UBUNTU);
    // might grow, but for now only ubuntu, maybe already work with others but not yet tested
    OsCapability osCapability = node.getOs();
    // check type
    if (osCapability.getType().isPresent()) {
        OsCapability.Type type = osCapability.getType().get();
        if (!supportedTypes.contains(type)) {
            throw new UnsupportedTypeException("OS Type " + type + " not supported.");
        }
    }
    // check distribution
    if (osCapability.getDistribution().isPresent()) {
        OsCapability.Distribution distribution = osCapability.getDistribution().get();
        if (!supportedDistributions.contains(distribution)) {
            throw new UnsupportedTypeException("OS distribution " + distribution + " not supported.");
        }
    }
}
Also used : OsCapability(org.opentosca.toscana.model.capability.OsCapability) UnsupportedTypeException(org.opentosca.toscana.model.visitor.UnsupportedTypeException)

Example 4 with OsCapability

use of org.opentosca.toscana.model.capability.OsCapability in project TOSCAna by StuPro-TOSCAna.

the class Compute method init.

private void init() {
    setDefault(HOST, new ContainerCapability(getChildEntity(HOST)));
    setDefault(OS, new OsCapability(getChildEntity(OS)));
    setDefault(ENDPOINT, new AdminEndpointCapability(getChildEntity(ENDPOINT)));
    setDefault(SCALABLE, new ScalableCapability(getChildEntity(SCALABLE)));
    setDefault(BINDING, new BindableCapability(getChildEntity(BINDING)));
    setDefault(LOCAL_STORAGE, new BlockStorageRequirement(getChildEntity(LOCAL_STORAGE)));
}
Also used : ScalableCapability(org.opentosca.toscana.model.capability.ScalableCapability) AdminEndpointCapability(org.opentosca.toscana.model.capability.AdminEndpointCapability) BlockStorageRequirement(org.opentosca.toscana.model.requirement.BlockStorageRequirement) OsCapability(org.opentosca.toscana.model.capability.OsCapability) ContainerCapability(org.opentosca.toscana.model.capability.ContainerCapability) BindableCapability(org.opentosca.toscana.model.capability.BindableCapability)

Aggregations

OsCapability (org.opentosca.toscana.model.capability.OsCapability)4 SdkClientException (com.amazonaws.SdkClientException)1 Instance (com.scaleset.cfbuilder.ec2.Instance)1 SecurityGroup (com.scaleset.cfbuilder.ec2.SecurityGroup)1 CFNCommand (com.scaleset.cfbuilder.ec2.metadata.CFNCommand)1 CFNInit (com.scaleset.cfbuilder.ec2.metadata.CFNInit)1 CFNPackage (com.scaleset.cfbuilder.ec2.metadata.CFNPackage)1 DBInstance (com.scaleset.cfbuilder.rds.DBInstance)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 Test (org.junit.Test)1 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)1 TransformationContext (org.opentosca.toscana.core.transformation.TransformationContext)1 Artifact (org.opentosca.toscana.model.artifact.Artifact)1 AdminEndpointCapability (org.opentosca.toscana.model.capability.AdminEndpointCapability)1 BindableCapability (org.opentosca.toscana.model.capability.BindableCapability)1 ComputeCapability (org.opentosca.toscana.model.capability.ComputeCapability)1 ContainerCapability (org.opentosca.toscana.model.capability.ContainerCapability)1 EndpointCapability (org.opentosca.toscana.model.capability.EndpointCapability)1