Search in sources :

Example 11 with Result

use of com.opensymphony.xwork2.Result in project tis by qlangtech.

the class TestSchemaAction method testDoSaveByExpertModel.

/**
 * 测试专家模式Schema保存, 将mall_id类型由string改成test类型,并且去掉了一个动态字段pt_*
 *
 * @throws Exception
 */
public void testDoSaveByExpertModel() throws Exception {
    // event_submit_do_save_by_expert_model: y
    request.setParameter("emethod", "saveByExpertModel");
    request.setParameter("action", "schema_action");
    // request.addHeader("appname", collection);
    setCollection(collection);
    try (InputStream post = this.getClass().getResourceAsStream("schema-action-do-save-by-expert-model.json")) {
        request.setContent(IOUtils.toByteArray(post));
    }
    ActionProxy proxy = getActionProxy();
    String result = proxy.execute();
    assertEquals("SchemaAction_ajax", result);
    AjaxValve.ActionExecResult aResult = showBizResult();
    assertNotNull(aResult);
    assertTrue(aResult.isSuccess());
    // this.verifyAll();
    SchemaAction.CreateSnapshotResult bizResult = (SchemaAction.CreateSnapshotResult) aResult.getBizResult();
    assertNotNull(bizResult);
    Integer newSnapshotId = bizResult.getNewId();
    assertTrue("newSnapshotId can not be null", newSnapshotId > 0);
    SnapshotDomain snapshotView = runContext.getSnapshotViewDAO().getView(newSnapshotId);
    assertNotNull("snapshotView can not be null", snapshotView);
    UploadResource solrSchema = snapshotView.getSolrSchema();
    String mallIdTypeModifiedXml = StringUtils.remove(new String(solrSchema.getContent(), TisUTF8.get()), '\r');
    try (InputStream input = this.getClass().getResourceAsStream("schema-action-do-save-by-expert-model-modify-mallid-type-assert.xml")) {
        assertNotNull(input);
        String mallIdTypeModifiedXmlExpect = StringUtils.trimToEmpty(IOUtils.toString(input, TisUTF8.get()));
        assertEquals(mallIdTypeModifiedXmlExpect, StringUtils.trimToEmpty(mallIdTypeModifiedXml));
    }
// JsonUtil.assertJSONEqual(TestSchemaAction.class, "schema-action-do-save-by-expert-model-modify-mallid-type-assert.xml"
// , mallIdTypeModifiedXml, (msg, e, a) -> {
// assertEquals(msg, e, a);
// });
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) SnapshotDomain(com.qlangtech.tis.manage.common.SnapshotDomain) InputStream(java.io.InputStream) AjaxValve(com.qlangtech.tis.manage.common.valve.AjaxValve) UploadResource(com.qlangtech.tis.manage.biz.dal.pojo.UploadResource)

Example 12 with Result

use of com.opensymphony.xwork2.Result in project tis by qlangtech.

the class TestSchemaAction method testGetFieldsBySnapshotId.

public void testGetFieldsBySnapshotId() throws Exception {
    request.setParameter("emethod", "getFieldsBySnapshotId");
    request.setParameter("action", "schema_action");
    request.setParameter("snapshot", "21123");
    request.setParameter("editable", "false");
    request.setParameter("restype", "schema.xml");
    setCollection(collection);
    ActionProxy proxy = getActionProxy();
    String result = proxy.execute();
    assertEquals("SchemaAction_ajax", result);
    AjaxValve.ActionExecResult aResult = showBizResult();
    assertNotNull(aResult);
    assertTrue(aResult.isSuccess());
    JSONObject biz = (JSONObject) aResult.getBizResult();
    assertNotNull(biz);
    String assertFileName = "assert-testGetFieldsBySnapshotId.json";
    try (InputStream assertInput = this.getClass().getResourceAsStream(assertFileName)) {
        assertNotNull(assertInput);
        // FileUtils.write(new File("testGetFieldsBySnapshotId.json"), JsonUtil.toString(biz), TisUTF8.get());
        assertEquals(IOUtils.toString(assertInput, TisUTF8.get()), JsonUtil.toString(biz));
    }
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) JSONObject(com.alibaba.fastjson.JSONObject) InputStream(java.io.InputStream) AjaxValve(com.qlangtech.tis.manage.common.valve.AjaxValve)

Example 13 with Result

use of com.opensymphony.xwork2.Result in project tis by qlangtech.

the class TestPluginAction method testGetPluginConfigInfoWithTargetDescriptorName.

/**
 * 在DataX实例创建时,使用Mysql类型的Reader时 需要选择导入表的的步骤中需要使用到
 *
 * @throws Exception
 */
