Search in sources :

Example 1 with V1ServicePort

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;
}
Also used : V1ServicePort(io.kubernetes.client.openapi.models.V1ServicePort) HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1ServiceSpec(io.kubernetes.client.openapi.models.V1ServiceSpec) ArrayList(java.util.ArrayList) V1Service(io.kubernetes.client.openapi.models.V1Service)

Example 2 with V1ServicePort

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);
    }
}
Also used : V1ServicePort(io.kubernetes.client.openapi.models.V1ServicePort) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with V1ServicePort

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);
    }
}
Also used : V1ServicePort(io.kubernetes.client.openapi.models.V1ServicePort) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with V1ServicePort

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;
}
Also used : V1ServicePort(io.kubernetes.client.openapi.models.V1ServicePort) HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) IntOrString(io.kubernetes.client.custom.IntOrString) V1ServiceSpec(io.kubernetes.client.openapi.models.V1ServiceSpec) V1Service(io.kubernetes.client.openapi.models.V1Service) IntOrString(io.kubernetes.client.custom.IntOrString)

Aggregations

V1ServicePort (io.kubernetes.client.openapi.models.V1ServicePort)4 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)2 V1Service (io.kubernetes.client.openapi.models.V1Service)2 V1ServiceSpec (io.kubernetes.client.openapi.models.V1ServiceSpec)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 IntOrString (io.kubernetes.client.custom.IntOrString)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1