Bump upstreams
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / transactions / md / OvsdbOperationalCommandAggregator.java
1 /*
2  * Copyright (c) 2015 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
9 package org.opendaylight.ovsdb.southbound.transactions.md;
10
11 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.List;
15 import java.util.Map;
16 import java.util.NoSuchElementException;
17 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
18 import org.opendaylight.ovsdb.lib.message.TableUpdates;
19 import org.opendaylight.ovsdb.lib.notation.Version;
20 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
21 import org.opendaylight.ovsdb.southbound.InstanceIdentifierCodec;
22 import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
23 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 public class OvsdbOperationalCommandAggregator implements TransactionCommand {
30
31     private static final Logger LOG = LoggerFactory.getLogger(OvsdbOperationalCommandAggregator.class);
32     private final List<TransactionCommand> commands = new ArrayList<>();
33     private final Map<NodeId, Node> updatedBridgeNodes = new HashMap<>();
34
35     public OvsdbOperationalCommandAggregator(InstanceIdentifierCodec instanceIdentifierCodec,
36             OvsdbConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema, boolean initialUpdate) {
37         commands.add(new OpenVSwitchUpdateCommand(instanceIdentifierCodec, key, updates, dbSchema));
38         commands.add(new OvsdbManagersUpdateCommand(key, updates,  dbSchema));
39         commands.add(new OvsdbManagersRemovedCommand(key, updates,  dbSchema));
40         commands.add(new OvsdbQosUpdateCommand(instanceIdentifierCodec, key, updates,  dbSchema));
41         commands.add(new OvsdbQosRemovedCommand(key, updates,  dbSchema));
42         commands.add(new OvsdbQueueUpdateCommand(instanceIdentifierCodec, key, updates,  dbSchema));
43         commands.add(new OvsdbQueueRemovedCommand(key, updates,  dbSchema));
44         commands.add(new OvsdbBridgeUpdateCommand(instanceIdentifierCodec, key, updates,  dbSchema,
45                 updatedBridgeNodes));
46         commands.add(new OvsdbBridgeRemovedCommand(instanceIdentifierCodec, key, updates,  dbSchema));
47         commands.add(new OvsdbControllerUpdateCommand(key, updates,  dbSchema));
48         commands.add(new OvsdbControllerRemovedCommand(instanceIdentifierCodec, key, updates,  dbSchema));
49         if (initialUpdate) {
50             commands.add(new OvsdbInitialPortUpdateCommand(instanceIdentifierCodec, key, updates, dbSchema,
51                     updatedBridgeNodes));
52         } else {
53             commands.add(new OvsdbPortUpdateCommand(instanceIdentifierCodec, key, updates, dbSchema));
54         }
55         commands.add(new OvsdbPortRemoveCommand(instanceIdentifierCodec, key, updates, dbSchema));
56
57         if (dbSchema.getVersion().compareTo(
58                 Version.fromString(SouthboundConstants.AUTOATTACH_SUPPORTED_OVS_SCHEMA_VERSION)) >= 0) {
59             commands.add(new OvsdbAutoAttachUpdateCommand(key, updates, dbSchema));
60             commands.add(new OvsdbAutoAttachRemovedCommand(key, updates, dbSchema));
61         } else {
62             LOG.debug("UNSUPPORTED FUNCTIONALITY: AutoAttach not supported in OVS schema version {}",
63                     dbSchema.getVersion().toString());
64         }
65     }
66
67     @SuppressFBWarnings("DCN_NULLPOINTER_EXCEPTION")
68     @Override
69     public void execute(ReadWriteTransaction transaction) {
70         for (TransactionCommand command : commands) {
71             try {
72                 command.execute(transaction);
73             } catch (NullPointerException | NoSuchElementException | ClassCastException e) {
74                 LOG.warn("Exception trying to execute {}", command, e);
75             }
76         }
77     }
78
79     @Override
80     public void onSuccess() {
81         for (TransactionCommand command : commands) {
82             command.onSuccess();
83         }
84     }
85
86     @Override
87     public void onFailure(Throwable throwable) {
88         for (TransactionCommand command: commands) {
89             command.onFailure(throwable);
90         }
91     }
92 }