Search in sources :

Example 1 with CloudSdk

use of com.google.cloud.tools.appengine.cloudsdk.CloudSdk in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineDeploy method deploy.

/**
 * Given a staging directory, deploy the application to Google App Engine.
 */
// TODO(eshaul) break this down into smaller parts
public void deploy(@NotNull Path stagingDirectory, @NotNull ProcessStartListener deployStartListener) {
    final StringBuilder rawDeployOutput = new StringBuilder();
    DefaultDeployConfiguration configuration = new DefaultDeployConfiguration();
    String appYamlName;
    if (environment.isStandard() || environment.isFlexCompat()) {
        appYamlName = FlexibleFacetEditor.APP_YAML_FILE_NAME;
    } else {
        String moduleName = deploymentConfiguration.getModuleName();
        if (StringUtils.isEmpty(moduleName)) {
            callback.errorOccurred(GctBundle.message("appengine.deployment.error.appyaml.notspecified"));
            return;
        }
        AppEngineFlexibleFacet flexFacet = AppEngineFlexibleFacet.getFacetByModuleName(moduleName, helper.getProject());
        if (flexFacet == null) {
            // This should not happen since staging already verified the file
            callback.errorOccurred(GctBundle.message("appengine.deployment.error.appyaml.notfound"));
            return;
        } else {
            appYamlName = Paths.get(flexFacet.getConfiguration().getAppYamlPath()).getFileName().toString();
        }
    }
    List<File> deployables = APPENGINE_EXTRA_CONFIG_FILE_PATHS.stream().map(configFilePath -> stagingDirectory.resolve(configFilePath).toFile()).filter(configFile -> deploymentConfiguration.isDeployAllConfigs() && configFile.exists()).collect(Collectors.toList());
    deployables.add(stagingDirectory.resolve(appYamlName).toFile());
    configuration.setDeployables(deployables);
    configuration.setProject(deploymentConfiguration.getCloudProjectName());
    configuration.setPromote(deploymentConfiguration.isPromote());
    // promoting).
    if ((environment.isFlexible() || environment.isFlexCompat()) && deploymentConfiguration.isPromote()) {
        configuration.setStopPreviousVersion(deploymentConfiguration.isStopPreviousVersion());
    }
    if (!StringUtil.isEmpty(deploymentConfiguration.getVersion())) {
        configuration.setVersion(deploymentConfiguration.getVersion());
    }
    ProcessExitListener deployExitListener = new DeployExitListener(rawDeployOutput);
    CloudSdk sdk = helper.createSdk(loggingHandler, deployStartListener, line -> loggingHandler.print(line + "\n"), rawDeployOutput::append, deployExitListener);
    // show a warning notification if the cloud sdk version is not supported
    CloudSdkVersionNotifier.getInstance().notifyIfUnsupportedVersion();
    CloudSdkAppEngineDeployment deployment = new CloudSdkAppEngineDeployment(sdk);
    deployment.deploy(configuration);
}
Also used : JsonParseException(com.google.gson.JsonParseException) StringUtils(org.apache.commons.lang.StringUtils) TypeToken(com.google.gson.reflect.TypeToken) VisibleForTesting(com.google.api.client.repackaged.com.google.common.annotations.VisibleForTesting) DefaultDeployConfiguration(com.google.cloud.tools.appengine.api.deploy.DefaultDeployConfiguration) ProcessStartListener(com.google.cloud.tools.appengine.cloudsdk.process.ProcessStartListener) AppEngineFlexibleFacet(com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacet) FlexibleFacetEditor(com.google.cloud.tools.intellij.appengine.facet.flexible.FlexibleFacetEditor) ImmutableList(com.google.common.collect.ImmutableList) Gson(com.google.gson.Gson) CloudSdkVersionNotifier(com.google.cloud.tools.intellij.appengine.sdk.CloudSdkVersionNotifier) DeploymentOperationCallback(com.intellij.remoteServer.runtime.deployment.ServerRuntimeInstance.DeploymentOperationCallback) GctBundle(com.google.cloud.tools.intellij.util.GctBundle) LoggingHandler(com.intellij.remoteServer.runtime.log.LoggingHandler) CloudSdk(com.google.cloud.tools.appengine.cloudsdk.CloudSdk) Logger(com.intellij.openapi.diagnostic.Logger) Path(java.nio.file.Path) ProcessExitListener(com.google.cloud.tools.appengine.cloudsdk.process.ProcessExitListener) StringUtil(com.intellij.openapi.util.text.StringUtil) Collectors(java.util.stream.Collectors) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Type(java.lang.reflect.Type) Paths(java.nio.file.Paths) CloudSdkAppEngineDeployment(com.google.cloud.tools.appengine.cloudsdk.CloudSdkAppEngineDeployment) NotNull(org.jetbrains.annotations.NotNull) ProcessExitListener(com.google.cloud.tools.appengine.cloudsdk.process.ProcessExitListener) CloudSdkAppEngineDeployment(com.google.cloud.tools.appengine.cloudsdk.CloudSdkAppEngineDeployment) AppEngineFlexibleFacet(com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacet) DefaultDeployConfiguration(com.google.cloud.tools.appengine.api.deploy.DefaultDeployConfiguration) CloudSdk(com.google.cloud.tools.appengine.cloudsdk.CloudSdk) File(java.io.File)

