new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItIstioCrossDomainTransaction.java
@Test
  @DisplayName("Check cross domain transaction with istio works")
  public void testIstioCrossDomainTransaction() {

    //build application archive
    Path distDir = BuildApplication.buildApplication(Paths.get(APP_DIR, "txforward"), null, null,
        "build", domain1Namespace);
    logger.info("distDir is {0}", distDir.toString());
    assertTrue(Paths.get(distDir.toString(),
        "txforward.ear").toFile().exists(),
        "Application archive is not available");
    String appSource = distDir.toString() + "/txforward.ear";
    logger.info("Application is in {0}", appSource);

    // create admin credential secret for domain1
    logger.info("Create admin credential secret for domain1");
    String domain1AdminSecretName = domainUid1 + "-weblogic-credentials";
    assertDoesNotThrow(() -> createSecretWithUsernamePassword(
        domain1AdminSecretName, domain1Namespace, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT),
        String.format("createSecret %s failed for %s", domain1AdminSecretName, domainUid1));

    // create admin credential secret for domain2
    logger.info("Create admin credential secret for domain2");
    String domain2AdminSecretName = domainUid2 + "-weblogic-credentials";
    assertDoesNotThrow(() -> createSecretWithUsernamePassword(
        domain2AdminSecretName, domain2Namespace, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT),
        String.format("createSecret %s failed for %s", domain2AdminSecretName, domainUid2));
 
    logger.info("Creating image with model file and verify");
    String domain1Image = createImageAndVerify(
        WDT_IMAGE_NAME1, WDT_MODEL_FILE_DOMAIN1, appSource, WDT_MODEL_DOMAIN1_PROPS, PROPS_TEMP_DIR, domainUid1);
    logger.info("Created {0} image", domain1Image);

    // docker login and push image to docker registry if necessary
    dockerLoginAndPushImageToRegistry(domain1Image);

    logger.info("Creating image with model file and verify");
    String domain2Image = createImageAndVerify(
        WDT_IMAGE_NAME2, WDT_MODEL_FILE_DOMAIN2, appSource, WDT_MODEL_DOMAIN2_PROPS, PROPS_TEMP_DIR, domainUid2);
    logger.info("Created {0} image", domain2Image);

    // docker login and push image to docker registry if necessary
    dockerLoginAndPushImageToRegistry(domain2Image);

    //create domain1
    createDomain(domainUid1, domain1Namespace, domain1AdminSecretName, domain1Image);
    //create domain2
    createDomain(domainUid2, domain2Namespace, domain2AdminSecretName, domain2Image);

    String clusterService = domainUid1 + "-cluster-" + clusterName + "." + domain1Namespace + ".svc.cluster.local";

    Map<String, String> templateMap  = new HashMap();
    templateMap.put("NAMESPACE", domain1Namespace);
    templateMap.put("ADMIN_SERVICE",domain1AdminServerPodName);
    templateMap.put("CLUSTER_SERVICE", clusterService);

    Path svcYamlSrc = Paths.get(RESOURCE_DIR, "istio", "istio-cdt-http-template-service.yaml");
    Path svcYmlTarget = assertDoesNotThrow(
        () -> generateFileFromTemplate(svcYamlSrc.toString(),
            "istiocrossdomaintransactiontemp/istio-cdt-http-service.yaml", templateMap));
    logger.info("Generated Http VS/Gateway file path is {0}", svcYmlTarget);

    boolean deployRes = deployHttpIstioGatewayAndVirtualservice(svcYmlTarget);
    assertTrue(deployRes, "Could not deploy Http Istio Gateway/VirtualService");

    int istioIngressPort = getIstioHttpIngressPort();
    logger.info("Istio Ingress Port is {0}", istioIngressPort);

    logger.info("Validating WebLogic admin server access by login to console");

    String consoleUrl = "http://" + K8S_NODEPORT_HOST + ":" + istioIngressPort + "/console/login/LoginForm.jsp";
    boolean checkConsole =
        checkAppUsingHostHeader(consoleUrl, "domain1-" + domain1Namespace + ".org");
    assertTrue(checkConsole, "Failed to access WebLogic console on domain1");
    logger.info("WebLogic console on domain1 is accessible");

    //+ "-H 'host:domain1-" + domain1Namespace + ".org' "
    String curlRequest = String.format("curl -v --show-error --noproxy '*' "
            + "-H 'host:domain1-" + domain1Namespace + ".org' "
            + "http://%s:%s/TxForward/TxForward?urls=t3://%s.%s:7001,t3://%s1.%s:8001,t3://%s1.%s:8001,t3://%s2.%s:8001",
        K8S_NODEPORT_HOST, istioIngressPort, domain1AdminServerPodName, domain1Namespace,
        domain1ManagedServerPrefix, domain1Namespace, domain2ManagedServerPrefix,domain2Namespace,
        domain2ManagedServerPrefix, domain2Namespace);

    ExecResult result = null;
    logger.info("curl command {0}", curlRequest);
    result = assertDoesNotThrow(
        () -> exec(curlRequest, true));
    logger.info("curl result {0}", result.exitValue());
    assertTrue((result.exitValue() == 0), "curl command failed");
    if (result.exitValue() == 0) {
      logger.info("\n HTTP response is \n " + result.stdout());
      logger.info("curl command returned {0}", result.toString());
      assertTrue(result.stdout().contains("Status=Committed"), "crossDomainTransaction failed");
    }

  }
