mirror of
https://github.com/Telecominfraproject/wlan-cloud-opensync-controller.git
synced 2025-11-01 19:17:52 +00:00
added support for changing redirector based on API request
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user