@Nullable private Path getJavaToolsBasePath() { CloudSdkService cloudSdkService = CloudSdkService.getInstance(); return cloudSdkService.getSdkHomePath() != null ? cloudSdkService.getSdkHomePath().resolve(JAVA_TOOLS_RELATIVE_PATH.toString()) : null; }
/** Checks the current SDK status after waiting for readiness, notifies and logs about errors. */ private void handleErrors(CloudSdkStatusHandler sdkLogging) { // check the status of SDK after install. SdkStatus postInstallSdkStatus = CloudSdkService.getInstance().getStatus(); switch (postInstallSdkStatus) { case READY: // can continue without logging anything. break; case INSTALLING: // still installing, do nothing, up to caller to decide which message to show. break; case NOT_AVAILABLE: case INVALID: String message; NotificationType notificationType; boolean fatalSdkError = !CloudSdkService.getInstance().isInstallSupported(); if (fatalSdkError) { message = CloudSdkMessageBundle.message("managedsdk.not.available"); notificationType = NotificationType.ERROR; } else { message = sdkLogging.getErrorMessage(postInstallSdkStatus); notificationType = NotificationType.WARNING; } sdkLogging.onError(message); showCloudSdkNotification(message, notificationType); break; default: // do nothing, no error, not ready. } }
/** Callback when a user selected and applied a new cloud sdk type. */ public void onNewCloudSdkServiceTypeSelected(CloudSdkServiceType newServiceType) { if (supportedCloudSdkServices.containsKey(newServiceType)) { supportedCloudSdkServices.get(newServiceType).activate(); } else { throw new UnsupportedCloudSdkTypeException(newServiceType.name()); } }
/** Checks if current SDK service is currently installing and not ready for operations. */ private boolean isInstallInProgress() { return CloudSdkService.getInstance().getStatus() == SdkStatus.INSTALLING; }
private void mockSdkStatusChange(SdkStatus fromStatus, SdkStatus toStatus) { when(mockSdkService.getStatus()).thenReturn(fromStatus); when(mockSdkService.isInstallSupported()).thenReturn(true); // the only way to enable READY status before blocking on the same thread test thread starts. doAnswer( invocation -> { ((SdkStatusUpdateListener) invocation.getArgument(0)) .onSdkStatusChange(mockSdkService, toStatus); when(mockSdkService.getStatus()).thenReturn(toStatus); return null; }) .when(mockSdkService) .addStatusUpdateListener(any()); } }
String progressMessage, CloudSdkStatusHandler sdkLogging) { CloudSdkService cloudSdkService = CloudSdkService.getInstance(); if (cloudSdkService.isInstallSupported()) { cloudSdkService.install(); cloudSdkService.addStatusUpdateListener(sdkStatusUpdateListener); sdkLogging.log(CloudSdkMessageBundle.getString("managedsdk.waiting.for.sdk.ready") + "\n");
@Test public void checkConfiguration_when_sdkSupportsInstallation_doesNotThrowException() { setUpValidFlexConfiguration(); when(mockSdkService.getStatus()).thenReturn(SdkStatus.NOT_AVAILABLE); when(mockSdkService.isInstallSupported()).thenReturn(true); when(mockSdkValidator.validateCloudSdk()).thenReturn(ImmutableSet.of(CLOUD_SDK_NOT_FOUND)); try { configuration.checkConfiguration(mockRemoteServer, mockAppEngineDeployable, project); } catch (RuntimeConfigurationException e) { throw new AssertionError("installable SDK should not be validated", e); } }
@Before public void setUp() throws Exception { when(service.getSdkHomePath()).thenReturn(Paths.get("/home/path")); when(cloudSdkServiceManager.getCloudSdkService()).thenReturn(service); doReturn(mockSdk).when(sdkValidator).buildCloudSdkWithPath(any(Path.class)); }
private void setManagedSdkUiAvailable(boolean available) { if (ServiceManager.getService(PluginInfoService.class).shouldEnable(GctFeature.MANAGED_SDK)) { enableAutomaticUpdatesCheckbox.setEnabled(available); // only make it visible if managed SDK is active, not currently installing or updating, and // not up-to-date. if (available && CloudSdkServiceUserSettings.getInstance().getUserSelectedSdkServiceType() == CloudSdkServiceType.MANAGED_SDK) { ManagedCloudSdkService managedCloudSdkService = (ManagedCloudSdkService) CloudSdkService.getInstance(); updateNowButton.setEnabled( managedCloudSdkService.getStatus() == SdkStatus.READY && !managedCloudSdkService.isUpToDate()); } else { updateNowButton.setEnabled(false); } } }
@Test public void waitFor_when_sdkInstallNotSupported_showsFatalErrorNotification() throws InterruptedException { mockSdkStatusChange(SdkStatus.NOT_AVAILABLE, SdkStatus.NOT_AVAILABLE); when(mockSdkService.isInstallSupported()).thenReturn(false); cloudSdkServiceManager.blockUntilSdkReady(mockProject, "", mockStatusHandler); ApplicationManager.getApplication() .invokeAndWait( () -> verify(cloudSdkServiceManager) .showCloudSdkNotification( CloudSdkMessageBundle.message("managedsdk.not.available"), NotificationType.ERROR)); }
/** * Waits in background for Cloud SDK to be ready for all operations and then runs the given * runnable. If process results in error or user cancel, shows notification and does not run. This * method does not block and must be called from application UI thread. * * @param project Project to which runnable belongs. * @param afterSdkReady Runnable to execute after Cloud SDK is ready. This runnable will be * executed on the application UI thread. * @param progressMessage Message to show in progress dialog to identify which process is * starting, i.e. deployment or local server. * @param sdkStatusHandler Logger for errors etc. */ public void runWhenSdkReady( @Nullable Project project, @NotNull Runnable afterSdkReady, String progressMessage, CloudSdkStatusHandler sdkStatusHandler) { doWait( project, () -> { // at this point the installation should be either ready, failed or user cancelled. // run only if ready. if (CloudSdkService.getInstance().getStatus() == SdkStatus.READY) { ApplicationManager.getApplication().invokeLater(afterSdkReady); } }, progressMessage, sdkStatusHandler); }
@Test public void testDisplayableSdkVersion_isEmpty_whenSdkIsInvalid() { when(sdkService.getSdkHomePath()).thenReturn(missingCloudSdk.toPath()); feedbackAction.actionPerformed(null /*event*/); String expected = "- Google Cloud SDK version: \n"; verify(browserLauncher).browse(urlContains(expected), eq(null), eq(null)); }
private static ApplicationServer getOrCreateAppServer() { final CloudSdkService sdkService = CloudSdkService.getInstance(); if (sdkService == null) { return null; } final AppEngineServerIntegration integration = AppEngineServerIntegration.getInstance(); // There are no distinguishing features about the App Engine servers so just return // the first one found final List<ApplicationServer> servers = ApplicationServersManager.getInstance().getApplicationServers(integration); // make sure no servers are recently disposed (see #2326) servers.removeIf(server -> !server.isDisposed()); if (!servers.isEmpty()) { return servers.iterator().next(); } return ApplicationServersManager.getInstance() .createServer(integration, new JavaeePersistentData()); }
/** Checks if the default SDK stored path contains a valid Cloud SDK. */ public Set<CloudSdkValidationResult> validateCloudSdk() { CloudSdkService instance = CloudSdkService.getInstance(); return validateCloudSdk(instance != null ? instance.getSdkHomePath() : null); }
private void checkCommonConfig(AppEngineDeployable deployable) throws RuntimeConfigurationError { // do not check SDK if it supports dynamic install - the deployment runner will block itself // until installation is done. CloudSdkService cloudSdkService = CloudSdkService.getInstance(); SdkStatus sdkStatus = cloudSdkService.getStatus(); if (sdkStatus != SdkStatus.READY && !cloudSdkService.isInstallSupported()) { Set<CloudSdkValidationResult> sdkValidationResult = CloudSdkValidator.getInstance().validateCloudSdk(); if (!sdkValidationResult.isEmpty()) { CloudSdkValidationResult result = Iterables.getFirst(sdkValidationResult, null); throw new RuntimeConfigurationError( AppEngineMessageBundle.message( "appengine.flex.config.server.error", result.getMessage())); } } check( deployable instanceof UserSpecifiedPathDeploymentSource || deployable.isValid(), "appengine.config.deployment.source.error"); check( StringUtils.isNotBlank(cloudProjectName), "appengine.flex.config.project.missing.message"); }
@Test public void managedSdk_feature_notEnabled_customSdk_validationLabel_present() { when(mockPluginInfoService.shouldEnable(GctFeature.MANAGED_SDK)).thenReturn(false); when(mockCloudSdkService.getSdkHomePath()).thenReturn(Paths.get("/some/sdk")); when(mockCloudSdkValidator.validateCloudSdk(any())) .thenReturn(ImmutableSet.of(CloudSdkValidationResult.CLOUD_SDK_NOT_FOUND)); AppEngineCloudConfigurable appEngineCloudConfigurable = new AppEngineCloudConfigurable(); assertThat(appEngineCloudConfigurable.getSdkValidationErrorLabel().isVisible()).isTrue(); assertThat(appEngineCloudConfigurable.getSdkValidationErrorLabel().getText()) .contains("Cloud SDK home directory is not specified."); }
private void doUpdate() { CloudSdkService cloudSdkService = CloudSdkService.getInstance(); if (cloudSdkService instanceof ManagedCloudSdkService) { updateNotification.expire(); CloudSdkService afterNotificationCloudSdkService = CloudSdkService.getInstance(); if (afterNotificationCloudSdkService instanceof ManagedCloudSdkService) { ((ManagedCloudSdkService) afterNotificationCloudSdkService).update();
@Override public void initComponent() { if (!ApplicationManager.getApplication().isUnitTestMode()) { ServiceManager.getService(CloudSdkServiceManager.class).getCloudSdkService().activate(); } } }
/** Checks if the default SDK saved path contains a valid Cloud SDK installation. */ public boolean isValidCloudSdk() { return validateCloudSdk(CloudSdkService.getInstance().getSdkHomePath()).isEmpty(); }
@Override public void checkConfiguration() throws RuntimeConfigurationException { if (artifactPointer == null || artifactPointer.getArtifact() == null) { throw new RuntimeConfigurationError( AppEngineMessageBundle.message("appengine.run.server.artifact.missing")); } // do not check SDK if it supports dynamic install - the deployment runner will block itself // until installation is done. CloudSdkService cloudSdkService = CloudSdkService.getInstance(); SdkStatus sdkStatus = cloudSdkService.getStatus(); if (sdkStatus != SdkStatus.READY && !cloudSdkService.isInstallSupported()) { if (!CloudSdkValidator.getInstance().isValidCloudSdk()) { throw new RuntimeConfigurationError( AppEngineMessageBundle.message("appengine.run.server.sdk.misconfigured.panel.message")); } } if (ProjectRootManager.getInstance(commonModel.getProject()).getProjectSdk() == null) { throw new RuntimeConfigurationError( AppEngineMessageBundle.getString("appengine.run.server.nojdk")); } }