Example 2 with CloudSdk

use of com.google.cloud.tools.appengine.cloudsdk.CloudSdk in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineStop method stop.

/**
 * Stops the given module / version of an App Engine application.
 */
public void stop(@NotNull String module, @NotNull String version, @NotNull ProcessStartListener startListener) {
    ProcessOutputLineListener outputListener = new ProcessOutputLineListener() {

        @Override
        public void onOutputLine(String line) {
            loggingHandler.print(line + "\n");
        }
    };
    ProcessExitListener stopExitListener = new StopExitListener();
    CloudSdk sdk = helper.createSdk(loggingHandler, startListener, outputListener, outputListener, stopExitListener);
    DefaultVersionsSelectionConfiguration configuration = new DefaultVersionsSelectionConfiguration();
    configuration.setVersions(Collections.singletonList(version));
    configuration.setService(module);
    configuration.setProject(deploymentConfiguration.getCloudProjectName());
    CloudSdkAppEngineVersions command = new CloudSdkAppEngineVersions(sdk);
    command.stop(configuration);
}
Also used : ProcessExitListener(com.google.cloud.tools.appengine.cloudsdk.process.ProcessExitListener) DefaultVersionsSelectionConfiguration(com.google.cloud.tools.appengine.api.versions.DefaultVersionsSelectionConfiguration) CloudSdkAppEngineVersions(com.google.cloud.tools.appengine.cloudsdk.CloudSdkAppEngineVersions) ProcessOutputLineListener(com.google.cloud.tools.appengine.cloudsdk.process.ProcessOutputLineListener) CloudSdk(com.google.cloud.tools.appengine.cloudsdk.CloudSdk)

Example 3 with CloudSdk

use of com.google.cloud.tools.appengine.cloudsdk.CloudSdk in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudSdkAppEngineHelper method createSdk.

@Override
public CloudSdk createSdk(LoggingHandler loggingHandler, ProcessStartListener startListener, ProcessOutputLineListener logListener, ProcessOutputLineListener outputListener, ProcessExitListener exitListener) {
    if (credentialsPath == null) {
        loggingHandler.print(GctBundle.message("appengine.action.credential.not.found") + "\n");
        throw new AppEngineException("Failed to create application default credentials.");
    }
    PluginInfoService pluginInfoService = ServiceManager.getService(PluginInfoService.class);
    CloudSdk.Builder sdkBuilder = new CloudSdk.Builder().sdkPath(CloudSdkService.getInstance().getSdkHomePath()).async(true).addStdErrLineListener(logListener).addStdOutLineListener(outputListener).exitListener(exitListener).startListener(startListener).appCommandCredentialFile(credentialsPath.toFile()).appCommandMetricsEnvironment(pluginInfoService.getExternalPluginName()).appCommandMetricsEnvironmentVersion(pluginInfoService.getPluginVersion()).appCommandOutputFormat("json");
    getProjectJavaSdk(project).ifPresent(sdkBuilder::javaHome);
    return sdkBuilder.build();
}
Also used : PluginInfoService(com.google.cloud.tools.intellij.service.PluginInfoService) CloudSdk(com.google.cloud.tools.appengine.cloudsdk.CloudSdk) AppEngineException(com.google.cloud.tools.appengine.api.AppEngineException)

Example 4 with CloudSdk

use of com.google.cloud.tools.appengine.cloudsdk.CloudSdk in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudSdkValidator method validateCloudSdk.