public void testGetPluginConfigInfoWithTargetDescriptorName() throws Exception {
    // this.servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,);
    // event_submit_do_get_plugin_config_info: y
    // action: plugin_action
    // plugin: dataxReader:require,targetDescriptorName_MySQL,subFormFieldName_selectedTabs,dataxName_baisuitest
    // doGetPluginConfigInfo
    String dataXName = "baisuitestTestcase";
    request.addHeader(DataxReader.HEAD_KEY_REFERER, "/x/" + dataXName + "/config");
    request.setParameter("event_submit_do_get_plugin_config_info", "y");
    request.setParameter("action", "plugin_action");
    request.setParameter("plugin", "dataxReader:require,targetDescriptorName_MySQL,subFormFieldName_selectedTabs,dataxName_" + dataXName);
    // JSONObject content = new JSONObject();
    // 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("PluginAction_ajax", result);
    AjaxValve.ActionExecResult aResult = showBizResult();
    assertNotNull(aResult);
    assertTrue(aResult.isSuccess());
    Object bizResult = aResult.getBizResult();
    assertNotNull(bizResult);
    JSONObject bizJSON = (JSONObject) bizResult;
    JSONArray plugins = bizJSON.getJSONArray("plugins");
    assertEquals(1, plugins.size());
    JSONObject plugin = plugins.getJSONObject(0);
    JSONObject descriptors = plugin.getJSONObject("descriptors");
    JSONObject descriptor = null;
    JSONObject subFormMeta = null;
    int descriptorCount = 0;
    for (String readerImpl : descriptors.keySet()) {
        assertEquals("com.qlangtech.tis.plugin.datax.DataxMySQLReader", readerImpl);
        descriptor = descriptors.getJSONObject(readerImpl);
        assertNotNull(descriptor);
        subFormMeta = descriptor.getJSONObject("subFormMeta");
        assertNotNull(subFormMeta);
        JsonUtil.assertJSONEqual(TestPluginAction.class, "pluginAction-subformmeta.json", subFormMeta, (m, e, a) -> {
            assertEquals(m, e, a);
        });
        descriptorCount++;
    }
    assertEquals(1, descriptorCount);
    this.verifyAll();
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) JSONObject(com.alibaba.fastjson.JSONObject) AjaxValve(com.qlangtech.tis.manage.common.valve.AjaxValve) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject)

Example 14 with Result

use of com.opensymphony.xwork2.Result in project tis by qlangtech.

the class TestOfflineDatasourceAction method testDoGetDsTabsVals.

public void testDoGetDsTabsVals() throws Exception {
    // request.addHeader(DataxReader.HEAD_KEY_REFERER, "/x/" + dataXName + "/config");
    request.setParameter("emethod", "get_ds_tabs_vals");
    request.setParameter("action", "offline_datasource_action");
    // 
    String postContent = "{\n" + "    \"tabs\":[\n" + "        \"base\"\n" + "    ],\n" + "    \"name\":\"dataxReader\",\n" + "    \"require\":true,\n" + "    \"extraParam\":\"" + SubFormFilter.PLUGIN_META_TARGET_DESCRIPTOR_NAME + "_MySQL," + SubFormFilter.PLUGIN_META_SUB_FORM_FIELD + "_selectedTabs," + DataxUtils.DATAX_DB_NAME + "_order,maxReaderTableCount_9999\"\n" + "}";
    request.setContent(postContent.getBytes(TisUTF8.get()));
    ActionProxy proxy = getActionProxy();
    String result = proxy.execute();
    assertEquals("PluginAction_ajax", result);
    AjaxValve.ActionExecResult aResult = showBizResult();
    assertNotNull(aResult);
    assertTrue(aResult.isSuccess());
    Object bizResult = aResult.getBizResult();
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) AjaxValve(com.qlangtech.tis.manage.common.valve.AjaxValve)

Example 15 with Result

use of com.opensymphony.xwork2.Result in project tis by qlangtech.

the class CollectionAction method doQuery.

/**
 * 利用solr的disMax QP进行查询
 *
 * @param context
 * @throws Exception
 */
