/*
- * 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;
private TransactionInvoker txInvoker;
private Map<DatabaseSchema,TransactInvoker> transactInvokers;
private MonitorCallBack callback;
- // private ConnectionInfo key;
private InstanceIdentifier<Node> instanceIdentifier;
private volatile boolean hasDeviceOwnership = false;
private Entity connectedEntity;
}
try {
- List<String> databases = getDatabases().get();
- this.callback = new OvsdbMonitorCallback(this,txInvoker);
- for (String database : databases) {
- DatabaseSchema dbSchema = getSchema(database).get();
- if (dbSchema != null) {
- monitorAllTables(database, dbSchema);
- } else {
- LOG.warn("No schema reported for database {} for key {}",database,connectionInfo);
- }
+ String database = SouthboundConstants.OPEN_V_SWITCH;
+ DatabaseSchema dbSchema = getSchema(database).get();
+ if (dbSchema != null) {
+ LOG.info("Monitoring database: {}", database);
+ callback = new OvsdbMonitorCallback(this, txInvoker);
+ monitorAllTables(database, dbSchema);
+ } else {
+ LOG.info("No database {} found on {}", database, connectionInfo);
}
} catch (InterruptedException | ExecutionException e) {
- LOG.warn("Exception attempting to registerCallbacks {}: {}",connectionInfo,e);
+ LOG.warn("Exception attempting to registerCallbacks {}: ", connectionInfo, e);
}
}
}
public void createTransactInvokers() {
if (transactInvokers == null) {
try {
- transactInvokers = new HashMap<DatabaseSchema,TransactInvoker>();
+ transactInvokers = new HashMap<>();
List<String> databases = getDatabases().get();
for (String database : databases) {
DatabaseSchema dbSchema = getSchema(database).get();
}
}
} catch (InterruptedException | ExecutionException e) {
- LOG.warn("Exception attempting to createTransactionInvokers {}: {}",connectionInfo,e);
+ LOG.warn("Exception attempting to createTransactionInvokers {}", connectionInfo, e);
}
}
}
private void monitorAllTables(String database, DatabaseSchema dbSchema) {
Set<String> tables = dbSchema.getTables();
if (tables != null) {
- List<MonitorRequest<GenericTableSchema>> monitorRequests = Lists.newArrayList();
+ List<MonitorRequest> monitorRequests = Lists.newArrayList();
for (String tableName : tables) {
+ LOG.info("Southbound monitoring table {} in {}", tableName, dbSchema.getName());
GenericTableSchema tableSchema = dbSchema.table(tableName, GenericTableSchema.class);
Set<String> columns = tableSchema.getColumns();
MonitorRequestBuilder<GenericTableSchema> monitorBuilder = MonitorRequestBuilder.builder(tableSchema);
// OpenVSwitchPart
OpenVSwitch ovs = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), OpenVSwitch.class);
- Map<String, String> externalIdsMap = new HashMap<String, String>();
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,
ovs.getExternalIdsColumn().getData());
transaction.add(mutate);
} catch (NullPointerException e) {
- LOG.warn("Incomplete OVSDB Node external IDs");
+ LOG.warn("Incomplete OVSDB Node external IDs", e);
}
List<OpenvswitchOtherConfigs> otherConfigs = this.initialCreateData.getOpenvswitchOtherConfigs();
if (otherConfigs != null) {
- Map<String, String> otherConfigsMap = new HashMap<String, String>();
- 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()));
}
public <E extends TableSchema<E>> TableUpdates monitor(
- DatabaseSchema schema, List<MonitorRequest<E>> monitorRequests,
+ DatabaseSchema schema, List<MonitorRequest> monitorRequests,
MonitorCallBack callback) {
return client.monitor(schema, monitorRequests, callback);
}
@Override
public <E extends TableSchema<E>> TableUpdates monitor(
- DatabaseSchema schema, List<MonitorRequest<E>> monitorRequests,
+ DatabaseSchema schema, List<MonitorRequest> monitorRequests,
MonitorHandle monitorHandle, MonitorCallBack callback) {
return null;
}
}
public Boolean getHasDeviceOwnership() {
- return Boolean.valueOf(hasDeviceOwnership);
+ return hasDeviceOwnership;
}
public void setHasDeviceOwnership(Boolean hasDeviceOwnership) {
if (hasDeviceOwnership != null) {
- this.hasDeviceOwnership = hasDeviceOwnership.booleanValue();
+ this.hasDeviceOwnership = hasDeviceOwnership;
}
}