<feature version='${project.version}'>odl-ovsdb-southbound-api</feature>
<bundle>mvn:org.opendaylight.ovsdb/southbound-impl/{{VERSION}}</bundle>
<bundle>mvn:org.opendaylight.ovsdb/library/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.ovsdb/utils.yang-utils/{{VERSION}}</bundle>
<bundle>mvn:com.fasterxml.jackson.core/jackson-annotations/{{VERSION}}</bundle>
<bundle>mvn:com.fasterxml.jackson.core/jackson-core/{{VERSION}}</bundle>
<bundle>mvn:com.fasterxml.jackson.core/jackson-databind/{{VERSION}}</bundle>
<artifactId>schema.openvswitch</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.ovsdb</groupId>
+ <artifactId>utils.yang-utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2015, 2016 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import org.opendaylight.ovsdb.southbound.ovsdb.transact.TransactInvokerImpl;
import org.opendaylight.ovsdb.southbound.ovsdb.transact.TransactUtils;
import org.opendaylight.ovsdb.southbound.transactions.md.TransactionInvoker;
+import org.opendaylight.ovsdb.utils.yang.YangUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchExternalIds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.ListenableFuture;
// OpenVSwitchPart
OpenVSwitch ovs = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), OpenVSwitch.class);
- Map<String, String> externalIdsMap = new HashMap<>();
List<OpenvswitchExternalIds> externalIds = this.initialCreateData.getOpenvswitchExternalIds();
- if (externalIds != null) {
- for (OpenvswitchExternalIds externalId : externalIds) {
- externalIdsMap.put(externalId.getExternalIdKey(), externalId.getExternalIdValue());
- }
- }
-
stampInstanceIdentifier(transaction,this.instanceIdentifier.firstIdentifierOf(Node.class));
try {
- ovs.setExternalIds(ImmutableMap.copyOf(externalIdsMap));
+ ovs.setExternalIds(
+ YangUtils.convertYangKeyValueListToMap(externalIds, OpenvswitchExternalIds::getExternalIdKey,
+ OpenvswitchExternalIds::getExternalIdValue));
Mutate<GenericTableSchema> mutate = op.mutate(ovs)
.addMutation(ovs.getExternalIdsColumn().getSchema(),
Mutator.INSERT,
List<OpenvswitchOtherConfigs> otherConfigs = this.initialCreateData.getOpenvswitchOtherConfigs();
if (otherConfigs != null) {
- Map<String, String> otherConfigsMap = new HashMap<>();
- for (OpenvswitchOtherConfigs otherConfig : otherConfigs) {
- otherConfigsMap.put(otherConfig.getOtherConfigKey(), otherConfig.getOtherConfigValue());
- }
try {
- ovs.setOtherConfig(ImmutableMap.copyOf(otherConfigsMap));
+ ovs.setOtherConfig(YangUtils.convertYangKeyValueListToMap(otherConfigs,
+ OpenvswitchOtherConfigs::getOtherConfigKey,
+ OpenvswitchOtherConfigs::getOtherConfigValue));
transaction.add(op.mutate(ovs).addMutation(ovs.getOtherConfigColumn().getSchema(),
Mutator.INSERT,
ovs.getOtherConfigColumn().getData()));
/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2015, 2016 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import java.util.Collections;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import javax.annotation.Nonnull;
+
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.ovsdb.lib.notation.UUID;
import org.opendaylight.ovsdb.lib.operations.Insert;
import org.opendaylight.ovsdb.southbound.SouthboundConstants;
import org.opendaylight.ovsdb.southbound.SouthboundMapper;
import org.opendaylight.ovsdb.southbound.SouthboundUtil;
+import org.opendaylight.ovsdb.utils.yang.YangUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.InterfaceTypeInternal;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeExternalIds;
import org.slf4j.LoggerFactory;
import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
public class BridgeUpdateCommand extends AbstractTransactCommand {
Map<String, String> externalIdMap = new HashMap<>();
externalIdMap.put(SouthboundConstants.IID_EXTERNAL_ID_KEY, SouthboundUtil.serializeInstanceIdentifier(iid));
// Set user provided external ids
- List<BridgeExternalIds> bridgeExternalId = ovsdbManagedNode.getBridgeExternalIds();
- if (bridgeExternalId != null) {
- for (BridgeExternalIds externalId : bridgeExternalId) {
- externalIdMap.put(externalId.getBridgeExternalIdKey(), externalId.getBridgeExternalIdValue());
- }
- }
try {
- bridge.setExternalIds(ImmutableMap.copyOf(externalIdMap));
+ YangUtils.copyYangKeyValueListToMap(externalIdMap, ovsdbManagedNode.getBridgeExternalIds(),
+ BridgeExternalIds::getBridgeExternalIdKey, BridgeExternalIds::getBridgeExternalIdValue);
} catch (NullPointerException e) {
LOG.warn("Incomplete bridge external Id", e);
}
+ bridge.setExternalIds(externalIdMap);
}
- private void setOpenDaylightOtherConfig(Bridge bridge, OvsdbBridgeAugmentation ovsdbManagedNode) {
- List<BridgeOtherConfigs> bridgeOtherConfig = ovsdbManagedNode.getBridgeOtherConfigs();
- if (bridgeOtherConfig != null) {
- Map<String, String> otherConfigMap = new HashMap<>();
- for (BridgeOtherConfigs otherConf : bridgeOtherConfig) {
- otherConfigMap.put(otherConf.getBridgeOtherConfigKey(), otherConf.getBridgeOtherConfigValue());
- }
- try {
- bridge.setOtherConfig(ImmutableMap.copyOf(otherConfigMap));
- } catch (NullPointerException e) {
- LOG.warn("Incomplete bridge other config", e);
- }
+ private void setOpenDaylightOtherConfig(@Nonnull Bridge bridge, @Nonnull OvsdbBridgeAugmentation ovsdbManagedNode) {
+ try {
+ bridge.setOtherConfig(YangUtils.convertYangKeyValueListToMap(ovsdbManagedNode.getBridgeOtherConfigs(),
+ BridgeOtherConfigs::getBridgeOtherConfigKey, BridgeOtherConfigs::getBridgeOtherConfigValue));
+ } catch (NullPointerException e) {
+ LOG.warn("Incomplete bridge other config", e);
}
}
/*
- * Copyright (c) 2015 Intel Corporation and others. All rights reserved.
+ * Copyright (c) 2015, 2016 Intel Corporation and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import static org.opendaylight.ovsdb.lib.operations.Operations.op;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
+import org.opendaylight.ovsdb.utils.yang.YangUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchExternalIds;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchOtherConfigs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.ImmutableMap;
-
public class OvsdbNodeUpdateCommand implements TransactCommand {
private AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes;
private static final Logger LOG = LoggerFactory.getLogger(OvsdbNodeUpdateCommand.class);
// OpenVSwitchPart
OpenVSwitch ovs = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), OpenVSwitch.class);
- Map<String, String> externalIdsMap = new HashMap<>();
-
- List<OpenvswitchExternalIds> externalIds = ovsdbNode.getOpenvswitchExternalIds();
-
- if (externalIds != null) {
- for (OpenvswitchExternalIds externalId : externalIds) {
- externalIdsMap.put(externalId.getExternalIdKey(), externalId.getExternalIdValue());
- }
- }
stampInstanceIdentifier(transaction,ovsdbNodeEntry.getKey().firstIdentifierOf(Node.class));
try {
- ovs.setExternalIds(ImmutableMap.copyOf(externalIdsMap));
+ ovs.setExternalIds(YangUtils.convertYangKeyValueListToMap(ovsdbNode.getOpenvswitchExternalIds(),
+ OpenvswitchExternalIds::getExternalIdKey, OpenvswitchExternalIds::getExternalIdValue));
Mutate<GenericTableSchema> mutate = op.mutate(ovs)
.addMutation(ovs.getExternalIdsColumn().getSchema(),
Mutator.INSERT,
List<OpenvswitchOtherConfigs> otherConfigs = ovsdbNode.getOpenvswitchOtherConfigs();
if (otherConfigs != null) {
- Map<String, String> otherConfigsMap = new HashMap<>();
- for (OpenvswitchOtherConfigs otherConfig : otherConfigs) {
- otherConfigsMap.put(otherConfig.getOtherConfigKey(), otherConfig.getOtherConfigValue());
- }
try {
- ovs.setOtherConfig(ImmutableMap.copyOf(otherConfigsMap));
+ ovs.setOtherConfig(YangUtils.convertYangKeyValueListToMap(otherConfigs,
+ OpenvswitchOtherConfigs::getOtherConfigKey, OpenvswitchOtherConfigs::getOtherConfigValue));
transaction.add(op.mutate(ovs).addMutation(ovs.getOtherConfigColumn().getSchema(),
Mutator.INSERT,
ovs.getOtherConfigColumn().getData()));
import static org.opendaylight.ovsdb.lib.operations.Operations.op;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
-import org.opendaylight.ovsdb.lib.notation.Condition;
-import org.opendaylight.ovsdb.lib.notation.Mutator;
import org.opendaylight.ovsdb.lib.notation.UUID;
-import org.opendaylight.ovsdb.lib.operations.Mutate;
import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
-import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
-import org.opendaylight.ovsdb.schema.openvswitch.Port;
import org.opendaylight.ovsdb.schema.openvswitch.Qos;
import org.opendaylight.ovsdb.southbound.SouthboundConstants;
import org.opendaylight.ovsdb.southbound.SouthboundMapper;
+import org.opendaylight.ovsdb.utils.yang.YangUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntries;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.qos.entries.QosExternalIds;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.qos.entries.QosOtherConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.ImmutableMap;
-
public class QosUpdateCommand extends AbstractTransactCommand {
private static final Logger LOG = LoggerFactory.getLogger(QosUpdateCommand.class);
}
qos.setQueues(newQueueList);
- List<QosExternalIds> externalIds = qosEntry.getQosExternalIds();
Map<String, String> externalIdsMap = new HashMap<>();
- if (externalIds != null) {
- for (QosExternalIds externalId : externalIds) {
- externalIdsMap.put(externalId.getQosExternalIdKey(), externalId.getQosExternalIdValue());
- }
- }
- externalIdsMap.put(SouthboundConstants.QOS_ID_EXTERNAL_ID_KEY, qosEntry.getQosId().getValue());
try {
- qos.setExternalIds(ImmutableMap.copyOf(externalIdsMap));
+ YangUtils.copyYangKeyValueListToMap(externalIdsMap, qosEntry.getQosExternalIds(),
+ QosExternalIds::getQosExternalIdKey, QosExternalIds::getQosExternalIdValue);
} catch (NullPointerException e) {
LOG.warn("Incomplete Qos external IDs", e);
}
+ externalIdsMap.put(SouthboundConstants.QOS_ID_EXTERNAL_ID_KEY, qosEntry.getQosId().getValue());
+ qos.setExternalIds(externalIdsMap);
- List<QosOtherConfig> otherConfigs = qosEntry.getQosOtherConfig();
- if (otherConfigs != null) {
- Map<String, String> otherConfigsMap = new HashMap<>();
- for (QosOtherConfig otherConfig : otherConfigs) {
- otherConfigsMap.put(otherConfig.getOtherConfigKey(), otherConfig.getOtherConfigValue());
- }
- try {
- qos.setOtherConfig(ImmutableMap.copyOf(otherConfigsMap));
- } catch (NullPointerException e) {
- LOG.warn("Incomplete Qos other_config", e);
- }
+ try {
+ qos.setOtherConfig(YangUtils.convertYangKeyValueListToMap(qosEntry.getQosOtherConfig(),
+ QosOtherConfig::getOtherConfigKey, QosOtherConfig::getOtherConfigValue));
+ } catch (NullPointerException e) {
+ LOG.warn("Incomplete Qos other_config", e);
}
if (uuid == null) {
transaction.add(op.insert(qos)).build();
import java.util.Set;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
-import org.opendaylight.ovsdb.lib.notation.Mutator;
import org.opendaylight.ovsdb.lib.notation.UUID;
-import org.opendaylight.ovsdb.lib.operations.Mutate;
import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
-import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
-import org.opendaylight.ovsdb.schema.openvswitch.Qos;
import org.opendaylight.ovsdb.schema.openvswitch.Queue;
import org.opendaylight.ovsdb.southbound.SouthboundConstants;
-import org.opendaylight.ovsdb.southbound.SouthboundMapper;
+import org.opendaylight.ovsdb.utils.yang.YangUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntries;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.Queues;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.queues.QueuesExternalIds;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.queues.QueuesOtherConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.ImmutableMap;
-
public class QueueUpdateCommand extends AbstractTransactCommand {
private static final Logger LOG = LoggerFactory.getLogger(QueueUpdateCommand.class);
uuid = new UUID(queueUuid.getValue());
}
- List<QueuesExternalIds> externalIds = queueEntry.getQueuesExternalIds();
Map<String, String> externalIdsMap = new HashMap<>();
- if (externalIds != null) {
- for (QueuesExternalIds externalId : externalIds) {
- externalIdsMap.put(externalId.getQueuesExternalIdKey(), externalId.getQueuesExternalIdValue());
- }
- }
- externalIdsMap.put(SouthboundConstants.QUEUE_ID_EXTERNAL_ID_KEY, queueEntry.getQueueId().getValue());
try {
- queue.setExternalIds(ImmutableMap.copyOf(externalIdsMap));
+ YangUtils.copyYangKeyValueListToMap(externalIdsMap, queueEntry.getQueuesExternalIds(),
+ QueuesExternalIds::getQueuesExternalIdKey, QueuesExternalIds::getQueuesExternalIdValue);
} catch (NullPointerException e) {
LOG.warn("Incomplete Queue external IDs", e);
}
+ externalIdsMap.put(SouthboundConstants.QUEUE_ID_EXTERNAL_ID_KEY, queueEntry.getQueueId().getValue());
+ queue.setExternalIds(externalIdsMap);
- List<QueuesOtherConfig> otherConfigs = queueEntry.getQueuesOtherConfig();
- if (otherConfigs != null) {
- Map<String, String> otherConfigsMap = new HashMap<>();
- for (QueuesOtherConfig otherConfig : otherConfigs) {
- otherConfigsMap.put(otherConfig.getQueueOtherConfigKey(), otherConfig.getQueueOtherConfigValue());
- }
- try {
- queue.setOtherConfig(ImmutableMap.copyOf(otherConfigsMap));
- } catch (NullPointerException e) {
- LOG.warn("Incomplete Queue other_config", e);
- }
+ try {
+ queue.setOtherConfig(YangUtils.convertYangKeyValueListToMap(queueEntry.getQueuesOtherConfig(),
+ QueuesOtherConfig::getQueueOtherConfigKey, QueuesOtherConfig::getQueueOtherConfigValue));
+ } catch (NullPointerException e) {
+ LOG.warn("Incomplete Queue other_config", e);
}
if (uuid == null) {
transaction.add(op.insert(queue)).build();
/*
- * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2015, 2016 Brocade Communications Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import org.opendaylight.ovsdb.southbound.SouthboundConstants;
import org.opendaylight.ovsdb.southbound.SouthboundMapper;
import org.opendaylight.ovsdb.southbound.SouthboundProvider;
+import org.opendaylight.ovsdb.utils.yang.YangUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.InterfaceTypeBase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbPortInterfaceAttributes.VlanMode;
import org.slf4j.LoggerFactory;
import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.CheckedFuture;
//Configure optional input
if (terminationPoint.getOptions() != null) {
- Map<String, String> optionsMap = new HashMap<>();
- for (Options option : terminationPoint.getOptions()) {
- optionsMap.put(option.getOption(), option.getValue());
- }
try {
- ovsInterface.setOptions(ImmutableMap.copyOf(optionsMap));
+ ovsInterface.setOptions(YangUtils.convertYangKeyValueListToMap(terminationPoint.getOptions(),
+ Options::getOption, Options::getValue));
} catch (NullPointerException e) {
LOG.warn("Incomplete OVSDB interface options", e);
}
List<InterfaceExternalIds> interfaceExternalIds =
terminationPoint.getInterfaceExternalIds();
if (interfaceExternalIds != null && !interfaceExternalIds.isEmpty()) {
- Map<String, String> externalIdsMap = new HashMap<>();
- for (InterfaceExternalIds externalId: interfaceExternalIds) {
- externalIdsMap.put(externalId.getExternalIdKey(), externalId.getExternalIdValue());
- }
try {
- ovsInterface.setExternalIds(ImmutableMap.copyOf(externalIdsMap));
+ ovsInterface.setExternalIds(YangUtils.convertYangKeyValueListToMap(interfaceExternalIds,
+ InterfaceExternalIds::getExternalIdKey, InterfaceExternalIds::getExternalIdValue));
} catch (NullPointerException e) {
LOG.warn("Incomplete OVSDB interface external_ids", e);
}
List<InterfaceLldp> interfaceLldpList =
terminationPoint.getInterfaceLldp();
if (interfaceLldpList != null && !interfaceLldpList.isEmpty()) {
- Map<String, String> interfaceLldpMap = new HashMap<>();
- for (InterfaceLldp interfaceLldp : interfaceLldpList) {
- interfaceLldpMap.put(interfaceLldp.getLldpKey(), interfaceLldp.getLldpValue());
- }
try {
- ovsInterface.setLldp(ImmutableMap.copyOf(interfaceLldpMap));
+ ovsInterface.setLldp(YangUtils.convertYangKeyValueListToMap(interfaceLldpList,
+ InterfaceLldp::getLldpKey, InterfaceLldp::getLldpValue));
} catch (NullPointerException e) {
LOG.warn("Incomplete OVSDB interface lldp", e);
}
List<PortExternalIds> portExternalIds = terminationPoint.getPortExternalIds();
if (portExternalIds != null && !portExternalIds.isEmpty()) {
- Map<String, String> externalIdsMap = new HashMap<>();
- for (PortExternalIds externalId: portExternalIds) {
- externalIdsMap.put(externalId.getExternalIdKey(), externalId.getExternalIdValue());
- }
try {
- port.setExternalIds(ImmutableMap.copyOf(externalIdsMap));
+ port.setExternalIds(YangUtils.convertYangKeyValueListToMap(portExternalIds,
+ PortExternalIds::getExternalIdKey, PortExternalIds::getExternalIdValue));
} catch (NullPointerException e) {
LOG.warn("Incomplete OVSDB port external_ids", e);
}
List<PortOtherConfigs> portOtherConfigs =
terminationPoint.getPortOtherConfigs();
if (portOtherConfigs != null && !portOtherConfigs.isEmpty()) {
- Map<String, String> otherConfigsMap = new HashMap<>();
- for (PortOtherConfigs portOtherConfig : portOtherConfigs) {
- otherConfigsMap.put(portOtherConfig.getOtherConfigKey(),
- portOtherConfig.getOtherConfigValue());
- }
try {
- ovsPort.setOtherConfig(ImmutableMap.copyOf(otherConfigsMap));
+ ovsPort.setOtherConfig(YangUtils.convertYangKeyValueListToMap(portOtherConfigs,
+ PortOtherConfigs::getOtherConfigKey, PortOtherConfigs::getOtherConfigValue));
} catch (NullPointerException e) {
LOG.warn("Incomplete OVSDB port other_config", e);
}
/*
- * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2015, 2016 Brocade Communications Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import org.opendaylight.ovsdb.schema.openvswitch.Interface;
import org.opendaylight.ovsdb.schema.openvswitch.Port;
import org.opendaylight.ovsdb.southbound.SouthboundConstants;
+import org.opendaylight.ovsdb.utils.yang.YangUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbPortInterfaceAttributes.VlanMode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
public class TerminationPointUpdateCommand extends AbstractTransactCommand {
//Configure optional input
if (terminationPoint.getOptions() != null) {
- Map<String, String> optionsMap = new HashMap<>();
- for (Options option : terminationPoint.getOptions()) {
- optionsMap.put(option.getOption(), option.getValue());
- }
try {
- ovsInterface.setOptions(ImmutableMap.copyOf(optionsMap));
+ ovsInterface.setOptions(YangUtils.convertYangKeyValueListToMap(terminationPoint.getOptions(),
+ Options::getOption, Options::getValue));
} catch (NullPointerException e) {
LOG.warn("Incomplete OVSDB interface options", e);
}
List<InterfaceExternalIds> interfaceExternalIds =
terminationPoint.getInterfaceExternalIds();
if (interfaceExternalIds != null && !interfaceExternalIds.isEmpty()) {
- Map<String, String> externalIdsMap = new HashMap<>();
- for (InterfaceExternalIds externalId: interfaceExternalIds) {
- externalIdsMap.put(externalId.getExternalIdKey(), externalId.getExternalIdValue());
- }
try {
- ovsInterface.setExternalIds(ImmutableMap.copyOf(externalIdsMap));
+ ovsInterface.setExternalIds(YangUtils.convertYangKeyValueListToMap(interfaceExternalIds,
+ InterfaceExternalIds::getExternalIdKey, InterfaceExternalIds::getExternalIdValue));
} catch (NullPointerException e) {
LOG.warn("Incomplete OVSDB interface external_ids", e);
}
List<InterfaceLldp> interfaceLldpList =
terminationPoint.getInterfaceLldp();
if (interfaceLldpList != null && !interfaceLldpList.isEmpty()) {
- Map<String, String> interfaceLldpMap = new HashMap<>();
- for (InterfaceLldp interfaceLldp : interfaceLldpList) {
- interfaceLldpMap.put(interfaceLldp.getLldpKey(), interfaceLldp.getLldpValue());
- }
try {
- ovsInterface.setLldp(ImmutableMap.copyOf(interfaceLldpMap));
+ ovsInterface.setLldp(YangUtils.convertYangKeyValueListToMap(interfaceLldpList,
+ InterfaceLldp::getLldpKey, InterfaceLldp::getLldpValue));
} catch (NullPointerException e) {
LOG.warn("Incomplete OVSDB interface lldp", e);
}
List<PortExternalIds> portExternalIds = terminationPoint.getPortExternalIds();
if (portExternalIds != null && !portExternalIds.isEmpty()) {
- Map<String, String> externalIdsMap = new HashMap<>();
- for (PortExternalIds externalId: portExternalIds) {
- externalIdsMap.put(externalId.getExternalIdKey(), externalId.getExternalIdValue());
- }
try {
- port.setExternalIds(ImmutableMap.copyOf(externalIdsMap));
+ port.setExternalIds(YangUtils.convertYangKeyValueListToMap(portExternalIds,
+ PortExternalIds::getExternalIdKey, PortExternalIds::getExternalIdValue));
} catch (NullPointerException e) {
LOG.warn("Incomplete OVSDB port external_ids", e);
}
List<PortOtherConfigs> portOtherConfigs =
terminationPoint.getPortOtherConfigs();
if (portOtherConfigs != null && !portOtherConfigs.isEmpty()) {
- Map<String, String> otherConfigsMap = new HashMap<>();
- for (PortOtherConfigs portOtherConfig : portOtherConfigs) {
- otherConfigsMap.put(portOtherConfig.getOtherConfigKey(),
- portOtherConfig.getOtherConfigValue());
- }
try {
- ovsPort.setOtherConfig(ImmutableMap.copyOf(otherConfigsMap));
+ ovsPort.setOtherConfig(YangUtils.convertYangKeyValueListToMap(portOtherConfigs,
+ PortOtherConfigs::getOtherConfigKey, PortOtherConfigs::getOtherConfigValue));
} catch (NullPointerException e) {
LOG.warn("Incomplete OVSDB port other_config", e);
}
<module>servicehelper</module>
<module>southbound-utils</module>
<module>hwvtepsouthbound-utils</module>
+ <module>yang-utils</module>
</modules>
<!-- DO NOT install or deploy the repo root pom as it's only needed to initiate a build -->
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.opendaylight.odlparent</groupId>
+ <artifactId>bundle-parent</artifactId>
+ <version>1.7.0-SNAPSHOT</version>
+ <relativePath/>
+ </parent>
+
+ <groupId>org.opendaylight.ovsdb</groupId>
+ <artifactId>utils.yang-utils</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>jsr305</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.opendaylight.ovsdb.utils.yang
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
--- /dev/null
+/*
+ * Copyright © 2016 Red Hat, Inc. and others.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.ovsdb.utils.yang;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * YANG utility functions.
+ */
+public final class YangUtils {
+ /**
+ * Prevent instantiation.
+ */
+ private YangUtils() {
+ // Nothing to do
+ }
+
+ /**
+ * Copies a list of YANG key-value items to the given map. Any {@code null} key or value will cause an error.
+ *
+ * @param map The map to fill.
+ * @param yangList The list of YANG key-value items.
+ * @param keyExtractor The key extractor function to use.
+ * @param valueExtractor The value extractor function to use.
+ * @param <T> The YANG item type.
+ * @param <K> The key type.
+ * @param <V> The value type.
+ * @return The map.
+ */
+ @Nonnull
+ public static <T, K, V> Map<K, V> copyYangKeyValueListToMap(@Nonnull Map<K, V> map, @Nullable Iterable<T> yangList,
+ @Nonnull Function<T, K> keyExtractor,
+ @Nonnull Function<T, V> valueExtractor) {
+ if (yangList != null) {
+ for (T yangValue : yangList) {
+ K key = keyExtractor.apply(yangValue);
+ V value = valueExtractor.apply(yangValue);
+ Preconditions.checkNotNull(key);
+ Preconditions.checkNotNull(value);
+ map.put(key, value);
+ }
+ }
+ return map;
+ }
+
+ /**
+ * Converts a list of YANG key-value items to a map.
+ *
+ * @param yangList The list of YANG key-value items.
+ * @param keyExtractor The key extractor function to use.
+ * @param valueExtractor The value extractor function to use.
+ * @param <T> The YANG item type.
+ * @param <K> The key type.
+ * @param <V> The value type.
+ * @return The map.
+ */
+ @Nonnull
+ public static <T, K, V> Map<K, V> convertYangKeyValueListToMap(@Nullable Iterable<T> yangList,
+ @Nonnull Function<T, K> keyExtractor,
+ @Nonnull Function<T, V> valueExtractor) {
+ return copyYangKeyValueListToMap(new HashMap<>(), yangList, keyExtractor, valueExtractor);
+ }
+}