Fixes the delete rApp instance response messages.
Issue-ID: NONRTRIC-913
Signed-off-by: aravind.est <aravindhan.a@est.tech>
Change-Id: I5782dfcef343d50e1e4a72ab49ab82f1d54b6aca
import com.oransc.rappmanager.models.rappinstance.DeployOrder;
import com.oransc.rappmanager.models.rappinstance.RappInstance;
import com.oransc.rappmanager.models.rappinstance.RappInstanceDeployOrder;
-import com.oransc.rappmanager.models.rappinstance.RappInstanceState;
import com.oransc.rappmanager.models.statemachine.RappInstanceStateMachine;
import com.oransc.rappmanager.service.RappService;
import java.util.Map;
rappInstance.setState(rappInstanceStateMachine.getRappInstanceState(rappInstanceId));
return rappInstance;
}).map(ResponseEntity::ok).orElseThrow(() -> new RappHandlerException(HttpStatus.NOT_FOUND,
- String.format(RAPP_INSTANCE_NOT_FOUND, rappId)));
+ String.format(RAPP_INSTANCE_NOT_FOUND, rappInstanceId)));
}
@PutMapping("{rapp_instance_id}")
@DeleteMapping("{rapp_instance_id}")
public ResponseEntity<Object> deleteRappInstance(@PathVariable("rapp_id") String rappId,
@PathVariable("rapp_instance_id") UUID rappInstanceId) {
- return rappCacheService.getRapp(rappId).map(rapp -> Pair.of(rapp, rapp.getRappInstances()))
- .filter(rappPair -> rappPair.getRight().containsKey(rappInstanceId) && rappPair.getRight()
- .get(rappInstanceId)
- .getState()
- .equals(RappInstanceState.UNDEPLOYED))
- .map(rappPair -> {
- rappInstanceStateMachine.deleteRappInstance(
- rappPair.getLeft().getRappInstances().get(rappInstanceId));
- rappPair.getLeft().getRappInstances().remove(rappInstanceId);
- return ResponseEntity.noContent().build();
- }).orElseThrow(() -> new RappHandlerException(HttpStatus.NOT_FOUND,
- String.format(RAPP_INSTANCE_NOT_FOUND, rappId)));
+ return rappCacheService.getRapp(rappId).filter(rApp -> rApp.getRappInstances().containsKey(rappInstanceId))
+ .map(rApp -> rappService.deleteRappInstance(rApp, rappInstanceId)).orElseThrow(
+ () -> new RappHandlerException(HttpStatus.NOT_FOUND,
+ String.format(RAPP_INSTANCE_NOT_FOUND, rappId)));
}
}
import com.oransc.rappmanager.acm.service.AcmDeployer;
import com.oransc.rappmanager.dme.service.DmeDeployer;
import com.oransc.rappmanager.models.cache.RappCacheService;
+import com.oransc.rappmanager.models.exception.RappHandlerException;
import com.oransc.rappmanager.models.rapp.Rapp;
import com.oransc.rappmanager.models.rapp.RappEvent;
import com.oransc.rappmanager.models.rapp.RappState;
import com.oransc.rappmanager.models.rappinstance.RappInstanceState;
import com.oransc.rappmanager.models.statemachine.RappInstanceStateMachine;
import com.oransc.rappmanager.sme.service.SmeDeployer;
+import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
}
}
+ public ResponseEntity<Object> deleteRappInstance(Rapp rApp, UUID rappInstanceId) {
+ if (rApp.getRappInstances().get(rappInstanceId).getState().equals(RappInstanceState.UNDEPLOYED)) {
+ rappInstanceStateMachine.deleteRappInstance(rApp.getRappInstances().get(rappInstanceId));
+ rApp.getRappInstances().remove(rappInstanceId);
+ return ResponseEntity.noContent().build();
+ }
+ throw new RappHandlerException(HttpStatus.BAD_REQUEST,
+ String.format("Unable to delete rApp instance %s as it is not in UNDEPLOYED state", rappInstanceId));
+ }
+
public void updateRappInstanceState(Rapp rapp, RappInstance rappInstance) {
acmDeployer.syncRappInstanceStatus(rapp.getCompositionId(), rappInstance);
}
package com.oransc.rappmanager.service;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import com.oransc.rappmanager.acm.service.AcmDeployer;
import com.oransc.rappmanager.dme.service.DmeDeployer;
+import com.oransc.rappmanager.models.exception.RappHandlerException;
import com.oransc.rappmanager.models.rapp.Rapp;
import com.oransc.rappmanager.models.rapp.RappState;
import com.oransc.rappmanager.models.rappinstance.RappInstance;
import com.oransc.rappmanager.models.statemachine.RappInstanceStateMachine;
import com.oransc.rappmanager.sme.service.SmeDeployer;
import com.oransc.rappmanager.sme.service.SmeLifecycleManager;
+import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
assertEquals(HttpStatus.BAD_REQUEST, rappService.undeployRappInstance(rapp, rappInstance).getStatusCode());
}
+ @Test
+ void testDeleteRappInstance() {
+ Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile)
+ .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build();
+ RappInstance rappInstance = new RappInstance();
+ rappInstance.setState(RappInstanceState.UNDEPLOYED);
+ HashMap<UUID, RappInstance> rAppInstanceMap = new HashMap<>();
+ rAppInstanceMap.put(rappInstance.getRappInstanceId(), rappInstance);
+ rapp.setRappInstances(rAppInstanceMap);
+ rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId());
+ assertEquals(HttpStatus.NO_CONTENT,
+ rappService.deleteRappInstance(rapp, rappInstance.getRappInstanceId()).getStatusCode());
+ }
+
+ @Test
+ void testDeleteRappInstanceFailure() {
+ Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile)
+ .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build();
+ RappInstance rappInstance = new RappInstance();
+ rappInstance.setState(RappInstanceState.DEPLOYED);
+ HashMap<UUID, RappInstance> rAppInstanceMap = new HashMap<>();
+ rAppInstanceMap.put(rappInstance.getRappInstanceId(), rappInstance);
+ rapp.setRappInstances(rAppInstanceMap);
+ rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId());
+ assertThrows(RappHandlerException.class,
+ () -> rappService.deleteRappInstance(rapp, rappInstance.getRappInstanceId()));
+ }
+
@Test
void testDeleteRappSuccess() {
Rapp rApp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile)