Search in sources :

Example 51 with CompositeResult

use of org.jboss.hal.dmr.CompositeResult 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)

Example 52 with CompositeResult

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

the class DeploymentPreview method update.

@Override
public void update(DeploymentResource item) {
    Operation opDeployment = new Operation.Builder(item.getAddress(), READ_RESOURCE_OPERATION).param(INCLUDE_RUNTIME, true).build();
    ResourceAddress webRuntimeAddress = WEB_SUBSYSTEM_TEMPLATE.resolve(statementContext);
    Operation opSubsystem = new Operation.Builder(webRuntimeAddress, READ_RESOURCE_OPERATION).param(INCLUDE_RUNTIME, true).build();
    dispatcher.execute(new Composite(opDeployment, opSubsystem), (CompositeResult compositeResult) -> {
        ModelNode deploymentResult = compositeResult.step(0).get(RESULT);
        ModelNode subsystemResult = compositeResult.step(1).get(RESULT);
        DeploymentResource deploymentStats = new DeploymentResource(item.getAddress(), deploymentResult);
        previewAttributes.refresh(deploymentStats);
        boolean statsEnabled = subsystemResult.get(STATISTICS_ENABLED).asBoolean(false);
        if (statsEnabled) {
            Map<String, Long> updatedSession = new HashMap<>();
            updatedSession.put(ACTIVE_SESSIONS, deploymentStats.get(ACTIVE_SESSIONS).asLong());
            updatedSession.put(EXPIRED_SESSIONS, deploymentStats.get(EXPIRED_SESSIONS).asLong());
            updatedSession.put(REJECTED_SESSIONS, deploymentStats.get(REJECTED_SESSIONS).asLong());
            sessions.update(updatedSession);
            // only shows this chart if the max_active_session is set, otherwise the max has no limits
            if (deploymentStats.get(MAX_ACTIVE_SESSIONS).asInt() > -1) {
                maxSessions.update(deploymentStats.get(ACTIVE_SESSIONS).asLong(), deploymentStats.get(MAX_ACTIVE_SESSIONS).asLong());
                setVisible(maxSessions.element(), true);
            } else {
                setVisible(maxSessions.element(), false);
            }
            Map<String, Long> updatedTime = new HashMap<>();
            updatedTime.put(SESSION_MAX_ALIVE_TIME, deploymentStats.get(SESSION_MAX_ALIVE_TIME).asLong());
            updatedTime.put(SESSION_AVG_ALIVE_TIME, deploymentStats.get(SESSION_AVG_ALIVE_TIME).asLong());
            sessionTime.update(updatedTime);
        }
        setVisible(noStatistics.element(), !statsEnabled);
        setVisible(sessionsElement, statsEnabled);
        setVisible(maxTimeElement, statsEnabled);
        injectUrls();
    });
}
Also used : Composite(org.jboss.hal.dmr.Composite) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) HashMap(java.util.HashMap) CompositeResult(org.jboss.hal.dmr.CompositeResult) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) DeploymentResource(org.jboss.hal.core.deployment.DeploymentResource) Operation(org.jboss.hal.dmr.Operation) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 53 with CompositeResult

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

the class CrudOperations method reset.

/**
 * Undefines all non required attributes in the specified set. After the resource has been undefined the specified success
 * message is fired and the specified callback is executed.
 * <p>
 * If the set contains only required attributes, a warning message is fired and the specified callback is executed.
 *
 * @param type the human readable resource type used in the success message
 * @param name the resource name
 * @param address the fq address for the operation
 * @param attributes the attributes which should be reset
 * @param metadata the metadata of the attributes
 * @param successMessage the success message fired after resetting the resource
 * @param callback the callback executed after the resource has been undefined
 */
@JsIgnore
public void reset(String type, String name, ResourceAddress address, Set<String> attributes, Metadata metadata, SafeHtml successMessage, Callback callback) {
    Composite composite = operationFactory.resetResource(address, attributes, metadata);
    if (composite.isEmpty()) {
        MessageEvent.fire(eventBus, Message.warning(resources.messages().noReset()));
        callback.execute();
    } else {
        SafeHtml question = name == null ? resources.messages().resetSingletonConfirmationQuestion() : resources.messages().resetConfirmationQuestion(name);
        DialogFactory.showConfirmation(resources.messages().resetConfirmationTitle(type), question, () -> dispatcher.execute(composite, (CompositeResult result) -> {
            MessageEvent.fire(eventBus, Message.success(successMessage));
            callback.execute();
        }));
    }
}
Also used : Composite(org.jboss.hal.dmr.Composite) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) CompositeResult(org.jboss.hal.dmr.CompositeResult) JsIgnore(jsinterop.annotations.JsIgnore)

Aggregations

CompositeResult (org.jboss.hal.dmr.CompositeResult)53 Composite (org.jboss.hal.dmr.Composite)48 Operation (org.jboss.hal.dmr.Operation)42 ResourceAddress (org.jboss.hal.dmr.ResourceAddress)33 ModelNode (org.jboss.hal.dmr.ModelNode)31 ArrayList (java.util.ArrayList)21 List (java.util.List)18 Dispatcher (org.jboss.hal.dmr.dispatch.Dispatcher)17 ModelDescriptionConstants (org.jboss.hal.dmr.ModelDescriptionConstants)16 AddressTemplate (org.jboss.hal.meta.AddressTemplate)16 StatementContext (org.jboss.hal.meta.StatementContext)16 Inject (javax.inject.Inject)15 Ids (org.jboss.hal.resources.Ids)14 Environment (org.jboss.hal.config.Environment)13 FlowContext (org.jboss.hal.flow.FlowContext)13 Resources (org.jboss.hal.resources.Resources)13 EventBus (com.google.web.bindery.event.shared.EventBus)12 Collectors.toList (java.util.stream.Collectors.toList)12 Message (org.jboss.hal.spi.Message)12 MessageEvent (org.jboss.hal.spi.MessageEvent)12