Skip to content

Commit

Permalink
Merge pull request #11123 from ochaloup/WFLY-9818-xts-async-dot-net-i…
Browse files Browse the repository at this point in the history
…ntegration

[WFLY-9818] xts adding element to enable async endpoints registration
  • Loading branch information
kabir committed Jun 25, 2018
2 parents b93e87e + 9a23497 commit 1bf993b
Show file tree
Hide file tree
Showing 16 changed files with 440 additions and 80 deletions.
1 change: 1 addition & 0 deletions xts/src/main/java/org/jboss/as/xts/CommonAttributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ interface CommonAttributes {
String HOST = "host";
String XTS_ENVIRONMENT= "xts-environment";
String DEFAULT_CONTEXT_PROPAGATION = "default-context-propagation";
String ASYNC_REGISTRATION = "async-registration";
// TODO, many more!
}
1 change: 1 addition & 0 deletions xts/src/main/java/org/jboss/as/xts/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ enum Element {
HOST(CommonAttributes.HOST),
XTS_ENVIRONMENT(CommonAttributes.XTS_ENVIRONMENT),
DEFAULT_CONTEXT_PROPAGATION(CommonAttributes.DEFAULT_CONTEXT_PROPAGATION),
ASYNC_REGISTRATION(CommonAttributes.ASYNC_REGISTRATION),
;

private final String name;
Expand Down
3 changes: 2 additions & 1 deletion xts/src/main/java/org/jboss/as/xts/Namespace.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ enum Namespace {

XTS_1_0("urn:jboss:domain:xts:1.0"),
XTS_2_0("urn:jboss:domain:xts:2.0"),
XTS_3_0("urn:jboss:domain:xts:3.0"),
;

/**
* The current namespace version.
*/
public static final Namespace CURRENT = XTS_2_0;
public static final Namespace CURRENT = XTS_3_0;

private final String name;

Expand Down
3 changes: 2 additions & 1 deletion xts/src/main/java/org/jboss/as/xts/XTSExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public class XTSExtension implements Extension {
public static final String SUBSYSTEM_NAME = "xts";
protected static final PathElement SUBSYSTEM_PATH = PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, SUBSYSTEM_NAME);

static final ModelVersion CURRENT_MODEL_VERSION = ModelVersion.create(3, 0, 0);

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

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

static StandardResourceDescriptionResolver getResourceDescriptionResolver(final String keyPrefix) {
String prefix = SUBSYSTEM_NAME + (keyPrefix == null ? "" : "." + keyPrefix);
Expand All @@ -64,5 +64,6 @@ public void initialize(ExtensionContext context) {
public void initializeParsers(ExtensionParsingContext context) {
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.XTS_1_0.getUriString(), XTSSubsystemParser::new);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.XTS_2_0.getUriString(), XTSSubsystemParser::new);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.XTS_3_0.getUriString(), XTSSubsystemParser::new);
}
}
39 changes: 31 additions & 8 deletions xts/src/main/java/org/jboss/as/xts/XTSSubsystemAdd.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
import static org.jboss.as.xts.XTSSubsystemDefinition.DEFAULT_CONTEXT_PROPAGATION;
import static org.jboss.as.xts.XTSSubsystemDefinition.ENVIRONMENT_URL;
import static org.jboss.as.xts.XTSSubsystemDefinition.HOST_NAME;
import static org.jboss.as.xts.XTSSubsystemDefinition.ASYNC_REGISTRATION;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
Expand All @@ -48,7 +51,10 @@
import com.arjuna.webservices11.wsba.sei.BusinessAgreementWithParticipantCompletionCoordinatorPortTypeImpl;
import com.arjuna.webservices11.wsba.sei.BusinessAgreementWithParticipantCompletionParticipantPortTypeImpl;
import com.arjuna.webservices11.wscoor.sei.ActivationPortTypeImpl;
import com.arjuna.webservices11.wscoor.sei.CoordinationFaultPortTypeImpl;
import com.arjuna.webservices11.wscoor.sei.RegistrationPortTypeImpl;
import com.arjuna.webservices11.wscoor.sei.RegistrationResponsePortTypeImpl;

