Search in sources :

Example 1 with Message

use of org.jboss.hal.spi.Message in project console by hal.

the class StandaloneDeploymentColumn method explodeSubs.

private void explodeSubs(Deployment deployment) {
    ResourceAddress address = new ResourceAddress().add(DEPLOYMENT, deployment.getName());
    Operation disable = new Operation.Builder(address, UNDEPLOY).build();
    Composite op = new Composite(disable);
    String id = Ids.deployment(deployment.getName());
    ItemMonitor.startProgress(id);
    deployment.getSubdeployments().forEach(subdeployment -> {
        Operation explode = new Operation.Builder(address, EXPLODE).param(PATH, subdeployment.getName()).build();
        op.add(explode);
    });
    dispatcher.execute(op, (Consumer<CompositeResult>) result -> {
        enable(deployment);
        MessageEvent.fire(eventBus, Message.success(resources.messages().deploymentExploded(deployment.getName())));
    }, (operation, failure) -> {
        ItemMonitor.stopProgress(id);
        SafeHtml message = failure.contains("WFLYDR0015") ? resources.messages().deploymentSubAlreadyExploded() : resources.messages().lastOperationException();
        MessageEvent.fire(eventBus, Message.error(message, failure));
    });
}
Also used : Dialog(org.jboss.hal.ballroom.dialog.Dialog) Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) Deployment(org.jboss.hal.core.deployment.Deployment) 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) ManagementModel(org.jboss.hal.meta.ManagementModel) CheckDeployment(org.jboss.hal.client.deployment.DeploymentTasks.CheckDeployment) CreateEmptyDialog(org.jboss.hal.client.deployment.dialog.CreateEmptyDialog) UploadDeploymentStep(org.jboss.hal.client.deployment.wizard.UploadDeploymentStep) UploadOrReplace(org.jboss.hal.client.deployment.DeploymentTasks.UploadOrReplace) Column(org.jboss.hal.spi.Column) HTMLElement(elemental2.dom.HTMLElement) Message(org.jboss.hal.spi.Message) Server(org.jboss.hal.core.runtime.server.Server) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) DEPLOYMENT_ADDRESS(org.jboss.hal.client.deployment.StandaloneDeploymentColumn.DEPLOYMENT_ADDRESS) DeploymentState(org.jboss.hal.client.deployment.wizard.DeploymentState) ServerActions(org.jboss.hal.core.runtime.server.ServerActions) DeploymentContext(org.jboss.hal.client.deployment.wizard.DeploymentContext) CrudOperations(org.jboss.hal.core.CrudOperations) AddUnmanagedDialog(org.jboss.hal.client.deployment.dialog.AddUnmanagedDialog) NAMES(org.jboss.hal.client.deployment.wizard.DeploymentState.NAMES) List(java.util.List) Status(org.jboss.hal.core.deployment.Deployment.Status) 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) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) CSS.fontAwesome(org.jboss.hal.resources.CSS.fontAwesome) ModelNode(org.jboss.hal.dmr.ModelNode) 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) Outcome(org.jboss.hal.flow.Outcome) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) JsHelper(org.jboss.hal.js.JsHelper) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) AddUnmanagedDeployment(org.jboss.hal.client.deployment.DeploymentTasks.AddUnmanagedDeployment) UPLOAD(org.jboss.hal.client.deployment.wizard.DeploymentState.UPLOAD) RESTORE_SELECTION(org.jboss.hal.core.finder.FinderColumn.RefreshMode.RESTORE_SELECTION) FinderColumn(org.jboss.hal.core.finder.FinderColumn) 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) NamesStep(org.jboss.hal.client.deployment.wizard.NamesStep) Ids(org.jboss.hal.resources.Ids) Wizard(org.jboss.hal.ballroom.wizard.Wizard) EventBus(com.google.web.bindery.event.shared.EventBus) CSS.pfIcon(org.jboss.hal.resources.CSS.pfIcon) ItemMonitor(org.jboss.hal.core.finder.ItemMonitor) Consumer(java.util.function.Consumer) 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) Strings(org.jboss.hal.resources.Strings) UploadElement(org.jboss.hal.client.shared.uploadwizard.UploadElement) Elements.span(org.jboss.gwt.elemento.core.Elements.span) Composite(org.jboss.hal.dmr.Composite) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) CompositeResult(org.jboss.hal.dmr.CompositeResult) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Operation(org.jboss.hal.dmr.Operation)

