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-6913 Remove usage of deprecated AbstractAddStepHandler constructors in logging subsystem #6092

Merged
merged 1 commit into from
Jul 30, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ public void execute(final OperationContext context, final ModelNode operation) t
* A base step handler for logging operations.
*/
public abstract static class LoggingAddOperationStepHandler extends AbstractAddStepHandler {
public LoggingAddOperationStepHandler(final AttributeDefinition... attributes) {
super(attributes);
}

@Override
public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class LoggingSubsystemAdd extends AbstractAddStepHandler {
private final WildFlyLogContextSelector contextSelector;

LoggingSubsystemAdd(final PathManager pathManager, final WildFlyLogContextSelector contextSelector) {
super(LoggingResourceDefinition.ATTRIBUTES);
this.pathManager = pathManager;
this.contextSelector = contextSelector;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class FilterResourceDefinition extends SimpleResourceDefinition {
/**
* A step handler to add a custom filter
*/
private static final OperationStepHandler ADD = new LoggingOperations.LoggingAddOperationStepHandler(ATTRIBUTES) {
private static final OperationStepHandler ADD = new LoggingOperations.LoggingAddOperationStepHandler() {
private final List<String> reservedNames = Arrays.asList(
"accept",
"deny",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public boolean isMarshallable(final AttributeDefinition attribute, final ModelNo
/**
* A step handler to add a custom formatter
*/
private static final OperationStepHandler ADD = new LoggingOperations.LoggingAddOperationStepHandler(ATTRIBUTES) {
private static final OperationStepHandler ADD = new LoggingOperations.LoggingAddOperationStepHandler() {

@Override
public void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void marshallAsElement(final AttributeDefinition attribute, final ModelNo
/**
* A step handler to add a pattern formatter
*/
private static final OperationStepHandler ADD = new LoggingOperations.LoggingAddOperationStepHandler(ATTRIBUTES) {
private static final OperationStepHandler ADD = new LoggingOperations.LoggingAddOperationStepHandler() {

@Override
public void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
Expand Down Expand Up @@ -288,7 +289,7 @@ public void performRuntime(final OperationContext context, final ModelNode opera
final Class<? extends StructuredFormatter> type, final AttributeDefinition... additionalAttributes) {
super(
new Parameters(pathElement, LoggingExtension.getResourceDescriptionResolver(descriptionPrefix))
.setAddHandler(new AddStructuredFormatterStepHandler(type, Logging.join(DEFAULT_ATTRIBUTES, additionalAttributes)))
.setAddHandler(new AddStructuredFormatterStepHandler(type))
.setRemoveHandler(REMOVE)
.setCapabilities(Capabilities.FORMATTER_CAPABILITY)
);
Expand Down Expand Up @@ -350,8 +351,7 @@ private static String modelValueToMetaData(final ModelNode metaData) {
private static class AddStructuredFormatterStepHandler extends LoggingOperations.LoggingAddOperationStepHandler {
private final Class<? extends StructuredFormatter> type;

private AddStructuredFormatterStepHandler(final Class<? extends StructuredFormatter> type, final AttributeDefinition[] attributes) {
super(attributes);
private AddStructuredFormatterStepHandler(final Class<? extends StructuredFormatter> type) {
this.type = type;
}

Expand Down Expand Up @@ -391,7 +391,8 @@ public void performRuntime(final OperationContext context, final ModelNode opera
}

// Process the attributes
for (AttributeDefinition attribute : attributes) {
for (AttributeAccess access : context.getResourceRegistration().getAttributes(PathAddress.EMPTY_ADDRESS).values()) {
AttributeDefinition attribute = access.getAttributeDefinition();
if (attribute == META_DATA) {
final String metaData = modelValueToMetaData(META_DATA.resolveModelAttribute(context, model));
if (metaData != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ abstract class AbstractFileHandlerDefinition extends AbstractHandlerDefinition {
final ResolvePathHandler resolvePathHandler,
final PathInfoHandler diskUsagePathHandler,
final AttributeDefinition... attributes) {
super(createParameters(path, type, attributes, CommonAttributes.FILE, CommonAttributes.APPEND), registerLegacyOps, null, attributes);
super(createParameters(path, type, CommonAttributes.FILE, CommonAttributes.APPEND), registerLegacyOps, null, attributes);
this.registerLegacyOps = registerLegacyOps;
this.resolvePathHandler = resolvePathHandler;
this.diskUsagePathHandler = diskUsagePathHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.DefaultAttributeMarshaller;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ReadResourceNameOperationStepHandler;
import org.jboss.as.controller.SimpleAttributeDefinition;
Expand Down Expand Up @@ -110,30 +109,28 @@ public void marshallAsElement(final AttributeDefinition attribute, final ModelNo
FILTER,
};

private final OperationStepHandler writeHandler;
private final AttributeDefinition[] writableAttributes;
private final AttributeDefinition[] readOnlyAttributes;
private final boolean registerLegacyOps;

protected AbstractHandlerDefinition(final PathElement path,
final Class<? extends Handler> type,
final AttributeDefinition[] attributes) {
this(createParameters(path, type, attributes), true, null, attributes);
this(createParameters(path, type), true, null, attributes);
}

protected AbstractHandlerDefinition(final PathElement path,
final boolean registerLegacyOps,
final Class<? extends Handler> type,
final AttributeDefinition[] attributes) {
this(createParameters(path, type, attributes), registerLegacyOps, null, attributes);
this(createParameters(path, type), registerLegacyOps, null, attributes);
}

protected AbstractHandlerDefinition(final PathElement path,
final Class<? extends Handler> type,
final AttributeDefinition[] attributes,
final ConfigurationProperty<?>... constructionProperties) {
this(createParameters(path, type, attributes, constructionProperties),
true, null, attributes);
this(createParameters(path, type, constructionProperties), true, null, attributes);
}

protected AbstractHandlerDefinition(final Parameters parameters,
Expand All @@ -143,7 +140,6 @@ protected AbstractHandlerDefinition(final Parameters parameters,
super(parameters);
this.registerLegacyOps = registerLegacyOps;
this.writableAttributes = writableAttributes;
writeHandler = new HandlerOperations.LogHandlerWriteAttributeHandler();
this.readOnlyAttributes = readOnlyAttributes;
}

Expand All @@ -152,9 +148,9 @@ public void registerAttributes(final ManagementResourceRegistration resourceRegi
for (AttributeDefinition def : writableAttributes) {
// Filter requires a special reader
if (def.getName().equals(FILTER.getName())) {
resourceRegistration.registerReadWriteAttribute(def, LoggingOperations.ReadFilterOperationStepHandler.INSTANCE, writeHandler);
resourceRegistration.registerReadWriteAttribute(def, LoggingOperations.ReadFilterOperationStepHandler.INSTANCE, HandlerOperations.LogHandlerWriteAttributeHandler.INSTANCE);
} else {
resourceRegistration.registerReadWriteAttribute(def, null, writeHandler);
resourceRegistration.registerReadWriteAttribute(def, null, HandlerOperations.LogHandlerWriteAttributeHandler.INSTANCE);
}
}
if (readOnlyAttributes != null) {
Expand Down Expand Up @@ -240,10 +236,9 @@ void registerResourceTransformers(final KnownModelVersion modelVersion,
* @return the default parameters
*/
static Parameters createParameters(final PathElement path, final Class<? extends Handler> type,
final AttributeDefinition[] addAttributes,
final ConfigurationProperty<?>... constructionProperties) {
return new Parameters(path, LoggingExtension.getResourceDescriptionResolver(path.getKey()))
.setAddHandler(new HandlerOperations.HandlerAddOperationStepHandler(type, addAttributes, constructionProperties))
.setAddHandler(new HandlerOperations.HandlerAddOperationStepHandler(type, constructionProperties))
.setRemoveHandler(HandlerOperations.REMOVE_HANDLER)
.setCapabilities(Capabilities.HANDLER_CAPABILITY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.logging.CommonAttributes;
import org.jboss.as.logging.ConfigurationProperty;
Expand Down Expand Up @@ -116,13 +117,10 @@ public final void performRuntime(final OperationContext context, final ModelNode
*/
static class HandlerAddOperationStepHandler extends LoggingOperations.LoggingAddOperationStepHandler {
private final String[] constructionProperties;
private final AttributeDefinition[] attributes;
private final Class<? extends Handler> type;

HandlerAddOperationStepHandler(final Class<? extends Handler> type, final AttributeDefinition[] attributes, final ConfigurationProperty<?>... constructionProperties) {
super(attributes);
HandlerAddOperationStepHandler(final Class<? extends Handler> type, final ConfigurationProperty<?>... constructionProperties) {
this.type = type;
this.attributes = attributes;
final List<String> names = new ArrayList<>();
for (ConfigurationProperty<?> prop : constructionProperties) {
names.add(prop.getPropertyName());
Expand All @@ -131,17 +129,14 @@ static class HandlerAddOperationStepHandler extends LoggingOperations.LoggingAdd
}

@Override
public void populateModel(final ModelNode operation, final ModelNode model) throws OperationFailedException {
for (AttributeDefinition attribute : attributes) {
public void populateModel(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
super.populateModel(context, operation, resource);
if (context.getResourceRegistration().getAttributeNames(PathAddress.EMPTY_ADDRESS).contains(CommonAttributes.FILTER.getName())) {
// Filter attribute needs to be converted to filter spec
if (CommonAttributes.FILTER.equals(attribute)) {
final ModelNode filter = CommonAttributes.FILTER.validateOperation(operation);
if (filter.isDefined()) {
final String value = Filters.filterToFilterSpec(filter);
model.get(FILTER_SPEC.getName()).set(value.isEmpty() ? new ModelNode() : new ModelNode(value));
}
} else {
attribute.validateAndSet(operation, model);
final ModelNode filter = CommonAttributes.FILTER.validateOperation(operation);
if (filter.isDefined()) {
final String value = Filters.filterToFilterSpec(filter);
resource.getModel().get(FILTER_SPEC.getName()).set(value.isEmpty() ? new ModelNode() : new ModelNode(value));
}
}
}
Expand Down Expand Up @@ -202,7 +197,8 @@ public void performRuntime(final OperationContext context, final ModelNode opera
}
}

for (AttributeDefinition attribute : attributes) {
for (AttributeAccess access : context.getResourceRegistration().getAttributes(PathAddress.EMPTY_ADDRESS).values()) {
AttributeDefinition attribute = access.getAttributeDefinition();
// CLASS and MODULE should be ignored
final boolean skip;
if ((attribute.equals(CLASS) || attribute.equals(MODULE)) || attribute.equals(FILTER)) {
Expand Down Expand Up @@ -261,6 +257,10 @@ HandlerConfiguration createHandlerConfiguration(final String className,
* A default log handler write attribute step handler.
*/
static class LogHandlerWriteAttributeHandler extends LoggingOperations.LoggingWriteAttributeHandler {
static final OperationStepHandler INSTANCE = new LogHandlerWriteAttributeHandler();

private LogHandlerWriteAttributeHandler() {
}

@Override
protected boolean applyUpdate(final OperationContext context, final String attributeName, final String addressName, final ModelNode value, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public class SocketHandlerResourceDefinition extends SimpleResourceDefinition {
SSL_CONTEXT,
};

private static final LoggingAddOperationStepHandler ADD_HANDLER = new LoggingAddOperationStepHandler(ATTRIBUTES) {
private static final LoggingAddOperationStepHandler ADD_HANDLER = new LoggingAddOperationStepHandler() {

@Override
protected OperationStepHandler additionalModelStep(final LogContextConfiguration logContextConfiguration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,19 @@ public void marshallAsElement(final AttributeDefinition attribute, final ModelNo
NAMED_FORMATTER
};

private static final HandlerAddOperationStepHandler ADD_HANDLER = new HandlerAddOperationStepHandler(SyslogHandler.class, ATTRIBUTES);
private static final LogHandlerWriteAttributeHandler WRITE_HANDLER = new LogHandlerWriteAttributeHandler();

public static final SyslogHandlerResourceDefinition INSTANCE = new SyslogHandlerResourceDefinition();

private SyslogHandlerResourceDefinition() {
super(new Parameters(SYSLOG_HANDLER_PATH, LoggingExtension.getResourceDescriptionResolver(NAME))
.setAddHandler(ADD_HANDLER)
.setAddHandler( new HandlerAddOperationStepHandler(SyslogHandler.class))
.setRemoveHandler(HandlerOperations.REMOVE_HANDLER)
.setCapabilities(Capabilities.HANDLER_CAPABILITY));
}

@Override
public void registerAttributes(final ManagementResourceRegistration resourceRegistration) {
for (AttributeDefinition def : ATTRIBUTES) {
resourceRegistration.registerReadWriteAttribute(def, null, WRITE_HANDLER);
resourceRegistration.registerReadWriteAttribute(def, null, LogHandlerWriteAttributeHandler.INSTANCE);
}
}

Expand Down
Loading