Search in sources :

Example 1 with VALUE

use of org.jboss.hal.dmr.ModelDescriptionConstants.VALUE in project console by hal.

the class HeaderView method updateBreadcrumb.

@Override
public void updateBreadcrumb(ModelBrowserPath path) {
    clearBreadcrumb();
    if (path == null || path.isEmpty()) {
        // deselection
        breadcrumb.insertBefore(li().textContent(resources.constants().nothingSelected()).element(), breadcrumbToolsItem);
    } else {
        ModelBrowser modelBrowser = path.getModelBrowser();
        for (Iterator<Segment[]> iterator = path.iterator(); iterator.hasNext(); ) {
            Segment[] segments = iterator.next();
            Segment key = segments[0];
            Segment value = segments[1];
            boolean link = value != ModelBrowserPath.WILDCARD && iterator.hasNext();
            HTMLElement valueContainer;
            HTMLElement li = li().add(span().css(CSS.key).add(a().css(clickable).on(click, event -> modelBrowser.select(key.id, true)).textContent(key.text))).add(span().css(arrow).innerHtml(SafeHtmlUtils.fromSafeConstant("&#8658;"))).add(valueContainer = span().css(CSS.value).element()).element();
            if (link) {
                valueContainer.appendChild(valueContainer = a().css(clickable).on(click, event -> modelBrowser.select(value.id, true)).element());
            }
            valueContainer.textContent = value.text;
            breadcrumb.insertBefore(li, breadcrumbToolsItem);
        }
    }
}
Also used : Environment(org.jboss.hal.config.Environment) Endpoints(org.jboss.hal.config.Endpoints) LoggerFactory(org.slf4j.LoggerFactory) Tooltip(org.jboss.hal.ballroom.Tooltip) FinderSegment(org.jboss.hal.core.finder.FinderSegment) HtmlContentBuilder(org.jboss.gwt.elemento.core.builder.HtmlContentBuilder) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) VALUE(org.jboss.hal.dmr.ModelDescriptionConstants.VALUE) HTMLElement(elemental2.dom.HTMLElement) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Message(org.jboss.hal.spi.Message) HalViewImpl(org.jboss.hal.core.mvp.HalViewImpl) User(org.jboss.hal.config.User) Elements.i(org.jboss.gwt.elemento.core.Elements.i) Places(org.jboss.hal.core.mvp.Places) Names(org.jboss.hal.resources.Names) Settings(org.jboss.hal.config.Settings) Set(java.util.Set) CSS(org.jboss.hal.resources.CSS) EventType.click(org.jboss.gwt.elemento.core.EventType.click) FinderPath(org.jboss.hal.core.finder.FinderPath) MAX_BREADCRUMB_VALUE_LENGTH(org.jboss.hal.client.skeleton.HeaderPresenter.MAX_BREADCRUMB_VALUE_LENGTH) Collectors.joining(java.util.stream.Collectors.joining) Roles(org.jboss.hal.config.Roles) List(java.util.List) UIConstants(org.jboss.hal.resources.UIConstants) CSS.nav(org.jboss.hal.resources.CSS.nav) StreamSupport.stream(java.util.stream.StreamSupport.stream) Role(org.jboss.hal.config.Role) Segment(org.jboss.hal.core.modelbrowser.ModelBrowserPath.Segment) Element(elemental2.dom.Element) Strings.abbreviateMiddle(org.jboss.hal.resources.Strings.abbreviateMiddle) FontAwesomeSize.large(org.jboss.hal.resources.FontAwesomeSize.large) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) HandlerRegistration(com.google.web.bindery.event.shared.HandlerRegistration) ModelBrowser(org.jboss.hal.core.modelbrowser.ModelBrowser) SafeHtmlUtils(com.google.gwt.safehtml.shared.SafeHtmlUtils) AccessControl(org.jboss.hal.core.accesscontrol.AccessControl) Logger(org.slf4j.Logger) RBAC(org.jboss.hal.config.AccessControlProvider.RBAC) Iterator(java.util.Iterator) Ids(org.jboss.hal.resources.Ids) PlaceRequest(com.gwtplatform.mvp.shared.proxy.PlaceRequest) DropdownItem(org.jboss.hal.core.finder.FinderSegment.DropdownItem) ModelBrowserPath(org.jboss.hal.core.modelbrowser.ModelBrowserPath) FinderContext(org.jboss.hal.core.finder.FinderContext) HTMLLIElement(elemental2.dom.HTMLLIElement) Elements.nav(org.jboss.gwt.elemento.core.Elements.nav) NameTokens(org.jboss.hal.meta.token.NameTokens) Resources(org.jboss.hal.resources.Resources) EventType.bind(org.jboss.gwt.elemento.core.EventType.bind) RUN_AS(org.jboss.hal.config.Settings.Key.RUN_AS) Elements(org.jboss.gwt.elemento.core.Elements) ModelBrowser(org.jboss.hal.core.modelbrowser.ModelBrowser) HTMLElement(elemental2.dom.HTMLElement) FinderSegment(org.jboss.hal.core.finder.FinderSegment) Segment(org.jboss.hal.core.modelbrowser.ModelBrowserPath.Segment)

