Changeset 4380


Ignore:
Timestamp:
Aug 6, 2008, 1:30:07 PM (15 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1064: Add support for dry-run to the plug-in system

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/common-queries.xml

    r4376 r4380  
    32523252    </description>
    32533253  </query>
     3254 
     3255  <query id="SET_DRYRUN_ON_JOBS" type="HQL">
     3256    <sql>
     3257      UPDATE JobData job
     3258      SET job.dryRun = false
     3259      WHERE job.dryRun IS NULL
     3260    </sql>
     3261    <description>
     3262      A HQL query that set the dryRun property
     3263      to false on all jobs with a null value.
     3264    </description>
     3265  </query>
    32543266
    32553267
  • trunk/src/core/net/sf/basedb/core/Install.java

    r4379 r4380  
    107107    method.
    108108  */
    109   public static final int NEW_SCHEMA_VERSION = Integer.valueOf(62).intValue();
     109  public static final int NEW_SCHEMA_VERSION = Integer.valueOf(63).intValue();
    110110 
    111111  public static synchronized void createTables(boolean update, final ProgressReporter progress)
  • trunk/src/core/net/sf/basedb/core/Job.java

    r4379 r4380  
    579579 
    580580  /**
     581    Check if the job should be/was executed as a dry-run job.
     582    A dry-run job is a job that does all the things a normal job would
     583    do except committing the changes to the database. The dry-run job
     584    may output a log file with detailed information about what should
     585    have happened if it hadn't been a dry-run.
     586    @since 2.8
     587  */
     588  public boolean isDryRun()
     589  {
     590    return getData().isDryRun();
     591  }
     592   
     593  /**
    581594    The maximum allowed length of the status message.
    582595  */
     
    10581071      parameters in case these has changed since the job was created
    10591072    @throws PermissionDeniedException If the logged in user doesn't have write permission
     1073    @deprecated Use {@link #retry(boolean, boolean)} instead
    10601074  */
    10611075  public void retry(boolean useLatestConfiguration)
     1076    throws PermissionDeniedException
     1077  {
     1078    retry(useLatestConfiguration, false);
     1079  }
     1080 
     1081  /**
     1082    Retry a job which finished with an error or a successful dry-run job.
     1083    @param useLatestConfiguration If the job should use the latest configuration
     1084      parameters in case these has changed since the job was created
     1085    @param clearDryRun If the job was a dry-run job, clear the dry-run flag
     1086      to indicate that it should be executed for real the next time
     1087    @throws PermissionDeniedException If the logged in user doesn't have write permission
     1088  */
     1089  public void retry(boolean useLatestConfiguration, boolean clearDryRun)
    10621090    throws PermissionDeniedException
    10631091  {
     
    10801108      }
    10811109    }
    1082   }
     1110    if (clearDryRun) data.setDryRun(false);
     1111  }
     1112
    10831113 
    10841114  /**
     
    16291659      data.setServer(null);
    16301660      data.setJobAgentId(null);
     1661      data.setDryRun(response.isDryRun());
    16311662      data.setEstimatedExecutionTime(response.getEstimatedExecutionTime().getValue());
    16321663    }
     
    16611692        dc = sc.newDbControl();
    16621693        Job job = Job.getById(dc, jobId);
     1694        job.getData().setDryRun(response.isDryRun());
    16631695
    16641696        if (response.getStatus() == Response.Status.ERROR)
  • trunk/src/core/net/sf/basedb/core/PluginConfigurationRequest.java

    r3679 r4380  
    8686  private Job.ProgressReporterImpl progress;
    8787  private boolean allowImmediateExecution;
     88  private boolean dryRun;
    8889 
    8990  PluginConfigurationRequest(SessionControl sc, InteractivePlugin plugin, String command,
     
    9596    this.context = context;
    9697    this.allowImmediateExecution = allowImmediateExecution;
     98    if (job != null) dryRun = job.isDryRun();
    9799  }
    98100 
     
    107109    boolean allowImmediateDownload = allowImmediateExecution &&
    108110      plugin instanceof ImmediateDownloadExporter;
    109     PluginResponse pluginResponse = new PluginResponse(this, allowImmediateExecution, allowImmediateDownload);
     111    PluginResponse pluginResponse = new PluginResponse(this, allowImmediateExecution, allowImmediateDownload, dryRun);
    110112    Request request = new RequestImpl(allowImmediateExecution);
    111113    Response response = pluginResponse.getResponseImpl();
  • trunk/src/core/net/sf/basedb/core/PluginExecutionRequest.java

    r4078 r4380  
    8686  public PluginResponse invoke()
    8787  {
    88     PluginResponse pluginResponse = new PluginResponse(null, false, false);
     88    PluginResponse pluginResponse = new PluginResponse(null, false, false, getJob().isDryRun());
    8989    Request request = new RequestImpl(false);
    9090    Response response = pluginResponse.getResponseImpl();
  • trunk/src/core/net/sf/basedb/core/PluginResponse.java

    r4379 r4380  
    5959  private Job.ExecutionTime estimatedExecutionTime;
    6060  private String message;
     61  private boolean dryRun;
    6162  private List<? extends Throwable> errorList;
    6263  private String nextCommand;
    6364
    64   PluginResponse(PluginConfigurationRequest request, boolean allowImmediateExection, boolean allowImmediateDownload)
     65  PluginResponse(PluginConfigurationRequest request,
     66    boolean allowImmediateExection, boolean allowImmediateDownload, boolean dryRun)
    6567  {
    6668    this.request = request;
     
    7072    this.allowImmediateExecution = allowImmediateExection;
    7173    this.message = "A response has not been specified by the plugin";
     74    this.dryRun = dryRun;
    7275  }
    7376
     
    7881  {
    7982    return status;
     83  }
     84 
     85  /**
     86    Check if the job should be executed or was executed in
     87    dry-run mode.
     88    @since 2.8
     89  */
     90  public boolean isDryRun()
     91  {
     92    return dryRun;
    8093  }
    8194 
     
    136149 
    137150  /**
    138     aAve all parameters that has been configured during the configuration sequence to
     151    Save all parameters that has been configured during the configuration sequence to
    139152    the database.
    140153    @param dc An open DbControl to use when accessing the database.
     
    290303      PluginResponse.this.errorList = errorList;
    291304    }
     305   
     306    public void setDryRun(boolean dryRun)
     307    {
     308      PluginResponse.this.dryRun = dryRun;
     309    }
    292310    // -------------------------------------------
    293311  }
  • trunk/src/core/net/sf/basedb/core/Update.java

    r4379 r4380  
    712712  </tr>
    713713 
     714  <tr>
     715    <td>63</td>
     716    <td>
     717      Added:
     718      <ul>
     719      <li>{@link net.sf.basedb.core.data.JobData#isDryRun()}.
     720      </ul>
     721      The update will set the value for all existing jobs to false.
     722    </td>
     723  </tr>
     724 
    714725  </table>
    715726
     
    9941005      }
    9951006     
    996       if (schemaVersion < 62)
    997       {
    998         if (progress != null) progress.display((int)(61*progress_factor), "--Updating schema version: " + schemaVersion + " -> 62...");
    999         schemaVersion = setSchemaVersionInTransaction(session, 62);
     1007      if (schemaVersion < 63)
     1008      {
     1009        if (progress != null) progress.display((int)(62*progress_factor), "--Updating schema version: " + schemaVersion + " -> 63...");
     1010        schemaVersion = setSchemaVersionInTransaction(session, 63);
    10001011      }
    10011012     
     
    28902901          HibernateUtil.executeUpdate(query);
    28912902        }
     2903
     2904        if (schemaVersion < 63)
     2905        {
     2906          // Set dryRun = false on all jobs
     2907          org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session,
     2908            "SET_DRYRUN_ON_JOBS");
     2909          /*
     2910            UPDATE JobData job
     2911            SET job.dryRun = false
     2912            WHERE job.dryRun IS NULL
     2913          */
     2914          HibernateUtil.executeUpdate(query);
     2915        }
    28922916       
    28932917        //  Commit the changes
  • trunk/src/core/net/sf/basedb/core/data/JobData.java

    r4379 r4380  
    230230  }
    231231
     232  private boolean dryRun;
     233  /**
     234    If the job should be/was executed as a dry-run job.
     235    @hibernate.property column="`dry_run`" type="boolean" not-null="true"
     236  */
     237  public boolean isDryRun()
     238  {
     239    return dryRun;
     240  }
     241  public void setDryRun(boolean dryRun)
     242  {
     243    this.dryRun = dryRun;
     244  }
     245 
    232246  /**
    233247    The maximum allowed length of the status message.
  • trunk/src/core/net/sf/basedb/core/plugin/Response.java

    r4023 r4380  
    122122 
    123123  /**
     124    A plug-in may call this method in it's configuration phase or
     125    after it has been executed to indicate that the job should be
     126    or was executed as a dry-run job. A dry-run job is a job that
     127    does all the things a normal job would do except committing the
     128    changes to the database. The dry-run job may output a
     129    log file with detailed information about what should have happened
     130    if it hadn't been a dry-run.
     131    <p>
     132    NOTE! Setting this value to true doesn't change the behaviour
     133    of the core. It is the responsibility of the plug-in to check
     134    this value(eg. {@link Job#isDryRun()} and take appropriate action.
     135   
     136    @param dryRun TRUE to indicate that the job should be or was
     137      executed as a dry-run
     138    @since 2.8
     139  */
     140  public void setDryRun(boolean dryRun);
     141 
     142  /**
    124143    This will end the job execution or configuration and report it as a
    125144    failure. If in a configuration sequence the client application may try
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AbstractItemImporter.java

    r4372 r4380  
    345345        // Error handling
    346346        storeValue(job, request, ri.getParameter(Parameters.LOGFILE_PARAMETER));
    347         storeValue(job, request, ri.getParameter(Parameters.DRY_RUN_PARAMETER));
     347        response.setDryRun(Boolean.TRUE.equals(request.getParameterValue(Parameters.DRY_RUN_PARAMETER)));
     348//        storeValue(job, request, ri.getParameter(Parameters.DRY_RUN_PARAMETER));
    348349        storeValue(job, request, defaultErrorParameter);
    349350        storeValue(job, request, itemNotFoundErrorParameter);
     
    453454   
    454455    // Error handling, we don't use the error handling in AbstractFlatFileImporter
    455     this.dryRun = Boolean.TRUE.equals(job.getValue(Parameters.DRY_RUN_PARAMETER));
     456    this.dryRun = job.getJob().isDryRun();
    456457    this.createNotFoundItems = "create".equals(getErrorOption("itemNotFoundError"));
    457458    this.failIfNotFoundItems = "fail".equals(getErrorOption("itemNotFoundError"));
  • trunk/www/views/jobs/index.jsp

    r4127 r4380  
    234234    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
    235235    boolean useLatestConfiguration = Values.getBoolean(request.getParameter("useLatestConfiguration"), false);
     236    boolean clearDryRun = Values.getBoolean(request.getParameter("clearDryRun"), false);
    236237    dc = sc.newDbControl();
    237238    Job job = Job.getById(dc, cc.getId());
    238     job.retry(useLatestConfiguration);
     239    job.retry(useLatestConfiguration, clearDryRun);
    239240    dc.commit();
    240241    redirect = viewPage;
  • trunk/www/views/jobs/list_jobs.jsp

    r4355 r4380  
    279279        datatype="string"
    280280        title="Status message"
     281        sortable="true"
     282        filterable="true"
     283        exportable="true"
     284      />
     285      <tbl:columndef
     286        id="dryRun"
     287        property="dryRun"
     288        datatype="boolean"
     289        title="Dry run"
    281290        sortable="true"
    282291        filterable="true"
     
    594603                <tbl:cell column="status"><%=item.getStatus()%></tbl:cell>
    595604                <tbl:cell column="statusMessage"><%=HTML.encodeTags(item.getStatusMessage())%></tbl:cell>
     605                <tbl:cell column="dryRun"><%=item.isDryRun()%></tbl:cell>
    596606                <tbl:cell column="stackTrace"><%=HTML.encodeTags(item.getStackTrace())%></tbl:cell>
    597607                <tbl:cell column="server"><%=HTML.encodeTags(item.getServer())%></tbl:cell>
  • trunk/www/views/jobs/view_job.jsp

    r4379 r4380  
    153153    }
    154154  }
    155   function restartJob()
     155  function restartJob(clearDryRun)
    156156  {
    157157    var parameterVersion = <%=parameterVersion%>;
     
    167167      if (confirm(msg)) useLatestConfiguration = 1;
    168168    }
    169     location.href = 'index.jsp?ID=<%=ID%>&cmd=RestartJob&item_id=<%=itemId%>&useLatestConfiguration='+useLatestConfiguration;
     169    var url = 'index.jsp?ID=<%=ID%>&cmd=RestartJob&item_id=<%=itemId%>';
     170    url += '&useLatestConfiguration='+useLatestConfiguration;
     171    if (clearDryRun) url += '&clearDryRun=' + clearDryRun;
     172    location.href = url;
    170173  }
    171174  function reconfigureJob()
     
    229232        <td class="prompt">Status</td>
    230233        <td>
    231           <%=job.getStatus()%>: <%=HTML.niceFormat(job.getStatusMessage())%>
     234          <%=job.getStatus()%><%=job.isDryRun() ? " (dry-run)" : "" %>: <%=HTML.niceFormat(job.getStatusMessage())%>
    232235        </td>
    233236      </tr>
     
    531534      {
    532535        %>
    533         <base:button onclick="restartJob()" title="Restart job"
     536        <base:button onclick="restartJob(0)" title="Restart job"
    534537          image="refresh.gif"
    535538          tooltip="Try to run this job again with the same parameters"
     
    539542          tooltip="Change the parameters for this job and try again"
    540543          visible="<%=job.hasContext()%>"
     544        />
     545        <%
     546      }
     547      if (job.getStatus() == Job.Status.DONE && job.isDryRun())
     548      {
     549        %>
     550        <base:button onclick="restartJob(1)" title="Really run"
     551          image="refresh.gif"
     552          tooltip="Run this dry-run job for real"
    541553        />
    542554        <%
Note: See TracChangeset for help on using the changeset viewer.