1 package org.objectweb.petals.tools.petalsadmin.bean; 2 3 import java.util.ArrayList ; 4 import java.util.Date ; 5 import java.util.HashMap ; 6 import java.util.List ; 7 import java.util.ListIterator ; 8 import java.util.Map ; 9 import java.util.Random ; 10 11 import org.objectweb.petals.tools.petalsadmin.utils.JBIEntity; 12 import org.objectweb.petals.tools.petalsadmin.utils.JMXUtils; 13 14 public class MonitorBean { 15 16 private String serverHost; 17 private String jmxPort; 18 private String jmxUser; 19 private String jmxPasswd; 20 21 public MonitorBean() { 22 } 23 24 public List <List <Map <String ,Object >>> bulkData(Map <String , String > serverConf, long sinceTime) 25 throws Exception 26 { 27 try { 28 JMXUtils utilsJmx = new JMXUtils(serverHost,jmxPort,jmxUser,jmxPasswd); 29 return utilsJmx.bulkData(serverConf,sinceTime); 30 } 31 catch (Exception e) { 32 throw new Exception (e); 33 } 34 } 35 36 40 public List <List <Map <String ,Object >>> getExchanges(Map <String , String > serverConf, long sinceTime, String component) 41 throws Exception 42 { 43 List <List <Map <String , Object >>> bulkDatas; 45 try { 46 bulkDatas = this.bulkData(serverConf, sinceTime); 47 List <List <Map <String ,Object >>> componentExchanges = new ArrayList <List <Map <String ,Object >>>(); 49 50 ListIterator <List <Map <String ,Object >>> parcExchanges = bulkDatas.listIterator(); 52 while(parcExchanges.hasNext()) 53 { 54 boolean concernComponent=false; 56 List <Map <String ,Object >> currentExchange = parcExchanges.next(); 58 ListIterator <Map <String ,Object >> parcCaptures = currentExchange.listIterator(); 60 while (parcCaptures.hasNext()) 61 { 62 Map <String ,Object > capture = parcCaptures.next(); 64 if (capture.get("component").equals(component) && !concernComponent) 65 { 66 concernComponent=true; 69 } 70 } 71 if (concernComponent) 74 { 75 componentExchanges.add(currentExchange); 76 } 77 } 78 return componentExchanges; 79 } catch (Exception e) { 80 throw new Exception (e); 81 } 82 83 } 84 85 public List <Map <String , String >> getStartedServers() throws Exception 86 { 87 try { 88 JMXUtils utilsJmx = new JMXUtils(serverHost,jmxPort,jmxUser,jmxPasswd); 89 return utilsJmx.getStartedServers(); 90 } 91 catch (Exception e) { 92 throw new Exception (e); 93 } 94 } 95 96 public List <Map <String , String >> getAllServers() throws Exception 97 { 98 try { 99 JMXUtils utilsJmx = new JMXUtils(serverHost,jmxPort,jmxUser,jmxPasswd); 100 return utilsJmx.getAllServers(); 101 } 102 catch (Exception e) { 103 throw new Exception (e); 104 } 105 } 106 107 public Map <String , JBIEntity> listComponents(String phost, String pport, String pusername, String ppassword) 108 throws Exception { 109 try { 110 JMXUtils utilsJmx = new JMXUtils(phost,pport,pusername,ppassword); 111 return utilsJmx.listComponents(phost, pport, pusername, ppassword); 112 } 113 catch (Exception e) { 114 throw new Exception (e); 115 } 116 } 117 118 public boolean monitor(String phost, String pport, String pusername, String ppassword, String action) 119 throws Exception { 120 try { 121 JMXUtils utilsJmx = new JMXUtils(phost,pport,pusername,ppassword); 122 boolean boolAction; 123 if (action.equals("start")) 124 boolAction=true; 125 else 126 boolAction=false; 127 return utilsJmx.monitor(phost,pport,pusername,ppassword,boolAction); 128 } 129 catch (Exception e) { 130 throw new Exception (e); 131 } 132 } 133 134 public boolean monitorAllServers(List <Map <String , String >> startedServers, String action) 135 throws Exception { 136 try { 137 JMXUtils utilsJmx = new JMXUtils(serverHost,jmxPort,jmxUser,jmxPasswd); 138 boolean boolAction; 139 boolean result=true; 140 if (action.equals("start")) 141 boolAction=true; 142 else 143 boolAction=false; 144 if (startedServers!=null && startedServers.size()>0) 145 { 146 ListIterator <Map <String , String >> parcServers = startedServers.listIterator(); 147 while (parcServers.hasNext()) 148 { 149 Map <String , String > currentServer = parcServers.next(); 150 String serverHost = currentServer.get("host"); 151 String serverPort = currentServer.get("jmxPort"); 152 String serverLogin = currentServer.get("jmxLogin"); 153 String serverPasswd = currentServer.get("jmxPassword"); 154 utilsJmx.monitor(serverHost,serverPort,serverLogin,serverPasswd,boolAction); 155 } 156 } 157 return result; 158 } 159 catch (Exception e) { 160 return false; 161 } 162 } 163 164 public String getAttribute(Map <String , String > serverConf, String attributeName) 165 throws Exception { 166 try { 167 String serverHost = serverConf.get("host"); 168 String serverPort = serverConf.get("jmxPort"); 169 String serverLogin = serverConf.get("jmxLogin"); 170 String serverPasswd = serverConf.get("jmxPassword"); 171 JMXUtils utilsJmx = new JMXUtils(serverHost,serverPort,serverLogin,serverPasswd); 172 return utilsJmx.getAttribute(serverHost,serverPort,serverLogin,serverPasswd,attributeName); 173 } 174 catch (Exception e) { 175 throw new Exception (e); 176 } 177 } 178 179 180 181 182 183 184 191 public List <Map.Entry <String , List <Map <String ,Object >>>> oldbulkData(long sinceTime) 192 { 193 List <Map.Entry <String , List <Map <String ,Object >>>> list_exchanges = new ArrayList <Map.Entry <String , List <Map <String ,Object >>>>(); 194 Random rd = new Random (); 195 196 ArrayList <String > compo_list = this.getComponents("all"); 198 199 for (int i=1;i<=rd.nextInt(50);i++) 201 { 202 Map <String , List <Map <String ,Object >>> exchange = new HashMap <String , List <Map <String ,Object >>>(); 203 204 String id = new String ("ex_"+Math.abs(rd.nextLong())); 206 List <Map <String ,Object >> captureList = new ArrayList <Map <String ,Object >>(); 208 Map <String ,Object > capture = new HashMap <String ,Object >(); 210 for (int j=1;j<=4;j++) 212 { 213 capture = new HashMap <String ,Object >(); 214 215 Long t1 = new Date ().getTime(); 216 217 String component = new String (compo_list.get(rd.nextInt(compo_list.size()))); 219 220 String [] roles_list = new String [2]; 222 roles_list[0]="consumer"; 223 roles_list[1]="provider"; 224 String role = roles_list[rd.nextInt(2)]; 225 226 String [] types_list = new String [4]; 228 types_list[0]="in"; 229 types_list[1]="out"; 230 types_list[2]="fault"; 231 types_list[3]="ANY"; 232 String type=types_list[rd.nextInt(4)]; 233 234 String [] status_list= new String [3]; 236 status_list[0]="active"; 237 status_list[1]="done"; 238 status_list[2]="error"; 239 String status=status_list[rd.nextInt(3)]; 240 241 capture.put("time", t1); 243 capture.put("component",component); 244 capture.put("role",role); 245 capture.put("type", type); 246 capture.put("status", status); 247 248 captureList.add(capture); 250 } 251 252 exchange.put(id, captureList); 254 255 list_exchanges.add(exchange.entrySet().iterator().next()); 257 } 258 return list_exchanges; 259 } 260 261 266 public ArrayList <String > getComponents(String group) { 267 ArrayList <String > components = new ArrayList <String >(); 268 if (group=="BC") 269 { 270 components.add("FileTransfer"); 271 components.add("JMS"); 272 components.add("XQuare"); 273 } 274 else 275 { 276 if (group=="SE") 277 { 278 components.add("Clock"); 279 components.add("CSV"); 280 components.add("HelloWorld"); 281 components.add("SampleClient"); 282 components.add("XSLT"); 283 } 284 else 285 { 286 if (group=="all") 287 { 288 components.add("FileTransfer"); 289 components.add("JMS"); 290 components.add("XQuare"); 291 components.add("Clock"); 292 components.add("CSV"); 293 components.add("HelloWorld"); 294 components.add("SampleClient"); 295 components.add("XSLT"); 296 } 297 else 298 { 299 components.add("none"); 300 } 301 } 302 } 303 return components; 304 } 305 306 public String getJmxPasswd() { 307 return jmxPasswd; 308 } 309 310 public void setJmxPasswd(String jmxPasswd) { 311 this.jmxPasswd = jmxPasswd; 312 } 313 314 public String getJmxPort() { 315 return jmxPort; 316 } 317 318 public void setJmxPort(String jmxPort) { 319 this.jmxPort = jmxPort; 320 } 321 322 public String getJmxUser() { 323 return jmxUser; 324 } 325 326 public void setJmxUser(String jmxUser) { 327 this.jmxUser = jmxUser; 328 } 329 330 public String getServerHost() { 331 return serverHost; 332 } 333 334 public void setServerHost(String serverHost) { 335 this.serverHost = serverHost; 336 } 337 338 } 339 | Popular Tags |