Search in sources :

Example 16 with Property

use of org.jboss.hal.dmr.Property in project console by hal.

the class ThreadPoolPreview method update.

@Override
public void update(SubsystemMetadata item) {
    ResourceAddress address = EJB3_SUBSYSTEM_TEMPLATE.resolve(statementContext);
    Operation operation = new Operation.Builder(address, READ_RESOURCE_OPERATION).param(INCLUDE_RUNTIME, true).param(RECURSIVE, true).build();
    dispatcher.execute(operation, result -> {
        List<Property> properties = failSafePropertyList(result, THREAD_POOL);
        if (!properties.isEmpty()) {
            ModelNode threadPool = properties.get(0).getValue();
            long active = threadPool.get(ACTIVE_COUNT).asLong();
            long completed = threadPool.get(COMPLETED_TASK_COUNT).asLong();
            long queue = threadPool.get(QUEUE_SIZE).asLong();
            long rejected = threadPool.get(REJECTED_COUNT).asLong();
            tasks.update(ImmutableMap.of(Ids.TASKS_ACTIVE, active, Ids.TASKS_COMPLETED, completed, Ids.TASKS_QUEUE, queue, Ids.TASKS_REJECTED, rejected));
            int currentThreads = threadPool.get(CURRENT_THREAD_COUNT).asInt();
            int maxThreads = threadPool.get(MAX_THREADS).asInt();
            threads.update(currentThreads, maxThreads);
        }
    });
}
Also used : ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Operation(org.jboss.hal.dmr.Operation) ModelNode(org.jboss.hal.dmr.ModelNode) Property(org.jboss.hal.dmr.Property)

Example 17 with Property

use of org.jboss.hal.dmr.Property in project console by hal.

the class ReadAuthentication method call.

