Search in sources :

Example 1 with AppEngineFlexibleFacet

use of com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacet 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 AppEngineFlexibleFacet

use of com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacet in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineFlexibleDeploymentEditor method openModuleSettings.

private void openModuleSettings() {
    AppEngineFlexibleFacet flexFacet = ((AppEngineFlexibleFacet) appYamlCombobox.getSelectedItem());
    if (flexFacet != null && ModulesConfigurator.showFacetSettingsDialog(flexFacet, null)) {
        // The user may have updated the configuration, so we need to refresh it here too.
        reloadAppYamls(project);
        appYamlCombobox.setSelectedItem(flexFacet);
        toggleDockerfileSection();
        // When we get out of the dialog window, we want to re-eval the configuration.
        // validateConfiguration() can't be used here because the ConfigurationException
        // isn't caught anywhere, and fireEditorStateChanged() doesn't trigger any listeners
        // called from here. Emulating a user action triggers apply(), so that's what we're
        // doing here.
        commonConfig.triggerSettingsEditorValidation();
    }
}
Also used : AppEngineFlexibleFacet(com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacet)

Example 3 with AppEngineFlexibleFacet

use of com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacet in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineFlexibleStage method stage.

/**
 * Stages the application in the given staging directory, in preparation for deployment to the App
 * Engine flexible environment.
 *
 * @param stagingDirectory the directory to stage the application to
 * @return {@code true} if the application was staged successfully, {@code false} otherwise
 * @throws IOException if there was a filesystem error during copying
 */
public boolean stage(@NotNull Path stagingDirectory) throws IOException {
    try {
        String moduleName = deploymentConfiguration.getModuleName();
        if (StringUtils.isEmpty(moduleName)) {
            loggingHandler.print(getMessage("appengine.deployment.error.staging.yaml.notspecified"));
            return false;
        }
        AppEngineFlexibleFacet flexibleFacet = AppEngineFlexibleFacet.getFacetByModuleName(moduleName, project);
        if (flexibleFacet == null || StringUtils.isEmpty(flexibleFacet.getConfiguration().getAppYamlPath())) {
            loggingHandler.print(getMessage("appengine.deployment.error.staging.yaml.notspecified"));
            return false;
        }
        AppEngineFlexibleFacetConfiguration facetConfiguration = flexibleFacet.getConfiguration();
        String appYaml = facetConfiguration.getAppYamlPath();
        // Checks if the app.yaml exists before staging.
        if (!Files.exists(Paths.get(appYaml))) {
            loggingHandler.print(getMessage("appengine.deployment.error.staging.yaml.notfound"));
            return false;
        }
        boolean isCustomRuntime = AppEngineProjectService.getInstance().getFlexibleRuntimeFromAppYaml(appYaml).filter(FlexibleRuntime::isCustom).isPresent();
        // Checks if the Dockerfile exists before staging.
        String dockerDirectory = facetConfiguration.getDockerDirectory();
        if (isCustomRuntime) {
            if (Strings.isNullOrEmpty(dockerDirectory)) {
                loggingHandler.print(getMessage("appengine.deployment.error.staging.dockerfile.notspecified"));
                return false;
            }
            if (!Files.isRegularFile(Paths.get(dockerDirectory, DOCKERFILE_NAME))) {
                loggingHandler.print(getMessage("appengine.deployment.error.staging.dockerfile.notfound"));
                return false;
            }
        }
        String stagedArtifactName = deploymentConfiguration.getStagedArtifactName();
        if (Strings.isNullOrEmpty(stagedArtifactName)) {
            if (deploymentConfiguration.isStagedArtifactNameLegacy()) {
                // Uses "target.jar" or "target.war" for legacy configs.
                AppEngineFlexibleDeploymentArtifactType artifactType = AppEngineFlexibleDeploymentArtifactType.typeForPath(deploymentArtifactPath);
                stagedArtifactName = StagedArtifactNameLegacySupport.getTargetName(artifactType);
            } else {
                // Defaults to the name of the artifact.
                stagedArtifactName = deploymentArtifactPath.getFileName().toString();
            }
        }
        loggingHandler.print(getMessage("appengine.deployment.staging.artifact.as", stagedArtifactName));
        Path stagedArtifactPath = stagingDirectory.resolve(stagedArtifactName);
        // Creates parent directories first, if necessary.
        Files.createDirectories(stagedArtifactPath.getParent());
        Files.copy(deploymentArtifactPath, stagedArtifactPath);
        Path appYamlPath = Paths.get(appYaml);
        Files.copy(appYamlPath, stagingDirectory.resolve(appYamlPath.getFileName()));
        if (isCustomRuntime) {
            FileUtils.copyDirectory(Paths.get(dockerDirectory).toFile(), stagingDirectory.toFile());
        }
    } catch (InvalidPathException | MalformedYamlFileException e) {
        loggingHandler.print(e.getMessage() + "\n");
    }
    return true;
}
Also used : Path(java.nio.file.Path) MalformedYamlFileException(com.google.cloud.tools.intellij.appengine.project.MalformedYamlFileException) AppEngineFlexibleFacet(com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacet) AppEngineFlexibleFacetConfiguration(com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacetConfiguration) InvalidPathException(java.nio.file.InvalidPathException)

Example 4 with AppEngineFlexibleFacet

