CloudSdkServiceUserSettings.getInstance().setUserCancelledInstallation(true); ManagedCloudSdkServiceUiPresenter.getInstance().notifyManagedSdkJobCancellation(jobType); } else { logger.warn("Error while installing/updating managed Cloud SDK", throwable); ManagedCloudSdkServiceUiPresenter.getInstance() .notifyManagedSdkJobFailure(jobType, throwable.toString());
}; Notification updateNotification = ManagedCloudSdkServiceUiPresenter.getInstance() .notifyManagedSdkUpdate(cancelListener, disableUpdateListener);
private void executeWithSdkWriteLock(ThrowableRunnable<Exception> runWithLock) throws Exception { try { // if write lock is not available, show a progress to a user that all SDK processes must be // finished in order to update SDK. if (!CloudSdkServiceManager.getInstance().getSdkWriteLock().tryLock()) { ProgressListener waitForSdkProcessesProgress = ManagedCloudSdkServiceUiPresenter.getInstance().createProgressListener(this); waitForSdkProcessesProgress.start( CloudSdkMessageBundle.message("managedsdk.progress.wait.for.processes"), ProgressListener.UNKNOWN); try { CloudSdkServiceManager.getInstance().getSdkWriteLock().lockInterruptibly(); } finally { // make sure the indicator goes away in case of this job error/cancel waitForSdkProcessesProgress.done(); } } runWithLock.run(); } finally { CloudSdkServiceManager.getInstance().getSdkWriteLock().unlock(); } }
/** Creates managed SDK, installs if necessary, and checks for fatal errors. */ @VisibleForTesting void initManagedSdk() { try { managedCloudSdk = createManagedSdk(); // do not install SDK on activation if user cancelled installation once. if (!CloudSdkServiceUserSettings.getInstance().isUserCancelledInstallation()) { install(); } } catch (UnsupportedOsException ex) { logger.warn("Unsupported OS for Managed Cloud SDK", ex); updateStatus(SdkStatus.NOT_AVAILABLE); ManagedCloudSdkServiceUiPresenter.getInstance() .notifyManagedSdkJobFailure( ManagedSdkJobType.INSTALL, CloudSdkMessageBundle.message("managedsdk.unsupported.os")); } }
/** Installs core managed SDK if needed and returns its path if successful. */ private ManagedSdkJobResult installSdk() throws Exception { if (!safeCheckSdkStatus(() -> managedCloudSdk.isInstalled())) { ConsoleListener sdkConsoleListener = logger::debug; progressListener = ManagedCloudSdkServiceUiPresenter.getInstance().createProgressListener(this); notifySdkProcessingStarted(); executeWithSdkWriteLock( () -> managedCloudSdk.newInstaller().install(progressListener, sdkConsoleListener)); return ManagedSdkJobResult.PROCESSED; } return ManagedSdkJobResult.UP_TO_DATE; }
private ManagedSdkJobResult installAppEngineJavaComponent() throws Exception { if (!safeCheckSdkStatus(() -> managedCloudSdk.hasComponent(SdkComponent.APP_ENGINE_JAVA))) { ConsoleListener appEngineConsoleListener = logger::debug; progressListener = ManagedCloudSdkServiceUiPresenter.getInstance().createProgressListener(this); notifySdkProcessingStarted(); executeWithSdkWriteLock( () -> managedCloudSdk .newComponentInstaller() .installComponent( SdkComponent.APP_ENGINE_JAVA, progressListener, appEngineConsoleListener)); return ManagedSdkJobResult.PROCESSED; } else { return ManagedSdkJobResult.UP_TO_DATE; } }
private ManagedSdkJobResult updateManagedSdk() throws Exception { if (safeCheckSdkStatus(() -> managedCloudSdk.isInstalled()) && !safeCheckSdkStatus(() -> managedCloudSdk.isUpToDate())) { ConsoleListener sdkUpdateListener = logger::debug; progressListener = ManagedCloudSdkServiceUiPresenter.getInstance().createProgressListener(this); notifySdkProcessingStarted(); executeWithSdkWriteLock( () -> managedCloudSdk.newUpdater().update(progressListener, sdkUpdateListener)); return ManagedSdkJobResult.PROCESSED; } else { return ManagedSdkJobResult.UP_TO_DATE; } }
@Override public void onSuccess(ManagedSdkJobResult result) { logger.info( "Managed Google Cloud SDK successfully installed/updated at: " + getSdkHomePath()); updateStatus(SdkStatus.READY); if (result == ManagedSdkJobResult.PROCESSED) { ManagedCloudSdkUpdateService.getInstance().notifySdkUpdateCompleted(); String trackingEventAction; switch (jobType) { case UPDATE: trackingEventAction = GctTracking.MANAGED_SDK_SUCCESSFUL_UPDATE; break; default: trackingEventAction = GctTracking.MANAGED_SDK_SUCCESSFUL_INSTALL; break; } UsageTrackerService.getInstance().trackEvent(trackingEventAction).ping(); } ManagedCloudSdkServiceUiPresenter.getInstance().notifyManagedSdkJobSuccess(jobType, result); // no need to abstain from checking install status anymore after success. CloudSdkServiceUserSettings.getInstance().setUserCancelledInstallation(false); }