Search in sources :

Example 1 with SuccessfulMetadataCallback

use of org.jboss.hal.meta.processing.SuccessfulMetadataCallback 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 SuccessfulMetadataCallback

use of org.jboss.hal.meta.processing.SuccessfulMetadataCallback in project console by hal.

the class PropertiesOperations method saveWithProperties.

// ------------------------------------------------------ save methods
// please add additional save() or saveSingleton() methods from CrudOperations if necessary
/**
 * Saves the changed values and its properties (if modified) to the specified resource. After the resource has been saved a
 * standard success message is fired and the specified callback is executed.
 * <p>
 * This is the properties-extended version of {@link CrudOperations#save(String, String, AddressTemplate, Map, Callback)}:
 * <ol>
 * <li>New properties are added as children of the PSR</li>
 * <li>Modified properties are modified in the PSRs</li>
 * <li>Removed properties are removed from the PSR</li>
 * </ol>
 *
 * @param type the human readable resource type used in the success message
 * @param name the resource name
 * @param template the address template which is resolved against the current statement context and the resource name to get
 *        the resource address for the operation
 * @param changedValues the changed values / payload for the operation
 * @param psr the name of the properties sub resource (PSR) - most often this is "property"
 * @param properties the properties to save
 * @param callback the callback executed after saving the resource
 */
public void saveWithProperties(String type, String name, AddressTemplate template, Map<String, Object> changedValues, String psr, Map<String, String> properties, Callback callback) {
    changedValues.remove(psr);
    metadataProcessor.lookup(template, progress.get(), new SuccessfulMetadataCallback(eventBus, resources) {

        @Override
        public void onMetadata(Metadata metadata) {
            ResourceAddress address = template.resolve(statementContext, name);
            Composite operations = operationFactory.fromChangeSet(address, changedValues, metadata);
            saveInternal(type, name, address, operations, psr, properties, callback);
        }
    });
}
Also used : Composite(org.jboss.hal.dmr.Composite) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Metadata(org.jboss.hal.meta.Metadata) SuccessfulMetadataCallback(org.jboss.hal.meta.processing.SuccessfulMetadataCallback)

Example 3 with SuccessfulMetadataCallback

use of org.jboss.hal.meta.processing.SuccessfulMetadataCallback in project console by hal.

the class ConfigurationChangesPresenter method launchAdd.

void launchAdd() {
    AddressTemplate template;
    if (environment.isStandalone()) {
        template = HOST_CONFIGURATION_CHANGES_TEMPLATE;
    } else {
        if (hostOnly) {
            template = HOST_CONFIGURATION_CHANGES_TEMPLATE;
        } else {
            template = PROFILE_CONFIGURATION_CHANGES_TEMPLATE.replaceWildcards(profile);
        }
    }
    metadataProcessor.lookup(template, progress.get(), new SuccessfulMetadataCallback(getEventBus(), resources) {

        @Override
        public void onMetadata(Metadata metadata) {
            String id = Ids.build(Ids.CONFIGURATION_CHANGES, Ids.ADD);
            Form<ModelNode> form = new OperationFormBuilder<>(id, metadata, ADD).build();
            ModelNode changeModel = new ModelNode();
            Dialog dialog = new Dialog.Builder(resources.constants().configurationChanges()).add(form.element()).primary(resources.constants().yes(), () -> {
                boolean valid = form.save();
                // if the form contains validation error, don't close the dialog
                if (valid) {
                    crud.addSingleton(Names.CONFIGURATION_CHANGES, template, form.getModel(), address -> reload());
                }
                return valid;
            }).secondary(resources.constants().cancel(), () -> true).closeIcon(true).closeOnEsc(true).build();
            dialog.registerAttachable(form);
            dialog.show();
            form.edit(changeModel);
        }
    });
}
Also used : AddressTemplate(org.jboss.hal.meta.AddressTemplate) Dialog(org.jboss.hal.ballroom.dialog.Dialog) Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) StatementContext(org.jboss.hal.meta.StatementContext) OPTIONAL(org.jboss.hal.meta.AddressTemplate.OPTIONAL) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) CSS.formControlStatic(org.jboss.hal.resources.CSS.formControlStatic) HTMLElement(elemental2.dom.HTMLElement) Server(org.jboss.hal.core.runtime.server.Server) HasPresenter(org.jboss.hal.core.mvp.HasPresenter) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) Skeleton.applicationHeight(org.jboss.hal.ballroom.Skeleton.applicationHeight) CrudOperations(org.jboss.hal.core.CrudOperations) CONFIGURATION_CHANGES(org.jboss.hal.meta.token.NameTokens.CONFIGURATION_CHANGES) CSS.wrap(org.jboss.hal.resources.CSS.wrap) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) MARGIN_BIG(org.jboss.hal.ballroom.Skeleton.MARGIN_BIG) CSS.px(org.jboss.hal.resources.CSS.px) FinderPath(org.jboss.hal.core.finder.FinderPath) MetadataProcessor(org.jboss.hal.meta.processing.MetadataProcessor) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) HalView(org.jboss.hal.core.mvp.HalView) Optional(java.util.Optional) Finder(org.jboss.hal.core.finder.Finder) Footer(org.jboss.hal.spi.Footer) ModelNode(org.jboss.hal.dmr.ModelNode) Elements.div(org.jboss.gwt.elemento.core.Elements.div) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) CSSProperties(elemental2.dom.CSSProperties) SuccessfulMetadataCallback(org.jboss.hal.meta.processing.SuccessfulMetadataCallback) Inject(javax.inject.Inject) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) ApplicationFinderPresenter(org.jboss.hal.core.mvp.ApplicationFinderPresenter) LARGE(org.jboss.hal.ballroom.dialog.Dialog.Size.LARGE) Requires(org.jboss.hal.spi.Requires) ProxyCodeSplit(com.gwtplatform.mvp.client.annotations.ProxyCodeSplit) HTMLPreElement(elemental2.dom.HTMLPreElement) 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) PlaceRequest(com.gwtplatform.mvp.shared.proxy.PlaceRequest) ADD(org.jboss.hal.resources.Ids.ADD) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Elements.pre(org.jboss.gwt.elemento.core.Elements.pre) Resources(org.jboss.hal.resources.Resources) OperationFormBuilder(org.jboss.hal.core.mbui.form.OperationFormBuilder) Form(org.jboss.hal.ballroom.form.Form) OperationFormBuilder(org.jboss.hal.core.mbui.form.OperationFormBuilder) Form(org.jboss.hal.ballroom.form.Form) Dialog(org.jboss.hal.ballroom.dialog.Dialog) Metadata(org.jboss.hal.meta.Metadata) SuccessfulMetadataCallback(org.jboss.hal.meta.processing.SuccessfulMetadataCallback) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 4 with SuccessfulMetadataCallback

