Search in sources :

Example 1 with OutputProperty

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

Example 2 with OutputProperty

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

the class TransformationControllerTest method testGetOutputs.

// </editor-fold>
// <editor-fold desc="Output Tests">
@Test
public void testGetOutputs() throws Exception {
    List<Transformation> transformations = preInitNonCreationTests();
    Transformation t = transformations.get(0);
    when(t.getState()).thenReturn(TransformationState.DONE);
    String outputKey = "test_output";
    List<OutputProperty> outputs = Lists.newArrayList(new PlatformInput(outputKey, PropertyType.TEXT, "", true, "some value"));
    when(t.getOutputs()).thenReturn(outputs);
    mvc.perform(get(GET_OUTPUT_URL)).andDo(print()).andExpect(status().is(200)).andExpect(jsonPath("$.outputs").isArray()).andExpect(jsonPath("$.links[0].href").value("http://localhost" + GET_OUTPUT_URL)).andExpect(jsonPath("$.outputs[0].key").value(outputKey)).andReturn();
}
Also used : Transformation(org.opentosca.toscana.core.transformation.Transformation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) OutputProperty(org.opentosca.toscana.core.transformation.properties.OutputProperty) PlatformInput(org.opentosca.toscana.core.transformation.properties.PlatformInput) Test(org.junit.Test) BaseSpringTest(org.opentosca.toscana.core.BaseSpringTest)

Example 3 with OutputProperty

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

the class EffectiveModelTest method outputTest.

@Test
public void outputTest() {
    EffectiveModel model = new EffectiveModelFactory().create(TestCsars.Testing.OUTPUTS_TEMPLATE, logMock());
    Map<String, OutputProperty> outputs = model.getOutputs();
    assertNotNull(outputs);
    assertEquals(1, outputs.size());
    OutputProperty linkedOutput = outputs.get("test_output_linked");
    assertNotNull(linkedOutput);
    assertTrue(linkedOutput.getDescription().isPresent());
    assertEquals("test-description2", linkedOutput.getDescription().get());
    assertTrue(linkedOutput.getValue().isPresent());
    assertEquals("8084", linkedOutput.getValue().get());
}
Also used : OutputProperty(org.opentosca.toscana.core.transformation.properties.OutputProperty) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Aggregations

OutputProperty (org.opentosca.toscana.core.transformation.properties.OutputProperty)3 Test (org.junit.Test)2 Transformation (org.opentosca.toscana.core.transformation.Transformation)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 IllegalTransformationStateException (org.opentosca.toscana.api.exceptions.IllegalTransformationStateException)1 GetOutputsResponse (org.opentosca.toscana.api.model.GetOutputsResponse)1 OutputWrap (org.opentosca.toscana.api.model.OutputWrap)1 BaseSpringTest (org.opentosca.toscana.core.BaseSpringTest)1 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)1 Csar (org.opentosca.toscana.core.csar.Csar)1 PlatformInput (org.opentosca.toscana.core.transformation.properties.PlatformInput)1 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)1 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1