use of com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacet in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineFlexibleDeploymentEditorTest method flexibleConfig_customAppYaml.

@Test
public void flexibleConfig_customAppYaml() {
    AppEngineFlexibleFacet facet = AppEngineFlexibleFacet.getFacetByModule(customModule);
    editor.getAppYamlCombobox().setSelectedItem(facet);
    assertThat(editor.getDockerDirectoryPanel().isVisible()).isTrue();
    assertThat(editor.getStagedArtifactNamePanel().isVisible()).isTrue();
    assertThat(editor.getRuntimePanel().isVisible()).isTrue();
    assertThat(editor.getRuntimePanel().getLabelText()).isEqualTo("custom");
}
Also used : AppEngineFlexibleFacet(com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacet) Test(org.junit.Test)

Example 5 with AppEngineFlexibleFacet

use of com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacet in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineDeploymentConfiguration method checkFlexConfig.

/**
 * Checks that this configuration is valid for a flex deployment, otherwise throws a {@link
 * RuntimeConfigurationError}.
 *
 * @param deployable the {@link AppEngineDeployable deployment source} that was selected by the
 *     user to deploy
 * @param project the {@link Project} that this configuration belongs to
 * @throws RuntimeConfigurationError if this configuration is not valid for a flex deployment
 */
private void checkFlexConfig(AppEngineDeployable deployable, Project project) throws RuntimeConfigurationError {
    check(!(deployable instanceof UserSpecifiedPathDeploymentSource) || (!StringUtil.isEmpty(userSpecifiedArtifactPath) && isJarOrWar(userSpecifiedArtifactPath)), "appengine.flex.config.user.specified.artifact.error");
    check(StringUtils.isNotBlank(moduleName), "appengine.flex.config.select.module");
    AppEngineFlexibleFacet facet = AppEngineFlexibleFacet.getFacetByModuleName(moduleName, project);
    check(facet != null, "appengine.flex.config.select.module");
    String appYamlPath = facet.getConfiguration().getAppYamlPath();
    check(StringUtils.isNotBlank(appYamlPath), "appengine.flex.config.browse.app.yaml");
    check(Files.exists(Paths.get(appYamlPath)), "appengine.deployment.config.appyaml.error");
    try {
        Optional<FlexibleRuntime> runtime = AppEngineProjectService.getInstance().getFlexibleRuntimeFromAppYaml(appYamlPath);
        if (runtime.isPresent() && runtime.get().isCustom()) {
            String dockerDirectory = facet.getConfiguration().getDockerDirectory();
            check(StringUtils.isNotBlank(dockerDirectory), "appengine.flex.config.browse.docker.directory");
            check(Files.exists(Paths.get(dockerDirectory, DOCKERFILE_NAME)), "appengine.deployment.config.dockerfile.error");
        }
    } catch (MalformedYamlFileException e) {
        throw new RuntimeConfigurationError(GctBundle.message("appengine.appyaml.malformed"));
    }
}
Also used : UserSpecifiedPathDeploymentSource(com.google.cloud.tools.intellij.appengine.cloud.flexible.UserSpecifiedPathDeploymentSource) MalformedYamlFileException(com.google.cloud.tools.intellij.appengine.project.MalformedYamlFileException) AppEngineFlexibleFacet(com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacet) FlexibleRuntime(com.google.cloud.tools.intellij.appengine.project.AppEngineProjectService.FlexibleRuntime) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError)

Aggregations

AppEngineFlexibleFacet (com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacet)8 Test (org.junit.Test)4 MalformedYamlFileException (com.google.cloud.tools.intellij.appengine.project.MalformedYamlFileException)2 Path (java.nio.file.Path)2 VisibleForTesting (com.google.api.client.repackaged.com.google.common.annotations.VisibleForTesting)1 DefaultDeployConfiguration (com.google.cloud.tools.appengine.api.deploy.DefaultDeployConfiguration)1 CloudSdk (com.google.cloud.tools.appengine.cloudsdk.CloudSdk)1 CloudSdkAppEngineDeployment (com.google.cloud.tools.appengine.cloudsdk.CloudSdkAppEngineDeployment)1 ProcessExitListener (com.google.cloud.tools.appengine.cloudsdk.process.ProcessExitListener)1 ProcessStartListener (com.google.cloud.tools.appengine.cloudsdk.process.ProcessStartListener)1 UserSpecifiedPathDeploymentSource (com.google.cloud.tools.intellij.appengine.cloud.flexible.UserSpecifiedPathDeploymentSource)1 AppEngineFlexibleFacetConfiguration (com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacetConfiguration)1 FlexibleFacetEditor (com.google.cloud.tools.intellij.appengine.facet.flexible.FlexibleFacetEditor)1 FlexibleRuntime (com.google.cloud.tools.intellij.appengine.project.AppEngineProjectService.FlexibleRuntime)1 CloudSdkVersionNotifier (com.google.cloud.tools.intellij.appengine.sdk.CloudSdkVersionNotifier)1 GctBundle (com.google.cloud.tools.intellij.util.GctBundle)1 ImmutableList (com.google.common.collect.ImmutableList)1 Gson (com.google.gson.Gson)1 JsonParseException (com.google.gson.JsonParseException)1 TypeToken (com.google.gson.reflect.TypeToken)1