import org.opendaylight.transportpce.servicehandler.ServiceInput;
import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper;
import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.ServicePathRpcResult;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.TransportpcePceListener;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.service.path.rpc.result.PathDescription;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.service.path.rpc.result.PathDescriptionBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceImplementationRequestInput;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev181130.State;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.RpcStatusEx;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParameters;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParametersBuilder;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.PublishNotificationService;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.PublishNotificationServiceBuilder;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.notification.service.ServiceAEndBuilder;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.notification.service.ServiceZEndBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.ServicePathRpcResult;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.TransportpcePceListener;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.service.path.rpc.result.PathDescription;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.service.path.rpc.result.PathDescriptionBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestInput;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.list.Services;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.RpcStatusEx;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParametersBuilder;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationProcessService;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationProcessServiceBuilder;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.notification.process.service.ServiceAEndBuilder;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.notification.process.service.ServiceZEndBuilder;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class PceListenerImpl implements TransportpcePceListener {
+@Component
+public class PceListenerImpl implements TransportpcePceListener, PceListener {
private static final Logger LOG = LoggerFactory.getLogger(PceListenerImpl.class);
- private static final String TOPIC = "PceListener";
+ private static final String PUBLISHER = "PceListener";
private ServicePathRpcResult servicePathRpcResult;
private RendererServiceOperations rendererServiceOperations;
private Boolean serviceFeasiblity;
private NotificationPublishService notificationPublishService;
- public PceListenerImpl(RendererServiceOperations rendererServiceOperations,
- PathComputationService pathComputationService, NotificationPublishService notificationPublishService,
- ServiceDataStoreOperations serviceDataStoreOperations) {
+ @Activate
+ public PceListenerImpl(
+ @Reference RendererServiceOperations rendererServiceOperations,
+ @Reference PathComputationService pathComputationService,
+ @Reference NotificationPublishService notificationPublishService,
+ @Reference ServiceDataStoreOperations serviceDataStoreOperations) {
this.rendererServiceOperations = rendererServiceOperations;
this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService);
this.serviceDataStoreOperations = serviceDataStoreOperations;
private void onPathComputationResult(ServicePathRpcResult notification) {
LOG.info("PCE '{}' Notification received : {}", servicePathRpcResult.getNotificationType().getName(),
notification);
+
if (!checkStatus(notification)) {
return;
}
LOG.error("'PathDescription' parameter is null ");
return;
}
- PathDescription pathDescription = new PathDescriptionBuilder()
+ PathDescription pathDescription =
+ new PathDescriptionBuilder()
.setAToZDirection(servicePathRpcResult.getPathDescription().getAToZDirection())
.setZToADirection(servicePathRpcResult.getPathDescription().getZToADirection())
.build();
}
OperationResult operationResult = null;
if (tempService) {
- operationResult = this.serviceDataStoreOperations.createTempService(input.getTempServiceCreateInput());
+ operationResult =
+ this.serviceDataStoreOperations.createTempService(
+ input.getTempServiceCreateInput(), pathDescription);
if (!operationResult.isSuccess()) {
LOG.error("Temp Service not created in datastore !");
}
LOG.error("Service not created in datastore !");
}
}
- ResponseParameters responseParameters = new ResponseParametersBuilder()
- .setPathDescription(new org.opendaylight.yang.gen.v1.http
- .org.transportpce.b.c._interface.service.types.rev200128
- .response.parameters.sp.response.parameters.PathDescriptionBuilder(pathDescription).build())
- .build();
- PathComputationRequestOutput pceResponse = new PathComputationRequestOutputBuilder()
- .setResponseParameters(responseParameters).build();
- OperationResult operationServicePathSaveResult = this.serviceDataStoreOperations
- .createServicePath(input, pceResponse);
- if (!operationServicePathSaveResult.isSuccess()) {
+ if (!this.serviceDataStoreOperations
+ .createServicePath(
+ input,
+ //pceResponse
+ new PathComputationRequestOutputBuilder()
+ .setResponseParameters(
+ new ResponseParametersBuilder()
+ .setPathDescription(
+ new org.opendaylight.yang.gen.v1
+ .http.org.transportpce.b.c._interface.service.types.rev220118
+ .response.parameters.sp.response.parameters
+ .PathDescriptionBuilder(pathDescription)
+ .build())
+ .build())
+ .build())
+ .isSuccess()) {
LOG.error("Service Path not created in datastore !");
}
- ServiceImplementationRequestInput serviceImplementationRequest = ModelMappingUtils
- .createServiceImplementationRequest(input, pathDescription);
+ ServiceImplementationRequestInput serviceImplementationRequest =
+ ModelMappingUtils.createServiceImplementationRequest(input, pathDescription);
LOG.info("Sending serviceImplementation request : {}", serviceImplementationRequest);
- this.rendererServiceOperations.serviceImplementation(serviceImplementationRequest);
+ LOG.debug("Temp-service value is {}", tempService);
+ this.rendererServiceOperations.serviceImplementation(serviceImplementationRequest, tempService);
}
/**
* @return true is status is Successful, false otherwise.
*/
private boolean checkStatus(ServicePathRpcResult notification) {
- PublishNotificationService nbiNotification = getPublishNotificationService(notification);
- PublishNotificationServiceBuilder publishNotificationServiceBuilder = new PublishNotificationServiceBuilder(
- nbiNotification);
+ PublishNotificationProcessService nbiNotification = getPublishNotificationProcessService(notification);
+ PublishNotificationProcessServiceBuilder publishNotificationProcessServiceBuilder =
+ new PublishNotificationProcessServiceBuilder(nbiNotification);
+ //TODO is it worth to instantiate the 2 variables above if status is 'Pending' or 'Successful' ?
switch (servicePathRpcResult.getStatus()) {
case Failed:
LOG.error("PCE path computation failed !");
- nbiNotification = publishNotificationServiceBuilder.setMessage("ServiceCreate request failed ...")
+ nbiNotification = publishNotificationProcessServiceBuilder
+ .setMessage("ServiceCreate request failed ...")
.setResponseFailed("PCE path computation failed !")
.setOperationalState(State.Degraded).build();
sendNbiNotification(nbiNotification);
return false;
case Pending:
- LOG.warn("PCE path computation returned a Penging RpcStatusEx code!");
+ LOG.warn("PCE path computation returned a Pending RpcStatusEx code!");
return false;
case Successful:
LOG.info("PCE calculation done OK !");
- nbiNotification = publishNotificationServiceBuilder.setMessage("PCE calculation done OK !")
- .setResponseFailed("").setOperationalState(State.OutOfService).build();
- sendNbiNotification(nbiNotification);
return true;
default:
LOG.error("PCE path computation returned an unknown RpcStatusEx code {}",
servicePathRpcResult.getStatus());
- nbiNotification = publishNotificationServiceBuilder.setMessage("ServiceCreate request failed ...")
+ nbiNotification = publishNotificationProcessServiceBuilder
+ .setMessage("ServiceCreate request failed ...")
.setResponseFailed("PCE path computation returned an unknown RpcStatusEx code!")
.setOperationalState(State.Degraded).build();
sendNbiNotification(nbiNotification);
}
}
- private PublishNotificationService getPublishNotificationService(ServicePathRpcResult notification) {
- PublishNotificationServiceBuilder nbiNotificationBuilder = new PublishNotificationServiceBuilder();
- if (input != null) {
- nbiNotificationBuilder.setServiceName(input.getServiceName())
- .setServiceAEnd(new ServiceAEndBuilder(input.getServiceAEnd()).build())
- .setServiceZEnd(new ServiceZEndBuilder(input.getServiceZEnd()).build())
- .setCommonId(input.getCommonId()).setConnectionType(input.getConnectionType());
- } else {
- nbiNotificationBuilder.setServiceName(notification.getServiceName());
+ private PublishNotificationProcessService getPublishNotificationProcessService(ServicePathRpcResult notification) {
+ if (input == null) {
+ return new PublishNotificationProcessServiceBuilder()
+ .setServiceName(notification.getServiceName())
+ .setPublisherName(PUBLISHER)
+ .build();
}
- nbiNotificationBuilder.setTopic(TOPIC);
- return nbiNotificationBuilder.build();
+ return new PublishNotificationProcessServiceBuilder()
+ .setServiceName(input.getServiceName())
+ .setServiceAEnd(new ServiceAEndBuilder(input.getServiceAEnd()).build())
+ .setServiceZEnd(new ServiceZEndBuilder(input.getServiceZEnd()).build())
+ .setCommonId(input.getCommonId())
+ .setConnectionType(input.getConnectionType())
+ .setPublisherName(PUBLISHER)
+ .build();
}
/**
* Process cancel resource result.
*/
private void onCancelResourceResult() {
- if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
- LOG.info("PCE cancel resource failed !");
+ if (servicePathRpcResult.getStatus() == RpcStatusEx.Pending) {
+ LOG.warn("PCE cancel returned a Pending RpcStatusEx code !");
return;
- } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Pending) {
- LOG.warn("PCE cancel returned a Penging RpcStatusEx code!");
+ } else if (servicePathRpcResult.getStatus() != RpcStatusEx.Successful
+ && servicePathRpcResult.getStatus() != RpcStatusEx.Failed) {
+ LOG.error("PCE cancel returned an unknown RpcStatusEx code !");
return;
- } else if (servicePathRpcResult.getStatus() != RpcStatusEx.Successful) {
- LOG.error("PCE cancel returned an unknown RpcStatusEx code!");
+ }
+ PublishNotificationProcessServiceBuilder nbiNotificationBuilder;
+ State serviceOpState;
+ if (tempService) {
+ org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.temp.service.list.Services
+ tempServiceList = serviceDataStoreOperations.getTempService(input.getServiceName()).orElseThrow();
+ serviceOpState = tempServiceList.getOperationalState();
+ nbiNotificationBuilder =
+ new PublishNotificationProcessServiceBuilder()
+ .setServiceAEnd(new ServiceAEndBuilder(tempServiceList.getServiceAEnd()).build())
+ .setServiceZEnd(new ServiceZEndBuilder(tempServiceList.getServiceZEnd()).build())
+ .setCommonId(tempServiceList.getCommonId())
+ .setConnectionType(tempServiceList.getConnectionType())
+ .setPublisherName(PUBLISHER);
+ } else {
+ Services service = serviceDataStoreOperations.getService(input.getServiceName()).orElseThrow();
+ serviceOpState = service.getOperationalState();
+ nbiNotificationBuilder =
+ new PublishNotificationProcessServiceBuilder()
+ .setServiceName(service.getServiceName())
+ .setServiceAEnd(new ServiceAEndBuilder(service.getServiceAEnd()).build())
+ .setServiceZEnd(new ServiceZEndBuilder(service.getServiceZEnd()).build())
+ .setCommonId(service.getCommonId())
+ .setConnectionType(service.getConnectionType())
+ .setPublisherName(PUBLISHER);
+
+ }
+
+ if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
+ LOG.info("PCE cancel resource failed !");
+ sendNbiNotification(
+ nbiNotificationBuilder
+ .setResponseFailed("PCE cancel resource failed !")
+ .setMessage("ServiceDelete request failed ...")
+ .setOperationalState(serviceOpState)
+ .build());
return;
}
LOG.info("PCE cancel resource done OK !");
+ // Here the input refers to the transportPCE API and the serviceName will be commonId for temp-service
OperationResult deleteServicePathOperationResult =
this.serviceDataStoreOperations.deleteServicePath(input.getServiceName());
if (!deleteServicePathOperationResult.isSuccess()) {
- LOG.warn("Service path was not removed from datastore!");
+ LOG.warn("Service path was not removed from datastore !");
}
- OperationResult deleteServiceOperationResult = null;
+ OperationResult deleteServiceOperationResult;
+ String serviceType = "";
if (tempService) {
- deleteServiceOperationResult =
- this.serviceDataStoreOperations.deleteTempService(input.getServiceName());
- if (!deleteServiceOperationResult.isSuccess()) {
- LOG.warn("Temp Service was not removed from datastore!");
- }
+ deleteServiceOperationResult = this.serviceDataStoreOperations.deleteTempService(input.getServiceName());
+ serviceType = "Temp ";
} else {
- deleteServiceOperationResult =
- this.serviceDataStoreOperations.deleteService(input.getServiceName());
- if (!deleteServiceOperationResult.isSuccess()) {
- LOG.warn("Service was not removed from datastore!");
- }
+ deleteServiceOperationResult = this.serviceDataStoreOperations.deleteService(input.getServiceName());
+ }
+ if (deleteServiceOperationResult.isSuccess()) {
+ sendNbiNotification(
+ nbiNotificationBuilder
+ .setResponseFailed("")
+ .setMessage("{} Service deleted !")
+ .setOperationalState(State.Degraded)
+ .build());
+ } else {
+ LOG.warn("{} Service was not removed from datastore !", serviceType);
+ sendNbiNotification(
+ nbiNotificationBuilder
+ .setResponseFailed(serviceType + "Service was not removed from datastore !")
+ .setMessage("ServiceDelete request failed ...")
+ .setOperationalState(serviceOpState)
+ .build());
}
+ // TODO: should we re-initialize the temp-service boolean to false?
/**
* if it was an RPC serviceReconfigure, re-launch PCR.
*/
return true;
}
+ @Override
public void setInput(ServiceInput serviceInput) {
this.input = serviceInput;
}
+ @Override
public void setServiceReconfigure(Boolean serv) {
this.serviceReconfigure = serv;
}
+ @Override
public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
this.serviceDataStoreOperations = serviceData;
}
+ @Override
public void setTempService(Boolean tempService) {
this.tempService = tempService;
}
+ @Override
public void setServiceFeasiblity(Boolean serviceFeasiblity) {
this.serviceFeasiblity = serviceFeasiblity;
}
* Send notification to NBI notification in order to publish message.
* @param service PublishNotificationService
*/
- private void sendNbiNotification(PublishNotificationService service) {
+ private void sendNbiNotification(PublishNotificationProcessService service) {
try {
notificationPublishService.putNotification(service);
} catch (InterruptedException e) {