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 org.onap.vnf.vlb;
19 import io.fd.honeycomb.translate.read.ReadFailedException;
20 import io.fd.honeycomb.translate.write.WriteFailedException;
21 import java.util.Collections;
22 import java.util.List;
23 import javax.annotation.Nonnull;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vlb.business.vnf.onap.plugin.rev160918.VlbBusinessVnfOnapPluginState;
25 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;
26 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;
27 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;
28 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;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * Simple example of class handling Crud operations for plugin.
36 * No real handling, serves just as an illustration.
40 final class ElementCrudService implements CrudService<VdnsInstance> {
42 private static final Logger LOG = LoggerFactory.getLogger(ElementCrudService.class);
45 public void writeData(@Nonnull final InstanceIdentifier<VdnsInstance> identifier, @Nonnull final VdnsInstance data)
46 throws WriteFailedException {
49 // identifier.firstKeyOf(SomeClassUpperInHierarchy.class) can be used to identify
50 // relationships such as to which parent these data are related to
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<VdnsInstance> identifier, @Nonnull final VdnsInstance data)
62 throws WriteFailedException {
65 // identifier.firstKeyOf(SomeClassUpperInHierarchy.class) can be used to identify
66 // relationships such as to which parent these data are related to
68 // Performs any logic needed for persisting such data
69 LOG.info("Removing path[{}] / data [{}]", identifier, data);
71 throw new WriteFailedException.DeleteFailedException(identifier,
72 new NullPointerException("Provided data are null"));
77 public void updateData(@Nonnull final InstanceIdentifier<VdnsInstance> identifier, @Nonnull final VdnsInstance dataOld,
78 @Nonnull final VdnsInstance dataNew) throws WriteFailedException {
79 if (dataOld != null && dataNew != null) {
81 // identifier.firstKeyOf(SomeClassUpperInHierarchy.class) can be used to identify
82 // relationships such as to which parent these data are related to
84 // Performs any logic needed for persisting such data
85 LOG.info("Update path[{}] from [{}] to [{}]", identifier, dataOld, dataNew);
87 throw new WriteFailedException.DeleteFailedException(identifier,
88 new NullPointerException("Provided data are null"));
93 public VdnsInstance readSpecific(@Nonnull final InstanceIdentifier<VdnsInstance> identifier) throws ReadFailedException {
95 // read key specified in path identifier
96 final VdnsInstanceKey key = identifier.firstKeyOf(VdnsInstance.class);
98 // load data by this key
99 // *Key class will always contain key of entity, in this case long value
101 return new VdnsInstanceBuilder()
102 .setIpAddr(key.getIpAddr())
109 public List<VdnsInstance> readAll() throws ReadFailedException {
110 // read all data under parent node,in this case {@link ModuleState}
111 return Collections.singletonList(
112 readSpecific(InstanceIdentifier.create(VlbBusinessVnfOnapPluginState.class).child(VdnsInstances.class).child(VdnsInstance.class, new VdnsInstanceKey(""))));