HONEYCOMB-154: update revison of models that changed since 16.09
[honeycomb.git] / lisp / lisp2vpp / src / main / java / io / fd / honeycomb / lisp / translate / read / LispStateCustomizer.java
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;
18
19
20 import io.fd.honeycomb.translate.read.ReadContext;
21 import io.fd.honeycomb.translate.read.ReadFailedException;
22 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
23 import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator;
24 import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer;
25 import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer;
26 import java.util.concurrent.TimeoutException;
27 import javax.annotation.Nonnull;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.LispState;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.LispStateBuilder;
30 import org.opendaylight.yangtools.concepts.Builder;
31 import org.opendaylight.yangtools.yang.binding.DataObject;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import io.fd.vpp.jvpp.VppBaseCallException;
34 import io.fd.vpp.jvpp.core.dto.ShowLispStatus;
35 import io.fd.vpp.jvpp.core.dto.ShowLispStatusReply;
36 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40
41 /**
42  * Customizer that handles reads of {@code LispState}
43  */
44 public class LispStateCustomizer extends FutureJVppCustomizer
45         implements ReaderCustomizer<LispState, LispStateBuilder>, JvppReplyConsumer, ByteDataTranslator {
46
47     private static final Logger LOG = LoggerFactory.getLogger(LispStateCustomizer.class);
48
49     public LispStateCustomizer(FutureJVppCore futureJvpp) {
50         super(futureJvpp);
51     }
52
53     @Override
54     public LispStateBuilder getBuilder(InstanceIdentifier<LispState> id) {
55         return new LispStateBuilder();
56     }
57
58     @Override
59     public void readCurrentAttributes(InstanceIdentifier<LispState> id, LispStateBuilder builder, ReadContext ctx)
60             throws ReadFailedException {
61
62         ShowLispStatusReply reply;
63         try {
64             reply = getReply(getFutureJVpp().showLispStatus(new ShowLispStatus()).toCompletableFuture());
65         } catch (TimeoutException | VppBaseCallException e) {
66             throw new ReadFailedException(id, e);
67         }
68
69         builder.setEnable(byteToBoolean(reply.featureStatus));
70     }
71
72     @Override
73     public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final LispState readValue) {
74         LOG.warn("Merge is unsupported for data roots");
75     }
76 }