Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into ladybird
Browse files Browse the repository at this point in the history
  • Loading branch information
darranl committed Feb 20, 2017
2 parents cd5831a + 9bcdf58 commit cbcd558
Show file tree
Hide file tree
Showing 123 changed files with 4,765 additions and 1,277 deletions.
Expand Up @@ -24,6 +24,7 @@

import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiPredicate;
import java.util.stream.Stream;
Expand All @@ -39,6 +40,8 @@
import org.jboss.as.controller.SimpleOperationDefinitionBuilder;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.OperationEntry;
import org.jboss.as.controller.registry.Resource;
Expand All @@ -59,7 +62,6 @@ public AddStepHandler(AddStepHandlerDescriptor descriptor) {
}

public AddStepHandler(AddStepHandlerDescriptor descriptor, ResourceServiceHandler handler) {
super(descriptor.getAttributes());
this.descriptor = descriptor;
this.handler = handler;
}
Expand Down Expand Up @@ -124,7 +126,8 @@ protected void populateModel(OperationContext context, ModelNode operation, Reso
definition.validateOperation(operation);
}
// Validate and apply attribute translations
for (Map.Entry<AttributeDefinition, AttributeTranslation> entry : this.descriptor.getAttributeTranslations().entrySet()) {
Map<AttributeDefinition, AttributeTranslation> translations = this.descriptor.getAttributeTranslations();
for (Map.Entry<AttributeDefinition, AttributeTranslation> entry : translations.entrySet()) {
AttributeDefinition alias = entry.getKey();
AttributeTranslation translation = entry.getValue();
Attribute target = translation.getTargetAttribute();
Expand All @@ -136,8 +139,16 @@ protected void populateModel(OperationContext context, ModelNode operation, Reso
operation.get(targetName).set(translatedValue);
}
}

super.populateModel(context, operation, resource);
// Validate proper attributes
ModelNode model = resource.getModel();
ImmutableManagementResourceRegistration registration = context.getResourceRegistration();
for (String attributeName : registration.getAttributeNames(PathAddress.EMPTY_ADDRESS)) {
AttributeAccess attribute = registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, attributeName);
AttributeDefinition definition = attribute.getAttributeDefinition();
if ((attribute.getStorageType() == AttributeAccess.Storage.CONFIGURATION) && !translations.containsKey(definition)) {
definition.validateAndSet(operation, model);
}
}

// Auto-create required child resources as necessary
addRequiredChildren(context, this.descriptor.getRequiredChildren(), (Resource parent, PathElement path) -> parent.hasChild(path));
Expand Down Expand Up @@ -170,9 +181,13 @@ protected void recordCapabilitiesAndRequirements(OperationContext context, Model
// Only register capabilities when allowed by the associated predicate
this.descriptor.getCapabilities().entrySet().stream().filter(entry -> entry.getValue().test(model)).map(Map.Entry::getKey).forEach(capability -> context.registerCapability(capability.resolve(address)));

this.attributes.stream()
.filter(attribute -> attribute.hasCapabilityRequirements())
.forEach(attribute -> attribute.addCapabilityRequirements(context, model.get(attribute.getName())));
ImmutableManagementResourceRegistration registration = context.getResourceRegistration();
registration.getAttributeNames(PathAddress.EMPTY_ADDRESS).stream().map(name -> registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, name))
.filter(Objects::nonNull)
.map(AttributeAccess::getAttributeDefinition)
.filter(Objects::nonNull)
.filter(AttributeDefinition::hasCapabilityRequirements)
.forEach(attribute -> attribute.addCapabilityRequirements(context, model.get(attribute.getName())));

this.descriptor.getResourceCapabilityReferences().forEach((reference, resolver) -> reference.addCapabilityRequirements(context, null, resolver.apply(address)));
}
Expand Down
@@ -0,0 +1,62 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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 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 software 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 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.clustering.controller;

import java.util.Optional;

import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler;
import org.jboss.as.controller.operations.common.OrderedChildTypesAttachment;
import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.Resource;
import org.jboss.dmr.ModelNode;

