Search in sources :

Example 1 with TransformationContext

use of org.opentosca.toscana.core.transformation.TransformationContext in project TOSCAna by StuPro-TOSCAna.

the class DeploymentPropertyTest method check.

@Test
public void check() {
    try {
        File input = new File(this.tmpdir, "in");
        File output = new File(this.tmpdir, "out");
        PropertyInstance instance = new PropertyInstance(new HashSet<>(platform.properties), mock(Transformation.class));
        if (this.input != null) {
            instance.set(Platform.DEPLOY_AFTER_TRANSFORMATION_KEY, this.input);
        }
        Csar csar = new CsarImpl(input, "csarId", logMock());
        Transformation t = new TransformationImpl(csar, platform, logMock(), mock(EffectiveModel.class));
        Transformation transformation = spy(t);
        when(transformation.getInputs()).thenReturn(instance);
        TransformationContext context = new TransformationContext(transformation, output);
        Assert.assertEquals(expected, context.performDeployment());
    } catch (Exception e) {
        e.printStackTrace(System.out);
        if (expectedException == null || !expectedException.isInstance(e)) {
            fail();
        }
    }
}
Also used : Csar(org.opentosca.toscana.core.csar.Csar) TransformationImpl(org.opentosca.toscana.core.transformation.TransformationImpl) Transformation(org.opentosca.toscana.core.transformation.Transformation) CsarImpl(org.opentosca.toscana.core.csar.CsarImpl) PropertyInstance(org.opentosca.toscana.core.transformation.properties.PropertyInstance) File(java.io.File) TransformationContext(org.opentosca.toscana.core.transformation.TransformationContext) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) NoSuchPropertyException(org.opentosca.toscana.core.transformation.properties.NoSuchPropertyException) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 2 with TransformationContext

use of org.opentosca.toscana.core.transformation.TransformationContext in project TOSCAna by StuPro-TOSCAna.

the class AbstractLifeCycleTest method setUp.

@Before
public void setUp() throws IOException {
    TransformationContext context = mock(TransformationContext.class);
    PluginFileAccess access = new PluginFileAccess(new File(""), tmpdir, logMock());
    when(context.getPluginFileAccess()).thenReturn(access);
    when(context.getLogger((Class<?>) any(Class.class))).thenReturn(LoggerFactory.getLogger("Dummy Logger"));
    new TestLifecycle(context);
}
Also used : PluginFileAccess(org.opentosca.toscana.core.plugin.PluginFileAccess) TransformationContext(org.opentosca.toscana.core.transformation.TransformationContext) File(java.io.File) Before(org.junit.Before)

Example 3 with TransformationContext

use of org.opentosca.toscana.core.transformation.TransformationContext in project TOSCAna by StuPro-TOSCAna.

the class LifecycleAwarePluginTest method setUp.

@Before
public void setUp() throws Exception {
    Csar csar = new CsarImpl(tmpdir, "csarId", logMock());
    Transformation t = new TransformationImpl(csar, TestPlugins.PLATFORM1, logMock(), mock(EffectiveModel.class));
    context = spy(new TransformationContext(t, tmpdir));
    doReturn(false).when(context).performDeployment();
    lifecycle = spy(new TestTransformationLifecycle(context));
    checkModel = true;
    plugin = new LifecycleTestPlugin(TestPlugins.PLATFORM1);
}
Also used : Csar(org.opentosca.toscana.core.csar.Csar) TransformationImpl(org.opentosca.toscana.core.transformation.TransformationImpl) Transformation(org.opentosca.toscana.core.transformation.Transformation) CsarImpl(org.opentosca.toscana.core.csar.CsarImpl) TransformationContext(org.opentosca.toscana.core.transformation.TransformationContext) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) Before(org.junit.Before)

Example 4 with TransformationContext

use of org.opentosca.toscana.core.transformation.TransformationContext in project TOSCAna by StuPro-TOSCAna.

the class ExecutionDummyPlugin method transform.

@Override
public void transform(AbstractLifecycle lifecycle) throws Exception {
    TransformationContext context = lifecycle.getContext();
    Logger logger = context.getLogger(getClass());
    int i = 0;
    context.getPluginFileAccess().access("some-output-file").append("some transformation result").close();
    logger.info("Waiting 500ms until completion");
    while (!Thread.currentThread().isInterrupted() && i < 5) {
        Thread.sleep(100);
        i++;
    }
    if (failDuringExec) {
        logger.info("Throwing test exception");
        throw new InterruptedException("Test Exception");
    }
}
Also used : Logger(org.slf4j.Logger) TransformationContext(org.opentosca.toscana.core.transformation.TransformationContext)

Example 5 with TransformationContext

use of org.opentosca.toscana.core.transformation.TransformationContext in project TOSCAna by StuPro-TOSCAna.

the class FileCreationExcecutionDummy method transform.

@Override
public void transform(AbstractLifecycle lifecycle) throws Exception {
    TransformationContext transformation = lifecycle.getContext();
    Random rnd = new Random(123456);
    for (int i = 0; i < 5; i++) {
        String outerPath = "outer-" + i;
        for (int j = 0; j < 5; j++) {
            String innerPath = "inner-" + i;
            String path = outerPath + "/" + innerPath + ".bin";
            writeFilepath(transformation, rnd, path);
        }
    }
    for (int l = 0; l < 20; l++) {
        writeFilepath(transformation, rnd, "file-" + l + ".bin");
    }
    super.transform(lifecycle);
}
Also used : Random(java.util.Random) TransformationContext(org.opentosca.toscana.core.transformation.TransformationContext)

Aggregations

TransformationContext (org.opentosca.toscana.core.transformation.TransformationContext)13 File (java.io.File)4 Before (org.junit.Before)4 PluginFileAccess (org.opentosca.toscana.core.plugin.PluginFileAccess)4 Test (org.junit.Test)3 Csar (org.opentosca.toscana.core.csar.Csar)3 CsarImpl (org.opentosca.toscana.core.csar.CsarImpl)3 Transformation (org.opentosca.toscana.core.transformation.Transformation)3 TransformationImpl (org.opentosca.toscana.core.transformation.TransformationImpl)3 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)3 Logger (org.slf4j.Logger)3 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)2 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)2 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)2 IOException (java.io.IOException)1 Random (java.util.Random)1 IntegrationTest (org.opentosca.toscana.IntegrationTest)1 NoSuchPropertyException (org.opentosca.toscana.core.transformation.properties.NoSuchPropertyException)1 PropertyInstance (org.opentosca.toscana.core.transformation.properties.PropertyInstance)1 OsCapability (org.opentosca.toscana.model.capability.OsCapability)1