X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=servicehandler%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fservicehandler%2Fservice%2FServiceDataStoreOperationsImpl.java;h=55533fb0e96c3b44a823eefb94f896303c999ad5;hb=1e2f9a502de80450411761fd2f636e2b7ee32301;hp=bd590e607a2f088e28abc091a88b338c2c4c227a;hpb=af8abb98d3ad0da091ff30bc7abafbe6af7ae57e;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 bd590e607..55533fb0e 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 @@ -23,9 +23,9 @@ 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.rev200128.PathComputationRequestOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev181130.State; -import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev181130.AdminStates; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.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.rev190531.ServiceCreateInput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceList; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceListBuilder; @@ -35,8 +35,10 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempSer import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.Services; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.ServicesBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.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; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsBuilder; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; @@ -44,6 +46,8 @@ import org.slf4j.LoggerFactory; public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperations { private static final Logger LOG = LoggerFactory.getLogger(ServiceDataStoreOperationsImpl.class); + private static final String CREATE_MSG = "create"; + private static final String DELETING_SERVICE_MSG = "Deleting '{}' Service"; private DataBroker dataBroker; // This is class is public so that these messages can be accessed from Junit (avoid duplications). @@ -51,11 +55,13 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation public static final String SUCCESSFUL_MESSAGE; public static final String SERVICE_NOT_FOUND; + public static final String SERVICE_PATH_NOT_FOUND; // Static blocks are generated once and spare memory. static { SUCCESSFUL_MESSAGE = "Successful"; SERVICE_NOT_FOUND = "Service not found"; + SERVICE_PATH_NOT_FOUND = "Service path not found"; } public static String failedTo(String action, String serviceName) { @@ -121,8 +127,23 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation } @Override - public Optional getTempService(String serviceName) { + 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); + } catch (InterruptedException | ExecutionException | TimeoutException e) { + LOG.warn("Reading services failed:", e); + } + return Optional.empty(); + } + + @Override + public Optional + getTempService(String serviceName) { try { ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction(); InstanceIdentifier iid = @@ -157,7 +178,7 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation @Override public OperationResult deleteTempService(String commonId) { - LOG.debug("Deleting '{}' Service", commonId); + LOG.debug(DELETING_SERVICE_MSG, commonId); 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(); + Services services = new ServicesBuilder(readService.get()) + .setOperationalState(convertOperState(operationalState)) + .setAdministrativeState(convertAdminState(administrativeState)) + .build(); writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, services); writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS); return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE); @@ -215,11 +237,12 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation .child(org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.temp.service.list .Services.class, new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531 .temp.service.list.ServicesKey(serviceName)); - org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.temp.service.list - .Services services = new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.temp - .service.list.ServicesBuilder(readService.get()).setOperationalState(operationalState) - .setAdministrativeState(administrativeState) - .build(); + org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.temp.service.list.Services services = + new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.temp.service.list.ServicesBuilder( + readService.get()) + .setOperationalState(convertOperState(operationalState)) + .setAdministrativeState(convertAdminState(administrativeState)) + .build(); writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, services); writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS); return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE); @@ -241,8 +264,8 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS); return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE); } catch (TimeoutException | InterruptedException | ExecutionException e) { - LOG.warn("createService : {}", LogMessages.failedTo("create", serviceCreateInput.getServiceName()), e); - return OperationResult.failed(LogMessages.failedTo("create", serviceCreateInput.getServiceName())); + LOG.warn("createService : {}", LogMessages.failedTo(CREATE_MSG, serviceCreateInput.getServiceName()), e); + return OperationResult.failed(LogMessages.failedTo(CREATE_MSG, serviceCreateInput.getServiceName())); } } @@ -268,6 +291,37 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation } } + @Override + 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); + } catch (InterruptedException | ExecutionException | TimeoutException e) { + LOG.error("Reading service path list failed. Error={}", e.getMessage()); + } + return Optional.empty(); + } + + @Override + 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); + } catch (InterruptedException | ExecutionException | TimeoutException e) { + LOG.error("Reading service path failed. Error={}", e.getMessage()); + } + return Optional.empty(); + } + @Override public OperationResult createServicePath(ServiceInput serviceInput, PathComputationRequestOutput outputFromPce) { LOG.debug("Writing '{}' ServicePath ", serviceInput.getServiceName()); @@ -286,6 +340,42 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation } } + @Override + 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()) { + 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()) + .setPathDescription(pathDescription) + .setPceRoutingMetric(readServicePath.get().getPceRoutingMetric()) + .setSoftConstraints(readServicePath.get().getSoftConstraints()) + .build(); + + writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, servicePaths); + writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS); + return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE); + } catch (TimeoutException | InterruptedException | ExecutionException e) { + LOG.warn("modifyServicePath : {}", LogMessages.failedTo("modify service path", serviceName), e); + return OperationResult.failed(LogMessages.failedTo("modify service path", serviceName)); + } + } + @Override public OperationResult deleteServicePath(String serviceName) { InstanceIdentifier servicePathsIID = InstanceIdentifier.create(ServicePathList.class) @@ -341,8 +431,8 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS); return null; } catch (InterruptedException | TimeoutException | ExecutionException e) { - LOG.error("writeOrModifyOrDeleteServiceList : {}", LogMessages.failedTo("create", serviceName), e); - return LogMessages.failedTo("create", serviceName); + LOG.error("writeOrModifyOrDeleteServiceList : {}", LogMessages.failedTo(CREATE_MSG, serviceName), e); + return LogMessages.failedTo(CREATE_MSG, serviceName); } } @@ -356,12 +446,13 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation switch (choice) { case 0 : /* Modify. */ LOG.debug("Modifying '{}' Service", serviceName); - service.setOperationalState(State.InService).setAdministrativeState(AdminStates.InService); + service.setOperationalState(convertOperState(State.InService)) + .setAdministrativeState(convertAdminState(AdminStates.InService)); writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, service.build()); action = "modifyService"; break; case 1 : /* Delete */ - LOG.debug("Deleting '{}' Service", serviceName); + LOG.debug(DELETING_SERVICE_MSG, serviceName); writeTx.delete(LogicalDatastoreType.OPERATIONAL, iid); action = "deleteService"; break; @@ -378,4 +469,16 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation return null; } + + private org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev181130.AdminStates + convertAdminState(AdminStates adminState61) { + return org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev181130.AdminStates + .valueOf(adminState61.name()); + } + + private org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev181130.State + convertOperState(State operState61) { + return org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev181130.State + .valueOf(operState61.name()); + } }