Search in sources :

Example 1 with LogLevelManager

use of com.emc.storageos.systemservices.impl.logsvc.LogLevelManager in project coprhd-controller by CoprHD.

the class LogService method getLogLevels.

/**
 * Get current logging levels for all services and virtual machines
 *
 * @brief Get current log levels
 * @param nodeIds The ids of the virtual machines for which log data is
 *            collected.
 *            Allowed values: standalone,vipr1,vipr2 etc
 * @param nodeNames The custom names of the vipr nodes for which log data is
 *            collected.
 *            Allowed values: standalone,vipr1,vipr2 etc
 * @param logNames The names of the log files to process.
 * @prereq none
 * @return A list of log levels
 * @throws WebApplicationException When an invalid request is made.
 */
@GET
@Path("log-levels/")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.SECURITY_ADMIN })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public LogLevels getLogLevels(@QueryParam(LogRequestParam.NODE_ID) List<String> nodeIds, @QueryParam(LogRequestParam.NODE_NAME) List<String> nodeNames, @QueryParam(LogRequestParam.LOG_NAME) List<String> logNames) throws WebApplicationException {
    _log.info("Received getloglevels request");
    enforceRunningRequestLimit();
    MediaType mediaType = getMediaType();
    _log.debug("Get MediaType in header");
    nodeIds = _coordinatorClientExt.combineNodeNamesWithNodeIds(nodeNames, nodeIds);
    // Validate the passed node ids.
    validateNodeIds(nodeIds);
    _log.debug("Validated requested nodes");
    // Validate the passed log names.
    validateNodeServices(logNames);
    if (logNames != null && logNames.removeAll(_exemptLogSvcs)) {
        throw APIException.badRequests.parameterIsNotValid("log name");
    }
    _log.debug("Validated requested services");
    // Create the log request info bean from the request data.
    LogLevelRequest logLevelReq = new LogLevelRequest(nodeIds, logNames, LogSeverity.NA, null, null);
    final LogLevelManager logLevelMgr = new LogLevelManager(logLevelReq, mediaType, _logSvcPropertiesLoader);
    try {
        runningRequests.incrementAndGet();
        return logLevelMgr.process();
    } finally {
        runningRequests.decrementAndGet();
    }
}
Also used : LogLevelRequest(com.emc.vipr.model.sys.logging.LogLevelRequest) MediaType(javax.ws.rs.core.MediaType) LogLevelManager(com.emc.storageos.systemservices.impl.logsvc.LogLevelManager) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with LogLevelManager

use of com.emc.storageos.systemservices.impl.logsvc.LogLevelManager 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();
}
Also used : LogLevelRequest(com.emc.vipr.model.sys.logging.LogLevelRequest) MediaType(javax.ws.rs.core.MediaType) LogLevelManager(com.emc.storageos.systemservices.impl.logsvc.LogLevelManager) LogSeverity(com.emc.vipr.model.sys.logging.LogSeverity) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 LogLevelManager (com.emc.storageos.systemservices.impl.logsvc.LogLevelManager)2 LogLevelRequest (com.emc.vipr.model.sys.logging.LogLevelRequest)2 Path (javax.ws.rs.Path)2 MediaType (javax.ws.rs.core.MediaType)2 LogSeverity (com.emc.vipr.model.sys.logging.LogSeverity)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1