use of com.alibaba.citrus.turbine.Context in project tis by qlangtech.
the class TestPluginItems method validateRootFormSave.
private void validateRootFormSave() {
IPluginContext pluginContext = EasyMock.createMock("pluginContext", IPluginContext.class);
EasyMock.expect(pluginContext.isDataSourceAware()).andReturn(false);
EasyMock.expect(pluginContext.isCollectionAware()).andReturn(false).anyTimes();
EasyMock.expect(pluginContext.getRequestHeader(DataxReader.HEAD_KEY_REFERER)).andReturn("/x/" + dataXName + "/config").anyTimes();
Context context = EasyMock.createMock("context", Context.class);
// targetDescriptorName_MySQL,subFormFieldName_selectedTabs
UploadPluginMeta pluginMeta = UploadPluginMeta.parse("dataxReader:require,dataxName_" + dataXName);
PluginItems pluginItems = new PluginItems(pluginContext, pluginMeta);
IControlMsgHandler fieldErrorHandler = EasyMock.createMock("fieldErrorHandler", IControlMsgHandler.class);
JSONArray jsonArray = IOUtils.loadResourceFromClasspath(TestPluginItems.class, "datax_reader_mysql_post.json", true, (input) -> {
return JSON.parseArray(org.apache.commons.io.IOUtils.toString(input, TisUTF8.get()));
});
JSONArray itemsArray = jsonArray.getJSONArray(0);
Optional<IPropertyType.SubFormFilter> subFormFilter = pluginMeta.getSubFormFilter();
assertFalse("subFormFilter.isPresent():false", subFormFilter.isPresent());
List<AttrValMap> items = AttrValMap.describableAttrValMapList(fieldErrorHandler, itemsArray, subFormFilter);
pluginItems.items = items;
EasyMock.replay(pluginContext, context, fieldErrorHandler);
pluginItems.save(context);
EasyMock.verify(pluginContext, context, fieldErrorHandler);
}
use of com.alibaba.citrus.turbine.Context 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;
}
}
use of com.alibaba.citrus.turbine.Context in project tis by qlangtech.
the class CoreAction method pushConfig2Engine.
public static void pushConfig2Engine(BasicModule module, Context context, DocCollection collection, int snapshotId, boolean needReload) throws Exception {
// module.errorsPageShow(context);
if (traverseCollectionReplic(collection, false, /* collection */
new ReplicaCallback() {
@Override
public boolean process(boolean isLeader, final Replica replica) throws Exception {
try {
URL url = new URL(replica.getStr(BASE_URL_PROP) + "/admin/cores?action=CREATEALIAS&" + ICoreAdminAction.EXEC_ACTION + "=" + ICoreAdminAction.ACTION_UPDATE_CONFIG + "&core=" + replica.getStr(CORE_NAME_PROP) + "&" + ZkStateReader.COLLECTION_PROP + "=" + collection.getName() + "&needReload=" + needReload + "&" + ICoreAdminAction.TARGET_SNAPSHOT_ID + "=" + snapshotId);
return HttpUtils.processContent(url, new StreamProcess<Boolean>() {
@Override
public Boolean p(int status, InputStream stream, Map<String, List<String>> headerFields) {
ProcessResponse result = null;
if ((result = ProcessResponse.processResponse(stream, (err) -> module.addErrorMessage(context, replica.getName() + "," + err))).success) {
// addActionMessage(context, "成功触发了创建索引集群" + groupNum + "组,组内" + repliationCount + "个副本");
// return true;
}
return true;
}
});
} catch (MalformedURLException e) {
// e.printStackTrace();
log.error(collection.getName(), e);
module.addErrorMessage(context, e.getMessage());
}
return true;
}
})) {
// module.addActionMessage(context, "已经更新全部服务器配置文件");
}
}
use of com.alibaba.citrus.turbine.Context in project tis by qlangtech.
the class SchemaAction method appendNewSchema.
@SuppressWarnings("all")
protected boolean appendNewSchema(Context context, ISchemaPluginContext schemaPlugin, byte[] content, Application app) throws UnsupportedEncodingException, JSONException {
if (content == null) {
throw new NullPointerException("param content can not be null");
}
Integer publishSnapshotId = null;
final ServerGroupCriteria gquery = new ServerGroupCriteria();
final RunEnvironment runtime = RunEnvironment.getSysRuntime();
gquery.createCriteria().andAppIdEqualTo(app.getAppId()).andRuntEnvironmentEqualTo(runtime.getId()).andGroupIndexEqualTo((short) 0);
for (ServerGroup group : this.getServerGroupDAO().selectByExample(gquery)) {
publishSnapshotId = group.getPublishSnapshotId();
break;
}
if (publishSnapshotId == null) {
throw new IllegalStateException("app:" + app.getProjectName() + " publishSnapshotId can not be null");
}
IUser user = this.getUser();
// new
Long usrId = Long.parseLong(user.getId());
// Long(this.getCurrentIsv().getId());
CreateSnapshotResult result = createNewSnapshot(context, schemaPlugin, this.getSnapshotViewDAO().getView(publishSnapshotId), ConfigFileReader.FILE_SCHEMA, content, this, new IMessageHandler() {
@Override
public void errorsPageShow(Context context) {
}
@Override
public void addActionMessage(Context context, String msg) {
SchemaAction.this.addActionMessage(context, msg);
}
@Override
public void setBizResult(Context context, Object result) {
SchemaAction.this.setBizResult(context, result);
}
@Override
public void addErrorMessage(Context context, String msg) {
SchemaAction.this.addErrorMessage(context, msg);
}
}, StringUtils.EMPTY, usrId, user.getName());
if (!result.isSuccess()) {
List<String> errorMsgList = (List<String>) context.get(BasicModule.ACTION_ERROR_MSG);
StringBuffer err = new StringBuffer();
if (errorMsgList != null) {
for (String e : errorMsgList) {
err.append(e).append("<br/>");
}
}
JSONObject errors = new JSONObject();
errors.put("code", 300);
errors.put("reason", err.toString());
context.put("query_result", errors);
return false;
}
ServerGroup record = new ServerGroup();
record.setPublishSnapshotId(result.getNewId());
// .andGroupIndexEqualTo((short) 0);
if (this.getServerGroupDAO().updateByExampleSelective(record, gquery) < 0) {
throw new IllegalStateException("app:" + app.getProjectName() + " upate getServerGroupDAO have not success");
}
return true;
}
use of com.alibaba.citrus.turbine.Context in project tis by qlangtech.
the class DataSourceFactoryPluginStore method setPlugins.
@Override
public synchronized boolean setPlugins(IPluginContext pluginContext, Optional<Context> context, List<Descriptor.ParseDescribable<DataSourceFactory>> dlist, boolean update) {
if (dlist.size() != 1) {
throw new IllegalArgumentException("size of dlist must equal to 1");
}
if (!context.isPresent()) {
throw new IllegalArgumentException("Context shall exist");
}
Context ctx = context.get();
final String dbName = this.key.keyVal.getVal();
if (!super.setPlugins(pluginContext, context, dlist, update)) {
return false;
}
Descriptor.ParseDescribable<DataSourceFactory> dbDesc = dlist.get(0);
pluginContext.addDb(dbDesc, dbName, ctx, (shallUpdateDB && !update));
return !ctx.hasErrors();
}
Aggregations