Search in sources :

Example 11 with RootNode

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

the class DynamicRequirementTest method dynamicRequirementTest.

@Test
public void dynamicRequirementTest() {
    EffectiveModel model = new EffectiveModelFactory().create(TestTemplates.Requirements.DYNAMIC_REQUIREMENT, logMock());
    WebApplication app = (WebApplication) model.getNodes().iterator().next();
    Requirement<? extends Capability, ? extends RootNode, ? extends RootRelationship> dynamicRequirement = app.getRequirements().stream().filter(r -> "dynamic-requirement".equals(r.getEntityName())).findFirst().orElseThrow(() -> new IllegalStateException("dynamic requirement should exist"));
    RootRelationship relationship = dynamicRequirement.getRelationship().get();
    assertEquals(ConnectsTo.class, relationship.getClass());
    Capability capability = dynamicRequirement.get(dynamicRequirement.CAPABILITY);
    assertEquals(EndpointCapability.class, capability.getClass());
    RootNode fulfiller = dynamicRequirement.getFulfillers().iterator().next();
    assertEquals(app, fulfiller);
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) EndpointCapability(org.opentosca.toscana.model.capability.EndpointCapability) Capability(org.opentosca.toscana.model.capability.Capability) WebApplication(org.opentosca.toscana.model.node.WebApplication) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) RootRelationship(org.opentosca.toscana.model.relation.RootRelationship) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 12 with RootNode

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

the class FileCreatorTest method checkMultipleApplicationServices.

@Test
public void checkMultipleApplicationServices() throws IOException, JSONException {
    String serviceName = "mydb";
    envUser = System.getenv(CF_ENVIRONMENT_USER);
    envPw = System.getenv(CF_ENVIRONMENT_PW);
    envHost = System.getenv(CF_ENVIRONMENT_HOST);
    envOrga = System.getenv(CF_ENVIRONMENT_ORGA);
    envSpace = System.getenv(CF_ENVIRONMENT_SPACE);
    connection = createConnection();
    Application app = new Application("app", 1, context);
    Application secondApp = new Application("appSec", 2, context);
    app.setProvider(new Provider(Provider.CloudFoundryProviderType.PIVOTAL));
    app.setConnection(connection);
    secondApp.setProvider(new Provider(Provider.CloudFoundryProviderType.PIVOTAL));
    secondApp.setConnection(connection);
    app.addService(service1, ServiceTypes.MYSQL);
    secondApp.addService(serviceName, ServiceTypes.MYSQL);
    EffectiveModel lamp = new EffectiveModelFactory().create(TestCsars.VALID_LAMP_NO_INPUT_TEMPLATE, logMock());
    RootNode webApplicationNode = null;
    RootNode mysqlDatabaseNode = null;
    for (RootNode node : lamp.getNodes()) {
        if (node instanceof WebApplication) {
            webApplicationNode = node;
        }
        if (node instanceof MysqlDatabase) {
            mysqlDatabaseNode = node;
        }
    }
    app.addConfigMysql(service1, "my_db/configSql.sql");
    app.addExecuteFile("my_app/configure_myphpapp.sh", webApplicationNode);
    secondApp.addConfigMysql(serviceName, "database/config.sql");
    secondApp.addExecuteFile("database/dbinit.sh", mysqlDatabaseNode);
    List<Application> applications = new ArrayList<>();
    applications.add(app);
    applications.add(secondApp);
    FileCreator fileCreator = new FileCreator(fileAccess, applications, context);
    fileCreator.createFiles();
    File targetFile = new File(targetDir, outputPath + FILEPRAEFIX_DEPLOY + deploy_name + FILESUFFIX_DEPLOY);
    String deployscriptContent = FileUtils.readFileToString(targetFile);
    String expectedContent = "check python\n" + "python replace.py ../../app1/my_app/configure_myphpapp.sh /var/www/html/ /home/vcap/app/htdocs/\n" + "python replace.py ../../app2/database/dbinit.sh /var/www/html/ /home/vcap/app/htdocs/\n" + "cf push app -f ../manifest.yml --no-start\n" + "cf push appSec -f ../manifest.yml --no-start\n" + "python readCredentials.py app cleardb mysql cleardb\n" + "python configureMysql.py ../../app1/my_db/configSql.sql\n" + "cf start app\n" + "python executeCommand.py app /home/vcap/app/htdocs/my_app/configure_myphpapp.sh\n" + "python readCredentials.py appSec cleardb mysql mydb\n" + "python configureMysql.py ../../app2/database/config.sql\n" + "cf start appSec\n" + "python executeCommand.py appSec /home/vcap/app/database/dbinit.sh\n";
    assertTrue(deployscriptContent.contains(expectedContent));
// assertEquals(expectedContent, deployscriptContent);
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) MysqlDatabase(org.opentosca.toscana.model.node.MysqlDatabase) FileCreator(org.opentosca.toscana.plugins.cloudfoundry.filecreator.FileCreator) ArrayList(java.util.ArrayList) WebApplication(org.opentosca.toscana.model.node.WebApplication) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application) WebApplication(org.opentosca.toscana.model.node.WebApplication) File(java.io.File) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) Provider(org.opentosca.toscana.plugins.cloudfoundry.application.Provider) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 13 with RootNode

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

the class CloudFormationLifecycle method checkModel.

