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;
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations