import org.nuxeo.ecm.core.opencmis.bindings.NuxeoCmisServiceFactory;
import org.nuxeo.ecm.core.opencmis.impl.server.NuxeoCmisService;
import org.nuxeo.elasticsearch.ElasticSearchComponent;
+import org.nuxeo.elasticsearch.api.ESClient;
import org.nuxeo.elasticsearch.api.ElasticSearchService;
import org.nuxeo.runtime.api.Framework;
import org.nuxeo.runtime.transaction.TransactionRuntimeException;
CoreSessionInterface repoSession = null;
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = handler.getServiceContext();
+ ElasticSearchComponent es = (ElasticSearchComponent) Framework.getService(ElasticSearchService.class);
+ ESClient esClient = null;
+
+ try {
+ // Ensure an Elasticsearch connection has been established. This should have happened
+ // on startup, but may not have, if the Elasticsearch service wasn't reachable when
+ // Nuxeo started.
+
+ esClient = es.getClient();
+ } catch (Exception e) {
+ esClient = null;
+ }
try {
repoSession = getRepositorySession(ctx);
- ElasticSearchComponent es = (ElasticSearchComponent) Framework.getService(ElasticSearchService.class);
+ if (esClient == null) {
+ // The connection to ES has not been established.
+ // Attempt to start the ElasticSearchService.
+
+ es.start(null);
+
+ try {
+ // Wait for startup configuration to complete.
+
+ Thread.sleep(5000);
+ } catch (InterruptedException ex) {
+ }
+ }
+
String repositoryName = repoSession.getRepositoryName();
logger.info(String.format("Rebuilding Elasticsearch index for repository %s", repositoryName));
return null;
}
}
-
+
/*
* HTTP Methods
*/
-
+
@Override
@POST
public Response create(@Context ResourceMap resourceMap, @Context UriInfo ui, String xmlPayload) {
.entity(ServiceMessages.POST_UNSUPPORTED).type("text/plain").build();
return response;
}
-
+
@Override
@DELETE
@Path("{csid}")
.build();
return response;
}
-
+
@POST
@Path("{indexid}")
public Response reindex(
Response result = Response.ok().build();
boolean success = false;
String docType = null;
-
+
try {
RemoteServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = (RemoteServiceContext<PoxPayloadIn, PoxPayloadOut>) createServiceContext(uriInfo);
docType = ctx.getTenantQualifiedDoctype(); // this will used in the error message if an error occurs
} catch (Exception e) {
throw bigReThrow(e, ServiceMessages.REINDEX_FAILED);
}
-
+
if (success == false) {
Response response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
ServiceMessages.REINDEX_FAILED + ServiceMessages.indexResourceNotFoundMsg(indexid)).type("text/plain").build();
throw new CSWebApplicationException(response);
}
-
+
return result;
}
-
+
/* (non-Javadoc)
* @see org.collectionspace.services.common.ResourceBase#getList(javax.ws.rs.core.UriInfo, java.lang.String)
- *
+ *
* The index sub-resource does not support a getList operation.
*/
@Override