2 * Copyright © 2015, 2017 Intel Corporation and others. All rights reserved.
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
8 package org.opendaylight.ovsdb.southbound.ovsdb.transact;
10 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
12 import java.util.Collection;
13 import java.util.Collections;
14 import java.util.List;
16 import java.util.Map.Entry;
17 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
18 import org.opendaylight.ovsdb.lib.notation.Mutator;
19 import org.opendaylight.ovsdb.lib.operations.Mutate;
20 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
21 import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
22 import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
23 import org.opendaylight.ovsdb.southbound.InstanceIdentifierCodec;
24 import org.opendaylight.ovsdb.utils.yang.YangUtils;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchExternalIds;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchOtherConfigs;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 public class OvsdbNodeUpdateCommand implements TransactCommand {
34 private static final Logger LOG = LoggerFactory.getLogger(OvsdbNodeUpdateCommand.class);
37 public void execute(final TransactionBuilder transaction, final BridgeOperationalState state,
38 final DataChangeEvent events, final InstanceIdentifierCodec instanceIdentifierCodec) {
39 execute(transaction, TransactUtils.extractCreatedOrUpdated(events, OvsdbNodeAugmentation.class),
40 instanceIdentifierCodec);
44 public void execute(final TransactionBuilder transaction, final BridgeOperationalState state,
45 final Collection<DataTreeModification<Node>> modifications,
46 final InstanceIdentifierCodec instanceIdentifierCodec) {
47 execute(transaction, TransactUtils.extractCreatedOrUpdated(modifications, OvsdbNodeAugmentation.class),
48 instanceIdentifierCodec);
51 private static void execute(final TransactionBuilder transaction,
52 final Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> updated,
53 final InstanceIdentifierCodec instanceIdentifierCodec) {
54 for (Entry<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> ovsdbNodeEntry:
56 OvsdbNodeAugmentation ovsdbNode = ovsdbNodeEntry.getValue();
57 if (ovsdbNode.getConnectionInfo() != null) {
58 LOG.debug("Received request to update ovsdb node ip: {} port: {}",
59 ovsdbNode.getConnectionInfo().getRemoteIp(),
60 ovsdbNode.getConnectionInfo().getRemotePort());
62 LOG.debug("Received request to update ovsdb node: {}", ovsdbNode);
66 OpenVSwitch ovs = transaction.getTypedRowWrapper(OpenVSwitch.class);
68 stampInstanceIdentifier(transaction, ovsdbNodeEntry.getKey().firstIdentifierOf(Node.class),
69 instanceIdentifierCodec);
72 ovs.setExternalIds(YangUtils.convertYangKeyValueListToMap(ovsdbNode.getOpenvswitchExternalIds(),
73 OpenvswitchExternalIds::getExternalIdKey, OpenvswitchExternalIds::getExternalIdValue));
74 Mutate<GenericTableSchema> mutate = op.mutate(ovs)
75 .addMutation(ovs.getExternalIdsColumn().getSchema(),
77 ovs.getExternalIdsColumn().getData());
78 transaction.add(mutate);
79 } catch (NullPointerException e) {
80 LOG.warn("Incomplete OVSDB Node external IDs", e);
85 List<OpenvswitchOtherConfigs> otherConfigs = ovsdbNode.getOpenvswitchOtherConfigs();
86 if (otherConfigs != null) {
88 ovs.setOtherConfig(YangUtils.convertYangKeyValueListToMap(otherConfigs,
89 OpenvswitchOtherConfigs::getOtherConfigKey, OpenvswitchOtherConfigs::getOtherConfigValue));
90 transaction.add(op.mutate(ovs).addMutation(ovs.getOtherConfigColumn().getSchema(),
92 ovs.getOtherConfigColumn().getData()));
93 } catch (NullPointerException e) {
94 LOG.warn("Incomplete OVSDB Node other_config", e);
100 private static void stampInstanceIdentifier(final TransactionBuilder transaction,
101 final InstanceIdentifier<Node> iid, final InstanceIdentifierCodec instanceIdentifierCodec) {
102 OpenVSwitch ovs = transaction.getTypedRowWrapper(OpenVSwitch.class);
103 ovs.setExternalIds(Collections.emptyMap());
104 TransactUtils.stampInstanceIdentifier(transaction, iid, ovs.getSchema(),
105 ovs.getExternalIdsColumn().getSchema(), instanceIdentifierCodec);