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

[WFLY-16478] Use 6.0.0 as the new ModelVersion; add domain transforma… #4

Open
wants to merge 5 commits into
base: jca_2.1
Choose a base branch
from
Open
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 @@ -50,7 +50,7 @@ public class Constants {
static final String TX = "TX";
static final String NON_TX = "NonTX";

static final Boolean ELYTRON_MANAGED_SECURITY = Boolean.FALSE;
static final Boolean ELYTRON_MANAGED_SECURITY = Boolean.TRUE;

static final String ELYTRON_ENABLED_NAME = "elytron-enabled";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,8 @@ public class DistributedWorkManagerAdd extends AbstractAddStepHandler {

public static final DistributedWorkManagerAdd INSTANCE = new DistributedWorkManagerAdd();

@Override
protected void populateModel(final ModelNode operation, final ModelNode model) throws OperationFailedException {
for (JcaDistributedWorkManagerDefinition.DWmParameters parameter : JcaDistributedWorkManagerDefinition.DWmParameters.values()) {
parameter.getAttribute().validateAndSet(operation, model);
}
private DistributedWorkManagerAdd() {
super(JcaDistributedWorkManagerDefinition.DWmParameters.getAttributes());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static org.jboss.as.connector.subsystems.jca.Constants.ELYTRON_MANAGED_SECURITY;
import static org.jboss.as.connector.subsystems.jca.JcaWorkManagerDefinition.registerSubModels;

import java.util.Arrays;
import java.util.EnumSet;

import org.jboss.as.connector.metadata.api.common.Security;
Expand Down Expand Up @@ -131,7 +132,6 @@ enum DWmParameters {
.setDefaultValue(new ModelNode(ELYTRON_MANAGED_SECURITY))
.build());


public static AttributeDefinition[] getAttributeDefinitions() {
final AttributeDefinition[] returnValue = new AttributeDefinition[DWmParameters.values().length];
int i = 0;
Expand Down Expand Up @@ -167,6 +167,10 @@ public AttributeDefinition getAttribute() {
}

private AttributeDefinition attribute;

static AttributeDefinition[] getAttributes() {
return Arrays.stream(DWmParameters.values()).map(DWmParameters::getAttribute).toArray(AttributeDefinition[]::new);
}
}

enum DWmCapabilities {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class JcaExtension implements Extension {

public static final String SUBSYSTEM_NAME = "jca";

private static final ModelVersion CURRENT_MODEL_VERSION = ModelVersion.create(5, 0, 0);
private static final ModelVersion CURRENT_MODEL_VERSION = ModelVersion.create(6, 0, 0);

private static final String RESOURCE_NAME = JcaExtension.class.getPackage().getName() + ".LocalDescriptions";

Expand Down Expand Up @@ -113,6 +113,7 @@ public void initializeParsers(final ExtensionParsingContext context) {
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.JCA_3_0.getUriString(), () -> ConnectorSubsystemParser.INSTANCE);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.JCA_4_0.getUriString(), () -> ConnectorSubsystemParser.INSTANCE);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.JCA_5_0.getUriString(), () -> ConnectorSubsystemParser.INSTANCE);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.JCA_6_0.getUriString(), () -> ConnectorSubsystemParser.INSTANCE);
}

static final class ConnectorSubsystemParser implements XMLStreamConstants, XMLElementReader<List<ModelNode>>,
Expand Down Expand Up @@ -323,8 +324,9 @@ public void readElement(final XMLExtendedStreamReader reader, final List<ModelNo
final EnumSet<Element> requiredElement = EnumSet.of(Element.DEFAULT_WORKMANAGER);
boolean ccmAdded = false;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {

switch (Namespace.forUri(reader.getNamespaceURI())) {
Namespace readerNs = Namespace.forUri(reader.getNamespaceURI());
switch (readerNs) {
case JCA_6_0:
case JCA_5_0:
case JCA_4_0:
case JCA_3_0:
Expand All @@ -345,7 +347,7 @@ public void readElement(final XMLExtendedStreamReader reader, final List<ModelNo
break;
}
case DEFAULT_WORKMANAGER: {
parseWorkManager(reader, address, list, subsystem, true);
parseWorkManager(reader, address, list, true, readerNs);
final ModelNode bootstrapContextOperation = new ModelNode();
bootstrapContextOperation.get(OP).set(ADD);
final ModelNode bootStrapCOntextAddress = address.clone();
Expand All @@ -367,13 +369,13 @@ public void readElement(final XMLExtendedStreamReader reader, final List<ModelNo
break;
}
case WORKMANAGER: {
parseWorkManager(reader, address, list, subsystem, false);
parseWorkManager(reader, address, list, false, readerNs);
// AS7-4434 Multiple work managers are allowed
visited.remove(Element.WORKMANAGER);
break;
}
case DISTRIBUTED_WORKMANAGER: {
parseDistributedWorkManager(reader, address, list, subsystem, false);
parseDistributedWorkManager(reader, address, list, readerNs);
// AS7-4434 Multiple work managers are allowed
visited.remove(Element.DISTRIBUTED_WORKMANAGER);
break;
Expand All @@ -385,7 +387,9 @@ public void readElement(final XMLExtendedStreamReader reader, final List<ModelNo
case TRACER: {
if (Namespace.forUri(reader.getNamespaceURI()).equals(Namespace.JCA_3_0) ||
Namespace.forUri(reader.getNamespaceURI()).equals(Namespace.JCA_4_0) ||
Namespace.forUri(reader.getNamespaceURI()).equals(Namespace.JCA_5_0)) {
Namespace.forUri(reader.getNamespaceURI()).equals(Namespace.JCA_5_0) ||
Namespace.forUri(reader.getNamespaceURI()).equals(Namespace.JCA_6_0))
{
list.add(parseTracer(reader, address));
} else {
throw unexpectedElement(reader);
Expand Down Expand Up @@ -465,7 +469,7 @@ private ModelNode parseArchiveValidation(final XMLExtendedStreamReader reader, f
}

private void parseWorkManager(final XMLExtendedStreamReader reader, final ModelNode parentAddress,
final List<ModelNode> list, final ModelNode node, boolean defaultWm) throws XMLStreamException {
final List<ModelNode> list, boolean defaultWm, Namespace elementNs) throws XMLStreamException {

final ModelNode workManagerOperation = new ModelNode();
workManagerOperation.get(OP).set(ADD);
Expand Down Expand Up @@ -524,9 +528,17 @@ private void parseWorkManager(final XMLExtendedStreamReader reader, final ModelN
}
case ELYTRON_ENABLED: {
switch (readerNS) {
case JCA_6_0: {
String value = rawElementText(reader);
JcaWorkManagerDefinition.WmParameters.ELYTRON_ENABLED.getAttribute().parseAndSetParameter(value, workManagerOperation, reader);
break;
}
case JCA_5_0: {
String value = rawElementText(reader);
JcaWorkManagerDefinition.WmParameters.ELYTRON_ENABLED.getAttribute().parseAndSetParameter(value, workManagerOperation, reader);
if (!workManagerOperation.hasDefined(JcaWorkManagerDefinition.WmParameters.ELYTRON_ENABLED.getAttribute().getName())) {
workManagerOperation.get(JcaWorkManagerDefinition.WmParameters.ELYTRON_ENABLED.getAttribute().getName()).set(new ModelNode(false));
}
break;
}
default: {
Expand All @@ -542,10 +554,12 @@ private void parseWorkManager(final XMLExtendedStreamReader reader, final ModelN

}

// For older versions set 'elytron-enabled' to 'false' if not explicitly set, as that was the default in those xsds
handleLegacyWorkManagerSecurity(workManagerOperation, JcaWorkManagerDefinition.WmParameters.ELYTRON_ENABLED.getAttribute(), elementNs);
}

private void parseDistributedWorkManager(final XMLExtendedStreamReader reader, final ModelNode parentAddress,
final List<ModelNode> list, final ModelNode node, boolean defaultWm) throws XMLStreamException {
final List<ModelNode> list, Namespace elementNS) throws XMLStreamException {

final ModelNode distributedWorkManagerOperation = new ModelNode();
distributedWorkManagerOperation.get(OP).set(ADD);
Expand Down Expand Up @@ -603,7 +617,8 @@ private void parseDistributedWorkManager(final XMLExtendedStreamReader reader, f
case JCA_2_0:
case JCA_3_0:
case JCA_4_0:
case JCA_5_0: {
case JCA_5_0:
case JCA_6_0:{
parsePolicy(reader, distributedWorkManagerOperation);
break;
}
Expand All @@ -618,7 +633,8 @@ private void parseDistributedWorkManager(final XMLExtendedStreamReader reader, f
case JCA_2_0:
case JCA_3_0:
case JCA_4_0:
case JCA_5_0: {
case JCA_5_0:
case JCA_6_0:{
parseSelector(reader, distributedWorkManagerOperation);
break;
}
Expand All @@ -630,11 +646,21 @@ private void parseDistributedWorkManager(final XMLExtendedStreamReader reader, f
}
case ELYTRON_ENABLED: {
switch (readerNS) {
case JCA_5_0: {
case JCA_6_0:
{
String value = rawElementText(reader);
((SimpleAttributeDefinition) JcaDistributedWorkManagerDefinition.DWmParameters.ELYTRON_ENABLED.getAttribute()).parseAndSetParameter(value, distributedWorkManagerOperation, reader);
break;
}
case JCA_5_0:
{
String value = rawElementText(reader);
((SimpleAttributeDefinition) JcaDistributedWorkManagerDefinition.DWmParameters.ELYTRON_ENABLED.getAttribute()).parseAndSetParameter(value, distributedWorkManagerOperation, reader);
if (!distributedWorkManagerOperation.hasDefined(JcaDistributedWorkManagerDefinition.DWmParameters.ELYTRON_ENABLED.getAttribute().getName())) {
distributedWorkManagerOperation.get(JcaDistributedWorkManagerDefinition.DWmParameters.ELYTRON_ENABLED.getAttribute().getName()).set(new ModelNode(false));
}
break;
}
default: {
throw unexpectedElement(reader);
}
Expand All @@ -648,6 +674,8 @@ private void parseDistributedWorkManager(final XMLExtendedStreamReader reader, f

}

// For older versions set 'elytron-enabled' to 'false' if not explicitly set, as that was the default in those xsds
handleLegacyWorkManagerSecurity(distributedWorkManagerOperation, JcaDistributedWorkManagerDefinition.DWmParameters.ELYTRON_ENABLED.getAttribute(), elementNS);
}


Expand Down Expand Up @@ -918,5 +946,25 @@ private void writeProperty(XMLExtendedStreamWriter writer, String name, String v
writer.writeEndElement();

}

private static void handleLegacyWorkManagerSecurity(ModelNode addOp, AttributeDefinition ad, Namespace ns) {

if (!addOp.hasDefined(ad.getName())) {
switch (ns) {
case JCA_1_1:
case JCA_2_0:
case JCA_3_0:
case JCA_4_0:
case JCA_5_0:
// set the old default value from these xsd versions
addOp.get(ad.getName()).set(false);
break;
default:
// unconfigured value in later namespaces matches current AttributeDefinition default
break;
}
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, 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.connector.subsystems.jca;

import static org.jboss.as.connector.subsystems.jca.JcaDistributedWorkManagerDefinition.PATH_DISTRIBUTED_WORK_MANAGER;
import static org.jboss.as.connector.subsystems.jca.JcaExtension.SUBSYSTEM_NAME;
import static org.jboss.as.connector.subsystems.jca.JcaWorkManagerDefinition.PATH_WORK_MANAGER;

import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.transform.ExtensionTransformerRegistration;
import org.jboss.as.controller.transform.SubsystemTransformerRegistration;
import org.jboss.as.controller.transform.description.AttributeConverter;
import org.jboss.as.controller.transform.description.ChainedTransformationDescriptionBuilder;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
import org.jboss.as.controller.transform.description.TransformationDescriptionBuilder;

public class JcaTransformers implements ExtensionTransformerRegistration {

private static final ModelVersion EAP_7_4 = ModelVersion.create(5, 0, 0);

@Override
public String getSubsystemName() {
return SUBSYSTEM_NAME;
}

@Override
public void registerTransformers(SubsystemTransformerRegistration subsystemRegistration) {
ChainedTransformationDescriptionBuilder chainedBuilder = TransformationDescriptionBuilder.Factory.createChainedSubystemInstance(subsystemRegistration.getCurrentSubsystemVersion());
get500TransformationDescription(chainedBuilder.createBuilder(subsystemRegistration.getCurrentSubsystemVersion(), EAP_7_4));

chainedBuilder.buildAndRegister(subsystemRegistration, new ModelVersion[]{
EAP_7_4
});
}

private static void get500TransformationDescription(ResourceTransformationDescriptionBuilder parentBuilder) {
parentBuilder.addChildResource(PATH_WORK_MANAGER)
.getAttributeBuilder()
.setValueConverter(AttributeConverter.DEFAULT_VALUE,
JcaWorkManagerDefinition.WmParameters.ELYTRON_ENABLED.getAttribute())
.end();
parentBuilder.addChildResource(PATH_DISTRIBUTED_WORK_MANAGER)
.getAttributeBuilder()
.setValueConverter(AttributeConverter.DEFAULT_VALUE,
JcaDistributedWorkManagerDefinition.DWmParameters.ELYTRON_ENABLED.getAttribute())
.end();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
import static org.jboss.as.connector.subsystems.jca.Constants.WORKMANAGER_SHORT_RUNNING;
import static org.jboss.as.controller.OperationContext.Stage.MODEL;

import java.util.Arrays;
import java.util.Set;

import org.jboss.as.connector.logging.ConnectorLogger;
import org.jboss.as.connector.metadata.api.common.Security;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
Expand Down Expand Up @@ -157,12 +159,14 @@ public enum WmParameters {
.setRestartAllServices()
.setXmlName("name")
.build()),

ELYTRON_ENABLED(new SimpleAttributeDefinitionBuilder(ELYTRON_ENABLED_NAME, ModelType.BOOLEAN, true)
.setXmlName(Security.Tag.ELYTRON_ENABLED.getLocalName())
.setAllowExpression(true)
.setDefaultValue(new ModelNode(ELYTRON_MANAGED_SECURITY))
.build());


WmParameters(SimpleAttributeDefinition attribute) {
this.attribute = attribute;
}
Expand All @@ -172,6 +176,10 @@ public SimpleAttributeDefinition getAttribute() {
}

private SimpleAttributeDefinition attribute;

static AttributeDefinition[] getAttributes() {
return Arrays.stream(WmParameters.values()).map(WmParameters::getAttribute).toArray(AttributeDefinition[]::new);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ public enum Namespace {

JCA_4_0("urn:jboss:domain:jca:4.0"),

JCA_5_0("urn:jboss:domain:jca:5.0");
JCA_5_0("urn:jboss:domain:jca:5.0"),

JCA_6_0("urn:jboss:domain:jca:6.0");


/**
* The current namespace version.
*/
public static final Namespace CURRENT = JCA_5_0;
public static final Namespace CURRENT = JCA_6_0;

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,8 @@ public class WorkManagerAdd extends AbstractAddStepHandler {

public static final WorkManagerAdd INSTANCE = new WorkManagerAdd();


@Override
protected void populateModel(final ModelNode operation, final ModelNode model) throws OperationFailedException {
for (JcaWorkManagerDefinition.WmParameters parameter : JcaWorkManagerDefinition.WmParameters.values()) {
parameter.getAttribute().validateAndSet(operation, model);
}
private WorkManagerAdd() {
super(JcaWorkManagerDefinition.WmParameters.getAttributes());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
#

org.jboss.as.connector.subsystems.datasources.DataSourcesTransformers
org.jboss.as.connector.subsystems.datasources.DataSourcesTransformers
org.jboss.as.connector.subsystems.jca.JcaTransformers
Loading