Search in sources :

Example 1 with Transformation

use of org.opentosca.toscana.core.transformation.Transformation 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 Transformation

use of org.opentosca.toscana.core.transformation.Transformation 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 3 with Transformation

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

the class TransformerHealthIndicatorTest method initTestEnvironment.

private void initTestEnvironment() {
    // Create Dummy Csar
    // DummyCsar csar = new DummyCsar("test");
    Csar csar = new CsarImpl(new File(""), MOCK_CSAR_NAME, logMock());
    csar = spy(csar);
    Map<String, Transformation> transformations = new HashMap<>();
    Set<Platform> platformSet = new HashSet<>();
    for (Object[] d : MOCK_DATA) {
        // Initialize transformation Mock
        Transformation transformation = new TransformationImpl(csar, (Platform) d[0], logMock(), modelMock());
        transformation.setState((TransformationState) d[1]);
        transformations.put(((Platform) d[0]).id, transformation);
        // Add platform to supported platform list
        platformSet.add((Platform) d[0]);
    }
    // Add Transformations to csar
    when(csar.getTransformations()).thenReturn(transformations);
    // Platforms
    when(pluginService.getSupportedPlatforms()).thenReturn(platformSet);
    // Repository
    when(repository.findAll()).thenReturn(Collections.singletonList(csar));
}
Also used : Csar(org.opentosca.toscana.core.csar.Csar) TransformationImpl(org.opentosca.toscana.core.transformation.TransformationImpl) Transformation(org.opentosca.toscana.core.transformation.Transformation) Platform(org.opentosca.toscana.core.transformation.platform.Platform) HashMap(java.util.HashMap) CsarImpl(org.opentosca.toscana.core.csar.CsarImpl) File(java.io.File) HashSet(java.util.HashSet)

Example 4 with Transformation

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

the class KubernetesLampIT method getInputs.

@Override
protected PropertyInstance getInputs(EffectiveModel model) throws NoSuchPropertyException {
    Set<InputProperty> prop = new HashSet<>(plugin.getPlatform().properties);
    prop.addAll(model.getInputs().values());
    PropertyInstance instance = new PropertyInstance(prop, mock(Transformation.class));
    if (System.getenv("DH_USERNAME") != null) {
        // This Transformation is performed by pushing to a registry
        instance.set(DOCKER_PUSH_TO_REGISTRY_PROPERTY_KEY, "true");
        instance.set(DOCKER_REGISTRY_USERNAME_PROPERTY_KEY, System.getenv("DH_USERNAME"));
        instance.set(DOCKER_REGISTRY_PASSWORD_PROPERTY_KEY, System.getenv("DH_PASSWORD"));
        instance.set(DOCKER_REGISTRY_URL_PROPERTY_KEY, System.getenv("DH_URL"));
        instance.set(DOCKER_REGISTRY_REPOSITORY_PROPERTY_KEY, System.getenv("DH_REPOSITORY"));
    } else {
        // This Transformation is performed by storing the files in Tar archives
        instance.set(DOCKER_PUSH_TO_REGISTRY_PROPERTY_KEY, "false");
    }
    return instance;
}
Also used : Transformation(org.opentosca.toscana.core.transformation.Transformation) InputProperty(org.opentosca.toscana.core.transformation.properties.InputProperty) PropertyInstance(org.opentosca.toscana.core.transformation.properties.PropertyInstance) HashSet(java.util.HashSet)

Example 5 with Transformation

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

the class TransformationController method getOutputs.

/**
 *     Returns the outputs of a Transformation.
 *     <p>
 *     <table summary="">
 *     <tr>
 *     <td>HTTP-Code</td>
 *     <td>Mime-Type</td>
 *     <td>Description (Returned if)</td>
 *     </tr>
 *     <tr>
 *     <td>200</td>
 *     <td>application/hal+json</td>
 *     <td>Returns a List of the outputs. (Empty if no deployment has been executed)</td>
 *     </tr>
 *     <tr>
 *     <td>400</td>
 *     <td>application/json</td>
 *     <td>Returned if the transformation is not in a valid state (has to be in DONE or ERROR) to set inputs</td>
 *     </tr>
 *     <tr>
 *     <td>404</td>
 *     <td>application/json</td>
 *     <td>Returns a error message if the csar is not found or if the csar does not have a transformation for the given
 *     name (see returned error message for details)</td>
 *     </tr>
 *     </table>
 */
@ApiOperation(value = "Retrieve the outputs and their values", tags = { "transformations" }, notes = "This operation returns the outputs of a deployment. Retrieval of the outputs is not possible " + "if the transformation (including deployment) is not done yet")
@ApiResponses({ @ApiResponse(code = 200, message = "The operation was executed successfully", response = GetOutputsResponse.class), @ApiResponse(code = 404, message = "There is no CSAR for the given identifier or the CSAR does not have " + "a transformation for the specified platform", response = RestErrorResponse.class), @ApiResponse(code = 400, message = "The state of the transformation is invalid (not ERROR or DONE)", response = RestErrorResponse.class) })
@RequestMapping(path = "/{platform}/outputs", method = { RequestMethod.GET }, produces = "application/hal+json")
public ResponseEntity<GetOutputsResponse> getOutputs(@ApiParam(value = "The unique identifier for the CSAR", required = true, example = "test") @PathVariable(name = "csarId") String csarId, @ApiParam(value = "The identifier for the platform", required = true, example = "kubernetes") @PathVariable(name = "platform") String platformId) {
    Csar csar = findByCsarId(csarId);
    Transformation transformation = findTransformationByPlatform(csar, platformId);
    if (transformation.getState() != TransformationState.DONE && transformation.getState() != TransformationState.ERROR) {
        throw new IllegalTransformationStateException("The Transformation has not finished yet!");
    }
    List<OutputProperty> outputs = transformation.getOutputs();
    List<OutputWrap> wrappedOutputs = outputs.stream().map(OutputWrap::new).collect(Collectors.toList());
    return ResponseEntity.ok(new GetOutputsResponse(csarId, platformId, wrappedOutputs));
}
Also used : IllegalTransformationStateException(org.opentosca.toscana.api.exceptions.IllegalTransformationStateException) Csar(org.opentosca.toscana.core.csar.Csar) Transformation(org.opentosca.toscana.core.transformation.Transformation) GetOutputsResponse(org.opentosca.toscana.api.model.GetOutputsResponse) OutputProperty(org.opentosca.toscana.core.transformation.properties.OutputProperty) OutputWrap(org.opentosca.toscana.api.model.OutputWrap) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Transformation (org.opentosca.toscana.core.transformation.Transformation)22 Csar (org.opentosca.toscana.core.csar.Csar)16 ApiOperation (io.swagger.annotations.ApiOperation)9 ApiResponses (io.swagger.annotations.ApiResponses)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 TransformationImpl (org.opentosca.toscana.core.transformation.TransformationImpl)8 Test (org.junit.Test)6 File (java.io.File)4 IllegalTransformationStateException (org.opentosca.toscana.api.exceptions.IllegalTransformationStateException)4 BaseSpringTest (org.opentosca.toscana.core.BaseSpringTest)4 CsarImpl (org.opentosca.toscana.core.csar.CsarImpl)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 TransformationContext (org.opentosca.toscana.core.transformation.TransformationContext)3 PropertyInstance (org.opentosca.toscana.core.transformation.properties.PropertyInstance)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 GetInputsResponse (org.opentosca.toscana.api.model.GetInputsResponse)2