use of org.opentosca.toscana.plugins.util.TransformationFailureException in project TOSCAna by StuPro-TOSCAna.
the class CloudFormationLifecycle method transform.
@Override
public void transform() {
logger.info("Begin transformation to CloudFormation.");
Set<RootNode> nodes = model.getNodes();
// Visit Compute nodes first, then all others
try {
TransformModelNodeVisitor cfnNodeVisitor = new TransformModelNodeVisitor(context, cfnModule);
logger.info("Transform nodes");
visitComputeNodesFirst(nodes, cfnNodeVisitor);
logger.info("Handling environment variables.");
EnvironmentHandler environmentHandler = new EnvironmentHandler(cfnModule, logger);
environmentHandler.handleEnvironment();
logger.info("Creating CloudFormation template.");
fileAccess.access(OUTPUT_DIR + CloudFormationFileCreator.TEMPLATE_YAML).appendln(cfnModule.toString()).close();
CloudFormationFileCreator fileCreator = new CloudFormationFileCreator(context, cfnModule);
logger.info("Creating CloudFormation scripts.");
fileCreator.copyUtilScripts();
fileCreator.copyUtilDependencies();
fileCreator.writeScripts();
fileCreator.copyFiles();
fileCreator.writeReadme(context);
} catch (IOException ie) {
logger.error("File access error");
throw new TransformationFailureException("Could not write template with fileAccess", ie);
} catch (TransformationFailureException tfe) {
logger.error("Transformation to CloudFormation unsuccessful. Please check the StackTrace for more Info.");
throw tfe;
} catch (Exception e) {
logger.error("Transformation to CloudFormation unsuccessful. Unexpected exception should not appear here.");
throw new TransformationFailureException("Unexpected exception", e);
}
logger.info("Transformation to CloudFormation successful.");
}
use of org.opentosca.toscana.plugins.util.TransformationFailureException 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.plugins.util.TransformationFailureException 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.plugins.util.TransformationFailureException 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.plugins.util.TransformationFailureException in project TOSCAna by StuPro-TOSCAna.
the class CloudFoundryLifecycle method transform.
@Override
public void transform() {
logger.info("Begin transformation to Cloud Foundry.");
PluginFileAccess fileAccess = context.getPluginFileAccess();
fillApplications();
try {
FileCreator fileCreator = new FileCreator(fileAccess, filledApplications, context);
fileCreator.createFiles();
} catch (FileNotFoundException f) {
throw new TransformationFailureException("A file which is declared in the template could not be found", f);
} catch (IOException | JSONException e) {
e.printStackTrace();
}
}
Aggregations