added support for changing redirector based on API request

This commit is contained in:
DTop
2020-02-07 19:50:45 -05:00
parent cc90de46a0
commit bac9b3c001
3 changed files with 56 additions and 1 deletions

View File

@@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ai.connectus.opensync.ovsdb.ConnectusOvsdbClient;
@@ -21,7 +22,7 @@ public class OpenSyncExperimentController {
@Autowired
ConnectusOvsdbClient connectusOvsdbClient;
@RequestMapping(value = "/connectedClients", method = RequestMethod.GET)
public List<String> getConnectedClients()
{
@@ -30,4 +31,14 @@ public class OpenSyncExperimentController {
return ret;
}
@RequestMapping(value = "/changeRedirectorAddress", method = RequestMethod.POST)
public String changeRedirectorAddress(@RequestParam String apId, @RequestParam String newRedirectorAddress)
{
LOG.info("Changing redirector address for AP {} to {}", apId, newRedirectorAddress);
String ret = connectusOvsdbClient.changeRedirectorAddress(apId, newRedirectorAddress);
LOG.info("Changed redirector address for AP {} to {}", apId, ret);
return ret;
}
}

View File

@@ -161,4 +161,20 @@ public class ConnectusOvsdbClient {
return new HashSet<>(connectedClients.keySet());
}
/**
* @param apId
* @param newRedirectorAddress
* @return updated value of the redirector
*/
public String changeRedirectorAddress(String apId, String newRedirectorAddress) {
OvsdbClient ovsdbClient = connectedClients.get(apId);
if(ovsdbClient == null) {
throw new IllegalStateException("AP with id " + apId + " is not connected") ;
}
String ret = ovsdbDao.changeRedirectorAddress(ovsdbClient, apId, newRedirectorAddress);
return ret;
}
}

View File

@@ -1399,4 +1399,32 @@ public class OvsdbDao {
throw new RuntimeException(e);
}
}
public String changeRedirectorAddress(OvsdbClient ovsdbClient, String apId, String newRedirectorAddress) {
try {
List<Operation> operations = new ArrayList<>();
Map<String, Value> updateColumns = new HashMap<>();
updateColumns.put("redirector_addr", new Atom<>(newRedirectorAddress));
Row row = new Row(updateColumns );
operations.add(new Update(awlanNodeDbTable, row ));
CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations);
OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
if(LOG.isDebugEnabled()) {
LOG.debug("Updated {} redirector_addr = {}", awlanNodeDbTable, newRedirectorAddress);
for(OperationResult res : result) {
LOG.debug("Op Result {}", res);
}
}
} catch(OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) {
throw new RuntimeException(e);
}
return newRedirectorAddress;
}
}