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);
}
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());
}
}
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");
}
}
Aggregations