use of com.alibaba.fastjson.JSONArray in project pinot by linkedin.
the class DeleteAPIHybridClusterIntegrationTest method deleteFromGetAPI.
@Test
public void deleteFromGetAPI() throws Exception {
String segmentList = sendGetRequest(ControllerRequestURLBuilder.baseUrl(CONTROLLER_BASE_API_URL).forSegmentListAPIWithTableType(TABLE_NAME, CommonConstants.Helix.TableType.OFFLINE.toString()));
JSONArray offlineSegmentsList = getSegmentsFromJsonSegmentAPI(segmentList, CommonConstants.Helix.TableType.OFFLINE.toString());
String removedSegment = offlineSegmentsList.get(0).toString();
long removedSegmentRows = getNumRowsFromOfflineMetadata(removedSegment);
Assert.assertNotSame(removedSegmentRows, 0L);
sendGetRequest(ControllerRequestURLBuilder.baseUrl(CONTROLLER_BASE_API_URL).forDeleteSegmentWithGetAPI(TABLE_NAME, removedSegment, CommonConstants.Helix.TableType.OFFLINE.toString()));
waitForNumRows(nOfflineRows - removedSegmentRows, CommonConstants.Helix.TableType.OFFLINE);
String postDeleteSegmentList = sendGetRequest(ControllerRequestURLBuilder.baseUrl(CONTROLLER_BASE_API_URL).forSegmentListAPIWithTableType(TABLE_NAME, CommonConstants.Helix.TableType.OFFLINE.toString()));
JSONArray offlineSegmentsListReturn = getSegmentsFromJsonSegmentAPI(postDeleteSegmentList, CommonConstants.Helix.TableType.OFFLINE.toString());
offlineSegmentsList.remove(removedSegment);
Assert.assertEquals(offlineSegmentsListReturn, offlineSegmentsList);
// Testing Delete All API here
sendGetRequest(ControllerRequestURLBuilder.baseUrl(CONTROLLER_BASE_API_URL).forDeleteAllSegmentsWithTypeWithGetAPI(TABLE_NAME, CommonConstants.Helix.TableType.OFFLINE.toString()));
waitForNumRows(0, CommonConstants.Helix.TableType.OFFLINE);
String postDeleteSegmentListAll = sendGetRequest(ControllerRequestURLBuilder.baseUrl(CONTROLLER_BASE_API_URL).forSegmentListAPIWithTableType(TABLE_NAME, CommonConstants.Helix.TableType.OFFLINE.toString()));
Assert.assertEquals(getSegmentsFromJsonSegmentAPI(postDeleteSegmentListAll, CommonConstants.Helix.TableType.OFFLINE.toString()), Collections.emptyList());
waitForSegmentsToBeInDeleteDirectory();
repushOfflineSegments();
}
use of com.alibaba.fastjson.JSONArray in project pinot by linkedin.
the class DeleteAPIHybridClusterIntegrationTest method deleteFromDeleteAPI.
@Test
public void deleteFromDeleteAPI() throws Exception {
String segmentList = sendGetRequest(ControllerRequestURLBuilder.baseUrl(CONTROLLER_BASE_API_URL).forSegmentListAPIWithTableType(TABLE_NAME, CommonConstants.Helix.TableType.OFFLINE.toString()));
JSONArray offlineSegmentsList = getSegmentsFromJsonSegmentAPI(segmentList, CommonConstants.Helix.TableType.OFFLINE.toString());
Assert.assertNotNull(offlineSegmentsList);
String removedSegment = offlineSegmentsList.get(0).toString();
long removedSegmentRows = getNumRowsFromOfflineMetadata(removedSegment);
Assert.assertNotSame(removedSegmentRows, 0L);
sendDeleteRequest(ControllerRequestURLBuilder.baseUrl(CONTROLLER_BASE_API_URL).forSegmentDeleteAPI(TABLE_NAME, removedSegment, CommonConstants.Helix.TableType.OFFLINE.toString()));
waitForNumRows(nOfflineRows - removedSegmentRows, CommonConstants.Helix.TableType.OFFLINE);
String postDeleteSegmentList = sendGetRequest(ControllerRequestURLBuilder.baseUrl(CONTROLLER_BASE_API_URL).forSegmentListAPIWithTableType(TABLE_NAME, CommonConstants.Helix.TableType.OFFLINE.toString()));
JSONArray offlineSegmentsListReturn = getSegmentsFromJsonSegmentAPI(postDeleteSegmentList, CommonConstants.Helix.TableType.OFFLINE.toString());
offlineSegmentsList.remove(removedSegment);
Assert.assertEquals(offlineSegmentsListReturn, offlineSegmentsList);
// Testing Delete All API here
sendDeleteRequest(ControllerRequestURLBuilder.baseUrl(CONTROLLER_BASE_API_URL).forSegmentDeleteAllAPI(TABLE_NAME, CommonConstants.Helix.TableType.OFFLINE.toString()));
waitForNumRows(0, CommonConstants.Helix.TableType.OFFLINE);
String postDeleteSegmentListAll = sendGetRequest(ControllerRequestURLBuilder.baseUrl(CONTROLLER_BASE_API_URL).forSegmentListAPIWithTableType(TABLE_NAME, CommonConstants.Helix.TableType.OFFLINE.toString()));
Assert.assertEquals(getSegmentsFromJsonSegmentAPI(postDeleteSegmentListAll, CommonConstants.Helix.TableType.OFFLINE.toString()), Collections.emptyList());
waitForSegmentsToBeInDeleteDirectory();
repushOfflineSegments();
}
use of com.alibaba.fastjson.JSONArray in project otter by alibaba.
the class TestEventProcessor method process.
public boolean process(EventData eventData) {
// 基本步骤:
// 1. 获取binlog中的变更字段
// 2. 根据业务逻辑进行判断,如果需要忽略本条数据同步,直接返回false,否则返回true
// 3. 根据业务逻辑进行逻辑转化,比如可以修改整个EventData数据.
// 本文例子:源库的每条binlog变更,记录到一个日志表binlog
// create table test.binlog(
// id bigint(20) auto_increment,
// oschema varchar(256),
// otable varchar(256),
// gtime varchar(32)
// ovalue text,
// primary key(id);
// )
// 在process处理中,可以修改EventData的任何数据,达到数据转换的效果, just have fun.
JSONObject col = new JSONObject();
JSONArray array = new JSONArray();
for (EventColumn column : eventData.getColumns()) {
JSONObject obj = this.doColumn(column);
array.add(obj);
}
for (EventColumn key : eventData.getKeys()) {
JSONObject obj = this.doColumn(key);
array.add(obj);
}
col.put("schema", eventData.getSchemaName());
col.put("table", eventData.getTableName());
col.put("columns", array);
col.put("dml", eventData.getEventType());
col.put("exectime", eventData.getExecuteTime());
// 构造新的主键
EventColumn id = new EventColumn();
id.setColumnValue(eventData.getSchemaName());
id.setColumnType(Types.BIGINT);
id.setColumnName("id");
// 构造新的字段
EventColumn schema = new EventColumn();
schema.setColumnValue(eventData.getSchemaName());
schema.setColumnType(Types.VARCHAR);
schema.setColumnName("oschema");
EventColumn table = new EventColumn();
table.setColumnValue(eventData.getTableName());
table.setColumnType(Types.VARCHAR);
table.setColumnName("otable");
EventColumn ovalue = new EventColumn();
ovalue.setColumnValue(col.toJSONString());
ovalue.setColumnType(Types.VARCHAR);
ovalue.setColumnName("ovalue");
EventColumn gtime = new EventColumn();
gtime.setColumnValue(eventData.getExecuteTime() + "");
gtime.setColumnType(Types.VARCHAR);
gtime.setColumnName("gtime");
// 替换为新的字段和主键信息
List<EventColumn> cols = new ArrayList<EventColumn>();
cols.add(schema);
cols.add(table);
cols.add(gtime);
cols.add(ovalue);
eventData.setColumns(cols);
List<EventColumn> keys = new ArrayList<EventColumn>();
keys.add(id);
eventData.setKeys(keys);
//修改数据meta信息
eventData.setEventType(EventType.INSERT);
eventData.setSchemaName("test");
eventData.setTableName("binlog");
return true;
}
use of com.alibaba.fastjson.JSONArray in project atlas by alibaba.
the class DexDiffInfo method writeToFile.
public void writeToFile(String bundleName, File diffFile, File diffJsonFile) throws IOException {
JSONArray jsonArray = new JSONArray();
if (diffJsonFile.exists()) {
String content = FileUtils.readFileToString(diffJsonFile);
jsonArray = JSONArray.parseArray(content);
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("bundleName", bundleName);
if (addedMethods.size() > 0) {
List<String> addMethods = new ArrayList<String>();
List<MethodDiffInfoObject> diffInfoObjects = new ArrayList<MethodDiffInfoObject>();
for (DexBackedMethod method : addedMethods) {
addMethods.add("[add new Method:]" + method.getReturnType() + " " + method.getName() + "(" + Formater.formatStringList(method.getParameterTypes()) + ") in Class:" + method.getDefiningClass());
MethodDiffInfoObject diffInfoObject = new MethodDiffInfoObject();
diffInfoObject.setDiffType(DiffType.ADD);
diffInfoObject.setReturnType(method.getReturnType());
diffInfoObject.setMethodDeclaration(method.getName() + "(" + Formater.formatStringList(method.getParameterTypes()) + ")");
diffInfoObject.setInClass(method.getDefiningClass());
diffInfoObjects.add(diffInfoObject);
}
FileUtils.writeLines(diffFile, addMethods, true);
jsonObject.put("addedMethods", diffInfoObjects);
}
if (modifiedMethods.size() > 0) {
List<String> modifyMethods = new ArrayList<String>();
List<MethodDiffInfoObject> diffInfoObjects = new ArrayList<MethodDiffInfoObject>();
for (DexBackedMethod method : modifiedMethods) {
modifyMethods.add("[modify Method:]" + method.getReturnType() + " " + method.getName() + "(" + Formater.formatStringList(method.getParameterTypes()) + ") in Class:" + method.getDefiningClass());
MethodDiffInfoObject diffInfoObject = new MethodDiffInfoObject();
diffInfoObject.setDiffType(DiffType.MODIFY);
diffInfoObject.setReturnType(method.getReturnType());
diffInfoObject.setMethodDeclaration(method.getName() + "(" + Formater.formatStringList(method.getParameterTypes()) + ")");
diffInfoObject.setInClass(method.getDefiningClass());
diffInfoObjects.add(diffInfoObject);
}
FileUtils.writeLines(diffFile, modifyMethods, true);
jsonObject.put("modifiedMethods", diffInfoObjects);
}
jsonArray.add(jsonObject);
FileUtils.writeStringToFile(diffJsonFile, JSON.toJSONString(jsonArray));
}
use of com.alibaba.fastjson.JSONArray in project AisenWeiBo by wangdan.
the class SinaSDK method searchsResultUsers.
/**
* 使用H5页面查询用户
*
* @param q
* @param cookies
* @return
* @throws TaskException
*/
public ArrayList<SearchsResultUser> searchsResultUsers(String q, String cookies) throws TaskException {
ArrayList<SearchsResultUser> resultUsers = new ArrayList<>();
Setting action = newSetting("searchsResultUsers", "page/pageJson", "获取用户");
action.getExtras().put(BASE_URL, newSettingExtra(BASE_URL, "http://m.weibo.cn/", ""));
Params params = new Params();
// params.addParameter("containerid", "100103");
// params.addParameter("type", "3");
// params.addParameter("page", "1");
// params.addParameter("q", q);
// 我也搞不懂这个脑残接口到底怎么玩的
// http://m.weibo.cn/page/pageJson?containerid=100103type%3D3%26q%3Dwang&page=1
params.addParameter("containerid", "100103type%3D3%26q%3D" + q + "&page=1");
try {
HttpConfig config = getHttpConfig();
// config.cookie = cookies;
// config.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
// config.addHeader("Referer", "http://m.weibo.cn/searchs");
String response = doGet(config, action, params, String.class);
JSONObject responseJSON = JSONObject.parseObject(response);
int ok = responseJSON.getInteger("ok");
if (ok == 1) {
JSONArray cardsArray = responseJSON.getJSONArray("cards");
if (cardsArray.size() > 0) {
JSONObject cardGroupsObject = cardsArray.getJSONObject(1);
JSONArray cardGroupArray = cardGroupsObject.getJSONArray("card_group");
for (int i = 0; i < cardGroupArray.size(); i++) {
JSONObject cardGroup = cardGroupArray.getJSONObject(i);
SearchsResultUser user = new SearchsResultUser();
user.setDesc1(cardGroup.getString("desc1"));
user.setDesc2(cardGroup.getString("desc2"));
JSONObject userJSON = cardGroup.getJSONObject("user");
user.setId(userJSON.getString("id"));
user.setFollowing(userJSON.getBoolean("following"));
user.setFollow_me(userJSON.getBoolean("follow_me"));
user.setFansNum(userJSON.getString("fansNum"));
user.setScreen_name(userJSON.getString("screen_name"));
user.setDescription(userJSON.getString("description"));
user.setProfile_image_url(userJSON.getString("profile_image_url"));
user.setStatuses_count(userJSON.getInteger("statuses_count"));
user.setGender(userJSON.getString("gender"));
user.setRemark(userJSON.getString("remark"));
resultUsers.add(user);
}
}
}
} catch (Exception e) {
e.printStackTrace();
if (e instanceof TaskException) {
throw e;
}
}
return resultUsers;
}
Aggregations