Merge "OPNFLWPLUG-1000 : Execute reconciliation asynchronously when the user selected...
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / datastore / multipart / QueueStatsMultipartWriter.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.openflowplugin.api.openflow.md.util.OpenflowVersion;
13 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.Queue;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.QueueBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.QueueKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsData;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsDataBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.QueueIdAndStatisticsMap;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.flow.capable.node.connector.queue.statistics.FlowCapableNodeConnectorQueueStatisticsBuilder;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28
29 public class QueueStatsMultipartWriter extends AbstractMultipartWriter<QueueIdAndStatisticsMap> {
30
31     private final FeaturesReply features;
32
33
34     public QueueStatsMultipartWriter(final TxFacade txFacade,
35                                      final InstanceIdentifier<Node> instanceIdentifier,
36                                      final FeaturesReply features) {
37         super(txFacade, instanceIdentifier);
38         this.features = features;
39     }
40
41     @Override
42     protected Class<QueueIdAndStatisticsMap> getType() {
43         return QueueIdAndStatisticsMap.class;
44     }
45
46     @Override
47     public void storeStatistics(final QueueIdAndStatisticsMap statistics, final boolean withParents) {
48         final OpenflowVersion openflowVersion = OpenflowVersion.get(features.getVersion());
49
50         statistics.getQueueIdAndStatisticsMap()
51             .forEach((stat) -> {
52                 final Long port = InventoryDataServiceUtil
53                         .portNumberfromNodeConnectorId(openflowVersion, stat.getNodeConnectorId());
54                 final NodeConnectorId id = InventoryDataServiceUtil
55                         .nodeConnectorIdfromDatapathPortNo(
56                                 features.getDatapathId(),
57                                 port,
58                                 OpenflowVersion.get(features.getVersion()));
59
60                 writeToTransaction(
61                         getInstanceIdentifier()
62                                 .child(NodeConnector.class, new NodeConnectorKey(id))
63                                 .augmentation(FlowCapableNodeConnector.class)
64                                 .child(Queue.class, new QueueKey(stat.getQueueId())),
65                         new QueueBuilder()
66                                 .withKey(new QueueKey(stat.getQueueId()))
67                                 .setQueueId(stat.getQueueId())
68                                 .addAugmentation(
69                                         FlowCapableNodeConnectorQueueStatisticsData.class,
70                                         new FlowCapableNodeConnectorQueueStatisticsDataBuilder()
71                                                 .setFlowCapableNodeConnectorQueueStatistics(
72                                                         new FlowCapableNodeConnectorQueueStatisticsBuilder(stat)
73                                                                 .build())
74                                                 .build())
75                                 .build(),
76                         withParents);
77             });
78     }
79
80 }