Search in sources :

Example 6 with Transformation

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

the class TransformationController method getInputs.

/**
 *     Returns a list of inputs that might have to be set (if they are required) in order to start
 *     the transformation <p>
 *     Accessed with http call <code>GET /csars/{csar}/transformations/{platform}/inputs</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>Returned with content body (See samples.md) if the operation was successful</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}/inputs", method = RequestMethod.GET, produces = "application/hal+json")
@ApiOperation(value = "Retrieve the inputs of this transformation", tags = { "transformations" }, notes = "This Operation returns a list of inputs, specific to the csar and the platform. " + "If the input is invalid it has to be set in order to proceed with " + "starting the transformation. Setting the inputs is done with a POST or PUT to the same URL " + "(See Set Inputs Operation). If Transformation does not have any inputs, an empty array " + "is returned")
@ApiResponses({ @ApiResponse(code = 200, message = "The operation was executed successfully", response = GetInputsResponse.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<GetInputsResponse> getInputs(@ApiParam(value = "The 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);
    List<InputWrap> inputWrapList = toPropertyWrapList(transformation.getInputs(), null);
    GetInputsResponse response = new GetInputsResponse(csarId, platformId, inputWrapList);
    return ResponseEntity.ok(response);
}
Also used : Csar(org.opentosca.toscana.core.csar.Csar) Transformation(org.opentosca.toscana.core.transformation.Transformation) InputWrap(org.opentosca.toscana.api.model.InputWrap) GetInputsResponse(org.opentosca.toscana.api.model.GetInputsResponse) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with Transformation

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

the class TransformationController method getCSARTransformation.

/**
 *     Returns information about a single transformation
 *     <p>
 *     Accessed with http call <code>GET /csars/{csar}/transformations/{platform}/</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>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}", method = RequestMethod.GET, produces = "application/hal+json")
@ApiOperation(value = "Get details for a specific transformation", tags = { "transformations" }, notes = "Returns a HAL-Resource Containing the details for the transformation with the given parameters")
@ApiResponses({ @ApiResponse(code = 200, message = "The operation was executed successfully"), @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<TransformationResponse> getCSARTransformation(@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) {
    Csar csar = findByCsarId(name);
    Transformation transformation = findTransformationByPlatform(csar, platform);
    return ResponseEntity.ok().body(new TransformationResponse(transformation.getLifecyclePhases(), transformation.getState(), platform, name));
}
Also used : Csar(org.opentosca.toscana.core.csar.Csar) Transformation(org.opentosca.toscana.core.transformation.Transformation) TransformationResponse(org.opentosca.toscana.api.model.TransformationResponse) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with Transformation

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

the class CsarFilesystemDao method readFromDisk.

/**
 *     Reads csars from disks post: csarMap reflects contents of DATA_DIR on disk
 */
private void readFromDisk() {
    csarMap.clear();
    dataDir.mkdir();
    logger.info("Reading CSARs from repository");
    File[] files = dataDir.listFiles();
    for (File file : files) {
        if (isCsarDir(file)) {
            String id = file.getName();
            new File(getRootDir(id), id + ".log").delete();
            CsarImpl csar = new CsarImpl(getRootDir(id), id, getLog(id));
            LifecyclePhase unzip = csar.getLifecyclePhase(Csar.Phase.UNZIP);
            if (csar.getContentDir().listFiles().length != 0) {
                unzip.setState(LifecyclePhase.State.DONE);
                csar.validate();
            } else {
                unzip.setState(LifecyclePhase.State.FAILED);
            }
            csarMap.put(csar.getIdentifier(), csar);
            List<Transformation> transformations = transformationDao.find(csar);
            csar.setTransformations(transformations);
            csar.getLog().close();
        }
    }
    logger.info("Found {} CSARs in repository", csarMap.size());
}
Also used : Transformation(org.opentosca.toscana.core.transformation.Transformation) File(java.io.File) LifecyclePhase(org.opentosca.toscana.core.plugin.lifecycle.LifecyclePhase)

Example 9 with Transformation

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

the class CsarControllerTest method testDeleteCsarBusy.

@Test
public void testDeleteCsarBusy() throws Exception {
    // Add mock transformation to csar
    Csar csar = service.getCsar(VALID_CSAR_NAME).get();
    Transformation transformation = new TransformationImpl(csar, PLATFORM1, logMock(), modelMock());
    transformation.setState(TransformationState.TRANSFORMING);
    csar.getTransformations().put(PLATFORM1.id, transformation);
    // Perform request
    mvc.perform(delete(DELETE_VALID_CSAR_URL)).andDo(print()).andExpect(status().is(400));
}
Also used : Csar(org.opentosca.toscana.core.csar.Csar) TransformationImpl(org.opentosca.toscana.core.transformation.TransformationImpl) Transformation(org.opentosca.toscana.core.transformation.Transformation) Test(org.junit.Test) BaseSpringTest(org.opentosca.toscana.core.BaseSpringTest)

Example 10 with Transformation

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

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