Search in sources :

Example 1 with Outcome

use of org.jboss.hal.flow.Outcome in project console by hal.

the class StandaloneDeploymentColumn method replace.

private void replace(Deployment deployment) {
    UploadElement uploadElement = new UploadElement(resources.messages().noDeployment());
    Dialog dialog = new Dialog.Builder(resources.constants().replaceDeployment()).add(uploadElement.element()).cancel().primary(resources.constants().replace(), () -> {
        boolean valid = uploadElement.validate();
        if (valid) {
            ReplaceDeploymentPanel replaceDeploymentPanel = new ReplaceDeploymentPanel();
            replaceDeploymentPanel.on();
            series(new FlowContext(progress.get()), new CheckDeployment(dispatcher, deployment.getName()), // To replace an existing deployment, the original name and runtime-name must be preserved.
            new UploadOrReplace(environment, dispatcher, deployment.getName(), deployment.getRuntimeName(), uploadElement.getFiles().item(0), false)).subscribe(new Outcome<FlowContext>() {

                @Override
                public void onError(FlowContext context, Throwable error) {
                    replaceDeploymentPanel.off();
                    MessageEvent.fire(eventBus, Message.error(resources.messages().contentReplaceError(deployment.getName()), error.getMessage()));
                }

                @Override
                public void onSuccess(FlowContext context) {
                    refresh(Ids.content(deployment.getName()));
                    replaceDeploymentPanel.off();
                    MessageEvent.fire(eventBus, Message.success(resources.messages().contentReplaceSuccess(deployment.getName())));
                }
            });
        }
        return valid;
    }).build();
    dialog.show();
}
Also used : UploadOrReplace(org.jboss.hal.client.deployment.DeploymentTasks.UploadOrReplace) CheckDeployment(org.jboss.hal.client.deployment.DeploymentTasks.CheckDeployment) Dialog(org.jboss.hal.ballroom.dialog.Dialog) CreateEmptyDialog(org.jboss.hal.client.deployment.dialog.CreateEmptyDialog) AddUnmanagedDialog(org.jboss.hal.client.deployment.dialog.AddUnmanagedDialog) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) Outcome(org.jboss.hal.flow.Outcome) UploadElement(org.jboss.hal.client.shared.uploadwizard.UploadElement) FlowContext(org.jboss.hal.flow.FlowContext)

Example 2 with Outcome

use of org.jboss.hal.flow.Outcome in project console by hal.

the class DataSourceColumn method prepareWizard.

