Skip to content

Commit 2517643

Browse files
authored
Merge pull request #431 from Caltech-IPAC/DM-11387_filter_bgJobs_from_app
Dm 11387 Add ability to limit what will appears as background jobs
2 parents 3c9af9b + 638b1d4 commit 2517643

21 files changed

+235
-147
lines changed

src/firefly/java/edu/caltech/ipac/firefly/core/background/BackgroundStatus.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,17 @@ public class BackgroundStatus implements Serializable {
4444
public static final String WEB_PLOT_REQ = "WEB_PLOT_REQ";
4545
public static final String FILE_PATH = "FILE_PATH";
4646
public static final String TOTAL_BYTES = "TOTAL_BYTES";
47+
public static final String DATA_TAG = "DataTag";
48+
49+
// most likely not used anymore <---
4750
public static final String PUSH_DATA_BASE = "PUSH_DATA_#";
4851
public static final String PUSH_TYPE_BASE = "PUSH_TYPE_#";
4952
public static final String PUSH_CNT = "PUSH_CNT";
5053
public static final String USER_RESPONSE = "USER_RESPONSE_#";
5154
public static final String USER_DESC = "USER_DESC_#";
5255
public static final String RESPONSE_CNT = "RESPONSE_CNT";
5356
public static final String ACTIVE_REQUEST_CNT ="ACTIVE_REQUEST_CNT";
57+
// ---->
5458

5559
protected static final String URL_SUB = "URL_PARAM_SEP";
5660
private LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); // a map of Param keyed by name
@@ -92,11 +96,6 @@ public static BackgroundStatus cloneWithState(BackgroundState state, BackgroundS
9296
return retval;
9397
}
9498