Example 2 with VALUE

use of org.jboss.hal.dmr.ModelDescriptionConstants.VALUE in project console by hal.

the class OperationFactory method fromChangeSet.

/**
 * Turns a change-set into a composite operation containing
 * {@linkplain org.jboss.hal.dmr.ModelDescriptionConstants#WRITE_ATTRIBUTE_OPERATION write-attribute} and
 * {@linkplain org.jboss.hal.dmr.ModelDescriptionConstants#UNDEFINE_ATTRIBUTE_OPERATION undefine-attribute} operations.
 * <p>
 * The composite operation will contain {@linkplain org.jboss.hal.dmr.ModelDescriptionConstants#UNDEFINE_ATTRIBUTE_OPERATION
 * undefine-attribute} operations which reflect the alternative attributes as defined in the specified metadata.
 *
 * @param address the fq address used for the operations
 * @param changeSet the changed values
 * @param metadata the metadata which should contain the attribute definitions of the change-set
 */
public Composite fromChangeSet(ResourceAddress address, Map<String, Object> changeSet, Metadata metadata) {
    // TODO Is it safe to always use ATTRIBUTES as path when calling ResourceDescription methods?
    Map<String, Operation> operations = new HashMap<>();
    HashMap<String, Object> localChanges = new HashMap<>(changeSet);
    ResourceDescription resourceDescription = metadata.getDescription();
    // look for alternatives
    Set<String> conflicts = new HashSet<>();
    Map<String, List<String>> allAlternatives = localChanges.keySet().stream().filter(name -> {
        Object value = changeSet.get(name);
        return !isNullOrEmpty(value);
    }).collect(toMap(identity(), name -> resourceDescription.findAlternatives(ATTRIBUTES, name)));
    allAlternatives.forEach((attribute, alternatives) -> {
        logger.debug("Alternatives resolution for {} -> [{}]", attribute, String.join(", ", alternatives));
        HashSet<String> intersection = new HashSet<>(alternatives);
        intersection.retainAll(changeSet.keySet());
        if (intersection.isEmpty()) {
            // the easy part: no conflicts
            alternatives.forEach(alternative -> {
                boolean alternativeDoesntExist = resourceDescription.findAttribute(ATTRIBUTES, alternative) == null;
                if (resourceDescription.isDeprecated(ATTRIBUTES, alternative) || alternativeDoesntExist) {
                    logger.debug("Skip undefine operations for deprecated or non-existent alternative {}", alternative);
                } else {
                    logger.debug("Add undefine operations for alternative {}", alternative);
                    operations.putIfAbsent(alternative, undefineAttribute(address, alternative));
                    List<String> requires = resourceDescription.findRequires(ATTRIBUTES, alternative);
                    if (!requires.isEmpty()) {
                        logger.debug("Add undefine operations for attributes which require {}: [{}]", alternative, String.join(", ", requires));
                        requires.forEach(r -> operations.putIfAbsent(r, undefineAttribute(address, r)));
                    }
                }
            });
        } else {
            // possible conflicts: one or more alternatives are also in the change-set
            // just collect for now and resolve later
            conflicts.add(attribute);
            conflicts.addAll(intersection);
            logger.debug("Record conflict {} <-> [{}]", attribute, String.join(", ", intersection));
        }
        alternatives.forEach(localChanges::remove);
    });
    if (!conflicts.isEmpty()) {
        // try to resolve conflicts: only one of the conflicting attributes must have a value other than
        // null, empty or default
        logger.debug("Try to resolve conflicts between alternatives [{}]", String.join(", ", conflicts));
        Map<Boolean, List<String>> resolution = conflicts.stream().collect(groupingBy(conflict -> {
            Object value = changeSet.get(conflict);
            return isNullOrEmpty(value) || resourceDescription.isDefaultValue(ATTRIBUTES, conflict, value);
        }));
        List<String> undefine = resolution.getOrDefault(true, Collections.emptyList());
        List<String> write = resolution.getOrDefault(false, Collections.emptyList());
        if (write.size() > 1) {
            logger.error("More than one conflicting alternative attribute which is not null, empty or default: [{}]. This should have been caught by a form validation. Adding the write operations anyway to get an appropriate error message from the server.", String.join(", ", write));
        }
        logger.debug("Add undefine operations for [{}], write operation for [{}]", String.join(", ", undefine), String.join(", ", write));
        undefine.forEach(u -> {
            operations.putIfAbsent(u, undefineAttribute(address, u));
            localChanges.remove(u);
            // process requires of the current undefine attribute
            List<String> requires = resourceDescription.findRequires(ATTRIBUTES, u);
            requires.forEach(ur -> {
                operations.putIfAbsent(ur, undefineAttribute(address, ur));
                localChanges.remove(ur);
            });
        });
        write.forEach(w -> {
            operations.putIfAbsent(w, writeAttribute(address, w, changeSet.get(w), resourceDescription, true));
            localChanges.remove(w);
            List<String> writeAlternatives = resourceDescription.findAlternatives(ATTRIBUTES, w);
            // process alternatives of the current write attribute
            writeAlternatives.forEach(wa -> {
                operations.putIfAbsent(wa, undefineAttribute(address, wa));
                localChanges.remove(wa);
            });
        });
    }
    // handle the remaining attributes
    logger.debug("Process remaining attributes [{}]", String.join(", ", localChanges.keySet()));
    localChanges.forEach((name, value) -> operations.putIfAbsent(name, writeAttribute(address, name, value, resourceDescription, false)));
    return new Composite(operations.values().stream().filter(Objects::nonNull).collect(toList()));
}
Also used : ModelNode(org.jboss.hal.dmr.ModelNode) DEFAULT(org.jboss.hal.dmr.ModelDescriptionConstants.DEFAULT) TYPE(org.jboss.hal.dmr.ModelDescriptionConstants.TYPE) VALUE_TYPE(org.jboss.hal.dmr.ModelDescriptionConstants.VALUE_TYPE) LoggerFactory(org.slf4j.LoggerFactory) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) HashMap(java.util.HashMap) Function(java.util.function.Function) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ModelType(org.jboss.hal.dmr.ModelType) HashSet(java.util.HashSet) BigDecimal(java.math.BigDecimal) Property(org.jboss.hal.dmr.Property) ResourceDescription(org.jboss.hal.meta.description.ResourceDescription) Strings(com.google.common.base.Strings) Collectors.toMap(java.util.stream.Collectors.toMap) VALUE(org.jboss.hal.dmr.ModelDescriptionConstants.VALUE) Map(java.util.Map) Expression(org.jboss.hal.core.expression.Expression) NAME(org.jboss.hal.dmr.ModelDescriptionConstants.NAME) UNDEFINE_ATTRIBUTE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.UNDEFINE_ATTRIBUTE_OPERATION) BigInteger(java.math.BigInteger) EXPRESSIONS_ALLOWED(org.jboss.hal.dmr.ModelDescriptionConstants.EXPRESSIONS_ALLOWED) Metadata(org.jboss.hal.meta.Metadata) Logger(org.slf4j.Logger) ACCESS_TYPE(org.jboss.hal.dmr.ModelDescriptionConstants.ACCESS_TYPE) READ_ONLY(org.jboss.hal.dmr.ModelDescriptionConstants.READ_ONLY) Operation(org.jboss.hal.dmr.Operation) ModelNodeHelper.failSafeList(org.jboss.hal.dmr.ModelNodeHelper.failSafeList) ALTERNATIVES(org.jboss.hal.dmr.ModelDescriptionConstants.ALTERNATIVES) Set(java.util.Set) WRITE_ATTRIBUTE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION) NILLABLE(org.jboss.hal.dmr.ModelDescriptionConstants.NILLABLE) Objects(java.util.Objects) Composite(org.jboss.hal.dmr.Composite) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ATTRIBUTES(org.jboss.hal.dmr.ModelDescriptionConstants.ATTRIBUTES) Function.identity(java.util.function.Function.identity) Collections(java.util.Collections) REQUIRES(org.jboss.hal.dmr.ModelDescriptionConstants.REQUIRES) Composite(org.jboss.hal.dmr.Composite) HashMap(java.util.HashMap) Operation(org.jboss.hal.dmr.Operation) ResourceDescription(org.jboss.hal.meta.description.ResourceDescription) Objects(java.util.Objects) ArrayList(java.util.ArrayList) ModelNodeHelper.failSafeList(org.jboss.hal.dmr.ModelNodeHelper.failSafeList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) HashSet(java.util.HashSet)

