From: aravind.est Date: Mon, 21 Aug 2023 17:32:55 +0000 (+0100) Subject: Fix sonar code smells X-Git-Tag: 0.0.1~49 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F58%2F11658%2F1;p=nonrtric%2Fplt%2Frappmanager.git Fix sonar code smells Fix code smells reported by sonar. Issue-ID: NONRTRIC-910 Signed-off-by: aravind.est Change-Id: Ia8d0f88c878a55e425ea48c6c3db1fa62ef2df85 --- 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 287761a..41f4bae 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 @@ -118,6 +118,7 @@ public class AcmDeployer implements RappDeployer { } } catch (Exception e) { logger.warn("Unable to get composition instance state for composition {}", compositionId, e); + Thread.currentThread().interrupt(); } return targetInstanceStateTransition; } 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 928f4bc..59e69a6 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 @@ -71,7 +71,7 @@ import org.springframework.web.client.RestTemplate; RappInstanceStateMachine.class}) @TestInstance(TestInstance.Lifecycle.PER_CLASS) @AutoConfigureMockMvc -public class AcmDeployerTest { +class AcmDeployerTest { MockRestServiceServer mockServer; @SpyBean diff --git a/rapp-manager-application/src/main/java/com/oransc/rappmanager/BeanConfiguration.java b/rapp-manager-application/src/main/java/com/oransc/rappmanager/BeanConfiguration.java index be88202..0d3bd3d 100755 --- a/rapp-manager-application/src/main/java/com/oransc/rappmanager/BeanConfiguration.java +++ b/rapp-manager-application/src/main/java/com/oransc/rappmanager/BeanConfiguration.java @@ -49,7 +49,6 @@ public class BeanConfiguration { @Bean("acmApiClient") public ApiClient acmApiClient(RestTemplate restTemplate) { ApiClient apiClient = new ApiClient(restTemplate); - // apiClient.setDebugging(true); apiClient.setUsername(acmConfiguration.getUsername()); apiClient.setPassword(acmConfiguration.getPassword()); return apiClient.setBasePath(acmConfiguration.getBaseUrl()); diff --git a/rapp-manager-application/src/main/java/com/oransc/rappmanager/WriteCsarFile.java b/rapp-manager-application/src/main/java/com/oransc/rappmanager/WriteCsarFile.java deleted file mode 100755 index c421486..0000000 --- a/rapp-manager-application/src/main/java/com/oransc/rappmanager/WriteCsarFile.java +++ /dev/null @@ -1,95 +0,0 @@ -/*- - * ============LICENSE_START====================================================================== - * Copyright (C) 2023 Nordix Foundation. All rights reserved. - * =============================================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * 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; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; - -public class WriteCsarFile { - - public static void main(String[] args) { - String zipFileName = - "rapp-manager-application\\src\\main\\resources\\resource-csar\\rapp.csar"; - String csarPath = - "rapp-manager-application\\src\\main\\resources\\resource-csar"; - - try { - FileOutputStream fos = new FileOutputStream(zipFileName); - ZipOutputStream zos = new ZipOutputStream(fos); - - File directory = new File(csarPath); - System.out.println("Is directory " + directory.isDirectory()); - List fileList = new ArrayList<>(); - getFiles(directory, directory, fileList); - File[] files = fileList.toArray(new File[0]); - System.out.println("File size :" + files.length); - Arrays.sort(files, Collections.reverseOrder()); - - - for (File file : files) { - System.out.println("Processing " + file.getPath()); - if (!file.isDirectory()) { - System.out.println("Processing " + file.getPath()); - FileInputStream fis = new FileInputStream(csarPath + File.separator + file.getPath()); - - ZipEntry zipEntry = new ZipEntry(file.getPath().replaceAll("\\\\", "/")); - zos.putNextEntry(zipEntry); - - byte[] bytes = new byte[1024]; - int length; - while ((length = fis.read(bytes)) >= 0) { - zos.write(bytes, 0, length); - } - fis.close(); - } else { - System.out.println("Not a file: " + file.getPath()); - } - } - - zos.close(); - fos.close(); - - System.out.println("Zip file created successfully!"); - - } catch (IOException e) { - e.printStackTrace(); - } - } - - private static void getFiles(File baseDirectory, File directory, List fileList) { - File[] files = directory.listFiles(); - if (files != null) { - for (File file : files) { - if (file.isDirectory()) { - getFiles(baseDirectory, file, fileList); - } else { - fileList.add(new File(file.getPath().replace(baseDirectory.getPath() + File.separator, ""))); - } - } - } - } -} diff --git a/rapp-manager-application/src/main/java/com/oransc/rappmanager/rest/RappController.java b/rapp-manager-application/src/main/java/com/oransc/rappmanager/rest/RappController.java index 8cfbddc..7510a5c 100755 --- a/rapp-manager-application/src/main/java/com/oransc/rappmanager/rest/RappController.java +++ b/rapp-manager-application/src/main/java/com/oransc/rappmanager/rest/RappController.java @@ -59,6 +59,7 @@ public class RappController { private final RappManagerConfiguration rappManagerConfiguration; private final RappCacheService rappCacheService; private final RappService rappService; + private static final String RAPP_NOT_FOUND = "rApp %s not found."; @GetMapping public ResponseEntity> getRapps() { @@ -68,7 +69,7 @@ public class RappController { @GetMapping("{rapp_id}") public ResponseEntity getRapp(@PathVariable("rapp_id") String rappId) { return rappCacheService.getRapp(rappId).map(ResponseEntity::ok).orElseThrow( - () -> new RappHandlerException(HttpStatus.NOT_FOUND, "rApp '" + rappId + "' not found.")); + () -> new RappHandlerException(HttpStatus.NOT_FOUND, String.format(RAPP_NOT_FOUND, rappId))); } @PostMapping("{rapp_id}") @@ -102,7 +103,7 @@ public class RappController { .map(primeOrder -> rappService.primeRapp(rapp)) .orElseGet(() -> rappService.deprimeRapp(rapp))) .orElseThrow(() -> new RappHandlerException(HttpStatus.NOT_FOUND, - "rApp '" + rappId + "' not found.")); + String.format(RAPP_NOT_FOUND, rappId))); // @formatter:on } @@ -116,7 +117,7 @@ public class RappController { return ResponseEntity.ok().build(); }) .orElseThrow(() -> new RappHandlerException(HttpStatus.NOT_FOUND, - "rApp '" + rappId + "' not found.")); + String.format(RAPP_NOT_FOUND, rappId))); // @formatter:on } } diff --git a/rapp-manager-application/src/main/java/com/oransc/rappmanager/rest/RappInstanceController.java b/rapp-manager-application/src/main/java/com/oransc/rappmanager/rest/RappInstanceController.java index 20bfc6a..9566364 100755 --- a/rapp-manager-application/src/main/java/com/oransc/rappmanager/rest/RappInstanceController.java +++ b/rapp-manager-application/src/main/java/com/oransc/rappmanager/rest/RappInstanceController.java @@ -51,6 +51,7 @@ public class RappInstanceController { private final RappCacheService rappCacheService; private final RappInstanceStateMachine rappInstanceStateMachine; private final RappService rappService; + private static final String RAPP_INSTANCE_NOT_FOUND = "rApp instance %s not found."; @GetMapping public ResponseEntity> getAllRappInstances(@PathVariable("rapp_id") String rappId) { @@ -79,7 +80,7 @@ public class RappInstanceController { rappInstance.setState(rappInstanceStateMachine.getRappInstanceState(rappInstanceId)); return rappInstance; }).map(ResponseEntity::ok).orElseThrow(() -> new RappHandlerException(HttpStatus.NOT_FOUND, - "No instance found for rApp '" + rappId + "'.")); + String.format(RAPP_INSTANCE_NOT_FOUND, rappId))); } @PutMapping("{rapp_instance_id}") @@ -95,7 +96,7 @@ public class RappInstanceController { .map(primeOrder -> rappService.deployRappInstance(rappPair.getLeft(), rappPair.getRight())) .orElseGet(() -> rappService.undeployRappInstance(rappPair.getLeft(), rappPair.getRight()))) .orElseThrow(() -> new RappHandlerException(HttpStatus.NOT_FOUND, - "rApp instance '" + rappInstanceId + "' not found.")); + String.format(RAPP_INSTANCE_NOT_FOUND, rappId))); //@formatter:on } @@ -113,7 +114,7 @@ public class RappInstanceController { rappPair.getLeft().getRappInstances().remove(rappInstanceId); return ResponseEntity.noContent().build(); }).orElseThrow(() -> new RappHandlerException(HttpStatus.NOT_FOUND, - "rApp instance '" + rappInstanceId + "' not found.")); + String.format(RAPP_INSTANCE_NOT_FOUND, rappId))); } } 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 82054f5..6411b2b 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 @@ -21,9 +21,9 @@ package com.oransc.rappmanager.service; import com.oransc.rappmanager.acm.service.AcmDeployer; import com.oransc.rappmanager.models.rapp.Rapp; import com.oransc.rappmanager.models.rapp.RappEvent; +import com.oransc.rappmanager.models.rapp.RappState; import com.oransc.rappmanager.models.rappinstance.RappInstance; import com.oransc.rappmanager.models.rappinstance.RappInstanceState; -import com.oransc.rappmanager.models.rapp.RappState; import com.oransc.rappmanager.models.statemachine.RappInstanceStateMachine; import com.oransc.rappmanager.sme.service.SmeDeployer; import lombok.RequiredArgsConstructor; @@ -38,6 +38,7 @@ public class RappService { private final AcmDeployer acmDeployer; private final SmeDeployer smeDeployer; private final RappInstanceStateMachine rappInstanceStateMachine; + private static final String STATE_TRANSITION_NOT_PERMITTED = "State transition from %s to %s is not permitted."; public ResponseEntity primeRapp(Rapp rapp) { if (rapp.getState().equals(RappState.COMMISSIONED)) { @@ -48,8 +49,8 @@ public class RappService { return ResponseEntity.ok().build(); } else { return ResponseEntity.badRequest() - .body("State transition from " + RappState.PRIMED.name() + " to " + rapp.getState().name() - + " is not permitted."); + .body(String.format(STATE_TRANSITION_NOT_PERMITTED, RappState.PRIMED.name(), + rapp.getState().name())); } } @@ -65,9 +66,8 @@ public class RappService { return ResponseEntity.badRequest().body("Unable to deprime as there are active rapp instances,"); } else { return ResponseEntity.badRequest() - .body("State transition from " + RappState.COMMISSIONED.name() + " to " + rapp.getState() - .name() - + " is not permitted."); + .body(String.format(STATE_TRANSITION_NOT_PERMITTED, RappState.COMMISSIONED.name(), + rapp.getState().name())); } } } @@ -81,8 +81,9 @@ public class RappService { } return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build(); } else { - return ResponseEntity.badRequest().body("State transition from " + rappInstance.getState().name() + " to " - + RappInstanceState.DEPLOYED.name() + " is not permitted."); + return ResponseEntity.badRequest() + .body(String.format(STATE_TRANSITION_NOT_PERMITTED, rappInstance.getState().name(), + RappInstanceState.DEPLOYED.name())); } } @@ -95,9 +96,9 @@ public class RappService { } return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build(); } else { - return ResponseEntity.badRequest().body("State transition from " + rappInstance.getState().name() + " to " - + RappInstanceState.UNDEPLOYED.name() - + " is not permitted."); + return ResponseEntity.badRequest() + .body(String.format(STATE_TRANSITION_NOT_PERMITTED, rappInstance.getState().name(), + RappInstanceState.UNDEPLOYED.name())); } } diff --git a/rapp-manager-application/src/test/java/com/oransc/rappmanager/rest/RappControllerTest.java b/rapp-manager-application/src/test/java/com/oransc/rappmanager/rest/RappControllerTest.java index 50d62fa..6d4b84c 100755 --- a/rapp-manager-application/src/test/java/com/oransc/rappmanager/rest/RappControllerTest.java +++ b/rapp-manager-application/src/test/java/com/oransc/rappmanager/rest/RappControllerTest.java @@ -32,7 +32,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @AutoConfigureMockMvc -public class RappControllerTest { +class RappControllerTest { @Autowired private MockMvc mockMvc; diff --git a/rapp-manager-application/src/test/java/com/oransc/rappmanager/rest/RappInstanceControllerTest.java b/rapp-manager-application/src/test/java/com/oransc/rappmanager/rest/RappInstanceControllerTest.java index aa6f40e..d6ba4ce 100755 --- a/rapp-manager-application/src/test/java/com/oransc/rappmanager/rest/RappInstanceControllerTest.java +++ b/rapp-manager-application/src/test/java/com/oransc/rappmanager/rest/RappInstanceControllerTest.java @@ -32,7 +32,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @AutoConfigureMockMvc -public class RappInstanceControllerTest { +class RappInstanceControllerTest { @Autowired private MockMvc mockMvc; 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 0eba9e7..dbb3da7 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 @@ -23,7 +23,7 @@ import org.springframework.http.HttpStatus; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @AutoConfigureMockMvc -public class RappServiceTest { +class RappServiceTest { @Autowired RappService rappService; diff --git a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/cache/RappCacheService.java b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/cache/RappCacheService.java index ea34ae3..d81dd71 100755 --- a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/cache/RappCacheService.java +++ b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/cache/RappCacheService.java @@ -32,7 +32,7 @@ import org.springframework.stereotype.Service; @RequiredArgsConstructor public class RappCacheService { - private final String RAPP_CACHE = "rapp-cache"; + private static final String RAPP_CACHE = "rapp-cache"; private final CacheManager cacheManager; public Collection getAllRapp() { @@ -45,8 +45,7 @@ public class RappCacheService { } public Optional getRapp(String rappId) { - final Cache cache = cacheManager.getCache(RAPP_CACHE); - return Optional.ofNullable(cache.get(rappId, Rapp.class)); + return Optional.ofNullable(cacheManager.getCache(RAPP_CACHE)).map(cache -> cache.get(rappId, Rapp.class)); } public void putRapp(Rapp rapp) { diff --git a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandler.java b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandler.java index f7cdece..bbf59bb 100755 --- a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandler.java +++ b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandler.java @@ -19,8 +19,8 @@ package com.oransc.rappmanager.models.csar; import com.oransc.rappmanager.models.rapp.Rapp; -import com.oransc.rappmanager.models.rappinstance.RappACMInstance; import com.oransc.rappmanager.models.rapp.RappResources; +import com.oransc.rappmanager.models.rappinstance.RappACMInstance; import com.oransc.rappmanager.models.rappinstance.RappSMEInstance; import java.io.ByteArrayOutputStream; import java.io.File; @@ -42,20 +42,20 @@ import org.springframework.web.multipart.MultipartFile; public class RappCsarConfigurationHandler { Logger logger = LoggerFactory.getLogger(RappCsarConfigurationHandler.class); - private final String acmCompositionJsonLocation = "Files/Acm/definition/compositions.json"; - private final String acmDefinitionLocation = "Files/Acm/definition"; - private final String acmInstancesLocation = "Files/Acm/instances"; + private static final String ACM_COMPOSITION_JSON_LOCATION = "Files/Acm/definition/compositions.json"; + private static final String ACM_DEFINITION_LOCATION = "Files/Acm/definition"; + private static final String ACM_INSTANCES_LOCATION = "Files/Acm/instances"; - private final String smeProviderFuncsLocation = "Files/Sme/providers"; - private final String smeServiceApisLocation = "Files/Sme/serviceapis"; + private static final String SME_PROVIDER_FUNCS_LOCATION = "Files/Sme/providers"; + private static final String SME_SERVICE_APIS_LOCATION = "Files/Sme/serviceapis"; - private final String smeInvokersLocation = "Files/Sme/invokers"; + private static final String SME_INVOKERS_LOCATION = "Files/Sme/invokers"; public boolean isValidRappPackage(MultipartFile multipartFile) { - return multipartFile.getOriginalFilename() != null && multipartFile.getOriginalFilename().endsWith(".csar") - && isFileExistsInCsar(multipartFile, acmCompositionJsonLocation); - //TODO Additional file checks needs to be added + return multipartFile != null && multipartFile.getOriginalFilename() != null + && multipartFile.getOriginalFilename().endsWith(".csar") && isFileExistsInCsar(multipartFile, + ACM_COMPOSITION_JSON_LOCATION); } boolean isFileExistsInCsar(MultipartFile multipartFile, String fileLocation) { @@ -78,7 +78,7 @@ public class RappCsarConfigurationHandler { } public String getInstantiationPayload(Rapp rapp, RappACMInstance rappACMInstance, UUID compositionId) { - return getPayload(rapp, getResourceUri(acmInstancesLocation, rappACMInstance.getInstance())).replaceAll( + return getPayload(rapp, getResourceUri(ACM_INSTANCES_LOCATION, rappACMInstance.getInstance())).replaceAll( "COMPOSITIONID", String.valueOf(compositionId)); } @@ -115,20 +115,20 @@ public class RappCsarConfigurationHandler { public String getSmeProviderDomainPayload(Rapp rapp, RappSMEInstance rappSMEInstance) { - return getPayload(rapp, getResourceUri(smeProviderFuncsLocation, rappSMEInstance.getProviderFunction())); + return getPayload(rapp, getResourceUri(SME_PROVIDER_FUNCS_LOCATION, rappSMEInstance.getProviderFunction())); } public String getSmeProviderApiPayload(Rapp rapp, RappSMEInstance rappSMEInstance) { - return getPayload(rapp, getResourceUri(smeServiceApisLocation, rappSMEInstance.getServiceApis())); + return getPayload(rapp, getResourceUri(SME_SERVICE_APIS_LOCATION, rappSMEInstance.getServiceApis())); } public String getSmeInvokerPayload(Rapp rapp, RappSMEInstance rappSMEInstance) { - return getPayload(rapp, getResourceUri(smeInvokersLocation, rappSMEInstance.getInvokers())); + return getPayload(rapp, getResourceUri(SME_INVOKERS_LOCATION, rappSMEInstance.getInvokers())); } public String getAcmCompositionPayload(Rapp rapp) { return getPayload(rapp, - getResourceUri(acmDefinitionLocation, rapp.getRappResources().getAcm().getCompositionDefinitions())); + getResourceUri(ACM_DEFINITION_LOCATION, rapp.getRappResources().getAcm().getCompositionDefinitions())); } String getResourceUri(String resourceLocation, String resource) { @@ -141,13 +141,14 @@ public class RappCsarConfigurationHandler { File csarFile = getCsarFile(rapp); if (csarFile.exists()) { rappResources.setAcm(RappResources.ACMResources.builder().compositionDefinitions( - getFileListFromCsar(csarFile, acmDefinitionLocation).get(0)) - .compositionInstances(getFileListFromCsar(csarFile, acmInstancesLocation)) + getFileListFromCsar(csarFile, ACM_DEFINITION_LOCATION).get(0)) + .compositionInstances(getFileListFromCsar(csarFile, ACM_INSTANCES_LOCATION)) .build()); rappResources.setSme(RappResources.SMEResources.builder() - .providerFunctions(getFileListFromCsar(csarFile, smeProviderFuncsLocation)) - .serviceApis(getFileListFromCsar(csarFile, smeServiceApisLocation)) - .invokers(getFileListFromCsar(csarFile, smeInvokersLocation)).build()); + .providerFunctions(getFileListFromCsar(csarFile, + SME_PROVIDER_FUNCS_LOCATION)) + .serviceApis(getFileListFromCsar(csarFile, SME_SERVICE_APIS_LOCATION)) + .invokers(getFileListFromCsar(csarFile, SME_INVOKERS_LOCATION)).build()); } } catch (Exception e) { logger.warn("Error in getting the rapp resources", e); diff --git a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rapp/RappPrimeOrder.java b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rapp/RappPrimeOrder.java index 759be89..b0b3592 100755 --- a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rapp/RappPrimeOrder.java +++ b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rapp/RappPrimeOrder.java @@ -18,7 +18,6 @@ package com.oransc.rappmanager.models.rapp; -import com.oransc.rappmanager.models.rapp.PrimeOrder; import lombok.Data; @Data diff --git a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rapp/RappResources.java b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rapp/RappResources.java index 4dd5e3a..f9bf932 100755 --- a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rapp/RappResources.java +++ b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rapp/RappResources.java @@ -25,8 +25,8 @@ import lombok.Data; @Data public class RappResources { - public ACMResources acm; - public SMEResources sme; + ACMResources acm; + SMEResources sme; @Data @Builder 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 4e10ac0..c4cd18b 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 @@ -27,9 +27,11 @@ import java.util.UUID; import lombok.RequiredArgsConstructor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.messaging.support.MessageBuilder; import org.springframework.statemachine.StateMachine; import org.springframework.statemachine.config.StateMachineFactory; import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; @Service @RequiredArgsConstructor @@ -43,13 +45,14 @@ public class RappInstanceStateMachine { public void onboardRappInstance(UUID rappInstanceId) { StateMachine stateMachine = stateMachineFactory.getStateMachine(rappInstanceId); stateMachineMap.put(rappInstanceId, stateMachine); - stateMachine.start(); + stateMachine.startReactively().subscribe(); } 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()).sendEvent(rappEvent); + stateMachineMap.get(rappInstance.getRappInstanceId()) + .sendEvent(Mono.just(MessageBuilder.withPayload(rappEvent).build())).subscribe(); } public RappInstanceState getRappInstanceState(UUID rappInstanceId) { @@ -57,7 +60,7 @@ public class RappInstanceStateMachine { } public void deleteRappInstance(RappInstance rappInstance) { - stateMachineMap.get(rappInstance.getRappInstanceId()).stop(); + stateMachineMap.get(rappInstance.getRappInstanceId()).stopReactively().subscribe(); stateMachineMap.remove(rappInstance.getRappInstanceId()); } } diff --git a/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandlerTest.java b/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandlerTest.java index 10f5d96..b4c00a7 100755 --- a/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandlerTest.java +++ b/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandlerTest.java @@ -44,7 +44,7 @@ import org.springframework.web.multipart.MultipartFile; @SpringBootTest @ContextConfiguration(classes = RappCsarConfigurationHandler.class) -public class RappCsarConfigurationHandlerTest { +class RappCsarConfigurationHandlerTest { @Autowired RappCsarConfigurationHandler rappCsarConfigurationHandler; @@ -90,14 +90,14 @@ public class RappCsarConfigurationHandlerTest { File file = new File(validCsarFileLocation + validRappFile); List fileListFromCsar = rappCsarConfigurationHandler.getFileListFromCsar(file, "Files/Sme/serviceapis/"); - assertThat(fileListFromCsar.size()).isEqualTo(2); + assertThat(fileListFromCsar).hasSize(2); } @Test void testInvalidFileListing() { File file = new File(validCsarFileLocation); List fileListFromCsar = rappCsarConfigurationHandler.getFileListFromCsar(file, null); - assertThat(fileListFromCsar.size()).isEqualTo(0); + assertThat(fileListFromCsar).isEmpty(); } @Test @@ -109,10 +109,10 @@ public class RappCsarConfigurationHandlerTest { RappResources rappResources = rappCsarConfigurationHandler.getRappResource(rapp); assertThat(rappResources).isNotNull(); assertNotNull(rappResources.getAcm().getCompositionDefinitions()); - assertThat(rappResources.getAcm().getCompositionInstances().size()).isEqualTo(3); - assertThat(rappResources.getSme().getProviderFunctions().size()).isEqualTo(4); - assertThat(rappResources.getSme().getServiceApis().size()).isEqualTo(2); - assertThat(rappResources.getSme().getInvokers().size()).isEqualTo(2); + assertThat(rappResources.getAcm().getCompositionInstances()).hasSize(3); + assertThat(rappResources.getSme().getProviderFunctions()).hasSize(4); + assertThat(rappResources.getSme().getServiceApis()).hasSize(2); + assertThat(rappResources.getSme().getInvokers()).hasSize(2); } @Test 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 1ab5481..59d5c94 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 @@ -39,7 +39,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) @SpringBootTest(classes = {RappInstanceStateMachineConfig.class}) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -public class RappInstanceStateMachineConfigTest { +class RappInstanceStateMachineConfigTest { @Autowired StateMachineFactory stateMachineFactory; diff --git a/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachineTest.java b/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachineTest.java index db45d14..3e40a25 100755 --- a/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachineTest.java +++ b/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachineTest.java @@ -18,7 +18,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) @SpringBootTest(classes = {RappInstanceStateMachine.class, RappInstanceStateMachineConfig.class}) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -public class RappInstanceStateMachineTest { +class RappInstanceStateMachineTest { @Autowired RappInstanceStateMachine rappInstanceStateMachine; 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 6a6581a..1760e9c 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 @@ -140,11 +140,10 @@ public class SmeDeployer implements RappDeployer { try { String providerDomainPayload = rappCsarConfigurationHandler.getSmeProviderDomainPayload(rapp, rappInstance.getSme()); - logger.info("provider domain payload " + providerDomainPayload); + logger.debug("Provider domain payload {}", providerDomainPayload); if (providerDomainPayload != null) { APIProviderEnrolmentDetails apiProviderEnrolmentDetails = objectMapper.readValue(providerDomainPayload, APIProviderEnrolmentDetails.class); - //TODO Fix this Temporary workaround apiProviderEnrolmentDetails.setRegSec( apiProviderEnrolmentDetails.getRegSec() + rappInstance.getRappInstanceId()); APIProviderEnrolmentDetails responseApiEnrollmentDetails = @@ -191,9 +190,7 @@ public class SmeDeployer implements RappDeployer { if (providerApiPayload != null) { ServiceAPIDescription serviceAPIDescription = objectMapper.readValue(providerApiPayload, ServiceAPIDescription.class); - serviceAPIDescription.getAefProfiles().forEach(aefProfile -> { - aefProfile.setAefId(rappInstance.getSme().getAefId()); - }); + serviceAPIDescription.getAefProfiles().forEach(aefProfile -> aefProfile.setAefId(rappInstance.getSme().getAefId())); ServiceAPIDescription serviceAPIDescriptionResponse = publishServiceDefaultApiClient.postApfIdServiceApis(rappInstance.getSme().getApfId(), serviceAPIDescription); diff --git a/rapp-manager-sme/src/main/java/com/oransc/rappmanager/sme/service/SmeLifecycleManager.java b/rapp-manager-sme/src/main/java/com/oransc/rappmanager/sme/service/SmeLifecycleManager.java index cb5b049..e4511a8 100755 --- a/rapp-manager-sme/src/main/java/com/oransc/rappmanager/sme/service/SmeLifecycleManager.java +++ b/rapp-manager-sme/src/main/java/com/oransc/rappmanager/sme/service/SmeLifecycleManager.java @@ -39,7 +39,7 @@ public class SmeLifecycleManager implements SmartLifecycle { try { logger.info("Registering Rapp Manager as AMF"); APIProviderEnrolmentDetails providerServiceAMF = smeDeployer.createAMF(); - logger.info("Rapp Manager AMF Registration Id: " + providerServiceAMF.getApiProvDomId()); + logger.info("Rapp Manager AMF Registration Id: {}", providerServiceAMF.getApiProvDomId()); running = true; } catch (Exception e) { logger.warn("Error in initializing AMF", e); 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 9a8faf6..e00b259 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 @@ -66,7 +66,7 @@ import org.springframework.web.client.RestTemplate; RappInstanceStateMachine.class}) @TestInstance(TestInstance.Lifecycle.PER_CLASS) @AutoConfigureMockMvc -public class SmeDeployerTest { +class SmeDeployerTest { MockRestServiceServer mockServer; @Autowired