use of io.kubernetes.client.openapi.models.V1ServicePort in project twister2 by DSC-SPIDAL.
the class RequestObjectBuilder method createNodePortServiceObject.
/**
* create service for NodePort
* @return
*/
public static V1Service createNodePortServiceObject() {
String serviceName = KubernetesUtils.createServiceName(jobID);
int workerPort = KubernetesContext.workerBasePort(config);
int nodePort = KubernetesContext.serviceNodePort(config);
String protocol = KubernetesContext.workerTransportProtocol(config);
V1Service service = new V1Service();
service.setKind("Service");
service.setApiVersion("v1");
// set labels for the worker services
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();
// ClusterIP needs to be None for headless service
serviceSpec.setType("NodePort");
// set selector
HashMap<String, String> selectors = new HashMap<String, String>();
selectors.put("t2-wp", jobID);
serviceSpec.setSelector(selectors);
ArrayList<V1ServicePort> ports = new ArrayList<V1ServicePort>();
V1ServicePort servicePort = new V1ServicePort();
servicePort.setPort(workerPort);
servicePort.setProtocol(protocol);
// servicePort.setTargetPort(new IntOrString("port11"));
if (nodePort != 0) {
servicePort.nodePort(nodePort);
}
ports.add(servicePort);
serviceSpec.setPorts(ports);
service.setSpec(serviceSpec);
return service;
}
use of io.kubernetes.client.openapi.models.V1ServicePort in project java by kubernetes-client.
the class YamlTest method testLoadIntOrString.
@Test
public void testLoadIntOrString() {
try {
String strInput = "targetPort: test";
String intInput = "targetPort: 1";
V1ServicePort stringPort = Yaml.loadAs(strInput, V1ServicePort.class);
V1ServicePort intPort = Yaml.loadAs(intInput, V1ServicePort.class);
assertFalse("Target port for 'stringPort' was parsed to an integer, string expected.", stringPort.getTargetPort().isInteger());
assertEquals("test", stringPort.getTargetPort().getStrValue());
assertTrue("Target port for 'intPort' was parsed to a string, integer expected.", intPort.getTargetPort().isInteger());
assertEquals(1L, (long) intPort.getTargetPort().getIntValue());
} catch (Exception ex) {
assertNull("Unexpected exception: " + ex.toString(), ex);
}
}
use of io.kubernetes.client.openapi.models.V1ServicePort in project java by kubernetes-client.
the class YamlTest method testDumpIntOrString.
@Test
public void testDumpIntOrString() {
try {
String strInput = "targetPort: test\n";
String intInput = "targetPort: 1\n";
V1ServicePort stringPort = Yaml.loadAs(strInput, V1ServicePort.class);
V1ServicePort intPort = Yaml.loadAs(intInput, V1ServicePort.class);
StringWriter strOutput = new StringWriter();
Yaml.dump(stringPort, strOutput);
StringWriter intOutput = new StringWriter();
Yaml.dump(intPort, intOutput);
assertEquals(strInput, strOutput.toString());
assertEquals(intInput, intOutput.toString());
} catch (Exception ex) {
assertNull("Unexpected exception: " + ex.toString(), ex);
}
}
use of io.kubernetes.client.openapi.models.V1ServicePort 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