new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/WLSTUtils.java
public static void createWLSTJob(String wlstJobName, String wlstScriptConfigMapName, String namespace,
                                   V1Container jobContainer) throws ApiException {
    LoggingFacade logger = getLogger();
    logger.info("Running Kubernetes job to execute WLST script");

    V1Job jobBody = new V1Job()
        .metadata(
            new V1ObjectMeta()
                .name(wlstJobName)
                .namespace(namespace))
        .spec(new V1JobSpec()
            .backoffLimit(0) // try only once
            .template(new V1PodTemplateSpec()
                .spec(new V1PodSpec()
                    .restartPolicy("Never")
                    .containers(Arrays.asList(jobContainer
                        .name("execute-wlst-container")
                        .image(image)
                        .imagePullPolicy("IfNotPresent")
                        .volumeMounts(Arrays.asList(
                            new V1VolumeMount()
                                .name("wlst-job-cm-volume") // WLST script volume
                                .mountPath(MOUNT_POINT))))) // mounted under /sctipts inside pod
                    .volumes(Arrays.asList(new V1Volume()
                        .name("wlst-job-cm-volume") // WLST scripts volume
                        .configMap(new V1ConfigMapVolumeSource()
                            .name(wlstScriptConfigMapName)))) //config map containing WLST script
                    .imagePullSecrets(isUseSecret ? Arrays.asList(
                        new V1LocalObjectReference()
                            .name(OCR_SECRET_NAME))
                        : null))));
    String jobName = assertDoesNotThrow(()
        -> createNamespacedJob(jobBody), "Failed to create WLST execution Job");

    logger.info("Checking if the WLST job {0} completed in namespace {1}",
        jobName, namespace);
    withStandardRetryPolicy
        .conditionEvaluationListener(
            condition -> logger.info("Waiting for job {0} to be completed in namespace {1} "
                    + "(elapsed time {2} ms, remaining time {3} ms)",
                jobName,
                namespace,
                condition.getElapsedTimeInMS(),
                condition.getRemainingTimeInMS()))
        .until(jobCompleted(jobName, null, namespace));

    // check job status and fail test if the job failed to execute WLST
    V1Job job = getJob(jobName, namespace);
    if (job != null) {
      V1JobCondition jobCondition = job.getStatus().getConditions().stream().filter(
          v1JobCondition -> "Failed".equalsIgnoreCase(v1JobCondition.getType()))
          .findAny()
          .orElse(null);
      if (jobCondition != null) {
        logger.severe("Job {0} failed to execute WLST script", jobName);
        List<V1Pod> pods = listPods(namespace, "job-name=" + jobName).getItems();
        if (!pods.isEmpty()) {
          logger.severe(getPodLog(pods.get(0).getMetadata().getName(), namespace));
          fail("WLST execute job failed");
        }
      }
      List<V1Pod> pods = listPods(namespace, "job-name=" + jobName).getItems();
      if (!pods.isEmpty()) {
        logger.info(getPodLog(pods.get(0).getMetadata().getName(), namespace));
      }
    }
  }
/**
   * Create a job to execute WLST script.
   *
   * @param wlstJobName a unique job name
   * @param wlstScriptConfigMapName configmap holding WLST script file
   * @param namespace name of the namespace in which the job is created
   * @param jobContainer V1Container with job commands to execute WLST script
   * @throws ApiException when Kubernetes cluster query fails
   */
