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