Search in sources :

Example 1 with Server

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()))));
    });
}
Also used : Server(org.jboss.hal.core.runtime.server.Server) Composite(org.jboss.hal.dmr.Composite) CompositeResult(org.jboss.hal.dmr.CompositeResult) OperationFormBuilder(org.jboss.hal.core.mbui.form.OperationFormBuilder) Operation(org.jboss.hal.dmr.Operation)

Example 2 with Server

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())));
    }
}
Also used : Server(org.jboss.hal.core.runtime.server.Server) OperationFormBuilder(org.jboss.hal.core.mbui.form.OperationFormBuilder) Operation(org.jboss.hal.dmr.Operation)

Example 3 with Server

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;
}
Also used : ModelNode(org.jboss.hal.dmr.ModelNode) Dialog(org.jboss.hal.ballroom.dialog.Dialog) Provider(javax.inject.Provider) TimeoutHandler.repeatUntilTimeout(org.jboss.hal.dmr.dispatch.TimeoutHandler.repeatUntilTimeout) MessageEvent(org.jboss.hal.spi.MessageEvent) SHORT_TIMEOUT(org.jboss.hal.resources.UIConstants.SHORT_TIMEOUT) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Result(org.jboss.hal.core.runtime.Result) Inject(javax.inject.Inject) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) Map(java.util.Map) MetadataCallback(org.jboss.hal.meta.processing.MetadataProcessor.MetadataCallback) Message(org.jboss.hal.spi.Message) Server(org.jboss.hal.core.runtime.server.Server) Timeouts(org.jboss.hal.core.runtime.Timeouts) Metadata(org.jboss.hal.meta.Metadata) BlockingDialog(org.jboss.hal.ballroom.dialog.BlockingDialog) ServerActions(org.jboss.hal.core.runtime.server.ServerActions) Timeouts.hostTimeout(org.jboss.hal.core.runtime.Timeouts.hostTimeout) Logger(org.slf4j.Logger) Operation(org.jboss.hal.dmr.Operation) Collections.emptyList(java.util.Collections.emptyList) Ids(org.jboss.hal.resources.Ids) EventBus(com.google.web.bindery.event.shared.EventBus) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) CompletableSubscriber(rx.CompletableSubscriber) Composite(org.jboss.hal.dmr.Composite) LONG_TIMEOUT(org.jboss.hal.resources.UIConstants.LONG_TIMEOUT) List(java.util.List) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) MEDIUM(org.jboss.hal.ballroom.dialog.Dialog.Size.MEDIUM) MetadataProcessor(org.jboss.hal.meta.processing.MetadataProcessor) Callback(org.jboss.hal.spi.Callback) Action(org.jboss.hal.core.runtime.Action) Resources(org.jboss.hal.resources.Resources) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Core(org.jboss.hal.core.Core) Footer(org.jboss.hal.spi.Footer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Subscription(rx.Subscription) OperationFormBuilder(org.jboss.hal.core.mbui.form.OperationFormBuilder) Form(org.jboss.hal.ballroom.form.Form) DomGlobal.setTimeout(elemental2.dom.DomGlobal.setTimeout) Server(org.jboss.hal.core.runtime.server.Server) Composite(org.jboss.hal.dmr.Composite) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) OperationFormBuilder(org.jboss.hal.core.mbui.form.OperationFormBuilder) Operation(org.jboss.hal.dmr.Operation)

Example 4 with Server

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();
}
Also used : OperationMode(org.jboss.hal.config.OperationMode) ModelNode(org.jboss.hal.dmr.ModelNode) Completable(rx.Completable) Version(org.jboss.hal.config.Version) Logger(org.slf4j.Logger) CompositeResult(org.jboss.hal.dmr.CompositeResult) Environment(org.jboss.hal.config.Environment) Operation(org.jboss.hal.dmr.Operation) LoggerFactory(org.slf4j.LoggerFactory) KeycloakHolder(org.jboss.hal.config.keycloak.KeycloakHolder) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) ManagementModel(org.jboss.hal.meta.ManagementModel) FlowContext(org.jboss.hal.flow.FlowContext) ModelNodeHelper.asEnumValue(org.jboss.hal.dmr.ModelNodeHelper.asEnumValue) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Composite(org.jboss.hal.dmr.Composite) List(java.util.List) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Role(org.jboss.hal.config.Role) Keycloak(org.jboss.hal.config.keycloak.Keycloak) User(org.jboss.hal.config.User) Server(org.jboss.hal.core.runtime.server.Server) Composite(org.jboss.hal.dmr.Composite) CompositeResult(org.jboss.hal.dmr.CompositeResult) ArrayList(java.util.ArrayList) Operation(org.jboss.hal.dmr.Operation) Role(org.jboss.hal.config.Role) Version(org.jboss.hal.config.Version) ArrayList(java.util.ArrayList) List(java.util.List) Keycloak(org.jboss.hal.config.keycloak.Keycloak) ModelNode(org.jboss.hal.dmr.ModelNode) OperationMode(org.jboss.hal.config.OperationMode)