@Override
public boolean checkModel() {
    logger.info("Check model for compatibility to CloudFormation");
    Set<RootNode> nodes = model.getNodes();
    Set<RootRelationship> relationships = model.getTopology().edgeSet();
    try {
        CheckModelNodeVisitor checkModelNodeVisitor = new CheckModelNodeVisitor(context);
        logger.info("Check nodes");
        visitAllNodes(nodes, checkModelNodeVisitor);
        CheckModelRelationshipVisitor checkModelRelationshipVisitor = new CheckModelRelationshipVisitor(context);
        logger.info("Check relationships");
        visitAllRelationships(relationships, checkModelRelationshipVisitor);
    } catch (UnsupportedTypeException ute) {
        logger.error(ute.getMessage());
        return false;
    }
    return true;
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) UnsupportedTypeException(org.opentosca.toscana.model.visitor.UnsupportedTypeException) CheckModelNodeVisitor(org.opentosca.toscana.plugins.cloudformation.visitor.CheckModelNodeVisitor) CheckModelRelationshipVisitor(org.opentosca.toscana.plugins.cloudformation.visitor.CheckModelRelationshipVisitor) RootRelationship(org.opentosca.toscana.model.relation.RootRelationship)

Example 14 with RootNode

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

the class CloudFormationLifecycle method prepare.

@Override
public void prepare() {
    logger.info("Prepare model for compatibility to CloudFormation");
    Set<RootNode> nodes = model.getNodes();
    Graph<RootNode, RootRelationship> topology = model.getTopology();
    PrepareModelNodeVisitor prepareModelNodeVisitor = new PrepareModelNodeVisitor(context, cfnModule);
    logger.info("Prepare nodes");
    visitComputeNodesFirst(nodes, prepareModelNodeVisitor);
    logger.info("Prepare relationships");
    PrepareModelRelationshipVisitor prepareModelRelationshipVisitor = new PrepareModelRelationshipVisitor(context, cfnModule);
    visitAllRelationships(topology.edgeSet(), prepareModelRelationshipVisitor);
}
Also used : PrepareModelNodeVisitor(org.opentosca.toscana.plugins.cloudformation.visitor.PrepareModelNodeVisitor) RootNode(org.opentosca.toscana.model.node.RootNode) PrepareModelRelationshipVisitor(org.opentosca.toscana.plugins.cloudformation.visitor.PrepareModelRelationshipVisitor) RootRelationship(org.opentosca.toscana.model.relation.RootRelationship)

Example 15 with RootNode

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

the class CloudFormationLifecycle method transform.

@Override
public void transform() {
    logger.info("Begin transformation to CloudFormation.");
    Set<RootNode> nodes = model.getNodes();
    // Visit Compute nodes first, then all others
    try {
        TransformModelNodeVisitor cfnNodeVisitor = new TransformModelNodeVisitor(context, cfnModule);
        logger.info("Transform nodes");
        visitComputeNodesFirst(nodes, cfnNodeVisitor);
        logger.info("Handling environment variables.");
        EnvironmentHandler environmentHandler = new EnvironmentHandler(cfnModule, logger);
        environmentHandler.handleEnvironment();
        logger.info("Creating CloudFormation template.");
        fileAccess.access(OUTPUT_DIR + CloudFormationFileCreator.TEMPLATE_YAML).appendln(cfnModule.toString()).close();
        CloudFormationFileCreator fileCreator = new CloudFormationFileCreator(context, cfnModule);
        logger.info("Creating CloudFormation scripts.");
        fileCreator.copyUtilScripts();
        fileCreator.copyUtilDependencies();
        fileCreator.writeScripts();
        fileCreator.copyFiles();
        fileCreator.writeReadme(context);
    } catch (IOException ie) {
        logger.error("File access error");
        throw new TransformationFailureException("Could not write template with fileAccess", ie);
    } catch (TransformationFailureException tfe) {
        logger.error("Transformation to CloudFormation unsuccessful. Please check the StackTrace for more Info.");
        throw tfe;
    } catch (Exception e) {
        logger.error("Transformation to CloudFormation unsuccessful. Unexpected exception should not appear here.");
        throw new TransformationFailureException("Unexpected exception", e);
    }
    logger.info("Transformation to CloudFormation successful.");
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) EnvironmentHandler(org.opentosca.toscana.plugins.cloudformation.handler.EnvironmentHandler) TransformModelNodeVisitor(org.opentosca.toscana.plugins.cloudformation.visitor.TransformModelNodeVisitor) IOException(java.io.IOException) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) UnsupportedTypeException(org.opentosca.toscana.model.visitor.UnsupportedTypeException) IOException(java.io.IOException)

Aggregations

RootNode (org.opentosca.toscana.model.node.RootNode)20 RootRelationship (org.opentosca.toscana.model.relation.RootRelationship)7 WebApplication (org.opentosca.toscana.model.node.WebApplication)6 Compute (org.opentosca.toscana.model.node.Compute)4 TransformationFailureException (org.opentosca.toscana.plugins.util.TransformationFailureException)4 LinkedList (java.util.LinkedList)3 Test (org.junit.Test)3 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)3 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)3 Artifact (org.opentosca.toscana.model.artifact.Artifact)3 UnsupportedTypeException (org.opentosca.toscana.model.visitor.UnsupportedTypeException)3 Application (org.opentosca.toscana.plugins.cloudfoundry.application.Application)3 NodeStack (org.opentosca.toscana.plugins.kubernetes.util.NodeStack)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Entity (org.opentosca.toscana.core.parse.model.Entity)2 MappingEntity (org.opentosca.toscana.core.parse.model.MappingEntity)2 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)2 EndpointCapability (org.opentosca.toscana.model.capability.EndpointCapability)2