Refactored the wipe-out command code a bit.
Change-Id: I25624be97225f6ea3208d675efd7355319c7c738
Showing
1 changed file
with
34 additions
and
21 deletions
... | @@ -47,6 +47,38 @@ public class WipeOutCommand extends ClustersListCommand { | ... | @@ -47,6 +47,38 @@ public class WipeOutCommand extends ClustersListCommand { |
47 | return; | 47 | return; |
48 | } | 48 | } |
49 | 49 | ||
50 | + wipeOutIntents(); | ||
51 | + wipeOutHosts(); | ||
52 | + wipeOutDevices(); | ||
53 | + wipeOutLinks(); | ||
54 | + } | ||
55 | + | ||
56 | + private void wipeOutIntents() { | ||
57 | + print("Wiping intents"); | ||
58 | + IntentService intentService = get(IntentService.class); | ||
59 | + for (Intent intent : intentService.getIntents()) { | ||
60 | + if (intentService.getIntentState(intent.key()) != IntentState.WITHDRAWN) { | ||
61 | + intentService.withdraw(intent); | ||
62 | + } | ||
63 | + intentService.purge(intent); | ||
64 | + } | ||
65 | + } | ||
66 | + | ||
67 | + private void wipeOutHosts() { | ||
68 | + print("Wiping hosts"); | ||
69 | + HostAdminService hostAdminService = get(HostAdminService.class); | ||
70 | + while (hostAdminService.getHostCount() > 0) { | ||
71 | + try { | ||
72 | + for (Host host : hostAdminService.getHosts()) { | ||
73 | + hostAdminService.removeHost(host.id()); | ||
74 | + } | ||
75 | + } catch (Exception e) { | ||
76 | + log.warn("Unable to wipe-out hosts", e); | ||
77 | + } | ||
78 | + } | ||
79 | + } | ||
80 | + | ||
81 | + private void wipeOutDevices() { | ||
50 | print("Wiping devices"); | 82 | print("Wiping devices"); |
51 | DeviceAdminService deviceAdminService = get(DeviceAdminService.class); | 83 | DeviceAdminService deviceAdminService = get(DeviceAdminService.class); |
52 | while (deviceAdminService.getDeviceCount() > 0) { | 84 | while (deviceAdminService.getDeviceCount() > 0) { |
... | @@ -58,7 +90,9 @@ public class WipeOutCommand extends ClustersListCommand { | ... | @@ -58,7 +90,9 @@ public class WipeOutCommand extends ClustersListCommand { |
58 | log.warn("Unable to wipe-out devices", e); | 90 | log.warn("Unable to wipe-out devices", e); |
59 | } | 91 | } |
60 | } | 92 | } |
93 | + } | ||
61 | 94 | ||
95 | + private void wipeOutLinks() { | ||
62 | print("Wiping links"); | 96 | print("Wiping links"); |
63 | LinkAdminService linkAdminService = get(LinkAdminService.class); | 97 | LinkAdminService linkAdminService = get(LinkAdminService.class); |
64 | while (linkAdminService.getLinkCount() > 0) { | 98 | while (linkAdminService.getLinkCount() > 0) { |
... | @@ -71,26 +105,5 @@ public class WipeOutCommand extends ClustersListCommand { | ... | @@ -71,26 +105,5 @@ public class WipeOutCommand extends ClustersListCommand { |
71 | log.warn("Unable to wipe-out links", e); | 105 | log.warn("Unable to wipe-out links", e); |
72 | } | 106 | } |
73 | } | 107 | } |
74 | - | ||
75 | - print("Wiping hosts"); | ||
76 | - HostAdminService hostAdminService = get(HostAdminService.class); | ||
77 | - while (hostAdminService.getHostCount() > 0) { | ||
78 | - try { | ||
79 | - for (Host host : hostAdminService.getHosts()) { | ||
80 | - hostAdminService.removeHost(host.id()); | ||
81 | - } | ||
82 | - } catch (Exception e) { | ||
83 | - log.warn("Unable to wipe-out hosts", e); | ||
84 | - } | ||
85 | - } | ||
86 | - | ||
87 | - print("Wiping intents"); | ||
88 | - IntentService intentService = get(IntentService.class); | ||
89 | - for (Intent intent : intentService.getIntents()) { | ||
90 | - if (intentService.getIntentState(intent.key()) != IntentState.WITHDRAWN) { | ||
91 | - intentService.withdraw(intent); | ||
92 | - } | ||
93 | - intentService.purge(intent); | ||
94 | - } | ||
95 | } | 108 | } |
96 | } | 109 | } | ... | ... |
-
Please register or login to post a comment