use of org.opentosca.toscana.plugins.cloudformation.visitor.TransformModelNodeVisitor in project TOSCAna by StuPro-TOSCAna.
the class CloudFormationPluginTest method setUp.
@Before
public void setUp() throws Exception {
lamp = new EffectiveModelFactory().create(TestCsars.VALID_LAMP_NO_INPUT_TEMPLATE, logMock());
fileAccess = new PluginFileAccess(new File("src/test/resources/csars/yaml/valid/lamp-input/"), tmpdir, logMock());
cfnModule = new CloudFormationModule(fileAccess, "us-west-2", new BasicAWSCredentials("", ""));
TransformationContext context = mock(TransformationContext.class);
when(context.getModel()).thenReturn(lamp);
when(context.getLogger((Class<?>) any(Class.class))).thenReturn(LoggerFactory.getLogger("Dummy Logger"));
TransformModelNodeVisitor cfnNodeVisitorL = new TransformModelNodeVisitor(context, cfnModule);
cfnNodeVisitor = spy(cfnNodeVisitorL);
CapabilityMapper capabilityMapper = mock(CapabilityMapper.class);
when(capabilityMapper.mapOsCapabilityToImageId(any(OsCapability.class))).thenReturn("ami-testami");
when(cfnNodeVisitor.createCapabilityMapper()).thenReturn(capabilityMapper);
}
use of org.opentosca.toscana.plugins.cloudformation.visitor.TransformModelNodeVisitor 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.");
}
Aggregations