Search in sources :

Example 6 with ClusterStartup

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

the class Main method normalizeDomainSpec.

// -----------------------------------------------------------------------------
// 
// Below this point are methods that are called primarily from watch handlers,
// after watch events are received.
// 
// -----------------------------------------------------------------------------
private static void normalizeDomainSpec(DomainSpec spec) {
    // Normalize DomainSpec so that equals() will work correctly
    String imageName = spec.getImage();
    if (imageName == null || imageName.length() == 0) {
        spec.setImage(imageName = KubernetesConstants.DEFAULT_IMAGE);
    }
    String imagePullPolicy = spec.getImagePullPolicy();
    if (imagePullPolicy == null || imagePullPolicy.length() == 0) {
        spec.setImagePullPolicy(imagePullPolicy = (imageName.endsWith(KubernetesConstants.LATEST_IMAGE_SUFFIX)) ? KubernetesConstants.ALWAYS_IMAGEPULLPOLICY : KubernetesConstants.IFNOTPRESENT_IMAGEPULLPOLICY);
    }
    if (spec.getExportT3Channels() == null) {
        spec.setExportT3Channels(new ArrayList<String>());
    }
    String startupControl = spec.getStartupControl();
    if (startupControl == null || startupControl.length() == 0) {
        spec.setStartupControl(startupControl = StartupControlConstants.AUTO_STARTUPCONTROL);
    }
    if (spec.getServerStartup() == null) {
        spec.setServerStartup(new ArrayList<ServerStartup>());
    } else {
        for (ServerStartup ss : spec.getServerStartup()) {
            if (ss.getDesiredState() == null) {
                ss.setDesiredState(RUNNING_STATE);
            }
            if (ss.getEnv() == null) {
                ss.setEnv(new ArrayList<V1EnvVar>());
            }
        }
    }
    if (spec.getClusterStartup() == null) {
        spec.setClusterStartup(new ArrayList<ClusterStartup>());
    } else {
        for (ClusterStartup cs : spec.getClusterStartup()) {
            if (cs.getDesiredState() == null) {
                cs.setDesiredState(RUNNING_STATE);
            }
            if (cs.getEnv() == null) {
                cs.setEnv(new ArrayList<V1EnvVar>());
            }
            if (cs.getReplicas() == null) {
                cs.setReplicas(1);
            }
        }
    }
    if (spec.getReplicas() == null) {
        spec.setReplicas(1);
    }
}
Also used : ClusterStartup(oracle.kubernetes.weblogic.domain.v1.ClusterStartup) ServerStartup(oracle.kubernetes.weblogic.domain.v1.ServerStartup) V1EnvVar(io.kubernetes.client.models.V1EnvVar)

Example 7 with ClusterStartup

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

the class WlsDomainConfig method updateDomainSpecAsNeeded.

/**
 * Update the provided k8s domain spec to be consistent with the configuration of the WLS domain.
 * The method also logs warning if inconsistent WLS configurations are found that cannot be fixed by updating
 * the provided Domain spec.
 * It is the responsibility of the caller to persist the changes to DomainSpec to kubernetes.
 *
 * @param domainSpec The DomainSpec to be validated against the WLS configuration
 * @return true if the DomainSpec has been updated, false otherwise
 */
public boolean updateDomainSpecAsNeeded(DomainSpec domainSpec) {
    LOGGER.entering();
    boolean updated = false;
    List<ClusterStartup> clusterStartupList = domainSpec.getClusterStartup();
    // check each ClusterStartup if specified in the DomainSpec
    if (clusterStartupList != null) {
        for (ClusterStartup clusterStartup : clusterStartupList) {
            String clusterName = clusterStartup.getClusterName();
            if (clusterName != null) {
                WlsClusterConfig wlsClusterConfig = getClusterConfig(clusterName);
                updated |= wlsClusterConfig.validateClusterStartup(clusterStartup);
            }
        }
    }
    // validate replicas in DomainSpec if spcified
    if (domainSpec.getReplicas() != null) {
        Collection<WlsClusterConfig> clusterConfigs = getClusterConfigs().values();
        // WLS domain contains only one cluster
        if (clusterConfigs != null && clusterConfigs.size() == 1) {
            for (WlsClusterConfig wlsClusterConfig : clusterConfigs) {
                wlsClusterConfig.validateReplicas(domainSpec.getReplicas(), "domainSpec");
            }
        } else {
            // log info message if replicas is specified but number of WLS clusters in domain is not 1
            LOGGER.info(MessageKeys.DOMAIN_REPLICAS_IGNORED);
        }
    }
    LOGGER.exiting(updated);
    return updated;
}
Also used : ClusterStartup(oracle.kubernetes.weblogic.domain.v1.ClusterStartup)

