use of org.jboss.hal.meta.StatementContext in project console by hal.
the class RealmsPresenter method addIdentity.
void addIdentity(AddressTemplate template, Metadata metadata, String name) {
Metadata opMetadata = metadata.forOperation(ADD_IDENTITY);
SafeHtml identityAttributeHelp = resources.messages().identityAttributeHelp();
IdentityAttributeItem identityAttribute = new IdentityAttributeItem(Ids.asId(IDENTITY_ATTRIBUTE_MAPPING), IDENTITY_ATTRIBUTE_MAPPING);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(template.lastName(), ADD_IDENTITY), opMetadata).unboundFormItem(identityAttribute, 1, identityAttributeHelp).build();
form.attach();
AddResourceDialog dialog = new AddResourceDialog(resources.constants().addIdentity(), form, (name1, model) -> {
LabelBuilder labelBuilder = new LabelBuilder();
String resourceName = labelBuilder.label(template.lastName()) + SPACE + name;
String identity = model.get(IDENTITY).asString();
ResourceAddress address = template.resolve(statementContext, name);
List<Task<FlowContext>> tasks = new ArrayList<>();
Task<FlowContext> addTask = flowContext -> {
Operation addOp = new Operation.Builder(address, ADD_IDENTITY).param(IDENTITY, identity).build();
return dispatcher.execute(addOp).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().addError(resources.constants().identity(), identity, resourceName, ex.getMessage())))).toCompletable();
};
tasks.add(addTask);
if (identityAttribute.getValue() != null) {
identityAttribute.getValue().forEach((key, values) -> {
Task<FlowContext> addAttribute = flowContext -> {
ModelNode modelValues = new ModelNode();
values.forEach(modelValues::add);
Operation addIdentAttributeOp = new Operation.Builder(address, ADD_IDENTITY_ATTRIBUTE).param(IDENTITY, identity).param(NAME, key).param(VALUE, modelValues).build();
return dispatcher.execute(addIdentAttributeOp).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().addError(resources.constants().identity(), identity, resourceName, ex.getMessage())))).toCompletable();
};
tasks.add(addAttribute);
});
}
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext flowContext) {
MessageEvent.fire(getEventBus(), Message.success(resources.messages().addSuccess(resources.constants().identity(), identity, resourceName)));
}
@Override
public void onError(FlowContext context, Throwable throwable) {
MessageEvent.fire(getEventBus(), Message.error(resources.messages().addError(resources.constants().identity(), identity, resourceName, throwable.getMessage())));
}
});
});
dialog.show();
}
use of org.jboss.hal.meta.StatementContext 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();
}
use of org.jboss.hal.meta.StatementContext in project console by hal.
the class FindNonProgressingTask method call.
@Override
public void call(SingleEmitter<ModelNode> em) {
if (environment.isStandalone()) {
ResourceAddress address = MGMT_OPERATIONS_TEMPLATE.resolve(statementContext);
Operation operation = new Operation.Builder(address, FIND_NON_PROGRESSING_OPERATION).build();
dispatcher.execute(operation, result -> {
boolean hasNonProgressinOp = result != null && result.isDefined();
eventBus.fireEvent(new NonProgressingOperationEvent(hasNonProgressinOp));
em.onSuccess(result);
});
} else {
// return running hosts, to later call a find-non-progressing-operation on each host
Task<FlowContext> hostsTask = context -> {
ResourceAddress address = new ResourceAddress();
Operation operation = new Operation.Builder(address, READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, HOST).build();
return dispatcher.execute(operation).doOnSuccess(result -> {
List<String> hosts = result.asList().stream().map(ModelNode::asString).collect(toList());
context.set(HOSTS, hosts);
}).toCompletable();
};
// return running servers, to later call a find-non-progressing-operation on each runtime server
Task<FlowContext> serversTask = context -> {
// /host=*/server=*:query(select=[host,name],where={server-state=running})
ResourceAddress address = new ResourceAddress().add(HOST, WILDCARD).add(SERVER, WILDCARD);
Operation operation = new Operation.Builder(address, QUERY).param(SELECT, new ModelNode().add(HOST).add(NAME)).param(WHERE, new ModelNode().set(SERVER_STATE, "running")).build();
return dispatcher.execute(operation).doOnSuccess(result -> {
List<String> servers = Collections.emptyList();
if (result != null && result.isDefined()) {
servers = result.asList().stream().map(r -> hostServerAddress(r.get(RESULT))).collect(Collectors.toList());
}
context.set("servers", servers);
}).toCompletable();
};
// call find-non-progressing-operation on each host and server
Task<FlowContext> findNonProgressingTask = context -> {
List<String> hosts = context.get(HOSTS);
List<String> servers = context.get("servers");
Composite composite = new Composite();
for (String host : hosts) {
ResourceAddress address = new ResourceAddress().add(HOST, host).add(CORE_SERVICE, MANAGEMENT).add(SERVICE, MANAGEMENT_OPERATIONS);
Operation operation = new Operation.Builder(address, FIND_NON_PROGRESSING_OPERATION).build();
composite.add(operation);
}
if (!servers.isEmpty()) {
for (String server : servers) {
ResourceAddress address = AddressTemplate.of(server).append(MGMT_OPERATIONS_TEMPLATE).resolve(statementContext);
Operation operation = new Operation.Builder(address, FIND_NON_PROGRESSING_OPERATION).build();
composite.add(operation);
}
}
return dispatcher.execute(composite).doOnSuccess(result -> {
boolean nonProgressingOp = false;
for (ModelNode r : result) {
ModelNode findResult = r.get(RESULT);
if (findResult != null && findResult.isDefined()) {
nonProgressingOp = true;
break;
}
}
context.set("nonProgressingOp", nonProgressingOp);
}).toCompletable();
};
series(new FlowContext(progress.get()), hostsTask, serversTask, findNonProgressingTask).subscribe(new Outcome<FlowContext>() {
@Override
public void onError(FlowContext context, Throwable error) {
em.onError(error);
}
@Override
public void onSuccess(FlowContext context) {
boolean nonProgressingOp = context.get("nonProgressingOp");
eventBus.fireEvent(new NonProgressingOperationEvent(nonProgressingOp));
}
});
}
}
use of org.jboss.hal.meta.StatementContext in project console by hal.
the class ConfigurationChangesPresenter method reload.
@Override
protected void reload() {
AddressTemplate template;
if (environment.isStandalone()) {
template = CORE_MANAGEMENT_TEMPLATE;
} else {
if (hostOnly) {
template = CORE_MANAGEMENT_TEMPLATE;
} else {
template = AddressTemplate.of("/{selected.host}/{selected.server}/subsystem=core-management");
}
}
ResourceAddress coreAddress = template.resolve(statementContext);
Operation operation = new Operation.Builder(coreAddress, READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, SERVICE).build();
dispatcher.execute(operation, coreResult -> {
if (coreResult.asList().size() > 0) {
Optional<ModelNode> configurationChangesResult = coreResult.asList().stream().filter(service -> service.asString().equals(CONFIGURATION_CHANGES)).findFirst();
if (configurationChangesResult.isPresent()) {
ResourceAddress ccAddress = template.append("service=configuration-changes").resolve(statementContext);
Operation ccOperation = new Operation.Builder(ccAddress, LIST_CHANGES_OPERATION).build();
dispatcher.execute(ccOperation, ccResult -> getView().update(ccResult));
} else {
getView().update(new ModelNode());
}
} else {
getView().update(new ModelNode());
}
});
}
use of org.jboss.hal.meta.StatementContext in project console by hal.
the class HostColumn method prune.
private void prune(String operation) {
ResourceAddress address = new ResourceAddress().add(CORE_SERVICE, MANAGEMENT);
crud.readChildren(address, HOST_CONNECTION, children -> {
List<Operation> operations = children.stream().map(property -> {
ResourceAddress hcAddress = HOST_CONNECTION_TEMPLATE.resolve(statementContext, property.getName());
return new Operation.Builder(hcAddress, operation).build();
}).collect(toList());
dispatcher.execute(new Composite(operations), (CompositeResult result) -> {
MessageEvent.fire(eventBus, Message.success(resources.messages().pruneSuccessful()));
refresh(RESTORE_SELECTION);
});
});
}
Aggregations