Search in sources :

Example 1 with ServerActions

use of org.jboss.hal.core.runtime.server.ServerActions in project console by hal.

the class ServerPreview method update.

@Override
public void update(Server server) {
    ServerStatusSwitch sss = new ServerStatusSwitch(serverActions) {

        @Override
        protected void onPending(Server server) {
            pending(resources.messages().serverPending(server.getName()));
            disableAllLinks();
        }

        @Override
        protected void onBootErrors(Server server) {
            error(resources.messages().serverBootErrors(server.getName()));
            disableAllLinksBut(bootErrorsLink);
        }

        @Override
        protected void onFailed(Server server) {
            error(resources.messages().serverFailed(server.getName()));
            if (server.isStandalone()) {
                disableAllLinks();
            } else {
                disableAllLinksBut(startLink);
            }
        }

        @Override
        protected void onAdminMode(Server server) {
            adminOnly(resources.messages().serverAdminMode(server.getName()));
            disableAllLinks();
        }

        @Override
        protected void onStarting(Server server) {
            adminOnly(resources.messages().serverAdminMode(server.getName()));
            disableAllLinks();
        }

        @Override
        protected void onSuspended(Server server) {
            suspended(resources.messages().serverSuspended(server.getName()));
            disableAllLinksBut(resumeLink);
        }

        @Override
        protected void onNeedsReload(Server server) {
            needsReload(resources.messages().serverNeedsReload(server.getName()));
            disableAllLinksBut(reloadLink);
        }

        @Override
        protected void onNeedsRestart(Server server) {
            needsRestart(resources.messages().serverNeedsRestart(server.getName()));
            disableAllLinksBut(restartLink);
        }

        @Override
        protected void onRunning(Server server) {
            running(resources.messages().serverRunning(server.getName()));
            if (server.isStandalone()) {
                disableAllLinks();
            } else {
                disableAllLinksBut(stopLink);
            }
        }

        @Override
        protected void onStopped(Server server) {
            alertContainer.className = alert + " " + alertInfo;
            alertIcon.className = Icons.STOPPED;
            alertText.innerHTML = resources.messages().serverStopped(server.getName()).asString();
            if (server.isStandalone()) {
                disableAllLinks();
            } else {
                disableAllLinksBut(startLink);
            }
        }

        @Override
        protected void onUnknown(Server server) {
            unknown(resources.messages().serverUndefined(server.getName()));
            disableAllLinks();
        }
    };
    sss.accept(server);
    ServerPreviewAttributes.refresh(server, attributes);
    boolean displayOpenPorts = server.isRunning() || server.needsRestart() || server.needsReload();
    if (displayOpenPorts) {
        List<Task<FlowContext>> tasks = new ArrayList<>();
        tasks.add(flowContext -> {
            ResourceAddress address = SELECTED_SERVER.resolve(statementContext);
            Operation operation = new Operation.Builder(address, READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, SOCKET_BINDING_GROUP).build();
            return dispatcher.execute(operation).doOnSuccess(result -> flowContext.push(result.get(0).asString())).toCompletable();
        });
        tasks.add(flowContext -> {
            String socketBnding = flowContext.pop();
            ResourceAddress address = SELECTED_SERVER.resolve(statementContext).add(SOCKET_BINDING_GROUP, socketBnding).add(SOCKET_BINDING, "*");
            ModelNode select = new ModelNode();
            select.add("bound-port").add(NAME);
            ModelNode where = new ModelNode();
            where.set("bound", true);
            Operation operation = new Operation.Builder(address, QUERY).param(SELECT, select).param(WHERE, where).build();
            return dispatcher.execute(operation).doOnSuccess(result -> {
                ModelNode openPortsModel = new ModelNode();
                result.asList().forEach(m -> {
                    ModelNode sbModel = m.get(RESULT);
                    openPortsModel.add(sbModel.get(NAME).asString(), sbModel.get("bound-port").asInt());
                    flowContext.push(openPortsModel);
                });
            }).toCompletable();
        });
        series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {

            @Override
            public void onSuccess(FlowContext flowContext) {
                ModelNode openPorts = flowContext.pop();
                buildOpenPortsElement(openPorts);
            }
        });
        serverActions.readUrl(server, serverUrl);
    }
    Elements.setVisible(headerOpenPorts, displayOpenPorts);
    Elements.setVisible(ulOpenPorts, displayOpenPorts);
}
Also used : ModelNode(org.jboss.hal.dmr.ModelNode) Provider(javax.inject.Provider) Constraint(org.jboss.hal.meta.security.Constraint) StatementContext(org.jboss.hal.meta.StatementContext) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Icons(org.jboss.hal.resources.Icons) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) Task(org.jboss.hal.flow.Task) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) HTMLElement(elemental2.dom.HTMLElement) PreviewAttribute(org.jboss.hal.core.finder.PreviewAttributes.PreviewAttribute) PlaceManager(com.gwtplatform.mvp.client.proxy.PlaceManager) PreviewAttributes(org.jboss.hal.core.finder.PreviewAttributes) Server(org.jboss.hal.core.runtime.server.Server) Places(org.jboss.hal.core.mvp.Places) Names(org.jboss.hal.resources.Names) ServerActions(org.jboss.hal.core.runtime.server.ServerActions) PreviewAttributeFunction(org.jboss.hal.core.finder.PreviewAttributes.PreviewAttributeFunction) 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) CSS(org.jboss.hal.resources.CSS) EventType.click(org.jboss.gwt.elemento.core.EventType.click) FinderPath(org.jboss.hal.core.finder.FinderPath) ServerPreviewAttributes(org.jboss.hal.core.runtime.server.ServerPreviewAttributes) PlaceRequest(com.gwtplatform.mvp.shared.proxy.PlaceRequest) List(java.util.List) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) UIConstants(org.jboss.hal.resources.UIConstants) HTMLLIElement(elemental2.dom.HTMLLIElement) NameTokens(org.jboss.hal.meta.token.NameTokens) Resources(org.jboss.hal.resources.Resources) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Flow.series(org.jboss.hal.flow.Flow.series) RuntimePreview(org.jboss.hal.client.runtime.RuntimePreview) ServerColumn.serverConfigTemplate(org.jboss.hal.client.runtime.server.ServerColumn.serverConfigTemplate) Elements(org.jboss.gwt.elemento.core.Elements) Task(org.jboss.hal.flow.Task) Server(org.jboss.hal.core.runtime.server.Server) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) ArrayList(java.util.ArrayList) Operation(org.jboss.hal.dmr.Operation) FlowContext(org.jboss.hal.flow.FlowContext) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 2 with ServerActions

