Changeset 5406
- Timestamp:
- Sep 13, 2010, 12:36:49 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/common-queries.xml
r5403 r5406 1556 1556 AND job.type = :type 1557 1557 AND job.removed = false 1558 ORDER BY job.priority ASC, job. created ASC1558 ORDER BY job.priority ASC, job.scheduled ASC 1559 1559 </sql> 1560 1560 <description> 1561 1561 A Hibernate query that loads plugin jobs in the job queue waiting to be 1562 executed sorted by priority and waiting t ype. The query should return all1562 executed sorted by priority and waiting time. The query should return all 1563 1563 jobs, ignoring all settings specifying that the internal job queue should 1564 1564 not be used. … … 1575 1575 AND job.pluginDefinition.useInternalJobQueue = true 1576 1576 AND job.jobAgentId IS NULL 1577 ORDER BY job.priority ASC, job. created ASC1577 ORDER BY job.priority ASC, job.scheduled ASC 1578 1578 </sql> 1579 1579 <description> … … 3873 3873 </query> 3874 3874 3875 <query id="SET_SCHEDULED_FOR_JOBS" type="HQL"> 3876 <sql> 3877 UPDATE JobData job 3878 SET job.scheduled = job.created 3879 WHERE job.status > 1 AND job.scheduled IS NULL 3880 </sql> 3881 <description> 3882 An HQL update-query that sets the scheduled date 3883 to the creation date for existing jobs that have been 3884 scheduled and doesn't have a scheduled date. 3885 </description> 3886 </query> 3887 3888 3875 3889 </predefined-queries> -
trunk/src/core/net/sf/basedb/core/Install.java
r5405 r5406 115 115 method. 116 116 */ 117 public static final int NEW_SCHEMA_VERSION = Integer.valueOf(8 3).intValue();117 public static final int NEW_SCHEMA_VERSION = Integer.valueOf(84).intValue(); 118 118 119 119 public static synchronized void createTables(boolean update, final ProgressReporter progress) -
trunk/src/core/net/sf/basedb/core/InternalJobQueue.java
r5399 r5406 317 317 [AND job.pluginDefinition.useInternalJobQueue = true] 318 318 [AND job.jobAgentId IS NULL] 319 ORDER BY job.priority ASC, job. created ASC319 ORDER BY job.priority ASC, job.scheduled ASC 320 320 */ 321 321 query.setInteger("status", Job.Status.WAITING.getValue()); -
trunk/src/core/net/sf/basedb/core/Job.java
r5405 r5406 353 353 getData().setActiveProjectId(projectId); 354 354 } 355 if (action == Action.CREATE && getStatus() == Status.WAITING) 356 { 357 getData().setScheduled(new Date()); 358 } 355 359 } 356 360 … … 673 677 } 674 678 679 /** 680 Get the date and time the job was scheduled to the job queue. 681 @return A date, or null if the job hasn't been scheduled 682 @since 2.16 683 */ 684 public Date getScheduled() 685 { 686 return DateUtil.copy(getData().getScheduled()); 687 } 688 675 689 /** 676 690 Get the date and time the job was started. … … 1093 1107 data.setStatus(Job.Status.WAITING.getValue()); 1094 1108 data.setPercentComplete(0); 1109 data.setScheduled(new Date()); 1095 1110 data.setStarted(null); 1096 1111 data.setEnded(null); … … 1124 1139 job is started, if not given {@link Request#COMMAND_EXECUTE} 1125 1140 is used 1141 @param isShuttingDown TRUE if the system is currently shutting down 1142 (which means that the 'scheduled' data is not reset to allow the 1143 job to be started first once the system is up and running) 1126 1144 @since 2.16 1127 1145 */ 1128 void continueLater(String executeCommand )1146 void continueLater(String executeCommand, boolean isShuttingDown) 1129 1147 { 1130 1148 JobData data = getData(); 1131 1149 data.setStatus(Job.Status.WAITING.getValue()); 1132 1150 data.setPercentComplete(0); 1151 if (!isShuttingDown) data.setScheduled(new Date()); 1133 1152 data.setStarted(null); 1134 1153 data.setEnded(null); … … 1366 1385 } 1367 1386 getData().setStatus(Status.WAITING.getValue()); 1387 getData().setScheduled(new Date()); 1368 1388 setParameterValuesInternal(name, label, description, parameterType, Arrays.asList(value), true); 1369 1389 } … … 1417 1437 } 1418 1438 getData().setStatus(Status.WAITING.getValue()); 1439 getData().setScheduled(new Date()); 1419 1440 setParameterValuesInternal(name, label, description, parameterType, values, true); 1420 1441 } … … 1684 1705 JobData data = job.getData(); 1685 1706 data.setStatus(Job.Status.WAITING.getValue()); 1707 data.setScheduled(new Date()); 1686 1708 data.setPercentComplete(0); 1687 1709 data.setStarted(null); … … 1719 1741 } 1720 1742 1721 void setEnded(PluginResponse response )1743 void setEnded(PluginResponse response, boolean isShuttingDown) 1722 1744 { 1723 1745 DbControl dc = null; … … 1735 1757 { 1736 1758 // The job will be continue again when the system restarts 1737 job.continueLater(response.getNextCommand() );1759 job.continueLater(response.getNextCommand(), isShuttingDown); 1738 1760 } 1739 1761 else -
trunk/src/core/net/sf/basedb/core/JobAgent.java
r5384 r5406 390 390 AND job.status = Job.Status.WAITING 391 391 AND job.jobAgentId IS NULL OR job.jobAgentId = this.id 392 ORDER BY job.priority - jas.priorityBoost ASC, job. created ASC392 ORDER BY job.priority - jas.priorityBoost ASC, job.scheduled ASC 393 393 */ 394 394 … … 512 512 513 513 // Order by the waiting time 514 query.order(Orders.asc(Hql.property(" created")));514 query.order(Orders.asc(Hql.property("scheduled"))); 515 515 516 516 return query; -
trunk/src/core/net/sf/basedb/core/PluginExecutionRequest.java
r4889 r5406 27 27 import net.sf.basedb.core.plugin.Request; 28 28 import net.sf.basedb.core.plugin.Response; 29 import net.sf.basedb.core.signal.DelegatingSignalHandler; 30 import net.sf.basedb.core.signal.Signal; 29 31 import net.sf.basedb.core.signal.SignalHandler; 30 32 import net.sf.basedb.core.signal.SignalReceiver; … … 88 90 Request request = new RequestImpl(false); 89 91 Response response = pluginResponse.getResponseImpl(); 90 SignalHandler signalHandler = null; 92 DelegatingSignalHandler signalHandler = null; 93 boolean isShutdown = false; 91 94 Pinger pinger = null; 92 95 try … … 98 101 { 99 102 // Register a signal handler, receiver and transporter 100 signalHandler = ((SignalTarget)plugin).getSignalHandler(); 101 if (signalReceiver != null && signalHandler != null) 103 // We wrap the signal handler in a DelegatingSignalHandler 104 // since we need to know if the SHUTDOWN signal has been sent 105 SignalHandler sh = ((SignalTarget)plugin).getSignalHandler(); 106 if (signalReceiver != null && sh != null) 102 107 { 108 signalHandler = new DelegatingSignalHandler(sh); 103 109 signalId = signalReceiver.registerSignalHandler(signalHandler); 104 110 signalTransporter = signalReceiver.getSignalTransporterClass(); … … 123 129 } 124 130 done(); 125 if (progress != null) progress.setEnded(pluginResponse );131 if (progress != null) progress.setEnded(pluginResponse, signalHandler.hasReceived(Signal.SHUTDOWN)); 126 132 return pluginResponse; 127 133 } -
trunk/src/core/net/sf/basedb/core/Update.java
r5405 r5406 908 908 </td> 909 909 </tr> 910 <tr> 911 <td>84</td> 912 <td> 913 Added {@link JobData#getScheduled()}. The update will set the scheduled 914 date to the creation date for all existing jobs that is in WAITING status 915 or higher. 916 </td> 917 </tr> 910 918 </table> 911 919 … … 1238 1246 schemaVersion = setSchemaVersionInTransaction(session, 83); 1239 1247 } 1240 1248 1249 if (schemaVersion < 84) 1250 { 1251 if (progress != null) progress.display((int)(83*progress_factor), 1252 "--Updating schema version: " + schemaVersion + " -> 84..."); 1253 schemaVersion = updateToSchemaVersion84(session); 1254 } 1255 1241 1256 sc.logout(); 1242 1257 if (progress != null) progress.display(100, "Database updated successfully."); … … 2865 2880 if (tx != null) HibernateUtil.rollback(tx); 2866 2881 log.error("updateToSchemaVersion80: FAILED", ex); 2882 throw ex; 2883 } 2884 return schemaVersion; 2885 } 2886 2887 /** 2888 Set the scheduled data for existing jobs. 2889 */ 2890 private static int updateToSchemaVersion84(org.hibernate.Session session) 2891 throws BaseException 2892 { 2893 final int schemaVersion = 84; 2894 org.hibernate.Transaction tx = null; 2895 try 2896 { 2897 tx = HibernateUtil.newTransaction(session); 2898 2899 // Load and execute the query 2900 org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, "SET_SCHEDULED_FOR_JOBS"); 2901 /* 2902 UPDATE JobData job 2903 SET job.scheduled = job.created 2904 WHERE job.status > WAITING (=1) AND job.scheduled IS NULL 2905 */ 2906 query.executeUpdate(); 2907 2908 // Update the schema version number 2909 setSchemaVersion(session, schemaVersion); 2910 2911 // Commit the changes 2912 HibernateUtil.commit(tx); 2913 log.info("updateToSchemaVersion84: OK"); 2914 } 2915 catch (BaseException ex) 2916 { 2917 if (tx != null) HibernateUtil.rollback(tx); 2918 log.error("updateToSchemaVersion84: FAILED", ex); 2867 2919 throw ex; 2868 2920 } -
trunk/src/core/net/sf/basedb/core/data/JobData.java
r5405 r5406 371 371 } 372 372 373 private Date scheduled; 374 /** 375 Get the date and time the job was scheduled to the job queue, or null 376 if it hasn't been scheduled yet. This timestamp should be updated whenever 377 the status is changed to WAITING. 378 @hibernate.property column="`scheduled`" type="timestamp" not-null="false" 379 @since 2.16 380 */ 381 public Date getScheduled() 382 { 383 return scheduled; 384 } 385 public void setScheduled(Date scheduled) 386 { 387 this.scheduled = scheduled; 388 } 389 373 390 private Date started; 374 391 /** -
trunk/src/core/net/sf/basedb/core/signal/DelegatingSignalHandler.java
r5384 r5406 22 22 package net.sf.basedb.core.signal; 23 23 24 import java.util.ArrayList; 24 25 import java.util.Collection; 25 26 import java.util.Collections; … … 27 28 import java.util.HashSet; 28 29 import java.util.Iterator; 30 import java.util.List; 29 31 import java.util.Map; 30 32 import java.util.Set; … … 53 55 */ 54 56 private Map<Signal, Set<SignalHandler>> handlers; 57 58 /** 59 List holding received signals. 60 @since 2.16 61 */ 62 private final List<Signal> received; 55 63 56 64 /** … … 63 71 super(); 64 72 handlers = new HashMap<Signal, Set<SignalHandler>>(); 73 received = Collections.synchronizedList(new ArrayList<Signal>()); 74 } 75 76 /** 77 Create a new delegating signal handler and register the 78 given handlers as delegates. 79 @param handlers An array with signal handlers that signal should 80 be delegated to 81 @since 2.16 82 */ 83 public DelegatingSignalHandler(SignalHandler... handlers) 84 { 85 this(); 86 for (SignalHandler sh : handlers) 87 { 88 registerSignalHandler(sh); 89 } 65 90 } 66 91 … … 104 129 throw new UnsupportedSignalException(signal); 105 130 } 131 received.add(signal); 106 132 for (SignalHandler handler : all) 107 133 { … … 153 179 } 154 180 181 /** 182 Check if any signals has been received by this handler. 183 @return TRUE if at least one signal has been received, FALSE otherwise 184 @since 2.16 185 */ 186 public boolean hasReceivedSignals() 187 { 188 return received.size() > 0; 189 } 190 191 /** 192 Get the list of received signals. Calling this method clears the internal 193 list and if no signals are received in the meantime, the next call to 194 this method will return null. 195 @return A list with signals in the order they were 196 received, or null if no signals has been received 197 @since 2.16 198 */ 199 public List<Signal> getReceivedSignals() 200 { 201 List<Signal> toReturn = null; 202 if (received.size() > 0) 203 { 204 toReturn = new ArrayList<Signal>(received); 205 received.clear(); 206 } 207 return toReturn; 208 } 209 210 /** 211 Check if the given signal has been received by this signal handler. 212 @param signal The signal to check for 213 @return TRUE if the signal has been received, FALSE otherwise 214 @since 2.16 215 */ 216 public boolean hasReceived(Signal signal) 217 { 218 return received.contains(signal); 219 } 220 221 155 222 } -
trunk/www/views/jobs/index.jsp
r4889 r5406 56 56 <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> 57 57 <%! 58 private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,pluginType,percentComplete,status,statusMessage,description"); 58 private static final ItemContext defaultContext = Base.createDefaultContext("scheduled", "name,pluginType,scheduled,percentComplete,status,statusMessage,description"); 59 { 60 defaultContext.setSortDirection(ItemContext.SortDirection.DESC); 61 } 59 62 private static final Item itemType = Item.JOB; 60 63 %> -
trunk/www/views/jobs/list_jobs.jsp
r5351 r5406 345 345 datatype="date" 346 346 title="Created" 347 sortable="true" 348 filterable="true" 349 exportable="true" 350 formatter="<%=dateTimeFormatter%>" 351 /> 352 <tbl:columndef 353 id="scheduled" 354 property="scheduled" 355 datatype="date" 356 title="Scheduled" 347 357 sortable="true" 348 358 filterable="true" … … 644 654 </tbl:cell> 645 655 <tbl:cell column="created" value="<%=item.getCreated()%>" /> 656 <tbl:cell column="scheduled" value="<%=item.getScheduled()%>" /> 646 657 <tbl:cell column="started" value="<%=item.getStarted()%>" /> 647 658 <tbl:cell column="ended" value="<%=item.getEnded()%>" /> -
trunk/www/views/jobs/view_job.jsp
r5404 r5406 378 378 <td> 379 379 <%=dateTimeFormatter.format(job.getCreated())%> 380 </td> 381 </tr> 382 <tr valign="top"> 383 <td class="prompt">Scheduled</td> 384 <td> 385 <%=dateTimeFormatter.format(job.getScheduled())%> 380 386 </td> 381 387 </tr>
Note: See TracChangeset
for help on using the changeset viewer.