Search in sources :

Example 6 with ErrorDetail

use of org.datatransferproject.types.transfer.errors.ErrorDetail in project data-transfer-project by google.

the class GoogleJobStore method addErrorsToJob.

@Override
public void addErrorsToJob(UUID jobId, Collection<ErrorDetail> errors) throws IOException {
    if (errors == null || errors.isEmpty()) {
        return;
    }
    List<Entity> entities = new ArrayList<>();
    for (ErrorDetail errorDetail : errors) {
        Key key = getErrorKey(jobId, errorDetail.id());
        entities.add(GoogleCloudUtils.createEntityBuilder(key, ImmutableMap.of(JSON_DATA_FIELD, // TODO: encrypt this data
        objectMapper.writeValueAsString(errorDetail))).build());
    }
    datastore.add(entities.toArray(new Entity[entities.size()]));
}
Also used : ErrorDetail(org.datatransferproject.types.transfer.errors.ErrorDetail) Entity(com.google.cloud.datastore.Entity) ArrayList(java.util.ArrayList) Key(com.google.cloud.datastore.Key)

Example 7 with ErrorDetail

use of org.datatransferproject.types.transfer.errors.ErrorDetail in project data-transfer-project by google.

the class GoogleVideosImporterTest method failOneVideo.

@Test
public void failOneVideo() throws Exception {
    PhotosLibraryClient photosLibraryClient = mock(PhotosLibraryClient.class);
    // Mock uploads
    when(photosLibraryClient.uploadMediaItem(any())).thenReturn(UploadMediaItemResponse.newBuilder().setUploadToken("token1").build(), UploadMediaItemResponse.newBuilder().setUploadToken("token2").build());
    // Mock creation response
    final NewMediaItemResult newMediaItemResult = NewMediaItemResult.newBuilder().setStatus(Status.newBuilder().setCode(Code.OK_VALUE).build()).setMediaItem(MediaItem.newBuilder().setId("RESULT_ID_1").build()).setUploadToken("token1").build();
    final NewMediaItemResult newMediaItemResult2 = NewMediaItemResult.newBuilder().setStatus(Status.newBuilder().setCode(Code.INVALID_ARGUMENT_VALUE).build()).setUploadToken("token2").build();
    BatchCreateMediaItemsResponse response = BatchCreateMediaItemsResponse.newBuilder().addNewMediaItemResults(newMediaItemResult).addNewMediaItemResults(newMediaItemResult2).build();
    when(photosLibraryClient.batchCreateMediaItems(ArgumentMatchers.anyList())).thenReturn(response);
    InMemoryIdempotentImportExecutor executor = new InMemoryIdempotentImportExecutor(mock(Monitor.class));
    long length = googleVideosImporter.importVideoBatch(Lists.newArrayList(new VideoModel(VIDEO_TITLE, VIDEO_URI, VIDEO_DESCRIPTION, MP4_MEDIA_TYPE, VIDEO_ID, null, false), new VideoModel(VIDEO_TITLE, VIDEO_URI, VIDEO_DESCRIPTION, MP4_MEDIA_TYPE, "myId2", null, false)), photosLibraryClient, executor);
    assertEquals("Expected the number of bytes to be the one files of 32L.", 32L, length);
    assertEquals("Expected executor to have one error.", 1, executor.getErrors().size());
    ErrorDetail errorDetail = executor.getErrors().iterator().next();
    assertEquals("myId2", errorDetail.id());
    assertThat(errorDetail.exception(), CoreMatchers.containsString("Video item could not be created."));
}
Also used : ErrorDetail(org.datatransferproject.types.transfer.errors.ErrorDetail) Monitor(org.datatransferproject.api.launcher.Monitor) NewMediaItemResult(com.google.photos.library.v1.proto.NewMediaItemResult) BatchCreateMediaItemsResponse(com.google.photos.library.v1.proto.BatchCreateMediaItemsResponse) InMemoryIdempotentImportExecutor(org.datatransferproject.spi.transfer.idempotentexecutor.InMemoryIdempotentImportExecutor) PhotosLibraryClient(com.google.photos.library.v1.PhotosLibraryClient) VideoModel(org.datatransferproject.types.common.models.videos.VideoModel) Test(org.junit.Test)

Aggregations

ErrorDetail (org.datatransferproject.types.transfer.errors.ErrorDetail)7 IOException (java.io.IOException)3 Test (org.junit.Test)2 Entity (com.google.cloud.datastore.Entity)1 Key (com.google.cloud.datastore.Key)1 Stopwatch (com.google.common.base.Stopwatch)1 PhotosLibraryClient (com.google.photos.library.v1.PhotosLibraryClient)1 BatchCreateMediaItemsResponse (com.google.photos.library.v1.proto.BatchCreateMediaItemsResponse)1 NewMediaItemResult (com.google.photos.library.v1.proto.NewMediaItemResult)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 Monitor (org.datatransferproject.api.launcher.Monitor)1 BatchMediaItemResponse (org.datatransferproject.datatransfer.google.mediaModels.BatchMediaItemResponse)1 NewMediaItemUpload (org.datatransferproject.datatransfer.google.mediaModels.NewMediaItemUpload)1 JobAuthorization (org.datatransferproject.spi.cloud.types.JobAuthorization)1 PortabilityJob (org.datatransferproject.spi.cloud.types.PortabilityJob)1 InMemoryIdempotentImportExecutor (org.datatransferproject.spi.transfer.idempotentexecutor.InMemoryIdempotentImportExecutor)1 ImportResult (org.datatransferproject.spi.transfer.provider.ImportResult)1 AuthDataDecryptService (org.datatransferproject.spi.transfer.security.AuthDataDecryptService)1