new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItOperatorTwoDomains.java
private void runCreateDomainOnPVJobUsingWlst(String pvName,
                                               String pvcName,
                                               String domainUid,
                                               String domainNamespace) {

    logger.info("Creating a staging location for domain creation scripts");
    Path pvTemp = get(RESULTS_ROOT, this.getClass().getSimpleName(), "domainCreateTempPV");
    assertDoesNotThrow(() -> deleteDirectory(pvTemp.toFile()),"deleteDirectory failed with IOException");
    assertDoesNotThrow(() -> createDirectories(pvTemp), "createDirectories failed with IOException");

    logger.info("Copying the domain creation WLST script to staging location");
    Path srcWlstScript = get(RESOURCE_DIR, "python-scripts", "wlst-create-domain-onpv.py");
    Path targetWlstScript = get(pvTemp.toString(), "create-domain.py");
    assertDoesNotThrow(() -> copy(srcWlstScript, targetWlstScript, StandardCopyOption.REPLACE_EXISTING),
        "copy failed with IOException");

    logger.info("Creating WebLogic domain properties file");
    Path domainPropertiesFile = get(pvTemp.toString(), "domain.properties");
    createDomainProperties(domainPropertiesFile, domainUid);

    logger.info("Adding files to a ConfigMap for domain creation job");
    List<Path> domainScriptFiles = new ArrayList<>();
    domainScriptFiles.add(targetWlstScript);
    domainScriptFiles.add(domainPropertiesFile);

    logger.info("Creating a ConfigMap to hold domain creation scripts");
    String domainScriptConfigMapName = "create-domain-scripts-cm";
    createConfigMapFromFiles(domainScriptConfigMapName, domainScriptFiles, domainNamespace);

    logger.info("Running a Kubernetes job to create the domain");
    V1Job jobBody = new V1Job()
        .metadata(
            new V1ObjectMeta()
                .name("create-domain-onpv-job")
                .namespace(domainNamespace))
        .spec(new V1JobSpec()
            .backoffLimit(0) // try only once
            .template(new V1PodTemplateSpec()
                .spec(new V1PodSpec()
                    .restartPolicy("Never")
                    .initContainers(Arrays.asList(new V1Container()
                        .name("fix-pvc-owner")
                        .image(image)
                        .addCommandItem("/bin/sh")
                        .addArgsItem("-c")
                        .addArgsItem("chown -R 1000:1000 /shared")
                        .volumeMounts(Arrays.asList(
                            new V1VolumeMount()
                                .name(pvName)
                                .mountPath("/shared")))
                        .securityContext(new V1SecurityContext()
                            .runAsGroup(0L)
                            .runAsUser(0L))))
                    .containers(Arrays.asList(new V1Container()
                        .name("create-weblogic-domain-onpv-container")
                        .image(image)
                        .ports(Arrays.asList(new V1ContainerPort()
                            .containerPort(7001)))
                        .volumeMounts(Arrays.asList(
                            new V1VolumeMount()
                                .name("create-weblogic-domain-job-cm-volume") // domain creation scripts volume
                                .mountPath("/u01/weblogic"), // availble under /u01/weblogic inside pod
                            new V1VolumeMount()
                                .name(pvName) // location to write domain
                                .mountPath("/shared"))) // mounted under /shared inside pod
                        .addCommandItem("/bin/sh") //call wlst.sh script with py and properties file
                        .addArgsItem("/u01/oracle/oracle_common/common/bin/wlst.sh")
                        .addArgsItem("/u01/weblogic/create-domain.py")
                        .addArgsItem("-skipWLSModuleScanning")
                        .addArgsItem("-loadProperties")
                        .addArgsItem("/u01/weblogic/domain.properties")))
                    .volumes(Arrays.asList(
                        new V1Volume()
                            .name(pvName)
                            .persistentVolumeClaim(
                                new V1PersistentVolumeClaimVolumeSource()
                                    .claimName(pvcName)),
                        new V1Volume()
                            .name("create-weblogic-domain-job-cm-volume")
                            .configMap(
                                new V1ConfigMapVolumeSource()
                                    .name(domainScriptConfigMapName))))  //ConfigMap containing domain scripts
                    .imagePullSecrets(isUseSecret ? Arrays.asList(
                        new V1LocalObjectReference()
                            .name(OCR_SECRET_NAME))
                        : null))));

    logger.info("Running a job {0} to create a domain on PV for domain {1} in namespace {2}",
        jobBody.getMetadata().getName(), domainUid, domainNamespace);
    createJobAndWaitUntilComplete(jobBody, domainNamespace);
  }
/**
   * Run a job to create a WebLogic domain on a persistent volume by doing the following.
   * Copies the WLST domain script to a temp location.
   * Creates a domain properties in the temp location.
   * Creates a configmap containing domain scripts and property files.
   * Runs a job to create domain on persistent volume.
   *
   * @param pvName persistence volume on which the WebLogic domain home will be hosted
   * @param pvcName persistence volume claim for the WebLogic domain
   * @param domainUid the Uid of the domain to create
   * @param domainNamespace the namespace in which the domain will be created
   */
