Search in sources :

Example 6 with JobAuthorization

use of org.datatransferproject.spi.cloud.types.JobAuthorization in project data-transfer-project by google.

the class StartTransferJobAction method updateJobWithCredentials.

/**
 * Encrypt the export and import credentials with a new {@link SecretKey} and {@link PublicKey}
 * assigned to this job then update the data store to {@link JobAuthorization.State#CREDS_STORED}
 * state.
 */
private PortabilityJob updateJobWithCredentials(UUID jobId, PortabilityJob job, String authData) {
    // Populate job with encrypted auth data
    JobAuthorization updatedJobAuthorization = job.jobAuthorization().toBuilder().setEncryptedAuthData(authData).setState(CREDS_STORED).build();
    job = job.toBuilder().setAndValidateJobAuthorization(updatedJobAuthorization).build();
    monitor.debug(() -> format("Updating job %s from CREDS_ENCRYPTION_KEY_GENERATED to CREDS_STORED", jobId), jobId);
    try {
        jobStore.updateJobWithCredentials(jobId, job);
        monitor.debug(() -> format("Updated job %s to CREDS_STORED", jobId), jobId, EventCode.API_JOB_CREDS_STORED);
    } catch (IOException e) {
        throw new RuntimeException("Unable to update job", e);
    }
    return job;
}
Also used : JobAuthorization(org.datatransferproject.spi.cloud.types.JobAuthorization) IOException(java.io.IOException)

Example 7 with JobAuthorization

use of org.datatransferproject.spi.cloud.types.JobAuthorization in project data-transfer-project by google.

the class JobPollingService method pollUntilJobIsReady.

/**
 * Polls for job with populated auth data and stops this service when found.
 */
private void pollUntilJobIsReady() {
    monitor.debug(() -> "pollUntilJobIsReady");
    UUID jobId = JobMetadata.getJobId();
    PortabilityJob job = store.findJob(jobId);
    if (job == null) {
        monitor.severe(() -> format("Could not poll job %s, it was not present in the key-value store", jobId), EventCode.WORKER_JOB_ERRORED);
        this.stopAsync();
    } else if (job.state() == PortabilityJob.State.CANCELED) {
        monitor.info(() -> format("Could not poll job %s, it was cancelled", jobId), EventCode.WORKER_JOB_CANCELED);
        this.stopAsync();
    } else if (job.jobAuthorization().state() == JobAuthorization.State.CREDS_STORED) {
        monitor.debug(() -> format("Polled job %s in state CREDS_STORED", jobId));
        JobAuthorization jobAuthorization = job.jobAuthorization();
        if (!Strings.isNullOrEmpty(jobAuthorization.encryptedAuthData())) {
            monitor.debug(() -> format("Polled job %s has auth data as expected. Done polling.", jobId), EventCode.WORKER_CREDS_STORED);
        } else {
            monitor.severe(() -> format("Polled job %s does not have auth data as expected. " + "Done polling this job since it's in a bad state! Starting over.", jobId), EventCode.WORKER_JOB_ERRORED);
        }
        this.stopAsync();
    } else {
        monitor.debug(() -> format("Polling job %s until it's in state CREDS_STORED. " + "It's currently in state: %s", jobId, job.jobAuthorization().state()));
    }
}
Also used : PortabilityJob(org.datatransferproject.spi.cloud.types.PortabilityJob) JobAuthorization(org.datatransferproject.spi.cloud.types.JobAuthorization) UUID(java.util.UUID)

Aggregations

JobAuthorization (org.datatransferproject.spi.cloud.types.JobAuthorization)7 PortabilityJob (org.datatransferproject.spi.cloud.types.PortabilityJob)5 IOException (java.io.IOException)2 UUID (java.util.UUID)2 AuthDataDecryptService (org.datatransferproject.spi.transfer.security.AuthDataDecryptService)1 CopyException (org.datatransferproject.spi.transfer.types.CopyException)1 CopyExceptionWithFailureReason (org.datatransferproject.spi.transfer.types.CopyExceptionWithFailureReason)1 ExportInformation (org.datatransferproject.types.common.ExportInformation)1 AuthData (org.datatransferproject.types.transfer.auth.AuthData)1 AuthDataPair (org.datatransferproject.types.transfer.auth.AuthDataPair)1 ErrorDetail (org.datatransferproject.types.transfer.errors.ErrorDetail)1 Test (org.junit.Test)1