Search in sources :

Example 6 with PortabilityJob

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

the class GooglePhotosImporterTest method retrieveAlbumStringOnlyOnce.

@Test
public void retrieveAlbumStringOnlyOnce() throws PermissionDeniedException, InvalidTokenException, IOException {
    String albumId = "Album Id";
    String albumName = "Album Name";
    String albumDescription = "Album Description";
    PhotoAlbum albumModel = new PhotoAlbum(albumId, albumName, albumDescription);
    PortabilityJob portabilityJob = Mockito.mock(PortabilityJob.class);
    Mockito.when(portabilityJob.userLocale()).thenReturn("it");
    JobStore jobStore = Mockito.mock(JobStore.class);
    Mockito.when(jobStore.findJob(uuid)).thenReturn(portabilityJob);
    GoogleAlbum responseAlbum = new GoogleAlbum();
    responseAlbum.setId(NEW_ALBUM_ID);
    Mockito.when(googlePhotosInterface.createAlbum(any(GoogleAlbum.class))).thenReturn(responseAlbum);
    GooglePhotosImporter sut = new GooglePhotosImporter(null, jobStore, null, null, googlePhotosInterface, imageStreamProvider, monitor, 1.0);
    sut.importSingleAlbum(uuid, null, albumModel);
    sut.importSingleAlbum(uuid, null, albumModel);
    Mockito.verify(jobStore, atMostOnce()).findJob(uuid);
}
Also used : PortabilityJob(org.datatransferproject.spi.cloud.types.PortabilityJob) LocalJobStore(org.datatransferproject.cloud.local.LocalJobStore) JobStore(org.datatransferproject.spi.cloud.storage.JobStore) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) GoogleAlbum(org.datatransferproject.datatransfer.google.mediaModels.GoogleAlbum) Test(org.junit.Test)

Example 7 with PortabilityJob

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

the class GooglePhotosImporterTest method importAlbumWithITString.

@Test
public void importAlbumWithITString() throws PermissionDeniedException, InvalidTokenException, IOException {
    String albumId = "Album Id";
    String albumName = "Album Name";
    String albumDescription = "Album Description";
    PhotoAlbum albumModel = new PhotoAlbum(albumId, albumName, albumDescription);
    PortabilityJob portabilityJob = Mockito.mock(PortabilityJob.class);
    Mockito.when(portabilityJob.userLocale()).thenReturn("it");
    JobStore jobStore = Mockito.mock(JobStore.class);
    Mockito.when(jobStore.findJob(uuid)).thenReturn(portabilityJob);
    GoogleAlbum responseAlbum = new GoogleAlbum();
    responseAlbum.setId(NEW_ALBUM_ID);
    Mockito.when(googlePhotosInterface.createAlbum(any(GoogleAlbum.class))).thenReturn(responseAlbum);
    GooglePhotosImporter sut = new GooglePhotosImporter(null, jobStore, null, null, googlePhotosInterface, imageStreamProvider, monitor, 1.0);
    sut.importSingleAlbum(uuid, null, albumModel);
    ArgumentCaptor<GoogleAlbum> albumArgumentCaptor = ArgumentCaptor.forClass(GoogleAlbum.class);
    Mockito.verify(googlePhotosInterface).createAlbum(albumArgumentCaptor.capture());
    assertEquals(albumArgumentCaptor.getValue().getTitle(), albumName);
}
Also used : PortabilityJob(org.datatransferproject.spi.cloud.types.PortabilityJob) LocalJobStore(org.datatransferproject.cloud.local.LocalJobStore) JobStore(org.datatransferproject.spi.cloud.storage.JobStore) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) GoogleAlbum(org.datatransferproject.datatransfer.google.mediaModels.GoogleAlbum) Test(org.junit.Test)

Example 8 with PortabilityJob

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

the class AzureTableStore method updateJob.

@Override
protected void updateJob(UUID jobId, PortabilityJob job, JobUpdateValidator validator) throws IOException {
    Preconditions.checkNotNull(jobId, "Job is null");
    Preconditions.checkNotNull(job, "Job is null");
    try {
        CloudTable table = tableClient.getTableReference(JOB_TABLE);
        String serializedJob = configuration.getMapper().writeValueAsString(job);
        DataWrapper wrapper = new DataWrapper(configuration.getPartitionKey(), jobId.toString(), job.jobAuthorization().state().name(), serializedJob);
        if (validator != null) {
            PortabilityJob previousJob = findJob(jobId);
            if (previousJob == null) {
                throw new IOException("Could not find record for jobId: " + jobId);
            }
            validator.validate(previousJob, job);
        }
        TableOperation insert = TableOperation.insertOrReplace(wrapper);
        table.execute(insert);
    } catch (JsonProcessingException | StorageException | URISyntaxException e) {
        throw new IOException("Error updating job: " + jobId, e);
    }
}
Also used : PortabilityJob(org.datatransferproject.spi.cloud.types.PortabilityJob) TableOperation(com.microsoft.azure.storage.table.TableOperation) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) CloudTable(com.microsoft.azure.storage.table.CloudTable) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StorageException(com.microsoft.azure.storage.StorageException)

