From: <ju...@us...> - 2004-03-12 18:09:30
|
Update of /cvsroot/smartfrog/core/smartfrog/src/org/smartfrog In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7080/smartfrog/src/org/smartfrog Modified Files: SFSystem.java Log Message: Refactoring of SFSystem. New options to deploy description -a and -f: - a counter1:DEPLOY:org/smarfrog/examples/counter/exampe.sf:sfConfig:localhost:rootProcess -f FILE_NAME to load a list of deployment URLs. Some methods and some of the options will disappear from SFSystem. Index: SFSystem.java =================================================================== RCS file: /cvsroot/smartfrog/core/smartfrog/src/org/smartfrog/SFSystem.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** SFSystem.java 5 Mar 2004 10:53:56 -0000 1.11 --- SFSystem.java 12 Mar 2004 17:41:55 -0000 1.12 *************** *** 30,33 **** --- 30,34 ---- import java.util.Date; import java.util.Enumeration; + import java.util.Vector; import java.util.Properties; import java.util.StringTokenizer; *************** *** 54,57 **** --- 55,59 ---- import org.smartfrog.sfcore.security.SFClassLoader; import org.smartfrog.sfcore.security.SFSecurity; + import org.smartfrog.sfcore.common.ConfigurationDescriptor; *************** *** 158,161 **** --- 160,169 ---- Prim comp = null; Phases top; + //To calculate how long it takes to deploy a description + long deployTime = 0; + long parseTime = 0; + if (Logger.logStackTrace) { + deployTime = System.currentTimeMillis(); + } try { top = new SFParser(language).sfParse(is); *************** *** 176,179 **** --- 184,191 ---- try { ComponentDescription cd = top.sfAsComponentDescription(); + if (Logger.logStackTrace) { + parseTime = System.currentTimeMillis() - deployTime; + deployTime = System.currentTimeMillis(); + } comp = target.sfDeployComponentDescription(null, null, cd, c); try { *************** *** 207,213 **** --- 219,249 ---- throw ((SmartFrogException) SmartFrogException.forward(e)); } + + if (Logger.logStackTrace) { + deployTime = System.currentTimeMillis()-deployTime; + try { + comp.sfAddAttribute("sfParseTime",new Long(parseTime)); + comp.sfAddAttribute("sfDeployTime",new Long(deployTime)); + } catch (Exception ex){ + //ignored, this is only information + } + } return comp; } + /* + if (Logger.logStackTrace) { + deployTime = System.currentTimeMillis()-deployTime; + Logger.log(" * "+comp.sfCompleteName() + +" parsed in "+parseTime+" msecs." + +" deployed in "+deployTime+" msecs."); + try { + comp.sfAddAttribute("sfParseTime",new Long(parseTime)); + comp.sfAddAttribute("sfDeployTime",new Long(deployTime)); + } catch (Exception ex){ + //ignored, this is only information + } + } + */ /** * Reads the property "org.smartfrog.iniSFFile and deploys the *************** *** 257,266 **** url = (String) e.nextElement(); name = (String) names.nextElement(); - if (name != null) { ! nameContext = new ContextImpl(); nameContext.put("sfProcessComponentName", name); - } else { - name = "unnamed#" + counter++; } --- 293,301 ---- url = (String) e.nextElement(); name = (String) names.nextElement(); if (name != null) { ! if (nameContext==null) { ! nameContext = new ContextImpl(); ! } nameContext.put("sfProcessComponentName", name); } *************** *** 316,325 **** private static Prim deployFromURL(String url, String appName, ProcessCompound target, Context nameContext) throws SmartFrogException, RemoteException { ! //To calculate how long it takes to deploy a description ! long deployTime = 0; Prim deployedApp = null; ! if (Logger.logStackTrace) { ! deployTime = System.currentTimeMillis(); ! } InputStream is=null; try { --- 351,357 ---- private static Prim deployFromURL(String url, String appName, ProcessCompound target, Context nameContext) throws SmartFrogException, RemoteException { ! Prim deployedApp = null; ! InputStream is=null; try { *************** *** 332,340 **** } deployedApp = deployFrom(is, target, nameContext, getLanguageFromUrl(url)); - if (Logger.logStackTrace) { - deployTime = System.currentTimeMillis() - deployTime; - Logger.log(" - " + appName + " (" + url + ")" - + " deployed in " + deployTime + " millisecs."); - } } catch (SmartFrogException sfex) { sfex.put("URL:", url); --- 364,367 ---- *************** *** 646,649 **** --- 673,708 ---- return target; } + + /** + * Select target process compound using host and subprocess names + * + * @param String host host name. + * @param String subProcess subProcess name. + * + * @return ProcessCompound the target process compound + * + * @throws SmartFrogException In case of SmartFrog system error + */ + public static ProcessCompound selectTargetProcess(String host, String subProcess) + throws SmartFrogException, RemoteException { + ProcessCompound target = null; + try { + target = SFProcess.getProcessCompound(); + if (host!=null) { + target = SFProcess.getRootLocator(). + getRootProcessCompound(InetAddress.getByName(host)); + } + if (subProcess!=null) { + target = (ProcessCompound)target.sfResolveHere(subProcess); + } + } catch (Exception ex) { + SmartFrogException.forward(ex); + } + return target; + } + + + + /** * Gets the ProcessCompound running on the host. *************** *** 692,700 **** * @param status */ ! private static void exitWithStatus(StatusInfo status) { ! boolean somethingFailed=false; ! somethingFailed=status.detachRequests!=status.detachCount; ! somethingFailed|=status.terminateRequests!=status.terminatedCount; ! somethingFailed|=status.deployRequests!=status.deployedCount; if(somethingFailed) { exitWithError(); --- 751,755 ---- * @param status */ ! private static void exitWithStatus(boolean somethingFailed) { if(somethingFailed) { exitWithError(); *************** *** 746,749 **** --- 801,903 ---- + public static void runConfigurationDescriptors (Vector cfgDescs){ + if (cfgDescs==null) return; + for (Enumeration items = cfgDescs.elements(); items.hasMoreElements();) { + runConfigurationDescriptor((ConfigurationDescriptor)items.nextElement()); + } + } + + public static Object runConfigurationDescriptor (ConfigurationDescriptor cfgDesc){ + ProcessCompound targetP=null; + Prim targetC = null; + boolean isRootProcess = false; + try { + targetP = selectTargetProcess(cfgDesc.host,cfgDesc.subProcess); + // name has different meaning for DEPLOY + if (cfgDesc.getActionType()!=ConfigurationDescriptor.Action.DEPLOY) { + + targetC = (Prim)targetP.sfResolveWithParser(cfgDesc.name); + + if (targetC instanceof ProcessCompound) { + if (((ProcessCompound)targetC).sfIsRoot()) { + isRootProcess = true; + } + } + } + switch (cfgDesc.getActionType()) { + case (ConfigurationDescriptor.Action.DEPLOY): + Context nameContext = null; + InputStream is = getInputStreamForResource(cfgDesc.url); + // if the application is named! + if (cfgDesc.name!=null) { + nameContext = new ContextImpl(); + nameContext.put("sfProcessComponentName", cfgDesc.name); + } + Prim prim = deployFrom(is, targetP, nameContext, getLanguageFromUrl(cfgDesc.url)); + //Logger.log(MessageUtil. + // formatMessage(MSG_DEPLOY_SUCCESS, prim.sfCompleteName()+", "+ + // "\n using: " +cfgDesc.url)); + cfgDesc.setSuccessfulResult(); + return prim; + + case ConfigurationDescriptor.Action.DETACH: + { + String name = targetC.sfCompleteName().toString(); + targetC.sfDetach(); + cfgDesc.setSuccessfulResult(); + //Logger.log("- Detached: "+name + // +",\n now:"+targetC.sfCompleteName()); + } + return targetC; + + case ConfigurationDescriptor.Action.DETaTERM: + { + String name = targetC.sfCompleteName().toString(); + targetC.sfDetachAndTerminate(new TerminationRecord("normal", + "External Management Action", + targetP.sfCompleteName())); + cfgDesc.setSuccessfulResult(); + //Logger.log("- DetachAndTerminated: "+name); + } + break; + case ConfigurationDescriptor.Action.TERMINATE: + { + try { + String name = targetC.sfCompleteName().toString(); + targetC.sfTerminate(new TerminationRecord("normal", + "External Management Action", + targetP.sfCompleteName())); + //Logger.log("- Terminated: "+name); + cfgDesc.setSuccessfulResult(); + } catch (Exception ex) { + if (!isRootProcess) + throw ex; + //TODO: Check exception handling + if ((ex.getCause()instanceof java.net.SocketException)|| + (ex.getCause()instanceof java.io.EOFException)) { + Logger.log(MessageUtil.formatMessage( + MSG_SF_TERMINATED)); + cfgDesc.setSuccessfulResult(); + } else { + Logger.log(ex); + } + } + } + break; + default: + throw new SmartFrogInitException("Unknown Action in: "+ cfgDesc.toString()); + } + + } catch (Throwable thr){ + if (cfgDesc.resultException ==null) { + cfgDesc.setResult(ConfigurationDescriptor.Result.FAILED,null,thr); + //@Todo Improve error message! + //Logger.log( thr +"\n - ConfigurationDescriptor:" +cfgDesc.toString()+"\n"); + } else Logger.logQuietly(thr); + } + return cfgDesc; + } + + /** * Method invoked to start the SmartFrog system. *************** *** 790,804 **** exitWithError(); } // Check for exit flag if (opts.exit) { ! if (opts.names.size() != 0 && !errorDeploy) { ! Logger.log(MessageUtil. ! formatMessage(MSG_DEPLOY_SUCCESS, opts.names)); ! } ! if (opts.terminations.size() != 0 && !errorTermination) { ! Logger.log(MessageUtil. ! formatMessage(MSG_TERMINATE_SUCCESS, opts.terminations)); } ! exitWithStatus(info); } else { //Logger.log(MessageUtil.formatMessage(MSG_SF_READY)); --- 944,970 ---- exitWithError(); } + // Check for exit flag if (opts.exit) { ! //Report Actions successes of failures. ! boolean somethingFailed = false; ! ConfigurationDescriptor cfgDesc = null; ! for (Enumeration items = opts.cfgDescriptors.elements(); items.hasMoreElements();) { ! cfgDesc = (ConfigurationDescriptor)items.nextElement(); ! if (cfgDesc.getResultType()== ConfigurationDescriptor.Result.FAILED) { ! somethingFailed = true; ! } ! Logger.log(" - "+(cfgDesc).statusString()+"\n"); } ! // Messages not valid if using deploy ConfigurationDescriptors ! // if (opts.names.size() != 0 && !errorDeploy) { ! // Logger.log(MessageUtil. ! // formatMessage(MSG_DEPLOY_SUCCESS, opts.names)); ! // } ! // if (opts.terminations.size() != 0 && !errorTermination) { ! // Logger.log(MessageUtil. ! // formatMessage(MSG_TERMINATE_SUCCESS, opts.terminations)); ! // } ! exitWithStatus(somethingFailed); } else { //Logger.log(MessageUtil.formatMessage(MSG_SF_READY)); *************** *** 872,883 **** ProcessCompound targetPC = selectTargetProcess(options); ! status.detachRequests= options.detaching.size(); ! status.detachCount=detachAndTerminateNamedComponents(options, targetPC); ! ! status.terminateRequests=options.terminations.size(); ! status.terminatedCount=terminateNamedApplications(options, targetPC); ! status.deployRequests=options.configs.size(); ! status.deployedCount = deployFromURLsGiven(options, targetPC); return process; --- 1038,1053 ---- ProcessCompound targetPC = selectTargetProcess(options); ! runConfigurationDescriptors(options.cfgDescriptors); ! // First step in cleaning SFSystem. Check runConfigurationDescriptor method to ! // replace all this ones. ! // status.detachRequests= options.detaching.size(); ! // status.detachCount=detachAndTerminateNamedComponents(options, targetPC); ! // ! // status.terminateRequests=options.terminations.size(); ! // status.terminatedCount=terminateNamedApplications(options, targetPC); ! // ! // status.deployRequests=options.configs.size(); ! // status.deployedCount = deployFromURLsGiven(options, targetPC); return process; *************** *** 893,897 **** * @see SFClassLoader */ ! private static InputStream getInputStreamForResource(String resource) throws SmartFrogException{ InputStream is = null; --- 1063,1067 ---- * @see SFClassLoader */ ! public static InputStream getInputStreamForResource(String resource) throws SmartFrogException{ InputStream is = null; |