@Override
public Completable call(FlowContext context) {
    logger.debug("Read authentication");
    ResourceAddress address = CORE_SERVICE_TEMPLATE.resolve(statementContext);
    Operation opAuthorization = new Operation.Builder(address, READ_CHILDREN_RESOURCES_OPERATION).param(CHILD_TYPE, ACCESS).param(INCLUDE_RUNTIME, true).param(RECURSIVE_DEPTH, 1).build();
    Operation opWhoami = new Operation.Builder(ResourceAddress.root(), WHOAMI).param(VERBOSE, true).build();
    return dispatcher.execute(new Composite(opAuthorization, opWhoami)).doOnSuccess((CompositeResult compositeResult) -> {
        ModelNode result = compositeResult.step(0).get(RESULT);
        if (result.hasDefined(AUTHORIZATION)) {
            result = result.get(AUTHORIZATION);
            // provider
            AccessControlProvider accessControlProvider = asEnumValue(result, PROVIDER, AccessControlProvider::valueOf, SIMPLE);
            environment.setAccessControlProvider(accessControlProvider);
            // standard roles
            if (result.hasDefined(STANDARD_ROLE_NAMES)) {
                result.get(STANDARD_ROLE_NAMES).asList().stream().map(node -> new Role(node.asString())).forEach(role -> environment.getRoles().add(role));
            }
            // scoped roles
            if (!environment.isStandalone()) {
                if (result.hasDefined(HOST_SCOPED_ROLE)) {
                    result.get(HOST_SCOPED_ROLE).asPropertyList().stream().map(property -> scopedRole(property, Role.Type.HOST, HOSTS)).forEach(role -> environment.getRoles().add(role));
                }
                if (result.hasDefined(SERVER_GROUP_SCOPED_ROLE)) {
                    result.get(SERVER_GROUP_SCOPED_ROLE).asPropertyList().stream().map(property -> scopedRole(property, Role.Type.SERVER_GROUP, SERVER_GROUPS)).forEach(role -> environment.getRoles().add(role));
                }
            }
        } else {
            logger.warn("Unable to read {} (insufficient rights?). Use :whoami values as fallback.", CORE_SERVICE_TEMPLATE.append("access=authorization"));
            ModelNode resultWhoami = compositeResult.step(1).get(RESULT);
            environment.setAccessControlProvider(RBAC);
            environment.getRoles().clear();
            if (resultWhoami.hasDefined(ROLES)) {
                resultWhoami.get(ROLES).asList().stream().map(node -> new Role(node.asString())).forEach(role -> environment.getRoles().add(role));
            } else if (resultWhoami.hasDefined(MAPPED_ROLES)) {
                resultWhoami.get(MAPPED_ROLES).asList().stream().map(node -> new Role(node.asString())).forEach(role -> environment.getRoles().add(role));
            }
        }
    }).onErrorResumeNext(throwable -> {
        if (throwable instanceof DispatchFailure) {
            logger.error("Unable to read {}. Use :whoami values as fallback.", CORE_SERVICE_TEMPLATE);
            return Single.just(new CompositeResult(new ModelNode()));
        } else {
            return Single.error(throwable);
        }
    }).toCompletable();
}
Also used : ModelNode(org.jboss.hal.dmr.ModelNode) Completable(rx.Completable) Environment(org.jboss.hal.config.Environment) StatementContext(org.jboss.hal.meta.StatementContext) AccessControlProvider(org.jboss.hal.config.AccessControlProvider) LoggerFactory(org.slf4j.LoggerFactory) DispatchFailure(org.jboss.hal.dmr.dispatch.DispatchFailure) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) FlowContext(org.jboss.hal.flow.FlowContext) ModelNodeHelper.asEnumValue(org.jboss.hal.dmr.ModelNodeHelper.asEnumValue) Inject(javax.inject.Inject) Property(org.jboss.hal.dmr.Property) Single(rx.Single) AddressTemplate(org.jboss.hal.meta.AddressTemplate) SIMPLE(org.jboss.hal.config.AccessControlProvider.SIMPLE) Collectors.toSet(java.util.stream.Collectors.toSet) Logger(org.slf4j.Logger) RBAC(org.jboss.hal.config.AccessControlProvider.RBAC) CompositeResult(org.jboss.hal.dmr.CompositeResult) Operation(org.jboss.hal.dmr.Operation) Ids(org.jboss.hal.resources.Ids) Set(java.util.Set) Composite(org.jboss.hal.dmr.Composite) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Role(org.jboss.hal.config.Role) Collections(java.util.Collections) Role(org.jboss.hal.config.Role) Composite(org.jboss.hal.dmr.Composite) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) CompositeResult(org.jboss.hal.dmr.CompositeResult) AccessControlProvider(org.jboss.hal.config.AccessControlProvider) DispatchFailure(org.jboss.hal.dmr.dispatch.DispatchFailure) Operation(org.jboss.hal.dmr.Operation) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 18 with Property

use of org.jboss.hal.dmr.Property in project console by hal.

the class RemotingView method init.

