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;
}
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()));
}
}
Aggregations