Example 2 with Message

use of org.jboss.hal.spi.Message in project console by hal.

the class EnableSSLWizard method show.

public void show() {
    Constants constants = resources.constants();
    AddressTemplate template = undertowHttps ? UNDERTOW_HTTPS_LISTENER_TEMPLATE : HTTP_INTERFACE_TEMPLATE;
    Wizard.Builder<EnableSSLContext, EnableSSLState> wb = new Wizard.Builder<>(constants.enableSSLManagementTitle(), new EnableSSLContext());
    wb.addStep(EnableSSLState.DEFINE_STRATEGY, new DefineStrategyStep(resources, environment.isStandalone(), undertowHttps)).addStep(EnableSSLState.CONFIGURATION, new ConfigurationStep(existingResources, resources, environment, undertowHttps, template)).addStep(EnableSSLState.REVIEW, new ReviewStep(dispatcher, statementContext, resources, environment, undertowHttps, template)).onBack((context, currentState) -> {
        EnableSSLState previous = null;
        switch(currentState) {
            case DEFINE_STRATEGY:
                break;
            case CONFIGURATION:
                previous = EnableSSLState.DEFINE_STRATEGY;
                break;
            case REVIEW:
                previous = EnableSSLState.CONFIGURATION;
                break;
            default:
                break;
        }
        return previous;
    }).onNext((context, currentState) -> {
        EnableSSLState next = null;
        switch(currentState) {
            case DEFINE_STRATEGY:
                next = EnableSSLState.CONFIGURATION;
                break;
            case CONFIGURATION:
                next = EnableSSLState.REVIEW;
                break;
            case REVIEW:
                break;
            default:
                break;
        }
        return next;
    }).stayOpenAfterFinish().onFinish((wizard, context) -> {
        ModelNode model = context.model;
        ModelNode credRef = new ModelNode();
        credRef.get(CLEAR_TEXT).set(asString(model, AbstractConfiguration.KEY_STORE_PASSWORD));
        // use Flow tasks to run DMR operations as there are resources that must exists before next
        // operations are called, as in the example of a generate-key-pair and import-certificate
        // the key-store must exists. For this case, the Composite doesn't work.
        List<Task<FlowContext>> tasks = new ArrayList<>();
        // key-store is only created when user chooses to create all resources or create a key-store based on
        // an existing JKS file
        boolean createKeyStore = !context.strategy.equals(EnableSSLContext.Strategy.KEYSTORE_RESOURCE_EXISTS);
        String keyStoreName = createKeyStore ? asString(model, AbstractConfiguration.KEY_STORE_NAME) : asString(model, KEY_STORE);
        if (createKeyStore) {
            if (context.strategy.equals(EnableSSLContext.Strategy.KEYSTORE_CREATE)) {
                ResourceAddress ksAddress = keyStoreTemplate().resolve(statementContext, keyStoreName);
                tasks.add(flowContext -> {
                    Operation.Builder builder = new Operation.Builder(ksAddress, ADD).param(PATH, asString(model, KEY_STORE_PATH)).param(CREDENTIAL_REFERENCE, credRef).param(TYPE, asString(model, AbstractConfiguration.KEY_STORE_TYPE));
                    if (model.hasDefined(AbstractConfiguration.KEY_STORE_RELATIVE_TO)) {
                        builder.param(RELATIVE_TO, asString(model, AbstractConfiguration.KEY_STORE_RELATIVE_TO));
                    }
                    Operation keyStoreOp = builder.build();
                    return dispatcher.execute(keyStoreOp).doOnError(exception -> wizard.showError(constants.failed(), resources.messages().addKeyStoreError(keyStoreName), exception.getMessage(), false)).toCompletable();
                });
                tasks.add(flowContext -> {
                    Composite composite = new Composite();
                    // the generate-key=pair can only be called on an existing key-store
                    String dn = "CN=" + asString(model, AbstractConfiguration.PRIVATE_KEY_DN_CN) + ", OU=" + asString(model, AbstractConfiguration.PRIVATE_KEY_DN_OU) + ", O=" + asString(model, AbstractConfiguration.PRIVATE_KEY_DN_O) + ", L=" + asString(model, AbstractConfiguration.PRIVATE_KEY_DN_L) + ", ST=" + asString(model, AbstractConfiguration.PRIVATE_KEY_DN_ST) + ", C=" + asString(model, AbstractConfiguration.PRIVATE_KEY_DN_C);
                    Operation genKeyOp = new Operation.Builder(ksAddress, GENERATE_KEY_PAIR).param(ALIAS, asString(model, AbstractConfiguration.PRIVATE_KEY_ALIAS)).param(DISTINGUISHED_NAME, dn).param(VALIDITY, asString(model, AbstractConfiguration.PRIVATE_KEY_VALIDITY)).param(ModelDescriptionConstants.ALGORITHM, asString(model, AbstractConfiguration.PRIVATE_KEY_ALGORITHM)).build();
                    composite.add(genKeyOp);
                    Operation storeOp = new Operation.Builder(ksAddress, STORE).build();
                    composite.add(storeOp);
                    return dispatcher.execute(composite).toCompletable();
                });
            } else if (context.strategy.equals(EnableSSLContext.Strategy.KEYSTORE_FILE_EXISTS)) {
                tasks.add(flowContext -> {
                    ResourceAddress ksAddress = keyStoreTemplate().resolve(statementContext, keyStoreName);
                    Operation.Builder builder = new Operation.Builder(ksAddress, ADD).param(PATH, asString(model, KEY_STORE_PATH)).param(CREDENTIAL_REFERENCE, credRef).param(TYPE, asString(model, AbstractConfiguration.KEY_STORE_TYPE)).param(REQUIRED, true);
                    if (model.hasDefined(AbstractConfiguration.KEY_STORE_RELATIVE_TO)) {
                        builder.param(RELATIVE_TO, asString(model, AbstractConfiguration.KEY_STORE_RELATIVE_TO));
                    }
                    Operation keyStoreOp = builder.build();
                    return dispatcher.execute(keyStoreOp).doOnError(exception -> wizard.showError(constants.failed(), resources.messages().addKeyStoreError(keyStoreName), exception.getMessage(), false)).toCompletable();
                });
            } else if (context.strategy.equals(EnableSSLContext.Strategy.KEYSTORE_OBTAIN_LETSENCRYPT)) {
                ResourceAddress ksAddress = keyStoreTemplate().resolve(statementContext, keyStoreName);
                tasks.add(flowContext -> {
                    Operation.Builder builder = new Operation.Builder(ksAddress, ADD).param(PATH, asString(model, KEY_STORE_PATH)).param(CREDENTIAL_REFERENCE, credRef).param(TYPE, asString(model, AbstractConfiguration.KEY_STORE_TYPE));
                    if (model.hasDefined(AbstractConfiguration.KEY_STORE_RELATIVE_TO)) {
                        builder.param(RELATIVE_TO, asString(model, AbstractConfiguration.KEY_STORE_RELATIVE_TO));
                    }
                    Operation keyStoreOp = builder.build();
                    return dispatcher.execute(keyStoreOp).doOnError(exception -> wizard.showError(constants.failed(), resources.messages().addKeyStoreError(keyStoreName), exception.getMessage(), false)).toCompletable();
                });
                String caaName = asString(model, CAA_NAME);
                ResourceAddress caaAddress = certificateAuthorityAccountTemplate().resolve(statementContext, caaName);
                tasks.add(flowContext -> {
                    Operation caaOp = new Operation.Builder(caaAddress, ADD).param(KEY_STORE, keyStoreName).param(ALIAS, asString(model, CAA_ALIAS)).build();
                    return dispatcher.execute(caaOp).doOnError(exception -> wizard.showError(constants.failed(), resources.messages().addResourceError(caaName, exception.getMessage()), false)).toCompletable();
                });
                tasks.add(flowContext -> {
                    Composite composite = new Composite();
                    String obtainAlias = asString(model, PRIVATE_KEY_ALIAS);
                    Operation obtainOp = new Operation.Builder(ksAddress, OBTAIN_CERTIFICATE).param(ALIAS, obtainAlias).param(CERTIFICATE_AUTHORITY_ACCOUNT, caaName).param("domain-names", model.get(CAA_DOMAIN_NAMES)).param("agree-to-terms-of-service", true).param("staging", asString(model, CAA_STAGING)).build();
                    composite.add(obtainOp);
                    Operation storeOp = new Operation.Builder(ksAddress, STORE).build();
                    composite.add(storeOp);
                    return dispatcher.execute(composite).doOnError(ex -> wizard.showError(constants.failed(), resources.messages().obtainCertificateError(obtainAlias, keyStoreName, ex.getMessage()), false)).toCompletable();
                });
            }
        }
        String trustManagerName = model.hasDefined(TRUST_MANAGER) ? asString(model, TRUST_MANAGER) : null;
        if (context.mutualAuthentication) {
            ModelNode tsCredRef = new ModelNode();
            tsCredRef.get(CLEAR_TEXT).set(asString(model, AbstractConfiguration.TRUST_STORE_PASSWORD));
            String trustStoreName = asString(model, AbstractConfiguration.TRUST_STORE_NAME);
            ResourceAddress tsAddress = keyStoreTemplate().resolve(statementContext, trustStoreName);
            tasks.add(flowContext -> {
                Operation.Builder builder = new Operation.Builder(tsAddress, ADD).param(PATH, asString(model, AbstractConfiguration.TRUST_STORE_PATH)).param(CREDENTIAL_REFERENCE, tsCredRef).param(TYPE, asString(model, AbstractConfiguration.TRUST_STORE_TYPE));
                if (model.hasDefined(AbstractConfiguration.TRUST_STORE_RELATIVE_TO)) {
                    builder.param(RELATIVE_TO, asString(model, AbstractConfiguration.TRUST_STORE_RELATIVE_TO));
                }
                Operation trustStoreOp = builder.build();
                return dispatcher.execute(trustStoreOp).toCompletable();
            });
            tasks.add(flowContext -> {
                Composite composite = new Composite();
                Operation importCertOp = new Operation.Builder(tsAddress, IMPORT_CERTIFICATE).param(ALIAS, asString(model, AbstractConfiguration.CLIENT_CERTIFICATE_ALIAS)).param(PATH, asString(model, AbstractConfiguration.CLIENT_CERTIFICATE_PATH)).param(CREDENTIAL_REFERENCE, tsCredRef).param(VALIDATE, model.get(AbstractConfiguration.CLIENT_CERTIFICATE_VALIDATE).asBoolean(false)).param(TRUST_CACERTS, model.get(AbstractConfiguration.CLIENT_CERTIFICATE_TRUST).asBoolean(false)).build();
                composite.add(importCertOp);
                Operation storeOp = new Operation.Builder(tsAddress, STORE).build();
                composite.add(storeOp);
                ResourceAddress etmAddress = trustManagerTemplate().resolve(statementContext, trustManagerName);
                Operation trustManagerOp = new Operation.Builder(etmAddress, ADD).param(KEY_STORE, trustStoreName).param(ModelDescriptionConstants.ALGORITHM, KEY_MANAGER_ALGORITHM).build();
                composite.add(trustManagerOp);
                return dispatcher.execute(composite).toCompletable();
            });
        }
        Composite composite = new Composite();
        String keyManager = asString(model, KEY_MANAGER);
        ResourceAddress ekmAddress = keyManagerTemplate().resolve(statementContext, keyManager);
        Operation keyManagerOp = new Operation.Builder(ekmAddress, ADD).param(KEY_STORE, keyStoreName).param(ModelDescriptionConstants.ALGORITHM, KEY_MANAGER_ALGORITHM).param(CREDENTIAL_REFERENCE, credRef).build();
        composite.add(keyManagerOp);
        ModelNode protocols = new ModelNode();
        protocols.add(KEY_MANAGER_TLSV1_2);
        String serverSslContext = asString(model, SERVER_SSL_CONTEXT);
        ResourceAddress sslCtxAddress = sslContextTemplate().resolve(statementContext, serverSslContext);
        Operation.Builder sslCtxBuilder = new Operation.Builder(sslCtxAddress, ADD).param(KEY_MANAGER, keyManager).param(PROTOCOLS, protocols);
        if (context.mutualAuthentication) {
            sslCtxBuilder.param(TRUST_MANAGER, trustManagerName);
            sslCtxBuilder.param(WANT_CLIENT_AUTH, true);
        }
        Operation sslCtxOp = sslCtxBuilder.build();
        composite.add(sslCtxOp);
        if (undertowHttps) {
            ResourceAddress httpsAddress = UNDERTOW_HTTPS_LISTENER_TEMPLATE.resolve(statementContext, undertowServer, httpsListener);
            Operation writeSslCtxOp = new Operation.Builder(httpsAddress, WRITE_ATTRIBUTE_OPERATION).param(NAME, SSL_CONTEXT).param(VALUE, serverSslContext).build();
            composite.add(writeSslCtxOp);
            // undefine the "alternatives" attributes
            composite.add(undefineAttribute(httpsAddress, SECURITY_REALM));
            composite.add(undefineAttribute(httpsAddress, "verify-client"));
            composite.add(undefineAttribute(httpsAddress, "enabled-cipher-suites"));
            composite.add(undefineAttribute(httpsAddress, "enabled-protocols"));
            composite.add(undefineAttribute(httpsAddress, "ssl-session-cache-size"));
            composite.add(undefineAttribute(httpsAddress, "ssl-session-timeout"));
        } else {
            ResourceAddress httpInterfaceAddress = HTTP_INTERFACE_TEMPLATE.resolve(statementContext);
            Operation writeSslCtxOp = new Operation.Builder(httpInterfaceAddress, WRITE_ATTRIBUTE_OPERATION).param(NAME, SSL_CONTEXT).param(VALUE, serverSslContext).build();
            composite.add(writeSslCtxOp);
            if (environment.isStandalone()) {
                Operation writeSecureSocketBinding = new Operation.Builder(httpInterfaceAddress, WRITE_ATTRIBUTE_OPERATION).param(NAME, SECURE_SOCKET_BINDING).param(VALUE, asString(model, SECURE_SOCKET_BINDING)).build();
                composite.add(writeSecureSocketBinding);
            } else {
                Operation writeSecurePortOp = new Operation.Builder(httpInterfaceAddress, WRITE_ATTRIBUTE_OPERATION).param(NAME, SECURE_PORT).param(VALUE, asString(model, SECURE_PORT)).build();
                composite.add(writeSecurePortOp);
            }
        }
        tasks.add(flowContext -> dispatcher.execute(composite).toCompletable());
        series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {

            @Override
            public void onSuccess(FlowContext flowContext) {
                if (undertowHttps) {
                    wizard.showSuccess(resources.constants().success(), resources.messages().enableSSLResultsSuccessUndertow(httpsListener, serverSslContext), context1 -> presenter.reloadView(), true);
                } else {
                    // constructs the http management console url
                    String serverName = environment.isStandalone() ? Names.STANDALONE_SERVER : Names.DOMAIN_CONTROLLER;
                    String label = resources.constants().reload() + " " + serverName;
                    SafeHtml description;
                    StringBuilder location = new StringBuilder("https://" + window.location.getHostname() + ":");
                    if (environment.isStandalone()) {
                        location.append(context.securePort);
                        description = resources.messages().enableSSLResultsSuccessStandalone(location.toString());
                    } else {
                        location.append(asString(model, SECURE_PORT));
                        description = resources.messages().enableSSLResultsSuccessDomain(location.toString());
                    }
                    // extracts the url search path, so the url shows the view the user is located
                    String urlSuffix = window.location.getHref();
                    urlSuffix = urlSuffix.substring(urlSuffix.indexOf("//") + 2);
                    urlSuffix = urlSuffix.substring(urlSuffix.indexOf("/"));
                    location.append(urlSuffix);
                    wizard.showSuccess(resources.constants().success(), description, label, // reloads the server/host if user clicks on the success action
                    context1 -> presenter.reloadServer(host, location.toString()), // reload only the view and displays a success message
                    context2 -> {
                        presenter.reloadView();
                        MessageEvent.fire(eventBus, Message.success(resources.messages().enableSSLSuccess()));
                    }, true);
                }
            }

            @Override
            public void onError(FlowContext context, Throwable exception) {
                wizard.showError(resources.constants().failed(), resources.messages().enableSSLResultsError(), exception.getMessage(), false);
            }
        });
    });
    Wizard<EnableSSLContext, EnableSSLState> wizard = wb.build();
    wizard.show();
}
Also used : AddressTemplate(org.jboss.hal.meta.AddressTemplate) ModelNode(org.jboss.hal.dmr.ModelNode) Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) StatementContext(org.jboss.hal.meta.StatementContext) MessageEvent(org.jboss.hal.spi.MessageEvent) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) AbstractConfiguration(org.jboss.hal.client.shared.sslwizard.AbstractConfiguration) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) Task(org.jboss.hal.flow.Task) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) Constants(org.jboss.hal.resources.Constants) Map(java.util.Map) Message(org.jboss.hal.spi.Message) Names(org.jboss.hal.resources.Names) Operation(org.jboss.hal.dmr.Operation) Wizard(org.jboss.hal.ballroom.wizard.Wizard) EventBus(com.google.web.bindery.event.shared.EventBus) DomGlobal.window(elemental2.dom.DomGlobal.window) Composite(org.jboss.hal.dmr.Composite) List(java.util.List) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Resources(org.jboss.hal.resources.Resources) Flow.series(org.jboss.hal.flow.Flow.series) Footer(org.jboss.hal.spi.Footer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Host(org.jboss.hal.core.runtime.host.Host) Task(org.jboss.hal.flow.Task) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) ArrayList(java.util.ArrayList) Operation(org.jboss.hal.dmr.Operation) FlowContext(org.jboss.hal.flow.FlowContext) Composite(org.jboss.hal.dmr.Composite) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Constants(org.jboss.hal.resources.Constants) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) ModelNode(org.jboss.hal.dmr.ModelNode) Wizard(org.jboss.hal.ballroom.wizard.Wizard)

