Search in sources :

Example 21 with Task

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

the class PropertiesStep method readJdbcDriverProperties.

private void readJdbcDriverProperties(boolean isXa, String dsClassname, String driverName, Consumer<List<String>> callback) {
    List<Task<FlowContext>> tasks = jdbcDriverProperties(environment, dispatcher, statementContext, driverName, resources);
    series(new FlowContext(progress.get()), tasks).subscribe(new JdbcDriverOutcome(dsClassname, isXa, callback));
}
Also used : Task(org.jboss.hal.flow.Task) JdbcDriverOutcome(org.jboss.hal.client.configuration.subsystem.datasource.JdbcDriverTasks.JdbcDriverOutcome) FlowContext(org.jboss.hal.flow.FlowContext)

Example 22 with Task

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

the class ManagementOperationsPresenter method reload.

@Override
protected void reload() {
    if (environment.isStandalone()) {
        ResourceAddress addressFindNP = MANAGEMENT_OPERATIONS_TEMPLATE.resolve(statementContext);
        Operation operationFindNP = new Operation.Builder(addressFindNP, FIND_NON_PROGRESSING_OPERATION).build();
        ResourceAddress addressMO = MANAGEMENT_OPERATIONS_TEMPLATE.resolve(statementContext);
        Operation operationMO = new Operation.Builder(addressMO, READ_CHILDREN_RESOURCES_OPERATION).param(CHILD_TYPE, ACTIVE_OPERATION).build();
        dispatcher.execute(new Composite(operationFindNP, operationMO), (CompositeResult result) -> {
            ModelNode resultNP = result.step(0).get(RESULT);
            ModelNode resultOperations = result.step(1).get(RESULT);
            final String nonProgressingId = resultNP.isDefined() ? resultNP.asString() : null;
            List<ManagementOperations> activeOps = asNamedNodes(resultOperations.asPropertyList()).stream().map(ManagementOperations::new).peek(activeOp -> {
                if (nonProgressingId != null && nonProgressingId.equals(activeOp.getName())) {
                    activeOp.setAsNonProgressing();
                }
            }).collect(toList());
            getView().update(activeOps);
        });
    } else {
        // return available 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(toList());
                }
                context.set("servers", servers);
            }).toCompletable();
        };
        // call find-non-progressing-operation and read-resource of active operations
        // 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);
                ResourceAddress ad = new ResourceAddress(address.clone()).add(ACTIVE_OPERATION, WILDCARD);
                Operation operationMO = new Operation.Builder(ad, READ_RESOURCE_OPERATION).build();
                composite.add(operationMO);
            }
            if (!servers.isEmpty()) {
                for (String server : servers) {
                    ResourceAddress address = AddressTemplate.of(server).append(MANAGEMENT_OPERATIONS_TEMPLATE).resolve(statementContext);
                    Operation findOp = new Operation.Builder(address, FIND_NON_PROGRESSING_OPERATION).build();
                    composite.add(findOp);
                    ResourceAddress ad = new ResourceAddress(address.clone()).add(ACTIVE_OPERATION, WILDCARD);
                    Operation operation = new Operation.Builder(ad, READ_RESOURCE_OPERATION).build();
                    composite.add(operation);
                }
            }
            return dispatcher.execute(composite).doOnSuccess(response -> {
                List<String> nonProgressingOps = new ArrayList<>();
                List<ManagementOperations> ops = new ArrayList<>();
                for (ModelNode r : response) {
                    ModelNode result = r.get(RESULT);
                    if (result != null && result.isDefined()) {
                        ModelType type = result.getType();
                        // if model is LIST it is the list of active operations
                        if (ModelType.LIST.equals(type)) {
                            for (ModelNode op : result.asList()) {
                                ModelNode opResult = op.get(RESULT);
                                // the result has two addresses
                                // 1) the active-operation address itself, example
                                // /host=master/server=server-three/core-service=management/service=management-operations/active-operation=1940701884
                                // 2) the resource address
                                // /host=master/server=server-three/subsystem=elytron/filesystem-realm=file1
                                // the active-operation address should be store to later use it to cancel, if needed
                                // the resource address is displayed to the user
                                ModelNode activeOpAddress = op.get(ADDRESS);
                                opResult.get(HAL_ACTIVE_OP_ADDRESS).set(activeOpAddress);
                                String opId = null;
                                List<Property> activeOperationAddressList = activeOpAddress.asPropertyList();
                                for (Property p : activeOperationAddressList) {
                                    if (p.getName().equals(ACTIVE_OPERATION)) {
                                        opId = p.getValue().asString();
                                    }
                                    // store the host and server to later show in the view
                                    if (p.getName().equals(HOST)) {
                                        opResult.get(HAL_ACTIVE_ADDRESS_HOST).set(p.getValue().asString());
                                    }
                                    if (p.getName().equals(SERVER)) {
                                        opResult.get(HAL_ACTIVE_ADDRESS_SERVER).set(p.getValue().asString());
                                    }
                                }
                                NamedNode node = new NamedNode(opId, opResult);
                                ManagementOperations activeOp = new ManagementOperations(node);
                                ops.add(activeOp);
                            }
                        } else {
                            nonProgressingOps.add(result.asString());
                        }
                    }
                }
                // if there are non progressing operations, mark them in the list
                if (!nonProgressingOps.isEmpty()) {
                    Collections.sort(nonProgressingOps);
                    for (ManagementOperations mop : ops) {
                        if (nonProgressingOps.indexOf(mop.getName()) > -1) {
                            mop.setAsNonProgressing();
                        }
                    }
                }
                context.set("active-operations", ops);
            }).toCompletable();
        };
        series(new FlowContext(progress.get()), hostsTask, serversTask, findNonProgressingTask).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) {
                List<ManagementOperations> ops = context.get("active-operations");
                getView().update(ops);
            }
        });
    }
}
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) Composite(org.jboss.hal.dmr.Composite) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) CompositeResult(org.jboss.hal.dmr.CompositeResult) ArrayList(java.util.ArrayList) NamedNode(org.jboss.hal.dmr.NamedNode) Operation(org.jboss.hal.dmr.Operation) FlowContext(org.jboss.hal.flow.FlowContext) ModelType(org.jboss.hal.dmr.ModelType) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ModelNode(org.jboss.hal.dmr.ModelNode) Property(org.jboss.hal.dmr.Property)

