Update MRI projects for Aluminium
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / datastore / multipart / TableFeaturesMultipartWriter.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowplugin.impl.datastore.multipart;
10
11 import org.opendaylight.openflowplugin.api.openflow.device.TxFacade;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsDataBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesKey;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22
23 public class TableFeaturesMultipartWriter extends AbstractMultipartWriter<TableFeatures> {
24
25     public TableFeaturesMultipartWriter(final TxFacade txFacade,
26                                         final InstanceIdentifier<Node> instanceIdentifier) {
27         super(txFacade, instanceIdentifier);
28     }
29
30     @Override
31     protected Class<TableFeatures> getType() {
32         return TableFeatures.class;
33     }
34
35     @Override
36     public void storeStatistics(final TableFeatures statistics, final boolean withParents) {
37         statistics.nonnullTableFeatures().values()
38             .forEach(stat -> {
39                 writeToTransaction(getInstanceIdentifier()
40                         .augmentation(FlowCapableNode.class)
41                         .child(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features
42                                 .TableFeatures.class,
43                             new TableFeaturesKey(stat.getTableId())),
44                     stat,
45                     withParents);
46
47                 // Write parent for table statistics
48                 writeToTransaction(getInstanceIdentifier()
49                         .augmentation(FlowCapableNode.class)
50                         .child(Table.class, new TableKey(stat.getTableId())),
51                     new TableBuilder()
52                         .setId(stat.getTableId())
53                         .addAugmentation(FlowTableStatisticsData.class, new FlowTableStatisticsDataBuilder()
54                             .build())
55                         .build(),
56                     withParents);
57             });
58     }
59
60 }