use of com.emc.vipr.model.sys.logging.LogSeverity in project coprhd-controller by CoprHD.
the class LogService method setLogLevels.
/**
* Update log levels
*
* @brief Update log levels
* @param param The parameters required to update the log levels, including:
* node_id: optional, a list of node ids to be updated.
* All the nodes in the cluster will be updated by default
* log_name: optional, a list of service names to be updated.
* All the services will be updated by default
* severity: required, an int indicating the new log level.
* Refer to {@LogSeverity} for a full list of log levels.
* For log4j(the default logging implementation of ViPR),
* only the following values are valid:
* * 0 (FATAL)
* * 4 (ERROR)
* * 5 (WARN)
* * 7 (INFO)
* * 8 (DEBUG)
* * 9 (TRACE)
* @prereq none
* @return server response indicating if the operation succeeds.
* @throws WebApplicationException When an invalid request is made.
* @see LogSeverity
*/
@POST
@Path("log-levels/")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.SECURITY_ADMIN })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response setLogLevels(SetLogLevelParam param) throws WebApplicationException {
_log.info("Received setloglevels request");
enforceRunningRequestLimit();
MediaType mediaType = getMediaType();
_log.debug("Get MediaType {} in header", mediaType);
// get nodeIds for node names
List<String> nodeIds = _coordinatorClientExt.combineNodeNamesWithNodeIds(param.getNodeNames(), param.getNodeIds());
param.setNodeIds(nodeIds);
// Validate the passed node ids.
validateNodeIds(param.getNodeIds());
_log.debug("Validated requested nodes: {}", param.getNodeIds());
// Validate the passed log names.
validateNodeServices(param.getLogNames());
if (param.getLogNames() != null && param.getLogNames().removeAll(_exemptLogSvcs)) {
throw APIException.badRequests.parameterIsNotValid("log name");
}
_log.debug("Validated requested services: {}", param.getLogNames());
// Validate the passed severity is valid.
if (param.getSeverity() == null) {
throw APIException.badRequests.invalidSeverityInURI("null", VALID_LOG4J_SEVS.toString());
}
LogSeverity logSeverity = validateLogSeverity(param.getSeverity());
if (!VALID_LOG4J_SEVS.contains(logSeverity)) {
throw APIException.badRequests.invalidSeverityInURI(logSeverity.toString(), VALID_LOG4J_SEVS.toString());
}
_log.debug("Validated requested severity: {}", param.getSeverity());
// Validate the passed expiration time is valid.
if (param.getExpirInMin() != null && (param.getExpirInMin() < 0 || param.getExpirInMin() >= MAX_LOG_LEVEL_EXPIR)) {
throw APIException.badRequests.parameterNotWithinRange("expir_in_min", param.getExpirInMin(), 0, MAX_LOG_LEVEL_EXPIR, "");
}
_log.debug("Validated requested expiration: {}", param.getExpirInMin());
// Validate the passed log level scope value.
String scopeLevel = validateLogScope(param.getScope());
_log.debug("Validated requested scope: {}", param.getScope());
// Create the log request info bean from the request data.
LogLevelRequest logLevelReq = new LogLevelRequest(param.getNodeIds(), param.getLogNames(), logSeverity, param.getExpirInMin(), scopeLevel);
final LogLevelManager logLevelMgr = new LogLevelManager(logLevelReq, mediaType, _logSvcPropertiesLoader);
try {
runningRequests.incrementAndGet();
logLevelMgr.process();
} finally {
runningRequests.decrementAndGet();
}
return Response.ok().build();
}
Aggregations