use of com.unboundid.ldap.sdk.unboundidds.extensions.HeadAndTailSizeCollectSupportDataLogCaptureWindow in project ldapsdk by pingidentity.
the class CollectSupportData method doExtendedOperationProcessing.
/**
* Performs the collect-support-data processing against a remote server using
* the extended operation.
*
* @return A result code that indicates the result of the processing.
*/
@NotNull()
private ResultCode doExtendedOperationProcessing() {
// Create a connection pool that will be used to communicate with the
// server. Use an administrative session if appropriate.
final StartAdministrativeSessionPostConnectProcessor p;
if (useAdministrativeSessionArg.isPresent()) {
p = new StartAdministrativeSessionPostConnectProcessor(new StartAdministrativeSessionExtendedRequest(getToolName(), true));
} else {
p = null;
}
final LDAPConnectionPool pool;
try {
pool = getConnectionPool(1, 1, 0, p, null, true, new ReportBindResultLDAPConnectionPoolHealthCheck(this, true, false));
} catch (final LDAPException e) {
Debug.debugException(e);
wrapErr(0, WRAP_COLUMN, e.getMessage());
toolCompletionMessage.set(e.getMessage());
return e.getResultCode();
}
try {
// Create the properties to use for the extended request.
final CollectSupportDataExtendedRequestProperties properties = new CollectSupportDataExtendedRequestProperties();
final File outputPath = outputPathArg.getValue();
if (outputPath != null) {
if (!(outputPath.exists() && outputPath.isDirectory())) {
properties.setArchiveFileName(outputPath.getName());
}
}
try {
properties.setEncryptionPassphrase(getEncryptionPassphraseForExtOpProcessing());
} catch (final LDAPException e) {
Debug.debugException(e);
wrapErr(0, WRAP_COLUMN, e.getMessage());
toolCompletionMessage.set(e.getMessage());
return e.getResultCode();
}
properties.setIncludeExpensiveData(collectExpensiveDataArg.isPresent());
properties.setIncludeReplicationStateDump(collectReplicationStateDumpArg.isPresent());
properties.setIncludeBinaryFiles(includeBinaryFilesArg.isPresent());
properties.setIncludeExtensionSource(archiveExtensionSourceArg.isPresent());
properties.setUseSequentialMode(sequentialArg.isPresent());
if (securityLevelArg.isPresent()) {
properties.setSecurityLevel(CollectSupportDataSecurityLevel.forName(securityLevelArg.getValue()));
}
if (jstackCountArg.isPresent()) {
properties.setJStackCount(jstackCountArg.getValue());
}
if (reportCountArg.isPresent()) {
properties.setReportCount(reportCountArg.getValue());
}
if (reportIntervalSecondsArg.isPresent()) {
properties.setReportIntervalSeconds(reportIntervalSecondsArg.getValue());
}
if (logTimeRangeArg.isPresent()) {
try {
final ObjectPair<Date, Date> timeRange = parseTimeRange(logTimeRangeArg.getValue(), true);
properties.setLogCaptureWindow(new TimeWindowCollectSupportDataLogCaptureWindow(timeRange.getFirst(), timeRange.getSecond()));
} catch (final LDAPException e) {
// This should never happen because we should have pre-validated the
// value. But handle it just in case.
Debug.debugException(e);
wrapErr(0, WRAP_COLUMN, e.getMessage());
toolCompletionMessage.set(e.getMessage());
return e.getResultCode();
}
} else if (logDurationArg.isPresent()) {
properties.setLogCaptureWindow(new DurationCollectSupportDataLogCaptureWindow(logDurationArg.getValue(TimeUnit.MILLISECONDS)));
} else if (logFileHeadCollectionSizeKBArg.isPresent() || logFileTailCollectionSizeKBArg.isPresent()) {
properties.setLogCaptureWindow(new HeadAndTailSizeCollectSupportDataLogCaptureWindow(logFileHeadCollectionSizeKBArg.getValue(), logFileTailCollectionSizeKBArg.getValue()));
}
if (commentArg.isPresent()) {
properties.setComment(commentArg.getValue());
}
if (proxyToServerAddressArg.isPresent()) {
properties.setProxyToServer(proxyToServerAddressArg.getValue(), proxyToServerPortArg.getValue());
}
// Create the intermediate response listener that will be used to handle
// output and archive fragment messages.
ResultCode resultCode = null;
try (CollectSupportDataIRListener listener = new CollectSupportDataIRListener(this, outputPathArg.getValue())) {
// Construct the extended request to send to the server.
final Control[] controls;
if (dryRunArg.isPresent()) {
controls = new Control[] { new NoOpRequestControl() };
} else {
controls = StaticUtils.NO_CONTROLS;
}
final CollectSupportDataExtendedRequest request = new CollectSupportDataExtendedRequest(properties, listener, controls);
request.setResponseTimeoutMillis(0L);
// Send the request and read the result.
final CollectSupportDataExtendedResult result;
try {
result = (CollectSupportDataExtendedResult) pool.processExtendedOperation(request);
} catch (final LDAPException e) {
Debug.debugException(e);
final String message = ERR_CSD_ERROR_SENDING_REQUEST.get(StaticUtils.getExceptionMessage(e));
wrapErr(0, WRAP_COLUMN, message);
toolCompletionMessage.set(message);
return e.getResultCode();
}
resultCode = result.getResultCode();
final String diagnosticMessage = result.getDiagnosticMessage();
if (diagnosticMessage != null) {
if ((resultCode == ResultCode.SUCCESS) || (resultCode == ResultCode.NO_OPERATION)) {
wrapOut(0, WRAP_COLUMN, diagnosticMessage);
} else {
wrapErr(0, WRAP_COLUMN, diagnosticMessage);
}
toolCompletionMessage.set(diagnosticMessage);
} else {
toolCompletionMessage.set(INFO_CSD_COMPLETED_WITH_RESULT_CODE.get(String.valueOf(resultCode)));
}
} catch (final IOException e) {
Debug.debugException(e);
if (resultCode == ResultCode.SUCCESS) {
resultCode = ResultCode.LOCAL_ERROR;
toolCompletionMessage.set(e.getMessage());
}
}
return resultCode;
} finally {
pool.close();
}
}
Aggregations