Refactor TAPI rpc CreateConnectivityServiceImpl 58/110858/3
authorguillaume.lambert <guillaume.lambert@orange.com>
Tue, 19 Mar 2024 07:11:25 +0000 (08:11 +0100)
committerguillaume.lambert <guillaume.lambert@orange.com>
Tue, 26 Mar 2024 12:50:27 +0000 (13:50 +0100)
Signed-off-by: guillaume.lambert <guillaume.lambert@orange.com>
Change-Id: I85b7c6dc7e74c957f78123b5b8fb5dcf577fcb57

tapi/src/main/java/org/opendaylight/transportpce/tapi/impl/rpc/CreateConnectivityServiceImpl.java

index 6c7eb2bef744c108f0c21f51631abee71654a8ca..317a07967575be0e5770be9c058d1edc7108d2ad 100644 (file)
@@ -40,7 +40,6 @@ import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev22112
 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.ServiceType;
 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.context.ConnectivityService;
 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.context.ConnectivityServiceBuilder;
-import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.service.ConnectivityConstraint;
 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.service.ConnectivityConstraintBuilder;
 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.service.EndPoint;
 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.connectivity.service.EndPointBuilder;
@@ -82,52 +81,48 @@ public class CreateConnectivityServiceImpl implements CreateConnectivityService
         this.pceListenerImpl.setInput(input);
         this.pceListenerImpl.setServiceUuid(serviceUuid);
         this.rendererListenerImpl.setServiceUuid(serviceUuid);