Run a job to create a WebLogic domain on a persistent volume by doing the following.
Copies the WLST domain script to a temp location.
Creates a domain properties in the temp location.
Creates a configmap containing domain scripts and property files.
Runs a job to create domain on persistent volume.

@param pvName persistence volume on which the WebLogic domain home will be hosted
@param pvcName persistence volume claim for the WebLogic domain
@param domainUid the Uid of the domain to create
@param domainNamespace the namespace in which the domain will be created
Run a job to create a WebLogic domain on a persistent volume by doing the following . Copies the WLST domain script to a temp location . Creates a domain properties in the temp location . Creates a configmap containing domain scripts and property files . Runs a job to create domain on persistent volume . @param pvName persistence volume on which the WebLogic domain home will be hosted @param pvcName persistence volume claim for the WebLogic domain @param domainUid the Uid of the domain to create @param domainNamespace the namespace in which the domain will be created
private void runCreateDomainOnPVJobUsingWlst(String pvName,
                                               String pvcName,
                                               String domainUid,
                                               String domainNamespace) {
    logger.info("Creating a staging location for domain creation scripts");
    Path pvTemp = get(RESULTS_ROOT, this.getClass().getSimpleName(), "domainCreateTempPV");
    assertDoesNotThrow(() -> deleteDirectory(pvTemp.toFile()),"deleteDirectory failed with IOException");
    assertDoesNotThrow(() -> createDirectories(pvTemp), "createDirectories failed with IOException");
    logger.info("Copying the domain creation WLST script to staging location");
    Path srcWlstScript = get(RESOURCE_DIR, "python-scripts", "wlst-create-domain-onpv.py");
    Path targetWlstScript = get(pvTemp.toString(), "create-domain.py");
    assertDoesNotThrow(() -> copy(srcWlstScript, targetWlstScript, StandardCopyOption.REPLACE_EXISTING),
        "copy failed with IOException");
    logger.info("Creating WebLogic domain properties file");
    Path domainPropertiesFile = get(pvTemp.toString(), "domain.properties");
    createDomainProperties(domainPropertiesFile, domainUid);
    logger.info("Adding files to a ConfigMap for domain creation job");
    List<Path> domainScriptFiles = new ArrayList<>();
    domainScriptFiles.add(targetWlstScript);
    domainScriptFiles.add(domainPropertiesFile);
    logger.info("Creating a ConfigMap to hold domain creation scripts");
    String domainScriptConfigMapName = "create-domain-scripts-cm";
    createConfigMapFromFiles(domainScriptConfigMapName, domainScriptFiles, domainNamespace);
    logger.info("Running a Kubernetes job to create the domain");
    V1Job jobBody = new V1Job()
        .metadata(
            new V1ObjectMeta()
                .name("create-domain-onpv-job")
                .namespace(domainNamespace))
        .spec(new V1JobSpec()
            .backoffLimit(0) 
            .template(new V1PodTemplateSpec()
                .spec(new V1PodSpec()
                    .restartPolicy("Never")
                    .initContainers(Arrays.asList(new V1Container()
                        .name("fix-pvc-owner")
                        .image(image)
                        .addCommandItem("/bin/sh")
                        .addArgsItem("-c")
                        .addArgsItem("chown -R 1000:1000 /shared")
                        .volumeMounts(Arrays.asList(
                            new V1VolumeMount()
                                .name(pvName)
                                .mountPath("/shared")))
                        .securityContext(new V1SecurityContext()
                            .runAsGroup(0L)
                            .runAsUser(0L))))
                    .containers(Arrays.asList(new V1Container()
                        .name("create-weblogic-domain-onpv-container")
                        .image(image)
                        .ports(Arrays.asList(new V1ContainerPort()
                            .containerPort(7001)))
                        .volumeMounts(Arrays.asList(
                            new V1VolumeMount()
                                .name("create-weblogic-domain-job-cm-volume") 
                                .mountPath("/u01/weblogic"), 
                            new V1VolumeMount()
                                .name(pvName) 
                                .mountPath("/shared"))) 
                        .addCommandItem("/bin/sh") 
                        .addArgsItem("/u01/oracle/oracle_common/common/bin/wlst.sh")
                        .addArgsItem("/u01/weblogic/create-domain.py")
                        .addArgsItem("-skipWLSModuleScanning")
                        .addArgsItem("-loadProperties")
                        .addArgsItem("/u01/weblogic/domain.properties")))
                    .volumes(Arrays.asList(
                        new V1Volume()
                            .name(pvName)
                            .persistentVolumeClaim(
                                new V1PersistentVolumeClaimVolumeSource()
                                    .claimName(pvcName)),
                        new V1Volume()
                            .name("create-weblogic-domain-job-cm-volume")
                            .configMap(
                                new V1ConfigMapVolumeSource()
                                    .name(domainScriptConfigMapName))))  
                    .imagePullSecrets(isUseSecret ? Arrays.asList(
                        new V1LocalObjectReference()
                            .name(OCR_SECRET_NAME))
                        : null))));
    logger.info("Running a job {0} to create a domain on PV for domain {1} in namespace {2}",
        jobBody.getMetadata().getName(), domainUid, domainNamespace);
    createJobAndWaitUntilComplete(jobBody, domainNamespace);
  }
