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

Commit

Permalink
Bug 1191727 - EAP 6 management plug-in fails to discover managed serv…
Browse files Browse the repository at this point in the history
…ers if

any of them use an expression for their auto-start or
socket-binding-port-offset attributes

Configuration loading for ManagedASComponent was updated so it also properly
evaluates expressions. RHQ Server then stores already evaluated values, this
would result overwriting expressions once configuration is updated.

Resolve auto-start or offset attributes in case they're expressions. This
commit also adds expressionResolver to BaseServerComponent for future use.
Note: EAP operation :resolve-expression is not defined on domain controller
in / address, but it is on individual /host=master host levels - thus
evaluates the expression in host's context.

x
  • Loading branch information
Libor Zoubek committed Feb 16, 2015
1 parent 9065488 commit 289920a
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 7 deletions.
Expand Up @@ -30,8 +30,6 @@
import static org.rhq.modules.plugins.jbossas7.util.ProcessExecutionLogger.logExecutionResults;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -69,12 +67,12 @@
import org.rhq.core.util.PropertiesFileUpdate;
import org.rhq.core.util.StringUtil;
import org.rhq.core.util.file.FileUtil;
import org.rhq.core.util.stream.StreamUtil;
import org.rhq.modules.plugins.jbossas7.helper.HostConfiguration;
import org.rhq.modules.plugins.jbossas7.helper.HostPort;
import org.rhq.modules.plugins.jbossas7.helper.ServerPluginConfiguration;
import org.rhq.modules.plugins.jbossas7.json.Address;
import org.rhq.modules.plugins.jbossas7.json.ComplexResult;
import org.rhq.modules.plugins.jbossas7.json.ExpressionResolver;
import org.rhq.modules.plugins.jbossas7.json.Operation;
import org.rhq.modules.plugins.jbossas7.json.ReadAttribute;
import org.rhq.modules.plugins.jbossas7.json.ReadResource;
Expand Down Expand Up @@ -103,6 +101,7 @@ public abstract class BaseServerComponent<T extends ResourceComponent<?>> extend
private String releaseVersion;
private String aSHostName;
private long lastManagementInterfaceReply = 0;
private ExpressionResolver expressionResolver;

