b97586830acd588d7c80d7ba3892e23464eff993
[hc2vpp.git] /
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.translate.v3po.initializers;
18
19 import com.google.inject.Inject;
20 import com.google.inject.name.Named;
21 import io.fd.honeycomb.data.init.AbstractDataTreeConverter;
22 import java.util.stream.Collectors;
23 import javax.annotation.Nonnull;
24 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.VppClassifier;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.VppClassifierBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.VppClassifierState;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.vpp.classifier.ClassifyTableBuilder;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30
31 /**
32  * Initializes vpp-classfier node in config data tree based on operational state.
33  */
34 public final class VppClasifierInitializer extends AbstractDataTreeConverter<VppClassifierState, VppClassifier> {
35     private static final InstanceIdentifier<VppClassifierState> OPER_ID =
36         InstanceIdentifier.create(VppClassifierState.class);
37     private static final InstanceIdentifier<VppClassifier> CFG_ID = InstanceIdentifier.create(VppClassifier.class);
38
39     @Inject
40     public VppClasifierInitializer(@Named("honeycomb-initializer") @Nonnull final DataBroker bindingDataBroker) {
41         super(bindingDataBroker, OPER_ID, CFG_ID);
42     }
43
44     @Override
45     protected VppClassifier convert(final VppClassifierState operationalData) {
46         final VppClassifierBuilder builder = new VppClassifierBuilder();
47         builder.setClassifyTable(operationalData.getClassifyTable().stream()
48             .map(oper -> new ClassifyTableBuilder(oper).setName(oper.getName()).build())
49             .collect(Collectors.toList()));
50         return builder.build();
51     }
52 }