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 java.util.concurrent.CompletionStage;
26 import javax.annotation.Nonnull;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppStateBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.Version;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.VersionBuilder;
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.ShowVersion;
35 import io.fd.vpp.jvpp.core.dto.ShowVersionReply;
36 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
38 public final class VersionCustomizer
39 extends FutureJVppCustomizer
40 implements ReaderCustomizer<Version, VersionBuilder>, ByteDataTranslator, JvppReplyConsumer {
42 public VersionCustomizer(@Nonnull final FutureJVppCore futureJVppCore) {
43 super(futureJVppCore);
47 public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final Version readValue) {
48 ((VppStateBuilder) parentBuilder).setVersion(readValue);
53 public VersionBuilder getBuilder(@Nonnull InstanceIdentifier<Version> id) {
54 return new VersionBuilder();
58 public void readCurrentAttributes(@Nonnull InstanceIdentifier<Version> id, @Nonnull final VersionBuilder builder,
59 @Nonnull final ReadContext context) throws ReadFailedException {
61 // Execute with timeout
62 final CompletionStage<ShowVersionReply> showVersionFuture = getFutureJVpp().showVersion(new ShowVersion());
63 final ShowVersionReply reply = getReplyForRead(showVersionFuture.toCompletableFuture(), id);
65 builder.setBranch(toString(reply.version));
66 builder.setName(toString(reply.program));
67 builder.setBuildDate(toString(reply.buildDate));
68 builder.setBuildDirectory(toString(reply.buildDirectory));
69 } catch (VppBaseCallException e) {
70 throw new ReadFailedException(id, e);