|
| 1 | +// Copyright 2019, Oracle Corporation and/or its affiliates. All rights reserved. |
| 2 | +// Licensed under the Universal Permissive License v 1.0 as shown at |
| 3 | +// http://oss.oracle.com/licenses/upl. |
| 4 | + |
| 5 | +package oracle.kubernetes.operator; |
| 6 | + |
| 7 | +import java.util.HashMap; |
| 8 | +import java.util.Map; |
| 9 | + |
| 10 | +import oracle.kubernetes.operator.utils.Domain; |
| 11 | +import oracle.kubernetes.operator.utils.Operator; |
| 12 | +import oracle.kubernetes.operator.utils.TestUtils; |
| 13 | +import org.junit.AfterClass; |
| 14 | +import org.junit.Assert; |
| 15 | +import org.junit.Assume; |
| 16 | +import org.junit.BeforeClass; |
| 17 | +import org.junit.FixMethodOrder; |
| 18 | +import org.junit.Test; |
| 19 | +import org.junit.runners.MethodSorters; |
| 20 | + |
| 21 | +/** |
| 22 | + * This class contains Coherence related integration tests. |
| 23 | + */ |
| 24 | +@FixMethodOrder(MethodSorters.NAME_ASCENDING) |
| 25 | +public class ItCoherenceTests extends BaseTest { |
| 26 | + |
| 27 | + private static Domain domain = null; |
| 28 | + private static Operator operator1 = null; |
| 29 | + |
| 30 | + private static final String PROXY_CLIENT_SCRIPT = "buildRunProxyClient.sh"; |
| 31 | + private static final String PROXY_CLIENT_APP_NAME = "coherence-proxy-client"; |
| 32 | + private static final String PROXY_SERVER_APP_NAME = "coherence-proxy-server"; |
| 33 | + private static final String OP_CACHE_LOAD = "load"; |
| 34 | + private static final String OP_CACHE_VALIDATE = "validate"; |
| 35 | + private static final String PROXY_PORT = "9000"; |
| 36 | + |
| 37 | + /** |
| 38 | + * This method gets called only once before any of the test methods are executed. It does the |
| 39 | + * initialization of the integration test properties defined in OperatorIT.properties and setting |
| 40 | + * the resultRoot, pvRoot and projectRoot attributes. Also, create the operator. |
| 41 | + * |
| 42 | + * @throws Exception exception |
| 43 | + */ |
| 44 | + @BeforeClass |
| 45 | + public static void staticPrepare() throws Exception { |
| 46 | + // initialize test properties and create the directories |
| 47 | + if (!QUICKTEST) { |
| 48 | + initialize(APP_PROPS_FILE); |
| 49 | + operator1 = TestUtils.createOperator(OPERATOR1_YAML); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Releases k8s cluster lease, archives result, pv directories and destroy the operator. |
| 55 | + * |
| 56 | + * @throws Exception exception |
| 57 | + */ |
| 58 | + @AfterClass |
| 59 | + public static void staticUnPrepare() throws Exception { |
| 60 | + if (!QUICKTEST) { |
| 61 | + operator1.destroy(); |
| 62 | + tearDown(new Object() {}.getClass().getEnclosingClass().getSimpleName()); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + public void testRollingRestart() throws Exception { |
| 68 | + Assume.assumeFalse(QUICKTEST); |
| 69 | + |
| 70 | + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); |
| 71 | + logTestBegin(testMethodName); |
| 72 | + |
| 73 | + domain = createDomain(); |
| 74 | + Assert.assertNotNull(domain); |
| 75 | + |
| 76 | + try { |
| 77 | + // Build and run the proxy client on the admin VM to load the cache |
| 78 | + copyAndExecuteProxyClientInPod(OP_CACHE_LOAD); |
| 79 | + |
| 80 | + // Do the rolling restart |
| 81 | + restartDomainByChangingEnvProperty(); |
| 82 | + |
| 83 | + // Build and run the proxy client on the admin VM to validate the cache |
| 84 | + copyAndExecuteProxyClientInPod(OP_CACHE_VALIDATE); |
| 85 | + } finally { |
| 86 | + destroyDomain(); |
| 87 | + } |
| 88 | + logger.info("SUCCESS - " + testMethodName); |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Since the coherence.jar is not open source, we need to build the proxy client on the admin VM, which has the |
| 93 | + * coherence.jar. Copy the shell script file and all coherence app files over to the admin pod. |
| 94 | + * Then run the script to build the proxy client and run the proxy test. |
| 95 | + * |
| 96 | + * @param cacheOp - cache operation |
| 97 | + */ |
| 98 | + private static void copyAndExecuteProxyClientInPod(String cacheOp) { |
| 99 | + try { |
| 100 | + final String adminServerPod = domain.getDomainUid() + "-" + domain.getAdminServerName(); |
| 101 | + |
| 102 | + final String domainNS = domain.getDomainNs(); |
| 103 | + |
| 104 | + // Use the proxy running on Managed Server 1, get the internal POD IP |
| 105 | + final String podName = domain.getManagedSeverPodName(1); |
| 106 | + final String ProxyIP = TestUtils.getPodIP(domainNS, "", podName); |
| 107 | + |
| 108 | + String cohAppLocationOnHost = BaseTest.getAppLocationOnHost() + "/" + PROXY_CLIENT_APP_NAME; |
| 109 | + String cohAppLocationInPod = BaseTest.getAppLocationInPod() + "/" + PROXY_CLIENT_APP_NAME; |
| 110 | + final String cohScriptPathOnHost = cohAppLocationOnHost + "/" + PROXY_CLIENT_SCRIPT; |
| 111 | + final String cohScriptPathInPod = cohAppLocationInPod + "/" + PROXY_CLIENT_SCRIPT; |
| 112 | + final String successMarker = "CACHE-SUCCESS"; |
| 113 | + |
| 114 | + logger.info("Copying files to admin pod for App " + PROXY_CLIENT_APP_NAME); |
| 115 | + |
| 116 | + // Create app dir in the admin pod |
| 117 | + StringBuffer mkdirCmd = new StringBuffer(" -- bash -c 'mkdir -p "); |
| 118 | + mkdirCmd.append(cohAppLocationInPod).append("'"); |
| 119 | + TestUtils.kubectlexec(adminServerPod, domainNS, mkdirCmd.toString()); |
| 120 | + |
| 121 | + // Copy shell script to the pod |
| 122 | + TestUtils.copyFileViaCat(cohScriptPathOnHost, cohScriptPathInPod, adminServerPod, domainNS); |
| 123 | + |
| 124 | + // Copy all App files to the admin pod |
| 125 | + TestUtils.copyAppFilesToPod( |
| 126 | + cohAppLocationOnHost, cohAppLocationInPod, adminServerPod, domainNS); |
| 127 | + |
| 128 | + logger.info( |
| 129 | + "Executing script " |
| 130 | + + PROXY_CLIENT_SCRIPT |
| 131 | + + " for App " |
| 132 | + + PROXY_CLIENT_APP_NAME |
| 133 | + + " in the admin pod"); |
| 134 | + |
| 135 | + // Run the script to on the admin pod (note first arg is app directory is applocation in pod) |
| 136 | + domain.callShellScriptInAdminPod( |
| 137 | + successMarker, cohScriptPathInPod, cohAppLocationInPod, cacheOp, ProxyIP, PROXY_PORT); |
| 138 | + } catch (Exception e) { |
| 139 | + throw new RuntimeException(e); |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + /** |
| 144 | + * Create the domain. |
| 145 | + * |
| 146 | + * @return domain |
| 147 | + * @throws Exception exception |
| 148 | + */ |
| 149 | + private Domain createDomain() throws Exception { |
| 150 | + |
| 151 | + Map<String, String> envMap = new HashMap<>(); |
| 152 | + |
| 153 | + // Set this ENV var with the WDT archive so that it is included in the image build. |
| 154 | + envMap.put("CUSTOM_WDT_ARCHIVE", buildProxyServerWdtZip()); |
| 155 | + |
| 156 | + // create domain |
| 157 | + Map<String, Object> domainMap = TestUtils.loadYaml(DOMAININIMAGE_WDT_YAML); |
| 158 | + domainMap.put("namespace", "test1"); |
| 159 | + domainMap.put("domainUID", "coh"); |
| 160 | + domainMap.put("additionalEnvMap", envMap); |
| 161 | + |
| 162 | + domainMap.put( |
| 163 | + "customWdtTemplate", |
| 164 | + BaseTest.getProjectRoot() |
| 165 | + + "/integration-tests/src/test/resources/wdt/coh-wdt-config.yaml"); |
| 166 | + Domain domain = TestUtils.createDomain(domainMap); |
| 167 | + domain.verifyDomainCreated(); |
| 168 | + return domain; |
| 169 | + } |
| 170 | + |
| 171 | + /** |
| 172 | + * Destroy the domain. |
| 173 | + * |
| 174 | + * @throws Exception exception |
| 175 | + */ |
| 176 | + private static void destroyDomain() throws Exception { |
| 177 | + if (domain != null) { |
| 178 | + domain.destroy(); |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + /** |
| 183 | + * Modify the domain scope env property on the domain resource using kubectl apply -f domain.yaml |
| 184 | + * Verify that all the server pods in the domain got re-started. The property tested is: env: |
| 185 | + * "-Dweblogic.StdoutDebugEnabled=false"--> "-Dweblogic.StdoutDebugEnabled=true" |
| 186 | + * |
| 187 | + * @throws Exception exception |
| 188 | + */ |
| 189 | + private void restartDomainByChangingEnvProperty() throws Exception { |
| 190 | + |
| 191 | + // The default cmd loop sleep is too long and we could miss states like terminating. Change |
| 192 | + // the |
| 193 | + // sleep and iterations |
| 194 | + // |
| 195 | + setWaitTimePod(2); |
| 196 | + setMaxIterationsPod(150); |
| 197 | + |
| 198 | + domain.verifyDomainServerPodRestart( |
| 199 | + "\"-Dweblogic.StdoutDebugEnabled=false\"", "\"-Dweblogic.StdoutDebugEnabled=true\""); |
| 200 | + } |
| 201 | + |
| 202 | + /** |
| 203 | + * Build the WDT zip that contains the Coherence proxy server. |
| 204 | + * |
| 205 | + * @return the WDT zip path |
| 206 | + */ |
| 207 | + private static String buildProxyServerWdtZip() { |
| 208 | + |
| 209 | + // Build the proxy server gar file |
| 210 | + String garPath = getResultDir() + "/coh-proxy-server.gar"; |
| 211 | + String cohAppLocationOnHost = BaseTest.getAppLocationOnHost() + "/" + PROXY_SERVER_APP_NAME; |
| 212 | + TestUtils.buildJarArchive(garPath, cohAppLocationOnHost); |
| 213 | + |
| 214 | + // Build the WDT zip |
| 215 | + String wdtArchivePath = getResultDir() + "/coh-wdt-archive.zip"; |
| 216 | + TestUtils.buildWdtZip(wdtArchivePath, new String[] {garPath}, getResultDir()); |
| 217 | + return wdtArchivePath; |
| 218 | + } |
| 219 | +} |
0 commit comments