Thomas Vachuska

Refactored the wipe-out command code a bit.

Change-Id: I25624be97225f6ea3208d675efd7355319c7c738
......@@ -47,6 +47,38 @@ public class WipeOutCommand extends ClustersListCommand {
return;
}
wipeOutIntents();
wipeOutHosts();
wipeOutDevices();
wipeOutLinks();
}
private void wipeOutIntents() {
print("Wiping intents");
IntentService intentService = get(IntentService.class);
for (Intent intent : intentService.getIntents()) {
if (intentService.getIntentState(intent.key()) != IntentState.WITHDRAWN) {
intentService.withdraw(intent);
}
intentService.purge(intent);
}
}
private void wipeOutHosts() {
print("Wiping hosts");
HostAdminService hostAdminService = get(HostAdminService.class);
while (hostAdminService.getHostCount() > 0) {
try {
for (Host host : hostAdminService.getHosts()) {
hostAdminService.removeHost(host.id());
}
} catch (Exception e) {
log.warn("Unable to wipe-out hosts", e);
}
}
}
private void wipeOutDevices() {
print("Wiping devices");
DeviceAdminService deviceAdminService = get(DeviceAdminService.class);
while (deviceAdminService.getDeviceCount() > 0) {
......@@ -58,7 +90,9 @@ public class WipeOutCommand extends ClustersListCommand {
log.warn("Unable to wipe-out devices", e);
}
}
}
private void wipeOutLinks() {
print("Wiping links");
LinkAdminService linkAdminService = get(LinkAdminService.class);
while (linkAdminService.getLinkCount() > 0) {
......@@ -71,26 +105,5 @@ public class WipeOutCommand extends ClustersListCommand {
log.warn("Unable to wipe-out links", e);
}
}
print("Wiping hosts");
HostAdminService hostAdminService = get(HostAdminService.class);
while (hostAdminService.getHostCount() > 0) {
try {
for (Host host : hostAdminService.getHosts()) {
hostAdminService.removeHost(host.id());
}
} catch (Exception e) {
log.warn("Unable to wipe-out hosts", e);
}
}
print("Wiping intents");
IntentService intentService = get(IntentService.class);
for (Intent intent : intentService.getIntents()) {
if (intentService.getIntentState(intent.key()) != IntentState.WITHDRAWN) {
intentService.withdraw(intent);
}
intentService.purge(intent);
}
}
}
......