From: aravind.est Date: Thu, 25 Jan 2024 12:42:47 +0000 (+0000) Subject: Support for optional rApp and rApp instance parameters X-Git-Tag: 0.1.0~37 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=fc63eb0da4e4426fbfbecdd4f95bec68ca3ceded;hp=77a08f7b9a97e0c6fcce5729cdcc3c18ea90c002;p=nonrtric%2Fplt%2Frappmanager.git Support for optional rApp and rApp instance parameters ACM is mandatory for rApp and rApp instance. DME and SME can be optional in rApp and rApp instance. Issue-ID: NONRTRIC-930 Change-Id: I895f585146316eb7da0719658bb527ce66bcb187 Signed-off-by: aravind.est --- diff --git a/rapp-manager-acm/src/main/java/com/oransc/rappmanager/acm/service/AcmDeployer.java b/rapp-manager-acm/src/main/java/com/oransc/rappmanager/acm/service/AcmDeployer.java index dea83a4..c1a035c 100755 --- a/rapp-manager-acm/src/main/java/com/oransc/rappmanager/acm/service/AcmDeployer.java +++ b/rapp-manager-acm/src/main/java/com/oransc/rappmanager/acm/service/AcmDeployer.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START====================================================================== * Copyright (C) 2023 Nordix Foundation. All rights reserved. - * Copyright (C) 2023 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2023-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. @@ -138,7 +138,9 @@ public class AcmDeployer implements RappDeployer { rapp.getCompositionId()); AutomationComposition automationComposition = gson.fromJson(instantiationPayload, AutomationComposition.class); - dmeAcmInterceptor.injectAutomationComposition(automationComposition, rapp, rappInstance); + if (rappInstance.isDMEEnabled()) { + dmeAcmInterceptor.injectAutomationComposition(automationComposition, rapp, rappInstance); + } InstantiationResponse instantiationResponse = automationCompositionInstanceApiClient.createCompositionInstance(rapp.getCompositionId(), diff --git a/rapp-manager-acm/src/test/java/com/oransc/rappmanager/acm/service/AcmDeployerTest.java b/rapp-manager-acm/src/test/java/com/oransc/rappmanager/acm/service/AcmDeployerTest.java index aab5f34..30c77a1 100755 --- a/rapp-manager-acm/src/test/java/com/oransc/rappmanager/acm/service/AcmDeployerTest.java +++ b/rapp-manager-acm/src/test/java/com/oransc/rappmanager/acm/service/AcmDeployerTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START====================================================================== * Copyright (C) 2023 Nordix Foundation. All rights reserved. - * Copyright (C) 2023 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2023-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. @@ -163,7 +163,6 @@ class AcmDeployerTest { void testDeployRappInstance() throws Exception { UUID compositionId = UUID.randomUUID(); - UUID rappId = UUID.randomUUID(); UUID instanceId = UUID.randomUUID(); Rapp rapp = Rapp.builder().name("").packageName(validRappFile).compositionId(compositionId) .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build(); @@ -183,10 +182,33 @@ class AcmDeployerTest { mockServer.verify(); } + @Test + void testDeployRappInstanceWithoutDmeInjection() throws Exception { + + UUID compositionId = UUID.randomUUID(); + UUID instanceId = UUID.randomUUID(); + Rapp rapp = Rapp.builder().name("").packageName(validRappFile).compositionId(compositionId) + .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build(); + RappInstance rappInstance = rappResourceBuilder.getRappInstance(); + rappInstance.setDme(null); + rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); + InstantiationResponse instantiationResponse = new InstantiationResponse(); + instantiationResponse.setInstanceId(instanceId); + mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_ACM_INSTANCES, compositionId))) + .andExpect(method(HttpMethod.POST)).andRespond( + withStatus(HttpStatus.ACCEPTED).contentType(MediaType.APPLICATION_JSON) + .body(objectMapper.writeValueAsString(instantiationResponse))); + mockServer.expect(ExpectedCount.once(), + requestTo(acmConfiguration.getBaseUrl() + "compositions/" + compositionId + "/instances/" + instanceId)) + .andExpect(method(HttpMethod.PUT)).andRespond(withStatus(HttpStatus.ACCEPTED)); + boolean rappDeployStateActual = acmDeployer.deployRappInstance(rapp, rappInstance); + assertTrue(rappDeployStateActual); + mockServer.verify(); + } + @Test void testDeployRappInstanceFailureWithNoInstanceId() throws JsonProcessingException { UUID compositionId = UUID.randomUUID(); - UUID rappId = UUID.randomUUID(); Rapp rapp = Rapp.builder().name("").packageName(validRappFile).compositionId(compositionId) .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build(); RappInstance rappInstance = rappResourceBuilder.getRappInstance(); @@ -205,7 +227,6 @@ class AcmDeployerTest { @Test void testDeployRappInstanceFailure() { UUID compositionId = UUID.randomUUID(); - UUID rappId = UUID.randomUUID(); Rapp rapp = Rapp.builder().name("").packageName(validRappFile).compositionId(compositionId) .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build(); RappInstance rappInstance = rappResourceBuilder.getRappInstance(); diff --git a/rapp-manager-application/src/main/java/com/oransc/rappmanager/service/RappService.java b/rapp-manager-application/src/main/java/com/oransc/rappmanager/service/RappService.java index 9fddd4d..1e606d1 100755 --- a/rapp-manager-application/src/main/java/com/oransc/rappmanager/service/RappService.java +++ b/rapp-manager-application/src/main/java/com/oransc/rappmanager/service/RappService.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START====================================================================== * Copyright (C) 2023 Nordix Foundation. All rights reserved. - * Copyright (C) 2023 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2023-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. @@ -20,7 +20,7 @@ package com.oransc.rappmanager.service; import com.oransc.rappmanager.acm.service.AcmDeployer; -import com.oransc.rappmanager.dme.service.DmeDeployer; +import com.oransc.rappmanager.models.RappDeployer; import com.oransc.rappmanager.models.cache.RappCacheService; import com.oransc.rappmanager.models.exception.RappHandlerException; import com.oransc.rappmanager.models.rapp.Rapp; @@ -29,7 +29,7 @@ import com.oransc.rappmanager.models.rapp.RappState; import com.oransc.rappmanager.models.rappinstance.RappInstance; import com.oransc.rappmanager.models.rappinstance.RappInstanceState; import com.oransc.rappmanager.models.statemachine.RappInstanceStateMachine; -import com.oransc.rappmanager.sme.service.SmeDeployer; +import java.util.List; import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -41,8 +41,7 @@ import org.springframework.stereotype.Service; public class RappService { private final AcmDeployer acmDeployer; - private final SmeDeployer smeDeployer; - private final DmeDeployer dmeDeployer; + private final List rappDeployers; private final RappInstanceStateMachine rappInstanceStateMachine; private final RappCacheService rappCacheService; private static final String STATE_TRANSITION_NOT_PERMITTED = "State transition from %s to %s is not permitted."; @@ -51,7 +50,7 @@ public class RappService { if (rapp.getState().equals(RappState.COMMISSIONED)) { rapp.setState(RappState.PRIMING); rapp.setReason(null); - if (acmDeployer.primeRapp(rapp) && dmeDeployer.primeRapp(rapp)) { + if (rappDeployers.parallelStream().allMatch(rappDeployer -> rappDeployer.primeRapp(rapp))) { rapp.setState(RappState.PRIMED); return ResponseEntity.ok().build(); } @@ -67,7 +66,7 @@ public class RappService { if (rapp.getState().equals(RappState.PRIMED) && rapp.getRappInstances().isEmpty()) { rapp.setState(RappState.DEPRIMING); rapp.setReason(null); - if (acmDeployer.deprimeRapp(rapp) && dmeDeployer.deprimeRapp(rapp)) { + if (rappDeployers.parallelStream().allMatch(rappDeployer -> rappDeployer.deprimeRapp(rapp))) { rapp.setState(RappState.COMMISSIONED); return ResponseEntity.ok().build(); } @@ -103,8 +102,8 @@ public class RappService { if (rappInstance.getState().equals(RappInstanceState.UNDEPLOYED)) { rappInstance.setReason(null); rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.DEPLOYING); - if (acmDeployer.deployRappInstance(rapp, rappInstance) && smeDeployer.deployRappInstance(rapp, - rappInstance)) { + if (rappDeployers.parallelStream() + .allMatch(rappDeployer -> rappDeployer.deployRappInstance(rapp, rappInstance))) { return ResponseEntity.accepted().build(); } return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build(); @@ -119,8 +118,8 @@ public class RappService { if (rappInstance.getState().equals(RappInstanceState.DEPLOYED)) { rappInstance.setReason(null); rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.UNDEPLOYING); - if (acmDeployer.undeployRappInstance(rapp, rappInstance) && smeDeployer.undeployRappInstance(rapp, - rappInstance)) { + if (rappDeployers.parallelStream() + .allMatch(rappDeployer -> rappDeployer.undeployRappInstance(rapp, rappInstance))) { return ResponseEntity.accepted().build(); } return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build(); diff --git a/rapp-manager-application/src/test/java/com/oransc/rappmanager/service/RappServiceTest.java b/rapp-manager-application/src/test/java/com/oransc/rappmanager/service/RappServiceTest.java index 7bf8adb..29e0245 100755 --- a/rapp-manager-application/src/test/java/com/oransc/rappmanager/service/RappServiceTest.java +++ b/rapp-manager-application/src/test/java/com/oransc/rappmanager/service/RappServiceTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START====================================================================== * Copyright (C) 2023 Nordix Foundation. All rights reserved. - * Copyright (C) 2023 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2023-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. @@ -79,6 +79,7 @@ class RappServiceTest { .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build(); when(acmDeployer.primeRapp(any())).thenReturn(true); when(dmeDeployer.primeRapp(any())).thenReturn(true); + when(smeDeployer.primeRapp(any())).thenReturn(true); assertEquals(HttpStatus.OK, rappService.primeRapp(rapp).getStatusCode()); assertEquals(RappState.PRIMED, rapp.getState()); } @@ -122,6 +123,7 @@ class RappServiceTest { .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build(); when(acmDeployer.deprimeRapp(any())).thenReturn(true); when(dmeDeployer.deprimeRapp(any())).thenReturn(true); + when(smeDeployer.deprimeRapp(any())).thenReturn(true); assertEquals(HttpStatus.OK, rappService.deprimeRapp(rapp).getStatusCode()); assertEquals(RappState.COMMISSIONED, rapp.getState()); } diff --git a/rapp-manager-dme/src/main/java/com/oransc/rappmanager/dme/service/DmeDeployer.java b/rapp-manager-dme/src/main/java/com/oransc/rappmanager/dme/service/DmeDeployer.java index a57f9b4..901b0e2 100755 --- a/rapp-manager-dme/src/main/java/com/oransc/rappmanager/dme/service/DmeDeployer.java +++ b/rapp-manager-dme/src/main/java/com/oransc/rappmanager/dme/service/DmeDeployer.java @@ -1,6 +1,7 @@ /*- * ============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. @@ -20,25 +21,17 @@ package com.oransc.rappmanager.dme.service; import com.fasterxml.jackson.databind.ObjectMapper; import com.oransc.rappmanager.dme.data.ConsumerJob; -import com.oransc.rappmanager.dme.data.ProducerInfoTypeInfo; import com.oransc.rappmanager.dme.data.ProducerRegistrationInfo; -import com.oransc.rappmanager.dme.rest.DataConsumerApiClient; import com.oransc.rappmanager.dme.rest.DataProducerRegistrationApiClient; import com.oransc.rappmanager.models.RappDeployer; import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler; import com.oransc.rappmanager.models.rapp.Rapp; -import com.oransc.rappmanager.models.rapp.RappEvent; import com.oransc.rappmanager.models.rappinstance.RappInstance; -import com.oransc.rappmanager.models.statemachine.RappInstanceStateMachine; -import java.util.HashMap; import java.util.HashSet; -import java.util.Map; import java.util.Set; -import java.util.function.BiFunction; import lombok.RequiredArgsConstructor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @Service @@ -49,94 +42,63 @@ public class DmeDeployer implements RappDeployer { private final DataProducerRegistrationApiClient dataProducerRegistrationApiClient; - private final DataConsumerApiClient dataConsumerApiClient; - private final RappCsarConfigurationHandler rappCsarConfigurationHandler; private final ObjectMapper objectMapper; - private final RappInstanceStateMachine rappInstanceStateMachine; - @Override public boolean deployRappInstance(Rapp rapp, RappInstance rappInstance) { - logger.debug("Deploying DME functions for RappInstance {}", rappInstance.getRappInstanceId()); - boolean deployState = true; - if (rappInstance.getDme().getInfoTypesProducer() != null) { - deployState = createProducerInfoTypes(rapp, rappInstance.getDme().getInfoTypesProducer()); - } - if (rappInstance.getDme().getInfoTypeConsumer() != null) { - deployState = - deployState && createConsumerInfoTypes(rapp, Set.of(rappInstance.getDme().getInfoTypeConsumer())); - } - if (rappInstance.getDme().getInfoProducer() != null) { - deployState = deployState && createInfoProducer(rapp, rappInstance.getDme().getInfoProducer()); - } - if (rappInstance.getDme().getInfoConsumer() != null) { - deployState = deployState && createInfoConsumer(rapp, rappInstance.getDme().getInfoConsumer()); - } - if (deployState) { - rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.DMEDEPLOYED); - } else { - rappInstance.setReason("Unable to deploy DME"); - rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.DMEDEPLOYFAILED); - } - return deployState; + logger.debug("DME instance deployment is handled as part of ACM injection for {}", + rappInstance.getRappInstanceId()); + return true; } @Override public boolean undeployRappInstance(Rapp rapp, RappInstance rappInstance) { - logger.debug("Undeploying DME functions for RappInstance {}", rappInstance.getRappInstanceId()); - boolean undeployState = true; - if (rappInstance.getDme().getInfoConsumer() != null) { - undeployState = deleteInfoConsumer(rapp, rappInstance.getDme().getInfoConsumer()); - } - if (rappInstance.getDme().getInfoProducer() != null) { - undeployState = undeployState && deleteInfoProducer(rapp, rappInstance.getDme().getInfoProducer()); - } - if (undeployState) { - rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.DMEUNDEPLOYED); - } else { - rappInstance.setReason("Unable to undeploy DME"); - rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.DMEUNDEPLOYFAILED); - } - return undeployState; + logger.debug("DME instance undeployment is handled as part of ACM injection for {}", + rappInstance.getRappInstanceId()); + return true; } @Override public boolean primeRapp(Rapp rapp) { logger.debug("Priming DME functions for rApp {}", rapp.getRappId()); - try { - Set requiredInfoTypes = new HashSet<>(); - for (String producerResourceName : rapp.getRappResources().getDme().getInfoProducers()) { - String producerPayload = - rappCsarConfigurationHandler.getDmeInfoProducerPayload(rapp, producerResourceName); - ProducerRegistrationInfo producerRegistrationInfo = - objectMapper.readValue(producerPayload, ProducerRegistrationInfo.class); - requiredInfoTypes.addAll(producerRegistrationInfo.getSupportedInfoTypes()); - } - for (String consumerResourceName : rapp.getRappResources().getDme().getInfoConsumers()) { - String consumerPayload = - rappCsarConfigurationHandler.getDmeInfoConsumerPayload(rapp, consumerResourceName); - ConsumerJob consumerJob = objectMapper.readValue(consumerPayload, ConsumerJob.class); - requiredInfoTypes.add(consumerJob.getInfoTypeId()); - } - Set allInfoTypes = new HashSet<>(rapp.getRappResources().getDme().getProducerInfoTypes()); - allInfoTypes.addAll(rapp.getRappResources().getDme().getConsumerInfoTypes()); - requiredInfoTypes.removeAll(allInfoTypes); - if (!requiredInfoTypes.isEmpty()) { - allInfoTypes.addAll(dataProducerRegistrationApiClient.getInfoTypdentifiers()); + if (rapp.isDMEEnabled()) { + try { + Set requiredInfoTypes = new HashSet<>(); + for (String producerResourceName : rapp.getRappResources().getDme().getInfoProducers()) { + String producerPayload = + rappCsarConfigurationHandler.getDmeInfoProducerPayload(rapp, producerResourceName); + ProducerRegistrationInfo producerRegistrationInfo = + objectMapper.readValue(producerPayload, ProducerRegistrationInfo.class); + requiredInfoTypes.addAll(producerRegistrationInfo.getSupportedInfoTypes()); + } + for (String consumerResourceName : rapp.getRappResources().getDme().getInfoConsumers()) { + String consumerPayload = + rappCsarConfigurationHandler.getDmeInfoConsumerPayload(rapp, consumerResourceName); + ConsumerJob consumerJob = objectMapper.readValue(consumerPayload, ConsumerJob.class); + requiredInfoTypes.add(consumerJob.getInfoTypeId()); + } + Set allInfoTypes = new HashSet<>(rapp.getRappResources().getDme().getProducerInfoTypes()); + allInfoTypes.addAll(rapp.getRappResources().getDme().getConsumerInfoTypes()); requiredInfoTypes.removeAll(allInfoTypes); if (!requiredInfoTypes.isEmpty()) { - rapp.setReason(String.format("Invalid rapp package as the following info types cannot be found %s", - requiredInfoTypes)); + allInfoTypes.addAll(dataProducerRegistrationApiClient.getInfoTypdentifiers()); + requiredInfoTypes.removeAll(allInfoTypes); + if (!requiredInfoTypes.isEmpty()) { + rapp.setReason( + String.format("Invalid rapp package as the following info types cannot be found %s", + requiredInfoTypes)); + } } + return true; + } catch (Exception e) { + logger.warn("Failed to prime DME", e); + rapp.setReason("Failed to prime DME"); + return false; } - return true; - } catch (Exception e) { - logger.warn("Failed to prime DME", e); - rapp.setReason("Failed to prime DME"); - return false; } + return true; } @Override @@ -144,90 +106,4 @@ public class DmeDeployer implements RappDeployer { logger.debug("Depriming DME functions for rApp {}", rapp.getRappId()); return true; } - - boolean createProducerInfoTypes(Rapp rApp, Set infoTypes) { - logger.debug("Creating DME producer info types {} for rApp {}", infoTypes, rApp.getRappId()); - return createInfoTypes(rApp, infoTypes, rappCsarConfigurationHandler::getDmeProducerInfoTypePayload); - } - - boolean createConsumerInfoTypes(Rapp rApp, Set infoTypes) { - logger.debug("Creating DME consumer info types {} for rApp {}", infoTypes, rApp.getRappId()); - return createInfoTypes(rApp, infoTypes, rappCsarConfigurationHandler::getDmeConsumerInfoTypePayload); - } - - boolean createInfoTypes(Rapp rApp, Set infoTypes, BiFunction payloadReader) { - try { - Map producerInfoTypeInfoMap = new HashMap<>(); - for (String infoType : infoTypes) { - String infoTypePayload = payloadReader.apply(rApp, infoType); - if (infoTypePayload != null && !infoTypePayload.isEmpty()) { - producerInfoTypeInfoMap.put(infoType, - objectMapper.readValue(infoTypePayload, ProducerInfoTypeInfo.class)); - } - } - return producerInfoTypeInfoMap.entrySet().stream().map(stringProducerInfoTypeInfoEntry -> { - ResponseEntity objectResponseEntity = dataProducerRegistrationApiClient.putInfoTypeWithHttpInfo( - stringProducerInfoTypeInfoEntry.getKey(), stringProducerInfoTypeInfoEntry.getValue()); - return objectResponseEntity.getStatusCode().is2xxSuccessful(); - }).reduce(true, (a, b) -> a && b); - } catch (Exception e) { - logger.warn("Error in creating info types {} for rApp {}", infoTypes, rApp.getRappId(), e); - return false; - } - } - - boolean createInfoProducer(Rapp rApp, String producerResource) { - logger.debug("Creating DME info producer {} for rApp {}", producerResource, rApp.getRappId()); - try { - String infoProducerPayload = rappCsarConfigurationHandler.getDmeInfoProducerPayload(rApp, producerResource); - ProducerRegistrationInfo producerRegistrationInfo = - objectMapper.readValue(infoProducerPayload, ProducerRegistrationInfo.class); - - ResponseEntity objectResponseEntity = - dataProducerRegistrationApiClient.putInfoProducerWithHttpInfo(producerResource, - producerRegistrationInfo); - return objectResponseEntity.getStatusCode().is2xxSuccessful(); - } catch (Exception e) { - logger.warn("Error in creating info producer {} for rApp {}", producerResource, rApp.getRappId(), e); - return false; - } - } - - boolean createInfoConsumer(Rapp rApp, String consumerResource) { - logger.debug("Creating DME info consumer {} for rApp {}", consumerResource, rApp.getRappId()); - try { - String infoJobPayload = rappCsarConfigurationHandler.getDmeInfoConsumerPayload(rApp, consumerResource); - ConsumerJob consumerJob = objectMapper.readValue(infoJobPayload, ConsumerJob.class); - ResponseEntity objectResponseEntity = - dataConsumerApiClient.putIndividualInfoJobWithHttpInfo(consumerResource, consumerJob); - return objectResponseEntity.getStatusCode().is2xxSuccessful(); - } catch (Exception e) { - logger.warn("Error in creating info consumer {} for rApp {}", consumerResource, rApp.getRappId(), e); - return false; - } - } - - boolean deleteInfoProducer(Rapp rApp, String producerResource) { - logger.debug("Deleting DME info producer {} for rApp {}", producerResource, rApp.getRappId()); - try { - ResponseEntity objectResponseEntity = - dataProducerRegistrationApiClient.deleteInfoProducerWithHttpInfo(producerResource); - return objectResponseEntity.getStatusCode().is2xxSuccessful(); - } catch (Exception e) { - logger.warn("Error in deleting info producer {} for rApp {}", producerResource, rApp.getRappId(), e); - return false; - } - } - - boolean deleteInfoConsumer(Rapp rApp, String consumerResource) { - logger.debug("Deleting DME info consumer {} for rApp {}", consumerResource, rApp.getRappId()); - try { - ResponseEntity objectResponseEntity = - dataConsumerApiClient.deleteIndividualInfoJobWithHttpInfo(consumerResource); - return objectResponseEntity.getStatusCode().is2xxSuccessful(); - } catch (Exception e) { - logger.warn("Error in deleting info consumer {} for rApp {}", consumerResource, rApp.getRappId(), e); - return false; - } - } } diff --git a/rapp-manager-dme/src/test/java/com/oransc/rappmanager/dme/service/DmeDeployerTest.java b/rapp-manager-dme/src/test/java/com/oransc/rappmanager/dme/service/DmeDeployerTest.java index e85fbe3..acbf697 100755 --- a/rapp-manager-dme/src/test/java/com/oransc/rappmanager/dme/service/DmeDeployerTest.java +++ b/rapp-manager-dme/src/test/java/com/oransc/rappmanager/dme/service/DmeDeployerTest.java @@ -1,6 +1,7 @@ /*- * ============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. @@ -77,8 +78,6 @@ class DmeDeployerTest { RestTemplate restTemplate; @Autowired DmeConfiguration dmeConfiguration; - @SpyBean - RappInstanceStateMachine rappInstanceStateMachine; RappDmeResourceBuilder rappDmeResourceBuilder = new RappDmeResourceBuilder(); @@ -147,6 +146,16 @@ class DmeDeployerTest { assertNull(rapp.getReason()); } + @Test + void testPrimeRappWithoutDme() throws JsonProcessingException { + RappResources rappResources = rappDmeResourceBuilder.getResources(); + rappResources.setDme(null); + Rapp rapp = getRapp(Optional.empty()); + rapp.setPackageName(validRappFile); + rapp.setRappResources(rappResources); + assertTrue(dmeDeployer.primeRapp(rapp)); + } + @Test void testPrimeRappFailure() { RappResources rappResources = rappDmeResourceBuilder.getResources(); @@ -172,74 +181,7 @@ class DmeDeployerTest { void testDeployrAppInstanceSuccess() { Rapp rapp = getRapp(Optional.empty()); RappInstance rappInstance = rappDmeResourceBuilder.getRappInstance(); - getMockServerClientCreateInfoType(rappInstance.getDme().getInfoTypesProducer().toArray()[0].toString(), true); - getMockServerClientCreateInfoType(rappInstance.getDme().getInfoTypeConsumer(), true); - getMockServerClientCreateInfoProducer(rappInstance.getDme().getInfoProducer(), true); - getMockServerClientCreateInfoConsumer(rappInstance.getDme().getInfoConsumer(), true); - rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); - assertTrue(dmeDeployer.deployRappInstance(rapp, rappInstance)); - mockServer.verify(); - } - - @Test - void testDeployrAppInstanceSuccessWithoutConsumer() { - Rapp rapp = getRapp(Optional.empty()); - RappInstance rappInstance = rappDmeResourceBuilder.getRappInstance(); - rappInstance.getDme().setInfoTypeConsumer(null); - rappInstance.getDme().setInfoConsumer(null); - getMockServerClientCreateInfoType(rappInstance.getDme().getInfoTypesProducer().toArray()[0].toString(), true); - getMockServerClientCreateInfoProducer(rappInstance.getDme().getInfoProducer(), true); - rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); assertTrue(dmeDeployer.deployRappInstance(rapp, rappInstance)); - mockServer.verify(); - } - - @Test - void testDeployrAppInstanceWithoutProducer() { - Rapp rapp = getRapp(Optional.empty()); - RappInstance rappInstance = rappDmeResourceBuilder.getRappInstance(); - rappInstance.getDme().setInfoTypesProducer(null); - rappInstance.getDme().setInfoProducer(null); - getMockServerClientCreateInfoType(rappInstance.getDme().getInfoTypeConsumer(), true); - getMockServerClientCreateInfoConsumer(rappInstance.getDme().getInfoConsumer(), true); - rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); - assertTrue(dmeDeployer.deployRappInstance(rapp, rappInstance)); - mockServer.verify(); - } - - @Test - void testDeployrAppInstanceFailureWithInfoType() { - Rapp rapp = getRapp(Optional.empty()); - RappInstance rappInstance = rappDmeResourceBuilder.getRappInstance(); - getMockServerClientCreateInfoType(rappInstance.getDme().getInfoTypesProducer().toArray()[0].toString(), false); - rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); - assertFalse(dmeDeployer.deployRappInstance(rapp, rappInstance)); - mockServer.verify(); - } - - @Test - void testDeployrAppInstanceFailureWithInfoProducer() { - Rapp rapp = getRapp(Optional.empty()); - RappInstance rappInstance = rappDmeResourceBuilder.getRappInstance(); - getMockServerClientCreateInfoType(rappInstance.getDme().getInfoTypesProducer().toArray()[0].toString(), true); - getMockServerClientCreateInfoType(rappInstance.getDme().getInfoTypeConsumer(), true); - getMockServerClientCreateInfoProducer(rappInstance.getDme().getInfoProducer(), false); - rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); - assertFalse(dmeDeployer.deployRappInstance(rapp, rappInstance)); - mockServer.verify(); - } - - @Test - void testDeployrAppInstanceFailureWithInfoConsumer() { - Rapp rapp = getRapp(Optional.empty()); - RappInstance rappInstance = rappDmeResourceBuilder.getRappInstance(); - getMockServerClientCreateInfoType(rappInstance.getDme().getInfoTypesProducer().toArray()[0].toString(), true); - getMockServerClientCreateInfoType(rappInstance.getDme().getInfoTypeConsumer(), true); - getMockServerClientCreateInfoProducer(rappInstance.getDme().getInfoProducer(), true); - getMockServerClientCreateInfoConsumer(rappInstance.getDme().getInfoConsumer(), false); - rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); - assertFalse(dmeDeployer.deployRappInstance(rapp, rappInstance)); - mockServer.verify(); } @Test @@ -247,109 +189,11 @@ class DmeDeployerTest { Rapp rapp = getRapp(Optional.empty()); rapp.setState(RappState.PRIMED); RappInstance rappInstance = rappDmeResourceBuilder.getRappInstance(); - getMockServerClientDeleteInfoConsumer(rappInstance.getDme().getInfoConsumer(), true); - getMockServerClientDeleteInfoProducer(rappInstance.getDme().getInfoProducer(), true); - rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); assertTrue(dmeDeployer.undeployRappInstance(rapp, rappInstance)); - mockServer.verify(); - } - - - @Test - void testUndeployrAppInstanceFailureWithInfoProducer() { - Rapp rapp = getRapp(Optional.empty()); - rapp.setState(RappState.PRIMED); - RappInstance rappInstance = rappDmeResourceBuilder.getRappInstance(); - getMockServerClientDeleteInfoConsumer(rappInstance.getDme().getInfoConsumer(), true); - getMockServerClientDeleteInfoProducer(rappInstance.getDme().getInfoProducer(), false); - rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); - assertFalse(dmeDeployer.undeployRappInstance(rapp, rappInstance)); - mockServer.verify(); - } - - @Test - void testUndeployrAppInstanceFailureWithInfoConsumer() { - Rapp rapp = getRapp(Optional.empty()); - rapp.setState(RappState.PRIMED); - RappInstance rappInstance = rappDmeResourceBuilder.getRappInstance(); - getMockServerClientDeleteInfoConsumer(rappInstance.getDme().getInfoConsumer(), false); - rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); - assertFalse(dmeDeployer.undeployRappInstance(rapp, rappInstance)); - mockServer.verify(); - } - - @Test - void testCreateInfoTypeFailureInvalidInfoType() { - Rapp rapp = getRapp(Optional.empty()); - assertFalse(dmeDeployer.createProducerInfoTypes(rapp, null)); - assertFalse(dmeDeployer.createConsumerInfoTypes(rapp, null)); - } - - @Test - void testCreateInfoTypeFailureInvalidInfoProducer() { - Rapp rapp = getRapp(Optional.empty()); - assertFalse(dmeDeployer.createInfoProducer(rapp, "")); - } - - @Test - void testCreateInfoTypeFailureInvalidInfoConsumer() { - Rapp rapp = getRapp(Optional.empty()); - assertFalse(dmeDeployer.createInfoConsumer(rapp, "")); } Rapp getRapp(Optional rappOptional) { return Rapp.builder().rappId(rappOptional.orElse(UUID.randomUUID())).name("").packageName(validRappFile) .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build(); } - - void getMockServerClientCreateInfoType(String infoType, boolean isSuccess) { - if (isSuccess) { - mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INFO_TYPE, infoType))) - .andExpect(method(HttpMethod.PUT)).andRespond(withStatus(HttpStatus.CREATED)); - } else { - mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INFO_TYPE, infoType))) - .andExpect(method(HttpMethod.PUT)).andRespond(withStatus(HttpStatus.BAD_GATEWAY)); - } - } - - void getMockServerClientCreateInfoProducer(String infoProducer, boolean isSuccess) { - if (isSuccess) { - mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INFO_PRODUCER, infoProducer))) - .andExpect(method(HttpMethod.PUT)).andRespond(withStatus(HttpStatus.CREATED)); - } else { - mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INFO_PRODUCER, infoProducer))) - .andExpect(method(HttpMethod.PUT)).andRespond(withStatus(HttpStatus.BAD_GATEWAY)); - } - } - - void getMockServerClientCreateInfoConsumer(String infoConsumer, boolean isSuccess) { - if (isSuccess) { - mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INFO_CONSUMER, infoConsumer))) - .andExpect(method(HttpMethod.PUT)).andRespond(withStatus(HttpStatus.CREATED)); - } else { - mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INFO_CONSUMER, infoConsumer))) - .andExpect(method(HttpMethod.PUT)).andRespond(withStatus(HttpStatus.BAD_GATEWAY)); - } - } - - void getMockServerClientDeleteInfoProducer(String infoProducer, boolean isSuccess) { - if (isSuccess) { - mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INFO_PRODUCER, infoProducer))) - .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT)); - } else { - mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INFO_PRODUCER, infoProducer))) - .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.BAD_GATEWAY)); - } - } - - void getMockServerClientDeleteInfoConsumer(String infoConsumer, boolean isSuccess) { - if (isSuccess) { - mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INFO_CONSUMER, infoConsumer))) - .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT)); - } else { - mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INFO_CONSUMER, infoConsumer))) - .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.BAD_GATEWAY)); - } - } - } diff --git a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rapp/Rapp.java b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rapp/Rapp.java index 39e9ec9..d061602 100755 --- a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rapp/Rapp.java +++ b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rapp/Rapp.java @@ -1,6 +1,7 @@ /*- * ============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. @@ -20,9 +21,11 @@ package com.oransc.rappmanager.models.rapp; import com.oransc.rappmanager.models.rappinstance.RappInstance; +import java.beans.Transient; import java.util.HashMap; import java.util.Map; import java.util.UUID; +import java.util.stream.Stream; import lombok.Builder; import lombok.Data; @@ -42,4 +45,24 @@ public class Rapp { Map rappInstances = new HashMap<>(); UUID compositionId; + + @Transient + public boolean isSMEEnabled() { + if (rappResources != null && rappResources.getSme() != null) { + return Stream.of(rappResources.getSme().getInvokers(), rappResources.getSme().getServiceApis(), + rappResources.getSme().getProviderFunctions()).anyMatch(smeResource -> !smeResource.isEmpty()); + } + return false; + + } + + @Transient + public boolean isDMEEnabled() { + if (rappResources != null && rappResources.getDme() != null) { + return Stream.of(rappResources.getDme().getProducerInfoTypes(), + rappResources.getDme().getConsumerInfoTypes(), rappResources.getDme().getInfoProducers(), + rappResources.getDme().getInfoConsumers()).anyMatch(smeResource -> !smeResource.isEmpty()); + } + return false; + } } diff --git a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rappinstance/RappInstance.java b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rappinstance/RappInstance.java index 463baa2..aec6ee2 100755 --- a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rappinstance/RappInstance.java +++ b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rappinstance/RappInstance.java @@ -1,6 +1,7 @@ /*- * ============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. @@ -19,6 +20,7 @@ package com.oransc.rappmanager.models.rappinstance; import java.util.UUID; +import java.util.stream.Stream; import lombok.Data; @Data @@ -30,4 +32,22 @@ public class RappInstance { RappACMInstance acm; RappSMEInstance sme; RappDMEInstance dme; + + public boolean isSMEEnabled() { + if (sme != null) { + return Stream.of(sme.getInvokers(), sme.getServiceApis(), sme.getProviderFunction()) + .anyMatch(smeResource -> smeResource != null && !smeResource.isEmpty()); + } + return false; + } + + public boolean isDMEEnabled() { + if (dme != null) { + return Stream.concat( + dme.getInfoTypesProducer() == null ? Stream.empty() : dme.getInfoTypesProducer().stream(), + Stream.of(dme.getInfoTypeConsumer(), dme.getInfoProducer(), dme.getInfoConsumer())) + .anyMatch(dmeResource -> dmeResource != null && !dmeResource.isEmpty()); + } + return false; + } } diff --git a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachine.java b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachine.java index c4cd18b..b776df7 100755 --- a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachine.java +++ b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachine.java @@ -1,6 +1,7 @@ /*- * ============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. @@ -51,6 +52,10 @@ public class RappInstanceStateMachine { public void sendRappInstanceEvent(RappInstance rappInstance, RappEvent rappEvent) { logger.info("Sending rapp instance event {} for {}", rappEvent.name(), rappInstance.getRappInstanceId()); logger.debug("State machine map is {}", stateMachineMap); + stateMachineMap.get(rappInstance.getRappInstanceId()).getExtendedState().getVariables() + .put("sme", rappInstance.isSMEEnabled()); + stateMachineMap.get(rappInstance.getRappInstanceId()).getExtendedState().getVariables() + .put("dme", rappInstance.isDMEEnabled()); stateMachineMap.get(rappInstance.getRappInstanceId()) .sendEvent(Mono.just(MessageBuilder.withPayload(rappEvent).build())).subscribe(); } diff --git a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachineConfig.java b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachineConfig.java index 34c9a92..d9dbd3a 100755 --- a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachineConfig.java +++ b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachineConfig.java @@ -1,6 +1,7 @@ /*- * ============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. @@ -23,6 +24,7 @@ import com.oransc.rappmanager.models.rappinstance.RappInstanceState; import java.util.EnumSet; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.statemachine.StateContext; import org.springframework.statemachine.config.EnableStateMachineFactory; import org.springframework.statemachine.config.EnumStateMachineConfigurerAdapter; import org.springframework.statemachine.config.builders.StateMachineConfigurationConfigurer; @@ -103,19 +105,33 @@ public class RappInstanceStateMachineConfig extends EnumStateMachineConfigurerAd public Guard deployedGuard() { return stateContext -> { stateContext.getExtendedState().getVariables().put(stateContext.getEvent(), true); - return stateContext.getExtendedState().getVariables().get(RappEvent.ACMDEPLOYED) != null - && stateContext.getExtendedState().getVariables().get(RappEvent.SMEDEPLOYED) != null - && stateContext.getExtendedState().getVariables().get(RappEvent.DMEDEPLOYED) != null; + return stateContext.getExtendedState().getVariables().get(RappEvent.ACMDEPLOYED) != null && smeGuard( + stateContext, RappEvent.SMEDEPLOYED) && dmeGuard(stateContext, RappEvent.DMEDEPLOYED); }; } + boolean smeGuard(StateContext stateContext, RappEvent rappEvent) { + Boolean smeEnabled = (Boolean) stateContext.getExtendedState().getVariables().get("sme"); + if (smeEnabled != null && smeEnabled.equals(Boolean.TRUE)) { + return stateContext.getExtendedState().getVariables().get(rappEvent) != null; + } + return true; + } + + boolean dmeGuard(StateContext stateContext, RappEvent rappEvent) { + Boolean dmeEnabled = (Boolean) stateContext.getExtendedState().getVariables().get("dme"); + if (dmeEnabled != null && dmeEnabled.equals(Boolean.TRUE)) { + return stateContext.getExtendedState().getVariables().get(rappEvent) != null; + } + return true; + } + @Bean public Guard undeployedGuard() { return stateContext -> { stateContext.getExtendedState().getVariables().put(stateContext.getEvent(), true); - return stateContext.getExtendedState().getVariables().get(RappEvent.ACMUNDEPLOYED) != null - && stateContext.getExtendedState().getVariables().get(RappEvent.SMEUNDEPLOYED) != null - && stateContext.getExtendedState().getVariables().get(RappEvent.DMEUNDEPLOYED) != null; + return stateContext.getExtendedState().getVariables().get(RappEvent.ACMUNDEPLOYED) != null && smeGuard( + stateContext, RappEvent.SMEUNDEPLOYED) && dmeGuard(stateContext, RappEvent.DMEUNDEPLOYED); }; } } diff --git a/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/RappServiceEnablerTest.java b/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/RappServiceEnablerTest.java new file mode 100755 index 0000000..4c51287 --- /dev/null +++ b/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/RappServiceEnablerTest.java @@ -0,0 +1,161 @@ +/*- + * ============LICENSE_START====================================================================== + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END======================================================================== + */ + +package com.oransc.rappmanager.models; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler; +import com.oransc.rappmanager.models.rapp.Rapp; +import com.oransc.rappmanager.models.rapp.RappResources; +import com.oransc.rappmanager.models.rappinstance.RappACMInstance; +import com.oransc.rappmanager.models.rappinstance.RappDMEInstance; +import com.oransc.rappmanager.models.rappinstance.RappInstance; +import com.oransc.rappmanager.models.rappinstance.RappSMEInstance; +import java.util.Set; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; + +@SpringBootTest +@ContextConfiguration(classes = RappCsarConfigurationHandler.class) +class RappServiceEnablerTest { + + @Autowired + RappCsarConfigurationHandler rappCsarConfigurationHandler; + String validCsarFileLocation = "src/test/resources/"; + private final String validRappFile = "valid-rapp-package.csar"; + + @Test + void testRappIsDmeAndSmeEnabled() { + RappResources rappResources = rappCsarConfigurationHandler.getRappResource( + Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build()); + Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile) + .packageLocation(validCsarFileLocation).build(); + assertTrue(rapp.isDMEEnabled()); + assertTrue(rapp.isSMEEnabled()); + } + + @Test + void testRappIsNotDmeEnabled() { + RappResources rappResources = rappCsarConfigurationHandler.getRappResource( + Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build()); + Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile) + .packageLocation(validCsarFileLocation).build(); + rapp.getRappResources().setDme(null); + assertFalse(rapp.isDMEEnabled()); + } + + @Test + void testRappIsNotSmeEnabled() { + RappResources rappResources = rappCsarConfigurationHandler.getRappResource( + Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build()); + Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile) + .packageLocation(validCsarFileLocation).build(); + rapp.getRappResources().setSme(null); + assertFalse(rapp.isSMEEnabled()); + } + + @Test + void testRappIsNotDmeEnabledWithFolder() { + RappResources rappResources = rappCsarConfigurationHandler.getRappResource( + Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build()); + Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile) + .packageLocation(validCsarFileLocation).build(); + rapp.getRappResources().getDme().setConsumerInfoTypes(Set.of()); + rapp.getRappResources().getDme().setProducerInfoTypes(Set.of()); + rapp.getRappResources().getDme().setInfoConsumers(Set.of()); + rapp.getRappResources().getDme().setInfoProducers(Set.of()); + assertFalse(rapp.isDMEEnabled()); + } + + @Test + void testRappIsNotSmeEnabledWithFolder() { + RappResources rappResources = rappCsarConfigurationHandler.getRappResource( + Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build()); + Rapp rapp = Rapp.builder().name("").rappResources(rappResources).packageName(validRappFile) + .packageLocation(validCsarFileLocation).build(); + rapp.getRappResources().getSme().setProviderFunctions(Set.of()); + rapp.getRappResources().getSme().setServiceApis(Set.of()); + rapp.getRappResources().getSme().setInvokers(Set.of()); + assertFalse(rapp.isSMEEnabled()); + } + + @Test + void testRappInstanceIsDmeAndSmeEnabled() { + RappInstance rappInstance = new RappInstance(); + rappInstance.setAcm(new RappACMInstance()); + RappDMEInstance rappDMEInstance = new RappDMEInstance(); + rappDMEInstance.setInfoTypesProducer(Set.of("prod1", "prod2")); + rappDMEInstance.setInfoTypeConsumer("cons"); + rappInstance.setDme(rappDMEInstance); + RappSMEInstance rappSMEInstance = new RappSMEInstance(); + rappSMEInstance.setProviderFunction("func1"); + rappInstance.setSme(rappSMEInstance); + assertTrue(rappInstance.isDMEEnabled()); + assertTrue(rappInstance.isSMEEnabled()); + } + + @Test + void testRappInstanceIsNotDmeEnabled() { + RappInstance rappInstance = new RappInstance(); + rappInstance.setAcm(new RappACMInstance()); + RappSMEInstance rappSMEInstance = new RappSMEInstance(); + rappSMEInstance.setProviderFunction("func1"); + rappInstance.setSme(rappSMEInstance); + assertFalse(rappInstance.isDMEEnabled()); + } + + @Test + void testRappInstanceIsNotSmeEnabled() { + RappInstance rappInstance = new RappInstance(); + rappInstance.setAcm(new RappACMInstance()); + RappDMEInstance rappDMEInstance = new RappDMEInstance(); + rappDMEInstance.setInfoTypesProducer(Set.of("prod1", "prod2")); + rappDMEInstance.setInfoTypeConsumer("cons"); + rappInstance.setDme(rappDMEInstance); + assertFalse(rappInstance.isSMEEnabled()); + } + + @Test + void testRappInstanceIsNotDmeEnabledWithoutContent() { + RappInstance rappInstance = new RappInstance(); + rappInstance.setAcm(new RappACMInstance()); + RappSMEInstance rappSMEInstance = new RappSMEInstance(); + rappSMEInstance.setProviderFunction("func1"); + rappInstance.setSme(rappSMEInstance); + RappDMEInstance rappDMEInstance = new RappDMEInstance(); + rappInstance.setDme(rappDMEInstance); + assertFalse(rappInstance.isDMEEnabled()); + } + + @Test + void testRappInstanceIsNotSmeEnabledWithoutContent() { + RappInstance rappInstance = new RappInstance(); + rappInstance.setAcm(new RappACMInstance()); + RappDMEInstance rappDMEInstance = new RappDMEInstance(); + rappDMEInstance.setInfoTypesProducer(Set.of("prod1", "prod2")); + rappDMEInstance.setInfoTypeConsumer("cons"); + rappInstance.setDme(rappDMEInstance); + RappSMEInstance rappSMEInstance = new RappSMEInstance(); + rappInstance.setSme(rappSMEInstance); + assertFalse(rappInstance.isSMEEnabled()); + } +} diff --git a/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachineConfigTest.java b/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachineConfigTest.java index 4657c76..1c7b97e 100755 --- a/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachineConfigTest.java +++ b/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachineConfigTest.java @@ -1,6 +1,7 @@ /*- * ============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. @@ -49,6 +50,8 @@ class RappInstanceStateMachineConfigTest { @BeforeEach void getStateMachine() { stateMachine = stateMachineFactory.getStateMachine(UUID.randomUUID()); + stateMachine.getExtendedState().getVariables().put("sme", true); + stateMachine.getExtendedState().getVariables().put("dme", true); stateMachine.startReactively().subscribe(); } @@ -59,7 +62,7 @@ class RappInstanceStateMachineConfigTest { @Test void testOnboardedState() throws Exception { - StateMachineTestPlan plan = + StateMachineTestPlan plan = StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() .expectState(RappInstanceState.UNDEPLOYED).and().build(); plan.test(); @@ -67,7 +70,7 @@ class RappInstanceStateMachineConfigTest { @Test void testDeployingState() throws Exception { - StateMachineTestPlan plan = + StateMachineTestPlan plan = StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().build(); @@ -75,9 +78,9 @@ class RappInstanceStateMachineConfigTest { } @ParameterizedTest - @EnumSource(value = RappEvent.class, names = {"ACMDEPLOYED", "SMEDEPLOYED", "DMEDEPLOYED" }) + @EnumSource(value = RappEvent.class, names = {"ACMDEPLOYED", "SMEDEPLOYED", "DMEDEPLOYED"}) void testIndividualDeployedState(RappEvent rappEvent) throws Exception { - StateMachineTestPlan plan = + StateMachineTestPlan plan = StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() @@ -87,7 +90,7 @@ class RappInstanceStateMachineConfigTest { @Test void testDeployedState() throws Exception { - StateMachineTestPlan plan = + StateMachineTestPlan plan = StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() @@ -98,9 +101,61 @@ class RappInstanceStateMachineConfigTest { plan.test(); } + @Test + void testDeployedStateAcmOnly() throws Exception { + stateMachine.getExtendedState().getVariables().put("sme", false); + stateMachine.getExtendedState().getVariables().put("dme", false); + StateMachineTestPlan plan = + StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() + .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) + .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() + .sendEvent(RappEvent.ACMDEPLOYED).expectState(RappInstanceState.DEPLOYED).expectStateChanged(1) + .and().build(); + plan.test(); + } + + @Test + void testDeployedStateAcmOnlyWithNoKeyReference() throws Exception { + stateMachine.getExtendedState().getVariables().remove("sme"); + stateMachine.getExtendedState().getVariables().remove("dme"); + StateMachineTestPlan plan = + StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() + .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) + .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() + .sendEvent(RappEvent.ACMDEPLOYED).expectState(RappInstanceState.DEPLOYED).expectStateChanged(1) + .and().build(); + plan.test(); + } + + @Test + void testDeployedStateAcmAndSmeOnly() throws Exception { + stateMachine.getExtendedState().getVariables().put("dme", false); + StateMachineTestPlan plan = + StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() + .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) + .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() + .sendEvent(RappEvent.ACMDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() + .sendEvent(RappEvent.SMEDEPLOYED).expectState(RappInstanceState.DEPLOYED).expectStateChanged(1) + .and().build(); + plan.test(); + } + + @Test + void testDeployedStateAcmAndDmeOnly() throws Exception { + stateMachine.getExtendedState().getVariables().put("sme", false); + StateMachineTestPlan plan = + StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() + .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) + .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() + .sendEvent(RappEvent.ACMDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() + .sendEvent(RappEvent.DMEDEPLOYED).expectState(RappInstanceState.DEPLOYED).expectStateChanged(1) + .and().build(); + plan.test(); + } + @Test void testAcmDeployFailedState() throws Exception { - StateMachineTestPlan plan = + StateMachineTestPlan plan = StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() @@ -113,7 +168,7 @@ class RappInstanceStateMachineConfigTest { @Test void testSmeDeployFailedState() throws Exception { - StateMachineTestPlan plan = + StateMachineTestPlan plan = StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() @@ -126,7 +181,7 @@ class RappInstanceStateMachineConfigTest { @Test void testDmeDeployFailedState() throws Exception { - StateMachineTestPlan plan = + StateMachineTestPlan plan = StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() @@ -139,7 +194,7 @@ class RappInstanceStateMachineConfigTest { @Test void testUndeployingState() throws Exception { - StateMachineTestPlan plan = + StateMachineTestPlan plan = StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() @@ -152,9 +207,9 @@ class RappInstanceStateMachineConfigTest { } @ParameterizedTest - @EnumSource(value = RappEvent.class, names = {"ACMUNDEPLOYED", "SMEUNDEPLOYED", "DMEUNDEPLOYED" }) + @EnumSource(value = RappEvent.class, names = {"ACMUNDEPLOYED", "SMEUNDEPLOYED", "DMEUNDEPLOYED"}) void testIndividualUndeployedState(RappEvent rappEvent) throws Exception { - StateMachineTestPlan plan = + StateMachineTestPlan plan = StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() @@ -169,7 +224,7 @@ class RappInstanceStateMachineConfigTest { @Test void testUndeployedState() throws Exception { - StateMachineTestPlan plan = + StateMachineTestPlan plan = StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() @@ -180,13 +235,76 @@ class RappInstanceStateMachineConfigTest { .expectStateChanged(1).and().step().sendEvent(RappEvent.ACMUNDEPLOYED) .expectState(RappInstanceState.UNDEPLOYING).and().step().sendEvent(RappEvent.SMEUNDEPLOYED) .expectState(RappInstanceState.UNDEPLOYING).and().step().sendEvent(RappEvent.DMEUNDEPLOYED) - .expectStateChanged(1).and().build(); + .expectState(RappInstanceState.UNDEPLOYED).expectStateChanged(1).and().build(); + plan.test(); + } + + + @Test + void testUndeployedStateAcmOnly() throws Exception { + stateMachine.getExtendedState().getVariables().put("sme", false); + stateMachine.getExtendedState().getVariables().put("dme", false); + StateMachineTestPlan plan = + StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() + .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) + .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() + .sendEvent(RappEvent.ACMDEPLOYED).expectState(RappInstanceState.DEPLOYED).expectStateChanged(1) + .and().step().sendEvent(RappEvent.UNDEPLOYING).expectState(RappInstanceState.UNDEPLOYING) + .expectStateChanged(1).and().step().sendEvent(RappEvent.ACMUNDEPLOYED) + .expectState(RappInstanceState.UNDEPLOYED).expectStateChanged(1).and().build(); + plan.test(); + } + + @Test + void testUndeployedStateAcmOnlyWithNoKeyReference() throws Exception { + stateMachine.getExtendedState().getVariables().remove("sme"); + stateMachine.getExtendedState().getVariables().remove("dme"); + StateMachineTestPlan plan = + StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() + .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) + .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() + .sendEvent(RappEvent.ACMDEPLOYED).expectState(RappInstanceState.DEPLOYED).expectStateChanged(1) + .and().step().sendEvent(RappEvent.UNDEPLOYING).expectState(RappInstanceState.UNDEPLOYING) + .expectStateChanged(1).and().step().sendEvent(RappEvent.ACMUNDEPLOYED) + .expectState(RappInstanceState.UNDEPLOYED).expectStateChanged(1).and().build(); + plan.test(); + } + + @Test + void testUndeployedStateAcmAndSmeOnly() throws Exception { + stateMachine.getExtendedState().getVariables().put("dme", false); + StateMachineTestPlan plan = + StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() + .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) + .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() + .sendEvent(RappEvent.ACMDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() + .sendEvent(RappEvent.SMEDEPLOYED).expectState(RappInstanceState.DEPLOYED).expectStateChanged(1) + .and().step().sendEvent(RappEvent.UNDEPLOYING).expectState(RappInstanceState.UNDEPLOYING) + .expectStateChanged(1).and().step().sendEvent(RappEvent.ACMUNDEPLOYED) + .expectState(RappInstanceState.UNDEPLOYING).and().step().sendEvent(RappEvent.SMEUNDEPLOYED) + .expectState(RappInstanceState.UNDEPLOYED).expectStateChanged(1).and().build(); + plan.test(); + } + + @Test + void testUndeployedStateAcmAndDmeOnly() throws Exception { + stateMachine.getExtendedState().getVariables().put("sme", false); + StateMachineTestPlan plan = + StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() + .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) + .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() + .sendEvent(RappEvent.ACMDEPLOYED).expectState(RappInstanceState.DEPLOYING).and().step() + .sendEvent(RappEvent.DMEDEPLOYED).expectState(RappInstanceState.DEPLOYED).expectStateChanged(1) + .and().step().sendEvent(RappEvent.UNDEPLOYING).expectState(RappInstanceState.UNDEPLOYING) + .expectStateChanged(1).and().step().sendEvent(RappEvent.ACMUNDEPLOYED) + .expectState(RappInstanceState.UNDEPLOYING).and().step().sendEvent(RappEvent.DMEUNDEPLOYED) + .expectState(RappInstanceState.UNDEPLOYED).expectStateChanged(1).and().build(); plan.test(); } @Test void testUndeployAcmFailedState() throws Exception { - StateMachineTestPlan plan = + StateMachineTestPlan plan = StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() @@ -203,7 +321,7 @@ class RappInstanceStateMachineConfigTest { @Test void testUndeploySmeFailedState() throws Exception { - StateMachineTestPlan plan = + StateMachineTestPlan plan = StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() @@ -220,7 +338,7 @@ class RappInstanceStateMachineConfigTest { @Test void testUndeployDmeFailedState() throws Exception { - StateMachineTestPlan plan = + StateMachineTestPlan plan = StateMachineTestPlanBuilder.builder().stateMachine(stateMachine).step() .expectState(RappInstanceState.UNDEPLOYED).and().step().sendEvent(RappEvent.DEPLOYING) .expectState(RappInstanceState.DEPLOYING).expectStateChanged(1).and().step() diff --git a/rapp-manager-sme/src/main/java/com/oransc/rappmanager/sme/service/SmeDeployer.java b/rapp-manager-sme/src/main/java/com/oransc/rappmanager/sme/service/SmeDeployer.java index e1d9943..2050b51 100755 --- a/rapp-manager-sme/src/main/java/com/oransc/rappmanager/sme/service/SmeDeployer.java +++ b/rapp-manager-sme/src/main/java/com/oransc/rappmanager/sme/service/SmeDeployer.java @@ -88,32 +88,38 @@ public class SmeDeployer implements RappDeployer { @Override public boolean deployRappInstance(Rapp rapp, RappInstance rappInstance) { logger.debug("Deploying SME functions for RappInstance {}", rappInstance.getRappInstanceId()); - if (createProviderDomain(rapp, rappInstance) && createPublishApi(rapp, rappInstance) && createInvoker(rapp, - rappInstance)) { - rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEDEPLOYED); - return true; + if (rappInstance.isSMEEnabled()) { + if (createProviderDomain(rapp, rappInstance) && createPublishApi(rapp, rappInstance) && createInvoker(rapp, + rappInstance)) { + rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEDEPLOYED); + return true; + } + rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEDEPLOYFAILED); + rappInstance.setReason("Unable to deploy SME"); + return false; } - rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEDEPLOYFAILED); - rappInstance.setReason("Unable to deploy SME"); - return false; + return true; } @Override public boolean undeployRappInstance(Rapp rapp, RappInstance rappInstance) { logger.debug("Undeploying SME functions for Rapp {}", rapp.getName()); - try { - rappInstance.getSme().getInvokerIds().forEach(this::deleteInvoker); - rappInstance.getSme().getServiceApiIds() - .forEach(s -> deletePublishApi(s, rappInstance.getSme().getApfId())); - rappInstance.getSme().getProviderFunctionIds().forEach(this::deleteProviderFunc); - rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEUNDEPLOYED); - return true; - } catch (Exception e) { - logger.warn("Failed to Undeploy SME functions for Rapp {}", rapp.getName(), e); + 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); + rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEUNDEPLOYED); + return true; + } catch (Exception e) { + logger.warn("Failed to Undeploy SME functions for Rapp {}", rapp.getName(), e); + } + rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEUNDEPLOYFAILED); + rappInstance.setReason("Unable to undeploy SME"); + return false; } - rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEUNDEPLOYFAILED); - rappInstance.setReason("Unable to undeploy SME"); - return false; + return true; } @Override diff --git a/rapp-manager-sme/src/test/java/com/oransc/rappmanager/sme/service/SmeDeployerTest.java b/rapp-manager-sme/src/test/java/com/oransc/rappmanager/sme/service/SmeDeployerTest.java index e1b3752..4574ada 100755 --- a/rapp-manager-sme/src/test/java/com/oransc/rappmanager/sme/service/SmeDeployerTest.java +++ b/rapp-manager-sme/src/test/java/com/oransc/rappmanager/sme/service/SmeDeployerTest.java @@ -297,6 +297,18 @@ class SmeDeployerTest { assertTrue(deployRapp); } + @Test + void testDeployRappInstanceWithoutSme() throws Exception { + UUID rappId = UUID.randomUUID(); + Rapp rapp = + Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation) + .state(RappState.PRIMED).build(); + RappInstance rappInstance = getRappInstance(); + rappInstance.setSme(null); + rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); + assertTrue(smeDeployer.deployRappInstance(rapp, rappInstance)); + } + @Test void testDeployRappFailure() throws Exception { UUID rappId = UUID.randomUUID(); @@ -362,6 +374,16 @@ class SmeDeployerTest { assertTrue(undeployRapp); } + @Test + void testUndeployRappInstanceWithoutSme() { + UUID rappId = UUID.randomUUID(); + Rapp rapp = Rapp.builder().rappId(rappId).name(rappId.toString()).packageName(validRappFile) + .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build(); + RappInstance rappInstance = getRappInstance(); + rappInstance.setSme(null); + assertTrue(smeDeployer.undeployRappInstance(rapp, rappInstance)); + } + @Test void testUndeployRappInstanceFailure() { UUID rappId = UUID.randomUUID();