Fixup Augmentable and Identifiable methods changing
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / datastore / multipart / MeterConfigMultipartWriter.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.DeviceRegistry;
12 import org.opendaylight.openflowplugin.api.openflow.device.TxFacade;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatistics;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatisticsBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterConfigStatsReply;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22
23 public class MeterConfigMultipartWriter extends AbstractMultipartWriter<MeterConfigStatsReply> {
24
25     private final DeviceRegistry registry;
26
27     public MeterConfigMultipartWriter(final TxFacade txFacade,
28                                       final InstanceIdentifier<Node> instanceIdentifier,
29                                       final DeviceRegistry registry) {
30         super(txFacade, instanceIdentifier);
31         this.registry = registry;
32     }
33
34     @Override
35     protected Class<MeterConfigStatsReply> getType() {
36         return MeterConfigStatsReply.class;
37     }
38
39     @Override
40     public void storeStatistics(final MeterConfigStatsReply statistics, final boolean withParents) {
41         statistics.getMeterConfigStats()
42             .forEach(stat -> {
43                 writeToTransaction(
44                     getInstanceIdentifier()
45                         .augmentation(FlowCapableNode.class)
46                         .child(Meter.class, new MeterKey(stat.getMeterId())),
47                     new MeterBuilder(stat)
48                         .withKey(new MeterKey(stat.getMeterId()))
49                         .addAugmentation(NodeMeterStatistics.class, new NodeMeterStatisticsBuilder().build())
50                         .build(),
51                     withParents);
52
53                 registry.getDeviceMeterRegistry().store(stat.getMeterId());
54             });
55     }
56
57 }