use of org.jboss.hal.flow.Task in project console by hal.
the class PropertiesStep method readJdbcDriverProperties.
private void readJdbcDriverProperties(boolean isXa, String dsClassname, String driverName, Consumer<List<String>> callback) {
List<Task<FlowContext>> tasks = jdbcDriverProperties(environment, dispatcher, statementContext, driverName, resources);
series(new FlowContext(progress.get()), tasks).subscribe(new JdbcDriverOutcome(dsClassname, isXa, callback));
}
use of org.jboss.hal.flow.Task in project console by hal.
the class ManagementOperationsPresenter method reload.
@Override
protected void reload() {
if (environment.isStandalone()) {
ResourceAddress addressFindNP = MANAGEMENT_OPERATIONS_TEMPLATE.resolve(statementContext);
Operation operationFindNP = new Operation.Builder(addressFindNP, FIND_NON_PROGRESSING_OPERATION).build();
ResourceAddress addressMO = MANAGEMENT_OPERATIONS_TEMPLATE.resolve(statementContext);
Operation operationMO = new Operation.Builder(addressMO, READ_CHILDREN_RESOURCES_OPERATION).param(CHILD_TYPE, ACTIVE_OPERATION).build();
dispatcher.execute(new Composite(operationFindNP, operationMO), (CompositeResult result) -> {
ModelNode resultNP = result.step(0).get(RESULT);
ModelNode resultOperations = result.step(1).get(RESULT);
final String nonProgressingId = resultNP.isDefined() ? resultNP.asString() : null;
List<ManagementOperations> activeOps = asNamedNodes(resultOperations.asPropertyList()).stream().map(ManagementOperations::new).peek(activeOp -> {
if (nonProgressingId != null && nonProgressingId.equals(activeOp.getName())) {
activeOp.setAsNonProgressing();
}
}).collect(toList());
getView().update(activeOps);
});
} else {
// return available 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(toList());
}
context.set("servers", servers);
}).toCompletable();
};
// call find-non-progressing-operation and read-resource of active operations
// 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);
ResourceAddress ad = new ResourceAddress(address.clone()).add(ACTIVE_OPERATION, WILDCARD);
Operation operationMO = new Operation.Builder(ad, READ_RESOURCE_OPERATION).build();
composite.add(operationMO);
}
if (!servers.isEmpty()) {
for (String server : servers) {
ResourceAddress address = AddressTemplate.of(server).append(MANAGEMENT_OPERATIONS_TEMPLATE).resolve(statementContext);
Operation findOp = new Operation.Builder(address, FIND_NON_PROGRESSING_OPERATION).build();
composite.add(findOp);
ResourceAddress ad = new ResourceAddress(address.clone()).add(ACTIVE_OPERATION, WILDCARD);
Operation operation = new Operation.Builder(ad, READ_RESOURCE_OPERATION).build();
composite.add(operation);
}
}
return dispatcher.execute(composite).doOnSuccess(response -> {
List<String> nonProgressingOps = new ArrayList<>();
List<ManagementOperations> ops = new ArrayList<>();
for (ModelNode r : response) {
ModelNode result = r.get(RESULT);
if (result != null && result.isDefined()) {
ModelType type = result.getType();
// if model is LIST it is the list of active operations
if (ModelType.LIST.equals(type)) {
for (ModelNode op : result.asList()) {
ModelNode opResult = op.get(RESULT);
// the result has two addresses
// 1) the active-operation address itself, example
// /host=master/server=server-three/core-service=management/service=management-operations/active-operation=1940701884
// 2) the resource address
// /host=master/server=server-three/subsystem=elytron/filesystem-realm=file1
// the active-operation address should be store to later use it to cancel, if needed
// the resource address is displayed to the user
ModelNode activeOpAddress = op.get(ADDRESS);
opResult.get(HAL_ACTIVE_OP_ADDRESS).set(activeOpAddress);
String opId = null;
List<Property> activeOperationAddressList = activeOpAddress.asPropertyList();
for (Property p : activeOperationAddressList) {
if (p.getName().equals(ACTIVE_OPERATION)) {
opId = p.getValue().asString();
}
// store the host and server to later show in the view
if (p.getName().equals(HOST)) {
opResult.get(HAL_ACTIVE_ADDRESS_HOST).set(p.getValue().asString());
}
if (p.getName().equals(SERVER)) {
opResult.get(HAL_ACTIVE_ADDRESS_SERVER).set(p.getValue().asString());
}
}
NamedNode node = new NamedNode(opId, opResult);
ManagementOperations activeOp = new ManagementOperations(node);
ops.add(activeOp);
}
} else {
nonProgressingOps.add(result.asString());
}
}
}
// if there are non progressing operations, mark them in the list
if (!nonProgressingOps.isEmpty()) {
Collections.sort(nonProgressingOps);
for (ManagementOperations mop : ops) {
if (nonProgressingOps.indexOf(mop.getName()) > -1) {
mop.setAsNonProgressing();
}
}
}
context.set("active-operations", ops);
}).toCompletable();
};
series(new FlowContext(progress.get()), hostsTask, serversTask, findNonProgressingTask).subscribe(new Outcome<FlowContext>() {
@Override
public void onError(FlowContext context, Throwable error) {
MessageEvent.fire(getEventBus(), Message.error(SafeHtmlUtils.fromString("Error loading management operations: " + error.getMessage())));
}
@Override
public void onSuccess(FlowContext context) {
List<ManagementOperations> ops = context.get("active-operations");
getView().update(ops);
}
});
}
}
use of org.jboss.hal.flow.Task in project console by hal.
the class HostPresenter method disableSslForManagementInterface.
@Override
@SuppressWarnings("DuplicatedCode")
public void disableSslForManagementInterface() {
Constants constants = resources.constants();
String serverName = environment.isStandalone() ? Names.STANDALONE_SERVER : Names.DOMAIN_CONTROLLER;
String label = constants.reload() + " " + serverName;
SwitchItem reload = new SwitchItem(RELOAD, label);
reload.setExpressionAllowed(false);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(RELOAD, FORM), Metadata.empty()).unboundFormItem(reload).build();
form.attach();
HTMLElement formElement = form.element();
ModelNode model = new ModelNode();
model.setEmptyObject();
form.edit(model);
ResourceAddress httpAddress = HTTP_INTERFACE_TEMPLATE.resolve(statementContext);
DialogFactory.buildConfirmation(constants.disableSSL(), resources.messages().disableSSLManagementQuestion(serverName), formElement, Dialog.Size.MEDIUM, () -> {
List<Task<FlowContext>> tasks = new ArrayList<>();
// load the http-interface resource to get the port
Task<FlowContext> loadHttpInterface = flowContext -> {
Operation readHttpInterface = new Operation.Builder(httpAddress, READ_RESOURCE_OPERATION).build();
return dispatcher.execute(readHttpInterface).doOnSuccess(value -> {
if (value.hasDefined(PORT)) {
// only domain mode contains "port" attribute
String port = value.get(PORT).asString();
if (port.contains("$")) {
// if it contains an expression value, resolve it at host level
ResourceAddress address = AddressTemplate.of("/host=" + environment.getDomainController()).resolve(statementContext);
Operation readPort = new Operation.Builder(address, RESOLVE_EXPRESSION).param(EXPRESSION, port).build();
dispatcher.execute(readPort, portResult -> flowContext.set(PORT, portResult.asString()));
} else {
flowContext.set(PORT, port);
}
}
}).toCompletable();
};
tasks.add(loadHttpInterface);
// in domain-mode read the /host=<dc> domain controller
// it is important for later use if user wants to reload dc if in admin-mode
Task<FlowContext> loadDc = flowContext -> {
ResourceAddress dcAddress = AddressTemplate.of("/host=" + environment.getDomainController()).resolve(statementContext);
Operation readDcOp = new Operation.Builder(dcAddress, READ_RESOURCE_OPERATION).param(ATTRIBUTES_ONLY, true).build();
return dispatcher.execute(readDcOp).doOnSuccess(value -> flowContext.set(HOST, new Host(value))).toCompletable();
};
tasks.add(loadDc);
// as part of the disable ssl task, undefine the secure-port, it only exists in domain mode
Task<FlowContext> undefineSecurePortTask = flowContext -> {
Operation op = new Operation.Builder(httpAddress, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, SECURE_PORT).build();
return dispatcher.execute(op).toCompletable();
};
tasks.add(undefineSecurePortTask);
// as part of the disable ssl task, undefine the ssl-context
Task<FlowContext> undefineSslContextTask = flowContext -> {
Operation op = new Operation.Builder(httpAddress, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, SSL_CONTEXT).build();
return dispatcher.execute(op).toCompletable();
};
tasks.add(undefineSslContextTask);
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext flowContext) {
if (reload.getValue() != null && reload.getValue()) {
String port = flowContext.get(PORT).toString();
// extracts the url search path, so the reload shows the same view the use is on
String urlSuffix = window.location.getHref();
urlSuffix = urlSuffix.substring(urlSuffix.indexOf("//") + 2);
urlSuffix = urlSuffix.substring(urlSuffix.indexOf("/"));
// the location to redirect the browser to the unsecure URL
// TODO Replace hardcoded scheme
String location = "http://" + window.location.getHostname() + ":" + port + urlSuffix;
Host host = flowContext.get(HOST);
reloadServer(host, location);
} else {
reloadView();
MessageEvent.fire(getEventBus(), Message.success(resources.messages().disableSSLManagementSuccess()));
}
}
@Override
public void onError(FlowContext context, Throwable throwable) {
MessageEvent.fire(getEventBus(), Message.error(resources.messages().disableSSLManagementError(throwable.getMessage())));
}
});
}).show();
}
use of org.jboss.hal.flow.Task in project console by hal.
the class CacheColumn method addCache.
private void addCache(CacheType cacheType) {
Metadata metadata = metadataRegistry.lookup(cacheType.template);
AddResourceDialog dialog = new AddResourceDialog(Ids.build(cacheType.baseId, Ids.ADD), resources.messages().addResourceTitle(cacheType.type), metadata, (name, model) -> {
String cacheContainer = findCacheContainer(getFinder().getContext().getPath());
ResourceAddress address = cacheType.template.resolve(statementContext, cacheContainer, name);
if (cacheType.equals(CacheType.LOCAL)) {
crud.add(cacheType.type, name, address, model, (n, a) -> refresh(Ids.build(cacheType.baseId, name)));
} else {
ResourceAddress jgroupsAddress = AddressTemplates.TRANSPORT_JGROUPS_TEMPLATE.resolve(statementContext, cacheContainer);
ResourceCheck check = new ResourceCheck(dispatcher, jgroupsAddress);
Task<FlowContext> add = context -> {
Operation addJgroups = new Operation.Builder(jgroupsAddress, ADD).build();
int status = context.pop();
if (status == 200) {
context.set(JGROUPS_ADDITION_STATUS, false);
return Completable.complete();
} else {
context.set(JGROUPS_ADDITION_STATUS, true);
return dispatcher.execute(addJgroups).toCompletable();
}
};
series(new FlowContext(progress.get()), check, add).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {
@Override
public void onSuccess(FlowContext context) {
if (context.get(JGROUPS_ADDITION_STATUS).equals(true)) {
MessageEvent.fire(eventBus, Message.success(resources.messages().addResourceSuccess(Names.TRANSPORT, Names.JGROUPS)));
}
crud.add(cacheType.type, name, address, model, (n, a) -> refresh(Ids.build(cacheType.baseId, name)));
}
});
}
});
dialog.getForm().<String>getFormItem(NAME).addValidationHandler(createUniqueValidation());
dialog.show();
}
use of org.jboss.hal.flow.Task in project console by hal.
the class RealmsPresenter method saveIdentity.
void saveIdentity(Metadata metadata, String resource, String identity, Map<String, List<String>> originalAttributes, Map<String, List<String>> attributes, Consumer<Boolean> viewCallback) {
LabelBuilder labelBuilder = new LabelBuilder();
String resourceName = labelBuilder.label(metadata.getTemplate().lastName()) + SPACE + resource;
ResourceAddress address = metadata.getTemplate().resolve(statementContext, resource);
// remove the old attributes and add the attribute list
List<Task<FlowContext>> tasks = new ArrayList<>();
// compare the original values to the new values, to see which one to remove or add
originalAttributes.forEach((key, originalValues) -> {
List<String> newValues = attributes.get(key);
if (!originalValues.equals(newValues)) {
// remove the key tag if it is not present, the user deleted it
Task<FlowContext> addTask = flowContext -> {
Operation operation = new Operation.Builder(address, REMOVE_IDENTITY_ATTRIBUTE).param(IDENTITY, identity).param(NAME, key).build();
return dispatcher.execute(operation).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().saveIdentityError(identity, resourceName, ex.getMessage())))).toCompletable();
};
tasks.add(addTask);
}
});
attributes.forEach((name, newValues) -> {
List<String> originalValues = originalAttributes.get(name);
if (!newValues.equals(originalValues)) {
Task<FlowContext> addTask = flowContext -> {
ModelNode modelValues = new ModelNode();
newValues.forEach(modelValues::add);
Operation operation = new Operation.Builder(address, ADD_IDENTITY_ATTRIBUTE).param(IDENTITY, identity).param(NAME, name).param(VALUE, modelValues).build();
return dispatcher.execute(operation).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().saveIdentityError(identity, resourceName, ex.getMessage())))).toCompletable();
};
tasks.add(addTask);
}
});
if (tasks.isEmpty()) {
MessageEvent.fire(getEventBus(), Message.warning(resources.messages().noChanges()));
} else {
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext flowContext) {
viewCallback.accept(true);
MessageEvent.fire(getEventBus(), Message.success(resources.messages().saveIdentitySuccess(identity, resourceName)));
}
@Override
public void onError(FlowContext context, Throwable throwable) {
MessageEvent.fire(getEventBus(), Message.error(resources.messages().saveIdentityError(identity, resourceName, throwable.getMessage())));
}
});
}
}
Aggregations