This repository has been archived by the owner on Jul 11, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1191727 - EAP 6 management plug-in fails to discover managed serv…
…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
Showing
5 changed files
with
132 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...ns/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/ExpressionResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
289920a
There was a problem hiding this comment.
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.
289920a
There was a problem hiding this comment.
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.
289920a
There was a problem hiding this comment.
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