Search in sources :

Example 1 with MysqlDatabase

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

use of org.opentosca.toscana.model.node.MysqlDatabase 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)

Example 3 with MysqlDatabase

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

the class PrepareModelRelationshipVisitor method visit.

@Override
public void visit(ConnectsTo relation) {
    RootNode source = topology.getEdgeSource(relation);
    RootNode target = topology.getEdgeTarget(relation);
    if (source instanceof WebApplication && target instanceof MysqlDatabase) {
        MysqlDatabase mysqlDatabase = (MysqlDatabase) target;
        WebApplication webApplication = (WebApplication) source;
        // if they are hosted on the same compute --> we can set the compute private address to
        Compute computeMysqlDatabase = getCompute(mysqlDatabase);
        Compute computeWebApplication = getCompute(webApplication);
        if (computeMysqlDatabase.equals(computeWebApplication)) {
            // means we can set the private address as reference to the database endpoint
            Fn databaseEndpointFn = Fn.fnGetAtt(toAlphanumerical(mysqlDatabase.getEntityName()), AWS_ENDPOINT_REFERENCE);
            String databaseEndpoint = databaseEndpointFn.toString(true);
            cfnModule.putFn(databaseEndpoint, databaseEndpointFn);
            computeMysqlDatabase.setPrivateAddress(databaseEndpoint);
            computeMysqlDatabase.setPublicAddress(databaseEndpoint);
            logger.debug("Set private address and public address of '{}' to reference MysqlDatabase '{}'", computeMysqlDatabase.getEntityName(), mysqlDatabase.getEntityName());
        } else {
            logger.debug("Cannot safely set private/public address of '{}'", computeMysqlDatabase.getEntityName());
        }
    } else {
        logger.debug("Drop relationship, because it is not supported");
    }
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) MysqlDatabase(org.opentosca.toscana.model.node.MysqlDatabase) Compute(org.opentosca.toscana.model.node.Compute) Fn(com.scaleset.cfbuilder.core.Fn) WebApplication(org.opentosca.toscana.model.node.WebApplication)

Aggregations

MysqlDatabase (org.opentosca.toscana.model.node.MysqlDatabase)3 WebApplication (org.opentosca.toscana.model.node.WebApplication)3 Fn (com.scaleset.cfbuilder.core.Fn)2 Compute (org.opentosca.toscana.model.node.Compute)2 RootNode (org.opentosca.toscana.model.node.RootNode)2 File (java.io.File)1 SecureRandom (java.security.SecureRandom)1 ArrayList (java.util.ArrayList)1 Collectors (java.util.stream.Collectors)1 RandomStringUtils (org.apache.commons.lang3.RandomStringUtils)1 Test (org.junit.Test)1 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)1 TransformationContext (org.opentosca.toscana.core.transformation.TransformationContext)1 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)1 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)1 Port (org.opentosca.toscana.model.datatype.Port)1 HostedOn (org.opentosca.toscana.model.relation.HostedOn)1 NodeVisitor (org.opentosca.toscana.model.visitor.NodeVisitor)1 CloudFormationLifecycle.toAlphanumerical (org.opentosca.toscana.plugins.cloudformation.CloudFormationLifecycle.toAlphanumerical)1 CloudFormationModule (org.opentosca.toscana.plugins.cloudformation.CloudFormationModule)1