- @Override
- public void onServiceRpcResultSp(ServiceRpcResultSp notification) {
- if (notification != null && !compareServiceRpcResultSp(notification)) {
- serviceRpcResultSp = notification;
- StringBuilder build = new StringBuilder();
- build.append(
- "Received '" + notification.getNotificationType() + "' StubRenderer notification" + "from service '"
- + notification.getServiceName() + "' " + "with status '" + notification.getStatus() + "'");
- build.append(" with StatusMessage '" + notification.getStatusMessage() + "'");
- LOG.info(build.toString());
- switch (serviceRpcResultSp.getNotificationType().getIntValue()) {
- case 3 : /** service-implementation-request. */
- if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
- if (serviceRpcResultSp.getPathTopology() != null) {
- pathTopology = new PathTopologyBuilder()
- .setAToZ(serviceRpcResultSp.getPathTopology().getAToZ())
- .setZToA(serviceRpcResultSp.getPathTopology().getZToA())
- .build();
- LOG.info("PathTopology gets !");
- } else {
- LOG.info("'serviceRpcResultSp.getPathTopology()' parameter is null ");
- }
- if (serviceCreateInput != null) {
- updateServiceStatus(serviceCreateInput);
- } else if (serviceReconfigureInput != null) {
- updateServiceStatus(serviceReconfigureInput);
- } else if (service != null) {
- updateServiceStatus(service);
- }
- } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
- LOG.info("Stubrenderer computation failed !");
- pceCancelResResource();
- }
- break;
-
- case 4 : /** service-delete. */
- if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
- if (service != null) { //serviceRestoration
- LOG.info("RPC service delete came from serviceRestoration");
- pcePathComputation(service);
- } else {
- pceCancelResResource();
- }
- } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
- LOG.info("Stubrenderer computation failed !");
- }
- break;
-
- default:
- break;
- }
- } else {
- LOG.info("ServiceRpcResultSp already wired !");
- }
- }
-
- @Override
- public void onServicePathRpcResult(ServicePathRpcResult notification) {
- if (notification != null && !compareServicePathRpcResult(notification)) {
- servicePathRpcResult = notification;
- StringBuilder build = new StringBuilder();
- build.append(
- "Received '" + notification.getNotificationType() + "' Stubpce notification" + "from service '"
- + notification.getServiceName() + "' " + "with status '" + notification.getStatus() + "'");
- build.append(" with StatusMessage '" + notification.getStatusMessage() + "'");
- LOG.info(build.toString());
- switch (servicePathRpcResult.getNotificationType().getIntValue()) {
- case 1 : /** path-computation-request. */
- if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
- if (servicePathRpcResult.getPathDescription() != null) {
- pathDescription = new PathDescriptionBuilder()
- .setAToZDirection(servicePathRpcResult.getPathDescription().getAToZDirection())
- .setZToADirection(servicePathRpcResult.getPathDescription().getZToADirection())
- .build();
- LOG.info("PathDescription gets !");
- if (serviceReconfigureInput != null) {
- stubrendererImplementation(serviceReconfigureInput);
- } else if (serviceCreateInput != null) {
- stubrendererImplementation(serviceCreateInput);
- } else if (service != null) {
- stubrendererImplementation(service);
- }
- } else {
- LOG.info("'servicePathRpcResult.getPathDescription()'parameter is null ");
- }
- } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
- LOG.info("Stupce computation failed !");
- }
- break;
-
- case 2 : /** cancel-resource-reserve. */
- if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
- /**if it was an RPC serviceReconfigure, relaunch
- * PCR else delete the service.
- */
- if (serviceReconfigureInput != null) {
- LOG.info("cancel reserve resource request came from RPC serviceReconfigure !");
- pcePathComputation(serviceReconfigureInput);
- } else {
- deleteServiceFromDatastore();
- }
- } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
- LOG.info("Stupce computation failed !");
- }
- break;
-
- default:
- break;
- }
- } else {
- LOG.info("ServicePathRpcResult already wired !");
- }
- }
-
- public RpcActions getAction() {
- return action;
- }
-
- public void setAction(RpcActions action) {
- this.action = action;
- }
-
- /**
- * Compare ServicePathRpcResult.
- *
- * @param notification ServicePathRpcResult
- * @return <code>Boolean</code> true if idem, false else
- */
- public Boolean compareServicePathRpcResult(ServicePathRpcResult notification) {
- Boolean result = true;
- if (servicePathRpcResult == null) {
- result = false;
- } else {
- if (servicePathRpcResult.getNotificationType() != notification.getNotificationType()) {
- result = false;
- }
- if (servicePathRpcResult.getServiceName() != notification.getServiceName()) {
- result = false;
- }
- if (servicePathRpcResult.getStatus() != notification.getStatus()) {
- result = false;
- }
- if (servicePathRpcResult.getStatusMessage() != notification.getStatusMessage()) {
- result = false;
- }
- }
- return result;
- }
-
- /**
- * Compare ServiceRpcResultSp.
- *
- * @param notification ServiceRpcResultSp
- * @return <code>Boolean</code> true if idem, false else
- */
- public Boolean compareServiceRpcResultSp(ServiceRpcResultSp notification) {
- Boolean result = true;
- if (serviceRpcResultSp == null) {
- result = false;
- } else {
- if (serviceRpcResultSp.getNotificationType() != notification.getNotificationType()) {
- result = false;
- }
- if (serviceRpcResultSp.getServiceName() != notification.getServiceName()) {
- result = false;
- }
- if (serviceRpcResultSp.getStatus() != notification.getStatus()) {
- result = false;
- }
- if (serviceRpcResultSp.getStatusMessage() != notification.getStatusMessage()) {
- result = false;
- }
- }
- return result;
- }
-
- public PathDescription getPathDescription() {
- return pathDescription;
- }
-
- public void setPathDescription(PathDescription pathDescription) {
- this.pathDescription = pathDescription;
- }
-
- public ServiceDeleteInput getServiceDeleteInput() {
- return serviceDeleteInput;
- }
-
- public void setServiceDeleteInput(ServiceDeleteInput serviceDeleteInput) {
- this.serviceDeleteInput = serviceDeleteInput;
- }
-
- public ServiceReconfigureInput getServiceReconfigureInput() {
- return serviceReconfigureInput;
- }
-
- public void setServiceReconfigureInput(ServiceReconfigureInput serviceReconfigureInput) {
- this.serviceReconfigureInput = serviceReconfigureInput;
- }
-
- public ServiceFeasibilityCheckInput getServiceFeasibilityCheckInput() {
- return serviceFeasibilityCheckInput;
- }
-
- public void setServiceFeasibilityCheckInput(ServiceFeasibilityCheckInput serviceFeasibilityCheckInput) {
- this.serviceFeasibilityCheckInput = serviceFeasibilityCheckInput;
- }
-
- @Override
- public Future<RpcResult<ServiceStateModifyOutput>> serviceStateModify(ServiceStateModifyInput input) {
- LOG.info("RPC service state modify received");
- String servicename = input.getServiceName();
- String message = "";
- String responseCode = "500";
- if (servicename != null) {
- Services service = readServiceList(servicename);
- if (service != null) {
- LOG.info("Modify '{}' Service state", servicename);
- WriteTransaction writeTx = db.newWriteOnlyTransaction();
- String result = null;
- Future<Void> future = null;
- InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class).child(Services.class,
- new ServicesKey(servicename));
- ServicesBuilder modifyService = new ServicesBuilder(service);
- modifyService.setOperationalState(State.OutOfService);
- writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, modifyService.build());
- future = writeTx.submit();
- try {
- Futures.getChecked(future, ExecutionException.class);
- } catch (ExecutionException e) {
- LOG.info("Failed to {} service from Service List", action);
- result = "Failed to " + action + " service from Service List";
- }
- if (result == null) {
- responseCode = "200";
- message = "Service state modified !";
- }
- } else {
- message = "Service not present in datastore ! ";
- }
- } else {
- message = "servicename not set in ServiceStateModifyInput";
- }
- ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
- .setAckFinalIndicator("Yes")
- .setResponseCode(responseCode)
- .setResponseMessage(message)
- .build();
- ServiceStateModifyOutput output = new ServiceStateModifyOutputBuilder()
- .setConfigurationResponseCommon(configurationResponseCommon)
- .build();
- return RpcResultBuilder.success(output).buildFuture();
- }