/**
* Custom subsystem describe operation handler that works with override models.
* Workaround for WFCORE-2286.
* @author Paul Ferraro
*/
public class DefaultSubsystemDescribeHandler extends GenericSubsystemDescribeHandler implements Registration<ManagementResourceRegistration> {

@Override
protected void describe(OrderedChildTypesAttachment orderedChildTypesAttachment, Resource resource, ModelNode addressModel, ModelNode result, ImmutableManagementResourceRegistration registration) {
if (resource == null || registration.isRemote() || registration.isRuntimeOnly() || resource.isProxy() || resource.isRuntime() || registration.isAlias()) return;
result.add(createAddOperation(orderedChildTypesAttachment, addressModel, resource, registration.getChildAddresses(PathAddress.EMPTY_ADDRESS)));
PathAddress address = PathAddress.pathAddress(addressModel);
for (String type : resource.getChildTypes()) {
for (Resource.ResourceEntry entry : resource.getChildren(type)) {
PathElement path = entry.getPathElement();
ImmutableManagementResourceRegistration childRegistration = Optional.ofNullable(registration.getSubModel(PathAddress.pathAddress(path))).orElse(registration.getSubModel(PathAddress.pathAddress(PathElement.pathElement(path.getKey()))));
PathAddress childAddress = address.append(path);
this.describe(orderedChildTypesAttachment, entry, childAddress.toModelNode(), result, childRegistration);
}
}
}

@Override
public void register(ManagementResourceRegistration registration) {
registration.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, this);
}
}
Expand Up @@ -26,12 +26,14 @@
import java.util.Objects;

import org.jboss.as.controller.AbstractRemoveStepHandler;
import org.jboss.as.controller.AttributeDefinition;
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.SimpleOperationDefinitionBuilder;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.OperationEntry;
Expand Down Expand Up @@ -80,9 +82,9 @@ protected void performRemove(OperationContext context, ModelNode operation, Mode
ImmutableManagementResourceRegistration registration = context.getResourceRegistration();
registration.getAttributeNames(PathAddress.EMPTY_ADDRESS).stream().map(name -> registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, name))
.filter(Objects::nonNull)
.map(access -> access.getAttributeDefinition())
.map(AttributeAccess::getAttributeDefinition)
.filter(Objects::nonNull)
.filter(attribute -> attribute.hasCapabilityRequirements())
.filter(AttributeDefinition::hasCapabilityRequirements)
.forEach(attribute -> attribute.removeCapabilityRequirements(context, model.get(attribute.getName())));

this.descriptor.getResourceCapabilityReferences().forEach((reference, resolver) -> reference.removeCapabilityRequirements(context, null, resolver.apply(address)));
Expand Down
Expand Up @@ -48,13 +48,15 @@ protected ResourceRegistration(AddStepHandlerDescriptor descriptor, Registration

@Override
public void register(ManagementResourceRegistration registration) {
this.addRegistration.register(registration);
this.removeRegistration.register(registration);
new CapabilityRegistration(this.descriptor.getCapabilities().keySet()).register(registration);

// Register attributes before add operation
this.writeAttributeRegistration.register(registration);

// Register read/write handlers for attribute translations
// Register attribute translations
this.descriptor.getAttributeTranslations().entrySet().forEach(entry -> registration.registerReadWriteAttribute(entry.getKey(), new ReadAttributeTranslationHandler(entry.getValue()), new WriteAttributeTranslationHandler(entry.getValue())));

new CapabilityRegistration(this.descriptor.getCapabilities().keySet()).register(registration);
this.addRegistration.register(registration);
this.removeRegistration.register(registration);
}
}
Expand Up @@ -23,9 +23,9 @@

import java.util.Map;

import org.jboss.as.clustering.controller.Operations;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.transform.OperationResultTransformer;
import org.jboss.as.controller.transform.OperationTransformer;
import org.jboss.as.controller.transform.TransformationContext;
Expand All @@ -45,7 +45,7 @@ public AttributeOperationTransformer(Map<String, OperationTransformer> transform

@Override
public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) throws OperationFailedException {
String name = operation.get(ModelDescriptionConstants.NAME).asString();
String name = Operations.getName(operation);
OperationTransformer transformer = this.transformers.get(name);
return (transformer != null) ? transformer.transformOperation(context, address, operation) : new TransformedOperation(operation, OperationResultTransformer.ORIGINAL_RESULT);
}
Expand Down
Expand Up @@ -24,7 +24,6 @@

