Search in sources :

Example 1 with Result

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);
    }
}
Also used : ActionContext(com.opensymphony.xwork2.ActionContext) CountDownLatch(java.util.concurrent.CountDownLatch) ServletException(javax.servlet.ServletException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse)

Example 2 with Result

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();
}
Also used : ITISCoordinator(com.qlangtech.tis.cloud.ITISCoordinator) ActionProxy(com.opensymphony.xwork2.ActionProxy) JSONObject(com.alibaba.fastjson.JSONObject) AjaxValve(com.qlangtech.tis.manage.common.valve.AjaxValve)

Example 3 with Result

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());
}
Also used : ExtendWorkFlowBuildHistory(com.qlangtech.tis.coredefine.module.action.ExtendWorkFlowBuildHistory) ActionProxy(com.opensymphony.xwork2.ActionProxy) JSONObject(com.alibaba.fastjson.JSONObject) AjaxValve(com.qlangtech.tis.manage.common.valve.AjaxValve) JSONObject(com.alibaba.fastjson.JSONObject) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 4 with Result

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();
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) AjaxValve(com.qlangtech.tis.manage.common.valve.AjaxValve) JSONObject(com.alibaba.fastjson.JSONObject) List(java.util.List) NodeList(org.w3c.dom.NodeList) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 5 with Result

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();
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) JSONObject(com.alibaba.fastjson.JSONObject) AjaxValve(com.qlangtech.tis.manage.common.valve.AjaxValve)

Aggregations

ActionSupport (com.opensymphony.xwork2.ActionSupport)63 Test (org.junit.Test)52 ActionProxy (com.opensymphony.xwork2.ActionProxy)51 List (java.util.List)49 ValueStack (com.opensymphony.xwork2.util.ValueStack)38 Result (edu.stanford.CVC4.Result)35 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)34 ActionContext (com.opensymphony.xwork2.ActionContext)33 Expr (edu.stanford.CVC4.Expr)32 SExpr (edu.stanford.CVC4.SExpr)32 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)31 ArrayList (java.util.ArrayList)31 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)30 HashMap (java.util.HashMap)29 Rational (edu.stanford.CVC4.Rational)25 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)22 Map (java.util.Map)21 ServletActionContext (org.apache.struts2.ServletActionContext)21 Result (com.opensymphony.xwork2.Result)18 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)18