use of org.jboss.hal.dmr.CompositeResult 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);
}
});
}
use of org.jboss.hal.dmr.CompositeResult in project console by hal.
the class DeploymentPreview method update.
@Override
public void update(DeploymentResource item) {
Operation opDeployment = new Operation.Builder(item.getAddress(), READ_RESOURCE_OPERATION).param(INCLUDE_RUNTIME, true).build();
ResourceAddress webRuntimeAddress = WEB_SUBSYSTEM_TEMPLATE.resolve(statementContext);
Operation opSubsystem = new Operation.Builder(webRuntimeAddress, READ_RESOURCE_OPERATION).param(INCLUDE_RUNTIME, true).build();
dispatcher.execute(new Composite(opDeployment, opSubsystem), (CompositeResult compositeResult) -> {
ModelNode deploymentResult = compositeResult.step(0).get(RESULT);
ModelNode subsystemResult = compositeResult.step(1).get(RESULT);
DeploymentResource deploymentStats = new DeploymentResource(item.getAddress(), deploymentResult);
previewAttributes.refresh(deploymentStats);
boolean statsEnabled = subsystemResult.get(STATISTICS_ENABLED).asBoolean(false);
if (statsEnabled) {
Map<String, Long> updatedSession = new HashMap<>();
updatedSession.put(ACTIVE_SESSIONS, deploymentStats.get(ACTIVE_SESSIONS).asLong());
updatedSession.put(EXPIRED_SESSIONS, deploymentStats.get(EXPIRED_SESSIONS).asLong());
updatedSession.put(REJECTED_SESSIONS, deploymentStats.get(REJECTED_SESSIONS).asLong());
sessions.update(updatedSession);
// only shows this chart if the max_active_session is set, otherwise the max has no limits
if (deploymentStats.get(MAX_ACTIVE_SESSIONS).asInt() > -1) {
maxSessions.update(deploymentStats.get(ACTIVE_SESSIONS).asLong(), deploymentStats.get(MAX_ACTIVE_SESSIONS).asLong());
setVisible(maxSessions.element(), true);
} else {
setVisible(maxSessions.element(), false);
}
Map<String, Long> updatedTime = new HashMap<>();
updatedTime.put(SESSION_MAX_ALIVE_TIME, deploymentStats.get(SESSION_MAX_ALIVE_TIME).asLong());
updatedTime.put(SESSION_AVG_ALIVE_TIME, deploymentStats.get(SESSION_AVG_ALIVE_TIME).asLong());
sessionTime.update(updatedTime);
}
setVisible(noStatistics.element(), !statsEnabled);
setVisible(sessionsElement, statsEnabled);
setVisible(maxTimeElement, statsEnabled);
injectUrls();
});
}
use of org.jboss.hal.dmr.CompositeResult in project console by hal.
the class CrudOperations method reset.
/**
* Undefines all non required attributes in the specified set. After the resource has been undefined the specified success
* message is fired and the specified callback is executed.
* <p>
* If the set contains only required attributes, a warning message is fired and the specified callback is executed.
*
* @param type the human readable resource type used in the success message
* @param name the resource name
* @param address the fq address for the operation
* @param attributes the attributes which should be reset
* @param metadata the metadata of the attributes
* @param successMessage the success message fired after resetting the resource
* @param callback the callback executed after the resource has been undefined
*/
@JsIgnore
public void reset(String type, String name, ResourceAddress address, Set<String> attributes, Metadata metadata, SafeHtml successMessage, Callback callback) {
Composite composite = operationFactory.resetResource(address, attributes, metadata);
if (composite.isEmpty()) {
MessageEvent.fire(eventBus, Message.warning(resources.messages().noReset()));
callback.execute();
} else {
SafeHtml question = name == null ? resources.messages().resetSingletonConfirmationQuestion() : resources.messages().resetConfirmationQuestion(name);
DialogFactory.showConfirmation(resources.messages().resetConfirmationTitle(type), question, () -> dispatcher.execute(composite, (CompositeResult result) -> {
MessageEvent.fire(eventBus, Message.success(successMessage));
callback.execute();
}));
}
}
Aggregations