import org.jboss.as.clustering.controller.Operations;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.transform.OperationResultTransformer;
import org.jboss.as.controller.transform.OperationTransformer;
import org.jboss.as.controller.transform.TransformationContext;
Expand All @@ -45,7 +44,7 @@ public SimplePathOperationTransformer(PathAddressTransformer addressTransformer)
@Override
public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) {
ModelNode legacyOperation = operation.clone();
legacyOperation.get(ModelDescriptionConstants.OP_ADDR).set(this.addressTransformer.transform(address).toModelNode());
Operations.setPathAddress(legacyOperation, this.addressTransformer.transform(address));

InitialAttributeValueOperationContextAttachment attachment = context.getAttachment(InitialAttributeValueOperationContextAttachment.INITIAL_VALUES_ATTACHMENT);
if (attachment != null) {
Expand Down
Expand Up @@ -23,17 +23,13 @@

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.jboss.as.clustering.jgroups.logging.JGroupsLogger;
import org.jboss.modules.ModuleLoader;
import org.jgroups.Channel;
import org.jgroups.fork.ForkChannel;
import org.jgroups.stack.Configurator;
import org.jgroups.protocols.TP;
import org.jgroups.stack.Protocol;
import org.jgroups.stack.ProtocolStack;
import org.wildfly.clustering.jgroups.spi.ChannelFactory;
import org.wildfly.clustering.jgroups.spi.ProtocolConfiguration;
import org.wildfly.clustering.jgroups.spi.ProtocolStackConfiguration;
Expand All @@ -47,34 +43,28 @@
public class ForkChannelFactory implements ChannelFactory {

private final ChannelFactory parentFactory;
private final List<ProtocolConfiguration> protocols;
private final List<ProtocolConfiguration<? extends Protocol>> protocols;
private final Channel channel;

public ForkChannelFactory(Channel channel, ChannelFactory parentFactory, List<ProtocolConfiguration> protocols) {
public ForkChannelFactory(Channel channel, ChannelFactory parentFactory, List<ProtocolConfiguration<? extends Protocol>> protocols) {
this.channel = channel;
this.parentFactory = parentFactory;
this.protocols = protocols;
}

public ForkChannelFactory(Channel channel, ChannelFactory parentFactory, ProtocolConfiguration... protocols) {
this(channel, parentFactory, Arrays.asList(protocols));
}

@Override
public Channel createChannel(String id) throws Exception {
JGroupsLogger.ROOT_LOGGER.debugf("Creating fork channel %s from channel %s", id, this.channel.getClusterName());

String stackName = this.protocols.isEmpty() ? this.channel.getClusterName() : id;
ProtocolStackConfiguration forkStack = new ForkProtocolStackConfiguration(stackName, this.parentFactory.getProtocolStackConfiguration(), this.protocols);
List<Protocol> protocols = Configurator.createProtocols(JChannelFactory.createProtocols(forkStack, this.channel.getProtocolStack().getTransport().isMulticastCapable()), new ProtocolStack());

return new ForkChannel(this.channel, stackName, id, protocols.toArray(new Protocol[protocols.size()]));
return new ForkChannel(this.channel, stackName, id, this.protocols.stream().map(ProtocolConfiguration::createProtocol).toArray(Protocol[]::new));
}

@Override
public ProtocolStackConfiguration getProtocolStackConfiguration() {
List<ProtocolConfiguration> parentProtocols = this.parentFactory.getProtocolStackConfiguration().getProtocols();
List<ProtocolConfiguration> protocols = new ArrayList<>(parentProtocols.size() + this.protocols.size());
List<ProtocolConfiguration<? extends Protocol>> parentProtocols = this.parentFactory.getProtocolStackConfiguration().getProtocols();
List<ProtocolConfiguration<? extends Protocol>> protocols = new ArrayList<>(parentProtocols.size() + this.protocols.size());
protocols.addAll(parentProtocols);
protocols.addAll(this.protocols);
return new ForkProtocolStackConfiguration(this.channel.getClusterName(), this.parentFactory.getProtocolStackConfiguration(), protocols);
Expand All @@ -87,10 +77,10 @@ public boolean isUnknownForkResponse(ByteBuffer response) {

private static class ForkProtocolStackConfiguration implements ProtocolStackConfiguration {
private final String name;
private final List<ProtocolConfiguration> protocols;
private final List<ProtocolConfiguration<? extends Protocol>> protocols;
private final ProtocolStackConfiguration parentStack;

ForkProtocolStackConfiguration(String name, ProtocolStackConfiguration parentStack, List<ProtocolConfiguration> protocols) {
ForkProtocolStackConfiguration(String name, ProtocolStackConfiguration parentStack, List<ProtocolConfiguration<? extends Protocol>> protocols) {
this.name = name;
this.protocols = protocols;
this.parentStack = parentStack;
Expand All @@ -102,25 +92,15 @@ public String getName() {
}

@Override
public List<ProtocolConfiguration> getProtocols() {
public List<ProtocolConfiguration<? extends Protocol>> getProtocols() {
return this.protocols;
}

@Override
public Map<String, String> getDefaultProperties(String protocol) {
return this.parentStack.getDefaultProperties(protocol);
}

@Override
public TransportConfiguration getTransport() {
public TransportConfiguration<? extends TP> getTransport() {
return this.parentStack.getTransport();
}

@Override
public ModuleLoader getModuleLoader() {
return this.parentStack.getModuleLoader();
}

@Override
public String getNodeName() {
return this.parentStack.getNodeName();
Expand Down

0 comments on commit cbcd558

Please sign in to comment.