Example 5 with Server

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));
            }
        }
    });
}
Also used : PreviewContent(org.jboss.hal.core.finder.PreviewContent) HostActions(org.jboss.hal.core.runtime.host.HostActions) ServerGroupActionEvent(org.jboss.hal.core.runtime.group.ServerGroupActionEvent) Constraint(org.jboss.hal.meta.security.Constraint) HostResultEvent(org.jboss.hal.core.runtime.host.HostResultEvent) TopologyTasks(org.jboss.hal.core.runtime.TopologyTasks) AuthorisationDecision(org.jboss.hal.meta.security.AuthorisationDecision) PreviewAttribute(org.jboss.hal.core.finder.PreviewAttributes.PreviewAttribute) Server(org.jboss.hal.core.runtime.server.Server) CSS.hostContainer(org.jboss.hal.resources.CSS.hostContainer) Places(org.jboss.hal.core.mvp.Places) Names(org.jboss.hal.resources.Names) HostActionEvent(org.jboss.hal.core.runtime.host.HostActionEvent) ServerActions(org.jboss.hal.core.runtime.server.ServerActions) ServerGroupResultEvent(org.jboss.hal.core.runtime.group.ServerGroupResultEvent) CSS.inactive(org.jboss.hal.resources.CSS.inactive) HTMLTableElement(elemental2.dom.HTMLTableElement) Set(java.util.Set) CSS(org.jboss.hal.resources.CSS) ServerGroup(org.jboss.hal.core.runtime.group.ServerGroup) ServerActionHandler(org.jboss.hal.core.runtime.server.ServerActionEvent.ServerActionHandler) Flow.series(org.jboss.hal.flow.Flow.series) CSS.fontAwesome(org.jboss.hal.resources.CSS.fontAwesome) CSS.spinnerLg(org.jboss.hal.resources.CSS.spinnerLg) CSS.withProgress(org.jboss.hal.resources.CSS.withProgress) Constraints(org.jboss.hal.meta.security.Constraints) Supplier(java.util.function.Supplier) FlowContext(org.jboss.hal.flow.FlowContext) Outcome(org.jboss.hal.flow.Outcome) ArrayList(java.util.ArrayList) ServerGroupResultHandler(org.jboss.hal.core.runtime.group.ServerGroupResultEvent.ServerGroupResultHandler) Strings(com.google.common.base.Strings) EventCallbackFn(org.jboss.gwt.elemento.core.EventCallbackFn) Progress(org.jboss.hal.flow.Progress) CSS.marginRight5(org.jboss.hal.resources.CSS.marginRight5) CSS.name(org.jboss.hal.resources.CSS.name) EventBus(com.google.web.bindery.event.shared.EventBus) MouseEvent(elemental2.dom.MouseEvent) ServerStatusSwitch(org.jboss.hal.client.runtime.server.ServerStatusSwitch) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) NameTokens(org.jboss.hal.meta.token.NameTokens) HTMLDivElement(elemental2.dom.HTMLDivElement) NamedNode(org.jboss.hal.dmr.NamedNode) Elements(org.jboss.gwt.elemento.core.Elements) CSS.rowHeader(org.jboss.hal.resources.CSS.rowHeader) Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) HTMLTableCellElement(elemental2.dom.HTMLTableCellElement) HtmlContentBuilder(org.jboss.gwt.elemento.core.builder.HtmlContentBuilder) HostPreviewAttributes(org.jboss.hal.core.runtime.host.HostPreviewAttributes) CSS.divider(org.jboss.hal.resources.CSS.divider) HostActionHandler(org.jboss.hal.core.runtime.host.HostActionEvent.HostActionHandler) CSS.serverGroupContainer(org.jboss.hal.resources.CSS.serverGroupContainer) HTMLElement(elemental2.dom.HTMLElement) Message(org.jboss.hal.spi.Message) NodeList(elemental2.dom.NodeList) PreviewAttributes(org.jboss.hal.core.finder.PreviewAttributes) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) Lists.asList(com.google.common.collect.Lists.asList) HTMLTableSectionElement(elemental2.dom.HTMLTableSectionElement) CSS.marginLeft5(org.jboss.hal.resources.CSS.marginLeft5) Predicate(java.util.function.Predicate) CSS.dropdownMenu(org.jboss.hal.resources.CSS.dropdownMenu) CSS.px(org.jboss.hal.resources.CSS.px) EventType.click(org.jboss.gwt.elemento.core.EventType.click) FinderPath(org.jboss.hal.core.finder.FinderPath) ServerGroupActions(org.jboss.hal.core.runtime.group.ServerGroupActions) ServerPreviewAttributes(org.jboss.hal.core.runtime.server.ServerPreviewAttributes) CSS.error(org.jboss.hal.resources.CSS.error) List(java.util.List) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) UIConstants(org.jboss.hal.resources.UIConstants) CSS.dropdownToggle(org.jboss.hal.resources.CSS.dropdownToggle) ServerResultEvent(org.jboss.hal.core.runtime.server.ServerResultEvent) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) SecurityContextRegistry(org.jboss.hal.meta.security.SecurityContextRegistry) HostResultHandler(org.jboss.hal.core.runtime.host.HostResultEvent.HostResultHandler) CSS.centerBlock(org.jboss.hal.resources.CSS.centerBlock) DomGlobal.setTimeout(elemental2.dom.DomGlobal.setTimeout) ModelNode(org.jboss.hal.dmr.ModelNode) Element(elemental2.dom.Element) CSS.selected(org.jboss.hal.resources.CSS.selected) MessageEvent(org.jboss.hal.spi.MessageEvent) ServerActionEvent(org.jboss.hal.core.runtime.server.ServerActionEvent) ServerResultHandler(org.jboss.hal.core.runtime.server.ServerResultEvent.ServerResultHandler) CSS.server(org.jboss.hal.resources.CSS.server) CSS.clickable(org.jboss.hal.resources.CSS.clickable) Function(java.util.function.Function) HashSet(java.util.HashSet) CSS.topology(org.jboss.hal.resources.CSS.topology) ServerGroupActionHandler(org.jboss.hal.core.runtime.group.ServerGroupActionEvent.ServerGroupActionHandler) AddressTemplate(org.jboss.hal.meta.AddressTemplate) Comparator.comparing(java.util.Comparator.comparing) CSS.spinner(org.jboss.hal.resources.CSS.spinner) CSS.ok(org.jboss.hal.resources.CSS.ok) CSS.warning(org.jboss.hal.resources.CSS.warning) DomGlobal.document(elemental2.dom.DomGlobal.document) CSS.suspended(org.jboss.hal.resources.CSS.suspended) Ids(org.jboss.hal.resources.Ids) HTMLTableColElement(elemental2.dom.HTMLTableColElement) FinderPathFactory(org.jboss.hal.core.finder.FinderPathFactory) CSS.disconnected(org.jboss.hal.resources.CSS.disconnected) PlaceRequest(com.gwtplatform.mvp.shared.proxy.PlaceRequest) Consumer(java.util.function.Consumer) DomGlobal.clearTimeout(elemental2.dom.DomGlobal.clearTimeout) Collectors.toList(java.util.stream.Collectors.toList) CSS.pullRight(org.jboss.hal.resources.CSS.pullRight) Resources(org.jboss.hal.resources.Resources) Format(org.jboss.hal.ballroom.Format) TopologyTasks.topology(org.jboss.hal.core.runtime.TopologyTasks.topology) CSS.height(org.jboss.hal.resources.CSS.height) CSS.empty(org.jboss.hal.resources.CSS.empty) Host(org.jboss.hal.core.runtime.host.Host) MEDIUM_TIMEOUT(org.jboss.hal.resources.UIConstants.MEDIUM_TIMEOUT) StaticItem(org.jboss.hal.core.finder.StaticItem) HTMLElement(elemental2.dom.HTMLElement) ArrayList(java.util.ArrayList) NodeList(elemental2.dom.NodeList) Lists.asList(com.google.common.collect.Lists.asList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) FlowContext(org.jboss.hal.flow.FlowContext)

