use of com.emc.vipr.model.sys.logging.LogLevelRequest in project coprhd-controller by CoprHD.
the class LogLevelManager method propagate.
// Building the internal log URI for each node and calling using client
// Collecting streams from all nodes - if any node does not send response,
// logging error.
private LogLevels propagate(List<NodeInfo> nodeInfos, List<String> logNames, LogSeverity severity, int expirInMin, String scope) {
LogLevels nodeLogLevels = new LogLevels();
for (final NodeInfo node : nodeInfos) {
String baseNodeURL = String.format(BASE_URL_FORMAT, node.getIpAddress(), node.getPort());
_log.debug("processing node: " + baseNodeURL);
SysClientFactory.SysClient sysClient = SysClientFactory.getSysClient(URI.create(baseNodeURL), _propertiesLoader.getNodeLogCollectorTimeout() * 1000, _propertiesLoader.getNodeLogConnectionTimeout() * 1000);
try {
LogLevelRequest nodeLogReqInfo = new LogLevelRequest(new ArrayList<String>() {
{
add(node.getId());
}
}, logNames, severity, expirInMin, scope);
LogLevels nodeResp = sysClient.post(SysClientFactory.URI_LOG_LEVELS, LogLevels.class, nodeLogReqInfo);
nodeLogLevels.getLogLevels().addAll(nodeResp.getLogLevels());
} catch (Exception e) {
_log.error("Exception accessing node {}:", baseNodeURL, e);
}
}
return nodeLogLevels;
}
use of com.emc.vipr.model.sys.logging.LogLevelRequest 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();
}
}
use of com.emc.vipr.model.sys.logging.LogLevelRequest 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();
}
use of com.emc.vipr.model.sys.logging.LogLevelRequest in project coprhd-controller by CoprHD.
the class LogLevelManager method process.
/**
* @throws APIException When an error occurs satisfying the log request.
*/
public LogLevels process() {
List<NodeInfo> nodeInfo;
int expirInMin;
// Getting all nodes information
if (_logReqInfo.getNodeIds().isEmpty()) {
_log.debug("No nodes specified, assuming all nodes");
nodeInfo = ClusterNodesUtil.getClusterNodeInfo();
} else {
nodeInfo = getClusterNodesWithIds(_logReqInfo.getNodeIds());
}
if (nodeInfo.isEmpty()) {
throw APIException.internalServerErrors.noNodeAvailableError("update log levels");
}
LogLevelRequest logLevelReq = (LogLevelRequest) _logReqInfo;
if (logLevelReq.getExpirInMin() == null) {
_log.debug("No expiration specified, asuming default value");
expirInMin = _propertiesLoader.getLogLevelExpiration();
} else {
expirInMin = logLevelReq.getExpirInMin();
}
return propagate(nodeInfo, _logReqInfo.getLogNames(), _logReqInfo.getSeverity(), expirInMin, logLevelReq.getScope());
}
Aggregations