new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItJrfDomainInPV.java
@Test
  @DisplayName("Create JRF domain in PV using WLST script")
  public void testJrfDomainInPvUsingWlst() {
    final String clusterName = "cluster-jrfdomain-inpv";
    final String adminServerName = "wlst-admin-server";
    final String adminServerPodName = domainUid + "-" + adminServerName;
    final String managedServerNameBase = "wlst-ms-";
    final int managedServerPort = 8001;
    final String managedServerPodNamePrefix = domainUid + "-" + managedServerNameBase;
    final int replicaCount = 2;
    final int t3ChannelPort = getNextFreePort(30000, 32767);

    final String pvName = domainUid + "-pv";
    final String pvcName = domainUid + "-pvc";

    // create pull secrets for jrfDomainNamespace when running in non Kind Kubernetes cluster
    if (isUseSecret) {
      createDockerRegistrySecret(OCR_USERNAME, OCR_PASSWORD,
          OCR_EMAIL, OCR_REGISTRY, OCR_SECRET_NAME, jrfDomainNamespace);
    }

    // create JRF domain credential secret
    createSecretWithUsernamePassword(wlSecretName, jrfDomainNamespace,
        ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT);

    // create RCU credential secret
    CommonTestUtils.createRcuSecretWithUsernamePassword(rcuSecretName, jrfDomainNamespace,
        RCUSCHEMAUSERNAME, RCUSCHEMAPASSWORD, RCUSYSUSERNAME, RCUSYSPASSWORD);

    // create persistent volume and persistent volume claim for domain
    CommonTestUtils.createPV(pvName, domainUid, this.getClass().getSimpleName());
    CommonTestUtils.createPVC(pvName, pvcName, domainUid, jrfDomainNamespace);

    // create a temporary WebLogic domain property file
    File domainPropertiesFile = assertDoesNotThrow(() ->
            File.createTempFile("domain", "properties"),
        "Failed to create domain properties file");
    Properties p = new Properties();
    p.setProperty("oracleHome", "/u01/oracle"); //default $ORACLE_HOME
    p.setProperty("javaHome", "/u01/jdk"); //default $JAVA_HOME
    p.setProperty("domainParentDir", "/shared/domains/");
    p.setProperty("domainName", domainUid);
    p.setProperty("domainUser", ADMIN_USERNAME_DEFAULT);
    p.setProperty("domainPassword", ADMIN_PASSWORD_DEFAULT);
    p.setProperty("rcuDb", dbUrl);
    p.setProperty("rcuSchemaPrefix", RCUSCHEMAPREFIX);
    p.setProperty("rcuSchemaPassword", RCUSCHEMAPASSWORD);
    p.setProperty("adminListenPort", "7001");
    p.setProperty("adminName", adminServerName);
    p.setProperty("managedNameBase", managedServerNameBase);
    p.setProperty("managedServerPort",Integer.toString(managedServerPort));
    p.setProperty("prodMode", "true");
    p.setProperty("managedCount", "4");
    p.setProperty("clusterName", clusterName);
    p.setProperty("t3ChannelPublicAddress", K8S_NODEPORT_HOST);
    p.setProperty("t3ChannelPort", Integer.toString(t3ChannelPort));
    p.setProperty("exposeAdminT3Channel", "true");

    assertDoesNotThrow(() ->
            p.store(new FileOutputStream(domainPropertiesFile), "jrf wlst properties file"),
        "Failed to write domain properties file");

    // WLST script for creating domain
    Path wlstScript = Paths.get(RESOURCE_DIR, "python-scripts", "jrf-wlst-create-domain-onpv.py");

    // create configmap and domain on persistent volume using the WLST script and property file
    createDomainOnPVUsingWlst(wlstScript, domainPropertiesFile.toPath(),
        pvName, pvcName, jrfDomainNamespace);

    // create a domain custom resource configuration object
    logger.info("Creating domain custom resource");
    Domain domain = new Domain()
        .apiVersion(DOMAIN_API_VERSION)
        .kind("Domain")
        .metadata(new V1ObjectMeta()
            .name(domainUid)
            .namespace(jrfDomainNamespace))
        .spec(new DomainSpec()
            .domainUid(domainUid)
            .domainHome("/shared/domains/" + domainUid)  // point to domain home in pv
            .domainHomeSourceType("PersistentVolume") // set the domain home source type as pv
            .image(fmwImage)
            .imagePullPolicy("IfNotPresent")
            .imagePullSecrets(isUseSecret ? Arrays.asList(
                new V1LocalObjectReference()
                    .name(OCR_SECRET_NAME))
                : null)
            .webLogicCredentialsSecret(new V1SecretReference()
                .name(wlSecretName)
                .namespace(jrfDomainNamespace))
            .includeServerOutInPodLog(true)
            .logHomeEnabled(Boolean.TRUE)
            .logHome("/shared/logs/" + domainUid)
            .dataHome("")
            .serverStartPolicy("IF_NEEDED")
            .serverPod(new ServerPod() //serverpod
                .addEnvItem(new V1EnvVar()
                    .name("JAVA_OPTIONS")
                    .value("-Dweblogic.StdoutDebugEnabled=false"))
                .addEnvItem(new V1EnvVar()
                    .name("USER_MEM_ARGS")
                    .value("-Djava.security.egd=file:/dev/./urandom "))
                .addVolumesItem(new V1Volume()
                    .name(pvName)
                    .persistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource()
                        .claimName(pvcName)))
                .addVolumeMountsItem(new V1VolumeMount()
                    .mountPath("/shared")
                    .name(pvName)))
            .adminServer(new AdminServer() //admin server
                .serverStartState("RUNNING")
                .adminService(new AdminService()
                    .addChannelsItem(new Channel()
                        .channelName("default")
                        .nodePort(0))
                    .addChannelsItem(new Channel()
                        .channelName("T3Channel")
                        .nodePort(t3ChannelPort))))
            .addClustersItem(new Cluster() //cluster
                .clusterName(clusterName)
                .replicas(replicaCount)
                .serverStartState("RUNNING")));

    // verify the domain custom resource is created
    createDomainAndVerify(domain, jrfDomainNamespace);

    // verify the admin server service created
    checkServiceExists(adminServerPodName, jrfDomainNamespace);
    
    // verify admin server pod is ready
    checkPodReady(adminServerPodName, domainUid, jrfDomainNamespace);

    // verify managed server services created
    for (int i = 1; i <= replicaCount; i++) {
      logger.info("Checking managed server service {0} is created in namespace {1}",
          managedServerPodNamePrefix + i, jrfDomainNamespace);
      checkServiceExists(managedServerPodNamePrefix + i, jrfDomainNamespace);
    }

    // verify managed server pods are ready
    for (int i = 1; i <= replicaCount; i++) {
      logger.info("Waiting for managed server pod {0} to be ready in namespace {1}",
          managedServerPodNamePrefix + i, jrfDomainNamespace);
      checkPodReady(managedServerPodNamePrefix + i, domainUid, jrfDomainNamespace);
    }

  }