-        ListenableFuture<RpcResult<ServiceCreateOutput>> output = null;
-        OperationResult validationResult = CreateConnectivityServiceValidation.validateCreateConnectivityServiceRequest(
-                input);
-        if (validationResult.isSuccess()) {
-            LOG.info("input parameter of RPC create-connectivity are being handled");
-            // check uuid of SIP in tapi context
-            Map<ServiceInterfacePointKey, ServiceInterfacePoint> sipMap = this.tapiContext.getTapiContext()
-                    .getServiceInterfacePoint();
-            if (sipMap == null) {
-                return RpcResultBuilder.<CreateConnectivityServiceOutput>failed()
-                    .withError(ErrorType.RPC, "SIP list is empty")
-                    .buildFuture();
-            }
-            if (sipMap.containsKey(new ServiceInterfacePointKey(input.getEndPoint().values().stream().findFirst()
-                        .orElseThrow().getServiceInterfacePoint().getServiceInterfacePointUuid()))
-                    && sipMap.containsKey(new ServiceInterfacePointKey(input.getEndPoint().values().stream().skip(1)
-                        .findFirst().orElseThrow().getServiceInterfacePoint().getServiceInterfacePointUuid()))) {
-                LOG.info("SIPs found in sipMap");
-                // TODO: differentiate between OTN service and GbE service in TAPI
-                ServiceCreateInput sci = this.connectivityUtils.createORServiceInput(input, serviceUuid);
-                if (sci == null) {
-                    return RpcResultBuilder.<CreateConnectivityServiceOutput>failed()
-                        .withError(ErrorType.RPC, "Couldnt map Service create input")
-                        .buildFuture();
-                }
-                LOG.info("Service Create input = {}", sci);
-                output = rpcService.getRpc(ServiceCreate.class).invoke(sci);
-                if (!output.isDone()) {
-                    return RpcResultBuilder.<CreateConnectivityServiceOutput>failed()
-                        .withError(ErrorType.RPC, "Service create RPC failed")
-                        .buildFuture();
-                }
-            } else {
-                LOG.error("Unknown UUID");
-                return RpcResultBuilder.<CreateConnectivityServiceOutput>failed()
-                    .withError(ErrorType.RPC, "SIPs do not exist in tapi context")
-                    .buildFuture();
-            }
+        OperationResult validationResult =
+            CreateConnectivityServiceValidation.validateCreateConnectivityServiceRequest(input);
+        if (!validationResult.isSuccess()) {
+            return RpcResultBuilder.<CreateConnectivityServiceOutput>failed()
+                .withError(ErrorType.RPC, "Failed to create service")
+                .buildFuture();
+        }
+        LOG.info("input parameter of RPC create-connectivity are being handled");
+        // check uuid of SIP in tapi context
+        Map<ServiceInterfacePointKey, ServiceInterfacePoint> sipMap =
+                this.tapiContext.getTapiContext().getServiceInterfacePoint();
+        if (sipMap == null) {
+            return RpcResultBuilder.<CreateConnectivityServiceOutput>failed()
+                .withError(ErrorType.RPC, "SIP list is empty")
+                .buildFuture();
+        }
+        if (!sipMap.containsKey(new ServiceInterfacePointKey(input.getEndPoint().values().stream().findFirst()
+                    .orElseThrow().getServiceInterfacePoint().getServiceInterfacePointUuid()))
+                || !sipMap.containsKey(new ServiceInterfacePointKey(input.getEndPoint().values().stream().skip(1)
+                    .findFirst().orElseThrow().getServiceInterfacePoint().getServiceInterfacePointUuid()))) {
+            LOG.error("Unknown UUID");
+            return RpcResultBuilder.<CreateConnectivityServiceOutput>failed()
+                .withError(ErrorType.RPC, "SIPs do not exist in tapi context")
+                .buildFuture();
+        }
+        LOG.info("SIPs found in sipMap");
+        // TODO: differentiate between OTN service and GbE service in TAPI
+        ServiceCreateInput sci = this.connectivityUtils.createORServiceInput(input, serviceUuid);
+        if (sci == null) {
+            return RpcResultBuilder.<CreateConnectivityServiceOutput>failed()
+                .withError(ErrorType.RPC, "Couldnt map Service create input")
+                .buildFuture();
         }
+        LOG.info("Service Create input = {}", sci);
+        ListenableFuture<RpcResult<ServiceCreateOutput>> output = rpcService.getRpc(ServiceCreate.class).invoke(sci);
+        if (!output.isDone()) {
+            return RpcResultBuilder.<CreateConnectivityServiceOutput>failed()
+                .withError(ErrorType.RPC, "Service create RPC failed")
+                .buildFuture();
+        }
+        LOG.info("Service create request was successful");
         try {
-            if (output == null) {
-                return RpcResultBuilder.<CreateConnectivityServiceOutput>failed()
-                    .withError(ErrorType.RPC, "Failed to create service")
-                    .buildFuture();
-            }
-            LOG.info("Service create request was successful");
             if (output.get().getResult().getConfigurationResponseCommon().getResponseCode()
                     .equals(ResponseCodes.RESPONSE_FAILED)) {
                 return RpcResultBuilder.<CreateConnectivityServiceOutput>failed()
@@ -139,58 +134,59 @@ public class CreateConnectivityServiceImpl implements CreateConnectivityService
             LOG.error("Error checking response code of service create", e);
         }
         // Connections and states should be created/updated when the pce and renderer are done :)
-        Map<EndPointKey, EndPoint> endPointList = createEndPoints(input.getEndPoint());
         Name name = new NameBuilder()
             .setValueName("Connectivity Service Name")
             .setValue(serviceUuid.getValue())
             .build();
-        ConnectivityConstraint conConstr = new ConnectivityConstraintBuilder()
-            .setServiceType(ServiceType.POINTTOPOINTCONNECTIVITY)
-            .setServiceLevel(input.getConnectivityConstraint().getServiceLevel()).build();
-
         ConnectivityService service = new ConnectivityServiceBuilder()
             .setUuid(serviceUuid)
             .setAdministrativeState(AdministrativeState.LOCKED)
             .setOperationalState(OperationalState.DISABLED)
             .setLifecycleState(LifecycleState.PLANNED)
             .setLayerProtocolName(input.getLayerProtocolName())
-            .setConnectivityConstraint(conConstr)
+            .setConnectivityConstraint(
+                new ConnectivityConstraintBuilder()
+                    .setServiceType(ServiceType.POINTTOPOINTCONNECTIVITY)
+                    .setServiceLevel(input.getConnectivityConstraint().getServiceLevel())
+                    .build())
             .setDirection(ForwardingDirection.BIDIRECTIONAL)
             .setName(Map.of(name.key(), name))
             .setConnection(new HashMap<>())
-            .setEndPoint(endPointList)
+            .setEndPoint(createEndPoints(input.getEndPoint()))
             .build();
         // add to tapi context
         this.tapiContext.updateConnectivityContext(Map.of(service.key(), service), new HashMap<>());
         LOG.info("Created locked service in Datastore. Waiting for PCE and Renderer to complete tasks...");
         // return ConnectivityServiceCreateOutput
-        return RpcResultBuilder.success(new CreateConnectivityServiceOutputBuilder()
-            .setService(new ServiceBuilder(service).build()).build()).buildFuture();
+        return RpcResultBuilder.success(
+                new CreateConnectivityServiceOutputBuilder()
+                    .setService(new ServiceBuilder(service).build())
+                    .build())
+            .buildFuture();
     }
 
     private Map<EndPointKey, EndPoint> createEndPoints(
-            Map<org.opendaylight.yang.gen.v1.urn
-                .onf.otcc.yang.tapi.connectivity.rev221121.create.connectivity.service.input.EndPointKey,
-                org.opendaylight.yang.gen.v1.urn
-                    .onf.otcc.yang.tapi.connectivity.rev221121.create.connectivity.service.input.EndPoint> endPoints) {
+            Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
+                    .create.connectivity.service.input.EndPointKey,
+                org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
+                    .create.connectivity.service.input.EndPoint> endPoints) {
         Map<EndPointKey, EndPoint> endPointMap = new HashMap<>();
-        for (org.opendaylight.yang.gen.v1.urn
-                .onf.otcc.yang.tapi.connectivity.rev221121.create.connectivity.service.input.EndPoint ep:
-                endPoints.values()) {
+        for (org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121
+                .create.connectivity.service.input.EndPoint ep: endPoints.values()) {
             EndPoint endpoint = new EndPointBuilder()
-                .setServiceInterfacePoint(new ServiceInterfacePointBuilder()
-                    .setServiceInterfacePointUuid(ep.getServiceInterfacePoint().getServiceInterfacePointUuid())
-                    .build())
+                .setServiceInterfacePoint(
+                    new ServiceInterfacePointBuilder()
+                        .setServiceInterfacePointUuid(ep.getServiceInterfacePoint().getServiceInterfacePointUuid())
+                        .build())
                 .setName(ep.getName())
                 .setAdministrativeState(ep.getAdministrativeState())
                 .setDirection(ep.getDirection())
                 .setLifecycleState(ep.getLifecycleState())
                 .setOperationalState(ep.getOperationalState())
                 .setLayerProtocolName(ep.getLayerProtocolName())
-                // TODO: implement bandwidth profile
                 .setCapacity(new CapacityBuilder()
                     .setTotalSize(new TotalSizeBuilder().build())
-//                    .setBandwidthProfile(new BandwidthProfileBuilder().build()) // TODO: implement bandwidth profile
+                // TODO: implement bandwidth profile //.setBandwidthProfile(new BandwidthProfileBuilder().build())
                     .build())
                 .setProtectionRole(ep.getProtectionRole())
                 .setRole(ep.getRole())