- public Future<RpcResult<ServiceReconfigureOutput>> serviceReconfigure(ServiceReconfigureInput input) {
-
- LOG.info("RPC service reconfigure received");
- notificationUrl = null;// input.getnotificationUrl();
- boolean commonId = true;
- boolean coherencyHardSoft = false;
- ServiceRpcResult notification = null;
-
- String message = "";
- LOG.info("checking Service Compliancy ...");
- /*
- * Upon receipt of service-create RPC, service header and sdnc-request
- * header compliancy are verified.
- */
- compliancyCheck = new ServicehandlerCompliancyCheck(input.getServiceName(), input.getConnectionType(),
- RpcActions.ServiceReconfigure);
- if (compliancyCheck.check(true, false)) {
- LOG.info("Service compliant !");
- /*
- * If compliant, service-request parameters are verified in order to
- * check if there is no missing parameter that prevents calculating
- * a path and implement a service.
- */
- LOG.info("checking Tx/Rx Info for AEnd ...");
- txrxCheck = new ServicehandlerTxRxCheck(input.getServiceAEnd(), 1);
- if (txrxCheck.check()) {
- LOG.info("Tx/Rx Info for AEnd checked !");
- LOG.info("checking Tx/Rx Info for ZEnd ...");
- txrxCheck = new ServicehandlerTxRxCheck(input.getServiceZEnd(), 2);
- if (txrxCheck.check()) {
- LOG.info("Tx/Rx Info for ZEnd checked");
- /*
- * If OK, common-id is verified in order to see if there is
- * no routing policy provided. If yes, the routing
- * constraints of the policy are recovered and coherency
- * with hard/soft constraints provided in the input of the
- * RPC.
- */
- if (input.getCommonId() != null) {
- LOG.info("Common-id specified");
- /*
- * Check coherency with hard/soft constraints
- */
-
- checkCoherencyHardSoft = new CheckCoherencyHardSoft(input.getHardConstraints(),
- input.getSoftConstraints());
- if (checkCoherencyHardSoft.check()) {
- LOG.info("hard/soft constraints coherent !");
- coherencyHardSoft = true;
- } else {
- LOG.info("hard/soft constraints are not coherent !");
- message = "hard/soft constraints are not coherent !";
- }
- } else {
- commonId = false;
- }
-
- if (!commonId || (commonId && coherencyHardSoft)) {
- /*
- * Retrieving initial service topology.
- */
- String serviceName = input.getServiceName();
- Services service = readServiceList(serviceName);
- if (service != null) {
- LOG.debug("Service '" + serviceName + "' present in datastore !");
- /*
- * Sending cancel resource resv request to PCE
- */
-
- mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, input, false);
- notification = new ServiceRpcResultBuilder()
- .setNotificationType(ServiceNotificationTypes.ServiceReconfigureResult)
- .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
- .setStatusMessage("Cancelling ResourceResv ...").build();
- try {
- notificationPublishService.putNotification(notification);
- } catch (InterruptedException e) {
- LOG.info("notification offer rejected : " + e);
- }
- sendNotifToUrl(notification, notificationUrl);
- FutureCallback<CancelResourceReserveOutput> pceCallback =
- new FutureCallback<CancelResourceReserveOutput>() {
- String message = "";
- String responseCode = "";
- ServiceRpcResult notification = null;
-
- @Override
- public void onFailure(Throwable arg0) {
- LOG.error("Failed to cancel ResourceResv ! ");
- notification = new ServiceRpcResultBuilder()
- .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
- .setServiceName(serviceName).setStatus(RpcStatusEx.Failed)
- .setStatusMessage("PCR Request failed !").build();
- try {
- notificationPublishService.putNotification(notification);
- } catch (InterruptedException e) {
- LOG.info("notification offer rejected : " + e);
- }
-
- }
-
- @Override
- public void onSuccess(CancelResourceReserveOutput arg0) {
- if (mappingAndSendingPCRequest.getSuccess() && arg0 != null) {
- LOG.info("Service ResourceResv cancelled !");
- notification = new ServiceRpcResultBuilder()
- .setNotificationType(ServiceNotificationTypes.ServiceReconfigureResult)
- .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
- .setStatusMessage(
- "Service '" + serviceName + "' ResourceResv cancelled")
- .build();
- try {
- notificationPublishService.putNotification(notification);
- } catch (InterruptedException e) {
- LOG.info("notification offer rejected : " + e);
- }
- sendNotifToUrl(notification, notificationUrl);
-
- message = "Service '" + serviceName + "' ResourceResv cancelled";
-
- LOG.info("PCE replied to CancelResourceResv Request !");
- /*
- * Before sending the PCE request, input
- * data need to be formatted according
- * to the Service Handler - PCE
- * interface data model.
- */
- mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, input,
- true);
- /*
- * Once PCE request is being sent to the
- * PCE on interface B, PCE reply is
- * expected until a timer expires.
- */
- notification = new ServiceRpcResultBuilder()
- .setNotificationType(ServiceNotificationTypes.ServiceReconfigureResult)
- .setServiceName(serviceName).setStatus(RpcStatusEx.Pending)
- .setStatusMessage(message + ", submitting PathComputation Request ...")
- .build();
- try {
- notificationPublishService.putNotification(notification);
- } catch (InterruptedException e) {
- LOG.info("notification offer rejected : " + e);
- }
- sendNotifToUrl(notification, notificationUrl);
- PathComputationRequestOutput response = null;
- try {
- response = mappingAndSendingPCRequest.pathComputationRequest().get();
- } catch (InterruptedException | ExecutionException e2) {
- LOG.error(e2.getMessage());
- }
-
- if (mappingAndSendingPCRequest.getSuccess() && response != null) {
- /*
- * If PCE reply is received before
- * timer expiration with a positive
- * result, a service is created with
- * admin and operational status
- * 'down'.
- */
- LOG.info("PCE replied to PCR Request !");
- message = response.getConfigurationResponseCommon().getResponseMessage();
- notification = new ServiceRpcResultBuilder()
- .setNotificationType(
- ServiceNotificationTypes.ServiceReconfigureResult)
- .setServiceName(serviceName).setStatus(RpcStatusEx.Pending)
- .setStatusMessage("PCE replied to PCR Request !").build();
- try {
- notificationPublishService.putNotification(notification);
- } catch (InterruptedException e) {
- LOG.info("notification offer rejected : " + e);
- }
- sendNotifToUrl(notification, notificationUrl);
- /*
- * Send Implementation order to
- * renderer
- */
- mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry,
- input, response);
-
- notification = new ServiceRpcResultBuilder()
- .setNotificationType(
- ServiceNotificationTypes.ServiceReconfigureResult)
- .setServiceName(input.getServiceName())
- .setStatus(RpcStatusEx.Pending)
- .setStatusMessage("Submitting ServiceImplementation Request ...")
- .build();
- try {
- notificationPublishService.putNotification(notification);
- } catch (InterruptedException e) {
- LOG.info("notification offer rejected : " + e);
- }
- sendNotifToUrl(notification, notificationUrl);
-
- ServiceImplementationRequestOutput siOutput = null;
- try {
- siOutput = mappingAndSendingSIRequest.serviceImplementation().get();
- } catch (InterruptedException | ExecutionException e2) {
- LOG.error(e2.getMessage());
- }
- ConfigurationResponseCommon siCommon = siOutput
- .getConfigurationResponseCommon();
- message = siCommon.getResponseMessage();
-
- if (mappingAndSendingSIRequest.getSuccess() && siOutput != null) {
- message = "Service reconfigured ";
- LOG.info("Service reconfigured !");
- notification = new ServiceRpcResultBuilder()
- .setNotificationType(
- ServiceNotificationTypes.ServiceReconfigureResult)
- .setServiceName(input.getServiceName())
- .setStatus(RpcStatusEx.Pending)
- .setStatusMessage("Service reconfigure !").build();
- try {
- notificationPublishService.putNotification(notification);
- } catch (InterruptedException e) {
- LOG.info("notification offer rejected : " + e);
- }
- sendNotifToUrl(notification, notificationUrl);
- /*
- * Service implemented Update in
- * DB.
- */
- Boolean update = false;
- Boolean delete = false;
- Services modifService = mappingServices(null, input, response);
- InstanceIdentifier<Services> iid = InstanceIdentifier
- .create(ServiceList.class)
- .child(Services.class, new ServicesKey(serviceName));
- WriteTransaction writeTx = db.newWriteOnlyTransaction();
- writeTx.delete(LogicalDatastoreType.OPERATIONAL, iid);
- try {
- LOG.info("Deleting service info ...");
- writeTx.submit().checkedGet();
- delete = true;
- } catch (TransactionCommitFailedException e) {
- LOG.error("Failed to delete service from Service List");
- }
- if (delete) {
- iid = InstanceIdentifier.create(ServiceList.class).child(
- Services.class, new ServicesKey(input.getNewServiceName()));
- writeTx = db.newWriteOnlyTransaction();
- writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, modifService);
- try {
- LOG.info("Updating service info ...");
- writeTx.submit().checkedGet();
- update = true;
- } catch (TransactionCommitFailedException e) {
- LOG.error("Failed to modify service from Service List");
- }
- }
- if (update) {
- LOG.info("Service '" + serviceName + "' updated with new name '"
- + input.getNewServiceName() + "' ! ");
- StringBuilder build = new StringBuilder();
- build.append(message);
- build.append(" : Service updated on DataBase !");
- message = build.toString();
- } else {
- LOG.info("Service '" + serviceName + "' update failed ! ");
- StringBuilder build = new StringBuilder();
- build.append(message);
- build.append(" : Failed to modify service from Service List ");
- message = build.toString();
- }
- } else {
- LOG.info("Service not implemented !");
- message = response.getConfigurationResponseCommon()
- .getResponseMessage();
- notification = new ServiceRpcResultBuilder()
- .setNotificationType(
- ServiceNotificationTypes.ServiceReconfigureResult)
- .setServiceName(input.getServiceName())
- .setStatus(RpcStatusEx.Failed)
- .setStatusMessage(
- "Service not implemented, cancelling ResourceResv")
- .build();
- try {
- notificationPublishService.putNotification(notification);
- } catch (InterruptedException e) {
- LOG.info("notification offer rejected : " + e);
- }
- sendNotifToUrl(notification, notificationUrl);
- mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry,
- input, false);
- /*
- * Send Cancel resource Request
- * to PCE.
- */
- CancelResourceReserveOutput cancelOuptut = null;
- try {
- cancelOuptut = mappingAndSendingPCRequest.cancelResourceReserve()
- .get();
- } catch (InterruptedException | ExecutionException e1) {
- LOG.error(e1.getMessage());
- }
- if (mappingAndSendingPCRequest.getSuccess() && cancelOuptut != null) {
- LOG.info("Service ResourceResv cancelled !");
- message = response.getConfigurationResponseCommon()
- .getResponseMessage();
- notification = new ServiceRpcResultBuilder()
- .setNotificationType(
- ServiceNotificationTypes.ServiceReconfigureResult)
- .setServiceName(input.getServiceName())
- .setStatus(RpcStatusEx.Failed)
- .setStatusMessage("Service ResourceResv cancelled").build();
- try {
- notificationPublishService.putNotification(notification);
- } catch (InterruptedException e) {
- LOG.info("notification offer rejected : " + e);
- }
- sendNotifToUrl(notification, notificationUrl);
-
- message = cancelOuptut.getConfigurationResponseCommon()
- .getResponseMessage();
-
- StringBuilder build = new StringBuilder();
- build.append("Service not implemented - ");
- build.append(message);
- message = build.toString();
-
- LOG.info("PCE replied to CancelResourceResv Request !");
- } else {
- message = "Cancelling Resource reserved failed ";
- LOG.info(message);
- StringBuilder build = new StringBuilder();
- build.append("Service not implemented - ");
- build.append(message);
- message = build.toString();
-
- message = response.getConfigurationResponseCommon()
- .getResponseMessage();
- notification = new ServiceRpcResultBuilder()
- .setNotificationType(
- ServiceNotificationTypes.ServiceReconfigureResult)
- .setServiceName(input.getServiceName())
- .setStatus(RpcStatusEx.Failed)
- .setStatusMessage("Cancelling Resource reserved failed")
- .build();
- try {
- notificationPublishService.putNotification(notification);
- } catch (InterruptedException e) {
- LOG.info("notification offer rejected : " + e);
- }
- sendNotifToUrl(notification, notificationUrl);
- }
- }
-
- } else {
- LOG.error("PCE pathcomputation request failed !");
- message = "PCE pathcomputation request failed : "
- + mappingAndSendingPCRequest.getError();// "Path
- // not
- // calculated";
- }
- } else {
- message = "Cancelling Resource reserved failed ";
- LOG.info(message);
- StringBuilder build = new StringBuilder();
- build.append("Service not implemented - ");
- build.append(message);
- message = build.toString();
-
- notification = new ServiceRpcResultBuilder()
- .setNotificationType(ServiceNotificationTypes.ServiceReconfigureResult)
- .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
- .setStatusMessage("Cancelling Resource reserved failed").build();
- try {
- notificationPublishService.putNotification(notification);
- } catch (InterruptedException e) {
- LOG.info("notification offer rejected : " + e);
- }
- sendNotifToUrl(notification, notificationUrl);
- }
-
- }
- };
- ListenableFuture<CancelResourceReserveOutput> pce = mappingAndSendingPCRequest
- .cancelResourceReserve();
- Futures.addCallback(pce, pceCallback);
- LOG.info("CancelResRev Request in progress ");
- ServiceReconfigureOutput output = new ServiceReconfigureOutputBuilder()
- .setStatus(RpcStatusEx.Pending).setStatusMessage(message).build();
-
- return RpcResultBuilder.success(output).buildFuture();
-
- } else {
- message = "Service '" + serviceName + "' not exists in datastore";
- LOG.error(message);
- }
- }
- } else {
- message = txrxCheck.getMessage();
- }
- } else {
- message = txrxCheck.getMessage();
- }
- } else {
- message = compliancyCheck.getMessage();