[prev in list] [next in list] [prev in thread] [next in thread] 

List:       rhq-commits
Subject:    [rhq] Branch 'release-3.0.0' - 2 commits - modules/plugins
From:       joseph42 () fedoraproject ! org (Joseph Marques)
Date:       2010-06-29 22:18:03
Message-ID: 20100629221803.F1DE31201B6 () lists ! fedorahosted ! org
[Download RAW message or body]

 modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/AbstractManagedDeploymentComponent.java \
|  105 ++++------  modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java \
|   78 +++----  2 files changed, 83 insertions(+), 100 deletions(-)

New commits:
commit ab54c29d4306abe51df706b72f90b6454d20a057
Author: Joseph Marques <joseph at redhat.com>
Date:   Tue Jun 29 18:15:20 2010 -0400

    improve availability checking routines for JBossAS5 managed components
    
    * be tolerant of the underlying API changes - catch throwable
    * when getting the state object back, log if it's not UP/STARTED/RUNNING

diff --git a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/AbstractManagedDeploymentComponent.java \
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/AbstractManagedDeploymentComponent.java
 index 09892a0..de39733 100644
--- a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/AbstractManagedDeploymentComponent.java
                
+++ b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/AbstractManagedDeploymentComponent.java
 @@ -39,7 +39,6 @@ import org.jboss.deployers.spi.management.deploy.ProgressListener;
 import org.jboss.managed.api.DeploymentState;
 import org.jboss.managed.api.ManagedDeployment;
 import org.jboss.profileservice.spi.NoSuchDeploymentException;
-import org.jboss.remoting.CannotConnectException;
 
 import org.rhq.core.domain.configuration.Configuration;
 import org.rhq.core.domain.measurement.AvailabilityType;
@@ -105,14 +104,22 @@ public abstract class AbstractManagedDeploymentComponent \
extends AbstractManaged  }
 
     public AvailabilityType getAvailability() {
+        DeploymentState deploymentState = null;
         try {
-            return (getManagedDeployment().getDeploymentState() == \
                DeploymentState.STARTED) ? AvailabilityType.UP
-                : AvailabilityType.DOWN;
+            deploymentState = getManagedDeployment().getDeploymentState();
         } catch (NoSuchDeploymentException e) {
             log.warn(this.deploymentType + " deployment '" + this.deploymentName + \
"' not found. Cause: "  + e.getLocalizedMessage());
             return AvailabilityType.DOWN;
-        } catch (CannotConnectException e) {
+        } catch (Throwable t) {
+            log.debug("Could not get deployment state, cause: ", t);
+            return AvailabilityType.DOWN;
+        }
+
+        if (deploymentState == DeploymentState.STARTED) {
+            return AvailabilityType.UP;
+        } else {
+            log.debug("Deployment was not running, state was: " + deploymentState);
             return AvailabilityType.DOWN;
         }
     }
diff --git a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java \
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java
 index 0bf55c2..74130b4 100644
--- a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java
                
+++ b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java
 @@ -49,7 +49,6 @@ import org.jboss.metatype.api.values.CompositeValue;
 import org.jboss.metatype.api.values.EnumValue;
 import org.jboss.metatype.api.values.MetaValue;
 import org.jboss.metatype.api.values.SimpleValue;
-import org.jboss.remoting.CannotConnectException;
 
 import org.rhq.core.domain.configuration.Configuration;
 import org.rhq.core.domain.configuration.ConfigurationUpdateStatus;
@@ -105,13 +104,20 @@ public class ManagedComponentComponent extends \
                AbstractManagedComponent implemen
     // ResourceComponent Implementation  \
