Skip to content

Commit

Permalink
Merge pull request #1086 from bstansberry/WFCORE-988
Browse files Browse the repository at this point in the history
Fix problems revealed when domain testsuite runs with assertions enabled.
  • Loading branch information
bstansberry committed Oct 23, 2015
2 parents 146feb4 + 2cb5341 commit dbcb2a9
Show file tree
Hide file tree
Showing 53 changed files with 549 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ public void operationPrepared(OperationTransaction transaction, ModelNode result
}

context.addStep(responseNode, operation, prepareStep, OperationContext.Stage.MODEL);
ControllerLogger.MGMT_OP_LOGGER.tracef("Executing %s", operation);
context.executeOperation();
responseStreams = context.getResponseStreams();
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,45 @@ public interface TransformingProxyController extends ProxyController {
*/
OperationTransformer.TransformedOperation transformOperation(OperationContext context, ModelNode operation) throws OperationFailedException;

public static class Factory {
/**
* Transform the operation.
*
* @param parameters parameters that drive the transformation
* @param operation the operation to transform.
* @return the transformed operation
* @throws OperationFailedException
*/
OperationTransformer.TransformedOperation transformOperation(Transformers.TransformationInputs parameters, ModelNode operation) throws OperationFailedException;


/**
* Factory methods for creating a {@link TransformingProxyController}
*/
class Factory {

/**
* Creates a {@link TransactionalProtocolClient} based on the given {@code channelAssociation} and then
* uses that to create a {@link TransformingProxyController}.
*
* @param channelAssociation the channel handler. Cannot be {@code null}
* @param transformers transformers to use for transforming resources and operations. Cannot be {@code null}
* @param pathAddress address under which the proxy controller is registered in the resource tree
* @param addressTranslator translator to use for converting local addresses to addresses appropriate for the target process
* @return the proxy controller. Will not be {@code null}
*/
public static TransformingProxyController create(final ManagementChannelHandler channelAssociation, final Transformers transformers, final PathAddress pathAddress, final ProxyOperationAddressTranslator addressTranslator) {
final TransactionalProtocolClient client = TransactionalProtocolHandlers.createClient(channelAssociation);
return create(client, transformers, pathAddress, addressTranslator);
}

/**
* Creates a {@link TransformingProxyController} based on the given {@link TransactionalProtocolClient}.
* @param client the client for communicating with the target process. Cannot be {@code null}
* @param transformers transformers to use for transforming resources and operations. Cannot be {@code null}
* @param pathAddress address under which the proxy controller is registered in the resource tree
* @param addressTranslator translator to use for converting local addresses to addresses appropriate for the target process
* @return the proxy controller. Will not be {@code null}
*/
public static TransformingProxyController create(final TransactionalProtocolClient client, final Transformers transformers, final PathAddress pathAddress, final ProxyOperationAddressTranslator addressTranslator) {
final ModelVersion targetKernelVersion = transformers.getTarget().getVersion();
final RemoteProxyController proxy = RemoteProxyController.create(client, pathAddress, addressTranslator, targetKernelVersion);
Expand All @@ -97,19 +129,19 @@ public Resource transformResource(ResourceTransformationContext context, Resourc
}

@Override
public OperationTransformer.TransformedOperation transformOperation(OperationContext operationContext, ModelNode original) throws OperationFailedException {
public OperationTransformer.TransformedOperation transformOperation(TransformationInputs transformationParameters, ModelNode original) throws OperationFailedException {
final ModelNode operation = proxy.translateOperationForProxy(original);
return transformers.transformOperation(operationContext, operation);
return transformers.transformOperation(transformationParameters, operation);
}

@Override
public Resource transformRootResource(OperationContext operationContext, Resource resource) throws OperationFailedException {
return transformers.transformRootResource(operationContext, resource);
public Resource transformRootResource(TransformationInputs transformationParameters, Resource resource) throws OperationFailedException {
return transformers.transformRootResource(transformationParameters, resource);
}

@Override
public Resource transformRootResource(OperationContext operationContext, Resource resource, ResourceIgnoredTransformationRegistry ignoredTransformationRegistry) throws OperationFailedException {
return transformers.transformRootResource(operationContext, resource, ignoredTransformationRegistry);
public Resource transformRootResource(TransformationInputs transformationParameters, Resource resource, ResourceIgnoredTransformationRegistry ignoredTransformationRegistry) throws OperationFailedException {
return transformers.transformRootResource(transformationParameters, resource, ignoredTransformationRegistry);
}
};
return create(proxy, delegating);
Expand All @@ -119,58 +151,63 @@ private static TransformingProxyController create(final RemoteProxyController de
return new TransformingProxyControllerImpl(transformers, delegate);
}

}

static class TransformingProxyControllerImpl implements TransformingProxyController {
private static class TransformingProxyControllerImpl implements TransformingProxyController {

private final RemoteProxyController proxy;
private final Transformers transformers;
private final RemoteProxyController proxy;
private final Transformers transformers;

public TransformingProxyControllerImpl(Transformers transformers, RemoteProxyController proxy) {
this.transformers = transformers;
this.proxy = proxy;
}
public TransformingProxyControllerImpl(Transformers transformers, RemoteProxyController proxy) {
this.transformers = transformers;
this.proxy = proxy;
}

@Override
public TransactionalProtocolClient getProtocolClient() {
return proxy.getTransactionalProtocolClient();
}
@Override
public TransactionalProtocolClient getProtocolClient() {
return proxy.getTransactionalProtocolClient();
}

@Override
public Transformers getTransformers() {
return transformers;
}
@Override
public Transformers getTransformers() {
return transformers;
}

@Override
public PathAddress getProxyNodeAddress() {
return proxy.getProxyNodeAddress();
}
@Override
public PathAddress getProxyNodeAddress() {
return proxy.getProxyNodeAddress();
}

@Override
public OperationTransformer.TransformedOperation transformOperation(final OperationContext context, final ModelNode operation) throws OperationFailedException {
//Some transformers don't propagate the headers, back them up here and add them again
ModelNode operationHeaders = operation.hasDefined(OPERATION_HEADERS) ? operation.get(OPERATION_HEADERS) : null;
OperationTransformer.TransformedOperation transformed = transformers.transformOperation(context, operation);
@Override
public OperationTransformer.TransformedOperation transformOperation(final OperationContext context, final ModelNode operation) throws OperationFailedException {
return transformOperation(Transformers.TransformationInputs.getOrCreate(context), operation);
}

if (operationHeaders != null) {
ModelNode transformedOp = transformed.getTransformedOperation();
if (transformedOp != null && !transformedOp.hasDefined(OPERATION_HEADERS)) {
transformedOp.get(OPERATION_HEADERS).set(operationHeaders);
@Override
public OperationTransformer.TransformedOperation transformOperation(Transformers.TransformationInputs parameters, ModelNode operation) throws OperationFailedException {
//Some transformers don't propagate the headers, back them up here and add them again
ModelNode operationHeaders = operation.hasDefined(OPERATION_HEADERS) ? operation.get(OPERATION_HEADERS) : null;
OperationTransformer.TransformedOperation transformed = transformers.transformOperation(parameters, operation);

if (operationHeaders != null) {
ModelNode transformedOp = transformed.getTransformedOperation();
if (transformedOp != null && !transformedOp.hasDefined(OPERATION_HEADERS)) {
transformedOp.get(OPERATION_HEADERS).set(operationHeaders);
}
}
return transformed;
}
return transformed;
}

@Override
public void execute(final ModelNode operation, final OperationMessageHandler handler, final ProxyOperationControl control, final OperationAttachments attachments) {
// Execute untransformed
proxy.execute(operation, handler, control, attachments);
}
@Override
public void execute(final ModelNode operation, final OperationMessageHandler handler, final ProxyOperationControl control, final OperationAttachments attachments) {
// Execute untransformed
proxy.execute(operation, handler, control, attachments);
}

@Override
public ModelVersion getKernelModelVersion() {
return proxy.getKernelModelVersion();
@Override
public ModelVersion getKernelModelVersion() {
return proxy.getKernelModelVersion();
}
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,18 @@ public <T extends Operation> AsyncFuture<OperationResponse> execute(Transactiona
final Subject subject = SecurityActions.getSubject();
final ExecuteRequestContext context = new ExecuteRequestContext(new OperationWrapper<T>(listener, operation), subject, tempDir);
final ActiveOperation<OperationResponse, ExecuteRequestContext> op = channelAssociation.initializeOperation(context, context);
final AtomicBoolean cancelSent = new AtomicBoolean();
final AsyncFuture<OperationResponse> result = new AbstractDelegatingAsyncFuture<OperationResponse>(op.getResult()) {
@Override
public void asyncCancel(boolean interruptionDesired) {
try {
// Execute
channelAssociation.executeRequest(op, new CompleteTxRequest(ModelControllerProtocol.PARAM_ROLLBACK, channelAssociation));
} catch (IOException e) {
throw new RuntimeException(e);
public synchronized void asyncCancel(boolean interruptionDesired) {
if (!cancelSent.get()) {
try {
// Execute
channelAssociation.executeRequest(op, new CompleteTxRequest(ModelControllerProtocol.PARAM_ROLLBACK, channelAssociation));
cancelSent.set(true);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
};
Expand Down

0 comments on commit dbcb2a9

Please sign in to comment.