Search in sources :

Example 6 with JobStore

use of org.datatransferproject.spi.cloud.storage.JobStore in project data-transfer-project by google.

the class WorkerMain method initialize.

public void initialize() {
    Monitor monitor = loadMonitor();
    SettingsExtension settingsExtension = getSettingsExtension();
    settingsExtension.initialize();
    WorkerExtensionContext extensionContext = new WorkerExtensionContext(settingsExtension, monitor);
    // TODO this should be moved into a service extension
    extensionContext.registerService(HttpTransport.class, new NetHttpTransport());
    extensionContext.registerService(OkHttpClient.class, new OkHttpClient.Builder().build());
    extensionContext.registerService(JsonFactory.class, new JacksonFactory());
    ServiceLoader.load(ServiceExtension.class).iterator().forEachRemaining(serviceExtension -> serviceExtension.initialize(extensionContext));
    // TODO: verify that this is the cloud extension that is specified in the configuration
    CloudExtension cloudExtension = getCloudExtension();
    cloudExtension.initialize(extensionContext);
    monitor.info(() -> "Using CloudExtension: " + cloudExtension.getClass().getName());
    JobStore jobStore = cloudExtension.getJobStore();
    extensionContext.registerService(JobStore.class, jobStore);
    extensionContext.registerService(TemporaryPerJobDataStore.class, jobStore);
    AppCredentialStore appCredentialStore = cloudExtension.getAppCredentialStore();
    extensionContext.registerService(AppCredentialStore.class, appCredentialStore);
    List<TransferExtension> transferExtensions = getTransferExtensions(monitor);
    // Load security extension and services
    SecurityExtension securityExtension = SecurityExtensionLoader.getSecurityExtension(extensionContext);
    monitor.info(() -> "Using SecurityExtension: " + securityExtension.getClass().getName());
    IdempotentImportExecutor idempotentImportExecutor = IdempotentImportExecutorLoader.load(extensionContext);
    monitor.info(() -> "Using IdempotentImportExecutor: " + idempotentImportExecutor.getClass().getName());
    // TODO: make configurable
    SymmetricKeyGenerator symmetricKeyGenerator = new AesSymmetricKeyGenerator(monitor);
    JobHooks jobHooks = loadJobHooks();
    Injector injector = null;
    try {
        injector = Guice.createInjector(new WorkerModule(extensionContext, cloudExtension, transferExtensions, securityExtension, idempotentImportExecutor, symmetricKeyGenerator, jobHooks));
    } catch (Exception e) {
        monitor.severe(() -> "Unable to initialize Guice in Worker", e);
        throw e;
    }
    worker = injector.getInstance(Worker.class);
    // Reset the JobMetadata in case set previously when running SingleVMMain
    JobMetadata.reset();
}
Also used : AppCredentialStore(org.datatransferproject.spi.cloud.storage.AppCredentialStore) JobHooks(org.datatransferproject.spi.transfer.hooks.JobHooks) JobHooksLoader.loadJobHooks(org.datatransferproject.spi.transfer.hooks.JobHooksLoader.loadJobHooks) JobStore(org.datatransferproject.spi.cloud.storage.JobStore) SecurityExtension(org.datatransferproject.spi.transfer.security.SecurityExtension) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) IdempotentImportExecutor(org.datatransferproject.spi.transfer.idempotentexecutor.IdempotentImportExecutor) SettingsExtension(org.datatransferproject.config.extension.SettingsExtension) SettingsExtensionLoader.getSettingsExtension(org.datatransferproject.config.extension.SettingsExtensionLoader.getSettingsExtension) MonitorLoader.loadMonitor(org.datatransferproject.launcher.monitor.MonitorLoader.loadMonitor) Monitor(org.datatransferproject.api.launcher.Monitor) CloudExtension(org.datatransferproject.spi.cloud.extension.CloudExtension) CloudExtensionLoader.getCloudExtension(org.datatransferproject.spi.cloud.extension.CloudExtensionLoader.getCloudExtension) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) SymmetricKeyGenerator(org.datatransferproject.security.SymmetricKeyGenerator) AesSymmetricKeyGenerator(org.datatransferproject.security.AesSymmetricKeyGenerator) Injector(com.google.inject.Injector) TransferExtension(org.datatransferproject.spi.transfer.extension.TransferExtension) AesSymmetricKeyGenerator(org.datatransferproject.security.AesSymmetricKeyGenerator)

