use of org.datatransferproject.api.launcher.Monitor in project data-transfer-project by google.
the class RememberTheMilkTransferExtension method initialize.
@Override
public void initialize(ExtensionContext context) {
if (initialized)
return;
AppCredentials credentials;
try {
credentials = 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();
exporter = new RememberTheMilkTasksExporter(credentials);
importer = new RememberTheMilkTasksImporter(credentials, monitor);
initialized = true;
}
use of org.datatransferproject.api.launcher.Monitor 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();
}
use of org.datatransferproject.api.launcher.Monitor in project data-transfer-project by google.
the class JobPollingServiceTest method setUp.
@Before
public void setUp() {
store = new LocalJobStore();
PublicKeySerializer serializer = new PublicKeySerializer() {
@Override
public boolean canHandle(String scheme) {
return true;
}
@Override
public String serialize(byte[] encodedPublicKey) throws SecurityException {
return "key";
}
};
Scheduler scheduler = Scheduler.newFixedDelaySchedule(0, 20, TimeUnit.SECONDS);
Monitor monitor = new Monitor() {
};
ExtensionContext extensionContext = mock(ExtensionContext.class);
when(extensionContext.getSetting("credTimeoutSeconds", 300)).thenReturn(300);
jobPollingService = new JobPollingService(store, asymmetricKeyGenerator, serializer, scheduler, monitor, extensionContext);
}
use of org.datatransferproject.api.launcher.Monitor in project data-transfer-project by google.
the class GooglePhotosExporterTest method setup.
@Before
public void setup() throws IOException, InvalidTokenException, PermissionDeniedException {
GoogleCredentialFactory credentialFactory = mock(GoogleCredentialFactory.class);
jobStore = mock(TemporaryPerJobDataStore.class);
when(jobStore.getStream(any(), anyString())).thenReturn(mock(InputStreamWrapper.class));
photosInterface = mock(GooglePhotosInterface.class);
albumListResponse = mock(AlbumListResponse.class);
mediaItemSearchResponse = mock(MediaItemSearchResponse.class);
Monitor monitor = mock(Monitor.class);
googlePhotosExporter = new GooglePhotosExporter(credentialFactory, jobStore, new JacksonFactory(), photosInterface, monitor);
when(photosInterface.listAlbums(any(Optional.class))).thenReturn(albumListResponse);
when(photosInterface.listMediaItems(any(Optional.class), any(Optional.class))).thenReturn(mediaItemSearchResponse);
verifyNoInteractions(credentialFactory);
}
use of org.datatransferproject.api.launcher.Monitor 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);
}
Aggregations