-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into issue-235-Networks-create
- Loading branch information
Showing
11 changed files
with
586 additions
and
64 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
src/main/java/com/amihaiemil/docker/FilteredUriBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* Copyright (c) 2018, Mihai Emil Andronache | ||
* All rights reserved. | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* 1)Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* 2)Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* 3)Neither the name of docker-java-api nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.amihaiemil.docker; | ||
|
||
import org.apache.http.client.utils.URIBuilder; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
/** | ||
* {@link URIBuilder} with filtering. | ||
* @author Paulo Lobo (pauloeduardolobo@gmail.com) | ||
* @version $Id$ | ||
* @since 0.0.7 | ||
*/ | ||
final class FilteredUriBuilder extends URIBuilder { | ||
|
||
/** | ||
* Wrapped {@link URIBuilder}. | ||
*/ | ||
private final URIBuilder origin; | ||
|
||
/** | ||
* Filters. | ||
*/ | ||
private final Map<String, Iterable<String>> filters; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param builder Wrapped builder. | ||
* @param filters Filters. | ||
*/ | ||
FilteredUriBuilder(final URIBuilder builder, | ||
final Map<String, Iterable<String>> filters){ | ||
this.origin = builder; | ||
this.filters = filters; | ||
} | ||
|
||
@Override | ||
public URI build() { | ||
throw new UnsupportedOperationException("filters not implemented yet"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Copyright (c) 2018, Mihai Emil Andronache | ||
* All rights reserved. | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* 1)Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* 2)Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* 3)Neither the name of docker-java-api nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.amihaiemil.docker; | ||
|
||
import java.net.URI; | ||
import java.util.Iterator; | ||
import org.apache.http.client.HttpClient; | ||
|
||
/** | ||
* Listed plugins. | ||
* @author Boris Kuzmic (boris.kuzmic@gmail.com) | ||
* @since 0.0.7 | ||
* @todo #231:30min Implement ListedPlugins iterator with filtering using Map. | ||
* See ListedImages or ListedVolumes as examples. | ||
*/ | ||
final class ListedPlugins extends RtPlugins { | ||
|
||
/** | ||
* Ctor. | ||
* | ||
* @param client The http client. | ||
* @param uri The URI for this Network API. | ||
* @param dkr The docker entry point. | ||
*/ | ||
ListedPlugins(final HttpClient client, final URI uri, final Docker dkr) { | ||
super(client, uri, dkr); | ||
} | ||
|
||
@Override | ||
public Iterator<Plugin> iterator() { | ||
throw new UnsupportedOperationException( | ||
String.join(" ", | ||
"ListedPlugins.iterator() is not yet implemented.", | ||
"If you can contribute please", | ||
"do it here: https://www.github.com/amihaiemil/docker-java-api" | ||
) | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.amihaiemil.docker; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import javax.json.JsonArray; | ||
import org.apache.http.HttpStatus; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.entity.StringEntity; | ||
|
||
/** | ||
* Runtime {@link Plugins}. | ||
* | ||
* @author Boris Kuzmic (boris.kuzmic@gmail.com) | ||
* @since 0.0.7 | ||
*/ | ||
abstract class RtPlugins implements Plugins { | ||
|
||
/** | ||
* Apache HttpClient which sends the requests. | ||
*/ | ||
private final HttpClient client; | ||
|
||
/** | ||
* Base URI for Networks API. | ||
*/ | ||
private final URI baseUri; | ||
|
||
/** | ||
* Docker API. | ||
*/ | ||
private final Docker docker; | ||
|
||
/** | ||
* Ctor. | ||
* @param client The http client. | ||
* @param uri The URI for this Network API. | ||
* @param dkr The docker entry point. | ||
*/ | ||
RtPlugins(final HttpClient client, final URI uri, final Docker dkr) { | ||
this.client = client; | ||
this.baseUri = uri; | ||
this.docker = dkr; | ||
} | ||
|
||
@Override | ||
public void create(final String name, final String directory) | ||
throws IOException, UnexpectedResponseException { | ||
final HttpPost create = | ||
new HttpPost( | ||
String.format("%s/%s?name=%s", | ||
this.baseUri.toString(), | ||
"create", | ||
name | ||
) | ||
); | ||
try { | ||
create.setEntity( | ||
new StringEntity(directory) | ||
); | ||
this.client.execute( | ||
create, | ||
new MatchStatus( | ||
create.getURI(), | ||
HttpStatus.SC_NO_CONTENT | ||
) | ||
); | ||
} finally { | ||
create.releaseConnection(); | ||
} | ||
} | ||
|
||
@Override | ||
public void pullAndInstall(final String remote, final String name, | ||
final JsonArray properties) | ||
throws IOException, UnexpectedResponseException { | ||
final HttpPost pull = | ||
new HttpPost( | ||
new UncheckedUriBuilder(this.baseUri.toString().concat("/pull")) | ||
.addParameter("remote", remote) | ||
.addParameter("name", name) | ||
.build() | ||
); | ||
try { | ||
pull.setEntity( | ||
new StringEntity(properties.toString()) | ||
); | ||
this.client.execute( | ||
pull, | ||
new MatchStatus( | ||
pull.getURI(), | ||
HttpStatus.SC_NO_CONTENT | ||
) | ||
); | ||
} finally { | ||
pull.releaseConnection(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.