use of com.xiaomi.linden.thrift.common.Response in project linden by XiaoMi.
the class CoreLindenServiceImpl method delete.
@Override
public Future<Response> delete(final LindenDeleteRequest request) {
final Stopwatch sw = Stopwatch.createStarted();
return instanceExecutorPool.apply(new Function0<Response>() {
@Override
public Response apply() {
Response response = null;
try {
long eps = sw.elapsed(TimeUnit.MILLISECONDS);
if (eps > 10) {
LOGGER.warn("Warning: instanceExecutorPool took " + eps + "ms to start delete.");
if (eps > instanceFuturePoolWaitTimeout) {
response = ResponseUtils.buildFailedResponse("Waiting time is too long, " + eps + "ms in instance future pool");
return response;
}
}
response = lindenCore.delete(request);
} catch (Exception e) {
String errorStackInfo = Throwables.getStackTraceAsString(e);
response = ResponseUtils.buildFailedResponse(errorStackInfo);
} finally {
if (response.isSuccess()) {
LOGGER.info("Instance delete request succeeded, request: {}, cost: {} ms.", request, sw.elapsed(TimeUnit.MILLISECONDS));
} else {
LOGGER.error("Instance delete request failed, request: {}, cost: {} ms.", request, sw.elapsed(TimeUnit.MILLISECONDS));
}
return response;
}
}
});
}
use of com.xiaomi.linden.thrift.common.Response in project linden by XiaoMi.
the class LindenController method delete.
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
public String delete(@RequestParam("bql") String bql) {
Response response;
try {
Future<Response> future = LindenAdmin.getService().handleClusterDeleteRequest(bql);
response = Await.result(future, Duration.apply(30000, TimeUnit.MILLISECONDS));
} catch (Exception e) {
response = new Response();
response.setSuccess(false).setError(Throwables.getStackTraceAsString(e));
}
return ThriftToJSON(response);
}
use of com.xiaomi.linden.thrift.common.Response in project linden by XiaoMi.
the class CoreLindenServiceImpl method index.
@Override
public Future<Response> index(final String content) {
final Stopwatch sw = Stopwatch.createStarted();
return instanceExecutorPool.apply(new Function0<Response>() {
@Override
public Response apply() {
Response response = null;
try {
long eps = sw.elapsed(TimeUnit.MILLISECONDS);
if (eps > 10) {
LOGGER.warn("Warning: instanceExecutorPool took " + eps + "ms to start index.");
if (eps > instanceFuturePoolWaitTimeout) {
response = ResponseUtils.buildFailedResponse("Waiting time is too long, " + eps + "ms in instance future pool");
return response;
}
}
LindenIndexRequest indexRequest = LindenIndexRequestParser.parse(config.getSchema(), content);
response = lindenCore.index(indexRequest);
} catch (Exception e) {
String errorStackInfo = Throwables.getStackTraceAsString(e);
response = ResponseUtils.buildFailedResponse(errorStackInfo);
} finally {
if (response.isSuccess()) {
LOGGER.info("Instance index request succeeded, content: {}, cost: {} ms.", content, sw.elapsed(TimeUnit.MILLISECONDS));
} else {
LOGGER.error("Instance index request failed, content: {}, cost: {} ms.", content, sw.elapsed(TimeUnit.MILLISECONDS));
}
return response;
}
}
});
}
use of com.xiaomi.linden.thrift.common.Response in project linden by XiaoMi.
the class MultiLindenCoreImpl method delete.
@Override
public Response delete(LindenDeleteRequest request) throws IOException {
List<String> indexNames;
// Only INDEX_NAME division type supports specified index name request
if (multiIndexStrategy instanceof TimeLimitMultiIndexStrategy || multiIndexStrategy instanceof DocNumLimitMultiIndexStrategy) {
indexNames = new ArrayList<>(lindenCoreMap.keySet());
} else {
if (request.getIndexNames() == null || (request.getIndexNamesSize() == 1 && request.getIndexNames().get(0).equals(LINDEN))) {
indexNames = new ArrayList<>(lindenCoreMap.keySet());
} else {
indexNames = request.getIndexNames();
for (int i = 0; i < indexNames.size(); ++i) {
indexNames.set(i, MultiIndexStrategy.MULTI_INDEX_PREFIX_NAME + indexNames.get(i));
}
}
}
StringBuilder errorInfo = new StringBuilder();
for (final String indexName : indexNames) {
final LindenCore core = lindenCoreMap.get(indexName);
if (core != null) {
try {
Response response = core.delete(request);
if (!response.isSuccess()) {
errorInfo.append(indexName + ":" + response.getError() + ";");
LOGGER.error("Multi-index {} delete error: {}", indexName, response.error);
}
} catch (Exception e) {
errorInfo.append(indexName + ":" + Throwables.getStackTraceAsString(e) + ";");
LOGGER.error("Multi-index {} delete error: {}", indexName, Throwables.getStackTraceAsString(e));
}
} else {
errorInfo.append(indexName + " doesn't exist");
LOGGER.error("Multi-index {} delete error: " + indexName + " doesn't exist");
}
}
if (errorInfo.length() > 0) {
return ResponseUtils.buildFailedResponse("Multi-index delete error: " + errorInfo.toString());
} else {
return ResponseUtils.SUCCESS;
}
}
use of com.xiaomi.linden.thrift.common.Response in project linden by XiaoMi.
the class MultiLindenCoreImpl method index.
@Override
public Response index(LindenIndexRequest request) throws IOException {
if (request.getType().equals(IndexRequestType.DELETE_INDEX)) {
return deleteIndex(request);
}
LindenCore core = multiIndexStrategy.getCurrentLindenCore(request.getIndexName());
if (core != null) {
switch(request.getType()) {
case INDEX:
return core.index(request);
case DELETE:
return delete(request);
case REPLACE:
request.setType(IndexRequestType.DELETE);
Response response = delete(request);
if (response.isSuccess()) {
request.setType(IndexRequestType.INDEX);
response = core.index(request);
}
return response;
default:
return ResponseUtils.buildFailedResponse("IndexRequestType " + request.getType() + " is not supported.");
}
} else {
return ResponseUtils.buildFailedResponse("No corresponding linden core is found.");
}
}
Aggregations