/**
   * Create a JRF domain using WLST in a persistent volume.
   * Create a domain custom resource with domainHomeSourceType as PersistentVolume.
   * Verify domain pods runs in ready state and services are created.
   */
Create a JRF domain using WLST in a persistent volume.
Create a domain custom resource with domainHomeSourceType as PersistentVolume.
Verify domain pods runs in ready state and services are created.
Create a JRF domain using WLST in a persistent volume . Create a domain custom resource with domainHomeSourceType as PersistentVolume . Verify domain pods runs in ready state and services are created .
@Test
  @DisplayName("Create JRF domain in PV using WLST script")
  public void testJrfDomainInPvUsingWlst() {
    final String clusterName = "cluster-jrfdomain-inpv";
    final String adminServerName = "wlst-admin-server";
    final String adminServerPodName = domainUid + "-" + adminServerName;
    final String managedServerNameBase = "wlst-ms-";
    final int managedServerPort = 8001;
    final String managedServerPodNamePrefix = domainUid + "-" + managedServerNameBase;
    final int replicaCount = 2;
    final int t3ChannelPort = getNextFreePort(30000, 32767);
    final String pvName = domainUid + "-pv";
    final String pvcName = domainUid + "-pvc";
    if (isUseSecret) {
      createDockerRegistrySecret(OCR_USERNAME, OCR_PASSWORD,
          OCR_EMAIL, OCR_REGISTRY, OCR_SECRET_NAME, jrfDomainNamespace);
    }
    createSecretWithUsernamePassword(wlSecretName, jrfDomainNamespace,
        ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT);
    CommonTestUtils.createRcuSecretWithUsernamePassword(rcuSecretName, jrfDomainNamespace,
        RCUSCHEMAUSERNAME, RCUSCHEMAPASSWORD, RCUSYSUSERNAME, RCUSYSPASSWORD);
    CommonTestUtils.createPV(pvName, domainUid, this.getClass().getSimpleName());
    CommonTestUtils.createPVC(pvName, pvcName, domainUid, jrfDomainNamespace);
    File domainPropertiesFile = assertDoesNotThrow(() ->
            File.createTempFile("domain", "properties"),
        "Failed to create domain properties file");
    Properties p = new Properties();
    p.setProperty("oracleHome", "/u01/oracle"); 
    p.setProperty("javaHome", "/u01/jdk"); 
    p.setProperty("domainParentDir", "/shared/domains/");
    p.setProperty("domainName", domainUid);
    p.setProperty("domainUser", ADMIN_USERNAME_DEFAULT);
    p.setProperty("domainPassword", ADMIN_PASSWORD_DEFAULT);
    p.setProperty("rcuDb", dbUrl);
    p.setProperty("rcuSchemaPrefix", RCUSCHEMAPREFIX);
    p.setProperty("rcuSchemaPassword", RCUSCHEMAPASSWORD);
    p.setProperty("adminListenPort", "7001");
    p.setProperty("adminName", adminServerName);
    p.setProperty("managedNameBase", managedServerNameBase);
    p.setProperty("managedServerPort",Integer.toString(managedServerPort));
    p.setProperty("prodMode", "true");
    p.setProperty("managedCount", "4");
    p.setProperty("clusterName", clusterName);
    p.setProperty("t3ChannelPublicAddress", K8S_NODEPORT_HOST);
    p.setProperty("t3ChannelPort", Integer.toString(t3ChannelPort));
    p.setProperty("exposeAdminT3Channel", "true");
    assertDoesNotThrow(() ->
            p.store(new FileOutputStream(domainPropertiesFile), "jrf wlst properties file"),
        "Failed to write domain properties file");
    Path wlstScript = Paths.get(RESOURCE_DIR, "python-scripts", "jrf-wlst-create-domain-onpv.py");
    createDomainOnPVUsingWlst(wlstScript, domainPropertiesFile.toPath(),
        pvName, pvcName, jrfDomainNamespace);
    logger.info("Creating domain custom resource");
    Domain domain = new Domain()
        .apiVersion(DOMAIN_API_VERSION)
        .kind("Domain")
        .metadata(new V1ObjectMeta()
            .name(domainUid)
            .namespace(jrfDomainNamespace))
        .spec(new DomainSpec()
            .domainUid(domainUid)
            .domainHome("/shared/domains/" + domainUid)  
            .domainHomeSourceType("PersistentVolume") 
            .image(fmwImage)
            .imagePullPolicy("IfNotPresent")
            .imagePullSecrets(isUseSecret ? Arrays.asList(
                new V1LocalObjectReference()
                    .name(OCR_SECRET_NAME))
                : null)
            .webLogicCredentialsSecret(new V1SecretReference()
                .name(wlSecretName)
                .namespace(jrfDomainNamespace))
            .includeServerOutInPodLog(true)
            .logHomeEnabled(Boolean.TRUE)
            .logHome("/shared/logs/" + domainUid)
            .dataHome("")
            .serverStartPolicy("IF_NEEDED")
            .serverPod(new ServerPod() 
                .addEnvItem(new V1EnvVar()
                    .name("JAVA_OPTIONS")
                    .value("-Dweblogic.StdoutDebugEnabled=false"))
                .addEnvItem(new V1EnvVar()
                    .name("USER_MEM_ARGS")
                    .value("-Djava.security.egd=file:/dev/./urandom "))
                .addVolumesItem(new V1Volume()
                    .name(pvName)
                    .persistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource()
                        .claimName(pvcName)))
                .addVolumeMountsItem(new V1VolumeMount()
                    .mountPath("/shared")
                    .name(pvName)))
            .adminServer(new AdminServer() 
                .serverStartState("RUNNING")
                .adminService(new AdminService()
                    .addChannelsItem(new Channel()
                        .channelName("default")
                        .nodePort(0))
                    .addChannelsItem(new Channel()
                        .channelName("T3Channel")
                        .nodePort(t3ChannelPort))))
            .addClustersItem(new Cluster() 
                .clusterName(clusterName)
                .replicas(replicaCount)
                .serverStartState("RUNNING")));
    createDomainAndVerify(domain, jrfDomainNamespace);
    checkServiceExists(adminServerPodName, jrfDomainNamespace);
    checkPodReady(adminServerPodName, domainUid, jrfDomainNamespace);
    for (int i = 1; i <= replicaCount; i++) {
      logger.info("Checking managed server service {0} is created in namespace {1}",
          managedServerPodNamePrefix + i, jrfDomainNamespace);
      checkServiceExists(managedServerPodNamePrefix + i, jrfDomainNamespace);
    }
    for (int i = 1; i <= replicaCount; i++) {
      logger.info("Waiting for managed server pod {0} to be ready in namespace {1}",
          managedServerPodNamePrefix + i, jrfDomainNamespace);
      checkPodReady(managedServerPodNamePrefix + i, domainUid, jrfDomainNamespace);
    }
  }
