use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.
the class ExampleTest method exactUrlOnly.
@Test
public void exactUrlOnly() throws IOException, ApiException {
ApiClient client = new ApiClient();
client.setBasePath("http://localhost:" + PORT);
Configuration.setDefaultApiClient(client);
V1Namespace ns1 = new V1Namespace().metadata(new V1ObjectMeta().name("name"));
stubFor(get(urlEqualTo("/api/v1/namespaces/name")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(client.getJSON().serialize(ns1))));
CoreV1Api api = new CoreV1Api();
V1Namespace ns2 = api.readNamespace("name", null);
assertEquals(ns1, ns2);
}
use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.
the class ExecTest method testUrl.
@Test
public void testUrl() throws IOException, ApiException, InterruptedException {
Exec exec = new Exec(client);
V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name(podName).namespace(namespace));
Semaphore getCount = new Semaphore(2);
Parameters getParams = new Parameters();
getParams.put("semaphore", getCount);
wireMockRule.stubFor(get(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/exec")).withPostServeAction("semaphore", getParams).willReturn(aResponse().withStatus(404).withHeader("Content-Type", "application/json").withBody("{}")));
Process p = exec.exec(pod, cmd, "container", true, false);
p.waitFor();
exec.newExecutionBuilder(pod.getMetadata().getNamespace(), pod.getMetadata().getName(), cmd).setContainer("container").setStdin(false).setStderr(false).execute().waitFor();
// These will be released for each web call above.
// There is a race between the above waitFor() and the request actually being recorded
// by WireMock. This fixes it.
getCount.acquire(2);
wireMockRule.verify(getRequestedFor(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/exec")).withQueryParam("stdin", equalTo("true")).withQueryParam("stdout", equalTo("true")).withQueryParam("stderr", equalTo("true")).withQueryParam("container", equalTo("container")).withQueryParam("tty", equalTo("false")).withQueryParam("command", equalTo("cmd")));
wireMockRule.verify(getRequestedFor(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/exec")).withQueryParam("stdin", equalTo("false")).withQueryParam("stdout", equalTo("true")).withQueryParam("stderr", equalTo("false")).withQueryParam("container", equalTo("container")).withQueryParam("tty", equalTo("false")).withQueryParam("command", equalTo("cmd")));
assertEquals(-1975219, p.exitValue());
}
use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.
the class ReflectorRunnable method watchHandler.
private void watchHandler(Watchable<ApiType> watch) {
while (watch.hasNext()) {
io.kubernetes.client.util.Watch.Response<ApiType> item = watch.next();
Optional<EventType> eventType = EventType.findByType(item.type);
if (!eventType.isPresent()) {
log.error("unrecognized event {}", item);
continue;
}
if (eventType.get() == EventType.ERROR) {
if (item.status != null && item.status.getCode() == HttpURLConnection.HTTP_GONE) {
log.info("ResourceVersion {} and Watch connection expired: {} , will retry w/o resourceVersion next time", getRelistResourceVersion(), item.status.getMessage());
isLastSyncResourceVersionUnavailable = true;
throw new WatchExpiredException();
} else {
String errorMessage = String.format("got ERROR event and its status: %s", item.status.toString());
log.error(errorMessage);
throw new RuntimeException(errorMessage);
}
}
ApiType obj = item.object;
V1ObjectMeta meta = obj.getMetadata();
String newResourceVersion = meta.getResourceVersion();
switch(eventType.get()) {
case ADDED:
store.add(obj);
break;
case MODIFIED:
store.update(obj);
break;
case DELETED:
store.delete(obj);
break;
case BOOKMARK:
break;
}
lastSyncResourceVersion = newResourceVersion;
if (log.isDebugEnabled()) {
log.debug("{}#Receiving resourceVersion {}", apiTypeClass, lastSyncResourceVersion);
}
}
}
use of io.kubernetes.client.openapi.models.V1ObjectMeta in project twister2 by DSC-SPIDAL.
the class JobMasterRequestObject method createJobMasterHeadlessServiceObject.
/**
* create headless service for job master
*/
public static V1Service createJobMasterHeadlessServiceObject() {
String serviceName = KubernetesUtils.createJobMasterServiceName(jobID);
V1Service service = new V1Service();
service.setKind("Service");
service.setApiVersion("v1");
// set labels for the jm service
HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);
// construct and set metadata
V1ObjectMeta meta = new V1ObjectMeta();
meta.setName(serviceName);
meta.setLabels(labels);
service.setMetadata(meta);
// construct and set service spec
V1ServiceSpec serviceSpec = new V1ServiceSpec();
serviceSpec.setClusterIP("None");
// set selector
HashMap<String, String> selectors = new HashMap<String, String>();
selectors.put("t2-mp", jobID);
serviceSpec.setSelector(selectors);
service.setSpec(serviceSpec);
return service;
}
use of io.kubernetes.client.openapi.models.V1ObjectMeta in project twister2 by DSC-SPIDAL.
the class JobMasterRequestObject method createJobMasterServiceObject.
/**
* create regular service for job master
*/
public static V1Service createJobMasterServiceObject() {
String serviceName = KubernetesUtils.createJobMasterServiceName(jobID);
V1Service service = new V1Service();
service.setKind("Service");
service.setApiVersion("v1");
// set labels for the jm service
HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);
// construct and set metadata
V1ObjectMeta meta = new V1ObjectMeta();
meta.setName(serviceName);
meta.setLabels(labels);
service.setMetadata(meta);
// construct and set service spec
V1ServiceSpec serviceSpec = new V1ServiceSpec();
// set selector
HashMap<String, String> selectors = new HashMap<String, String>();
selectors.put("t2-mp", jobID);
serviceSpec.setSelector(selectors);
// set port
V1ServicePort servicePort = new V1ServicePort();
servicePort.setName("job-master-port");
servicePort.setPort(JobMasterContext.jobMasterPort(config));
servicePort.setTargetPort(new IntOrString(JobMasterContext.jobMasterPort(config)));
servicePort.setProtocol("TCP");
serviceSpec.setPorts(Arrays.asList(servicePort));
service.setSpec(serviceSpec);
return service;
}
Aggregations