use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.
the class LogNetworkStreamMerger method getLogNetworkStreams.
private List<LogNetworkReader> getLogNetworkStreams() {
List<NodeInfo> nodeInfo;
List<LogNetworkReader> logNetworkStreams = new ArrayList<>();
// Getting all nodes information
if (request.getNodeIds().isEmpty()) {
logger.info("No nodes specified, getting all nodes");
nodeInfo = ClusterNodesUtil.getClusterNodeInfo();
} else {
nodeInfo = getClusterNodesWithIds(request.getNodeIds());
}
if (nodeInfo.isEmpty()) {
throw APIException.internalServerErrors.noNodeAvailableError("collect logs info");
}
List<String> failedNodes = ClusterNodesUtil.getUnavailableControllerNodes();
if (!request.getNodeIds().isEmpty()) {
failedNodes.retainAll(request.getNodeIds());
}
if (!failedNodes.isEmpty()) {
logger.error("Cannot collect logs from unavailable nodes: {}", failedNodes.toString());
}
for (final NodeInfo node : nodeInfo) {
LogRequest req;
SysClientFactory.SysClient sysClient;
String baseNodeURL = String.format(SysClientFactory.BASE_URL_FORMAT, node.getIpAddress(), node.getPort());
logger.debug("getting stream from node: " + baseNodeURL);
logger.debug("connectTimeout=" + propertiesLoader.getNodeLogConnectionTimeout() * 1000);
logger.debug("readTimeout=" + propertiesLoader.getNodeLogCollectorTimeout() * 1000);
sysClient = SysClientFactory.getSysClient(URI.create(baseNodeURL), propertiesLoader.getNodeLogCollectorTimeout() * 1000, propertiesLoader.getNodeLogConnectionTimeout() * 1000);
logger.debug("sysclient=" + sysClient + " uri=" + URI.create(baseNodeURL));
try {
req = request;
req.setNodeIds(new ArrayList<String>() {
{
add(node.getId());
}
});
InputStream nodeResponseStream = sysClient.post(SysClientFactory.URI_NODE_LOGS, InputStream.class, req);
if (nodeResponseStream != null && nodeResponseStream.available() > 0) {
LogNetworkReader reader = new LogNetworkReader(node.getId(), node.getName(), nodeResponseStream, status);
logNetworkStreams.add(reader);
}
} catch (Exception e) {
logger.error("Exception accessing node {}:", baseNodeURL, e);
// socketTimeoutException wrapped in ClientHandlerException
if (e.getCause() != null && e.getCause().getCause() instanceof SocketTimeoutException) {
throw InternalServerErrorException.internalServerErrors.logCollectionTimeout();
}
}
}
return logNetworkStreams;
}
use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.
the class SysLogReaderTest method testLogCountSysParser.
/**
* Test if reader could recognize the correct count of system logs
*/
@Test
public void testLogCountSysParser() throws Exception {
System.out.println("starting testLogCountSysParser");
LogStatusInfo status = new LogStatusInfo();
final int WARN = 5;
// four kinds of different patterns in file
String filePath = "src/main/data/testReaderData/testSyslogParser.log";
long logCount = 47;
LogReader reader = null;
LogRequest req = new LogRequest.Builder().logLevel(WARN).build();
reader = new LogReader(filePath, req, status, null);
while (true) {
LogMessage log = reader.readNextLogMessage();
if (log == null) {
assertEquals("Log count should match", logCount, reader.getLogCount());
break;
}
}
System.out.println("done testLogCountSysParser");
}
use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.
the class SysLogReaderTest method testLogStatusInfo.
/**
* Test if reader could record correct status information
*/
@Test
public void testLogStatusInfo() throws Exception {
System.out.println("starting testLogStatusInfo");
LogStatusInfo status = new LogStatusInfo();
String filePath = "src/main/data/testReaderData/testStatus.log";
long logCount = 42;
LogReader reader = null;
LogRequest req = new LogRequest.Builder().build();
reader = new LogReader(filePath, req, status, null);
while (true) {
LogMessage log = reader.readNextLogMessage();
if (log == null) {
assertEquals("Log count should match", logCount, reader.getLogCount());
break;
}
}
BufferedReader br = new BufferedReader(new FileReader("src/main/data/testReaderData/testStatusResult.log"));
String line = br.readLine();
int index = 0;
while (line != null) {
assertTrue("status's size is not correct!", status.getStatus().size() > index);
assertEquals("status's contect is not correct!", line, status.getStatus().get(index));
index++;
line = br.readLine();
}
assertEquals("status's size is not correct!", status.getStatus().size(), index);
br.close();
System.out.println("done testLogStatusInfo");
}
use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.
the class SysLogReaderTest method testPriority.
/**
* Test if priority value is corrtect
*/
@Test
public void testPriority() throws Exception {
System.out.println("starting testPriority");
LogSyslogParser parser = new LogSyslogParser();
LogRequest req = new LogRequest.Builder().build();
String log1 = "2014-03-13 15:12:56 [auth] notice sudo: storageos : ";
String log2 = "2014-03-13 15:36:26 [syslog] info syslog-ng[4043]";
String log3 = "2014-03-13 16:27:54 [local7] warning NTP: [CONFIGURED, DEGRADED]";
String log4 = "2014-03-11 17:12:30 [user] err auditd: ";
String log5 = "2014-03-12 00:00:02 [mail] crit sendmail[10183]: NOQUEUE: SYSERR(root)";
assertTrue(LogSeverity.toLevel(new String(parser.parseLine(log1, req).getLevel())) == 6);
assertTrue(LogSeverity.toLevel(new String(parser.parseLine(log2, req).getLevel())) == 7);
assertTrue(LogSeverity.toLevel(new String(parser.parseLine(log3, req).getLevel())) == 5);
assertTrue(LogSeverity.toLevel(new String(parser.parseLine(log4, req).getLevel())) == 4);
assertTrue(LogSeverity.toLevel(new String(parser.parseLine(log5, req).getLevel())) == 3);
System.out.println("done testPriority");
}
use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.
the class LogStreamPerfTest method testPerformance.
@Test
public void testPerformance() throws Exception {
List<File> files = new ArrayList<>();
files.add(new File("/opt/storageos/logs/testData/controllersvc.log"));
files.add(new File("/opt/storageos/logs/testData/controllersvc.log.20131120-163817.gz"));
LogRequest req = new LogRequest.Builder().build();
LogStatusInfo status = new LogStatusInfo();
LogFileStream stream = new LogFileStream("", files, req, status);
long startTime = 0;
long endTime = 0;
startTime = System.nanoTime();
while (true) {
LogMessage log = stream.readNextLogMessage();
if (log == null) {
endTime = System.nanoTime();
break;
}
}
double elapsedTime = (double) (endTime - startTime) / 1000000000.0;
double speed = 1510.8 / elapsedTime;
System.out.println("Total read 1510.8 MB; Used " + elapsedTime + " sec; Average " + speed + " MB/sec.");
}
Aggregations