Search in sources :

Example 1 with ClusterExecutionOptions

use of com.evolveum.midpoint.task.api.ClusterExecutionOptions in project midpoint by Evolveum.

the class ClusterwideUserSessionManagerImpl method getLoggedInPrincipals.

@Override
@NotNull
public List<UserSessionManagementType> getLoggedInPrincipals(Task task, OperationResult result) {
    List<UserSessionManagementType> loggedUsers = guiProfiledPrincipalManager.getLocalLoggedInPrincipals();
    Map<String, UserSessionManagementType> usersMap = new HashMap<>();
    // fix for mid-6328
    loggedUsers.forEach(loggedUser -> {
        UserSessionManagementType addedUser = usersMap.get(loggedUser.getFocus().getOid());
        if (addedUser != null) {
            addedUser.setActiveSessions(addedUser.getActiveSessions() + loggedUser.getActiveSessions());
            addedUser.getNode().addAll(loggedUser.getNode());
        } else {
            usersMap.put(loggedUser.getFocus().getOid(), loggedUser);
        }
    });
    // We try to invoke this call also on nodes that are in transition. We want to get
    // information as complete as realistically possible.
    clusterExecutionHelper.execute((client, node, result1) -> {
        client.path(ClusterServiceConsts.EVENT_LIST_USER_SESSION);
        Response response = client.get();
        LOGGER.debug("Remote-node retrieval of user sessions finished on {} with status {}, {}", node.getNodeIdentifier(), response.getStatusInfo().getStatusCode(), response.getStatusInfo().getReasonPhrase());
        if (response.hasEntity()) {
            UserSessionManagementListType remoteSessionsWrapper = response.readEntity(UserSessionManagementListType.class);
            List<UserSessionManagementType> remoteSessions = remoteSessionsWrapper.getSession();
            for (UserSessionManagementType remoteSession : MiscUtil.emptyIfNull(remoteSessions)) {
                UserSessionManagementType existingUser = usersMap.get(remoteSession.getFocus().getOid());
                if (existingUser != null) {
                    existingUser.setActiveSessions(existingUser.getActiveSessions() + remoteSession.getActiveSessions());
                    existingUser.getNode().addAll(remoteSession.getNode());
                } else {
                    usersMap.put(remoteSession.getFocus().getOid(), remoteSession);
                }
            }
        }
        response.close();
    }, new ClusterExecutionOptions().tryNodesInTransition(), " list principals from remote nodes ", result);
    return new ArrayList<>(usersMap.values());
}
Also used : Response(javax.ws.rs.core.Response) UserSessionManagementType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UserSessionManagementListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementListType) ClusterExecutionOptions(com.evolveum.midpoint.task.api.ClusterExecutionOptions) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ClusterExecutionOptions

use of com.evolveum.midpoint.task.api.ClusterExecutionOptions in project midpoint by Evolveum.

the class ClusterwideUserSessionManagerImpl method terminateSessions.

@Override
public void terminateSessions(TerminateSessionEvent terminateSessionEvent, Task task, OperationResult result) {
    guiProfiledPrincipalManager.terminateLocalSessions(terminateSessionEvent);
    // We try to invoke this call also on nodes that are in transition. It is quite important
    // that terminate session is executed on as wide scale as realistically possible.
    clusterExecutionHelper.execute((client, node, result1) -> {
        client.path(ClusterServiceConsts.EVENT_TERMINATE_SESSION);
        Response response = client.post(terminateSessionEvent.toEventType());
        LOGGER.info("Remote-node user session termination finished on {} with status {}, {}", node.getNodeIdentifier(), response.getStatusInfo().getStatusCode(), response.getStatusInfo().getReasonPhrase());
        response.close();
    }, new ClusterExecutionOptions().tryNodesInTransition(), "session termination", result);
}
Also used : Response(javax.ws.rs.core.Response) ClusterExecutionOptions(com.evolveum.midpoint.task.api.ClusterExecutionOptions)

Example 3 with ClusterExecutionOptions

use of com.evolveum.midpoint.task.api.ClusterExecutionOptions in project midpoint by Evolveum.

the class RestConnector method startRemoteScheduler.

