Search in sources :

Example 1 with SdkStatus

use of com.google.cloud.tools.intellij.appengine.sdk.CloudSdkService.SdkStatus in project google-cloud-intellij by GoogleCloudPlatform.

the class ManagedCloudSdkServiceTest method failed_update_invalidSdk_makesSdkStatus_notAvailable.

@Test
public void failed_update_invalidSdk_makesSdkStatus_notAvailable() throws Exception {
    makeMockSdkInstalled(MOCK_SDK_PATH);
    emulateMockSdkUpdateProcess();
    SdkUpdater mockUpdater = mockManagedCloudSdk.newUpdater();
    doThrow(new CommandExitException(-1, "")).when(mockUpdater).update(any(), any());
    // update breaks SDK
    when(mockManagedCloudSdk.isInstalled()).thenReturn(false);
    sdkService.addStatusUpdateListener(mockStatusUpdateListener);
    sdkService.update();
    ArgumentCaptor<SdkStatus> statusCaptor = ArgumentCaptor.forClass(SdkStatus.class);
    verify(mockStatusUpdateListener, times(2)).onSdkStatusChange(any(), statusCaptor.capture());
    assertThat(statusCaptor.getAllValues()).isEqualTo(Arrays.asList(SdkStatus.INSTALLING, SdkStatus.NOT_AVAILABLE));
}
Also used : SdkUpdater(com.google.cloud.tools.managedcloudsdk.components.SdkUpdater) CommandExitException(com.google.cloud.tools.managedcloudsdk.command.CommandExitException) SdkStatus(com.google.cloud.tools.intellij.appengine.sdk.CloudSdkService.SdkStatus) Test(org.junit.Test)

Example 2 with SdkStatus

use of com.google.cloud.tools.intellij.appengine.sdk.CloudSdkService.SdkStatus in project google-cloud-intellij by GoogleCloudPlatform.

the class ManagedCloudSdkServiceTest method cancelled_update_keepsSdkStatus_available.

@Test
public void cancelled_update_keepsSdkStatus_available() throws Exception {
    makeMockSdkInstalled(MOCK_SDK_PATH);
    emulateMockSdkUpdateProcess();
    SdkUpdater mockUpdater = mockManagedCloudSdk.newUpdater();
    doThrow(new CancellationException()).when(mockUpdater).update(any(), any());
    sdkService.addStatusUpdateListener(mockStatusUpdateListener);
    sdkService.update();
    ArgumentCaptor<SdkStatus> statusCaptor = ArgumentCaptor.forClass(SdkStatus.class);
    verify(mockStatusUpdateListener, times(2)).onSdkStatusChange(any(), statusCaptor.capture());
    assertThat(statusCaptor.getAllValues()).isEqualTo(Arrays.asList(SdkStatus.INSTALLING, SdkStatus.READY));
}
Also used : CancellationException(java.util.concurrent.CancellationException) SdkUpdater(com.google.cloud.tools.managedcloudsdk.components.SdkUpdater) SdkStatus(com.google.cloud.tools.intellij.appengine.sdk.CloudSdkService.SdkStatus) Test(org.junit.Test)

Example 3 with SdkStatus

use of com.google.cloud.tools.intellij.appengine.sdk.CloudSdkService.SdkStatus in project google-cloud-intellij by GoogleCloudPlatform.

the class ManagedCloudSdkServiceTest method failed_install_changesSdkStatus_inProgress.

@Test
public void failed_install_changesSdkStatus_inProgress() throws Exception {
    sdkService.addStatusUpdateListener(mockStatusUpdateListener);
    emulateMockSdkInstallationProcess(MOCK_SDK_PATH);
    SdkInstaller mockInstaller = mockManagedCloudSdk.newInstaller();
    when(mockInstaller.install(any(), any())).thenThrow(new IOException("IO Error"));
    sdkService.install();
    ArgumentCaptor<SdkStatus> statusCaptor = ArgumentCaptor.forClass(SdkStatus.class);
    verify(mockStatusUpdateListener, times(2)).onSdkStatusChange(any(), statusCaptor.capture());
    assertThat(statusCaptor.getAllValues()).isEqualTo(Arrays.asList(SdkStatus.INSTALLING, SdkStatus.NOT_AVAILABLE));
}
Also used : SdkInstaller(com.google.cloud.tools.managedcloudsdk.install.SdkInstaller) IOException(java.io.IOException) SdkStatus(com.google.cloud.tools.intellij.appengine.sdk.CloudSdkService.SdkStatus) Test(org.junit.Test)

