+ if (input instanceof ServiceReconfigureInput) {
+ LOG.info("PCR came from RPC serviceReconfigure ...");
+ ServiceReconfigureInput tmp = (ServiceReconfigureInput)input;
+ serviceName = tmp.getNewServiceName();
+ type = ServiceNotificationTypes.ServiceReconfigureResult;
+ mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, tmp, true);
+ } else if (input instanceof ServiceCreateInput) {
+ LOG.info("PCR came from RPC serviceCreate ...");
+ ServiceCreateInput tmp = (ServiceCreateInput)input;
+ serviceName = tmp.getServiceName();
+ type = ServiceNotificationTypes.ServiceCreateResult;
+ mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, tmp, true);
+ } else if (input instanceof Services) {
+ LOG.info("PCR came from RPC serviceRestoration ...");
+ Services tmp = (Services)input;
+ serviceName = tmp.getServiceName();
+ type = ServiceNotificationTypes.ServiceRestorationResult;
+ mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, tmp, true);
+ } else if (input instanceof ServiceFeasibilityCheckInput) {
+ LOG.info("PCR came from RPC ServiceFeasibilityCheck ...");
+ ServiceFeasibilityCheckInput tmp = (ServiceFeasibilityCheckInput)input;
+ serviceName = "no name";
+ type = ServiceNotificationTypes.ServiceCreateResult;
+ mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, tmp, false);
+ }
+ final String name = serviceName;
+ final ServiceNotificationTypes notifType = type;
+
+ /**
+ * Once PCE request is being sent to the PCE on
+ * interface B, PCE reply is expected until a timer
+ * expires.
+ */
+ notification = new ServiceRpcResultShBuilder()
+ .setNotificationType(notifType)
+ .setServiceName(serviceName).setStatus(RpcStatusEx.Pending)
+ .setStatusMessage("Service compliant, submitting PathComputation Request ...").build();
+ try {
+ notificationPublishService.putNotification(notification);
+ } catch (InterruptedException e) {
+ LOG.info("notification offer rejected : {}", e);
+ }
+ FutureCallback<Boolean> pceCallback = new FutureCallback<Boolean>() {
+ String message = "";
+ ServiceRpcResultSh notification = null;
+
+ @Override
+ public void onSuccess(Boolean response) {
+ if (response) {
+ /**
+ * If PCE reply is received before timer
+ * expiration with a positive result, a
+ * service is created with admin and
+ * operational status 'down'.
+ */
+ message = "PCE replied to PCR Request !";
+ LOG.info(message);
+ notification = new ServiceRpcResultShBuilder()
+ .setNotificationType(notifType)
+ .setServiceName(name).setStatus(RpcStatusEx.Pending)
+ .setStatusMessage(message).build();
+ try {
+ notificationPublishService.putNotification(notification);
+ } catch (InterruptedException e) {
+ LOG.info("notification offer rejected : {}", e);
+ }
+ } else {
+ message = mappingAndSendingPCRequest.getError();
+ notification = new ServiceRpcResultShBuilder()
+ .setNotificationType(notifType)
+ .setServiceName("").setStatus(RpcStatusEx.Failed).setStatusMessage(message)
+ .build();
+ try {
+ notificationPublishService.putNotification(notification);
+ } catch (InterruptedException e) {
+ LOG.info("notification offer rejected : {}", e);
+ }
+ }
+ }
+
+ @Override
+ public void onFailure(Throwable arg0) {
+ LOG.error("Path not calculated..");
+ notification = new ServiceRpcResultShBuilder()
+ .setNotificationType(notifType)
+ .setServiceName(name).setStatus(RpcStatusEx.Failed)
+ .setStatusMessage("PCR Request failed : " + arg0.getMessage()).build();
+ try {
+ notificationPublishService.putNotification(notification);
+ } catch (InterruptedException e) {
+ LOG.info("notification offer rejected : {}", e);
+ }
+
+ }
+ };
+ ListenableFuture<Boolean> pce = mappingAndSendingPCRequest.pathComputationRequest();
+ Futures.addCallback(pce, pceCallback, executor);
+ }
+
+ /**
+ * Send RPC cancel reserve
+ * resource to PCE.
+ */
+ private void pceCancelResResource() {
+ LOG.info("sending RPC cancel reserve resource to PCE ...");
+ Services pceService = null;
+ ServiceNotificationTypes notif = null;
+ if (serviceDeleteInput != null) {
+ LOG.info("pceCancelResResource came from RPC serviceDelete");
+ notif = ServiceNotificationTypes.ServiceDeleteResult;
+ String serviceName = serviceDeleteInput.getServiceDeleteReqInfo().getServiceName();
+ if (serviceName != null) {
+ pceService = readServiceList(serviceName);
+ } else {
+ LOG.info("Parameter 'serviceName' for pceCancelResResource is null");
+ }
+ } else if (service != null) {
+ notif = ServiceNotificationTypes.ServiceRestorationResult;
+ LOG.info("pceCancelResResource came from RPC serviceRestoration");
+ pceService = service;
+ } else if (serviceReconfigureInput != null) {
+ notif = ServiceNotificationTypes.ServiceReconfigureResult;
+ LOG.info("pceCancelResResource came from RPC serviceReconfigure");
+ String serviceName = serviceReconfigureInput.getServiceName();
+ if (serviceName != null) {
+ pceService = readServiceList(serviceName);
+ } else {
+ LOG.info("Parameter 'serviceName' for pceCancelResResource is null");
+ }
+ } else if (serviceCreateInput != null) {
+ notif = ServiceNotificationTypes.ServiceCreateResult;
+ LOG.info("pceCancelResResource came from RPC serviceCreate");
+ String serviceName = serviceCreateInput.getServiceName();
+ if (serviceName != null) {
+ pceService = readServiceList(serviceName);
+ } else {
+ LOG.info("Parameter 'serviceName' for pceCancelResResource is null");
+ }
+ }
+ if (pceService != null && notif != null) {
+ final Services cancelService = pceService;
+ final ServiceNotificationTypes type = notif;
+ mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, pceService, false);
+ FutureCallback<Boolean> pceCallback = new FutureCallback<Boolean>() {
+ String message = "";
+ ServiceRpcResultSh notification = null;
+ @Override
+ public void onSuccess(Boolean response) {
+ if (response) {
+ /**
+ * If PCE reply is received before timer
+ * expiration with a positive result, a
+ * service is created with admin and
+ * operational status 'down'.
+ */
+ message = "PCE replied to cancel resource Request !";
+ LOG.info(message);
+ notification = new ServiceRpcResultShBuilder()
+ .setNotificationType(type)
+ .setServiceName(cancelService.getServiceName()).setStatus(RpcStatusEx.Pending)
+ .setStatusMessage(message).build();
+ try {
+ notificationPublishService.putNotification(notification);
+ } catch (InterruptedException e) {
+ LOG.info("notification offer rejected : {}", e);
+ }
+ } else {
+ message = mappingAndSendingPCRequest.getError();
+ notification = new ServiceRpcResultShBuilder()
+ .setNotificationType(type)
+ .setServiceName("").setStatus(RpcStatusEx.Failed).setStatusMessage(message)
+ .build();
+ try {
+ notificationPublishService.putNotification(notification);
+ } catch (InterruptedException e) {
+ LOG.info("notification offer rejected : {}", e);
+ }
+ }
+ }
+
+ @Override
+ public void onFailure(Throwable arg0) {
+ message = "Cancel resource request failed !";
+ LOG.error(message);
+ notification = new ServiceRpcResultShBuilder()
+ .setNotificationType(type)
+ .setServiceName(cancelService.getServiceName()).setStatus(RpcStatusEx.Failed)
+ .setStatusMessage(message + " : " + arg0.getMessage()).build();
+ try {
+ notificationPublishService.putNotification(notification);
+ } catch (InterruptedException e) {
+ LOG.info("notification offer rejected : {}", e);
+ }
+
+ }
+ };
+ ListenableFuture<Boolean> pce = mappingAndSendingPCRequest.cancelResourceReserve();
+ Futures.addCallback(pce, pceCallback, executor);
+ }
+ }
+
+ private void stubrendererDelete() {
+ LOG.info("sending RPC service delete to stubrenderer ...");
+ String tmp = null;
+ String id = null;
+ if (service != null) {
+ LOG.info("RPC service delete came from RPC serviceRestoration !");
+ tmp = service.getServiceName();
+ id = service.getCommonId();
+ } else if (serviceDeleteInput != null) {
+ LOG.info("RPC service delete came from ServiceDelete !");
+ tmp = serviceDeleteInput.getServiceDeleteReqInfo().getServiceName();
+ id = serviceDeleteInput.getSdncRequestHeader().getRequestId();
+ }
+
+ if (tmp != null && id != null) {
+ final String serviceName = tmp;
+ LOG.info("stubrendererDelete service '{}'", serviceName);
+ mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, id, serviceName);
+ ListenableFuture<Boolean> renderer = mappingAndSendingSIRequest.serviceDelete();
+ FutureCallback<Boolean> rendererCallback = new FutureCallback<Boolean>() {
+ String message = "";
+ ServiceRpcResultSh notification = null;
+
+ @Override
+ public void onFailure(Throwable arg0) {
+ message = "ServiceDelete Request failed : " + arg0;
+ LOG.error("ServiceDelete Request failed !");
+ notification = new ServiceRpcResultShBuilder()
+ .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
+ .setServiceName(serviceName).setStatus(RpcStatusEx.Failed)
+ .setStatusMessage(message).build();
+ try {
+ notificationPublishService.putNotification(notification);
+ } catch (InterruptedException e) {
+ LOG.info("notification offer rejected : {}", e);
+ }
+
+ }
+
+ @Override
+ public void onSuccess(Boolean response) {
+ if (response) {
+ message = "Service deleted !";
+ notification = new ServiceRpcResultShBuilder()
+ .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
+ .setServiceName(serviceName).setStatus(RpcStatusEx.Pending)
+ .setStatusMessage(message).build();
+ try {
+ notificationPublishService.putNotification(notification);
+ } catch (InterruptedException e) {
+ LOG.info("notification offer rejected : {}", e);
+ }
+ } else {
+ message = "deleting service failed !";
+ notification = new ServiceRpcResultShBuilder()
+ .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
+ .setServiceName(serviceName).setStatus(RpcStatusEx.Failed)
+ .setStatusMessage(message)
+ .build();
+ try {
+ notificationPublishService.putNotification(notification);
+ } catch (InterruptedException e) {
+ LOG.info("notification offer rejected : {}", e);
+ }
+ }
+ }
+ };
+ Futures.addCallback(renderer, rendererCallback, executor);
+ } else {
+ LOG.info("Parameter 'serviceName' and / or 'id' is null");
+ }
+ }
+
+ /**
+ * send a RPC serviceImplementation
+ * to stubrenderer after
+ * receiving a stubpce notification.
+ *
+ * @param input ServiceCreate or ServiceReconfigure
+ */
+ private <T> void stubrendererImplementation(T input) {
+ ServiceRpcResultSh notification = null;
+ String serviceName = null;
+ String message = "";
+ String newServiceName = null;
+ ServiceNotificationTypes type = null;
+ Boolean create = false;
+ Boolean delete = true;
+ if (pathDescription != null) {
+ LOG.info("Pathdescription conatins in Stubpce notification received !");
+ String result = null;
+ PathComputationRequestOutput pathComputationResponse =
+ new PathComputationRequestOutputBuilder()
+ .setResponseParameters(new org.opendaylight.yang.gen.v1.http.org
+ .transportpce.b.c._interface.service.types.rev170426.response
+ .parameters.sp.ResponseParametersBuilder()
+ .setPathDescription(pathDescription)
+ .build())
+ .build();
+ if (input instanceof ServiceReconfigureInput) {
+ /** delete and write . */
+ LOG.info("RPC serviceImplementation came from RPC serviceReconfigure ...");
+ ServiceReconfigureInput tmp = (ServiceReconfigureInput)input;
+ serviceName = tmp.getServiceName();
+ newServiceName = tmp.getNewServiceName();
+ type = ServiceNotificationTypes.ServiceReconfigureResult;
+ delete = false;
+ mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, tmp,pathComputationResponse);
+ } else if (input instanceof ServiceCreateInput) {
+ /** create. */
+ LOG.info("RPC serviceImplementation came from RPC serviceCreate ...");
+ ServiceCreateInput tmp = (ServiceCreateInput)input;
+ serviceName = tmp.getServiceName();
+ type = ServiceNotificationTypes.ServiceCreateResult;
+ mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, tmp,pathComputationResponse);
+ delete = true;
+ create = true;
+ } else if (input instanceof Services) {
+ /** update. */
+ LOG.info("RPC serviceImplementation came from RPC ServiceRestoration ...");
+ Services tmp = new ServicesBuilder((Services)input)
+ .setAdministrativeState(State.OutOfService)
+ .setOperationalState(State.OutOfService)
+ .setLifecycleState(LifecycleState.Planned)
+ .build();
+ serviceName = tmp.getServiceName();
+ type = ServiceNotificationTypes.ServiceRestorationResult;
+ mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, tmp, pathComputationResponse);
+ delete = true;
+ create = true;
+ }
+ final String name = serviceName;
+ final ServiceNotificationTypes notifType = type;
+ if (!create) { /** ServiceReconfigure. */
+ if ((result = writeOrModifyOrDeleteServiceList(serviceName, pathComputationResponse,null, 1)) == null) {
+ LOG.info("Service '{}' deleted from datastore", serviceName);
+ serviceName = newServiceName;
+ delete = true;
+ } else {
+ LOG.info("deleting Service '{}' failed !", serviceName);
+ }
+ }
+ if (delete) {
+ if ((result = writeOrModifyOrDeleteServiceList(serviceName,pathComputationResponse,null, 2)) != null) {
+ LOG.info("writting Service failed !");
+ StringBuilder build = new StringBuilder();
+ build.append(message);
+ build.append(" " + result);
+ message = build.toString();
+ } else {
+ /**
+ * Send Implementation order to renderer
+ */
+ notification = new ServiceRpcResultShBuilder()
+ .setNotificationType(notifType)
+ .setServiceName(name)
+ .setStatus(RpcStatusEx.Pending)
+ .setStatusMessage("Submitting ServiceImplementation Request ...")
+ .build();
+ try {
+ notificationPublishService.putNotification(notification);
+ } catch (InterruptedException e) {
+ LOG.info("notification offer rejected : {}", e);
+ }
+
+ FutureCallback<Boolean> rendererCallback = new FutureCallback<Boolean>() {
+ String message = "";
+ ServiceRpcResultSh notification = null;
+
+ @Override
+ public void onSuccess(Boolean response) {
+ if (response) {
+ /**
+ * If stubrenderer reply is received before timer
+ * expiration with a positive result, a
+ * service is created with admin and
+ * operational status 'down'.
+ */
+ message = "StubRenderer replied to Request !";
+ LOG.info(message);
+ notification = new ServiceRpcResultShBuilder()
+ .setNotificationType(notifType)
+ .setServiceName(name).setStatus(RpcStatusEx.Pending)
+ .setStatusMessage(message).build();
+ try {
+ notificationPublishService.putNotification(notification);
+ } catch (InterruptedException e) {
+ LOG.info("notification offer rejected : {}", e);
+ }
+ } else {
+ message = mappingAndSendingSIRequest.getError();
+ notification = new ServiceRpcResultShBuilder()
+ .setNotificationType(notifType)
+ .setServiceName(name).setStatus(RpcStatusEx.Failed).setStatusMessage(message)
+ .build();
+ try {
+ notificationPublishService.putNotification(notification);
+ } catch (InterruptedException e) {
+ LOG.info("notification offer rejected : {}", e);
+ }
+ }
+ }
+
+ @Override
+ public void onFailure(Throwable arg0) {
+ LOG.error("Service not implemented ...");
+ notification = new ServiceRpcResultShBuilder()
+ .setNotificationType(notifType)
+ .setServiceName(name).setStatus(RpcStatusEx.Failed)
+ .setStatusMessage("Service implementation failed : " + arg0.getMessage()).build();
+ try {
+ notificationPublishService.putNotification(notification);
+ } catch (InterruptedException e) {
+ LOG.info("notification offer rejected : {}", e);
+ }
+ }
+ };
+ ListenableFuture<Boolean> renderer = mappingAndSendingSIRequest.serviceImplementation();
+ Futures.addCallback(renderer, rendererCallback, executor);
+ }
+ } else {
+ LOG.info("deleting Service failed");
+ }
+ } else {
+ message = "PathDescription contains in Stubpce notification "
+ + "not recieved !";
+ LOG.info(message);
+ }
+ }
+
+ /**
+ * Checking Service Compliancy.
+ *
+ * @return String if not compliant, null else
+ */
+ private String serviceCompliancy(SdncRequestHeader sdncRequestHeader, String serviceName,
+ ConnectionType connectionType, RpcActions rpcActions, ServiceEndpoint aend, ServiceEndpoint zend,
+ String commonIdValue, HardConstraints hard, SoftConstraints soft) {
+ String message = null;
+ Boolean contype = false;
+ Boolean sdncRequest = false;
+ Boolean commonId = true;
+ Boolean coherencyHardSoft = false;
+
+ if (rpcActions.equals(RpcActions.ServiceCreate) || rpcActions.equals(RpcActions.ServiceFeasibilityCheck)
+ || rpcActions.equals(RpcActions.ServiceDelete)) {
+ sdncRequest = true;
+ } else if (rpcActions.equals(RpcActions.ServiceCreate)
+ || rpcActions.equals(RpcActions.ServiceFeasibilityCheck)
+ || rpcActions.equals(RpcActions.ServiceReconfigure)) {
+ contype = true;
+ }
+ compliancyCheck = new ServicehandlerCompliancyCheck(sdncRequestHeader, serviceName,
+ connectionType, rpcActions);
+ if (compliancyCheck.check(contype, sdncRequest)) {