Fixup Augmentable and Identifiable methods changing
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / datastore / multipart / GroupDescMultipartWriter.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.group.statistics.rev131111.NodeGroupStatistics;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatisticsBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupDescStatsReply;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22
23 public class GroupDescMultipartWriter extends AbstractMultipartWriter<GroupDescStatsReply> {
24
25     private final DeviceRegistry registry;
26
27     public GroupDescMultipartWriter(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<GroupDescStatsReply> getType() {
36         return GroupDescStatsReply.class;
37     }
38
39     @Override
40     public void storeStatistics(final GroupDescStatsReply statistics, final boolean withParents) {
41         statistics.getGroupDescStats()
42             .forEach(stat -> {
43                 writeToTransaction(
44                     getInstanceIdentifier()
45                         .augmentation(FlowCapableNode.class)
46                         .child(Group.class, new GroupKey(stat.getGroupId())),
47                     new GroupBuilder(stat)
48                         .withKey(new GroupKey(stat.getGroupId()))
49                         .addAugmentation(NodeGroupStatistics.class, new NodeGroupStatisticsBuilder().build())
50                         .build(),
51                     withParents);
52
53                 registry.getDeviceGroupRegistry().store(stat.getGroupId());
54             });
55     }
56
57 }