2 * Copyright (c) 2016 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package io.fd.honeycomb.translate.v3po.vppstate;
19 import io.fd.honeycomb.translate.read.ReadContext;
20 import io.fd.honeycomb.translate.read.ReadFailedException;
21 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
22 import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator;
23 import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer;
24 import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer;
25 import io.fd.vpp.jvpp.core.dto.ShowVersion;
26 import io.fd.vpp.jvpp.core.dto.ShowVersionReply;
27 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
28 import java.util.concurrent.CompletionStage;
29 import javax.annotation.Nonnull;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppStateBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.Version;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.VersionBuilder;
33 import org.opendaylight.yangtools.concepts.Builder;
34 import org.opendaylight.yangtools.yang.binding.DataObject;
35 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
37 public final class VersionCustomizer
38 extends FutureJVppCustomizer
39 implements ReaderCustomizer<Version, VersionBuilder>, ByteDataTranslator, JvppReplyConsumer {
41 public VersionCustomizer(@Nonnull final FutureJVppCore futureJVppCore) {
42 super(futureJVppCore);
46 public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final Version readValue) {
47 ((VppStateBuilder) parentBuilder).setVersion(readValue);
52 public VersionBuilder getBuilder(@Nonnull InstanceIdentifier<Version> id) {
53 return new VersionBuilder();
57 public void readCurrentAttributes(@Nonnull InstanceIdentifier<Version> id, @Nonnull final VersionBuilder builder,
58 @Nonnull final ReadContext context) throws ReadFailedException {
60 // Execute with timeout
61 final CompletionStage<ShowVersionReply> showVersionFuture = getFutureJVpp().showVersion(new ShowVersion());
62 final ShowVersionReply reply = getReplyForRead(showVersionFuture.toCompletableFuture(), id);
64 builder.setBranch(toString(reply.version));
65 builder.setName(toString(reply.program));
66 builder.setBuildDate(toString(reply.buildDate));
67 builder.setBuildDirectory(toString(reply.buildDirectory));