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

Commit

Permalink
Bug 1140676 - Exception logged while inventorying EAP 6 host controll…
Browse files Browse the repository at this point in the history
…er after setting http-interface

Throw IPCE when security realm is not ready so that a proper resource
error shows up in the GUI.

(cherry picked from commit 9c1d53d)
Signed-off-by: Libor Zoubek <lzoubek@redhat.com>
  • Loading branch information
tsegismont authored and Libor Zoubek committed Sep 26, 2014
1 parent b223cef commit 1101df8
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 51 deletions.
Expand Up @@ -60,7 +60,6 @@
import org.rhq.core.pluginapi.inventory.CreateChildResourceFacet;
import org.rhq.core.pluginapi.inventory.CreateResourceReport;
import org.rhq.core.pluginapi.inventory.DeleteResourceFacet;
import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceComponent;
import org.rhq.core.pluginapi.inventory.ResourceContext;
import org.rhq.core.pluginapi.measurement.MeasurementFacet;
Expand All @@ -78,6 +77,7 @@
import org.rhq.modules.plugins.jbossas7.json.ResolveExpression;
import org.rhq.modules.plugins.jbossas7.json.Result;
import org.rhq.modules.plugins.jbossas7.json.ResultFailedException;
import org.rhq.modules.plugins.jbossas7.json.SecurityRealmNotReadyException;