Example 9 with PortabilityJob

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

the class GoogleJobStore method updateJob.

/**
 * Verifies a {@code PortabilityJob} already exists for {@code jobId}, and updates the entry to
 * {@code job}, within a {@code Transaction}. If {@code validator} is non-null,
 * validator.validate() is called first in the transaction.
 *
 * @throws IOException if a job didn't already exist for {@code jobId} or there was a problem
 *     updating it @throws IllegalStateException if validator.validate() failed
 */
@Override
protected void updateJob(UUID jobId, PortabilityJob job, JobUpdateValidator validator) throws IOException {
    Preconditions.checkNotNull(jobId);
    Transaction transaction = datastore.newTransaction();
    Key key = getJobKey(jobId);
    try {
        Entity previousEntity = transaction.get(key);
        if (previousEntity == null) {
            throw new IOException("Could not find record for jobId: " + jobId);
        }
        if (validator != null) {
            PortabilityJob previousJob = PortabilityJob.fromMap(getProperties(previousEntity));
            validator.validate(previousJob, job);
        }
        Entity newEntity = createUpdatedEntity(key, job.toMap());
        transaction.put(newEntity);
        transaction.commit();
    } catch (Throwable t) {
        transaction.rollback();
        throw new IOException("Failed atomic update of jobId: " + jobId, t);
    }
}
Also used : Entity(com.google.cloud.datastore.Entity) PortabilityJob(org.datatransferproject.spi.cloud.types.PortabilityJob) Transaction(com.google.cloud.datastore.Transaction) IOException(java.io.IOException) Key(com.google.cloud.datastore.Key)

Example 10 with PortabilityJob

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

the class LocalJobStore method updateJob.

/**
 * Verifies a {@code PortabilityJob} already exists for {@code jobId}, and updates the entry to
 * {@code job}. If {@code validator} is non-null, validator.validate() is called first, as part of
 * the atomic update.
 *
 * @throws IOException if a job didn't already exist for {@code jobId} or there was a problem
 *     updating it
 * @throws IllegalStateException if validator.validate() failed
 */
@Override
protected synchronized void updateJob(UUID jobId, PortabilityJob job, JobUpdateValidator validator) throws IOException {
    Preconditions.checkNotNull(jobId);
    try {
        Map<String, Object> previousEntry = JOB_MAP.replace(jobId, job.toMap());
        if (previousEntry == null) {
            throw new IOException("jobId: " + jobId + " didn't exist in the map");
        }
        if (validator != null) {
            PortabilityJob previousJob = PortabilityJob.fromMap(previousEntry);
            validator.validate(previousJob, job);
        }
    } catch (NullPointerException | IllegalStateException e) {
        throw new IOException("Couldn't update jobId: " + jobId, e);
    }
}
Also used : PortabilityJob(org.datatransferproject.spi.cloud.types.PortabilityJob) IOException(java.io.IOException)

Aggregations

PortabilityJob (org.datatransferproject.spi.cloud.types.PortabilityJob)24 UUID (java.util.UUID)11 IOException (java.io.IOException)8 JobAuthorization (org.datatransferproject.spi.cloud.types.JobAuthorization)6 Test (org.junit.Test)6 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 SimpleDateFormat (java.text.SimpleDateFormat)3 TransferJob (org.datatransferproject.types.client.transfer.TransferJob)3 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)3 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)3 InOrder (org.mockito.InOrder)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DateFormat (java.text.DateFormat)2 SecretKey (javax.crypto.SecretKey)2 LocalJobStore (org.datatransferproject.cloud.local.LocalJobStore)2 GoogleAlbum (org.datatransferproject.datatransfer.google.mediaModels.GoogleAlbum)2 AuthDataGenerator (org.datatransferproject.spi.api.auth.AuthDataGenerator)2 JobStore (org.datatransferproject.spi.cloud.storage.JobStore)2 InputStreamWrapper (org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore.InputStreamWrapper)2