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.write;
23 import org.onap.vnf.vlb.CrudService;
24 import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
25 import io.fd.honeycomb.translate.write.WriteContext;
26 import io.fd.honeycomb.translate.write.WriteFailedException;
27 import javax.annotation.Nonnull;
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.VdnsInstance;
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.vdns.instances.VdnsInstanceKey;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 * Writer for {@link Element} list node from our YANG model.
35 public final class ElementCustomizer implements ListWriterCustomizer<VdnsInstance, VdnsInstanceKey> {
37 private final CrudService<VdnsInstance> crudService;
38 private DnsInstanceManager dnsInstanceManager;
40 public ElementCustomizer(@Nonnull final CrudService<VdnsInstance> crudService) {
41 this.crudService = crudService;
42 dnsInstanceManager = DnsInstanceManager.getInstance();
46 public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<VdnsInstance> id, @Nonnull final VdnsInstance dataAfter,
47 @Nonnull final WriteContext writeContext) throws WriteFailedException {
48 //perform write of data,or throw exception
49 //invoked by PUT operation,if provided data doesn't exist in Config data
50 crudService.writeData(id, dataAfter);
51 dnsInstanceManager.addDnsInstance(dataAfter.getIpAddr(), dataAfter);
55 public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<VdnsInstance> id,
56 @Nonnull final VdnsInstance dataBefore,
57 @Nonnull final VdnsInstance dataAfter, @Nonnull final WriteContext writeContext)
58 throws WriteFailedException {
59 //perform update of data,or throw exception
60 //invoked by PUT operation,if provided data does exist in Config data
61 crudService.updateData(id, dataBefore, dataAfter);
62 dnsInstanceManager.updateDnsInstance(dataAfter.getIpAddr(), dataAfter);
66 public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<VdnsInstance> id,
67 @Nonnull final VdnsInstance dataBefore,
68 @Nonnull final WriteContext writeContext) throws WriteFailedException {
69 //perform delete of data,or throw exception
70 //invoked by DELETE operation
71 crudService.deleteData(id, dataBefore);
72 dnsInstanceManager.deleteDnsInstance(dataBefore.getIpAddr());