Search in sources :

Example 1 with TransformModelNodeVisitor

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);
}
Also used : PluginFileAccess(org.opentosca.toscana.core.plugin.PluginFileAccess) OsCapability(org.opentosca.toscana.model.capability.OsCapability) TransformModelNodeVisitor(org.opentosca.toscana.plugins.cloudformation.visitor.TransformModelNodeVisitor) File(java.io.File) TransformationContext(org.opentosca.toscana.core.transformation.TransformationContext) CapabilityMapper(org.opentosca.toscana.plugins.cloudformation.mapper.CapabilityMapper) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) Before(org.junit.Before)

Example 2 with TransformModelNodeVisitor

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.");
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) EnvironmentHandler(org.opentosca.toscana.plugins.cloudformation.handler.EnvironmentHandler) TransformModelNodeVisitor(org.opentosca.toscana.plugins.cloudformation.visitor.TransformModelNodeVisitor) IOException(java.io.IOException) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) UnsupportedTypeException(org.opentosca.toscana.model.visitor.UnsupportedTypeException) IOException(java.io.IOException)

Aggregations

TransformModelNodeVisitor (org.opentosca.toscana.plugins.cloudformation.visitor.TransformModelNodeVisitor)2 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 File (java.io.File)1 IOException (java.io.IOException)1 Before (org.junit.Before)1 PluginFileAccess (org.opentosca.toscana.core.plugin.PluginFileAccess)1 TransformationContext (org.opentosca.toscana.core.transformation.TransformationContext)1 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)1 OsCapability (org.opentosca.toscana.model.capability.OsCapability)1 RootNode (org.opentosca.toscana.model.node.RootNode)1 UnsupportedTypeException (org.opentosca.toscana.model.visitor.UnsupportedTypeException)1 EnvironmentHandler (org.opentosca.toscana.plugins.cloudformation.handler.EnvironmentHandler)1 CapabilityMapper (org.opentosca.toscana.plugins.cloudformation.mapper.CapabilityMapper)1 TransformationFailureException (org.opentosca.toscana.plugins.util.TransformationFailureException)1