Search in sources :

Example 1 with Property

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

the class ServerActions method copyServer.

// ------------------------------------------------------ server operations
public void copyServer(Server server, Callback callback) {
    Operation operation = new Operation.Builder(ResourceAddress.root(), READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, HOST).build();
    dispatcher.execute(operation, result -> {
        List<String> hosts = new ArrayList<>();
        result.asList().forEach(m -> hosts.add(m.asString()));
        // get the first host only to retrieve the r-r-d for server-config
        // as /host=*/server-config=*:read-operation-description(name=add) does not work
        AddressTemplate template = AddressTemplate.of("/host=" + hosts.get(0) + "/server-config=*");
        metadataProcessor.lookup(template, progress.get(), new SuccessfulMetadataCallback(eventBus, resources) {

            @Override
            public void onMetadata(Metadata metadata) {
                String id = Ids.build(SERVER_GROUP, statementContext.selectedServerGroup(), SERVER, FORM);
                SingleSelectBoxItem hostFormItem = new SingleSelectBoxItem(HOST, Names.HOST, hosts, false);
                hostFormItem.setRequired(true);
                NameItem nameItem = new NameItem();
                ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).fromRequestProperties().unboundFormItem(nameItem, 0).unboundFormItem(hostFormItem, 1, resources.messages().addServerHostHelp()).exclude(AUTO_START, SOCKET_BINDING_DEFAULT_INTERFACE, SOCKET_BINDING_GROUP, UPDATE_AUTO_START_WITH_SERVER_STATUS).build();
                AddResourceDialog dialog = new AddResourceDialog(resources.messages().copyServerTitle(), form, (resource, payload) -> {
                    // read server-config recursively to retrieve nested resources
                    ModelNode serverConfigModel = new ModelNode();
                    serverConfigModel.get(HOST).set(server.getHost());
                    serverConfigModel.get(SERVER_CONFIG).set(server.getName());
                    ResourceAddress serverAddress = new ResourceAddress(serverConfigModel);
                    Operation opReadServer = new Operation.Builder(serverAddress, READ_RESOURCE_OPERATION).param(RECURSIVE, true).build();
                    dispatcher.execute(opReadServer, new Consumer<ModelNode>() {

                        @Override
                        public void accept(ModelNode newServerModel) {
                            String newServerName = nameItem.getValue();
                            // set the chosen group in the model
                            newServerModel.get(GROUP).set(payload.get(GROUP).asString());
                            if (payload.hasDefined(SOCKET_BINDING_PORT_OFFSET)) {
                                newServerModel.get(SOCKET_BINDING_PORT_OFFSET).set(payload.get(SOCKET_BINDING_PORT_OFFSET).asLong());
                            }
                            newServerModel.get(NAME).set(newServerName);
                            ModelNode newServerModelAddress = new ModelNode();
                            newServerModelAddress.get(HOST).set(hostFormItem.getValue());
                            newServerModelAddress.get(SERVER_CONFIG).set(newServerName);
                            Operation opAddServer = new Operation.Builder(new ResourceAddress(newServerModelAddress), ADD).payload(newServerModel).build();
                            Composite comp = new Composite();
                            comp.add(opAddServer);
                            // create operation for each nested resource of the source server
                            createOperation(comp, JVM, newServerModel, newServerModelAddress);
                            createOperation(comp, INTERFACE, newServerModel, newServerModelAddress);
                            createOperation(comp, PATH, newServerModel, newServerModelAddress);
                            createOperation(comp, SYSTEM_PROPERTY, newServerModel, newServerModelAddress);
                            createOperation(comp, SSL, newServerModel, newServerModelAddress);
                            dispatcher.execute(comp, (CompositeResult result) -> {
                                MessageEvent.fire(eventBus, Message.success(resources.messages().addResourceSuccess(Names.SERVER, newServerName)));
                                callback.execute();
                            }, (operation1, failure) -> {
                                MessageEvent.fire(eventBus, Message.error(resources.messages().addResourceError(newServerName, failure)));
                                callback.execute();
                            }, (operation1, exception) -> {
                                MessageEvent.fire(eventBus, Message.error(resources.messages().addResourceError(newServerName, exception.getMessage())));
                                callback.execute();
                            });
                        }

                        private void createOperation(Composite composite, String resource, ModelNode model, ModelNode baseAddress) {
                            if (model.hasDefined(resource)) {
                                List<Property> props = model.get(resource).asPropertyList();
                                props.forEach(p -> {
                                    String propname = p.getName();
                                    ModelNode _address = baseAddress.clone();
                                    _address.get(resource).set(propname);
                                    Operation operation = new Operation.Builder(new ResourceAddress(_address), ADD).payload(p.getValue()).build();
                                    composite.add(operation);
                                });
                            }
                        }
                    });
                });
                dialog.show();
            }
        });
    });
}
Also used : AddressTemplate(org.jboss.hal.meta.AddressTemplate) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) Dialog(org.jboss.hal.ballroom.dialog.Dialog) DISABLED(org.jboss.hal.core.runtime.server.ServerConfigStatus.DISABLED) Provider(javax.inject.Provider) Elements.a(org.jboss.gwt.elemento.core.Elements.a) TimeoutHandler.repeatUntilTimeout(org.jboss.hal.dmr.dispatch.TimeoutHandler.repeatUntilTimeout) STOPPED(org.jboss.hal.core.runtime.server.ServerConfigStatus.STOPPED) StatementContext(org.jboss.hal.meta.StatementContext) LoggerFactory(org.slf4j.LoggerFactory) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) ManagementModel(org.jboss.hal.meta.ManagementModel) Icons(org.jboss.hal.resources.Icons) ModelNodeHelper.asEnumValue(org.jboss.hal.dmr.ModelNodeHelper.asEnumValue) TextBoxItem(org.jboss.hal.ballroom.form.TextBoxItem) OnError(org.jboss.hal.dmr.dispatch.Dispatcher.OnError) Elements.p(org.jboss.gwt.elemento.core.Elements.p) STARTED(org.jboss.hal.core.runtime.server.ServerConfigStatus.STARTED) HTMLElement(elemental2.dom.HTMLElement) Map(java.util.Map) SuspendState(org.jboss.hal.core.runtime.SuspendState) Message(org.jboss.hal.spi.Message) Timeouts(org.jboss.hal.core.runtime.Timeouts) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) EnumSet(java.util.EnumSet) CSS.marginLeft5(org.jboss.hal.resources.CSS.marginLeft5) Predicate(java.util.function.Predicate) SingleSelectBoxItem(org.jboss.hal.ballroom.form.SingleSelectBoxItem) FORM(org.jboss.hal.resources.Ids.FORM) ReadSocketBinding(org.jboss.hal.core.runtime.server.ServerUrlTasks.ReadSocketBinding) List(java.util.List) MetadataProcessor(org.jboss.hal.meta.processing.MetadataProcessor) Callback(org.jboss.hal.spi.Callback) Action(org.jboss.hal.core.runtime.Action) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Core(org.jboss.hal.core.Core) Flow.series(org.jboss.hal.flow.Flow.series) Footer(org.jboss.hal.spi.Footer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Subscription(rx.Subscription) CSS.fontAwesome(org.jboss.hal.resources.CSS.fontAwesome) DomGlobal.setTimeout(elemental2.dom.DomGlobal.setTimeout) ModelNode(org.jboss.hal.dmr.ModelNode) Alert(org.jboss.hal.ballroom.Alert) MessageEvent(org.jboss.hal.spi.MessageEvent) SHORT_TIMEOUT(org.jboss.hal.resources.UIConstants.SHORT_TIMEOUT) SuccessfulMetadataCallback(org.jboss.hal.meta.processing.SuccessfulMetadataCallback) ModelNodeHelper.getOrDefault(org.jboss.hal.dmr.ModelNodeHelper.getOrDefault) HashMap(java.util.HashMap) RUNNING(org.jboss.hal.core.runtime.RunningState.RUNNING) Result(org.jboss.hal.core.runtime.Result) FlowContext(org.jboss.hal.flow.FlowContext) Outcome(org.jboss.hal.flow.Outcome) ArrayList(java.util.ArrayList) OnFail(org.jboss.hal.dmr.dispatch.Dispatcher.OnFail) Inject(javax.inject.Inject) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Property(org.jboss.hal.dmr.Property) Strings(com.google.common.base.Strings) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) TimeoutHandler.repeatOperationUntil(org.jboss.hal.dmr.dispatch.TimeoutHandler.repeatOperationUntil) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) ReadSocketBindingGroup(org.jboss.hal.core.runtime.server.ServerUrlTasks.ReadSocketBindingGroup) BlockingDialog(org.jboss.hal.ballroom.dialog.BlockingDialog) Logger(org.slf4j.Logger) CompositeResult(org.jboss.hal.dmr.CompositeResult) Operation(org.jboss.hal.dmr.Operation) Ids(org.jboss.hal.resources.Ids) EventBus(com.google.web.bindery.event.shared.EventBus) CSS.pfIcon(org.jboss.hal.resources.CSS.pfIcon) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) CompletableSubscriber(rx.CompletableSubscriber) Consumer(java.util.function.Consumer) Composite(org.jboss.hal.dmr.Composite) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Resources(org.jboss.hal.resources.Resources) SUSPENDED(org.jboss.hal.core.runtime.SuspendState.SUSPENDED) RunningState(org.jboss.hal.core.runtime.RunningState) Elements.span(org.jboss.gwt.elemento.core.Elements.span) Elements(org.jboss.gwt.elemento.core.Elements) OperationFormBuilder(org.jboss.hal.core.mbui.form.OperationFormBuilder) Form(org.jboss.hal.ballroom.form.Form) URL_KEY(org.jboss.hal.core.runtime.server.ServerUrlTasks.URL_KEY) SingleSelectBoxItem(org.jboss.hal.ballroom.form.SingleSelectBoxItem) Composite(org.jboss.hal.dmr.Composite) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) CompositeResult(org.jboss.hal.dmr.CompositeResult) OperationFormBuilder(org.jboss.hal.core.mbui.form.OperationFormBuilder) ArrayList(java.util.ArrayList) Metadata(org.jboss.hal.meta.Metadata) SuccessfulMetadataCallback(org.jboss.hal.meta.processing.SuccessfulMetadataCallback) Operation(org.jboss.hal.dmr.Operation) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) Consumer(java.util.function.Consumer) ModelNode(org.jboss.hal.dmr.ModelNode) Property(org.jboss.hal.dmr.Property)

