Skip to content

Commit

Permalink
Auto-open browser on deploy (#1332)
Browse files Browse the repository at this point in the history
* Cleaned up StandardDeployJob and added step to auto-open the deployed
app in a browser

* Moved StandardDeployJob.DeployOutput and
StandardDeployJob#parseDeployJsonOutput into  AppEngineDeployUtil

* Minor clean up

* When creating DeployOutput check for a valid version object

* Removed duplicate version check

* Minor changes per PR comments

* Separated StdOutLineListener for the deploy and staging process

* Created a utility function for lauching a web browser with a specified
url.

* Utilizing WorkbenchUtil#openInBrowser

* Minor changes per PR comments

* Created a private constructor for AppEngineDeployOutput so that the only
way to create an instance is on a successful call to
AppEngineDeployOutput#parse

* Changed variable name

* Nit

* Created a VersionNotFoundException to be thrown when we cannot determine
the version of the deployed application

* Created a convience method WorkbenchUtil#openInBrowser(IWorkbench
workbench, String urlPath)

* Updated javadoc for WorkbenchUtil#openInBrowserInUiThread and
WorkbenchUtil#openInBrowser
  • Loading branch information
nbashirbello authored Feb 8, 2017
1 parent d337a34 commit 717ab82
Show file tree
Hide file tree
Showing 17 changed files with 439 additions and 135 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.tools.eclipse.appengine.deploy;

import com.google.gson.JsonParseException;
import org.junit.Assert;
import org.junit.Test;

/**
* Unit tests for {@link AppEngineDeployOutput}
*/
public class AppEngineDeployOutputTest {
@Test
public void testDeployOutputJsonParsingOneVersion() {
String jsonOutput =
"{\n" +
" \"configs\": [],\n" +
" \"versions\": [\n" +
" {\n" +
" \"id\": \"20160429t112518\",\n" +
" \"last_deployed_time\": null,\n" +
" \"project\": \"some-project\",\n" +
" \"service\": \"default\",\n" +
" \"traffic_split\": null,\n" +
" \"version\": null\n" +
" }\n" +
" ]\n" +
"}\n";

AppEngineDeployOutput deployOutput =
AppEngineDeployOutput.parse(jsonOutput);
Assert.assertEquals("20160429t112518", deployOutput.getVersion());
Assert.assertEquals("default", deployOutput.getService());
}

@Test
public void testDeployOutputJsonParsingTwoVersions() {
String jsonOutput =
"{\n" +
" \"configs\": [],\n" +
" \"versions\": [\n" +
" {\n" +
" \"id\": \"20160429t112518\",\n" +
" \"last_deployed_time\": null,\n" +
" \"project\": \"some-project\",\n" +
" \"service\": \"default\",\n" +
" \"traffic_split\": null,\n" +
" \"version\": null\n" +
" },\n" +
" {\n" +
" \"id\": \"20160429t112518\",\n" +
" \"last_deployed_time\": null,\n" +
" \"project\": \"some-project\",\n" +
" \"service\": \"default\",\n" +
" \"traffic_split\": null,\n" +
" \"version\": null\n" +
" }\n" +
" ]\n" +
"}\n";

try {
AppEngineDeployOutput.parse(jsonOutput);
Assert.fail("Failure to throw exception when parsing deploy output with more that one version entry");
} catch (JsonParseException e) {
// Success! Should throw a JsonParseException.
}
}

@Test
public void testDeployOutputJsonParsingOldFormat() {
String jsonOutput =
"{\n" +
" \"default\": \"https://springboot-maven-project.appspot.com\"\n" +
"}\n";

try {
AppEngineDeployOutput.parse(jsonOutput);
Assert.fail("Failure to throw exception when parsing deploy output in old format");
} catch (JsonParseException e) {
// Success! Should throw a JsonParseException.
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Require-Bundle: com.google.cloud.tools.appengine;bundle-version="0.2.6",
Require-Bundle: com.google.cloud.tools.appengine,
com.google.cloud.tools.eclipse.util,
com.google.gson,
com.google.guava;bundle-version="[20.0.0,21.0.0)",
org.eclipse.core.commands,
org.eclipse.core.jobs,
org.eclipse.core.resources,
org.eclipse.equinox.common,
org.eclipse.jst.j2ee.ui,
org.eclipse.swt,
org.eclipse.ui.workbench,
org.eclipse.wst.common.modulecore,
org.eclipse.wst.common.project.facet.core,
org.eclipse.wst.server.core
Expand All @@ -24,6 +27,8 @@ Export-Package: com.google.cloud.tools.eclipse.appengine.deploy,
Import-Package: com.google.api.client.auth.oauth2,
com.google.cloud.tools.eclipse.login,
com.google.cloud.tools.eclipse.sdk,
com.google.cloud.tools.eclipse.sdk.ui,
com.google.cloud.tools.eclipse.ui.util,
org.eclipse.core.runtime;bundle-symbolic-name:="org.eclipse.core.runtime",
org.eclipse.core.runtime.preferences;version="3.3.0",
org.osgi.framework;version="1.8.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.tools.eclipse.appengine.deploy;

import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import java.util.List;

/**
* Holds de-serialized JSON output of gcloud app deploy. Don't change the field names
* because Gson uses them for automatic de-serialization.
*/
// TODO: move into appengine-plugins-core
// TODO expand to include other Version attributes
public class AppEngineDeployOutput {
private AppEngineDeployOutput() {
}

private static class Version {
String id;
String service;
}

private List<Version> versions;

/**
* @return version, can be null
*/
public String getVersion() {
return versions.get(0).id;
}

/**
* @return service, can be null
*/
public String getService() {
return versions.get(0).service;
}

/**
* Parse the raw JSON output of the deployment.
*
* @return the output of gcloud app deploy
* @throws JsonParseException if unable to extract the deploy output information needed
*/
public static AppEngineDeployOutput parse(String jsonOutput) throws JsonParseException {
AppEngineDeployOutput deployOutput = new Gson().fromJson(jsonOutput, AppEngineDeployOutput.class);
if (deployOutput == null
|| deployOutput.versions == null || deployOutput.versions.size() != 1) {
throw new JsonParseException("Cannot get app version: unexpected gcloud JSON output format");
}
return deployOutput;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.tools.eclipse.appengine.deploy;

/**
* Thrown if the version of a deployed App Engine application cannot be determined.
*/
public class VersionNotFoundException extends Exception {

private static final long serialVersionUID = 1L;

public VersionNotFoundException(String message, Throwable cause) {
super(message, cause);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ deploy.job.staging.failed=Staging failed. Check the error message in the Console
deploy.job.deploy.failed=Deploy failed. Check the error message in the Console View
deploy.failed.error.message=Deploy failed.
cloudsdk.process.failed=Process exited with error code {0}
save.credential.failed=Error temporarily saving credential
browser.launch.failed=Error launching deployed app in browser
browser.launch.title=App Engine Deploy - {0}
Loading

0 comments on commit 717ab82

Please sign in to comment.