@Override
public void start(ResourceContext<T> resourceContext) throws Exception {
Expand All @@ -115,6 +114,7 @@ public void start(ResourceContext<T> resourceContext) throws Exception {
logFileEventDelegate = new LogFileEventResourceComponentHelper(context);
logFileEventDelegate.startLogFileEventPollers();
startScriptConfig = new StartScriptConfiguration(pluginConfiguration);
expressionResolver = new ExpressionResolver(connection, getHostAddress());
}

@Override
Expand Down Expand Up @@ -890,6 +890,10 @@ protected String findASDomainHostName() {
return findASDomainHostName(getASConnection());
}

protected ExpressionResolver getExpressionResolver() {
return expressionResolver;
}

/**
* Reads local-host-name attribute
*
Expand Down
Expand Up @@ -42,6 +42,7 @@
import org.rhq.modules.plugins.jbossas7.helper.JdrReportRunner;
import org.rhq.modules.plugins.jbossas7.json.Address;
import org.rhq.modules.plugins.jbossas7.json.ComplexResult;
import org.rhq.modules.plugins.jbossas7.json.ExpressionResolver;
import org.rhq.modules.plugins.jbossas7.json.Operation;
import org.rhq.modules.plugins.jbossas7.json.ReadAttribute;
import org.rhq.modules.plugins.jbossas7.json.ReadResource;
Expand Down Expand Up @@ -229,7 +230,7 @@ public Configuration loadResourceConfiguration() throws Exception {
throw new Exception("Failed to extract hostname from server path [" + serverPath + "].", e);
}
configuration.put(new PropertySimple("hostname", serverPath));

ExpressionResolver resolver = getServerComponent().getExpressionResolver();
Operation op = new ReadResource(getAddress());
ComplexResult res = getASConnection().executeComplex(op);
if (res.isSuccess()) {
Expand All @@ -244,7 +245,9 @@ public Configuration loadResourceConfiguration() throws Exception {
sbGroup = (String) sgMap.get("socket-binding-group");

configuration.put(new PropertySimple("socket-binding-group", sbGroup));
Integer offSet = (Integer) map.get("socket-binding-port-offset");
Boolean autoStart = resolver.getBoolean(map.get("auto-start"));
configuration.put(new PropertySimple("auto-start", autoStart));
Integer offSet = resolver.getInteger(map.get("socket-binding-port-offset"));
if (offSet == null)
offSet = 0;
configuration.put(new PropertySimple("socket-binding-port-offset", offSet));
Expand Down
Expand Up @@ -40,6 +40,7 @@
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
import org.rhq.modules.plugins.jbossas7.json.Address;
import org.rhq.modules.plugins.jbossas7.json.ComplexResult;
import org.rhq.modules.plugins.jbossas7.json.ExpressionResolver;
import org.rhq.modules.plugins.jbossas7.json.Operation;
import org.rhq.modules.plugins.jbossas7.json.ReadAttribute;
import org.rhq.modules.plugins.jbossas7.json.ReadChildrenNames;
Expand All @@ -66,6 +67,8 @@ public Set<DiscoveredResourceDetails> discoverResources(
parentComponent = discoveryContext.getParentResourceComponent();
Configuration hcConfig = discoveryContext.getParentResourceContext().getPluginConfiguration();
String hostName = parentComponent.getASHostName();

// TODO verify we don't need this anymore
if (hostName==null) {
hostName = getHostName(discoveryContext.getParentResourceComponent().getASConnection());
}
Expand Down Expand Up @@ -179,6 +182,7 @@ private List<ServerInfo> getManagedServers(String domainHost) {
Result res = connection.execute(operation);
List<String> servers = (List<String>) res.getResult();
List<ServerInfo> ret = new ArrayList<ServerInfo>(servers.size());
ExpressionResolver resolver = parentComponent.getExpressionResolver();
for (String server : servers) {
ServerInfo info = new ServerInfo();
info.name = server;
Expand All @@ -190,8 +194,8 @@ private List<ServerInfo> getManagedServers(String domainHost) {
ComplexResult cres = connection.executeComplex(operation);
Map<String, Object> map = cres.getResult();
info.group = (String) map.get("group");
info.autoStart = (Boolean) map.get("auto-start");
Integer offset = (Integer) map.get("socket-binding-port-offset");
info.autoStart = resolver.getBoolean(map.get("auto-start"));
Integer offset = resolver.getInteger(map.get("socket-binding-port-offset"));
if (offset != null)
info.portOffset = offset;
info.bindingGroup = (String) map.get("socket-binding-group");
Expand Down
@@ -0,0 +1,109 @@
/*
* RHQ Management Platform
* Copyright (C) 2005-2015 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation version 2 of the License.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.modules.plugins.jbossas7.json;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.rhq.modules.plugins.jbossas7.ASConnection;

/**
* @author lzoubek
* Expression resovler can be used for possibly resolving given object value returned by {@link Result}. Expression resolver detects,
* if given object is expression and if so, resolves it (by asking AS7 server).
*/
public class ExpressionResolver {

private static final Log LOG = LogFactory.getLog(ExpressionResolver.class);
private final ASConnection connection;
private final Address address;

public ExpressionResolver(ASConnection connection, Address address) {
this.connection = connection;
this.address = address;
}

/**
* @see ExpressionResolver#resolve(Object)
*/
public Boolean getBoolean(Object value) {
Object resolved = resolve(value);
if (resolved == null) {
return null;
}
if (resolved instanceof Boolean) {
return (Boolean) resolved;
}
return Boolean.valueOf(resolved.toString());
}

/**
* @see ExpressionResolver#resolve(Object)
*/
public Integer getInteger(Object value) {
Object resolved = resolve(value);
if (resolved == null) {
return null;
}
if (resolved instanceof Integer) {
return (Integer) resolved;
}
return Integer.valueOf(resolved.toString());
}

/**
* @see ExpressionResolver#resolve(Object)
*/
public String getString(Object value) {
return (String) resolve(value);
}

/**
* Resolves given value if it is an expression (it must be a map with exactly 1 key called 'EXPRESSION_VALUE')
* @param value to be resolved
* @return resolved value or unchanged value if value is not an expression or failed to resolve
*/
@SuppressWarnings("rawtypes")
public Object resolve(Object value) {
if (value == null) {
return value;
}
if (value instanceof Map) {
Map map = (Map) value;
if (map.size() == 1) {
String expression = (String) map.get("EXPRESSION_VALUE");
if (expression != null) {
ResolveExpression resolveExpressionOperation = new ResolveExpression(expression, this.address);
Result result = connection.execute(resolveExpressionOperation);
if (!result.isSuccess()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Could not resolve expression value " + value + " due to error "
+ result.getFailureDescription());
}
return value;
}
return result.getResult();
}
}
}
return value;
}
}
Expand Up @@ -29,4 +29,9 @@ public ResolveExpression(String expression) {
addAdditionalProperty("expression", expression);
}

public ResolveExpression(String expression, Address address) {
super("resolve-expression", address);
addAdditionalProperty("expression", expression);
}

}

3 comments on commit 289920a

@tsegismont
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Libor.

This new ExpressionResolver class might be handy, but why not ask the server to resolve expressions while sending the initial request for discovery? That would avoid an additional roundtrip.

@lzoubek
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? I did not find a way to make server to resolve expressions when calling read-resource or read-children-names.

@tsegismont
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry Libor, my bad. I had in mind that it was available in AS7/EAP6. It's coming with Wildfly only:
https://issues.jboss.org/browse/WFCORE-119

Please sign in to comment.