Search in sources :

Example 16 with RestException

use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException in project scheduling by ow2-proactive.

the class CommonRest method checkPermissions.

@Override
public Map<String, Boolean> checkPermissions(String sessionId, List<String> methods) throws RestException {
    if (methods == null || methods.isEmpty()) {
        return Collections.emptyMap();
    }
    Scheduler scheduler = checkAccess(sessionId);
    Map<String, Boolean> answer = new HashMap<>(methods.size());
    for (String method : methods) {
        try {
            checkPermission(scheduler.getSubject(), new MethodCallPermission(method), "Access to the method " + method + " is not allowed");
            answer.put(method, Boolean.TRUE);
        } catch (PermissionException e) {
            answer.put(method, Boolean.FALSE);
        } catch (NotConnectedException e) {
            throw new NotConnectedRestException(YOU_ARE_NOT_CONNECTED_TO_THE_SCHEDULER_YOU_SHOULD_LOG_ON_FIRST);
        }
    }
    return answer;
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)

Example 17 with RestException

use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException in project scheduling by ow2-proactive.

the class CommonRest method getLogLevel.

@Override
public String getLogLevel(String sessionId, String name) throws RestException {
    Scheduler scheduler = checkAccess(sessionId);
    try {
        checkPermission(scheduler.getSubject(), new RMCoreAllPermission(), "Resource Manager administrative rights is required");
        Logger loggerInstance;
        if (name == null) {
            loggerInstance = Logger.getRootLogger();
        } else {
            loggerInstance = Logger.getLogger(name);
        }
        if (loggerInstance == null) {
            throw new RestException("No logger found with name " + name);
        }
        return loggerInstance.getEffectiveLevel().toString();
    } catch (PermissionException e) {
        throw new PermissionRestException("Resource Manager administrative rights is required");
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(YOU_ARE_NOT_CONNECTED_TO_THE_SCHEDULER_YOU_SHOULD_LOG_ON_FIRST);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) RestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Logger(org.apache.log4j.Logger)

Example 18 with RestException

use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException in project scheduling by ow2-proactive.

the class CommonRest method setLogLevelMultiple.

@Override
public boolean setLogLevelMultiple(String sessionId, Map<String, String> loggersConfiguration) throws RestException {
    Scheduler scheduler = checkAccess(sessionId);
    boolean levelChanged = false;
    try {
        try {
            checkPermission(scheduler.getSubject(), new RMCoreAllPermission(), "Resource Manager administrative rights is required");
        } catch (PermissionException e) {
            checkPermission(scheduler.getSubject(), new NSAdminPermission(), "Resource Manager administrative rights is required");
        }
        if (loggersConfiguration != null) {
            for (Map.Entry<String, String> entry : loggersConfiguration.entrySet()) {
                Logger loggerInstance;
                String name = entry.getKey();
                String level = entry.getValue();
                if (name == null) {
                    loggerInstance = Logger.getRootLogger();
                } else {
                    loggerInstance = Logger.getLogger(name);
                }
                if (loggerInstance == null) {
                    throw new RestException("No logger found with name " + name);
                }
                Level levelInstance = Level.toLevel(level, Level.INFO);
                Level effectiveLevel = loggerInstance.getEffectiveLevel();
                if (levelInstance.toInt() != effectiveLevel.toInt()) {
                    logger.info("Changing logger " + name + " to " + levelInstance.toString());
                    levelChanged = true;
                } else {
                    logger.debug("Logger " + name + " is already on level " + levelInstance.toString());
                }
                loggerInstance.setLevel(levelInstance);
            }
        }
        return levelChanged;
    } catch (PermissionException e) {
        throw new PermissionRestException("Resource Manager administrative rights is required");
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(YOU_ARE_NOT_CONNECTED_TO_THE_SCHEDULER_YOU_SHOULD_LOG_ON_FIRST);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) RestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Logger(org.apache.log4j.Logger) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) Level(org.apache.log4j.Level)

Example 19 with RestException

use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException in project scheduling by ow2-proactive.

the class CommonRest method getCurrentLoggers.

@Override
public Map<String, String> getCurrentLoggers(String sessionId) throws RestException {
    Scheduler scheduler = checkAccess(sessionId);
    try {
        try {
            checkPermission(scheduler.getSubject(), new RMCoreAllPermission(), "Resource Manager administrative rights is required");
        } catch (PermissionException e) {
            checkPermission(scheduler.getSubject(), new NSAdminPermission(), "Resource Manager administrative rights is required");
        }
        Map<String, String> loggers = new LinkedHashMap<>();
        Enumeration loggerEnumeration = LogManager.getCurrentLoggers();
        while (loggerEnumeration.hasMoreElements()) {
            Object loggerObject = loggerEnumeration.nextElement();
            if (loggerObject != null && loggerObject instanceof Logger) {
                Logger loggerInstance = (Logger) loggerObject;
                if (loggerInstance.getName() != null && loggerInstance.getLevel() != null) {
                    loggers.put(loggerInstance.getName(), loggerInstance.getLevel().toString());
                }
            }
        }
        return loggers;
    } catch (PermissionException e) {
        throw new PermissionRestException("Resource Manager administrative rights is required");
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(YOU_ARE_NOT_CONNECTED_TO_THE_SCHEDULER_YOU_SHOULD_LOG_ON_FIRST);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Logger(org.apache.log4j.Logger) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)

Example 20 with RestException

use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException in project scheduling by ow2-proactive.

the class CommonRest method setLogLevel.

@Override
public boolean setLogLevel(String sessionId, String name, String level) throws RestException {
    Scheduler scheduler = checkAccess(sessionId);
    boolean levelChanged;
    try {
        checkPermission(scheduler.getSubject(), new RMCoreAllPermission(), "Resource Manager administrative rights is required");
        Logger loggerInstance;
        if (name == null) {
            loggerInstance = Logger.getRootLogger();
        } else {
            loggerInstance = Logger.getLogger(name);
        }
        if (loggerInstance == null) {
            throw new RestException("No logger found with name " + name);
        }
        Level levelInstance = Level.toLevel(level, Level.INFO);
        Level effectiveLevel = loggerInstance.getEffectiveLevel();
        if (levelInstance.toInt() != effectiveLevel.toInt()) {
            logger.info("Changing logger " + name + " to " + levelInstance.toString());
            levelChanged = true;
        } else {
            logger.warn("Logger " + name + " is already on level " + levelInstance.toString());
            levelChanged = false;
        }
        loggerInstance.setLevel(levelInstance);
        return levelChanged;
    } catch (PermissionException e) {
        throw new PermissionRestException("Resource Manager administrative rights is required");
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(YOU_ARE_NOT_CONNECTED_TO_THE_SCHEDULER_YOU_SHOULD_LOG_ON_FIRST);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) RestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Level(org.apache.log4j.Level) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Logger(org.apache.log4j.Logger)

Aggregations

NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)8 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)7 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)7 HttpSession (javax.servlet.http.HttpSession)6 RestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException)6 Logger (org.apache.log4j.Logger)5 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)5 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)5 Session (org.ow2.proactive_grid_cloud_portal.common.Session)5 SchedulerRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException)3 URISyntaxException (java.net.URISyntaxException)2 KeyException (java.security.KeyException)2 ArrayList (java.util.ArrayList)2 LoginException (javax.security.auth.login.LoginException)2 Level (org.apache.log4j.Level)2 RMException (org.ow2.proactive.resourcemanager.exception.RMException)2 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)2 Page (org.ow2.proactive.scheduler.common.Page)2 TaskStatesPage (org.ow2.proactive.scheduler.common.task.TaskStatesPage)2 SchedulerProxyUserInterface (org.ow2.proactive.scheduler.common.util.SchedulerProxyUserInterface)2