@PostConstruct
void init() {
    // remote connector
    Metadata connectorMetadata = mbuiContext.metadataRegistry().lookup(CONNECTOR_TEMPLATE);
    connectorForm = new ModelNodeForm.Builder<NamedNode>(Ids.REMOTING_CONNECTOR_FORM, connectorMetadata).unboundFormItem(new PropertiesItem(PROPERTY), 1).onSave((form, changedValues) -> presenter.saveConnector(form, changedValues)).prepareReset(form -> presenter.resetConnector(form)).build();
    registerAttachable(connectorForm);
    // remote connector security
    Metadata connectorSecurityMetadata = mbuiContext.metadataRegistry().lookup(CONNECTOR_SECURITY_TEMPLATE);
    connectorSecurityForm = new ModelNodeForm.Builder<>(Ids.REMOTING_CONNECTOR_SECURITY_FORM, connectorSecurityMetadata).unboundFormItem(new PropertiesItem(PROPERTY), 2).singleton(() -> new Operation.Builder(SELECTED_CONNECTOR_SECURITY_TEMPLATE.resolve(presenter.selectedConnectorContext), READ_RESOURCE_OPERATION).build(), () -> presenter.createConnectorSecurity()).onSave((form, changedValues) -> presenter.saveConnectorSecurity(form, changedValues)).prepareReset(form -> presenter.resetConnectorSecurity(form)).prepareRemove(form -> presenter.removeConnectorSecurity(form)).build();
    registerAttachable(connectorSecurityForm);
    // remote connector security policy
    Metadata connectorSecurityPolicyMetadata = mbuiContext.metadataRegistry().lookup(CONNECTOR_SECURITY_POLICY_TEMPLATE);
    connectorSecurityPolicyForm = new ModelNodeForm.Builder<>(Ids.REMOTING_CONNECTOR_SECURITY_POLICY_FORM, connectorSecurityPolicyMetadata).singleton(() -> new Operation.Builder(SELECTED_CONNECTOR_SECURITY_POLICY_TEMPLATE.resolve(presenter.selectedConnectorContext), READ_RESOURCE_OPERATION).build(), () -> presenter.createConnectorSecurityPolicy()).onSave((form, changedValues) -> presenter.saveConnectorSecurityPolicy(changedValues)).prepareReset(form -> presenter.resetConnectorSecurityPolicy(form)).prepareRemove(form -> presenter.removeConnectorSecurityPolicy(form)).build();
    registerAttachable(connectorSecurityPolicyForm);
    // remote connector tabs
    Tabs connectorTabs = new Tabs(Ids.REMOTING_CONNECTOR_TAB_CONTAINER);
    connectorTabs.add(Ids.REMOTING_CONNECTOR_TAB, mbuiContext.resources().constants().attributes(), connectorForm.element());
    connectorTabs.add(Ids.REMOTING_CONNECTOR_SECURITY_TAB, Names.SECURITY, connectorSecurityForm.element());
    connectorTabs.add(Ids.REMOTING_CONNECTOR_SECURITY_POLICY_TAB, Names.POLICY, connectorSecurityPolicyForm.element());
    connectorTable.element().parentNode.appendChild(connectorTabs.element());
    // http connector
    Metadata httpConnectorMetadata = mbuiContext.metadataRegistry().lookup(HTTP_CONNECTOR_TEMPLATE);
    httpConnectorForm = new ModelNodeForm.Builder<NamedNode>(Ids.REMOTING_HTTP_CONNECTOR_FORM, httpConnectorMetadata).unboundFormItem(new PropertiesItem(PROPERTY), 2).onSave((form, changedValues) -> presenter.saveHttpConnector(form, changedValues)).prepareReset(form -> presenter.resetHttpConnector(form)).build();
    registerAttachable(httpConnectorForm);
    // http connector security
    Metadata httpConnectorSecurityMetadata = mbuiContext.metadataRegistry().lookup(HTTP_CONNECTOR_SECURITY_TEMPLATE);
    httpConnectorSecurityForm = new ModelNodeForm.Builder<>(Ids.REMOTING_HTTP_CONNECTOR_SECURITY_FORM, httpConnectorSecurityMetadata).unboundFormItem(new PropertiesItem(PROPERTY), 2).singleton(() -> new Operation.Builder(SELECTED_HTTP_CONNECTOR_SECURITY_TEMPLATE.resolve(presenter.selectedHttpConnectorContext), READ_RESOURCE_OPERATION).build(), () -> presenter.createHttpConnectorSecurity()).onSave((form, changedValues) -> presenter.saveHttpConnectorSecurity(form, changedValues)).prepareReset(form -> presenter.resetHttpConnectorSecurity(form)).prepareRemove(form -> presenter.removeHttpConnectorSecurity(form)).build();
    registerAttachable(httpConnectorSecurityForm);
    // http connector security policy
    Metadata httpConnectorSecurityPolicyMetadata = mbuiContext.metadataRegistry().lookup(HTTP_CONNECTOR_SECURITY_POLICY_TEMPLATE);
    httpConnectorSecurityPolicyForm = new ModelNodeForm.Builder<>(Ids.REMOTING_HTTP_CONNECTOR_SECURITY_POLICY_FORM, httpConnectorSecurityPolicyMetadata).singleton(() -> new Operation.Builder(SELECTED_HTTP_CONNECTOR_SECURITY_POLICY_TEMPLATE.resolve(presenter.selectedHttpConnectorContext), READ_RESOURCE_OPERATION).build(), () -> presenter.createHttpConnectorSecurityPolicy()).onSave((form, changedValues) -> presenter.saveHttpConnectorSecurityPolicy(changedValues)).prepareReset(form -> presenter.resetHttpConnectorSecurityPolicy(form)).prepareRemove(form -> presenter.removeHttpConnectorSecurityPolicy(form)).build();
    registerAttachable(httpConnectorSecurityPolicyForm);
    // http connector tabs
    Tabs httpConnectorTabs = new Tabs(Ids.REMOTING_HTTP_CONNECTOR_TAB_CONTAINER);
    httpConnectorTabs.add(Ids.REMOTING_HTTP_CONNECTOR_TAB, mbuiContext.resources().constants().attributes(), httpConnectorForm.element());
    httpConnectorTabs.add(Ids.REMOTING_HTTP_CONNECTOR_SECURITY_TAB, Names.SECURITY, httpConnectorSecurityForm.element());
    httpConnectorTabs.add(Ids.REMOTING_HTTP_CONNECTOR_SECURITY_POLICY_TAB, Names.POLICY, httpConnectorSecurityPolicyForm.element());
    httpConnectorTable.element().parentNode.appendChild(httpConnectorTabs.element());
}
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) PropertiesItem(org.jboss.hal.ballroom.form.PropertiesItem) Metadata(org.jboss.hal.meta.Metadata) NamedNode(org.jboss.hal.dmr.NamedNode) Tabs(org.jboss.hal.ballroom.Tabs) Operation(org.jboss.hal.dmr.Operation) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) PostConstruct(javax.annotation.PostConstruct)

