use of org.jboss.hal.flow.Outcome in project console by hal.
the class StandaloneDeploymentColumn method replace.
private void replace(Deployment deployment) {
UploadElement uploadElement = new UploadElement(resources.messages().noDeployment());
Dialog dialog = new Dialog.Builder(resources.constants().replaceDeployment()).add(uploadElement.element()).cancel().primary(resources.constants().replace(), () -> {
boolean valid = uploadElement.validate();
if (valid) {
ReplaceDeploymentPanel replaceDeploymentPanel = new ReplaceDeploymentPanel();
replaceDeploymentPanel.on();
series(new FlowContext(progress.get()), new CheckDeployment(dispatcher, deployment.getName()), // To replace an existing deployment, the original name and runtime-name must be preserved.
new UploadOrReplace(environment, dispatcher, deployment.getName(), deployment.getRuntimeName(), uploadElement.getFiles().item(0), false)).subscribe(new Outcome<FlowContext>() {
@Override
public void onError(FlowContext context, Throwable error) {
replaceDeploymentPanel.off();
MessageEvent.fire(eventBus, Message.error(resources.messages().contentReplaceError(deployment.getName()), error.getMessage()));
}
@Override
public void onSuccess(FlowContext context) {
refresh(Ids.content(deployment.getName()));
replaceDeploymentPanel.off();
MessageEvent.fire(eventBus, Message.success(resources.messages().contentReplaceSuccess(deployment.getName())));
}
});
}
return valid;
}).build();
dialog.show();
}
use of org.jboss.hal.flow.Outcome in project console by hal.
the class DataSourceColumn method prepareWizard.
private void prepareWizard(boolean xa) {
Task<FlowContext> readDataSources = context -> crud.readChildren(DATA_SOURCE_SUBSYSTEM_TEMPLATE, xa ? XA_DATA_SOURCE : DATA_SOURCE).doOnSuccess(children -> {
List<DataSource> dataSources = children.stream().map(property -> new DataSource(property, xa)).collect(toList());
context.set(DATASOURCES, dataSources);
}).toCompletable();
List<Task<FlowContext>> tasks = new ArrayList<>();
tasks.add(readDataSources);
tasks.addAll(runningServers(environment, dispatcher, properties(PROFILE_NAME, statementContext.selectedProfile())));
tasks.add(new JdbcDriverTasks.ReadRuntime(environment, dispatcher));
tasks.add(new JdbcDriverTasks.CombineDriverResults());
series(new FlowContext(progress.get()), tasks).subscribe(new Outcome<FlowContext>() {
@Override
public void onError(FlowContext context, Throwable error) {
showWizard(Collections.emptyList(), Collections.emptyList(), xa);
}
@Override
public void onSuccess(FlowContext context) {
List<DataSource> dataSources = context.get(DATASOURCES);
List<JdbcDriver> drivers = context.get(JdbcDriverTasks.DRIVERS);
showWizard(dataSources, drivers, xa);
}
});
}
use of org.jboss.hal.flow.Outcome 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.flow.Outcome in project console by hal.
the class TopologyPreview method update.
// ------------------------------------------------------ dmr functions
@Override
public void update(StaticItem item) {
// remember selection
HTMLElement element = (HTMLElement) document.querySelector(DOT + topology + " ." + selected);
String hostName = element != null ? String.valueOf(element.dataset.get("host")) : null;
String serverGroupName = element != null ? String.valueOf(element.dataset.get("serverGroup")) : null;
String serverName = element != null ? String.valueOf(element.dataset.get("server")) : null;
clearSelected();
setVisible(loadingSection, false);
setVisible(topologySection, false);
hideDetails();
// show the loading indicator if the operations take too long
double timeoutHandle = setTimeout((o) -> setVisible(loadingSection, true), MEDIUM_TIMEOUT);
series(new FlowContext(progress.get()), topology(environment, dispatcher)).subscribe(new Outcome<FlowContext>() {
@Override
public void onError(FlowContext context, Throwable error) {
clearTimeout(timeoutHandle);
setVisible(loadingSection, false);
MessageEvent.fire(eventBus, Message.error(resources.messages().topologyError(), error.getMessage()));
}
@Override
public void onSuccess(FlowContext context) {
clearTimeout(timeoutHandle);
setVisible(loadingSection, false);
Elements.removeChildrenFrom(topologySection);
List<Host> hosts = context.get(TopologyTasks.HOSTS);
List<ServerGroup> serverGroups = context.get(TopologyTasks.SERVER_GROUPS);
List<Server> servers = context.get(TopologyTasks.SERVERS);
topologySection.appendChild(buildTable(hosts, serverGroups, servers));
setVisible(topologySection, true);
adjustTdHeight();
// restore selection
if (hostName != null) {
hosts.stream().filter(host -> hostName.equals(host.getName())).findAny().ifPresent(host -> hostDetails(host));
}
if (serverGroupName != null) {
serverGroups.stream().filter(serverGroup -> serverGroupName.equals(serverGroup.getName())).findAny().ifPresent(serverGroup -> serverGroupDetails(serverGroup));
}
if (serverName != null) {
servers.stream().filter(server -> serverName.equals(server.getName())).findAny().ifPresent(server -> serverDetails(server));
}
}
});
}
use of org.jboss.hal.flow.Outcome in project console by hal.
the class ManagementOperationsPresenter method cancelNonProgressingOperation.
void cancelNonProgressingOperation() {
if (environment.isStandalone()) {
ResourceAddress address = MANAGEMENT_OPERATIONS_TEMPLATE.resolve(statementContext);
Operation operation = new Operation.Builder(address, CANCEL_NON_PROGRESSING_OPERATION).build();
dispatcher.execute(operation, result -> {
MessageEvent.fire(eventBus, Message.info(resources.messages().cancelledOperation(result.asString())));
reload();
}, (operation1, failure) -> {
// operation to cancel, handle this a non error in HAL
if (failure.contains(WFLYDM_0089)) {
MessageEvent.fire(eventBus, Message.success(SafeHtmlUtils.fromString(failure)));
} else {
MessageEvent.fire(eventBus, Message.error(SafeHtmlUtils.fromString(failure)));
}
reload();
}, (operation1, ex) -> {
// operation to cancel, handle this a non error in HAL
if (ex.getMessage().contains(WFLYDM_0089)) {
MessageEvent.fire(eventBus, Message.success(SafeHtmlUtils.fromString(ex.getMessage())));
} else {
MessageEvent.fire(eventBus, Message.error(SafeHtmlUtils.fromString(ex.getMessage())));
}
reload();
});
} else {
Composite composite = new Composite();
// return running hosts, to later call a cancel-non-progressing-operation on each host
ResourceAddress rootAddress = new ResourceAddress();
Operation opHosts = new Operation.Builder(rootAddress, READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, HOST).build();
composite.add(opHosts);
ResourceAddress address = new ResourceAddress().add(HOST, WILDCARD).add(SERVER, WILDCARD);
Operation opRunningServers = new Operation.Builder(address, QUERY).param(SELECT, new ModelNode().add(HOST).add(NAME)).param(WHERE, new ModelNode().set(SERVER_STATE, "running")).build();
composite.add(opRunningServers);
dispatcher.execute(composite, (CompositeResult compositeResult) -> {
// available hosts
List<String> hosts = compositeResult.step(0).get(RESULT).asList().stream().map(ModelNode::asString).collect(toList());
// runing servers
List<String> servers = Collections.emptyList();
ModelNode result = compositeResult.step(1);
if (result != null && result.isDefined()) {
servers = result.get(RESULT).asList().stream().map(r -> hostServerAddress(r.get(RESULT))).collect(toList());
}
// run each :cancel-non-progressing-operation on a specific task
// because the :cancel-non-progressing-operation returns as a failure
// for this case, continue to run the next task
List<Task<FlowContext>> tasks = new ArrayList<>(hosts.size());
for (String host : hosts) {
// call cancel-non-progressing-operation on each host
Task<FlowContext> task = context -> {
ResourceAddress hostAddress = new ResourceAddress().add(HOST, host).add(CORE_SERVICE, MANAGEMENT).add(SERVICE, MANAGEMENT_OPERATIONS);
return buildCancelOperation(hostAddress, context);
};
tasks.add(task);
}
for (String server : servers) {
// call cancel-non-progressing-operation on each server
Task<FlowContext> task = context -> {
ResourceAddress serverAddress = AddressTemplate.of(server).append(MANAGEMENT_OPERATIONS_TEMPLATE).resolve(statementContext);
return buildCancelOperation(serverAddress, context);
};
tasks.add(task);
}
series(new FlowContext(progress.get()), tasks).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) {
if (context.emptyStack()) {
// display the standard message if there is no cancelled operation
MessageEvent.fire(eventBus, Message.success(SafeHtmlUtils.fromString(context.get(WFLYDM_0089))));
} else {
// display the cancelled non progressing operation ids
List<String> canceledOps = new ArrayList<>();
while (!context.emptyStack()) {
canceledOps.add(context.pop());
}
String ids = Joiner.on(", ").join(canceledOps);
MessageEvent.fire(eventBus, Message.success(resources.messages().cancelledOperation(ids)));
}
reload();
}
});
});
}
}
Aggregations