Initial OpenECOMP Demo commit
[demo.git] / vnfs / honeycomb_plugin / sample_plugin / sample-plugin-impl / src / main / java / io / fd / honeycomb / tutorial / init / ConfigDataInitializer.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 io.fd.honeycomb.tutorial.init;
18
19 import io.fd.honeycomb.data.init.AbstractDataTreeConverter;
20 import com.google.inject.Inject;
21 import com.google.inject.name.Named;
22 import javax.annotation.Nonnull;
23 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.sample.plugin.rev160918.SamplePlugin;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.sample.plugin.rev160918.SamplePluginBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.sample.plugin.rev160918.SamplePluginState;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28
29 /**
30  * Initialize configuration data based on operational data.
31  * <p/>
32  * Very useful when a plugin is initiated but the underlying layer already contains some operation state.
33  * Deriving the configuration from existing operational state enables reconciliation in case when Honeycomb's persistence
34  * is not available to do the work for us.
35  */
36 public final class ConfigDataInitializer extends AbstractDataTreeConverter<SamplePluginState, SamplePlugin> {
37
38     @Inject
39     public ConfigDataInitializer(@Named("honeycomb-initializer") @Nonnull final DataBroker bindingDataBroker) {
40         super(bindingDataBroker, InstanceIdentifier.create(SamplePluginState.class), InstanceIdentifier.create(SamplePlugin.class));
41     }
42
43     @Override
44     public SamplePlugin convert(final SamplePluginState operationalData) {
45         // Transfer all the operational data into configuration
46         return new SamplePluginBuilder()
47                 .setPgStreams(operationalData.getPgStreams())
48                 .build();
49     }
50 }