/*
   * This test verifies cross domain transaction is successful. domain in image using wdt is used
   * to create 2 domains in different namespaces. An app is deployed to both the domains and the servlet
   * is invoked which starts a transaction that spans both domains.
   * The application consists of a servlet front-end and a remote object that defines a method to register
   * a simple javax.transaction.Synchronization object. When the servlet is invoked, a global transaction
   * is started, and the specified list of server URLs is used to look up the remote object and register
   * a Synchronization object on each server.  Finally, the transaction is committed.  If the server
   * listen-addresses are resolvable between the transaction participants, then the transaction should
   * complete successfully.
   */
This test verifies cross domain transaction is successful. domain in image using wdt is used
to create 2 domains in different namespaces. An app is deployed to both the domains and the servlet
is invoked which starts a transaction that spans both domains.
The application consists of a servlet front-end and a remote object that defines a method to register
a simple javax.transaction.Synchronization object. When the servlet is invoked, a global transaction
is started, and the specified list of server URLs is used to look up the remote object and register
a Synchronization object on each server.  Finally, the transaction is committed.  If the server
listen-addresses are resolvable between the transaction participants, then the transaction should
complete successfully.
This test verifies cross domain transaction is successful . domain in image using wdt is used to create 2 domains in different namespaces . An app is deployed to both the domains and the servlet is invoked which starts a transaction that spans both domains . The application consists of a servlet front - end and a remote object that defines a method to register a simple javax . transaction . Synchronization object . When the servlet is invoked a global transaction is started and the specified list of server URLs is used to look up the remote object and register a Synchronization object on each server . Finally the transaction is committed . If the server listen - addresses are resolvable between the transaction participants then the transaction should complete successfully .
@Test
  @DisplayName("Check cross domain transaction with istio works")
  public void testIstioCrossDomainTransaction() {
    Path distDir = BuildApplication.buildApplication(Paths.get(APP_DIR, "txforward"), null, null,
        "build", domain1Namespace);
    logger.info("distDir is {0}", distDir.toString());
    assertTrue(Paths.get(distDir.toString(),
        "txforward.ear").toFile().exists(),
        "Application archive is not available");
    String appSource = distDir.toString() + "/txforward.ear";
    logger.info("Application is in {0}", appSource);
    logger.info("Create admin credential secret for domain1");
    String domain1AdminSecretName = domainUid1 + "-weblogic-credentials";
    assertDoesNotThrow(() -> createSecretWithUsernamePassword(
        domain1AdminSecretName, domain1Namespace, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT),
        String.format("createSecret %s failed for %s", domain1AdminSecretName, domainUid1));
    logger.info("Create admin credential secret for domain2");
    String domain2AdminSecretName = domainUid2 + "-weblogic-credentials";
    assertDoesNotThrow(() -> createSecretWithUsernamePassword(
        domain2AdminSecretName, domain2Namespace, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT),
        String.format("createSecret %s failed for %s", domain2AdminSecretName, domainUid2));
    logger.info("Creating image with model file and verify");
    String domain1Image = createImageAndVerify(
        WDT_IMAGE_NAME1, WDT_MODEL_FILE_DOMAIN1, appSource, WDT_MODEL_DOMAIN1_PROPS, PROPS_TEMP_DIR, domainUid1);
    logger.info("Created {0} image", domain1Image);
    dockerLoginAndPushImageToRegistry(domain1Image);
    logger.info("Creating image with model file and verify");
    String domain2Image = createImageAndVerify(
        WDT_IMAGE_NAME2, WDT_MODEL_FILE_DOMAIN2, appSource, WDT_MODEL_DOMAIN2_PROPS, PROPS_TEMP_DIR, domainUid2);
    logger.info("Created {0} image", domain2Image);
    dockerLoginAndPushImageToRegistry(domain2Image);
    createDomain(domainUid1, domain1Namespace, domain1AdminSecretName, domain1Image);
    createDomain(domainUid2, domain2Namespace, domain2AdminSecretName, domain2Image);
    String clusterService = domainUid1 + "-cluster-" + clusterName + "." + domain1Namespace + ".svc.cluster.local";
    Map<String, String> templateMap  = new HashMap();
    templateMap.put("NAMESPACE", domain1Namespace);
    templateMap.put("ADMIN_SERVICE",domain1AdminServerPodName);
    templateMap.put("CLUSTER_SERVICE", clusterService);
    Path svcYamlSrc = Paths.get(RESOURCE_DIR, "istio", "istio-cdt-http-template-service.yaml");
    Path svcYmlTarget = assertDoesNotThrow(
        () -> generateFileFromTemplate(svcYamlSrc.toString(),
            "istiocrossdomaintransactiontemp/istio-cdt-http-service.yaml", templateMap));
    logger.info("Generated Http VS/Gateway file path is {0}", svcYmlTarget);
    boolean deployRes = deployHttpIstioGatewayAndVirtualservice(svcYmlTarget);
    assertTrue(deployRes, "Could not deploy Http Istio Gateway/VirtualService");
    int istioIngressPort = getIstioHttpIngressPort();
    logger.info("Istio Ingress Port is {0}", istioIngressPort);
    logger.info("Validating WebLogic admin server access by login to console");
    String consoleUrl = "http://" + K8S_NODEPORT_HOST + ":" + istioIngressPort + "/console/login/LoginForm.jsp";
    boolean checkConsole =
        checkAppUsingHostHeader(consoleUrl, "domain1-" + domain1Namespace + ".org");
    assertTrue(checkConsole, "Failed to access WebLogic console on domain1");
    logger.info("WebLogic console on domain1 is accessible");
    String curlRequest = String.format("curl -v --show-error --noproxy '*' "
            + "-H 'host:domain1-" + domain1Namespace + ".org' "
            + "http://%s:%s/TxForward/TxForward?urls=t3://%s.%s:7001,t3://%s1.%s:8001,t3://%s1.%s:8001,t3://%s2.%s:8001",
        K8S_NODEPORT_HOST, istioIngressPort, domain1AdminServerPodName, domain1Namespace,
        domain1ManagedServerPrefix, domain1Namespace, domain2ManagedServerPrefix,domain2Namespace,
        domain2ManagedServerPrefix, domain2Namespace);
    ExecResult result = null;
    logger.info("curl command {0}", curlRequest);
    result = assertDoesNotThrow(
        () -> exec(curlRequest, true));
    logger.info("curl result {0}", result.exitValue());
    assertTrue((result.exitValue() == 0), "curl command failed");
    if (result.exitValue() == 0) {
      logger.info("\n HTTP response is \n " + result.stdout());
      logger.info("curl command returned {0}", result.toString());
      assertTrue(result.stdout().contains("Status=Committed"), "crossDomainTransaction failed");
    }
  }
