Skip to content

Commit

Permalink
Merge pull request #280 from bkuzmic/issue-268-Plugin
Browse files Browse the repository at this point in the history
For #268: Implementing Plugin upgrade() and push() methods
  • Loading branch information
amihaiemil committed Jan 9, 2019
2 parents 4b1b760 + 8704f87 commit 1968fba
Show file tree
Hide file tree
Showing 5 changed files with 415 additions and 43 deletions.
7 changes: 4 additions & 3 deletions src/main/java/com/amihaiemil/docker/Plugin.java
Expand Up @@ -34,9 +34,10 @@
* A docker plugin.
* @author Boris Kuzmic (boris.kuzmic@gmail.com)
* @see <a href="https://docs.docker.com/engine/api/v1.35/#tag/Plugin">Docker Plugin API</a>
* @todo #266:30min Continue implementing rest of the Plugin methods besides
* enable and disable. More information about API methods can be found at:
* https://docs.docker.com/engine/api/v1.35/#tag/Plugin
* @todo #266:30min Implement Plugin#configure method. The tests are already
* coded, so after the implementation just remove the ignore annotation from
* these tests. More information about Configure API method can be found at:
* https://docs.docker.com/engine/api/v1.35/#operation/PluginSet
* @since 0.0.7
*/
public interface Plugin extends JsonObject {
Expand Down
53 changes: 39 additions & 14 deletions src/main/java/com/amihaiemil/docker/RtPlugin.java
Expand Up @@ -33,6 +33,8 @@
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;

/**
* Runtime {@link Plugin}.
Expand Down Expand Up @@ -122,24 +124,47 @@ public void disable() throws IOException, UnexpectedResponseException {
@Override
public void upgrade(final String remote, final JsonArray properties)
throws IOException, UnexpectedResponseException {
throw new UnsupportedOperationException(
String.join(" ",
"RtPlugin.upgrade() is not yet implemented.",
"If you can contribute please",
"do it here: https://www.github.com/amihaiemil/docker-java-api"
)
);
final HttpPost upgrade =
new HttpPost(
new UncheckedUriBuilder(this.uri.toString().concat("/upgrade"))
.addParameter("remote", remote)
.build()
);
try {
upgrade.setEntity(
new StringEntity(
properties.toString(), ContentType.APPLICATION_JSON
)
);
this.client.execute(
upgrade,
new MatchStatus(
upgrade.getURI(),
HttpStatus.SC_NO_CONTENT
)
);
} finally {
upgrade.releaseConnection();
}
}

@Override
public void push() throws IOException, UnexpectedResponseException {
throw new UnsupportedOperationException(
String.join(" ",
"RtPlugin.push() is not yet implemented.",
"If you can contribute please",
"do it here: https://www.github.com/amihaiemil/docker-java-api"
)
);
final HttpPost push =
new HttpPost(
String.format("%s/%s", this.uri.toString(), "push")
);
try {
this.client.execute(
push,
new MatchStatus(
push.getURI(),
HttpStatus.SC_OK
)
);
} finally {
push.releaseConnection();
}
}

@Override
Expand Down

0 comments on commit 1968fba

Please sign in to comment.