use of org.jboss.hal.dmr.dispatch.DispatchFailure in project console by hal.
the class RrdTask method call.
@Override
public Completable call(LookupContext context) {
boolean recursive = context.recursive;
List<Completable> completables = new ArrayList<>();
// create and partition non-optional operations
List<Operation> operations = rrdOps.create(context, recursive, false);
List<List<Operation>> piles = Lists.partition(operations, batchSize);
List<Composite> composites = piles.stream().map(Composite::new).collect(toList());
for (Composite composite : composites) {
completables.add(dispatcher.execute(composite).doOnSuccess(parseRrdAction(context, composite)).toCompletable());
}
// create optional operations w/o partitioning!
List<Operation> optionalOperations = rrdOps.create(context, recursive, true);
// Do not refactor to
// List<Composite> optionalComposites = optionalOperations.stream().map(Composite::new).collect(toList());
// the GWT compiler will crash with an ArrayIndexOutOfBoundsException!
List<Composite> optionalComposites = new ArrayList<>();
optionalOperations.forEach(operation -> optionalComposites.add(new Composite(operation)));
for (Composite composite : optionalComposites) {
completables.add(dispatcher.execute(composite).onErrorResumeNext(throwable -> {
if (throwable instanceof DispatchFailure) {
logger.debug("Ignore errors on optional resource operation {}", composite.asCli());
return Single.just(new CompositeResult(new ModelNode()));
} else {
return Single.error(throwable);
}
}).doOnSuccess(parseRrdAction(context, composite)).toCompletable());
}
if (!completables.isEmpty()) {
if (logger.isDebugEnabled()) {
logger.debug("About to execute {} ({}+{}) composite operations (regular+optional)", composites.size() + optionalComposites.size(), composites.size(), optionalComposites.size());
String compositeOps = composites.stream().map(Composite::asCli).collect(Collectors.joining(", "));
logger.debug("Composite operations: {}", compositeOps);
if (!optionalComposites.isEmpty()) {
String optionalOps = optionalComposites.stream().map(Composite::asCli).collect(Collectors.joining(", "));
logger.debug("Optional operations: {}", optionalOps);
}
}
return Completable.concat(completables);
} else {
logger.debug("No DMR operations necessary");
return Completable.complete();
}
}
use of org.jboss.hal.dmr.dispatch.DispatchFailure in project console by hal.
the class ReadAuthentication method call.
@Override
public Completable call(FlowContext context) {
logger.debug("Read authentication");
ResourceAddress address = CORE_SERVICE_TEMPLATE.resolve(statementContext);
Operation opAuthorization = new Operation.Builder(address, READ_CHILDREN_RESOURCES_OPERATION).param(CHILD_TYPE, ACCESS).param(INCLUDE_RUNTIME, true).param(RECURSIVE_DEPTH, 1).build();
Operation opWhoami = new Operation.Builder(ResourceAddress.root(), WHOAMI).param(VERBOSE, true).build();
return dispatcher.execute(new Composite(opAuthorization, opWhoami)).doOnSuccess((CompositeResult compositeResult) -> {
ModelNode result = compositeResult.step(0).get(RESULT);
if (result.hasDefined(AUTHORIZATION)) {
result = result.get(AUTHORIZATION);
// provider
AccessControlProvider accessControlProvider = asEnumValue(result, PROVIDER, AccessControlProvider::valueOf, SIMPLE);
environment.setAccessControlProvider(accessControlProvider);
// standard roles
if (result.hasDefined(STANDARD_ROLE_NAMES)) {
result.get(STANDARD_ROLE_NAMES).asList().stream().map(node -> new Role(node.asString())).forEach(role -> environment.getRoles().add(role));
}
// scoped roles
if (!environment.isStandalone()) {
if (result.hasDefined(HOST_SCOPED_ROLE)) {
result.get(HOST_SCOPED_ROLE).asPropertyList().stream().map(property -> scopedRole(property, Role.Type.HOST, HOSTS)).forEach(role -> environment.getRoles().add(role));
}
if (result.hasDefined(SERVER_GROUP_SCOPED_ROLE)) {
result.get(SERVER_GROUP_SCOPED_ROLE).asPropertyList().stream().map(property -> scopedRole(property, Role.Type.SERVER_GROUP, SERVER_GROUPS)).forEach(role -> environment.getRoles().add(role));
}
}
} else {
logger.warn("Unable to read {} (insufficient rights?). Use :whoami values as fallback.", CORE_SERVICE_TEMPLATE.append("access=authorization"));
ModelNode resultWhoami = compositeResult.step(1).get(RESULT);
environment.setAccessControlProvider(RBAC);
environment.getRoles().clear();
if (resultWhoami.hasDefined(ROLES)) {
resultWhoami.get(ROLES).asList().stream().map(node -> new Role(node.asString())).forEach(role -> environment.getRoles().add(role));
} else if (resultWhoami.hasDefined(MAPPED_ROLES)) {
resultWhoami.get(MAPPED_ROLES).asList().stream().map(node -> new Role(node.asString())).forEach(role -> environment.getRoles().add(role));
}
}
}).onErrorResumeNext(throwable -> {
if (throwable instanceof DispatchFailure) {
logger.error("Unable to read {}. Use :whoami values as fallback.", CORE_SERVICE_TEMPLATE);
return Single.just(new CompositeResult(new ModelNode()));
} else {
return Single.error(throwable);
}
}).toCompletable();
}
Aggregations