use of org.jboss.hal.core.runtime.server.ServerActions in project console by hal.

the class ApplyPatchWizard method show.

public void show() {
    Messages messages = resources.messages();
    Wizard.Builder<PatchContext, PatchState> wb = new Wizard.Builder<>(messages.addResourceTitle(Names.PATCH), new PatchContext());
    checkServersState(servers -> {
        if (servers != null) {
            wb.addStep(CHECK_SERVERS, new CheckRunningServersStep(resources, servers, statementContext.selectedHost()));
        }
        wb.addStep(UPLOAD, new UploadPatchStep(resources)).addStep(CONFIGURE, new ConfigurationStep(metadata, resources)).onBack((context, currentState) -> {
            PatchState previous = null;
            switch(currentState) {
                case CHECK_SERVERS:
                    break;
                case UPLOAD:
                    previous = CHECK_SERVERS;
                    break;
                case CONFIGURE:
                    previous = UPLOAD;
                    break;
                default:
                    break;
            }
            return previous;
        }).onNext((context, currentState) -> {
            PatchState next = null;
            switch(currentState) {
                case CHECK_SERVERS:
                    next = UPLOAD;
                    break;
                case UPLOAD:
                    next = CONFIGURE;
                    break;
                case CONFIGURE:
                    break;
                default:
                    break;
            }
            return next;
        }).stayOpenAfterFinish().onFinish((wzd, context) -> {
            String name = context.file.name;
            wzd.showProgress(resources.constants().patchInProgress(), messages.patchInProgress(name));
            series(new FlowContext(progress.get()), new UploadPatch(statementContext, dispatcher, serverActions, context)).subscribe(new Outcome<FlowContext>() {

                @Override
                public void onError(FlowContext flowContext, Throwable error) {
                    wzd.showError(resources.constants().patchError(), messages.patchAddError(name, error.getMessage()), error.getMessage());
                }

                @Override
                public void onSuccess(FlowContext context) {
                    callback.execute();
                    wzd.showSuccess(resources.constants().patchSuccessful(), messages.patchSucessfullyApplied(name), messages.view(Names.PATCH), cxt -> {
                    /* nothing to do, content is already selected */
                    });
                }
            });
        });
        Wizard<PatchContext, PatchState> wizard = wb.build();
        wizard.show();
    });
}
Also used : Completable(rx.Completable) Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) StatementContext(org.jboss.hal.meta.StatementContext) Messages(org.jboss.hal.resources.Messages) UPLOAD(org.jboss.hal.client.patching.wizard.PatchState.UPLOAD) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) FlowContext(org.jboss.hal.flow.FlowContext) Outcome(org.jboss.hal.flow.Outcome) Property(org.jboss.hal.dmr.Property) Task(org.jboss.hal.flow.Task) Progress(org.jboss.hal.flow.Progress) PATCHING_TEMPLATE(org.jboss.hal.client.patching.PatchesColumn.PATCHING_TEMPLATE) Server(org.jboss.hal.core.runtime.server.Server) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) ServerActions(org.jboss.hal.core.runtime.server.ServerActions) Operation(org.jboss.hal.dmr.Operation) CONFIGURE(org.jboss.hal.client.patching.wizard.PatchState.CONFIGURE) Wizard(org.jboss.hal.ballroom.wizard.Wizard) CHECK_SERVERS(org.jboss.hal.client.patching.wizard.PatchState.CHECK_SERVERS) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Callback(org.jboss.hal.spi.Callback) Resources(org.jboss.hal.resources.Resources) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Flow.series(org.jboss.hal.flow.Flow.series) Messages(org.jboss.hal.resources.Messages) FlowContext(org.jboss.hal.flow.FlowContext) Wizard(org.jboss.hal.ballroom.wizard.Wizard)

