new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItOperatorTwoDomains.java
private void createTwoDomainsOnPVUsingWlstAndVerify() {

    String wlSecretName = "weblogic-credentials";

    for (int i = 0; i < numberOfDomains; i++) {

      if (isUseSecret) {
        // create pull secrets for WebLogic image
        createOCRRepoSecret(domainNamespaces.get(i));
      }

      t3ChannelPort = getNextFreePort(32001, 32700);
      logger.info("t3ChannelPort for domain {0} is {1}", domainUids.get(i), t3ChannelPort);

      String domainUid = domainUids.get(i);
      String domainNamespace = domainNamespaces.get(i);
      String pvName = domainUid + "-pv-" + domainNamespace;
      String pvcName = domainUid + "-pvc";

      // create WebLogic credentials secret
      createSecretWithUsernamePassword(wlSecretName, domainNamespace, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT);

      // create persistent volume and persistent volume claims
      Path pvHostPath = assertDoesNotThrow(
          () -> createDirectories(get(PV_ROOT, this.getClass().getSimpleName(), domainUid + "-persistentVolume")),
              "createDirectories failed with IOException");

      logger.info("Creating PV directory {0}", pvHostPath);
      assertDoesNotThrow(() -> deleteDirectory(pvHostPath.toFile()), "deleteDirectory failed with IOException");
      assertDoesNotThrow(() -> createDirectories(pvHostPath), "createDirectories failed with IOException");

      V1PersistentVolume v1pv = new V1PersistentVolume()
          .spec(new V1PersistentVolumeSpec()
              .addAccessModesItem("ReadWriteMany")
              .storageClassName(domainUid + "-weblogic-domain-storage-class")
              .volumeMode("Filesystem")
              .putCapacityItem("storage", Quantity.fromString("5Gi"))
              .persistentVolumeReclaimPolicy("Recycle")
              .accessModes(Arrays.asList("ReadWriteMany"))
              .hostPath(new V1HostPathVolumeSource()
                  .path(pvHostPath.toString())))
          .metadata(new V1ObjectMetaBuilder()
              .withName(pvName)
              .build()
              .putLabelsItem("weblogic.domainUid", domainUid));

      V1PersistentVolumeClaim v1pvc = new V1PersistentVolumeClaim()
          .spec(new V1PersistentVolumeClaimSpec()
              .addAccessModesItem("ReadWriteMany")
              .storageClassName(domainUid + "-weblogic-domain-storage-class")
              .volumeName(pvName)
              .resources(new V1ResourceRequirements()
                  .putRequestsItem("storage", Quantity.fromString("5Gi"))))
          .metadata(new V1ObjectMetaBuilder()
              .withName(pvcName)
              .withNamespace(domainNamespace)
              .build()
              .putLabelsItem("weblogic.domainUid", domainUid));

      String labelSelector = String.format("weblogic.domainUid in (%s)", domainUid);
      createPVPVCAndVerify(v1pv, v1pvc, labelSelector, domainNamespace);

      // run create a domain on PV job using WLST
      runCreateDomainOnPVJobUsingWlst(pvName, pvcName, domainUid, domainNamespace);

      // create the 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(domainNamespace))
          .spec(new DomainSpec()
              .domainUid(domainUid)
              .domainHome("/shared/domains/" + domainUid)
              .domainHomeSourceType("PersistentVolume")
              .image(image)
              .imagePullSecrets(isUseSecret ? Arrays.asList(
                  new V1LocalObjectReference()
                      .name(OCR_SECRET_NAME))
                  : null)
              .webLogicCredentialsSecret(new V1SecretReference()
                  .name(wlSecretName)
                  .namespace(domainNamespace))
              .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")));

      logger.info("Creating domain custom resource {0} in namespace {1}", domainUid, domainNamespace);
      createDomainAndVerify(domain, domainNamespace);

      String adminServerPodName = domainUid + "-" + ADMIN_SERVER_NAME_BASE;
      // check admin server pod is ready and service exists in domain namespace
      checkPodReadyAndServiceExists(adminServerPodName, domainUid, domainNamespace);

      // check for managed server pods are ready and services exist in domain namespace
      for (int j = 1; j <= replicaCount; j++) {
        String managedServerPodName = domainUid + "-" + MANAGED_SERVER_NAME_BASE + j;
        checkPodReadyAndServiceExists(managedServerPodName, domainUid, domainNamespace);
      }

      logger.info("Getting admin service node port");
      int serviceNodePort =
              getServiceNodePort(domainNamespace, adminServerPodName + "-external", "default");

      logger.info("Validating WebLogic admin server access by login to console");
      assertTrue(assertDoesNotThrow(
          () -> adminNodePortAccessible(serviceNodePort, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT),
          "Access to admin server node port failed"), "Console login validation failed");
    }
  }
/**
   * Create two domains on PV using WLST.
   */
Create two domains on PV using WLST.
Create two domains on PV using WLST .
private void createTwoDomainsOnPVUsingWlstAndVerify() {
    String wlSecretName = "weblogic-credentials";
    for (int i = 0; i < numberOfDomains; i++) {
      if (isUseSecret) {
        createOCRRepoSecret(domainNamespaces.get(i));
      }
      t3ChannelPort = getNextFreePort(32001, 32700);
      logger.info("t3ChannelPort for domain {0} is {1}", domainUids.get(i), t3ChannelPort);
      String domainUid = domainUids.get(i);
      String domainNamespace = domainNamespaces.get(i);
      String pvName = domainUid + "-pv-" + domainNamespace;
      String pvcName = domainUid + "-pvc";
      createSecretWithUsernamePassword(wlSecretName, domainNamespace, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT);
      Path pvHostPath = assertDoesNotThrow(
          () -> createDirectories(get(PV_ROOT, this.getClass().getSimpleName(), domainUid + "-persistentVolume")),
              "createDirectories failed with IOException");
      logger.info("Creating PV directory {0}", pvHostPath);
      assertDoesNotThrow(() -> deleteDirectory(pvHostPath.toFile()), "deleteDirectory failed with IOException");
      assertDoesNotThrow(() -> createDirectories(pvHostPath), "createDirectories failed with IOException");
      V1PersistentVolume v1pv = new V1PersistentVolume()
          .spec(new V1PersistentVolumeSpec()
              .addAccessModesItem("ReadWriteMany")
              .storageClassName(domainUid + "-weblogic-domain-storage-class")
              .volumeMode("Filesystem")
              .putCapacityItem("storage", Quantity.fromString("5Gi"))
              .persistentVolumeReclaimPolicy("Recycle")
              .accessModes(Arrays.asList("ReadWriteMany"))
              .hostPath(new V1HostPathVolumeSource()
                  .path(pvHostPath.toString())))
          .metadata(new V1ObjectMetaBuilder()
              .withName(pvName)
              .build()
              .putLabelsItem("weblogic.domainUid", domainUid));
      V1PersistentVolumeClaim v1pvc = new V1PersistentVolumeClaim()
          .spec(new V1PersistentVolumeClaimSpec()
              .addAccessModesItem("ReadWriteMany")
              .storageClassName(domainUid + "-weblogic-domain-storage-class")
              .volumeName(pvName)
              .resources(new V1ResourceRequirements()
                  .putRequestsItem("storage", Quantity.fromString("5Gi"))))
          .metadata(new V1ObjectMetaBuilder()
              .withName(pvcName)
              .withNamespace(domainNamespace)
              .build()
              .putLabelsItem("weblogic.domainUid", domainUid));
      String labelSelector = String.format("weblogic.domainUid in (%s)", domainUid);
      createPVPVCAndVerify(v1pv, v1pvc, labelSelector, domainNamespace);
      runCreateDomainOnPVJobUsingWlst(pvName, pvcName, domainUid, domainNamespace);
      logger.info("Creating domain custom resource");
      Domain domain = new Domain()
          .apiVersion(DOMAIN_API_VERSION)
          .kind("Domain")
          .metadata(new V1ObjectMeta()
              .name(domainUid)
              .namespace(domainNamespace))
          .spec(new DomainSpec()
              .domainUid(domainUid)
              .domainHome("/shared/domains/" + domainUid)
              .domainHomeSourceType("PersistentVolume")
              .image(image)
              .imagePullSecrets(isUseSecret ? Arrays.asList(
                  new V1LocalObjectReference()
                      .name(OCR_SECRET_NAME))
                  : null)
              .webLogicCredentialsSecret(new V1SecretReference()
                  .name(wlSecretName)
                  .namespace(domainNamespace))
              .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")));
      logger.info("Creating domain custom resource {0} in namespace {1}", domainUid, domainNamespace);
      createDomainAndVerify(domain, domainNamespace);
      String adminServerPodName = domainUid + "-" + ADMIN_SERVER_NAME_BASE;
      checkPodReadyAndServiceExists(adminServerPodName, domainUid, domainNamespace);
      for (int j = 1; j <= replicaCount; j++) {
        String managedServerPodName = domainUid + "-" + MANAGED_SERVER_NAME_BASE + j;
        checkPodReadyAndServiceExists(managedServerPodName, domainUid, domainNamespace);
      }
      logger.info("Getting admin service node port");
      int serviceNodePort =
              getServiceNodePort(domainNamespace, adminServerPodName + "-external", "default");
      logger.info("Validating WebLogic admin server access by login to console");
      assertTrue(assertDoesNotThrow(
          () -> adminNodePortAccessible(serviceNodePort, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT),
          "Access to admin server node port failed"), "Console login validation failed");
    }
  }
private void createTwoDomainsOnPVUsingWlstAndVerify ( ) { String wlSecretName = "weblogic-credentials" ; for ( int i = 0 ; i < numberOfDomains ; i ++ ) { if ( isUseSecret ) { createOCRRepoSecret ( domainNamespaces . get ( i ) ) ; } t3ChannelPort = getNextFreePort ( 32001 , 32700 ) ; logger . info ( "t3ChannelPort for domain {0} is {1}" , domainUids . get ( i ) , t3ChannelPort ) ; String domainUid = domainUids . get ( i ) ; String domainNamespace = domainNamespaces . get ( i ) ; String pvName = domainUid + "-pv-" + domainNamespace ; String pvcName = domainUid + "-pvc" ; createSecretWithUsernamePassword ( wlSecretName , domainNamespace , ADMIN_USERNAME_DEFAULT , ADMIN_PASSWORD_DEFAULT ) ; Path pvHostPath = assertDoesNotThrow ( ( ) -> createDirectories ( get ( PV_ROOT , this . getClass ( ) . getSimpleName ( ) , domainUid + "-persistentVolume" ) ) , "createDirectories failed with IOException" ) ; logger . info ( "Creating PV directory {0}" , pvHostPath ) ; assertDoesNotThrow ( ( ) -> deleteDirectory ( pvHostPath . toFile ( ) ) , "deleteDirectory failed with IOException" ) ; assertDoesNotThrow ( ( ) -> createDirectories ( pvHostPath ) , "createDirectories failed with IOException" ) ; V1PersistentVolume v1pv = new V1PersistentVolume ( ) . spec ( new V1PersistentVolumeSpec ( ) . addAccessModesItem ( "ReadWriteMany" ) . storageClassName ( domainUid + "-weblogic-domain-storage-class" ) . volumeMode ( "Filesystem" ) . putCapacityItem ( "storage" , Quantity . fromString ( "5Gi" ) ) . persistentVolumeReclaimPolicy ( "Recycle" ) . accessModes ( Arrays . asList ( "ReadWriteMany" ) ) . hostPath ( new V1HostPathVolumeSource ( ) . path ( pvHostPath . toString ( ) ) ) ) . metadata ( new V1ObjectMetaBuilder ( ) . withName ( pvName ) . build ( ) . putLabelsItem ( "weblogic.domainUid" , domainUid ) ) ; V1PersistentVolumeClaim v1pvc = new V1PersistentVolumeClaim ( ) . spec ( new V1PersistentVolumeClaimSpec ( ) . addAccessModesItem ( "ReadWriteMany" ) . storageClassName ( domainUid + "-weblogic-domain-storage-class" ) . volumeName ( pvName ) . resources ( new V1ResourceRequirements ( ) . putRequestsItem ( "storage" , Quantity . fromString ( "5Gi" ) ) ) ) . metadata ( new V1ObjectMetaBuilder ( ) . withName ( pvcName ) . withNamespace ( domainNamespace ) . build ( ) . putLabelsItem ( "weblogic.domainUid" , domainUid ) ) ; String labelSelector = String . format ( "weblogic.domainUid in (%s)" , domainUid ) ; createPVPVCAndVerify ( v1pv , v1pvc , labelSelector , domainNamespace ) ; runCreateDomainOnPVJobUsingWlst ( pvName , pvcName , domainUid , domainNamespace ) ; logger . info ( "Creating domain custom resource" ) ; Domain domain = new Domain ( ) . apiVersion ( DOMAIN_API_VERSION ) . kind ( "Domain" ) . metadata ( new V1ObjectMeta ( ) . name ( domainUid ) . namespace ( domainNamespace ) ) . spec ( new DomainSpec ( ) . domainUid ( domainUid ) . domainHome ( "/shared/domains/" + domainUid ) . domainHomeSourceType ( "PersistentVolume" ) . image ( image ) . imagePullSecrets ( isUseSecret ? Arrays . asList ( new V1LocalObjectReference ( ) . name ( OCR_SECRET_NAME ) ) : null ) . webLogicCredentialsSecret ( new V1SecretReference ( ) . name ( wlSecretName ) . namespace ( domainNamespace ) ) . 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" ) ) ) ; logger . info ( "Creating domain custom resource {0} in namespace {1}" , domainUid , domainNamespace ) ; createDomainAndVerify ( domain , domainNamespace ) ; String adminServerPodName = domainUid + "-" + ADMIN_SERVER_NAME_BASE ; checkPodReadyAndServiceExists ( adminServerPodName , domainUid , domainNamespace ) ; for ( int j = 1 ; j <= replicaCount ; j ++ ) { String managedServerPodName = domainUid + "-" + MANAGED_SERVER_NAME_BASE + j ; checkPodReadyAndServiceExists ( managedServerPodName , domainUid , domainNamespace ) ; } logger . info ( "Getting admin service node port" ) ; int serviceNodePort = getServiceNodePort ( domainNamespace , adminServerPodName + "-external" , "default" ) ; logger . info ( "Validating WebLogic admin server access by login to console" ) ; assertTrue ( assertDoesNotThrow ( ( ) -> adminNodePortAccessible ( serviceNodePort , ADMIN_USERNAME_DEFAULT , ADMIN_PASSWORD_DEFAULT ) , "Access to admin server node port failed" ) , "Console login validation failed" ) ; } }
Create two domains on PV using WLST.
Create two domains on PV using WLST .
// create pull secrets for WebLogic image // create WebLogic credentials secret // create persistent volume and persistent volume claims // run create a domain on PV job using WLST // create the domain custom resource configuration object // check admin server pod is ready and service exists in domain namespace // check for managed server pods are ready and services exist in domain namespace