import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
+import java.math.BigInteger;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import com.google.common.collect.ImmutableSet;
import junit.framework.Assert;
import org.junit.After;
@Test
public void testTypedBridgeOperations() throws IOException, InterruptedException, ExecutionException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
- this.monitorBridge();
+ this.monitorTables();
this.createTypedBridge();
this.createTypedController();
+ this.testCreateTypedPortandInterface();
}
private void createTypedBridge() throws IOException, InterruptedException, ExecutionException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Row bridgeRow = tableCache.get(bridge.getSchema().getName()).get(testBridgeUuid);
Bridge monitoredBridge = ovs.getTypedRowWrapper(Bridge.class, bridgeRow);
Assert.assertEquals(monitoredBridge.getNameColumn().getData(), bridge.getNameColumn().getData());
+ Assert.assertNotNull(monitoredBridge.getVersion());
+ Assert.assertNotNull(this.getOpenVSwitchTableUuid());
}
private void createTypedController() throws IOException, InterruptedException, ExecutionException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
.value(controller2.getTargetColumn()))
.add(op.mutate(bridge.getSchema())
.addMutation(bridge.getControllerColumn().getSchema(), Mutator.INSERT,
- Sets.newHashSet(new UUID(transactionUuidStr)))
+ Sets.newHashSet(new UUID(transactionUuidStr)))
.where(bridge.getNameColumn().getSchema().opEqual(testBridgeName))
.build());
Assert.assertEquals(2, monitoredBridge.getControllerColumn().getData().size());
}
+ private void testCreateTypedPortandInterface() throws InterruptedException, ExecutionException{
+ String portUuidStr = "testPort";
+ String intfUuidStr = "testIntf";
+ Port port = ovs.createTypedRowWrapper(Port.class);
+ port.setName("testPort");
+ port.setTag(ImmutableSet.of(BigInteger.ONE));
+ port.setMac(ImmutableSet.of("00:00:00:00:00:01"));
+ port.setInterfaces(ImmutableSet.of(new UUID(intfUuidStr)));
+
+ Interface intf = ovs.createTypedRowWrapper(Interface.class);
+ intf.setName(port.getNameColumn().getData());
+ intf.setExternalIds(ImmutableMap.of("vm-id", "12345abcedf78910"));
+
+ Bridge bridge = ovs.getTypedRowWrapper(Bridge.class, null);
+ TransactionBuilder transactionBuilder = ovs.transactBuilder()
+ .add(op.insert(port.getSchema())
+ .withId(portUuidStr)
+ .value(port.getNameColumn())
+ .value(port.getMacColumn()))
+ .add(op.insert(intf.getSchema())
+ .withId(intfUuidStr)
+ .value(intf.getNameColumn()))
+ .add(op.update(port.getSchema())
+ .set(port.getTagColumn())
+ .set(port.getMacColumn())
+ .set(port.getInterfacesColumn())
+ .where(port.getNameColumn().getSchema().opEqual(port.getName()))
+ .build())
+ .add(op.update(intf.getSchema())
+ .set(intf.getExternalIdsColumn())
+ .where(intf.getNameColumn().getSchema().opEqual(intf.getName()))
+ .build())
+ .add(op.mutate(bridge.getSchema())
+ .addMutation(bridge.getPortsColumn().getSchema(), Mutator.INSERT, Sets.newHashSet(new UUID(portUuidStr)))
+ .where(bridge.getNameColumn().getSchema().opEqual(testBridgeName))
+ .build());
+ ListenableFuture<List<OperationResult>> results = transactionBuilder.execute();
+ List<OperationResult> operationResults = results.get();
+ Assert.assertFalse(operationResults.isEmpty());
+ // Check if Results matches the number of operations in transaction
+ Assert.assertEquals(transactionBuilder.getOperations().size(), operationResults.size());
+ System.out.println("Insert & Mutate operation results for Port and Interface = " + operationResults);
+ }
+
public void testGetDBs() throws ExecutionException, InterruptedException {
ListenableFuture<List<String>> databases = ovs.getDatabases();
List<String> dbNames = databases.get();
Assert.assertTrue(OPEN_VSWITCH_SCHEMA+" schema is not supported by the switch", hasOpenVswitchSchema);
}
- public void monitorBridge() throws ExecutionException, InterruptedException, IOException {
+ private UUID getOpenVSwitchTableUuid() {
+ OpenVSwitch openVSwitch = ovs.getTypedRowWrapper(OpenVSwitch.class, null);
+ Map<UUID, Row> ovsTable = tableCache.get(openVSwitch.getSchema().getName());
+ if (ovsTable != null) {
+ if (ovsTable.keySet().size() >= 1) {
+ return (UUID)ovsTable.keySet().toArray()[0];
+ }
+ }
+ return null;
+ }
+
+ public void monitorTables() throws ExecutionException, InterruptedException, IOException {
Assert.assertNotNull(dbSchema);
- GenericTableSchema bridge = dbSchema.table("Bridge", GenericTableSchema.class);
+ Bridge bridge = ovs.createTypedRowWrapper(Bridge.class);
+ OpenVSwitch openVSwitch = ovs.createTypedRowWrapper(OpenVSwitch.class);
List<MonitorRequest<GenericTableSchema>> monitorRequests = Lists.newArrayList();
- MonitorRequestBuilder<GenericTableSchema> builder = MonitorRequestBuilder.builder(bridge);
- monitorRequests.add(builder.with(new MonitorSelect(true, true, true, true))
- .build());
+ MonitorRequestBuilder<GenericTableSchema> bridgeBuilder = MonitorRequestBuilder.builder(bridge.getSchema());
+ MonitorRequestBuilder<GenericTableSchema> ovsTableBuilder = MonitorRequestBuilder.builder(openVSwitch.getSchema());
+ monitorRequests.add(bridgeBuilder.with(new MonitorSelect(true, true, true, true)).build());
+ monitorRequests.add(ovsTableBuilder.with(new MonitorSelect(true, true, true, true)).build());
MonitorHandle monitor = ovs.monitor(dbSchema, monitorRequests, new UpdateMonitor());
Assert.assertNotNull(monitor);