be6aa12e666d65781f4f839e2a4199ff4001a4a6
[hc2vpp.git] /
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.lisp.translate.read.dump.executor;
18
19 import static com.google.common.base.Preconditions.checkNotNull;
20
21 import io.fd.honeycomb.lisp.translate.read.dump.executor.params.LocatorDumpParams;
22 import io.fd.honeycomb.translate.v3po.util.TranslateUtils;
23 import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor;
24 import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException;
25 import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpCallFailedException;
26 import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpTimeoutException;
27 import java.util.concurrent.TimeoutException;
28 import javax.annotation.Nonnull;
29 import org.openvpp.jvpp.VppBaseCallException;
30 import org.openvpp.jvpp.core.dto.LispLocatorDetailsReplyDump;
31 import org.openvpp.jvpp.core.dto.LispLocatorDump;
32 import org.openvpp.jvpp.core.future.FutureJVppCore;
33
34
35 /**
36  * Executor for dumping of locators
37  */
38 public class LocatorDumpExecutor extends AbstractDumpExecutor
39         implements EntityDumpExecutor<LispLocatorDetailsReplyDump, LocatorDumpParams> {
40
41
42     public LocatorDumpExecutor(@Nonnull final FutureJVppCore vppApi) {
43         super(vppApi);
44     }
45
46     @Override
47     public LispLocatorDetailsReplyDump executeDump(final LocatorDumpParams params) throws DumpExecutionFailedException {
48         checkNotNull(params, "Params for dump request not present");
49
50         LispLocatorDump request = new LispLocatorDump();
51         request.lsIndex = params.getLocatorSetIndex();
52         //flag that lsIndex is set
53         request.isIndexSet = (byte) 1;
54
55         try {
56             return TranslateUtils.getReply(vppApi.lispLocatorDump(request).toCompletableFuture());
57         } catch (TimeoutException e) {
58             throw DumpTimeoutException
59                     .wrapTimeoutException("Locator dump ended in timeout with params" + params.toString(), e);
60         } catch (VppBaseCallException e) {
61             throw DumpCallFailedException
62                     .wrapFailedCallException("Locator dump failed with params" + params.toString(), e);
63         }
64     }
65 }