Changeset 6432
- Timestamp:
- Mar 14, 2014, 8:23:38 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/core-extensions.xml
r6424 r6432 152 152 </extension-point> 153 153 154 <extension-point 155 id="net.sf.basedb.core.signal.job"> 156 <action-class>net.sf.basedb.core.signal.SignalHandler</action-class> 157 <name>Job signal handler</name> 158 <description> 159 Extension point for sending signals to jobs. Intended for jobs 160 running on external servers outside of direct control for BASE. 161 The ClientContext is populated with the current SessionControl and 162 Job item, and the "signal-uri" attribute is set to the URI registered 163 with Job.setSignalTransporter. It is recommended that implementations 164 return quickly. If the action takes a long time the handler should spawn 165 a new thread. 166 </description> 167 </extension-point> 168 154 169 <extension 155 170 id="net.sf.basedb.core.uri.http-connection-manager" -
trunk/src/core/net/sf/basedb/core/Install.java
r6424 r6432 118 118 method. 119 119 */ 120 public static final int NEW_SCHEMA_VERSION = Integer.valueOf(11 5).intValue();120 public static final int NEW_SCHEMA_VERSION = Integer.valueOf(116).intValue(); 121 121 122 122 public static synchronized int createTables(SchemaGenerator.Mode mode, ProgressReporter progress, -
trunk/src/core/net/sf/basedb/core/Job.java
r6127 r6432 29 29 import net.sf.basedb.core.data.PluginConfigurationData; 30 30 import net.sf.basedb.core.data.PluginDefinitionData; 31 32 31 import net.sf.basedb.core.plugin.Plugin; 33 32 import net.sf.basedb.core.plugin.InteractivePlugin; … … 36 35 import net.sf.basedb.core.plugin.Response; 37 36 import net.sf.basedb.core.plugin.Plugin.MainType; 37 import net.sf.basedb.core.signal.ExtensionSignalTransporter; 38 38 import net.sf.basedb.core.signal.Signal; 39 39 import net.sf.basedb.core.signal.SignalTransporter; 40 import net.sf.basedb.util.extensions.ClientContext; 40 41 41 42 import java.util.Collection; … … 396 397 397 398 /** 399 The maximum allowed length of the external ID. 400 @since 3.3 401 */ 402 public static final int MAX_EXTERNAL_ID_LENGTH = JobData.MAX_EXTERNAL_ID_LENGTH; 403 404 /** 405 Get the external ID of a job running on an external server. 406 @since 3.3 407 */ 408 public String getExternalId() 409 { 410 return getData().getExternalId(); 411 } 412 /** 413 Set the external ID. 414 @since 3.3 415 */ 416 public void setExternalId(String externalId) 417 { 418 checkPermission(Permission.WRITE); 419 getData().setExternalId(StringUtil.setNullableString(externalId, "externalId", MAX_EXTERNAL_ID_LENGTH)); 420 } 421 422 /** 398 423 Get the type of job, ie. if it is a job executed by a plugin 399 424 or not. … … 836 861 Note 3! This method always returns the same transporter instance if 837 862 it is called multiple times. 863 <p> 864 Note 4! If the signal transporter is a {@link ExtensionSignalTransporter} 865 the extension point is "net.sf.basedb.core.signal.job". The client 866 context is populated with a {@link SessionControl} and the current item 867 is this {@link Job}. The information in the job should be considered read-only, 868 if the signal handler wants to update information it must create a new 869 {@link DbControl} from the session control and re-load the job. 838 870 839 871 @return An initialised signal transporter object, or null … … 858 890 SignalTransporter transporter = (SignalTransporter)Class.forName(transporterClass).newInstance(); 859 891 transporter.init(initParams); 892 893 if (transporter instanceof ExtensionSignalTransporter) 894 { 895 ExtensionSignalTransporter xtTransporter = (ExtensionSignalTransporter)transporter; 896 ClientContext context = new ClientContext(getSessionControl(), this); 897 xtTransporter.setContext(context); 898 xtTransporter.setExtensionPointId("net.sf.basedb.core.signal.job"); 899 } 900 860 901 signalTransporter = new JobSignalTransporter(transporter); 861 902 } … … 870 911 871 912 /** 913 Request that the underlying job updates the status information about 914 itself. This method is intended to be used for external jobs that 915 are not BASE plug-ins (which can report progress through the plug-in API). 916 917 This method sends a {@link Signal#STATUS} signal to the 918 {@link SignalTransporter} that has been registered for the job. 919 If there is no signal transporter this method does nothing. 920 921 The signal transporter should deliver the signal as quickly as possible 922 and then return. The actual progress update may take place at a later 923 time when it is convenient to do so for the job. 924 925 @return TRUE if a {@link Signal#STATUS} could be sent, FALSE if not 926 @since 3.3 927 */ 928 public boolean requestStatusUpdate() 929 { 930 boolean signalSent = false; 931 if (hasSignalTransporter()) 932 { 933 try 934 { 935 SignalTransporter transporter = getSignalTransporter(); 936 Collection<Signal> supported = transporter.getSupportedSignals(); 937 if (supported == null || supported.contains(Signal.STATUS)) 938 { 939 transporter.send(Signal.STATUS); 940 signalSent = true; 941 } 942 } 943 catch (RuntimeException ex) 944 { 945 ex.printStackTrace(); 946 } 947 } 948 return signalSent; 949 } 950 951 952 /** 872 953 Get the date and time the job ended. 873 954 @return A date, or null if the job hasn't ended … … 879 960 880 961 /** 962 Set the job's status to {@link Status#WAITING}. This status is 963 used to signal that a job has been fully configured and is ready 964 for execution. 965 966 @param server Name of the server which this job will executed on 967 @param agent The job agent that is going to execute the 968 job or null if it is executed by something else, eg. the 969 internal job queue 970 @throws PermissionDeniedException If the logged in user doesn't have write permission. 971 @since 3.3 972 */ 973 public void setScheduled(String server, JobAgent agent) 974 throws PermissionDeniedException 975 { 976 checkPermission(Permission.WRITE); 977 Job.Status status = getStatus(); 978 if (status != Status.UNCONFIGURED) 979 { 980 throw new PermissionDeniedException("Can't schedule a job with status '"+getStatus()+"': "+toString()); 981 } 982 JobData data = getData(); 983 data.setScheduled(new Date()); 984 data.setStatus(Status.WAITING.getValue()); 985 data.setServer(StringUtil.setNullableString(server, "server", MAX_SERVER_LENGTH)); 986 getData().setJobAgentId(agent == null ? null : agent.getId()); 987 } 988 989 /** 881 990 Set the job's status to {@link Status#PREPARED}. This status is 882 used to signal that a job is about to be executed, but the actual ex cecution991 used to signal that a job is about to be executed, but the actual execution 883 992 hasn't started yet. This status prevents two job agents from trying to 884 993 start the same job twice. … … 1350 1459 throw new PermissionDeniedException("Cannot configure an executing job: "+toString()); 1351 1460 } 1352 getData().setStatus(Status.WAITING.getValue());1353 getData().setScheduled(new Date());1461 //getData().setStatus(Status.WAITING.getValue()); 1462 //getData().setScheduled(new Date()); 1354 1463 setParameterValuesInternal(name, label, description, parameterType, Arrays.asList(value), true); 1355 1464 } … … 1402 1511 throw new PermissionDeniedException("Cannot configure an executing job: "+toString()); 1403 1512 } 1404 getData().setStatus(Status.WAITING.getValue());1405 getData().setScheduled(new Date());1513 //getData().setStatus(Status.WAITING.getValue()); 1514 //getData().setScheduled(new Date()); 1406 1515 setParameterValuesInternal(name, label, description, parameterType, values, true); 1407 1516 } -
trunk/src/core/net/sf/basedb/core/Update.java
r6424 r6432 208 208 </td> 209 209 </tr> 210 211 <tr> 212 <td>116</td> 213 <td> 214 Added {@link JobData#getExternalId()}. No special database update is needed. Only increase 215 the schema version. 216 </td> 217 </tr> 210 218 </table> 211 219 … … 340 348 } 341 349 342 if (schemaVersion < 11 5)343 { 344 if (progress != null) progress.display((int)(progress_current), "--Updating schema version: " + schemaVersion + " -> 11 5...");345 // Schemaversion 115 only updates the version number346 schemaVersion = setSchemaVersionInTransaction(session, 11 5);347 progress_current += progress_step;350 if (schemaVersion < 116) 351 { 352 if (progress != null) progress.display((int)(progress_current), "--Updating schema version: " + schemaVersion + " -> 116..."); 353 // Schemaversion 115 and 116 only updates the version number 354 schemaVersion = setSchemaVersionInTransaction(session, 116); 355 progress_current += 2 * progress_step; 348 356 } 349 357 -
trunk/src/core/net/sf/basedb/core/data/JobData.java
r6127 r6432 105 105 } 106 106 107 /** 108 The maximum allowed length of the external ID. 109 @since 3.3 110 */ 111 public static final int MAX_EXTERNAL_ID_LENGTH = 255; 112 private String externalId; 113 /** 114 External ID of a job running on an external system. 115 @hibernate.property column="`external_id`" type="string" length="255" not-null="false" 116 @since 3.3 117 */ 118 public String getExternalId() 119 { 120 return externalId; 121 } 122 public void setExternalId(String externalId) 123 { 124 this.externalId = externalId; 125 } 126 107 127 private PluginDefinitionData pluginDefinition; 108 128 /** -
trunk/src/core/net/sf/basedb/core/signal/LocalSignalReceiver.java
r6127 r6432 114 114 { 115 115 logger.info("Receiving signal " + signal.getId() + " to " + handlerId); 116 SignalHandler handler = super.getSignalHandler(handlerId);116 SignalHandler handler = getSignalHandler(handlerId); 117 117 if (handler != null) handler.handleSignal(signal); 118 118 } -
trunk/src/core/net/sf/basedb/core/signal/Signal.java
r5399 r6432 68 68 ); 69 69 70 /** 71 The STATUS signal, that requests that the receiver should 72 update the status on the system. This signal is typically sent 73 to a job managed by an external job manager when someone 74 on the BASE side want to have an update about the progress. 75 @since 3.3 76 */ 77 public static final Signal STATUS = 78 registerSignal("STATUS", "Status", 79 "Sending this signal indicates that the system wants a status " + 80 "update from the receiver. Exactly what this means is up to the sender " + 81 "and reciever to agree on. Typically, this signal can be sent to external " + 82 "job managers when someone on the BASE side wants to have an update about the progress." 83 ); 70 84 71 85 /** -
trunk/src/core/net/sf/basedb/core/signal/SignalHandler.java
r4516 r6432 24 24 import java.util.Collection; 25 25 26 import net.sf.basedb.util.extensions.Action; 27 26 28 /** 27 29 A signal handler is an object that is able to receive and act on signals. … … 41 43 */ 42 44 public interface SignalHandler 45 extends Action 43 46 { 44 47 /** 45 Handle the given signal. 48 Handle the given signal. It is recommended that signals are handled 49 as quickly as possible. If there is a risk that it may take a long time 50 it is recommended to spawn a new thread and handle the signal asynchronously. 46 51 @param signal The signal to handle 47 52 @throws UnsupportedSignalException If the signal is not supported -
trunk/www/views/jobs/ajax.jsp
r6124 r6432 51 51 dc = sc.newDbControl(); 52 52 Job job = Job.getById(dc, itemId); 53 job.requestStatusUpdate(); 53 54 json.put("id", job.getId()); 54 55 json.put("jobStatus", job.getStatus().name()); -
trunk/www/views/jobs/index.jsp
r6192 r6432 263 263 dc = sc.newDbControl(); 264 264 Job job = Job.getById(dc, cc.getId()); 265 if (job.getStatus() == Job.Status.WAITING) 266 { 267 job.doneError("Aborted by user"); 265 SignalTransporter signalTransporter = job.getSignalTransporter(); 266 if (signalTransporter == null) 267 { 268 if (job.getStatus() == Job.Status.WAITING) 269 { 270 job.doneError("Aborted by user"); 271 } 268 272 } 269 273 else 270 274 { 271 SignalTransporter signalTransporter = job.getSignalTransporter(); 272 if (signalTransporter != null) signalTransporter.send(Signal.ABORT); 275 signalTransporter.send(Signal.ABORT); 273 276 } 274 277 dc.commit(); -
trunk/www/views/jobs/view_job.jsp
r6378 r6432 162 162 } 163 163 164 // Check if the plug-in supports the "Abort" signal 165 boolean supportsAbort = status == Job.Status.WAITING && writePermission; 166 if (status == Job.Status.EXECUTING && writePermission) 164 // Check if the job can be aborted 165 boolean supportsAbort = false; 166 167 // The status must be executable or EXECUTING 168 if ((status == Job.Status.EXECUTING || status.isExecutable()) && writePermission) 167 169 { 170 // Check if a signal-transporter exists 168 171 try 169 172 { 170 173 SignalTransporter signalTransporter = job.getSignalTransporter(); 171 Collection<Signal> supportedSignals = signalTransporter != null ? 172 signalTransporter.getSupportedSignals() : null; 173 supportsAbort = signalTransporter != null && 174 (supportedSignals == null || supportedSignals.contains(Signal.ABORT)); 174 if (signalTransporter == null) 175 { 176 // The job is only abortable if it is waiting 177 supportsAbort = status == Job.Status.WAITING; 178 } 179 else 180 { 181 // Otherwise we must check with the signal transporter 182 Collection<Signal> supportedSignals = signalTransporter.getSupportedSignals(); 183 supportsAbort = supportedSignals == null || supportedSignals.contains(Signal.ABORT); 184 } 175 185 } 176 186 catch (Exception ex) 177 187 {} 178 188 } 189 if (autoUpdate) job.requestStatusUpdate(); 179 190 %> 180 191 <base:page type="popup" title="<%=title%>" id="view-page">
Note: See TracChangeset
for help on using the changeset viewer.