Example 23 with Task

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

the class HostPresenter 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
        Task<FlowContext> loadHttpInterface = flowContext -> {
            Operation readHttpInterface = new Operation.Builder(httpAddress, READ_RESOURCE_OPERATION).build();
            return dispatcher.execute(readHttpInterface).doOnSuccess(value -> {
                if (value.hasDefined(PORT)) {
                    // only domain mode contains "port" attribute
                    String port = value.get(PORT).asString();
                    if (port.contains("$")) {
                        // if it contains an expression value, resolve it at host level
                        ResourceAddress address = AddressTemplate.of("/host=" + environment.getDomainController()).resolve(statementContext);
                        Operation readPort = new Operation.Builder(address, RESOLVE_EXPRESSION).param(EXPRESSION, port).build();
                        dispatcher.execute(readPort, portResult -> flowContext.set(PORT, portResult.asString()));
                    } else {
                        flowContext.set(PORT, port);
                    }
                }
            }).toCompletable();
        };
        tasks.add(loadHttpInterface);
        // in domain-mode read the /host=<dc> domain controller
        // it is important for later use if user wants to reload dc if in admin-mode
        Task<FlowContext> loadDc = flowContext -> {
            ResourceAddress dcAddress = AddressTemplate.of("/host=" + environment.getDomainController()).resolve(statementContext);
            Operation readDcOp = new Operation.Builder(dcAddress, READ_RESOURCE_OPERATION).param(ATTRIBUTES_ONLY, true).build();
            return dispatcher.execute(readDcOp).doOnSuccess(value -> flowContext.set(HOST, new Host(value))).toCompletable();
        };
        tasks.add(loadDc);
        // as part of the disable ssl task, undefine the secure-port, it only exists in domain mode
        Task<FlowContext> undefineSecurePortTask = flowContext -> {
            Operation op = new Operation.Builder(httpAddress, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, SECURE_PORT).build();
            return dispatcher.execute(op).toCompletable();
        };
        tasks.add(undefineSecurePortTask);
        // 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;
                    Host host = flowContext.get(HOST);
                    reloadServer(host, location);
                } else {
                    reloadView();
                    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();
}
Also used : INCLUDE_RUNTIME(org.jboss.hal.dmr.ModelDescriptionConstants.INCLUDE_RUNTIME) TopologyTasks.reloadBlocking(org.jboss.hal.core.runtime.TopologyTasks.reloadBlocking) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) HTTP_INTERFACE_TEMPLATE(org.jboss.hal.client.runtime.host.AddressTemplates.HTTP_INTERFACE_TEMPLATE) VALUE(org.jboss.hal.dmr.ModelDescriptionConstants.VALUE) Map(java.util.Map) UNDEFINE_ATTRIBUTE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.UNDEFINE_ATTRIBUTE_OPERATION) LIST_ADD_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.LIST_ADD_OPERATION) HttpManagementInterfacePresenter(org.jboss.hal.client.runtime.managementinterface.HttpManagementInterfacePresenter) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) MANAGEMENT_INTERFACE(org.jboss.hal.dmr.ModelDescriptionConstants.MANAGEMENT_INTERFACE) CrudOperations(org.jboss.hal.core.CrudOperations) INDEX(org.jboss.hal.dmr.ModelDescriptionConstants.INDEX) PATH(org.jboss.hal.dmr.ModelDescriptionConstants.PATH) RESULT(org.jboss.hal.dmr.ModelDescriptionConstants.RESULT) CORE_SERVICE(org.jboss.hal.dmr.ModelDescriptionConstants.CORE_SERVICE) Flow.series(org.jboss.hal.flow.Flow.series) SYSTEM_PROPERTY(org.jboss.hal.dmr.ModelDescriptionConstants.SYSTEM_PROPERTY) Footer(org.jboss.hal.spi.Footer) EXPRESSION(org.jboss.hal.dmr.ModelDescriptionConstants.EXPRESSION) ATTRIBUTES_ONLY(org.jboss.hal.dmr.ModelDescriptionConstants.ATTRIBUTES_ONLY) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) KEY_STORE(org.jboss.hal.dmr.ModelDescriptionConstants.KEY_STORE) JVM(org.jboss.hal.dmr.ModelDescriptionConstants.JVM) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Task(org.jboss.hal.flow.Task) RELOAD(org.jboss.hal.dmr.ModelDescriptionConstants.RELOAD) Progress(org.jboss.hal.flow.Progress) TRUST_MANAGER(org.jboss.hal.dmr.ModelDescriptionConstants.TRUST_MANAGER) CompositeResult(org.jboss.hal.dmr.CompositeResult) EnableSSLWizard(org.jboss.hal.client.shared.sslwizard.EnableSSLWizard) SSL_CONTEXT(org.jboss.hal.dmr.ModelDescriptionConstants.SSL_CONTEXT) Operation(org.jboss.hal.dmr.Operation) EventBus(com.google.web.bindery.event.shared.EventBus) WRITE_ATTRIBUTE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) DomGlobal.window(elemental2.dom.DomGlobal.window) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) NameTokens(org.jboss.hal.meta.token.NameTokens) READ_CHILDREN_NAMES_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.READ_CHILDREN_NAMES_OPERATION) NamedNode(org.jboss.hal.dmr.NamedNode) ADMIN_ONLY(org.jboss.hal.dmr.ModelDescriptionConstants.ADMIN_ONLY) Form(org.jboss.hal.ballroom.form.Form) ConstantHeadersPresenter(org.jboss.hal.client.runtime.managementinterface.ConstantHeadersPresenter) Dialog(org.jboss.hal.ballroom.dialog.Dialog) LIST_REMOVE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.LIST_REMOVE_OPERATION) Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) StatementContext(org.jboss.hal.meta.StatementContext) ELYTRON_TEMPLATE(org.jboss.hal.client.runtime.host.AddressTemplates.ELYTRON_TEMPLATE) HTMLElement(elemental2.dom.HTMLElement) Message(org.jboss.hal.spi.Message) KEY_MANAGER(org.jboss.hal.dmr.ModelDescriptionConstants.KEY_MANAGER) NAME(org.jboss.hal.dmr.ModelDescriptionConstants.NAME) SECURE_PORT(org.jboss.hal.dmr.ModelDescriptionConstants.SECURE_PORT) READ_RESOURCE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.READ_RESOURCE_OPERATION) SOCKET_BINDING_GROUP(org.jboss.hal.dmr.ModelDescriptionConstants.SOCKET_BINDING_GROUP) PORT(org.jboss.hal.dmr.ModelDescriptionConstants.PORT) RESTART_SERVERS(org.jboss.hal.dmr.ModelDescriptionConstants.RESTART_SERVERS) ModelNodeHelper.asNamedNodes(org.jboss.hal.dmr.ModelNodeHelper.asNamedNodes) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) FinderPath(org.jboss.hal.core.finder.FinderPath) FORM(org.jboss.hal.resources.Ids.FORM) Collectors(java.util.stream.Collectors) List(java.util.List) OperationFactory(org.jboss.hal.core.OperationFactory) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem) Finder(org.jboss.hal.core.finder.Finder) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) HOST(org.jboss.hal.dmr.ModelDescriptionConstants.HOST) SupportsExpertMode(org.jboss.hal.core.mvp.SupportsExpertMode) ModelNode(org.jboss.hal.dmr.ModelNode) MessageEvent(org.jboss.hal.spi.MessageEvent) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) CHILD_TYPE(org.jboss.hal.dmr.ModelDescriptionConstants.CHILD_TYPE) HashMap(java.util.HashMap) CONSTANT_HEADERS(org.jboss.hal.dmr.ModelDescriptionConstants.CONSTANT_HEADERS) READ_CHILDREN_RESOURCES_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.READ_CHILDREN_RESOURCES_OPERATION) Inject(javax.inject.Inject) AddressTemplate(org.jboss.hal.meta.AddressTemplate) Constants(org.jboss.hal.resources.Constants) RESOLVE_EXPRESSION(org.jboss.hal.dmr.ModelDescriptionConstants.RESOLVE_EXPRESSION) INTERFACE(org.jboss.hal.dmr.ModelDescriptionConstants.INTERFACE) Requires(org.jboss.hal.spi.Requires) ProxyCodeSplit(com.gwtplatform.mvp.client.annotations.ProxyCodeSplit) Ids(org.jboss.hal.resources.Ids) FinderPathFactory(org.jboss.hal.core.finder.FinderPathFactory) Composite(org.jboss.hal.dmr.Composite) HEADERS(org.jboss.hal.dmr.ModelDescriptionConstants.HEADERS) MANAGEMENT(org.jboss.hal.dmr.ModelDescriptionConstants.MANAGEMENT) MbuiPresenter(org.jboss.hal.core.mbui.MbuiPresenter) Resources(org.jboss.hal.resources.Resources) MbuiView(org.jboss.hal.core.mbui.MbuiView) EnableSSLPresenter(org.jboss.hal.client.shared.sslwizard.EnableSSLPresenter) SERVER_SSL_CONTEXT(org.jboss.hal.dmr.ModelDescriptionConstants.SERVER_SSL_CONTEXT) Host(org.jboss.hal.core.runtime.host.Host) Task(org.jboss.hal.flow.Task) HTMLElement(elemental2.dom.HTMLElement) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Constants(org.jboss.hal.resources.Constants) Host(org.jboss.hal.core.runtime.host.Host) Operation(org.jboss.hal.dmr.Operation) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) List(java.util.List) ModelNode(org.jboss.hal.dmr.ModelNode) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem)