Example 2 with Property

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

the class ServerGroupActions method addChildOperations.

private static void addChildOperations(Composite composite, ModelNode rootModel, ModelNode baseAddress, int depth) {
    if (depth <= 0) {
        return;
    }
    for (Property property : rootModel.asPropertyList()) {
        if (ModelType.OBJECT.equals(property.getValue().getType())) {
            for (Property resource : property.getValue().asPropertyList()) {
                if (ModelType.OBJECT.equals(resource.getValue().getType())) {
                    ModelNode resourceAddress = baseAddress.clone().add(property.getName(), resource.getName());
                    Operation operation = new Operation.Builder(new ResourceAddress(resourceAddress), ADD).payload(resource.getValue()).build();
                    composite.add(operation);
                    addChildOperations(composite, resource.getValue(), resourceAddress, depth - 1);
                }
            }
        }
    }
}
Also used : ResourceAddress(org.jboss.hal.dmr.ResourceAddress) OperationFormBuilder(org.jboss.hal.core.mbui.form.OperationFormBuilder) Operation(org.jboss.hal.dmr.Operation) ModelNode(org.jboss.hal.dmr.ModelNode) Property(org.jboss.hal.dmr.Property)

Example 3 with Property

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

the class SingleRrdParser method parseSingle.

private void parseSingle(ResourceAddress address, ModelNode modelNode) {
    // resource description
    // to reduce the payload we only use the flat model node w/o children
    ModelNode childrenNode = modelNode.hasDefined(CHILDREN) ? modelNode.remove(CHILDREN) : new ModelNode();
    if (!rrdResult.containsResourceDescription(address) && modelNode.hasDefined(DESCRIPTION)) {
        rrdResult.addResourceDescription(addressProcessor.apply(address), new ResourceDescription(modelNode));
    }
    // security context
    ModelNode accessControl = modelNode.get(ACCESS_CONTROL);
    if (accessControl.isDefined()) {
        if (!rrdResult.containsSecurityContext(address) && accessControl.hasDefined(DEFAULT)) {
            rrdResult.addSecurityContext(address, new SecurityContext(accessControl.get(DEFAULT)));
        }
        // exceptions
        if (accessControl.hasDefined(EXCEPTIONS)) {
            List<Property> exceptions = accessControl.get(EXCEPTIONS).asPropertyList();
            for (Property property : exceptions) {
                ModelNode exception = property.getValue();
                ResourceAddress exceptionAddress = new ResourceAddress(exception.get(ADDRESS));
                if (!rrdResult.containsSecurityContext(exceptionAddress)) {
                    rrdResult.addSecurityContext(exceptionAddress, new SecurityContext(exception));
                }
            }
        }
    }
    // children
    if (childrenNode.isDefined()) {
        List<Property> children = childrenNode.asPropertyList();
        for (Property child : children) {
            String addressKey = child.getName();
            if (child.getValue().hasDefined(MODEL_DESCRIPTION)) {
                List<Property> modelDescriptions = child.getValue().get(MODEL_DESCRIPTION).asPropertyList();
                for (Property modelDescription : modelDescriptions) {
                    String addressValue = modelDescription.getName();
                    ModelNode childNode = modelDescription.getValue();
                    ResourceAddress childAddress = new ResourceAddress(address).add(addressKey, addressValue);
                    parseSingle(childAddress, childNode);
                }
            }
        }
    }
}
Also used : ResourceDescription(org.jboss.hal.meta.description.ResourceDescription) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) SecurityContext(org.jboss.hal.meta.security.SecurityContext) ModelNode(org.jboss.hal.dmr.ModelNode) Property(org.jboss.hal.dmr.Property)

Example 4 with Property

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

the class Metadata method forComplexAttribute.

/**
 * Creates a new metadata instance based on this metadata with the attributes taken from the specified complex attribute.
 * The resource description will only include the attributes but no operations!
 *
 * @param prefixLabel if {@code true} the labels of the attributes of the complex attribute are prefixed with name of the
 *        complex attribute.
 */
@JsIgnore
public Metadata forComplexAttribute(String name, boolean prefixLabel) {
    ModelNode payload = new ModelNode();
    payload.get(DESCRIPTION).set(failSafeGet(description, ATTRIBUTES + "/" + name + "/" + DESCRIPTION));
    payload.get(REQUIRED).set(failSafeGet(description, ATTRIBUTES + "/" + name + "/" + REQUIRED));
    payload.get(NILLABLE).set(failSafeGet(description, ATTRIBUTES + "/" + name + "/" + NILLABLE));
    Property complexAttribute = description.findAttribute(ATTRIBUTES, name);
    if (complexAttribute != null && complexAttribute.getValue().hasDefined(VALUE_TYPE)) {
        complexAttribute.getValue().get(VALUE_TYPE).asPropertyList().forEach(nestedProperty -> {
            // The nested name is *always* just the nested property name,
            // since it's used when building the DMR operations
            String nestedName = nestedProperty.getName();
            ModelNode nestedDescription = nestedProperty.getValue();
            // up by LabelBuilder.label(Property)
            if (prefixLabel) {
                nestedDescription.get(HAL_LABEL).set(name + "-" + nestedProperty.getName());
            }
            payload.get(ATTRIBUTES).get(nestedName).set(nestedDescription);
        });
    }
    SecurityContext parentContext = this.securityContext.get();
    SecurityContext attributeContext = new SecurityContext(new ModelNode()) {

        @Override
        public boolean isReadable() {
            return parentContext.isReadable(name);
        }

        @Override
        public boolean isWritable() {
            return parentContext.isWritable(name);
        }

        @Override
        public boolean isReadable(String attribute) {
            // if the complex attribute is readable all nested attributes are readable as well
            return isReadable();
        }

        @Override
        public boolean isWritable(String attribute) {
            // if the complex attribute is writable all nested attributes are writable as well
            return isWritable();
        }

        @Override
        public boolean isExecutable(String operation) {
            return parentContext.isExecutable(operation);
        }
    };
    return new Metadata(template, () -> attributeContext, new ResourceDescription(payload), capabilities);
}
Also used : ResourceDescription(org.jboss.hal.meta.description.ResourceDescription) StaticResourceDescription(org.jboss.hal.meta.description.StaticResourceDescription) SecurityContext(org.jboss.hal.meta.security.SecurityContext) ModelNode(org.jboss.hal.dmr.ModelNode) JsProperty(jsinterop.annotations.JsProperty) Property(org.jboss.hal.dmr.Property) JsIgnore(jsinterop.annotations.JsIgnore)

