Search in sources :

Example 1 with RetryException

use of org.datatransferproject.types.transfer.retry.RetryException in project data-transfer-project by google.

the class PortabilityAbstractInMemoryDataCopier method copyIteration.

protected ExportResult<?> copyIteration(UUID jobId, AuthData exportAuthData, AuthData importAuthData, Optional<ExportInformation> exportInformation, String jobIdPrefix, int copyIteration) throws CopyException {
    monitor.debug(() -> jobIdPrefix + "Copy iteration: " + copyIteration);
    RetryStrategyLibrary retryStrategyLibrary = retryStrategyLibraryProvider.get();
    monitor.debug(() -> jobIdPrefix + "Starting export, copy iteration: " + copyIteration, EventCode.COPIER_STARTED_EXPORT);
    CallableExporter callableExporter = new CallableExporter(exporterProvider, jobId, exportAuthData, exportInformation, metricRecorder);
    RetryingCallable<ExportResult> retryingExporter = new RetryingCallable<>(callableExporter, retryStrategyLibrary, Clock.systemUTC(), monitor, JobMetadata.getDataType(), JobMetadata.getExportService());
    ExportResult<?> exportResult;
    boolean exportSuccess = false;
    Stopwatch exportStopwatch = Stopwatch.createStarted();
    try {
        exportResult = retryingExporter.call();
        exportSuccess = exportResult.getType() != ExportResult.ResultType.ERROR;
    } catch (RetryException | RuntimeException e) {
        if (e.getClass() == RetryException.class && CopyExceptionWithFailureReason.class.isAssignableFrom(e.getCause().getClass())) {
            throw (CopyExceptionWithFailureReason) e.getCause();
        }
        throw new CopyException(jobIdPrefix + "Error happened during export", e);
    } finally {
        metricRecorder.exportPageFinished(JobMetadata.getDataType(), JobMetadata.getExportService(), exportSuccess, exportStopwatch.elapsed());
    }
    monitor.debug(() -> jobIdPrefix + "Finished export, copy iteration: " + copyIteration, EventCode.COPIER_FINISHED_EXPORT);
    if (exportResult.getExportedData() != null) {
        monitor.debug(() -> jobIdPrefix + "Starting import, copy iteration: " + copyIteration, EventCode.COPIER_STARTED_IMPORT);
        CallableImporter callableImporter = new CallableImporter(importerProvider, jobId, idempotentImportExecutor, importAuthData, exportResult.getExportedData(), metricRecorder);
        RetryingCallable<ImportResult> retryingImporter = new RetryingCallable<>(callableImporter, retryStrategyLibrary, Clock.systemUTC(), monitor, JobMetadata.getDataType(), JobMetadata.getImportService());
        boolean importSuccess = false;
        Stopwatch importStopwatch = Stopwatch.createStarted();
        try {
            ImportResult importResult = retryingImporter.call();
            importSuccess = importResult.getType() == ImportResult.ResultType.OK;
            if (importSuccess) {
                try {
                    jobStore.addCounts(jobId, importResult.getCounts().orElse(null));
                    jobStore.addBytes(jobId, importResult.getBytes().orElse(null));
                } catch (IOException e) {
                    monitor.debug(() -> jobIdPrefix + "Unable to add counts to job: ", e);
                }
            }
        } catch (RetryException | RuntimeException e) {
            if (e.getClass() == RetryException.class && CopyExceptionWithFailureReason.class.isAssignableFrom(e.getCause().getClass())) {
                throw (CopyExceptionWithFailureReason) e.getCause();
            }
            throw new CopyException(jobIdPrefix + "Error happened during import", e);
        } finally {
            metricRecorder.importPageFinished(JobMetadata.getDataType(), JobMetadata.getImportService(), importSuccess, importStopwatch.elapsed());
        }
        monitor.debug(() -> jobIdPrefix + "Finished import, copy iteration: " + copyIteration, EventCode.COPIER_FINISHED_IMPORT);
    }
    return exportResult;
}
Also used : CopyException(org.datatransferproject.spi.transfer.types.CopyException) ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) RetryingCallable(org.datatransferproject.types.transfer.retry.RetryingCallable) CallableImporter(org.datatransferproject.transfer.CallableImporter) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) RetryException(org.datatransferproject.types.transfer.retry.RetryException) CallableExporter(org.datatransferproject.transfer.CallableExporter) RetryStrategyLibrary(org.datatransferproject.types.transfer.retry.RetryStrategyLibrary) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)1 IOException (java.io.IOException)1 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)1 ImportResult (org.datatransferproject.spi.transfer.provider.ImportResult)1 CopyException (org.datatransferproject.spi.transfer.types.CopyException)1 CallableExporter (org.datatransferproject.transfer.CallableExporter)1 CallableImporter (org.datatransferproject.transfer.CallableImporter)1 RetryException (org.datatransferproject.types.transfer.retry.RetryException)1 RetryStrategyLibrary (org.datatransferproject.types.transfer.retry.RetryStrategyLibrary)1 RetryingCallable (org.datatransferproject.types.transfer.retry.RetryingCallable)1