private void prepareWizard(boolean xa) {
    Task<FlowContext> readDataSources = context -> crud.readChildren(DATA_SOURCE_SUBSYSTEM_TEMPLATE, xa ? XA_DATA_SOURCE : DATA_SOURCE).doOnSuccess(children -> {
        List<DataSource> dataSources = children.stream().map(property -> new DataSource(property, xa)).collect(toList());
        context.set(DATASOURCES, dataSources);
    }).toCompletable();
    List<Task<FlowContext>> tasks = new ArrayList<>();
    tasks.add(readDataSources);
    tasks.addAll(runningServers(environment, dispatcher, properties(PROFILE_NAME, statementContext.selectedProfile())));
    tasks.add(new JdbcDriverTasks.ReadRuntime(environment, dispatcher));
    tasks.add(new JdbcDriverTasks.CombineDriverResults());
    series(new FlowContext(progress.get()), tasks).subscribe(new Outcome<FlowContext>() {

        @Override
        public void onError(FlowContext context, Throwable error) {
            showWizard(Collections.emptyList(), Collections.emptyList(), xa);
        }

        @Override
        public void onSuccess(FlowContext context) {
            List<DataSource> dataSources = context.get(DATASOURCES);
            List<JdbcDriver> drivers = context.get(JdbcDriverTasks.DRIVERS);
            showWizard(dataSources, drivers, xa);
        }
    });
}
Also used : Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) Constraint(org.jboss.hal.meta.security.Constraint) ItemActionFactory(org.jboss.hal.core.finder.ItemActionFactory) StatementContext(org.jboss.hal.meta.StatementContext) ItemDisplay(org.jboss.hal.core.finder.ItemDisplay) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Icons(org.jboss.hal.resources.Icons) JdbcDriver(org.jboss.hal.core.datasource.JdbcDriver) HTMLElement(elemental2.dom.HTMLElement) TopologyTasks.runningServers(org.jboss.hal.core.runtime.TopologyTasks.runningServers) Message(org.jboss.hal.spi.Message) Places(org.jboss.hal.core.mvp.Places) Names(org.jboss.hal.resources.Names) CrudOperations(org.jboss.hal.core.CrudOperations) List(java.util.List) MetadataRegistry(org.jboss.hal.meta.MetadataRegistry) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) DataSourceWizard(org.jboss.hal.client.configuration.subsystem.datasource.wizard.DataSourceWizard) AddressTemplates(org.jboss.hal.client.configuration.subsystem.datasource.AddressTemplates) Flow.series(org.jboss.hal.flow.Flow.series) Finder(org.jboss.hal.core.finder.Finder) Footer(org.jboss.hal.spi.Footer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) AsyncColumn(org.jboss.hal.spi.AsyncColumn) MessageEvent(org.jboss.hal.spi.MessageEvent) ColumnAction(org.jboss.hal.core.finder.ColumnAction) ItemAction(org.jboss.hal.core.finder.ItemAction) FlowContext(org.jboss.hal.flow.FlowContext) Outcome(org.jboss.hal.flow.Outcome) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Task(org.jboss.hal.flow.Task) Progress(org.jboss.hal.flow.Progress) RESTORE_SELECTION(org.jboss.hal.core.finder.FinderColumn.RefreshMode.RESTORE_SELECTION) FinderColumn(org.jboss.hal.core.finder.FinderColumn) Comparator.comparing(java.util.Comparator.comparing) ModelNodeHelper.properties(org.jboss.hal.dmr.ModelNodeHelper.properties) ColumnActionFactory(org.jboss.hal.core.finder.ColumnActionFactory) Requires(org.jboss.hal.spi.Requires) CompositeResult(org.jboss.hal.dmr.CompositeResult) Operation(org.jboss.hal.dmr.Operation) Ids(org.jboss.hal.resources.Ids) EventBus(com.google.web.bindery.event.shared.EventBus) CSS.pfIcon(org.jboss.hal.resources.CSS.pfIcon) PlaceRequest(com.gwtplatform.mvp.shared.proxy.PlaceRequest) Composite(org.jboss.hal.dmr.Composite) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Collectors.toList(java.util.stream.Collectors.toList) NameTokens(org.jboss.hal.meta.token.NameTokens) Resources(org.jboss.hal.resources.Resources) DataSource(org.jboss.hal.core.datasource.DataSource) NamedNode(org.jboss.hal.dmr.NamedNode) Collections(java.util.Collections) Task(org.jboss.hal.flow.Task) ArrayList(java.util.ArrayList) FlowContext(org.jboss.hal.flow.FlowContext) DataSource(org.jboss.hal.core.datasource.DataSource) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList)

Example 3 with Outcome

use of org.jboss.hal.flow.Outcome in project console by hal.

the class FindNonProgressingTask method call.