Example 5 with Property

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

the class ResetServerDialog method reset.

void reset(String messagingServer) {
    LabelBuilder labelBuilder = new LabelBuilder();
    String l1 = labelBuilder.label(RESET_ALL_MESSAGE_COUNTERS);
    Property p1 = metadata.getDescription().findOperation(RESET_ALL_MESSAGE_COUNTERS);
    if (p1 != null && p1.getValue().hasDefined(DESCRIPTION)) {
        l1 = p1.getValue().get(DESCRIPTION).asString();
        l1 = Strings.sanitize(l1);
    }
    String l2 = labelBuilder.label(RESET_ALL_MESSAGE_COUNTER_HISTORIES);
    Property p2 = metadata.getDescription().findOperation(RESET_ALL_MESSAGE_COUNTER_HISTORIES);
    if (p2 != null && p2.getValue().hasDefined(DESCRIPTION)) {
        l2 = p2.getValue().get(DESCRIPTION).asString();
        l2 = Strings.sanitize(l2);
    }
    Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.RESET_MESSAGE_COUNTERS, Metadata.empty()).unboundFormItem(new SwitchItem(RESET_ALL_MESSAGE_COUNTERS, l1)).unboundFormItem(new SwitchItem(RESET_ALL_MESSAGE_COUNTER_HISTORIES, l2)).onSave((f, changedValues) -> column.resetServer(messagingServer, !f.getFormItem(RESET_ALL_MESSAGE_COUNTERS).isEmpty(), !f.getFormItem(RESET_ALL_MESSAGE_COUNTER_HISTORIES).isEmpty())).build();
    form.addFormValidation(new RequireAtLeastOneAttributeValidation<>(asList(RESET_ALL_MESSAGE_COUNTERS, RESET_ALL_MESSAGE_COUNTER_HISTORIES), resources));
    // Make the long labels more readable
    stream(form.element().querySelectorAll("." + halFormLabel + ", ." + halFormInput)).filter(htmlElements()).map(asHtmlElement()).forEach(element -> element.style.width = WidthUnionType.of("50%"));
    Dialog dialog = new Dialog.Builder(resources.constants().reset()).add(form.element()).primary(resources.constants().reset(), form::save).size(Size.MEDIUM).closeIcon(true).closeOnEsc(true).cancel().build();
    dialog.registerAttachable(form);
    form.edit(new ModelNode());
    dialog.show();
}
Also used : ModelNode(org.jboss.hal.dmr.ModelNode) Dialog(org.jboss.hal.ballroom.dialog.Dialog) RESET_ALL_MESSAGE_COUNTERS(org.jboss.hal.dmr.ModelDescriptionConstants.RESET_ALL_MESSAGE_COUNTERS) Size(org.jboss.hal.ballroom.dialog.Dialog.Size) Ids(org.jboss.hal.resources.Ids) Elements.stream(org.jboss.gwt.elemento.core.Elements.stream) Elements.asHtmlElement(org.jboss.gwt.elemento.core.Elements.asHtmlElement) CSS.halFormLabel(org.jboss.hal.resources.CSS.halFormLabel) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Elements.htmlElements(org.jboss.gwt.elemento.core.Elements.htmlElements) Property(org.jboss.hal.dmr.Property) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem) RESET_ALL_MESSAGE_COUNTER_HISTORIES(org.jboss.hal.dmr.ModelDescriptionConstants.RESET_ALL_MESSAGE_COUNTER_HISTORIES) Resources(org.jboss.hal.resources.Resources) DESCRIPTION(org.jboss.hal.dmr.ModelDescriptionConstants.DESCRIPTION) Arrays.asList(java.util.Arrays.asList) RequireAtLeastOneAttributeValidation(org.jboss.hal.core.mbui.form.RequireAtLeastOneAttributeValidation) Strings(org.jboss.hal.resources.Strings) WidthUnionType(elemental2.dom.CSSProperties.WidthUnionType) Metadata(org.jboss.hal.meta.Metadata) CSS.halFormInput(org.jboss.hal.resources.CSS.halFormInput) Form(org.jboss.hal.ballroom.form.Form) Dialog(org.jboss.hal.ballroom.dialog.Dialog) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) ModelNode(org.jboss.hal.dmr.ModelNode) Property(org.jboss.hal.dmr.Property) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem)

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