HONEYCOMB-154: update revison of models that changed since 16.09
[honeycomb.git] / lisp / lisp2vpp / src / main / java / io / fd / honeycomb / lisp / translate / read / ItrRemoteLocatorSetCustomizer.java
1 /*
2  * Copyright (c) 2015 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 static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS;
21
22 import com.google.common.base.Optional;
23 import io.fd.honeycomb.lisp.translate.read.dump.executor.ItrRemoteLocatorSetDumpExecutor;
24 import io.fd.honeycomb.translate.read.ReadContext;
25 import io.fd.honeycomb.translate.read.ReadFailedException;
26 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
27 import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager;
28 import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager.DumpCacheManagerBuilder;
29 import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator;
30 import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer;
31 import io.fd.vpp.jvpp.core.dto.LispGetMapRequestItrRlocsReply;
32 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
33 import javax.annotation.Nonnull;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.itr.remote.locator.sets.grouping.ItrRemoteLocatorSet;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.itr.remote.locator.sets.grouping.ItrRemoteLocatorSetBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.lisp.feature.data.grouping.LispFeatureDataBuilder;
37 import org.opendaylight.yangtools.concepts.Builder;
38 import org.opendaylight.yangtools.yang.binding.DataObject;
39 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
40
41 public class ItrRemoteLocatorSetCustomizer extends FutureJVppCustomizer
42         implements ReaderCustomizer<ItrRemoteLocatorSet, ItrRemoteLocatorSetBuilder>, ByteDataTranslator {
43
44     private static final String CACHE_KEY = ItrRemoteLocatorSetCustomizer.class.getName();
45
46     private final DumpCacheManager<LispGetMapRequestItrRlocsReply, Void> dumpCacheManager;
47
48     public ItrRemoteLocatorSetCustomizer(@Nonnull final FutureJVppCore futureJVppCore) {
49         super(futureJVppCore);
50         dumpCacheManager = new DumpCacheManagerBuilder<LispGetMapRequestItrRlocsReply, Void>()
51                 .withExecutor(new ItrRemoteLocatorSetDumpExecutor(futureJVppCore)).build();
52     }
53
54     @Nonnull
55     @Override
56     public ItrRemoteLocatorSetBuilder getBuilder(@Nonnull final InstanceIdentifier<ItrRemoteLocatorSet> id) {
57         return new ItrRemoteLocatorSetBuilder();
58     }
59
60     @Override
61     public void readCurrentAttributes(@Nonnull final InstanceIdentifier<ItrRemoteLocatorSet> id,
62                                       @Nonnull final ItrRemoteLocatorSetBuilder builder, @Nonnull final ReadContext ctx)
63             throws ReadFailedException {
64
65         final Optional<LispGetMapRequestItrRlocsReply> reply =
66                 dumpCacheManager.getDump(id, CACHE_KEY, ctx.getModificationCache(), NO_PARAMS);
67         if (!reply.isPresent() || reply.get().locatorSetName == null) {
68             return;
69         }
70
71         builder.setRemoteLocatorSetName(toString(reply.get().locatorSetName));
72     }
73
74     @Override
75     public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder,
76                       @Nonnull final ItrRemoteLocatorSet readValue) {
77         ((LispFeatureDataBuilder) parentBuilder).setItrRemoteLocatorSet(readValue);
78     }
79 }