Skip to content

Commit 8440cf2

Browse files
committed
Refactoring the client POM as it doesn't use stratos (to avoid conflicts and since this implementation uses REST EASY) and refactoring the code after testing with latest Kubernetes set up https://github.com/nirmal070125/vagrant-kubernetes-setup/releases/tag/v2.0
1 parent 77b5834 commit 8440cf2

8 files changed

Lines changed: 124 additions & 122 deletions

File tree

pom.xml

Lines changed: 96 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,120 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2-
<modelVersion>4.0.0</modelVersion>
3-
<groupId>com.nirmal.kubernetes</groupId>
4-
<artifactId>com.nirmal.kubernetes.java.client</artifactId>
5-
<version>0.0.1-SNAPSHOT</version>
6-
<name>KubernetesAPIJavaClient</name>
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.nirmal.kubernetes</groupId>
5+
<artifactId>com.nirmal.kubernetes.java.client</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<name>KubernetesAPIJavaClient</name>
78

8-
<scm>
9-
<developerConnection>scm:git:https://github.com/nirmal070125/KubernetesAPIJavaClient</developerConnection>
10-
<tag>HEAD</tag>
11-
</scm>
9+
<scm>
10+
<developerConnection>scm:git:https://github.com/nirmal070125/KubernetesAPIJavaClient</developerConnection>
11+
<tag>HEAD</tag>
12+
</scm>
1213

13-
<dependencies>
14-
<dependency>
15-
<groupId>org.jboss.resteasy</groupId>
16-
<artifactId>resteasy-client</artifactId>
17-
<version>3.0.8.Final</version>
18-
</dependency>
19-
<dependency>
20-
<groupId>org.jboss.resteasy</groupId>
21-
<artifactId>resteasy-jaxrs</artifactId>
22-
<version>3.0.8.Final</version>
23-
<!-- filter out unwanted jars -->
24-
<exclusions>
25-
<exclusion>
26-
<groupId>commons-httpclient</groupId>
27-
<artifactId>commons-httpclient</artifactId>
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.jboss.resteasy</groupId>
17+
<artifactId>resteasy-client</artifactId>
18+
<version>3.0.8.Final</version>
19+
</dependency>
20+
<dependency>
21+
<groupId>org.jboss.resteasy</groupId>
22+
<artifactId>resteasy-jaxrs</artifactId>
23+
<version>3.0.8.Final</version>
24+
<!-- filter out unwanted jars -->
25+
<exclusions>
26+
<exclusion>
27+
<groupId>commons-httpclient</groupId>
28+
<artifactId>commons-httpclient</artifactId>
2829
</exclusion>
29-
<exclusion>
30-
<groupId>javax.servlet</groupId>
31-
<artifactId>servlet-api</artifactId>
30+
<exclusion>
31+
<groupId>javax.servlet</groupId>
32+
<artifactId>servlet-api</artifactId>
3233
</exclusion>
3334
</exclusions>
3435
</dependency>
3536
<dependency>
3637
<groupId>org.jboss.resteasy</groupId>
3738
<artifactId>resteasy-jaxb-provider</artifactId>
3839
<version>3.0.8.Final</version>
39-
</dependency>
40-
<dependency>
41-
<groupId>org.apache.httpcomponents</groupId>
42-
<artifactId>httpclient</artifactId>
43-
<version>4.3.4</version>
44-
</dependency>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.apache.httpcomponents</groupId>
43+
<artifactId>httpclient</artifactId>
44+
<version>4.3.4</version>
45+
</dependency>
4546
<dependency>
4647
<groupId>commons-httpclient</groupId>
4748
<artifactId>commons-httpclient</artifactId>
4849
<version>3.1</version>
4950
</dependency>
5051
<dependency>
51-
<groupId>commons-lang</groupId>
52-
<artifactId>commons-lang</artifactId>
53-
<version>2.3</version>
52+
<groupId>org.apache.commons</groupId>
53+
<artifactId>commons-lang3</artifactId>
54+
<version>3.1</version>
5455
</dependency>
5556

5657
<dependency>
57-
<groupId>org.jboss.resteasy</groupId>
58-
<artifactId>resteasy-jackson-provider</artifactId>
59-
<version>3.0.8.Final</version>
58+
<groupId>org.jboss.resteasy</groupId>
59+
<artifactId>resteasy-jackson-provider</artifactId>
60+
<version>3.0.8.Final</version>
6061
</dependency>
6162
<dependency>
62-
<groupId>junit</groupId>
63-
<artifactId>junit</artifactId>
64-
<scope>test</scope>
65-
<version>4.11</version>
66-
</dependency>
63+
<groupId>junit</groupId>
64+
<artifactId>junit</artifactId>
65+
<scope>test</scope>
66+
<version>4.11</version>
67+
</dependency>
6768
</dependencies>
6869

69-
<build>
70-
<plugins>
71-
<plugin>
72-
<artifactId>maven-compiler-plugin</artifactId>
73-
<version>3.1</version>
74-
<configuration>
75-
<source />
76-
<target />
77-
</configuration>
78-
</plugin>
79-
</plugins>
80-
</build>
81-
82-
<profiles>
83-
<profile>
84-
<id>unit</id>
85-
<activation>
86-
<activeByDefault>true</activeByDefault>
87-
</activation>
88-
<build>
89-
<plugins>
90-
<plugin>
91-
<groupId>org.apache.maven.plugins</groupId>
92-
<artifactId>maven-surefire-plugin</artifactId>
93-
<configuration>
94-
<groups>com.nirmal.kubernetes.java.client.UnitTests</groups>
95-
</configuration>
96-
</plugin>
97-
</plugins>
98-
</build>
99-
</profile>
100-
<profile>
101-
<id>live</id>
102-
<build>
103-
<plugins>
104-
<plugin>
105-
<groupId>org.apache.maven.plugins</groupId>
106-
<artifactId>maven-surefire-plugin</artifactId>
107-
<configuration>
108-
<groups>com.nirmal.kubernetes.java.client.LiveTests</groups>
109-
<systemPropertyVariables>
110-
<kubernetes.api.endpoint>${kubernetes.api.endpoint}</kubernetes.api.endpoint>
111-
<docker.image>${docker.image}</docker.image>
112-
</systemPropertyVariables>
113-
</configuration>
114-
</plugin>
115-
</plugins>
116-
</build>
117-
</profile>
118-
</profiles>
70+
<build>
71+
<plugins>
72+
<plugin>
73+
<artifactId>maven-compiler-plugin</artifactId>
74+
<version>3.1</version>
75+
<configuration>
76+
<source />
77+
<target />
78+
</configuration>
79+
</plugin>
80+
</plugins>
81+
</build>
82+
83+
<profiles>
84+
<profile>
85+
<id>unit</id>
86+
<activation>
87+
<activeByDefault>true</activeByDefault>
88+
</activation>
89+
<build>
90+
<plugins>
91+
<plugin>
92+
<groupId>org.apache.maven.plugins</groupId>
93+
<artifactId>maven-surefire-plugin</artifactId>
94+
<configuration>
95+
<groups>com.nirmal.kubernetes.java.client.UnitTests</groups>
96+
</configuration>
97+
</plugin>
98+
</plugins>
99+
</build>
100+
</profile>
101+
<profile>
102+
<id>live</id>
103+
<build>
104+
<plugins>
105+
<plugin>
106+
<groupId>org.apache.maven.plugins</groupId>
107+
<artifactId>maven-surefire-plugin</artifactId>
108+
<configuration>
109+
<groups>com.nirmal.kubernetes.java.client.LiveTests</groups>
110+
<systemPropertyVariables>
111+
<kubernetes.api.endpoint>${kubernetes.api.endpoint}</kubernetes.api.endpoint>
112+
<docker.image>${docker.image}</docker.image>
113+
</systemPropertyVariables>
114+
</configuration>
115+
</plugin>
116+
</plugins>
117+
</build>
118+
</profile>
119+
</profiles>
119120
</project>

src/main/java/com/nirmal/kubernetes/java/client/KubernetesApiClient.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222

2323
import java.util.Arrays;
2424