Aggregations

Server (org.jboss.hal.core.runtime.server.Server)16 Operation (org.jboss.hal.dmr.Operation)12 List (java.util.List)7 ModelDescriptionConstants (org.jboss.hal.dmr.ModelDescriptionConstants)7 ResourceAddress (org.jboss.hal.dmr.ResourceAddress)7 Dispatcher (org.jboss.hal.dmr.dispatch.Dispatcher)7 ArrayList (java.util.ArrayList)6 Provider (javax.inject.Provider)6 ModelNode (org.jboss.hal.dmr.ModelNode)6 FlowContext (org.jboss.hal.flow.FlowContext)6 Progress (org.jboss.hal.flow.Progress)6 Ids (org.jboss.hal.resources.Ids)6 Resources (org.jboss.hal.resources.Resources)6 EventBus (com.google.web.bindery.event.shared.EventBus)5 HTMLElement (elemental2.dom.HTMLElement)5 Environment (org.jboss.hal.config.Environment)5 ServerActions (org.jboss.hal.core.runtime.server.ServerActions)5 Flow.series (org.jboss.hal.flow.Flow.series)5 AddressTemplate (org.jboss.hal.meta.AddressTemplate)5 PlaceRequest (com.gwtplatform.mvp.shared.proxy.PlaceRequest)4