use of org.jboss.hal.meta.processing.SuccessfulMetadataCallback in project console by hal.

the class PatchesColumn method applyPatch.

private void applyPatch() {
    // check the host controller for restart-required
    checkHostState(() -> metadataProcessor.lookup(PATCHING_TEMPLATE, progress.get(), new SuccessfulMetadataCallback(eventBus, resources) {

        @Override
        public void onMetadata(Metadata metadata) {
            Metadata metadataOp = metadata.forOperation(PATCH);
            new ApplyPatchWizard(resources, environment, metadataOp, statementContext, dispatcher, progress, serverActions, () -> refresh(RESTORE_SELECTION)).show();
        }
    }));
}
Also used : Metadata(org.jboss.hal.meta.Metadata) SuccessfulMetadataCallback(org.jboss.hal.meta.processing.SuccessfulMetadataCallback) ApplyPatchWizard(org.jboss.hal.client.patching.wizard.ApplyPatchWizard)

Example 5 with SuccessfulMetadataCallback

use of org.jboss.hal.meta.processing.SuccessfulMetadataCallback in project console by hal.

the class ModelBrowser method showResourceView.

private void showResourceView(Node<Context> node, ResourceAddress address) {
    Node<Context> parent = tree.getNode(node.parent);
    AddressTemplate template = asGenericTemplate(parent, address);
    metadataProcessor.lookup(template, progress.get(), new SuccessfulMetadataCallback(eventBus, resources) {

        @Override
        public void onMetadata(Metadata metadata) {
            resourcePanel.update(node, node.data.getAddress(), metadata);
            resourcePanel.show();
        }
    });
}
Also used : FlowContext(org.jboss.hal.flow.FlowContext) SelectionContext(org.jboss.hal.ballroom.tree.SelectionContext) AddressTemplate(org.jboss.hal.meta.AddressTemplate) Metadata(org.jboss.hal.meta.Metadata) SuccessfulMetadataCallback(org.jboss.hal.meta.processing.SuccessfulMetadataCallback)

Aggregations

Metadata (org.jboss.hal.meta.Metadata)8 SuccessfulMetadataCallback (org.jboss.hal.meta.processing.SuccessfulMetadataCallback)8 ResourceAddress (org.jboss.hal.dmr.ResourceAddress)5 AddressTemplate (org.jboss.hal.meta.AddressTemplate)5 EventBus (com.google.web.bindery.event.shared.EventBus)4 HTMLElement (elemental2.dom.HTMLElement)4 Inject (javax.inject.Inject)4 Provider (javax.inject.Provider)4 ModelNode (org.jboss.hal.dmr.ModelNode)4 Operation (org.jboss.hal.dmr.Operation)4 Dispatcher (org.jboss.hal.dmr.dispatch.Dispatcher)4 Progress (org.jboss.hal.flow.Progress)4 MetadataProcessor (org.jboss.hal.meta.processing.MetadataProcessor)4 Ids (org.jboss.hal.resources.Ids)4 Names (org.jboss.hal.resources.Names)4 Resources (org.jboss.hal.resources.Resources)4 Footer (org.jboss.hal.spi.Footer)4 List (java.util.List)3 Map (java.util.Map)3 FlowContext (org.jboss.hal.flow.FlowContext)3