+ LOG.info("Mapping to PCE Cancel resource request input");
+ CancelResourceReserveInputBuilder cancelResourceReserveInput = new CancelResourceReserveInputBuilder();
+ if (serviceName != null) {
+ ServiceHandlerHeaderBuilder serviceHandlerHeader = new ServiceHandlerHeaderBuilder();
+ if (sdncRequestHeader != null) {
+ serviceHandlerHeader.setRequestId(sdncRequestHeader.getRequestId());
+ }
+ cancelResourceReserveInput.setServiceName(serviceName)
+ .setServiceHandlerHeader(serviceHandlerHeader.build());
+ return cancelResourceReserveInput.build();
+ } else {
+ LOG.error("Service Name (common-id for Temp service) is not set");
+ return null;
+ }
+ }
+
+ public CancelResourceReserveOutput cancelPCEResource(String serviceName, ServiceNotificationTypes notifType) {
+ LOG.info("Calling cancel resource reserve computation.");
+ notification = new ServiceRpcResultShBuilder().setNotificationType(notifType).setServiceName(serviceName)
+ .setStatus(RpcStatusEx.Pending)
+ .setStatusMessage("submitting Cancel resource reserve Request ...").build();
+ try {
+ notificationPublishService.putNotification(notification);
+ } catch (InterruptedException e) {
+ LOG.info("notification offer rejected : ", e);
+ }
+ FutureCallback<CancelResourceReserveOutput> pceCallback = new FutureCallback<CancelResourceReserveOutput>() {
+
+ String message = "";
+ ServiceRpcResultSh notification = null;
+
+ @Override
+ public void onSuccess(CancelResourceReserveOutput response) {
+ if (response != null) {
+ /**
+ * 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 CRR Request !";
+ LOG.info("PCE replied to CRR Request : {}", response);
+ notification =
+ new ServiceRpcResultShBuilder().setNotificationType(notifType).setServiceName(serviceName)
+ .setStatus(RpcStatusEx.Successful).setStatusMessage(message).build();
+ try {
+ notificationPublishService.putNotification(notification);
+ } catch (InterruptedException e) {
+ LOG.info("notification offer rejected : ", e);
+ }
+ } else {
+ message = "PCE failed ";
+ 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("Cancel resource failed !");
+ notification = new ServiceRpcResultShBuilder().setNotificationType(notifType)
+ .setServiceName(serviceName).setStatus(RpcStatusEx.Failed)
+ .setStatusMessage("CRR Request failed : " + arg0.getMessage()).build();
+ try {
+ notificationPublishService.putNotification(notification);
+ } catch (InterruptedException e) {
+ LOG.info("notification offer rejected : ", e);
+ }
+ }
+ };
+ CancelResourceReserveInput cancelResourceReserveInput = mappingCancelResourceReserve(serviceName, null);
+ ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder();
+ if (cancelResourceReserveInput != null) {
+ String requestId = cancelResourceReserveInput.getServiceHandlerHeader().getRequestId();
+ ListenableFuture<CancelResourceReserveOutput> pce =
+ this.pathComputationService.cancelResourceReserve(cancelResourceReserveInput);
+ Futures.addCallback(pce, pceCallback, executor);
+ if (requestId != null) {
+ configurationResponseCommon.setRequestId(requestId);
+ }
+ configurationResponseCommon.setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
+ .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress");
+ return new CancelResourceReserveOutputBuilder()
+ .setConfigurationResponseCommon(configurationResponseCommon.build()).build();
+ } else {
+ configurationResponseCommon.setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES)
+ .setResponseCode(ResponseCodes.RESPONSE_FAILED).setResponseMessage("PCE failed !");
+ return new CancelResourceReserveOutputBuilder()
+ .setConfigurationResponseCommon(configurationResponseCommon.build()).build();
+ }
+ }
+
+ private static PathComputationRequestOutput returnPCEFailed() {
+ ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
+ .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setResponseCode(ResponseCodes.RESPONSE_FAILED)
+ .setResponseMessage("PCE calculation failed").build();
+ ResponseParameters reponseParameters = new ResponseParametersBuilder().build();
+ return new PathComputationRequestOutputBuilder().setConfigurationResponseCommon(configurationResponseCommon)
+ .setResponseParameters(reponseParameters).build();
+ }
+
+ private Boolean validateParams(String serviceName, SdncRequestHeader sdncRequestHeader) {
+ boolean result = true;
+ if (!checkString(serviceName)) {
+ result = false;
+ LOG.error("Service Name (common-id for Temp service) is not set");
+ } else if (sdncRequestHeader == null) {
+ LOG.error("Service sdncRequestHeader 'request-id' is not set");
+ result = false;