Skip to content

Commit

Permalink
Migrate discovery subsystem to SubsystemResourceXMLSchema.
Browse files Browse the repository at this point in the history
  • Loading branch information
pferraro committed Nov 27, 2024
1 parent b6689e8 commit a44cf96
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.wildfly.extension.discovery;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;

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.dmr.ModelNode;
import org.wildfly.discovery.impl.AggregateDiscoveryProvider;
import org.wildfly.discovery.spi.DiscoveryProvider;
import org.wildfly.subsystem.resource.capability.CapabilityReference;
import org.wildfly.subsystem.resource.capability.CapabilityReferenceListAttributeDefinition;
import org.wildfly.subsystem.service.ServiceDependency;

/**
* Describes an aggregate discovery provider resource.
* @author Paul Ferraro
*/
public enum AggregateDiscoveryProviderResourceDescription implements DiscoveryProviderResourceDescription {
INSTANCE;

static final CapabilityReferenceListAttributeDefinition<DiscoveryProvider> PROVIDER_NAMES = new CapabilityReferenceListAttributeDefinition.Builder<>("providers", CapabilityReference.builder(DiscoveryProviderResourceRegistrar.DISCOVERY_PROVIDER_CAPABILITY, DiscoveryProviderResourceRegistrar.DISCOVERY_PROVIDER_DESCRIPTOR).build()).build();

private final PathElement path = PathElement.pathElement("aggregate-provider");

@Override
public PathElement getPathElement() {
return this.path;
}

@Override
public Stream<AttributeDefinition> getAttributes() {
return Stream.of(PROVIDER_NAMES);
}

@Override
public ServiceDependency<DiscoveryProvider> resolve(OperationContext context, ModelNode model) throws OperationFailedException {
return AggregateDiscoveryProviderResourceDescription.PROVIDER_NAMES.resolve(context, model).map(new Function<>() {
@Override
public DiscoveryProvider apply(List<DiscoveryProvider> providers) {
return new AggregateDiscoveryProvider(providers.toArray(DiscoveryProvider[]::new));
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@
*/
package org.wildfly.extension.discovery;

import java.util.Collection;
import java.util.List;
import java.util.function.Function;

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.dmr.ModelNode;
import org.wildfly.discovery.impl.AggregateDiscoveryProvider;
import org.wildfly.discovery.spi.DiscoveryProvider;
import org.wildfly.subsystem.resource.ResourceDescriptor;
import org.wildfly.subsystem.resource.capability.CapabilityReference;
import org.wildfly.subsystem.resource.capability.CapabilityReferenceListAttributeDefinition;
import org.wildfly.subsystem.service.ResourceServiceInstaller;
import org.wildfly.subsystem.service.ServiceDependency;
import org.wildfly.subsystem.service.capability.CapabilityServiceInstaller;
Expand All @@ -26,21 +20,15 @@
* Registers the aggregate discovery provider resource definition.
* @author Paul Ferraro
*/
public class AggregateDiscoveryProviderRegistrar extends DiscoveryProviderRegistrar {
public class AggregateDiscoveryProviderResourceRegistrar extends DiscoveryProviderResourceRegistrar {

static final PathElement PATH = PathElement.pathElement("aggregate-provider");

private static final CapabilityReferenceListAttributeDefinition<DiscoveryProvider> PROVIDER_NAMES = new CapabilityReferenceListAttributeDefinition.Builder<>("providers", CapabilityReference.builder(DISCOVERY_PROVIDER_CAPABILITY, DISCOVERY_PROVIDER_DESCRIPTOR).build()).build();

static final Collection<AttributeDefinition> ATTRIBUTES = List.of(PROVIDER_NAMES);

AggregateDiscoveryProviderRegistrar() {
super(PATH, ResourceDescriptor.builder(DiscoverySubsystemRegistrar.RESOLVER.createChildResolver(PATH)).addAttributes(ATTRIBUTES));
AggregateDiscoveryProviderResourceRegistrar() {
super(AggregateDiscoveryProviderResourceDescription.INSTANCE);
}

@Override
public ResourceServiceInstaller configure(OperationContext context, ModelNode model) throws OperationFailedException {
ServiceDependency<DiscoveryProvider> provider = PROVIDER_NAMES.resolve(context, model).map(new Function<>() {
ServiceDependency<DiscoveryProvider> provider = AggregateDiscoveryProviderResourceDescription.PROVIDER_NAMES.resolve(context, model).map(new Function<>() {
@Override
public DiscoveryProvider apply(List<DiscoveryProvider> providers) {
return new AggregateDiscoveryProvider(providers.toArray(DiscoveryProvider[]::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
public class DiscoveryExtension extends SubsystemExtension<DiscoverySubsystemSchema> {

public DiscoveryExtension() {
super(SubsystemConfiguration.of(DiscoverySubsystemRegistrar.NAME, DiscoverySubsystemModel.CURRENT, DiscoverySubsystemRegistrar::new), SubsystemPersistence.of(DiscoverySubsystemSchema.CURRENT));
super(SubsystemConfiguration.of(DiscoverySubsystemResourceDescription.INSTANCE, DiscoverySubsystemModel.CURRENT, DiscoverySubsystemResourceRegistrar::new), SubsystemPersistence.of(DiscoverySubsystemSchema.CURRENT));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
public class DiscoveryExtensionTransformerRegistration extends SubsystemExtensionTransformerRegistration {

public DiscoveryExtensionTransformerRegistration() {
super(DiscoverySubsystemRegistrar.NAME, DiscoverySubsystemModel.CURRENT, DiscoverySubsystemTransformationDescriptionFactory.INSTANCE);
super(DiscoverySubsystemResourceDescription.INSTANCE, DiscoverySubsystemModel.CURRENT, DiscoverySubsystemTransformationDescriptionFactory.INSTANCE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.wildfly.extension.discovery;

import org.jboss.as.controller.ResourceDescription;
import org.wildfly.discovery.spi.DiscoveryProvider;
import org.wildfly.subsystem.resource.ResourceModelResolver;
import org.wildfly.subsystem.service.ServiceDependency;

/**
* Describes a discovery provider resource
*/
public interface DiscoveryProviderResourceDescription extends ResourceDescription, ResourceModelResolver<ServiceDependency<DiscoveryProvider>> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
*/
package org.wildfly.extension.discovery;

import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.ResourceDefinition;
import org.jboss.as.controller.ResourceRegistration;
import org.jboss.as.controller.capability.RuntimeCapability;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.dmr.ModelNode;
import org.wildfly.discovery.spi.DiscoveryProvider;
import org.wildfly.service.descriptor.UnaryServiceDescriptor;
import org.wildfly.subsystem.resource.ChildResourceDefinitionRegistrar;
Expand All @@ -17,34 +18,42 @@
import org.wildfly.subsystem.resource.ResourceDescriptor;
import org.wildfly.subsystem.resource.operation.ResourceOperationRuntimeHandler;
import org.wildfly.subsystem.service.ResourceServiceConfigurator;
import org.wildfly.subsystem.service.ResourceServiceInstaller;
import org.wildfly.subsystem.service.capability.CapabilityServiceInstaller;

/**
* Abstract registrar for a discovery provider resource definition.
* @author Paul Ferraro
*/
public abstract class DiscoveryProviderRegistrar implements ChildResourceDefinitionRegistrar, ResourceServiceConfigurator {
public class DiscoveryProviderResourceRegistrar implements ChildResourceDefinitionRegistrar, ResourceServiceConfigurator {

// TODO Move this to an SPI module, when this capability acquires any consumers
static final UnaryServiceDescriptor<DiscoveryProvider> DISCOVERY_PROVIDER_DESCRIPTOR = UnaryServiceDescriptor.of("org.wildfly.discovery.provider", DiscoveryProvider.class);
static final RuntimeCapability<Void> DISCOVERY_PROVIDER_CAPABILITY = RuntimeCapability.Builder.of(DISCOVERY_PROVIDER_DESCRIPTOR).setAllowMultipleRegistrations(true).build();

private final ResourceRegistration registration;
private final ResourceDescriptor descriptor;
private final DiscoveryProviderResourceDescription description;

DiscoveryProviderRegistrar(PathElement path, ResourceDescriptor.Builder builder) {
this.registration = ResourceRegistration.of(path);
this.descriptor = builder.addCapability(DISCOVERY_PROVIDER_CAPABILITY)
.withRuntimeHandler(ResourceOperationRuntimeHandler.configureService(this))
.build();
DiscoveryProviderResourceRegistrar(DiscoveryProviderResourceDescription description) {
this.description = description;
}

@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent, ManagementResourceRegistrationContext context) {
ResourceDefinition definition = ResourceDefinition.builder(this.registration, this.descriptor.getResourceDescriptionResolver()).build();
ResourceDescriptor descriptor = ResourceDescriptor.builder(DiscoverySubsystemResourceRegistrar.RESOLVER.createChildResolver(this.description.getPathElement()))
.addAttributes(this.description.getAttributes().toList())
.addCapability(DISCOVERY_PROVIDER_CAPABILITY)
.withRuntimeHandler(ResourceOperationRuntimeHandler.configureService(this))
.build();
ResourceDefinition definition = ResourceDefinition.builder(this.description, descriptor.getResourceDescriptionResolver()).build();
ManagementResourceRegistration registration = parent.registerSubModel(definition);

ManagementResourceRegistrar.of(this.descriptor).register(registration);
ManagementResourceRegistrar.of(descriptor).register(registration);

return registration;
}

@Override
public ResourceServiceInstaller configure(OperationContext context, ModelNode model) throws OperationFailedException {
return CapabilityServiceInstaller.builder(DiscoveryProviderResourceRegistrar.DISCOVERY_PROVIDER_CAPABILITY, this.description.resolve(context, model)).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.wildfly.extension.discovery;

import org.jboss.as.controller.SubsystemResourceDescription;

/**
* Describes the discovery subsystem resource.
*/
public enum DiscoverySubsystemResourceDescription implements SubsystemResourceDescription {
INSTANCE;

@Override
public String getName() {
return "discovery";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

package org.wildfly.extension.discovery;

import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ResourceDefinition;
import org.jboss.as.controller.ResourceRegistration;
import org.jboss.as.controller.SubsystemRegistration;
import org.jboss.as.controller.descriptions.ParentResourceDescriptionResolver;
import org.jboss.as.controller.descriptions.SubsystemResourceDescriptionResolver;
Expand All @@ -21,23 +19,21 @@
* Registrar for the discovery subsystem.
* @author Paul Ferraro
*/
class DiscoverySubsystemRegistrar implements SubsystemResourceDefinitionRegistrar {
class DiscoverySubsystemResourceRegistrar implements SubsystemResourceDefinitionRegistrar {

static final String NAME = "discovery";
static final PathElement PATH = SubsystemResourceDefinitionRegistrar.pathElement(NAME);
static final ParentResourceDescriptionResolver RESOLVER = new SubsystemResourceDescriptionResolver(NAME, DiscoverySubsystemRegistrar.class);
static final ParentResourceDescriptionResolver RESOLVER = new SubsystemResourceDescriptionResolver(DiscoverySubsystemResourceDescription.INSTANCE.getName(), DiscoverySubsystemResourceRegistrar.class);

@Override
public ManagementResourceRegistration register(SubsystemRegistration parent, ManagementResourceRegistrationContext context) {
parent.setHostCapable();

ManagementResourceRegistration registration = parent.registerSubsystemModel(ResourceDefinition.builder(ResourceRegistration.of(PATH), RESOLVER).build());
ManagementResourceRegistration registration = parent.registerSubsystemModel(ResourceDefinition.builder(DiscoverySubsystemResourceDescription.INSTANCE, RESOLVER).build());
ResourceDescriptor descriptor = ResourceDescriptor.builder(RESOLVER).build();

ManagementResourceRegistrar.of(descriptor).register(registration);

new AggregateDiscoveryProviderRegistrar().register(registration, context);
new StaticDiscoveryProviderRegistrar().register(registration, context);
new AggregateDiscoveryProviderResourceRegistrar().register(registration, context);
new StaticDiscoveryProviderResourceRegistrar().register(registration, context);

return registration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,29 @@

package org.wildfly.extension.discovery;

import org.jboss.as.controller.PersistentResourceXMLDescription;
import org.jboss.as.controller.PersistentSubsystemSchema;
import java.util.List;

import org.jboss.as.controller.SubsystemSchema;
import org.jboss.as.controller.persistence.xml.ResourceXMLElement;
import org.jboss.as.controller.persistence.xml.SubsystemResourceXMLSchema;
import org.jboss.as.controller.xml.VersionedNamespace;
import org.jboss.as.controller.xml.XMLCardinality;
import org.jboss.as.controller.xml.XMLChoice;
import org.jboss.staxmapper.IntVersion;

/**
* Enumeration of discovery subsystem schema versions.
* @author Paul Ferraro
*/
enum DiscoverySubsystemSchema implements PersistentSubsystemSchema<DiscoverySubsystemSchema> {
enum DiscoverySubsystemSchema implements SubsystemResourceXMLSchema<DiscoverySubsystemSchema> {
VERSION_1_0(1, 0),
;
static final DiscoverySubsystemSchema CURRENT = VERSION_1_0;

private final VersionedNamespace<IntVersion, DiscoverySubsystemSchema> namespace;

DiscoverySubsystemSchema(int major, int minor) {
this.namespace = SubsystemSchema.createLegacySubsystemURN(DiscoverySubsystemRegistrar.NAME, new IntVersion(major, minor));
this.namespace = SubsystemSchema.createLegacySubsystemURN(DiscoverySubsystemResourceDescription.INSTANCE.getName(), new IntVersion(major, minor));
}

@Override
Expand All @@ -32,11 +36,10 @@ public VersionedNamespace<IntVersion, DiscoverySubsystemSchema> getNamespace() {
}

@Override
public PersistentResourceXMLDescription getXMLDescription() {
PersistentResourceXMLDescription.Factory factory = PersistentResourceXMLDescription.factory(this);
return factory.builder(DiscoverySubsystemRegistrar.PATH)
.addChild(factory.builder(StaticDiscoveryProviderRegistrar.PATH).addAttributes(StaticDiscoveryProviderRegistrar.ATTRIBUTES.stream()).build())
.addChild(factory.builder(AggregateDiscoveryProviderRegistrar.PATH).addAttributes(AggregateDiscoveryProviderRegistrar.ATTRIBUTES.stream()).build())
public ResourceXMLElement getSubsystemResourceXMLElement() {
ResourceXMLElement.Builder.Factory factory = ResourceXMLElement.Builder.Factory.newInstance(this);
return factory.createBuilder(DiscoverySubsystemResourceDescription.INSTANCE)
.appendChild(XMLChoice.of(List.of(factory.createBuilder(StaticDiscoveryProviderResourceDescription.INSTANCE).build(), factory.createBuilder(AggregateDiscoveryProviderResourceDescription.INSTANCE).build()), XMLCardinality.Unbounded.OPTIONAL))
.build();
}
}
Loading

0 comments on commit a44cf96

Please sign in to comment.