@Override
public void call(SingleEmitter<ModelNode> em) {
    if (environment.isStandalone()) {
        ResourceAddress address = MGMT_OPERATIONS_TEMPLATE.resolve(statementContext);
        Operation operation = new Operation.Builder(address, FIND_NON_PROGRESSING_OPERATION).build();
        dispatcher.execute(operation, result -> {
            boolean hasNonProgressinOp = result != null && result.isDefined();
            eventBus.fireEvent(new NonProgressingOperationEvent(hasNonProgressinOp));
            em.onSuccess(result);
        });
    } else {
        // return running hosts, to later call a find-non-progressing-operation on each host
        Task<FlowContext> hostsTask = context -> {
            ResourceAddress address = new ResourceAddress();
            Operation operation = new Operation.Builder(address, READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, HOST).build();
            return dispatcher.execute(operation).doOnSuccess(result -> {
                List<String> hosts = result.asList().stream().map(ModelNode::asString).collect(toList());
                context.set(HOSTS, hosts);
            }).toCompletable();
        };
        // return running servers, to later call a find-non-progressing-operation on each runtime server
        Task<FlowContext> serversTask = context -> {
            // /host=*/server=*:query(select=[host,name],where={server-state=running})
            ResourceAddress address = new ResourceAddress().add(HOST, WILDCARD).add(SERVER, WILDCARD);
            Operation operation = new Operation.Builder(address, QUERY).param(SELECT, new ModelNode().add(HOST).add(NAME)).param(WHERE, new ModelNode().set(SERVER_STATE, "running")).build();
            return dispatcher.execute(operation).doOnSuccess(result -> {
                List<String> servers = Collections.emptyList();
                if (result != null && result.isDefined()) {
                    servers = result.asList().stream().map(r -> hostServerAddress(r.get(RESULT))).collect(Collectors.toList());
                }
                context.set("servers", servers);
            }).toCompletable();
        };
        // call find-non-progressing-operation on each host and server
        Task<FlowContext> findNonProgressingTask = context -> {
            List<String> hosts = context.get(HOSTS);
            List<String> servers = context.get("servers");
            Composite composite = new Composite();
            for (String host : hosts) {
                ResourceAddress address = new ResourceAddress().add(HOST, host).add(CORE_SERVICE, MANAGEMENT).add(SERVICE, MANAGEMENT_OPERATIONS);
                Operation operation = new Operation.Builder(address, FIND_NON_PROGRESSING_OPERATION).build();
                composite.add(operation);
            }
            if (!servers.isEmpty()) {
                for (String server : servers) {
                    ResourceAddress address = AddressTemplate.of(server).append(MGMT_OPERATIONS_TEMPLATE).resolve(statementContext);
                    Operation operation = new Operation.Builder(address, FIND_NON_PROGRESSING_OPERATION).build();
                    composite.add(operation);
                }
            }
            return dispatcher.execute(composite).doOnSuccess(result -> {
                boolean nonProgressingOp = false;
                for (ModelNode r : result) {
                    ModelNode findResult = r.get(RESULT);
                    if (findResult != null && findResult.isDefined()) {
                        nonProgressingOp = true;
                        break;
                    }
                }
                context.set("nonProgressingOp", nonProgressingOp);
            }).toCompletable();
        };
        series(new FlowContext(progress.get()), hostsTask, serversTask, findNonProgressingTask).subscribe(new Outcome<FlowContext>() {

            @Override
            public void onError(FlowContext context, Throwable error) {
                em.onError(error);
            }

            @Override
            public void onSuccess(FlowContext context) {
                boolean nonProgressingOp = context.get("nonProgressingOp");
                eventBus.fireEvent(new NonProgressingOperationEvent(nonProgressingOp));
            }
        });
    }
}
Also used : ModelNode(org.jboss.hal.dmr.ModelNode) Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) NonProgressingOperationEvent(org.jboss.hal.core.runtime.NonProgressingOperationEvent) Operation(org.jboss.hal.dmr.Operation) StatementContext(org.jboss.hal.meta.StatementContext) EventBus(com.google.web.bindery.event.shared.EventBus) Action1(rx.functions.Action1) Collectors(java.util.stream.Collectors) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) SingleEmitter(rx.SingleEmitter) FlowContext(org.jboss.hal.flow.FlowContext) Outcome(org.jboss.hal.flow.Outcome) Composite(org.jboss.hal.dmr.Composite) List(java.util.List) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Task(org.jboss.hal.flow.Task) Collectors.toList(java.util.stream.Collectors.toList) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Flow.series(org.jboss.hal.flow.Flow.series) Collections(java.util.Collections) Composite(org.jboss.hal.dmr.Composite) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Operation(org.jboss.hal.dmr.Operation) FlowContext(org.jboss.hal.flow.FlowContext) NonProgressingOperationEvent(org.jboss.hal.core.runtime.NonProgressingOperationEvent) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 4 with Outcome

use of org.jboss.hal.flow.Outcome 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)

Example 5 with Outcome

use of org.jboss.hal.flow.Outcome in project console by hal.

the class ManagementOperationsPresenter method cancelNonProgressingOperation.

