Search in sources :

Example 16 with Monitor

use of org.datatransferproject.api.launcher.Monitor in project data-transfer-project by google.

the class KoofrVideosImporterTest method setUp.

@Before
public void setUp() throws Exception {
    server = new MockWebServer();
    server.start();
    client = mock(KoofrClient.class);
    clientFactory = mock(KoofrClientFactory.class);
    when(clientFactory.create(any())).thenReturn(client);
    monitor = mock(Monitor.class);
    importer = new KoofrVideosImporter(clientFactory, monitor);
    executor = mock(IdempotentImportExecutor.class);
    when(executor.executeAndSwallowIOExceptions(any(), any(), any())).then((InvocationOnMock invocation) -> {
        Callable<String> callable = invocation.getArgument(2);
        return callable.call();
    });
    authData = new TokensAndUrlAuthData("acc", "refresh", "");
}
Also used : KoofrClientFactory(org.datatransferproject.transfer.koofr.common.KoofrClientFactory) Monitor(org.datatransferproject.api.launcher.Monitor) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MockWebServer(okhttp3.mockwebserver.MockWebServer) KoofrClient(org.datatransferproject.transfer.koofr.common.KoofrClient) TokensAndUrlAuthData(org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData) IdempotentImportExecutor(org.datatransferproject.spi.transfer.idempotentexecutor.IdempotentImportExecutor) Before(org.junit.Before)

Example 17 with Monitor

use of org.datatransferproject.api.launcher.Monitor in project data-transfer-project by google.

the class KoofrTransferExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    // rather than throwing if called multiple times.
    if (initialized)
        return;
    JobStore jobStore = context.getService(JobStore.class);
    HttpTransport httpTransport = context.getService(HttpTransport.class);
    JsonFactory jsonFactory = context.getService(JsonFactory.class);
    OkHttpClient client = new OkHttpClient.Builder().build();
    ObjectMapper mapper = new ObjectMapper();
    AppCredentials appCredentials;
    try {
        appCredentials = context.getService(AppCredentialStore.class).getAppCredentials("KOOFR_KEY", "KOOFR_SECRET");
    } catch (IOException e) {
        Monitor monitor = context.getMonitor();
        monitor.info(() -> "Unable to retrieve Koofr AppCredentials. Did you set KOOFR_KEY and KOOFR_SECRET?");
        return;
    }
    // Create the KoofrCredentialFactory with the given {@link AppCredentials}.
    KoofrCredentialFactory credentialFactory = new KoofrCredentialFactory(httpTransport, jsonFactory, appCredentials);
    Monitor monitor = context.getMonitor();
    int fileUploadReadTimeout = context.getSetting("koofrFileUploadReadTimeout", 60000);
    int fileUploadWriteTimeout = context.getSetting("koofrFileUploadWriteTimeout", 60000);
    monitor.info(() -> format("Configuring Koofr HTTP file upload client with read timeout %d ms and write timeout %d ms", fileUploadReadTimeout, fileUploadWriteTimeout));
    OkHttpClient fileUploadClient = client.newBuilder().readTimeout(fileUploadReadTimeout, TimeUnit.MILLISECONDS).writeTimeout(fileUploadReadTimeout, TimeUnit.MILLISECONDS).build();
    KoofrClientFactory koofrClientFactory = new KoofrClientFactory(BASE_API_URL, client, fileUploadClient, mapper, monitor, credentialFactory);
    ImmutableMap.Builder<String, Importer> importBuilder = ImmutableMap.builder();
    importBuilder.put(PHOTOS, new KoofrPhotosImporter(koofrClientFactory, monitor, jobStore));
    importBuilder.put(VIDEOS, new KoofrVideosImporter(koofrClientFactory, monitor));
    importerMap = importBuilder.build();
    ImmutableMap.Builder<String, Exporter> exportBuilder = ImmutableMap.builder();
    exportBuilder.put(PHOTOS, new KoofrPhotosExporter(koofrClientFactory, monitor));
    exportBuilder.put(VIDEOS, new KoofrVideosExporter(koofrClientFactory, monitor));
    exporterMap = exportBuilder.build();
    initialized = true;
}
Also used : KoofrPhotosExporter(org.datatransferproject.transfer.koofr.photos.KoofrPhotosExporter) OkHttpClient(okhttp3.OkHttpClient) KoofrClientFactory(org.datatransferproject.transfer.koofr.common.KoofrClientFactory) AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) KoofrCredentialFactory(org.datatransferproject.transfer.koofr.common.KoofrCredentialFactory) JsonFactory(com.google.api.client.json.JsonFactory) JobStore(org.datatransferproject.spi.cloud.storage.JobStore) KoofrVideosImporter(org.datatransferproject.transfer.koofr.videos.KoofrVideosImporter) IOException(java.io.IOException) Exporter(org.datatransferproject.spi.transfer.provider.Exporter) KoofrPhotosExporter(org.datatransferproject.transfer.koofr.photos.KoofrPhotosExporter) KoofrVideosExporter(org.datatransferproject.transfer.koofr.videos.KoofrVideosExporter) ImmutableMap(com.google.common.collect.ImmutableMap) HttpTransport(com.google.api.client.http.HttpTransport) KoofrPhotosImporter(org.datatransferproject.transfer.koofr.photos.KoofrPhotosImporter) Monitor(org.datatransferproject.api.launcher.Monitor) KoofrVideosExporter(org.datatransferproject.transfer.koofr.videos.KoofrVideosExporter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) KoofrVideosImporter(org.datatransferproject.transfer.koofr.videos.KoofrVideosImporter) Importer(org.datatransferproject.spi.transfer.provider.Importer) KoofrPhotosImporter(org.datatransferproject.transfer.koofr.photos.KoofrPhotosImporter)

