use of com.scaleset.cfbuilder.ec2.SecurityGroup 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 com.scaleset.cfbuilder.ec2.SecurityGroup 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);
}
}
Aggregations