Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Bug 822250 - Tomcat6 mod_cluster config file
Browse files Browse the repository at this point in the history
  • Loading branch information
maxime-beck committed Feb 17, 2015
1 parent 289920a commit 03b9174
Show file tree
Hide file tree
Showing 10 changed files with 740 additions and 890 deletions.
Expand Up @@ -23,42 +23,82 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.mc4j.ems.connection.bean.EmsBean;
import org.mc4j.ems.connection.bean.attribute.EmsAttribute;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.ConfigurationUpdateStatus;
import org.rhq.core.domain.configuration.definition.PropertyDefinition;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
import org.rhq.core.util.exception.ThrowableUtil;
import org.rhq.plugins.jmx.JMXComponent;
import org.rhq.plugins.jmx.MBeanResourceComponent;
import org.rhq.plugins.modcluster.config.JBossWebServerFile;
import org.rhq.core.pluginapi.operation.OperationResult;

@SuppressWarnings({ "deprecation" })
public class CatalinaServiceComponent extends MBeanResourceComponent<JMXComponent<?>> {
import org.rhq.plugins.modcluster.ModClusterServerComponent.SupportedOperations;

/**
* @author Stefan Negrea, Maxime Beck
*/

@SuppressWarnings({"deprecation"})
public class CatalinaServiceComponent extends MBeanResourceComponent {

private static final Log log = LogFactory.getLog(CatalinaServiceComponent.class);

private final static String MOD_CLUSTER_CONFIG_FILE = "modclusterConfigFile";
private static final String MOD_CLUSTER_MBEAN_NAME = "Catalina:type=ModClusterListener";

private ModClusterOperationsDelegate operationsDelegate;

public CatalinaServiceComponent() {
this.operationsDelegate = new ModClusterOperationsDelegate((MBeanResourceComponent) this);
}

@Override
public void updateResourceConfiguration(ConfigurationUpdateReport report) {
//Update JMX properties
super.updateResourceConfiguration(report);

if (report.getStatus() == ConfigurationUpdateStatus.SUCCESS) {
//Propagate the JMX configuration updates to HTTPD
try {
super.invokeOperation("refresh", new Configuration());
} catch (Exception e) {
report.setErrorMessage("Failed to save the resource configuration to file. " + e.getMessage());
}
public Configuration loadResourceConfiguration() {
Configuration configuration = new Configuration();
ConfigurationDefinition configurationDefinition = this.resourceContext.getResourceType()
.getResourceConfigurationDefinition();

try {
EmsBean bean = getEmsConnection().getBean(MOD_CLUSTER_MBEAN_NAME);

//Persist configuration changes to configuration file
if (report.getStatus() == ConfigurationUpdateStatus.SUCCESS) {
saveResouceConfigurationToFile(report, true);
for (PropertyDefinition property : configurationDefinition.getPropertyDefinitions().values()) {
if (property instanceof PropertyDefinitionSimple) {
EmsAttribute attribute = bean.getAttribute(property.getName());
if (attribute != null) {
configuration.put(new PropertySimple(property.getName(), attribute.refresh()));
}
}
}
} catch (Exception e) {
log.debug("Unable to load mod_cluster configuration file.", e);
}

return configuration;
}

@Override
public void updateResourceConfiguration(ConfigurationUpdateReport report) {
this.saveResouceConfigurationToFile(report, false);

try {
storeConfig();
} catch (Exception e) {
report.setErrorMessage("Failed to persist configuration change.");
}
}

void storeConfig() throws Exception {
invokeOperation(SupportedOperations.STORECONFIG.name(), new Configuration());
}

public OperationResult invokeOperation(String name, Configuration parameters) throws InterruptedException,
Exception {
SupportedOperations operation = Enum.valueOf(SupportedOperations.class, name.toUpperCase());
return this.operationsDelegate.invoke(operation, parameters);
}

@Override
Expand All @@ -72,50 +112,60 @@ protected Object getPropertyValueAsType(PropertySimple propSimple, String typeNa

private void saveResouceConfigurationToFile(ConfigurationUpdateReport report, boolean ignoreReadOnly) {
ConfigurationDefinition configurationDefinition = this.getResourceContext().getResourceType()
.getResourceConfigurationDefinition();
.getResourceConfigurationDefinition();
EmsBean bean = null;

// assume we succeed - we'll set to failure if we can't set all properties
report.setStatus(ConfigurationUpdateStatus.SUCCESS);

try {
JBossWebServerFile jbossWebServerFile = getJBossWebServerFileInstance();

for (String key : report.getConfiguration().getSimpleProperties().keySet()) {
PropertySimple property = report.getConfiguration().getSimple(key);
if (property != null) {
try {
PropertyDefinitionSimple def = configurationDefinition.getPropertyDefinitionSimple(property
for (String key : report.getConfiguration().getSimpleProperties().keySet()) {
PropertySimple property = report.getConfiguration().getSimple(key);
if (property != null) {
try {
if(null == bean)
bean = getEmsConnection().getBean(MOD_CLUSTER_MBEAN_NAME);
EmsAttribute attribute = bean.getAttribute(key);
if (attribute == null) {
log.debug("Removing " + key + " does correspond to an attribut");
report.getConfiguration().remove(key);
continue; // skip unsupported attributes
}
PropertyDefinitionSimple def = configurationDefinition.getPropertyDefinitionSimple(property
.getName());
if (!(ignoreReadOnly && def.isReadOnly())) {
jbossWebServerFile.setPropertyValue(property.getName(), property.getStringValue());
if (!(ignoreReadOnly && def.isReadOnly())) {
switch (def.getType()) {
case INTEGER: {
if (property.getIntegerValue() != null)
attribute.setValue(property.getIntegerValue());
break;
}

case LONG: {
if (property.getLongValue() != null)
attribute.setValue(property.getLongValue());
break;
}

case BOOLEAN: {
if (property.getBooleanValue() != null)
attribute.setValue(property.getBooleanValue());
break;
}

/*With StoreConfig, every other types are Sting*/
default: {
if (property.getStringValue() != null)
attribute.setValue(property.getStringValue());
break;
}
}
} catch (Exception e) {
property.setErrorMessage(ThrowableUtil.getStackAsString(e));
report.setErrorMessage("Failed setting resource configuration. " + e.getMessage());
log.info("Failure setting MBean Resource configuration value for " + key, e);
}
} catch (Exception e) {
property.setErrorMessage(ThrowableUtil.getStackAsString(e));
report.setErrorMessage("Failed setting resource configuration - see property error messages for details");
log.info("Failure setting MBean Resource configuration value for " + key, e);
}
}

jbossWebServerFile.saveConfigurationFile();
} catch (Exception e) {
report.setErrorMessage("Failed to save the resource configuration to file. " + e.getMessage());
log.debug("Unable to save mod_cluster configuration file.", e);
}
}

private JBossWebServerFile getJBossWebServerFileInstance() throws Exception {
ModClusterServerComponent modClusterComponent = (ModClusterServerComponent) this.resourceContext
.getParentResourceComponent();

PropertySimple property = modClusterComponent.getResourceContext().getPluginConfiguration()
.getSimple(MOD_CLUSTER_CONFIG_FILE);

if (property != null) {
String fileName = property.getStringValue();
return new JBossWebServerFile(fileName);
}

return null;
}
}

This file was deleted.

This file was deleted.

0 comments on commit 03b9174

Please sign in to comment.