import org.jboss.as.controller.AbstractBoottimeAddStepHandler;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
Expand Down Expand Up @@ -79,6 +85,8 @@
import org.oasis_open.docs.ws_tx.wsba._2006._06.BusinessAgreementWithParticipantCompletionCoordinatorService;
import org.oasis_open.docs.ws_tx.wsba._2006._06.BusinessAgreementWithParticipantCompletionParticipantService;
import org.oasis_open.docs.ws_tx.wscoor._2006._06.ActivationService;
import org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationFaultService;
import org.oasis_open.docs.ws_tx.wscoor._2006._06.RegistrationResponseService;
import org.oasis_open.docs.ws_tx.wscoor._2006._06.RegistrationService;


Expand Down Expand Up @@ -136,11 +144,7 @@ static class ContextInfo {
* publisher API rather than via war files containing web.xml descriptors
*/
private static final ContextInfo[] contextDefinitions = {
new ContextInfo("ws-c11",
new EndpointInfo[]{
new EndpointInfo(ActivationPortTypeImpl.class.getName(), ActivationService.class.getSimpleName()),
new EndpointInfo(RegistrationPortTypeImpl.class.getName(), RegistrationService.class.getSimpleName())
}),
// ContextInfo ws-c11 filled at method getContextDefinitions
new ContextInfo("ws-t11-coordinator",
new EndpointInfo[]{
new EndpointInfo(CoordinatorPortTypeImpl.class.getName(), CoordinatorService.class.getSimpleName()),
Expand All @@ -164,18 +168,37 @@ static class ContextInfo {
})
};

static final EndpointInfo[] wsC11 = new EndpointInfo[] {
new EndpointInfo(ActivationPortTypeImpl.class.getName(), ActivationService.class.getSimpleName()),
new EndpointInfo(RegistrationPortTypeImpl.class.getName(), RegistrationService.class.getSimpleName())
};
static final EndpointInfo[] wsC11Async = new EndpointInfo[] {
new EndpointInfo(RegistrationResponsePortTypeImpl.class.getName(), RegistrationResponseService.class.getSimpleName()),
new EndpointInfo(CoordinationFaultPortTypeImpl.class.getName(), CoordinationFaultService.class.getSimpleName())
};

private XTSSubsystemAdd() {
}

static ContextInfo[] getContextDefinitions() {
return contextDefinitions;
static Iterable<ContextInfo> getContextDefinitions(OperationContext context, ModelNode model) throws IllegalArgumentException, OperationFailedException {
Collection<ContextInfo> updatedContextDefinitions = new ArrayList<>(Arrays.asList(contextDefinitions));
Collection<EndpointInfo> wsC11EndpointInfos = new ArrayList<>(Arrays.asList(wsC11));
if(ASYNC_REGISTRATION.resolveModelAttribute(context, model).asBoolean()) {
wsC11EndpointInfos.addAll(Arrays.asList(wsC11Async));
}

ContextInfo wsC11ContextInfo = new ContextInfo("ws-c11", wsC11EndpointInfos.toArray(new EndpointInfo[wsC11EndpointInfos.size()]));
updatedContextDefinitions.add(wsC11ContextInfo);

return updatedContextDefinitions;
}

@Override
protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException {
HOST_NAME.validateAndSet(operation, model);
ENVIRONMENT_URL.validateAndSet(operation, model);
DEFAULT_CONTEXT_PROPAGATION.validateAndSet(operation, model);
ASYNC_REGISTRATION.validateAndSet(operation, model);
}


Expand Down Expand Up @@ -233,7 +256,7 @@ protected void execute(DeploymentProcessorTarget processorTarget) {
ArrayList<ServiceController<Context>> controllers = new ArrayList<ServiceController<Context>>();
Map<Class<?>, Object> attachments = new HashMap<>();
attachments.put(RejectionRule.class, new GracefulShutdownRejectionRule());
for (ContextInfo contextInfo : contextDefinitions) {
for (ContextInfo contextInfo : getContextDefinitions(context, model)) {
String contextName = contextInfo.contextPath;
Map<String, String> map = new HashMap<String, String>();
for (EndpointInfo endpointInfo : contextInfo.endpointInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ public class XTSSubsystemDefinition extends SimpleResourceDefinition {
.setFlags(AttributeAccess.Flag.RESTART_JVM)
.build();

protected static final SimpleAttributeDefinition ASYNC_REGISTRATION =
new SimpleAttributeDefinitionBuilder(CommonAttributes.ASYNC_REGISTRATION, ModelType.BOOLEAN, true)
.setAllowExpression(true)
.setXmlName(Attribute.ENABLED.getLocalName())
.setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES) // we need to register new WS endpoints
.setDefaultValue(new ModelNode(false))
.build();

@Deprecated //just legacy support
private static final ObjectTypeAttributeDefinition ENVIRONMENT = ObjectTypeAttributeDefinition.
Builder.of(CommonAttributes.XTS_ENVIRONMENT, ENVIRONMENT_URL)
Expand Down Expand Up @@ -97,6 +105,7 @@ public void registerAttributes(ManagementResourceRegistration resourceRegistrati
resourceRegistration.registerReadWriteAttribute(HOST_NAME, null, new ReloadRequiredWriteAttributeHandler(HOST_NAME));
resourceRegistration.registerReadWriteAttribute(ENVIRONMENT_URL, null, new ReloadRequiredWriteAttributeHandler(ENVIRONMENT_URL));
resourceRegistration.registerReadWriteAttribute(DEFAULT_CONTEXT_PROPAGATION, null, new ReloadRequiredWriteAttributeHandler(DEFAULT_CONTEXT_PROPAGATION));
resourceRegistration.registerReadWriteAttribute(ASYNC_REGISTRATION, null, new ReloadRequiredWriteAttributeHandler(ASYNC_REGISTRATION));
//this here just for legacy support!
resourceRegistration.registerReadOnlyAttribute(ENVIRONMENT, new OperationStepHandler() {
@Override
Expand Down
100 changes: 77 additions & 23 deletions xts/src/main/java/org/jboss/as/xts/XTSSubsystemParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
import static org.jboss.as.xts.XTSSubsystemDefinition.DEFAULT_CONTEXT_PROPAGATION;
import static org.jboss.as.xts.XTSSubsystemDefinition.ASYNC_REGISTRATION;
import static org.jboss.as.xts.XTSSubsystemDefinition.ENVIRONMENT_URL;
import static org.jboss.as.xts.XTSSubsystemDefinition.HOST_NAME;

Expand Down Expand Up @@ -87,6 +88,10 @@ public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) th
parseDefaultContextPropagationElement(reader, subsystem);
break;
}
case ASYNC_REGISTRATION: {
parseAsyncRegistrationElement(reader, subsystem);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
Expand Down Expand Up @@ -120,25 +125,28 @@ public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingCon
writer.writeEndElement();
}

if (node.hasDefined(ASYNC_REGISTRATION.getName())) {
writer.writeStartElement(Element.ASYNC_REGISTRATION.getLocalName());
ASYNC_REGISTRATION.marshallAsAttribute(node, writer);
writer.writeEndElement();
}

writer.writeEndElement();
}

private void parseHostElement(XMLExtendedStreamReader reader, ModelNode subsystem) throws XMLStreamException {
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME);
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
ParseUtils.requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
processAttributes(reader, (index, attribute) -> {
required.remove(attribute);
final String value = reader.getAttributeValue(index);
switch (attribute) {
case NAME:
HOST_NAME.parseAndSetParameter(value, subsystem, reader);
break;
default:
throw ParseUtils.unexpectedAttribute(reader, i);
throw ParseUtils.unexpectedAttribute(reader, index);
}
}
});
// Handle elements
ParseUtils.requireNoContent(reader);

Expand All @@ -158,20 +166,16 @@ private void parseHostElement(XMLExtendedStreamReader reader, ModelNode subsyste
*
*/
private void parseXTSEnvironmentElement(XMLExtendedStreamReader reader, ModelNode subsystem) throws XMLStreamException {

final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
ParseUtils.requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
processAttributes(reader, (index, attribute) -> {
final String value = reader.getAttributeValue(index);
switch (attribute) {
case URL:
ENVIRONMENT_URL.parseAndSetParameter(value, subsystem, reader);
break;
default:
throw ParseUtils.unexpectedAttribute(reader, i);
throw ParseUtils.unexpectedAttribute(reader, index);
}
}
});
// Handle elements
ParseUtils.requireNoContent(reader);
}
Expand All @@ -184,22 +188,41 @@ private void parseXTSEnvironmentElement(XMLExtendedStreamReader reader, ModelNod
* @throws XMLStreamException
*/
private void parseDefaultContextPropagationElement(XMLExtendedStreamReader reader, ModelNode subsystem) throws XMLStreamException {
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
ParseUtils.requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
processAttributes(reader, (index, attribute) -> {
final String value = reader.getAttributeValue(index);
switch (attribute) {
case ENABLED:
if (value == null || (!value.toLowerCase().equals("true") && !value.toLowerCase().equals("false"))) {
throw ParseUtils.invalidAttributeValue(reader, i);
throw ParseUtils.invalidAttributeValue(reader, index);
}
DEFAULT_CONTEXT_PROPAGATION.parseAndSetParameter(value, subsystem, reader);
break;
default:
throw ParseUtils.unexpectedAttribute(reader, i);
throw ParseUtils.unexpectedAttribute(reader, index);
}
}
});

// Handle elements
ParseUtils.requireNoContent(reader);
}

/**
* Handle the async-registration element.
*/
private void parseAsyncRegistrationElement(XMLExtendedStreamReader reader, ModelNode subsystem) throws XMLStreamException {
processAttributes(reader, (index, attribute) -> {
final String value = reader.getAttributeValue(index);
switch (attribute) {
case ENABLED:
if (value == null || (!value.toLowerCase().equals("true") && !value.toLowerCase().equals("false"))) {
throw ParseUtils.invalidAttributeValue(reader, index);
}
ASYNC_REGISTRATION.parseAndSetParameter(value, subsystem, reader);
break;
default:
throw ParseUtils.unexpectedAttribute(reader, index);
}
});

// Handle elements
ParseUtils.requireNoContent(reader);
Expand All @@ -215,8 +238,39 @@ private List<Element> getExpectedElements(final XMLExtendedStreamReader reader)
elements.add(Element.XTS_ENVIRONMENT);
elements.add(Element.HOST);
elements.add(Element.DEFAULT_CONTEXT_PROPAGATION);
} else if (Namespace.XTS_3_0.equals(namespace)) {
elements.add(Element.XTS_ENVIRONMENT);
elements.add(Element.HOST);
elements.add(Element.DEFAULT_CONTEXT_PROPAGATION);
elements.add(Element.ASYNC_REGISTRATION);
}

return elements;
}

/**
* Functional interface to provide similar functionality as {@link BiConsumer}
* but with cought exception {@link XMLStreamException} declared.
*/
@FunctionalInterface
private interface AttributeProcessor<T, R> {
void process(T t, R r) throws XMLStreamException;
}

/**
* Iterating over all attributes got from the reader parameter.
*
* @param reader reading the parameters from
* @param attributeProcessorCallback callback being processed for each attribute
* @throws XMLStreamException troubles parsing xml
*/
private void processAttributes(final XMLExtendedStreamReader reader, AttributeProcessor<Integer, Attribute> attributeProcessorCallback) throws XMLStreamException {
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
ParseUtils.requireNoNamespaceAttribute(reader, i);
// final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
attributeProcessorCallback.process(i, attribute);
}
}
}
2 changes: 1 addition & 1 deletion xts/src/main/java/org/jboss/as/xts/XTSSubsystemRemove.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private XTSSubsystemRemove() {

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
for (ContextInfo contextInfo : XTSSubsystemAdd.getContextDefinitions()) {
for (ContextInfo contextInfo : XTSSubsystemAdd.getContextDefinitions(context, model)) {
String contextName = contextInfo.contextPath;
context.removeService(WSServices.ENDPOINT_PUBLISH_SERVICE.append(contextName));
}
Expand Down

0 comments on commit 1bf993b

Please sign in to comment.