Example 3 with Message

use of org.jboss.hal.spi.Message in project console by hal.

the class ComplexAttributeOperations method remove.

/**
 * Undefines the complex attribute. After the attribute has been undefined a standard success message is fired and the
 * specified callback is executed.
 *
 * @param complexAttribute the name of the complex attribute
 * @param type the human readable name of the complex attribute
 * @param address the fq address for the operation
 * @param callback the callback executed after the complex attribute has been undefined
 */
@JsIgnore
public void remove(String complexAttribute, String type, ResourceAddress address, Callback callback) {
    Operation operation = new Operation.Builder(address, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, complexAttribute).build();
    SafeHtml question = resources.messages().removeSingletonConfirmationQuestion();
    DialogFactory.showConfirmation(resources.messages().removeConfirmationTitle(type), question, () -> dispatcher.execute(operation, result -> {
        MessageEvent.fire(eventBus, Message.success(resources.messages().removeSingletonResourceSuccess(type)));
        callback.execute();
    }));
}
Also used : ModelNode(org.jboss.hal.dmr.ModelNode) Iterables(com.google.common.collect.Iterables) Provider(javax.inject.Provider) StatementContext(org.jboss.hal.meta.StatementContext) MessageEvent(org.jboss.hal.spi.MessageEvent) SuccessfulMetadataCallback(org.jboss.hal.meta.processing.SuccessfulMetadataCallback) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Inject(javax.inject.Inject) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) Map(java.util.Map) Message(org.jboss.hal.spi.Message) Metadata(org.jboss.hal.meta.Metadata) Nullable(javax.annotation.Nullable) Collectors.toSet(java.util.stream.Collectors.toSet) CompositeResult(org.jboss.hal.dmr.CompositeResult) Operation(org.jboss.hal.dmr.Operation) Collections.emptyList(java.util.Collections.emptyList) Set(java.util.Set) EventBus(com.google.web.bindery.event.shared.EventBus) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) Composite(org.jboss.hal.dmr.Composite) JsIgnore(jsinterop.annotations.JsIgnore) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) FormItem(org.jboss.hal.ballroom.form.FormItem) MetadataProcessor(org.jboss.hal.meta.processing.MetadataProcessor) Callback(org.jboss.hal.spi.Callback) StreamSupport.stream(java.util.stream.StreamSupport.stream) Resources(org.jboss.hal.resources.Resources) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Footer(org.jboss.hal.spi.Footer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Form(org.jboss.hal.ballroom.form.Form) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Operation(org.jboss.hal.dmr.Operation) JsIgnore(jsinterop.annotations.JsIgnore)

Example 4 with Message

use of org.jboss.hal.spi.Message in project console by hal.

the class AssignmentColumn method columnActionHandler.

private ColumnActionHandler<Assignment> columnActionHandler(Role role, boolean include) {
    return column -> {
        Principal principal = findPrincipal(getFinder().getContext().getPath());
        if (principal != null) {
            series(new FlowContext(progress.get()), new CheckRoleMapping(dispatcher, role), new AddRoleMapping(dispatcher, role, status -> status == 404), new AddAssignment(dispatcher, role, principal, include)).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {

                @Override
                public void onSuccess(FlowContext context) {
                    String type = resources.constants().role();
                    SafeHtml message = include ? resources.messages().assignmentIncludeSuccess(type, role.getName()) : resources.messages().assignmentExcludeSuccess(type, role.getName());
                    MessageEvent.fire(eventBus, Message.success(message));
                    accessControl.reload(() -> {
                        refresh(RefreshMode.RESTORE_SELECTION);
                        if (isCurrentUser(principal)) {
                            eventBus.fireEvent(new UserChangedEvent());
                        }
                    });
                }
            });
        }
    };
}
Also used : ColumnActionHandler(org.jboss.hal.core.finder.ColumnActionHandler) Provider(javax.inject.Provider) AsyncColumn(org.jboss.hal.spi.AsyncColumn) ItemActionFactory(org.jboss.hal.core.finder.ItemActionFactory) 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) ItemDisplay(org.jboss.hal.core.finder.ItemDisplay) FinderSegment(org.jboss.hal.core.finder.FinderSegment) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) UserChangedEvent(org.jboss.hal.config.UserChangedEvent) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Inject(javax.inject.Inject) AddRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping) Progress(org.jboss.hal.flow.Progress) HTMLElement(elemental2.dom.HTMLElement) Message(org.jboss.hal.spi.Message) FinderColumn(org.jboss.hal.core.finder.FinderColumn) User(org.jboss.hal.config.User) Collectors.toSet(java.util.stream.Collectors.toSet) CheckRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.CheckRoleMapping) Operation(org.jboss.hal.dmr.Operation) Ids(org.jboss.hal.resources.Ids) INCLUDE_TEMPLATE(org.jboss.hal.client.accesscontrol.AddressTemplates.INCLUDE_TEMPLATE) EXCLUDE_TEMPLATE(org.jboss.hal.client.accesscontrol.AddressTemplates.EXCLUDE_TEMPLATE) REMOVE(org.jboss.hal.dmr.ModelDescriptionConstants.REMOVE) Set(java.util.Set) EventBus(com.google.web.bindery.event.shared.EventBus) AddAssignment(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddAssignment) FinderPath(org.jboss.hal.core.finder.FinderPath) Sets(com.google.common.collect.Sets) List(java.util.List) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Collectors.toList(java.util.stream.Collectors.toList) Resources(org.jboss.hal.resources.Resources) Flow.series(org.jboss.hal.flow.Flow.series) Role(org.jboss.hal.config.Role) Finder(org.jboss.hal.core.finder.Finder) Footer(org.jboss.hal.spi.Footer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Elements.span(org.jboss.gwt.elemento.core.Elements.span) CSS.fontAwesome(org.jboss.hal.resources.CSS.fontAwesome) UserChangedEvent(org.jboss.hal.config.UserChangedEvent) AddRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping) AddAssignment(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddAssignment) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) FlowContext(org.jboss.hal.flow.FlowContext) CheckRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.CheckRoleMapping)

Example 5 with Message

use of org.jboss.hal.spi.Message 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

Message (org.jboss.hal.spi.Message)10 EventBus (com.google.web.bindery.event.shared.EventBus)8 Provider (javax.inject.Provider)8 Operation (org.jboss.hal.dmr.Operation)8 ResourceAddress (org.jboss.hal.dmr.ResourceAddress)8 Dispatcher (org.jboss.hal.dmr.dispatch.Dispatcher)8 Progress (org.jboss.hal.flow.Progress)8 Resources (org.jboss.hal.resources.Resources)8 Footer (org.jboss.hal.spi.Footer)8 MessageEvent (org.jboss.hal.spi.MessageEvent)8 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)7 Inject (javax.inject.Inject)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Composite (org.jboss.hal.dmr.Composite)6 ModelDescriptionConstants (org.jboss.hal.dmr.ModelDescriptionConstants)6 ModelNode (org.jboss.hal.dmr.ModelNode)6 Flow.series (org.jboss.hal.flow.Flow.series)6 FlowContext (org.jboss.hal.flow.FlowContext)6 AddressTemplate (org.jboss.hal.meta.AddressTemplate)6