Example 4 with SdkStatus

use of com.google.cloud.tools.intellij.appengine.sdk.CloudSdkService.SdkStatus in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineServerModel method checkConfiguration.

@Override
public void checkConfiguration() throws RuntimeConfigurationException {
    if (artifactPointer == null || artifactPointer.getArtifact() == null) {
        throw new RuntimeConfigurationError(GctBundle.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(GctBundle.message("appengine.run.server.sdk.misconfigured.panel.message"));
        }
    }
    if (ProjectRootManager.getInstance(commonModel.getProject()).getProjectSdk() == null) {
        throw new RuntimeConfigurationError(GctBundle.getString("appengine.run.server.nosdk"));
    }
}
Also used : CloudSdkService(com.google.cloud.tools.intellij.appengine.sdk.CloudSdkService) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError) SdkStatus(com.google.cloud.tools.intellij.appengine.sdk.CloudSdkService.SdkStatus)

Example 5 with SdkStatus

use of com.google.cloud.tools.intellij.appengine.sdk.CloudSdkService.SdkStatus in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudSdkStartupPolicy method createStartupScriptHelper.

@Nullable
@Override
public ScriptHelper createStartupScriptHelper(final ProgramRunner programRunner) {
    return new ScriptHelper() {

        @Nullable
        @Override
        public ExecutableObject getDefaultScript(final CommonModel commonModel) {
            return new ExecutableObject() {

                @Override
                public String getDisplayString() {
                    return GctBundle.getString("appengine.run.startupscript.name");
                }

                @Override
                public OSProcessHandler createProcessHandler(String workingDirectory, Map<String, String> configuredEnvironment) throws ExecutionException {
                    try {
                        CloudSdkServiceManager.getInstance().blockUntilSdkReady(commonModel.getProject(), GctBundle.getString("appengine.run.startupscript"), new CloudSdkStatusHandler() {

                            @Override
                            public void log(String s) {
                                logger.info("Cloud SDK precondition check reported: " + s);
                            }

                            @Override
                            public void onError(String s) {
                                logger.warn("Cloud SDK precondition check reported error: " + s);
                            }

                            @Override
                            public void onUserCancel() {
                            }

                            @Override
                            public String getErrorMessage(SdkStatus sdkStatus) {
                                switch(sdkStatus) {
                                    case INVALID:
                                    case NOT_AVAILABLE:
                                        return GctBundle.message("appengine.run.server.sdk.misconfigured.message");
                                    default:
                                        return "";
                                }
                            }
                        });
                    } catch (InterruptedException e) {
                        // should not happen, but would be an error.
                        throw new ExecutionException(GctBundle.message("appengine.run.server.sdk.misconfigured.message"));
                    }
                    // wait complete, check the final status here manually.
                    SdkStatus sdkStatus = CloudSdkService.getInstance().getStatus();
                    switch(sdkStatus) {
                        case INVALID:
                        case NOT_AVAILABLE:
                            throw new ExecutionException(GctBundle.message("appengine.run.server.sdk.misconfigured.message"));
                        case INSTALLING:
                            // cannot continue still installing.
                            throw new ExecutionException(GctBundle.message("appengine.run.server.sdk.installing.message"));
                        case READY:
                            // continue to start local dev server process.
                            break;
                    }
                    Sdk javaSdk = ProjectRootManager.getInstance(commonModel.getProject()).getProjectSdk();
                    if (javaSdk == null || javaSdk.getHomePath() == null) {
                        throw new ExecutionException(GctBundle.message("appengine.run.server.nosdk"));
                    }
                    AppEngineServerModel runConfiguration;
                    try {
                        // Getting the clone so the debug flags aren't added
                        // to the persisted settings.
                        runConfiguration = (AppEngineServerModel) commonModel.getServerModel().clone();
                    } catch (CloneNotSupportedException ee) {
                        throw new ExecutionException(ee);
                    }
                    Map<String, String> environment = Maps.newHashMap(configuredEnvironment);
                    // IntelliJ appends the JVM flags to the environment
                    // variables, keyed by an empty
                    // string; so we need extract them here.
                    String jvmFlags = environment.get(JVM_FLAGS_ENVIRONMENT_KEY);
                    if (jvmFlags != null) {
                        runConfiguration.appendJvmFlags(Arrays.asList(jvmFlags.trim().split(" ")));
                    }
                    // We don't want to pass the jvm flags to the dev server environment
                    environment.remove(JVM_FLAGS_ENVIRONMENT_KEY);
                    runConfiguration.setEnvironment(environment);
                    AppEngineStandardRunTask runTask = new AppEngineStandardRunTask(runConfiguration, javaSdk, programRunner.getRunnerId());
                    AppEngineExecutor executor = new AppEngineExecutor(runTask);
                    executor.run();
                    Process devappserverProcess = executor.getProcess();
                    startupProcessHandler = new OSProcessHandler(devappserverProcess, GctBundle.getString("appengine.run.startupscript"));
                    return startupProcessHandler;
                }
            };
        }
    };
}
Also used : ExecutableObject(com.intellij.javaee.run.localRun.ExecutableObject) AppEngineServerModel(com.google.cloud.tools.intellij.appengine.server.instance.AppEngineServerModel) AppEngineStandardRunTask(com.google.cloud.tools.intellij.appengine.cloud.executor.AppEngineStandardRunTask) AppEngineExecutor(com.google.cloud.tools.intellij.appengine.cloud.executor.AppEngineExecutor) CommonModel(com.intellij.javaee.run.configuration.CommonModel) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) CloudSdkStatusHandler(com.google.cloud.tools.intellij.appengine.sdk.CloudSdkServiceManager.CloudSdkStatusHandler) Sdk(com.intellij.openapi.projectRoots.Sdk) ScriptHelper(com.intellij.javaee.run.localRun.ScriptHelper) ExecutionException(com.intellij.execution.ExecutionException) Map(java.util.Map) SdkStatus(com.google.cloud.tools.intellij.appengine.sdk.CloudSdkService.SdkStatus) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