95-
// public BackgroundStatus(BackgroundState state, BackgroundStatus copyFromReq) {
96-
// if (copyFromReq!=null) this.copyFrom(copyFromReq);
97-
// setState(state);
98-
// }
99-
10099
public static BackgroundStatus createUnknownFailStat() {
101100
return new BackgroundStatus(NO_ID, BackgroundState.FAIL, BgType.UNKNOWN);
102101
}
@@ -428,6 +427,9 @@ public void setWebPlotRequest(WebPlotRequest wpr) {
428427

429428
public void setFilePath(String filePath) { setParam(FILE_PATH,filePath); }
430429

430+
public String getDataTag() { return getParam(DATA_TAG); }
431+
public void setDataTag(String dataTag) { setParam(DATA_TAG, dataTag); }
432+
431433
/**
432434
* @return processed bytes if all bundles were processed successfully, otherwise previously estimated size in bytes
433435
*/
@@ -478,17 +480,13 @@ public String toString() {
478480
}
479481

480482
public BackgroundStatus cloneWithState(BackgroundState state) {
481-
BackgroundStatus s = newInstance();
483+
BackgroundStatus s = new BackgroundStatus();
482484
s.copyFrom(this);
483485
s.setState(state);
484486
return s;
485487
}
486488

487-
public BackgroundStatus newInstance() {
488-
return new BackgroundStatus();
489-
}
490-
491-
//====================================================================
489+
//====================================================================
492490
// overriding equals
493491
//====================================================================
494492
@Override
@@ -504,7 +502,7 @@ public boolean equals(Object obj) {
504502
return false;
505503
}
506504

507-
//====================================================================
505+
//====================================================================
508506
// convenience data converting routines
509507
//====================================================================
510508
public boolean getBooleanParam(String key, boolean defValue) {

src/firefly/java/edu/caltech/ipac/firefly/server/packagedata/BackgroundInfo.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class BackgroundInfo implements Serializable {
2525
private String email;
2626
private String baseFileName;
2727
private String title;
28+
private String dataTag;
2829
private ServerEvent.EventTarget eventTarget;
2930
//======================================================================
3031
//----------------------- Constructors ---------------------------------
@@ -34,12 +35,14 @@ public BackgroundInfo(BackgroundStatus bgStat,
3435
String email,
3536
String baseFileName,
3637
String title,
38+
String dataTag,
3739
ServerEvent.EventTarget eventTarget,
3840
boolean canceled) {
3941
this.bgStat= bgStat;
4042
this.canceled= canceled;
4143
this.email= email;
4244
this.baseFileName = baseFileName;
45+
this.dataTag = dataTag;
4346
this.eventTarget= eventTarget;
4447
this.title = title;
4548
}
@@ -82,6 +85,14 @@ public void setTitle(String title) {
8285
bgStat.setParam(BackgroundStatus.TITLE, title);
8386
}
8487

88+
public String getDataTag() {
89+
return dataTag;
90+
}
91+
92+
public void setDataTag(String dataTag) {
93+
this.dataTag = dataTag;
94+
}
95+
8596
public ServerEvent.EventTarget getEventTarget() { return eventTarget; }
8697
}
8798

src/firefly/java/edu/caltech/ipac/firefly/server/packagedata/BackgroundInfoCacher.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ public BackgroundInfoCacher(String key) {
4444
* @param baseFileName base name
4545
* @param title title
4646
*/
47-
public BackgroundInfoCacher(String key, String email, String baseFileName, String title, ServerEvent.EventTarget target) {
47+
public BackgroundInfoCacher(String key, String email, String baseFileName, String title, String dataTag, ServerEvent.EventTarget target) {
4848
this(key);
49-
updateInfo(new BackgroundInfo(null, email, baseFileName, title, target, false));
49+
updateInfo(new BackgroundInfo(null, email, baseFileName, title, dataTag, target, false));
5050
}
5151

5252
public static void fireBackgroundJobAdd(BackgroundStatus bgStat) {
5353
if (bgStat != null) {
54+
mergeInfoIntoStatus(getInfo(new StringKey(bgStat.getID())), bgStat);
5455
FluxAction addAction = new FluxAction("background.bgJobAdd", QueryUtil.convertToJsonObject(bgStat));
5556
ServerEventManager.fireAction(addAction, ServerEvent.Scope.USER);
5657
}
@@ -164,27 +165,39 @@ private void updateInfo(BackgroundInfo info) {
164165
fireStatusUpdate(info);
165166
}
166167

167-
private void mergeInfoIntoStatus(BackgroundInfo info, BackgroundStatus bgStatus) {
168-
bgStatus.setParam(ServerParams.TITLE, info.getTitle());
169-
bgStatus.setParam(ServerParams.EMAIL, info.getEmailAddress());
168+
/**
169+
* because on the client, bgStatus is a combination of both bgInfo and bgStatus. So here, we will
170+
* update the two objects so it can be stored correctly.
171+
*/
172+
private static void mergeInfoIntoStatus(BackgroundInfo info, BackgroundStatus bgStatus) {
173+
if (info != null && bgStatus != null) {
174+
bgStatus.setParam(ServerParams.TITLE, info.getTitle());
175+
bgStatus.setParam(ServerParams.EMAIL, info.getEmailAddress());
176+
bgStatus.setParam(BackgroundStatus.DATA_TAG, info.getDataTag());
177+
}
170178
}
171179

172180
private BackgroundInfo getInfo() {
181+
return getInfo(_key);
182+
}
183+
184+
private static BackgroundInfo getInfo(StringKey key) {
173185
Cache cache= BackgroundEnv.getCache();
174186
BackgroundInfo retval= null;
175-
if (cache.isCached(_key)) {
176-
BackgroundInfo info= (BackgroundInfo)cache.get(_key);
187+
if (cache.isCached(key)) {
188+
BackgroundInfo info= (BackgroundInfo)cache.get(key);
177189
if (info!=null) {
178190
retval= new BackgroundInfo(info.getStatus(),
179191
info.getEmailAddress(),
180192
info.getBaseFileName(),
181193
info.getTitle(),
194+
info.getDataTag(),
182195
info.getEventTarget(),
183196
info.isCanceled());
184197
}
185198
}
186199
else {
187-
Logger.error( "Could not update background info, BackgroundInfo not found in cache, key: "+_key );
200+
Logger.error( "Could not update background info, BackgroundInfo not found in cache, key: "+ key );
188201
}
189202
return retval;
190203
}

src/firefly/java/edu/caltech/ipac/firefly/server/packagedata/PackageMaster.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,11 @@ public BackgroundStatus packageData(DownloadRequest req,
163163
SearchProcessor<List<FileGroup>> processor) {
164164

165165
PackagingWorker worker= new PackagingWorker(processor,req);
166+
String dataTag = req.getSearchRequest() != null ? req.getSearchRequest().getMeta(BackgroundStatus.DATA_TAG) : null;
166167
BackgroundEnv.BackgroundProcessor backProcess=
167168
new BackgroundEnv.BackgroundProcessor( worker, req.getBaseFileName(),
168-
req.getTitle(),req.getEmail(),
169+
req.getTitle(), dataTag,
170+
req.getEmail(),
169171
req.getDataSource(),
170172
ServerContext.getRequestOwner());
171173
BackgroundStatus bgStat= BackgroundEnv.backgroundProcess(WAIT_MILLS,backProcess, BgType.PACKAGE);

src/firefly/java/edu/caltech/ipac/firefly/server/query/BackgroundEnv.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ private static ScriptRet buildScript(BackgroundStatus bgStat,
231231
_log.warn("Bad url for download script: " + part.getURL() + "Background ID: " + bgStat.getID());
232232
}
233233
}
234+
if (fName.length() < 3) {
235+
fName = StringUtils.pad(3, fName, StringUtils.Align.LEFT, '_');
236+
}
234237
if (urlList.size()>0) {
235238
String ext = attributes.contains(ScriptAttributes.URLsOnly) ? ".txt" : ".sh";
236239
try {
@@ -475,6 +478,7 @@ public static class BackgroundProcessor implements Runnable {
475478
private final String _bid;
476479
private final String _baseFileName;
477480
private final String _title;
481+
private final String _dataTag;
478482
private final String _email;
479483
private final String _dataSource;
480484
private final RequestOwner _requestOwner;
@@ -484,24 +488,27 @@ public static class BackgroundProcessor implements Runnable {
484488
public BackgroundProcessor(Worker worker,
485489
String baseFileName,
486490
String title,
491+
String dataTag,
487492
String email,
488493
String dataSource,
489494
RequestOwner requestOwner) {
490-
this(worker,baseFileName,title,email,dataSource,requestOwner,null,null);
495+
this(worker,baseFileName,title,dataTag,email,dataSource,requestOwner,null,null);
491496
}
492497

493498
public BackgroundProcessor(Worker worker,
494499
String title,
500+
String dataTag,
495501
String dataSource,
496502
RequestOwner requestOwner,
497503
String bid,
498504
ServerEvent.EventTarget target) {
499-
this(worker,null,title,null,dataSource,requestOwner,bid,target);
505+
this(worker,null,title,dataTag,null,dataSource,requestOwner,bid,target);
500506
}
501507

502508
public BackgroundProcessor(Worker worker,
503509
String baseFileName,
504510
String title,
511+
String dataTag,
505512
String email,
506513
String dataSource,
507514
RequestOwner requestOwner,
@@ -511,10 +518,11 @@ public BackgroundProcessor(Worker worker,
511518
_worker= worker;
512519
_baseFileName= baseFileName;
513520
_title= title;
521+
_dataTag = dataTag;
514522
_email= email;
515523
_dataSource= dataSource;
516524
_requestOwner= requestOwner;
517-
piCacher= new BackgroundInfoCacher(_bid, _email, _baseFileName, _title, evTarget); // force a cache entry here
525+
piCacher= new BackgroundInfoCacher(_bid, _email, _baseFileName, _title, _dataTag, evTarget); // force a cache entry here
518526
}
519527

520528

src/firefly/java/edu/caltech/ipac/firefly/server/query/SearchManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,12 @@ public FileInfo getFileInfo(TableServerRequest request) throws DataAccessExcepti
206206
public BackgroundStatus getRawDataSetBackground(TableServerRequest request, Request clientRequest, int waitMillis) throws RPCException {
207207

208208
Logger.briefDebug("Backgrounded search started:" + waitMillis + " wait, req:" + request);
209-
String email= request.getMeta(ServerParams.EMAIL) == null ? "" : request.getMeta(ServerParams.EMAIL);
209+
String email= request.getMeta(ServerParams.EMAIL);
210210
SearchWorker worker= new SearchWorker(request, clientRequest);
211211
String title = request.getTblTitle() == null ? request.getRequestId() : request.getTblTitle();
212212
BackgroundEnv.BackgroundProcessor processor=
213213
new BackgroundEnv.BackgroundProcessor(worker, null,
214-
title,
214+
title, request.getMeta(BackgroundStatus.DATA_TAG),
215215
email, request.getRequestId(),
216216
ServerContext.getRequestOwner() );
217217
return BackgroundEnv.backgroundProcess(waitMillis, processor, BackgroundStatus.BgType.SEARCH);

src/firefly/java/edu/caltech/ipac/firefly/server/query/SearchServerCommands.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public String doCommand(SrvParam params) throws Exception {
184184
public static class AddBgJob extends ServCommand {
185185

186186
public String doCommand(SrvParam params) throws Exception {
187-
BackgroundStatus bgStatus = QueryUtil.convertToBackgroundStatus(params.getRequired("bgStats"));
187+
BackgroundStatus bgStatus = QueryUtil.convertToBackgroundStatus(params.getRequired("bgStatus"));
188188
BackgroundEnv.addUserBackgroundInfo(bgStatus);
189189
return "true";
190190
}

src/firefly/java/edu/caltech/ipac/visualize/plot/Histogram.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ else if (i>HISTSIZ2)
117117
int histMinIndex = getLowSumIndex(lowLimit);
118118

119119
if (histMaxIndex==-1 || histMinIndex==-1){
120-
System.out.println("the index can not be negative");
121120
break;
122121
}
123122

0 commit comments

Comments
 (0)