17bd9aa35c097f5dc1fcc52a66c079f7ee0d61b0
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / ovsdb / transact / TransactCommandAggregator.java
1 /*
2  * Copyright (c) 2014, 2016 Cisco Systems, Inc. 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 package org.opendaylight.ovsdb.southbound.ovsdb.transact;
9
10 import java.util.Collection;
11
12 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
13 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
14 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22  * This transactional command aggregates all the Southbound commands.
23  */
24 public class TransactCommandAggregator implements TransactCommand {
25     private static final Logger LOG = LoggerFactory.getLogger(TransactCommandAggregator.class);
26
27     private static final Class<? extends TransactCommand>[] COMMAND_CLASSES =
28             new Class[] {
29                     BridgeUpdateCommand.class,
30                     OpenVSwitchBridgeAddCommand.class,
31                     ControllerUpdateCommand.class,
32                     ControllerRemovedCommand.class,
33                     ProtocolUpdateCommand.class,
34                     ProtocolRemovedCommand.class,
35                     BridgeRemovedCommand.class,
36                     TerminationPointCreateCommand.class,
37                     TerminationPointDeleteCommand.class,
38                     OvsdbNodeUpdateCommand.class,
39                     AutoAttachUpdateCommand.class,
40                     AutoAttachRemovedCommand.class,
41                     QosUpdateCommand.class,
42                     QosRemovedCommand.class,
43                     QueueUpdateCommand.class,
44                     QueueRemovedCommand.class,
45                     TerminationPointUpdateCommand.class,
46             };
47
48     @Override
49     public void execute(TransactionBuilder transaction, BridgeOperationalState state,
50                         AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> events) {
51         for (Class<? extends TransactCommand> commandClass : COMMAND_CLASSES) {
52             try {
53                 commandClass.newInstance().execute(transaction, state, events);
54             } catch (InstantiationException | IllegalAccessException e) {
55                 LOG.error("Error instantiating {}", commandClass, e);
56             }
57         }
58     }
59
60     @Override
61     public void execute(TransactionBuilder transaction, BridgeOperationalState state,
62                         Collection<DataTreeModification<Node>> modifications) {
63         for (Class<? extends TransactCommand> commandClass : COMMAND_CLASSES) {
64             try {
65                 commandClass.newInstance().execute(transaction, state, modifications);
66             } catch (InstantiationException | IllegalAccessException e) {
67                 LOG.error("Error instantiating {}", commandClass, e);
68             }
69         }
70     }
71 }