Reason field added to show why rApp priming/depriming failed.
Priming/depriming failure shown with bad gateway http response code.
Issue-ID: NONRTRIC-913
Signed-off-by: aravind.est <aravindhan.a@est.tech>
Change-Id: I33f286120930c34c0898d891577cde4fc9bc2ce5
primeACMComposition(commissioningResponse.getCompositionId(), PrimeOrder.PRIME);
return true;
} else {
primeACMComposition(commissioningResponse.getCompositionId(), PrimeOrder.PRIME);
return true;
} else {
- logger.error("Failed to create automation composition");
+ logger.warn("Failed to create automation composition");
}
} catch (Exception e) {
}
} catch (Exception e) {
- logger.error("Failed to create automation composition", e);
+ logger.warn("Error in creating automation composition", e);
+ rapp.setReason("Unable to create automation composition");
} catch (Exception e) {
logger.error("Failed deprime automation composition", e);
}
} catch (Exception e) {
logger.error("Failed deprime automation composition", e);
}
+ rapp.setReason("Unable to delete automation composition");
public ResponseEntity<String> primeRapp(Rapp rapp) {
if (rapp.getState().equals(RappState.COMMISSIONED)) {
rapp.setState(RappState.PRIMING);
public ResponseEntity<String> primeRapp(Rapp rapp) {
if (rapp.getState().equals(RappState.COMMISSIONED)) {
rapp.setState(RappState.PRIMING);
if (acmDeployer.primeRapp(rapp) && dmeDeployer.primeRapp(rapp)) {
rapp.setState(RappState.PRIMED);
if (acmDeployer.primeRapp(rapp) && dmeDeployer.primeRapp(rapp)) {
rapp.setState(RappState.PRIMED);
+ return ResponseEntity.ok().build();
} else {
rapp.setState(RappState.COMMISSIONED);
} else {
rapp.setState(RappState.COMMISSIONED);
+ return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build();
- return ResponseEntity.ok().build();
} else {
return ResponseEntity.badRequest()
.body(String.format(STATE_TRANSITION_NOT_PERMITTED, RappState.PRIMED.name(),
} else {
return ResponseEntity.badRequest()
.body(String.format(STATE_TRANSITION_NOT_PERMITTED, RappState.PRIMED.name(),
public ResponseEntity<String> deprimeRapp(Rapp rapp) {
if (rapp.getState().equals(RappState.PRIMED) && rapp.getRappInstances().isEmpty()) {
rapp.setState(RappState.DEPRIMING);
public ResponseEntity<String> deprimeRapp(Rapp rapp) {
if (rapp.getState().equals(RappState.PRIMED) && rapp.getRappInstances().isEmpty()) {
rapp.setState(RappState.DEPRIMING);
if (acmDeployer.deprimeRapp(rapp) && dmeDeployer.deprimeRapp(rapp)) {
rapp.setState(RappState.COMMISSIONED);
if (acmDeployer.deprimeRapp(rapp) && dmeDeployer.deprimeRapp(rapp)) {
rapp.setState(RappState.COMMISSIONED);
+ return ResponseEntity.ok().build();
} else {
rapp.setState(RappState.PRIMED);
} else {
rapp.setState(RappState.PRIMED);
+ return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build();
- return ResponseEntity.ok().build();
} else {
if (!rapp.getRappInstances().isEmpty()) {
return ResponseEntity.badRequest().body("Unable to deprime as there are active rapp instances,");
} else {
if (!rapp.getRappInstances().isEmpty()) {
return ResponseEntity.badRequest().body("Unable to deprime as there are active rapp instances,");
import com.fasterxml.jackson.databind.ObjectMapper;
import com.oransc.rappmanager.acm.service.AcmDeployer;
import com.fasterxml.jackson.databind.ObjectMapper;
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.rapp.PrimeOrder;
import com.oransc.rappmanager.models.rapp.Rapp;
import com.oransc.rappmanager.models.cache.RappCacheService;
import com.oransc.rappmanager.models.rapp.PrimeOrder;
import com.oransc.rappmanager.models.rapp.Rapp;
@MockBean
AcmDeployer acmDeployer;
@MockBean
AcmDeployer acmDeployer;
+ @MockBean
+ DmeDeployer dmeDeployer;
+
@MockBean
SmeLifecycleManager smeLifecycleManager;
@MockBean
SmeLifecycleManager smeLifecycleManager;
.packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
rappCacheService.putRapp(rapp);
when(acmDeployer.primeRapp(any())).thenReturn(true);
.packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
rappCacheService.putRapp(rapp);
when(acmDeployer.primeRapp(any())).thenReturn(true);
+ when(dmeDeployer.primeRapp(any())).thenReturn(true);
RappPrimeOrder rappPrimeOrder = new RappPrimeOrder();
rappPrimeOrder.setPrimeOrder(PrimeOrder.PRIME);
mockMvc.perform(MockMvcRequestBuilders.put("/rapps/{rapp_id}", rappId).contentType(MediaType.APPLICATION_JSON)
RappPrimeOrder rappPrimeOrder = new RappPrimeOrder();
rappPrimeOrder.setPrimeOrder(PrimeOrder.PRIME);
mockMvc.perform(MockMvcRequestBuilders.put("/rapps/{rapp_id}", rappId).contentType(MediaType.APPLICATION_JSON)
.packageLocation(validCsarFileLocation).state(RappState.PRIMED).build();
rappCacheService.putRapp(rapp);
when(acmDeployer.deprimeRapp(any())).thenReturn(true);
.packageLocation(validCsarFileLocation).state(RappState.PRIMED).build();
rappCacheService.putRapp(rapp);
when(acmDeployer.deprimeRapp(any())).thenReturn(true);
+ when(dmeDeployer.deprimeRapp(any())).thenReturn(true);
RappPrimeOrder rappPrimeOrder = new RappPrimeOrder();
rappPrimeOrder.setPrimeOrder(PrimeOrder.DEPRIME);
mockMvc.perform(MockMvcRequestBuilders.put("/rapps/{rapp_id}", rappId).contentType(MediaType.APPLICATION_JSON)
RappPrimeOrder rappPrimeOrder = new RappPrimeOrder();
rappPrimeOrder.setPrimeOrder(PrimeOrder.DEPRIME);
mockMvc.perform(MockMvcRequestBuilders.put("/rapps/{rapp_id}", rappId).contentType(MediaType.APPLICATION_JSON)
.packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
when(acmDeployer.primeRapp(any())).thenReturn(false);
when(dmeDeployer.primeRapp(any())).thenReturn(true);
.packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
when(acmDeployer.primeRapp(any())).thenReturn(false);
when(dmeDeployer.primeRapp(any())).thenReturn(true);
- assertEquals(HttpStatus.OK, rappService.primeRapp(rapp).getStatusCode());
+ assertEquals(HttpStatus.BAD_GATEWAY, rappService.primeRapp(rapp).getStatusCode());
assertEquals(RappState.COMMISSIONED, rapp.getState());
}
assertEquals(RappState.COMMISSIONED, rapp.getState());
}
.packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
when(acmDeployer.primeRapp(any())).thenReturn(true);
when(dmeDeployer.primeRapp(any())).thenReturn(false);
.packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
when(acmDeployer.primeRapp(any())).thenReturn(true);
when(dmeDeployer.primeRapp(any())).thenReturn(false);
- assertEquals(HttpStatus.OK, rappService.primeRapp(rapp).getStatusCode());
+ assertEquals(HttpStatus.BAD_GATEWAY, rappService.primeRapp(rapp).getStatusCode());
assertEquals(RappState.COMMISSIONED, rapp.getState());
}
assertEquals(RappState.COMMISSIONED, rapp.getState());
}
.packageLocation(validCsarFileLocation).state(RappState.PRIMED).build();
when(acmDeployer.deprimeRapp(any())).thenReturn(false);
when(dmeDeployer.deprimeRapp(any())).thenReturn(true);
.packageLocation(validCsarFileLocation).state(RappState.PRIMED).build();
when(acmDeployer.deprimeRapp(any())).thenReturn(false);
when(dmeDeployer.deprimeRapp(any())).thenReturn(true);
- assertEquals(HttpStatus.OK, rappService.deprimeRapp(rapp).getStatusCode());
+ assertEquals(HttpStatus.BAD_GATEWAY, rappService.deprimeRapp(rapp).getStatusCode());
assertEquals(RappState.PRIMED, rapp.getState());
}
assertEquals(RappState.PRIMED, rapp.getState());
}
.packageLocation(validCsarFileLocation).state(RappState.PRIMED).build();
when(acmDeployer.deprimeRapp(any())).thenReturn(true);
when(dmeDeployer.deprimeRapp(any())).thenReturn(false);
.packageLocation(validCsarFileLocation).state(RappState.PRIMED).build();
when(acmDeployer.deprimeRapp(any())).thenReturn(true);
when(dmeDeployer.deprimeRapp(any())).thenReturn(false);
- assertEquals(HttpStatus.OK, rappService.deprimeRapp(rapp).getStatusCode());
+ assertEquals(HttpStatus.BAD_GATEWAY, rappService.deprimeRapp(rapp).getStatusCode());
assertEquals(RappState.PRIMED, rapp.getState());
}
assertEquals(RappState.PRIMED, rapp.getState());
}
allInfoTypes.addAll(dataProducerRegistrationApiClient.getInfoTypdentifiers());
requiredInfoTypes.removeAll(allInfoTypes);
if (!requiredInfoTypes.isEmpty()) {
allInfoTypes.addAll(dataProducerRegistrationApiClient.getInfoTypdentifiers());
requiredInfoTypes.removeAll(allInfoTypes);
if (!requiredInfoTypes.isEmpty()) {
- logger.info("Invalid rapp package as the following info types cannot be found {}",
- requiredInfoTypes);
- rapp.setIsDmeValid(false);
- } else {
- rapp.setIsDmeValid(true);
+ rapp.setReason(String.format("Invalid rapp package as the following info types cannot be found %s",
+ requiredInfoTypes));
- } else {
- rapp.setIsDmeValid(true);
}
return true;
} catch (Exception e) {
logger.warn("Failed to prime DME", e);
}
return true;
} catch (Exception e) {
logger.warn("Failed to prime DME", e);
- rapp.setIsDmeValid(false);
+ rapp.setReason("Failed to prime DME");
@Override
public boolean deprimeRapp(Rapp rapp) {
logger.debug("Depriming DME functions for rApp {}", rapp.getRappId());
@Override
public boolean deprimeRapp(Rapp rapp) {
logger.debug("Depriming DME functions for rApp {}", rapp.getRappId());
- rapp.setIsDmeValid(null);
package com.oransc.rappmanager.dme.service;
package com.oransc.rappmanager.dme.service;
-import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
@ParameterizedTest
@MethodSource("getSuccessParamsWithUnavailableInfoTypes")
@ParameterizedTest
@MethodSource("getSuccessParamsWithUnavailableInfoTypes")
- void testPrimeRappSuccessWithUnavailableInfoType(String rappFile, boolean result) throws JsonProcessingException {
+ void testPrimeRappSuccessWithUnavailableInfoType(String rappFile, boolean isSuccess)
+ throws JsonProcessingException {
RappResources rappResources = rappDmeResourceBuilder.getResources();
Rapp rapp = getRapp(Optional.empty());
rapp.setPackageName(rappFile);
RappResources rappResources = rappDmeResourceBuilder.getResources();
Rapp rapp = getRapp(Optional.empty());
rapp.setPackageName(rappFile);
if (rappFile.equals(validRappFileNewInfoType)) {
mockServer.verify();
}
if (rappFile.equals(validRappFileNewInfoType)) {
mockServer.verify();
}
- assertEquals(rapp.getIsDmeValid(), result);
+ if (isSuccess) {
+ assertNull(rapp.getReason());
+ } else {
+ assertNotNull(rapp.getReason());
+ }
}
private static Stream<Arguments> getSuccessParamsWithUnavailableInfoTypes() {
}
private static Stream<Arguments> getSuccessParamsWithUnavailableInfoTypes() {
- @MethodSource("getSuccessParamsWithAvailableInfoTypes")
- void testPrimeRappSuccessWithValidInfoType(String rappFile, boolean result) throws JsonProcessingException {
+ @ValueSource(strings = {validRappFile, validRappFileNewInfoType})
+ void testPrimeRappSuccessWithValidInfoType(String rappFile) throws JsonProcessingException {
RappResources rappResources = rappDmeResourceBuilder.getResources();
Rapp rapp = getRapp(Optional.empty());
rapp.setPackageName(rappFile);
RappResources rappResources = rappDmeResourceBuilder.getResources();
Rapp rapp = getRapp(Optional.empty());
rapp.setPackageName(rappFile);
if (rappFile.equals(validRappFileNewInfoType)) {
mockServer.verify();
}
if (rappFile.equals(validRappFileNewInfoType)) {
mockServer.verify();
}
- assertEquals(rapp.getIsDmeValid(), result);
- }
-
- private static Stream<Arguments> getSuccessParamsWithAvailableInfoTypes() {
- return Stream.of(Arguments.of(validRappFile, true), Arguments.of(validRappFileNewInfoType, true));
+ assertNull(rapp.getReason());
Rapp rapp = getRapp(Optional.empty());
rapp.setRappResources(rappResources);
assertFalse(dmeDeployer.primeRapp(rapp));
Rapp rapp = getRapp(Optional.empty());
rapp.setRappResources(rappResources);
assertFalse(dmeDeployer.primeRapp(rapp));
- assertFalse(rapp.getIsDmeValid());
+ assertFalse(rapp.getReason().isEmpty());
}
@Test
void testDeprimeRapp() {
Rapp rapp = getRapp(Optional.empty());
}
@Test
void testDeprimeRapp() {
Rapp rapp = getRapp(Optional.empty());
- rapp.setIsDmeValid(true);
assertTrue(dmeDeployer.deprimeRapp(rapp));
assertTrue(dmeDeployer.deprimeRapp(rapp));
- assertNull(rapp.getIsDmeValid());
+ assertNull(rapp.getReason());
UUID rappId = UUID.randomUUID();
String name;
RappState state;
UUID rappId = UUID.randomUUID();
String name;
RappState state;
String packageLocation;
String packageName;
RappResources rappResources;
String packageLocation;
String packageName;
RappResources rappResources;
Map<UUID, RappInstance> rappInstances = new HashMap<>();
UUID compositionId;
Map<UUID, RappInstance> rappInstances = new HashMap<>();
UUID compositionId;
@Autowired
RappCacheService rappCacheService;
@Autowired
RappCacheService rappCacheService;
@Test
void testPutRapp() {
UUID rappId = UUID.randomUUID();
@Test
void testPutRapp() {
UUID rappId = UUID.randomUUID();