Bump upstream dependencies to Ca
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / rpcs / ServiceImplementationRequestImpl.java
1 /*
2  * Copyright © 2024 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.renderer.rpcs;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.util.concurrent.ListenableFuture;
13 import java.util.concurrent.ExecutionException;
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.rev210915.ServiceImplementationRequest;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestInput;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestOutput;
19 import org.opendaylight.yangtools.yang.common.RpcResult;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23
24 public class ServiceImplementationRequestImpl implements ServiceImplementationRequest {
25     private static final Logger LOG = LoggerFactory.getLogger(ServiceImplementationRequestImpl.class);
26     private final RendererServiceOperations rendererServiceOperations;
27
28     public ServiceImplementationRequestImpl(final RendererServiceOperations rendererServiceOperations) {
29         this.rendererServiceOperations = requireNonNull(rendererServiceOperations);
30     }
31
32     @Override
33     public ListenableFuture<RpcResult<ServiceImplementationRequestOutput>> invoke(
34             ServiceImplementationRequestInput input) {
35         String serviceName = input.getServiceName();
36         LOG.info("Calling RPC service impl request {}", serviceName);
37         ServiceImplementationRequestOutput output = null;
38         try {
39             output = this.rendererServiceOperations.serviceImplementation(input, false).get();
40         } catch (InterruptedException | ExecutionException e) {
41             LOG.error("RPC service implementation failed !", e);
42             Thread.currentThread().interrupt();
43         }
44         return ModelMappingUtils.createServiceImplementationRpcResponse(output);
45     }
46
47 }