protected Set<CloudSdkValidationResult> validateCloudSdk(Path path) {
    Set<CloudSdkValidationResult> validationResults = new HashSet<>();
    if (path == null) {
        validationResults.add(CloudSdkValidationResult.CLOUD_SDK_NOT_FOUND);
        // If the Cloud SDK is not found, don't bother checking anything else
        return validationResults;
    }
    CloudSdk sdk = buildCloudSdkWithPath(path);
    try {
        sdk.validateCloudSdk();
    } catch (CloudSdkNotFoundException exception) {
        validationResults.add(CloudSdkValidationResult.CLOUD_SDK_NOT_FOUND);
        // If the Cloud SDK is not found, don't bother checking anything else
        return validationResults;
    } catch (CloudSdkOutOfDateException exception) {
        validationResults.add(com.google.cloud.tools.intellij.appengine.sdk.CloudSdkValidationResult.CLOUD_SDK_VERSION_NOT_SUPPORTED);
    }
    try {
        sdk.validateAppEngineJavaComponents();
    } catch (AppEngineJavaComponentsNotInstalledException ex) {
        validationResults.add(CloudSdkValidationResult.NO_APP_ENGINE_COMPONENT);
    }
    return validationResults;
}
Also used : AppEngineJavaComponentsNotInstalledException(com.google.cloud.tools.appengine.cloudsdk.AppEngineJavaComponentsNotInstalledException) CloudSdkOutOfDateException(com.google.cloud.tools.appengine.cloudsdk.CloudSdkOutOfDateException) CloudSdk(com.google.cloud.tools.appengine.cloudsdk.CloudSdk) CloudSdkNotFoundException(com.google.cloud.tools.appengine.cloudsdk.CloudSdkNotFoundException) HashSet(java.util.HashSet)

Example 5 with CloudSdk

use of com.google.cloud.tools.appengine.cloudsdk.CloudSdk in project app-maven-plugin by GoogleCloudPlatform.

the class CloudSdkLoginMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    try {
        CloudSdk sdk = getAppEngineFactory().defaultCloudSdkBuilder().build();
        new CloudSdkAuth(sdk).login();
    } catch (AppEngineException ex) {
        throw new RuntimeException(ex);
    }
    if (getServiceAccountKeyFile() != null) {
        getLog().warn("serviceAccountKeyFile is configured and will be used instead of Cloud SDK auth " + "state.");
    }
}
Also used : CloudSdkAuth(com.google.cloud.tools.appengine.cloudsdk.CloudSdkAuth) CloudSdk(com.google.cloud.tools.appengine.cloudsdk.CloudSdk) AppEngineException(com.google.cloud.tools.appengine.api.AppEngineException)

Aggregations

CloudSdk (com.google.cloud.tools.appengine.cloudsdk.CloudSdk)7 AppEngineException (com.google.cloud.tools.appengine.api.AppEngineException)2 ProcessExitListener (com.google.cloud.tools.appengine.cloudsdk.process.ProcessExitListener)2 ProcessOutputLineListener (com.google.cloud.tools.appengine.cloudsdk.process.ProcessOutputLineListener)2 VisibleForTesting (com.google.api.client.repackaged.com.google.common.annotations.VisibleForTesting)1 DefaultDeployConfiguration (com.google.cloud.tools.appengine.api.deploy.DefaultDeployConfiguration)1 DefaultStageStandardConfiguration (com.google.cloud.tools.appengine.api.deploy.DefaultStageStandardConfiguration)1 DefaultVersionsSelectionConfiguration (com.google.cloud.tools.appengine.api.versions.DefaultVersionsSelectionConfiguration)1 AppEngineJavaComponentsNotInstalledException (com.google.cloud.tools.appengine.cloudsdk.AppEngineJavaComponentsNotInstalledException)1 CloudSdkAppEngineDeployment (com.google.cloud.tools.appengine.cloudsdk.CloudSdkAppEngineDeployment)1 CloudSdkAppEngineStandardStaging (com.google.cloud.tools.appengine.cloudsdk.CloudSdkAppEngineStandardStaging)1 CloudSdkAppEngineVersions (com.google.cloud.tools.appengine.cloudsdk.CloudSdkAppEngineVersions)1 CloudSdkAuth (com.google.cloud.tools.appengine.cloudsdk.CloudSdkAuth)1 CloudSdkNotFoundException (com.google.cloud.tools.appengine.cloudsdk.CloudSdkNotFoundException)1 CloudSdkOutOfDateException (com.google.cloud.tools.appengine.cloudsdk.CloudSdkOutOfDateException)1 NonZeroExceptionExitListener (com.google.cloud.tools.appengine.cloudsdk.process.NonZeroExceptionExitListener)1 ProcessStartListener (com.google.cloud.tools.appengine.cloudsdk.process.ProcessStartListener)1 AppEngineFlexibleFacet (com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacet)1 FlexibleFacetEditor (com.google.cloud.tools.intellij.appengine.facet.flexible.FlexibleFacetEditor)1 CloudSdkVersionNotifier (com.google.cloud.tools.intellij.appengine.sdk.CloudSdkVersionNotifier)1