Example 19 with Property

use of org.jboss.hal.dmr.Property 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 20 with Property

use of org.jboss.hal.dmr.Property in project console by hal.

the class ReadChildrenAutoComplete method operation.

private Operation operation(ResourceAddress address, int numberOfTemplates) {
    Operation operation;
    int wildcards = 0;
    if (address.isDefined()) {
        for (Property property : address.asPropertyList()) {
            if ("*".equals(property.getValue().asString())) {
                wildcards++;
            }
        }
    }
    if (numberOfTemplates == 1 && (wildcards == 0 || (wildcards == 1 && "*".equals(address.lastValue())))) {
        ResourceAddress parent = address.getParent();
        String childName = address.lastName();
        operation = new Operation.Builder(parent, READ_CHILDREN_NAMES_OPERATION, true).param(CHILD_TYPE, childName).build();
    } else {
        // The address is something like /foo=*/bar=*
        // Would be nice if we could use
        // /foo=*:read-children-names(child-type=bar)
        // but it returns an empty list, so we're using
        // /foo=*/bar=*:read-resource
        // which makes parsing the response more complicated
        operation = new Operation.Builder(address, READ_RESOURCE_OPERATION, true).param(ATTRIBUTES_ONLY, true).param(INCLUDE_ALIASES, false).param(INCLUDE_DEFAULTS, false).param(INCLUDE_RUNTIME, false).param(PROXIES, false).build();
    }
    return operation;
}
Also used : ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Operation(org.jboss.hal.dmr.Operation) Property(org.jboss.hal.dmr.Property)

Aggregations

Property (org.jboss.hal.dmr.Property)39 ModelNode (org.jboss.hal.dmr.ModelNode)26 Operation (org.jboss.hal.dmr.Operation)15 ResourceAddress (org.jboss.hal.dmr.ResourceAddress)15 Ids (org.jboss.hal.resources.Ids)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Inject (javax.inject.Inject)6 Composite (org.jboss.hal.dmr.Composite)6 ModelType (org.jboss.hal.dmr.ModelType)6 Metadata (org.jboss.hal.meta.Metadata)6 Resources (org.jboss.hal.resources.Resources)6 Map (java.util.Map)5 Form (org.jboss.hal.ballroom.form.Form)5 EventBus (com.google.web.bindery.event.shared.EventBus)4 HashMap (java.util.HashMap)4 Collectors.toList (java.util.stream.Collectors.toList)4 Collectors.toMap (java.util.stream.Collectors.toMap)4 PropertiesItem (org.jboss.hal.ballroom.form.PropertiesItem)4 Environment (org.jboss.hal.config.Environment)4