Example 7 with JobStore

use of org.datatransferproject.spi.cloud.storage.JobStore in project data-transfer-project by google.

the class GooglePhotosImporterTest method importPhotoInTempStoreFailure.

@Test
public void importPhotoInTempStoreFailure() throws Exception {
    PhotoModel photoModel = new PhotoModel(PHOTO_TITLE, IMG_URI, PHOTO_DESCRIPTION, JPEG_MEDIA_TYPE, "oldPhotoID1", OLD_ALBUM_ID, true);
    Mockito.when(googlePhotosInterface.uploadPhotoContent(any())).thenThrow(new IOException("Unit Testing"));
    JobStore jobStore = Mockito.mock(LocalJobStore.class);
    Mockito.when(jobStore.getStream(any(), any())).thenReturn(new TemporaryPerJobDataStore.InputStreamWrapper(new ByteArrayInputStream("TestingBytes".getBytes())));
    Mockito.doNothing().when(jobStore).removeData(any(), anyString());
    GooglePhotosImporter googlePhotosImporter = new GooglePhotosImporter(null, jobStore, null, null, googlePhotosInterface, null, null, 1.0);
    BatchMediaItemResponse batchMediaItemResponse = new BatchMediaItemResponse(new NewMediaItemResult[] { buildMediaItemResult("token1", Code.OK_VALUE) });
    Mockito.when(googlePhotosInterface.createPhotos(any(NewMediaItemUpload.class))).thenReturn(batchMediaItemResponse);
    UUID jobId = UUID.randomUUID();
    googlePhotosImporter.importPhotoBatch(jobId, Mockito.mock(TokensAndUrlAuthData.class), Lists.newArrayList(photoModel), executor, NEW_ALBUM_ID);
    Mockito.verify(jobStore, Mockito.times(0)).removeData(any(), anyString());
    Mockito.verify(jobStore, Mockito.times(1)).getStream(any(), anyString());
}
Also used : TemporaryPerJobDataStore(org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore) BatchMediaItemResponse(org.datatransferproject.datatransfer.google.mediaModels.BatchMediaItemResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) TokensAndUrlAuthData(org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData) LocalJobStore(org.datatransferproject.cloud.local.LocalJobStore) JobStore(org.datatransferproject.spi.cloud.storage.JobStore) NewMediaItemUpload(org.datatransferproject.datatransfer.google.mediaModels.NewMediaItemUpload) IOException(java.io.IOException) UUID(java.util.UUID) Test(org.junit.Test)

Example 8 with JobStore

use of org.datatransferproject.spi.cloud.storage.JobStore in project data-transfer-project by google.

the class GooglePhotosImporterTest method setUp.

@Before
public void setUp() throws IOException, InvalidTokenException, PermissionDeniedException {
    googlePhotosInterface = Mockito.mock(GooglePhotosInterface.class);
    monitor = Mockito.mock(Monitor.class);
    executor = new InMemoryIdempotentImportExecutor(monitor);
    Mockito.when(googlePhotosInterface.makePostRequest(anyString(), any(), any(), eq(NewMediaItemResult.class))).thenReturn(Mockito.mock(NewMediaItemResult.class));
    JobStore jobStore = new LocalJobStore();
    InputStream inputStream = Mockito.mock(InputStream.class);
    imageStreamProvider = Mockito.mock(ImageStreamProvider.class);
    HttpURLConnection conn = Mockito.mock(HttpURLConnection.class);
    Mockito.when(imageStreamProvider.getConnection(anyString())).thenReturn(conn);
    Mockito.when(conn.getInputStream()).thenReturn(inputStream);
    Mockito.when(conn.getContentLengthLong()).thenReturn(32L);
    googlePhotosImporter = new GooglePhotosImporter(null, jobStore, null, null, googlePhotosInterface, imageStreamProvider, monitor, 1.0);
}
Also used : LocalJobStore(org.datatransferproject.cloud.local.LocalJobStore) Monitor(org.datatransferproject.api.launcher.Monitor) HttpURLConnection(java.net.HttpURLConnection) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NewMediaItemResult(org.datatransferproject.datatransfer.google.mediaModels.NewMediaItemResult) ImageStreamProvider(org.datatransferproject.transfer.ImageStreamProvider) LocalJobStore(org.datatransferproject.cloud.local.LocalJobStore) JobStore(org.datatransferproject.spi.cloud.storage.JobStore) InMemoryIdempotentImportExecutor(org.datatransferproject.spi.transfer.idempotentexecutor.InMemoryIdempotentImportExecutor) Before(org.junit.Before)

