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.
18 * Modifications copyright (c) 2019 AT&T Intellectual Property
21 package org.onap.vnf.vfw;
23 import io.fd.honeycomb.translate.read.ReadFailedException;
24 import io.fd.honeycomb.translate.write.WriteFailedException;
25 import java.util.Collections;
26 import java.util.List;
27 import javax.annotation.Nonnull;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.stream.count.rev190118.StreamCountState;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.stream.count.rev190118.stream.count.params.Streams;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.stream.count.rev190118.stream.count.params.StreamsBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.stream.count.rev190118.StreamNum;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
37 * Simple example of class handling Crud operations for plugin.
39 * No real handling, serves just as an illustration.
43 final class ElementCrudService implements CrudService<Streams> {
45 private static final Logger LOG = LoggerFactory.getLogger(ElementCrudService.class);
48 public void writeData(@Nonnull final InstanceIdentifier<Streams> identifier, @Nonnull final Streams data)
49 throws WriteFailedException {
52 // Performs any logic needed for persisting such data
53 LOG.info("Writing path[{}] / data [{}]", identifier, data);
55 throw new WriteFailedException.CreateFailedException(identifier, data,
56 new NullPointerException("Provided data are null"));
61 public void deleteData(@Nonnull final InstanceIdentifier<Streams> identifier, @Nonnull final Streams data)
62 throws WriteFailedException {
65 // Performs any logic needed for persisting such data
66 LOG.info("Removing path[{}] / data [{}]", identifier, data);
68 throw new WriteFailedException.DeleteFailedException(identifier,
69 new NullPointerException("Provided data are null"));
74 public void updateData(@Nonnull final InstanceIdentifier<Streams> identifier, @Nonnull final Streams dataOld,
75 @Nonnull final Streams dataNew) throws WriteFailedException {
76 if (dataOld != null && dataNew != null) {
78 // Performs any logic needed for persisting such data
79 LOG.info("Update path[{}] from [{}] to [{}]", identifier, dataOld, dataNew);
81 throw new WriteFailedException.DeleteFailedException(identifier,
82 new NullPointerException("Provided data are null"));
87 public Streams readSpecific(@Nonnull final InstanceIdentifier<Streams> identifier) throws ReadFailedException {
89 // load data by this key
90 // *Key class will always contain key of entity, in this case long value
92 return new StreamsBuilder()
93 .setActiveStreams(new StreamNum(1L))
98 public List<Streams> readAll() throws ReadFailedException {
99 // read all data under parent node,in this case {@link ModuleState}
100 return Collections.singletonList(
101 readSpecific(InstanceIdentifier.create(StreamCountState.class).child(Streams.class)));