Example 3 with VALUE

use of org.jboss.hal.dmr.ModelDescriptionConstants.VALUE in project console by hal.

the class StandaloneServerPresenter 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, there are differente attributes for
        // standalone and domain mode.
        Task<FlowContext> loadHttpInterface = flowContext -> {
            Operation readHttpInterface = new Operation.Builder(httpAddress, READ_RESOURCE_OPERATION).build();
            return dispatcher.execute(readHttpInterface).doOnSuccess(value -> {
                if (value.hasDefined(SOCKET_BINDING)) {
                    // standalone mode uses a socket-binding for port
                    // store the socket-binding name in the flow context and on a later call
                    // read the socket-binding-group=<s-b-g>/socket-binding=<http-binding> to
                    // retrieve the port number
                    flowContext.set(SOCKET_BINDING, value.get(SOCKET_BINDING).asString());
                }
            }).toCompletable();
        };
        tasks.add(loadHttpInterface);
        // if standalone mode, read the socket-binding-group=<s-b-g>/socket-binding=<http-binding>
        // to retrieve the port number
        Task<FlowContext> readHttpPortTask = flowContext -> {
            Operation op = new Operation.Builder(ResourceAddress.root(), READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, SOCKET_BINDING_GROUP).build();
            return dispatcher.execute(op).doOnSuccess(result -> {
                String sbg = result.asList().get(0).asString();
                String httpBinding = flowContext.get(SOCKET_BINDING);
                ResourceAddress address = SOCKET_BINDING_GROUP_TEMPLATE.resolve(statementContext, sbg, httpBinding);
                Operation readPort = new Operation.Builder(address, READ_ATTRIBUTE_OPERATION).param(NAME, PORT).param(RESOLVE_EXPRESSIONS, true).build();
                dispatcher.execute(readPort, portResult -> flowContext.set(PORT, portResult.asString()));
            }).toCompletable();
        };
        tasks.add(readHttpPortTask);
        // as part of the disable ssl task, undefine the secure-socket-binding
        // the attribute only exists in standalone mode
        Task<FlowContext> undefSslTask = flowContext -> {
            Operation op = new Operation.Builder(httpAddress, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, SECURE_SOCKET_BINDING).build();
            return dispatcher.execute(op).toCompletable();
        };
        tasks.add(undefSslTask);
        // 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;
                    reloadServer(null, location);
                } else {
                    reload();
                    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 : Dialog(org.jboss.hal.ballroom.dialog.Dialog) INCLUDE_RUNTIME(org.jboss.hal.dmr.ModelDescriptionConstants.INCLUDE_RUNTIME) 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) TopologyTasks.reloadBlocking(org.jboss.hal.core.runtime.TopologyTasks.reloadBlocking) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) SOCKET_BINDING(org.jboss.hal.dmr.ModelDescriptionConstants.SOCKET_BINDING) VALUE(org.jboss.hal.dmr.ModelDescriptionConstants.VALUE) HTMLElement(elemental2.dom.HTMLElement) Map(java.util.Map) Message(org.jboss.hal.spi.Message) KEY_MANAGER(org.jboss.hal.dmr.ModelDescriptionConstants.KEY_MANAGER) NAME(org.jboss.hal.dmr.ModelDescriptionConstants.NAME) UNDEFINE_ATTRIBUTE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.UNDEFINE_ATTRIBUTE_OPERATION) READ_RESOURCE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.READ_RESOURCE_OPERATION) SOCKET_BINDING_GROUP(org.jboss.hal.dmr.ModelDescriptionConstants.SOCKET_BINDING_GROUP) Server(org.jboss.hal.core.runtime.server.Server) 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) PORT(org.jboss.hal.dmr.ModelDescriptionConstants.PORT) SOCKET_BINDING_GROUP_TEMPLATE(org.jboss.hal.client.shared.sslwizard.AbstractConfiguration.SOCKET_BINDING_GROUP_TEMPLATE) CrudOperations(org.jboss.hal.core.CrudOperations) RESOLVE_EXPRESSIONS(org.jboss.hal.dmr.ModelDescriptionConstants.RESOLVE_EXPRESSIONS) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) INDEX(org.jboss.hal.dmr.ModelDescriptionConstants.INDEX) FinderPath(org.jboss.hal.core.finder.FinderPath) SECURE_SOCKET_BINDING(org.jboss.hal.dmr.ModelDescriptionConstants.SECURE_SOCKET_BINDING) FORM(org.jboss.hal.resources.Ids.FORM) Collectors(java.util.stream.Collectors) List(java.util.List) OperationFactory(org.jboss.hal.core.OperationFactory) PATH(org.jboss.hal.dmr.ModelDescriptionConstants.PATH) RESULT(org.jboss.hal.dmr.ModelDescriptionConstants.RESULT) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem) 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) ATTRIBUTES_ONLY(org.jboss.hal.dmr.ModelDescriptionConstants.ATTRIBUTES_ONLY) MessageEvent(org.jboss.hal.spi.MessageEvent) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) CHILD_TYPE(org.jboss.hal.dmr.ModelDescriptionConstants.CHILD_TYPE) KEY_STORE(org.jboss.hal.dmr.ModelDescriptionConstants.KEY_STORE) HashMap(java.util.HashMap) CONSTANT_HEADERS(org.jboss.hal.dmr.ModelDescriptionConstants.CONSTANT_HEADERS) 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) RELOAD(org.jboss.hal.dmr.ModelDescriptionConstants.RELOAD) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) Constants(org.jboss.hal.resources.Constants) TRUST_MANAGER(org.jboss.hal.dmr.ModelDescriptionConstants.TRUST_MANAGER) Requires(org.jboss.hal.spi.Requires) CompositeResult(org.jboss.hal.dmr.CompositeResult) ProxyCodeSplit(com.gwtplatform.mvp.client.annotations.ProxyCodeSplit) EnableSSLWizard(org.jboss.hal.client.shared.sslwizard.EnableSSLWizard) SSL_CONTEXT(org.jboss.hal.dmr.ModelDescriptionConstants.SSL_CONTEXT) 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) READ_ATTRIBUTE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION) WRITE_ATTRIBUTE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) DomGlobal.window(elemental2.dom.DomGlobal.window) Composite(org.jboss.hal.dmr.Composite) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) HEADERS(org.jboss.hal.dmr.ModelDescriptionConstants.HEADERS) NameTokens(org.jboss.hal.meta.token.NameTokens) 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) READ_CHILDREN_NAMES_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.READ_CHILDREN_NAMES_OPERATION) SERVER_SSL_CONTEXT(org.jboss.hal.dmr.ModelDescriptionConstants.SERVER_SSL_CONTEXT) START_MODE(org.jboss.hal.dmr.ModelDescriptionConstants.START_MODE) Host(org.jboss.hal.core.runtime.host.Host) Form(org.jboss.hal.ballroom.form.Form) ConstantHeadersPresenter(org.jboss.hal.client.runtime.managementinterface.ConstantHeadersPresenter) Task(org.jboss.hal.flow.Task) HTMLElement(elemental2.dom.HTMLElement) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Constants(org.jboss.hal.resources.Constants) Operation(org.jboss.hal.dmr.Operation) FlowContext(org.jboss.hal.flow.FlowContext) List(java.util.List) ArrayList(java.util.ArrayList) ModelNode(org.jboss.hal.dmr.ModelNode) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem)

