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.
18 * Modifications copyright (c) 2019 AT&T Intellectual Property
21 package io.fd.honeycomb.lcmapi.init;
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;
34 * Initialize configuration data based on operational data.
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.
40 public final class ConfigDataInitializer extends AbstractDataTreeConverter<StreamCountState, StreamCount> {
43 public ConfigDataInitializer(@Named("honeycomb-initializer") @Nonnull final DataBroker bindingDataBroker) {
44 super(bindingDataBroker, InstanceIdentifier.create(StreamCountState.class), InstanceIdentifier.create(StreamCount.class));
48 public StreamCount convert(final StreamCountState operationalData) {
49 // Transfer all the operational data into configuration
50 return new StreamCountBuilder()
51 .setStreams(operationalData.getStreams())