Search in sources :

Example 6 with Platform

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

the class TransformerHealthIndicatorTest method testPlatformList.

@Test
public void testPlatformList() throws Exception {
    when(pluginService.getSupportedPlatforms()).thenReturn(PLATFORMS);
    String json = getHealthAsString();
    List<String> platforms = getPlatforms(json);
    assertEquals(PLATFORMS.size(), platforms.size());
    Map<String, Boolean> foundPlatforms = new HashMap<>();
    for (Platform platform : PLATFORMS) {
        foundPlatforms.put(platform.id, false);
        for (String p : platforms) {
            if (p.equals(platform.id)) {
                log.info("Found platform {}", p);
                foundPlatforms.put(p, true);
            }
        }
    }
    assertTrue("Could not find all platforms", foundPlatforms.values().stream().allMatch(e -> e));
}
Also used : Transformation(org.opentosca.toscana.core.transformation.Transformation) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CsarDao(org.opentosca.toscana.core.csar.CsarDao) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) TransformationImpl(org.opentosca.toscana.core.transformation.TransformationImpl) HashSet(java.util.HashSet) Platform(org.opentosca.toscana.core.transformation.platform.Platform) Map(java.util.Map) CsarImpl(org.opentosca.toscana.core.csar.CsarImpl) Before(org.junit.Before) PLATFORMS(org.opentosca.toscana.core.testdata.TestPlugins.PLATFORMS) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TRANSFORMING(org.opentosca.toscana.core.transformation.TransformationState.TRANSFORMING) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JsonPath(com.jayway.jsonpath.JsonPath) ERROR(org.opentosca.toscana.core.transformation.TransformationState.ERROR) File(java.io.File) Csar(org.opentosca.toscana.core.csar.Csar) List(java.util.List) PLATFORM2(org.opentosca.toscana.core.testdata.TestPlugins.PLATFORM2) PLATFORM1(org.opentosca.toscana.core.testdata.TestPlugins.PLATFORM1) TransformationState(org.opentosca.toscana.core.transformation.TransformationState) PluginService(org.opentosca.toscana.core.plugin.PluginService) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) Platform(org.opentosca.toscana.core.transformation.platform.Platform) HashMap(java.util.HashMap) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 7 with Platform

use of org.opentosca.toscana.core.transformation.platform.Platform 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 8 with Platform

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

the class PlatformController method getPlatforms.

/**
 *     Lists all Supported Platforms (HTTP Response Method).
 *     <p>
 *     It handles the <code>/platforms</code> Request
 *     <p>
 *     Always responds with HTTP-Code 200 (application/hal+json)
 */
@ApiOperation(value = "List all supported Platforms", notes = "Returns a HAL resource (_embedded) containing all " + "Platforms supported by this transformer", code = 200, response = PlatformResources.class)
@RequestMapping(path = "", method = RequestMethod.GET, produces = "application/hal+json")
public ResponseEntity<Resources<PlatformResponse>> getPlatforms() {
    Link selfLink = linkTo(methodOn(PlatformController.class).getPlatforms()).withSelfRel();
    ArrayList<PlatformResponse> responses = new ArrayList<>();
    for (Platform platform : platformService.getSupportedPlatforms()) {
        logger.info("Adding Platform {} to response ", platform.id);
        PlatformResponse res = getPlatformResource(platform);
        responses.add(res);
    }
    Resources<PlatformResponse> resources = new HiddenResources<>(responses, selfLink);
    return ResponseEntity.ok(resources);
}
Also used : HiddenResources(org.opentosca.toscana.api.docs.HiddenResources) Platform(org.opentosca.toscana.core.transformation.platform.Platform) ArrayList(java.util.ArrayList) PlatformResponse(org.opentosca.toscana.api.model.PlatformResponse) Link(org.springframework.hateoas.Link) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with Platform

use of org.opentosca.toscana.core.transformation.platform.Platform 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 10 with Platform

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

the class TransformationFilesystemDao method readFromDisk.

private Set<Transformation> readFromDisk(Csar csar) {
    File[] transformationFiles = csarDao.getTransformationsDir(csar).listFiles();
    Set<Transformation> transformations = new HashSet<>();
    for (File pluginEntry : transformationFiles) {
        if (!pluginEntry.isDirectory()) {
            continue;
        }
        Optional<Platform> platform = platformService.findPlatformById(pluginEntry.getName());
        if (platform.isPresent()) {
            Transformation transformation = createTransformation(csar, platform.get());
            readTargetArtifactFromDisk(transformation);
            transformations.add(transformation);
        } else {
            try {
                logger.warn("Found transformation '{}' for unsupported platform '{}' on disk", pluginEntry, pluginEntry.getName());
                logger.warn("Deleting '{}'", pluginEntry);
                FileUtils.deleteDirectory(pluginEntry);
            } catch (IOException e) {
                logger.error("Failed to delete illegal transformation directory '{}'", pluginEntry, e);
            }
        }
    }
    return transformations;
}
Also used : Platform(org.opentosca.toscana.core.transformation.platform.Platform) IOException(java.io.IOException) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

Platform (org.opentosca.toscana.core.transformation.platform.Platform)16 HashSet (java.util.HashSet)9 File (java.io.File)7 Csar (org.opentosca.toscana.core.csar.Csar)6 CsarImpl (org.opentosca.toscana.core.csar.CsarImpl)5 PlatformInput (org.opentosca.toscana.core.transformation.properties.PlatformInput)5 TransformationImpl (org.opentosca.toscana.core.transformation.TransformationImpl)4 ApiOperation (io.swagger.annotations.ApiOperation)3 Before (org.junit.Before)3 Test (org.junit.Test)3 Transformation (org.opentosca.toscana.core.transformation.Transformation)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ApiResponses (io.swagger.annotations.ApiResponses)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 PlatformNotFoundException (org.opentosca.toscana.api.exceptions.PlatformNotFoundException)2 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)2 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1