SME resources can be provided as optional.
rApp and rApp instances failures are provided in API response.
Issue-ID: NONRTRIC-975
Change-Id: I139fbb23289cb71b0c35187a1135cc1dd3899379
Signed-off-by: aravind.est <aravindhan.a@est.tech>
return ResponseEntity.ok().build();
}
rapp.setState(RappState.COMMISSIONED);
- return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build();
+ throw new RappHandlerException(HttpStatus.BAD_GATEWAY, rapp.getReason());
}
throw new RappHandlerException(HttpStatus.BAD_REQUEST,
String.format(STATE_TRANSITION_NOT_PERMITTED, rapp.getState().name(), RappState.PRIMED.name()));
return ResponseEntity.ok().build();
}
rapp.setState(RappState.PRIMED);
- return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build();
+ throw new RappHandlerException(HttpStatus.BAD_GATEWAY, rapp.getReason());
}
if (!rapp.getRappInstances().isEmpty()) {
throw new RappHandlerException(HttpStatus.BAD_REQUEST,
.allMatch(rappDeployer -> rappDeployer.deployRappInstance(rapp, rappInstance))) {
return ResponseEntity.accepted().build();
}
- return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build();
+ throw new RappHandlerException(HttpStatus.BAD_GATEWAY, rappInstance.getReason());
}
throw new RappHandlerException(HttpStatus.BAD_REQUEST,
String.format("Unable to deploy rApp instance %s as it is not in UNDEPLOYED state",
.allMatch(rappDeployer -> rappDeployer.undeployRappInstance(rapp, rappInstance))) {
return ResponseEntity.accepted().build();
}
- return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build();
+ throw new RappHandlerException(HttpStatus.BAD_GATEWAY, rappInstance.getReason());
}
throw new RappHandlerException(HttpStatus.BAD_REQUEST,
String.format("Unable to undeploy rApp instance %s as it is not in DEPLOYED state",
.packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
when(acmDeployer.primeRapp(any())).thenReturn(false);
when(dmeDeployer.primeRapp(any())).thenReturn(true);
- assertEquals(HttpStatus.BAD_GATEWAY, rappService.primeRapp(rapp).getStatusCode());
+ RappHandlerException rappHandlerException =
+ assertThrows(RappHandlerException.class, () -> rappService.primeRapp(rapp));
+ assertEquals(HttpStatus.BAD_GATEWAY, rappHandlerException.getStatusCode());
assertEquals(RappState.COMMISSIONED, rapp.getState());
}
.packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
when(acmDeployer.primeRapp(any())).thenReturn(true);
when(dmeDeployer.primeRapp(any())).thenReturn(false);
- assertEquals(HttpStatus.BAD_GATEWAY, rappService.primeRapp(rapp).getStatusCode());
+ RappHandlerException rappHandlerException =
+ assertThrows(RappHandlerException.class, () -> rappService.primeRapp(rapp));
+ assertEquals(HttpStatus.BAD_GATEWAY, rappHandlerException.getStatusCode());
assertEquals(RappState.COMMISSIONED, rapp.getState());
}
.packageLocation(validCsarFileLocation).state(RappState.PRIMED).build();
when(acmDeployer.deprimeRapp(any())).thenReturn(false);
when(dmeDeployer.deprimeRapp(any())).thenReturn(true);
- assertEquals(HttpStatus.BAD_GATEWAY, rappService.deprimeRapp(rapp).getStatusCode());
+ RappHandlerException rappHandlerException =
+ assertThrows(RappHandlerException.class, () -> rappService.deprimeRapp(rapp));
+ assertEquals(HttpStatus.BAD_GATEWAY, rappHandlerException.getStatusCode());
assertEquals(RappState.PRIMED, rapp.getState());
}
.packageLocation(validCsarFileLocation).state(RappState.PRIMED).build();
when(acmDeployer.deprimeRapp(any())).thenReturn(true);
when(dmeDeployer.deprimeRapp(any())).thenReturn(false);
- assertEquals(HttpStatus.BAD_GATEWAY, rappService.deprimeRapp(rapp).getStatusCode());
+ RappHandlerException rappHandlerException =
+ assertThrows(RappHandlerException.class, () -> rappService.deprimeRapp(rapp));
+ assertEquals(HttpStatus.BAD_GATEWAY, rappHandlerException.getStatusCode());
assertEquals(RappState.PRIMED, rapp.getState());
}
when(acmDeployer.deployRappInstance(any(), any())).thenReturn(true);
when(smeDeployer.deployRappInstance(any(), any())).thenReturn(false);
when(dmeDeployer.deployRappInstance(any(), any())).thenReturn(true);
- assertEquals(HttpStatus.BAD_GATEWAY, rappService.deployRappInstance(rapp, rappInstance).getStatusCode());
+ RappHandlerException rappHandlerException =
+ assertThrows(RappHandlerException.class, () -> rappService.deployRappInstance(rapp, rappInstance));
+ assertEquals(HttpStatus.BAD_GATEWAY, rappHandlerException.getStatusCode());
}
@Test
when(acmDeployer.undeployRappInstance(any(), any())).thenReturn(true);
when(smeDeployer.undeployRappInstance(any(), any())).thenReturn(false);
when(dmeDeployer.undeployRappInstance(any(), any())).thenReturn(true);
- assertEquals(HttpStatus.BAD_GATEWAY, rappService.undeployRappInstance(rapp, rappInstance).getStatusCode());
+ RappHandlerException rappHandlerException =
+ assertThrows(RappHandlerException.class, () -> rappService.undeployRappInstance(rapp, rappInstance));
+ assertEquals(HttpStatus.BAD_GATEWAY, rappHandlerException.getStatusCode());
}
@Test
/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2023 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2024 OpenInfra Foundation Europe. 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.
public boolean deployRappInstance(Rapp rapp, RappInstance rappInstance) {
logger.debug("Deploying SME functions for RappInstance {}", rappInstance.getRappInstanceId());
if (rappInstance.isSMEEnabled()) {
- if (createProviderDomain(rapp, rappInstance) && createPublishApi(rapp, rappInstance) && createInvoker(rapp,
- rappInstance)) {
+ if ((rappInstance.getSme().getProviderFunction() == null || createProviderDomain(rapp, rappInstance)) && (
+ rappInstance.getSme().getServiceApis() == null || createPublishApi(rapp, rappInstance)) && (
+ rappInstance.getSme().getInvokers() == null || createInvoker(rapp, rappInstance))) {
rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEDEPLOYED);
return true;
}
logger.debug("Undeploying SME functions for Rapp {}", rapp.getName());
if (rappInstance.isSMEEnabled()) {
try {
- rappInstance.getSme().getInvokerIds().forEach(this::deleteInvoker);
- rappInstance.getSme().getServiceApiIds()
- .forEach(s -> deletePublishApi(s, rappInstance.getSme().getApfId()));
- rappInstance.getSme().getProviderFunctionIds().forEach(this::deleteProviderFunc);
+ Optional.ofNullable(rappInstance.getSme().getInvokerIds())
+ .ifPresent(invokerList -> invokerList.forEach(this::deleteInvoker));
+ Optional.ofNullable(rappInstance.getSme().getServiceApiIds()).ifPresent(
+ serviceApiList -> serviceApiList.forEach(
+ s -> deletePublishApi(s, rappInstance.getSme().getApfId())));
+ Optional.ofNullable(rappInstance.getSme().getProviderFunctionIds())
+ .ifPresent(providerList -> providerList.forEach(this::deleteProviderFunc));
rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEUNDEPLOYED);
return true;
} catch (Exception e) {
/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2023 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2024 OpenInfra Foundation Europe. 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.
}
@Test
- void testCreateProviderDomainFailure() throws Exception {
+ void testCreateProviderDomainFailure() {
UUID rappId = UUID.randomUUID();
Rapp rapp =
Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
@Test
- void testCreatePublishApiFailure() throws Exception {
+ void testCreatePublishApiFailure() {
UUID rappId = UUID.randomUUID();
UUID apfId = UUID.randomUUID();
Rapp rapp =
}
@Test
- void testDeployRappInstanceWithoutSme() throws Exception {
+ void testDeployRappInstanceNoInvoker() throws Exception {
+ UUID rappId = UUID.randomUUID();
+ APIProviderEnrolmentDetails apiProviderEnrolmentDetails = getProviderDomainApiEnrollmentDetails();
+ APIProviderFunctionDetails apfProviderFunctionDetails = apiProviderEnrolmentDetails.getApiProvFuncs().stream()
+ .filter(apiProviderFunctionDetails -> apiProviderFunctionDetails.getApiProvFuncRole()
+ .equals(ApiProviderFuncRole.APF))
+ .findFirst().get();
+ Rapp rapp =
+ Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
+ .state(RappState.COMMISSIONED).build();
+ mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
+ .andExpect(method(HttpMethod.POST)).andRespond(
+ withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
+ .body(objectMapper.writeValueAsString(apiProviderEnrolmentDetails)));
+ ServiceAPIDescription serviceAPIDescription = getServiceApiDescription();
+ mockServer.expect(ExpectedCount.once(),
+ requestTo(String.format(URI_PUBLISH_APIS, apfProviderFunctionDetails.getApiProvFuncId())))
+ .andExpect(method(HttpMethod.POST)).andRespond(
+ withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
+ .body(objectMapper.writeValueAsString(serviceAPIDescription)));
+ RappInstance rappInstance = getRappInstance();
+ rappInstance.getSme().setInvokers(null);
+ rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId());
+ boolean deployRapp = smeDeployer.deployRappInstance(rapp, rappInstance);
+ mockServer.verify();
+ assertTrue(deployRapp);
+ }
+
+ @Test
+ void testDeployRappInstanceNoProvider() throws Exception {
+ UUID rappId = UUID.randomUUID();
+ Rapp rapp =
+ Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
+ .state(RappState.COMMISSIONED).build();
+ APIInvokerEnrolmentDetails apiInvokerEnrolmentDetails = getApiInvokerEnrollmentDetails();
+ mockServer.expect(ExpectedCount.once(), requestTo(URI_INVOKERS)).andExpect(method(HttpMethod.POST)).andRespond(
+ withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
+ .body(objectMapper.writeValueAsString(apiInvokerEnrolmentDetails)));
+ RappInstance rappInstance = getRappInstance();
+ rappInstance.getSme().setProviderFunction(null);
+ rappInstance.getSme().setServiceApis(null);
+ rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId());
+ boolean deployRapp = smeDeployer.deployRappInstance(rapp, rappInstance);
+ mockServer.verify();
+ assertTrue(deployRapp);
+ }
+
+ @Test
+ void testDeployRappInstanceWithoutSme() {
UUID rappId = UUID.randomUUID();
Rapp rapp =
Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
assertTrue(undeployRapp);
}
+ @Test
+ void testUndeployRappInstanceNoInvokers() {
+ UUID rappId = UUID.randomUUID();
+ UUID apfId = UUID.randomUUID();
+ List<String> serviceApis = List.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
+ Map<String, String> providerFuncs = Map.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()),
+ String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
+ Rapp rapp = Rapp.builder().rappId(rappId).name(rappId.toString()).packageName(validRappFile)
+ .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
+ mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_API, apfId, serviceApis.get(0))))
+ .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
+ mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_API, apfId, serviceApis.get(1))))
+ .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
+ mockServer.expect(ExpectedCount.once(),
+ requestTo(String.format(URI_PROVIDER_REGISTRATION, providerFuncs.values().toArray()[0])))
+ .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
+ mockServer.expect(ExpectedCount.once(),
+ requestTo(String.format(URI_PROVIDER_REGISTRATION, providerFuncs.values().toArray()[1])))
+ .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
+ RappInstance rappInstance = getRappInstance();
+ rappInstance.getSme().setApfId(String.valueOf(apfId));
+ rappInstance.getSme().setProviderFunctionIds(providerFuncs.values().stream().toList());
+ rappInstance.getSme().setServiceApiIds(serviceApis);
+ rappInstance.getSme().setInvokerIds(null);
+ rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId());
+ boolean undeployRapp = smeDeployer.undeployRappInstance(rapp, rappInstance);
+ mockServer.verify();
+ assertTrue(undeployRapp);
+ }
+
+ @Test
+ void testUndeployRappInstanceNoProviders() {
+ UUID rappId = UUID.randomUUID();
+ UUID apfId = UUID.randomUUID();
+ List<String> invokers = List.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
+ Rapp rapp = Rapp.builder().rappId(rappId).name(rappId.toString()).packageName(validRappFile)
+ .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
+ mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INVOKER, invokers.get(0))))
+ .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
+ mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INVOKER, invokers.get(1))))
+ .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
+ RappInstance rappInstance = getRappInstance();
+ rappInstance.getSme().setApfId(String.valueOf(apfId));
+ rappInstance.getSme().setProviderFunctionIds(null);
+ rappInstance.getSme().setServiceApiIds(null);
+ rappInstance.getSme().setInvokerIds(invokers);
+ rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId());
+ boolean undeployRapp = smeDeployer.undeployRappInstance(rapp, rappInstance);
+ mockServer.verify();
+ assertTrue(undeployRapp);
+ }
+
@Test
void testUndeployRappInstanceWithoutSme() {
UUID rappId = UUID.randomUUID();