1 |
7800
|
tao
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
|
|
* Purpose: A class represents a file log for the index events.
|
4 |
|
|
* Copyright: 2013 Regents of the University of California and the
|
5 |
|
|
* National Center for Ecological Analysis and Synthesis
|
6 |
|
|
* Authors: Jing Tao
|
7 |
|
|
*
|
8 |
|
|
* This program is free software; you can redistribute it and/or modify
|
9 |
|
|
* it under the terms of the GNU General Public License as published by
|
10 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
11 |
|
|
* (at your option) any later version.
|
12 |
|
|
*
|
13 |
|
|
* This program is distributed in the hope that it will be useful,
|
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
* GNU General Public License for more details.
|
17 |
|
|
*
|
18 |
|
|
* You should have received a copy of the GNU General Public License
|
19 |
|
|
* along with this program; if not, write to the Free Software
|
20 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
21 |
|
|
*/
|
22 |
|
|
package edu.ucsb.nceas.metacat.index.event;
|
23 |
|
|
|
24 |
|
|
import java.io.File;
|
25 |
|
|
import java.io.FileNotFoundException;
|
26 |
|
|
import java.io.FileOutputStream;
|
27 |
|
|
import java.io.IOException;
|
28 |
|
|
import java.text.DateFormat;
|
29 |
|
|
import java.text.SimpleDateFormat;
|
30 |
|
|
import java.util.Date;
|
31 |
|
|
import java.util.List;
|
32 |
|
|
import java.util.Vector;
|
33 |
|
|
|
34 |
|
|
import org.apache.commons.io.FileUtils;
|
35 |
|
|
import org.apache.commons.io.IOUtils;
|
36 |
|
|
import org.dataone.configuration.Settings;
|
37 |
|
|
import org.dataone.service.types.v1.Identifier;
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
/**
|
41 |
|
|
* A class represents a file log for the index events.
|
42 |
|
|
* @author tao
|
43 |
|
|
*
|
44 |
|
|
*/
|
45 |
|
|
public class IndexEventFileLog implements IndexEventLog {
|
46 |
|
|
private static final String FIELDSEPERATOR = " ";
|
47 |
|
|
private static final String LOGFILENAME = "solr-index.log";
|
48 |
|
|
private File logFile = null;
|
49 |
|
|
private long index=1;
|
50 |
|
|
|
51 |
|
|
/**
|
52 |
|
|
* Constructor. Initialize the log file. The log file locates solr.homeDir.
|
53 |
|
|
* If the solr.homeDir doesn't exists in the metacat.properties, the it will locate the user's home directory.
|
54 |
|
|
* @throws IOException
|
55 |
|
|
*/
|
56 |
|
|
public IndexEventFileLog() throws IOException {
|
57 |
|
|
String path = Settings.getConfiguration().getString("solr.homeDir");
|
58 |
|
|
if(path == null || path.trim().equals("")) {
|
59 |
|
|
path = System.getProperty("user.home");
|
60 |
|
|
}
|
61 |
|
|
File pathDir = new File(path);
|
62 |
|
|
if(!pathDir.exists()) {
|
63 |
|
|
pathDir.mkdirs();
|
64 |
|
|
}
|
65 |
|
|
logFile = new File(pathDir, LOGFILENAME);
|
66 |
|
|
if(!logFile.exists()) {
|
67 |
|
|
logFile.createNewFile();
|
68 |
|
|
}
|
69 |
|
|
}
|
70 |
|
|
/**
|
71 |
|
|
* Write an IndexEvent into a file
|
72 |
|
|
* @param event
|
73 |
|
|
* @return the serial number for this event
|
74 |
|
|
* @throws IndexEventLogException
|
75 |
|
|
*/
|
76 |
|
|
public synchronized long write(IndexEvent event) throws IndexEventLogException {
|
77 |
|
|
if(event != null) {
|
78 |
|
|
Vector<String> lines = new Vector<String>();
|
79 |
|
|
StringBuffer lineBuffer = new StringBuffer();
|
80 |
|
|
lineBuffer.append("\""+index+"\""+FIELDSEPERATOR);
|
81 |
|
|
int type = event.getType();
|
82 |
|
|
lineBuffer.append("\""+type+"\""+FIELDSEPERATOR);
|
83 |
|
|
Date date = event.getDate();
|
84 |
|
|
if(date != null) {
|
85 |
|
|
DateFormat formate = new SimpleDateFormat();
|
86 |
|
|
lineBuffer.append("\""+formate.format(date)+"\""+FIELDSEPERATOR);
|
87 |
|
|
}
|
88 |
|
|
Identifier id = event.getPid();
|
89 |
|
|
if(id != null) {
|
90 |
|
|
lineBuffer.append("\""+id.getValue()+"\""+FIELDSEPERATOR);
|
91 |
|
|
}
|
92 |
|
|
String description = event.getDescription();
|
93 |
|
|
if(description != null) {
|
94 |
|
|
lineBuffer.append("\""+description+"\""+FIELDSEPERATOR);
|
95 |
|
|
}
|
96 |
|
|
lines.add(lineBuffer.toString());
|
97 |
|
|
String lineEnding = null;//null means to use the system default one.
|
98 |
|
|
boolean append = true;
|
99 |
|
|
try {
|
100 |
|
|
FileUtils.writeLines(logFile, "UTF-8", lines, append);
|
101 |
|
|
//FileUtils.writeLines(logFile, "UTF-8", lines, lineEnding);
|
102 |
|
|
//IOUtils.writeLines(lines, lineEnding, new FileOutputStream(logFile), "UTF-8");
|
103 |
|
|
} catch (FileNotFoundException e) {
|
104 |
|
|
// TODO Auto-generated catch block
|
105 |
|
|
throw new IndexEventLogException(e.getMessage());
|
106 |
|
|
} catch (IOException e) {
|
107 |
|
|
// TODO Auto-generated catch block
|
108 |
|
|
throw new IndexEventLogException(e.getMessage());
|
109 |
|
|
}
|
110 |
|
|
index++;
|
111 |
|
|
}
|
112 |
|
|
return index;
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
/**
|
117 |
|
|
* Gets the list of IndexEvent matching the specified set of filters. The filter parameters can be null
|
118 |
|
|
* @param type the type of the event
|
119 |
|
|
* @param pid the identifier of the data object in the event
|
120 |
|
|
* @param start the start time of the time range for query
|
121 |
|
|
* @param end the end time of the time range for query
|
122 |
|
|
* @return
|
123 |
|
|
* @throws IndexEventLogException
|
124 |
|
|
*/
|
125 |
7805
|
tao
|
public List<IndexEvent> getEvents(int type, Identifier pid, Date start, Date end) throws IndexEventLogException {
|
126 |
7800
|
tao
|
List<IndexEvent> list = null;
|
127 |
|
|
return list;
|
128 |
|
|
}
|
129 |
|
|
|
130 |
7805
|
tao
|
|
131 |
7800
|
tao
|
/**
|
132 |
7805
|
tao
|
* Get the list of identifiers which were failed to build the solr index since the
|
133 |
|
|
* previous timed indexing (including the ones in the timed indexing).
|
134 |
|
|
* @return the list of failure identifiers. The null will be returned if no failure.
|
135 |
7800
|
tao
|
*/
|
136 |
7806
|
tao
|
public List<String> getFailedPids() throws IndexEventLogException {
|
137 |
7805
|
tao
|
return null;
|
138 |
7800
|
tao
|
}
|
139 |
|
|
|
140 |
7805
|
tao
|
|
141 |
7800
|
tao
|
/**
|
142 |
7805
|
tao
|
* Get the latest SystemMetadata modification Date of the objects that were built
|
143 |
|
|
* the solr index during the previous timed indexing process.
|
144 |
|
|
* @return the date. The null will be returned if there is no such date.
|
145 |
|
|
* @throws IndexEventLogException
|
146 |
7800
|
tao
|
*/
|
147 |
7805
|
tao
|
public Date getLastProcessDate() throws IndexEventLogException {
|
148 |
|
|
return null;
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
/**
|
153 |
|
|
* Set the SystemMetadata modification Date of the objects that were built
|
154 |
|
|
* the solr index during the previous timed indexing process.
|
155 |
|
|
* @throws IndexEventLogException
|
156 |
|
|
*/
|
157 |
|
|
public void setLastProcessDate(Date date) throws IndexEventLogException {
|
158 |
7800
|
tao
|
|
159 |
|
|
}
|
160 |
|
|
}
|