1
2
3
4
5
6 package gov.bnl.gums.admin;
7
8 import org.apache.commons.cli.*;
9
10
11
12
13
14 public class Pool_AddRange extends RemoteCommand {
15 static {
16 command = new Pool_AddRange();
17 }
18
19
20
21
22 public Pool_AddRange() {
23 syntax = "PERSISTANCE GROUP RANGE";
24 description = "Adds range of accounts to a pool. " +
25 "PERSISTANCE is the 'persistenceFactory' as defined in the configuration for the group. " +
26 "GROUP is the 'name' as defined in the configuration for the pool. " +
27 "RANGE is the group of accounts to be added (i.e. grid0050-125)." +
28 "NOTE: This command is depricated in favor of PoolAddRange; required with 1.1 server";
29 }
30
31 protected org.apache.commons.cli.Options buildOptions() {
32 Options options = new Options();
33
34 return options;
35 }
36
37 protected void execute(org.apache.commons.cli.CommandLine cmd)
38 throws Exception {
39 if (cmd.getArgs().length < 3) {
40 failForWrongParameters("Missing parameters...");
41 }
42
43 String[] userDN = (cmd.getArgs());
44 String persistenceFactory = cmd.getArgs()[0];
45 String groupName = cmd.getArgs()[1];
46
47 for (int nArg = 2; nArg < cmd.getArgs().length; nArg++) {
48 addRange(persistenceFactory, groupName,
49 cmd.getArgs()[nArg]);
50 }
51 }
52
53 private void addRange(String persistenceFactory, String groupName, String range) throws Exception {
54 String firstAccount = range.substring(0, range.indexOf('-'));
55 String lastAccountN = range.substring(range.indexOf('-') + 1);
56 String firstAccountN = firstAccount.substring(firstAccount.length() - lastAccountN.length());
57 String accountBase = firstAccount.substring(0, firstAccount.length() - lastAccountN.length());
58 int nFirstAccount = Integer.parseInt(firstAccountN);
59 int nLastAccount = Integer.parseInt(lastAccountN);
60
61 StringBuffer last = new StringBuffer(firstAccount);
62 String nLastAccountString = Integer.toString(nLastAccount);
63 last.replace(firstAccount.length() - nLastAccountString.length(), firstAccount.length(), nLastAccountString);
64
65 System.out.println("Adding accounts between '" + firstAccount + "' and '" + last.toString() + "' to pool '" + groupName + "'");
66
67 StringBuffer buf = new StringBuffer(firstAccount);
68 int len = firstAccount.length();
69 for (int account = nFirstAccount; account <= nLastAccount; account++) {
70 String nAccount = Integer.toString(account);
71 buf.replace(len - nAccount.length(), len, nAccount);
72 getGums().poolAddAccount(persistenceFactory, groupName, buf.toString());
73 System.out.println(buf.toString() + " added");
74 }
75 }
76 }