use of org.apache.manifoldcf.core.interfaces.ManifoldCFException in project manifoldcf by apache.
the class AmazonCloudSearchConnector method flushDocuments.
protected void flushDocuments(IOutputHistoryActivity activities) throws ManifoldCFException, ServiceInterruption {
Logging.ingest.info("AmazonCloudSearch: Starting flush to Amazon");
// Repeat until we are empty of cached stuff
int chunkNumber = 0;
while (true) {
DocumentRecord[] records = documentChunkManager.readChunk(serverHost, serverPath, CHUNK_SIZE);
try {
if (records.length == 0)
break;
// The records consist of up to 1000 individual input streams, which must be all concatenated together into the post
// To do that, we go into and out of Reader space once again...
JSONArrayReader arrayReader = new JSONArrayReader();
for (DocumentRecord dr : records) {
arrayReader.addArrayElement(new JSONValueReader(new InputStreamReader(dr.getDataStream(), Consts.UTF_8)));
}
// post data..
String responsbody = postData(new ReaderInputStream(arrayReader, Consts.UTF_8));
// check status
String status = getStatusFromJsonResponse(responsbody);
if ("success".equals(status)) {
// Activity-log the individual documents we sent
for (DocumentRecord dr : records) {
activities.recordActivity(null, dr.getActivity(), dr.getDataSize(), dr.getUri(), "OK", null);
}
Logging.ingest.info("AmazonCloudSearch: Successfully sent document chunk " + chunkNumber);
// remove documents from table..
documentChunkManager.deleteChunk(records);
} else {
// Activity-log the individual documents that failed
for (DocumentRecord dr : records) {
activities.recordActivity(null, dr.getActivity(), dr.getDataSize(), dr.getUri(), "FAILED", responsbody);
}
Logging.ingest.error("AmazonCloudSearch: Error sending document chunk " + chunkNumber + ": '" + responsbody + "'");
throw new ManifoldCFException("Received error status from service after feeding document. Response body: '" + responsbody + "'");
}
} catch (ManifoldCFException e) {
if (e.getErrorCode() == ManifoldCFException.INTERRUPTED)
throw e;
for (DocumentRecord dr : records) {
activities.recordActivity(null, dr.getActivity(), dr.getDataSize(), dr.getUri(), e.getClass().getSimpleName().toUpperCase(Locale.ROOT), e.getMessage());
}
throw e;
} catch (ServiceInterruption e) {
for (DocumentRecord dr : records) {
activities.recordActivity(null, dr.getActivity(), dr.getDataSize(), dr.getUri(), e.getClass().getSimpleName().toUpperCase(Locale.ROOT), e.getMessage());
}
throw e;
} finally {
Throwable exception = null;
for (DocumentRecord dr : records) {
try {
dr.close();
} catch (Throwable e) {
exception = e;
}
}
if (exception != null) {
if (exception instanceof ManifoldCFException)
throw (ManifoldCFException) exception;
else if (exception instanceof Error)
throw (Error) exception;
else if (exception instanceof RuntimeException)
throw (RuntimeException) exception;
else
throw new RuntimeException("Unknown exception class thrown: " + exception.getClass().getName() + ": " + exception.getMessage(), exception);
}
}
}
}
use of org.apache.manifoldcf.core.interfaces.ManifoldCFException in project manifoldcf by apache.
the class AmazonCloudSearchConnector method check.
/**
* Test the connection. Returns a string describing the connection integrity.
*@return the connection's status as a displayable string.
*/
@Override
public String check() throws ManifoldCFException {
try {
getSession();
String responsbody = postData(new ReaderInputStream(new StringReader("[]"), Consts.UTF_8));
String status = "";
try {
status = getStatusFromJsonResponse(responsbody);
} catch (ManifoldCFException e) {
Logging.ingest.debug(e);
return "Could not get status from response body. Check Access Policy setting of your domain of Amazon CloudSearch.: " + e.getMessage();
}
if ("error".equalsIgnoreCase(status)) {
return "Connection working. responsbody : " + responsbody;
}
return "Connection NOT working. responsbody : " + responsbody;
} catch (ServiceInterruption e) {
Logging.ingest.debug(e);
return "Transient exception: " + e.getMessage();
}
}
use of org.apache.manifoldcf.core.interfaces.ManifoldCFException in project manifoldcf by apache.
the class AmazonCloudSearchConnector method getSession.
/**
* Set up a session
*/
protected void getSession() throws ManifoldCFException {
if (documentChunkManager == null) {
IDBInterface databaseHandle = DBInterfaceFactory.make(currentContext, ManifoldCF.getMasterDatabaseName(), ManifoldCF.getMasterDatabaseUsername(), ManifoldCF.getMasterDatabasePassword());
documentChunkManager = new DocumentChunkManager(databaseHandle);
}
serverHost = params.getParameter(AmazonCloudSearchConfig.SERVER_HOST);
if (serverHost == null)
throw new ManifoldCFException("Server host parameter required");
serverPath = params.getParameter(AmazonCloudSearchConfig.SERVER_PATH);
if (serverPath == null)
throw new ManifoldCFException("Server path parameter required");
String proxyProtocol = params.getParameter(AmazonCloudSearchConfig.PROXY_PROTOCOL);
String proxyHost = params.getParameter(AmazonCloudSearchConfig.PROXY_HOST);
String proxyPort = params.getParameter(AmazonCloudSearchConfig.PROXY_PORT);
// Https is OK here without a custom trust store because we know we are talking to an Amazon instance, which has certs that
// are presumably non-custom.
String urlStr = "https://" + serverHost + serverPath;
poster = new HttpPost(urlStr);
// set proxy
if (proxyHost != null && proxyHost.length() > 0) {
try {
HttpHost proxy = new HttpHost(proxyHost, Integer.parseInt(proxyPort), proxyProtocol);
RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
poster.setConfig(config);
} catch (NumberFormatException e) {
throw new ManifoldCFException("Number format exception: " + e.getMessage(), e);
}
}
poster.addHeader("Content-Type", "application/json");
}
use of org.apache.manifoldcf.core.interfaces.ManifoldCFException in project manifoldcf by apache.
the class DocumentChunkManager method recordDocument.
/**
* Record document information for later trasmission to Amazon.
* @param uid documentuid
* @param sdfData document SDF data.
* @throws ManifoldCFException
*/
public void recordDocument(String uid, String host, String path, String uri, String activity, Long length, InputStream sdfData) throws ManifoldCFException, IOException {
TempFileInput tfi = null;
try {
// This downloads all the data from upstream!
try {
tfi = new TempFileInput(sdfData);
} catch (ManifoldCFException e) {
if (e.getErrorCode() == ManifoldCFException.INTERRUPTED)
throw e;
throw new IOException("Fetch failed: " + e.getMessage());
}
while (true) {
long sleepAmt = 0L;
try {
beginTransaction();
try {
ArrayList params = new ArrayList();
String query = buildConjunctionClause(params, new ClauseDescription[] { new UnitaryClause(HOST_FIELD, host), new UnitaryClause(PATH_FIELD, path), new UnitaryClause(UID_FIELD, uid) });
IResultSet set = performQuery("SELECT " + UID_FIELD + " FROM " + getTableName() + " WHERE " + query + " FOR UPDATE", params, null, null);
Map<String, Object> parameterMap = new HashMap<String, Object>();
parameterMap.put(SDF_DATA_FIELD, tfi);
parameterMap.put(URI_FIELD, uri);
parameterMap.put(ACTIVITY_FIELD, activity);
if (length != null)
parameterMap.put(LENGTH_FIELD, length);
// if record exists on table, update record.
if (set.getRowCount() > 0) {
performUpdate(parameterMap, " WHERE " + query, params, null);
} else {
parameterMap.put(UID_FIELD, uid);
parameterMap.put(HOST_FIELD, host);
parameterMap.put(PATH_FIELD, path);
performInsert(parameterMap, null);
}
break;
} catch (ManifoldCFException e) {
signalRollback();
throw e;
} catch (RuntimeException e) {
signalRollback();
throw e;
} catch (Error e) {
signalRollback();
throw e;
} finally {
endTransaction();
}
} catch (ManifoldCFException e) {
// Look for deadlock and retry if so
if (e.getErrorCode() == e.DATABASE_TRANSACTION_ABORT) {
sleepAmt = getSleepAmt();
continue;
}
throw e;
}
}
} finally {
if (tfi != null)
tfi.discard();
}
}
use of org.apache.manifoldcf.core.interfaces.ManifoldCFException in project manifoldcf by apache.
the class CmisRepositoryConnector method getSession.
/**
* Set up a session
*/
protected void getSession() throws ManifoldCFException, ServiceInterruption {
if (session == null) {
if (StringUtils.isEmpty(binding))
throw new ManifoldCFException("Parameter " + CmisConfig.BINDING_PARAM + " required but not set");
if (StringUtils.isEmpty(username))
throw new ManifoldCFException("Parameter " + CmisConfig.USERNAME_PARAM + " required but not set");
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("CMIS: Username = '" + username + "'");
if (StringUtils.isEmpty(password))
throw new ManifoldCFException("Parameter " + CmisConfig.PASSWORD_PARAM + " required but not set");
Logging.connectors.debug("CMIS: Password exists");
if (StringUtils.isEmpty(protocol))
throw new ManifoldCFException("Parameter " + CmisConfig.PROTOCOL_PARAM + " required but not set");
if (StringUtils.isEmpty(server))
throw new ManifoldCFException("Parameter " + CmisConfig.SERVER_PARAM + " required but not set");
if (StringUtils.isEmpty(port))
throw new ManifoldCFException("Parameter " + CmisConfig.PORT_PARAM + " required but not set");
if (StringUtils.isEmpty(path))
throw new ManifoldCFException("Parameter " + CmisConfig.PATH_PARAM + " required but not set");
long currentTime;
GetSessionThread t = new GetSessionThread();
try {
t.start();
t.join();
Throwable thr = t.getException();
if (thr != null) {
if (thr instanceof java.net.MalformedURLException)
throw (java.net.MalformedURLException) thr;
else if (thr instanceof NotBoundException)
throw (NotBoundException) thr;
else if (thr instanceof RemoteException)
throw (RemoteException) thr;
else if (thr instanceof CmisConnectionException)
throw new ManifoldCFException("CMIS: Error during getting a new session: " + thr.getMessage(), thr);
else if (thr instanceof CmisPermissionDeniedException)
throw new ManifoldCFException("CMIS: Wrong credentials during getting a new session: " + thr.getMessage(), thr);
else
throw (Error) thr;
}
} catch (InterruptedException e) {
t.interrupt();
throw new ManifoldCFException("Interrupted: " + e.getMessage(), e, ManifoldCFException.INTERRUPTED);
} catch (java.net.MalformedURLException e) {
throw new ManifoldCFException(e.getMessage(), e);
} catch (NotBoundException e) {
// Transient problem: Server not available at the moment.
Logging.connectors.warn("CMIS: Server not up at the moment: " + e.getMessage(), e);
currentTime = System.currentTimeMillis();
throw new ServiceInterruption(e.getMessage(), currentTime + 60000L);
} catch (RemoteException e) {
Throwable e2 = e.getCause();
if (e2 instanceof InterruptedException || e2 instanceof InterruptedIOException)
throw new ManifoldCFException(e2.getMessage(), e2, ManifoldCFException.INTERRUPTED);
// Treat this as a transient problem
Logging.connectors.warn("CMIS: Transient remote exception creating session: " + e.getMessage(), e);
currentTime = System.currentTimeMillis();
throw new ServiceInterruption(e.getMessage(), currentTime + 60000L);
}
}
lastSessionFetch = System.currentTimeMillis();
}
Aggregations