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-6815][Community] Added reload-enhanced operation to reload a domain to a certain stability #5992

Merged
merged 7 commits into from
Jun 20, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ public DefaultOperationDescriptionProvider(final String operationName,
this(operationName, descriptionResolver, attributeDescriptionResolver, replyType, replyValueType, replyAllowNull, deprecationData, replyParameters, parameters, null);
}

public DefaultOperationDescriptionProvider(final String operationName,
final ResourceDescriptionResolver descriptionResolver,
final ResourceDescriptionResolver attributeDescriptionResolver,
final ModelType replyType,
final ModelType replyValueType,
final boolean replyAllowNull,
final DeprecationData deprecationData,
final AttributeDefinition[] replyParameters,
final AttributeDefinition[] parameters,
final List<AccessConstraintDefinition> accessConstraints) {
this(operationName, descriptionResolver, attributeDescriptionResolver, replyType, replyValueType, replyAllowNull, deprecationData, replyParameters, parameters, accessConstraints, Stability.DEFAULT);
}

public DefaultOperationDescriptionProvider(final String operationName,
final ResourceDescriptionResolver descriptionResolver,
final ResourceDescriptionResolver attributeDescriptionResolver,
Expand All @@ -119,7 +132,8 @@ public DefaultOperationDescriptionProvider(final String operationName,
final DeprecationData deprecationData,
final AttributeDefinition[] replyParameters,
final AttributeDefinition[] parameters,
final List<AccessConstraintDefinition> accessConstraints) {
final List<AccessConstraintDefinition> accessConstraints,
final Stability stability) {
this.operationName = operationName;
this.descriptionResolver = descriptionResolver;
this.attributeDescriptionResolver = attributeDescriptionResolver;
Expand All @@ -130,7 +144,7 @@ public DefaultOperationDescriptionProvider(final String operationName,
this.deprecationData = deprecationData;
this.replyParameters = replyParameters;
this.accessConstraints = accessConstraints != null ? accessConstraints : Collections.<AccessConstraintDefinition>emptyList();
this.stability = Stability.DEFAULT;
this.stability = stability;
}

public DefaultOperationDescriptionProvider(OperationDefinition definition, ResourceDescriptionResolver resolver, ResourceDescriptionResolver attributeResolver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.UninterruptibleCountDownLatch;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.operations.validation.EnumValidator;
import org.jboss.as.controller.remote.EarlyResponseSendListener;
import org.jboss.as.version.Stability;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jboss.msc.service.LifecycleEvent;
Expand All @@ -35,9 +37,15 @@ public abstract class ProcessReloadHandler<T extends RunningModeControl> impleme
* The operation name.
*/
protected static final String OPERATION_NAME = ModelDescriptionConstants.RELOAD;
protected static final String ENHANCED_OPERATION_NAME = ModelDescriptionConstants.RELOAD_ENHANCED;

protected static final AttributeDefinition ADMIN_ONLY = new SimpleAttributeDefinitionBuilder(ModelDescriptionConstants.ADMIN_ONLY, ModelType.BOOLEAN, true)
.setDefaultValue(ModelNode.FALSE).build();
.setDefaultValue(ModelNode.FALSE).build();

protected static final AttributeDefinition STABILITY = new SimpleAttributeDefinitionBuilder(ModelDescriptionConstants.STABILITY, ModelType.STRING, true)
.setStability(Stability.COMMUNITY)
.setValidator(EnumValidator.create(Stability.class))
.build();

private final T runningModeControl;
private final ControlledProcessState processState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.SimpleOperationDefinition;
import org.jboss.as.controller.SimpleOperationDefinitionBuilder;
import org.jboss.as.controller.access.management.SensitiveTargetAccessConstraintDefinition;
import org.jboss.as.controller.descriptions.DefaultOperationDescriptionProvider;
import org.jboss.as.controller.descriptions.DescriptionProvider;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
Expand All @@ -24,10 +25,12 @@
import org.jboss.as.controller.registry.OperationEntry;
import org.jboss.as.domain.controller.LocalHostControllerInfo;
import org.jboss.as.host.controller.HostControllerEnvironment;
import org.jboss.as.host.controller.HostEnvironmentAwareProcessReloadHandler;
import org.jboss.as.host.controller.HostModelUtil;
import org.jboss.as.host.controller.HostRunningModeControl;
import org.jboss.as.host.controller.RestartMode;
import org.jboss.as.host.controller.logging.HostControllerLogger;
import org.jboss.as.version.Stability;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jboss.msc.service.ServiceName;
Expand All @@ -36,10 +39,10 @@
*
* @author <a href="[email protected]">Kabir Khan</a>
*/
public class HostProcessReloadHandler extends ProcessReloadHandler<HostRunningModeControl>{
public class HostProcessReloadHandler extends HostEnvironmentAwareProcessReloadHandler {

private static final AttributeDefinition RESTART_SERVERS = new SimpleAttributeDefinitionBuilder(ModelDescriptionConstants.RESTART_SERVERS, ModelType.BOOLEAN, true)
.setDefaultValue(ModelNode.TRUE).build();
.setDefaultValue(ModelNode.TRUE).build();

private static final AttributeDefinition USE_CURRENT_DOMAIN_CONFIG = new SimpleAttributeDefinitionBuilder(ModelDescriptionConstants.USE_CURRENT_DOMAIN_CONFIG, ModelType.BOOLEAN, true)
.setAlternatives(ModelDescriptionConstants.DOMAIN_CONFIG)
Expand All @@ -60,27 +63,40 @@ public class HostProcessReloadHandler extends ProcessReloadHandler<HostRunningMo
.build();


private static final AttributeDefinition[] MASTER_ATTRIBUTES = new AttributeDefinition[] {ADMIN_ONLY, RESTART_SERVERS, USE_CURRENT_DOMAIN_CONFIG, USE_CURRENT_HOST_CONFIG, DOMAIN_CONFIG, HOST_CONFIG};
private static final AttributeDefinition[] PRIMARY_HC_ATTRIBUTES = new AttributeDefinition[] {ADMIN_ONLY, RESTART_SERVERS, USE_CURRENT_DOMAIN_CONFIG, USE_CURRENT_HOST_CONFIG, DOMAIN_CONFIG, HOST_CONFIG};

private static final AttributeDefinition[] SLAVE_ATTRIBUTES = new AttributeDefinition[] {ADMIN_ONLY, RESTART_SERVERS, USE_CURRENT_HOST_CONFIG, HOST_CONFIG};
private static final AttributeDefinition[] SECONDARY_HC_ATTRIBUTES = new AttributeDefinition[] {ADMIN_ONLY, RESTART_SERVERS, USE_CURRENT_HOST_CONFIG, HOST_CONFIG};

private static final AttributeDefinition[] ENHANCED_PRIMARY_HC_ATTRIBUTES = new AttributeDefinition[] {ADMIN_ONLY, USE_CURRENT_DOMAIN_CONFIG, USE_CURRENT_HOST_CONFIG, DOMAIN_CONFIG, HOST_CONFIG, STABILITY};

private static final AttributeDefinition[] ENHANCED_SECONDARY_HC_ATTRIBUTES = new AttributeDefinition[] {ADMIN_ONLY, USE_CURRENT_HOST_CONFIG, HOST_CONFIG, STABILITY};

private final HostControllerEnvironment environment;
private final LocalHostControllerInfo hostControllerInfo;
private final ProcessType processType;

public static OperationDefinition getDefinition(final LocalHostControllerInfo hostControllerInfo) {
return new DeferredParametersOperationDefinitionBuilder(hostControllerInfo, OPERATION_NAME, HostModelUtil.getResourceDescriptionResolver())
.setParameters(hostControllerInfo.isMasterDomainController() ? MASTER_ATTRIBUTES : SLAVE_ATTRIBUTES)
.withFlag(OperationEntry.Flag.HOST_CONTROLLER_ONLY)
.setRuntimeOnly()
.build();
.setParameters(hostControllerInfo.isMasterDomainController() ? PRIMARY_HC_ATTRIBUTES : SECONDARY_HC_ATTRIBUTES)
.withFlag(OperationEntry.Flag.HOST_CONTROLLER_ONLY)
.setRuntimeOnly()
.build();
}

public static OperationDefinition getEnhancedDefinition(final LocalHostControllerInfo hostControllerInfo) {
return new DeferredParametersOperationDefinitionBuilder(hostControllerInfo, ENHANCED_OPERATION_NAME, HostModelUtil.getResourceDescriptionResolver(), ENHANCED_PRIMARY_HC_ATTRIBUTES, ENHANCED_SECONDARY_HC_ATTRIBUTES, Stability.COMMUNITY)
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't really important, but I think it would be clearer if both the calls to this constructor had the same format

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for reviewing @kabir

What do you mean about having the same format?

I understand that what you suggested is to remove the overloaded DeferredParametersOperationDefinitionBuilder constructor, so both getEnhancedDefinition and getDefinition use the same number of arguments to improve the code readability and make it more clear, correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So far, just updated it to assert that closing the snapshot indeed reloaded the host controller to the original stability level

.setStability(Stability.COMMUNITY)
.setAccessConstraints(SensitiveTargetAccessConstraintDefinition.RELOAD_ENHANCED)
.setParameters(hostControllerInfo.isMasterDomainController() ? ENHANCED_PRIMARY_HC_ATTRIBUTES : ENHANCED_SECONDARY_HC_ATTRIBUTES)
.withFlag(OperationEntry.Flag.HOST_CONTROLLER_ONLY)
.setRuntimeOnly()
.build();
}

public HostProcessReloadHandler(final ServiceName rootService, final HostRunningModeControl runningModeControl,
final ControlledProcessState processState, final HostControllerEnvironment environment,
final LocalHostControllerInfo hostControllerInfo) {
super(rootService, runningModeControl, processState);
super(rootService, runningModeControl, processState, environment);
this.processType = environment.getProcessType();
this.environment = environment;
this.hostControllerInfo = hostControllerInfo;
Expand All @@ -102,6 +118,14 @@ public void execute(OperationContext context, ModelNode operation) throws Operat

@Override
protected ProcessReloadHandler.ReloadContext<HostRunningModeControl> initializeReloadContext(final OperationContext context, final ModelNode operation) throws OperationFailedException {
final Stability stability;
if (operation.hasDefined(STABILITY.getName())) {
String val = STABILITY.resolveModelAttribute(context, operation).asString();
stability = Stability.fromString(val);
environment.checkStabilityIsValidForInstallation(stability);
} else {
stability = null;
}
final boolean adminOnly = ADMIN_ONLY.resolveModelAttribute(context, operation).asBoolean(false);
final boolean restartServers = RESTART_SERVERS.resolveModelAttribute(context, operation).asBoolean(true);
final boolean useCurrentHostConfig = USE_CURRENT_HOST_CONFIG.resolveModelAttribute(context, operation).asBoolean(true);
Expand All @@ -124,7 +148,7 @@ protected ProcessReloadHandler.ReloadContext<HostRunningModeControl> initializeR
throw HostControllerLogger.ROOT_LOGGER.domainConfigForReloadNotFound(hostConfig);
}

return new ReloadContext<HostRunningModeControl>() {
return new ReloadContext<>() {

@Override
public void reloadInitiated(HostRunningModeControl runningModeControl) {
Expand All @@ -140,24 +164,42 @@ public void doReload(HostRunningModeControl runningModeControl) {
runningModeControl.setNewDomainBootFileName(domainConfig);
runningModeControl.setNewBootFileName(hostConfig);
runningModeControl.setReloadHostName(hostName);
if (stability != null) {
updateHostEnvironmentStability(stability);
}
}
};
}

/**
* The host controller info does not know if it is master or not until later in the bootup process
* The host controller info does not know if it is master or not until later in the booting process
*/
private static class DeferredParametersOperationDefinitionBuilder extends SimpleOperationDefinitionBuilder {
private final LocalHostControllerInfo hostControllerInfo;
private final AttributeDefinition[] primaryHcAttr;
private final AttributeDefinition[] secondaryHcAttr;
private final Stability stability;

public DeferredParametersOperationDefinitionBuilder(LocalHostControllerInfo hostControllerInfo, String name, ResourceDescriptionResolver resolver) {
super(name, resolver);
this.hostControllerInfo = hostControllerInfo;
this.primaryHcAttr = PRIMARY_HC_ATTRIBUTES;
this.secondaryHcAttr = SECONDARY_HC_ATTRIBUTES;
this.stability = Stability.DEFAULT;
}

public DeferredParametersOperationDefinitionBuilder(LocalHostControllerInfo hostControllerInfo, String name, ResourceDescriptionResolver resolver, AttributeDefinition[] primaryHcAttr, AttributeDefinition[] secondaryHcAttr, Stability stability) {
super(name, resolver);
this.hostControllerInfo = hostControllerInfo;
this.primaryHcAttr = primaryHcAttr;
this.secondaryHcAttr = secondaryHcAttr;
this.stability = stability;
}

@Override
public SimpleOperationDefinition internalBuild(final ResourceDescriptionResolver resolver, final ResourceDescriptionResolver attributeResolver) {
return new SimpleOperationDefinition(new SimpleOperationDefinitionBuilder(name, resolver)
.setStability(stability)
.setAttributeResolver(attributeResolver)
.setParameters(parameters)
.withFlags(flags)) {
Expand All @@ -166,8 +208,8 @@ public DescriptionProvider getDescriptionProvider() {
return new DescriptionProvider() {
@Override
public ModelNode getModelDescription(Locale locale) {
AttributeDefinition[] params = hostControllerInfo.isMasterDomainController() ? MASTER_ATTRIBUTES : SLAVE_ATTRIBUTES;
return new DefaultOperationDescriptionProvider(getName(), resolver, attributeResolver, replyType, replyValueType, replyAllowNull, deprecationData, replyParameters, params, accessConstraints).getModelDescription(locale);
AttributeDefinition[] params = hostControllerInfo.isMasterDomainController() ? primaryHcAttr : secondaryHcAttr;
return new DefaultOperationDescriptionProvider(getName(), resolver, attributeResolver, replyType, replyValueType, replyAllowNull, deprecationData, replyParameters, params, accessConstraints, stability).getModelDescription(locale);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@
import org.jboss.as.server.controller.resources.VersionModelInitializer;
import org.jboss.as.server.deployment.ContentCleanerService;
import org.jboss.as.server.mgmt.UndertowHttpManagementService;
import org.jboss.as.version.Stability;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceBuilder;
Expand Down Expand Up @@ -262,18 +261,17 @@ static void addService(final ServiceTarget serviceTarget,
final ManagementSecurityIdentitySupplier securityIdentitySupplier = new ManagementSecurityIdentitySupplier();
final RuntimeHostControllerInfoAccessor hostControllerInfoAccessor = new DomainHostControllerInfoAccessor(hostControllerInfo);
final ProcessType processType = environment.getProcessType();
final Stability stability = environment.getStability();
final ExtensionRegistry hostExtensionRegistry = ExtensionRegistry.builder(processType)
.withRunningModeControl(runningModeControl)
.withStability(stability)
.withStabilitySupplier(environment::getStability)
.withAuditLogger(auditLogger)
.withAuthorizer(authorizer)
.withSecurityIdentitySupplier(securityIdentitySupplier)
.withHostControllerInfoAccessor(hostControllerInfoAccessor)
.build();
final ExtensionRegistry extensionRegistry = ExtensionRegistry.builder(processType)
.withRunningModeControl(runningModeControl)
.withStability(stability)
.withStabilitySupplier(environment::getStability)
.withAuditLogger(auditLogger)
.withAuthorizer(authorizer)
.withSecurityIdentitySupplier(securityIdentitySupplier)
Expand Down
Loading