Search in sources :

Example 1 with ClusterStartup

use of oracle.kubernetes.weblogic.domain.v1.ClusterStartup in project weblogic-kubernetes-operator by oracle.

the class WlsDomainConfigTest method verifyUpdateDomainSpecNoWarningIfReplicasOK.

@Test
public void verifyUpdateDomainSpecNoWarningIfReplicasOK() throws Exception {
    WlsDomainConfig wlsDomainConfig = WlsDomainConfig.create().load(JSON_STRING_1_CLUSTER);
    DomainSpec domainSpec = new DomainSpec().withClusterStartup(Arrays.asList(new ClusterStartup().withClusterName("DockerCluster"))).withReplicas(5);
    TestUtil.LogHandlerImpl handler = null;
    WlsClusterConfig wlsClusterConfig = wlsDomainConfig.getClusterConfig("DockerCluster");
    try {
        handler = TestUtil.setupLogHandler(wlsClusterConfig);
        wlsDomainConfig.updateDomainSpecAsNeeded(domainSpec);
        assertFalse(handler.hasWarningMessageLogged());
    } finally {
        TestUtil.removeLogHandler(wlsClusterConfig, handler);
    }
}
Also used : DomainSpec(oracle.kubernetes.weblogic.domain.v1.DomainSpec) ClusterStartup(oracle.kubernetes.weblogic.domain.v1.ClusterStartup) Test(org.junit.Test)

Example 2 with ClusterStartup

use of oracle.kubernetes.weblogic.domain.v1.ClusterStartup in project weblogic-kubernetes-operator by oracle.

the class WlsDomainConfigTest method verifyUpdateDomainSpecWarnsIfClusterStatupReplicasTooLarge.

@Test
public void verifyUpdateDomainSpecWarnsIfClusterStatupReplicasTooLarge() throws Exception {
    WlsDomainConfig wlsDomainConfig = WlsDomainConfig.create().load(JSON_STRING_2_CLUSTERS);
    DomainSpec domainSpec = new DomainSpec().withClusterStartup(Arrays.asList(new ClusterStartup().withClusterName("DockerCluster2").withReplicas(3))).withReplicas(5);
    TestUtil.LogHandlerImpl handler = null;
    WlsClusterConfig wlsClusterConfig = wlsDomainConfig.getClusterConfig("DockerCluster2");
    try {
        handler = TestUtil.setupLogHandler(wlsClusterConfig);
        wlsDomainConfig.updateDomainSpecAsNeeded(domainSpec);
        assertTrue("Message logged: " + handler.getAllFormattedMessage(), handler.hasWarningMessageWithSubString("Replicas in clusterStartup for cluster DockerCluster2 is specified with a value of 3 which is larger than the number of configured WLS servers in the cluster: 2"));
    } finally {
        TestUtil.removeLogHandler(wlsClusterConfig, handler);
    }
}
Also used : DomainSpec(oracle.kubernetes.weblogic.domain.v1.DomainSpec) ClusterStartup(oracle.kubernetes.weblogic.domain.v1.ClusterStartup) Test(org.junit.Test)

Example 3 with ClusterStartup

use of oracle.kubernetes.weblogic.domain.v1.ClusterStartup in project weblogic-kubernetes-operator by oracle.

the class WlsDomainConfigTest method verifyUpdateDomainSpecNoWarningIfClusterStatupReplicasOK.

@Test
public void verifyUpdateDomainSpecNoWarningIfClusterStatupReplicasOK() throws Exception {
    WlsDomainConfig wlsDomainConfig = WlsDomainConfig.create().load(JSON_STRING_2_CLUSTERS);
    DomainSpec domainSpec = new DomainSpec().withClusterStartup(Arrays.asList(new ClusterStartup().withClusterName("DockerCluster2").withReplicas(2))).withReplicas(5);
    TestUtil.LogHandlerImpl handler = null;
    WlsClusterConfig wlsClusterConfig = wlsDomainConfig.getClusterConfig("DockerCluster2");
    try {
        handler = TestUtil.setupLogHandler(wlsClusterConfig);
        wlsDomainConfig.updateDomainSpecAsNeeded(domainSpec);
        assertFalse(handler.hasWarningMessageLogged());
    } finally {
        TestUtil.removeLogHandler(wlsClusterConfig, handler);
    }
}
Also used : DomainSpec(oracle.kubernetes.weblogic.domain.v1.DomainSpec) ClusterStartup(oracle.kubernetes.weblogic.domain.v1.ClusterStartup) Test(org.junit.Test)

Example 4 with ClusterStartup

use of oracle.kubernetes.weblogic.domain.v1.ClusterStartup in project weblogic-kubernetes-operator by oracle.

the class WlsDomainConfigTest method verifyUpdateDomainSpecWarnsIfReplicasTooLarge.

@Test
public void verifyUpdateDomainSpecWarnsIfReplicasTooLarge() throws Exception {
    WlsDomainConfig wlsDomainConfig = WlsDomainConfig.create().load(JSON_STRING_1_CLUSTER);
    DomainSpec domainSpec = new DomainSpec().withClusterStartup(Arrays.asList(new ClusterStartup().withClusterName("DockerCluster"))).withReplicas(10);
    TestUtil.LogHandlerImpl handler = null;
    WlsClusterConfig wlsClusterConfig = wlsDomainConfig.getClusterConfig("DockerCluster");
    try {
        handler = TestUtil.setupLogHandler(wlsClusterConfig);
        wlsDomainConfig.updateDomainSpecAsNeeded(domainSpec);
        assertTrue("Message logged: " + handler.getAllFormattedMessage(), handler.hasWarningMessageWithSubString("Replicas in domainSpec for cluster DockerCluster is specified with a value of 10 which is larger than the number of configured WLS servers in the cluster: 5"));
    } finally {
        TestUtil.removeLogHandler(wlsClusterConfig, handler);
    }
}
Also used : DomainSpec(oracle.kubernetes.weblogic.domain.v1.DomainSpec) ClusterStartup(oracle.kubernetes.weblogic.domain.v1.ClusterStartup) Test(org.junit.Test)

Example 5 with ClusterStartup

use of oracle.kubernetes.weblogic.domain.v1.ClusterStartup 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)

Aggregations

ClusterStartup (oracle.kubernetes.weblogic.domain.v1.ClusterStartup)14 Test (org.junit.Test)11 DomainSpec (oracle.kubernetes.weblogic.domain.v1.DomainSpec)9 ApiException (io.kubernetes.client.ApiException)1 V1EnvVar (io.kubernetes.client.models.V1EnvVar)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 CallBuilderFactory (oracle.kubernetes.operator.helpers.CallBuilderFactory)1 ServerStartup (oracle.kubernetes.weblogic.domain.v1.ServerStartup)1