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.health.read;
19 import static org.onap.vnf.health.ModuleConfiguration.ELEMENT_SERVICE_NAME;
21 import java.io.IOException;
23 import com.google.inject.Inject;
24 import com.google.inject.name.Named;
25 import org.onap.vnf.health.CrudService;
26 import io.fd.honeycomb.translate.impl.read.GenericReader;
27 import io.fd.honeycomb.translate.read.ReaderFactory;
28 import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder;
29 import javax.annotation.Nonnull;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.health.vnf.onap.plugin.rev160918.HealthVnfOnapPluginState;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.health.vnf.onap.plugin.rev160918.HealthVnfOnapPluginStateBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.health.vnf.onap.plugin.rev160918.health.vnf.onap.plugin.params.HealthCheck;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
36 * Factory producing readers for health-vnf-onap-plugin plugin's data.
38 public final class ModuleStateReaderFactory implements ReaderFactory {
40 public static final InstanceIdentifier<HealthVnfOnapPluginState> ROOT_STATE_CONTAINER_ID =
41 InstanceIdentifier.create(HealthVnfOnapPluginState.class);
44 * Injected crud service to be passed to customizers instantiated in this factory.
47 @Named(ELEMENT_SERVICE_NAME)
48 private CrudService<HealthCheck> crudService;
51 public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) {
53 // register reader that only delegate read's to its children
54 registry.addStructuralReader(ROOT_STATE_CONTAINER_ID, HealthVnfOnapPluginStateBuilder.class);
56 // just adds reader to the structure
57 // use addAfter/addBefore if you want to add specific order to readers on the same level of tree
58 // use subtreeAdd if you want to handle multiple nodes in single customizer/subtreeAddAfter/subtreeAddBefore if you also want to add order
59 // be aware that instance identifier passes to subtreeAdd/subtreeAddAfter/subtreeAddBefore should define subtree,
60 // therefore it should be relative from handled node down - InstanceIdentifier.create(HandledNode), not parent.child(HandledNode.class)
63 new GenericReader<>(ROOT_STATE_CONTAINER_ID.child(HealthCheck.class),
64 new ElementStateCustomizer(crudService)));
65 } catch (IOException e) {
66 // TODO Auto-generated catch block