Skip to content

Commit

Permalink
Make <deployeable> obsolete. Detect automatically if you are trying…
Browse files Browse the repository at this point in the history
… to deploy an app, pod or group

Fixes #11
  • Loading branch information
unterstein committed Mar 14, 2017
1 parent 551d469 commit 2d80680
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
3 changes: 1 addition & 2 deletions samples/simple-group-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
<plugin>
<groupId>dcos</groupId>
<artifactId>dcos-maven-plugin</artifactId>
<version>0.2</version>
<version>0.3-SNAPSHOT</version>
<configuration>
<dcosUrl>https://frontend-elasticl-lgydh6t853qv-753743843.eu-central-1.elb.amazonaws.com/</dcosUrl>
<deployable>group</deployable>
<appDefinitionFile>group-definition.json</appDefinitionFile>
<ignoreSslCertificate>true</ignoreSslCertificate>
</configuration>
Expand Down
3 changes: 1 addition & 2 deletions samples/simple-pod-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
<plugin>
<groupId>dcos</groupId>
<artifactId>dcos-maven-plugin</artifactId>
<version>0.2</version>
<version>0.3-SNAPSHOT</version>
<configuration>
<dcosUrl>https://frontend-elasticl-lgydh6t853qv-753743843.eu-central-1.elb.amazonaws.com/</dcosUrl>
<deployable>pod</deployable>
<appDefinitionFile>pod-definition.json</appDefinitionFile>
<ignoreSslCertificate>true</ignoreSslCertificate>
</configuration>
Expand Down
38 changes: 31 additions & 7 deletions src/main/java/dcos/AbstractDcosMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.apache.maven.plugins.annotations.Parameter;

import java.io.File;
import java.util.Map;

/**
* Abstract Mojo for handle `mvn dcos:*` commands
Expand All @@ -24,7 +25,7 @@ abstract class AbstractDcosMojo extends AbstractMojo {
@Parameter(defaultValue = "false", property = "ignoreSslCertificate", required = true)
Boolean ignoreSslCertificate;

@Parameter(defaultValue = "APP", property = "deployable", required = true)
@Parameter(defaultValue = "EMPTY", property = "deployable", required = true)
String deployable;

void logConfiguration() {
Expand All @@ -36,16 +37,39 @@ void logConfiguration() {
log.info("deployable: " + deployable);
}

String buildDcosUrl(Object id) {
String url = dcosUrl + "/service/marathon/v2/";
String buildDcosUrl(Object id, Map<String, Object> entity) {
String baseUrl = dcosUrl + "/service/marathon/v2/";
String result;
// Legacy handling
if (StringUtils.equalsIgnoreCase("POD", deployable)) {
result = url + "pods/" + id;
result = podUrl(baseUrl, id);
} else if (StringUtils.equalsIgnoreCase("GROUP", deployable)) {
result = url + "groups/";
result = groupUrl(baseUrl, id);
} else if (StringUtils.equalsIgnoreCase("APP", deployable)) {
result = appUrl(baseUrl, id);
} else {
result = url + "apps/" + id;
// new `automatic` handling
if (entity.containsKey("containers")) {
result = podUrl(baseUrl, id);
} else if (entity.containsKey("apps")) {
result = groupUrl(baseUrl, id);
} else {
result = appUrl(baseUrl, id);
}
}
return DcosPluginHelper.cleanUrl(result);
getLog().info("Calculated url: " + result);
return result;
}

private String appUrl(String baseUrl, Object id) {
return DcosPluginHelper.cleanUrl(baseUrl + "apps/" + id);
}

private String groupUrl(String baseUrl, Object id) {
return DcosPluginHelper.cleanUrl(baseUrl + "groups/");
}

private String podUrl(String baseUrl, Object id) {
return DcosPluginHelper.cleanUrl(baseUrl + "pods/" + id);
}
}
2 changes: 1 addition & 1 deletion src/main/java/dcos/DcosDeployMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void execute() throws MojoExecutionException {
logConfiguration();
client = DcosPluginHelper.buildClient(ignoreSslCertificate);
Map<String, Object> marathonConfigurationJson = DcosPluginHelper.readJsonFileToMap(appDefinitionFile);
HttpPut put = new HttpPut(buildDcosUrl(marathonConfigurationJson.get("id")));
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));
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 @@ -24,7 +24,7 @@ public void execute() throws MojoExecutionException {
logConfiguration();
client = DcosPluginHelper.buildClient(ignoreSslCertificate);
Map<String, Object> marathonConfigurationJson = DcosPluginHelper.readJsonFileToMap(appDefinitionFile);
HttpPost post = new HttpPost(DcosPluginHelper.cleanUrl(buildDcosUrl(marathonConfigurationJson.get("id")) + "/restart"));
HttpPost post = new HttpPost(DcosPluginHelper.cleanUrl(buildDcosUrl(marathonConfigurationJson.get("id"), marathonConfigurationJson) + "/restart"));
post.setHeader("Authorization", "token=" + DcosPluginHelper.readToken(dcosTokenFile));
CloseableHttpResponse response = client.execute(post);
getLog().info("Response from DC/OS [" + response.getStatusLine().getStatusCode() + "] " + IOUtils.toString(response.getEntity().getContent(), "UTF-8"));
Expand Down

0 comments on commit 2d80680

Please sign in to comment.