void cancelNonProgressingOperation() {
    if (environment.isStandalone()) {
        ResourceAddress address = MANAGEMENT_OPERATIONS_TEMPLATE.resolve(statementContext);
        Operation operation = new Operation.Builder(address, CANCEL_NON_PROGRESSING_OPERATION).build();
        dispatcher.execute(operation, result -> {
            MessageEvent.fire(eventBus, Message.info(resources.messages().cancelledOperation(result.asString())));
            reload();
        }, (operation1, failure) -> {
            // operation to cancel, handle this a non error in HAL
            if (failure.contains(WFLYDM_0089)) {
                MessageEvent.fire(eventBus, Message.success(SafeHtmlUtils.fromString(failure)));
            } else {
                MessageEvent.fire(eventBus, Message.error(SafeHtmlUtils.fromString(failure)));
            }
            reload();
        }, (operation1, ex) -> {
            // operation to cancel, handle this a non error in HAL
            if (ex.getMessage().contains(WFLYDM_0089)) {
                MessageEvent.fire(eventBus, Message.success(SafeHtmlUtils.fromString(ex.getMessage())));
            } else {
                MessageEvent.fire(eventBus, Message.error(SafeHtmlUtils.fromString(ex.getMessage())));
            }
            reload();
        });
    } else {
        Composite composite = new Composite();
        // return running hosts, to later call a cancel-non-progressing-operation on each host
        ResourceAddress rootAddress = new ResourceAddress();
        Operation opHosts = new Operation.Builder(rootAddress, READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, HOST).build();
        composite.add(opHosts);
        ResourceAddress address = new ResourceAddress().add(HOST, WILDCARD).add(SERVER, WILDCARD);
        Operation opRunningServers = new Operation.Builder(address, QUERY).param(SELECT, new ModelNode().add(HOST).add(NAME)).param(WHERE, new ModelNode().set(SERVER_STATE, "running")).build();
        composite.add(opRunningServers);
        dispatcher.execute(composite, (CompositeResult compositeResult) -> {
            // available hosts
            List<String> hosts = compositeResult.step(0).get(RESULT).asList().stream().map(ModelNode::asString).collect(toList());
            // runing servers
            List<String> servers = Collections.emptyList();
            ModelNode result = compositeResult.step(1);
            if (result != null && result.isDefined()) {
                servers = result.get(RESULT).asList().stream().map(r -> hostServerAddress(r.get(RESULT))).collect(toList());
            }
            // run each :cancel-non-progressing-operation on a specific task
            // because the :cancel-non-progressing-operation returns as a failure
            // for this case, continue to run the next task
            List<Task<FlowContext>> tasks = new ArrayList<>(hosts.size());
            for (String host : hosts) {
                // call cancel-non-progressing-operation on each host
                Task<FlowContext> task = context -> {
                    ResourceAddress hostAddress = new ResourceAddress().add(HOST, host).add(CORE_SERVICE, MANAGEMENT).add(SERVICE, MANAGEMENT_OPERATIONS);
                    return buildCancelOperation(hostAddress, context);
                };
                tasks.add(task);
            }
            for (String server : servers) {
                // call cancel-non-progressing-operation on each server
                Task<FlowContext> task = context -> {
                    ResourceAddress serverAddress = AddressTemplate.of(server).append(MANAGEMENT_OPERATIONS_TEMPLATE).resolve(statementContext);
                    return buildCancelOperation(serverAddress, context);
                };
                tasks.add(task);
            }
            series(new FlowContext(progress.get()), tasks).subscribe(new Outcome<FlowContext>() {

                @Override
                public void onError(FlowContext context, Throwable error) {
                    MessageEvent.fire(getEventBus(), Message.error(SafeHtmlUtils.fromString("Error loading management operations: " + error.getMessage())));
                }

                @Override
                public void onSuccess(FlowContext context) {
                    if (context.emptyStack()) {
                        // display the standard message if there is no cancelled operation
                        MessageEvent.fire(eventBus, Message.success(SafeHtmlUtils.fromString(context.get(WFLYDM_0089))));
                    } else {
                        // display the cancelled non progressing operation ids
                        List<String> canceledOps = new ArrayList<>();
                        while (!context.emptyStack()) {
                            canceledOps.add(context.pop());
                        }
                        String ids = Joiner.on(", ").join(canceledOps);
                        MessageEvent.fire(eventBus, Message.success(resources.messages().cancelledOperation(ids)));
                    }
                    reload();
                }
            });
        });
    }
}
Also used : ModelNode(org.jboss.hal.dmr.ModelNode) Completable(rx.Completable) Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) StatementContext(org.jboss.hal.meta.StatementContext) MessageEvent(org.jboss.hal.spi.MessageEvent) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) FlowContext(org.jboss.hal.flow.FlowContext) Outcome(org.jboss.hal.flow.Outcome) ArrayList(java.util.ArrayList) ModelType(org.jboss.hal.dmr.ModelType) Inject(javax.inject.Inject) Property(org.jboss.hal.dmr.Property) Task(org.jboss.hal.flow.Task) Single(rx.Single) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) Message(org.jboss.hal.spi.Message) HasPresenter(org.jboss.hal.core.mvp.HasPresenter) Names(org.jboss.hal.resources.Names) ApplicationFinderPresenter(org.jboss.hal.core.mvp.ApplicationFinderPresenter) SafeHtmlUtils(com.google.gwt.safehtml.shared.SafeHtmlUtils) ModelNodeHelper.asNamedNodes(org.jboss.hal.dmr.ModelNodeHelper.asNamedNodes) Requires(org.jboss.hal.spi.Requires) CompositeResult(org.jboss.hal.dmr.CompositeResult) ProxyCodeSplit(com.gwtplatform.mvp.client.annotations.ProxyCodeSplit) Operation(org.jboss.hal.dmr.Operation) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) Ids(org.jboss.hal.resources.Ids) FinderPathFactory(org.jboss.hal.core.finder.FinderPathFactory) EventBus(com.google.web.bindery.event.shared.EventBus) FinderPath(org.jboss.hal.core.finder.FinderPath) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) MANAGEMENT_OPERATIONS(org.jboss.hal.meta.token.NameTokens.MANAGEMENT_OPERATIONS) Composite(org.jboss.hal.dmr.Composite) List(java.util.List) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Collectors.toList(java.util.stream.Collectors.toList) Resources(org.jboss.hal.resources.Resources) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) HalView(org.jboss.hal.core.mvp.HalView) Flow.series(org.jboss.hal.flow.Flow.series) Finder(org.jboss.hal.core.finder.Finder) Footer(org.jboss.hal.spi.Footer) NamedNode(org.jboss.hal.dmr.NamedNode) Collections(java.util.Collections) Joiner(com.google.common.base.Joiner) Task(org.jboss.hal.flow.Task) Composite(org.jboss.hal.dmr.Composite) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) CompositeResult(org.jboss.hal.dmr.CompositeResult) ArrayList(java.util.ArrayList) Operation(org.jboss.hal.dmr.Operation) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ModelNode(org.jboss.hal.dmr.ModelNode)

Aggregations

FlowContext (org.jboss.hal.flow.FlowContext)14 Outcome (org.jboss.hal.flow.Outcome)14 Provider (javax.inject.Provider)12 Environment (org.jboss.hal.config.Environment)12 ModelDescriptionConstants (org.jboss.hal.dmr.ModelDescriptionConstants)12 Dispatcher (org.jboss.hal.dmr.dispatch.Dispatcher)12 Flow.series (org.jboss.hal.flow.Flow.series)12 Progress (org.jboss.hal.flow.Progress)12 Operation (org.jboss.hal.dmr.Operation)11 ResourceAddress (org.jboss.hal.dmr.ResourceAddress)11 StatementContext (org.jboss.hal.meta.StatementContext)11 Resources (org.jboss.hal.resources.Resources)11 List (java.util.List)10 EventBus (com.google.web.bindery.event.shared.EventBus)9 ArrayList (java.util.ArrayList)9 Collectors.toList (java.util.stream.Collectors.toList)9 Task (org.jboss.hal.flow.Task)9 Ids (org.jboss.hal.resources.Ids)9 Names (org.jboss.hal.resources.Names)9 Composite (org.jboss.hal.dmr.Composite)8