Squashed commit of the following:
[demo.git] / vnfs / honeycomb_plugin / stream-count / stream-count-impl / src / main / java / io / fd / honeycomb / lcmapi / 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 /*
18  * Modifications copyright (c) 2019 AT&T Intellectual Property
19  */
20
21 package io.fd.honeycomb.lcmapi.init;
22
23 import io.fd.honeycomb.data.init.AbstractDataTreeConverter;
24 import com.google.inject.Inject;
25 import com.google.inject.name.Named;
26 import javax.annotation.Nonnull;
27 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.stream.count.rev190118.StreamCount;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.stream.count.rev190118.StreamCountBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.stream.count.rev190118.StreamCountState;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32
33 /**
34  * Initialize configuration data based on operational data.
35  * <p/>
36  * Very useful when a plugin is initiated but the underlying layer already contains some operation state.
37  * Deriving the configuration from existing operational state enables reconciliation in case when Honeycomb's persistence
38  * is not available to do the work for us.
39  */
40 public final class ConfigDataInitializer extends AbstractDataTreeConverter<StreamCountState, StreamCount> {
41
42     @Inject
43     public ConfigDataInitializer(@Named("honeycomb-initializer") @Nonnull final DataBroker bindingDataBroker) {
44         super(bindingDataBroker, InstanceIdentifier.create(StreamCountState.class), InstanceIdentifier.create(StreamCount.class));
45     }
46
47     @Override
48     public StreamCount convert(final StreamCountState operationalData) {
49         // Transfer all the operational data into configuration
50         return new StreamCountBuilder()
51                 .setStreams(operationalData.getStreams())
52                 .build();
53     }
54 }