use of org.jboss.hal.resources.Ids 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();
}
});
});
}
}
use of org.jboss.hal.resources.Ids in project console by hal.
the class DeploymentPresenter method reload.
@Override
protected void reload() {
ResourceAddress address = deploymentAddress();
// task 1: read sessions ids, servlets and websockets
Operation readResourceOp = new Operation.Builder(address, READ_RESOURCE_OPERATION).param(INCLUDE_RUNTIME, true).param(RECURSIVE, true).build();
Operation listSessionsOp = new Operation.Builder(address, LIST_SESSIONS).build();
Task<FlowContext> task1 = context -> dispatcher.execute(new Composite(readResourceOp, listSessionsOp)).doOnSuccess((CompositeResult result) -> {
ModelNode readResourceResult = result.step(0).get(RESULT);
List<NamedNode> servlets = asNamedNodes(failSafePropertyList(readResourceResult, SERVLET));
List<NamedNode> websockets = asNamedNodes(failSafePropertyList(readResourceResult, WEBSOCKET));
// sorted session ids (important for step 2!)
ModelNode listSessionsResult = result.step(1).get(RESULT);
List<String> sessionIds = listSessionsResult.isDefined() ? listSessionsResult.asList().stream().map(ModelNode::asString).sorted().collect(toList()) : Collections.emptyList();
context.set(SERVLETS, servlets);
context.set(WEBSOCKETS, websockets);
context.set(SESSION_IDS, sessionIds);
}).toCompletable();
// task 2: read session creation and last access times
Task<FlowContext> task2 = context -> {
List<String> sessionIds = context.get(SESSION_IDS);
if (sessionIds.isEmpty()) {
context.set(SESSIONS, Collections.emptyList());
return Completable.complete();
} else {
List<Operation> operations = new ArrayList<>();
for (String id : sessionIds) {
operations.add(new Operation.Builder(address, GET_SESSION_CREATION_TIME).param(SESSION_ID, id).build());
operations.add(new Operation.Builder(address, GET_SESSION_LAST_ACCESSED_TIME).param(SESSION_ID, id).build());
}
return dispatcher.execute(new Composite(operations)).doOnSuccess((CompositeResult result) -> {
int i = 0;
List<Session> sessions = new ArrayList<>();
for (String sessionId : sessionIds) {
ModelNode modelNode = new ModelNode();
if (result.step(i).isDefined() && result.step(i).get(RESULT).isDefined()) {
modelNode.get(CREATION_TIME).set(result.step(i).get(RESULT));
}
i++;
if (result.step(i).isDefined() && result.step(i).get(RESULT).isDefined()) {
modelNode.get(LAST_ACCESSED_TIME).set(result.step(i).get(RESULT));
}
i++;
sessions.add(new Session(sessionId, modelNode));
}
context.set(SESSIONS, sessions);
}).toCompletable();
}
};
series(new FlowContext(progress.get()), task1, task2).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext context) {
List<Session> sessions = context.get(SESSIONS);
List<NamedNode> servlets = context.get(SERVLETS);
List<NamedNode> websockets = context.get(WEBSOCKETS);
getView().updateSessions(sessions);
getView().updateServlets(servlets);
getView().updateWebsockets(websockets);
}
});
}
Aggregations