25-
import javax.ws.rs.client.Client;
26-
import javax.ws.rs.client.ClientBuilder;
27-
2825
import org.apache.commons.logging.Log;
2926
import org.apache.commons.logging.LogFactory;
3027
import org.apache.http.HttpStatus;
@@ -58,7 +55,7 @@ public Pod getPod(String podId) throws KubernetesClientException{
5855

5956
handleNullResponse("Pod ["+podId+"] retrieval failed.", res);
6057

61-
if (res.getEntity() == null ) {
58+
if (res.getResponseStatus().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
6259
String msg = "Pod ["+podId+"] doesn't exist.";
6360
log.error(msg);
6461
throw new KubernetesClientException(msg);
@@ -80,7 +77,7 @@ public PodList getAllPods() throws KubernetesClientException {
8077
ClientRequest request = new ClientRequest(endpointUrl+"pods/");
8178
ClientResponse<PodList> res = request.get(PodList.class);
8279
handleNullResponse("Pod retrieval failed.", res);
83-
if (res.getEntity() == null ) {
80+
if (res.getResponseStatus().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
8481
return new PodList();
8582
}
8683
PodList podList = new PodList();
@@ -165,7 +162,7 @@ public ReplicationController getReplicationController(String controllerId)
165162

166163
handleNullResponse("Replication Controller ["+controllerId+"] retrieval failed.", res);
167164

168-
if (res.getEntity() == null ) {
165+
if (res.getResponseStatus().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
169166
String msg = "Replication Controller ["+controllerId+"] doesn't exist.";
170167
log.error(msg);
171168
throw new KubernetesClientException(msg);
@@ -190,7 +187,7 @@ public ReplicationController[] getAllReplicationControllers()
190187

191188
handleNullResponse("Replication Controller retrieval failed.", res);
192189

193-
if (res.getEntity() == null ) {
190+
if (res.getResponseStatus().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
194191
return new ReplicationController[0];
195192
}
196193
return res.getEntity().getItems();
@@ -218,7 +215,7 @@ public void createReplicationController(ReplicationController controller)
218215
return;
219216
}
220217

221-
if (res.getResponseStatus().getStatusCode() != HttpStatus.SC_OK &&
218+
if (res.getResponseStatus().getStatusCode() != HttpStatus.SC_ACCEPTED &&
222219
res.getResponseStatus().getStatusCode() != HttpStatus.SC_OK ) {
223220
String msg = "Replication Controller [" + controller
224221
+ "] creation failed. Error: "
@@ -316,7 +313,7 @@ public Service getService(String serviceId)
316313

317314
handleNullResponse("Service ["+serviceId+"] retrieval failed.", res);
318315

319-
if (res.getEntity() == null ) {
316+
if (res.getResponseStatus().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
320317
String msg = "Service ["+serviceId+"] doesn't exist.";
321318
log.error(msg);
322319
throw new KubernetesClientException(msg);
@@ -339,7 +336,7 @@ public ServiceList getAllServices() throws KubernetesClientException {
339336

340337
handleNullResponse("Service retrieval failed.", res);
341338

342-
if (res.getEntity() == null ) {
339+
if (res.getResponseStatus().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
343340
return new ServiceList();
344341
}
345342
ServiceList serviceList = new ServiceList();
@@ -423,7 +420,7 @@ public PodList getSelectedPods(Label[] label) throws KubernetesClientException {
423420

424421
handleNullResponse("Pod retrieval failed.", res);
425422

426-
if (res.getEntity() == null ) {
423+
if (res.getResponseStatus().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
427424
return new PodList();
428425
}
429426
PodList podList = new PodList();

src/main/java/com/nirmal/kubernetes/java/client/model/Container.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package com.nirmal.kubernetes.java.client.model;
2222

2323
import java.util.Arrays;
24+
import org.apache.commons.lang3.ArrayUtils;
2425

2526
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
2627

@@ -64,25 +65,25 @@ public String[] getCommand() {
6465
return command;
6566
}
6667
public void setCommand(String[] command) {
67-
this.command = command;
68+
this.command = ArrayUtils.clone(command);
6869
}
6970
public VolumeMount[] getVolumeMounts() {
7071
return volumeMounts;
7172
}
7273
public void setVolumeMounts(VolumeMount[] volumeMounts) {
73-
this.volumeMounts = volumeMounts;
74+
this.volumeMounts = ArrayUtils.clone(volumeMounts);
7475
}
7576
public Port[] getPorts() {
7677
return ports;
7778
}
7879
public void setPorts(Port[] ports) {
79-
this.ports = ports;
80+
this.ports = ArrayUtils.clone(ports);
8081
}
8182
public EnvironmentVariable[] getEnv() {
8283
return env;
8384
}
8485
public void setEnv(EnvironmentVariable[] env) {
85-
this.env = env;
86+
this.env = ArrayUtils.clone(env);
8687
}
8788
@Override
8889
public String toString() {

src/main/java/com/nirmal/kubernetes/java/client/model/Manifest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package com.nirmal.kubernetes.java.client.model;
2222

2323
import java.util.Arrays;
24+
import org.apache.commons.lang3.ArrayUtils;
2425

2526
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
2627

@@ -53,13 +54,13 @@ public Container[] getContainers() {
5354
return containers;
5455
}
5556
public void setContainers(Container[] containers) {
56-
this.containers = containers;
57+
this.containers = ArrayUtils.clone(containers);
5758
}
5859
public Volume[] getVolumes() {
5960
return volumes;
6061
}
6162
public void setVolumes(Volume[] volumes) {
62-
this.volumes = volumes;
63+
this.volumes = ArrayUtils.clone(volumes);
6364
}
6465
@Override
6566
public String toString() {

src/main/java/com/nirmal/kubernetes/java/client/model/PodList.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package com.nirmal.kubernetes.java.client.model;
2222

2323
import java.util.Arrays;
24+
import org.apache.commons.lang3.ArrayUtils;
2425

2526
import javax.xml.bind.annotation.XmlRootElement;
2627

@@ -50,7 +51,7 @@ public Pod[] getItems() {
5051
return items;
5152
}
5253
public void setItems(Pod[] items) {
53-
this.items = items;
54+
this.items = ArrayUtils.clone(items);
5455
}
5556
@Override
5657
public String toString() {

src/main/java/com/nirmal/kubernetes/java/client/model/ReplicationControllerList.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package com.nirmal.kubernetes.java.client.model;
2222

2323
import java.util.Arrays;
24+
import org.apache.commons.lang3.ArrayUtils;
2425

2526
import javax.xml.bind.annotation.XmlRootElement;
2627

@@ -50,7 +51,7 @@ public ReplicationController[] getItems() {
5051
return items;
5152
}
5253
public void setItems(ReplicationController[] items) {
53-
this.items = items;
54+
this.items = ArrayUtils.clone(items);
5455
}
5556
@Override
5657
public String toString() {

0 commit comments

Comments
 (0)