use of com.emc.storageos.systemservices.impl.logsvc.stream.LogNetworkReader 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.storageos.systemservices.impl.logsvc.stream.LogNetworkReader in project coprhd-controller by CoprHD.
the class LogNetworkReaderPerfTest method testPerformance.
@Test
public void testPerformance() throws Exception {
List<String> svcs = new ArrayList<String>() {
{
add("controllersvc");
add("coordinatorsvc");
add("apisvc");
}
};
int bufSize = 1024 * 64;
LogRequest req = new LogRequest.Builder().baseNames(svcs).build();
final LogNetworkWriter writer = new LogNetworkWriter(req, propertiesLoader);
try (final PipedOutputStream out = new PipedOutputStream();
final BufferedOutputStream outputStream = new BufferedOutputStream(out, bufSize);
final PipedInputStream inputStream = new PipedInputStream(out)) {
LogNetworkReader reader = new LogNetworkReader("vipr1", "vipr1", inputStream, new LogStatusInfo());
long totalSize = 0;
long startTime = System.nanoTime();
new Thread(new Runnable() {
public void run() {
try {
writer.write(outputStream);
} catch (Exception e) {
// NOSONAR
e.printStackTrace();
// ("squid:S1148 suppress sonar warning on printStackTrace. It's a test case and exceptions are meant to be printed to stdout/stderr")
}
}
}).start();
LogMessage log = null;
while ((log = reader.readNextLogMessage()) != null) {
totalSize += log.toStringOriginalFormat().getBytes().length;
}
long endTime = System.nanoTime();
totalSize /= (1024L * 1024L);
double elapsedTime = (double) (endTime - startTime) / 1000000000.0;
System.out.println("Total read " + totalSize + " MB;" + " Used " + elapsedTime + " sec; Average " + (totalSize / elapsedTime) + " MB/sec.");
}
}
Aggregations