--------------------------------------------  
     public AvailabilityType getAvailability() {
-        RunState runState;
+        RunState runState = null;
         try {
             runState = getManagedComponent().getRunState();
-        } catch (CannotConnectException e) {
+        } catch (Throwable t) {
+            log.debug("Could not get component state, cause: ", t);
+            return AvailabilityType.DOWN;
+        }
+
+        if (runState == RunState.RUNNING) {
+            return AvailabilityType.UP;
+        } else {
+            log.debug("Component was not running, state was: " + runState);
             return AvailabilityType.DOWN;
         }
-        return (runState == RunState.RUNNING) ? AvailabilityType.UP : \
AvailabilityType.DOWN;  }
 
     public void start(ResourceContext<ProfileServiceComponent> resourceContext) \
throws Exception {


commit 80ac41afa88f74bc69a2032b74efad2d542d1e4a
Author: Joseph Marques <joseph at redhat.com>
Date:   Tue Jun 29 18:05:03 2010 -0400

    cosmetic - automatic relayout of code

diff --git a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/AbstractManagedDeploymentComponent.java \
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/AbstractManagedDeploymentComponent.java
 index b2963cd..09892a0 100644
--- a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/AbstractManagedDeploymentComponent.java
                
+++ b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/AbstractManagedDeploymentComponent.java
 @@ -28,6 +28,7 @@ import java.util.Set;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import org.jboss.deployers.spi.management.KnownDeploymentTypes;
 import org.jboss.deployers.spi.management.ManagementView;
 import org.jboss.deployers.spi.management.deploy.DeploymentManager;
@@ -56,10 +57,8 @@ import org.rhq.plugins.jbossas5.util.DeploymentUtils;
  * @author Mark Spritzler
  * @author Ian Springer
  */
-public abstract class AbstractManagedDeploymentComponent
-        extends AbstractManagedComponent
-        implements MeasurementFacet, OperationFacet, ProgressListener
-{
+public abstract class AbstractManagedDeploymentComponent extends \
AbstractManagedComponent implements MeasurementFacet, +    OperationFacet, \
                ProgressListener {
     public static final String DEPLOYMENT_NAME_PROPERTY = "deploymentName";
     public static final String DEPLOYMENT_TYPE_NAME_PROPERTY = "deploymentTypeName";
     public static final String EXTENSION_PROPERTY = "extension";
@@ -85,8 +84,7 @@ public abstract class AbstractManagedDeploymentComponent
 
     // ----------- ResourceComponent Implementation ------------
 
-    public void start(ResourceContext<ProfileServiceComponent> resourceContext) \
                throws Exception
-    {
+    public void start(ResourceContext<ProfileServiceComponent> resourceContext) \
throws Exception {  super.start(resourceContext);
         Configuration pluginConfig = getResourceContext().getPluginConfiguration();
         this.deploymentName = \
pluginConfig.getSimple(DEPLOYMENT_NAME_PROPERTY).getStringValue(); @@ -94,41 +92,35 \
                @@ public abstract class AbstractManagedDeploymentComponent
         String deploymentTypeName = \
                pluginConfig.getSimple(DEPLOYMENT_TYPE_NAME_PROPERTY).getStringValue();
                
         this.deploymentType = KnownDeploymentTypes.valueOf(deploymentTypeName);
         log.trace("Started ResourceComponent for " + getResourceDescription() + ", \
                managing " + this.deploymentType
-                + " deployment '" + this.deploymentName + "' with path '" + \
                this.deploymentFile + "'.");
-        
+            + " deployment '" + this.deploymentName + "' with path '" + \
this.deploymentFile + "'."); +
         try {
             getManagedDeployment();
         } catch (Exception e) {
-        	log.warn("The underlying file [" + this.deploymentFile + "] no longer \
exists. It may have been deleted from the filesystem external to Jopr. If you wish to \
remove this Resource from inventory, you may add &debug=true to the URL for the \
Browse Resources > Services page and then click the UNINVENTORY button next to this \
Resource"); +            log
+                .warn("The underlying file ["
+                    + this.deploymentFile
+                    + "] no longer exists. It may have been deleted from the \
filesystem external to Jopr. If you wish to remove this Resource from inventory, you \
may add &debug=true to the URL for the Browse Resources > Services page and then \
click the UNINVENTORY button next to this Resource");  }
     }
 
-    public AvailabilityType getAvailability()
-    {
-        try
-        {
-            return (getManagedDeployment().getDeploymentState() == \
                DeploymentState.STARTED) ? AvailabilityType.UP :
-                    AvailabilityType.DOWN;
-        }
-        catch (NoSuchDeploymentException e)
-        {
+    public AvailabilityType getAvailability() {
+        try {
+            return (getManagedDeployment().getDeploymentState() == \
DeploymentState.STARTED) ? AvailabilityType.UP +                : \
AvailabilityType.DOWN; +        } catch (NoSuchDeploymentException e) {
             log.warn(this.deploymentType + " deployment '" + this.deploymentName + \
                "' not found. Cause: "
-                    + e.getLocalizedMessage());
+                + e.getLocalizedMessage());
             return AvailabilityType.DOWN;
-        }
-        catch (CannotConnectException e)
-        {
+        } catch (CannotConnectException e) {
             return AvailabilityType.DOWN;
         }
     }
 
     // ------------ MeasurementFacet Implementation ------------
 
-    public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> \
                requests)
-            throws Exception
-    {
-        if (this.deploymentType == KnownDeploymentTypes.JavaEEWebApplication)
-        {
+    public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> \
requests) throws Exception { +        if (this.deploymentType == \
                KnownDeploymentTypes.JavaEEWebApplication) {
             WarMeasurementFacetDelegate warMeasurementFacetDelegate = new \
WarMeasurementFacetDelegate(this);  warMeasurementFacetDelegate.getValues(report, \
requests);  }
@@ -136,43 +128,32 @@ public abstract class AbstractManagedDeploymentComponent
 
     // ------------ OperationFacet Implementation ------------
 
-    public OperationResult invokeOperation(String name, Configuration parameters) \
                throws Exception
-    {
+    public OperationResult invokeOperation(String name, Configuration parameters) \
                throws Exception {
         DeploymentManager deploymentManager = \
getConnection().getDeploymentManager();  DeploymentProgress progress;
-        if (name.equals("start"))
-        {
-        	//FIXME: This is a workaround until JOPR-309 will be fixed.
-        	if(getAvailability() != AvailabilityType.UP)
-        	{
-        		progress = deploymentManager.start(this.deploymentName);
-        	}
-        	else
-        	{
-        		log.warn("Operation '" + name + "' on " + getResourceDescription() + " \
                failed because the Resource is already started.");
-        		OperationResult result = new OperationResult();
-        		result.setErrorMessage(this.deploymentFile.getName() + " is already \
                started.");
-        		return result;
-        	}
-        }
-        else if (name.equals("stop"))
-        {
+        if (name.equals("start")) {
+            //FIXME: This is a workaround until JOPR-309 will be fixed.
+            if (getAvailability() != AvailabilityType.UP) {
+                progress = deploymentManager.start(this.deploymentName);
+            } else {
+                log.warn("Operation '" + name + "' on " + getResourceDescription()
+                    + " failed because the Resource is already started.");
+                OperationResult result = new OperationResult();
+                result.setErrorMessage(this.deploymentFile.getName() + " is already \
started."); +                return result;
+            }
+        } else if (name.equals("stop")) {
             progress = deploymentManager.stop(this.deploymentName);
-        }
-        else if (name.equals("restart"))
-        {
+        } else if (name.equals("restart")) {
             progress = deploymentManager.stop(this.deploymentName);
             DeploymentStatus stopStatus = DeploymentUtils.run(progress);
             // Still try to start, even if stop fails (maybe the app wasn't running \
to begin with).  progress = deploymentManager.start(this.deploymentName);
-        }
-        else
-        {
+        } else {
             throw new UnsupportedOperationException(name);
         }
         DeploymentStatus status = DeploymentUtils.run(progress);
-        log.debug("Operation '" + name + "' on " + getResourceDescription() + " \
                returned status [" + status
-                + "].");
+        log.debug("Operation '" + name + "' on " + getResourceDescription() + " \
returned status [" + status + "].");  if (status.isFailed()) {
             throw status.getFailure();
         }
@@ -181,8 +162,7 @@ public abstract class AbstractManagedDeploymentComponent
 
     // ------------ ProgressListener implementation -------------
 
-    public void progressEvent(ProgressEvent event)
-    {
+    public void progressEvent(ProgressEvent event) {
         log.debug(event);
     }
 
@@ -196,15 +176,13 @@ public abstract class AbstractManagedDeploymentComponent
         return deploymentType;
     }
 
-    protected ManagedDeployment getManagedDeployment() throws \
                NoSuchDeploymentException
-    {
+    protected ManagedDeployment getManagedDeployment() throws \
                NoSuchDeploymentException {
         ManagementView managementView = getConnection().getManagementView();
         managementView.load();
         return managementView.getDeployment(this.deploymentName);
     }
 
-    private File getDeploymentFile()
-    {
+    private File getDeploymentFile() {
         // e.g.: vfszip:/C:/opt/jboss-5.0.0.GA/server/default/deploy/foo.war
         URI vfsURI = URI.create(this.deploymentName);
         // e.g.: foo.war
diff --git a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java \
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java
 index aefb351..0bf55c2 100644
--- a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java
                
+++ b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java
 @@ -30,6 +30,9 @@ import java.util.Set;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
 import org.jboss.deployers.spi.management.ManagementView;
 import org.jboss.deployers.spi.management.deploy.DeploymentManager;
 import org.jboss.deployers.spi.management.deploy.DeploymentProgress;
@@ -48,12 +51,9 @@ import org.jboss.metatype.api.values.MetaValue;
 import org.jboss.metatype.api.values.SimpleValue;
 import org.jboss.remoting.CannotConnectException;
 
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
 import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.PropertySimple;
 import org.rhq.core.domain.configuration.ConfigurationUpdateStatus;
+import org.rhq.core.domain.configuration.PropertySimple;
 import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
 import org.rhq.core.domain.measurement.AvailabilityType;
 import org.rhq.core.domain.measurement.DataType;
@@ -72,11 +72,11 @@ import org.rhq.core.pluginapi.operation.OperationFacet;
 import org.rhq.core.pluginapi.operation.OperationResult;
 import org.rhq.core.util.exception.ThrowableUtil;
 import org.rhq.plugins.jbossas5.util.ConversionUtils;
+import org.rhq.plugins.jbossas5.util.DebugUtils;
 import org.rhq.plugins.jbossas5.util.DeploymentUtils;
 import org.rhq.plugins.jbossas5.util.ManagedComponentUtils;
-import org.rhq.plugins.jbossas5.util.ResourceTypeUtils;
 import org.rhq.plugins.jbossas5.util.ResourceComponentUtils;
-import org.rhq.plugins.jbossas5.util.DebugUtils;
+import org.rhq.plugins.jbossas5.util.ResourceTypeUtils;
 
 /**
  * Service ResourceComponent for all {@link ManagedComponent}s in a Profile.
@@ -93,7 +93,7 @@ public class ManagedComponentComponent extends \
AbstractManagedComponent implemen  String COMPONENT_NAME = "componentName";
         String TEMPLATE_NAME = "templateName";
         String COMPONENT_NAME_PROPERTY = "componentNameProperty";
-    }    
+    }
 
     protected static final char PREFIX_DELIMITER = '|';
 
@@ -129,53 +129,45 @@ public class ManagedComponentComponent extends \
AbstractManagedComponent implemen  
     // ConfigurationComponent Implementation  \
--------------------------------------------  
-    public Configuration loadResourceConfiguration()
-    {
+    public Configuration loadResourceConfiguration() {
         Configuration resourceConfig;
-        try
-        {
+        try {
             Map<String, ManagedProperty> managedProperties = \
                getManagedComponent().getProperties();
-            Map<String, PropertySimple> customProps =
-                    \
ResourceComponentUtils.getCustomProperties(getResourceContext().getPluginConfiguration());
                
-            if (this.log.isDebugEnabled()) this.log.debug("*** AFTER LOAD:\n"
-                    + DebugUtils.convertPropertiesToString(managedProperties));
-            resourceConfig = \
                ConversionUtils.convertManagedObjectToConfiguration(managedProperties,
                
-                    customProps, getResourceContext().getResourceType());
-        }
-        catch (Exception e)
-        {
+            Map<String, PropertySimple> customProps = \
ResourceComponentUtils.getCustomProperties(getResourceContext() +                \
.getPluginConfiguration()); +            if (this.log.isDebugEnabled())
+                this.log.debug("*** AFTER LOAD:\n" + \
DebugUtils.convertPropertiesToString(managedProperties)); +            resourceConfig \
= ConversionUtils.convertManagedObjectToConfiguration(managedProperties, customProps, \
+                getResourceContext().getResourceType()); +        } catch (Exception \
e) {  RunState runState = getManagedComponent().getRunState();
             if (runState == RunState.RUNNING) {
-               this.log.error("Failed to load configuration for " + \
getResourceDescription() + ".", e); +                this.log.error("Failed to load \
configuration for " + getResourceDescription() + ".", e);  } else {
-               this.log.debug("Failed to load configuration for " + \
                getResourceDescription()
-                            + ", but managed component is not in the RUNNING \
state.", e); +                this.log.debug("Failed to load configuration for " + \
getResourceDescription() +                    + ", but managed component is not in \
the RUNNING state.", e);  }
             throw new RuntimeException(ThrowableUtil.getAllMessages(e));
         }
         return resourceConfig;
     }
 
-    public void updateResourceConfiguration(ConfigurationUpdateReport \
                configurationUpdateReport)
-    {
+    public void updateResourceConfiguration(ConfigurationUpdateReport \
                configurationUpdateReport) {
         Configuration resourceConfig = configurationUpdateReport.getConfiguration();
         Configuration pluginConfig = getResourceContext().getPluginConfiguration();
-        try
-        {
+        try {
             ManagedComponent managedComponent = getManagedComponent();
             Map<String, ManagedProperty> managedProperties = \
                managedComponent.getProperties();
             Map<String, PropertySimple> customProps = \
                ResourceComponentUtils.getCustomProperties(pluginConfig);
-            if (this.log.isDebugEnabled()) this.log.debug("*** BEFORE UPDATE:\n"
-                    + DebugUtils.convertPropertiesToString(managedProperties));
+            if (this.log.isDebugEnabled())
+                this.log.debug("*** BEFORE UPDATE:\n" + \
                DebugUtils.convertPropertiesToString(managedProperties));
             ConversionUtils.convertConfigurationToManagedProperties(managedProperties, \
                resourceConfig,
-                    getResourceContext().getResourceType(), customProps);
-            if (this.log.isDebugEnabled()) this.log.debug("*** AFTER UPDATE:\n"
-                    + DebugUtils.convertPropertiesToString(managedProperties));
+                getResourceContext().getResourceType(), customProps);
+            if (this.log.isDebugEnabled())
+                this.log.debug("*** AFTER UPDATE:\n" + \
DebugUtils.convertPropertiesToString(managedProperties));  \
                updateComponent(managedComponent);
             configurationUpdateReport.setStatus(ConfigurationUpdateStatus.SUCCESS);
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             this.log.error("Failed to update configuration for " + \
                getResourceDescription() + ".", e);
             configurationUpdateReport.setStatus(ConfigurationUpdateStatus.FAILURE);
             configurationUpdateReport.setErrorMessage(ThrowableUtil.getAllMessages(e));
 @@ -241,7 +233,7 @@ public class ManagedComponentComponent extends \
                AbstractManagedComponent implemen
                     log.error("Failed to collect metric for " + request, e);
                 } else {
                     log.debug("Failed to collect metric for " + request
-                            + ", but managed component is not in the RUNNING \
state.", e); +                        + ", but managed component is not in the \
RUNNING state.", e);  }
             }
         }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic