├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── circle.sh ├── circle.yml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── rx-docker-client ├── build.gradle ├── gradle.properties └── src │ ├── main │ └── java │ │ └── com │ │ └── shekhargulati │ │ └── reactivex │ │ └── docker │ │ └── client │ │ ├── AuthConfig.java │ │ ├── BuildImageQueryParameters.java │ │ ├── ContainerLogQueryParameters.java │ │ ├── ContainerOperations.java │ │ ├── DefaultRxDockerClient.java │ │ ├── DockerErrorDetails.java │ │ ├── HostAndPort.java │ │ ├── ImageListQueryParameters.java │ │ ├── ImageOperations.java │ │ ├── ImageTagQueryParameters.java │ │ ├── MiscOperations.java │ │ ├── QueryParameters.java │ │ ├── QueryParametersBuilder.java │ │ ├── RxDockerClient.java │ │ ├── function │ │ ├── ContainerEndpointUriFunction.java │ │ └── TriFunction.java │ │ ├── representations │ │ ├── ContainerArchiveInformation.java │ │ ├── ContainerChange.java │ │ ├── ContainerInspectResponse.java │ │ ├── ContainerState.java │ │ ├── ContainerStats.java │ │ ├── CpuStats.java │ │ ├── CpuUsage.java │ │ ├── DockerContainer.java │ │ ├── DockerContainerRequest.java │ │ ├── DockerContainerRequestBuilder.java │ │ ├── DockerContainerResponse.java │ │ ├── DockerImage.java │ │ ├── DockerImageHistory.java │ │ ├── DockerImageInfo.java │ │ ├── DockerImageInspectDetails.java │ │ ├── DockerInfo.java │ │ ├── DockerVersion.java │ │ ├── ExecCreateRequest.java │ │ ├── ExecCreateResponse.java │ │ ├── ExecStartRequest.java │ │ ├── HostConfig.java │ │ ├── HostConfigBuilder.java │ │ ├── Image.java │ │ ├── ImageTag.java │ │ ├── MemoryStats.java │ │ ├── NetworkSettings.java │ │ ├── NetworkStats.java │ │ ├── PortBinding.java │ │ └── ProcessListResponse.java │ │ └── utils │ │ ├── Dates.java │ │ ├── Precondition.java │ │ ├── StreamUtils.java │ │ ├── Strings.java │ │ └── Validations.java │ └── test │ ├── java │ └── com │ │ └── shekhargulati │ │ └── reactivex │ │ └── docker │ │ └── client │ │ ├── BuildImageQueryParametersTest.java │ │ ├── ContainerLogQueryParametersTest.java │ │ ├── DefaultRxDockerClientTest.java │ │ ├── HostAndPortTest.java │ │ ├── ImageListQueryParametersTest.java │ │ ├── QueryParametersTest.java │ │ ├── junit │ │ ├── CreateDockerContainer.java │ │ ├── CreateDockerContainers.java │ │ └── DockerContainerRule.java │ │ └── utils │ │ ├── FileUtilsTest.java │ │ └── StringUtilsTest.java │ └── resources │ └── images │ ├── dockerfile_option_image.tar │ ├── hello-world-image.tar │ ├── hello-world.tar │ ├── my_docker_image.tar │ └── my_hello_world_image.tar ├── samples ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── shekhargulati │ └── reactivex │ └── rx_docker_client │ └── samples │ ├── CreateExposePortsAndStartContainer.java │ └── RxDockerClientExamples.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Gradle template 3 | .gradle 4 | build/ 5 | 6 | # Ignore Gradle GUI config 7 | gradle-app.setting 8 | 9 | 10 | ### JetBrains template 11 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm 12 | 13 | *.iml 14 | 15 | ## Directory-based project format: 16 | .idea/ 17 | # if you remove the above rule, at least ignore the following: 18 | 19 | # User-specific stuff: 20 | # .idea/workspace.xml 21 | # .idea/tasks.xml 22 | # .idea/dictionaries 23 | 24 | # Sensitive or high-churn files: 25 | # .idea/dataSources.ids 26 | # .idea/dataSources.xml 27 | # .idea/sqlDataSources.xml 28 | # .idea/dynamic.xml 29 | # .idea/uiDesigner.xml 30 | 31 | # Gradle: 32 | # .idea/gradle.xml 33 | # .idea/libraries 34 | 35 | # Mongo Explorer plugin: 36 | # .idea/mongoSettings.xml 37 | 38 | ## File-based project format: 39 | *.ipr 40 | *.iws 41 | 42 | ## Plugin-specific files: 43 | 44 | # IntelliJ 45 | out/ 46 | 47 | # mpeltonen/sbt-idea plugin 48 | .idea_modules/ 49 | 50 | # JIRA plugin 51 | atlassian-ide-plugin.xml 52 | 53 | # Crashlytics plugin (for Android Studio and IntelliJ) 54 | com_crashlytics_export_strings.xml 55 | crashlytics.properties 56 | crashlytics-build.properties 57 | 58 | 59 | ### Java template 60 | *.class 61 | 62 | # Mobile Tools for Java (J2ME) 63 | .mtj.tmp/ 64 | 65 | # Package Files # 66 | *.jar 67 | *.war 68 | *.ear 69 | 70 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 71 | hs_err_pid* 72 | 73 | rx-docker-client.iml 74 | 75 | !gradle/wrapper/gradle-wrapper.jar 76 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright 2015 Shekhar Gulati . 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Rx Docker Client [![Circle CI](https://circleci.com/gh/shekhargulati/rx-docker-client.png?style=shield)](https://circleci.com/gh/shekhargulati/rx-docker-client) [![](https://img.shields.io/maven-central/v/com.shekhargulati.reactivex/rx-docker-client.svg)](http://search.maven.org/#search%7Cga%7C1%7Crx-docker-client) [![License](https://img.shields.io/:license-mit-blue.svg)](./LICENSE) 2 | ========= 3 | 4 | rx-docker-client is a reactive Java REST API client for Docker REST API(http://docs.docker.com/engine/reference/api/docker_remote_api/). The API uses JDK 8. It makes use of following awesome libraries to get the job done: 5 | 6 | 1. RxJava 7 | 2. OKHttp 8 | 3. Gson 9 | 10 | ## Table of Contents 11 | * [Why](#why) 12 | * [Getting Started](#getting-started) 13 | * [Usage](#usage) 14 | * [License](#license) 15 | 16 | Why 17 | ---- 18 | 19 | Most of the existing Java Docker client are synchronous in nature. This API makes use of Reactive programming paradigm so every API call returns an Observable. It allows you to compose REST API calls together. You can use functional methods like `map`, `filter`,`flatmap`, `zip`, etc on the returned Observable. You can decide whether you want to subscribe on the main thread or use a thread from the thread pool and get results on it. It provides a higher fluent abstraction that you can use to write composable programs. 20 | 21 | To show the power of rx-docker-client API, let's suppose you want to search **ubuntu** image and then pull the image corresponding to the first search result. You can do this very easily with rx-docker-client as shown below. 22 | 23 | ```java 24 | RxDockerClient client = RxDockerClient.fromDefaultEnv(); 25 | client.searchImagesObs("ubuntu") 26 | .first() 27 | .flatMap(imageInfo -> client.pullImageObs(imageInfo.getName())) 28 | .subscribe(System.out::println); 29 | ``` 30 | 31 | In the code shown above, `first`, `flatMap`, and `subscribe` are all RxJava operators. The `searchImagesObs` and `pullImageObs` returns Observable so we can compose different functions together. 32 | 33 | Getting Started 34 | -------- 35 | 36 | To use rx-docker-client in your application, you have to add `rx-docker-client` in your classpath. rx-docker-client is available on [Maven Central](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22rx-docker-client%22) so you just need to add dependency to your favorite build tool as show below. 37 | 38 | For Apache Maven users, please add following to your pom.xml. 39 | 40 | ```xml 41 | 42 | 43 | com.shekhargulati.reactivex 44 | rx-docker-client 45 | 0.2.2 46 | jar 47 | 48 | 49 | ``` 50 | 51 | Gradle users can add following to their build.gradle file. 52 | 53 | ``` 54 | compile(group: 'com.shekhargulati.reactivex', name: 'rx-docker-client', version: '0.2.2', ext: 'jar'){ 55 | transitive=true 56 | } 57 | ``` 58 | 59 | Usage 60 | ----- 61 | For most of the operations rx-docker-client provide both the blocking and non-blocking methods. The non-blocking methods returns an Observable so you can compose functions together. 62 | 63 | ### Blocking methods 64 | 65 | Below are few examples of some of the blocking methods. When you make call to these methods they will return when they have result. 66 | 67 | ```java 68 | //Create a new Docker client using DOCKER_HOST and DOCKER_CERT_PATH environment variables 69 | RxDockerClient client = RxDockerClient.fromDefaultEnv(); 70 | 71 | // Getting Docker version 72 | DockerVersion dockerVersion = client.serverVersion(); 73 | System.out.println(dockerVersion.version()); // 1.8.3 74 | 75 | DockerInfo info = client.info(); 76 | System.out.println(info.images()); // 40 77 | 78 | HttpStatus ping = client.ping(); 79 | System.out.println(ping); // HttpStatus{code=200, message='OK'} 80 | 81 | // Pull image 82 | HttpStatus successPullImage = client.pullImage("ubuntu"); 83 | System.out.println("On Success HTTP Code will be 200"); 84 | ``` 85 | 86 | ### non-blocking methods 87 | 88 | It is suggested that you use methods which return an Observable as they allow you to write non-blocking and composable code. All the non-blocking methods name ends with **Obs**. 89 | 90 | #### To pull image 91 | 92 | ```java 93 | //Create a new Docker client using DOCKER_HOST and DOCKER_CERT_PATH environment variables 94 | RxDockerClient client = RxDockerClient.fromDefaultEnv(); 95 | 96 | // pull the latest image from Docker Hub 97 | Observable pullImageObs = client.pullImageObs("busybox"); 98 | pullImageObs.subscribe(System.out::println, 99 | e -> System.err.println("Encountered exception >> " + e.getMessage()), 100 | () -> System.out.println("Successfully completed")); 101 | ``` 102 | 103 | ### Create and start container 104 | 105 | ```java 106 | DockerContainerRequest request = new DockerContainerRequestBuilder() 107 | .setImage("ubuntu:latest") 108 | .setCmd(Arrays.asList("/bin/bash")) 109 | .setAttachStdin(true) 110 | .setTty(true) 111 | .createDockerContainerRequest(); 112 | 113 | String container = "my_first_container"; 114 | client.createContainerObs(request, container) 115 | .flatMap(res -> client.startContainerObs(res.getId())) 116 | .subscribe(System.out::println); 117 | ``` 118 | 119 | #### Creating and starting multiple containers 120 | 121 | 122 | ```java 123 | RxDockerClient dockerClient = RxDockerClient.fromDefaultEnv(); 124 | 125 | DockerContainerRequest request = new DockerContainerRequestBuilder() 126 | .setImage("ubuntu:latest") 127 | .setCmd(Arrays.asList("/bin/bash")) 128 | .setAttachStdin(true) 129 | .setTty(true) 130 | .createDockerContainerRequest(); 131 | 132 | Observable.range(1, 10) 133 | .flatMap(i -> dockerClient.createContainerObs(request, "container-" + i)) 134 | .flatMap(r -> dockerClient.startContainerObs(r.getId()), (containerResponse, status) -> String.format("%s >> %d", containerResponse.getId(), status.code())) 135 | .forEach(System.out::println); 136 | ``` 137 | 138 | ### Create and start container with exposed ports 139 | 140 | ```java 141 | RxDockerClient client = RxDockerClient.fromDefaultEnv(); 142 | final String[] exposedPorts = new String[]{"9999/tcp"}; 143 | final String[] hostPorts = new String[]{"9999/tcp"}; 144 | 145 | final Map> portBindings = new HashMap<>(); 146 | for (String hostPort : hostPorts) { 147 | List hostPortBinding = new ArrayList<>(); 148 | hostPortBinding.add(PortBinding.of("0.0.0.0", hostPort)); 149 | portBindings.put(hostPort, hostPortBinding); 150 | } 151 | final HostConfig hostConfig = new HostConfigBuilder().setPortBindings(portBindings).createHostConfig(); 152 | DockerContainerRequest request = new DockerContainerRequestBuilder() 153 | .setImage("ubuntu") 154 | .setCmd(Arrays.asList("/bin/bash")) 155 | .setAttachStdin(true) 156 | .addExposedPort(exposedPorts) 157 | .setHostConfig(hostConfig) 158 | .setTty(true) 159 | .createDockerContainerRequest(); 160 | DockerContainerResponse response = client.createContainer(request, "my_container"); 161 | client.startContainer(response.getId()); 162 | ``` 163 | 164 | ### Container Stats 165 | 166 | ```java 167 | Observable containerStatsObservable = client.containerStatsObs(containerId); 168 | Subscriber containerStatsSubscriber = new Subscriber() { 169 | 170 | @Override 171 | public void onCompleted() { 172 | logger.info("Successfully received all the container stats for container with id {}", containerId); 173 | } 174 | 175 | @Override 176 | public void onError(Throwable e) { 177 | logger.error("Error encountered while processing container stats for container with id {}", containerId); 178 | } 179 | 180 | @Override 181 | public void onNext(ContainerStats msg) { 182 | logger.info("Received a new message for container '{}'", containerId); 183 | } 184 | }; 185 | ``` 186 | ### View Container logs 187 | 188 | ```java 189 | Observable logsObs = client.containerLogsObs(containerId); 190 | logsObs.subscribe(System.out::println, 191 | e -> System.err.println("Encountered exception >> " + e.getMessage()), 192 | () -> System.out.println("Successfully completed")); 193 | ``` 194 | 195 | ### Build image 196 | 197 | ```java 198 | Observable buildImageObs = client.buildImageObs("shekhargulati/my_hello_world_image", 199 | Paths.get("src", "test", "resources", "images", "my_hello_world_image.tar")); 200 | buildImageObs.subscribe(System.out::println); 201 | ``` 202 | 203 | ### Building and pushing image 204 | 205 | ```java 206 | String image = "shekhar007/my_hello_world_image"; 207 | 208 | Observable buildImageObs = client.buildImageObs(image, Paths.get("src", "test", "resources", "images", "my_hello_world_image.tar")); 209 | 210 | buildImageObs.subscribe(System.out::println, 211 | e -> System.err.println("Encountered exception >> " + e.getMessage()), 212 | () -> System.out.println("Successfully completed")); 213 | 214 | client.pushImageObs(image, AuthConfig.authConfig("xxxx", "xxx", "xxx")).subscribe(System.out::println, 215 | e -> System.err.println("Encountered exception >> " + e.getMessage()), 216 | () -> System.out.println("Successfully completed")); 217 | ``` 218 | 219 | 220 | ### Misc functions 221 | 222 | ```java 223 | client.removeImage("hello-world"); 224 | client.removeDanglingImages(); 225 | client.listDanglingImages(); 226 | client.removeImages(dockerImage -> dockerImage.repoTags().stream().anyMatch(repo -> repo.contains("test_rx_docker"))); 227 | client.removeAllContainers(); 228 | ``` 229 | 230 | License 231 | ------- 232 | rx-docker-client is licensed under the MIT License - see the `LICENSE` file for details. 233 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | allprojects { 2 | group = "com.shekhargulati.reactivex" 3 | } 4 | 5 | subprojects { 6 | 7 | apply plugin: 'java' 8 | apply plugin: 'eclipse' 9 | apply plugin: 'idea' 10 | apply plugin: 'signing' 11 | 12 | sourceCompatibility = 1.8 13 | targetCompatibility = 1.8 14 | 15 | repositories { 16 | mavenCentral() 17 | } 18 | 19 | dependencies { 20 | testCompile group: 'junit', name: 'junit', version: '4.12' 21 | 22 | } 23 | 24 | task javadocJar(type: Jar) { 25 | classifier = 'javadoc' 26 | from javadoc 27 | } 28 | 29 | task sourcesJar(type: Jar) { 30 | classifier = 'sources' 31 | from sourceSets.main.allSource 32 | } 33 | 34 | artifacts { 35 | archives javadocJar, sourcesJar 36 | } 37 | 38 | signing { 39 | sign configurations.archives 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /circle.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -ex 2 | 3 | docker_opts='DOCKER_OPTS="$DOCKER_OPTS -D -H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock --registry-mirror=http://localhost:5000"' 4 | sudo sh -c "echo '$docker_opts' >> /etc/default/docker" 5 | cat /etc/default/docker 6 | export DOCKER_HOST=tcp://127.0.0.1:2375 -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | pre: 3 | - rx-docker-client/circle.sh 4 | java: 5 | version: oraclejdk8 6 | services: 7 | - docker 8 | 9 | ## Customize test commands 10 | test: 11 | post: 12 | - mkdir -p $CIRCLE_ARTIFACTS/junit/ 13 | - find . -type f -regex ".*/rx-docker-client/target/surefire-reports/.*xml" -exec cp {} $CIRCLE_ARTIFACTS/junit/ \; 14 | - find . -type f -regex ".*/rx-docker-client/build/reports/tests/index.html" -exec cp {} $CIRCLE_ARTIFACTS/junit/ \; 15 | - find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} $CIRCLE_ARTIFACTS/junit/ \; 16 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | version=0.2.2-SNAPSHOT -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shekhargulati/rx-docker-client/7268db42a1de77c43e713247ac3732a9e054de69/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Sep 08 06:38:35 IST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /rx-docker-client/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'net.researchgate.release' version '2.3.3' 3 | } 4 | apply plugin: 'java' 5 | apply plugin: 'maven' 6 | apply plugin: 'maven-publish' 7 | apply plugin: "jacoco" 8 | 9 | group = 'com.shekhargulati.reactivex' 10 | 11 | repositories { 12 | mavenLocal() 13 | mavenCentral() 14 | } 15 | 16 | uploadArchives { 17 | repositories { 18 | mavenDeployer { 19 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 20 | 21 | repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { 22 | authentication(userName: System.getenv('OSS_USER'), password: System.getenv('OSS_PASSWORD')) 23 | } 24 | 25 | snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { 26 | authentication(userName: System.getenv('OSS_USER'), password: System.getenv('OSS_PASSWORD')) 27 | } 28 | 29 | pom.project { 30 | name 'Rx Docker Client' 31 | packaging 'jar' 32 | artifactId 'rx-docker-client' 33 | description 'RxJava based Docker REST API client for the JVM' 34 | url 'https://github.com/shekhargulati/rx-docker-client' 35 | 36 | scm { 37 | connection 'https://github.com/shekhargulati/rx-docker-client.git' 38 | developerConnection 'https://github.com/shekhargulati/rx-docker-client.git' 39 | url 'https://github.com/shekhargulati/rx-docker-client.git' 40 | } 41 | 42 | licenses { 43 | license { 44 | name 'MIT' 45 | url 'https://github.com/shekhargulati/rx-docker-client/blob/master/LICENSE' 46 | } 47 | } 48 | 49 | developers { 50 | developer { 51 | id 'shekhargulati' 52 | name 'Shekhar Gulati' 53 | email 'shekhargulati84@gmail.com' 54 | } 55 | } 56 | } 57 | } 58 | } 59 | } 60 | 61 | 62 | dependencies { 63 | 64 | compile 'com.shekhargulati.reactivex:rx-okhttp:0.1.9' 65 | compile 'com.google.code.gson:gson:2.6.2' 66 | compile 'org.slf4j:slf4j-api:1.7.12' 67 | 68 | testCompile 'org.slf4j:slf4j-simple:1.7.12' 69 | testCompile 'org.hamcrest:hamcrest-all:1.3' 70 | } 71 | 72 | jacocoTestReport { 73 | reports { 74 | xml.enabled = true 75 | html.enabled = true 76 | } 77 | } 78 | 79 | check.dependsOn jacocoTestReport -------------------------------------------------------------------------------- /rx-docker-client/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # /* 3 | # * The MIT License 4 | # * 5 | # * Copyright 2015 Shekhar Gulati . 6 | # * 7 | # * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # * of this software and associated documentation files (the "Software"), to deal 9 | # * in the Software without restriction, including without limitation the rights 10 | # * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # * copies of the Software, and to permit persons to whom the Software is 12 | # * furnished to do so, subject to the following conditions: 13 | # * 14 | # * The above copyright notice and this permission notice shall be included in 15 | # * all copies or substantial portions of the Software. 16 | # * 17 | # * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | # * THE SOFTWARE. 24 | # */ 25 | # 26 | 27 | version=0.2.3-SNAPSHOT -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/AuthConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client; 26 | 27 | import com.google.gson.Gson; 28 | import com.google.gson.GsonBuilder; 29 | import com.google.gson.annotations.SerializedName; 30 | 31 | import java.util.Base64; 32 | 33 | import static com.google.gson.FieldNamingPolicy.UPPER_CAMEL_CASE; 34 | 35 | public class AuthConfig { 36 | 37 | @SerializedName("Username") 38 | private String username; 39 | @SerializedName("Password") 40 | private String password; 41 | @SerializedName("Email") 42 | private String email; 43 | @SerializedName("ServerAddress") 44 | private String serverAddress = "https://index.docker.io/v1/"; 45 | 46 | private Gson gson = new GsonBuilder() 47 | .setFieldNamingPolicy(UPPER_CAMEL_CASE) 48 | .setPrettyPrinting().create(); 49 | 50 | public AuthConfig(String username, String password, String email) { 51 | this.username = username; 52 | this.password = password; 53 | this.email = email; 54 | } 55 | 56 | public static AuthConfig authConfig(String username, String password, String email) { 57 | return new AuthConfig(username, password, email); 58 | } 59 | 60 | public AuthConfig withServerAddress(String serverAddress) { 61 | this.serverAddress = serverAddress; 62 | return this; 63 | } 64 | 65 | public String username() { 66 | return username; 67 | } 68 | 69 | public String password() { 70 | return password; 71 | } 72 | 73 | public String email() { 74 | return email; 75 | } 76 | 77 | public String serverAddress() { 78 | return serverAddress; 79 | } 80 | 81 | public String xAuthHeader() { 82 | return Base64.getEncoder().encodeToString(toJson().getBytes()); 83 | } 84 | 85 | public String toJson() { 86 | return gson.toJson(this); 87 | } 88 | } 89 | 90 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/BuildImageQueryParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client; 26 | 27 | import java.util.Optional; 28 | 29 | public class BuildImageQueryParameters { 30 | private Optional dockerFile = Optional.empty(); 31 | private Optional remote = Optional.empty(); 32 | 33 | public static BuildImageQueryParameters withRemoteDockerfile(final String remote) { 34 | return new BuildImageQueryParameters(null, remote); 35 | } 36 | 37 | private BuildImageQueryParameters() { 38 | this(null, null); 39 | } 40 | 41 | public BuildImageQueryParameters(String dockerFile) { 42 | this(dockerFile, null); 43 | } 44 | 45 | public BuildImageQueryParameters(String dockerFile, String remote) { 46 | this.dockerFile = Optional.ofNullable(dockerFile); 47 | this.remote = Optional.ofNullable(remote); 48 | } 49 | 50 | public String toQueryParameterString() { 51 | Optional queryBuilder = Optional.of(new StringBuilder("&")) 52 | .flatMap(qb -> Optional.ofNullable(dockerFile.map(df -> qb.append("dockerfile=").append(df).append("&")).orElse(qb))) 53 | .flatMap(qb -> Optional.ofNullable(remote.map(r -> qb.append("remote=").append(r).append("&")).orElse(qb))); 54 | return queryBuilder 55 | .filter(qb -> qb.toString().endsWith("&")) 56 | .map(StringBuilder::toString) 57 | .map(qb -> qb.substring(0, qb.lastIndexOf("&"))) 58 | .orElse(""); 59 | } 60 | 61 | public static BuildImageQueryParameters withDefaultValues() { 62 | return new BuildImageQueryParameters(); 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/ContainerLogQueryParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client; 26 | 27 | import java.time.Instant; 28 | import java.util.Optional; 29 | 30 | public class ContainerLogQueryParameters { 31 | private boolean stderr = true; 32 | private boolean stdout = true; 33 | private boolean timestamps = true; 34 | private int tail = -1; 35 | private Optional since = Optional.empty(); 36 | 37 | private static final ContainerLogQueryParameters DEFAULT = new ContainerLogQueryParameters(); 38 | 39 | public static ContainerLogQueryParameters withDefaultValues() { 40 | return DEFAULT; 41 | } 42 | 43 | private ContainerLogQueryParameters() { 44 | } 45 | 46 | public ContainerLogQueryParameters(boolean stderr, boolean stdout, boolean timestamps, int tail, Instant since) { 47 | this.stderr = stderr; 48 | this.stdout = stdout; 49 | this.timestamps = timestamps; 50 | this.tail = tail; 51 | this.since = Optional.ofNullable(since); 52 | } 53 | 54 | public String toQueryParametersString() { 55 | StringBuilder queryBuilder = new StringBuilder("?"); 56 | queryBuilder.append("stderr=" + stderr); 57 | queryBuilder.append("&"); 58 | queryBuilder.append("stdout=" + stdout); 59 | queryBuilder.append("&"); 60 | queryBuilder.append("timestamps=" + timestamps); 61 | queryBuilder.append("&"); 62 | if (tail < 0) { 63 | queryBuilder.append("tail=all"); 64 | } else { 65 | queryBuilder.append("tail=" + tail); 66 | } 67 | queryBuilder.append("&"); 68 | if (since.isPresent()) { 69 | queryBuilder.append("since=" + since.get().getEpochSecond()); 70 | } 71 | String queryStr = queryBuilder.toString(); 72 | if (queryStr.endsWith("&")) { 73 | queryStr = queryStr.substring(0, queryStr.lastIndexOf("&")); 74 | } 75 | return queryStr; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/ContainerOperations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client; 26 | 27 | import com.shekhargulati.reactivex.docker.client.representations.*; 28 | import com.shekhargulati.reactivex.rxokhttp.HttpStatus; 29 | import com.shekhargulati.reactivex.rxokhttp.QueryParameter; 30 | import okhttp3.Response; 31 | import org.slf4j.Logger; 32 | import org.slf4j.LoggerFactory; 33 | import rx.Observable; 34 | 35 | import java.nio.file.Path; 36 | import java.util.List; 37 | import java.util.Optional; 38 | 39 | public interface ContainerOperations { 40 | String CONTAINER_ENDPOINT = "containers/json%s"; 41 | String CONTAINERS_ENDPOINT = "containers/%s"; 42 | String CONTAINER_JSON_ENDPOINT = CONTAINERS_ENDPOINT + "/json"; 43 | String CREATE_CONTAINER_ENDPOINT = "containers/create"; 44 | String CONTAINER_LIST_PROCESS_ENDPOINT = CONTAINERS_ENDPOINT + "/top"; 45 | String CONTAINER_START_ENDPOINT = CONTAINERS_ENDPOINT + "/start"; 46 | String CONTAINER_STOP_ENDPOINT = CONTAINERS_ENDPOINT + "/stop"; 47 | String CONTAINER_RESTART_ENDPOINT = CONTAINERS_ENDPOINT + "/restart"; 48 | String CONTAINER_KILL_ENDPOINT = CONTAINERS_ENDPOINT + "/kill"; 49 | String CONTAINER_REMOVE_ENDPOINT = CONTAINERS_ENDPOINT; 50 | String CONTAINER_RENAME_ENDPOINT = CONTAINERS_ENDPOINT + "/rename"; 51 | String CONTAINER_WAIT_ENDPOINT = CONTAINERS_ENDPOINT + "/wait"; 52 | String CONTAINER_EXPORT_ENDPOINT = CONTAINERS_ENDPOINT + "/export"; 53 | String CONTAINER_STATS_ENDPOINT = CONTAINERS_ENDPOINT + "/stats"; 54 | String CONTAINER_LOGS_ENDPOINT = CONTAINERS_ENDPOINT + "/logs"; 55 | String CONTAINER_CHANGES_ENDPOINT = CONTAINERS_ENDPOINT + "/changes"; 56 | String CONTAINER_RESIZE_ENDPOINT = CONTAINERS_ENDPOINT + "/resize"; 57 | String CONTAINER_PAUSE_ENDPOINT = CONTAINERS_ENDPOINT + "/pause"; 58 | String CONTAINER_UNPAUSE_ENDPOINT = CONTAINERS_ENDPOINT + "/unpause"; 59 | String CONTAINER_ATTACH_ENDPOINT = CONTAINERS_ENDPOINT + "/attach"; 60 | String CONTAINER_ARCHIVE_ENDPOINT = CONTAINERS_ENDPOINT + "/archive"; 61 | String CONTAINER_EXEC_CREATE_ENDPOINT = CONTAINERS_ENDPOINT + "/exec"; 62 | String CONTAINER_EXEC_ENDPOINT = "/exec/%s"; 63 | String CONTAINER_EXEC_START_ENDPOINT = CONTAINER_EXEC_ENDPOINT + "/start"; 64 | 65 | Logger logger = LoggerFactory.getLogger(ContainerOperations.class); 66 | 67 | Observable listRunningContainerObs(); 68 | 69 | List listRunningContainers(); 70 | 71 | Observable listAllContainersObs(); 72 | 73 | List listAllContainers(); 74 | 75 | List listContainers(QueryParameters queryParameters); 76 | 77 | Observable listContainersObs(QueryParameters queryParameters); 78 | 79 | DockerContainerResponse createContainer(DockerContainerRequest request, String name); 80 | 81 | DockerContainerResponse createContainer(DockerContainerRequest request); 82 | 83 | Observable createContainerObs(DockerContainerRequest request, Optional name); 84 | 85 | Observable createContainerObs(String jsonRequest, String name); 86 | 87 | DockerContainerResponse createContainer(String jsonRequest, String name); 88 | 89 | Observable createContainerObs(String jsonRequest); 90 | 91 | DockerContainerResponse createContainer(String jsonRequest); 92 | 93 | ContainerInspectResponse inspectContainer(String containerId); 94 | 95 | Observable inspectContainerObs(String containerId); 96 | 97 | ProcessListResponse listProcesses(String containerId); 98 | 99 | Observable listProcessesObs(String containerId); 100 | 101 | Observable startContainerObs(String containerId); 102 | 103 | HttpStatus startContainer(String containerId); 104 | 105 | HttpStatus stopContainer(String containerId, final int waitInSecs); 106 | 107 | Observable stopContainerObs(String containerId, final int waitInSecs); 108 | 109 | HttpStatus restartContainer(String containerId, int waitInSecs); 110 | 111 | Observable restartContainerObs(String containerId, int waitInSecs); 112 | 113 | HttpStatus killRunningContainer(String containerId); 114 | 115 | Observable killRunningContainerObs(String containerId); 116 | 117 | default void killAllRunningContainers() { 118 | listContainers(new QueryParameters()).forEach(container -> { 119 | String containerId = container.getId(); 120 | logger.info("killing running container with id {}", containerId); 121 | killRunningContainer(containerId); 122 | }); 123 | } 124 | 125 | HttpStatus removeContainer(String containerId); 126 | 127 | HttpStatus removeContainer(String containerId, boolean removeVolume, boolean force); 128 | 129 | Observable removeContainerObs(String containerId); 130 | 131 | Observable removeContainerObs(String containerId, boolean removeVolume, boolean force); 132 | 133 | default void removeAllContainers() { 134 | listAllContainers().forEach(container -> { 135 | String containerId = container.getId(); 136 | logger.info("removing container with id {}", containerId); 137 | removeContainer(containerId, true, true); 138 | }); 139 | } 140 | 141 | HttpStatus renameContainer(String containerId, String newName); 142 | 143 | Observable renameContainerObs(String containerId, String newName); 144 | 145 | HttpStatus waitContainer(String containerId); 146 | 147 | Observable waitContainerObs(String containerId); 148 | 149 | void exportContainer(String containerId, Path pathToExportTo); 150 | 151 | Observable containerStatsObs(String containerId); 152 | 153 | Observable containerLogsObs(String containerId, ContainerLogQueryParameters queryParameters); 154 | 155 | Observable containerLogsObs(String containerId); 156 | 157 | Observable createContainerObs(DockerContainerRequest request, String name); 158 | 159 | Observable createContainerObs(DockerContainerRequest request); 160 | 161 | List inspectChangesOnContainerFilesystem(String containerId); 162 | 163 | Observable inspectChangesOnContainerFilesystemObs(String containerId); 164 | 165 | HttpStatus resizeContainerTty(String containerId, QueryParameter... queryParameters); 166 | 167 | Observable resizeContainerTtyObs(String containerId, QueryParameter... queryParameters); 168 | 169 | HttpStatus pauseContainer(String containerId); 170 | 171 | Observable pauseContainerObs(String containerId); 172 | 173 | HttpStatus unpauseContainer(String containerId); 174 | 175 | Observable unpauseContainerObs(String containerId); 176 | 177 | Observable attachContainerObs(String containerId, QueryParameter... queryParameters); 178 | 179 | ContainerArchiveInformation containerArchiveInformation(String containerId, String path); 180 | 181 | Observable containerArchiveInformationObs(String containerId, String path); 182 | 183 | void containerArchive(String containerId, String path, Path pathToExportTo); 184 | 185 | /** 186 | * Sets up an exec instance in a running container 187 | * 188 | *

