use of org.jboss.hal.core.runtime.server.Server in project console by hal.
the class ServerGroupActions method remove.
public void remove(ServerGroup serverGroup) {
List<Server> stoppedServers = serverGroup.getServers(Server::isStopped);
DialogFactory.showConfirmation(resources.messages().removeConfirmationTitle(Names.SERVER_GROUP), resources.messages().removeConfirmationQuestion(serverGroup.getName()), () -> {
prepare(serverGroup, stoppedServers, Action.REMOVE);
Composite comp = new Composite();
for (Server server : stoppedServers) {
comp.add(new Operation.Builder(server.getServerConfigAddress(), REMOVE).build());
}
Operation operation = new Operation.Builder(serverGroup.getAddress(), REMOVE).build();
comp.add(operation);
dispatcher.execute(comp, (CompositeResult result) -> finish(serverGroup, stoppedServers, Result.SUCCESS, Message.success(resources.messages().removeResourceSuccess(Names.SERVER_GROUP, serverGroup.getName()))), (operation1, failure) -> finish(serverGroup, stoppedServers, Result.ERROR, Message.error(resources.messages().removeError(serverGroup.getName(), failure))), (operation1, exception) -> finish(serverGroup, stoppedServers, Result.ERROR, Message.error(resources.messages().removeError(serverGroup.getName(), exception.getMessage()))));
});
}
use of org.jboss.hal.core.runtime.server.Server in project console by hal.
the class ServerGroupActions method start.
public void start(ServerGroup serverGroup) {
List<Server> downServers = serverGroup.getServers(server -> server.isStopped() || server.isFailed());
if (!downServers.isEmpty()) {
prepare(serverGroup, downServers, Action.START);
Operation operation = new Operation.Builder(serverGroup.getAddress(), START_SERVERS).param(BLOCKING, false).build();
dispatcher.execute(operation, result -> repeatCompositeUntil(dispatcher, serverGroupTimeout(serverGroup, Action.START), readServerConfigStatus(downServers), checkServerConfigStatus(downServers.size(), STARTED)).subscribe(new ServerGroupTimeoutCallback(serverGroup, downServers, resources.messages().startServerGroupSuccess(serverGroup.getName()))), new ServerGroupFailedCallback(serverGroup, downServers, resources.messages().startServerGroupError(serverGroup.getName())), new ServerGroupExceptionCallback(serverGroup, downServers, resources.messages().startServerGroupError(serverGroup.getName())));
} else {
MessageEvent.fire(eventBus, Message.warning(resources.messages().serverGroupNoStoppedServers(serverGroup.getName())));
}
}
use of org.jboss.hal.core.runtime.server.Server in project console by hal.
the class HostActions method ping.
private Operation ping(Host host) {
ResourceAddress address = new ResourceAddress().add(HOST, // do not use host.getAddressName() here!
host.getName());
Operation operation = new Operation.Builder(address, READ_RESOURCE_OPERATION).build();
if (host.hasServers(Server::isStarted)) {
Operation[] operations = host.getServers(Server::isStarted).stream().map(server -> {
ResourceAddress serverAddress = host.getAddress().add(SERVER, server.getName());
return new Operation.Builder(serverAddress, READ_RESOURCE_OPERATION).build();
}).toArray(Operation[]::new);
operation = new Composite(operation, operations);
} else {
operation = new Operation.Builder(address, READ_RESOURCE_OPERATION).build();
}
return operation;
}
use of org.jboss.hal.core.runtime.server.Server in project console by hal.
the class ReadEnvironment method call.
@Override
public Completable call(FlowContext context) {
logger.debug("Read environment");
Keycloak keycloak = keycloakHolder.getKeycloak();
environment.setSingleSignOn(keycloak != null);
if (keycloak != null) {
logger.debug("Keycloak token: {}", keycloak.token);
}
List<Operation> ops = new ArrayList<>();
ops.add(new Operation.Builder(ResourceAddress.root(), READ_RESOURCE_OPERATION).param(ATTRIBUTES_ONLY, true).param(INCLUDE_RUNTIME, true).build());
ops.add(new Operation.Builder(ResourceAddress.root(), WHOAMI).param(VERBOSE, true).build());
ops.add(new Operation.Builder(ResourceAddress.root(), READ_CHILDREN_RESOURCES_OPERATION).param(CHILD_TYPE, CORE_SERVICE).param(RECURSIVE, false).build());
return dispatcher.execute(new Composite(ops)).doOnSuccess((CompositeResult result) -> {
ModelNode node = result.step(0).get(RESULT);
// operation mode
OperationMode operationMode = asEnumValue(node, LAUNCH_TYPE, (name) -> OperationMode.valueOf(name), OperationMode.UNDEFINED);
environment.setOperationMode(operationMode);
logger.debug("Operation mode: {}", operationMode);
// name and org
if (node.get(NAME).isDefined()) {
String name = node.get(NAME).asString();
environment.setName(name);
}
String orgAttribute = environment.isStandalone() ? ORGANIZATION : DOMAIN_ORGANIZATION;
if (node.get(orgAttribute).isDefined()) {
String org = node.get(orgAttribute).asString();
environment.setOrganization(org);
}
// server info
environment.setInstanceInfo(node.get(PRODUCT_NAME).asString(), node.get(PRODUCT_VERSION).asString(), node.get(RELEASE_CODENAME).asString(), node.get(RELEASE_VERSION).asString());
// management version
Version version = ManagementModel.parseVersion(node);
environment.setManagementVersion(version);
logger.debug("Management model version: {}", version);
if (environment.isStandalone()) {
Server.STANDALONE.addServerAttributes(node);
}
// user info
if (environment.isSingleSignOn()) {
user.setName(keycloak.userProfile.username);
// are not supported on the javascript side when run in the browser.
if (keycloak.realmAccess != null && keycloak.realmAccess.roles != null) {
for (int i = 0; i < keycloak.realmAccess.roles.length; i++) {
String role = keycloak.realmAccess.roles[i];
user.addRole(new Role(role));
}
}
} else {
ModelNode whoami = result.step(1).get(RESULT);
String username = whoami.get("identity").get("username").asString();
user.setName(username);
if (whoami.hasDefined("mapped-roles")) {
List<ModelNode> roles = whoami.get("mapped-roles").asList();
for (ModelNode role : roles) {
String roleName = role.asString();
user.addRole(new Role(roleName));
}
}
}
user.setAuthenticated(true);
logger.debug("User info: {} {}", user.getName(), user.getRoles());
ModelNode step = result.step(2).get(RESULT);
environment.setPatchingEnabled(!environment.isStandalone() || step.get(PATCHING).isDefined());
}).toCompletable();
}
use of org.jboss.hal.core.runtime.server.Server 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));
}
}
});
}
Aggregations