Example 24 with Task

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

the class CacheColumn method addCache.

private void addCache(CacheType cacheType) {
    Metadata metadata = metadataRegistry.lookup(cacheType.template);
    AddResourceDialog dialog = new AddResourceDialog(Ids.build(cacheType.baseId, Ids.ADD), resources.messages().addResourceTitle(cacheType.type), metadata, (name, model) -> {
        String cacheContainer = findCacheContainer(getFinder().getContext().getPath());
        ResourceAddress address = cacheType.template.resolve(statementContext, cacheContainer, name);
        if (cacheType.equals(CacheType.LOCAL)) {
            crud.add(cacheType.type, name, address, model, (n, a) -> refresh(Ids.build(cacheType.baseId, name)));
        } else {
            ResourceAddress jgroupsAddress = AddressTemplates.TRANSPORT_JGROUPS_TEMPLATE.resolve(statementContext, cacheContainer);
            ResourceCheck check = new ResourceCheck(dispatcher, jgroupsAddress);
            Task<FlowContext> add = context -> {
                Operation addJgroups = new Operation.Builder(jgroupsAddress, ADD).build();
                int status = context.pop();
                if (status == 200) {
                    context.set(JGROUPS_ADDITION_STATUS, false);
                    return Completable.complete();
                } else {
                    context.set(JGROUPS_ADDITION_STATUS, true);
                    return dispatcher.execute(addJgroups).toCompletable();
                }
            };
            series(new FlowContext(progress.get()), check, add).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {

                @Override
                public void onSuccess(FlowContext context) {
                    if (context.get(JGROUPS_ADDITION_STATUS).equals(true)) {
                        MessageEvent.fire(eventBus, Message.success(resources.messages().addResourceSuccess(Names.TRANSPORT, Names.JGROUPS)));
                    }
                    crud.add(cacheType.type, name, address, model, (n, a) -> refresh(Ids.build(cacheType.baseId, name)));
                }
            });
        }
    });
    dialog.getForm().<String>getFormItem(NAME).addValidationHandler(createUniqueValidation());
    dialog.show();
}
Also used : AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) AddressTemplates(org.jboss.hal.client.configuration.subsystem.infinispan.AddressTemplates) Provider(javax.inject.Provider) 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) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) FinderSegment(org.jboss.hal.core.finder.FinderSegment) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Icons(org.jboss.hal.resources.Icons) HTMLElement(elemental2.dom.HTMLElement) Message(org.jboss.hal.spi.Message) Metadata(org.jboss.hal.meta.Metadata) Places(org.jboss.hal.core.mvp.Places) ResourceCheck(org.jboss.hal.dmr.ResourceCheck) Names(org.jboss.hal.resources.Names) CrudOperations(org.jboss.hal.core.CrudOperations) Collections.emptyList(java.util.Collections.emptyList) FinderPath(org.jboss.hal.core.finder.FinderPath) List(java.util.List) MetadataRegistry(org.jboss.hal.meta.MetadataRegistry) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) CLEAR_SELECTION(org.jboss.hal.core.finder.FinderColumn.RefreshMode.CLEAR_SELECTION) Flow.series(org.jboss.hal.flow.Flow.series) Finder(org.jboss.hal.core.finder.Finder) Footer(org.jboss.hal.spi.Footer) Arrays.stream(java.util.Arrays.stream) Completable(rx.Completable) AsyncColumn(org.jboss.hal.spi.AsyncColumn) MessageEvent(org.jboss.hal.spi.MessageEvent) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) ColumnAction(org.jboss.hal.core.finder.ColumnAction) ItemAction(org.jboss.hal.core.finder.ItemAction) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Property(org.jboss.hal.dmr.Property) Task(org.jboss.hal.flow.Task) Progress(org.jboss.hal.flow.Progress) FinderColumn(org.jboss.hal.core.finder.FinderColumn) ColumnActionFactory(org.jboss.hal.core.finder.ColumnActionFactory) Requires(org.jboss.hal.spi.Requires) 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) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Collectors.toList(java.util.stream.Collectors.toList) Resources(org.jboss.hal.resources.Resources) Collections(java.util.Collections) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Metadata(org.jboss.hal.meta.Metadata) ResourceCheck(org.jboss.hal.dmr.ResourceCheck) Operation(org.jboss.hal.dmr.Operation) FlowContext(org.jboss.hal.flow.FlowContext)

