Search in sources :

Example 1 with CloudSdkStatusHandler

use of com.google.cloud.tools.intellij.appengine.sdk.CloudSdkServiceManager.CloudSdkStatusHandler 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)

Example 2 with CloudSdkStatusHandler

use of com.google.cloud.tools.intellij.appengine.sdk.CloudSdkServiceManager.CloudSdkStatusHandler in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineRuntimeInstance method deploy.

@Override
public void deploy(@NotNull final DeploymentTask<AppEngineDeploymentConfiguration> task, @NotNull final DeploymentLogManager logManager, @NotNull final DeploymentOperationCallback callback) {
    FileDocumentManager.getInstance().saveAllDocuments();
    Services.getLoginService().logInIfNot();
    if (!Services.getLoginService().isLoggedIn()) {
        callback.errorOccurred(GctBundle.message("appengine.deployment.error.not.logged.in"));
        return;
    }
    AppEngineDeploymentConfiguration deploymentConfig = task.getConfiguration();
    AppEngineHelper appEngineHelper = new CloudSdkAppEngineHelper(task.getProject());
    ProjectManager.getInstance().addProjectManagerListener(task.getProject(), projectClosingListener);
    appEngineHelper.createDeployRunner(logManager.getMainLoggingHandler(), task.getSource(), deploymentConfig, callback).ifPresent(deployRunner -> {
        // keep track of any active deployments
        synchronized (createdDeployments) {
            createdDeployments.put(task.getProject(), deployRunner);
        }
        CloudSdkServiceManager.getInstance().runWhenSdkReady(task.getProject(), deployRunner, GctBundle.message("appengine.deployment.status.deploying"), new CloudSdkStatusHandler() {

            @Override
            public void log(String message) {
                logManager.getMainLoggingHandler().print(message + "\n");
            }

            @Override
            public void onError(String message) {
                callback.errorOccurred(message);
            }

            @Override
            public void onUserCancel() {
                String cancelMessage = GctBundle.message("appengine.deployment.user.cancel");
                callback.errorOccurred(cancelMessage);
                logManager.getMainLoggingHandler().print(cancelMessage + "\n");
            }

            @Override
            public String getErrorMessage(SdkStatus sdkStatus) {
                switch(sdkStatus) {
                    case INVALID:
                        return GctBundle.message("appengine.deployment.error.sdk.invalid");
                    case NOT_AVAILABLE:
                        return GctBundle.message("appengine.deployment.error.sdk.not.available");
                    default:
                        return GctBundle.message("appengine.deployment.error.sdk.retry");
                }
            }
        });
    });
}
Also used : CloudSdkStatusHandler(com.google.cloud.tools.intellij.appengine.sdk.CloudSdkServiceManager.CloudSdkStatusHandler) SdkStatus(com.google.cloud.tools.intellij.appengine.sdk.CloudSdkService.SdkStatus)

Aggregations

SdkStatus (com.google.cloud.tools.intellij.appengine.sdk.CloudSdkService.SdkStatus)2 CloudSdkStatusHandler (com.google.cloud.tools.intellij.appengine.sdk.CloudSdkServiceManager.CloudSdkStatusHandler)2 AppEngineExecutor (com.google.cloud.tools.intellij.appengine.cloud.executor.AppEngineExecutor)1 AppEngineStandardRunTask (com.google.cloud.tools.intellij.appengine.cloud.executor.AppEngineStandardRunTask)1 AppEngineServerModel (com.google.cloud.tools.intellij.appengine.server.instance.AppEngineServerModel)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 Sdk (com.intellij.openapi.projectRoots.Sdk)1 Map (java.util.Map)1 Nullable (org.jetbrains.annotations.Nullable)1