Create a job to execute WLST script.
Create a job to execute WLST script .
public static void createWLSTJob(String wlstJobName, String wlstScriptConfigMapName, String namespace,
                                   V1Container jobContainer) throws ApiException {
    LoggingFacade logger = getLogger();
    logger.info("Running Kubernetes job to execute WLST script");
    V1Job jobBody = new V1Job()
        .metadata(
            new V1ObjectMeta()
                .name(wlstJobName)
                .namespace(namespace))
        .spec(new V1JobSpec()
            .backoffLimit(0) 
            .template(new V1PodTemplateSpec()
                .spec(new V1PodSpec()
                    .restartPolicy("Never")
                    .containers(Arrays.asList(jobContainer
                        .name("execute-wlst-container")
                        .image(image)
                        .imagePullPolicy("IfNotPresent")
                        .volumeMounts(Arrays.asList(
                            new V1VolumeMount()
                                .name("wlst-job-cm-volume") 
                                .mountPath(MOUNT_POINT))))) 
                    .volumes(Arrays.asList(new V1Volume()
                        .name("wlst-job-cm-volume") 
                        .configMap(new V1ConfigMapVolumeSource()
                            .name(wlstScriptConfigMapName)))) 
                    .imagePullSecrets(isUseSecret ? Arrays.asList(
                        new V1LocalObjectReference()
                            .name(OCR_SECRET_NAME))
                        : null))));
    String jobName = assertDoesNotThrow(()
        -> createNamespacedJob(jobBody), "Failed to create WLST execution Job");
    logger.info("Checking if the WLST job {0} completed in namespace {1}",
        jobName, namespace);
    withStandardRetryPolicy
        .conditionEvaluationListener(
            condition -> logger.info("Waiting for job {0} to be completed in namespace {1} "
                    + "(elapsed time {2} ms, remaining time {3} ms)",
                jobName,
                namespace,
                condition.getElapsedTimeInMS(),
                condition.getRemainingTimeInMS()))
        .until(jobCompleted(jobName, null, namespace));
    V1Job job = getJob(jobName, namespace);
    if (job != null) {
      V1JobCondition jobCondition = job.getStatus().getConditions().stream().filter(
          v1JobCondition -> "Failed".equalsIgnoreCase(v1JobCondition.getType()))
          .findAny()
          .orElse(null);
      if (jobCondition != null) {
        logger.severe("Job {0} failed to execute WLST script", jobName);
        List<V1Pod> pods = listPods(namespace, "job-name=" + jobName).getItems();
        if (!pods.isEmpty()) {
          logger.severe(getPodLog(pods.get(0).getMetadata().getName(), namespace));
          fail("WLST execute job failed");
        }
      }
      List<V1Pod> pods = listPods(namespace, "job-name=" + jobName).getItems();
      if (!pods.isEmpty()) {
        logger.info(getPodLog(pods.get(0).getMetadata().getName(), namespace));
      }
    }
  }
public static void createWLSTJob ( String wlstJobName , String wlstScriptConfigMapName , String namespace , V1Container jobContainer ) throws ApiException { LoggingFacade logger = getLogger ( ) ; logger . info ( "Running Kubernetes job to execute WLST script" ) ; V1Job jobBody = new V1Job ( ) . metadata ( new V1ObjectMeta ( ) . name ( wlstJobName ) . namespace ( namespace ) ) . spec ( new V1JobSpec ( ) . backoffLimit ( 0 ) . template ( new V1PodTemplateSpec ( ) . spec ( new V1PodSpec ( ) . restartPolicy ( "Never" ) . containers ( Arrays . asList ( jobContainer . name ( "execute-wlst-container" ) . image ( image ) . imagePullPolicy ( "IfNotPresent" ) . volumeMounts ( Arrays . asList ( new V1VolumeMount ( ) . name ( "wlst-job-cm-volume" ) . mountPath ( MOUNT_POINT ) ) ) ) ) . volumes ( Arrays . asList ( new V1Volume ( ) . name ( "wlst-job-cm-volume" ) . configMap ( new V1ConfigMapVolumeSource ( ) . name ( wlstScriptConfigMapName ) ) ) ) . imagePullSecrets ( isUseSecret ? Arrays . asList ( new V1LocalObjectReference ( ) . name ( OCR_SECRET_NAME ) ) : null ) ) ) ) ; String jobName = assertDoesNotThrow ( ( ) -> createNamespacedJob ( jobBody ) , "Failed to create WLST execution Job" ) ; logger . info ( "Checking if the WLST job {0} completed in namespace {1}" , jobName , namespace ) ; withStandardRetryPolicy . conditionEvaluationListener ( condition -> logger . info ( "Waiting for job {0} to be completed in namespace {1} " + "(elapsed time {2} ms, remaining time {3} ms)" , jobName , namespace , condition . getElapsedTimeInMS ( ) , condition . getRemainingTimeInMS ( ) ) ) . until ( jobCompleted ( jobName , null , namespace ) ) ; V1Job job = getJob ( jobName , namespace ) ; if ( job != null ) { V1JobCondition jobCondition = job . getStatus ( ) . getConditions ( ) . stream ( ) . filter ( v1JobCondition -> "Failed" . equalsIgnoreCase ( v1JobCondition . getType ( ) ) ) . findAny ( ) . orElse ( null ) ; if ( jobCondition != null ) { logger . severe ( "Job {0} failed to execute WLST script" , jobName ) ; List < V1Pod > pods = listPods ( namespace , "job-name=" + jobName ) . getItems ( ) ; if ( ! pods . isEmpty ( ) ) { logger . severe ( getPodLog ( pods . get ( 0 ) . getMetadata ( ) . getName ( ) , namespace ) ) ; fail ( "WLST execute job failed" ) ; } } List < V1Pod > pods = listPods ( namespace , "job-name=" + jobName ) . getItems ( ) ; if ( ! pods . isEmpty ( ) ) { logger . info ( getPodLog ( pods . get ( 0 ) . getMetadata ( ) . getName ( ) , namespace ) ) ; } } }
Create a job to execute WLST script.
Create a job to execute WLST script .
// try only once // WLST script volume // mounted under /sctipts inside pod // WLST scripts volume //config map containing WLST script // check job status and fail test if the job failed to execute WLST