Skip to content

Commit

Permalink
Fixes: #158 - dev appserver 1 stuff and #164 - Stop should generate a…
Browse files Browse the repository at this point in the history
… configuration based on dev appserver 1 or 2-alpha. (#165)

* WIP - Fixes #158 - dev appserver 1 stuff

* javadoc and simpler code whether checking <services> parameter has been configured by the user

* remove default value from appYamls, revert file->path change

* unit tests for RunMojo

* update appengine-plugins-core dependency to 0.3.0

* try to fix kokoro test

* use custom ports to test run in integration test to avoid port clash on Kokoro

* fix async run test as well for Kokoro

* Fixes #158 - dev appserver 1 stuff

* additional tests

* add datastorePath to RunMojo

* add javadoc to datastorePath

* increase timeout to see if it fixes the kokoro-ubuntu build

* reformat pom.xml dependency for junitparams, rename SupportedVersion to SupportedDevServerVersion
  • Loading branch information
akerekes authored Apr 7, 2017
1 parent 17a333c commit e71b362
Show file tree
Hide file tree
Showing 13 changed files with 411 additions and 70 deletions.
7 changes: 7 additions & 0 deletions app-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>pl.pragmatists</groupId>
<artifactId>JUnitParams</artifactId>
<version>1.0.6</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-verifier</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,38 @@
*/
public interface AppEngineFactory {

/**
* Supported dev app server versions.
*/
public enum SupportedDevServerVersion {
V1, V2ALPHA;

/**
* Parses {@code versionString} into a {@link SupportedDevServerVersion}. The aim is to let the
* users use lowercase in version strings.
*/
public static SupportedDevServerVersion parse(String versionString) {
if ("1".equals(versionString)) {
return V1;
} else if ("2-alpha".equals(versionString)) {
return V2ALPHA;
} else {
throw new IllegalArgumentException("Unsupported version value: " + versionString);
}
}
}

AppEngineStandardStaging standardStaging();

AppEngineFlexibleStaging flexibleStaging();

AppEngineDeployment deployment();

AppEngineDevServer devServerRunSync();
AppEngineDevServer devServerRunSync(SupportedDevServerVersion version);

AppEngineDevServer devServerRunAsync(int startSuccessTimeout);
AppEngineDevServer devServerRunAsync(int startSuccessTimeout, SupportedDevServerVersion version);

AppEngineDevServer devServerStop();
AppEngineDevServer devServerStop(SupportedDevServerVersion version);

GenRepoInfoFile genRepoInfoFile();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.cloud.tools.appengine.cloudsdk.CloudSdk;
import com.google.cloud.tools.appengine.cloudsdk.CloudSdkAppEngineDeployment;
import com.google.cloud.tools.appengine.cloudsdk.CloudSdkAppEngineDevServer;
import com.google.cloud.tools.appengine.cloudsdk.CloudSdkAppEngineDevServer1;
import com.google.cloud.tools.appengine.cloudsdk.CloudSdkAppEngineFlexibleStaging;
import com.google.cloud.tools.appengine.cloudsdk.CloudSdkAppEngineStandardStaging;
import com.google.cloud.tools.appengine.cloudsdk.CloudSdkGenRepoInfoFile;
Expand Down Expand Up @@ -65,21 +66,38 @@ public AppEngineDeployment deployment() {
}

@Override
public AppEngineDevServer devServerRunSync() {
return cloudSdkFactory.devServer(defaultCloudSdkBuilder().build());
public AppEngineDevServer devServerRunSync(SupportedDevServerVersion version) {
return createDevServerForVersion(version);
}

private AppEngineDevServer createDevServerForVersion(SupportedDevServerVersion version) {
return createDevServerForVersion(version, defaultCloudSdkBuilder().build());
}

private AppEngineDevServer createDevServerForVersion(SupportedDevServerVersion version,
CloudSdk cloudSdk) {
switch (version) {
case V1:
return cloudSdkFactory.devServer1(cloudSdk);
case V2ALPHA:
return cloudSdkFactory.devServer(cloudSdk);
default:
throw new IllegalArgumentException("Unsupported dev server version: " + version);
}
}

@Override
public AppEngineDevServer devServerRunAsync(int startSuccessTimeout) {
public AppEngineDevServer devServerRunAsync(int startSuccessTimeout,
SupportedDevServerVersion version) {
CloudSdk.Builder builder = defaultCloudSdkBuilder()
.async(true)
.runDevAppServerWait(startSuccessTimeout);
return cloudSdkFactory.devServer(builder.build());
return createDevServerForVersion(version, builder.build());
}

@Override
public AppEngineDevServer devServerStop() {
return cloudSdkFactory.devServer(defaultCloudSdkBuilder().build());
public AppEngineDevServer devServerStop(SupportedDevServerVersion version) {
return createDevServerForVersion(version);
}

@Override
Expand Down Expand Up @@ -139,6 +157,10 @@ public AppEngineDevServer devServer(CloudSdk cloudSdk) {
return new CloudSdkAppEngineDevServer(cloudSdk);
}

public AppEngineDevServer devServer1(CloudSdk cloudSdk) {
return new CloudSdkAppEngineDevServer1(cloudSdk);
}

public GenRepoInfoFile genRepoInfoFile(CloudSdk cloudSdk) {
return new CloudSdkGenRepoInfoFile(cloudSdk);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.google.cloud.tools.maven;

import com.google.cloud.tools.maven.AppEngineFactory.SupportedDevServerVersion;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Execute;
Expand All @@ -41,11 +43,13 @@ public class RunAsyncMojo extends RunMojo {
public void execute() throws MojoExecutionException, MojoFailureException {
verifyAppEngineStandardApp();

getLog().info("Waiting " + startSuccessTimeout + " seconds for the Dev App Server to start.");
SupportedDevServerVersion version = convertDevserverVersionString();
getLog().info("Waiting " + startSuccessTimeout + " seconds for the Dev App Server "
+ devserverVersion + " to start.");

getAppEngineFactory().devServerRunAsync(startSuccessTimeout).run(this);
getAppEngineFactory().devServerRunAsync(startSuccessTimeout, version).run(this);

getLog().info("Dev App Server started.");
getLog().info("Dev App Server " + devserverVersion + " started.");
getLog().info("Use the 'mvn appengine:stop' command to stop the server.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.tools.maven;

import com.google.cloud.tools.appengine.api.devserver.RunConfiguration;
import com.google.cloud.tools.maven.AppEngineFactory.SupportedDevServerVersion;

import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -52,6 +53,14 @@ public class RunMojo extends CloudSdkMojo implements RunConfiguration {
required = true)
protected List<File> services;

/**
* Version of the dev app server to use to run the services. Supported values are "1" and
* "2-alpha". (default: "1")
*/
@Parameter(alias = "devserver.version", property = "app.devserver.version", required = true,
defaultValue = "1")
protected String devserverVersion;

/**
* Host name to which application modules should bind. (default: localhost)
*/
Expand Down Expand Up @@ -83,11 +92,19 @@ public class RunMojo extends CloudSdkMojo implements RunConfiguration {
protected String authDomain;

/**
* Path to the data (datastore, blobstore, etc.) associated with the application. (default: None)
* Path to the data (datastore, blobstore, etc.) associated with the application. Supported only
* for devserver version 2-alpha. (default: None)
*/
@Parameter(alias = "devserver.storagePath", property = "app.devserver.storagePath")
protected File storagePath;

/**
* Path to a file used to store datastore contents (defaults to a file in --storage_path if not
* set). Supported only for devserver version 2-alpha.(default: None)
*/
@Parameter(alias = "devserver.datastorePath", property = "app.devserver.datastorePath")
protected File datastorePath;

/**
* The log level below which logging messages generated by application code will not be displayed
* on the console. Options: debug, info, warning, critical, error. (default: info)
Expand Down Expand Up @@ -207,9 +224,24 @@ public class RunMojo extends CloudSdkMojo implements RunConfiguration {

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
SupportedDevServerVersion convertedVersion = convertDevserverVersionString();
handleAppYamlsDeprecation();
verifyAppEngineStandardApp();
getAppEngineFactory().devServerRunSync().run(this);
getAppEngineFactory().devServerRunSync(convertedVersion).run(this);
}

/**
* Verifies that {@code version} is of the supported values.
* @throws MojoExecutionException if {@code version} cannot be converted to
* {@link SupportedDevServerVersion}
*/
protected SupportedDevServerVersion convertDevserverVersionString()
throws MojoExecutionException {
try {
return SupportedDevServerVersion.parse(devserverVersion);
} catch (IllegalArgumentException ex) {
throw new MojoExecutionException("Invalid version", ex);
}
}

/**
Expand Down Expand Up @@ -396,7 +428,6 @@ public List<File> getServices() {

@Override
public File getDatastorePath() {
// TODO Auto-generated method stub
return null;
return datastorePath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.tools.maven;

import com.google.cloud.tools.appengine.api.devserver.StopConfiguration;
import com.google.cloud.tools.maven.AppEngineFactory.SupportedDevServerVersion;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand All @@ -29,6 +30,26 @@
@Mojo(name = "stop")
public class StopMojo extends CloudSdkMojo implements StopConfiguration {

/**
* Version of the dev app server to use to run the services. Supported values are "1" and
* "2-alpha". (default: "1")
*/
@Parameter(alias = "devserver.version", property = "app.devserver.version", required = true,
defaultValue = "1")
protected String devserverVersion;

/**
* Host name to which application modules should bind. (default: localhost)
*/
@Parameter(alias = "devserver.host", property = "app.devserver.host")
protected String host;

/**
* Lowest port to which application modules should bind. (default: 8080)
*/
@Parameter(alias = "devserver.port", property = "app.devserver.port")
protected Integer port;

/**
* Host name to which the admin server was bound. (default: localhost)
*/
Expand All @@ -41,17 +62,34 @@ public class StopMojo extends CloudSdkMojo implements StopConfiguration {
@Parameter(alias = "devserver.adminPort", property = "app.devserver.adminPort")
protected Integer adminPort;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
getAppEngineFactory().devServerStop().stop(this);
SupportedDevServerVersion convertedVersion = null;
try {
convertedVersion = SupportedDevServerVersion.parse(devserverVersion);
} catch (IllegalArgumentException ex) {
throw new MojoExecutionException("Invalid version", ex);
}
getAppEngineFactory().devServerStop(convertedVersion).stop(this);
}

@Override
public String getAdminHost() {
return adminHost;
// https://github.com/GoogleCloudPlatform/app-maven-plugin/issues/164
if (SupportedDevServerVersion.parse(devserverVersion) == SupportedDevServerVersion.V2ALPHA) {
return adminHost;
} else {
return host;
}
}

@Override
public Integer getAdminPort() {
return adminPort;
// https://github.com/GoogleCloudPlatform/app-maven-plugin/issues/164
if (SupportedDevServerVersion.parse(devserverVersion) == SupportedDevServerVersion.V2ALPHA) {
return adminPort;
} else {
return port;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.mockito.Mockito.when;

import com.google.cloud.tools.appengine.cloudsdk.CloudSdk;
import com.google.cloud.tools.maven.AppEngineFactory.SupportedDevServerVersion;
import com.google.cloud.tools.maven.CloudSdkAppEngineFactory.DefaultProcessOutputLineListener;

import org.junit.Before;
Expand All @@ -31,7 +32,6 @@
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;

Expand Down Expand Up @@ -99,9 +99,20 @@ public void testDeployment() {
}

@Test
public void testDevServerRunSync() {
public void testDevServer1RunSync() {
// invoke
factory.devServerRunSync();
factory.devServerRunSync(SupportedDevServerVersion.V1);

// verify
verify(cloudSdkBuilderMock).build();
verify(cloudSdkFactoryMock).devServer1(cloudSdkMock);
verifyDefaultCloudSdkBuilder();
}

@Test
public void testDevServer2RunSync() {
// invoke
factory.devServerRunSync(SupportedDevServerVersion.V2ALPHA);

// verify
verify(cloudSdkBuilderMock).build();
Expand All @@ -110,11 +121,26 @@ public void testDevServerRunSync() {
}

@Test
public void testDevServerRunAsync() {
public void testDevServer1RunAsync() {
final int START_SUCCESS_TIMEOUT = 25;

// invoke
factory.devServerRunAsync(START_SUCCESS_TIMEOUT, SupportedDevServerVersion.V1);

// verify
verify(cloudSdkBuilderMock).build();
verify(cloudSdkFactoryMock).devServer1(cloudSdkMock);
verify(cloudSdkBuilderMock).async(true);
verify(cloudSdkBuilderMock).runDevAppServerWait(START_SUCCESS_TIMEOUT);
verifyDefaultCloudSdkBuilder();
}

@Test
public void testDevServer2RunAsync() {
final int START_SUCCESS_TIMEOUT = 25;

// invoke
factory.devServerRunAsync(START_SUCCESS_TIMEOUT);
factory.devServerRunAsync(START_SUCCESS_TIMEOUT, SupportedDevServerVersion.V2ALPHA);

// verify
verify(cloudSdkBuilderMock).build();
Expand All @@ -125,9 +151,18 @@ public void testDevServerRunAsync() {
}

@Test
public void testDevServerStop() {
public void testDevServer1Stop() {
// invoke
factory.devServerStop(SupportedDevServerVersion.V1);

// verify
verify(cloudSdkFactoryMock).devServer1(cloudSdkMock);
}

@Test
public void testDevServer2Stop() {
// invoke
factory.devServerStop();
factory.devServerStop(SupportedDevServerVersion.V2ALPHA);

// verify
verify(cloudSdkFactoryMock).devServer(cloudSdkMock);
Expand Down
Loading

0 comments on commit e71b362

Please sign in to comment.