Skip to content

Commit

Permalink
[WFCORE-6750] Code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kabir committed Jun 24, 2024
1 parent e25403d commit 77c2b08
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static ResourceDescriptionResolver getResourceDescriptionResolver(final S
@Override
public void initialize(ExtensionContext context) {
final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, CURRENT_VERSION);
subsystem.registerXMLElementWriter(new PersistentResourceXMLDescriptionWriter(CoreManagementSubsystemSchema_1_0.ALL.get(context.getStability())));
subsystem.registerXMLElementWriter(new PersistentResourceXMLDescriptionWriter(CoreManagementSubsystemSchema.CURRENT.get(context.getStability())));
//This subsystem should be runnable on a host
subsystem.setHostCapable();
ManagementResourceRegistration registration = subsystem.registerSubsystemModel(new CoreManagementRootResourceDefinition());
Expand All @@ -58,6 +58,6 @@ public void initialize(ExtensionContext context) {

@Override
public void initializeParsers(ExtensionParsingContext context) {
context.setSubsystemXmlMappings(CoreManagementExtension.SUBSYSTEM_NAME, EnumSet.allOf(CoreManagementSubsystemSchema_1_0.class));
context.setSubsystemXmlMappings(CoreManagementExtension.SUBSYSTEM_NAME, EnumSet.allOf(CoreManagementSubsystemSchema.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,15 @@
package org.wildfly.extension.core.management;


import org.jboss.as.controller.AbstractBoottimeAddStepHandler;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PersistentResourceDefinition;
import org.jboss.as.controller.ReloadRequiredRemoveStepHandler;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.server.AbstractDeploymentChainStep;
import org.jboss.as.server.DeploymentProcessorTarget;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceBuilder;
import org.wildfly.extension.core.management.UnstableApiAnnotationResourceDefinition.UnstableApiAnnotationLevel;
import org.wildfly.extension.core.management.deployment.ReportUnstableApiAnnotationsProcessor;
import org.wildfly.extension.core.management.deployment.ScanUnstableApiAnnotationsProcessor;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;

import static org.jboss.as.server.deployment.Phase.PARSE;
import static org.jboss.as.server.deployment.Phase.PARSE_REPORT_EXPERIMENTAL_ANNOTATIONS;
import static org.jboss.as.server.deployment.Phase.PARSE_SCAN_EXPERIMENTAL_ANNOTATIONS;
import static org.wildfly.extension.core.management.CoreManagementExtension.SUBSYSTEM_NAME;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.ModelOnlyAddStepHandler;
import org.jboss.as.controller.PersistentResourceDefinition;
import org.jboss.as.controller.ReloadRequiredRemoveStepHandler;

/**
* {@link org.jboss.as.controller.ResourceDefinition} for the core-management subsystem root resource.
Expand All @@ -42,7 +26,7 @@ class CoreManagementRootResourceDefinition extends PersistentResourceDefinition
CoreManagementRootResourceDefinition() {
super(CoreManagementExtension.SUBSYSTEM_PATH,
CoreManagementExtension.getResourceDescriptionResolver(),
new CoreManagementAddHandler(),
ModelOnlyAddStepHandler.INSTANCE,
ReloadRequiredRemoveStepHandler.INSTANCE);
}

Expand All @@ -58,36 +42,4 @@ protected List<? extends PersistentResourceDefinition> getChildren() {
UnstableApiAnnotationResourceDefinition.INSTANCE
);
}

private static class CoreManagementAddHandler extends AbstractBoottimeAddStepHandler {

@Override
protected void performBoottime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {

if (context.isNormalServer()) {
context.addStep(new AbstractDeploymentChainStep() {
@Override
protected void execute(DeploymentProcessorTarget processorTarget) {
processorTarget.addDeploymentProcessor(SUBSYSTEM_NAME, PARSE, PARSE_SCAN_EXPERIMENTAL_ANNOTATIONS,
new ScanUnstableApiAnnotationsProcessor(context.getRunningMode(), context.getStability(), UnstableApiAnnotationService.LEVEL_SUPPLIER));
processorTarget.addDeploymentProcessor(SUBSYSTEM_NAME, PARSE, PARSE_REPORT_EXPERIMENTAL_ANNOTATIONS,
new ReportUnstableApiAnnotationsProcessor(UnstableApiAnnotationService.LEVEL_SUPPLIER));
}
}, OperationContext.Stage.RUNTIME);
}

Resource unstableApiResource = resource.getChild(UnstableApiAnnotationResourceDefinition.PATH);
UnstableApiAnnotationLevel level = null;
if (unstableApiResource != null) {
ModelNode model = unstableApiResource.getModel();
String levelValue = UnstableApiAnnotationResourceDefinition.LEVEL.resolveModelAttribute(context, model).asString();
level = UnstableApiAnnotationLevel.valueOf(levelValue);
}

ServiceBuilder<?> sb = context.getCapabilityServiceTarget().addService();
Consumer<UnstableApiAnnotationService> serviceConsumer = sb.provides(UnstableApiAnnotationService.SERVICE_NAME);
sb.setInstance(new UnstableApiAnnotationService(serviceConsumer, level));
sb.install();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@
*
* @author <a href="http://jmesnil.net/">Jeff Mesnil</a> (c) 2016 Red Hat inc.
*/
public enum CoreManagementSubsystemSchema_1_0 implements PersistentSubsystemSchema<CoreManagementSubsystemSchema_1_0> {
public enum CoreManagementSubsystemSchema implements PersistentSubsystemSchema<CoreManagementSubsystemSchema> {

VERSION_1_0(1),
VERSION_1_0_PREVIEW(1, Stability.PREVIEW);
static final Map<Stability, CoreManagementSubsystemSchema_1_0> ALL = Feature.map(EnumSet.of(VERSION_1_0, VERSION_1_0_PREVIEW));
static final Map<Stability, CoreManagementSubsystemSchema> CURRENT = Feature.map(EnumSet.of(VERSION_1_0, VERSION_1_0_PREVIEW));

private final VersionedNamespace<IntVersion, CoreManagementSubsystemSchema_1_0> namespace;
private final VersionedNamespace<IntVersion, CoreManagementSubsystemSchema> namespace;

CoreManagementSubsystemSchema_1_0(int major) {
CoreManagementSubsystemSchema(int major) {
this.namespace = SubsystemSchema.createLegacySubsystemURN(CoreManagementExtension.SUBSYSTEM_NAME, new IntVersion(major, 0));
}

CoreManagementSubsystemSchema_1_0(int major, Stability stability) {
CoreManagementSubsystemSchema(int major, Stability stability) {
this.namespace = SubsystemSchema.createLegacySubsystemURN(CoreManagementExtension.SUBSYSTEM_NAME, stability, new IntVersion(major, 0));
}

@Override
public VersionedNamespace<IntVersion, CoreManagementSubsystemSchema_1_0> getNamespace() {
public VersionedNamespace<IntVersion, CoreManagementSubsystemSchema> getNamespace() {
return this.namespace;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,41 @@
*/
package org.wildfly.extension.core.management;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SERVICE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.UNSTABLE_API_ANNOTATIONS;
import static org.jboss.as.server.deployment.Phase.PARSE;
import static org.jboss.as.server.deployment.Phase.PARSE_REPORT_EXPERIMENTAL_ANNOTATIONS;
import static org.jboss.as.server.deployment.Phase.PARSE_SCAN_EXPERIMENTAL_ANNOTATIONS;
import static org.wildfly.extension.core.management.CoreManagementExtension.SUBSYSTEM_NAME;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.jboss.as.controller.AbstractBoottimeAddStepHandler;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.PersistentResourceDefinition;
import org.jboss.as.controller.ReloadRequiredAddStepHandler;
import org.jboss.as.controller.ReloadRequiredRemoveStepHandler;
import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler;
import org.jboss.as.controller.ResourceRegistration;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.operations.validation.EnumValidator;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.server.AbstractDeploymentChainStep;
import org.jboss.as.server.DeploymentProcessorTarget;
import org.jboss.as.version.Stability;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;

import java.util.Collection;
import java.util.Collections;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SERVICE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.UNSTABLE_API_ANNOTATIONS;
import org.wildfly.extension.core.management.deployment.ReportUnstableApiAnnotationsProcessor;
import org.wildfly.extension.core.management.deployment.ScanUnstableApiAnnotationsProcessor;

/**
* Resource to list all configuration changes.
* Resource to configure the unstable api annotation usage reporting.
*
* @author <a href="mailto:ehugonne@redhat.com">Emmanuel Hugonnet</a> (c) 2015 Red Hat, inc.
*/
public class UnstableApiAnnotationResourceDefinition extends PersistentResourceDefinition {

Expand All @@ -38,32 +47,54 @@ public class UnstableApiAnnotationResourceDefinition extends PersistentResourceD
ModelDescriptionConstants.LEVEL, ModelType.STRING, true)
.setValidator(EnumValidator.create(UnstableApiAnnotationLevel.class))
.setDefaultValue(new ModelNode(UnstableApiAnnotationLevel.LOG.name()))
.setRestartAllServices()
.build();
public static final PathElement PATH = PathElement.pathElement(SERVICE, UNSTABLE_API_ANNOTATIONS);
static final ResourceRegistration RESOURCE_REGISTRATION = ResourceRegistration.of(PATH, STABILITY);
static final UnstableApiAnnotationResourceDefinition INSTANCE = new UnstableApiAnnotationResourceDefinition();

private static final List<AttributeDefinition> ATTRIBUTES = Collections.singletonList(LEVEL);

private UnstableApiAnnotationResourceDefinition() {
super(
new Parameters(
RESOURCE_REGISTRATION,
CoreManagementExtension.getResourceDescriptionResolver(UNSTABLE_API_ANNOTATIONS))
.setAddHandler(ReloadRequiredAddStepHandler.INSTANCE)
.setAddHandler(UnstableApiAnnotationResourceAddHandler.INSTANCE)
.setRemoveHandler(ReloadRequiredRemoveStepHandler.INSTANCE));
}


@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
super.registerAttributes(resourceRegistration);
resourceRegistration.registerReadWriteAttribute(LEVEL, null, ReloadRequiredWriteAttributeHandler.INSTANCE);
public Collection<AttributeDefinition> getAttributes() {
return ATTRIBUTES;
}

@Override
public Collection<AttributeDefinition> getAttributes() {
return Collections.emptyList();
private static class UnstableApiAnnotationResourceAddHandler extends AbstractBoottimeAddStepHandler {


static final UnstableApiAnnotationResourceAddHandler INSTANCE = new UnstableApiAnnotationResourceAddHandler();
@Override
public void performBoottime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
ModelNode model = resource.getModel();
String levelValue = UnstableApiAnnotationResourceDefinition.LEVEL.resolveModelAttribute(context, model).asString();
UnstableApiAnnotationLevel level = UnstableApiAnnotationLevel.valueOf(levelValue);

if (context.isNormalServer()) {
context.addStep(new AbstractDeploymentChainStep() {
@Override
protected void execute(DeploymentProcessorTarget processorTarget) {
processorTarget.addDeploymentProcessor(SUBSYSTEM_NAME, PARSE, PARSE_SCAN_EXPERIMENTAL_ANNOTATIONS,
new ScanUnstableApiAnnotationsProcessor(context.getRunningMode(), context.getStability(), level));
processorTarget.addDeploymentProcessor(SUBSYSTEM_NAME, PARSE, PARSE_REPORT_EXPERIMENTAL_ANNOTATIONS,
new ReportUnstableApiAnnotationsProcessor(level));
}
}, OperationContext.Stage.RUNTIME);
}
}
}


public enum UnstableApiAnnotationLevel {
LOG,
ERROR
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

package org.wildfly.extension.core.management.deployment;

import static org.wildfly.extension.core.management.logging.CoreManagementLogger.UNSUPPORTED_ANNOTATION_LOGGER;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Set;

import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
Expand All @@ -23,20 +30,12 @@
import org.wildfly.unstable.api.annotation.classpath.runtime.bytecode.ExtendsAnnotatedClass;
import org.wildfly.unstable.api.annotation.classpath.runtime.bytecode.ImplementsAnnotatedInterface;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;

import static org.wildfly.extension.core.management.logging.CoreManagementLogger.UNSUPPORTED_ANNOTATION_LOGGER;

public class ReportUnstableApiAnnotationsProcessor implements DeploymentUnitProcessor {

private final Supplier<UnstableApiAnnotationLevel> levelSupplier;
private final UnstableApiAnnotationLevel level;

public ReportUnstableApiAnnotationsProcessor(Supplier<UnstableApiAnnotationLevel> levelSupplier) {
this.levelSupplier = levelSupplier;
public ReportUnstableApiAnnotationsProcessor(UnstableApiAnnotationLevel level) {
this.level = level;
}

/**
Expand Down Expand Up @@ -122,7 +121,6 @@ private void reportAnnotationUsages(DeploymentUnit top, AnnotationUsages annotat
}

private AnnotationUsageReporter getAnnotationUsageReporter(DeploymentPhaseContext ctx, DeploymentUnit top) throws DeploymentUnitProcessingException {
UnstableApiAnnotationLevel level = levelSupplier.get();
if (level == UnstableApiAnnotationLevel.ERROR) {
return new ErrorAnnotationUsageReporter();
}
Expand Down
Loading

0 comments on commit 77c2b08

Please sign in to comment.