@ Test @ DisplayName ( "Create JRF domain in PV using WLST script" ) public void testJrfDomainInPvUsingWlst ( ) { final String clusterName = "cluster-jrfdomain-inpv" ; final String adminServerName = "wlst-admin-server" ; final String adminServerPodName = domainUid + "-" + adminServerName ; final String managedServerNameBase = "wlst-ms-" ; final int managedServerPort = 8001 ; final String managedServerPodNamePrefix = domainUid + "-" + managedServerNameBase ; final int replicaCount = 2 ; final int t3ChannelPort = getNextFreePort ( 30000 , 32767 ) ; final String pvName = domainUid + "-pv" ; final String pvcName = domainUid + "-pvc" ; if ( isUseSecret ) { createDockerRegistrySecret ( OCR_USERNAME , OCR_PASSWORD , OCR_EMAIL , OCR_REGISTRY , OCR_SECRET_NAME , jrfDomainNamespace ) ; } createSecretWithUsernamePassword ( wlSecretName , jrfDomainNamespace , ADMIN_USERNAME_DEFAULT , ADMIN_PASSWORD_DEFAULT ) ; CommonTestUtils . createRcuSecretWithUsernamePassword ( rcuSecretName , jrfDomainNamespace , RCUSCHEMAUSERNAME , RCUSCHEMAPASSWORD , RCUSYSUSERNAME , RCUSYSPASSWORD ) ; CommonTestUtils . createPV ( pvName , domainUid , this . getClass ( ) . getSimpleName ( ) ) ; CommonTestUtils . createPVC ( pvName , pvcName , domainUid , jrfDomainNamespace ) ; File domainPropertiesFile = assertDoesNotThrow ( ( ) -> File . createTempFile ( "domain" , "properties" ) , "Failed to create domain properties file" ) ; Properties p = new Properties ( ) ; p . setProperty ( "oracleHome" , "/u01/oracle" ) ; p . setProperty ( "javaHome" , "/u01/jdk" ) ; p . setProperty ( "domainParentDir" , "/shared/domains/" ) ; p . setProperty ( "domainName" , domainUid ) ; p . setProperty ( "domainUser" , ADMIN_USERNAME_DEFAULT ) ; p . setProperty ( "domainPassword" , ADMIN_PASSWORD_DEFAULT ) ; p . setProperty ( "rcuDb" , dbUrl ) ; p . setProperty ( "rcuSchemaPrefix" , RCUSCHEMAPREFIX ) ; p . setProperty ( "rcuSchemaPassword" , RCUSCHEMAPASSWORD ) ; p . setProperty ( "adminListenPort" , "7001" ) ; p . setProperty ( "adminName" , adminServerName ) ; p . setProperty ( "managedNameBase" , managedServerNameBase ) ; p . setProperty ( "managedServerPort" , Integer . toString ( managedServerPort ) ) ; p . setProperty ( "prodMode" , "true" ) ; p . setProperty ( "managedCount" , "4" ) ; p . setProperty ( "clusterName" , clusterName ) ; p . setProperty ( "t3ChannelPublicAddress" , K8S_NODEPORT_HOST ) ; p . setProperty ( "t3ChannelPort" , Integer . toString ( t3ChannelPort ) ) ; p . setProperty ( "exposeAdminT3Channel" , "true" ) ; assertDoesNotThrow ( ( ) -> p . store ( new FileOutputStream ( domainPropertiesFile ) , "jrf wlst properties file" ) , "Failed to write domain properties file" ) ; Path wlstScript = Paths . get ( RESOURCE_DIR , "python-scripts" , "jrf-wlst-create-domain-onpv.py" ) ; createDomainOnPVUsingWlst ( wlstScript , domainPropertiesFile . toPath ( ) , pvName , pvcName , jrfDomainNamespace ) ; logger . info ( "Creating domain custom resource" ) ; Domain domain = new Domain ( ) . apiVersion ( DOMAIN_API_VERSION ) . kind ( "Domain" ) . metadata ( new V1ObjectMeta ( ) . name ( domainUid ) . namespace ( jrfDomainNamespace ) ) . spec ( new DomainSpec ( ) . domainUid ( domainUid ) . domainHome ( "/shared/domains/" + domainUid ) . domainHomeSourceType ( "PersistentVolume" ) . image ( fmwImage ) . imagePullPolicy ( "IfNotPresent" ) . imagePullSecrets ( isUseSecret ? Arrays . asList ( new V1LocalObjectReference ( ) . name ( OCR_SECRET_NAME ) ) : null ) . webLogicCredentialsSecret ( new V1SecretReference ( ) . name ( wlSecretName ) . namespace ( jrfDomainNamespace ) ) . includeServerOutInPodLog ( true ) . logHomeEnabled ( Boolean . TRUE ) . logHome ( "/shared/logs/" + domainUid ) . dataHome ( "" ) . serverStartPolicy ( "IF_NEEDED" ) . serverPod ( new ServerPod ( ) . addEnvItem ( new V1EnvVar ( ) . name ( "JAVA_OPTIONS" ) . value ( "-Dweblogic.StdoutDebugEnabled=false" ) ) . addEnvItem ( new V1EnvVar ( ) . name ( "USER_MEM_ARGS" ) . value ( "-Djava.security.egd=file:/dev/./urandom " ) ) . addVolumesItem ( new V1Volume ( ) . name ( pvName ) . persistentVolumeClaim ( new V1PersistentVolumeClaimVolumeSource ( ) . claimName ( pvcName ) ) ) . addVolumeMountsItem ( new V1VolumeMount ( ) . mountPath ( "/shared" ) . name ( pvName ) ) ) . adminServer ( new AdminServer ( ) . serverStartState ( "RUNNING" ) . adminService ( new AdminService ( ) . addChannelsItem ( new Channel ( ) . channelName ( "default" ) . nodePort ( 0 ) ) . addChannelsItem ( new Channel ( ) . channelName ( "T3Channel" ) . nodePort ( t3ChannelPort ) ) ) ) . addClustersItem ( new Cluster ( ) . clusterName ( clusterName ) . replicas ( replicaCount ) . serverStartState ( "RUNNING" ) ) ) ; createDomainAndVerify ( domain , jrfDomainNamespace ) ; checkServiceExists ( adminServerPodName , jrfDomainNamespace ) ; checkPodReady ( adminServerPodName , domainUid , jrfDomainNamespace ) ; for ( int i = 1 ; i <= replicaCount ; i ++ ) { logger . info ( "Checking managed server service {0} is created in namespace {1}" , managedServerPodNamePrefix + i , jrfDomainNamespace ) ; checkServiceExists ( managedServerPodNamePrefix + i , jrfDomainNamespace ) ; } for ( int i = 1 ; i <= replicaCount ; i ++ ) { logger . info ( "Waiting for managed server pod {0} to be ready in namespace {1}" , managedServerPodNamePrefix + i , jrfDomainNamespace ) ; checkPodReady ( managedServerPodNamePrefix + i , domainUid , jrfDomainNamespace ) ; } }
Create a JRF domain using WLST in a persistent volume.
Create a JRF domain using WLST in a persistent volume .
// create pull secrets for jrfDomainNamespace when running in non Kind Kubernetes cluster // create JRF domain credential secret // create RCU credential secret // create persistent volume and persistent volume claim for domain // create a temporary WebLogic domain property file //default $ORACLE_HOME //default $JAVA_HOME // WLST script for creating domain // create configmap and domain on persistent volume using the WLST script and property file // create a domain custom resource configuration object // point to domain home in pv // set the domain home source type as pv //serverpod //admin server //cluster // verify the domain custom resource is created // verify the admin server service created // verify admin server pod is ready // verify managed server services created // verify managed server pods are ready