Search in sources :

Example 1 with Ids

use of org.jboss.hal.resources.Ids in project console by hal.

the class ManagementOperationsPresenter method cancelNonProgressingOperation.

void cancelNonProgressingOperation() {
    if (environment.isStandalone()) {
        ResourceAddress address = MANAGEMENT_OPERATIONS_TEMPLATE.resolve(statementContext);
        Operation operation = new Operation.Builder(address, CANCEL_NON_PROGRESSING_OPERATION).build();
        dispatcher.execute(operation, result -> {
            MessageEvent.fire(eventBus, Message.info(resources.messages().cancelledOperation(result.asString())));
            reload();
        }, (operation1, failure) -> {
            // operation to cancel, handle this a non error in HAL
            if (failure.contains(WFLYDM_0089)) {
                MessageEvent.fire(eventBus, Message.success(SafeHtmlUtils.fromString(failure)));
            } else {
                MessageEvent.fire(eventBus, Message.error(SafeHtmlUtils.fromString(failure)));
            }
            reload();
        }, (operation1, ex) -> {
            // operation to cancel, handle this a non error in HAL
            if (ex.getMessage().contains(WFLYDM_0089)) {
                MessageEvent.fire(eventBus, Message.success(SafeHtmlUtils.fromString(ex.getMessage())));
            } else {
                MessageEvent.fire(eventBus, Message.error(SafeHtmlUtils.fromString(ex.getMessage())));
            }
            reload();
        });
    } else {
        Composite composite = new Composite();
        // return running hosts, to later call a cancel-non-progressing-operation on each host
        ResourceAddress rootAddress = new ResourceAddress();
        Operation opHosts = new Operation.Builder(rootAddress, READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, HOST).build();
        composite.add(opHosts);
        ResourceAddress address = new ResourceAddress().add(HOST, WILDCARD).add(SERVER, WILDCARD);
        Operation opRunningServers = new Operation.Builder(address, QUERY).param(SELECT, new ModelNode().add(HOST).add(NAME)).param(WHERE, new ModelNode().set(SERVER_STATE, "running")).build();
        composite.add(opRunningServers);
        dispatcher.execute(composite, (CompositeResult compositeResult) -> {
            // available hosts
            List<String> hosts = compositeResult.step(0).get(RESULT).asList().stream().map(ModelNode::asString).collect(toList());
            // runing servers
            List<String> servers = Collections.emptyList();
            ModelNode result = compositeResult.step(1);
            if (result != null && result.isDefined()) {
                servers = result.get(RESULT).asList().stream().map(r -> hostServerAddress(r.get(RESULT))).collect(toList());
            }
            // run each :cancel-non-progressing-operation on a specific task
            // because the :cancel-non-progressing-operation returns as a failure
            // for this case, continue to run the next task
            List<Task<FlowContext>> tasks = new ArrayList<>(hosts.size());
            for (String host : hosts) {
                // call cancel-non-progressing-operation on each host
                Task<FlowContext> task = context -> {
                    ResourceAddress hostAddress = new ResourceAddress().add(HOST, host).add(CORE_SERVICE, MANAGEMENT).add(SERVICE, MANAGEMENT_OPERATIONS);
                    return buildCancelOperation(hostAddress, context);
                };
                tasks.add(task);
            }
            for (String server : servers) {
                // call cancel-non-progressing-operation on each server
                Task<FlowContext> task = context -> {
                    ResourceAddress serverAddress = AddressTemplate.of(server).append(MANAGEMENT_OPERATIONS_TEMPLATE).resolve(statementContext);
                    return buildCancelOperation(serverAddress, context);
                };
                tasks.add(task);
            }
            series(new FlowContext(progress.get()), tasks).subscribe(new Outcome<FlowContext>() {

                @Override
                public void onError(FlowContext context, Throwable error) {
                    MessageEvent.fire(getEventBus(), Message.error(SafeHtmlUtils.fromString("Error loading management operations: " + error.getMessage())));
                }

                @Override
                public void onSuccess(FlowContext context) {
                    if (context.emptyStack()) {
                        // display the standard message if there is no cancelled operation
                        MessageEvent.fire(eventBus, Message.success(SafeHtmlUtils.fromString(context.get(WFLYDM_0089))));
                    } else {
                        // display the cancelled non progressing operation ids
                        List<String> canceledOps = new ArrayList<>();
                        while (!context.emptyStack()) {
                            canceledOps.add(context.pop());
                        }
                        String ids = Joiner.on(", ").join(canceledOps);
                        MessageEvent.fire(eventBus, Message.success(resources.messages().cancelledOperation(ids)));
                    }
                    reload();
                }
            });
        });
    }
}
Also used : ModelNode(org.jboss.hal.dmr.ModelNode) Completable(rx.Completable) Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) StatementContext(org.jboss.hal.meta.StatementContext) MessageEvent(org.jboss.hal.spi.MessageEvent) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) FlowContext(org.jboss.hal.flow.FlowContext) Outcome(org.jboss.hal.flow.Outcome) ArrayList(java.util.ArrayList) ModelType(org.jboss.hal.dmr.ModelType) Inject(javax.inject.Inject) Property(org.jboss.hal.dmr.Property) Task(org.jboss.hal.flow.Task) Single(rx.Single) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) Message(org.jboss.hal.spi.Message) HasPresenter(org.jboss.hal.core.mvp.HasPresenter) Names(org.jboss.hal.resources.Names) ApplicationFinderPresenter(org.jboss.hal.core.mvp.ApplicationFinderPresenter) SafeHtmlUtils(com.google.gwt.safehtml.shared.SafeHtmlUtils) ModelNodeHelper.asNamedNodes(org.jboss.hal.dmr.ModelNodeHelper.asNamedNodes) Requires(org.jboss.hal.spi.Requires) CompositeResult(org.jboss.hal.dmr.CompositeResult) ProxyCodeSplit(com.gwtplatform.mvp.client.annotations.ProxyCodeSplit) Operation(org.jboss.hal.dmr.Operation) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) Ids(org.jboss.hal.resources.Ids) FinderPathFactory(org.jboss.hal.core.finder.FinderPathFactory) EventBus(com.google.web.bindery.event.shared.EventBus) FinderPath(org.jboss.hal.core.finder.FinderPath) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) MANAGEMENT_OPERATIONS(org.jboss.hal.meta.token.NameTokens.MANAGEMENT_OPERATIONS) Composite(org.jboss.hal.dmr.Composite) List(java.util.List) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Collectors.toList(java.util.stream.Collectors.toList) Resources(org.jboss.hal.resources.Resources) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) HalView(org.jboss.hal.core.mvp.HalView) Flow.series(org.jboss.hal.flow.Flow.series) Finder(org.jboss.hal.core.finder.Finder) Footer(org.jboss.hal.spi.Footer) NamedNode(org.jboss.hal.dmr.NamedNode) Collections(java.util.Collections) Joiner(com.google.common.base.Joiner) Task(org.jboss.hal.flow.Task) Composite(org.jboss.hal.dmr.Composite) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) CompositeResult(org.jboss.hal.dmr.CompositeResult) ArrayList(java.util.ArrayList) Operation(org.jboss.hal.dmr.Operation) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 2 with Ids

