Search in sources :

Example 6 with CallBuilderFactory

use of oracle.kubernetes.operator.helpers.CallBuilderFactory in project weblogic-kubernetes-operator by oracle.

the class DomainStatusUpdater method doDomainUpdate.

private static NextAction doDomainUpdate(Domain dom, DomainPresenceInfo info, Packet packet, Step conflictStep, Step next) {
    V1ObjectMeta meta = dom.getMetadata();
    NextAction na = new NextAction();
    CallBuilderFactory factory = ContainerResolver.getInstance().getContainer().getSPI(CallBuilderFactory.class);
    na.invoke(factory.create().replaceDomainAsync(meta.getName(), meta.getNamespace(), dom, new ResponseStep<Domain>(next) {

        @Override
        public NextAction onFailure(Packet packet, ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
            if (statusCode == CallBuilder.NOT_FOUND) {
                // Just ignore update
                return doNext(packet);
            }
            return super.onFailure(conflictStep, packet, e, statusCode, responseHeaders);
        }

        @Override
        public NextAction onSuccess(Packet packet, Domain result, int statusCode, Map<String, List<String>> responseHeaders) {
            info.setDomain(result);
            return doNext(packet);
        }
    }), packet);
    return na;
}
Also used : Packet(oracle.kubernetes.operator.work.Packet) V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) CallBuilderFactory(oracle.kubernetes.operator.helpers.CallBuilderFactory) Domain(oracle.kubernetes.weblogic.domain.v1.Domain) NextAction(oracle.kubernetes.operator.work.NextAction) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) TreeMap(java.util.TreeMap) ResponseStep(oracle.kubernetes.operator.helpers.ResponseStep) ApiException(io.kubernetes.client.ApiException)

Example 7 with CallBuilderFactory

use of oracle.kubernetes.operator.helpers.CallBuilderFactory in project weblogic-kubernetes-operator by oracle.

the class RestBackendImpl method getDomainsList.

private List<Domain> getDomainsList() {
    CallBuilderFactory factory = ContainerResolver.getInstance().getContainer().getSPI(CallBuilderFactory.class);
    Collection<List<Domain>> c = new ArrayList<List<Domain>>();
    try {
        for (String ns : targetNamespaces) {
            DomainList dl = factory.create().listDomain(ns);
            if (dl != null) {
                c.add(dl.getItems());
            }
        }
        return c.stream().flatMap(Collection::stream).collect(Collectors.toList());
    } catch (ApiException e) {
        throw handleApiException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) CallBuilderFactory(oracle.kubernetes.operator.helpers.CallBuilderFactory) DomainList(oracle.kubernetes.weblogic.domain.v1.DomainList) ArrayList(java.util.ArrayList) List(java.util.List) DomainList(oracle.kubernetes.weblogic.domain.v1.DomainList) Domain(oracle.kubernetes.weblogic.domain.v1.Domain) ApiException(io.kubernetes.client.ApiException)

Example 8 with CallBuilderFactory

use of oracle.kubernetes.operator.helpers.CallBuilderFactory in project weblogic-kubernetes-operator by oracle.

the class HealthCheckHelperTest method createNamespace.

// Create a named namespace
private V1Namespace createNamespace(String name) throws Exception {
    CallBuilderFactory factory = new CallBuilderFactory(null);
    try {
        V1Namespace existing = factory.create().readNamespace(name);
        if (existing != null)
            return existing;
    } catch (ApiException ignore) {
    // Just ignore and try to create it
    }
    V1Namespace body = new V1Namespace();
    // Set the required api version and kind of resource
    body.setApiVersion("v1");
    body.setKind("Namespace");
    // Setup the standard object metadata
    V1ObjectMeta meta = new V1ObjectMeta();
    meta.setName(name);
    body.setMetadata(meta);
    return factory.create().createNamespace(body);
}
Also used : V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) V1Namespace(io.kubernetes.client.models.V1Namespace) CallBuilderFactory(oracle.kubernetes.operator.helpers.CallBuilderFactory) ApiException(io.kubernetes.client.ApiException)

Example 9 with CallBuilderFactory

use of oracle.kubernetes.operator.helpers.CallBuilderFactory in project weblogic-kubernetes-operator by oracle.

the class SecretHelperTest method createInvalidSecret.

// Create a named secret with no username / password in specified namespace
private V1Secret createInvalidSecret(String name, String namespace) throws Exception {
    CallBuilderFactory factory = new CallBuilderFactory(null);
    try {
        V1Secret existing = factory.create().readSecret(name, namespace);
        if (existing != null)
            return existing;
    } catch (ApiException ignore) {
    // Just ignore and try to create it
    }
    if (isVersion18)
        return null;
    V1Secret body = new V1Secret();
    // Set the required api version and kind of resource
    body.setApiVersion("v1");
    body.setKind("Secret");
    // Setup the standard object metadata
    V1ObjectMeta meta = new V1ObjectMeta();
    meta.setName(name);
    meta.setNamespace(namespace);
    body.setMetadata(meta);
    return factory.create().createSecret(namespace, body);
}
Also used : V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) CallBuilderFactory(oracle.kubernetes.operator.helpers.CallBuilderFactory) V1Secret(io.kubernetes.client.models.V1Secret) ApiException(io.kubernetes.client.ApiException)

Example 10 with CallBuilderFactory

use of oracle.kubernetes.operator.helpers.CallBuilderFactory 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)

Aggregations

CallBuilderFactory (oracle.kubernetes.operator.helpers.CallBuilderFactory)11 ApiException (io.kubernetes.client.ApiException)8 V1ObjectMeta (io.kubernetes.client.models.V1ObjectMeta)6 Domain (oracle.kubernetes.weblogic.domain.v1.Domain)3 V1Namespace (io.kubernetes.client.models.V1Namespace)2 V1Secret (io.kubernetes.client.models.V1Secret)2 Packet (oracle.kubernetes.operator.work.Packet)2 Before (org.junit.Before)2 V1Service (io.kubernetes.client.models.V1Service)1 V1ServiceList (io.kubernetes.client.models.V1ServiceList)1 VersionInfo (io.kubernetes.client.models.VersionInfo)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 DomainPresenceInfo (oracle.kubernetes.operator.helpers.DomainPresenceInfo)1 ResponseStep (oracle.kubernetes.operator.helpers.ResponseStep)1