import org.opendaylight.controller.cluster.example.messages.PrintRole;
import org.opendaylight.controller.cluster.example.messages.PrintState;
import org.opendaylight.controller.cluster.raft.ConfigParams;
-import org.opendaylight.controller.cluster.raft.client.messages.AddRaftPeer;
-import org.opendaylight.controller.cluster.raft.client.messages.RemoveRaftPeer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
* Commands
* bye
* createNodes:{num}
- * addNodes:{num}
* stopNode:{nodeName}
* reinstateNode:{nodeName}
* addClients:{num}
int n = Integer.parseInt(arr[1]);
td.createNodes(n);
- } else if (command.startsWith("addNodes")) {
- String[] arr = command.split(":");
- int n = Integer.parseInt(arr[1]);
- td.addNodes(n);
-
} else if (command.startsWith("addClients")) {
String[] arr = command.split(":");
int n = Integer.parseInt(arr[1]);
}
}
- // add new nodes , pass in the count
- public void addNodes(int num) {
- Map<String, String> newPeers = new HashMap<>();
- for (int i=0; i < num; i++) {
- nameCounter = nameCounter + 1;
- newPeers.put("example-"+nameCounter, "akka://default/user/example-"+nameCounter);
- allPeers.put("example-"+nameCounter, "akka://default/user/example-"+nameCounter);
-
- }
- Map<String, ActorRef> newActorRefs = new HashMap<String, ActorRef>(num);
- for (Map.Entry<String, String> entry : newPeers.entrySet()) {
- ActorRef exampleActor = createExampleActor(entry.getKey());
- newActorRefs.put(entry.getKey(), exampleActor);
-
- //now also add these new nodes as peers from the previous nodes
- for (ActorRef actor : actorRefs.values()) {
- actor.tell(new AddRaftPeer(entry.getKey(), entry.getValue()), null);
- }
-
- System.out.println("Added node:" + entry);
- }
-
- actorRefs.putAll(newActorRefs);
- }
-
-
// add num clients to all nodes in the system
public void addClients(int num) {
for(Map.Entry<String,ActorRef> actorRefEntry : actorRefs.entrySet()) {
actorSystem.stop(actorRef);
actorRefs.remove(actorName);
-
- for (ActorRef actor : actorRefs.values()) {
- actor.tell(new RemoveRaftPeer(actorName), null);
- }
-
allPeers.remove(actorName);
}
allPeers.put(actorName, address);
ActorRef exampleActor = createExampleActor(actorName);
-
- for (ActorRef actor : actorRefs.values()) {
- actor.tell(new AddRaftPeer(actorName, address), null);
- }
-
actorRefs.put(actorName, exampleActor);
addClientsToNode(actorName, 1);