95053ec407b021cf98c2145a690f7dcf23433655
[transportpce.git] / servicehandler / src / main / 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 com.google.common.util.concurrent.ListenableFuture;
11
12 import java.util.concurrent.ExecutionException;
13
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService;
16 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutput;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestInput;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestOutput;
21 import org.opendaylight.yangtools.yang.common.RpcResult;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 public class StubRendererServiceOperations implements RendererServiceOperations {
26     private static final Logger LOG = LoggerFactory.getLogger(StubRendererServiceOperations.class);
27     private StubrendererImpl stubrendererImpl;
28
29     public StubRendererServiceOperations(NetworkModelWavelengthService networkModelWavelengthService,
30             DataBroker dataBroker) {
31         this.stubrendererImpl = new StubrendererImpl(networkModelWavelengthService, dataBroker);
32     }
33
34     @Override
35     public ServiceImplementationRequestOutput serviceImplementation(ServiceImplementationRequestInput input) {
36         ListenableFuture<RpcResult<ServiceImplementationRequestOutput>> rpcResultFuture =
37                 this.stubrendererImpl.serviceImplementation(input);
38         try {
39             return rpcResultFuture.get().getResult();
40         } catch (InterruptedException e) {
41             LOG.error("RPC serviceImplementation failed !",e);
42         } catch (ExecutionException e) {
43             LOG.error("RPC serviceImplementation failed !",e);
44         }
45         return null;
46     }
47
48     @Override
49     public ServiceDeleteOutput serviceDelete(ServiceDeleteInput input) {
50         ListenableFuture<RpcResult<ServiceDeleteOutput>> rpcResultFuture = this.stubrendererImpl.serviceDelete(input);
51         try {
52             return rpcResultFuture.get().getResult();
53         } catch (InterruptedException e) {
54             LOG.error("RPC serviceDelete failed !",e);
55         } catch (ExecutionException e) {
56             LOG.error("RPC serviceDelete failed !",e);
57         }
58         return null;
59     }
60 }