Example 3 with ServerActions

use of org.jboss.hal.core.runtime.server.ServerActions in project console by hal.

the class RollbackWizard method show.

public void show() {
    Messages messages = resources.messages();
    Wizard.Builder<PatchContext, PatchState> wb = new Wizard.Builder<>(resources.constants().rollback(), new PatchContext());
    checkServersState(servers -> {
        if (servers != null) {
            wb.addStep(CHECK_SERVERS, new CheckRunningServersStep(resources, servers, statementContext.selectedHost()));
        }
        wb.addStep(ROLLBACK, new org.jboss.hal.client.patching.wizard.RollbackStep(metadata, resources, statementContext.selectedHost(), patchId)).onBack((context, currentState) -> {
            PatchState previous = null;
            switch(currentState) {
                case CHECK_SERVERS:
                    break;
                case ROLLBACK:
                    previous = CHECK_SERVERS;
                    break;
                default:
                    break;
            }
            return previous;
        }).onNext((context, currentState) -> {
            PatchState next = null;
            switch(currentState) {
                case CHECK_SERVERS:
                    next = ROLLBACK;
                    break;
                case ROLLBACK:
                    break;
                default:
                    break;
            }
            return next;
        }).stayOpenAfterFinish().onFinish((wzd, context) -> {
            String name = context.patchId;
            wzd.showProgress(resources.constants().rollbackInProgress(), messages.rollbackInProgress(name));
            series(new FlowContext(progress.get()), new RollbackTask(statementContext, dispatcher, serverActions, context)).subscribe(new Outcome<FlowContext>() {

                @Override
                public void onError(FlowContext context, Throwable error) {
                    wzd.showError(resources.constants().rollbackError(), messages.rollbackError(error.getMessage()), error.getMessage());
                }

                @Override
                public void onSuccess(FlowContext context) {
                    callback.execute();
                    wzd.showSuccess(resources.constants().rollbackSuccessful(), messages.rollbackSucessful(name));
                }
            });
        });
        Wizard<PatchContext, PatchState> wizard = wb.build();
        wizard.show();
    });
}
Also used : Completable(rx.Completable) ServerActions(org.jboss.hal.core.runtime.server.ServerActions) Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) Operation(org.jboss.hal.dmr.Operation) StatementContext(org.jboss.hal.meta.StatementContext) Messages(org.jboss.hal.resources.Messages) Wizard(org.jboss.hal.ballroom.wizard.Wizard) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) FlowContext(org.jboss.hal.flow.FlowContext) Outcome(org.jboss.hal.flow.Outcome) ROLLBACK(org.jboss.hal.client.patching.wizard.PatchState.ROLLBACK) CHECK_SERVERS(org.jboss.hal.client.patching.wizard.PatchState.CHECK_SERVERS) Property(org.jboss.hal.dmr.Property) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Task(org.jboss.hal.flow.Task) Progress(org.jboss.hal.flow.Progress) Callback(org.jboss.hal.spi.Callback) Resources(org.jboss.hal.resources.Resources) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) PATCHING_TEMPLATE(org.jboss.hal.client.patching.PatchesColumn.PATCHING_TEMPLATE) Flow.series(org.jboss.hal.flow.Flow.series) Server(org.jboss.hal.core.runtime.server.Server) Metadata(org.jboss.hal.meta.Metadata) Messages(org.jboss.hal.resources.Messages) FlowContext(org.jboss.hal.flow.FlowContext) Wizard(org.jboss.hal.ballroom.wizard.Wizard)

Aggregations

Provider (javax.inject.Provider)3 Server (org.jboss.hal.core.runtime.server.Server)3 ServerActions (org.jboss.hal.core.runtime.server.ServerActions)3 ModelDescriptionConstants (org.jboss.hal.dmr.ModelDescriptionConstants)3 Operation (org.jboss.hal.dmr.Operation)3 ResourceAddress (org.jboss.hal.dmr.ResourceAddress)3 Dispatcher (org.jboss.hal.dmr.dispatch.Dispatcher)3 Flow.series (org.jboss.hal.flow.Flow.series)3 FlowContext (org.jboss.hal.flow.FlowContext)3 Progress (org.jboss.hal.flow.Progress)3 Task (org.jboss.hal.flow.Task)3 StatementContext (org.jboss.hal.meta.StatementContext)3 Resources (org.jboss.hal.resources.Resources)3 Wizard (org.jboss.hal.ballroom.wizard.Wizard)2 PATCHING_TEMPLATE (org.jboss.hal.client.patching.PatchesColumn.PATCHING_TEMPLATE)2 CHECK_SERVERS (org.jboss.hal.client.patching.wizard.PatchState.CHECK_SERVERS)2 Environment (org.jboss.hal.config.Environment)2 Names (org.jboss.hal.resources.Names)2 EventBus (com.google.web.bindery.event.shared.EventBus)1 PlaceManager (com.gwtplatform.mvp.client.proxy.PlaceManager)1