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