Skip to content

Commit 26a9cc0

Browse files
committed
Implement missing methods with JAX-WS for v2
We need a different Java API than the REST API to simplify it and overcome some JAX-WS limitations
1 parent e9977b7 commit 26a9cc0

5 files changed

Lines changed: 311 additions & 78 deletions

File tree

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@
6666
<artifactId>commons-lang3</artifactId>
6767
<version>3.1</version>
6868
</dependency>
69+
<dependency>
70+
<groupId>com.google.guava</groupId>
71+
<artifactId>guava</artifactId>
72+
<version>18.0</version>
73+
</dependency>
6974

7075
<dependency>
7176
<groupId>org.jboss.resteasy</groupId>

src/main/java/com/github/kubernetes/java/client/interfaces/KubernetesAPIClientInterface.java

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,7 @@
2020
*/
2121
package com.github.kubernetes.java.client.interfaces;
2222

23-
import javax.ws.rs.Consumes;
24-
import javax.ws.rs.DELETE;
25-
import javax.ws.rs.GET;
26-
import javax.ws.rs.POST;
27-
import javax.ws.rs.PUT;
28-
import javax.ws.rs.Path;
2923
import javax.ws.rs.PathParam;
30-
import javax.ws.rs.Produces;
31-
import javax.ws.rs.core.MediaType;
3224

