X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=servicehandler%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fservicehandler%2Fservice%2FServiceDataStoreOperationsImpl.java;h=9c9c8de52c3e0b5135fcba8947944338330be587;hb=116031ee55870cc5a3c90a18716fbd0fc26bb399;hp=be0c5d7ee95d10fd6f1d791f3b995590308321a7;hpb=f3253f3398b27936e0d017f6b470b0360827b8f4;p=transportpce.git diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImpl.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImpl.java index be0c5d7ee..9c9c8de52 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImpl.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImpl.java @@ -10,12 +10,10 @@ package org.opendaylight.transportpce.servicehandler.service; import com.google.common.util.concurrent.FluentFuture; import java.util.Optional; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.mdsal.binding.api.DataBroker; -import org.opendaylight.mdsal.binding.api.ReadTransaction; import org.opendaylight.mdsal.binding.api.WriteTransaction; import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; @@ -23,18 +21,18 @@ import org.opendaylight.transportpce.common.OperationResult; import org.opendaylight.transportpce.common.Timeouts; import org.opendaylight.transportpce.servicehandler.ModelMappingUtils; import org.opendaylight.transportpce.servicehandler.ServiceInput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev230925.PathComputationRequestOutput; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State; import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceList; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceListBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceList; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceListBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.Services; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.ServicesBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.ServicesKey; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceList; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceListBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceCreateInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceList; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceListBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.list.Services; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.list.ServicesBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.list.ServicesKey; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.service.path.PathDescription; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.ServicePathList; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths; @@ -92,9 +90,10 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation try { LOG.info("initializing service registry"); WriteTransaction transaction = this.dataBroker.newWriteOnlyTransaction(); - InstanceIdentifier iid = InstanceIdentifier.create(ServiceList.class); - ServiceList initialRegistry = new ServiceListBuilder().build(); - transaction.put(LogicalDatastoreType.OPERATIONAL, iid, initialRegistry); + transaction.merge( + LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.create(ServiceList.class), + new ServiceListBuilder().build()); FluentFuture future = transaction.commit(); future.get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { @@ -106,9 +105,10 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation try { LOG.info("initializing temp service registry"); WriteTransaction transaction = this.dataBroker.newWriteOnlyTransaction(); - InstanceIdentifier iid = InstanceIdentifier.create(TempServiceList.class); - TempServiceList initialRegistry = new TempServiceListBuilder().build(); - transaction.put(LogicalDatastoreType.OPERATIONAL, iid, initialRegistry); + transaction.merge( + LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.create(TempServiceList.class), + new TempServiceListBuilder().build()); FluentFuture future = transaction.commit(); future.get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { @@ -119,12 +119,13 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation @Override public Optional getService(String serviceName) { try { - ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction(); - InstanceIdentifier iid = - InstanceIdentifier.create(ServiceList.class).child(Services.class, new ServicesKey(serviceName)); - Future> future = - readTx.read(LogicalDatastoreType.OPERATIONAL, iid); - return future.get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS); + return this.dataBroker.newReadOnlyTransaction() + .read( + LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.create(ServiceList.class) + .child(Services.class, new ServicesKey(serviceName)) + ) + .get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { LOG.warn("Reading service {} failed:", serviceName, e); } @@ -134,12 +135,11 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation @Override public Optional getServices() { try { - ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction(); - InstanceIdentifier iid = - InstanceIdentifier.create(ServiceList.class); - Future> future = - readTx.read(LogicalDatastoreType.OPERATIONAL, iid); - return future.get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS); + return this.dataBroker.newReadOnlyTransaction() + .read( + LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.create(ServiceList.class)) + .get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { LOG.warn("Reading services failed:", e); } @@ -147,19 +147,19 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation } @Override - public Optional - getTempService(String serviceName) { + public Optional getTempService(String serviceName) { try { - ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction(); - InstanceIdentifier iid = InstanceIdentifier.create(TempServiceList.class).child( - org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list.Services.class, - new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list.ServicesKey( - serviceName)); - FluentFuture> future - = readTx.read(LogicalDatastoreType.OPERATIONAL, iid); - return future.get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS); + return this.dataBroker.newReadOnlyTransaction() + .read( + LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.create(TempServiceList.class) + .child( + org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526 + .temp.service.list.Services.class, + new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526 + .temp.service.list.ServicesKey(serviceName))) + .get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { LOG.warn("Reading service {} failed:", serviceName, e); } @@ -171,9 +171,10 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation LOG.debug(DELETING_SERVICE_MSG, serviceName); try { WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction(); - InstanceIdentifier iid = - InstanceIdentifier.create(ServiceList.class).child(Services.class, new ServicesKey(serviceName)); - writeTx.delete(LogicalDatastoreType.OPERATIONAL, iid); + writeTx.delete( + LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.create(ServiceList.class) + .child(Services.class, new ServicesKey(serviceName))); writeTx.commit().get(Timeouts.DATASTORE_DELETE, TimeUnit.MILLISECONDS); return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE); } catch (TimeoutException | InterruptedException | ExecutionException e) { @@ -187,12 +188,14 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation LOG.debug(DELETING_SERVICE_MSG, commonId); try { WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction(); - InstanceIdentifier iid = InstanceIdentifier.create(TempServiceList.class).child(org.opendaylight.yang.gen.v1 - .http.org.openroadm.service.rev211210.temp.service.list.Services.class, - new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list - .ServicesKey(commonId)); - writeTx.delete(LogicalDatastoreType.OPERATIONAL, iid); + writeTx.delete( + LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.create(TempServiceList.class) + .child( + org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526 + .temp.service.list.Services.class, + new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526 + .temp.service.list.ServicesKey(commonId))); writeTx.commit().get(Timeouts.DATASTORE_DELETE, TimeUnit.MILLISECONDS); return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE); } catch (TimeoutException | InterruptedException | ExecutionException e) { @@ -205,19 +208,20 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation public OperationResult modifyService(String serviceName, State operationalState, AdminStates administrativeState) { LOG.debug("Modifying '{}' Service", serviceName); Optional readService = getService(serviceName); - if (!readService.isPresent()) { + if (readService.isEmpty()) { LOG.warn("modifyService: {}", LogMessages.SERVICE_NOT_FOUND); return OperationResult.failed(LogMessages.SERVICE_NOT_FOUND); } try { WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction(); - InstanceIdentifier iid = InstanceIdentifier.create(ServiceList.class) - .child(Services.class, new ServicesKey(serviceName)); - Services services = new ServicesBuilder(readService.get()) - .setOperationalState(operationalState) - .setAdministrativeState(administrativeState) - .build(); - writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, services); + writeTx.merge( + LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.create(ServiceList.class) + .child(Services.class, new ServicesKey(serviceName)), + new ServicesBuilder(readService.orElseThrow()) + .setOperationalState(operationalState) + .setAdministrativeState(administrativeState) + .build()); writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS); return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE); } catch (TimeoutException | InterruptedException | ExecutionException e) { @@ -227,29 +231,30 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation } @Override - public OperationResult modifyTempService(String serviceName, State operationalState, - AdminStates administrativeState) { + public OperationResult modifyTempService( + String serviceName, State operationalState, AdminStates administrativeState) { LOG.debug("Modifying '{}' Temp Service", serviceName); - Optional readService = getTempService(serviceName); - if (!readService.isPresent()) { + Optional readService = getTempService(serviceName); + if (readService.isEmpty()) { LOG.warn("modifyTempService: {}", LogMessages.SERVICE_NOT_FOUND); return OperationResult.failed(LogMessages.SERVICE_NOT_FOUND); } try { WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction(); - InstanceIdentifier iid = InstanceIdentifier.create(TempServiceList.class) - .child(org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list - .Services.class, new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210 - .temp.service.list.ServicesKey(serviceName)); - org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list.Services services = - new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list.ServicesBuilder( - readService.get()) - .setOperationalState(operationalState) - .setAdministrativeState(administrativeState) - .build(); - writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, services); + writeTx.merge( + LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.create(TempServiceList.class) + .child( + org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526 + .temp.service.list.Services.class, + new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526 + .temp.service.list.ServicesKey(serviceName)), + new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526 + .temp.service.list.ServicesBuilder(readService.orElseThrow()) + .setOperationalState(operationalState) + .setAdministrativeState(administrativeState) + .build()); writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS); return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE); } catch (TimeoutException | InterruptedException | ExecutionException e) { @@ -262,11 +267,12 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation public OperationResult createService(ServiceCreateInput serviceCreateInput) { LOG.debug("Writing '{}' Service", serviceCreateInput.getServiceName()); try { - InstanceIdentifier iid = InstanceIdentifier.create(ServiceList.class) - .child(Services.class, new ServicesKey(serviceCreateInput.getServiceName())); - Services service = ModelMappingUtils.mappingServices(serviceCreateInput, null); WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction(); - writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, service); + writeTx.put( + LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.create(ServiceList.class) + .child(Services.class, new ServicesKey(serviceCreateInput.getServiceName())), + ModelMappingUtils.mappingServices(serviceCreateInput, null)); writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS); return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE); } catch (TimeoutException | InterruptedException | ExecutionException e) { @@ -276,18 +282,21 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation } @Override - public OperationResult createTempService(TempServiceCreateInput tempServiceCreateInput) { + public OperationResult createTempService( + TempServiceCreateInput tempServiceCreateInput, + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev230925 + .service.path.rpc.result.PathDescription pathDescription) { LOG.debug("Writing '{}' Temp Service", tempServiceCreateInput.getCommonId()); try { - InstanceIdentifier iid = InstanceIdentifier.create(TempServiceList.class) - .child(org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list - .Services.class, new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp - .service.list.ServicesKey(tempServiceCreateInput.getCommonId())); - org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list - .Services service = ModelMappingUtils.mappingServices(tempServiceCreateInput); WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction(); - writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, service); + writeTx.put( + LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.create(TempServiceList.class) + .child(org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526 + .temp.service.list.Services.class, + new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526 + .temp.service.list.ServicesKey(tempServiceCreateInput.getCommonId())), + ModelMappingUtils.mappingServices(tempServiceCreateInput, pathDescription)); writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS); return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE); } catch (TimeoutException | InterruptedException | ExecutionException e) { @@ -301,11 +310,11 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation public Optional getServicePaths() { LOG.debug("Retrieving list of ServicePath..."); try { - ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction(); - InstanceIdentifier servicePathListIID = InstanceIdentifier.create(ServicePathList.class); - Future> future = readTx.read(LogicalDatastoreType.OPERATIONAL, - servicePathListIID); - return future.get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS); + return this.dataBroker.newReadOnlyTransaction() + .read( + LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.create(ServicePathList.class)) + .get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { LOG.error("Reading service path list failed. Error={}", e.getMessage()); } @@ -316,12 +325,12 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation public Optional getServicePath(String serviceName) { LOG.debug("Retrieving service path of service {}", serviceName); try { - ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction(); - InstanceIdentifier servicePathsIID = InstanceIdentifier.create(ServicePathList.class) - .child(ServicePaths.class, new ServicePathsKey(serviceName)); - Future> future = readTx.read(LogicalDatastoreType.OPERATIONAL, - servicePathsIID); - return future.get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS); + return this.dataBroker.newReadOnlyTransaction() + .read( + LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.create(ServicePathList.class) + .child(ServicePaths.class, new ServicePathsKey(serviceName))) + .get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { LOG.error("Reading service path failed. Error={}", e.getMessage()); } @@ -332,11 +341,12 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation public OperationResult createServicePath(ServiceInput serviceInput, PathComputationRequestOutput outputFromPce) { LOG.debug("Writing '{}' ServicePath ", serviceInput.getServiceName()); try { - InstanceIdentifier servicePathsIID = InstanceIdentifier.create(ServicePathList.class) - .child(ServicePaths.class, new ServicePathsKey(serviceInput.getServiceName())); - ServicePaths servicePath = ModelMappingUtils.mappingServicePaths(serviceInput, outputFromPce); WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction(); - writeTx.put(LogicalDatastoreType.OPERATIONAL, servicePathsIID, servicePath); + writeTx.put( + LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.create(ServicePathList.class) + .child(ServicePaths.class, new ServicePathsKey(serviceInput.getServiceName())), + ModelMappingUtils.mappingServicePaths(serviceInput, outputFromPce)); writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS); return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE); } catch (TimeoutException | InterruptedException | ExecutionException e) { @@ -350,30 +360,30 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation public OperationResult modifyServicePath(PathDescription pathDescription, String serviceName) { LOG.debug("Updating servicePath because of a change in the openroadm-topology"); Optional readServicePath = getServicePath(serviceName); - if (!readServicePath.isPresent()) { + if (readServicePath.isEmpty()) { LOG.warn("modifyServicePath: {}", LogMessages.SERVICE_PATH_NOT_FOUND); return OperationResult.failed(LogMessages.SERVICE_PATH_NOT_FOUND); } try { WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction(); - InstanceIdentifier iid = InstanceIdentifier.create(ServicePathList.class) - .child(ServicePaths.class, new ServicePathsKey(serviceName)); - ServicePaths servicePaths = new ServicePathsBuilder() - .setServiceAEnd(readServicePath.get().getServiceAEnd()) - .setServiceHandlerHeader(readServicePath.get().getServiceHandlerHeader()) - .setServicePathName(readServicePath.get().getServicePathName()) - .setServiceZEnd(readServicePath.get().getServiceZEnd()) - .setSupportingServiceName(readServicePath.get().getSupportingServiceName()) - .setEquipmentSrgs(readServicePath.get().getEquipmentSrgs()) - .setFiberSpanSrlgs(readServicePath.get().getFiberSpanSrlgs()) - .setHardConstraints(readServicePath.get().getHardConstraints()) - .setLatency(readServicePath.get().getLatency()) + writeTx.merge( + LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.create(ServicePathList.class) + .child(ServicePaths.class, new ServicePathsKey(serviceName)), + new ServicePathsBuilder() + .setServiceAEnd(readServicePath.orElseThrow().getServiceAEnd()) + .setServiceHandlerHeader(readServicePath.orElseThrow().getServiceHandlerHeader()) + .setServicePathName(readServicePath.orElseThrow().getServicePathName()) + .setServiceZEnd(readServicePath.orElseThrow().getServiceZEnd()) + .setSupportingServiceName(readServicePath.orElseThrow().getSupportingServiceName()) + .setEquipmentSrgs(readServicePath.orElseThrow().getEquipmentSrgs()) + .setFiberSpanSrlgs(readServicePath.orElseThrow().getFiberSpanSrlgs()) + .setHardConstraints(readServicePath.orElseThrow().getHardConstraints()) + .setLatency(readServicePath.orElseThrow().getLatency()) .setPathDescription(pathDescription) - .setPceRoutingMetric(readServicePath.get().getPceRoutingMetric()) - .setSoftConstraints(readServicePath.get().getSoftConstraints()) - .build(); - - writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, servicePaths); + .setPceRoutingMetric(readServicePath.orElseThrow().getPceRoutingMetric()) + .setSoftConstraints(readServicePath.orElseThrow().getSoftConstraints()) + .build()); writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS); return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE); } catch (TimeoutException | InterruptedException | ExecutionException e) { @@ -384,7 +394,8 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation @Override public OperationResult deleteServicePath(String serviceName) { - InstanceIdentifier servicePathsIID = InstanceIdentifier.create(ServicePathList.class) + InstanceIdentifier servicePathsIID = + InstanceIdentifier.create(ServicePathList.class) .child(ServicePaths.class, new ServicePathsKey(serviceName)); LOG.debug("Deleting service from {}", servicePathsIID); WriteTransaction servicePathsWriteTx = this.dataBroker.newWriteOnlyTransaction(); @@ -413,26 +424,25 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation */ @Deprecated @Override - public String writeOrModifyOrDeleteServiceList(String serviceName, ServiceCreateInput input, - PathComputationRequestOutput output, int choice) { + public String writeOrModifyOrDeleteServiceList( + String serviceName, ServiceCreateInput input, PathComputationRequestOutput output, int choice) { LOG.debug("WriteOrModifyOrDeleting '{}' Service", serviceName); WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction(); Optional readService = getService(serviceName); - /* * Write Service. */ - if (!readService.isPresent()) { + if (readService.isEmpty()) { if (choice != 2) { LOG.warn("writeOrModifyOrDeleteServiceList: {}", LogMessages.SERVICE_NOT_FOUND); return LogMessages.SERVICE_NOT_FOUND; } - LOG.debug("Writing '{}' Service", serviceName); - InstanceIdentifier iid = InstanceIdentifier.create(ServiceList.class) - .child(Services.class, new ServicesKey(serviceName)); - Services service = ModelMappingUtils.mappingServices(input, null); - writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, service); + writeTx.put( + LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.create(ServiceList.class) + .child(Services.class, new ServicesKey(serviceName)), + ModelMappingUtils.mappingServices(input, null)); try { writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS); return null; @@ -446,15 +456,18 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation * Modify / Delete Service. */ InstanceIdentifier iid = - InstanceIdentifier.create(ServiceList.class).child(Services.class, new ServicesKey(serviceName)); - ServicesBuilder service = new ServicesBuilder(readService.get()); + InstanceIdentifier.create(ServiceList.class).child(Services.class, new ServicesKey(serviceName)); String action = null; switch (choice) { case 0 : /* Modify. */ LOG.debug("Modifying '{}' Service", serviceName); - service.setOperationalState(State.InService) - .setAdministrativeState(AdminStates.InService); - writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, service.build()); + writeTx.merge( + LogicalDatastoreType.OPERATIONAL, + iid, + new ServicesBuilder(readService.orElseThrow()) + .setOperationalState(State.InService) + .setAdministrativeState(AdminStates.InService) + .build()); action = "modifyService"; break; case 1 : /* Delete */