use of org.jboss.hal.core.runtime.server.ServerActions in project console by hal.
the class ServerPreview method update.
@Override
public void update(Server server) {
ServerStatusSwitch sss = new ServerStatusSwitch(serverActions) {
@Override
protected void onPending(Server server) {
pending(resources.messages().serverPending(server.getName()));
disableAllLinks();
}
@Override
protected void onBootErrors(Server server) {
error(resources.messages().serverBootErrors(server.getName()));
disableAllLinksBut(bootErrorsLink);
}
@Override
protected void onFailed(Server server) {
error(resources.messages().serverFailed(server.getName()));
if (server.isStandalone()) {
disableAllLinks();
} else {
disableAllLinksBut(startLink);
}
}
@Override
protected void onAdminMode(Server server) {
adminOnly(resources.messages().serverAdminMode(server.getName()));
disableAllLinks();
}
@Override
protected void onStarting(Server server) {
adminOnly(resources.messages().serverAdminMode(server.getName()));
disableAllLinks();
}
@Override
protected void onSuspended(Server server) {
suspended(resources.messages().serverSuspended(server.getName()));
disableAllLinksBut(resumeLink);
}
@Override
protected void onNeedsReload(Server server) {
needsReload(resources.messages().serverNeedsReload(server.getName()));
disableAllLinksBut(reloadLink);
}
@Override
protected void onNeedsRestart(Server server) {
needsRestart(resources.messages().serverNeedsRestart(server.getName()));
disableAllLinksBut(restartLink);
}
@Override
protected void onRunning(Server server) {
running(resources.messages().serverRunning(server.getName()));
if (server.isStandalone()) {
disableAllLinks();
} else {
disableAllLinksBut(stopLink);
}
}
@Override
protected void onStopped(Server server) {
alertContainer.className = alert + " " + alertInfo;
alertIcon.className = Icons.STOPPED;
alertText.innerHTML = resources.messages().serverStopped(server.getName()).asString();
if (server.isStandalone()) {
disableAllLinks();
} else {
disableAllLinksBut(startLink);
}
}
@Override
protected void onUnknown(Server server) {
unknown(resources.messages().serverUndefined(server.getName()));
disableAllLinks();
}
};
sss.accept(server);
ServerPreviewAttributes.refresh(server, attributes);
boolean displayOpenPorts = server.isRunning() || server.needsRestart() || server.needsReload();
if (displayOpenPorts) {
List<Task<FlowContext>> tasks = new ArrayList<>();
tasks.add(flowContext -> {
ResourceAddress address = SELECTED_SERVER.resolve(statementContext);
Operation operation = new Operation.Builder(address, READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, SOCKET_BINDING_GROUP).build();
return dispatcher.execute(operation).doOnSuccess(result -> flowContext.push(result.get(0).asString())).toCompletable();
});
tasks.add(flowContext -> {
String socketBnding = flowContext.pop();
ResourceAddress address = SELECTED_SERVER.resolve(statementContext).add(SOCKET_BINDING_GROUP, socketBnding).add(SOCKET_BINDING, "*");
ModelNode select = new ModelNode();
select.add("bound-port").add(NAME);
ModelNode where = new ModelNode();
where.set("bound", true);
Operation operation = new Operation.Builder(address, QUERY).param(SELECT, select).param(WHERE, where).build();
return dispatcher.execute(operation).doOnSuccess(result -> {
ModelNode openPortsModel = new ModelNode();
result.asList().forEach(m -> {
ModelNode sbModel = m.get(RESULT);
openPortsModel.add(sbModel.get(NAME).asString(), sbModel.get("bound-port").asInt());
flowContext.push(openPortsModel);
});
}).toCompletable();
});
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {
@Override
public void onSuccess(FlowContext flowContext) {
ModelNode openPorts = flowContext.pop();
buildOpenPortsElement(openPorts);
}
});
serverActions.readUrl(server, serverUrl);
}
Elements.setVisible(headerOpenPorts, displayOpenPorts);
Elements.setVisible(ulOpenPorts, displayOpenPorts);
}
use of org.jboss.hal.core.runtime.server.ServerActions in project console by hal.
the class ApplyPatchWizard method show.
public void show() {
Messages messages = resources.messages();
Wizard.Builder<PatchContext, PatchState> wb = new Wizard.Builder<>(messages.addResourceTitle(Names.PATCH), new PatchContext());
checkServersState(servers -> {
if (servers != null) {
wb.addStep(CHECK_SERVERS, new CheckRunningServersStep(resources, servers, statementContext.selectedHost()));
}
wb.addStep(UPLOAD, new UploadPatchStep(resources)).addStep(CONFIGURE, new ConfigurationStep(metadata, resources)).onBack((context, currentState) -> {
PatchState previous = null;
switch(currentState) {
case CHECK_SERVERS:
break;
case UPLOAD:
previous = CHECK_SERVERS;
break;
case CONFIGURE:
previous = UPLOAD;
break;
default:
break;
}
return previous;
}).onNext((context, currentState) -> {
PatchState next = null;
switch(currentState) {
case CHECK_SERVERS:
next = UPLOAD;
break;
case UPLOAD:
next = CONFIGURE;
break;
case CONFIGURE:
break;
default:
break;
}
return next;
}).stayOpenAfterFinish().onFinish((wzd, context) -> {
String name = context.file.name;
wzd.showProgress(resources.constants().patchInProgress(), messages.patchInProgress(name));
series(new FlowContext(progress.get()), new UploadPatch(statementContext, dispatcher, serverActions, context)).subscribe(new Outcome<FlowContext>() {
@Override
public void onError(FlowContext flowContext, Throwable error) {
wzd.showError(resources.constants().patchError(), messages.patchAddError(name, error.getMessage()), error.getMessage());
}
@Override
public void onSuccess(FlowContext context) {
callback.execute();
wzd.showSuccess(resources.constants().patchSuccessful(), messages.patchSucessfullyApplied(name), messages.view(Names.PATCH), cxt -> {
/* nothing to do, content is already selected */
});
}
});
});
Wizard<PatchContext, PatchState> wizard = wb.build();
wizard.show();
});
}
use of org.jboss.hal.core.runtime.server.ServerActions in project console by hal.
the class RollbackWizard method show.
public void show() {
Messages messages = resources.messages();
Wizard.Builder<PatchContext, PatchState> wb = new Wizard.Builder<>(resources.constants().rollback(), new PatchContext());
checkServersState(servers -> {
if (servers != null) {
wb.addStep(CHECK_SERVERS, new CheckRunningServersStep(resources, servers, statementContext.selectedHost()));
}
wb.addStep(ROLLBACK, new org.jboss.hal.client.patching.wizard.RollbackStep(metadata, resources, statementContext.selectedHost(), patchId)).onBack((context, currentState) -> {
PatchState previous = null;
switch(currentState) {
case CHECK_SERVERS:
break;
case ROLLBACK:
previous = CHECK_SERVERS;
break;
default:
break;
}
return previous;
}).onNext((context, currentState) -> {
PatchState next = null;
switch(currentState) {
case CHECK_SERVERS:
next = ROLLBACK;
break;
case ROLLBACK:
break;
default:
break;
}
return next;
}).stayOpenAfterFinish().onFinish((wzd, context) -> {
String name = context.patchId;
wzd.showProgress(resources.constants().rollbackInProgress(), messages.rollbackInProgress(name));
series(new FlowContext(progress.get()), new RollbackTask(statementContext, dispatcher, serverActions, context)).subscribe(new Outcome<FlowContext>() {
@Override
public void onError(FlowContext context, Throwable error) {
wzd.showError(resources.constants().rollbackError(), messages.rollbackError(error.getMessage()), error.getMessage());
}
@Override
public void onSuccess(FlowContext context) {
callback.execute();
wzd.showSuccess(resources.constants().rollbackSuccessful(), messages.rollbackSucessful(name));
}
});
});
Wizard<PatchContext, PatchState> wizard = wb.build();
wizard.show();
});
}
Aggregations