Example 4 with VALUE

use of org.jboss.hal.dmr.ModelDescriptionConstants.VALUE in project console by hal.

the class RemotingView method updateGenericConnector.

@SuppressWarnings("HardCodedStringLiteral")
private void updateGenericConnector(NamedNode node, Form<NamedNode> form, Form<ModelNode> securityForm, Form<ModelNode> policyForm) {
    FormItem<Object> properties = form.getFormItem(PROPERTY);
    FormItem<Object> securityProperties = securityForm.getFormItem(PROPERTY);
    if (node != null) {
        Map<String, String> p = failSafePropertyList(node, PROPERTY).stream().collect(toMap(Property::getName, property -> property.getValue().get(VALUE).asString()));
        ModelNode security = failSafeGet(node, "security/sasl");
        Map<String, String> sp = failSafePropertyList(node, "security/sasl/" + PROPERTY).stream().collect(toMap(Property::getName, property -> property.getValue().get(VALUE).asString()));
        ModelNode policy = failSafeGet(node, "security/sasl/sasl-policy/policy");
        form.view(node);
        properties.setValue(p);
        securityForm.view(security);
        securityProperties.setValue(sp);
        policyForm.view(policy);
    } else {
        form.clear();
        properties.clearValue();
        securityForm.clear();
        securityProperties.clearValue();
        policyForm.clear();
    }
}
Also used : ModelNode(org.jboss.hal.dmr.ModelNode) MbuiViewImpl(org.jboss.hal.core.mbui.MbuiViewImpl) Tabs(org.jboss.hal.ballroom.Tabs) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Property(org.jboss.hal.dmr.Property) PROPERTY(org.jboss.hal.dmr.ModelDescriptionConstants.PROPERTY) Collectors.toMap(java.util.stream.Collectors.toMap) MbuiElement(org.jboss.hal.spi.MbuiElement) VALUE(org.jboss.hal.dmr.ModelDescriptionConstants.VALUE) Map(java.util.Map) READ_RESOURCE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.READ_RESOURCE_OPERATION) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) Nullable(javax.annotation.Nullable) ModelNodeHelper.asNamedNodes(org.jboss.hal.dmr.ModelNodeHelper.asNamedNodes) Table(org.jboss.hal.ballroom.table.Table) Operation(org.jboss.hal.dmr.Operation) AddressTemplates(org.jboss.hal.client.configuration.subsystem.remoting.AddressTemplates) Ids(org.jboss.hal.resources.Ids) VerticalNavigation(org.jboss.hal.ballroom.VerticalNavigation) ModelNodeHelper.failSafeGet(org.jboss.hal.dmr.ModelNodeHelper.failSafeGet) ModelNodeHelper.failSafePropertyList(org.jboss.hal.dmr.ModelNodeHelper.failSafePropertyList) FormItem(org.jboss.hal.ballroom.form.FormItem) PropertiesItem(org.jboss.hal.ballroom.form.PropertiesItem) MbuiContext(org.jboss.hal.core.mbui.MbuiContext) PostConstruct(javax.annotation.PostConstruct) MbuiView(org.jboss.hal.spi.MbuiView) NamedNode(org.jboss.hal.dmr.NamedNode) Form(org.jboss.hal.ballroom.form.Form) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 5 with VALUE

use of org.jboss.hal.dmr.ModelDescriptionConstants.VALUE 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)

Aggregations

VALUE (org.jboss.hal.dmr.ModelDescriptionConstants.VALUE)7 List (java.util.List)6 Map (java.util.Map)6 Ids (org.jboss.hal.resources.Ids)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 ModelNode (org.jboss.hal.dmr.ModelNode)5 ResourceAddress (org.jboss.hal.dmr.ResourceAddress)5 Names (org.jboss.hal.resources.Names)5 Strings (com.google.common.base.Strings)4 HTMLElement (elemental2.dom.HTMLElement)4 Inject (javax.inject.Inject)4 Environment (org.jboss.hal.config.Environment)4 FinderPath (org.jboss.hal.core.finder.FinderPath)4 Operation (org.jboss.hal.dmr.Operation)4 Metadata (org.jboss.hal.meta.Metadata)4 NameTokens (org.jboss.hal.meta.token.NameTokens)4 Resources (org.jboss.hal.resources.Resources)4 Message (org.jboss.hal.spi.Message)4 Set (java.util.Set)3