Skip to content

Commit

Permalink
Merge pull request #952 from eclipse/CHE-253
Browse files Browse the repository at this point in the history
CHE-253: Refactor Che docker client
  • Loading branch information
Mykola Morhun committed May 4, 2016
2 parents 76ec686 + 95a4f19 commit 00b26db
Show file tree
Hide file tree
Showing 55 changed files with 6,113 additions and 324 deletions.
14 changes: 14 additions & 0 deletions plugins/plugin-docker/che-plugin-docker-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-dto</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-gwt</artifactId>
Expand All @@ -101,6 +105,16 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.che.plugin.docker.client;

import java.util.Arrays;
import java.util.Objects;

/**
* @author andrew00x
Expand Down Expand Up @@ -39,4 +40,19 @@ public String toString() {
", id='" + id + '\'' +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Exec exec = (Exec)o;
return Arrays.equals(command, exec.command) &&
Objects.equals(id, exec.id);
}

@Override
public int hashCode() {
return Objects.hash(Arrays.hashCode(command), id);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

/**
* @author andrew00x
* @author Alexander Garagatyi
* @author Mykola Morhun
*/
public abstract class DockerConnection implements Closeable {
private String method;
private String path;
private Entity<?> entity;
private StringBuilder query = new StringBuilder();
private List<Pair<String, ?>> headers = Collections.emptyList();
private List<Pair<String, ?>> headers = new LinkedList<>();

public DockerConnection method(String method) {
this.method = method;
Expand Down Expand Up @@ -61,8 +62,13 @@ public DockerConnection query(String name, Object... values) {
return this;
}

public DockerConnection header(String key, Object value) {
this.headers.add(Pair.of(key, value));
return this;
}

public DockerConnection headers(List<Pair<String, ?>> headers) {
this.headers = headers;
this.headers.addAll(headers);
return this;
}

Expand All @@ -71,6 +77,10 @@ public DockerConnection entity(InputStream entity) {
return this;
}

/**
* @deprecated use {@link #entity(byte[])} instead
*/
@Deprecated
public DockerConnection entity(String entity) {
this.entity = new StringEntity(entity);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* @author andrew00x
*/
public class ContainerCommited {
public class ContainerCommitted {
private String id;

public String getId() {
Expand All @@ -26,7 +26,7 @@ public void setId(String id) {

@Override
public String toString() {
return "ContainerCommited{" +
return "ContainerCommitted{" +
"id='" + id + '\'' +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/** @author andrew00x */
/**
* @author andrew00x
* @author Mykola Morhun
*/
public class ContainerInfo {
private String id;
// Date format: yyyy-MM-dd'T'HH:mm:ss.SSSSSSXXX
Expand All @@ -38,6 +42,8 @@ public class ContainerInfo {
private String[] execIDs;
private int restartCount;
private String logPath;
/** Node is used for Docker Swarm */
private Node node;

private Map<String, String> volumes = new HashMap<>();
private Map<String, Boolean> volumesRW = new HashMap<>();
Expand Down Expand Up @@ -226,6 +232,14 @@ public void setLogPath(String logPath) {
this.logPath = logPath;
}

public Node getNode() {
return node;
}

public void setNode(Node node) {
this.node = node;
}

@Override
public String toString() {
return "ContainerInfo{" +
Expand All @@ -252,6 +266,46 @@ public String toString() {
", logPath='" + logPath + '\'' +
", volumes=" + volumes +
", volumesRW=" + volumesRW +
", node=" + node +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ContainerInfo that = (ContainerInfo)o;
return restartCount == that.restartCount &&
Objects.equals(id, that.id) &&
Objects.equals(created, that.created) &&
Objects.equals(appArmorProfile, that.appArmorProfile) &&
Objects.equals(path, that.path) &&
Arrays.equals(args, that.args) &&
Objects.equals(config, that.config) &&
Objects.equals(state, that.state) &&
Objects.equals(image, that.image) &&
Objects.equals(networkSettings, that.networkSettings) &&
Objects.equals(resolvConfPath, that.resolvConfPath) &&
Objects.equals(hostConfig, that.hostConfig) &&
Objects.equals(driver, that.driver) &&
Objects.equals(execDriver, that.execDriver) &&
Objects.equals(hostnamePath, that.hostnamePath) &&
Objects.equals(hostsPath, that.hostsPath) &&
Objects.equals(mountLabel, that.mountLabel) &&
Objects.equals(name, that.name) &&
Objects.equals(processLabel, that.processLabel) &&
Arrays.equals(execIDs, that.execIDs) &&
Objects.equals(logPath, that.logPath) &&
Objects.equals(node, that.node) &&
Objects.equals(volumes, that.volumes) &&
Objects.equals(volumesRW, that.volumesRW);
}

@Override
public int hashCode() {
return Objects
.hash(id, created, appArmorProfile, path, Arrays.hashCode(args), config, state, image, networkSettings, resolvConfPath,
hostConfig, driver, execDriver, hostnamePath, hostsPath, mountLabel, name, processLabel, Arrays.hashCode(execIDs),
restartCount, logPath, node, volumes, volumesRW);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.plugin.docker.client.json;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
* Describe docker node in swarm model
*
* @author Eugene Voevodin
* @author Alexander Garagatyi
*/
public class Node {

private String id;
private String name;
private String addr;
private String ip;
private int cpus;
private long memory;

private Map<String, String> labels = new HashMap<>();

public String getID() {
return id;
}

public void setID(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getAddr() {
return addr;
}

public void setAddr(String addr) {
this.addr = addr;
}

public String getIP() {
return ip;
}

public void setIP(String ip) {
this.ip = ip;
}

public int getCpus() {
return cpus;
}

public void setCpus(int cpus) {
this.cpus = cpus;
}

public long getMemory() {
return memory;
}

public void setMemory(long memory) {
this.memory = memory;
}

public Map<String, String> getLabels() {
return labels;
}

public void setLabels(Map<String, String> labels) {
this.labels = labels;
}

@Override
public String toString() {
return "Node{" +
"ID='" + id + '\'' +
", name='" + name + '\'' +
", addr='" + addr + '\'' +
", IP='" + ip + '\'' +
", cpus=" + cpus +
", memory=" + memory +
", labels=" + labels +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Node)) return false;
Node node = (Node)o;
return Objects.equals(getCpus(), node.getCpus()) &&
Objects.equals(getMemory(), node.getMemory()) &&
Objects.equals(getID(), node.getID()) &&
Objects.equals(getName(), node.getName()) &&
Objects.equals(getAddr(), node.getAddr()) &&
Objects.equals(getIP(), node.getIP()) &&
Objects.equals(getLabels(), node.getLabels());
}

@Override
public int hashCode() {
return Objects.hash(getID(), getName(), getAddr(), getIP(), getCpus(), getMemory(), getLabels());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
*******************************************************************************/
package org.eclipse.che.plugin.docker.client.json;

import java.util.Objects;

/**
* @author Anton Korneta
*/
public class Version {
private String version;
private String aPIVersion;
private String apiVersion;
private String goVersion;
private String gitCommit;
private String os;
Expand All @@ -29,12 +31,12 @@ public void setVersion(String version) {
this.version = version;
}

public String getaPIVersion() {
return aPIVersion;
public String getApiVersion() {
return apiVersion;
}

public void setaPIVersion(String aPIVersion) {
this.aPIVersion = aPIVersion;
public void setApiVersion(String apiVersion) {
this.apiVersion = apiVersion;
}

public String getGoVersion() {
Expand Down Expand Up @@ -73,11 +75,30 @@ public void setArch(String arch) {
public String toString() {
return "Version{" +
"Version='" + version + '\'' +
", APIVersion='" + aPIVersion + '\'' +
", APIVersion='" + apiVersion + '\'' +
", GoVersion='" + goVersion + '\'' +
", GitCommit='" + gitCommit + '\'' +
", Os='" + os + '\'' +
", Arch='" + arch + '\'' +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Version version1 = (Version)o;
return Objects.equals(version, version1.version) &&
Objects.equals(apiVersion, version1.apiVersion) &&
Objects.equals(goVersion, version1.goVersion) &&
Objects.equals(gitCommit, version1.gitCommit) &&
Objects.equals(os, version1.os) &&
Objects.equals(arch, version1.arch);
}

@Override
public int hashCode() {
return Objects.hash(version, apiVersion, goVersion, gitCommit, os, arch);
}

}
Loading

0 comments on commit 00b26db

Please sign in to comment.