Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFCORE-949] : Removing http-interface autocompletes but fails. #1089

Merged
merged 1 commit into from
Sep 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,33 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.jboss.as.host.controller.operations;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.MANAGEMENT_INTERFACE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NATIVE_INTERFACE;
import static org.jboss.as.host.controller.resources.HttpManagementResourceDefinition.HTTP_MANAGEMENT_CAPABILITY;

import java.util.Collections;

import org.jboss.as.controller.AbstractRemoveStepHandler;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ProcessType;
import org.jboss.as.host.controller.HostControllerEnvironment;
import org.jboss.as.remoting.RemotingHttpUpgradeService;
import org.jboss.as.remoting.RemotingServices;
import org.jboss.as.controller.ReloadRequiredRemoveStepHandler;
import org.jboss.as.remoting.management.ManagementRemotingServices;
import org.jboss.as.server.mgmt.UndertowHttpManagementService;
import org.jboss.dmr.ModelNode;

/**
* Removes the HTTP management interface.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
public class HttpManagementRemoveHandler extends AbstractRemoveStepHandler {
public class HttpManagementRemoveHandler extends ReloadRequiredRemoveStepHandler {

private final LocalHostControllerInfoImpl hostControllerInfo;
private final HostControllerEnvironment environment;
public static final HttpManagementRemoveHandler INSTANCE = new HttpManagementRemoveHandler();

public HttpManagementRemoveHandler(final LocalHostControllerInfoImpl hostControllerInfo, final HostControllerEnvironment environment) {
public HttpManagementRemoveHandler() {
super(HTTP_MANAGEMENT_CAPABILITY);
this.hostControllerInfo = hostControllerInfo;
this.environment = environment;
}

@Override
Expand All @@ -59,20 +54,12 @@ protected boolean requiresRuntime(OperationContext context) {
}

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
context.removeService(UndertowHttpManagementService.SERVICE_NAME);
context.removeService(UndertowHttpManagementService.SERVICE_NAME.append("requests"));
context.removeService(UndertowHttpManagementService.SERVICE_NAME.append("shutdown"));

RemotingServices.removeConnectorServices(context, ManagementRemotingServices.HTTP_CONNECTOR);
context.removeService(RemotingHttpUpgradeService.UPGRADE_SERVICE_NAME.append(ManagementRemotingServices.HTTP_CONNECTOR));
clearHostControllerInfo(hostControllerInfo);
}

@Override
protected void recoverServices(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
HttpManagementAddHandler.populateHostControllerInfo(hostControllerInfo, context, model);
HttpManagementAddHandler.installHttpManagementServices(environment, hostControllerInfo, context, model);
protected void performRemove(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final PathAddress nativeAddress = context.getCurrentAddress().getParent().append(PathElement.pathElement(MANAGEMENT_INTERFACE, NATIVE_INTERFACE));
context.addStep((OperationContext opContext, ModelNode op) -> {
ManagementRemotingServices.isManagementResourceRemoveable(opContext, nativeAddress);
}, OperationContext.Stage.MODEL, false);
super.performRemove(context, operation, model);
}

static void clearHostControllerInfo(LocalHostControllerInfoImpl hostControllerInfo) {
Expand All @@ -81,6 +68,6 @@ static void clearHostControllerInfo(LocalHostControllerInfoImpl hostControllerIn
hostControllerInfo.setHttpManagementSecureInterface(null);
hostControllerInfo.setHttpManagementSecurePort(0);
hostControllerInfo.setHttpManagementSecurityRealm(null);
hostControllerInfo.setAllowedOrigins(Collections.EMPTY_LIST);
hostControllerInfo.setAllowedOrigins(Collections.emptyList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2015 Red Hat, inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.jboss.as.host.controller.operations;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HTTP_INTERFACE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.MANAGEMENT_INTERFACE;
import static org.jboss.as.host.controller.resources.NativeManagementResourceDefinition.NATIVE_MANAGEMENT_CAPABILITY;

import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ProcessType;
import org.jboss.as.controller.ReloadRequiredRemoveStepHandler;
import org.jboss.as.remoting.management.ManagementRemotingServices;
import org.jboss.dmr.ModelNode;

/**
*
* @author <a href="mailto:ehugonne@redhat.com">Emmanuel Hugonnet</a> (c) 2015 Red Hat, inc.
*/
public class NativeManagementRemoveHandler extends ReloadRequiredRemoveStepHandler {

public static final NativeManagementRemoveHandler INSTANCE = new NativeManagementRemoveHandler();

public NativeManagementRemoveHandler() {
super(NATIVE_MANAGEMENT_CAPABILITY);
}

@Override
protected boolean requiresRuntime(OperationContext context) {
return (context.getProcessType() != ProcessType.EMBEDDED_HOST_CONTROLLER);
}

@Override
protected void performRemove(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final PathAddress httpAddress = context.getCurrentAddress().getParent().append(PathElement.pathElement(MANAGEMENT_INTERFACE, HTTP_INTERFACE));
context.addStep((OperationContext opContext, ModelNode op) -> {
ManagementRemotingServices.isManagementResourceRemoveable(opContext, httpAddress);
}, OperationContext.Stage.MODEL, false);
super.performRemove(context, operation, model);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public HttpManagementResourceDefinition(final LocalHostControllerInfoImpl hostCo
super(RESOURCE_PATH,
HostModelUtil.getResourceDescriptionResolver("core", "management", "http-interface"),
new HttpManagementAddHandler(hostControllerInfo, environment),
new HttpManagementRemoveHandler(hostControllerInfo, environment),
OperationEntry.Flag.RESTART_NONE, OperationEntry.Flag.RESTART_NONE);
HttpManagementRemoveHandler.INSTANCE,
OperationEntry.Flag.RESTART_NONE, OperationEntry.Flag.RESTART_RESOURCE_SERVICES);
this.accessConstraints = SensitiveTargetAccessConstraintDefinition.MANAGEMENT_INTERFACES.wrapAsList();
setDeprecated(ModelVersion.create(1, 7));
}
Expand All @@ -162,9 +162,4 @@ public void registerAttributes(ManagementResourceRegistration resourceRegistrati
public List<AccessConstraintDefinition> getAccessConstraints() {
return accessConstraints;
}

@Override
public void registerCapabilities(ManagementResourceRegistration resourceRegistration) {
resourceRegistration.registerCapability(HTTP_MANAGEMENT_CAPABILITY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.jboss.as.host.controller.operations.LocalHostControllerInfoImpl;
import org.jboss.as.host.controller.operations.NativeManagementAddHandler;
import org.jboss.as.host.controller.operations.NativeManagementWriteAttributeHandler;
import org.jboss.as.server.operations.NativeManagementRemoveHandler;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;

Expand Down Expand Up @@ -102,8 +103,8 @@ public class NativeManagementResourceDefinition extends SimpleResourceDefinition
public NativeManagementResourceDefinition(final LocalHostControllerInfoImpl hostControllerInfo) {
super(RESOURCE_PATH,
HostModelUtil.getResourceDescriptionResolver("core","management","native-interface"),
new NativeManagementAddHandler(hostControllerInfo), null,
OperationEntry.Flag.RESTART_NONE, null);
new NativeManagementAddHandler(hostControllerInfo), NativeManagementRemoveHandler.INSTANCE,
OperationEntry.Flag.RESTART_NONE, OperationEntry.Flag.RESTART_RESOURCE_SERVICES);
this.accessConstraints = SensitiveTargetAccessConstraintDefinition.MANAGEMENT_INTERFACES.wrapAsList();
setDeprecated(ModelVersion.create(1, 7));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
*/
package org.jboss.as.jmx;

import static org.jboss.as.jmx.CommonAttributes.JMX;
Expand All @@ -45,8 +45,8 @@
public class RemotingConnectorResource extends SimpleResourceDefinition {

static final PathElement REMOTE_CONNECTOR_CONFIG_PATH = PathElement.pathElement(REMOTING_CONNECTOR, JMX);
static final SimpleAttributeDefinition USE_MANAGEMENT_ENDPOINT =
new SimpleAttributeDefinitionBuilder(CommonAttributes.USE_MANAGEMENT_ENDPOINT, ModelType.BOOLEAN, true)
static final SimpleAttributeDefinition USE_MANAGEMENT_ENDPOINT
= new SimpleAttributeDefinitionBuilder(CommonAttributes.USE_MANAGEMENT_ENDPOINT, ModelType.BOOLEAN, true)
.setDefaultValue(new ModelNode(true))
.setAllowExpression(true)
.build();
Expand All @@ -67,7 +67,7 @@ private RemotingConnectorResource() {

@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
final OperationStepHandler writeHandler = new ReloadRequiredWriteAttributeHandler(USE_MANAGEMENT_ENDPOINT){
final OperationStepHandler writeHandler = new ReloadRequiredWriteAttributeHandler(USE_MANAGEMENT_ENDPOINT) {
@Override
protected void recordCapabilitiesAndRequirements(OperationContext context, AttributeDefinition attributeDefinition, ModelNode newValue, ModelNode oldValue) {
super.recordCapabilitiesAndRequirements(context, attributeDefinition, newValue, oldValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import javax.security.auth.callback.UnsupportedCallbackException;

import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.logging.BasicLogger;
import org.jboss.logging.Logger;
import org.jboss.logging.annotations.Cause;
Expand Down Expand Up @@ -129,4 +130,7 @@ public interface RemotingLogger extends BasicLogger {
@Message(id = 24, value = "The remoting subsystem is present but no io subsystem was found. An io subsystem " +
"was not required when remoting schema '%s' was current but now is, so a default subsystem is being added.")
void addingIOSubsystem(String legacyNS);

@Message(id = 25, value = "Can't remove %s as JMX uses it as a remoting endpoint")
OperationFailedException couldNotRemoveResource(PathAddress address);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,25 @@
package org.jboss.as.remoting.management;


import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
import static org.jboss.msc.service.ServiceController.Mode.ACTIVE;
import static org.jboss.msc.service.ServiceController.Mode.ON_DEMAND;

import java.util.NoSuchElementException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;

import org.jboss.as.controller.ModelController;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.remote.AbstractModelControllerOperationHandlerFactoryService;
import org.jboss.as.controller.remote.ModelControllerClientOperationHandlerFactoryService;
import org.jboss.as.protocol.mgmt.support.ManagementChannelInitialization;
import org.jboss.as.remoting.RemotingServices;
import org.jboss.as.remoting.logging.RemotingLogger;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
Expand Down Expand Up @@ -157,4 +164,31 @@ public static void removeManagementChannelServices(final OperationContext contex
final ServiceName operationHandlerName = endpointName.append(channelName).append(ModelControllerClientOperationHandlerFactoryService.OPERATION_HANDLER_NAME_SUFFIX);
context.removeService(operationHandlerName);
}

private static final String USE_MGMT_ENDPOINT = "use-management-endpoint";

/**
* Manual check because introducing a capability can't be done without a full refactoring.
* This has to go as soon as the management interfaces are redesigned.
* @param context the OperationContext
* @param otherManagementEndpoint : the address to check that may provide an exposed jboss-remoting endpoint.
* @throws OperationFailedException in case we can't remove the management resource.
*/
public static void isManagementResourceRemoveable(OperationContext context, PathAddress otherManagementEndpoint) throws OperationFailedException {
ModelNode remotingConnector;
try {
remotingConnector = context.readResourceFromRoot(
PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, "jmx"), PathElement.pathElement("remoting-connector", "jmx")), false).getModel();
} catch (NoSuchElementException ex) {
return;
}
if (!remotingConnector.hasDefined(USE_MGMT_ENDPOINT) ||
(remotingConnector.hasDefined(USE_MGMT_ENDPOINT) && context.resolveExpressions(remotingConnector.get(USE_MGMT_ENDPOINT)).asBoolean(true))) {
try {
context.readResourceFromRoot(otherManagementEndpoint, false);
} catch (NoSuchElementException ex) {
throw RemotingLogger.ROOT_LOGGER.couldNotRemoveResource(context.getCurrentAddress());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private HttpManagementResourceDefinition() {
super(RESOURCE_PATH,
ServerDescriptions.getResourceDescriptionResolver("core.management.http-interface"),
HttpManagementAddHandler.INSTANCE, HttpManagementRemoveHandler.INSTANCE,
OperationEntry.Flag.RESTART_NONE, OperationEntry.Flag.RESTART_NONE);
OperationEntry.Flag.RESTART_NONE, OperationEntry.Flag.RESTART_RESOURCE_SERVICES);
this.accessConstraints = SensitiveTargetAccessConstraintDefinition.MANAGEMENT_INTERFACES.wrapAsList();
setDeprecated(ModelVersion.create(1, 7));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private NativeManagementResourceDefinition() {
super(RESOURCE_PATH,
ServerDescriptions.getResourceDescriptionResolver("core.management.native-interface"),
NativeManagementAddHandler.INSTANCE, NativeManagementRemoveHandler.INSTANCE,
OperationEntry.Flag.RESTART_NONE, OperationEntry.Flag.RESTART_NONE);
OperationEntry.Flag.RESTART_NONE, OperationEntry.Flag.RESTART_RESOURCE_SERVICES);
this.accessConstraints = SensitiveTargetAccessConstraintDefinition.MANAGEMENT_INTERFACES.wrapAsList();
setDeprecated(ModelVersion.create(3));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,27 @@

package org.jboss.as.server.operations;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.MANAGEMENT_INTERFACE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NATIVE_INTERFACE;
import static org.jboss.as.server.mgmt.HttpManagementResourceDefinition.HTTP_MANAGEMENT_CAPABILITY;

import org.jboss.as.controller.AbstractRemoveStepHandler;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ProcessType;
import org.jboss.as.controller.ReloadRequiredRemoveStepHandler;
import org.jboss.as.controller.RunningMode;
import org.jboss.as.domain.management.access.RbacSanityCheckOperation;
import org.jboss.as.remoting.RemotingHttpUpgradeService;
import org.jboss.as.remoting.RemotingServices;
import org.jboss.as.remoting.management.ManagementRemotingServices;
import org.jboss.as.server.mgmt.UndertowHttpManagementService;
import org.jboss.dmr.ModelNode;

/**
* Removes the HTTP management interface.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
public class HttpManagementRemoveHandler extends AbstractRemoveStepHandler {
public class HttpManagementRemoveHandler extends ReloadRequiredRemoveStepHandler {

public static final HttpManagementRemoveHandler INSTANCE = new HttpManagementRemoveHandler();

Expand All @@ -50,30 +51,17 @@ private HttpManagementRemoveHandler() {
}

@Override
protected void performRemove(OperationContext context, ModelNode operation, ModelNode model)
throws OperationFailedException {
protected void performRemove(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
RbacSanityCheckOperation.addOperation(context);
final PathAddress nativeAddress = context.getCurrentAddress().getParent().append(PathElement.pathElement(MANAGEMENT_INTERFACE, NATIVE_INTERFACE));
context.addStep((OperationContext opContext, ModelNode op) -> {
ManagementRemotingServices.isManagementResourceRemoveable(opContext, nativeAddress);
}, OperationContext.Stage.MODEL, false);
super.performRemove(context, operation, model);
}

@Override
protected boolean requiresRuntime(OperationContext context) {
return context.getProcessType() != ProcessType.EMBEDDED_SERVER || context.getRunningMode() != RunningMode.ADMIN_ONLY;
}

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {

context.removeService(UndertowHttpManagementService.SERVICE_NAME);
context.removeService(UndertowHttpManagementService.SERVICE_NAME.append("shutdown"));
context.removeService(UndertowHttpManagementService.SERVICE_NAME.append("requests"));

RemotingServices.removeConnectorServices(context, ManagementRemotingServices.HTTP_CONNECTOR);
context.removeService(RemotingHttpUpgradeService.UPGRADE_SERVICE_NAME.append(ManagementRemotingServices.HTTP_CONNECTOR));
}

@Override
protected void recoverServices(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
HttpManagementAddHandler.INSTANCE.performRuntime(context, operation, model);
}
}