Search in sources :

Example 31 with V1Service

use of io.kubernetes.client.models.V1Service in project weblogic-kubernetes-operator by oracle.

the class ServiceHelperTest method createReadListUpdate.

@Test
public void createReadListUpdate() throws Exception {
    CallBuilderFactory factory = new CallBuilderFactory(null);
    // Domain
    Domain dom = new Domain();
    V1ObjectMeta metadata = new V1ObjectMeta();
    metadata.setResourceVersion("12345");
    metadata.setNamespace("tests");
    dom.setMetadata(metadata);
    DomainSpec spec = new DomainSpec();
    spec.setDomainUID("domain-uid");
    spec.setDomainName("base_domain");
    dom.setSpec(spec);
    // Create a new service.
    System.out.println("Creating service");
    Step s = ServiceHelper.createForServerStep(null);
    Engine e = new Engine("ServiceHelperTest");
    Packet p = new Packet();
    DomainPresenceInfo info = new DomainPresenceInfo(dom);
    p.getComponents().put(ProcessingConstants.DOMAIN_COMPONENT_NAME, Component.createFor(info));
    p.put(ProcessingConstants.SERVER_NAME, "admin");
    p.put(ProcessingConstants.PORT, Integer.valueOf(7001));
    Fiber f = e.createFiber();
    f.start(s, p, null);
    f.get();
    // Read the service we just created.
    System.out.println("Reading service");
    V1Service service = factory.create().readService("domain-uid-admin", "tests");
    checkService(service, false);
    // Get a list of services.
    System.out.println("Listing services");
    V1ServiceList serviceList = factory.create().listService("tests");
    boolean serviceFound = false;
    for (V1Service item : serviceList.getItems()) {
        if (item.getMetadata().getName().equals("domain-uid-admin")) {
            serviceFound = true;
            break;
        }
    }
    Assert.assertTrue("Expected service domain-uid-admin not found in list", serviceFound);
    // Add a second selector to this service.
    Map<String, String> selector = service.getSpec().getSelector();
    selector.put("domain", "domain-uid");
    service.getSpec().setSelector(selector);
// TODO: uncomment out when bug calling replace service is fixed.
// System.out.println("Replacing service");
// service = serviceHelper.replace("domain-uid-admin", service);
// checkService(service, true);
}
Also used : Packet(oracle.kubernetes.operator.work.Packet) V1ServiceList(io.kubernetes.client.models.V1ServiceList) V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) Fiber(oracle.kubernetes.operator.work.Fiber) V1Service(io.kubernetes.client.models.V1Service) CallBuilderFactory(oracle.kubernetes.operator.helpers.CallBuilderFactory) Step(oracle.kubernetes.operator.work.Step) DomainPresenceInfo(oracle.kubernetes.operator.helpers.DomainPresenceInfo) DomainSpec(oracle.kubernetes.weblogic.domain.v1.DomainSpec) Domain(oracle.kubernetes.weblogic.domain.v1.Domain) Engine(oracle.kubernetes.operator.work.Engine) Test(org.junit.Test)

Example 32 with V1Service

use of io.kubernetes.client.models.V1Service in project weblogic-kubernetes-operator by oracle.

the class ServiceWatcherTest method whenServiceHasNoChannelName_returnNull.

@Test
public void whenServiceHasNoChannelName_returnNull() throws Exception {
    V1Service service = new V1Service().metadata(new V1ObjectMeta());
    assertThat(ServiceWatcher.getServiceChannelName(service), nullValue());
}
Also used : V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) V1Service(io.kubernetes.client.models.V1Service) Test(org.junit.Test)

Example 33 with V1Service

use of io.kubernetes.client.models.V1Service in project weblogic-kubernetes-operator by oracle.

the class WatchBuilderTest method whenServiceWatchSpecifiesParameters_verifyAndReturnResponse.

