From 2b6f21e4c36be892feefea1071cd2f393ed967e9 Mon Sep 17 00:00:00 2001 From: Martial COULIBALY Date: Mon, 28 Jan 2019 18:27:37 +0100 Subject: [PATCH] Service-restoration implementation First implementation of service-restoration rpc according to openroadm-service documentation. Change-Id: I6a8687b088c2e1fcb2d0d747ce46dd94f0ddc25e Signed-off-by: Martial COULIBALY --- .../servicehandler/DowngradeConstraints.java | 188 ++++++++++++++++++ .../servicehandler/ModelMappingUtils.java | 21 ++ .../impl/ServicehandlerImpl.java | 76 ++++++- .../impl/ServiceHandlerImplTest.java | 51 +++++ .../utils/ServiceDataUtils.java | 10 + 5 files changed, 345 insertions(+), 1 deletion(-) create mode 100644 servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/DowngradeConstraints.java diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/DowngradeConstraints.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/DowngradeConstraints.java new file mode 100644 index 000000000..639b66247 --- /dev/null +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/DowngradeConstraints.java @@ -0,0 +1,188 @@ +/* + * Copyright © 2017 Orange, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.servicehandler; + +import java.util.List; + +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.CoRoutingOrGeneral; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.CoRouting; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.CoRoutingBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.General; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.GeneralBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Diversity; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.DiversityBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Exclude; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.ExcludeBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Include; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.IncludeBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Latency; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraints; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraintsBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraints; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraintsBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Class to Map Hard Constraints to Soft Constraints. + * + * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange + * + */ +public final class DowngradeConstraints { + + private static final Logger LOG = LoggerFactory.getLogger(DowngradeConstraints.class); + + private DowngradeConstraints() { + } + + /** + * Add Hard Constraints to Soft Constraints. + * + * + * @param hardConstraints to be added + * @param softConstraints to be modified + * @return SoftConstraints modified + */ + public static SoftConstraints updateSoftConstraints(HardConstraints hardConstraints, + SoftConstraints softConstraints) { + SoftConstraintsBuilder softConstraintsBuilder = new SoftConstraintsBuilder(softConstraints); + List hardCustomerCode = hardConstraints.getCustomerCode(); + if (!hardCustomerCode.isEmpty()) { + softConstraintsBuilder.getCustomerCode().addAll(hardCustomerCode); + } else { + LOG.warn("hard constraints customer code list is empty !"); + } + CoRoutingOrGeneral coRoutingOrGeneral = hardConstraints.getCoRoutingOrGeneral(); + if (coRoutingOrGeneral != null) { + if (coRoutingOrGeneral instanceof General) { + General hardGeneral = (General) coRoutingOrGeneral; + if (softConstraintsBuilder.getCoRoutingOrGeneral() instanceof General) { + General softGeneral = (General) softConstraintsBuilder.getCoRoutingOrGeneral(); + updateGeneral(hardGeneral, softGeneral); + } else { + softConstraintsBuilder.setCoRoutingOrGeneral(hardGeneral); + } + } else if (coRoutingOrGeneral instanceof CoRouting) { + CoRouting hardCoRouting = (CoRouting) coRoutingOrGeneral; + if (softConstraintsBuilder.getCoRoutingOrGeneral() instanceof CoRouting) { + CoRouting softCoRouting = (CoRouting) softConstraintsBuilder.getCoRoutingOrGeneral(); + updateCoRouting(hardCoRouting, softCoRouting); + } else { + softConstraintsBuilder.setCoRoutingOrGeneral(hardCoRouting); + } + } + } else { + LOG.warn("hard constraints CoRoutingOrGeneral is null !"); + } + return softConstraintsBuilder.build(); + } + + private static General updateGeneral(General hard, General soft) { + GeneralBuilder result = new GeneralBuilder(soft); + try { + result.setDiversity(updateDiveristy(hard.getDiversity(), soft.getDiversity())); + result.setExclude(updateExclude(hard.getExclude(), soft.getExclude())); + result.setInclude(updateInclude(hard.getInclude(), soft.getInclude())); + } catch (NullPointerException e) { + LOG.warn("failed to update some 'General' parameters !", e); + } + return result.build(); + } + + private static Include updateInclude(Include hard, Include soft) { + IncludeBuilder result = new IncludeBuilder(soft); + if (hard != null) { + result.getFiberBundle().addAll(hard.getFiberBundle()); + result.getNodeId().addAll(hard.getNodeId()); + result.getSite().addAll(hard.getSite()); + result.getSupportingServiceName().addAll(hard.getSupportingServiceName()); + } + return result.build(); + } + + private static Exclude updateExclude(Exclude hard, Exclude soft) throws NullPointerException { + ExcludeBuilder result = new ExcludeBuilder(soft); + if (hard != null) { + result.getFiberBundle().addAll(hard.getFiberBundle()); + result.getNodeId().addAll(hard.getNodeId()); + result.getSite().addAll(hard.getSite()); + result.getSupportingServiceName().addAll(hard.getSupportingServiceName()); + } + return result.build(); + } + + private static Diversity updateDiveristy(Diversity hard, Diversity soft) throws NullPointerException { + DiversityBuilder result = new DiversityBuilder(soft); + if (hard != null) { + result.getExistingService().addAll(hard.getExistingService()); + result.setExistingServiceApplicability(hard.getExistingServiceApplicability()); + } + return result.build(); + } + + private static CoRouting updateCoRouting(CoRouting hard, CoRouting soft) { + CoRoutingBuilder result = new CoRoutingBuilder(soft); + try { + result.setCoRouting( + updateCoCoRouting(hard.getCoRouting(), soft.getCoRouting())); + } catch (NullPointerException e) { + LOG.warn("failed to update some 'CoRouting' parameters !", e); + } + return result.build(); + } + + private static org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing + .or.general.co.routing.CoRouting updateCoCoRouting(org.opendaylight.yang.gen.v1.http.org.openroadm.routing + .constrains.rev161014.constraints.co.routing.or.general.co.routing.CoRouting hard, org.opendaylight + .yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.co + .routing.CoRouting soft) throws NullPointerException { + org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general + .co.routing.CoRoutingBuilder result = new org.opendaylight.yang.gen.v1.http.org.openroadm.routing + .constrains.rev161014.constraints.co.routing.or.general.co.routing.CoRoutingBuilder(soft); + if (hard != null) { + result.getExistingService().addAll(hard.getExistingService()); + } + return result.build(); + } + + /** + * Remove all hard constraints except latency. + * + * @param hardConstraints HardConstarints to be downgraded + * @return HardConstraints downgraded + */ + public static HardConstraints downgradeHardConstraints(HardConstraints hardConstraints) { + HardConstraintsBuilder hardConstraintsBuilder = new HardConstraintsBuilder(); + CoRoutingOrGeneral coRoutingOrGeneral = hardConstraints.getCoRoutingOrGeneral(); + Latency latency = null; + if (coRoutingOrGeneral instanceof General) { + General general = (General) coRoutingOrGeneral; + if (general != null) { + latency = general.getLatency(); + if (latency != null) { + hardConstraintsBuilder.setCoRoutingOrGeneral(new GeneralBuilder().setLatency(latency).build()); + } else { + LOG.warn("latency value not found in HardContraints !"); + } + } + } + return hardConstraintsBuilder.build(); + } + + /** + * Convert HardConstraints to SoftConstraints. + * + * @param hardConstraints to be converted. + * @return SoftConstraints converted. + */ + public static SoftConstraints convertToSoftConstraints(HardConstraints hardConstraints) { + SoftConstraintsBuilder softConstraintsBuilder = new SoftConstraintsBuilder(hardConstraints); + return softConstraintsBuilder.build(); + } +} diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtils.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtils.java index c427b216a..97cf989c7 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtils.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtils.java @@ -39,6 +39,9 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.Service import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteInput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteOutput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationOutputBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateOutput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateOutputBuilder; @@ -133,6 +136,16 @@ public final class ModelMappingUtils { return builder.build(); } + public static org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 + .ServiceDeleteInput createServiceDeleteInput(ServiceRestorationInput serviceRestorationInput, + Services services) { + ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(); + builder.setServiceName(serviceRestorationInput.getServiceName()); + builder.setServiceHandlerHeader(new ServiceHandlerHeaderBuilder().setRequestId( + services.getSdncRequestHeader().getRequestId()).build()); + return builder.build(); + } + public static org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput createServiceDeleteInput(ServiceReconfigureInput serviceReconfigureInput) { ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(); @@ -273,6 +286,14 @@ public final class ModelMappingUtils { return RpcResultBuilder.success(output.build()).buildFuture(); } + public static ListenableFuture> createRestoreServiceReply(String message, + RpcStatus status) { + ServiceRestorationOutputBuilder output = new ServiceRestorationOutputBuilder() + .setStatus(status) + .setStatusMessage(message); + return RpcResultBuilder.success(output.build()).buildFuture(); + } + public static Services mappingServices(ServiceCreateInput serviceCreateInput, ServiceReconfigureInput serviceReconfigureInput) { org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceAEnd aend = null; diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java index 47eb143de..debb648ee 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java @@ -21,6 +21,7 @@ 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.DowngradeConstraints; import org.opendaylight.transportpce.servicehandler.ModelMappingUtils; import org.opendaylight.transportpce.servicehandler.ServiceInput; import org.opendaylight.transportpce.servicehandler.listeners.PceListenerImpl; @@ -38,6 +39,9 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev1 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommon; 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.common.types.rev161014.State; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraints; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraints; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.EquipmentNotificationInput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.EquipmentNotificationOutput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.NetworkReOptimizationInput; @@ -274,7 +278,77 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { @Override public ListenableFuture> serviceRestoration(ServiceRestorationInput input) { - throw new UnsupportedOperationException("Not implemented yet"); + LOG.info("RPC service restoration received"); + String message = ""; + String serviceName = input.getServiceName(); + Optional servicesObject = this.serviceDataStoreOperations.getService(serviceName); + if (servicesObject.isPresent()) { + Services service = servicesObject.get(); + State state = service.getOperationalState(); + if (state != State.InService) { + ServiceDeleteInputBuilder deleteInputBldr = new ServiceDeleteInputBuilder(); + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx"); + OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC); + DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime)); + deleteInputBldr.setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder() + .setServiceName(serviceName).setDueDate(datetime) + .setTailRetention(TailRetention.No).build()); + SdncRequestHeaderBuilder sdncBuilder = new SdncRequestHeaderBuilder(); + sdncBuilder.setNotificationUrl(service.getSdncRequestHeader().getNotificationUrl()); + sdncBuilder.setRequestId(service.getSdncRequestHeader().getRequestId()); + sdncBuilder.setRequestSystemId(service.getSdncRequestHeader().getRequestSystemId()); + sdncBuilder.setRpcAction(RpcActions.ServiceDelete); + deleteInputBldr.setSdncRequestHeader(sdncBuilder.build()); + ServiceInput serviceInput = new ServiceInput(deleteInputBldr.build()); + serviceInput.setServiceAEnd(service.getServiceAEnd()); + serviceInput.setServiceZEnd(service.getServiceZEnd()); + serviceInput.setConnectionType(service.getConnectionType()); + HardConstraints hardConstraints = service.getHardConstraints(); + if (hardConstraints != null) { + SoftConstraints softConstraints = service.getSoftConstraints(); + if (softConstraints != null) { + LOG.info("converting hard constraints to soft constraints ..."); + serviceInput.setSoftConstraints( + DowngradeConstraints.updateSoftConstraints(hardConstraints, softConstraints)); + serviceInput.setHardConstraints(DowngradeConstraints.downgradeHardConstraints(hardConstraints)); + } else { + LOG.warn("service '{}' SoftConstraints is not set !", serviceName); + serviceInput.setSoftConstraints(DowngradeConstraints.convertToSoftConstraints(hardConstraints)); + serviceInput.setHardConstraints(DowngradeConstraints.downgradeHardConstraints(hardConstraints)); + } + } else { + LOG.warn("service '{}' HardConstraints is not set !", serviceName); + } + this.pceListenerImpl.setInput(serviceInput); + this.pceListenerImpl.setServiceReconfigure(true); + this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations); + this.rendererListenerImpl.setServiceInput(serviceInput); + this.rendererListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 + .ServiceDeleteInput serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput( + new ServiceInput(deleteInputBldr.build())); + 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 present in datastore, service-restore in progress..."); + ConfigurationResponseCommon common = output.getConfigurationResponseCommon(); + return ModelMappingUtils.createRestoreServiceReply(common.getResponseMessage(), + RpcStatus.Successful); + } else { + return ModelMappingUtils.createRestoreServiceReply("Renderer service delete failed !", + RpcStatus.Failed); + } + } else { + LOG.error("Service '{}' is in 'inService' state", input.getServiceName()); + message = "Service '" + input.getServiceName() + "' is in 'inService' state"; + return ModelMappingUtils.createRestoreServiceReply(message, RpcStatus.Failed); + } + } else { + LOG.error("Service '{}' is not present", input.getServiceName()); + message = "Service '" + input.getServiceName() + "' is not present"; + return ModelMappingUtils.createRestoreServiceReply(message, RpcStatus.Failed); + } } @Override diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServiceHandlerImplTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServiceHandlerImplTest.java index cea175dfe..6c06e45c2 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServiceHandlerImplTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServiceHandlerImplTest.java @@ -68,6 +68,7 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev1 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.Port; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.PortBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.State; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInputBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateOutput; @@ -78,6 +79,8 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.Service import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureOutput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteInput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationOutput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInputBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteInput; @@ -899,4 +902,52 @@ public class ServiceHandlerImplTest extends AbstractTest { result.getStatus()); Assert.assertEquals("Renderer service delete in progress", result.getStatusMessage()); } + + @Test + public void restorationServiceIfServiceNotPresent() throws ExecutionException, InterruptedException { + ServiceRestorationInput input = ServiceDataUtils.buildServiceRestorationInput(); + ServiceRestorationOutput result = this.serviceHandler.serviceRestoration(input).get().getResult(); + Assert.assertEquals(result.getStatus(), RpcStatus.Failed); + Assert.assertEquals(result.getStatusMessage(), "Service 'service 1' is not present"); + } + + @Test + public void restorationServiceIfServiceNotDown() throws ExecutionException, InterruptedException { + ServiceRestorationInput input = ServiceDataUtils.buildServiceRestorationInput(); + Services serviceMock = ModelMappingUtils.mappingServices(ServiceDataUtils.buildServiceCreateInput(), null); + ServicesBuilder builder = new ServicesBuilder(serviceMock).setAdministrativeState(State.InService) + .setOperationalState(State.InService); + Optional service = Optional.of(builder.build()); + Mockito.when(this.serviceDataStoreOperationsMock.getService(any(String.class))).thenReturn(service); + ServiceRestorationOutput result = this.serviceHandlerImplMock.serviceRestoration(input).get().getResult(); + Assert.assertEquals(RpcStatus.Failed, result.getStatus()); + Assert.assertEquals("Service 'service 1' is in 'inService' state", result.getStatusMessage()); + } + + @Test + public void restorationServiceIfServicePresentAndDown() throws ExecutionException, InterruptedException { + ServiceRestorationInput serviceRestorationInput = ServiceDataUtils.buildServiceRestorationInput(); + Services serviceMock = ModelMappingUtils.mappingServices(ServiceDataUtils.buildServiceCreateInput(), null); + ServicesBuilder builder = new ServicesBuilder(serviceMock).setAdministrativeState(State.OutOfService) + .setOperationalState(State.OutOfService); + Optional service = Optional.of(builder.build()); + Mockito.when(this.serviceDataStoreOperationsMock.getService(any(String.class))).thenReturn(service); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput input = + ModelMappingUtils.createServiceDeleteInput(serviceRestorationInput, serviceMock); + ConfigurationResponseCommon configurationResponseCommon = + new ConfigurationResponseCommonBuilder().setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES) + .setRequestId("1").setResponseCode(ResponseCodes.RESPONSE_OK) + .setResponseMessage("Renderer service delete in progress").build(); + org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutput output = + new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017 + .ServiceDeleteOutputBuilder().setConfigurationResponseCommon(configurationResponseCommon).build(); + Mockito.when( + this.rendererServiceWrapperMock.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult)) + .thenReturn(output); + ServiceRestorationOutput result = + this.serviceHandlerImplMock.serviceRestoration(serviceRestorationInput).get().getResult(); + Assert.assertEquals(org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus.Successful, + result.getStatus()); + Assert.assertEquals("Renderer service delete in progress", result.getStatusMessage()); + } } diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/ServiceDataUtils.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/ServiceDataUtils.java index 6298e55f5..5c1dd3c6a 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/ServiceDataUtils.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/ServiceDataUtils.java @@ -49,6 +49,9 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.Service import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureInputBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteInput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationInput.Option; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationInputBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInputBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteInput; @@ -235,6 +238,13 @@ public final class ServiceDataUtils { return builder.build(); } + public static ServiceRestorationInput buildServiceRestorationInput() { + ServiceRestorationInputBuilder builder = new ServiceRestorationInputBuilder(); + builder.setServiceName("service 1"); + builder.setOption(Option.Permanent); + return builder.build(); + } + public static ServiceReconfigureInput buildServiceReconfigureInput() { ServiceReconfigureInputBuilder builtInput = new ServiceReconfigureInputBuilder(); org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.reconfigure.input -- 2.36.6