REST Endpoint:

189 | *
POST /containers/(id)/exec
190 | * 191 | * @param containerId id of the running container 192 | * @param cmd command to run inside the container 193 | * @return response object with exec instance id 194 | */ 195 | Observable execCreateObs(String containerId, String... cmd); 196 | 197 | /** 198 | * Sets up an exec instance in a running container 199 | * 200 | *

REST Endpoint:

201 | *
POST /containers/(id)/exec
202 | * 203 | * @param containerId id of the running container 204 | * @param request exec create request 205 | * @return response object with exec instance id 206 | */ 207 | Observable execCreateObs(String containerId, ExecCreateRequest request); 208 | 209 | /** 210 | * Starts the exec using the defaults i.e. Detach=false and Tty=False 211 | * 212 | *

REST Endpoint:

213 | *
POST /exec/(id)/start
214 | * 215 | * @param execId exec instance id 216 | * @return an Observable stream 217 | */ 218 | Observable execStartObs(String execId); 219 | 220 | /** 221 | * Starts the exec using the defaults i.e. Detach=false and Tty=False 222 | * 223 | *

REST Endpoint:

224 | *
POST /exec/(id)/start
225 | * 226 | * @param execId exec instance id 227 | * @param request exec start request 228 | * @return an Observable stream 229 | */ 230 | Observable execStartObs(String execId, ExecStartRequest request); 231 | 232 | } 233 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/DockerErrorDetails.java: -------------------------------------------------------------------------------- 1 | package com.shekhargulati.reactivex.docker.client; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.reflect.TypeToken; 5 | 6 | import java.lang.reflect.Type; 7 | 8 | public class DockerErrorDetails { 9 | private ErrorDetails errorDetail; 10 | private String error; 11 | 12 | public static DockerErrorDetails errorDetails(final String json) { 13 | Type type = new TypeToken() { 14 | }.getType(); 15 | DockerErrorDetails details = new Gson().fromJson(json, type); 16 | return details; 17 | } 18 | 19 | 20 | public ErrorDetails getErrorDetail() { 21 | return errorDetail; 22 | } 23 | 24 | public String getError() { 25 | return error; 26 | } 27 | } 28 | 29 | 30 | class ErrorDetails { 31 | private String message; 32 | 33 | public String getMessage() { 34 | return message; 35 | } 36 | } -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/HostAndPort.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client; 26 | 27 | import com.shekhargulati.reactivex.docker.client.utils.Strings; 28 | import com.shekhargulati.reactivex.docker.client.utils.Validations; 29 | 30 | public final class HostAndPort { 31 | 32 | private final String host; 33 | private final int port; 34 | 35 | public HostAndPort(String host, int port) { 36 | this.host = host; 37 | this.port = port; 38 | } 39 | 40 | public static HostAndPort using(String host, int port) { 41 | return new HostAndPort(host, port); 42 | } 43 | 44 | public static HostAndPort from(String hostPortString) { 45 | Validations.validate(hostPortString, Strings::isEmptyOrNull, "hostPortString can't be null"); 46 | String endpointWithoutScheme = hostPortString.replaceAll(".*://", ""); 47 | String[] split = endpointWithoutScheme.split(":"); 48 | Validations.validate(split, arr -> arr.length != 2, String.format("%s should be of format host:port for example 192.168.99.100:2376", hostPortString)); 49 | return new HostAndPort(split[0], Integer.parseInt(split[1])); 50 | } 51 | 52 | public String getHost() { 53 | return host; 54 | } 55 | 56 | public int getPort() { 57 | return port; 58 | } 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/ImageListQueryParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client; 26 | 27 | import com.google.gson.Gson; 28 | 29 | import java.io.UnsupportedEncodingException; 30 | import java.net.URLEncoder; 31 | import java.util.*; 32 | 33 | import static java.nio.charset.StandardCharsets.UTF_8; 34 | 35 | public class ImageListQueryParameters { 36 | private Optional imageName = Optional.empty(); 37 | private Map> filters = new HashMap<>(); 38 | private boolean all = false; 39 | 40 | public static ImageListQueryParameters queryParameterWithImageName(String imageName) { 41 | return new ImageListQueryParameters(imageName); 42 | } 43 | 44 | public static ImageListQueryParameters allImagesQueryParameters() { 45 | return new ImageListQueryParameters(true); 46 | } 47 | 48 | public static ImageListQueryParameters defaultQueryParameters() { 49 | return new ImageListQueryParameters(); 50 | } 51 | 52 | private ImageListQueryParameters() { 53 | } 54 | 55 | public ImageListQueryParameters(String imageName, boolean all) { 56 | this.imageName = Optional.ofNullable(imageName); 57 | this.all = all; 58 | } 59 | 60 | private ImageListQueryParameters(String imageName) { 61 | this.imageName = Optional.ofNullable(imageName); 62 | } 63 | 64 | private ImageListQueryParameters(boolean all) { 65 | this.all = all; 66 | } 67 | 68 | public ImageListQueryParameters addFilter(String key, String value) { 69 | filters.put(key, filters.compute(key, (k, v) -> { 70 | if (v == null) { 71 | v = new ArrayList<>(); 72 | 73 | } 74 | v.add(value); 75 | return v; 76 | })); 77 | return this; 78 | } 79 | 80 | public String toQuery() { 81 | StringBuilder queryBuilder = new StringBuilder("?"); 82 | queryBuilder.append("all=" + all); 83 | queryBuilder.append("&"); 84 | if (imageName.isPresent()) { 85 | queryBuilder.append("filter=" + imageName.get()); 86 | queryBuilder.append("&"); 87 | } 88 | if (!filters.isEmpty()) { 89 | String json = new Gson().toJson(filters); 90 | try { 91 | final String encoded = URLEncoder.encode(json, UTF_8.name()); 92 | queryBuilder.append("filters=" + encoded); 93 | } catch (UnsupportedEncodingException e) { 94 | throw new IllegalArgumentException(String.format("unable to encode filter %s", filters)); 95 | } 96 | } 97 | String queryStr = queryBuilder.toString(); 98 | if (queryStr.endsWith("&")) { 99 | queryStr = queryStr.substring(0, queryStr.lastIndexOf("&")); 100 | } 101 | return queryStr; 102 | } 103 | 104 | 105 | } 106 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/ImageTagQueryParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client; 26 | 27 | public class ImageTagQueryParameters { 28 | 29 | private final String repo; 30 | private final String tag; 31 | private boolean force = false; 32 | 33 | private ImageTagQueryParameters(String repo, String tag) { 34 | this.repo = repo; 35 | this.tag = tag; 36 | } 37 | 38 | public static ImageTagQueryParameters with(String repo, String tag) { 39 | return new ImageTagQueryParameters(repo, tag); 40 | } 41 | 42 | public ImageTagQueryParameters withForce() { 43 | this.force = true; 44 | return this; 45 | } 46 | 47 | public String toQuery() { 48 | StringBuilder queryBuilder = new StringBuilder("?"); 49 | queryBuilder.append("repo=" + repo); 50 | queryBuilder.append("&"); 51 | queryBuilder.append("force=" + force); 52 | queryBuilder.append("&"); 53 | queryBuilder.append("tag=" + tag); 54 | return queryBuilder.toString(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/MiscOperations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client; 26 | 27 | import com.shekhargulati.reactivex.docker.client.representations.DockerInfo; 28 | import com.shekhargulati.reactivex.docker.client.representations.DockerVersion; 29 | import com.shekhargulati.reactivex.rxokhttp.HttpStatus; 30 | import rx.Observable; 31 | 32 | public interface MiscOperations { 33 | 34 | String VERSION_ENDPOINT = "version"; 35 | String INFO_ENDPOINT = "info"; 36 | String CHECK_AUTH_ENDPOINT = "auth"; 37 | String PING_ENDPOINT = "_ping"; 38 | 39 | Observable serverVersionObs(); 40 | 41 | DockerVersion serverVersion(); 42 | 43 | Observable infoObs(); 44 | 45 | DockerInfo info(); 46 | 47 | HttpStatus checkAuth(AuthConfig authConfig); 48 | 49 | Observable checkAuthObs(AuthConfig authConfig); 50 | 51 | HttpStatus ping(); 52 | 53 | } 54 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/QueryParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client; 26 | 27 | import java.util.HashMap; 28 | import java.util.Map; 29 | import java.util.Optional; 30 | import java.util.stream.Collectors; 31 | 32 | public class QueryParameters { 33 | 34 | private boolean all; 35 | private Optional since = Optional.empty(); 36 | private Optional before = Optional.empty(); 37 | private boolean size = false; 38 | private int limit; 39 | private Map filters = new HashMap<>(); 40 | private String query; 41 | 42 | public QueryParameters() { 43 | this.query = createQuery(); 44 | } 45 | 46 | public QueryParameters(boolean all, String since, String before, boolean size, int limit, Map filters) { 47 | this.all = all; 48 | this.since = Optional.ofNullable(since); 49 | this.before = Optional.ofNullable(before); 50 | this.size = size; 51 | this.limit = limit; 52 | this.filters = filters; 53 | this.query = createQuery(); 54 | } 55 | 56 | private String createQuery() { 57 | StringBuilder queryBuilder = new StringBuilder("?"); 58 | queryBuilder.append("all=" + all); 59 | queryBuilder.append("&"); 60 | queryBuilder.append("size=" + size); 61 | queryBuilder.append("&"); 62 | if (since.isPresent()) { 63 | queryBuilder.append("since=" + since.get()); 64 | queryBuilder.append("&"); 65 | } 66 | if (before.isPresent()) { 67 | queryBuilder.append("before=" + before.get()); 68 | queryBuilder.append("&"); 69 | } 70 | if (limit > 1) { 71 | queryBuilder.append("limit=" + limit); 72 | queryBuilder.append("&"); 73 | } 74 | queryBuilder.append(this.filters.entrySet().stream().map(entry -> String.format("%s=%s", entry.getKey(), entry.getValue())).collect(Collectors.joining(";"))); 75 | String queryStr = queryBuilder.toString(); 76 | if (queryStr.endsWith("&")) { 77 | queryStr = queryStr.substring(0, queryStr.lastIndexOf("&")); 78 | } 79 | return queryStr; 80 | } 81 | 82 | public boolean isAll() { 83 | return all; 84 | } 85 | 86 | public Optional getSince() { 87 | return since; 88 | } 89 | 90 | public Optional getBefore() { 91 | return before; 92 | } 93 | 94 | public boolean isSize() { 95 | return size; 96 | } 97 | 98 | public int getLimit() { 99 | return limit; 100 | } 101 | 102 | public Map getFilters() { 103 | return filters; 104 | } 105 | 106 | public String toQuery() { 107 | return query; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/QueryParametersBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client; 26 | 27 | import java.util.HashMap; 28 | import java.util.Map; 29 | 30 | public class QueryParametersBuilder { 31 | private boolean all = false; 32 | private String since; 33 | private String before; 34 | private boolean size = false; 35 | private int limit; 36 | private Map filters = new HashMap<>(); 37 | 38 | public QueryParametersBuilder withAll(boolean all) { 39 | this.all = all; 40 | return this; 41 | } 42 | 43 | public QueryParametersBuilder withSince(String since) { 44 | this.since = since; 45 | return this; 46 | } 47 | 48 | public QueryParametersBuilder withBefore(String before) { 49 | this.before = before; 50 | return this; 51 | } 52 | 53 | public QueryParametersBuilder withSize(boolean size) { 54 | this.size = size; 55 | return this; 56 | } 57 | 58 | public QueryParametersBuilder withLimit(int limit) { 59 | this.limit = limit; 60 | return this; 61 | } 62 | 63 | public QueryParametersBuilder withFilter(String key, String value) { 64 | this.filters.put(key, value); 65 | return this; 66 | } 67 | 68 | public QueryParameters createQueryParameters() { 69 | return new QueryParameters(all, since, before, size, limit, filters); 70 | } 71 | 72 | public static QueryParameters defaultQueryParameters() { 73 | return new QueryParameters(); 74 | } 75 | } -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/RxDockerClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client; 26 | 27 | public interface RxDockerClient extends MiscOperations, ContainerOperations, ImageOperations { 28 | 29 | String DEFAULT_DOCKER_HOST = "127.0.0.1"; 30 | int DEFAULT_DOCKER_PORT = 2375; 31 | 32 | /** 33 | * Builds the client using DOCKER_HOST and DOCKER_CERT_PATH environment variables 34 | * 35 | * @return a new instance of DefaultRxDockerClient 36 | */ 37 | static RxDockerClient fromDefaultEnv() { 38 | return newDockerClient(System.getenv("DOCKER_HOST"), System.getenv("DOCKER_CERT_PATH")); 39 | } 40 | 41 | static DefaultRxDockerClient newDockerClient(final String dockerHost, final String dockerCertPath) { 42 | return new DefaultRxDockerClient(dockerHost, dockerCertPath); 43 | } 44 | 45 | String getApiUri(); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/function/ContainerEndpointUriFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.function; 26 | 27 | @FunctionalInterface 28 | public interface ContainerEndpointUriFunction extends TriFunction { 29 | 30 | } 31 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/function/TriFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.function; 26 | 27 | import java.util.Objects; 28 | import java.util.function.BiFunction; 29 | 30 | @FunctionalInterface 31 | public interface TriFunction { 32 | 33 | R apply(T t, U u, V v); 34 | 35 | default TriFunction andThen(Y y, BiFunction after) { 36 | Objects.requireNonNull(after); 37 | return (T t, U u, V v) -> after.apply(apply(t, u, v), y); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/ContainerArchiveInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * The MIT License 4 | * * 5 | * * Copyright 2015 Shekhar Gulati . 6 | * * 7 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * * of this software and associated documentation files (the "Software"), to deal 9 | * * in the Software without restriction, including without limitation the rights 10 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * * copies of the Software, and to permit persons to whom the Software is 12 | * * furnished to do so, subject to the following conditions: 13 | * * 14 | * * The above copyright notice and this permission notice shall be included in 15 | * * all copies or substantial portions of the Software. 16 | * * 17 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * * THE SOFTWARE. 24 | * 25 | */ 26 | 27 | package com.shekhargulati.reactivex.docker.client.representations; 28 | 29 | import com.google.gson.annotations.SerializedName; 30 | 31 | public class ContainerArchiveInformation { 32 | 33 | @SerializedName("name") 34 | private String name; 35 | @SerializedName("size") 36 | private int size; 37 | @SerializedName("mode") 38 | private long mode; 39 | @SerializedName("mtime") 40 | private String mtime; 41 | @SerializedName("linkTarget") 42 | private String linkTarget; 43 | 44 | public String getName() { 45 | return name; 46 | } 47 | 48 | public int getSize() { 49 | return size; 50 | } 51 | 52 | public long getMode() { 53 | return mode; 54 | } 55 | 56 | public String getMtime() { 57 | return mtime; 58 | } 59 | 60 | public String getLinkTarget() { 61 | return linkTarget; 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return "ContainerArchiveInformation{" + 67 | "name='" + name + '\'' + 68 | ", size=" + size + 69 | ", mode=" + mode + 70 | ", mtime='" + mtime + '\'' + 71 | ", linkTarget='" + linkTarget + '\'' + 72 | '}'; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/ContainerChange.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * 4 | * * The MIT License 5 | * * 6 | * * Copyright 2015 Shekhar Gulati . 7 | * * 8 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * * of this software and associated documentation files (the "Software"), to deal 10 | * * in the Software without restriction, including without limitation the rights 11 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * * copies of the Software, and to permit persons to whom the Software is 13 | * * furnished to do so, subject to the following conditions: 14 | * * 15 | * * The above copyright notice and this permission notice shall be included in 16 | * * all copies or substantial portions of the Software. 17 | * * 18 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * * THE SOFTWARE. 25 | * 26 | */ 27 | package com.shekhargulati.reactivex.docker.client.representations; 28 | 29 | import com.google.gson.annotations.SerializedName; 30 | 31 | /** 32 | * Created by shekhargulati on 24/11/15. 33 | */ 34 | public class ContainerChange { 35 | 36 | @SerializedName("PATH") 37 | private String path; 38 | @SerializedName("KIND") 39 | private int kind; 40 | 41 | public String getPath() { 42 | return path; 43 | } 44 | 45 | public int getKind() { 46 | return kind; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/ContainerState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import com.google.gson.annotations.SerializedName; 28 | 29 | import java.util.Date; 30 | 31 | public class ContainerState { 32 | 33 | @SerializedName("Running") 34 | private Boolean running; 35 | @SerializedName("Paused") 36 | private Boolean paused; 37 | @SerializedName("Restarting") 38 | private Boolean restarting; 39 | @SerializedName("Pid") 40 | private Integer pid; 41 | @SerializedName("ExitCode") 42 | private Integer exitCode; 43 | @SerializedName("StartedAt") 44 | private Date startedAt; 45 | @SerializedName("FinishedAt") 46 | private Date finishedAt; 47 | @SerializedName("Error") 48 | private String error; 49 | @SerializedName("OOMKilled") 50 | private Boolean oomKilled; 51 | 52 | public Boolean running() { 53 | return running; 54 | } 55 | 56 | public Boolean paused() { 57 | return paused; 58 | } 59 | 60 | public Boolean restarting() { 61 | return restarting; 62 | } 63 | 64 | public Integer pid() { 65 | return pid; 66 | } 67 | 68 | public Integer exitCode() { 69 | return exitCode; 70 | } 71 | 72 | public Date startedAt() { 73 | return startedAt == null ? null : new Date(startedAt.getTime()); 74 | } 75 | 76 | public Date finishedAt() { 77 | return finishedAt == null ? null : new Date(finishedAt.getTime()); 78 | } 79 | 80 | public String error() { 81 | return error; 82 | } 83 | 84 | public Boolean oomKilled() { 85 | return oomKilled; 86 | } 87 | 88 | @Override 89 | public boolean equals(final Object o) { 90 | if (this == o) { 91 | return true; 92 | } 93 | if (o == null || getClass() != o.getClass()) { 94 | return false; 95 | } 96 | 97 | final ContainerState that = (ContainerState) o; 98 | 99 | if (exitCode != null ? !exitCode.equals(that.exitCode) : that.exitCode != null) { 100 | return false; 101 | } 102 | if (finishedAt != null ? !finishedAt.equals(that.finishedAt) : that.finishedAt != null) { 103 | return false; 104 | } 105 | if (pid != null ? !pid.equals(that.pid) : that.pid != null) { 106 | return false; 107 | } 108 | if (running != null ? !running.equals(that.running) : that.running != null) { 109 | return false; 110 | } 111 | if (paused != null ? !paused.equals(that.paused) : that.paused != null) { 112 | return false; 113 | } 114 | if (restarting != null ? !restarting.equals(that.restarting) : that.restarting != null) { 115 | return false; 116 | } 117 | if (startedAt != null ? !startedAt.equals(that.startedAt) : that.startedAt != null) { 118 | return false; 119 | } 120 | if (error != null ? !error.equals(that.error) : that.error != null) { 121 | return false; 122 | } 123 | if (oomKilled != null ? !oomKilled.equals(that.oomKilled) : that.oomKilled != null) { 124 | return false; 125 | } 126 | 127 | return true; 128 | } 129 | 130 | @Override 131 | public int hashCode() { 132 | int result = running != null ? running.hashCode() : 0; 133 | result = 31 * result + (pid != null ? pid.hashCode() : 0); 134 | result = 31 * result + (paused != null ? paused.hashCode() : 0); 135 | result = 31 * result + (restarting != null ? restarting.hashCode() : 0); 136 | result = 31 * result + (exitCode != null ? exitCode.hashCode() : 0); 137 | result = 31 * result + (startedAt != null ? startedAt.hashCode() : 0); 138 | result = 31 * result + (finishedAt != null ? finishedAt.hashCode() : 0); 139 | result = 31 * result + (error != null ? error.hashCode() : 0); 140 | result = 31 * result + (oomKilled != null ? oomKilled.hashCode() : 0); 141 | return result; 142 | } 143 | 144 | 145 | @Override 146 | public String toString() { 147 | return "ContainerState{" + 148 | "running=" + running + 149 | ", paused=" + paused + 150 | ", restarting=" + restarting + 151 | ", pid=" + pid + 152 | ", exitCode=" + exitCode + 153 | ", startedAt=" + startedAt + 154 | ", finishedAt=" + finishedAt + 155 | ", error='" + error + '\'' + 156 | ", oomKilled=" + oomKilled + 157 | '}'; 158 | } 159 | } -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/ContainerStats.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import com.google.gson.annotations.SerializedName; 28 | 29 | public class ContainerStats { 30 | @SerializedName("read") 31 | private String read; 32 | @SerializedName("network") 33 | private NetworkStats network; 34 | @SerializedName("memory_stats") 35 | private MemoryStats memoryStats; 36 | @SerializedName("cpu_stats") 37 | private CpuStats cpuStats; 38 | @SerializedName("precpu_stats") 39 | private CpuStats precpuStats; 40 | 41 | public String read() { 42 | return read; 43 | } 44 | 45 | public NetworkStats network() { 46 | return network; 47 | } 48 | 49 | public MemoryStats memoryStats() { 50 | return memoryStats; 51 | } 52 | 53 | public CpuStats cpuStats() { 54 | return cpuStats; 55 | } 56 | 57 | public CpuStats precpuStats() { 58 | return precpuStats; 59 | } 60 | 61 | @Override 62 | public int hashCode() { 63 | final int prime = 31; 64 | int result = 1; 65 | result = prime * result + (cpuStats == null ? 0 : cpuStats.hashCode()); 66 | result = prime * result + (memoryStats == null ? 0 : memoryStats.hashCode()); 67 | result = prime * result + (network == null ? 0 : network.hashCode()); 68 | result = prime * result + (precpuStats == null ? 0 : precpuStats.hashCode()); 69 | result = prime * result + (read == null ? 0 : read.hashCode()); 70 | return result; 71 | } 72 | 73 | @Override 74 | public boolean equals(Object obj) { 75 | if (this == obj) { 76 | return true; 77 | } 78 | if (obj == null) { 79 | return false; 80 | } 81 | if (getClass() != obj.getClass()) { 82 | return false; 83 | } 84 | ContainerStats other = (ContainerStats) obj; 85 | if (cpuStats == null) { 86 | if (other.cpuStats != null) { 87 | return false; 88 | } 89 | } else if (!cpuStats.equals(other.cpuStats)) { 90 | return false; 91 | } 92 | if (memoryStats == null) { 93 | if (other.memoryStats != null) { 94 | return false; 95 | } 96 | } else if (!memoryStats.equals(other.memoryStats)) { 97 | return false; 98 | } 99 | if (network == null) { 100 | if (other.network != null) { 101 | return false; 102 | } 103 | } else if (!network.equals(other.network)) { 104 | return false; 105 | } 106 | if (precpuStats == null) { 107 | if (other.precpuStats != null) { 108 | return false; 109 | } 110 | } else if (!precpuStats.equals(other.precpuStats)) { 111 | return false; 112 | } 113 | if (read == null) { 114 | if (other.read != null) { 115 | return false; 116 | } 117 | } else if (!read.equals(other.read)) { 118 | return false; 119 | } 120 | return true; 121 | } 122 | 123 | @Override 124 | public String toString() { 125 | return "ContainerStats{" + 126 | "read='" + read + '\'' + 127 | ", network=" + network + 128 | ", memoryStats=" + memoryStats + 129 | ", cpuStats=" + cpuStats + 130 | ", precpuStats=" + precpuStats + 131 | '}'; 132 | } 133 | } -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/CpuStats.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import com.google.gson.annotations.SerializedName; 28 | 29 | public class CpuStats { 30 | @SerializedName("cpu_usage") 31 | private CpuUsage cpuUsage; 32 | @SerializedName("system_cpu_usage") 33 | Long systemCpuUsage; 34 | 35 | public CpuUsage cpuUsage() { 36 | return cpuUsage; 37 | } 38 | 39 | public Long systemCpuUsage() { 40 | return systemCpuUsage; 41 | } 42 | 43 | @Override 44 | public int hashCode() { 45 | final int prime = 31; 46 | int result = 1; 47 | result = prime * result + (cpuUsage == null ? 0 : cpuUsage.hashCode()); 48 | result = prime * result + (systemCpuUsage == null ? 0 : systemCpuUsage.hashCode()); 49 | return result; 50 | } 51 | 52 | @Override 53 | public boolean equals(Object obj) { 54 | if (this == obj) { 55 | return true; 56 | } 57 | if (obj == null) { 58 | return false; 59 | } 60 | if (getClass() != obj.getClass()) { 61 | return false; 62 | } 63 | CpuStats other = (CpuStats) obj; 64 | if (cpuUsage == null) { 65 | if (other.cpuUsage != null) { 66 | return false; 67 | } 68 | } else if (!cpuUsage.equals(other.cpuUsage)) { 69 | return false; 70 | } 71 | if (systemCpuUsage == null) { 72 | if (other.systemCpuUsage != null) { 73 | return false; 74 | } 75 | } else if (!systemCpuUsage.equals(other.systemCpuUsage)) { 76 | return false; 77 | } 78 | return true; 79 | } 80 | 81 | @Override 82 | public String toString() { 83 | return "CpuStats{" + 84 | "cpuUsage=" + cpuUsage + 85 | ", systemCpuUsage=" + systemCpuUsage + 86 | '}'; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/CpuUsage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import com.google.gson.annotations.SerializedName; 28 | 29 | import java.util.List; 30 | 31 | public class CpuUsage { 32 | @SerializedName("total_usage") 33 | private Long totalUsage; 34 | @SerializedName("percpu_usage") 35 | private List percpuUsage; 36 | @SerializedName("usage_in_kernelmode") 37 | private Long usageInKernelmode; 38 | @SerializedName("usage_in_usermode") 39 | private Long usageInUsermode; 40 | 41 | public Long totalUsage() { 42 | return totalUsage; 43 | } 44 | 45 | public List percpuUsage() { 46 | return percpuUsage; 47 | } 48 | 49 | public Long usageInKernelmode() { 50 | return usageInKernelmode; 51 | } 52 | 53 | public Long usageInUsermode() { 54 | return usageInUsermode; 55 | } 56 | 57 | @Override 58 | public int hashCode() { 59 | final int prime = 31; 60 | int result = 1; 61 | result = prime * result + (percpuUsage == null ? 0 : percpuUsage.hashCode()); 62 | result = prime * result + (totalUsage == null ? 0 : totalUsage.hashCode()); 63 | result = prime * result + (usageInKernelmode == null ? 0 : usageInKernelmode.hashCode()); 64 | result = prime * result + (usageInUsermode == null ? 0 : usageInUsermode.hashCode()); 65 | return result; 66 | } 67 | 68 | @Override 69 | public boolean equals(Object obj) { 70 | if (this == obj) { 71 | return true; 72 | } 73 | if (obj == null) { 74 | return false; 75 | } 76 | if (getClass() != obj.getClass()) { 77 | return false; 78 | } 79 | CpuUsage other = (CpuUsage) obj; 80 | if (percpuUsage == null) { 81 | if (other.percpuUsage != null) { 82 | return false; 83 | } 84 | } else if (!percpuUsage.equals(other.percpuUsage)) { 85 | return false; 86 | } 87 | if (totalUsage == null) { 88 | if (other.totalUsage != null) { 89 | return false; 90 | } 91 | } else if (!totalUsage.equals(other.totalUsage)) { 92 | return false; 93 | } 94 | if (usageInKernelmode == null) { 95 | if (other.usageInKernelmode != null) { 96 | return false; 97 | } 98 | } else if (!usageInKernelmode.equals(other.usageInKernelmode)) { 99 | return false; 100 | } 101 | if (usageInUsermode == null) { 102 | if (other.usageInUsermode != null) { 103 | return false; 104 | } 105 | } else if (!usageInUsermode.equals(other.usageInUsermode)) { 106 | return false; 107 | } 108 | return true; 109 | } 110 | 111 | @Override 112 | public String toString() { 113 | return "CpuUsage{" + 114 | "totalUsage=" + totalUsage + 115 | ", percpuUsage=" + percpuUsage + 116 | ", usageInKernelmode=" + usageInKernelmode + 117 | ", usageInUsermode=" + usageInUsermode + 118 | '}'; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/DockerContainer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import com.google.gson.annotations.SerializedName; 28 | 29 | import java.util.List; 30 | 31 | public class DockerContainer { 32 | @SerializedName("Id") 33 | private String id; 34 | @SerializedName("Names") 35 | private List names; 36 | @SerializedName("Image") 37 | private String image; 38 | @SerializedName("Command") 39 | private String command; 40 | @SerializedName("Created") 41 | private Long created; 42 | @SerializedName("Status") 43 | private String status; 44 | @SerializedName("SizeRw") 45 | private Long sizeRw; 46 | @SerializedName("SizeRootFs") 47 | private Long sizeRootFs; 48 | 49 | public String getId() { 50 | return id; 51 | } 52 | 53 | public List getNames() { 54 | return names; 55 | } 56 | 57 | public String getImage() { 58 | return image; 59 | } 60 | 61 | public String getCommand() { 62 | return command; 63 | } 64 | 65 | public Long getCreated() { 66 | return created; 67 | } 68 | 69 | public String getStatus() { 70 | return status; 71 | } 72 | 73 | public Long getSizeRw() { 74 | return sizeRw; 75 | } 76 | 77 | public Long getSizeRootFs() { 78 | return sizeRootFs; 79 | } 80 | 81 | @Override 82 | public String toString() { 83 | return "DockerContainer{" + 84 | "id='" + id + '\'' + 85 | ", names=" + names + 86 | ", image='" + image + '\'' + 87 | ", command='" + command + '\'' + 88 | '}'; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/DockerContainerRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import com.google.gson.Gson; 28 | import com.google.gson.annotations.SerializedName; 29 | import com.google.gson.reflect.TypeToken; 30 | 31 | import java.lang.reflect.Type; 32 | import java.util.HashMap; 33 | import java.util.List; 34 | import java.util.Map; 35 | 36 | public class DockerContainerRequest { 37 | 38 | @SerializedName("Hostname") 39 | private String hostname; 40 | @SerializedName("Domainname") 41 | private String domainname; 42 | @SerializedName("User") 43 | private String user; 44 | @SerializedName("AttachStdin") 45 | private Boolean attachStdin; 46 | @SerializedName("AttachStdout") 47 | private Boolean attachStdout; 48 | @SerializedName("AttachStderr") 49 | private Boolean attachStderr; 50 | @SerializedName("PortSpecs") 51 | private List portSpecs; 52 | @SerializedName("ExposedPorts") 53 | private Map exposedPorts = new HashMap<>(); 54 | @SerializedName("Tty") 55 | private Boolean tty; 56 | @SerializedName("OpenStdin") 57 | private Boolean openStdin; 58 | @SerializedName("StdinOnce") 59 | private Boolean stdinOnce; 60 | @SerializedName("Env") 61 | private List env; 62 | @SerializedName("Cmd") 63 | private List cmd; 64 | @SerializedName("Image") 65 | private String image; 66 | @SerializedName("Volumes") 67 | private Map volumes; 68 | @SerializedName("WorkingDir") 69 | private String workingDir; 70 | @SerializedName("Entrypoint") 71 | private List entrypoint; 72 | @SerializedName("NetworkDisabled") 73 | private Boolean networkDisabled; 74 | @SerializedName("OnBuild") 75 | private List onBuild; 76 | @SerializedName("Labels") 77 | private Map labels; 78 | @SerializedName("MacAddress") 79 | private String macAddress; 80 | @SerializedName("HostConfig") 81 | private HostConfig hostConfig; 82 | 83 | DockerContainerRequest(DockerContainerRequestBuilder builder) { 84 | this.hostname = builder.hostname; 85 | this.domainname = builder.domainname; 86 | this.user = builder.user; 87 | this.attachStdin = builder.attachStdin; 88 | this.attachStdout = builder.attachStdout; 89 | this.attachStderr = builder.attachStderr; 90 | this.portSpecs = builder.portSpecs; 91 | this.exposedPorts = builder.exposedPorts; 92 | this.tty = builder.tty; 93 | this.openStdin = builder.openStdin; 94 | this.stdinOnce = builder.stdinOnce; 95 | this.env = builder.env; 96 | this.cmd = builder.cmd; 97 | this.image = builder.image; 98 | this.volumes = builder.volumes; 99 | this.workingDir = builder.workingDir; 100 | this.entrypoint = builder.entrypoint; 101 | this.networkDisabled = builder.networkDisabled; 102 | this.onBuild = builder.onBuild; 103 | this.labels = builder.labels; 104 | this.macAddress = builder.macAddress; 105 | this.hostConfig = builder.hostConfig; 106 | } 107 | 108 | public String getHostname() { 109 | return hostname; 110 | } 111 | 112 | public String getDomainname() { 113 | return domainname; 114 | } 115 | 116 | public String getUser() { 117 | return user; 118 | } 119 | 120 | public Boolean getAttachStdin() { 121 | return attachStdin; 122 | } 123 | 124 | public Boolean getAttachStdout() { 125 | return attachStdout; 126 | } 127 | 128 | public Boolean getAttachStderr() { 129 | return attachStderr; 130 | } 131 | 132 | public List getPortSpecs() { 133 | return portSpecs; 134 | } 135 | 136 | public Map getExposedPorts() { 137 | return exposedPorts; 138 | } 139 | 140 | public Boolean getTty() { 141 | return tty; 142 | } 143 | 144 | public Boolean getOpenStdin() { 145 | return openStdin; 146 | } 147 | 148 | public Boolean getStdinOnce() { 149 | return stdinOnce; 150 | } 151 | 152 | public List getEnv() { 153 | return env; 154 | } 155 | 156 | public List getCmd() { 157 | return cmd; 158 | } 159 | 160 | public String getImage() { 161 | return image; 162 | } 163 | 164 | public Map getVolumes() { 165 | return volumes; 166 | } 167 | 168 | public String getWorkingDir() { 169 | return workingDir; 170 | } 171 | 172 | public List getEntrypoint() { 173 | return entrypoint; 174 | } 175 | 176 | public Boolean getNetworkDisabled() { 177 | return networkDisabled; 178 | } 179 | 180 | public List getOnBuild() { 181 | return onBuild; 182 | } 183 | 184 | public Map getLabels() { 185 | return labels; 186 | } 187 | 188 | public String getMacAddress() { 189 | return macAddress; 190 | } 191 | 192 | public HostConfig getHostConfig() { 193 | return hostConfig; 194 | } 195 | 196 | public String toJson() { 197 | Gson gson = new Gson(); 198 | Type type = new TypeToken() { 199 | }.getType(); 200 | return gson.toJson(this, type); 201 | } 202 | 203 | @Override 204 | public String toString() { 205 | return "DockerContainerRequest{" + 206 | "hostname='" + hostname + '\'' + 207 | ", domainname='" + domainname + '\'' + 208 | ", user='" + user + '\'' + 209 | ", attachStdin=" + attachStdin + 210 | ", attachStdout=" + attachStdout + 211 | ", attachStderr=" + attachStderr + 212 | ", portSpecs=" + portSpecs + 213 | ", exposedPorts=" + exposedPorts + 214 | ", tty=" + tty + 215 | ", openStdin=" + openStdin + 216 | ", stdinOnce=" + stdinOnce + 217 | ", env=" + env + 218 | ", cmd=" + cmd + 219 | ", image='" + image + '\'' + 220 | ", volumes=" + volumes + 221 | ", workingDir='" + workingDir + '\'' + 222 | ", entrypoint=" + entrypoint + 223 | ", networkDisabled=" + networkDisabled + 224 | ", onBuild=" + onBuild + 225 | ", labels=" + labels + 226 | ", macAddress='" + macAddress + '\'' + 227 | ", hostConfig=" + hostConfig + 228 | '}'; 229 | } 230 | } 231 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/DockerContainerRequestBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import java.util.Collections; 28 | import java.util.HashMap; 29 | import java.util.List; 30 | import java.util.Map; 31 | 32 | public class DockerContainerRequestBuilder { 33 | String hostname; 34 | String domainname; 35 | String user; 36 | Boolean attachStdin; 37 | Boolean attachStdout; 38 | Boolean attachStderr; 39 | List portSpecs; 40 | Map exposedPorts = new HashMap<>(); 41 | Boolean tty; 42 | Boolean openStdin; 43 | Boolean stdinOnce; 44 | List env; 45 | List cmd; 46 | String image; 47 | Map volumes; 48 | String workingDir; 49 | List entrypoint; 50 | Boolean networkDisabled; 51 | List onBuild; 52 | Map labels; 53 | String macAddress; 54 | HostConfig hostConfig; 55 | 56 | public DockerContainerRequestBuilder setHostname(String hostname) { 57 | this.hostname = hostname; 58 | return this; 59 | } 60 | 61 | public DockerContainerRequestBuilder setDomainname(String domainname) { 62 | this.domainname = domainname; 63 | return this; 64 | } 65 | 66 | public DockerContainerRequestBuilder setUser(String user) { 67 | this.user = user; 68 | return this; 69 | } 70 | 71 | public DockerContainerRequestBuilder setAttachStdin(Boolean attachStdin) { 72 | this.attachStdin = attachStdin; 73 | return this; 74 | } 75 | 76 | public DockerContainerRequestBuilder setAttachStdout(Boolean attachStdout) { 77 | this.attachStdout = attachStdout; 78 | return this; 79 | } 80 | 81 | public DockerContainerRequestBuilder setAttachStderr(Boolean attachStderr) { 82 | this.attachStderr = attachStderr; 83 | return this; 84 | } 85 | 86 | public DockerContainerRequestBuilder setPortSpecs(List portSpecs) { 87 | this.portSpecs = portSpecs; 88 | return this; 89 | } 90 | 91 | public DockerContainerRequestBuilder addExposedPort(String... ports) { 92 | for (String port : ports) { 93 | this.exposedPorts.put(port, Collections.emptyMap()); 94 | } 95 | return this; 96 | } 97 | 98 | public DockerContainerRequestBuilder setTty(Boolean tty) { 99 | this.tty = tty; 100 | return this; 101 | } 102 | 103 | public DockerContainerRequestBuilder setOpenStdin(Boolean openStdin) { 104 | this.openStdin = openStdin; 105 | return this; 106 | } 107 | 108 | public DockerContainerRequestBuilder setStdinOnce(Boolean stdinOnce) { 109 | this.stdinOnce = stdinOnce; 110 | return this; 111 | } 112 | 113 | public DockerContainerRequestBuilder setEnv(List env) { 114 | this.env = env; 115 | return this; 116 | } 117 | 118 | public DockerContainerRequestBuilder setCmd(List cmd) { 119 | this.cmd = cmd; 120 | return this; 121 | } 122 | 123 | public DockerContainerRequestBuilder setImage(String image) { 124 | this.image = image; 125 | return this; 126 | } 127 | 128 | public DockerContainerRequestBuilder setVolumes(Map volumes) { 129 | this.volumes = volumes; 130 | return this; 131 | } 132 | 133 | public DockerContainerRequestBuilder setWorkingDir(String workingDir) { 134 | this.workingDir = workingDir; 135 | return this; 136 | } 137 | 138 | public DockerContainerRequestBuilder setEntrypoint(List entrypoint) { 139 | this.entrypoint = entrypoint; 140 | return this; 141 | } 142 | 143 | public DockerContainerRequestBuilder setNetworkDisabled(Boolean networkDisabled) { 144 | this.networkDisabled = networkDisabled; 145 | return this; 146 | } 147 | 148 | public DockerContainerRequestBuilder setOnBuild(List onBuild) { 149 | this.onBuild = onBuild; 150 | return this; 151 | } 152 | 153 | public DockerContainerRequestBuilder setLabels(Map labels) { 154 | this.labels = labels; 155 | return this; 156 | } 157 | 158 | public DockerContainerRequestBuilder setMacAddress(String macAddress) { 159 | this.macAddress = macAddress; 160 | return this; 161 | } 162 | 163 | public DockerContainerRequestBuilder setHostConfig(HostConfig hostConfig) { 164 | this.hostConfig = hostConfig; 165 | return this; 166 | } 167 | 168 | public DockerContainerRequest createDockerContainerRequest() { 169 | return new DockerContainerRequest(this); 170 | } 171 | } -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/DockerContainerResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import com.google.gson.annotations.SerializedName; 28 | 29 | import java.util.List; 30 | 31 | public class DockerContainerResponse { 32 | 33 | @SerializedName("Id") 34 | private String id; 35 | @SerializedName("Warnings") 36 | private List warnings; 37 | 38 | public String getId() { 39 | return id; 40 | } 41 | 42 | public List getWarnings() { 43 | return warnings; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "DockerContainerResponse{" + 49 | "id='" + id + '\'' + 50 | ", warnings=" + warnings + 51 | '}'; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/DockerImage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import com.google.gson.annotations.SerializedName; 28 | 29 | import java.util.List; 30 | 31 | public class DockerImage { 32 | 33 | @SerializedName("Created") 34 | private String created; 35 | @SerializedName("Id") 36 | private String id; 37 | @SerializedName("ParentId") 38 | private String parentId; 39 | @SerializedName("RepoTags") 40 | private List repoTags; 41 | @SerializedName("Size") 42 | private Long size; 43 | @SerializedName("VirtualSize") 44 | private Long virtualSize; 45 | 46 | public String created() { 47 | return created; 48 | } 49 | 50 | public String id() { 51 | return id; 52 | } 53 | 54 | public String parentId() { 55 | return parentId; 56 | } 57 | 58 | public List repoTags() { 59 | return repoTags; 60 | } 61 | 62 | public Long size() { 63 | return size; 64 | } 65 | 66 | public Long virtualSize() { 67 | return virtualSize; 68 | } 69 | 70 | @Override 71 | public boolean equals(Object o) { 72 | if (this == o) return true; 73 | if (o == null || getClass() != o.getClass()) return false; 74 | 75 | DockerImage that = (DockerImage) o; 76 | 77 | if (created != null ? !created.equals(that.created) : that.created != null) return false; 78 | if (id != null ? !id.equals(that.id) : that.id != null) return false; 79 | if (parentId != null ? !parentId.equals(that.parentId) : that.parentId != null) return false; 80 | if (repoTags != null ? !repoTags.equals(that.repoTags) : that.repoTags != null) return false; 81 | if (size != null ? !size.equals(that.size) : that.size != null) return false; 82 | if (virtualSize != null ? !virtualSize.equals(that.virtualSize) : that.virtualSize != null) return false; 83 | 84 | return true; 85 | } 86 | 87 | @Override 88 | public int hashCode() { 89 | int result = created != null ? created.hashCode() : 0; 90 | result = 31 * result + (id != null ? id.hashCode() : 0); 91 | result = 31 * result + (parentId != null ? parentId.hashCode() : 0); 92 | result = 31 * result + (repoTags != null ? repoTags.hashCode() : 0); 93 | result = 31 * result + (size != null ? size.hashCode() : 0); 94 | result = 31 * result + (virtualSize != null ? virtualSize.hashCode() : 0); 95 | return result; 96 | } 97 | 98 | @Override 99 | public String toString() { 100 | return "DockerImage{" + 101 | "created='" + created + '\'' + 102 | ", id='" + id + '\'' + 103 | ", parentId='" + parentId + '\'' + 104 | ", repoTags=" + repoTags + 105 | ", size=" + size + 106 | ", virtualSize=" + virtualSize + 107 | '}'; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/DockerImageHistory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import com.google.gson.annotations.SerializedName; 28 | 29 | import java.util.List; 30 | 31 | public class DockerImageHistory { 32 | 33 | @SerializedName("Id") 34 | private String id; 35 | @SerializedName("Created") 36 | private String created; 37 | @SerializedName("CreatedBy") 38 | private String createdBy; 39 | @SerializedName("Tags") 40 | private List tags; 41 | @SerializedName("Size") 42 | private Long size; 43 | @SerializedName("Comment") 44 | private String comment; 45 | 46 | public String getId() { 47 | return id; 48 | } 49 | 50 | public String getCreated() { 51 | return created; 52 | } 53 | 54 | public String getCreatedBy() { 55 | return createdBy; 56 | } 57 | 58 | public List getTags() { 59 | return tags; 60 | } 61 | 62 | public Long getSize() { 63 | return size; 64 | } 65 | 66 | public String getComment() { 67 | return comment; 68 | } 69 | 70 | @Override 71 | public String toString() { 72 | return "DockerImageHistory{" + 73 | "id='" + id + '\'' + 74 | ", created='" + created + '\'' + 75 | ", createdBy='" + createdBy + '\'' + 76 | ", tags=" + tags + 77 | ", size=" + size + 78 | ", comment='" + comment + '\'' + 79 | '}'; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/DockerImageInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import com.google.gson.annotations.SerializedName; 28 | 29 | public class DockerImageInfo { 30 | 31 | @SerializedName("description") 32 | private String description; 33 | @SerializedName("is_official") 34 | private boolean official; 35 | @SerializedName("is_automated") 36 | private boolean automated; 37 | @SerializedName("name") 38 | private String name; 39 | @SerializedName("star_count") 40 | private int starCount; 41 | 42 | public String getDescription() { 43 | return description; 44 | } 45 | 46 | public boolean isOfficial() { 47 | return official; 48 | } 49 | 50 | public boolean isAutomated() { 51 | return automated; 52 | } 53 | 54 | public String getName() { 55 | return name; 56 | } 57 | 58 | public int getStarCount() { 59 | return starCount; 60 | } 61 | 62 | @Override 63 | public String toString() { 64 | return "DockerImageInfo{" + 65 | "description='" + description + '\'' + 66 | ", official=" + official + 67 | ", automated=" + automated + 68 | ", name='" + name + '\'' + 69 | ", starCount=" + starCount + 70 | '}'; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/DockerImageInspectDetails.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import com.google.gson.annotations.SerializedName; 28 | 29 | import java.util.Date; 30 | 31 | public class DockerImageInspectDetails { 32 | @SerializedName("Id") 33 | private String id; 34 | @SerializedName("Parent") 35 | private String parent; 36 | @SerializedName("Comment") 37 | private String comment; 38 | @SerializedName("Created") 39 | private Date created; 40 | @SerializedName("Container") 41 | private String container; 42 | @SerializedName("ContainerConfig") 43 | private DockerContainerRequest containerConfig; 44 | @SerializedName("DockerVersion") 45 | private String dockerVersion; 46 | @SerializedName("Author") 47 | private String author; 48 | @SerializedName("Config") 49 | private DockerContainerRequest config; 50 | @SerializedName("Architecture") 51 | private String architecture; 52 | @SerializedName("Os") 53 | private String os; 54 | @SerializedName("Size") 55 | private Long size; 56 | @SerializedName("VirtualSize") 57 | private Long virtualSize; 58 | 59 | public String getId() { 60 | return id; 61 | } 62 | 63 | public String getParent() { 64 | return parent; 65 | } 66 | 67 | public String getComment() { 68 | return comment; 69 | } 70 | 71 | public Date getCreated() { 72 | return created; 73 | } 74 | 75 | public String getContainer() { 76 | return container; 77 | } 78 | 79 | public DockerContainerRequest getContainerConfig() { 80 | return containerConfig; 81 | } 82 | 83 | public String getDockerVersion() { 84 | return dockerVersion; 85 | } 86 | 87 | public String getAuthor() { 88 | return author; 89 | } 90 | 91 | public DockerContainerRequest getConfig() { 92 | return config; 93 | } 94 | 95 | public String getArchitecture() { 96 | return architecture; 97 | } 98 | 99 | public String getOs() { 100 | return os; 101 | } 102 | 103 | public Long getSize() { 104 | return size; 105 | } 106 | 107 | public Long getVirtualSize() { 108 | return virtualSize; 109 | } 110 | 111 | @Override 112 | public String toString() { 113 | return "DockerImageInspectDetails{" + 114 | "id='" + id + '\'' + 115 | ", parent='" + parent + '\'' + 116 | ", comment='" + comment + '\'' + 117 | ", created=" + created + 118 | ", container='" + container + '\'' + 119 | ", dockerVersion='" + dockerVersion + '\'' + 120 | ", author='" + author + '\'' + 121 | ", architecture='" + architecture + '\'' + 122 | ", os='" + os + '\'' + 123 | ", size=" + size + 124 | ", virtualSize=" + virtualSize + 125 | '}'; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/DockerInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import com.google.gson.annotations.SerializedName; 28 | 29 | import java.util.List; 30 | 31 | public class DockerInfo { 32 | @SerializedName("Containers") 33 | private int containers; 34 | @SerializedName("Images") 35 | private int images; 36 | @SerializedName("Driver") 37 | private String storageDriver; 38 | @SerializedName("DriverStatus") 39 | private List> driverStatus; 40 | @SerializedName("ExecutionDriver") 41 | private String executionDriver; 42 | @SerializedName("KernelVersion") 43 | private String kernelVersion; 44 | @SerializedName("NCPU") 45 | private int cpus; 46 | @SerializedName("MemTotal") 47 | private long memTotal; 48 | @SerializedName("Name") 49 | private String name; 50 | @SerializedName("ID") 51 | private String id; 52 | @SerializedName("OperatingSystem") 53 | private String operatingSystem; 54 | @SerializedName("Debug") 55 | private Boolean debug; 56 | @SerializedName("NFd") 57 | private int fileDescriptors; 58 | @SerializedName("NGoroutines") 59 | private int goroutines; 60 | @SerializedName("NEventsListener") 61 | private int eventsListener; 62 | @SerializedName("InitPath") 63 | private String initPath; 64 | @SerializedName("InitSha1") 65 | private String initSha1; 66 | @SerializedName("IndexServerAddress") 67 | private String indexServerAddress; 68 | @SerializedName("MemoryLimit") 69 | private Boolean memoryLimit; 70 | @SerializedName("SwapLimit") 71 | private Boolean swapLimit; 72 | @SerializedName("IPv4Forwarding") 73 | private boolean ipv4Forwarding; 74 | @SerializedName("Labels") 75 | private List labels; 76 | @SerializedName("DockerRootDir") 77 | private String dockerRootDir; 78 | 79 | public int containers() { 80 | return containers; 81 | } 82 | 83 | public int images() { 84 | return images; 85 | } 86 | 87 | public String storageDriver() { 88 | return storageDriver; 89 | } 90 | 91 | public List> driverStatus() { 92 | return driverStatus; 93 | } 94 | 95 | public int cpus() { 96 | return cpus; 97 | } 98 | 99 | public long memTotal() { 100 | return memTotal; 101 | } 102 | 103 | public String name() { 104 | return name; 105 | } 106 | 107 | public String id() { 108 | return id; 109 | } 110 | 111 | public String executionDriver() { 112 | return executionDriver; 113 | } 114 | 115 | public String kernelVersion() { 116 | return kernelVersion; 117 | } 118 | 119 | public String operatingSystem() { 120 | return operatingSystem; 121 | } 122 | 123 | public boolean debug() { 124 | return debug; 125 | } 126 | 127 | public int fileDescriptors() { 128 | return fileDescriptors; 129 | } 130 | 131 | public int goroutines() { 132 | return goroutines; 133 | } 134 | 135 | public int eventsListener() { 136 | return eventsListener; 137 | } 138 | 139 | public String initPath() { 140 | return initPath; 141 | } 142 | 143 | public String initSha1() { 144 | return initSha1; 145 | } 146 | 147 | public String indexServerAddress() { 148 | return indexServerAddress; 149 | } 150 | 151 | public boolean memoryLimit() { 152 | return memoryLimit; 153 | } 154 | 155 | public boolean swapLimit() { 156 | return swapLimit; 157 | } 158 | 159 | public boolean ipv4Forwarding() { 160 | return ipv4Forwarding; 161 | } 162 | 163 | public List labels() { 164 | return labels; 165 | } 166 | 167 | public String dockerRootDir() { 168 | return dockerRootDir; 169 | } 170 | 171 | @Override 172 | public boolean equals(Object o) { 173 | if (this == o) { 174 | return true; 175 | } 176 | if (o == null || getClass() != o.getClass()) { 177 | return false; 178 | } 179 | 180 | DockerInfo info = (DockerInfo) o; 181 | 182 | if (containers != info.containers) { 183 | return false; 184 | } 185 | if (debug != null ? !debug.equals(info.debug) 186 | : info.debug != null) { 187 | return false; 188 | } 189 | if (eventsListener != info.eventsListener) { 190 | return false; 191 | } 192 | if (fileDescriptors != info.fileDescriptors) { 193 | return false; 194 | } 195 | if (goroutines != info.goroutines) { 196 | return false; 197 | } 198 | if (images != info.images) { 199 | return false; 200 | } 201 | if (executionDriver != null ? !executionDriver.equals(info.executionDriver) 202 | : info.executionDriver != null) { 203 | return false; 204 | } 205 | if (initPath != null ? !initPath.equals(info.initPath) : info.initPath != null) { 206 | return false; 207 | } 208 | if (kernelVersion != null ? !kernelVersion.equals(info.kernelVersion) 209 | : info.kernelVersion != null) { 210 | return false; 211 | } 212 | if (storageDriver != null ? !storageDriver.equals(info.storageDriver) 213 | : info.storageDriver != null) { 214 | return false; 215 | } 216 | if (memoryLimit != null ? !memoryLimit.equals(info.memoryLimit) 217 | : info.memoryLimit != null) { 218 | return false; 219 | } 220 | if (swapLimit != null ? !swapLimit.equals(info.swapLimit) 221 | : info.swapLimit != null) { 222 | return false; 223 | } 224 | 225 | return true; 226 | } 227 | 228 | @Override 229 | public int hashCode() { 230 | int result = containers; 231 | result = 31 * result + images; 232 | result = 31 * result + (storageDriver != null ? storageDriver.hashCode() : 0); 233 | result = 31 * result + (driverStatus != null ? driverStatus.hashCode() : 0); 234 | result = 31 * result + cpus; 235 | result = 31 * result + (int) memTotal; 236 | result = 31 * result + (name != null ? name.hashCode() : 0); 237 | result = 31 * result + (executionDriver != null ? executionDriver.hashCode() : 0); 238 | result = 31 * result + (kernelVersion != null ? kernelVersion.hashCode() : 0); 239 | result = 31 * result + (debug != null ? debug.hashCode() : 0); 240 | result = 31 * result + fileDescriptors; 241 | result = 31 * result + goroutines; 242 | result = 31 * result + eventsListener; 243 | result = 31 * result + (initPath != null ? initPath.hashCode() : 0); 244 | result = 31 * result + (initSha1 != null ? initSha1.hashCode() : 0); 245 | result = 31 * result + (indexServerAddress != null ? indexServerAddress.hashCode() : 0); 246 | result = 31 * result + (memoryLimit != null ? memoryLimit.hashCode() : 0); 247 | result = 31 * result + (swapLimit != null ? swapLimit.hashCode() : 0); 248 | return result; 249 | } 250 | 251 | @Override 252 | public String toString() { 253 | return String.format("Info{ containers = %d, images = %d, storageDriver = %s, " 254 | + "driverStatus = %s, cpus = %d, memTotal = %d, name = %s, " 255 | + "executionDriver = %s, kernelVersion = %s, debug = %b, " 256 | + "fileDescriptors = %d, goroutines = %d, eventsListener = %d, " 257 | + "initPath = %s, initSha1 = %s, indexServerAddress = %s, " 258 | + "memoryLimit = %b, swapLimit = %b", 259 | containers, images, storageDriver, driverStatus, cpus, memTotal, name, 260 | executionDriver, kernelVersion, debug, fileDescriptors, goroutines, 261 | eventsListener, initPath, initSha1, indexServerAddress, memoryLimit, 262 | swapLimit); 263 | } 264 | } 265 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/DockerVersion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import com.google.gson.annotations.SerializedName; 28 | 29 | public class DockerVersion { 30 | @SerializedName("ApiVersion") 31 | private String apiVersion; 32 | @SerializedName("Arch") 33 | private String arch; 34 | @SerializedName("GitCommit") 35 | private String gitCommit; 36 | @SerializedName("GoVersion") 37 | private String goVersion; 38 | @SerializedName("KernelVersion") 39 | private String kernelVersion; 40 | @SerializedName("Os") 41 | private String os; 42 | @SerializedName("Version") 43 | private String version; 44 | 45 | public String apiVersion() { 46 | return apiVersion; 47 | } 48 | 49 | public String arch() { 50 | return arch; 51 | } 52 | 53 | public String gitCommit() { 54 | return gitCommit; 55 | } 56 | 57 | public String goVersion() { 58 | return goVersion; 59 | } 60 | 61 | public String kernelVersion() { 62 | return kernelVersion; 63 | } 64 | 65 | public String os() { 66 | return os; 67 | } 68 | 69 | public String version() { 70 | return version; 71 | } 72 | 73 | @Override 74 | public boolean equals(final Object o) { 75 | if (this == o) { 76 | return true; 77 | } 78 | if (o == null || getClass() != o.getClass()) { 79 | return false; 80 | } 81 | 82 | final DockerVersion version1 = (DockerVersion) o; 83 | 84 | if (apiVersion != null ? !apiVersion.equals(version1.apiVersion) 85 | : version1.apiVersion != null) { 86 | return false; 87 | } 88 | if (arch != null ? !arch.equals(version1.arch) : version1.arch != null) { 89 | return false; 90 | } 91 | if (gitCommit != null ? !gitCommit.equals(version1.gitCommit) : version1.gitCommit != null) { 92 | return false; 93 | } 94 | if (goVersion != null ? !goVersion.equals(version1.goVersion) : version1.goVersion != null) { 95 | return false; 96 | } 97 | if (kernelVersion != null ? !kernelVersion.equals(version1.kernelVersion) 98 | : version1.kernelVersion != null) { 99 | return false; 100 | } 101 | if (os != null ? !os.equals(version1.os) : version1.os != null) { 102 | return false; 103 | } 104 | if (version != null ? !version.equals(version1.version) : version1.version != null) { 105 | return false; 106 | } 107 | 108 | return true; 109 | } 110 | 111 | @Override 112 | public int hashCode() { 113 | int result = apiVersion != null ? apiVersion.hashCode() : 0; 114 | result = 31 * result + (arch != null ? arch.hashCode() : 0); 115 | result = 31 * result + (gitCommit != null ? gitCommit.hashCode() : 0); 116 | result = 31 * result + (goVersion != null ? goVersion.hashCode() : 0); 117 | result = 31 * result + (kernelVersion != null ? kernelVersion.hashCode() : 0); 118 | result = 31 * result + (os != null ? os.hashCode() : 0); 119 | result = 31 * result + (version != null ? version.hashCode() : 0); 120 | return result; 121 | } 122 | 123 | @Override 124 | public String toString() { 125 | return "DockerVersion{" + 126 | "apiVersion='" + apiVersion + '\'' + 127 | ", arch='" + arch + '\'' + 128 | ", gitCommit='" + gitCommit + '\'' + 129 | ", goVersion='" + goVersion + '\'' + 130 | ", kernelVersion='" + kernelVersion + '\'' + 131 | ", os='" + os + '\'' + 132 | ", version='" + version + '\'' + 133 | '}'; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/ExecCreateRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * The MIT License 4 | * * 5 | * * Copyright 2015 Shekhar Gulati . 6 | * * 7 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * * of this software and associated documentation files (the "Software"), to deal 9 | * * in the Software without restriction, including without limitation the rights 10 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * * copies of the Software, and to permit persons to whom the Software is 12 | * * furnished to do so, subject to the following conditions: 13 | * * 14 | * * The above copyright notice and this permission notice shall be included in 15 | * * all copies or substantial portions of the Software. 16 | * * 17 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * * THE SOFTWARE. 24 | * 25 | */ 26 | 27 | package com.shekhargulati.reactivex.docker.client.representations; 28 | 29 | import com.google.gson.annotations.SerializedName; 30 | 31 | import java.util.List; 32 | 33 | public class ExecCreateRequest { 34 | 35 | @SerializedName("AttachStdin") 36 | private boolean attachStdin = true; 37 | 38 | @SerializedName("AttachStdout") 39 | private boolean attachStdout = true; 40 | 41 | @SerializedName("AttachStderr") 42 | private boolean attachStderr = true; 43 | 44 | @SerializedName("Tty") 45 | private boolean tty = false; 46 | 47 | @SerializedName("Cmd") 48 | private List cmd; 49 | 50 | private ExecCreateRequest(List cmd) { 51 | this.cmd = cmd; 52 | } 53 | 54 | public static ExecCreateRequest withCmd(List cmd) { 55 | return new ExecCreateRequest(cmd); 56 | } 57 | 58 | public boolean isAttachStdin() { 59 | return attachStdin; 60 | } 61 | 62 | public boolean isAttachStdout() { 63 | return attachStdout; 64 | } 65 | 66 | public boolean isAttachStderr() { 67 | return attachStderr; 68 | } 69 | 70 | public boolean isTty() { 71 | return tty; 72 | } 73 | 74 | public List getCmd() { 75 | return cmd; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/ExecCreateResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * The MIT License 4 | * * 5 | * * Copyright 2015 Shekhar Gulati . 6 | * * 7 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * * of this software and associated documentation files (the "Software"), to deal 9 | * * in the Software without restriction, including without limitation the rights 10 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * * copies of the Software, and to permit persons to whom the Software is 12 | * * furnished to do so, subject to the following conditions: 13 | * * 14 | * * The above copyright notice and this permission notice shall be included in 15 | * * all copies or substantial portions of the Software. 16 | * * 17 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * * THE SOFTWARE. 24 | * 25 | */ 26 | 27 | package com.shekhargulati.reactivex.docker.client.representations; 28 | 29 | import com.google.gson.annotations.SerializedName; 30 | 31 | import java.util.ArrayList; 32 | import java.util.List; 33 | 34 | public class ExecCreateResponse { 35 | 36 | @SerializedName("Id") 37 | private String id; 38 | 39 | @SerializedName("Warnings") 40 | private List warnings = new ArrayList<>(); 41 | 42 | public String getId() { 43 | return id; 44 | } 45 | 46 | public List getWarnings() { 47 | return warnings; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return "ExecCreateResponse{" + 53 | "id='" + id + '\'' + 54 | ", warnings=" + warnings + 55 | '}'; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/ExecStartRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * The MIT License 4 | * * 5 | * * Copyright 2015 Shekhar Gulati . 6 | * * 7 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * * of this software and associated documentation files (the "Software"), to deal 9 | * * in the Software without restriction, including without limitation the rights 10 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * * copies of the Software, and to permit persons to whom the Software is 12 | * * furnished to do so, subject to the following conditions: 13 | * * 14 | * * The above copyright notice and this permission notice shall be included in 15 | * * all copies or substantial portions of the Software. 16 | * * 17 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * * THE SOFTWARE. 24 | * 25 | */ 26 | 27 | package com.shekhargulati.reactivex.docker.client.representations; 28 | 29 | import com.google.gson.annotations.SerializedName; 30 | 31 | public class ExecStartRequest { 32 | 33 | @SerializedName("Detach") 34 | private boolean detach = false; 35 | 36 | @SerializedName("Tty") 37 | private boolean tty = false; 38 | 39 | private ExecStartRequest() { 40 | } 41 | 42 | private ExecStartRequest(boolean detach, boolean tty) { 43 | this.detach = detach; 44 | this.tty = tty; 45 | } 46 | 47 | public static ExecStartRequest withDefaults() { 48 | return new ExecStartRequest(); 49 | } 50 | 51 | public static ExecStartRequest withParameters(boolean detach, boolean tty) { 52 | return new ExecStartRequest(detach, tty); 53 | } 54 | 55 | public boolean isDetach() { 56 | return detach; 57 | } 58 | 59 | public boolean isTty() { 60 | return tty; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/HostConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import com.google.gson.annotations.SerializedName; 28 | 29 | import java.util.List; 30 | import java.util.Map; 31 | 32 | public class HostConfig { 33 | 34 | @SerializedName("Binds") 35 | private List binds; 36 | @SerializedName("ContainerIDFile") 37 | private String containerIDFile; 38 | @SerializedName("LxcConf") 39 | private List lxcConf; 40 | @SerializedName("Privileged") 41 | private Boolean privileged; 42 | @SerializedName("PortBindings") 43 | private Map> portBindings; 44 | @SerializedName("Links") 45 | private List links; 46 | @SerializedName("PublishAllPorts") 47 | private Boolean publishAllPorts; 48 | @SerializedName("Dns") 49 | private List dns; 50 | @SerializedName("DnsSearch") 51 | private List dnsSearch; 52 | @SerializedName("VolumesFrom") 53 | private List volumesFrom; 54 | @SerializedName("NetworkMode") 55 | private String networkMode; 56 | @SerializedName("SecurityOpt") 57 | private List securityOpt; 58 | @SerializedName("Memory") 59 | private Long memory; 60 | @SerializedName("MemorySwap") 61 | private Long memorySwap; 62 | @SerializedName("CpuShares") 63 | private Long cpuShares; 64 | @SerializedName("CpusetCpus") 65 | private String cpusetCpus; 66 | @SerializedName("CgroupParent") 67 | private String cgroupParent; 68 | @SerializedName("CapAdd") 69 | private List capAdd; 70 | 71 | HostConfig(HostConfigBuilder builder) { 72 | this.binds = builder.binds; 73 | this.containerIDFile = builder.containerIDFile; 74 | this.lxcConf = builder.lxcConf; 75 | this.privileged = builder.privileged; 76 | this.portBindings = builder.portBindings; 77 | this.links = builder.links; 78 | this.publishAllPorts = builder.publishAllPorts; 79 | this.dns = builder.dns; 80 | this.dnsSearch = builder.dnsSearch; 81 | this.volumesFrom = builder.volumesFrom; 82 | this.networkMode = builder.networkMode; 83 | this.securityOpt = builder.securityOpt; 84 | this.memory = builder.memory; 85 | this.memorySwap = builder.memorySwap; 86 | this.cpuShares = builder.cpuShares; 87 | this.cpusetCpus = builder.cpusetCpus; 88 | this.cgroupParent = builder.cgroupParent; 89 | this.capAdd = builder.capAdd; 90 | } 91 | 92 | public List getBinds() { 93 | return binds; 94 | } 95 | 96 | public String getContainerIDFile() { 97 | return containerIDFile; 98 | } 99 | 100 | public List getLxcConf() { 101 | return lxcConf; 102 | } 103 | 104 | public Boolean getPrivileged() { 105 | return privileged; 106 | } 107 | 108 | public Map> getPortBindings() { 109 | return portBindings; 110 | } 111 | 112 | public List getLinks() { 113 | return links; 114 | } 115 | 116 | public Boolean getPublishAllPorts() { 117 | return publishAllPorts; 118 | } 119 | 120 | public List getDns() { 121 | return dns; 122 | } 123 | 124 | public List getDnsSearch() { 125 | return dnsSearch; 126 | } 127 | 128 | public List getVolumesFrom() { 129 | return volumesFrom; 130 | } 131 | 132 | public String getNetworkMode() { 133 | return networkMode; 134 | } 135 | 136 | public List getSecurityOpt() { 137 | return securityOpt; 138 | } 139 | 140 | public Long getMemory() { 141 | return memory; 142 | } 143 | 144 | public Long getMemorySwap() { 145 | return memorySwap; 146 | } 147 | 148 | public Long getCpuShares() { 149 | return cpuShares; 150 | } 151 | 152 | public String getCpusetCpus() { 153 | return cpusetCpus; 154 | } 155 | 156 | public String getCgroupParent() { 157 | return cgroupParent; 158 | } 159 | 160 | public List getCapAdd() { 161 | return capAdd; 162 | } 163 | 164 | public static class LxcConfParameter { 165 | 166 | @SerializedName("Key") 167 | private String key; 168 | @SerializedName("Value") 169 | private String value; 170 | 171 | public LxcConfParameter(final String key, final String value) { 172 | this.key = key; 173 | this.value = value; 174 | } 175 | 176 | public String key() { 177 | return key; 178 | } 179 | 180 | public String value() { 181 | return value; 182 | } 183 | 184 | @Override 185 | public boolean equals(final Object o) { 186 | if (this == o) { 187 | return true; 188 | } 189 | if (o == null || getClass() != o.getClass()) { 190 | return false; 191 | } 192 | 193 | final LxcConfParameter that = (LxcConfParameter) o; 194 | 195 | if (key != null ? !key.equals(that.key) : that.key != null) { 196 | return false; 197 | } 198 | if (value != null ? !value.equals(that.value) : that.value != null) { 199 | return false; 200 | } 201 | 202 | return true; 203 | } 204 | 205 | @Override 206 | public int hashCode() { 207 | int result = key != null ? key.hashCode() : 0; 208 | result = 31 * result + (value != null ? value.hashCode() : 0); 209 | return result; 210 | } 211 | 212 | @Override 213 | public String toString() { 214 | return "LxcConfParameter{" + 215 | "key='" + key + '\'' + 216 | ", value='" + value + '\'' + 217 | '}'; 218 | } 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/HostConfigBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import java.util.List; 28 | import java.util.Map; 29 | 30 | public class HostConfigBuilder { 31 | List binds; 32 | String containerIDFile; 33 | List lxcConf; 34 | Boolean privileged; 35 | Map> portBindings; 36 | List links; 37 | Boolean publishAllPorts; 38 | List dns; 39 | List dnsSearch; 40 | List volumesFrom; 41 | String networkMode; 42 | List securityOpt; 43 | Long memory; 44 | Long memorySwap; 45 | Long cpuShares; 46 | String cpusetCpus; 47 | String cgroupParent; 48 | List capAdd; 49 | 50 | public HostConfigBuilder setBinds(List binds) { 51 | this.binds = binds; 52 | return this; 53 | } 54 | 55 | public HostConfigBuilder setContainerIDFile(String containerIDFile) { 56 | this.containerIDFile = containerIDFile; 57 | return this; 58 | } 59 | 60 | public HostConfigBuilder setLxcConf(List lxcConf) { 61 | this.lxcConf = lxcConf; 62 | return this; 63 | } 64 | 65 | public HostConfigBuilder setPrivileged(Boolean privileged) { 66 | this.privileged = privileged; 67 | return this; 68 | } 69 | 70 | public HostConfigBuilder setPortBindings(Map> portBindings) { 71 | this.portBindings = portBindings; 72 | return this; 73 | } 74 | 75 | public HostConfigBuilder setLinks(List links) { 76 | this.links = links; 77 | return this; 78 | } 79 | 80 | public HostConfigBuilder setPublishAllPorts(Boolean publishAllPorts) { 81 | this.publishAllPorts = publishAllPorts; 82 | return this; 83 | } 84 | 85 | public HostConfigBuilder setDns(List dns) { 86 | this.dns = dns; 87 | return this; 88 | } 89 | 90 | public HostConfigBuilder setDnsSearch(List dnsSearch) { 91 | this.dnsSearch = dnsSearch; 92 | return this; 93 | } 94 | 95 | public HostConfigBuilder setVolumesFrom(List volumesFrom) { 96 | this.volumesFrom = volumesFrom; 97 | return this; 98 | } 99 | 100 | public HostConfigBuilder setNetworkMode(String networkMode) { 101 | this.networkMode = networkMode; 102 | return this; 103 | } 104 | 105 | public HostConfigBuilder setSecurityOpt(List securityOpt) { 106 | this.securityOpt = securityOpt; 107 | return this; 108 | } 109 | 110 | public HostConfigBuilder setMemory(Long memory) { 111 | this.memory = memory; 112 | return this; 113 | } 114 | 115 | public HostConfigBuilder setMemorySwap(Long memorySwap) { 116 | this.memorySwap = memorySwap; 117 | return this; 118 | } 119 | 120 | public HostConfigBuilder setCpuShares(Long cpuShares) { 121 | this.cpuShares = cpuShares; 122 | return this; 123 | } 124 | 125 | public HostConfigBuilder setCpusetCpus(String cpusetCpus) { 126 | this.cpusetCpus = cpusetCpus; 127 | return this; 128 | } 129 | 130 | public HostConfigBuilder setCgroupParent(String cgroupParent) { 131 | this.cgroupParent = cgroupParent; 132 | return this; 133 | } 134 | 135 | public HostConfigBuilder setCapAdd(List capAdd) { 136 | this.capAdd = capAdd; 137 | return this; 138 | } 139 | 140 | public HostConfig createHostConfig() { 141 | return new HostConfig(this); 142 | } 143 | } -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/Image.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | public class Image { 28 | } 29 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/ImageTag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * The MIT License 4 | * * 5 | * * Copyright 2015 Shekhar Gulati . 6 | * * 7 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * * of this software and associated documentation files (the "Software"), to deal 9 | * * in the Software without restriction, including without limitation the rights 10 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * * copies of the Software, and to permit persons to whom the Software is 12 | * * furnished to do so, subject to the following conditions: 13 | * * 14 | * * The above copyright notice and this permission notice shall be included in 15 | * * all copies or substantial portions of the Software. 16 | * * 17 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * * THE SOFTWARE. 24 | * 25 | */ 26 | 27 | package com.shekhargulati.reactivex.docker.client.representations; 28 | 29 | import java.util.Optional; 30 | 31 | /** 32 | * Created by shekhargulati on 04/12/15. 33 | */ 34 | public class ImageTag { 35 | 36 | private final String image; 37 | private final Optional tag; 38 | 39 | private ImageTag(String image, String tag) { 40 | this.image = image; 41 | this.tag = Optional.ofNullable(tag); 42 | } 43 | 44 | private ImageTag(String image) { 45 | this(image, null); 46 | } 47 | 48 | public static ImageTag of(String image, String tag) { 49 | return new ImageTag(image, tag); 50 | } 51 | 52 | public static ImageTag of(String image) { 53 | return new ImageTag(image); 54 | } 55 | 56 | 57 | public String getImage() { 58 | return image; 59 | } 60 | 61 | public Optional getTag() { 62 | return tag; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/MemoryStats.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import com.google.gson.annotations.SerializedName; 28 | 29 | public class MemoryStats { 30 | @SerializedName("max_usage") 31 | private Long maxUsage; 32 | @SerializedName("usage") 33 | private Long usage; 34 | @SerializedName("failcnt") 35 | private Long failcnt; 36 | @SerializedName("limit") 37 | private Long limit; 38 | 39 | public Long maxUsage() { 40 | return maxUsage; 41 | } 42 | 43 | public Long usage() { 44 | return usage; 45 | } 46 | 47 | public Long failcnt() { 48 | return failcnt; 49 | } 50 | 51 | public Long limit() { 52 | return limit; 53 | } 54 | 55 | @Override 56 | public int hashCode() { 57 | final int prime = 31; 58 | int result = 1; 59 | result = prime * result + (failcnt == null ? 0 : failcnt.hashCode()); 60 | result = prime * result + (limit == null ? 0 : limit.hashCode()); 61 | result = prime * result + (maxUsage == null ? 0 : maxUsage.hashCode()); 62 | result = prime * result + (usage == null ? 0 : usage.hashCode()); 63 | return result; 64 | } 65 | 66 | @Override 67 | public boolean equals(Object obj) { 68 | if (this == obj) { 69 | return true; 70 | } 71 | if (obj == null) { 72 | return false; 73 | } 74 | if (getClass() != obj.getClass()) { 75 | return false; 76 | } 77 | MemoryStats other = (MemoryStats) obj; 78 | if (failcnt == null) { 79 | if (other.failcnt != null) { 80 | return false; 81 | } 82 | } else if (!failcnt.equals(other.failcnt)) { 83 | return false; 84 | } 85 | if (limit == null) { 86 | if (other.limit != null) { 87 | return false; 88 | } 89 | } else if (!limit.equals(other.limit)) { 90 | return false; 91 | } 92 | if (maxUsage == null) { 93 | if (other.maxUsage != null) { 94 | return false; 95 | } 96 | } else if (!maxUsage.equals(other.maxUsage)) { 97 | return false; 98 | } 99 | if (usage == null) { 100 | if (other.usage != null) { 101 | return false; 102 | } 103 | } else if (!usage.equals(other.usage)) { 104 | return false; 105 | } 106 | return true; 107 | } 108 | 109 | @Override 110 | public String toString() { 111 | return "MemoryStats{" + 112 | "maxUsage=" + maxUsage + 113 | ", usage=" + usage + 114 | ", failcnt=" + failcnt + 115 | ", limit=" + limit + 116 | '}'; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/NetworkSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import com.google.gson.annotations.SerializedName; 28 | 29 | import java.util.List; 30 | import java.util.Map; 31 | 32 | public class NetworkSettings { 33 | 34 | @SerializedName("IPAddress") 35 | private String ipAddress; 36 | @SerializedName("IPPrefixLen") 37 | private Integer ipPrefixLen; 38 | @SerializedName("Gateway") 39 | private String gateway; 40 | @SerializedName("Bridge") 41 | private String bridge; 42 | @SerializedName("PortMapping") 43 | private Map> portMapping; 44 | @SerializedName("Ports") 45 | private Map> ports; 46 | @SerializedName("MacAddress") 47 | private String macAddress; 48 | 49 | public String getIpAddress() { 50 | return ipAddress; 51 | } 52 | 53 | public Integer getIpPrefixLen() { 54 | return ipPrefixLen; 55 | } 56 | 57 | public String getGateway() { 58 | return gateway; 59 | } 60 | 61 | public String getBridge() { 62 | return bridge; 63 | } 64 | 65 | public Map> getPortMapping() { 66 | return portMapping; 67 | } 68 | 69 | public Map> getPorts() { 70 | return ports; 71 | } 72 | 73 | public String getMacAddress() { 74 | return macAddress; 75 | } 76 | } -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/NetworkStats.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import com.google.gson.annotations.SerializedName; 28 | 29 | public class NetworkStats { 30 | @SerializedName("rx_bytes") 31 | private Long rxBytes; 32 | @SerializedName("rx_packets") 33 | private Long rxPackets; 34 | @SerializedName("rx_dropped") 35 | private Long rxDropped; 36 | @SerializedName("rx_errors") 37 | private Long rxErrors; 38 | @SerializedName("tx_bytes") 39 | private Long txBytes; 40 | @SerializedName("tx_packets") 41 | private Long txPackets; 42 | @SerializedName("tx_dropped") 43 | private Long txDropped; 44 | @SerializedName("tx_errors") 45 | private Long txErrors; 46 | 47 | public Long rxBytes() { 48 | return rxBytes; 49 | } 50 | 51 | public Long rxPackets() { 52 | return rxPackets; 53 | } 54 | 55 | public Long rxDropped() { 56 | return rxDropped; 57 | } 58 | 59 | public Long rxErrors() { 60 | return rxErrors; 61 | } 62 | 63 | public Long txBytes() { 64 | return txBytes; 65 | } 66 | 67 | public Long txPackets() { 68 | return txPackets; 69 | } 70 | 71 | public Long txDropped() { 72 | return txDropped; 73 | } 74 | 75 | public Long txErrors() { 76 | return txErrors; 77 | } 78 | 79 | @Override 80 | public int hashCode() { 81 | final int prime = 31; 82 | int result = 1; 83 | result = prime * result + (rxBytes == null ? 0 : rxBytes.hashCode()); 84 | result = prime * result + (rxDropped == null ? 0 : rxDropped.hashCode()); 85 | result = prime * result + (rxErrors == null ? 0 : rxErrors.hashCode()); 86 | result = prime * result + (rxPackets == null ? 0 : rxPackets.hashCode()); 87 | result = prime * result + (txBytes == null ? 0 : txBytes.hashCode()); 88 | result = prime * result + (txDropped == null ? 0 : txDropped.hashCode()); 89 | result = prime * result + (txErrors == null ? 0 : txErrors.hashCode()); 90 | result = prime * result + (txPackets == null ? 0 : txPackets.hashCode()); 91 | return result; 92 | } 93 | 94 | @Override 95 | public boolean equals(Object obj) { 96 | if (this == obj) { 97 | return true; 98 | } 99 | if (obj == null) { 100 | return false; 101 | } 102 | if (getClass() != obj.getClass()) { 103 | return false; 104 | } 105 | NetworkStats other = (NetworkStats) obj; 106 | if (rxBytes == null) { 107 | if (other.rxBytes != null) { 108 | return false; 109 | } 110 | } else if (!rxBytes.equals(other.rxBytes)) { 111 | return false; 112 | } 113 | if (rxDropped == null) { 114 | if (other.rxDropped != null) { 115 | return false; 116 | } 117 | } else if (!rxDropped.equals(other.rxDropped)) { 118 | return false; 119 | } 120 | if (rxErrors == null) { 121 | if (other.rxErrors != null) { 122 | return false; 123 | } 124 | } else if (!rxErrors.equals(other.rxErrors)) { 125 | return false; 126 | } 127 | if (rxPackets == null) { 128 | if (other.rxPackets != null) { 129 | return false; 130 | } 131 | } else if (!rxPackets.equals(other.rxPackets)) { 132 | return false; 133 | } 134 | if (txBytes == null) { 135 | if (other.txBytes != null) { 136 | return false; 137 | } 138 | } else if (!txBytes.equals(other.txBytes)) { 139 | return false; 140 | } 141 | if (txDropped == null) { 142 | if (other.txDropped != null) { 143 | return false; 144 | } 145 | } else if (!txDropped.equals(other.txDropped)) { 146 | return false; 147 | } 148 | if (txErrors == null) { 149 | if (other.txErrors != null) { 150 | return false; 151 | } 152 | } else if (!txErrors.equals(other.txErrors)) { 153 | return false; 154 | } 155 | if (txPackets == null) { 156 | if (other.txPackets != null) { 157 | return false; 158 | } 159 | } else if (!txPackets.equals(other.txPackets)) { 160 | return false; 161 | } 162 | return true; 163 | } 164 | 165 | @Override 166 | public String toString() { 167 | return "NetworkStats{" + 168 | "rxBytes=" + rxBytes + 169 | ", rxPackets=" + rxPackets + 170 | ", rxDropped=" + rxDropped + 171 | ", rxErrors=" + rxErrors + 172 | ", txBytes=" + txBytes + 173 | ", txPackets=" + txPackets + 174 | ", txDropped=" + txDropped + 175 | ", txErrors=" + txErrors + 176 | '}'; 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/PortBinding.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | 28 | import com.google.gson.annotations.SerializedName; 29 | 30 | public class PortBinding { 31 | 32 | @SerializedName("HostIp") 33 | private String hostIp; 34 | @SerializedName("HostPort") 35 | private String hostPort; 36 | 37 | public String hostIp() { 38 | return hostIp; 39 | } 40 | 41 | public void hostIp(final String hostIp) { 42 | this.hostIp = hostIp; 43 | } 44 | 45 | public String hostPort() { 46 | return hostPort; 47 | } 48 | 49 | public void hostPort(final String hostPort) { 50 | this.hostPort = hostPort; 51 | } 52 | 53 | public static PortBinding of(final String ip, final String port) { 54 | final PortBinding binding = new PortBinding(); 55 | binding.hostIp(ip); 56 | binding.hostPort(port); 57 | return binding; 58 | } 59 | 60 | public static PortBinding of(final String ip, final int port) { 61 | return of(ip, String.valueOf(port)); 62 | } 63 | 64 | @Override 65 | public boolean equals(final Object o) { 66 | if (this == o) { 67 | return true; 68 | } 69 | if (o == null || getClass() != o.getClass()) { 70 | return false; 71 | } 72 | 73 | final PortBinding that = (PortBinding) o; 74 | 75 | if (hostIp != null ? !hostIp.equals(that.hostIp) : that.hostIp != null) { 76 | return false; 77 | } 78 | if (hostPort != null ? !hostPort.equals(that.hostPort) : that.hostPort != null) { 79 | return false; 80 | } 81 | 82 | return true; 83 | } 84 | 85 | @Override 86 | public int hashCode() { 87 | int result = hostIp != null ? hostIp.hashCode() : 0; 88 | result = 31 * result + (hostPort != null ? hostPort.hashCode() : 0); 89 | return result; 90 | } 91 | 92 | @Override 93 | public String toString() { 94 | return "PortBinding{" + 95 | "hostIp='" + hostIp + '\'' + 96 | ", hostPort='" + hostPort + '\'' + 97 | '}'; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/representations/ProcessListResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.representations; 26 | 27 | import com.google.gson.annotations.SerializedName; 28 | 29 | import java.util.List; 30 | 31 | public class ProcessListResponse { 32 | 33 | @SerializedName("Titles") 34 | private List titles; 35 | 36 | @SerializedName("Processes") 37 | private List> processes; 38 | 39 | public List getTitles() { 40 | return titles; 41 | } 42 | 43 | public List> getProcesses() { 44 | return processes; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "ProcessListResponse{" + 50 | "titles=" + titles + 51 | ", processes=" + processes + 52 | '}'; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/utils/Dates.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.utils; 26 | 27 | public abstract class Dates { 28 | public static final String DOCKER_DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; 29 | } 30 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/utils/Precondition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.utils; 26 | 27 | @FunctionalInterface 28 | public interface Precondition { 29 | 30 | public boolean precondition(T t); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/utils/StreamUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.utils; 26 | 27 | import java.util.Iterator; 28 | import java.util.Spliterator; 29 | import java.util.Spliterators; 30 | import java.util.stream.Stream; 31 | import java.util.stream.StreamSupport; 32 | 33 | public abstract class StreamUtils { 34 | 35 | public static Stream iteratorToStream(Iterator iterator) { 36 | return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/utils/Strings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.utils; 26 | 27 | import java.util.Optional; 28 | 29 | public abstract class Strings { 30 | 31 | public static boolean isEmptyOrNull(String str) { 32 | Optional optional = Optional.ofNullable(str); 33 | return optional.flatMap(s -> s.trim().length() == 0 ? Optional.of(true) : Optional.of(false)).orElse(true); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /rx-docker-client/src/main/java/com/shekhargulati/reactivex/docker/client/utils/Validations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.docker.client.utils; 26 | 27 | import java.util.function.Predicate; 28 | import java.util.function.Supplier; 29 | 30 | public abstract class Validations { 31 | 32 | public static void validate(T t, Predicate predicate, String message) throws IllegalArgumentException { 33 | if (predicate.test(t)) { 34 | throw new IllegalArgumentException(message); 35 | } 36 | } 37 | 38 | public static void validate(T t, Predicate predicate, Supplier messageSupplier) throws IllegalArgumentException { 39 | validate(t, predicate, messageSupplier.get()); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /rx-docker-client/src/test/java/com/shekhargulati/reactivex/docker/client/BuildImageQueryParametersTest.java: -------------------------------------------------------------------------------- 1 | package com.shekhargulati.reactivex.docker.client; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.hamcrest.CoreMatchers.equalTo; 6 | import static org.junit.Assert.assertThat; 7 | 8 | public class BuildImageQueryParametersTest { 9 | 10 | @Test 11 | public void shouldReturnEmptyStringForDefaultQueryParameters() throws Exception { 12 | BuildImageQueryParameters defaultQueryParameters = BuildImageQueryParameters.withDefaultValues(); 13 | assertThat(defaultQueryParameters.toQueryParameterString(), equalTo("")); 14 | } 15 | 16 | @Test 17 | public void shouldBuildQueryParameterWithBothQueryParameters() throws Exception { 18 | BuildImageQueryParameters queryParameters = new BuildImageQueryParameters("test/dockerfile", "http://abc.com"); 19 | assertThat(queryParameters.toQueryParameterString(), equalTo("&dockerfile=test/dockerfile&remote=http://abc.com")); 20 | } 21 | 22 | @Test 23 | public void shouldBuildQueryParameterWithDockerfileOption() throws Exception { 24 | BuildImageQueryParameters queryParameters = new BuildImageQueryParameters("abc/abc"); 25 | assertThat(queryParameters.toQueryParameterString(), equalTo("&dockerfile=abc/abc")); 26 | } 27 | } -------------------------------------------------------------------------------- /rx-docker-client/src/test/java/com/shekhargulati/reactivex/docker/client/ContainerLogQueryParametersTest.java: -------------------------------------------------------------------------------- 1 | package com.shekhargulati.reactivex.docker.client; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import static org.hamcrest.CoreMatchers.equalTo; 7 | 8 | public class ContainerLogQueryParametersTest { 9 | 10 | @Test 11 | public void shouldSetDefaultValuesForContainerLogQueryParameter() throws Exception { 12 | ContainerLogQueryParameters queryParameters = ContainerLogQueryParameters.withDefaultValues(); 13 | Assert.assertThat(queryParameters.toQueryParametersString(), equalTo("?stderr=true&stdout=true×tamps=true&tail=all")); 14 | } 15 | 16 | 17 | } -------------------------------------------------------------------------------- /rx-docker-client/src/test/java/com/shekhargulati/reactivex/docker/client/HostAndPortTest.java: -------------------------------------------------------------------------------- 1 | package com.shekhargulati.reactivex.docker.client; 2 | 3 | import org.junit.Rule; 4 | import org.junit.Test; 5 | import org.junit.rules.ExpectedException; 6 | 7 | import static org.hamcrest.CoreMatchers.equalTo; 8 | import static org.hamcrest.CoreMatchers.is; 9 | import static org.junit.Assert.assertThat; 10 | 11 | public class HostAndPortTest { 12 | 13 | @Rule 14 | public ExpectedException expectedException = ExpectedException.none(); 15 | 16 | @Test 17 | public void shouldParseValidHostPortString() throws Exception { 18 | String hostPortString = "192.168.99.100:2376"; 19 | HostAndPort hostAndPort = HostAndPort.from(hostPortString); 20 | assertThat(hostAndPort.getHost(), is(equalTo("192.168.99.100"))); 21 | assertThat(hostAndPort.getPort(), is(equalTo(2376))); 22 | } 23 | 24 | @Test 25 | public void shouldThrowIllegalArgumentExceptionWhenHostPortStringIsInvalid() throws Exception { 26 | String hostPortString = "test"; 27 | expectedException.expect(IllegalArgumentException.class); 28 | expectedException.expectMessage(equalTo("test should be of format host:port for example 192.168.99.100:2376")); 29 | HostAndPort.from(hostPortString); 30 | 31 | } 32 | } -------------------------------------------------------------------------------- /rx-docker-client/src/test/java/com/shekhargulati/reactivex/docker/client/ImageListQueryParametersTest.java: -------------------------------------------------------------------------------- 1 | package com.shekhargulati.reactivex.docker.client; 2 | 3 | import org.junit.Test; 4 | 5 | import static com.shekhargulati.reactivex.docker.client.ImageListQueryParameters.*; 6 | import static org.hamcrest.CoreMatchers.equalTo; 7 | import static org.junit.Assert.assertThat; 8 | 9 | public class ImageListQueryParametersTest { 10 | 11 | @Test 12 | public void defaultQueryForListImages() throws Exception { 13 | ImageListQueryParameters queryParameters = defaultQueryParameters(); 14 | assertThat(queryParameters.toQuery(), equalTo("?all=false")); 15 | } 16 | 17 | @Test 18 | public void queryForLisAllImages() throws Exception { 19 | ImageListQueryParameters queryParameters = allImagesQueryParameters(); 20 | assertThat(queryParameters.toQuery(), equalTo("?all=true")); 21 | } 22 | 23 | @Test 24 | public void queryForImageWithSpecificName() throws Exception { 25 | ImageListQueryParameters queryParameters = queryParameterWithImageName("busybox"); 26 | assertThat(queryParameters.toQuery(), equalTo("?all=false&filter=busybox")); 27 | 28 | } 29 | 30 | @Test 31 | public void shouldEncodeFilters() throws Exception { 32 | ImageListQueryParameters queryParameters = defaultQueryParameters().addFilter("dangling", "true"); 33 | assertThat(queryParameters.toQuery(), equalTo("?all=false&filters=%7B%22dangling%22%3A%5B%22true%22%5D%7D")); 34 | } 35 | 36 | 37 | } -------------------------------------------------------------------------------- /rx-docker-client/src/test/java/com/shekhargulati/reactivex/docker/client/QueryParametersTest.java: -------------------------------------------------------------------------------- 1 | package com.shekhargulati.reactivex.docker.client; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.hamcrest.CoreMatchers.equalTo; 6 | import static org.junit.Assert.assertThat; 7 | 8 | public class QueryParametersTest { 9 | 10 | @Test 11 | public void shouldBuildQueryWhenNoQueryParameterIsApplied() throws Exception { 12 | QueryParametersBuilder builder = new QueryParametersBuilder(); 13 | String expectedQuery = "?all=false&size=false"; 14 | QueryParameters queryParameters = builder.createQueryParameters(); 15 | assertThat(queryParameters.toQuery(), equalTo(expectedQuery)); 16 | } 17 | 18 | @Test 19 | public void shouldBuildQueryWhenQueryParameterPresent() throws Exception { 20 | QueryParameters queryParameters = new QueryParametersBuilder(). 21 | withAll(true). 22 | withLimit(5). 23 | withSize(true). 24 | createQueryParameters(); 25 | 26 | String expectedQuery = "?all=true&size=true&limit=5"; 27 | assertThat(queryParameters.toQuery(), equalTo(expectedQuery)); 28 | } 29 | 30 | @Test 31 | public void shouldBuildQueryWithBefore() throws Exception { 32 | QueryParameters queryParameters = new QueryParametersBuilder(). 33 | withBefore("beforeId").createQueryParameters(); 34 | 35 | String expectedQuery = "?all=false&size=false&before=beforeId"; 36 | assertThat(queryParameters.toQuery(), equalTo(expectedQuery)); 37 | } 38 | 39 | @Test 40 | public void shouldBuildQueryWithFilters() throws Exception { 41 | QueryParameters queryParameters = new QueryParametersBuilder(). 42 | withFilter("status", "created"). 43 | withFilter("exited", "1"). 44 | createQueryParameters(); 45 | 46 | String expectedQuery = "?all=false&size=false&exited=1;status=created"; 47 | assertThat(queryParameters.toQuery(), equalTo(expectedQuery)); 48 | } 49 | } -------------------------------------------------------------------------------- /rx-docker-client/src/test/java/com/shekhargulati/reactivex/docker/client/junit/CreateDockerContainer.java: -------------------------------------------------------------------------------- 1 | package com.shekhargulati.reactivex.docker.client.junit; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Retention(RetentionPolicy.RUNTIME) 6 | @Target(ElementType.METHOD) 7 | @Repeatable(CreateDockerContainers.class) 8 | public @interface CreateDockerContainer { 9 | 10 | /** 11 | * Name for containers 12 | * 13 | * @return container names 14 | */ 15 | String container(); 16 | 17 | /** 18 | * Command to run 19 | * 20 | * @return command 21 | */ 22 | String[] command() default "/bin/bash"; 23 | 24 | String image() default "ubuntu"; 25 | 26 | boolean attachStdin() default true; 27 | 28 | boolean tty() default true; 29 | 30 | boolean start() default false; 31 | 32 | boolean pullImage() default false; 33 | 34 | String[] exposedPorts() default {}; 35 | 36 | String[] hostPorts() default {}; 37 | 38 | } 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /rx-docker-client/src/test/java/com/shekhargulati/reactivex/docker/client/junit/CreateDockerContainers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * The MIT License 4 | * * 5 | * * Copyright 2015 Shekhar Gulati . 6 | * * 7 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * * of this software and associated documentation files (the "Software"), to deal 9 | * * in the Software without restriction, including without limitation the rights 10 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * * copies of the Software, and to permit persons to whom the Software is 12 | * * furnished to do so, subject to the following conditions: 13 | * * 14 | * * The above copyright notice and this permission notice shall be included in 15 | * * all copies or substantial portions of the Software. 16 | * * 17 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * * THE SOFTWARE. 24 | * 25 | */ 26 | 27 | package com.shekhargulati.reactivex.docker.client.junit; 28 | 29 | import java.lang.annotation.ElementType; 30 | import java.lang.annotation.Retention; 31 | import java.lang.annotation.RetentionPolicy; 32 | import java.lang.annotation.Target; 33 | 34 | @Retention(RetentionPolicy.RUNTIME) 35 | @Target(ElementType.METHOD) 36 | public @interface CreateDockerContainers { 37 | 38 | public CreateDockerContainer[] value(); 39 | } 40 | -------------------------------------------------------------------------------- /rx-docker-client/src/test/java/com/shekhargulati/reactivex/docker/client/junit/DockerContainerRule.java: -------------------------------------------------------------------------------- 1 | package com.shekhargulati.reactivex.docker.client.junit; 2 | 3 | import com.shekhargulati.reactivex.docker.client.RxDockerClient; 4 | import com.shekhargulati.reactivex.docker.client.representations.*; 5 | import org.junit.rules.TestRule; 6 | import org.junit.runner.Description; 7 | import org.junit.runners.model.Statement; 8 | 9 | import java.util.*; 10 | import java.util.stream.Stream; 11 | 12 | import static java.util.stream.Collectors.toList; 13 | 14 | public class DockerContainerRule implements TestRule { 15 | 16 | private final RxDockerClient client; 17 | private List containerIds; 18 | 19 | public DockerContainerRule(RxDockerClient client) { 20 | this.client = client; 21 | } 22 | 23 | @Override 24 | public Statement apply(Statement base, Description description) { 25 | try { 26 | CreateDockerContainer[] containerAnnotations = description.getTestClass().getDeclaredMethod(description.getMethodName()).getAnnotationsByType(CreateDockerContainer.class); 27 | if (containerAnnotations != null && containerAnnotations.length > 0) { 28 | return new Statement() { 29 | @Override 30 | public void evaluate() throws Throwable { 31 | containerIds = createContainers(containerAnnotations); 32 | try { 33 | base.evaluate(); 34 | } finally { 35 | containerIds.forEach(DockerContainerRule.this::removeContainer); 36 | } 37 | } 38 | }; 39 | } 40 | return base; 41 | } catch (NoSuchMethodException e) { 42 | throw new RuntimeException(e); 43 | } 44 | } 45 | 46 | private List createContainers(CreateDockerContainer[] containers) { 47 | return Stream.of(containers).map(this::createAndStartContainer).map(DockerContainerResponse::getId).collect(toList()); 48 | } 49 | 50 | private DockerContainerResponse createAndStartContainer(CreateDockerContainer c) { 51 | if (c.pullImage()) { 52 | client.pullImage("registry"); 53 | } 54 | final Map> portBindings = new HashMap<>(); 55 | for (String hostPort : c.hostPorts()) { 56 | List hostPortBinding = new ArrayList<>(); 57 | hostPortBinding.add(PortBinding.of("0.0.0.0", hostPort)); 58 | portBindings.put(hostPort, hostPortBinding); 59 | } 60 | final HostConfig hostConfig = new HostConfigBuilder().setPortBindings(portBindings).createHostConfig(); 61 | 62 | DockerContainerRequest request = new DockerContainerRequestBuilder() 63 | .setImage(c.image()) 64 | .setCmd(Arrays.asList(c.command())) 65 | .setAttachStdin(c.attachStdin()) 66 | .setTty(c.tty()) 67 | .addExposedPort(c.exposedPorts()) 68 | .setHostConfig(hostConfig) 69 | .createDockerContainerRequest(); 70 | 71 | DockerContainerResponse response = client.createContainer(request, c.container()); 72 | if (c.start()) { 73 | client.startContainer(response.getId()); 74 | } 75 | return response; 76 | } 77 | 78 | 79 | private void removeContainer(String containerId) { 80 | try { 81 | client.removeContainer(containerId, false, true); 82 | } catch (Exception e) { 83 | // ignore as circle ci does not allow containers and images to be destroyed 84 | } 85 | } 86 | 87 | public List containerIds() { 88 | return containerIds; 89 | } 90 | 91 | public String first() { 92 | if (containerIds.isEmpty()) { 93 | throw new NoSuchElementException("No container found"); 94 | } 95 | return containerIds.get(0); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /rx-docker-client/src/test/java/com/shekhargulati/reactivex/docker/client/utils/FileUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.shekhargulati.reactivex.docker.client.utils; 2 | 3 | import org.junit.Rule; 4 | import org.junit.Test; 5 | import org.junit.rules.TemporaryFolder; 6 | 7 | import java.nio.file.Files; 8 | import java.nio.file.Path; 9 | 10 | public class FileUtilsTest { 11 | 12 | @Rule 13 | public TemporaryFolder tmp = new TemporaryFolder(); 14 | 15 | @Test 16 | public void shouldTestIfFileExistsInsideDirectory() throws Exception { 17 | Path pathToExportTo = tmp.newFolder().toPath(); 18 | System.out.println(pathToExportTo); 19 | Path tempFile = Files.createTempFile(pathToExportTo, "abc", "def"); 20 | System.out.println(tempFile); 21 | Files.newDirectoryStream(pathToExportTo, p -> p.toFile().isFile()).forEach(System.out::println); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /rx-docker-client/src/test/java/com/shekhargulati/reactivex/docker/client/utils/StringUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.shekhargulati.reactivex.docker.client.utils; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.hamcrest.CoreMatchers.equalTo; 6 | import static org.hamcrest.CoreMatchers.is; 7 | import static org.junit.Assert.assertThat; 8 | 9 | public class StringUtilsTest { 10 | 11 | @Test 12 | public void shouldReturnTrueForNull() throws Exception { 13 | boolean emptyOrNull = Strings.isEmptyOrNull(null); 14 | assertThat(emptyOrNull, is(equalTo(true))); 15 | } 16 | 17 | @Test 18 | public void shouldReturnTrueForEmptyString() throws Exception { 19 | boolean emptyOrNull = Strings.isEmptyOrNull(""); 20 | assertThat(emptyOrNull, is(equalTo(true))); 21 | } 22 | 23 | @Test 24 | public void shouldReturnTrueForEmptyWithSpacesString() throws Exception { 25 | boolean emptyOrNull = Strings.isEmptyOrNull(" "); 26 | assertThat(emptyOrNull, is(equalTo(true))); 27 | } 28 | 29 | @Test 30 | public void shouldReturnFalseWhenStringHasContent() throws Exception { 31 | boolean emptyOrNull = Strings.isEmptyOrNull("shekhar"); 32 | assertThat(emptyOrNull, is(equalTo(false))); 33 | } 34 | } -------------------------------------------------------------------------------- /rx-docker-client/src/test/resources/images/dockerfile_option_image.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shekhargulati/rx-docker-client/7268db42a1de77c43e713247ac3732a9e054de69/rx-docker-client/src/test/resources/images/dockerfile_option_image.tar -------------------------------------------------------------------------------- /rx-docker-client/src/test/resources/images/hello-world-image.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shekhargulati/rx-docker-client/7268db42a1de77c43e713247ac3732a9e054de69/rx-docker-client/src/test/resources/images/hello-world-image.tar -------------------------------------------------------------------------------- /rx-docker-client/src/test/resources/images/hello-world.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shekhargulati/rx-docker-client/7268db42a1de77c43e713247ac3732a9e054de69/rx-docker-client/src/test/resources/images/hello-world.tar -------------------------------------------------------------------------------- /rx-docker-client/src/test/resources/images/my_docker_image.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shekhargulati/rx-docker-client/7268db42a1de77c43e713247ac3732a9e054de69/rx-docker-client/src/test/resources/images/my_docker_image.tar -------------------------------------------------------------------------------- /rx-docker-client/src/test/resources/images/my_hello_world_image.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shekhargulati/rx-docker-client/7268db42a1de77c43e713247ac3732a9e054de69/rx-docker-client/src/test/resources/images/my_hello_world_image.tar -------------------------------------------------------------------------------- /samples/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | 3 | repositories { 4 | mavenCentral() 5 | } 6 | 7 | dependencies { 8 | compile 'com.shekhargulati.reactivex:rx-docker-client:0.2.1' 9 | } 10 | -------------------------------------------------------------------------------- /samples/src/main/java/com/shekhargulati/reactivex/rx_docker_client/samples/CreateExposePortsAndStartContainer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.rx_docker_client.samples; 26 | 27 | import com.shekhargulati.reactivex.docker.client.RxDockerClient; 28 | import com.shekhargulati.reactivex.docker.client.representations.*; 29 | 30 | import java.util.*; 31 | 32 | public class CreateExposePortsAndStartContainer { 33 | 34 | public static void main(String[] args) { 35 | RxDockerClient client = RxDockerClient.fromDefaultEnv(); 36 | 37 | final String[] exposedPorts = new String[]{"9999/tcp"}; 38 | final String[] hostPorts = new String[]{"9999/tcp"}; 39 | 40 | final Map> portBindings = new HashMap<>(); 41 | for (String hostPort : hostPorts) { 42 | List hostPortBinding = new ArrayList<>(); 43 | hostPortBinding.add(PortBinding.of("0.0.0.0", hostPort)); 44 | portBindings.put(hostPort, hostPortBinding); 45 | } 46 | final HostConfig hostConfig = new HostConfigBuilder().setPortBindings(portBindings).createHostConfig(); 47 | DockerContainerRequest request = new DockerContainerRequestBuilder() 48 | .setImage("ubuntu") 49 | .setCmd(Arrays.asList("/bin/bash")) 50 | .setAttachStdin(true) 51 | .addExposedPort(exposedPorts) 52 | .setHostConfig(hostConfig) 53 | .setTty(true) 54 | .createDockerContainerRequest(); 55 | DockerContainerResponse response = client.createContainer(request, "my_container"); 56 | client.startContainer(response.getId()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /samples/src/main/java/com/shekhargulati/reactivex/rx_docker_client/samples/RxDockerClientExamples.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Shekhar Gulati . 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.shekhargulati.reactivex.rx_docker_client.samples; 26 | 27 | import com.shekhargulati.reactivex.docker.client.RxDockerClient; 28 | import com.shekhargulati.reactivex.docker.client.representations.DockerContainerRequest; 29 | import com.shekhargulati.reactivex.docker.client.representations.DockerContainerRequestBuilder; 30 | import rx.Observable; 31 | 32 | import java.nio.file.Paths; 33 | import java.util.Arrays; 34 | 35 | public class RxDockerClientExamples { 36 | 37 | public static void main(String[] args) { 38 | RxDockerClient client = RxDockerClient.fromDefaultEnv(); 39 | 40 | DockerContainerRequest request = new DockerContainerRequestBuilder() 41 | .setImage("ubuntu:latest") 42 | .setCmd(Arrays.asList("/bin/bash")) 43 | .setAttachStdin(true) 44 | .setTty(true) 45 | .createDockerContainerRequest(); 46 | 47 | String container = "my_first_container"; 48 | client.createContainerObs(request, container) 49 | .flatMap(res -> client.startContainerObs(res.getId())) 50 | .subscribe(System.out::println, 51 | e -> System.err.println("Encountered exception >> " + e.getMessage()), 52 | () -> System.out.println("Successfully completed")); 53 | 54 | 55 | Observable buildImageObs = client.buildImageObs("shekhargulati/my_hello_world_image", 56 | Paths.get("src", "test", "resources", "images", "my_hello_world_image.tar")); 57 | buildImageObs.subscribe(System.out::println); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'rx-docker-client-root' 2 | include 'samples' 3 | include 'rx-docker-client' 4 | --------------------------------------------------------------------------------