@Test
public void whenServiceWatchSpecifiesParameters_verifyAndReturnResponse() throws Exception {
    String startResourceVersion = getNextResourceVersion();
    V1Service service = new V1Service().apiVersion(API_VERSION).kind("Service").metadata(createMetaData("service3", NAMESPACE));
    defineHttpResponse(SERVICE_RESOURCE, withResponses(createModifiedResponse(service)).andValidations(parameter("resourceVersion").withValue(startResourceVersion), parameter("labelSelector").withValue(DOMAINUID_LABEL + "," + CREATEDBYOPERATOR_LABEL), parameter("watch").withValue("true")));
    WatchI<V1Service> serviceWatch = new WatchBuilder().withResourceVersion(startResourceVersion).withLabelSelector(DOMAINUID_LABEL + "," + CREATEDBYOPERATOR_LABEL).createServiceWatch(NAMESPACE);
    assertThat(serviceWatch, contains(modifyEvent(service)));
}
Also used : V1Service(io.kubernetes.client.models.V1Service) HttpUserAgentTest(com.meterware.pseudoserver.HttpUserAgentTest) Test(org.junit.Test)

Example 34 with V1Service

use of io.kubernetes.client.models.V1Service in project twister2 by DSC-SPIDAL.

the class KubernetesUtils method createServiceObject.

public static V1Service createServiceObject(String serviceName, String serviceLabel, int port, int targetPort) {
    V1Service service = new V1Service();
    service.setKind("Service");
    service.setApiVersion("v1");
    // construct and set metadata
    V1ObjectMeta meta = new V1ObjectMeta();
    meta.setName(serviceName);
    service.setMetadata(meta);
    // construct and set service spec
    V1ServiceSpec serviceSpec = new V1ServiceSpec();
    // ClusterIP needs to be None for headless service
    serviceSpec.setClusterIP("None");
    // set selector
    HashMap<String, String> selectors = new HashMap<String, String>();
    selectors.put("app", serviceLabel);
    serviceSpec.setSelector(selectors);
    ArrayList<V1ServicePort> ports = new ArrayList<V1ServicePort>();
    V1ServicePort servicePort = new V1ServicePort();
    servicePort.setPort(port);
    servicePort.setTargetPort(new IntOrString(targetPort));
    servicePort.setProtocol("TCP");
    ports.add(servicePort);
    serviceSpec.setPorts(ports);
    service.setSpec(serviceSpec);
    return service;
}
Also used : V1ServicePort(io.kubernetes.client.models.V1ServicePort) HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) IntOrString(io.kubernetes.client.custom.IntOrString) V1ServiceSpec(io.kubernetes.client.models.V1ServiceSpec) ArrayList(java.util.ArrayList) V1Service(io.kubernetes.client.models.V1Service) IntOrString(io.kubernetes.client.custom.IntOrString)

Aggregations

V1Service (io.kubernetes.client.models.V1Service)34 Test (org.junit.Test)15 Type (java.lang.reflect.Type)14 V1ObjectMeta (io.kubernetes.client.models.V1ObjectMeta)11 ProgressRequestBody (io.kubernetes.client.ProgressRequestBody)7 ProgressResponseBody (io.kubernetes.client.ProgressResponseBody)7 DomainPresenceInfo (oracle.kubernetes.operator.helpers.DomainPresenceInfo)3 V1ServiceList (io.kubernetes.client.models.V1ServiceList)2 V1ServicePort (io.kubernetes.client.models.V1ServicePort)2 V1ServiceSpec (io.kubernetes.client.models.V1ServiceSpec)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ServerKubernetesObjects (oracle.kubernetes.operator.helpers.ServerKubernetesObjects)2 Engine (oracle.kubernetes.operator.work.Engine)2 Domain (oracle.kubernetes.weblogic.domain.v1.Domain)2 DomainSpec (oracle.kubernetes.weblogic.domain.v1.DomainSpec)2 HttpUserAgentTest (com.meterware.pseudoserver.HttpUserAgentTest)1 ApiException (io.kubernetes.client.ApiException)1 JSON (io.kubernetes.client.JSON)1 IntOrString (io.kubernetes.client.custom.IntOrString)1