/**
* The base class for all AS7 resource components.
Expand Down Expand Up @@ -121,22 +121,15 @@ public class BaseComponent<T extends ResourceComponent<?>> implements AS7Compone
* @see org.rhq.core.pluginapi.inventory.ResourceComponent#start(org.rhq.core.pluginapi.inventory.ResourceContext)
*/
@Override
public void start(ResourceContext<T> context) throws InvalidPluginConfigurationException, Exception {
public void start(ResourceContext<T> context) throws Exception {
this.context = context;
pluginConfiguration = context.getPluginConfiguration();
serverComponent = findServerComponent();
path = pluginConfiguration.getSimpleValue("path");
address = new Address(path);
key = context.getResourceKey();
myServerName = context.getResourceKey().substring(context.getResourceKey().lastIndexOf("/") + 1);

PropertySimple includeRuntimeProperty = pluginConfiguration.getSimple("includeRuntime");
if (includeRuntimeProperty != null && includeRuntimeProperty.getBooleanValue() != null
&& includeRuntimeProperty.getBooleanValue()) {
includeRuntime = true;
} else {
includeRuntime = false;
}
includeRuntime = Boolean.parseBoolean(pluginConfiguration.getSimpleValue("includeRuntime", null));
}

@Override
Expand Down Expand Up @@ -225,7 +218,7 @@ protected ReadMetricResult getMetricValue(MeasurementReport report, MeasurementS
complexRequest = ComplexRequest.create(reqName);
op = new ReadAttribute(address, complexRequest.getProp());
} else {
op = new ReadAttribute(address, reqName); // TODO batching
op = new ReadAttribute(address, reqName);
}

Result res = getASConnection().execute(op);
Expand All @@ -246,7 +239,8 @@ protected ReadMetricResult getMetricValue(MeasurementReport report, MeasurementS
return ReadMetricResult.Null;
try {
if (complexRequest != null) {
HashMap<String, Number> myValues = (HashMap<String, Number>) val;
@SuppressWarnings("unchecked")
Map<String, Number> myValues = (Map<String, Number>) val;
for (String key : myValues.keySet()) {
String sub = complexRequest.getSub();
if (key.equals(sub)) {
Expand Down Expand Up @@ -308,7 +302,7 @@ private void addMetric2Report(MeasurementReport report, MeasurementScheduleReque
}

protected String getStringValue(Object val) {
String realVal = "";
String realVal;
if (val instanceof String)
realVal = (String) val;
else
Expand Down Expand Up @@ -418,19 +412,6 @@ public void deleteResource() throws Exception {
if (!res.isSuccess()) {
throw new IllegalArgumentException("Delete for [" + path + "] failed: " + res.getFailureDescription());
}
if (path.contains("server-group")) {
// This was a server group level deployment - TODO do we also need to remove the entry in /deployments ?
/*
for (PROPERTY_VALUE val : address) {
if (val.getKey().equals("deployment")) {
ComplexResult res2 = connection.executeComplex(new Operation("remove",val.getKey(),val.getValue()));
if (!res2.isSuccess())
throw new IllegalArgumentException("Removal of [" + path + "] falied : " + res2.getFailureDescription());
}
}
*/
}
}

@Override
Expand All @@ -456,6 +437,7 @@ public CreateResourceReport createResource(CreateResourceReport report) {
ReadChildrenNames op = new ReadChildrenNames(address, pathProperty.getStringValue());
Result res = connection.execute(op);
if (res.isSuccess()) {
@SuppressWarnings("unchecked")
List<String> entries = (List<String>) res.getResult();
if (!entries.isEmpty()) {
report.setErrorMessage("Resource is a singleton, but there are already children " + entries
Expand Down Expand Up @@ -499,7 +481,7 @@ protected CreateResourceReport deployContent(CreateResourceReport report) {
return report;
}

long size = 0L;
long size;
try {
size = contentServices.downloadPackageBitsForChildResource(cctx, resourceTypeName, details.getKey(), out);
} catch (Exception e) {
Expand Down Expand Up @@ -633,8 +615,7 @@ public CreateResourceReport runDeploymentMagicOnServer(CreateResourceReport repo
}

@Override
public OperationResult invokeOperation(String name, Configuration parameters) throws InterruptedException,
Exception {
public OperationResult invokeOperation(String name, Configuration parameters) throws Exception {

String what;
String op;
Expand All @@ -647,7 +628,7 @@ public OperationResult invokeOperation(String name, Configuration parameters) th
what = ""; // dummy value
op = name;
}
Operation operation = null;
Operation operation;

Address theAddress = new Address();

Expand Down Expand Up @@ -681,7 +662,7 @@ public OperationResult invokeOperation(String name, Configuration parameters) th
if (type.equals("jms-queue")) {
PropertySimple ps = (PropertySimple) parameters.get("durable");
if (ps != null) {
boolean durable = ps.getBooleanValue();
boolean durable = Boolean.parseBoolean(ps.getStringValue());
operation.addAdditionalProperty("durable", durable);
}
String selector = parameters.getSimpleValue("selector", "");
Expand Down Expand Up @@ -844,7 +825,6 @@ private Object getObjectForProperty(PropertySimple prop, PropertySimpleType type
}

///// These two are used to 'inject' the connection and the path from tests.
// TODO: Refactor this - we should be able to mock the ResourceContext passed to start() instead.
public void setConnection(ASConnection connection) {
this.testConnection = connection;
}
Expand Down Expand Up @@ -874,27 +854,33 @@ protected String readAttribute(Address address, String name, int timeoutSec) thr
return readAttribute(address, name, String.class, timeoutSec);
}

protected <T> T readAttribute(Address address, String name, Class<T> resultType) throws Exception {
protected <R> R readAttribute(Address address, String name, Class<R> resultType) throws Exception {
return readAttribute(address, name, resultType, 10);
}

protected <T> T readAttribute(Address address, String name, Class<T> resultType, int timeoutSec) throws Exception {
protected <R> R readAttribute(Address address, String name, Class<R> resultType, int timeoutSec) throws Exception {
Operation op = new ReadAttribute(address, name);
Result res = getASConnection().execute(op, timeoutSec);

if (!res.isSuccess()) {
if (res.isTimedout()) {
throw new TimeoutException("Read attribute operation timed out");
}

if (res.isRolledBack() && !res.getFailureDescription().startsWith("JBAS015135")) { // this means we've connected, authenticated, but still failed
if (res.isRolledBack() && !res.getFailureDescription().startsWith("JBAS015135")) {
// this means we've connected, authenticated, but still failed
throw new ResultFailedException("Failed to read attribute [" + name + "] of address ["
+ getAddress().getPath() + "] - response: " + res);
}

if (res.isRolledBack() && res.getFailureDescription().startsWith("JBAS015135")) {
// this means we've connected, authenticated, but still failed
throw new SecurityRealmNotReadyException("Failed to read attribute [" + name + "] of address ["
+ getAddress().getPath() + "] - response: " + res);
}
throw new Exception("Failed to read attribute [" + name + "] of address [" + getAddress().getPath()
+ "] - response: " + res);
}
return (T) res.getResult();

return resultType.cast(res.getResult());
}

protected Address getServerAddress() {
Expand Down Expand Up @@ -927,6 +913,7 @@ protected void collectMulticastAddressTrait(MeasurementReport report, Measuremen
Integer multicastPort;
try {
try {
@SuppressWarnings("unchecked")
Map<String, String> map = readAttribute(jgroupsSocketBindingAddress, "multicast-address", Map.class);
String expressionValue = map.get("EXPRESSION_VALUE");
int beginIndex = expressionValue.indexOf("${jboss.default.multicast.address");
Expand Down
Expand Up @@ -64,7 +64,6 @@
import org.rhq.core.pluginapi.measurement.MeasurementFacet;
import org.rhq.core.pluginapi.operation.OperationResult;
import org.rhq.core.pluginapi.util.StartScriptConfiguration;
import org.rhq.core.system.ProcessExecution;
import org.rhq.core.system.ProcessExecutionResults;
import org.rhq.core.system.ProcessInfo;
import org.rhq.core.util.PropertiesFileUpdate;
Expand All @@ -81,6 +80,7 @@
import org.rhq.modules.plugins.jbossas7.json.ReadResource;
import org.rhq.modules.plugins.jbossas7.json.Result;
import org.rhq.modules.plugins.jbossas7.json.ResultFailedException;
import org.rhq.modules.plugins.jbossas7.json.SecurityRealmNotReadyException;

/**
* Base component for functionality that is common to Standalone Servers and Host Controllers.
Expand Down Expand Up @@ -127,6 +127,7 @@ public void stop() {
@Override
public AvailabilityType getAvailability() {
AvailabilityType availabilityType;
boolean securityRealmReady = true;
try {
try {
readAttribute(getHostAddress(), "name", AVAIL_OP_TIMEOUT_SECONDS);
Expand All @@ -138,6 +139,10 @@ public AvailabilityType getAvailability() {
LOG.info("Detected domain host name [" + getASHostName() + "]");
readAttribute(getHostAddress(), "name");
availabilityType = UP;
} catch (SecurityRealmNotReadyException e) {
previousAvailabilityType = DOWN;
availabilityType = DOWN;
securityRealmReady = false;
}
} catch (TimeoutException e) {
long now = new Date().getTime();
Expand All @@ -159,6 +164,11 @@ public AvailabilityType getAvailability() {
availabilityType = DOWN;
}

if (!securityRealmReady) {
throw new InvalidPluginConfigurationException("The security realm of the HTTP management interface"
+ " is not ready to process requests. This usually indicates that no user is configured");
}

if (availabilityType == DOWN) {
releaseVersion = null;
} else if (previousAvailabilityType != UP) {
Expand Down Expand Up @@ -291,7 +301,6 @@ public ASConnection getASConnection() {
return connection;
}

// TODO: Refactor this - we should be able to mock the ResourceContext passed to start() instead.
@Override
public void setConnection(ASConnection connection) {
this.connection = connection;
Expand Down Expand Up @@ -383,7 +392,7 @@ protected boolean waitUntilDown() throws InterruptedException {
Thread.sleep(SECONDS.toMillis(1));
}
}
return notAnswering;
return true;
}

/**
Expand Down Expand Up @@ -490,10 +499,7 @@ protected OperationResult runCliCommand(Configuration parameters) throws Interru
}

public boolean isManuallyAddedServer() {
if (pluginConfiguration.get("manuallyAdded") != null) {
return true;
}
return false;
return pluginConfiguration.get("manuallyAdded") != null;
}

private boolean isManuallyAddedServer(OperationResult operationResult, String operation) {
Expand Down Expand Up @@ -578,7 +584,7 @@ private boolean waitForServerToStart() throws InterruptedException {
Thread.sleep(SECONDS.toMillis(1));
}
}
return up;
return true;
}

/**
Expand Down Expand Up @@ -969,7 +975,7 @@ protected BundleHandoverResponse deployPatch(BundleHandoverRequest request) {
} catch (IOException e) {
return BundleHandoverResponse
.failure(BundleHandoverResponse.FailureType.EXECUTION,
"Failed to create a temp file to copy patch to.");
"Failed to create a temp file to copy patch to.");
}

try {
Expand All @@ -984,13 +990,12 @@ protected BundleHandoverResponse deployPatch(BundleHandoverRequest request) {
if (parameters != null) {
for (Map.Entry<String, String> e : parameters.entrySet()) {
String name = e.getKey();
String value = e.getValue();

if (!("override".equals(name) || "override-all".equals(name) || "preserve".equals(name) ||
"override-modules".equals(name))) {
return BundleHandoverResponse.failure(INVALID_PARAMETER,
"'" + name +
"' is not a supported parameter. Only 'override', 'override-all', 'preserve' and 'override-modules' are supported.");
"'" + name +
"' is not a supported parameter. Only 'override', 'override-all', 'preserve' and 'override-modules' are supported.");
}
}
}
Expand Down Expand Up @@ -1052,7 +1057,7 @@ private String deployPatch(File patchFile, Map<String, String> additionalParams)

protected String collectPatches() {
ProcessExecutionResults results = ServerControl.onServer(context.getPluginConfiguration(), getMode(),
context.getSystemInformation())
context.getSystemInformation())
.cli().disconnected(true).executeCliCommand("patch info");

if (results.getError() != null) {
Expand Down
@@ -0,0 +1,34 @@
/*
* RHQ Management Platform
* Copyright (C) 2005-2014 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;

/**
* Denotes JBAS015135: The security realm is not ready to process requests. This usually indicates that no user is
* configured.
*
* @author Thomas Segismont
*/
public class SecurityRealmNotReadyException extends Exception {
private static final long serialVersionUID = 1L;

public SecurityRealmNotReadyException(String message) {
super(message);
}
}

0 comments on commit 1101df8

Please sign in to comment.