public void startRemoteScheduler(NodeType node, OperationResult result) throws SchemaException {
    clusterExecutionHelper.execute(node, (client, actualNode, result1) -> {
        client.path(TaskConstants.START_LOCAL_SCHEDULER_REST_PATH);
        Response response = client.post(null);
        Response.StatusType statusInfo = response.getStatusInfo();
        LOGGER.debug("Starting remote scheduler on {} finished with status {}: {}", node.getNodeIdentifier(), statusInfo.getStatusCode(), statusInfo.getReasonPhrase());
        if (statusInfo.getFamily() != Response.Status.Family.SUCCESSFUL) {
            LOGGER.warn("Starting scheduler on {} finished with status {}: {}", node.getNodeIdentifier(), statusInfo.getStatusCode(), statusInfo.getReasonPhrase());
            result1.recordFatalError("Starting remote scheduler finished with status " + statusInfo.getStatusCode() + ": " + statusInfo.getReasonPhrase());
        }
        response.close();
    }, new ClusterExecutionOptions().tryAllNodes(), "start scheduler", result);
}
Also used : Response(javax.ws.rs.core.Response) ClusterExecutionOptions(com.evolveum.midpoint.task.api.ClusterExecutionOptions)

Example 4 with ClusterExecutionOptions

use of com.evolveum.midpoint.task.api.ClusterExecutionOptions in project midpoint by Evolveum.

the class RestConnector method stopRemoteTaskRun.

public void stopRemoteTaskRun(String oid, NodeType node, OperationResult result) throws SchemaException {
    clusterExecutionHelper.execute(node, (client, actualNode, result1) -> {
        client.path(TaskConstants.STOP_LOCAL_TASK_REST_PATH_PREFIX + oid + TaskConstants.STOP_LOCAL_TASK_REST_PATH_SUFFIX);
        Response response = client.post(null);
        Response.StatusType statusInfo = response.getStatusInfo();
        LOGGER.debug("Stopping task {} on {} finished with status {}: {}", oid, node.getNodeIdentifier(), statusInfo.getStatusCode(), statusInfo.getReasonPhrase());
        if (statusInfo.getFamily() != Response.Status.Family.SUCCESSFUL) {
            LOGGER.warn("Stopping task {} on {} finished with status {}: {}", oid, node.getNodeIdentifier(), statusInfo.getStatusCode(), statusInfo.getReasonPhrase());
            result1.recordFatalError("Stopping remote task finished with status " + statusInfo.getStatusCode() + ": " + statusInfo.getReasonPhrase());
        }
        response.close();
    }, new ClusterExecutionOptions().tryAllNodes(), "stop task", result);
}
Also used : Response(javax.ws.rs.core.Response) ClusterExecutionOptions(com.evolveum.midpoint.task.api.ClusterExecutionOptions)

Example 5 with ClusterExecutionOptions

use of com.evolveum.midpoint.task.api.ClusterExecutionOptions in project midpoint by Evolveum.

the class RestConnector method stopRemoteScheduler.

public void stopRemoteScheduler(NodeType node, OperationResult result) throws SchemaException {
    clusterExecutionHelper.execute(node, (client, actualNode, result1) -> {
        client.path(TaskConstants.STOP_LOCAL_SCHEDULER_REST_PATH);
        Response response = client.post(null);
        Response.StatusType statusInfo = response.getStatusInfo();
        LOGGER.debug("Stopping remote scheduler on {} finished with status {}: {}", node.getNodeIdentifier(), statusInfo.getStatusCode(), statusInfo.getReasonPhrase());
        if (statusInfo.getFamily() != Response.Status.Family.SUCCESSFUL) {
            LOGGER.warn("Stopping scheduler on {} finished with status {}: {}", node.getNodeIdentifier(), statusInfo.getStatusCode(), statusInfo.getReasonPhrase());
            result1.recordFatalError("Stopping remote scheduler finished with status " + statusInfo.getStatusCode() + ": " + statusInfo.getReasonPhrase());
        }
        response.close();
    }, new ClusterExecutionOptions().tryAllNodes(), "stop scheduler", result);
}
Also used : Response(javax.ws.rs.core.Response) ClusterExecutionOptions(com.evolveum.midpoint.task.api.ClusterExecutionOptions)

Aggregations

ClusterExecutionOptions (com.evolveum.midpoint.task.api.ClusterExecutionOptions)5 Response (javax.ws.rs.core.Response)5 UserSessionManagementListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementListType)1 UserSessionManagementType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementType)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 NotNull (org.jetbrains.annotations.NotNull)1