From: <st...@us...> - 2007-07-10 16:52:50
|
Revision: 4620 http://svn.sourceforge.net/smartfrog/?rev=4620&view=rev Author: steve_l Date: 2007-07-10 09:52:43 -0700 (Tue, 10 Jul 2007) Log Message: ----------- SFOS-270: Improve logging of deploy times. SFOS-271: Add a way to deploy but not start a component Modified Paths: -------------- trunk/core/smartfrog/src/org/smartfrog/sfcore/common/ActionDeploy.java trunk/core/smartfrog/src/org/smartfrog/sfcore/common/ConfigurationDescriptor.java trunk/core/smartfrog/src/org/smartfrog/sfcore/common/SmartFrogCoreKeys.java Added Paths: ----------- trunk/core/smartfrog/src/org/smartfrog/sfcore/common/ActionLoad.java Modified: trunk/core/smartfrog/src/org/smartfrog/sfcore/common/ActionDeploy.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/sfcore/common/ActionDeploy.java 2007-07-10 15:26:50 UTC (rev 4619) +++ trunk/core/smartfrog/src/org/smartfrog/sfcore/common/ActionDeploy.java 2007-07-10 16:52:43 UTC (rev 4620) @@ -22,7 +22,6 @@ import org.smartfrog.sfcore.prim.Prim; import org.smartfrog.sfcore.prim.TerminationRecord; import org.smartfrog.sfcore.processcompound.ProcessCompound; -import org.smartfrog.sfcore.parser.Phases; import org.smartfrog.sfcore.componentdescription.ComponentDescription; import org.smartfrog.sfcore.componentdescription.ComponentDescriptionImpl; import org.smartfrog.sfcore.reference.Reference; @@ -37,30 +36,50 @@ * Deploy a component */ public class ActionDeploy extends ConfigurationAction { - public static final String KEY_LANGUAGE = "#language"; + /** + * Parses, deploys and starts "sfConfig" from a resource to the target process compound rethrows an exception if it fails, + * after trying to clean up. This method will check if parent is a rootProcess and it so, it will register "url" as + * a root component that will start its own liveness. + * + * @param url URL of resource to parse + * @param appName name of the application + * @param parent parent for the new component. If null if will use 'target'. + * @param target the target process compound to request deployment + * @param c a context of additional attributes that should be set before deployment + * @param deployReference reference to resolve in ComponentDescription. If ref is null the whole result + * ComponentDescription is returned. + * @return Prim Reference to deployed component + * @throws SmartFrogException failure in some part of the process + * @throws RemoteException In case of network/rmi error + */ + public static Prim Deploy(String url, String appName, Prim parent, Compound target, + Context c, Reference deployReference) throws SmartFrogException, RemoteException { + return Deploy(url,appName,parent,target,c,deployReference,true); + } /** - * Parses and deploys "sfConfig" from a resource to the target process - * compound rethrows an exception if it fails, after trying to clean up. - * This method will check if parent is a rootProcess and it so, it will - * register "url" as a root component that will start its own liveness. - * - * @param url URL of resource to parse - * @param appName name of the application - * @param parent parent for the new component. If null if will use 'target'. - * @param target the target process compound to request deployment - * @param c a context of additional attributes that should be set before - * deployment + * Parses, deploys and optionally starts "sfConfig" from a resource to the target process + * compound rethrows an exception if it fails, after trying to clean up. + * This method will check if parent is a rootProcess and it so, it will + * register "url" as a root component that will start its own liveness. + * + * @param url URL of resource to parse + * @param appName name of the application + * @param parent parent for the new component. If null if will use 'target'. + * @param target the target process compound to request deployment + * @param context a context of additional attributes that should be set before + * deployment * @param deployReference reference to resolve in ComponentDescription. * If ref is null the whole result ComponentDescription is returned. + * @param start flag to set to true to start the component after deploying it by calling sfDeploy and sfStart * @return Prim Reference to deployed component * * @throws SmartFrogException failure in some part of the process * @throws RemoteException In case of network/rmi error */ - public static Prim Deploy(String url, String appName,Prim parent, Compound target, - Context c, Reference deployReference) throws SmartFrogException, RemoteException { + protected static Prim Deploy(String url, String appName, Prim parent, Compound target, + Context context, Reference deployReference, boolean start) throws SmartFrogException, RemoteException { //First thing first: system gets initialized //Protect system if people use this as entry point @@ -71,111 +90,133 @@ } - Prim comp = null; - Phases top; - //To calculate how long it takes to deploy a description - long deployTime = 0; - long parseTime = 0; + Prim comp = null; + //To calculate how long it takes to deploy a description + long beginTime; + long deployTime = 0; + long startTime = 0; + long parseTime; -// if (Logger.logStackTrace) { - deployTime = System.currentTimeMillis(); -// } - if (c==null) c = new ContextImpl(); + beginTime = System.currentTimeMillis(); + if (context == null) { + context = new ContextImpl(); + } - // Checks if 'parent' is a processCompound. If parent is a process compound - // the parentage is made null and it is registered as an attribute, not a - // child, so it is a root component and starts is own liveness - if ((parent!=null)&&(parent instanceof ProcessCompound)){ - // This component will be a root component - parent=null; + // Checks if 'parent' is a processCompound. If parent is a process compound + // the parentage is made null and it is registered as an attribute, not a + // child, so it is a root component and starts is own liveness + if ((parent != null) && (parent instanceof ProcessCompound)) { + // This component will be a root component + parent = null; - } else if ((parent!=null)&&(parent instanceof Compound)&&(appName==null)){ - //From ProcessCompoundImpl. Creates name for unnamed components... + } else if ((parent != null) && (parent instanceof Compound) && (appName == null)) { + //From ProcessCompoundImpl. Creates name for unnamed components... // appName = SmartFrogCoreKeys.SF_UNNAMED + (new Date()).getTime() + "_" + // ProcessCompoundImpl.registrationNumber++; - } - // This is needed so that the root component is properly named - // when registering with the ProcessCompound - if ((parent==null)&&(appName!=null)) c.put("sfProcessComponentName", appName); + } + // This is needed so that the root component is properly named + // when registering with the ProcessCompound + if ((parent == null) && (appName != null)) { + context.put("sfProcessComponentName", appName); + } - // The processCompound/Compound is used to do the deployment! - if ((parent!=null)&&(parent instanceof Compound)){ - target = (Compound)parent; - } + // The processCompound/Compound is used to do the deployment! + if ((parent != null) && (parent instanceof Compound)) { + target = (Compound) parent; + } //select the language first from the context, then from the URL itself String language; - language=(String) c.get(KEY_LANGUAGE); + language=(String) context.get(SmartFrogCoreKeys.KEY_LANGUAGE); if(language==null) { language=url; } - try { - ComponentDescription cd; - try { - cd = ComponentDescriptionImpl.sfComponentDescription(url,language,null,deployReference); -// if (Logger.logStackTrace) { - parseTime = System.currentTimeMillis()-deployTime; - deployTime = System.currentTimeMillis(); -// } - } catch (SmartFrogException sfex) { - if (sfex instanceof SmartFrogDeploymentException) - throw sfex; - else - throw new SmartFrogDeploymentException( - "deploying description '"+url+"' for '"+appName+"'", + + ComponentDescription cd; + try { + cd = ComponentDescriptionImpl.sfComponentDescription(url, language, null, deployReference); + parseTime = System.currentTimeMillis(); + + } catch (SmartFrogException sfex) { + if (sfex instanceof SmartFrogDeploymentException) { + throw sfex; + } else { + throw new SmartFrogDeploymentException( + "deploying description '" + url + "' for '" + appName + "'", sfex, comp, - c); - } + context); + } + } + try { + comp = target.sfDeployComponentDescription(appName, parent, cd, context); + if (start) { + try { + comp.sfDeploy(); + deployTime = System.currentTimeMillis(); + } catch (Throwable thr) { + if (thr instanceof SmartFrogLifecycleException) { + throw (SmartFrogLifecycleException) SmartFrogLifecycleException.forward(thr); + } + throw SmartFrogLifecycleException.sfDeploy("", thr, null); + } - comp = target.sfDeployComponentDescription(appName, parent, cd, c); - - try { - comp.sfDeploy(); - } catch (Throwable thr){ - if (thr instanceof SmartFrogLifecycleException){ - throw (SmartFrogLifecycleException) SmartFrogLifecycleException.forward(thr); + try { + comp.sfStart(); + startTime = System.currentTimeMillis(); + } catch (Throwable thr) { + if (thr instanceof SmartFrogLifecycleException) { + throw (SmartFrogLifecycleException) thr; + } + throw SmartFrogLifecycleException.sfStart("", thr, null); + } + } + } catch (Throwable e) { + //if the component is non null, get the name of the component + //and then terminate it abnormally + if (comp != null) { + Reference compName = null; + try { + compName = comp.sfCompleteName(); } - throw SmartFrogLifecycleException.sfDeploy("",thr,null); - } - try { - comp.sfStart(); - } catch (Throwable thr){ - if (thr instanceof SmartFrogLifecycleException){ - throw (SmartFrogLifecycleException) SmartFrogLifecycleException.forward(thr); + catch (Exception ignored) { } - throw SmartFrogLifecycleException.sfStart("",thr,null); + try { + comp.sfTerminate(TerminationRecord.abnormal("Deployment Failure: " + e, compName)); + } catch (Exception ignored) { + } } - } catch (Throwable e) { - if (comp != null) { - Reference compName = null; - try { - compName = comp.sfCompleteName(); - } - catch (Exception ex) { - } - try { - comp.sfTerminate(TerminationRecord.abnormal("Deployment Failure: " + e, compName)); - } catch (Exception ex) {} - } - throw ((SmartFrogException) SmartFrogException.forward(e)); + throw (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; + //finally, attach times + addTime(comp, SmartFrogCoreKeys.SF_TIME_PARSE, parseTime - beginTime); + addTime(comp, SmartFrogCoreKeys.SF_TIME_DEPLOY, deployTime -parseTime); + addTime(comp, SmartFrogCoreKeys.SF_TIME_START, startTime - deployTime); + return comp; } /** + * Add a time to the component; ignore any exceptions + * @param comp compoent to add + * @param name key name + * @param time time to add + */ + private static void addTime(Prim comp, String name, long time) { + try { + if(time>=0) { + comp.sfAddAttribute(name, new Long(time)); + } + } catch (SmartFrogRuntimeException ignored) { + + } catch (RemoteException ignored) { + + } + } + + /** * Deploy Action. * * @param targetP target where to execute the configuration command @@ -216,12 +257,7 @@ } } - prim = Deploy(configuration.getUrl(), - name, - parent, - targetP, - configuration.getContext(), - configuration.getDeployReference()); + prim = doDeploy(configuration, name, parent, targetP); } catch (SmartFrogException sex){ configuration.setResult(ConfigurationDescriptor.Result.FAILED,null,sex); @@ -234,4 +270,35 @@ return prim; } + /** + * Override point; call the deployment operations + * @param configuration configuration to deploy + * @param name name of the component + * @param parent parent flag + * @param targetP target + * @return + * @throws SmartFrogException + * @throws RemoteException + */ + protected Prim doDeploy(ConfigurationDescriptor configuration, String name, Prim parent, ProcessCompound targetP) throws SmartFrogException, RemoteException { + Prim prim; + prim = Deploy(configuration.getUrl(), + name, + parent, + targetP, + configuration.getContext(), + configuration.getDeployReference(), + getStartFlag(configuration)); + return prim; + } + + /** + * Override point: get the start flag for this configuration. The default always returns true. + * @param configuration the configuration which is being deployed + * @return true if the configuration should start. + */ + protected boolean getStartFlag(ConfigurationDescriptor configuration) { + return true; + } + } Added: trunk/core/smartfrog/src/org/smartfrog/sfcore/common/ActionLoad.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/sfcore/common/ActionLoad.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/sfcore/common/ActionLoad.java 2007-07-10 16:52:43 UTC (rev 4620) @@ -0,0 +1,42 @@ +/** (C) Copyright 2007 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + */ +package org.smartfrog.sfcore.common; + +/** + * A variant of ActionDeploy that can be used to load but not start an + * application. This is used by the testharness. + * created 10-Jul-2007 15:48:18 + */ + +public class ActionLoad extends ActionDeploy { + + + /** + * Override point: get the start flag for this configuration. + * This override always returns false. + * + * @param configuration the configuration which is being deployed + * @return false. + */ + protected boolean getStartFlag(ConfigurationDescriptor configuration) { + return false; + } + +} Modified: trunk/core/smartfrog/src/org/smartfrog/sfcore/common/ConfigurationDescriptor.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/sfcore/common/ConfigurationDescriptor.java 2007-07-10 15:26:50 UTC (rev 4619) +++ trunk/core/smartfrog/src/org/smartfrog/sfcore/common/ConfigurationDescriptor.java 2007-07-10 16:52:43 UTC (rev 4620) @@ -56,24 +56,26 @@ private Action() { } - final static public String ACT_DEPLOY = "DEPLOY"; - final static public int DEPLOY = 0; - final static public String ACT_TERMINATE = "TERMINATE"; - final static public int TERMINATE = 1; - final static public String ACT_UNDEFINED = "UNDEFINED"; - final static public int UNDEFINED = 2; - final static public String ACT_DETACH= "DETACH"; - final static public int DETACH = 3; - final static public String ACT_DETaTERM = "DETaTERM"; - final static public int DETaTERM = 4; - final static public String ACT_PING = "PING"; - final static public int PING = 5; - final static public String ACT_PARSE = "PARSE"; - final static public int PARSE = 6; - final static public String ACT_DIAGNOSTICS = "DIAGNOSTICS"; - final static public int DIAGNOSTICS = 7; - final static public String ACT_UPDATE = "UPDATE"; - final static public int UPDATE = 8; + public static final String ACT_DEPLOY = "DEPLOY"; + public static final int DEPLOY = 0; + public static final String ACT_TERMINATE = "TERMINATE"; + public static final int TERMINATE = 1; + public static final String ACT_UNDEFINED = "UNDEFINED"; + public static final int UNDEFINED = 2; + public static final String ACT_DETACH= "DETACH"; + public static final int DETACH = 3; + public static final String ACT_DETaTERM = "DETaTERM"; + public static final int DETaTERM = 4; + public static final String ACT_PING = "PING"; + public static final int PING = 5; + public static final String ACT_PARSE = "PARSE"; + public static final int PARSE = 6; + public static final String ACT_DIAGNOSTICS = "DIAGNOSTICS"; + public static final int DIAGNOSTICS = 7; + public static final String ACT_UPDATE = "UPDATE"; + public static final int UPDATE = 8; + public static final String ACT_LOAD = "LOAD"; + public static final int LOAD = 9; static public String[] type= { ACT_DEPLOY, @@ -84,7 +86,9 @@ ACT_PING, ACT_PARSE, ACT_DIAGNOSTICS, - ACT_UPDATE}; + ACT_UPDATE, + ACT_LOAD + }; } @@ -136,10 +140,10 @@ private Result() { } - final static public int SUCCESSFUL=0; - final static public int FAILED=1; - final static public int UNDEFINED=2; - final static public int UNKNOWN=3; + public static final int SUCCESSFUL=0; + public static final int FAILED=1; + public static final int UNDEFINED=2; + public static final int UNKNOWN=3; static String[] type= {"SUCCESSFUL", "FAILED", "UNDEFINED", @@ -540,7 +544,7 @@ * ex. foo * ex. "HOST localhost:foo" * ex. 'HOST localhost:foo' - * - ACTION: possible actions: DEPLOY, TERMINATE, DETACH, DETaTERM, PING, PARSE, DIAGNOSTICS, UPDATE + * - ACTION: possible actions: DEPLOY, TERMINATE, DETACH, DETaTERM, PING, PARSE, DIAGNOSTICS, UPDATE, LOAD * - url: description used by ACTION * ex. /home/sf/foo.sf * ex. "c:\sf\foo.sf" @@ -564,13 +568,11 @@ *</pre> * @see Action * @throws SmartFrogInitException failure in some part of the process - * - // TODO fix this text for JavaDocs */ public ConfigurationDescriptor (String deploymentURL) throws SmartFrogInitException { try { originalSFACT = deploymentURL; - if (SFSystem.sfLog().isDebugEnabled()){SFSystem.sfLog().debug("Parsing SFACT: ["+originalSFACT+"]"); } + if (SFSystem.sfLog().isDebugEnabled()){SFSystem.sfLog().debug("Parsing SFACT: ["+originalSFACT+"]"); } if (deploymentURL==null) { throw new SmartFrogInitException("Deployment URL: null"); @@ -855,6 +857,9 @@ case Action.UPDATE: action = new ActionUpdate(); break; + case Action.LOAD: + action = new ActionLoad(); + break; default: throw new SmartFrogInitException("Action type unknown"); } Modified: trunk/core/smartfrog/src/org/smartfrog/sfcore/common/SmartFrogCoreKeys.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/sfcore/common/SmartFrogCoreKeys.java 2007-07-10 15:26:50 UTC (rev 4619) +++ trunk/core/smartfrog/src/org/smartfrog/sfcore/common/SmartFrogCoreKeys.java 2007-07-10 16:52:43 UTC (rev 4620) @@ -323,4 +323,31 @@ * Value {@value} */ public static final String SF_FINAL= "sfFinal"; + + + /** + * Time attribute set in ActionDeploy deployment + * + * Value {@value} + */ + String SF_TIME_PARSE = "sfParseTime"; + /** + * Time attribute set in ActionDeploy deployment + * + * Value {@value} + */ + String SF_TIME_DEPLOY = "sfDeployTime"; + + /** + * Time attribute set in ActionDeploy deployment + * + * Value {@value} + */ + String SF_TIME_START = "sfStartTime"; + + /** + * The language attribute, which can be set/found from the context. + * {@value} + */ + String KEY_LANGUAGE = "#language"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |