Search in sources :

Example 1 with PlatformNotFoundException

use of org.opentosca.toscana.api.exceptions.PlatformNotFoundException in project TOSCAna by StuPro-TOSCAna.

the class TransformationController method addTransformation.

/**
 *     Creates a new transformation for the given platform and csar <p>
 *     <p>
 *     Accessed with http call <code>PUT or POST /csars/{csar}/transformations/{platform}/create</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 created</td>
 *     </tr>
 *     <tr>
 *     <td>404</td>
 *     <td>application/json</td>
 *     <td>Returns a error message if the csar is not found or if the given platform name is not found (see returned error
 *     message for details)</td>
 *     </tr>
 *     </table>
 */
@RequestMapping(path = "/{platform}/create", method = { RequestMethod.POST, RequestMethod.PUT }, produces = "application/hal+json")
@ApiOperation(value = "Create a new Transformation", tags = { "transformations" }, notes = "Creates a new transformation for the given CSAR and Platform " + "(If the platform does not exist and there is no other transformation with the same CSAR and Platform, " + "you have to delete the old transformation in this case)")
@ApiResponses({ @ApiResponse(code = 200, message = "The operation was executed successfully"), @ApiResponse(code = 400, message = "The transfomation could not get created because there already is a Transformation" + " of this CSAR on the given Platform", response = RestErrorResponse.class), @ApiResponse(code = 404, message = "There is no CSAR for the given identifier or the platform is not known.", response = RestErrorResponse.class) })
public ResponseEntity<Void> addTransformation(@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("Creating transformation for csar '{}' on '{}'", name, platform);
    Csar csar = findByCsarId(name);
    // Return bad Request if a transformation for this platform is already present
    if (csar.getTransformation(platform).isPresent()) {
        throw new TransformationAlreadyPresentException();
    }
    // Return 404 if the platform does not exist
    Optional<Platform> optionalPlatform = platformService.findPlatformById(platform);
    Platform p = optionalPlatform.orElseThrow(PlatformNotFoundException::new);
    transformationService.createTransformation(csar, p);
    return ResponseEntity.ok().build();
}
Also used : TransformationAlreadyPresentException(org.opentosca.toscana.api.exceptions.TransformationAlreadyPresentException) Csar(org.opentosca.toscana.core.csar.Csar) Platform(org.opentosca.toscana.core.transformation.platform.Platform) PlatformNotFoundException(org.opentosca.toscana.api.exceptions.PlatformNotFoundException) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with PlatformNotFoundException

use of org.opentosca.toscana.api.exceptions.PlatformNotFoundException in project TOSCAna by StuPro-TOSCAna.

the class PlatformController method getPlatform.

/**
 *     Returns the information for a specific platform.
 *     <p>
 *     This method handles the <code>/platforms/{id}</code> request
 *     <p>
 *     jResponds with Http code 200 normally (application/hal+json) and with code 404 (application/hal+json, standard
 *     error message) if the platform with the given name (case sensitive) does not exist.
 *
 *     @param id the <code>id</code> (identifier) of the platform (HTTP Path Parameter)
 */
@ApiOperation(value = "Get the Details for a specific Platform", notes = "Returns the resource object for one specific plugin (platform)", code = 200)
@ApiResponses({ @ApiResponse(code = 200, message = "The request has been executed with no error!", response = PlatformResponse.class), @ApiResponse(code = 404, message = "There is no platform with the given name", response = RestErrorResponse.class) })
@RequestMapping(path = "/{id}", method = RequestMethod.GET, produces = "application/hal+json")
public ResponseEntity<PlatformResponse> getPlatform(@ApiParam(name = "id", value = "The Platform identifier", required = true) @PathVariable(name = "id") String id) {
    Optional<Platform> optionalPlatform = platformService.findPlatformById(id);
    Platform p = optionalPlatform.orElseThrow(PlatformNotFoundException::new);
    return ResponseEntity.ok(getPlatformResource(p));
}
Also used : Platform(org.opentosca.toscana.core.transformation.platform.Platform) PlatformNotFoundException(org.opentosca.toscana.api.exceptions.PlatformNotFoundException) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 PlatformNotFoundException (org.opentosca.toscana.api.exceptions.PlatformNotFoundException)2 Platform (org.opentosca.toscana.core.transformation.platform.Platform)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 TransformationAlreadyPresentException (org.opentosca.toscana.api.exceptions.TransformationAlreadyPresentException)1 Csar (org.opentosca.toscana.core.csar.Csar)1