6db468c39326da4d32ef4a144f57dedbeb174b45
[transportpce.git] / servicehandler / src / test / java / org / opendaylight / transportpce / servicehandler / stub / StubRendererServiceOperations.java
1 /*
2  * Copyright © 2018 Orange, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.transportpce.servicehandler.stub;
9
10 import java.util.concurrent.ExecutionException;
11 import java.util.concurrent.Future;
12
13 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
14 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
15 import org.opendaylight.transportpce.servicehandler.mappers.ServiceDeleteInputConverter;
16 import org.opendaylight.transportpce.servicehandler.mappers.ServiceDeleteOutputConverter;
17 import org.opendaylight.transportpce.servicehandler.mappers.ServiceImplementationRequestInputConverter;
18 import org.opendaylight.transportpce.servicehandler.mappers.ServiceImplementationRequestOutputConverter;
19 import org.opendaylight.transportpce.stubrenderer.impl.StubrendererImpl;
20 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceDeleteInput;
21 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceDeleteOutput;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestInput;
23 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestOutput;
24 import org.opendaylight.yangtools.yang.common.RpcResult;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 public class StubRendererServiceOperations implements RendererServiceOperations {
29     private static final Logger LOG = LoggerFactory.getLogger(StubRendererServiceOperations.class);
30     private StubrendererImpl stubrenderer;
31
32     public StubRendererServiceOperations(NotificationPublishService notificationPublishService) {
33         this.stubrenderer = new StubrendererImpl(notificationPublishService);
34     }
35
36     @Override
37     public ServiceImplementationRequestOutput serviceImplementation(ServiceImplementationRequestInput input) {
38         Future<RpcResult<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426
39             .ServiceImplementationRequestOutput>> rpcResultFuture = this.stubrenderer
40                 .serviceImplementationRequest(ServiceImplementationRequestInputConverter.getStub(input));
41         try {
42             return ServiceImplementationRequestOutputConverter.getConcrete(rpcResultFuture.get().getResult());
43         } catch (InterruptedException e) {
44             LOG.error("RPC serviceImplementation failed !",e);
45         } catch (ExecutionException e) {
46             LOG.error("RPC serviceImplementation failed !",e);
47         }
48         return null;
49     }
50
51     @Override
52     public ServiceDeleteOutput serviceDelete(ServiceDeleteInput input) {
53         Future<RpcResult<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426
54             .ServiceDeleteOutput>> rpcResultFuture = this.stubrenderer
55                 .serviceDelete(ServiceDeleteInputConverter.getStub(input));
56         try {
57             return ServiceDeleteOutputConverter.getConcrete(rpcResultFuture.get().getResult());
58         } catch (InterruptedException e) {
59             LOG.error("RPC serviceDelete failed !",e);
60         } catch (ExecutionException e) {
61             LOG.error("RPC serviceDelete failed !",e);
62         }
63         return null;
64     }
65 }