Add health check to vLBMS
[demo.git] / vnfs / vLBMS / apis / health-vnf-onap-plugin / health-vnf-onap-plugin-impl / src / main / java / org / onap / vnf / health / write / ElementCustomizer.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.vnf.health.write;
18
19 import org.onap.vnf.health.CrudService;
20 import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
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.health.vnf.onap.plugin.rev160918.health.vnf.onap.plugin.params.HealthCheck;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26
27 /**
28  * Writer for {@link Element} list node from our YANG model.
29  */
30 //public final class ElementCustomizer implements ListWriterCustomizer<HealthCheck, HealthCheckKey> {
31 public final class ElementCustomizer implements WriterCustomizer<HealthCheck> {
32
33     private final CrudService<HealthCheck> crudService;
34
35     public ElementCustomizer(@Nonnull final CrudService<HealthCheck> crudService) {
36         this.crudService = crudService;
37     }
38
39     @Override
40     public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<HealthCheck> id, @Nonnull final HealthCheck dataAfter,
41                                        @Nonnull final WriteContext writeContext) throws WriteFailedException {
42         //perform write of data,or throw exception
43         //invoked by PUT operation,if provided data doesn't exist in Config data
44         crudService.writeData(id, dataAfter);
45     }
46
47     @Override
48     public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<HealthCheck> id,
49                                         @Nonnull final HealthCheck dataBefore,
50                                         @Nonnull final HealthCheck dataAfter, @Nonnull final WriteContext writeContext)
51             throws WriteFailedException {
52         //perform update of data,or throw exception
53         //invoked by PUT operation,if provided data does exist in Config data
54         crudService.updateData(id, dataBefore, dataAfter);
55     }
56
57     @Override
58     public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<HealthCheck> id,
59                                         @Nonnull final HealthCheck dataBefore,
60                                         @Nonnull final WriteContext writeContext) throws WriteFailedException {
61         //perform delete of data,or throw exception
62         //invoked by DELETE operation
63         crudService.deleteData(id, dataBefore);
64     }
65 }