public void doQuery(Context context) throws Exception {
    // this.parseJsonPost();
    JSONObject post = getIndexWithPost();
    // if (StringUtils.isEmpty(post.getString(KEY_INDEX_NAME))) {
    // throw new IllegalArgumentException("indexName can not be null");
    // }
    // this.indexName = TISCollectionUtils.NAME_PREFIX + post.getString(KEY_INDEX_NAME);
    JSONArray searchFields = post.getJSONArray(KEY_QUERY_SEARCH_FIELDS);
    Objects.requireNonNull(searchFields, "param " + KEY_QUERY_SEARCH_FIELDS + " can not be null ");
    if (searchFields.size() < 1) {
        throw new IllegalArgumentException(KEY_QUERY_SEARCH_FIELDS + " relevant field can not be empty");
    }
    final List<SubCriteria> andQueryCriteria = Lists.newArrayList();
    searchFields.forEach((f) -> {
        SubCriteria subCriteria = new SubCriteria();
        JSONObject o = (JSONObject) f;
        Option opt = null;
        String word = null;
        for (String key : o.keySet()) {
            word = o.getString(key);
            if (StringUtils.isEmpty(word)) {
                throw new IllegalArgumentException("query field:" + key + ",relevant:" + word + ",val can not be null");
            }
            opt = new Option(key, word);
            subCriteria.addOr(opt);
        }
        andQueryCriteria.add(subCriteria);
    });
    JSONArray storedFields = post.getJSONArray(KEY_QUERY_FIELDS);
    if (storedFields == null) {
        throw new IllegalArgumentException("param 'fields' can not be null");
    }
    storedFields.stream().map((r) -> (String) r).collect(Collectors.toList());
    // final String fields = post.getString(KEY_QUERY_FIELDS);
    // if (StringUtils.isEmpty(fields)) {
    // throw new IllegalArgumentException("param 'fields' can not be null");
    // }
    final Integer limit = post.getInteger(KEY_QUERY_LIMIT);
    if (limit == null) {
        throw new IllegalArgumentException("param limit can not be null");
    }
    // final String queryFields = post.getString(KEY_QUERY_QUERY_FIELDS);
    // if (StringUtils.isEmpty(queryFields)) {
    // throw new IllegalArgumentException("'queryFields' can not be null");
    // }
    final String orderBy = post.getString(KEY_QUERY_ORDER_BY);
    Integer rowsOffset = post.getInteger(KEY_QUERY_ROWS_OFFSET);
    AppDomainInfo app = getAppDomain();
    final QueryResutStrategy queryResutStrategy = QueryIndexServlet.createQueryResutStrategy(app, this.getRequest(), getResponse(), getDaoContext());
    final List<ServerJoinGroup> serverlist = queryResutStrategy.queryProcess();
    for (ServerJoinGroup server : serverlist) {
        // 组装url
        final String url = server.getIpAddress();
        QueryCloudSolrClient solrClient = new QueryCloudSolrClient(url);
        SolrQuery query = new SolrQuery();
        query.set(CommonParams.FL, storedFields.stream().map((r) -> (String) r).collect(Collectors.joining(",")));
        // query.setParam(QUERY_PARSIING_DEF_TYPE, "dismax");
        // query.setParam(DisMaxParams.QF, queryFields);
        query.setQuery(this.createQuery(andQueryCriteria));
        query.setRows(limit);
        if (rowsOffset != null) {
            query.setStart(rowsOffset);
        }
        if (StringUtils.isNotEmpty(orderBy)) {
            query.add(CommonParams.SORT, orderBy);
        }
        QueryResponse result = solrClient.query(indexName.getCollectionName(), query, SolrRequest.METHOD.POST);
        solrClient.close();
        Map<String, Object> biz = Maps.newHashMap();
        long c = result.getResults().getNumFound();
        biz.put(RESULT_KEY_ROWS_COUNT, c);
        List<Map<String, Object>> resultList = Lists.newArrayList();
        Map<String, Object> row = null;
        for (SolrDocument doc : result.getResults()) {
            row = Maps.newHashMap();
            for (Map.Entry<String, Object> f : doc.entrySet()) {
                row.put(f.getKey(), f.getValue());
            }
            resultList.add(row);
        }
        biz.put(RESULT_KEY_ROWS, resultList);
        this.setBizResult(context, biz);
        return;
    }
}
Also used : OfflineDatasourceAction(com.qlangtech.tis.offline.module.action.OfflineDatasourceAction) StringUtils(org.apache.commons.lang.StringUtils) PluginStore(com.qlangtech.tis.plugin.PluginStore) SqlTaskNode(com.qlangtech.tis.sql.parser.SqlTaskNode) PSchemaField(com.qlangtech.tis.solrdao.pojo.PSchemaField) URL(java.net.URL) TIS(com.qlangtech.tis.TIS) LoggerFactory(org.slf4j.LoggerFactory) ReplicasSpec(com.qlangtech.tis.config.k8s.ReplicasSpec) Autowired(org.springframework.beans.factory.annotation.Autowired) LogCollectorClient(com.qlangtech.tis.rpc.grpc.log.LogCollectorClient) CreateIndexConfirmModel(com.qlangtech.tis.runtime.module.action.CreateIndexConfirmModel) SnapshotViewImplDAO(com.qlangtech.tis.manage.biz.dal.dao.impl.SnapshotViewImplDAO) StreamObserver(io.grpc.stub.StreamObserver) StatusRpcClient(com.tis.hadoop.rpc.StatusRpcClient) LogType(com.qlangtech.tis.trigger.socket.LogType) ActionContext(com.opensymphony.xwork2.ActionContext) SelectableServer(com.qlangtech.tis.coredefine.module.control.SelectableServer) IPluginStore(com.qlangtech.tis.plugin.IPluginStore) SchemaAction(com.qlangtech.tis.runtime.module.action.SchemaAction) DependencyNode(com.qlangtech.tis.sql.parser.meta.DependencyNode) IncrStreamFactory(com.qlangtech.tis.plugin.incr.IncrStreamFactory) com.qlangtech.tis.manage.common(com.qlangtech.tis.manage.common) SysInitializeAction(com.qlangtech.tis.runtime.module.action.SysInitializeAction) Descriptor(com.qlangtech.tis.extension.Descriptor) IndexQuery(com.qlangtech.tis.runtime.module.screen.IndexQuery) Collectors(java.util.stream.Collectors) Replica(org.apache.solr.common.cloud.Replica) ViewPojo(com.qlangtech.tis.runtime.module.screen.ViewPojo) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) SolrQuery(org.apache.solr.client.solrj.SolrQuery) QueryCloudSolrClient(com.qlangtech.tis.manage.servlet.QueryCloudSolrClient) RunEnvironment(com.qlangtech.tis.pubhook.common.RunEnvironment) ISchemaPluginContext(com.qlangtech.tis.solrdao.ISchemaPluginContext) TransactionStatus(org.springframework.transaction.TransactionStatus) JSONObject(com.alibaba.fastjson.JSONObject) DBConfigSuit(com.qlangtech.tis.db.parser.DBConfigSuit) com.qlangtech.tis.workflow.pojo(com.qlangtech.tis.workflow.pojo) IMessageHandler(com.qlangtech.tis.runtime.module.misc.IMessageHandler) ILogListener(com.qlangtech.tis.trigger.jst.ILogListener) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ISchemaField(com.qlangtech.tis.solrdao.ISchemaField) ParseResult(com.qlangtech.tis.solrdao.impl.ParseResult) java.util(java.util) SolrFieldsParser(com.qlangtech.tis.solrdao.SolrFieldsParser) QueryIndexServlet(com.qlangtech.tis.manage.servlet.QueryIndexServlet) Context(com.alibaba.citrus.turbine.Context) PMonotorTarget(com.qlangtech.tis.rpc.grpc.log.stream.PMonotorTarget) JSONArray(com.alibaba.fastjson.JSONArray) RpcServiceReference(com.tis.hadoop.rpc.RpcServiceReference) Lists(com.google.common.collect.Lists) QueryResutStrategy(com.qlangtech.tis.manage.servlet.QueryResutStrategy) com.qlangtech.tis.coredefine.module.action(com.qlangtech.tis.coredefine.module.action) PExecuteState(com.qlangtech.tis.rpc.grpc.log.stream.PExecuteState) com.qlangtech.tis.util(com.qlangtech.tis.util) OfflineManager(com.qlangtech.tis.offline.module.manager.impl.OfflineManager) Application(com.qlangtech.tis.manage.biz.dal.pojo.Application) Position(com.qlangtech.tis.sql.parser.meta.Position) Logger(org.slf4j.Logger) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) NodeType(com.qlangtech.tis.sql.parser.meta.NodeType) com.qlangtech.tis.plugin.ds(com.qlangtech.tis.plugin.ds) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) File(java.io.File) CommonParams(org.apache.solr.common.params.CommonParams) SchemaResult(com.qlangtech.tis.solrdao.SchemaResult) SolrDocument(org.apache.solr.common.SolrDocument) IParamContext(com.qlangtech.tis.order.center.IParamContext) ERRules(com.qlangtech.tis.sql.parser.er.ERRules) ServerJoinGroup(com.qlangtech.tis.manage.servlet.ServerJoinGroup) SqlTaskNodeMeta(com.qlangtech.tis.sql.parser.SqlTaskNodeMeta) InputStream(java.io.InputStream) QueryResutStrategy(com.qlangtech.tis.manage.servlet.QueryResutStrategy) JSONArray(com.alibaba.fastjson.JSONArray) ServerJoinGroup(com.qlangtech.tis.manage.servlet.ServerJoinGroup) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrDocument(org.apache.solr.common.SolrDocument) JSONObject(com.alibaba.fastjson.JSONObject) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) JSONObject(com.alibaba.fastjson.JSONObject) QueryCloudSolrClient(com.qlangtech.tis.manage.servlet.QueryCloudSolrClient)

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