use of org.jboss.hal.resources.Ids in project console by hal.

the class DeploymentPresenter method reload.

@Override
protected void reload() {
    ResourceAddress address = deploymentAddress();
    // task 1: read sessions ids, servlets and websockets
    Operation readResourceOp = new Operation.Builder(address, READ_RESOURCE_OPERATION).param(INCLUDE_RUNTIME, true).param(RECURSIVE, true).build();
    Operation listSessionsOp = new Operation.Builder(address, LIST_SESSIONS).build();
    Task<FlowContext> task1 = context -> dispatcher.execute(new Composite(readResourceOp, listSessionsOp)).doOnSuccess((CompositeResult result) -> {
        ModelNode readResourceResult = result.step(0).get(RESULT);
        List<NamedNode> servlets = asNamedNodes(failSafePropertyList(readResourceResult, SERVLET));
        List<NamedNode> websockets = asNamedNodes(failSafePropertyList(readResourceResult, WEBSOCKET));
        // sorted session ids (important for step 2!)
        ModelNode listSessionsResult = result.step(1).get(RESULT);
        List<String> sessionIds = listSessionsResult.isDefined() ? listSessionsResult.asList().stream().map(ModelNode::asString).sorted().collect(toList()) : Collections.emptyList();
        context.set(SERVLETS, servlets);
        context.set(WEBSOCKETS, websockets);
        context.set(SESSION_IDS, sessionIds);
    }).toCompletable();
    // task 2: read session creation and last access times
    Task<FlowContext> task2 = context -> {
        List<String> sessionIds = context.get(SESSION_IDS);
        if (sessionIds.isEmpty()) {
            context.set(SESSIONS, Collections.emptyList());
            return Completable.complete();
        } else {
            List<Operation> operations = new ArrayList<>();
            for (String id : sessionIds) {
                operations.add(new Operation.Builder(address, GET_SESSION_CREATION_TIME).param(SESSION_ID, id).build());
                operations.add(new Operation.Builder(address, GET_SESSION_LAST_ACCESSED_TIME).param(SESSION_ID, id).build());
            }
            return dispatcher.execute(new Composite(operations)).doOnSuccess((CompositeResult result) -> {
                int i = 0;
                List<Session> sessions = new ArrayList<>();
                for (String sessionId : sessionIds) {
                    ModelNode modelNode = new ModelNode();
                    if (result.step(i).isDefined() && result.step(i).get(RESULT).isDefined()) {
                        modelNode.get(CREATION_TIME).set(result.step(i).get(RESULT));
                    }
                    i++;
                    if (result.step(i).isDefined() && result.step(i).get(RESULT).isDefined()) {
                        modelNode.get(LAST_ACCESSED_TIME).set(result.step(i).get(RESULT));
                    }
                    i++;
                    sessions.add(new Session(sessionId, modelNode));
                }
                context.set(SESSIONS, sessions);
            }).toCompletable();
        }
    };
    series(new FlowContext(progress.get()), task1, task2).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {

        @Override
        public void onSuccess(FlowContext context) {
            List<Session> sessions = context.get(SESSIONS);
            List<NamedNode> servlets = context.get(SERVLETS);
            List<NamedNode> websockets = context.get(WEBSOCKETS);
            getView().updateSessions(sessions);
            getView().updateServlets(servlets);
            getView().updateWebsockets(websockets);
        }
    });
}
Also used : INCLUDE_RUNTIME(org.jboss.hal.dmr.ModelDescriptionConstants.INCLUDE_RUNTIME) LIST_SESSIONS(org.jboss.hal.dmr.ModelDescriptionConstants.LIST_SESSIONS) Provider(javax.inject.Provider) CREATION_TIME(org.jboss.hal.dmr.ModelDescriptionConstants.CREATION_TIME) StatementContext(org.jboss.hal.meta.StatementContext) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) LAST_ACCESSED_TIME(org.jboss.hal.dmr.ModelDescriptionConstants.LAST_ACCESSED_TIME) Message(org.jboss.hal.spi.Message) READ_RESOURCE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.READ_RESOURCE_OPERATION) HasPresenter(org.jboss.hal.core.mvp.HasPresenter) Names(org.jboss.hal.resources.Names) LIST_SESSION_ATTRIBUTES(org.jboss.hal.dmr.ModelDescriptionConstants.LIST_SESSION_ATTRIBUTES) ModelNodeHelper.asNamedNodes(org.jboss.hal.dmr.ModelNodeHelper.asNamedNodes) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) FinderPath(org.jboss.hal.core.finder.FinderPath) List(java.util.List) RESULT(org.jboss.hal.dmr.ModelDescriptionConstants.RESULT) WEB_SUBDEPLOYMENT_TEMPLATE(org.jboss.hal.client.runtime.subsystem.undertow.AddressTemplates.WEB_SUBDEPLOYMENT_TEMPLATE) HalView(org.jboss.hal.core.mvp.HalView) Flow.series(org.jboss.hal.flow.Flow.series) Finder(org.jboss.hal.core.finder.Finder) Footer(org.jboss.hal.spi.Footer) SupportsExpertMode(org.jboss.hal.core.mvp.SupportsExpertMode) ModelNode(org.jboss.hal.dmr.ModelNode) Completable(rx.Completable) MessageEvent(org.jboss.hal.spi.MessageEvent) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Property(org.jboss.hal.dmr.Property) DEPLOYMENT(org.jboss.hal.dmr.ModelDescriptionConstants.DEPLOYMENT) Task(org.jboss.hal.flow.Task) WEB_DEPLOYMENT_ADDRESS(org.jboss.hal.client.runtime.subsystem.undertow.AddressTemplates.WEB_DEPLOYMENT_ADDRESS) Progress(org.jboss.hal.flow.Progress) INVALIDATE_SESSION(org.jboss.hal.dmr.ModelDescriptionConstants.INVALIDATE_SESSION) ApplicationFinderPresenter(org.jboss.hal.core.mvp.ApplicationFinderPresenter) Requires(org.jboss.hal.spi.Requires) RECURSIVE(org.jboss.hal.dmr.ModelDescriptionConstants.RECURSIVE) WEBSOCKET(org.jboss.hal.dmr.ModelDescriptionConstants.WEBSOCKET) GET_SESSION_CREATION_TIME(org.jboss.hal.dmr.ModelDescriptionConstants.GET_SESSION_CREATION_TIME) CompositeResult(org.jboss.hal.dmr.CompositeResult) ProxyCodeSplit(com.gwtplatform.mvp.client.annotations.ProxyCodeSplit) 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) SESSION_ID(org.jboss.hal.dmr.ModelDescriptionConstants.SESSION_ID) PlaceRequest(com.gwtplatform.mvp.shared.proxy.PlaceRequest) GET_SESSION_LAST_ACCESSED_TIME(org.jboss.hal.dmr.ModelDescriptionConstants.GET_SESSION_LAST_ACCESSED_TIME) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) WEB_DEPLOYMENT_TEMPLATE(org.jboss.hal.client.runtime.subsystem.undertow.AddressTemplates.WEB_DEPLOYMENT_TEMPLATE) SERVLET(org.jboss.hal.dmr.ModelDescriptionConstants.SERVLET) Composite(org.jboss.hal.dmr.Composite) SUBDEPLOYMENT(org.jboss.hal.dmr.ModelDescriptionConstants.SUBDEPLOYMENT) ModelNodeHelper.failSafePropertyList(org.jboss.hal.dmr.ModelNodeHelper.failSafePropertyList) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Collectors.toList(java.util.stream.Collectors.toList) NameTokens(org.jboss.hal.meta.token.NameTokens) WEB_SUBDEPLOYMENT_ADDRESS(org.jboss.hal.client.runtime.subsystem.undertow.AddressTemplates.WEB_SUBDEPLOYMENT_ADDRESS) Resources(org.jboss.hal.resources.Resources) NamedNode(org.jboss.hal.dmr.NamedNode) UNDERTOW(org.jboss.hal.dmr.ModelDescriptionConstants.UNDERTOW) Collections(java.util.Collections) Composite(org.jboss.hal.dmr.Composite) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) CompositeResult(org.jboss.hal.dmr.CompositeResult) ArrayList(java.util.ArrayList) Operation(org.jboss.hal.dmr.Operation) FlowContext(org.jboss.hal.flow.FlowContext) List(java.util.List) ArrayList(java.util.ArrayList) ModelNodeHelper.failSafePropertyList(org.jboss.hal.dmr.ModelNodeHelper.failSafePropertyList) Collectors.toList(java.util.stream.Collectors.toList) ModelNode(org.jboss.hal.dmr.ModelNode)

Aggregations

EventBus (com.google.web.bindery.event.shared.EventBus)2 NameToken (com.gwtplatform.mvp.client.annotations.NameToken)2 ProxyCodeSplit (com.gwtplatform.mvp.client.annotations.ProxyCodeSplit)2 ProxyPlace (com.gwtplatform.mvp.client.proxy.ProxyPlace)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors.toList (java.util.stream.Collectors.toList)2 Inject (javax.inject.Inject)2 Provider (javax.inject.Provider)2 DialogFactory (org.jboss.hal.ballroom.dialog.DialogFactory)2 Finder (org.jboss.hal.core.finder.Finder)2 FinderPath (org.jboss.hal.core.finder.FinderPath)2 FinderPathFactory (org.jboss.hal.core.finder.FinderPathFactory)2 ApplicationFinderPresenter (org.jboss.hal.core.mvp.ApplicationFinderPresenter)2 HalView (org.jboss.hal.core.mvp.HalView)2 HasPresenter (org.jboss.hal.core.mvp.HasPresenter)2 Composite (org.jboss.hal.dmr.Composite)2 CompositeResult (org.jboss.hal.dmr.CompositeResult)2 Joiner (com.google.common.base.Joiner)1