Search in sources :

Example 1 with CallBuilderFactory

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

the class RestBackendImpl method updateReplicasForDomain.

private void updateReplicasForDomain(String namespace, Domain domain, String cluster, int managedServerCount) {
    // Capacity of configured cluster is valid for scaling
    // Set replicas value on corresponding ClusterStartup (if defined)
    // or on the Domain level replicas value for cluster not defined in a ClusterStartup
    String domainUID = domain.getSpec().getDomainUID();
    boolean domainModified = false;
    ClusterStartup clusterStartup = getClusterStartup(domain, cluster);
    int currentReplicasCount = clusterStartup != null ? clusterStartup.getReplicas() : domain.getSpec().getReplicas();
    if (managedServerCount != currentReplicasCount) {
        if (clusterStartup != null) {
            // set replica value on corresponding ClusterStartup
            clusterStartup.setReplicas(managedServerCount);
            domainModified = true;
        } else if (StartupControlConstants.AUTO_STARTUPCONTROL.equals(domain.getSpec().getStartupControl())) {
            // set replica on Domain for cluster not defined in ClusterStartup
            domain.getSpec().setReplicas(managedServerCount);
            domainModified = true;
        } else {
            // so scaling will not occur since Domain.spec.Replicas property will be ignored.
            throw createWebApplicationException(Status.BAD_REQUEST, MessageKeys.SCALING_AUTO_CONTROL_AUTO, cluster);
        }
    }
    if (domainModified) {
        try {
            CallBuilderFactory factory = ContainerResolver.getInstance().getContainer().getSPI(CallBuilderFactory.class);
            // Write out the Domain with updated replica values
            // TODO: Can we patch instead of replace?
            factory.create().replaceDomain(domainUID, namespace, domain);
        } catch (ApiException e) {
            LOGGER.finer("Unexpected exception when updating Domain " + domainUID + " in namespace " + namespace, e);
            throw new WebApplicationException(e.getMessage());
        }
    }
}
Also used : ClusterStartup(oracle.kubernetes.weblogic.domain.v1.ClusterStartup) WebApplicationException(javax.ws.rs.WebApplicationException) CallBuilderFactory(oracle.kubernetes.operator.helpers.CallBuilderFactory) ApiException(io.kubernetes.client.ApiException)

Example 2 with CallBuilderFactory

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

the class SecretHelperTest method createSecret.

// Create a named secret with username / password in specified name
private V1Secret createSecret(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);
    Map<String, byte[]> data = new HashMap<String, byte[]>();
    data.put(SecretHelper.ADMIN_SERVER_CREDENTIALS_USERNAME, USERNAME.getBytes());
    data.put(SecretHelper.ADMIN_SERVER_CREDENTIALS_PASSWORD, PASSWORD.getBytes());
    body.setData(data);
    try {
        return factory.create().createSecret(namespace, body);
    } catch (Exception e) {
        e.printStackTrace(System.out);
        throw e;
    }
}
Also used : HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) CallBuilderFactory(oracle.kubernetes.operator.helpers.CallBuilderFactory) V1Secret(io.kubernetes.client.models.V1Secret) ApiException(io.kubernetes.client.ApiException) ApiException(io.kubernetes.client.ApiException)

Example 3 with CallBuilderFactory

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

the class SecretHelperTest 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 4 with CallBuilderFactory

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

the class SecretHelperTest method setUp.

@Before
public void setUp() throws Exception {
    CallBuilderFactory factory = new CallBuilderFactory(null);
    // Determine if 1.8 since some bugs with kubernetes-client / java and secrets
    VersionInfo verInfo = factory.create().readVersionCode();
    if ("1".equals(verInfo.getMajor()) && "8".equals(verInfo.getMinor())) {
        isVersion18 = true;
    }
    createNamespace(UNIT_NAMESPACE);
    createSecret(SECRET_NAME, UNIT_NAMESPACE);
    createInvalidSecret(INVALID_SECRET_NAME, UNIT_NAMESPACE);
    createSecret(SECRET_NAME, "default");
    defaultSecretHelper = new SecretHelper("default");
    unitSecretHelper = new SecretHelper(UNIT_NAMESPACE);
}
Also used : VersionInfo(io.kubernetes.client.models.VersionInfo) SecretHelper(oracle.kubernetes.operator.helpers.SecretHelper) CallBuilderFactory(oracle.kubernetes.operator.helpers.CallBuilderFactory) Before(org.junit.Before)

Example 5 with CallBuilderFactory

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

the class ServiceHelperTest method tearDown.

@After
public void tearDown() throws Exception {
    CallBuilderFactory factory = new CallBuilderFactory(null);
    // Delete the service if we created one.
    if (serviceCreated) {
        System.out.println("Deleting service post-test");
        factory.create().deleteService("domain-uid-admin", "tests");
        serviceCreated = false;
    }
}
Also used : CallBuilderFactory(oracle.kubernetes.operator.helpers.CallBuilderFactory) After(org.junit.After)

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