use of com.scaleset.cfbuilder.core.Fn 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 com.scaleset.cfbuilder.core.Fn in project TOSCAna by StuPro-TOSCAna.
the class PrepareModelNodeVisitor method visit.
@Override
public void visit(Compute node) {
// compute nodes only get transformed if they are present in this map
cfnModule.addComputeToEc2(node);
// Set private and public address of this EC2 instance
String computeName = toAlphanumerical(node.getEntityName());
Fn privateIpFn = Fn.fnGetAtt(computeName, AWS_INSTANCE_PRIVATE_IP);
Fn publicIpFn = Fn.fnGetAtt(computeName, AWS_INSTANCE_PUBLIC_IP);
String privateIpFnString = privateIpFn.toString(true);
String publicIpFnString = publicIpFn.toString(true);
cfnModule.putFn(privateIpFnString, privateIpFn);
cfnModule.putFn(publicIpFnString, publicIpFn);
node.setPrivateAddress(privateIpFnString);
node.setPublicAddress(publicIpFnString);
}
use of com.scaleset.cfbuilder.core.Fn 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