Skip to content

Commit b696702

Browse files
committed
IRSA-975: NED searching seems not to work
- column names must be enclose by double-quotes - remove caching done at the search processor’s level - introduce SharedDbProcessor: results from same processor share the same database - convert IBE’s template into a search processor - convert XYGenericProcessor into an EmbeddedDbProcessor - use firefly’s config file where applicable. - limit log message to 2k characters
1 parent ea94f21 commit b696702

34 files changed

+587
-504
lines changed

config/log4j.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
log4j.rootLogger=INFO, console
22
log4j.appender.console=org.apache.log4j.ConsoleAppender
33
log4j.appender.console.layout=org.apache.log4j.PatternLayout
4-
log4j.appender.console.layout.ConversionPattern=%d{MM/dd HH:mm:ss} %5p - %m [%t] (%c{2}#%M:%L)%n
4+
log4j.appender.console.layout.ConversionPattern=%d{MM/dd HH:mm:ss} %5p - %.2000m [%t] (%c{2}#%M:%L)%n
55

66
# ${host.name} is defined as an evironment variable at tomcat startup... not a log4j variable.
77
log4j.appender.@app-name@_stats=org.apache.log4j.DailyRollingFileAppender
@@ -14,15 +14,15 @@ log4j.appender.@app-name@_brief=org.apache.log4j.DailyRollingFileAppender
1414
log4j.appender.@app-name@_brief.File=${catalina.base}/logs/@[email protected]
1515
log4j.appender.@app-name@_brief.DatePattern='.'yyyy-ww
1616
log4j.appender.@app-name@_brief.layout=org.apache.log4j.PatternLayout
17-
log4j.appender.@app-name@_brief.layout.ConversionPattern=%d{MM/dd HH:mm:ss} %5p - %m [%t] (%c{2}#%M:%L)%n
17+
log4j.appender.@app-name@_brief.layout.ConversionPattern=%d{MM/dd HH:mm:ss} %5p - %.2000m [%t] (%c{2}#%M:%L)%n
1818

1919
log4j.appender.@app-name@=org.apache.log4j.DailyRollingFileAppender
2020
log4j.appender.@[email protected]=${catalina.base}/logs/@[email protected]
2121
log4j.appender.@[email protected]='.'yyyy-ww
2222
log4j.appender.@[email protected]=org.apache.log4j.PatternLayout
2323
log4j.appender.@[email protected]=\
2424
%d{MM/dd HH:mm:ss} %5p Thread: %t %c{2}#%M:%L\
25-
%n %m%n
25+
%n %.2000m%n
2626

2727

2828
# this renderer print the object into multiple lines

src/firefly/html/demo/ffapi-highlevel-charttest.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ <h3>Default chart for 'allwise' table group below</h3>
184184
firefly.showChart('defaultChart', {tbl_group: 'allwise'});
185185

186186
// using column expressions
187-
var tblReqXpr = Object.assign({}, tblReq, {inclCols: 'ra + dec as radec, ra, dec, ln(dec) as LnOfDec, power(ra, 2) as ra_sq'});
187+
var tblReqXpr = Object.assign({}, tblReq, {inclCols: '"ra" + "dec" as "radec", "ra", "dec", ln("dec") as "LnOfDec", power("ra", 2) as "ra_sq"'});
188188
tblReqXpr.META_INFO.tbl_id = 'tblwithXpr';
189189
tblReqXpr.META_INFO.title = 'table with expressions';
190190
tblReqXpr.tbl_id = 'tblwithXpr';

src/firefly/java/edu/caltech/ipac/firefly/server/catquery/CatMasterTableQuery.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
import edu.caltech.ipac.util.DataObject;
2626
import edu.caltech.ipac.util.DataType;
2727
import edu.caltech.ipac.util.StringUtils;
28-
import edu.caltech.ipac.util.cache.Cache;
29-
import edu.caltech.ipac.util.cache.CacheManager;
30-
import edu.caltech.ipac.util.cache.StringKey;
3128

3229
import java.io.File;
3330
import java.io.IOException;
@@ -257,17 +254,7 @@ public static DataGroup getBaseGatorData(String originalFilename) throws IOExcep
257254
}
258255

259256
protected File loadDataFile(TableServerRequest request) throws IOException, DataAccessException {
260-
File retFile;
261-
262-
StringKey key = new StringKey(CatMasterTableQuery.class.getName(), getUniqueID(request));
263-
Cache cache = CacheManager.getCache(Cache.TYPE_TEMP_FILE);
264-
retFile = (File) cache.get(key);
265-
if (retFile == null) {
266-
retFile = getMasterCatalogFile(request);
267-
cache.put(key, retFile);
268-
}
269-
270-
return retFile;
257+
return getMasterCatalogFile(request);
271258
}
272259

273260
}

src/firefly/java/edu/caltech/ipac/firefly/server/catquery/GatorDD.java

Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import edu.caltech.ipac.firefly.server.query.EmbeddedDbProcessor;
2020
import edu.caltech.ipac.firefly.server.query.ParamDoc;
2121
import edu.caltech.ipac.firefly.server.query.SearchProcessorImpl;
22+
import edu.caltech.ipac.firefly.server.query.SharedDbProcessor;
2223
import edu.caltech.ipac.firefly.server.util.ipactable.DataGroupPart;
24+
import edu.caltech.ipac.firefly.server.util.ipactable.DataGroupReader;
2325
import edu.caltech.ipac.firefly.server.util.ipactable.TableDef;
2426
import edu.caltech.ipac.util.AppProperties;
2527
import edu.caltech.ipac.util.DataGroup;
@@ -52,69 +54,23 @@
5254
@ParamDoc(name = CatalogRequest.SERVICE_ROOT, desc = "the part of the URL string that specifies the service and first params. " +
5355
"optional: almost never used")
5456
})
55-
public class GatorDD extends EmbeddedDbProcessor {
57+
public class GatorDD extends SharedDbProcessor {
5658

57-
public FileInfo createDbFile(TableServerRequest treq) throws DataAccessException {
58-
59-
DbAdapter dbAdapter = DbAdapter.getAdapter(treq);
60-
File dbFile = new File(ServerContext.getTempWorkDir(), String.format("GatorDD-%s.%s", FileUtil.getHostname(), dbAdapter.getName()));
59+
public DataGroup fetchData(TableServerRequest treq) throws DataAccessException {
60+
TableServerRequest ntreq = (TableServerRequest) treq.cloneRequest();
61+
ntreq.keepBaseParamOnly();
6162
try {
62-
if (dbFile.createNewFile()) {
63-
// created for the first time... populate dd and meta tables
64-
DataGroup dd = new DataGroup("DD for GatorDD", new DataType[]{
65-
new DataType("name", String.class),
66-
new DataType("description", String.class),
67-
new DataType("units", String.class),
68-
new DataType("indx", String.class),
69-
new DataType("dbtype", String.class),
70-
new DataType("tableflg", Integer.class),
71-
new DataType("sel", String.class)
72-
});
73-
EmbeddedDbUtil.createDDTbl(dbFile, dd, dbAdapter, "data");
74-
EmbeddedDbUtil.setDbMetaInfo(treq, DbAdapter.getAdapter(treq), dbFile);
75-
}
63+
File results = new GatorDDImpl().loadDataFile(treq);
64+
return DataGroupReader.read(results);
7665
} catch (IOException e) {
77-
// should not happen.
66+
throw new DataAccessException(e.getMessage(), e);
7867
}
79-
return new FileInfo(dbFile);
80-
}
81-
82-
@Override
83-
protected DataGroupPart getResultSet(TableServerRequest treq, File dbFile) throws DataAccessException {
84-
DbAdapter dbAdapter = DbAdapter.getAdapter(treq);
85-
DbInstance dbInstance = dbAdapter.getDbInstance(dbFile);
86-
String tblName = treq.getParam(CatalogRequest.CATALOG);
87-
88-
String tblExists = String.format("select count(*) from %s", tblName);
89-
try {
90-
JdbcFactory.getSimpleTemplate(dbInstance).queryForInt(tblExists);
91-
} catch (Exception e) {
92-
// DD for this catalog does not exists.. fetch data and populate
93-
fetchDataIntoTable(treq, tblName, dbFile, dbAdapter);
94-
}
95-
96-
treq.setParam(TableServerRequest.SQL_FROM, tblName);
97-
treq.setPageSize(Integer.MAX_VALUE);
98-
String sql = String.format("%s %s %s", dbAdapter.selectPart(treq), dbAdapter.fromPart(treq), dbAdapter.wherePart(treq));
99-
sql = dbAdapter.translateSql(sql);
100-
101-
DataGroup dg = EmbeddedDbUtil.runQuery(dbAdapter, dbFile, sql, "data");
102-
TableDef tm = new TableDef();
103-
tm.setStatus(DataGroupPart.State.COMPLETED);
104-
return new DataGroupPart(tm, dg, treq.getStartIndex(), dg.size());
10568
}
10669

10770
@Override
10871
public boolean doLogging() {
10972
return false;
11073
}
111-
112-
private void fetchDataIntoTable(TableServerRequest treq, String tblName, File dbFile, DbAdapter dbAdapter) throws DataAccessException {
113-
TableServerRequest ntreq = (TableServerRequest) treq.cloneRequest();
114-
ntreq.keepBaseParamOnly();
115-
DataGroupPart dgp = new GatorDDImpl().getData(treq);
116-
EmbeddedDbUtil.createDataTbl(dbFile, dgp.getData(), dbAdapter, tblName);
117-
}
11874
}
11975

12076

src/firefly/java/edu/caltech/ipac/firefly/server/db/BaseDbAdapter.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* @version $Id: DbInstance.java,v 1.3 2012/03/15 20:35:40 loi Exp $
2929
*/
3030
abstract public class BaseDbAdapter implements DbAdapter {
31-
private static long MAX_IDLE_TIME = 1000 * 60 * 5; // will be cleaned up if idle more than 5 minutes.
31+
private static long MAX_IDLE_TIME = 1000 * 60 * 15; // will be purged up if idle more than 5 minutes.
3232
private static Map<String, EmbeddedDbInstance> dbInstances = new HashMap<>();
3333
private static Logger.LoggerImpl LOGGER = Logger.getLogger();
3434

@@ -75,7 +75,7 @@ public String createDataSql(DataType[] dtTypes, String tblName) {
7575
tblName = StringUtils.isEmpty(tblName) ? "data" : tblName;
7676
List<String> coldefs = new ArrayList<>();
7777
for(DataType dt : dtTypes) {
78-
coldefs.add( String.format("\"%s\" %s", dt.getKeyName().toUpperCase(),getDataType(dt.getDataType())));
78+
coldefs.add( String.format("\"%s\" %s", dt.getKeyName(), getDataType(dt.getDataType()))); // add quotes to avoid reserved words clashes
7979
}
8080

8181
return String.format("create table %s (%s)", tblName, StringUtils.toString(coldefs, ","));
@@ -103,13 +103,6 @@ public String selectPart(TableServerRequest treq) {
103103
return cols;
104104
}
105105

106-
public String fromPart(TableServerRequest treq) {
107-
String from = treq.getParam(TableServerRequest.SQL_FROM);
108-
from = from == null ? EmbeddedDbUtil.getResultSetID(treq) : from;
109-
from = "from " + (StringUtils.isEmpty(from) ? "data" : from);
110-
return from;
111-
}
112-
113106
public String wherePart(TableServerRequest treq) {
114107
String where = "";
115108
if (treq.getFilters() != null && treq.getFilters().size() > 0) {
@@ -171,12 +164,16 @@ public String getDataType(Class type) {
171164
}
172165

173166
public DbInstance getDbInstance(File dbFile) {
167+
return getDbInstance(dbFile, true);
168+
}
169+
170+
public DbInstance getDbInstance(File dbFile, boolean create) {
174171
EmbeddedDbInstance ins = dbInstances.get(dbFile.getPath());
175-
if (ins == null) {
172+
if (ins == null && create) {
176173
ins = createDbInstance(dbFile);
177174
dbInstances.put(dbFile.getPath(), ins);
178175
}
179-
ins.touch();
176+
if (ins != null ) ins.touch();
180177
return ins;
181178

182179
}

src/firefly/java/edu/caltech/ipac/firefly/server/db/DbAdapter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public interface DbAdapter {
6060
String getMetaSql(String forTable);
6161

6262
String selectPart(TableServerRequest treq);
63-
String fromPart(TableServerRequest treq);
6463
String wherePart(TableServerRequest treq);
6564
String orderByPart(TableServerRequest treq) ;
6665
String pagingPart(TableServerRequest treq) ;

0 commit comments

Comments
 (0)