3325
import com.github.kubernetes.java.client.exceptions.KubernetesClientException;
3426
import com.github.kubernetes.java.client.model.Label;
@@ -49,41 +41,27 @@ public interface KubernetesAPIClientInterface {
4941
* @return {@link Pod}
5042
* @throws KubernetesClientException
5143
*/
52-
@GET
53-
@Path("/pods/{podId}")
54-
@Consumes(MediaType.APPLICATION_JSON)
55-
@Produces(MediaType.APPLICATION_JSON)
5644
public Pod getPod(@PathParam("podId") String podId) throws KubernetesClientException;
5745

5846
/**
5947
* Get all Pods
6048
* @return Pods
6149
* @throws KubernetesClientException
6250
*/
63-
@GET
64-
@Path("/pods")
65-
@Consumes(MediaType.APPLICATION_JSON)
66-
@Produces(MediaType.APPLICATION_JSON)
6751
public PodList getAllPods() throws KubernetesClientException;
6852

6953
/**
7054
* Create a new Pod
7155
* @param pod Pod to be created
7256
* @throws KubernetesClientException
7357
*/
74-
@POST
75-
@Path("/pods")
76-
@Consumes(MediaType.APPLICATION_JSON)
77-
@Produces(MediaType.APPLICATION_JSON)
7858
public void createPod(Pod pod) throws KubernetesClientException;
7959

8060
/**
8161
* Delete a Pod
8262
* @param podId Id of the Pod to be deleted
8363
* @throws KubernetesClientException
8464
*/
85-
@DELETE
86-
@Consumes(MediaType.APPLICATION_JSON)
8765
public void deletePod(String podId) throws KubernetesClientException;
8866

8967
/* Replication Controller API */
@@ -94,26 +72,20 @@ public interface KubernetesAPIClientInterface {
9472
* @return {@link ReplicationController}
9573
* @throws KubernetesClientException
9674
*/
97-
@GET
98-
@Consumes(MediaType.APPLICATION_JSON)
9975
public ReplicationController getReplicationController(String controllerId) throws KubernetesClientException;
10076

10177
/**
10278
* Get all Replication Controllers.
10379
* @return {@link ReplicationController}s
10480
* @throws KubernetesClientException
10581
*/
106-
@GET
107-
@Consumes(MediaType.APPLICATION_JSON)
10882
public ReplicationControllerList getAllReplicationControllers() throws KubernetesClientException;
10983

11084
/**
11185
* Create a new Replication Controller
11286
* @param controller controller to be created
11387
* @throws KubernetesClientException
11488
*/
115-
@POST
116-
@Consumes(MediaType.APPLICATION_JSON)
11789
public void createReplicationController(ReplicationController controller) throws KubernetesClientException;
11890

11991
/**
@@ -122,17 +94,13 @@ public interface KubernetesAPIClientInterface {
12294
* @param replicas update the replicas count of the current controller.
12395
* @throws KubernetesClientException
12496
*/
125-
@PUT
126-
@Consumes(MediaType.APPLICATION_JSON)
12797
public void updateReplicationController(String controllerId, int replicas) throws KubernetesClientException;
12898

12999
/**
130100
* Delete a Replication Controller.
131101
* @param replication controller id controller id to be deleted.
132102
* @throws KubernetesClientException
133103
*/
134-
@DELETE
135-
@Consumes(MediaType.APPLICATION_JSON)
136104
public void deleteReplicationController(String controllerId) throws KubernetesClientException;
137105

138106
/* Services API */
@@ -143,38 +111,27 @@ public interface KubernetesAPIClientInterface {
143111
* @return {@link Service}
144112
* @throws KubernetesClientException
145113
*/
146-
@GET
147-
@Path("/services/{serviceId}")
148-
@Consumes(MediaType.APPLICATION_JSON)
149114
public Service getService(@PathParam("serviceId") String serviceId) throws KubernetesClientException;
150115

151116
/**
152117
* Get all the services.
153118
* @return array of {@link Service}s
154119
* @throws KubernetesClientException
155120
*/
156-
@GET
157-
@Path("/services")
158-
@Consumes(MediaType.APPLICATION_JSON)
159121
public ServiceList getAllServices() throws KubernetesClientException;
160122

161123
/**
162124
* Create a new Kubernetes service.
163125
* @param service service to be created.
164126
* @throws KubernetesClientException
165127
*/
166-
@POST
167-
@Path("/services")
168-
@Consumes(MediaType.APPLICATION_JSON)
169128
public void createService(Service service) throws KubernetesClientException;
170129

171130
/**
172131
* Delete a Service.
173132
* @param serviceId service id to be deleted.
174133
* @throws KubernetesClientException
175134
*/
176-
@DELETE
177-
@Consumes(MediaType.APPLICATION_JSON)
178135
public void deleteService(String serviceId) throws KubernetesClientException;
179136

180137
/**
@@ -183,8 +140,5 @@ public interface KubernetesAPIClientInterface {
183140
* @return Pods selected Pods by executing the label query.
184141
* @throws KubernetesClientException
185142
*/
186-
@GET
187-
@Path("/pods")
188-
@Consumes(MediaType.APPLICATION_JSON)
189143
public PodList getSelectedPods(Label[] label) throws KubernetesClientException;
190144
}
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
/*
2+
*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
*
20+
*/
21+
package com.github.kubernetes.java.client.v2;
22+
23+
import javax.ws.rs.Consumes;
24+
import javax.ws.rs.DELETE;
25+
import javax.ws.rs.GET;
26+
import javax.ws.rs.POST;
27+
import javax.ws.rs.PUT;
28+
import javax.ws.rs.Path;
29+
import javax.ws.rs.PathParam;
30+
import javax.ws.rs.Produces;
31+
import javax.ws.rs.QueryParam;
32+
import javax.ws.rs.core.MediaType;
33+
34+
import com.github.kubernetes.java.client.exceptions.KubernetesClientException;
35+
import com.github.kubernetes.java.client.model.Label;
36+
import com.github.kubernetes.java.client.model.Pod;
37+
import com.github.kubernetes.java.client.model.PodList;
38+
import com.github.kubernetes.java.client.model.ReplicationController;
39+
import com.github.kubernetes.java.client.model.ReplicationControllerList;
40+
import com.github.kubernetes.java.client.model.Service;
41+
import com.github.kubernetes.java.client.model.ServiceList;
42+
43+
public interface KubernetesAPI {
44+
45+
/* Pod API */
46+
47+
/**
48+
* Get information of a Pod given the PodID
49+
* @param podId id of the pod
50+
* @return {@link Pod}
51+
* @throws KubernetesClientException
52+
*/
53+
@GET
54+
@Path("/pods/{podId}")
55+
@Consumes(MediaType.APPLICATION_JSON)
56+
@Produces(MediaType.APPLICATION_JSON)
57+
public Pod getPod(@PathParam("podId") String podId) throws KubernetesClientException;
58+
59+
/**
60+
* Get all Pods
61+
* @return Pods
62+
* @throws KubernetesClientException
63+
*/
64+
@GET
65+
@Path("/pods")
66+
@Consumes(MediaType.APPLICATION_JSON)
67+
@Produces(MediaType.APPLICATION_JSON)
68+
public PodList getAllPods() throws KubernetesClientException;
69+
70+
/**
71+
* Create a new Pod
72+
* @param pod Pod to be created
73+
* @throws KubernetesClientException
74+
*/
75+
@POST
76+
@Path("/pods")
77+
@Consumes(MediaType.APPLICATION_JSON)
78+
@Produces(MediaType.APPLICATION_JSON)
79+
public void createPod(Pod pod) throws KubernetesClientException;
80+
81+
/**
82+
* Delete a Pod
83+
* @param podId Id of the Pod to be deleted
84+
* @throws KubernetesClientException
85+
*/
86+
@DELETE
87+
@Path("/pods/{podId}")
88+
@Consumes(MediaType.APPLICATION_JSON)
89+
public void deletePod(@PathParam("podId") String podId) throws KubernetesClientException;
90+
91+
/* Replication Controller API */
92+
93+
/**
94+
* Get a Replication Controller Info
95+
* @param controllerId id of the Replication Controller
96+
* @return {@link ReplicationController}
97+
* @throws KubernetesClientException
98+
*/
99+
@GET
100+
@Path("/replicationControllers/{controllerId}")
101+
@Consumes(MediaType.APPLICATION_JSON)
102+
public ReplicationController getReplicationController(@PathParam("controllerId") String controllerId) throws KubernetesClientException;
103+
104+
/**
105+
* Get all Replication Controllers.
106+
* @return {@link ReplicationController}s
107+
* @throws KubernetesClientException
108+
*/
109+
@GET
110+
@Path("/replicationControllers")
111+
@Consumes(MediaType.APPLICATION_JSON)
112+
public ReplicationControllerList getAllReplicationControllers() throws KubernetesClientException;
113+
114+
/**
115+
* Create a new Replication Controller
116+
* @param controller controller to be created
117+
* @throws KubernetesClientException
118+
*/
119+
@POST
120+
@Path("/replicationControllers")
121+
@Consumes(MediaType.APPLICATION_JSON)
122+
public void createReplicationController(ReplicationController controller) throws KubernetesClientException;
123+
124+
/**
125+
* Convenience method to update the number of replicas in a Replication Controller.
126+
* @param controllerId id of the controller to be updated
127+
* @param replicas update the replicas count of the current controller.
128+
* @throws KubernetesClientException
129+
*/
130+
@PUT
131+
@Path("/replicationControllers/{controllerId}")
132+
@Consumes(MediaType.APPLICATION_JSON)
133+
public void updateReplicationController(@PathParam("controllerId") String controllerId, int replicas) throws KubernetesClientException;
134+
135+
/**
136+
* Update a Replication Controller
137+
* @param controllerId id of the controller to be updated
138+
* @param controller controller to update (only the number of replicas can be updated).
139+
* @throws KubernetesClientException
140+
*/
141+
@PUT
142+
@Path("/replicationControllers/{controllerId}")
143+
@Consumes(MediaType.APPLICATION_JSON)
144+
public void updateReplicationController(@PathParam("controllerId") String controllerId, ReplicationController replicationController) throws KubernetesClientException;
145+
146+
/**
147+
* Delete a Replication Controller.
148+
* @param replication controller id controller id to be deleted.
149+
* @throws KubernetesClientException
150+
*/
151+
@DELETE
152+
@Path("/replicationControllers/{controllerId}")
153+
@Consumes(MediaType.APPLICATION_JSON)
154+
public void deleteReplicationController(@PathParam("controllerId") String controllerId) throws KubernetesClientException;
155+
156+
/* Services API */
157+
158+
/**
159+
* Get the Service with the given id.
160+
* @param serviceId id of the service.
161+
* @return {@link Service}
162+
* @throws KubernetesClientException
163+
*/
164+
@GET
165+
@Path("/services/{serviceId}")
166+
@Consumes(MediaType.APPLICATION_JSON)
167+
public Service getService(@PathParam("serviceId") String serviceId) throws KubernetesClientException;
168+
169+
/**
170+
* Get all the services.
171+
* @return array of {@link Service}s
172+
* @throws KubernetesClientException
173+
*/
174+
@GET
175+
@Path("/services")
176+
@Consumes(MediaType.APPLICATION_JSON)
177+
public ServiceList getAllServices() throws KubernetesClientException;
178+
179+
/**
180+
* Create a new Kubernetes service.
181+
* @param service service to be created.
182+
* @throws KubernetesClientException
183+
*/
184+
@POST
185+
@Path("/services")
186+
@Consumes(MediaType.APPLICATION_JSON)
187+
public void createService(Service service) throws KubernetesClientException;
188+
189+
/**
190+
* Delete a Service.
191+
* @param serviceId service id to be deleted.
192+
* @throws KubernetesClientException
193+
*/
194+
@DELETE
195+
@Path("/services/{serviceId}")
196+
@Consumes(MediaType.APPLICATION_JSON)
197+
public void deleteService(@PathParam("serviceId") String serviceId) throws KubernetesClientException;
198+
199+
/**
200+
* Run a label query and retrieve a sub set of Pods.
201+
* @param labels parameter label=label1,label2,label3
202+
* @return Pods selected Pods by executing the label query.
203+
* @throws KubernetesClientException
204+
*/
205+
@GET
206+
@Path("/pods")
207+
@Consumes(MediaType.APPLICATION_JSON)
208+
public PodList getSelectedPods(@QueryParam("labels") String labels) throws KubernetesClientException;
209+
}

0 commit comments

Comments
 (0)