use of org.opentosca.toscana.model.node.Compute 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");
}
}
use of org.opentosca.toscana.model.node.Compute in project TOSCAna by StuPro-TOSCAna.
the class TransformModelNodeVisitor method visit.
@Override
public void visit(Dbms node) {
try {
// get the compute where the dbms this node is hosted on, is hosted on
Compute computeHost = getCompute(node);
String computeHostName = toAlphanumerical(computeHost.getEntityName());
operationHandler.handleGenericHostedNode(node, computeHost);
// Open Dbms port
String SecurityGroupName = computeHostName + SECURITY_GROUP;
SecurityGroup securityGroup = (SecurityGroup) cfnModule.getResource(SecurityGroupName);
if (node.getPort().isPresent()) {
Integer dbmsPort = node.getPort().orElseThrow(() -> new IllegalArgumentException("Database " + "port not set"));
securityGroup.ingress(ingress -> ingress.cidrIp(IP_OPEN), PROTOCOL_TCP, dbmsPort);
}
} catch (Exception e) {
logger.error("Error while creating Dbms resource.");
throw new TransformationFailureException("Failed at Dbms node " + node.getEntityName(), e);
}
}
use of org.opentosca.toscana.model.node.Compute in project TOSCAna by StuPro-TOSCAna.
the class TransformModelNodeVisitor method visit.
@Override
public void visit(WebApplication node) {
try {
// get the compute where the apache this node is hosted on, is hosted on
Compute compute = getCompute(node);
String computeName = toAlphanumerical(compute.getEntityName());
node.getAppEndpoint().getPort().ifPresent(port -> {
SecurityGroup computeSecurityGroup = (SecurityGroup) cfnModule.getResource(computeName + SECURITY_GROUP);
computeSecurityGroup.ingress(ingress -> ingress.cidrIp(IP_OPEN), PROTOCOL_TCP, port.port);
});
// handle create
operationHandler.handleCreate(node, computeName);
// handle configure
operationHandler.handleConfigure(node, computeName);
// handle start
operationHandler.handleStart(node, computeName);
} catch (Exception e) {
logger.error("Error while creating WebApplication");
throw new TransformationFailureException("Failed at WebApplication node " + node.getEntityName(), e);
}
}
use of org.opentosca.toscana.model.node.Compute in project TOSCAna by StuPro-TOSCAna.
the class TransformModelNodeVisitor method visit.
@Override
public void visit(MysqlDatabase node) {
try {
String nodeName = toAlphanumerical(node.getEntityName());
// get the compute where the dbms this node is hosted on, is hosted on
Compute compute = getCompute(node);
String serverName = toAlphanumerical(compute.getEntityName());
String dbName = node.getDatabaseName();
String masterUser = node.getUser().orElseThrow(() -> new IllegalArgumentException("Database user not set"));
String masterPassword = node.getPassword().orElseThrow(() -> new IllegalArgumentException("Database " + "password not set"));
Integer port = node.getPort().orElseThrow(() -> new IllegalArgumentException("Database port not set"));
// check what values should be taken
ComputeCapability hostedOnComputeCapability = compute.getHost();
CapabilityMapper capabilityMapper = createCapabilityMapper();
String dBInstanceClass = capabilityMapper.mapComputeCapabilityToInstanceType(hostedOnComputeCapability, CapabilityMapper.RDS_DISTINCTION);
Integer allocatedStorage = capabilityMapper.mapComputeCapabilityToRDSAllocatedStorage(hostedOnComputeCapability);
// SSD
String storageType = "gp2";
String securityGroupName = nodeName + SECURITY_GROUP;
SecurityGroup securityGroup = cfnModule.resource(SecurityGroup.class, securityGroupName).groupDescription("Open database " + dbName + " for access to group " + serverName + SECURITY_GROUP);
Set<Compute> hostsOfConnectedTo = getHostsOfConnectedTo(node);
for (Compute hostOfConnectedTo : hostsOfConnectedTo) {
securityGroup.ingress(ingress -> ingress.sourceSecurityGroupName(cfnModule.ref(toAlphanumerical(hostOfConnectedTo.getEntityName()) + SECURITY_GROUP)), PROTOCOL_TCP, port);
}
cfnModule.resource(DBInstance.class, nodeName).engine("MySQL").dBName(dbName).masterUsername(masterUser).masterUserPassword(masterPassword).dBInstanceClass(dBInstanceClass).allocatedStorage(allocatedStorage).storageType(storageType).vPCSecurityGroups(cfnModule.fnGetAtt(securityGroupName, "GroupId"));
// handle sql artifact
for (Artifact artifact : node.getArtifacts()) {
String relPath = artifact.getFilePath();
if (relPath.endsWith(".sql")) {
String sql = cfnModule.getFileAccess().read(artifact.getFilePath());
String computeName = createSqlCompute(node, sql);
securityGroup.ingress(ingress -> ingress.sourceSecurityGroupName(cfnModule.ref(toAlphanumerical(computeName) + SECURITY_GROUP)), PROTOCOL_TCP, port);
}
}
} catch (Exception e) {
logger.error("Error while creating MysqlDatabase resource.");
throw new TransformationFailureException("Failed at MysqlDatabase node " + node.getEntityName(), e);
}
}
use of org.opentosca.toscana.model.node.Compute in project TOSCAna by StuPro-TOSCAna.
the class CloudFoundryLifecycle method prepare.
@Override
public void prepare() {
logger.info("Begin preparation for transformation to Cloud Foundry");
PrepareVisitor prepareVisitor = new PrepareVisitor(logger);
for (RootNode node : context.getModel().getNodes()) {
node.accept(prepareVisitor);
}
logger.debug("Collecting Compute Nodes in topology");
ComputeNodeFindingVisitor computeFinder = new ComputeNodeFindingVisitor();
model.getNodes().forEach(e -> {
e.accept(computeFinder);
KubernetesNodeContainer container = new KubernetesNodeContainer(e);
nodes.put(e.getEntityName(), container);
});
computeFinder.getComputeNodes().forEach(e -> computeNodes.add(nodes.get(e.getEntityName())));
logger.debug("Finding top Level Nodes");
graph = model.getTopology();
Set<RootNode> topLevelNodes = determineTopLevelNodes(context.getModel(), computeFinder.getComputeNodes().stream().map(Compute.class::cast).collect(Collectors.toList()), e -> nodes.get(e.getEntityName()).activateParentComputeNode());
logger.debug("Building complete Topology stacks");
this.stacks.addAll(buildTopologyStacks(model, topLevelNodes, nodes));
// TODO: check how many different applications there are and fill list with them
// probably there must be a combination of application and set of nodes
applications = new ArrayList<>();
int i = 1;
for (NodeStack stack : stacks) {
Application myApp = new Application(i, context);
i++;
myApp.setProvider(provider);
myApp.setConnection(connection);
myApp.setName(stack.getStackName());
myApp.addStack(stack);
applications.add(myApp);
}
}
Aggregations