Changeset 4380 for trunk/src/core/net


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/src/core/net/sf/basedb/core
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.