Skip to content

Commit

Permalink
changed default for marathon configuration to application.json and …
Browse files Browse the repository at this point in the history
…adapted legacy handling for `app-definition.json`

Fixes #7
  • Loading branch information
unterstein committed Mar 14, 2017
1 parent 2d80680 commit 81d5853
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 7 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion samples/jee-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<plugin>
<groupId>dcos</groupId>
<artifactId>dcos-maven-plugin</artifactId>
<version>0.1</version>
<version>0.3-SNAPSHOT</version>
<configuration>
<dcosUrl>https://frontend-elasticl-lgydh6t853qv-753743843.eu-central-1.elb.amazonaws.com/</dcosUrl>
<ignoreSslCertificate>true</ignoreSslCertificate>
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion samples/simple-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<plugin>
<groupId>dcos</groupId>
<artifactId>dcos-maven-plugin</artifactId>
<version>0.1</version>
<version>0.3-SNAPSHOT</version>
<configuration>
<dcosUrl>https://junterste-elasticl-wzqyi9j6o2f2-484663919.eu-central-1.elb.amazonaws.com/</dcosUrl>
<ignoreSslCertificate>true</ignoreSslCertificate>
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion samples/spring-boot-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<plugin>
<groupId>dcos</groupId>
<artifactId>dcos-maven-plugin</artifactId>
<version>0.1</version>
<version>0.3-SNAPSHOT</version>
<configuration>
<dcosUrl>http://junterste-elasticl-792mfv4rl50j-59247683.us-west-2.elb.amazonaws.com/</dcosUrl>
<ignoreSslCertificate>true</ignoreSslCertificate>
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/dcos/AbstractDcosMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
*/
abstract class AbstractDcosMojo extends AbstractMojo {

@Parameter(defaultValue = "${project.basedir}/app-definition.json", property = "appDefinition", required = true)
@Parameter(defaultValue = "${project.basedir}/application.json", property = "appDefinition", required = true)
File appDefinitionFile;

@Parameter(defaultValue = "${project.basedir}/app-definition.json", property = "legacyAppDefinition", required = true, readonly = true)
File legacyAppDefinitionFile;

@Parameter(defaultValue = "${project.basedir}/.dcos-token", property = "dcosTokenFile", required = true)
File dcosTokenFile;

Expand All @@ -31,6 +34,7 @@ abstract class AbstractDcosMojo extends AbstractMojo {
void logConfiguration() {
Log log = getLog();
log.info("app definition: " + appDefinitionFile);
log.info("legacy default app definition: " + legacyAppDefinitionFile);
log.info("dcos token: " + dcosTokenFile);
log.info("dcos url: " + dcosUrl);
log.info("ignore ssl certificate: " + ignoreSslCertificate);
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/dcos/DcosDeployMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ public void execute() throws MojoExecutionException {
getLog().info("About to execute DC/OS deploy");
logConfiguration();
client = DcosPluginHelper.buildClient(ignoreSslCertificate);
Map<String, Object> marathonConfigurationJson = DcosPluginHelper.readJsonFileToMap(appDefinitionFile);
Map<String, Object> marathonConfigurationJson = DcosPluginHelper.readJsonFileToMap(appDefinitionFile, legacyAppDefinitionFile);
HttpPut put = new HttpPut(buildDcosUrl(marathonConfigurationJson.get("id"), marathonConfigurationJson));
put.setHeader("Authorization", "token=" + DcosPluginHelper.readToken(dcosTokenFile));
put.setHeader("Content-Type", "application/json");
put.setEntity(new FileEntity(appDefinitionFile));
if (appDefinitionFile.exists()) {
put.setEntity(new FileEntity(appDefinitionFile));
} else {
// legacy handling
put.setEntity(new FileEntity(legacyAppDefinitionFile));
}
CloseableHttpResponse response = client.execute(put);
getLog().info("Response from DC/OS [" + response.getStatusLine().getStatusCode() + "] " + IOUtils.toString(response.getEntity().getContent(), "UTF-8"));
} catch (Exception e) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/dcos/DcosPluginHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ static Map<String, Object> readJsonFileToMap(File file) {
}
}

@SuppressWarnings("deprecation")
static Map<String, Object> readJsonFileToMap(File file, File fallbackFile) {
if (file.exists()) {
return readJsonFileToMap(file);
}
return readJsonFileToMap(fallbackFile);
}

@SuppressWarnings("deprecation")
static String readToken(File tokenFile) {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dcos/DcosRestartMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void execute() throws MojoExecutionException {
getLog().info("About to execute DC/OS restart");
logConfiguration();
client = DcosPluginHelper.buildClient(ignoreSslCertificate);
Map<String, Object> marathonConfigurationJson = DcosPluginHelper.readJsonFileToMap(appDefinitionFile);
Map<String, Object> marathonConfigurationJson = DcosPluginHelper.readJsonFileToMap(appDefinitionFile, legacyAppDefinitionFile);
HttpPost post = new HttpPost(DcosPluginHelper.cleanUrl(buildDcosUrl(marathonConfigurationJson.get("id"), marathonConfigurationJson) + "/restart"));
post.setHeader("Authorization", "token=" + DcosPluginHelper.readToken(dcosTokenFile));
CloseableHttpResponse response = client.execute(post);
Expand Down

0 comments on commit 81d5853

Please sign in to comment.