Search in sources :

Example 21 with Transformation

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

the class TransformationController method startTransformation.

/**
 *     This Mapping starts a transformation
 *     <p>
 *     Accessed with http call <code>GET /csars/{csar}/transformations/{platform}/start</code>
 *     <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 empty body if the transformation has been started</td>
 *     </tr>
 *     <tr>
 *     <td>400</td>
 *     <td>application/json</td>
 *     <td>Returned if the transformation is not in a valid state (Required Properties missing, Already running/Done) 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>
 */
@RequestMapping(path = "/{platform}/start", method = RequestMethod.POST, produces = "application/hal+json")
@ApiOperation(value = "Start a Transformation", tags = { "transformations" }, notes = "Starts a transformation that has been created and is ready to get started. To start a transformation, the " + "Transformation has to be in the state READY otherwise the transformation cannot start.")
@ApiResponses({ @ApiResponse(code = 200, message = "The operation was executed successfully"), @ApiResponse(code = 400, message = "The state of the transformation is illegal. This means that the transformation is not in the" + "READY state. Therefore starting it is not possible", response = RestErrorResponse.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) })
public ResponseEntity startTransformation(@ApiParam(value = "The unique identifier for the CSAR", required = true, example = "test") @PathVariable(name = "csarId") String name, @ApiParam(value = "The identifier for the platform", required = true, example = "kubernetes") @PathVariable(name = "platform") String platform) {
    logger.info("Starting transformation for csar '{}' on '{}'", name, platform);
    Csar csar = findByCsarId(name);
    Transformation transformation = findTransformationByPlatform(csar, platform);
    if (transformationService.startTransformation(transformation)) {
        return ResponseEntity.ok().build();
    } else {
        throw new IllegalTransformationStateException("Transformation could not start because" + " its not in a valid state to start.");
    }
}
Also used : IllegalTransformationStateException(org.opentosca.toscana.api.exceptions.IllegalTransformationStateException) Csar(org.opentosca.toscana.core.csar.Csar) Transformation(org.opentosca.toscana.core.transformation.Transformation) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with Transformation

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

the class TransformationController method getCSARTransformations.

/**
 *     This Request Returns a list of all transformations belonging to a csar.
 *     <p>
 *     Accessed with http call <code>GET /csars/{csar}/transformations/</code>
 *     <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 the resource (list) of all transformations that belong to this given csar</td>
 *     </tr>
 *     <tr>
 *     <td>404</td>
 *     <td>application/json</td>
 *     <td>Returns a error message if the csar is not found (see returned error message for details)</td>
 *     </tr>
 *     </table>
 */
@RequestMapping(path = "", method = RequestMethod.GET, produces = "application/hal+json")
@ApiOperation(value = "List all transformations of a CSAR", tags = { "transformations", "csars" }, notes = "Returns a HAL-Resources list containing all Transformations for a specific CSAR")
@ApiResponses({ @ApiResponse(code = 200, message = "The operation was executed successfully", response = TransformationResources.class), @ApiResponse(code = 404, message = "There is no CSAR for the given identifier", response = RestErrorResponse.class) })
public ResponseEntity<Resources<TransformationResponse>> getCSARTransformations(@ApiParam(value = "The unique identifier for the CSAR", required = true, example = "test") @PathVariable(name = "csarId") String name) {
    Csar csar = findByCsarId(name);
    Link selfLink = linkTo(methodOn(TransformationController.class).getCSARTransformations(name)).withSelfRel().expand(name);
    List<TransformationResponse> transformations = new ArrayList<>();
    for (Map.Entry<String, Transformation> entry : csar.getTransformations().entrySet()) {
        transformations.add(new TransformationResponse(entry.getValue().getLifecyclePhases(), entry.getValue().getState(), entry.getKey(), csar.getIdentifier()));
    }
    Resources<TransformationResponse> resources = new HiddenResources<>(transformations, selfLink);
    return ResponseEntity.ok(resources);
}
Also used : Csar(org.opentosca.toscana.core.csar.Csar) Transformation(org.opentosca.toscana.core.transformation.Transformation) HiddenResources(org.opentosca.toscana.api.docs.HiddenResources) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Link(org.springframework.hateoas.Link) TransformationResponse(org.opentosca.toscana.api.model.TransformationResponse) 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