7 Replies Latest reply on Jan 4, 2017 11:04 AM by cfang

    Display JSL

    richardmoore

      Is there a way to display the JSL before and after variable resolution during a before job listener?

        • 1. Re: Display JSL
          cfang

          not in standard, spec'ed API.

           

          With JBeret internal methods and for debugging purpose, you can inject JobExecution into your listener, get JobInstance from the JobExecution, and get the unsubstituted job from the JobInstance.

           

          @Inject

          JobExecution jobExecution;

           

          JobExecutionImpl exe = (JobExecutionImpl) jobExecution;

          JobInstanceImpl ins = exe.getJobInstance();

          Job job = ins.getUnsubstitutedJob();

           

          //to get the job with resolved variables:

          Job job = exe.getSubstitutedJob();

          • 2. Re: Display JSL
            richardmoore

            I gave it a try but the job ends right at the start. Here is what I have, what did I do wrong -

             

            public class JobStatsListener extends AbstractJobListener {

             

              @Inject

              private JobContext jobContext;

             

              @Inject

              JobExecution jobExecution;

             

              @Override

              public void beforeJob() throws Exception {

              String status = "Starting job: " + jobContext.getJobName();

              if (!System.getProperty("batchJobname").equals(jobContext.getJobName())) {

              String msg = "Batch jobname does not equal JSL jobname (job@id)";

              log.severe(msg);

              throw new RuntimeException(msg);

              }

              log.info(status);

              displayJsl();

              }

             

              private void displayJsl() {

              JobExecutionImpl exe = (JobExecutionImpl) jobExecution;

              JobInstanceImpl ins = exe.getJobInstance();

             

              Job uj = ins.getUnsubstitutedJob();

              log.info("Unsubstituted JSL -");

              log.info(uj.toString());

             

              Job sj = exe.getSubstitutedJob();

              log.info("Substituted JSL -");

              log.info(sj.toString());

              }

            • 3. Re: Display JSL
              cfang

              org.jberet.job.model.Job does not override toString() method.  So your log will not show the content of the job.  You will need to traverse the job elements to see its content.

               

              You mentioined your job execution ended right at the start.  Does your first step has a next attribute, or transition elements?

              • 4. Re: Display JSL
                richardmoore

                Ends which executing:    operator = BatchRuntime.getJobOperator();

                 

                I think it has to do with the job listener because if I comment out the code to get the JobExecutionImpl and so on but leave -

                 

                @Inject

                  JobExecution jobExecution;

                 

                it ends immediately. If I remove this the job executes. Below is the jsl -

                 

                 

                <!DOCTYPE job [

                  <!ENTITY job-listeners SYSTEM "entities/awg-job-listeners.xml">

                  <!ENTITY step-listeners SYSTEM "entities/awg-step-listeners.xml">

                ]>

                       

                <job id="Jberet_Adhoc_SqlTest" version="1.0" xmlns="http://xmlns.jcp.org/xml/ns/javaee">

                 

                  &job-listeners;

                 

                  <step id="test">

                 

                  &step-listeners;

                 

                  <chunk>

                  <reader ref="jdbcItemReader">

                  <properties>

                  <property name="dataSourceLookup" value="jdbc/db2"/>

                  <property name="sql" value="SELECT fclty_cd, fclty_ltr2_cd, fclty_nm, dw_fclty_ltr2_cd, current timestamp as current_ts FROM db2pdba.aim_fclty" />

                  <property name="beanType" value="java.util.Map" />

                  </properties>

                  </reader>

                  <writer ref="jacksonCsvItemWriter">

                  <properties>

                  <property name="resource" value="#{systemProperties['APP_DATA_TMP_FCLTY_SUBSYS']}/Jberet_Adhoc_SqlTest.out" />

                  <property name="writeMode" value="overwrite" />

                  <property name="columnSeparator" value="|" />

                  <property name="beanType" value="java.util.Map" />

                  <property name="useHeader" value="false" />

                  <property name="csvGeneratorFeatures" value="ALWAYS_QUOTE_STRINGS=false, STRICT_CHECK_FOR_QUOTING=true"/>

                  <property name="columns" value="FCLTY_CD STRING, FCLTY_LTR2_CD STRING, FCLTY_NM STRING, DW_FCLTY_LTR2_CD STRING, CURRENT_TS STRING" />

                  </properties>

                  </writer>

                  </chunk>

                 

                  <end on="COMPLETED" />

                  <fail on="*" />

                  </step>

                 

                </job>

                • 5. Re: Display JSL
                  cfang

                  I just realized I made a mistake in my earlier code (sorry): you need to inject JobContext, not JobExecution, and then you can get JobExecutionImpl from JobContext.  So it shoudl be something like:

                  @Inject

                  JobContext jobContext;

                   

                  JobExecutionImpl exe = jobContext.getJobExecution();

                  JobInstanceImpl ins = exe.getJobInstance();

                  Job job = ins.getUnsubstitutedJob();

                   

                  //to get the job with resolved variables:

                  Job job = exe.getSubstitutedJob();

                  • 6. Re: Display JSL
                    richardmoore

                    How do I get to the contents of the step (properties, batchlet/chunk, so on) once I have the following from the Job?

                     

                    private static String toStringJobElements(List<JobElement> elements) {

                      StringBuffer sb = new StringBuffer();

                     

                      for (JobElement element : elements) {

                      sb.append(System.getProperty("line.separator"));

                      @SuppressWarnings("rawtypes")

                      List<Transition> transitions = element.getTransitionElements();

                      if (transitions.isEmpty()) {

                      sb.append("<step id=\"" + element.getId() + "\" />");

                      sb.append(System.getProperty("line.separator"));

                      } else {

                      sb.append("<step id=\"" + element.getId() + "\">");

                      sb.append(toStringTransitions(transitions));     // just the deciders: fail, end, stop, ...

                      sb.append(System.getProperty("line.separator"));

                      sb.append("</step>");

                      }

                      }

                     

                    return sb.toString();

                      }

                    • 7. Re: Display JSL
                      cfang

                      You can check its type with instanceof, for each job element, and then decide how to get their content, and which content you want to get.  For ex,

                       

                      private static void printJob(final List<JobElement> elements) {

                         for (JobElement e : elements) {

                         if (e instanceof Step) {

                        Step step = (Step) e;
                        final Properties stepProperties = step.getProperties();
                        final java.util.Properties stepProperties2 = Properties.toJavaUtilProperties(stepProperties);
                         System.out.printf("step properties: %s%n", stepProperties2);

                        final RefArtifact batchlet = step.getBatchlet();
                         printArtifact(batchlet);

                        final Chunk chunk = step.getChunk();
                        if (chunk != null) {

                         final RefArtifact reader = chunk.getReader();
                         printArtifact(reader);

                        final RefArtifact writer = chunk.getWriter();
                         printArtifact(writer);

                        final RefArtifact processor = chunk.getProcessor();
                         printArtifact(processor);
                         }

                        } else if(e instanceof Decision) {

                       

                        } else if(e instanceof Flow) {

                       

                        } else if(e instanceof Split) {

                       

                        }

                        }

                      }

                       

                      private static void printArtifact(final RefArtifact artifact) {

                         if (artifact == null) {

                         return;
                         }

                         final String ref = artifact.getRef();
                        final Properties properties = artifact.getProperties();
                        final java.util.Properties javaUtilProperties = Properties.toJavaUtilProperties(properties);
                         System.out.printf("%s %s %s%n", artifact.getClass(), ref, javaUtilProperties);
                      }