Example 18 with Monitor

use of org.datatransferproject.api.launcher.Monitor in project data-transfer-project by google.

the class RememberTheMilkAuthServiceExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    if (initialized)
        return;
    AppCredentials appCredentials;
    try {
        appCredentials = context.getService(AppCredentialStore.class).getAppCredentials(RTM_KEY, RTM_SECRET);
    } catch (IOException e) {
        Monitor monitor = context.getMonitor();
        monitor.info(() -> format("Unable to retrieve RememberTheMilk AppCredentials. Did you set %s and %s?", RTM_KEY, RTM_SECRET), e);
        return;
    }
    Monitor monitor = context.getMonitor();
    importAuthDataGenerator = new RememberTheMilkAuthDataGenerator(appCredentials, AuthMode.IMPORT, monitor);
    exportAuthDataGenerator = new RememberTheMilkAuthDataGenerator(appCredentials, AuthMode.EXPORT, monitor);
    initialized = true;
}
Also used : Monitor(org.datatransferproject.api.launcher.Monitor) AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) IOException(java.io.IOException)

Example 19 with Monitor

use of org.datatransferproject.api.launcher.Monitor in project data-transfer-project by google.

the class GoogleCloudExtension method initialize.

/*
   * Initializes the GoogleCloudExtension based on the ExtensionContext.
   */
@Override
public void initialize(ExtensionContext context) {
    Preconditions.checkArgument(!initialized, "Attempting to initialize GoogleCloudExtension more than once");
    HttpTransport httpTransport = context.getService(HttpTransport.class);
    JsonFactory jsonFactory = context.getService(JsonFactory.class);
    ObjectMapper objectMapper = context.getTypeManager().getMapper();
    String cloud = context.cloud();
    Constants.Environment environment = context.environment();
    Monitor monitor = context.getMonitor();
    GoogleCloudExtensionModule module = new GoogleCloudExtensionModule(httpTransport, jsonFactory, objectMapper, cloud, environment, monitor);
    injector = Guice.createInjector(module);
    initialized = true;
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) Monitor(org.datatransferproject.api.launcher.Monitor) JsonFactory(com.google.api.client.json.JsonFactory) Constants(org.datatransferproject.api.launcher.Constants) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 20 with Monitor

use of org.datatransferproject.api.launcher.Monitor in project data-transfer-project by google.

the class MicrosoftPhotosExporterTest method setUp.

@Before
public void setUp() throws IOException {
    MicrosoftCredentialFactory credentialFactory = mock(MicrosoftCredentialFactory.class);
    photosInterface = mock(MicrosoftPhotosInterface.class);
    driveItemsResponse = mock(MicrosoftDriveItemsResponse.class);
    Monitor monitor = mock(Monitor.class);
    microsoftPhotosExporter = new MicrosoftPhotosExporter(credentialFactory, new JacksonFactory(), photosInterface, monitor);
    when(photosInterface.getDriveItems(any(Optional.class), any(Optional.class))).thenReturn(driveItemsResponse);
    when(photosInterface.getDriveItemsFromSpecialFolder(any(MicrosoftSpecialFolder.FolderType.class))).thenReturn(driveItemsResponse);
    verifyNoInteractions(credentialFactory);
}
Also used : Monitor(org.datatransferproject.api.launcher.Monitor) Optional(java.util.Optional) MicrosoftCredentialFactory(org.datatransferproject.transfer.microsoft.common.MicrosoftCredentialFactory) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) Before(org.junit.Before)

Aggregations

Monitor (org.datatransferproject.api.launcher.Monitor)32 IOException (java.io.IOException)10 AppCredentials (org.datatransferproject.types.transfer.auth.AppCredentials)10 Before (org.junit.Before)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 HttpTransport (com.google.api.client.http.HttpTransport)7 ImmutableMap (com.google.common.collect.ImmutableMap)7 Importer (org.datatransferproject.spi.transfer.provider.Importer)7 TemporaryPerJobDataStore (org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore)6 JsonFactory (com.google.api.client.json.JsonFactory)5 JobStore (org.datatransferproject.spi.cloud.storage.JobStore)5 Exporter (org.datatransferproject.spi.transfer.provider.Exporter)5 TokensAndUrlAuthData (org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData)5 OkHttpClient (okhttp3.OkHttpClient)4 KoofrClientFactory (org.datatransferproject.transfer.koofr.common.KoofrClientFactory)4 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)3 MockWebServer (okhttp3.mockwebserver.MockWebServer)3 GoogleCredentialFactory (org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory)3 KoofrClient (org.datatransferproject.transfer.koofr.common.KoofrClient)3 Optional (java.util.Optional)2