private void runCreateDomainOnPVJobUsingWlst ( String pvName , String pvcName , String domainUid , String domainNamespace ) { logger . info ( "Creating a staging location for domain creation scripts" ) ; Path pvTemp = get ( RESULTS_ROOT , this . getClass ( ) . getSimpleName ( ) , "domainCreateTempPV" ) ; assertDoesNotThrow ( ( ) -> deleteDirectory ( pvTemp . toFile ( ) ) , "deleteDirectory failed with IOException" ) ; assertDoesNotThrow ( ( ) -> createDirectories ( pvTemp ) , "createDirectories failed with IOException" ) ; logger . info ( "Copying the domain creation WLST script to staging location" ) ; Path srcWlstScript = get ( RESOURCE_DIR , "python-scripts" , "wlst-create-domain-onpv.py" ) ; Path targetWlstScript = get ( pvTemp . toString ( ) , "create-domain.py" ) ; assertDoesNotThrow ( ( ) -> copy ( srcWlstScript , targetWlstScript , StandardCopyOption . REPLACE_EXISTING ) , "copy failed with IOException" ) ; logger . info ( "Creating WebLogic domain properties file" ) ; Path domainPropertiesFile = get ( pvTemp . toString ( ) , "domain.properties" ) ; createDomainProperties ( domainPropertiesFile , domainUid ) ; logger . info ( "Adding files to a ConfigMap for domain creation job" ) ; List < Path > domainScriptFiles = new ArrayList < > ( ) ; domainScriptFiles . add ( targetWlstScript ) ; domainScriptFiles . add ( domainPropertiesFile ) ; logger . info ( "Creating a ConfigMap to hold domain creation scripts" ) ; String domainScriptConfigMapName = "create-domain-scripts-cm" ; createConfigMapFromFiles ( domainScriptConfigMapName , domainScriptFiles , domainNamespace ) ; logger . info ( "Running a Kubernetes job to create the domain" ) ; V1Job jobBody = new V1Job ( ) . metadata ( new V1ObjectMeta ( ) . name ( "create-domain-onpv-job" ) . namespace ( domainNamespace ) ) . spec ( new V1JobSpec ( ) . backoffLimit ( 0 ) . template ( new V1PodTemplateSpec ( ) . spec ( new V1PodSpec ( ) . restartPolicy ( "Never" ) . initContainers ( Arrays . asList ( new V1Container ( ) . name ( "fix-pvc-owner" ) . image ( image ) . addCommandItem ( "/bin/sh" ) . addArgsItem ( "-c" ) . addArgsItem ( "chown -R 1000:1000 /shared" ) . volumeMounts ( Arrays . asList ( new V1VolumeMount ( ) . name ( pvName ) . mountPath ( "/shared" ) ) ) . securityContext ( new V1SecurityContext ( ) . runAsGroup ( 0L ) . runAsUser ( 0L ) ) ) ) . containers ( Arrays . asList ( new V1Container ( ) . name ( "create-weblogic-domain-onpv-container" ) . image ( image ) . ports ( Arrays . asList ( new V1ContainerPort ( ) . containerPort ( 7001 ) ) ) . volumeMounts ( Arrays . asList ( new V1VolumeMount ( ) . name ( "create-weblogic-domain-job-cm-volume" ) . mountPath ( "/u01/weblogic" ) , new V1VolumeMount ( ) . name ( pvName ) . mountPath ( "/shared" ) ) ) . addCommandItem ( "/bin/sh" ) . addArgsItem ( "/u01/oracle/oracle_common/common/bin/wlst.sh" ) . addArgsItem ( "/u01/weblogic/create-domain.py" ) . addArgsItem ( "-skipWLSModuleScanning" ) . addArgsItem ( "-loadProperties" ) . addArgsItem ( "/u01/weblogic/domain.properties" ) ) ) . volumes ( Arrays . asList ( new V1Volume ( ) . name ( pvName ) . persistentVolumeClaim ( new V1PersistentVolumeClaimVolumeSource ( ) . claimName ( pvcName ) ) , new V1Volume ( ) . name ( "create-weblogic-domain-job-cm-volume" ) . configMap ( new V1ConfigMapVolumeSource ( ) . name ( domainScriptConfigMapName ) ) ) ) . imagePullSecrets ( isUseSecret ? Arrays . asList ( new V1LocalObjectReference ( ) . name ( OCR_SECRET_NAME ) ) : null ) ) ) ) ; logger . info ( "Running a job {0} to create a domain on PV for domain {1} in namespace {2}" , jobBody . getMetadata ( ) . getName ( ) , domainUid , domainNamespace ) ; createJobAndWaitUntilComplete ( jobBody , domainNamespace ) ; }
Run a job to create a WebLogic domain on a persistent volume by doing the following.
Run a job to create a WebLogic domain on a persistent volume by doing the following .
// try only once // domain creation scripts volume // availble under /u01/weblogic inside pod // location to write domain // mounted under /shared inside pod //call wlst.sh script with py and properties file //ConfigMap containing domain scripts