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) 2018 AT&T Intellectual Property
21 package org.onap.vnf.vlb;
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.vlb.business.vnf.onap.plugin.rev160918.VlbBusinessVnfOnapPluginState;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vlb.business.vnf.onap.plugin.rev160918.vlb.business.vnf.onap.plugin.params.VdnsInstances;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vlb.business.vnf.onap.plugin.rev160918.vlb.business.vnf.onap.plugin.params.vdns.instances.VdnsInstance;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vlb.business.vnf.onap.plugin.rev160918.vlb.business.vnf.onap.plugin.params.vdns.instances.VdnsInstanceBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vlb.business.vnf.onap.plugin.rev160918.vlb.business.vnf.onap.plugin.params.vdns.instances.VdnsInstanceKey;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
38 * Simple example of class handling Crud operations for plugin.
40 * No real handling, serves just as an illustration.
44 final class ElementCrudService implements CrudService<VdnsInstance> {
46 private static final Logger LOG = LoggerFactory.getLogger(ElementCrudService.class);
49 public void writeData(@Nonnull final InstanceIdentifier<VdnsInstance> identifier, @Nonnull final VdnsInstance data)
50 throws WriteFailedException {
53 // identifier.firstKeyOf(SomeClassUpperInHierarchy.class) can be used to identify
54 // relationships such as to which parent these data are related to
56 // Performs any logic needed for persisting such data
57 LOG.info("Writing path[{}] / data [{}]", identifier, data);
59 throw new WriteFailedException.CreateFailedException(identifier, data,
60 new NullPointerException("Provided data are null"));
65 public void deleteData(@Nonnull final InstanceIdentifier<VdnsInstance> identifier, @Nonnull final VdnsInstance data)
66 throws WriteFailedException {
69 // identifier.firstKeyOf(SomeClassUpperInHierarchy.class) can be used to identify
70 // relationships such as to which parent these data are related to
72 // Performs any logic needed for persisting such data
73 LOG.info("Removing path[{}] / data [{}]", identifier, data);
75 throw new WriteFailedException.DeleteFailedException(identifier,
76 new NullPointerException("Provided data are null"));
81 public void updateData(@Nonnull final InstanceIdentifier<VdnsInstance> identifier, @Nonnull final VdnsInstance dataOld,
82 @Nonnull final VdnsInstance dataNew) throws WriteFailedException {
83 if (dataOld != null && dataNew != null) {
85 // identifier.firstKeyOf(SomeClassUpperInHierarchy.class) can be used to identify
86 // relationships such as to which parent these data are related to
88 // Performs any logic needed for persisting such data
89 LOG.info("Update path[{}] from [{}] to [{}]", identifier, dataOld, dataNew);
91 throw new WriteFailedException.DeleteFailedException(identifier,
92 new NullPointerException("Provided data are null"));
97 public VdnsInstance readSpecific(@Nonnull final InstanceIdentifier<VdnsInstance> identifier) throws ReadFailedException {
99 // read key specified in path identifier
100 final VdnsInstanceKey key = identifier.firstKeyOf(VdnsInstance.class);
102 // load data by this key
103 // *Key class will always contain key of entity, in this case long value
105 return new VdnsInstanceBuilder()
106 .setIpAddr(key.getIpAddr())
108 .setOamIpAddr("10.0.80.0")
114 public List<VdnsInstance> readAll() throws ReadFailedException {
115 // read all data under parent node,in this case {@link ModuleState}
116 return Collections.singletonList(
117 readSpecific(InstanceIdentifier.create(VlbBusinessVnfOnapPluginState.class).child(VdnsInstances.class).child(VdnsInstance.class, new VdnsInstanceKey(""))));