Search in sources :

Example 6 with StartAdministrativeSessionPostConnectProcessor

use of com.unboundid.ldap.sdk.unboundidds.extensions.StartAdministrativeSessionPostConnectProcessor 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();
    }
}
Also used : StartAdministrativeSessionPostConnectProcessor(com.unboundid.ldap.sdk.unboundidds.extensions.StartAdministrativeSessionPostConnectProcessor) TimeWindowCollectSupportDataLogCaptureWindow(com.unboundid.ldap.sdk.unboundidds.extensions.TimeWindowCollectSupportDataLogCaptureWindow) LDAPConnectionPool(com.unboundid.ldap.sdk.LDAPConnectionPool) CollectSupportDataExtendedRequest(com.unboundid.ldap.sdk.unboundidds.extensions.CollectSupportDataExtendedRequest) NoOpRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.NoOpRequestControl) DurationCollectSupportDataLogCaptureWindow(com.unboundid.ldap.sdk.unboundidds.extensions.DurationCollectSupportDataLogCaptureWindow) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) IOException(java.io.IOException) Date(java.util.Date) Control(com.unboundid.ldap.sdk.Control) NoOpRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.NoOpRequestControl) StartAdministrativeSessionExtendedRequest(com.unboundid.ldap.sdk.unboundidds.extensions.StartAdministrativeSessionExtendedRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) CollectSupportDataExtendedRequestProperties(com.unboundid.ldap.sdk.unboundidds.extensions.CollectSupportDataExtendedRequestProperties) HeadAndTailSizeCollectSupportDataLogCaptureWindow(com.unboundid.ldap.sdk.unboundidds.extensions.HeadAndTailSizeCollectSupportDataLogCaptureWindow) File(java.io.File) ResultCode(com.unboundid.ldap.sdk.ResultCode) CollectSupportDataExtendedResult(com.unboundid.ldap.sdk.unboundidds.extensions.CollectSupportDataExtendedResult) NotNull(com.unboundid.util.NotNull)

Aggregations

LDAPException (com.unboundid.ldap.sdk.LDAPException)6 StartAdministrativeSessionExtendedRequest (com.unboundid.ldap.sdk.unboundidds.extensions.StartAdministrativeSessionExtendedRequest)6 StartAdministrativeSessionPostConnectProcessor (com.unboundid.ldap.sdk.unboundidds.extensions.StartAdministrativeSessionPostConnectProcessor)6 NotNull (com.unboundid.util.NotNull)6 LDAPConnectionPool (com.unboundid.ldap.sdk.LDAPConnectionPool)5 ResultCode (com.unboundid.ldap.sdk.ResultCode)5 IOException (java.io.IOException)5 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)4 ArgumentException (com.unboundid.util.args.ArgumentException)4 Control (com.unboundid.ldap.sdk.Control)3 FixedRateBarrier (com.unboundid.util.FixedRateBarrier)3 Filter (com.unboundid.ldap.sdk.Filter)2 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)2 LDAPSearchException (com.unboundid.ldap.sdk.LDAPSearchException)2 AssertionRequestControl (com.unboundid.ldap.sdk.controls.AssertionRequestControl)2 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)2 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)2 ProxiedAuthorizationV1RequestControl (com.unboundid.ldap.sdk.controls.ProxiedAuthorizationV1RequestControl)2 ProxiedAuthorizationV2RequestControl (com.unboundid.ldap.sdk.controls.ProxiedAuthorizationV2RequestControl)2 SimplePagedResultsControl (com.unboundid.ldap.sdk.controls.SimplePagedResultsControl)2