/** 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()); } }
/** * 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 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); } }
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"); }
/** 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. } }
@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")); } }