@ Test @ DisplayName ( "Check cross domain transaction with istio works" ) public void testIstioCrossDomainTransaction ( ) { Path distDir = BuildApplication . buildApplication ( Paths . get ( APP_DIR , "txforward" ) , null , null , "build" , domain1Namespace ) ; logger . info ( "distDir is {0}" , distDir . toString ( ) ) ; assertTrue ( Paths . get ( distDir . toString ( ) , "txforward.ear" ) . toFile ( ) . exists ( ) , "Application archive is not available" ) ; String appSource = distDir . toString ( ) + "/txforward.ear" ; logger . info ( "Application is in {0}" , appSource ) ; logger . info ( "Create admin credential secret for domain1" ) ; String domain1AdminSecretName = domainUid1 + "-weblogic-credentials" ; assertDoesNotThrow ( ( ) -> createSecretWithUsernamePassword ( domain1AdminSecretName , domain1Namespace , ADMIN_USERNAME_DEFAULT , ADMIN_PASSWORD_DEFAULT ) , String . format ( "createSecret %s failed for %s" , domain1AdminSecretName , domainUid1 ) ) ; logger . info ( "Create admin credential secret for domain2" ) ; String domain2AdminSecretName = domainUid2 + "-weblogic-credentials" ; assertDoesNotThrow ( ( ) -> createSecretWithUsernamePassword ( domain2AdminSecretName , domain2Namespace , ADMIN_USERNAME_DEFAULT , ADMIN_PASSWORD_DEFAULT ) , String . format ( "createSecret %s failed for %s" , domain2AdminSecretName , domainUid2 ) ) ; logger . info ( "Creating image with model file and verify" ) ; String domain1Image = createImageAndVerify ( WDT_IMAGE_NAME1 , WDT_MODEL_FILE_DOMAIN1 , appSource , WDT_MODEL_DOMAIN1_PROPS , PROPS_TEMP_DIR , domainUid1 ) ; logger . info ( "Created {0} image" , domain1Image ) ; dockerLoginAndPushImageToRegistry ( domain1Image ) ; logger . info ( "Creating image with model file and verify" ) ; String domain2Image = createImageAndVerify ( WDT_IMAGE_NAME2 , WDT_MODEL_FILE_DOMAIN2 , appSource , WDT_MODEL_DOMAIN2_PROPS , PROPS_TEMP_DIR , domainUid2 ) ; logger . info ( "Created {0} image" , domain2Image ) ; dockerLoginAndPushImageToRegistry ( domain2Image ) ; createDomain ( domainUid1 , domain1Namespace , domain1AdminSecretName , domain1Image ) ; createDomain ( domainUid2 , domain2Namespace , domain2AdminSecretName , domain2Image ) ; String clusterService = domainUid1 + "-cluster-" + clusterName + "." + domain1Namespace + ".svc.cluster.local" ; Map < String , String > templateMap = new HashMap ( ) ; templateMap . put ( "NAMESPACE" , domain1Namespace ) ; templateMap . put ( "ADMIN_SERVICE" , domain1AdminServerPodName ) ; templateMap . put ( "CLUSTER_SERVICE" , clusterService ) ; Path svcYamlSrc = Paths . get ( RESOURCE_DIR , "istio" , "istio-cdt-http-template-service.yaml" ) ; Path svcYmlTarget = assertDoesNotThrow ( ( ) -> generateFileFromTemplate ( svcYamlSrc . toString ( ) , "istiocrossdomaintransactiontemp/istio-cdt-http-service.yaml" , templateMap ) ) ; logger . info ( "Generated Http VS/Gateway file path is {0}" , svcYmlTarget ) ; boolean deployRes = deployHttpIstioGatewayAndVirtualservice ( svcYmlTarget ) ; assertTrue ( deployRes , "Could not deploy Http Istio Gateway/VirtualService" ) ; int istioIngressPort = getIstioHttpIngressPort ( ) ; logger . info ( "Istio Ingress Port is {0}" , istioIngressPort ) ; logger . info ( "Validating WebLogic admin server access by login to console" ) ; String consoleUrl = "http://" + K8S_NODEPORT_HOST + ":" + istioIngressPort + "/console/login/LoginForm.jsp" ; boolean checkConsole = checkAppUsingHostHeader ( consoleUrl , "domain1-" + domain1Namespace + ".org" ) ; assertTrue ( checkConsole , "Failed to access WebLogic console on domain1" ) ; logger . info ( "WebLogic console on domain1 is accessible" ) ; String curlRequest = String . format ( "curl -v --show-error --noproxy '*' " + "-H 'host:domain1-" + domain1Namespace + ".org' " + "http://%s:%s/TxForward/TxForward?urls=t3://%s.%s:7001,t3://%s1.%s:8001,t3://%s1.%s:8001,t3://%s2.%s:8001" , K8S_NODEPORT_HOST , istioIngressPort , domain1AdminServerPodName , domain1Namespace , domain1ManagedServerPrefix , domain1Namespace , domain2ManagedServerPrefix , domain2Namespace , domain2ManagedServerPrefix , domain2Namespace ) ; ExecResult result = null ; logger . info ( "curl command {0}" , curlRequest ) ; result = assertDoesNotThrow ( ( ) -> exec ( curlRequest , true ) ) ; logger . info ( "curl result {0}" , result . exitValue ( ) ) ; assertTrue ( ( result . exitValue ( ) == 0 ) , "curl command failed" ) ; if ( result . exitValue ( ) == 0 ) { logger . info ( "\n HTTP response is \n " + result . stdout ( ) ) ; logger . info ( "curl command returned {0}" , result . toString ( ) ) ; assertTrue ( result . stdout ( ) . contains ( "Status=Committed" ) , "crossDomainTransaction failed" ) ; } }
This test verifies cross domain transaction is successful.
This test verifies cross domain transaction is successful .
//build application archive // create admin credential secret for domain1 // create admin credential secret for domain2 // docker login and push image to docker registry if necessary // docker login and push image to docker registry if necessary //create domain1 //create domain2 //+ "-H 'host:domain1-" + domain1Namespace + ".org' "