use of com.opensymphony.xwork2.Result in project tis by qlangtech.
the class QueryIndexServlet method execuetQuery.
/**
* 执行查询逻辑和使用的场景无关
*
* @param domain
* @param
* @param getContext
*/
public static void execuetQuery(IParamGetter params, final AppDomainInfo domain, final QueryRequestContext requestContext, RunContext getContext, final QueryResutStrategy queryResutStrategy, final List<ServerJoinGroup> serverlist, final String querystr, final String sort, final String[] fqs, final Integer shownumf, final List<String> showFields) {
Assert.assertNotNull("param SolrQueryModuleCreator can not be null", queryResutStrategy.getRequest());
Assert.assertNotNull(queryResutStrategy);
Assert.assertNotNull(serverlist);
final ActionContext context = ActionContext.getContext();
final boolean distrib = params.getBoolean(CommonParams.DISTRIB);
final CountDownLatch lock = new CountDownLatch(distrib ? 1 : serverlist.size());
final AtomicBoolean hasGetSchema = new AtomicBoolean(false);
List<Row> rows = Lists.newArrayList();
synchronized (lock) {
for (final ServerJoinGroup server : serverlist) {
threadPool.execute(new Runnable() {
@Override
public void run() {
ActionContext.setContext(context);
// 组装url
final String url = server.getIpAddress();
try {
QueryCloudSolrClient solrClient = new QueryCloudSolrClient(url);
QueryResponse result = solrClient.query(domain.getAppName(), queryResutStrategy.getRequest().build(params, querystr, sort, fqs, shownumf, showFields), METHOD.POST);
solrClient.close();
long c = result.getResults().getNumFound();
if (c < 1) {
return;
}
// count.add(c);
requestContext.add(c);
rows.addAll(convert2Html(requestContext, result, server, distrib));
// queryResutStrategy.getRequest().processResult(requestContext, result, server);
} catch (Exception e) {
e.printStackTrace();
queryResutStrategy.getRequest().handleError(url, server, requestContext.resultCount.get(), e);
} finally {
lock.countDown();
}
}
});
if (distrib) {
break;
}
}
}
try {
lock.await();
queryResutStrategy.getRequest().processResult(requestContext, rows);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.opensymphony.xwork2.Result in project tis by qlangtech.
the class TestCollectionAction method testDeleteCollection.
public void testDeleteCollection() throws Exception {
ITISCoordinator zkCoordinator = MockZKUtils.createZkMock();
MockZooKeeperGetter.mockCoordinator = zkCoordinator;
// createCoordinatorMock((r) -> {
// });
request.setParameter("emethod", "deleteIndex");
request.setParameter("action", "collection_action");
JSONObject content = new JSONObject();
// search4search4employees
content.put(CollectionAction.KEY_INDEX_NAME, TEST_TABLE_EMPLOYEES_NAME);
request.setContent(content.toJSONString().getBytes(TisUTF8.get()));
ActionProxy proxy = getActionProxy();
this.replay();
String result = proxy.execute();
assertEquals("CollectionAction_ajax", result);
AjaxValve.ActionExecResult aResult = showBizResult();
assertNotNull(aResult);
assertTrue(aResult.isSuccess());
this.verifyAll();
}
use of com.opensymphony.xwork2.Result in project tis by qlangtech.
the class TestCollectionAction method testDoGetTaskStatus.
public void testDoGetTaskStatus() throws Exception {
request.setParameter("emethod", "getTaskStatus");
request.setParameter("action", "collection_action");
JSONObject content = new JSONObject();
int taskId = 644;
content.put(IParamContext.KEY_TASK_ID, taskId);
content.put(CollectionAction.KEY_SHOW_LOG, true);
request.setContent(content.toJSONString().getBytes(TisUTF8.get()));
ActionProxy proxy = getActionProxy();
String result = proxy.execute();
assertEquals("CollectionAction_ajax", result);
AjaxValve.ActionExecResult aResult = showBizResult();
assertNotNull(aResult);
assertTrue(aResult.isSuccess());
Map<String, Object> bizResult = (Map<String, Object>) aResult.getBizResult();
assertNotNull(bizResult.get("log"));
ExtendWorkFlowBuildHistory status = (ExtendWorkFlowBuildHistory) bizResult.get("status");
assertNotNull(status);
assertEquals(taskId, status.getId().intValue());
}
use of com.opensymphony.xwork2.Result in project tis by qlangtech.
the class TestCollectionAction method testQuery.
public void testQuery() throws Exception {
// URL.setURLStreamHandlerFactory(new StubStreamHandlerFactory());
// URLStreamHandler streamHandler = mock("httpStreamHander", StubStreamHandlerFactory.StubHttpURLStreamHander.class);
// StubStreamHandlerFactory.streamHander = streamHandler;
buildZkStateReaderMock();
request.setParameter("emethod", "query");
request.setParameter("action", "collection_action");
int rowsLimit = 3;
JSONObject content = new JSONObject();
content.put(CollectionAction.KEY_INDEX_NAME, TEST_TABLE_EMPLOYEES_NAME);
JSONArray searchFields = new JSONArray();
JSONObject queryField = new JSONObject();
// queryField.put("field", FIELD_EMPLOYEES_FIRST_NAME);
queryField.put(FIELD_EMPLOYEES_FIRST_NAME, "Nirm");
queryField.put(FIELD_EMPLOYEES_LAST_NAME, "Nirm");
searchFields.add(queryField);
content.put(CollectionAction.KEY_QUERY_SEARCH_FIELDS, searchFields);
JSONArray returnFields = new JSONArray();
returnFields.add(FIELD_EMPLOYEES_FIRST_NAME);
returnFields.add(FIELD_EMPLOYEES_LAST_NAME);
content.put(CollectionAction.KEY_QUERY_FIELDS, returnFields);
content.put(CollectionAction.KEY_QUERY_LIMIT, rowsLimit);
content.put(CollectionAction.KEY_QUERY_ROWS_OFFSET, 2);
request.setContent(content.toJSONString().getBytes(TisUTF8.get()));
ActionProxy proxy = getActionProxy();
this.replay();
String result = proxy.execute();
assertEquals("CollectionAction_ajax", result);
AjaxValve.ActionExecResult actionExecResult = showBizResult();
Map<String, Object> bizResult = (Map<String, Object>) actionExecResult.getBizResult();
assertNotNull("bizResult can not be null", bizResult);
Long rowsCount = (Long) bizResult.get(CollectionAction.RESULT_KEY_ROWS_COUNT);
assertEquals("", 227l, (long) rowsCount);
List<Map<String, String>> rows = (List<Map<String, String>>) bizResult.get(CollectionAction.RESULT_KEY_ROWS);
assertNotNull(rows);
assertEquals(rowsLimit, rows.size());
this.verifyAll();
}
use of com.opensymphony.xwork2.Result in project tis by qlangtech.
the class TestCollectionAction method testDoGetIndexStatus.
public void testDoGetIndexStatus() throws Exception {
// this.buildZkStateReaderMock();
createMockCollection(COLLECTION_NAME);
request.setParameter("emethod", "getIndexStatus");
request.setParameter("action", "collection_action");
JSONObject content = new JSONObject();
content.put(CollectionAction.KEY_INDEX_NAME, TEST_TABLE_EMPLOYEES_NAME);
request.setContent(content.toJSONString().getBytes(TisUTF8.get()));
this.replay();
ActionProxy proxy = getActionProxy();
String result = proxy.execute();
assertEquals("CollectionAction_ajax", result);
AjaxValve.ActionExecResult aResult = showBizResult();
assertNotNull(aResult);
assertTrue(aResult.isSuccess());
this.verifyAll();
}
Aggregations