SdkStatus (com.google.cloud.tools.intellij.appengine.sdk.CloudSdkService.SdkStatus)11 Test (org.junit.Test)6 SdkUpdater (com.google.cloud.tools.managedcloudsdk.components.SdkUpdater)4 CloudSdkService (com.google.cloud.tools.intellij.appengine.sdk.CloudSdkService)2 CloudSdkStatusHandler (com.google.cloud.tools.intellij.appengine.sdk.CloudSdkServiceManager.CloudSdkStatusHandler)2 CommandExitException (com.google.cloud.tools.managedcloudsdk.command.CommandExitException)2 RuntimeConfigurationError (com.intellij.execution.configurations.RuntimeConfigurationError)2 AppEngineExecutor (com.google.cloud.tools.intellij.appengine.cloud.executor.AppEngineExecutor)1 AppEngineStandardRunTask (com.google.cloud.tools.intellij.appengine.cloud.executor.AppEngineStandardRunTask)1 UserSpecifiedPathDeploymentSource (com.google.cloud.tools.intellij.appengine.cloud.flexible.UserSpecifiedPathDeploymentSource)1 CloudSdkValidationResult (com.google.cloud.tools.intellij.appengine.sdk.CloudSdkValidationResult)1 AppEngineServerModel (com.google.cloud.tools.intellij.appengine.server.instance.AppEngineServerModel)1 CommandExecutionException (com.google.cloud.tools.managedcloudsdk.command.CommandExecutionException)1 SdkComponentInstaller (com.google.cloud.tools.managedcloudsdk.components.SdkComponentInstaller)1 SdkInstaller (com.google.cloud.tools.managedcloudsdk.install.SdkInstaller)1 ExecutionException (com.intellij.execution.ExecutionException)1 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)1 CommonModel (com.intellij.javaee.run.configuration.CommonModel)1 ExecutableObject (com.intellij.javaee.run.localRun.ExecutableObject)1 ScriptHelper (com.intellij.javaee.run.localRun.ScriptHelper)1