- 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 '" + serviceName + "' deleted from datastore");
- serviceName = newServiceName;
- delete = true;
- } else {
- LOG.info("deleting Service '" + serviceName + "' failed !");
- }
- }
- 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 (sdncRequestHeader != null) {
- sdncRequest = true;
- }
- if (connectionType != null) {
- contype = true;
- }
- compliancyCheck = new ServicehandlerCompliancyCheck(sdncRequestHeader, serviceName,
- connectionType, rpcActions);
- if (compliancyCheck.check(contype, sdncRequest)) {
- 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(aend, 1);
- if (txrxCheck.check()) {
- LOG.info("Tx/Rx Info for AEnd checked !");
- LOG.info("checking Tx/Rx Info for ZEnd ...");
- txrxCheck = new ServicehandlerTxRxCheck(zend, 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 (commonIdValue != null) {
- LOG.info("Common-id specified");
- /**
- * Check coherency with hard/soft constraints.
- */
- checkCoherencyHardSoft = new CheckCoherencyHardSoft(hard,soft);
- 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)) {
- message = null;
- }
- } else {
- message = txrxCheck.getMessage();
- }
+ Optional<Services> servicesObject = this.serviceDataStoreOperations.getService(input.getServiceName());
+ if (servicesObject.isPresent()) {
+ LOG.info("Service '{}' is present", input.getServiceName());
+ OperationResult validationResult = ServiceCreateValidation
+ .validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceReconfigure);
+ if (!validationResult.isSuccess()) {
+ LOG.warn("Aborting service reconfigure because validation of service create request failed: {}",
+ validationResult.getResultMessage());
+ return ModelMappingUtils.createCreateServiceReply(input, validationResult.getResultMessage(),
+ RpcStatus.Failed);
+ }
+ this.pceListenerImpl.setInput(new ServiceInput(input));
+ this.pceListenerImpl.setServiceReconfigure(true);
+ this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
+ this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
+ this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
+ org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
+ .ServiceDeleteInput serviceDeleteInput =
+ ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
+ org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
+ .ServiceDeleteOutput output = this.rendererServiceWrapper.performRenderer(serviceDeleteInput,
+ ServiceNotificationTypes.ServiceDeleteResult);
+ if (output != null) {
+ LOG.info("Service compliant, service reconfigure in progress...");
+ ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
+ return ModelMappingUtils.createCreateServiceReply(input, common.getResponseMessage(),
+ RpcStatus.Successful);