|
33 | 33 | import org.apache.http.HttpStatus;
|
34 | 34 | import org.apache.http.client.HttpClient;
|
35 | 35 | import org.apache.http.client.methods.HttpPost;
|
| 36 | +import org.apache.http.entity.ContentType; |
| 37 | +import org.apache.http.entity.StringEntity; |
36 | 38 |
|
37 | 39 | /**
|
38 | 40 | * Runtime {@link Plugin}.
|
@@ -122,24 +124,47 @@ public void disable() throws IOException, UnexpectedResponseException {
|
122 | 124 | @Override
|
123 | 125 | public void upgrade(final String remote, final JsonArray properties)
|
124 | 126 | 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 | + } |
132 | 149 | }
|
133 | 150 |
|
134 | 151 | @Override
|
135 | 152 | 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 | + } |
143 | 168 | }
|
144 | 169 |
|
145 | 170 | @Override
|
|
0 commit comments