Example 8 with ClusterStartup

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

the class WlsClusterConfigTest method verifyValidateClusterStartupWarnsIfReplicasTooHigh.

@Test
public void verifyValidateClusterStartupWarnsIfReplicasTooHigh() throws Exception {
    WlsClusterConfig wlsClusterConfig = new WlsClusterConfig("cluster1");
    wlsClusterConfig.addServerConfig(createWlsServerConfig("ms-0", 8011, null));
    ClusterStartup cs = new ClusterStartup().withClusterName("cluster1").withReplicas(2);
    TestUtil.LogHandlerImpl handler = null;
    try {
        handler = TestUtil.setupLogHandler(wlsClusterConfig);
        wlsClusterConfig.validateClusterStartup(cs);
        assertTrue("Message logged: " + handler.getAllFormattedMessage(), handler.hasWarningMessageWithSubString("Replicas in clusterStartup for cluster cluster1 is specified with a value of 2 which is larger than the number of configured WLS servers in the cluster: 1"));
    } finally {
        TestUtil.removeLogHandler(wlsClusterConfig, handler);
    }
}
Also used : ClusterStartup(oracle.kubernetes.weblogic.domain.v1.ClusterStartup) Test(org.junit.Test)

Example 9 with ClusterStartup

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

the class WlsClusterConfigTest method verifyValidateClusterStartupWarnsIfNoServersInCluster.

@Test
public void verifyValidateClusterStartupWarnsIfNoServersInCluster() throws Exception {
    WlsClusterConfig wlsClusterConfig = new WlsClusterConfig("cluster1");
    ClusterStartup cs = new ClusterStartup().withClusterName("cluster1").withReplicas(1);
    TestUtil.LogHandlerImpl handler = null;
    try {
        handler = TestUtil.setupLogHandler(wlsClusterConfig);
        wlsClusterConfig.validateClusterStartup(cs);
        assertTrue("Message logged: " + handler.getAllFormattedMessage(), handler.hasWarningMessageWithSubString("No servers configured in WebLogic cluster with name cluster1"));
    } finally {
        TestUtil.removeLogHandler(wlsClusterConfig, handler);
    }
}
Also used : ClusterStartup(oracle.kubernetes.weblogic.domain.v1.ClusterStartup) Test(org.junit.Test)

Example 10 with ClusterStartup

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

the class WlsDomainConfigTest method verifyUpdateDomainSpecWarnsIfNoServersInClusterStartupCluster.

@Test
public void verifyUpdateDomainSpecWarnsIfNoServersInClusterStartupCluster() throws Exception {
    WlsDomainConfig wlsDomainConfig = new WlsDomainConfig();
    DomainSpec domainSpec = new DomainSpec().withClusterStartup(Arrays.asList(new ClusterStartup().withClusterName("noSuchCluster")));
    TestUtil.LogHandlerImpl handler = null;
    WlsClusterConfig wlsClusterConfig = wlsDomainConfig.getClusterConfig("noSuchCluster");
    try {
        handler = TestUtil.setupLogHandler(wlsClusterConfig);
        wlsDomainConfig.updateDomainSpecAsNeeded(domainSpec);
        assertTrue("Message logged: " + handler.getAllFormattedMessage(), handler.hasWarningMessageWithSubString("No servers configured in WebLogic cluster with name noSuchCluster"));
    } 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)

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