Example 25 with Task

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

the class RealmsPresenter method saveIdentity.

void saveIdentity(Metadata metadata, String resource, String identity, Map<String, List<String>> originalAttributes, Map<String, List<String>> attributes, Consumer<Boolean> viewCallback) {
    LabelBuilder labelBuilder = new LabelBuilder();
    String resourceName = labelBuilder.label(metadata.getTemplate().lastName()) + SPACE + resource;
    ResourceAddress address = metadata.getTemplate().resolve(statementContext, resource);
    // remove the old attributes and add the attribute list
    List<Task<FlowContext>> tasks = new ArrayList<>();
    // compare the original values to the new values, to see which one to remove or add
    originalAttributes.forEach((key, originalValues) -> {
        List<String> newValues = attributes.get(key);
        if (!originalValues.equals(newValues)) {
            // remove the key tag if it is not present, the user deleted it
            Task<FlowContext> addTask = flowContext -> {
                Operation operation = new Operation.Builder(address, REMOVE_IDENTITY_ATTRIBUTE).param(IDENTITY, identity).param(NAME, key).build();
                return dispatcher.execute(operation).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().saveIdentityError(identity, resourceName, ex.getMessage())))).toCompletable();
            };
            tasks.add(addTask);
        }
    });
    attributes.forEach((name, newValues) -> {
        List<String> originalValues = originalAttributes.get(name);
        if (!newValues.equals(originalValues)) {
            Task<FlowContext> addTask = flowContext -> {
                ModelNode modelValues = new ModelNode();
                newValues.forEach(modelValues::add);
                Operation operation = new Operation.Builder(address, ADD_IDENTITY_ATTRIBUTE).param(IDENTITY, identity).param(NAME, name).param(VALUE, modelValues).build();
                return dispatcher.execute(operation).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().saveIdentityError(identity, resourceName, ex.getMessage())))).toCompletable();
            };
            tasks.add(addTask);
        }
    });
    if (tasks.isEmpty()) {
        MessageEvent.fire(getEventBus(), Message.warning(resources.messages().noChanges()));
    } else {
        series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {

            @Override
            public void onSuccess(FlowContext flowContext) {
                viewCallback.accept(true);
                MessageEvent.fire(getEventBus(), Message.success(resources.messages().saveIdentitySuccess(identity, resourceName)));
            }

            @Override
            public void onError(FlowContext context, Throwable throwable) {
                MessageEvent.fire(getEventBus(), Message.error(resources.messages().saveIdentityError(identity, resourceName, throwable.getMessage())));
            }
        });
    }
}
Also used : Dialog(org.jboss.hal.ballroom.dialog.Dialog) Provider(javax.inject.Provider) StatementContext(org.jboss.hal.meta.StatementContext) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) IDENTITY_ATTRIBUTE_MAPPING(org.jboss.hal.resources.Names.IDENTITY_ATTRIBUTE_MAPPING) Map(java.util.Map) Message(org.jboss.hal.spi.Message) HasPresenter(org.jboss.hal.core.mvp.HasPresenter) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) ModelNodeHelper.asNamedNodes(org.jboss.hal.dmr.ModelNodeHelper.asNamedNodes) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) FinderPath(org.jboss.hal.core.finder.FinderPath) List(java.util.List) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) AddressTemplates(org.jboss.hal.client.runtime.subsystem.elytron.AddressTemplates) 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) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) SupportsExpertMode(org.jboss.hal.core.mvp.SupportsExpertMode) ModelNode(org.jboss.hal.dmr.ModelNode) PasswordWizard(org.jboss.hal.client.runtime.subsystem.elytron.wizardpassword.PasswordWizard) MessageEvent(org.jboss.hal.spi.MessageEvent) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Task(org.jboss.hal.flow.Task) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) ApplicationFinderPresenter(org.jboss.hal.core.mvp.ApplicationFinderPresenter) 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) Ids(org.jboss.hal.resources.Ids) FinderPathFactory(org.jboss.hal.core.finder.FinderPathFactory) EventBus(com.google.web.bindery.event.shared.EventBus) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) Consumer(java.util.function.Consumer) Composite(org.jboss.hal.dmr.Composite) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) NameTokens(org.jboss.hal.meta.token.NameTokens) Resources(org.jboss.hal.resources.Resources) NamedNode(org.jboss.hal.dmr.NamedNode) Form(org.jboss.hal.ballroom.form.Form) Task(org.jboss.hal.flow.Task) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) ArrayList(java.util.ArrayList) Operation(org.jboss.hal.dmr.Operation) FlowContext(org.jboss.hal.flow.FlowContext) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) ModelNode(org.jboss.hal.dmr.ModelNode)

Aggregations

Task (org.jboss.hal.flow.Task)28 FlowContext (org.jboss.hal.flow.FlowContext)27 ArrayList (java.util.ArrayList)23 List (java.util.List)23 Provider (javax.inject.Provider)22 Dispatcher (org.jboss.hal.dmr.dispatch.Dispatcher)22 Flow.series (org.jboss.hal.flow.Flow.series)22 Progress (org.jboss.hal.flow.Progress)22 EventBus (com.google.web.bindery.event.shared.EventBus)21 ModelNode (org.jboss.hal.dmr.ModelNode)21 Operation (org.jboss.hal.dmr.Operation)21 StatementContext (org.jboss.hal.meta.StatementContext)21 Resources (org.jboss.hal.resources.Resources)21 ResourceAddress (org.jboss.hal.dmr.ResourceAddress)20 ModelDescriptionConstants (org.jboss.hal.dmr.ModelDescriptionConstants)19 Ids (org.jboss.hal.resources.Ids)19 Message (org.jboss.hal.spi.Message)19 MessageEvent (org.jboss.hal.spi.MessageEvent)19 AddressTemplate (org.jboss.hal.meta.AddressTemplate)18 Footer (org.jboss.hal.spi.Footer)18