12
12
import java .io .FileNotFoundException ;
13
13
import java .io .IOException ;
14
14
import java .io .InputStream ;
15
+ import java .io .Serializable ;
15
16
import java .net .HttpURLConnection ;
16
17
import java .net .MalformedURLException ;
17
18
import java .net .URL ;
24
25
import com .conveyal .datatools .common .status .MonitorableJob ;
25
26
import com .conveyal .datatools .manager .models .Deployment ;
26
27
import com .conveyal .datatools .manager .persistence .FeedStore ;
28
+ import com .fasterxml .jackson .annotation .JsonProperty ;
27
29
import org .slf4j .Logger ;
28
30
import org .slf4j .LoggerFactory ;
29
31
@@ -58,6 +60,11 @@ public class DeployJob extends MonitorableJob {
58
60
/** This hides the status field on the parent class, providing additional fields. */
59
61
public DeployStatus status ;
60
62
63
+ @ JsonProperty
64
+ public String getDeploymentId () {
65
+ return deployment .id ;
66
+ }
67
+
61
68
public DeployJob (Deployment deployment , String owner , List <String > targets , String publicUrl , String s3Bucket , String s3CredentialsFilename ) {
62
69
// TODO add new job type or get rid of enum in favor of just using class names
63
70
super (owner , "Deploying " + deployment .name , JobType .DEPLOY_TO_OTP );
@@ -92,7 +99,7 @@ public void jobLogic () {
92
99
93
100
LOG .info ("Created deployment bundle file: " + deploymentTempFile .getAbsolutePath ());
94
101
95
- // dump the deployment bundle
102
+ // Dump the deployment bundle to the temp file.
96
103
try {
97
104
status .message = "Creating OTP Bundle" ;
98
105
this .deployment .dump (deploymentTempFile , true , true , true );
@@ -106,10 +113,10 @@ public void jobLogic () {
106
113
}
107
114
108
115
status .percentComplete = 100.0 * (double ) tasksCompleted / totalTasks ;
109
- System . out . println ( " pctComplete = " + status .percentComplete );
116
+ LOG . info ( "Deployment pctComplete = {}" , status .percentComplete );
110
117
status .built = true ;
111
118
112
- // upload to S3, if applicable
119
+ // Upload to S3, if applicable
113
120
if (this .s3Bucket != null ) {
114
121
status .message = "Uploading to S3" ;
115
122
status .uploadingS3 = true ;
@@ -147,7 +154,7 @@ public void jobLogic () {
147
154
status .uploadingS3 = false ;
148
155
}
149
156
150
- // if no OTP targets (i.e. we're only deploying to S3), we're done
157
+ // If there are no OTP targets (i.e. we're only deploying to S3), we're done.
151
158
if (this .targets == null ) {
152
159
status .completed = true ;
153
160
return ;
@@ -156,7 +163,7 @@ public void jobLogic () {
156
163
// figure out what router we're using
157
164
String router = deployment .routerId != null ? deployment .routerId : "default" ;
158
165
159
- // load it to OTP
166
+ // Send the deployment file over the wire to each OTP server.
160
167
for (String rawUrl : this .targets ) {
161
168
status .message = "Deploying to " + rawUrl ;
162
169
status .uploading = true ;
@@ -253,6 +260,7 @@ public void jobLogic () {
253
260
input .close ();
254
261
} catch (IOException e ) {
255
262
// do nothing
263
+ LOG .warn ("Could not close input stream for deployment file." );
256
264
}
257
265
258
266
status .uploading = false ;
@@ -301,32 +309,26 @@ public void jobFinished () {
301
309
if (!deleted ) {
302
310
LOG .error ("Deployment {} not deleted! Disk space in danger of filling up." , deployment .id );
303
311
}
304
-
312
+ String message ;
305
313
if (!status .error ) {
306
314
// Update status with successful completion state only if no error was encountered.
307
315
status .update (false , "Deployment complete!" , 100 , true );
316
+ message = String .format ("Deployment %s successfully deployed to %s" , deployment .name , publicUrl );
317
+ } else {
318
+ message = String .format ("WARNING: Deployment %s failed to deploy to %s" , deployment .name , publicUrl );
308
319
}
320
+ // Send notification to those subscribed to updates for the deployment.
321
+ NotifyUsersForSubscriptionJob .createNotification ("deployment-updated" , deployment .id , message );
309
322
}
310
323
311
324
/**
312
325
* Represents the current status of this job.
313
326
*/
314
327
public static class DeployStatus extends Status {
315
- // /** What error message (defined in messages.<lang>) should be displayed to the user? */
316
- // public String message;
317
- //
318
- // /** Is this deployment completed (successfully or unsuccessfully) */
319
- // public boolean completed;
320
-
321
- // /** Was there an error? */
322
- // public boolean error;
323
-
328
+ private static final long serialVersionUID = 1L ;
324
329
/** Did the manager build the bundle successfully */
325
330
public boolean built ;
326
331
327
- // /** Is the bundle currently being uploaded to the server? */
328
- // public boolean uploading;
329
-
330
332
/** Is the bundle currently being uploaded to an S3 bucket? */
331
333
public boolean uploadingS3 ;
332
334
0 commit comments