1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package jgroup.upgrade;
20
21 import java.rmi.RemoteException;
22
23 import jgroup.core.arm.ReplicationManager;
24 import jgroup.core.registry.DependableRegistry;
25 import jgroup.core.registry.RegistryFactory;
26 import jgroup.relacs.config.AppConfig;
27 import jgroup.util.Abort;
28
29
30
31
32
33
34
35 public class UpgradeManagementClient {
36
37 public static void main(String argv[]) throws Exception {
38
39
40 boolean create_cmd = true;
41 boolean remove_cmd = true;
42 boolean wait_cmd = true;
43 boolean test_cmd = false;
44 boolean upgrade_cmd = false;
45 boolean list_cmd = false;
46 String cmd = "uwc";
47 if (argv.length > 0 && argv[0] != null)
48 cmd = argv[0];
49 System.out.println("Got the following params: " + cmd);
50
51 if (cmd.indexOf('c') >= 0)
52 create_cmd = true;
53 else
54 create_cmd = false;
55 if (cmd.indexOf('r') >= 0)
56 remove_cmd = true;
57 else
58 remove_cmd = false;
59 if (cmd.indexOf('w') >= 0)
60 wait_cmd = true;
61 else
62 wait_cmd = false;
63 if (cmd.indexOf('t') >= 0)
64 test_cmd = true;
65 else
66 test_cmd = false;
67 if (cmd.indexOf('u') >= 0)
68 upgrade_cmd = true;
69 else
70 upgrade_cmd = false;
71 if (cmd.indexOf('l') >= 0)
72 list_cmd = true;
73 else
74 list_cmd = false;
75
76
77
78
79
80 DependableRegistry dregistry = RegistryFactory.getRegistry();
81
82
83
84
85
86
87 ReplicationManager replicaManager =
88 (ReplicationManager) dregistry.lookup("Jgroup/ReplicationManager");
89 System.out.println("Successful lookup: ReplicationManager");
90
91 AppConfig app = null;
92
93
94 if (create_cmd) {
95 try {
96 System.out.println("Creating group: " + app);
97 replicaManager.createGroup(app);
98 } catch (Exception exception) {
99 throw new Abort("Failed to create the upgrade server group", exception);
100 }
101 System.out.println(
102 "The group with upgradable servers is successfully created!");
103 }
104
105 if (remove_cmd) {
106 try {
107 System.out.println("Removing group: " + app);
108 replicaManager.removeGroup(app);
109 } catch (Exception exception) {
110 throw new Abort("Failed to remove the upgrade server group", exception);
111 }
112 System.out.println(
113 "The group with upgradable servers is successfully removed!");
114
115 }
116
117
118 if (wait_cmd) {
119 System.out.println("Watining 30 sec to send an upgrade request");
120
121
122 try {
123 Thread.sleep(30000);
124 } catch (InterruptedException ex) {
125 }
126 }
127
128 if (list_cmd) {
129 try {
130 DependableRegistry reg = RegistryFactory.getRegistry();
131 String objs[] = reg.list();
132 System.out.println("The following entries in DRegistry:");
133 for(int i=0; i< objs.length; i++)
134 System.out.println("[" +i+ "]: " + objs[i]);
135 System.out.println("=============");
136 } catch (RemoteException ex) {
137 throw new Abort("Am upgrade server test failed ", ex);
138 }
139 }
140
141
142 if (test_cmd) {
143 try {
144 System.out.println("Trying to getthe Registry ");
145 DependableRegistry reg = RegistryFactory.getRegistry();
146 System.out.println("Trying to lookup UpgradeServer");
147
148
149
150
151
152
153
154
155
156 } catch (RemoteException ex) {
157 throw new Abort("Am upgrade server test failed ", ex);
158 }
159 }
160
161
162 if (upgrade_cmd) {
163
164 UpgradeManager upgrManager =
165 (UpgradeManager) dregistry.lookup("Jgroup/UpgradeManager");
166
167 long start = 0;
168 long utp = 0;
169 try {
170 System.out.println("Upgrading group: " + app);
171 start = System.currentTimeMillis();
172 upgrManager.upgradeGroup(app);
173 utp = System.currentTimeMillis() - start;
174 System.out.println("Server upgraded, UTP = " + utp);
175 } catch (Exception exception) {
176 utp = System.currentTimeMillis() - start;
177 System.out.println("Server upgrade FAILED, exception thrown after time = " + utp);
178 throw new Abort("Failed to create upgrserver", exception);
179 }
180 }
181 }
182
183 }