package org.opendaylight.transportpce.servicehandler.impl;
import com.google.common.util.concurrent.ListenableFuture;
+
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
+
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.transportpce.common.OperationResult;
import org.opendaylight.transportpce.common.ResponseCodes;
import org.opendaylight.transportpce.pce.service.PathComputationService;
+import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService;
import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
import org.opendaylight.transportpce.servicehandler.ModelMappingUtils;
+import org.opendaylight.transportpce.servicehandler.ServiceInput;
import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper;
import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl;
import org.opendaylight.transportpce.servicehandler.validation.ServiceCreateValidation;
import org.opendaylight.transportpce.servicehandler.validation.checks.ComplianceCheckResult;
import org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerCompliancyCheck;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.PathComputationRequestOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestOutput;
import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.RpcActions;
import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeaderBuilder;
import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus;
import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteOutput;
import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceFeasibilityCheckInput;
import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceFeasibilityCheckOutput;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceList;
import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureInput;
import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureOutput;
import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteConfirmInput;
import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.delete.input.ServiceDeleteReqInfo.TailRetention;
import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.delete.input.ServiceDeleteReqInfoBuilder;
import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.ServicesKey;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestInput;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.slf4j.Logger;
//TODO: remove private request fields as they are in global scope
public ServicehandlerImpl(DataBroker databroker, PathComputationService pathComputationService,
- RendererServiceOperations rendererServiceOperations) {
+ RendererServiceOperations rendererServiceOperations,
+ NetworkModelWavelengthService networkModelWavelengthService) {
this.db = databroker;
this.rendererServiceOperations = rendererServiceOperations;
this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(this.db);
public ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreate(ServiceCreateInput input) {
LOG.info("RPC service creation received");
// Validation
- OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest(input);
+ OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest(
+ new ServiceInput(input), RpcActions.ServiceCreate);
if (! validationResult.isSuccess()) {
LOG.warn("Aborting service create because validation of service create request failed: {}",
validationResult.getResultMessage());
ResponseCodes.RESPONSE_FAILED);
}
- OperationResult operationServicePathSaveResult = this.serviceDataStoreOperations.createServicePath(input,
- pceResponse);
+ OperationResult operationServicePathSaveResult = this.serviceDataStoreOperations.createServicePath(
+ new ServiceInput(input), pceResponse);
if (!operationServicePathSaveResult.isSuccess()) {
String message = "Service Path not updated in datastore !";
LOG.info(message);
}
ServiceImplementationRequestInput serviceImplementationRequest =
- ModelMappingUtils.createServiceImplementationRequest(input, pceResponse);
- org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426
- .ServiceImplementationRequestOutput serviceImplementationRequestOutput = this.rendererServiceOperations
+ ModelMappingUtils.createServiceImplementationRequest(new ServiceInput(input), pceResponse);
+ ServiceImplementationRequestOutput serviceImplementationRequestOutput = this.rendererServiceOperations
.serviceImplementation(serviceImplementationRequest);
if (ResponseCodes.RESPONSE_OK
.equals(serviceImplementationRequestOutput.getConfigurationResponseCommon().getResponseCode())) {
//Check presence of service to be deleted
String serviceName = input.getServiceDeleteReqInfo().getServiceName();
- Optional<Services> service = this.serviceDataStoreOperations.getService(serviceName);
- if (!service.isPresent()) {
- message = "Service '" + serviceName + "' does not exist in datastore";
- LOG.error(message);
- return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
- message, ResponseCodes.RESPONSE_FAILED);
+ LOG.info("serviceName : {}", serviceName);
+ try {
+ Optional<Services> service = this.serviceDataStoreOperations.getService(serviceName);
+ if (!service.isPresent()) {
+ message = "Service '" + serviceName + "' does not exist in datastore";
+ LOG.error(message);
+ return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
+ message, ResponseCodes.RESPONSE_FAILED);
+ }
+ } catch (NullPointerException e) {
+ LOG.info("failed to get service '{}' from datastore : ", serviceName, e);
}
LOG.debug("Service '{}' present in datastore !", serviceName);
- org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceDeleteInput
- serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(input);
- org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426
- .ServiceDeleteOutput output = this.rendererServiceOperations.serviceDelete(serviceDeleteInput);
+ 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.rendererServiceOperations.serviceDelete(serviceDeleteInput);
if (!ResponseCodes.RESPONSE_OK
.equals(output.getConfigurationResponseCommon().getResponseCode())) {
@Override
public ListenableFuture<RpcResult<ServiceRerouteOutput>> serviceReroute(ServiceRerouteInput input) {
- InstanceIdentifier<Services> servicesIID = InstanceIdentifier.create(ServiceList.class)
- .child(Services.class, new ServicesKey(input.getServiceName()));
- ReadOnlyTransaction rtx = this.db.newReadOnlyTransaction();
- Optional<Services> servicesObject;
+ LOG.info("RPC service reroute received");
+ String message = "";
try {
- servicesObject = rtx.read(LogicalDatastoreType.OPERATIONAL, servicesIID).get().toJavaUtil();
+ Optional<Services> servicesObject = this.serviceDataStoreOperations.getService(input.getServiceName());
if (servicesObject.isPresent()) {
ServiceDeleteInputBuilder deleteInputBldr = new ServiceDeleteInputBuilder();
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx");
sdncBuilder.setRpcAction(RpcActions.ServiceDelete);
deleteInputBldr.setSdncRequestHeader(sdncBuilder.build());
// Calling delete service
- serviceDelete(deleteInputBldr.build());
+ ServiceDeleteOutput serviceDeleteOutput = serviceDelete(deleteInputBldr.build()).get().getResult();
// Calling create request now
+ if (!ResponseCodes.RESPONSE_OK
+ .equals(serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode())) {
+ message = "Service delete failed!";
+ return ModelMappingUtils.createRerouteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
+ message, RpcStatus.Failed);
+ }
ServiceCreateInputBuilder serviceCreateBldr = new ServiceCreateInputBuilder();
serviceCreateBldr.setServiceName(input.getServiceName() + 2);
serviceCreateBldr.setCommonId(servicesObject.get().getCommonId());
ServiceZEndBuilder serviceZendBuilder = new ServiceZEndBuilder(servicesObject.get().getServiceZEnd());
serviceCreateBldr.setServiceZEnd(serviceZendBuilder.build());
serviceCreateBldr.setSoftConstraints(servicesObject.get().getSoftConstraints());
- serviceCreate(serviceCreateBldr.build());
- ServiceRerouteOutputBuilder output = new ServiceRerouteOutputBuilder()
- .setHardConstraints(null).setSoftConstraints(null).setStatus(
- org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus.Successful)
- .setStatusMessage("Success");
- return RpcResultBuilder.success(output).buildFuture();
+ ServiceCreateOutput serviceCreateOutput = serviceCreate(serviceCreateBldr.build()).get().getResult();
+ if (!ResponseCodes.RESPONSE_OK
+ .equals(serviceCreateOutput.getConfigurationResponseCommon().getResponseCode())) {
+ message = "Service create failed!";
+ return ModelMappingUtils.createRerouteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
+ message, RpcStatus.Failed);
+ }
+ message = "Service reroute successfully !";
+ return ModelMappingUtils.createRerouteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
+ message, RpcStatus.Successful);
+ } else {
+ LOG.error("Service '{}' is not present", input.getServiceName());
+ message = "Service '" + input.getServiceName() + "' is not present";
}
} catch (InterruptedException | ExecutionException e) {
LOG.info("Exception caught" , e);
}
ServiceRerouteOutputBuilder output = new ServiceRerouteOutputBuilder()
- .setHardConstraints(null).setSoftConstraints(null).setStatus(RpcStatus.Failed).setStatusMessage("Failure");
-
+ .setHardConstraints(null).setSoftConstraints(null).setStatus(RpcStatus.Failed).setStatusMessage(message);
return RpcResultBuilder.success(output).buildFuture();
}
@Override
public ListenableFuture<RpcResult<TempServiceDeleteOutput>> tempServiceDelete(TempServiceDeleteInput input) {
- // TODO Auto-generated method stub
- return null;
+ LOG.info("RPC temp serviceDelete request received for {}", input.getCommonId());
+ String message = "";
+
+ /*
+ * Upon receipt of service-deleteService RPC, service header and sdnc-request
+ * header compliancy are verified.
+ */
+ LOG.info("checking Service Compliancy ...");
+ ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerCompliancyCheck.check(input.getCommonId(),
+ null, null, RpcActions.ServiceDelete, false, false);
+ if (serviceHandlerCheckResult.hasPassed()) {
+ LOG.info("Service compliant !");
+ } else {
+ LOG.info("Service is not compliant !");
+ return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
+ "Service not compliant !", ResponseCodes.RESPONSE_FAILED);
+ }
+
+ //Check presence of service to be deleted
+ String commonId = input.getCommonId();
+ LOG.info("service common-id : {}", commonId);
+ try {
+ Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.temp.service.list
+ .Services> service = this.serviceDataStoreOperations.getTempService(commonId);
+ if (!service.isPresent()) {
+ message = "Service '" + commonId + "' does not exist in datastore";
+ LOG.error(message);
+ return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
+ message, ResponseCodes.RESPONSE_FAILED);
+ }
+ } catch (NullPointerException e) {
+ LOG.info("failed to get service '{}' from datastore : ", commonId, e);
+ }
+
+ LOG.debug("Service '{}' present in datastore !", commonId);
+ 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.rendererServiceOperations.serviceDelete(serviceDeleteInput);
+
+ if (!ResponseCodes.RESPONSE_OK
+ .equals(output.getConfigurationResponseCommon().getResponseCode())) {
+ message = "Service delete failed!";
+ return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES, message,
+ ResponseCodes.RESPONSE_FAILED);
+ }
+
+ OperationResult deleteServicePathOperationResult =
+ this.serviceDataStoreOperations.deleteServicePath(input.getCommonId());
+ if (!deleteServicePathOperationResult.isSuccess()) {
+ LOG.warn("Service path was not removed from datastore!");
+ }
+
+ OperationResult deleteServiceOperationResult =
+ this.serviceDataStoreOperations.deleteTempService(input.getCommonId());
+ if (!deleteServiceOperationResult.isSuccess()) {
+ LOG.warn("Service was not removed from datastore!");
+ }
+
+ return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
+ "Service delete was successful!", ResponseCodes.RESPONSE_OK);
}
@Override
public ListenableFuture<RpcResult<TempServiceCreateOutput>> tempServiceCreate(TempServiceCreateInput input) {
- // TODO Auto-generated method stub
- return null;
+ LOG.info("RPC temp service creation received");
+ // Validation
+ OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest(
+ new ServiceInput(input), RpcActions.TempServiceCreate);
+ if (! validationResult.isSuccess()) {
+ LOG.warn("Aborting service create because validation of service create request failed: {}",
+ validationResult.getResultMessage());
+ return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES,
+ validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED);
+ }
+
+ // Starting service create operation
+ LOG.info("Commencing PCE");
+ //TODO: createService service status into datastore
+ PathComputationRequestOutput pceResponse = this.pceServiceWrapper.performPCE(input, true);
+ String pceResponseCode = pceResponse.getConfigurationResponseCommon().getResponseCode();
+ if (!ResponseCodes.RESPONSE_OK.equals(pceResponseCode)) {
+ LOG.info("PCE calculation failed {}", pceResponseCode);
+ return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES,
+ pceResponse.getConfigurationResponseCommon().getResponseMessage(), ResponseCodes.RESPONSE_FAILED);
+ }
+
+ LOG.info("PCE calculation done OK {}", pceResponseCode);
+
+ OperationResult operationResult = this.serviceDataStoreOperations.createTempService(input, pceResponse);
+ if (!operationResult.isSuccess()) {
+ String message = "Service status not updated in datastore !";
+ LOG.info(message);
+ return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, message,
+ ResponseCodes.RESPONSE_FAILED);
+ }
+
+ OperationResult operationServicePathSaveResult = this.serviceDataStoreOperations.createServicePath(
+ new ServiceInput(input), pceResponse);
+ if (!operationServicePathSaveResult.isSuccess()) {
+ String message = "Service Path not updated in datastore !";
+ LOG.info(message);
+ return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, message,
+ ResponseCodes.RESPONSE_FAILED);
+ }
+
+ ServiceImplementationRequestInput serviceImplementationRequest =
+ ModelMappingUtils.createServiceImplementationRequest(new ServiceInput(input), pceResponse);
+ ServiceImplementationRequestOutput serviceImplementationRequestOutput = this.rendererServiceOperations
+ .serviceImplementation(serviceImplementationRequest);
+ if (ResponseCodes.RESPONSE_OK
+ .equals(serviceImplementationRequestOutput.getConfigurationResponseCommon().getResponseCode())) {
+ String message = "Service rendered successfully !";
+ LOG.info(message);
+ operationResult = this.serviceDataStoreOperations.modifyTempService(input.getCommonId(), State.InService,
+ State.InService);
+ if (!operationResult.isSuccess()) {
+ LOG.warn("Service status not updated in datastore !");
+ }
+ return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, message,
+ ResponseCodes.RESPONSE_OK);
+ } else {
+ String message = "Service rendering has failed !";
+ LOG.warn(message);
+
+ OperationResult deleteServicePathOperationResult =
+ this.serviceDataStoreOperations.deleteServicePath(input.getCommonId());
+ if (!deleteServicePathOperationResult.isSuccess()) {
+ LOG.warn("Service path was not removed from datastore!");
+ }
+
+ OperationResult deleteServiceOperationResult =
+ this.serviceDataStoreOperations.deleteService(input.getCommonId());
+ if (!deleteServiceOperationResult.isSuccess()) {
+ LOG.warn("Service was not removed from datastore!");
+ }
+
+ return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, message,
+ ResponseCodes.RESPONSE_FAILED);
+ }
}
}