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));
}
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));
}
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);
}
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();
}
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;
}
Aggregations