dce7d7178e6a1c248456a4dcf8aa7c56962efd20
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / rpcs / TransportPCEServicePathRPCImpl.java
1 /*
2  * Copyright © 2017 AT&T 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.renderer.rpcs;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11
12 import java.util.concurrent.ExecutionException;
13
14 import org.opendaylight.transportpce.renderer.ModelMappingUtils;
15 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutput;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestInput;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestOutput;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.TransportpceRendererService;
21 import org.opendaylight.yangtools.yang.common.RpcResult;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 public class TransportPCEServicePathRPCImpl implements TransportpceRendererService {
26
27     private static final Logger LOG = LoggerFactory.getLogger(TransportPCEServicePathRPCImpl.class);
28
29     private final RendererServiceOperations rendererServiceOperations;
30
31     public TransportPCEServicePathRPCImpl(RendererServiceOperations rendererServiceOperations) {
32         this.rendererServiceOperations = rendererServiceOperations;
33     }
34
35     @Override
36     public ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDelete(ServiceDeleteInput input) {
37         String serviceName = input.getServiceName();
38         LOG.info("Calling RPC service delete request {} {}", serviceName);
39         ServiceDeleteOutput output = null;
40         try {
41             output = this.rendererServiceOperations.serviceDelete(input).get();
42         } catch (InterruptedException | ExecutionException e) {
43             LOG.error("RPC service delete failed !");
44         }
45         return ModelMappingUtils.createServiceDeleteRpcResponse(output);
46     }
47
48     @Override
49     public ListenableFuture<RpcResult<ServiceImplementationRequestOutput>> serviceImplementationRequest(
50             ServiceImplementationRequestInput input) {
51         String serviceName = input.getServiceName();
52         LOG.info("Calling RPC service impl request {} {}", serviceName);
53         ServiceImplementationRequestOutput output = null;
54         try {
55             output = this.rendererServiceOperations.serviceImplementation(input).get();
56         } catch (InterruptedException | ExecutionException e) {
57             LOG.error("RPC service implementation failed !");
58         }
59         return ModelMappingUtils.createServiceImplementationRpcResponse(output);
60     }
61
62 }
63