Search in sources :

Example 21 with Monitor

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;
}
Also used : Monitor(org.datatransferproject.api.launcher.Monitor) RememberTheMilkTasksExporter(org.datatransferproject.transfer.rememberthemilk.tasks.RememberTheMilkTasksExporter) RememberTheMilkTasksImporter(org.datatransferproject.transfer.rememberthemilk.tasks.RememberTheMilkTasksImporter) AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) IOException(java.io.IOException)

Example 22 with Monitor

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();
}
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 23 with Monitor

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);
}
Also used : LocalJobStore(org.datatransferproject.cloud.local.LocalJobStore) Monitor(org.datatransferproject.api.launcher.Monitor) PublicKeySerializer(org.datatransferproject.spi.transfer.security.PublicKeySerializer) Scheduler(com.google.common.util.concurrent.AbstractScheduledService.Scheduler) ExtensionContext(org.datatransferproject.api.launcher.ExtensionContext) Before(org.junit.Before)

Example 24 with Monitor

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);
}
Also used : TemporaryPerJobDataStore(org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore) AlbumListResponse(org.datatransferproject.datatransfer.google.mediaModels.AlbumListResponse) InputStreamWrapper(org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore.InputStreamWrapper) Monitor(org.datatransferproject.api.launcher.Monitor) Optional(java.util.Optional) GoogleCredentialFactory(org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) MediaItemSearchResponse(org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse) Before(org.junit.Before)

Example 25 with Monitor

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);
}
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)

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