Skip to content

Commit 1968fba

Browse files
authored
Merge pull request #280 from bkuzmic/issue-268-Plugin
For #268: Implementing Plugin upgrade() and push() methods
2 parents 4b1b760 + 8704f87 commit 1968fba

File tree

5 files changed

+415
-43
lines changed

5 files changed

+415
-43
lines changed

src/main/java/com/amihaiemil/docker/Plugin.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@
3434
* A docker plugin.
3535
* @author Boris Kuzmic ([email protected])
3636
* @see <a href="https://docs.docker.com/engine/api/v1.35/#tag/Plugin">Docker Plugin API</a>
37-
* @todo #266:30min Continue implementing rest of the Plugin methods besides
38-
* enable and disable. More information about API methods can be found at:
39-
* https://docs.docker.com/engine/api/v1.35/#tag/Plugin
37+
* @todo #266:30min Implement Plugin#configure method. The tests are already
38+
* coded, so after the implementation just remove the ignore annotation from
39+
* these tests. More information about Configure API method can be found at:
40+
* https://docs.docker.com/engine/api/v1.35/#operation/PluginSet
4041
* @since 0.0.7
4142
*/
4243
public interface Plugin extends JsonObject {

src/main/java/com/amihaiemil/docker/RtPlugin.java

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import org.apache.http.HttpStatus;
3434
import org.apache.http.client.HttpClient;
3535
import org.apache.http.client.methods.HttpPost;
36+
import org.apache.http.entity.ContentType;
37+
import org.apache.http.entity.StringEntity;
3638

3739
/**
3840
* Runtime {@link Plugin}.
@@ -122,24 +124,47 @@ public void disable() throws IOException, UnexpectedResponseException {
122124
@Override
123125
public void upgrade(final String remote, final JsonArray properties)
124126
throws IOException, UnexpectedResponseException {
125-
throw new UnsupportedOperationException(
126-
String.join(" ",
127-
"RtPlugin.upgrade() is not yet implemented.",
128-
"If you can contribute please",
129-
"do it here: https://www.github.com/amihaiemil/docker-java-api"
130-
)
131-
);
127+
final HttpPost upgrade =
128+
new HttpPost(
129+
new UncheckedUriBuilder(this.uri.toString().concat("/upgrade"))
130+
.addParameter("remote", remote)
131+
.build()
132+
);
133+
try {
134+
upgrade.setEntity(
135+
new StringEntity(
136+
properties.toString(), ContentType.APPLICATION_JSON
137+
)
138+
);
139+
this.client.execute(
140+
upgrade,
141+
new MatchStatus(
142+
upgrade.getURI(),
143+
HttpStatus.SC_NO_CONTENT
144+
)
145+
);
146+
} finally {
147+
upgrade.releaseConnection();
148+
}
132149
}
133150

134151
@Override
135152
public void push() throws IOException, UnexpectedResponseException {
136-
throw new UnsupportedOperationException(
137-
String.join(" ",
138-
"RtPlugin.push() is not yet implemented.",
139-
"If you can contribute please",
140-
"do it here: https://www.github.com/amihaiemil/docker-java-api"
141-
)
142-
);
153+
final HttpPost push =
154+
new HttpPost(
155+
String.format("%s/%s", this.uri.toString(), "push")
156+
);
157+
try {
158+
this.client.execute(
159+
push,
160+
new MatchStatus(
161+
push.getURI(),
162+
HttpStatus.SC_OK
163+
)
164+
);
165+
} finally {
166+
push.releaseConnection();
167+
}
143168
}
144169

145170
@Override

0 commit comments

Comments
 (0)