Example 9 with JobStore

use of org.datatransferproject.spi.cloud.storage.JobStore in project data-transfer-project by google.

the class GoogleTransferExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    // times.
    if (initialized)
        return;
    JobStore jobStore = context.getService(JobStore.class);
    HttpTransport httpTransport = context.getService(HttpTransport.class);
    JsonFactory jsonFactory = context.getService(JsonFactory.class);
    AppCredentials appCredentials;
    try {
        appCredentials = context.getService(AppCredentialStore.class).getAppCredentials("GOOGLE_KEY", "GOOGLE_SECRET");
    } catch (IOException e) {
        Monitor monitor = context.getMonitor();
        monitor.info(() -> "Unable to retrieve Google AppCredentials. Did you set GOOGLE_KEY and GOOGLE_SECRET?");
        return;
    }
    Monitor monitor = context.getMonitor();
    // Create the GoogleCredentialFactory with the given {@link AppCredentials}.
    GoogleCredentialFactory credentialFactory = new GoogleCredentialFactory(httpTransport, jsonFactory, appCredentials, monitor);
    ImmutableMap.Builder<String, Importer> importerBuilder = ImmutableMap.builder();
    importerBuilder.put("BLOBS", new DriveImporter(credentialFactory, jobStore, monitor));
    importerBuilder.put("CONTACTS", new GoogleContactsImporter(credentialFactory));
    importerBuilder.put("CALENDAR", new GoogleCalendarImporter(credentialFactory));
    importerBuilder.put("MAIL", new GoogleMailImporter(credentialFactory, monitor));
    importerBuilder.put("TASKS", new GoogleTasksImporter(credentialFactory));
    importerBuilder.put("PHOTOS", new GooglePhotosImporter(credentialFactory, jobStore, jsonFactory, monitor, context.getSetting("googleWritesPerSecond", 1.0)));
    importerBuilder.put("VIDEOS", new GoogleVideosImporter(appCredentials, jobStore, monitor));
    importerMap = importerBuilder.build();
    ImmutableMap.Builder<String, Exporter> exporterBuilder = ImmutableMap.builder();
    exporterBuilder.put("BLOBS", new DriveExporter(credentialFactory, jobStore, monitor));
    exporterBuilder.put("CONTACTS", new GoogleContactsExporter(credentialFactory));
    exporterBuilder.put("CALENDAR", new GoogleCalendarExporter(credentialFactory));
    exporterBuilder.put("MAIL", new GoogleMailExporter(credentialFactory));
    exporterBuilder.put("SOCIAL-POSTS", new GooglePlusExporter(credentialFactory));
    exporterBuilder.put("TASKS", new GoogleTasksExporter(credentialFactory, monitor));
    exporterBuilder.put("PHOTOS", new GooglePhotosExporter(credentialFactory, jobStore, jsonFactory, monitor));
    exporterBuilder.put("VIDEOS", new GoogleVideosExporter(credentialFactory, jsonFactory));
    exporterMap = exporterBuilder.build();
    initialized = true;
}
Also used : GoogleCalendarImporter(org.datatransferproject.datatransfer.google.calendar.GoogleCalendarImporter) GoogleTasksExporter(org.datatransferproject.datatransfer.google.tasks.GoogleTasksExporter) AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) GooglePhotosImporter(org.datatransferproject.datatransfer.google.photos.GooglePhotosImporter) JsonFactory(com.google.api.client.json.JsonFactory) GoogleMailImporter(org.datatransferproject.datatransfer.google.mail.GoogleMailImporter) GoogleCredentialFactory(org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory) GoogleCalendarExporter(org.datatransferproject.datatransfer.google.calendar.GoogleCalendarExporter) GoogleVideosExporter(org.datatransferproject.datatransfer.google.videos.GoogleVideosExporter) DriveExporter(org.datatransferproject.datatransfer.google.drive.DriveExporter) GoogleMailExporter(org.datatransferproject.datatransfer.google.mail.GoogleMailExporter) Exporter(org.datatransferproject.spi.transfer.provider.Exporter) GoogleTasksExporter(org.datatransferproject.datatransfer.google.tasks.GoogleTasksExporter) GooglePlusExporter(org.datatransferproject.datatransfer.google.gplus.GooglePlusExporter) GooglePhotosExporter(org.datatransferproject.datatransfer.google.photos.GooglePhotosExporter) GoogleContactsExporter(org.datatransferproject.datatransfer.google.contacts.GoogleContactsExporter) GoogleContactsExporter(org.datatransferproject.datatransfer.google.contacts.GoogleContactsExporter) Monitor(org.datatransferproject.api.launcher.Monitor) GooglePlusExporter(org.datatransferproject.datatransfer.google.gplus.GooglePlusExporter) GoogleVideosImporter(org.datatransferproject.datatransfer.google.videos.GoogleVideosImporter) GooglePhotosImporter(org.datatransferproject.datatransfer.google.photos.GooglePhotosImporter) GoogleContactsImporter(org.datatransferproject.datatransfer.google.contacts.GoogleContactsImporter) Importer(org.datatransferproject.spi.transfer.provider.Importer) GoogleMailImporter(org.datatransferproject.datatransfer.google.mail.GoogleMailImporter) GoogleCalendarImporter(org.datatransferproject.datatransfer.google.calendar.GoogleCalendarImporter) DriveImporter(org.datatransferproject.datatransfer.google.drive.DriveImporter) GoogleVideosImporter(org.datatransferproject.datatransfer.google.videos.GoogleVideosImporter) GoogleTasksImporter(org.datatransferproject.datatransfer.google.tasks.GoogleTasksImporter) GoogleContactsImporter(org.datatransferproject.datatransfer.google.contacts.GoogleContactsImporter) DriveImporter(org.datatransferproject.datatransfer.google.drive.DriveImporter) JobStore(org.datatransferproject.spi.cloud.storage.JobStore) GoogleVideosExporter(org.datatransferproject.datatransfer.google.videos.GoogleVideosExporter) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap) GooglePhotosExporter(org.datatransferproject.datatransfer.google.photos.GooglePhotosExporter) HttpTransport(com.google.api.client.http.HttpTransport) GoogleCalendarExporter(org.datatransferproject.datatransfer.google.calendar.GoogleCalendarExporter) GoogleTasksImporter(org.datatransferproject.datatransfer.google.tasks.GoogleTasksImporter) DriveExporter(org.datatransferproject.datatransfer.google.drive.DriveExporter) GoogleMailExporter(org.datatransferproject.datatransfer.google.mail.GoogleMailExporter)

Aggregations

JobStore (org.datatransferproject.spi.cloud.storage.JobStore)9 Monitor (org.datatransferproject.api.launcher.Monitor)5 LocalJobStore (org.datatransferproject.cloud.local.LocalJobStore)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 HttpTransport (com.google.api.client.http.HttpTransport)2 JsonFactory (com.google.api.client.json.JsonFactory)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 UUID (java.util.UUID)2 BatchMediaItemResponse (org.datatransferproject.datatransfer.google.mediaModels.BatchMediaItemResponse)2 GoogleAlbum (org.datatransferproject.datatransfer.google.mediaModels.GoogleAlbum)2 NewMediaItemUpload (org.datatransferproject.datatransfer.google.mediaModels.NewMediaItemUpload)2 PortabilityJob (org.datatransferproject.spi.cloud.types.PortabilityJob)2 KoofrClientFactory (org.datatransferproject.transfer.koofr.common.KoofrClientFactory)2 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)2 TokensAndUrlAuthData (org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)1