/*-
* ============LICENSE_START======================================================================
- * Copyright (C) 2023 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2023-2024 Nordix Foundation. All rights reserved.
* ===============================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import com.oransc.rappmanager.configuration.RappManagerConfiguration;
import com.oransc.rappmanager.models.cache.RappCacheService;
import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
+import com.oransc.rappmanager.models.csar.validator.RappValidationHandler;
import com.oransc.rappmanager.models.exception.RappHandlerException;
import com.oransc.rappmanager.models.rapp.PrimeOrder;
import com.oransc.rappmanager.models.rapp.Rapp;
Logger logger = LoggerFactory.getLogger(RappController.class);
private final RappCsarConfigurationHandler rappCsarConfigurationHandler;
+ private final RappValidationHandler rappValidationHandler;
private final RappManagerConfiguration rappManagerConfiguration;
private final RappCacheService rappCacheService;
private final RappService rappService;
+ private static final String RAPP_NOT_FOUND = "rApp %s not found.";
@GetMapping
public ResponseEntity<Collection<Rapp>> getRapps() {
@GetMapping("{rapp_id}")
public ResponseEntity<Rapp> getRapp(@PathVariable("rapp_id") String rappId) {
return rappCacheService.getRapp(rappId).map(ResponseEntity::ok).orElseThrow(
- () -> new RappHandlerException(HttpStatus.NOT_FOUND, "rApp '" + rappId + "' not found."));
+ () -> new RappHandlerException(HttpStatus.NOT_FOUND, String.format(RAPP_NOT_FOUND, rappId)));
}
@PostMapping("{rapp_id}")
public ResponseEntity<Rapp> createRapp(@PathVariable("rapp_id") String rappId,
@RequestPart("file") MultipartFile csarFilePart) throws IOException {
- if (rappCsarConfigurationHandler.isValidRappPackage(csarFilePart)) {
+ if (rappValidationHandler.isValidRappPackage(csarFilePart)) {
File csarFile = new File(
rappCsarConfigurationHandler.getRappPackageLocation(rappManagerConfiguration.getCsarLocation(),
rappId, csarFilePart.getOriginalFilename()).toUri());
.map(primeOrder -> rappService.primeRapp(rapp))
.orElseGet(() -> rappService.deprimeRapp(rapp)))
.orElseThrow(() -> new RappHandlerException(HttpStatus.NOT_FOUND,
- "rApp '" + rappId + "' not found."));
+ String.format(RAPP_NOT_FOUND, rappId)));
// @formatter:on
}
@DeleteMapping("{rapp_id}")
- public ResponseEntity<Object> deleteRapp(@PathVariable("rapp_id") String rappId) {
+ public ResponseEntity<String> deleteRapp(@PathVariable("rapp_id") String rappId) {
// @formatter:off
return rappCacheService.getRapp(rappId)
- .filter(rapp -> rapp.getRappInstances().isEmpty() && rapp.getState().equals(RappState.COMMISSIONED))
- .map(rapp -> {
- rappCacheService.deleteRapp(rapp);
- return ResponseEntity.ok().build();
- })
+ .map(rappService::deleteRapp)
.orElseThrow(() -> new RappHandlerException(HttpStatus.NOT_FOUND,
- "rApp '" + rappId + "' not found."));
+ String.format(RAPP_NOT_FOUND, rappId)));
// @formatter:on
}
}