use of org.jboss.hal.dmr.ModelDescriptionConstants.RESULT in project console by hal.
the class StandaloneServerPresenter 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, there are differente attributes for
// standalone and domain mode.
Task<FlowContext> loadHttpInterface = flowContext -> {
Operation readHttpInterface = new Operation.Builder(httpAddress, READ_RESOURCE_OPERATION).build();
return dispatcher.execute(readHttpInterface).doOnSuccess(value -> {
if (value.hasDefined(SOCKET_BINDING)) {
// standalone mode uses a socket-binding for port
// store the socket-binding name in the flow context and on a later call
// read the socket-binding-group=<s-b-g>/socket-binding=<http-binding> to
// retrieve the port number
flowContext.set(SOCKET_BINDING, value.get(SOCKET_BINDING).asString());
}
}).toCompletable();
};
tasks.add(loadHttpInterface);
// if standalone mode, read the socket-binding-group=<s-b-g>/socket-binding=<http-binding>
// to retrieve the port number
Task<FlowContext> readHttpPortTask = flowContext -> {
Operation op = new Operation.Builder(ResourceAddress.root(), READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, SOCKET_BINDING_GROUP).build();
return dispatcher.execute(op).doOnSuccess(result -> {
String sbg = result.asList().get(0).asString();
String httpBinding = flowContext.get(SOCKET_BINDING);
ResourceAddress address = SOCKET_BINDING_GROUP_TEMPLATE.resolve(statementContext, sbg, httpBinding);
Operation readPort = new Operation.Builder(address, READ_ATTRIBUTE_OPERATION).param(NAME, PORT).param(RESOLVE_EXPRESSIONS, true).build();
dispatcher.execute(readPort, portResult -> flowContext.set(PORT, portResult.asString()));
}).toCompletable();
};
tasks.add(readHttpPortTask);
// as part of the disable ssl task, undefine the secure-socket-binding
// the attribute only exists in standalone mode
Task<FlowContext> undefSslTask = flowContext -> {
Operation op = new Operation.Builder(httpAddress, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, SECURE_SOCKET_BINDING).build();
return dispatcher.execute(op).toCompletable();
};
tasks.add(undefSslTask);
// 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;
reloadServer(null, location);
} else {
reload();
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.dmr.ModelDescriptionConstants.RESULT 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