1 package org.enhydra.shark.test; 2 3 import java.util.*; 4 5 import org.enhydra.shark.Shark; 6 import org.enhydra.shark.api.RootException; 7 import org.enhydra.shark.api.client.wfbase.BaseException; 8 import org.enhydra.shark.api.client.wfmodel.*; 9 import org.enhydra.shark.api.client.wfservice.*; 10 import org.enhydra.shark.api.common.SharkConstants; 11 import org.enhydra.shark.transaction.SharkDODSTransaction; 12 13 public class ManualTest extends Thread { 14 16 private static long startT; 17 private static long endT; 18 private static AdminMisc am; 19 private WfResource res; 20 private int actCompleted; 21 22 public ManualTest() throws BaseException, ConnectFailed, NotConnected { 23 SharkConnection sc=Shark.getInstance().getSharkConnection(); 24 sc.connect(username,pwd,"",""); 25 res=sc.getResourceObject(); 26 27 this.actCompleted = 0; 28 synchronized(pwd) { 29 ++counter; 30 } 31 start(); 32 } 33 private String m1 = "Assignment is not valid anymore"; 34 private String m2 = "activity state is closed"; 35 private String m3 = "Can't change to state "; 36 public void run () { 37 for (WfAssignment[] ass=null;true;) { 38 try { 39 ass=res.get_sequence_work_item(0); 40 } catch(BaseException e) { 41 e.printStackTrace(); 42 continue; 43 } 44 if (ass!=null && ass.length>0) { 45 for (int i=0; i<ass.length; i++) { 46 String asss=ass[i].toString(); 47 try { 48 WfProcess _prc_ = ass[i].activity().container(); 50 WfActivity [] acts = 51 _prc_.get_activities_in_state(SharkConstants.STATE_OPEN_RUNNING) 52 .get_next_n_sequence(0); 53 if (acts.length < 1) { 54 System.err.println(":::NONE"); 55 } else { 56 for (int k = 0; k < acts.length; k++) { 57 WfActivity _aha_ = acts[k]; 58 System.err.println 59 (":::"+ am.getActivityResourceUsername 60 (_prc_.key(), _aha_.key())); 61 } 62 } 63 if (!ass[i].get_accepted_status()) { 64 System.err.println("Thread "+this+" - Accepting ass "+asss+", active threads="+Thread.activeCount()); 65 ass[i].set_accepted_status(true); 66 } 67 System.err.println("Thread "+this+" - Completing ass "+asss+", active threads="+Thread.activeCount()); 69 ass[i].activity().complete(); 70 ++actCompleted; 71 System.err.println("Thread "+this+" - Ass "+asss+" completed, active threads="+Thread.activeCount()); 72 } catch (Exception ex) { 73 if ((ex instanceof RootException) 74 && (m1.equals(ex.getMessage()) 75 || m2.equals(ex.getMessage()) 76 || (ex.getMessage()!=null && ex.getMessage().startsWith(m3)))) { 77 System.err.println("failed: yet ignoring " 78 + ex.getMessage()); 79 continue; 80 } 81 ex.printStackTrace(); 82 System.err.println("Thread "+this+" - Problems while executing ass "+asss+", active threads="+Thread.activeCount()+" errMsg="+ex.getMessage()); 83 } 84 } 85 } else { 86 break; 87 } 88 } 89 System.err.print("There are " 91 + Thread.activeCount() 92 +" active threads; this one completed " 93 + actCompleted 94 +" activities "); 95 synchronized(pwd) { 96 --counter; 97 if (0 == counter) { 98 endT=System.currentTimeMillis(); 99 SharkDODSTransaction.info(); 101 try { 106 ExecutionAdministration ea=Shark.getInstance().getAdminInterface().getExecutionAdministration(); 107 ea.connect(username,pwd,"",""); 108 WfProcessMgr mgr=ea.getProcessMgr(pkgId,pDefId); 109 WfProcess[] procs=mgr.get_sequence_process(0); 110 for (int i=0; i<procs.length; i++) { 111 System.out.println("Process "+procs[i]+" state is "+procs[i].state()+", last state time="+new Date(procs[i].last_state_time().getTime())); 112 } 113 } catch (Exception ex){} 115 System.out.println("The exec. lasted "+(endT-startT)+" ms"); System.exit(0); 117 } 118 } 119 } 120 121 static String username="admin"; 122 static String pwd="enhydra"; 123 124 static int counter = 0; 125 126 static String pkgId; 127 static String pDefId; 128 public static void main (String [] args) throws Exception { 129 if (args==null || args.length<3) { 130 printUsage(); 131 return; 132 } 133 String confFilePath=args[0]; 134 String xpdlName=args[1]; 135 String pDefId=args[2]; 136 int hmThreads=1; 137 if (args.length>3) { 138 hmThreads=Integer.parseInt(args[3]); 139 } 140 int hm=1; 141 if (args.length>4) { 142 hm=Integer.parseInt(args[4]); 143 } 144 Map cntxt=new HashMap(); 145 if (args.length>5) { 146 for (int i=5; i<args.length; i++) { 147 String cnt=args[i]; 148 int ind=cnt.indexOf("="); 149 String id=cnt.substring(0,ind); 150 String val=cnt.substring(ind+1,cnt.length()); 151 if (val!=null && val.equals("true") || val.equals("false")) { 152 Boolean bool=new Boolean (val); 153 cntxt.put(id,bool); 154 continue; 155 } 156 try { 157 Double d=Double.valueOf(val); 158 if (val.indexOf(".")==-1) { 159 Long l=new Long (d.longValue()); 160 cntxt.put(id,l); 161 } else { 162 cntxt.put(id,d); 163 } 164 } catch (Exception ex) { 165 cntxt.put(id,val); 166 } 167 168 } 169 } 170 171 try { 172 Shark.configure(confFilePath); 173 } catch (Exception ex) { 174 ex.printStackTrace(); 175 printUsage(); 176 return; 177 } 178 Shark ss=Shark.getInstance(); 179 PackageAdministration pa=ss.getAdminInterface().getPackageAdministration(); 180 RepositoryMgr rm=ss.getRepositoryManager(); 181 String pkgId=null; 182 am=ss.getAdminInterface().getAdminMisc(); 183 UserGroupAdministration uga=ss.getAdminInterface().getUserGroupAdministration(); 184 try { 185 System.out.println("All GRPS:"); 186 String [] gns=uga.getAllGroupnames(); 187 for (int i=0; i<gns.length; i++) { 188 System.out.println("Group - "+gns[i]); 189 } 190 System.out.println("All USERS:"); 191 String [] uns=uga.getAllUsers(); 192 for (int i=0; i<uns.length; i++) { 193 System.out.println("User - "+uns[i]); 194 } 195 196 if (!uga.doesGroupExist("test")) { 197 uga.createGroup("test","test group"); 198 } 199 if (!uga.doesUserExist(username)) { 200 uga.createUser("test", username, pwd,"Jane", "Doe",""); 201 } 202 203 } catch (Throwable t) {t.printStackTrace();} 204 205 try { 206 pkgId=rm.getPackageId(xpdlName); 207 if (!pa.isPackageOpened(pkgId)) { 208 pa.openPackage(xpdlName); 209 } 210 SharkConnection sc=ss.getSharkConnection(); 211 sc.connect(username,pwd,"",""); 212 213 startT=System.currentTimeMillis(); 214 for (int i = 0; i < hm; ++i) { 215 WfProcess proc=sc.createProcess(pkgId,pDefId); 216 proc.set_process_context(cntxt); 217 proc.start(); 218 } 219 220 ManualTest.pkgId=pkgId; 224 ManualTest.pDefId=pDefId; 225 226 for (int i=0;i<hmThreads; i++) { 227 new ManualTest(); 228 } 229 } catch (Throwable ex) { 230 if (ex instanceof PackageInvalid) { 231 System.out.println("PIERRS="+((PackageInvalid)ex).getXPDLValidationErrors()); 232 } 233 if (ex instanceof ExternalPackageInvalid) { 234 System.out.println("PIERRS="+((ExternalPackageInvalid)ex).getXPDLValidationErrors()); 235 } 236 ex.printStackTrace(); 237 printUsage(); 238 System.exit(1); 239 } 240 } 241 242 static void printUsage () { 243 System.err.println("This application is used to start and execute shark's processes, that contain at least one manual activity, until all of them are finished."); 244 System.err.println(); 245 System.err.println("usage: java ManualTest configFilePath xpdlName pDefId [noOfThreads [noOfProcToStart [var1=val1 [var2=val2 ... ]]]]"); 246 System.err.println(); 247 System.err.println("arguments:"); 248 System.err.println(" configFilePath the path to Shark's configuration file."); 249 System.err.println(" xpdlName the path to XPDL file where process definition for the process one want to start can be found."); 250 System.err.println(" This path has to be relative to shark's external repository folder."); 251 System.err.println(" pDefId the id of xpdl process definition."); 252 System.err.println(" noOfThreads the number of threads that will fight to execute activities (default is 1)."); 253 System.err.println(" noOfProcToStart the number of processes that will be started (default is 1)."); 254 System.err.println(" vari=vali the process variable id and its value."); 255 System.err.println(); 256 System.err.println("NOTE: variable value will be interpreted as:"); 257 System.err.println(" Boolean - if you enter 'true' or 'false',"); 258 System.err.println(" Long - if you enter only digits,"); 259 System.err.println(" Double - if you enter only digits and full-stop,"); 260 System.err.println(" String - otherwise."); 261 } 262 263 } 264 265 | Popular Tags |