From: Balagangadhar (Bala) Bathula Date: Tue, 8 Aug 2023 03:01:44 +0000 (-0400) Subject: Skip the temp-service-create if already exists X-Git-Tag: 8.0.0~29 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=ce58f21d0a025babe3b5076e24ea82802ebf9703;hp=7a69c663e959822ef9e579b4522a9fa98213afdc;p=transportpce.git Skip the temp-service-create if already exists - If a temp-service with a commonId already exists in the data-store (temp-service-list), and if the temp-service-create is issued, then the controller should fail with an error message, indicating it already exists. - Add code to check if the same commonId exists in the datastore and add a failed response. - Add a new Junit test to check it JIRA: TRNSPRTPCE-753 Signed-off-by: Balagangadhar (Bala) Bathula Co-authored-by: Gilles Thouenon Change-Id: I9f425e9febd8820f3053ecd5dfdd14f8a66279c4 --- diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java index d71da9f17..2a95a747d 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java @@ -666,6 +666,14 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED); } + //Check any presence of temp-service with the same commonId + String commonId = input.getCommonId(); + if (this.serviceDataStoreOperations.getTempService(commonId).isPresent()) { + LOG.warn(TEMP_SERVICE_CREATE_MSG, LogMessages.serviceInDS("Temp (" + commonId + ")")); + return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, + LogMessages.serviceInDS("Temp (" + commonId + ")"), ResponseCodes.RESPONSE_FAILED); + } + // Starting service create operation LOG.debug(TEMP_SERVICE_CREATE_MSG, LogMessages.PCE_CALLING); this.pceListenerImpl.setInput(new ServiceInput(input)); diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImplTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImplTest.java index be9ad142d..90c6b22ef 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImplTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImplTest.java @@ -531,6 +531,31 @@ public class ServicehandlerImplTest extends AbstractTest { result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } + @Test + void tempServiceCreateShouldBeFailedWithServiceAlreadyExist() throws ExecutionException, InterruptedException { + final ServiceDataStoreOperations serviceDSOperations = mock(ServiceDataStoreOperations.class); + when(serviceDSOperations.getTempService(any())) + .thenReturn(Optional.of( + new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list + .ServicesBuilder() + .setCommonId("bad_commonId") + .build())); + ListenableFuture> result = + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDSOperations, catalogDataStoreOperations) + .tempServiceCreate(ServiceDataUtils.buildTempServiceCreateInput()); + result.addListener(() -> endSignal.countDown(), executorService); + endSignal.await(); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + "Service 'Temp (commonId)' already exists in datastore", + result.get().getResult().getConfigurationResponseCommon().getResponseMessage()); + } + @Test void tempServiceCreateShouldBeSuccessfulWhenPerformPCESuccessful() throws ExecutionException, InterruptedException {