Skip to content

Commit

Permalink
Merge pull request #1762 from bstansberry/WFCORE-1737
Browse files Browse the repository at this point in the history
[WFCORE-1737] Properly handle non-existent registrations in wildcard read-resource-description ops
  • Loading branch information
bstansberry committed Aug 31, 2016
2 parents 6b2b0af + 1290d33 commit fcb8439
Show file tree
Hide file tree
Showing 4 changed files with 676 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ProcessType;
import org.jboss.as.controller.UnauthorizedException;
import org.jboss.as.controller._private.OperationFailedRuntimeException;
import org.jboss.as.controller.access.Action;
import org.jboss.as.controller.access.AuthorizationResult;
import org.jboss.as.controller.access.ResourceNotAddressableException;
Expand Down Expand Up @@ -482,9 +483,13 @@ public void handleResult(OperationContext.ResultAction resultAction, OperationCo
}
}

protected abstract void executeSingleTargetChild(PathAddress base, PathElement currentElement, PathAddress newRemaining, OperationContext context, boolean ignoreMissing);
protected abstract void executeSingleTargetChild(PathAddress base, PathElement currentElement,
PathAddress newRemaining, OperationContext context, boolean ignoreMissing);

protected abstract void executeMultiTargetChildren(PathAddress base, PathElement currentElement, PathAddress newRemaining, OperationContext context, ImmutableManagementResourceRegistration registration, boolean ignoreMissing);
protected abstract void executeMultiTargetChildren(PathAddress base, PathElement currentElement,
PathAddress newRemaining, OperationContext context,
ImmutableManagementResourceRegistration registration,
boolean ignoreMissing);

/**
* If not authorized, this will throw an exception for {@link ModelAddressResolver} for use with the
Expand Down Expand Up @@ -878,9 +883,11 @@ protected void executeMultiTargetChildren(PathAddress base, PathElement currentE

final Set<PathElement> children = context.getResourceRegistration().getChildAddresses(base);
if (children == null || children.isEmpty()) {
return;
throw new NoSuchResourceTypeException(base.append(currentElement));
}

boolean foundValid = false;
PathAddress invalid = null;
for (final PathElement path : children) {
if (childType != null && !childType.equals(path.getKey())) {
continue;
Expand All @@ -892,15 +899,44 @@ protected void executeMultiTargetChildren(PathAddress base, PathElement currentE
}
final PathAddress next = base.append(path);
final ImmutableManagementResourceRegistration nr = context.getResourceRegistration().getSubModel(next);
execute(next, newRemaining, context, nr, ignoreMissing);
try {
execute(next, newRemaining, context, nr, ignoreMissing);
foundValid = true;
} catch (NoSuchResourceTypeException e) {
if (!foundValid) {
PathAddress failedAddr = e.getPathAddress();
// Store the failed address for error reporting, but only if
// 1) this is the first failure, or
// 2) The size of the failed address is larger than the currently
// cached one, indicating there is some path that has a larger number
// of valid elements than the currently cached path. So we want to
// report that larger path
if (invalid == null || failedAddr.size() > invalid.size()) {
PathAddress newBase = base.append(currentElement);
invalid = newBase.append(failedAddr.subAddress(newBase.size()));
}
}
}
}

if (!foundValid) {
if (invalid == null) {
// No children matched currentElement
invalid = base.append(currentElement);
}
throw new NoSuchResourceTypeException(invalid);
}
}

@Override
protected void executeSingleTargetChild(PathAddress base, PathElement currentElement, PathAddress newRemaining, OperationContext context, boolean ignoreMissing) {
final PathAddress next = base.append(currentElement);
final ImmutableManagementResourceRegistration nr = context.getResourceRegistration().getSubModel(next);
execute(next, newRemaining, context, nr, ignoreMissing);
if (nr != null) {
execute(next, newRemaining, context, nr, ignoreMissing);
} else {
throw new NoSuchResourceTypeException(next);
}
}

@Override
Expand Down Expand Up @@ -1093,4 +1129,16 @@ private static void reportInvalidLocaleFormat(OperationContext context, String f
}


private static final class NoSuchResourceTypeException extends OperationFailedRuntimeException {
private final PathAddress pathAddress;

private NoSuchResourceTypeException(PathAddress pathAddress) {
super(ControllerLogger.ROOT_LOGGER.noSuchResourceType(pathAddress));
this.pathAddress = pathAddress;
}

private PathAddress getPathAddress() {
return pathAddress;
}
}
}

0 comments on commit fcb8439

Please sign in to comment.