diff --git a/src/main/java/com/aliyun/openservices/log/sample/ScmSample.java b/src/main/java/com/aliyun/openservices/log/sample/ScmSample.java index ea9416d0..5715508f 100755 --- a/src/main/java/com/aliyun/openservices/log/sample/ScmSample.java +++ b/src/main/java/com/aliyun/openservices/log/sample/ScmSample.java @@ -363,8 +363,6 @@ public void ListACLs() { public void CreateMachineGroup() { //Construct machineGroup type1: using ArrayList to create machinelist - String groupType = "Armory"; - String externalName = "testgroup"; String groupTopic = "testtopic"; ArrayList machineList = new ArrayList(); @@ -372,8 +370,6 @@ public void CreateMachineGroup() { machineList.add("127.0.0.2"); MachineGroup group = new MachineGroup(testMachineGroupName, "ip", machineList); - group.SetGroupType(groupType); - group.SetExternalName(externalName); group.SetGroupTopic(groupTopic); try { @@ -388,19 +384,16 @@ public void CreateMachineGroup() { } public void UpdateMachineGroup() { //Construct machineGroup type2: using JSONArray to create machinelist - String groupType = ""; - String externalName = "testgroup2"; String groupTopic = "testtopic2"; ArrayList machineList = new ArrayList(); machineList.add("uu_id_1"); machineList.add("uu_id_2"); - GroupAttribute groupAttribute = new GroupAttribute(externalName, groupTopic); + GroupAttribute groupAttribute = new GroupAttribute("", groupTopic); MachineGroup group = new MachineGroup(testMachineGroupName, "userdefined", machineList); - group.SetGroupType(groupType); group.SetGroupAttribute(groupAttribute); try { diff --git a/src/test/java/com/aliyun/openservices/log/functiontest/SlsClientUnitTest.java b/src/test/java/com/aliyun/openservices/log/functiontest/SlsClientUnitTest.java index a9321954..f3094217 100644 --- a/src/test/java/com/aliyun/openservices/log/functiontest/SlsClientUnitTest.java +++ b/src/test/java/com/aliyun/openservices/log/functiontest/SlsClientUnitTest.java @@ -381,11 +381,9 @@ public void TestExtractConfigFromResponse() { public void TestExtractMachineGroupFromResponse() { JSONObject jObj = new JSONObject(); jObj.put("groupName", "testgroup"); - jObj.put("groupType", "Armory"); jObj.put("machineIdentifyType", "uuid"); JSONObject groupAttribute = new JSONObject(); - groupAttribute.put("externalName", "testgroupX"); groupAttribute.put("groupTopic", "topic"); jObj.put("groupAttribute", groupAttribute); @@ -407,9 +405,7 @@ public void TestExtractMachineGroupFromResponse() { } assertEquals(group.GetGroupName(), "testgroup"); - assertEquals(group.GetGroupType(), "Armory"); assertEquals(group.GetMachineIdentifyType(), "uuid"); - assertEquals(group.GetExternalName(), "testgroupX"); assertEquals(group.GetGroupTopic(), "topic"); assertEquals(group.GetMachineList().size(), machineList.size()); @@ -921,8 +917,6 @@ public void TestCreateMachineGroup() { String testGroupName = "test_group"; String machineIdentifyType = "uuid"; - String groupType = "Armory"; - String externalName = "testgroup"; ArrayList machineList = new ArrayList(); machineList.add("UUID1"); @@ -930,8 +924,6 @@ public void TestCreateMachineGroup() { MachineGroup group = new MachineGroup(testGroupName, "userdefined", machineList); group.SetMachineIdentifyType(machineIdentifyType); - group.SetGroupType(groupType); - group.SetExternalName(externalName); String project = "test-project"; @@ -1049,8 +1041,6 @@ public void TestUpdateMachineGroup() { String testGroupName = "test_group"; String machineIdentifyType = "uuid"; - String groupType = ""; - String externalName = "testgroup2"; String groupTopic = "groupTopic2"; ArrayList machineList = new ArrayList(); @@ -1058,8 +1048,6 @@ public void TestUpdateMachineGroup() { MachineGroup group = new MachineGroup(testGroupName, "userdefined", machineList); group.SetMachineIdentifyType(machineIdentifyType); - group.SetGroupType(groupType); - group.SetExternalName(externalName); group.SetGroupTopic(groupTopic); String project = "test-project"; @@ -1206,9 +1194,7 @@ public void TestRemoveConfigFromMachineGroup() { @Test public void TestGetMachineGroup() { String testGroupName = "test_group"; - String groupType = "Armory"; String machineIdentifyType = "uuid"; - String externalName = "testgroup"; String groupTopic = "groupTopic"; JSONArray machineList = new JSONArray(); @@ -1218,8 +1204,6 @@ public void TestGetMachineGroup() { MachineGroup group = new MachineGroup(); group.SetMachineIdentifyType(machineIdentifyType); group.SetGroupName(testGroupName); - group.SetGroupType(groupType); - group.SetExternalName(externalName); group.SetGroupTopic(groupTopic); group.SetMachineList(machineList); @@ -1230,10 +1214,8 @@ public void TestGetMachineGroup() { JSONObject groupDict = new JSONObject(); groupDict.put("groupName", group.GetGroupName()); - groupDict.put("groupType", group.GetGroupType()); JSONObject groupAttributeDict = new JSONObject(); - groupAttributeDict.put("externalName", group.GetGroupAttribute().GetExternalName()); groupAttributeDict.put("groupTopic", group.GetGroupAttribute().GetGroupTopic()); groupDict.put("groupAttribute", groupAttributeDict); @@ -1269,9 +1251,7 @@ public void TestGetMachineGroup() { mock.ChangeResponse(response); GetMachineGroupResponse res = mock.GetMachineGroup(project, testGroupName); assertEquals("group name does not match", testGroupName, res.GetMachineGroup().GetGroupName()); - assertEquals("group type does not match", groupType, res.GetMachineGroup().GetGroupType()); assertEquals("machineIdentifyType does not match", machineIdentifyType, res.GetMachineGroup().GetMachineIdentifyType()); - assertEquals("external name does not match", externalName, res.GetMachineGroup().GetExternalName()); assertEquals("group topic does not match", groupTopic, res.GetMachineGroup().GetGroupTopic()); assertEquals("createTime does not match", createTime, res.GetMachineGroup().GetCreateTime()); assertEquals("lastModifyTime does not match", lastModifyTime, res.GetMachineGroup().GetLastModifyTime()); @@ -2261,16 +2241,16 @@ public void TestGetHistograms() { try { mock.ChangeResponse(response); GetHistogramsResponse res = mock.GetHistograms("project", "logStore", 0, 0, "topic", "query"); - - /* - String resComplete = "Incomplete"; - if (res.IsCompleted()) { - resComplete = "Complete"; - } - - assertEquals("Complete", resComplete); - assertEquals(300, res.GetTotalCount()); - */ + + /* + String resComplete = "Incomplete"; + if (res.IsCompleted()) { + resComplete = "Complete"; + } + + assertEquals("Complete", resComplete); + assertEquals(300, res.GetTotalCount()); + */ assertEquals(histograms.size(), res.GetHistograms().size()); for (int i = 0; i < histograms.size(); i++) { assertEquals(histograms.get(i).GetCount(), res.GetHistograms().get(i).GetCount()); @@ -2949,21 +2929,21 @@ public void TestCommonMisc() { } catch (LogException e) { assertTrue(e.GetErrorMessage(), false); } - - - /*String logStoreJsonString = logStore.ToJsonString(); - JSONObject logStoreJson = JSONObject.parseObject(logStoreJsonString); - LogStore another = new LogStore(); - try { - another.FromJsonObject(logStoreJson); - assertEquals(another.GetLogStoreName(), logStore.GetLogStoreName()); - assertEquals(another.GetShardCount(), logStore.GetShardCount()); - assertEquals(another.GetTtl(), logStore.GetTtl()); - assertEquals(another.GetCreateTime(), logStore.GetCreateTime()); - assertEquals(another.GetLastModifyTime(), logStore.GetLastModifyTime()); - } catch (LogException e) { - assertTrue(e.GetErrorMessage(), false); - }*/ + + + /*String logStoreJsonString = logStore.ToJsonString(); + JSONObject logStoreJson = JSONObject.parseObject(logStoreJsonString); + LogStore another = new LogStore(); + try { + another.FromJsonObject(logStoreJson); + assertEquals(another.GetLogStoreName(), logStore.GetLogStoreName()); + assertEquals(another.GetShardCount(), logStore.GetShardCount()); + assertEquals(another.GetTtl(), logStore.GetTtl()); + assertEquals(another.GetCreateTime(), logStore.GetCreateTime()); + assertEquals(another.GetLastModifyTime(), logStore.GetLastModifyTime()); + } catch (LogException e) { + assertTrue(e.GetErrorMessage(), false); + }*/ LogItem log = new LogItem(12); @@ -3057,126 +3037,121 @@ public void TestCommonMisc() { acl.SetPrinciple("ID"); assertEquals("ID", acl.GetPrinciple()); - GroupAttribute attribute = new GroupAttribute("externalName1", "groupTopic1"); - assertEquals("externalName1", attribute.GetExternalName()); + GroupAttribute attribute = new GroupAttribute("", "groupTopic1"); assertEquals("groupTopic1", attribute.GetGroupTopic()); - String fromAttributeStr = "{\"externalName\":\"externalName2\",\"groupTopic\":\"groupTopic2\"}"; + String fromAttributeStr = "{\"groupTopic\":\"groupTopic2\"}"; try { attribute.FromJsonString(fromAttributeStr); - assertEquals("externalName2", attribute.GetExternalName()); assertEquals("groupTopic2", attribute.GetGroupTopic()); } catch (LogException e) { assertTrue(e.GetErrorMessage(), false); } - - /*try { - JSONObject errorInfoObj = new JSONObject(); - attribute.FromJsonObject(errorInfoObj); - } catch (LogException e) { - assertEquals("FailToGenerateGroupAttribute", e.GetErrorCode()); - }*/ + + /*try { + JSONObject errorInfoObj = new JSONObject(); + attribute.FromJsonObject(errorInfoObj); + } catch (LogException e) { + assertEquals("FailToGenerateGroupAttribute", e.GetErrorCode()); + }*/ try { attribute.FromJsonString("af"); } catch (LogException e) { assertEquals("FailToGenerateGroupAttribute", e.GetErrorCode()); } - - /*ArrayList machineList = new ArrayList(); - machineList.add("uuid1"); - MachineGroup group1 = new MachineGroup("groupName", "userdefined", machineList); - group1.SetGroupAttribute(attribute); - group1.SetGroupType("type1"); - group1.SetCreateTime(543211); - group1.SetLastModifyTime(543212); - - String groupJsonStr = group1.ToJsonString(); - JSONObject groupJsonObj = JSONObject.parseObject(groupJsonStr); - - assertEquals("groupName", groupJsonObj.getString("groupName")); - assertEquals("type1", groupJsonObj.getString("groupType")); - assertEquals(543211, groupJsonObj.getIntValue("createTime")); - assertEquals(543212, groupJsonObj.getIntValue("lastModifyTime")); - - assertEquals("externalName2", groupJsonObj.getJSONObject("groupAttribute").getString("externalName")); - assertEquals("groupTopic2", groupJsonObj.getJSONObject("groupAttribute").getString("groupTopic")); - - assertEquals(1, groupJsonObj.getJSONArray("machineList").size()); - String machine1 = groupJsonObj.getJSONArray("machineList").getString(0); - assertEquals("uuid1", machine1); - - try { - group1.FromJsonString("af"); - } catch (LogException e) { - assertEquals("FailToGenerateMachineGroup", e.GetErrorCode()); - } - - Config config1 = new Config("configName"); - config1.SetCreateTime(32321); - config1.SetLastModifyTime(32322); - JSONObject configObj = JSONObject.parseObject(config1.ToJsonString()); - assertEquals("configName", configObj.getString("configName")); - assertEquals(32321, configObj.getIntValue("createTime")); - assertEquals(32322, configObj.getIntValue("lastModifyTime")); - - try { - config1.FromJsonString("af"); - } catch (LogException e) { - assertEquals("FailToGenerateConfig", e.GetErrorCode()); - } - - ACLPrivileges privileges = new ACLPrivileges(); - String privilegesStr = "[\"READ\",\"WRITE\",\"READ\"]"; - try { - privileges.FromJsonString(privilegesStr); - assertEquals(2, privileges.GetPrivileges().size()); - assertEquals(ACLPrivilege.READ, privileges.GetPrivileges().get(0)); - assertEquals(ACLPrivilege.WRITE, privileges.GetPrivileges().get(1)); - } catch (LogException e) { - assertTrue(e.GetErrorMessage(), false); - } - - try { - privileges.FromJsonString("fsad"); - } catch (LogException e) { - assertEquals("FailToGenerateACLPrivileges", e.GetErrorCode()); - } - - ACL acl1 = new ACL(); - try { - acl1.FromJsonString("fsad"); - } catch (LogException e) { - assertEquals("FailToGenerateACL", e.GetErrorCode()); - } - - acl1.SetCreateTime(3321); - acl1.SetLastModifyTime(3322); - - acl1.SetPrinciple("principle"); - acl1.SetPrivilege(privileges); - - try { - JSONObject aclDict = JSONObject.parseObject(acl1.ToJsonString()); - assertEquals(3321, aclDict.getIntValue("createTime")); - assertEquals(3322, aclDict.getIntValue("lastModifyTime")); - assertEquals("principle", aclDict.getString("principle")); - - JSONArray privilegesArray = aclDict.getJSONArray("privilege"); - assertEquals(2, privilegesArray.size()); - assertEquals("READ", privilegesArray.getString(0)); - assertEquals("WRITE", privilegesArray.getString(1)); - } catch (LogException e) { - assertTrue(e.GetErrorMessage(), false); - } - - try { - acl1.SetPrivilege(new ACLPrivileges()); - acl1.ToRequestJson(); - } catch (LogException e) { - assertEquals("BadResponse", e.GetErrorCode()); - assertEquals("ACL privilege must have at least one value", e.GetErrorMessage()); - }*/ + + /*ArrayList machineList = new ArrayList(); + machineList.add("uuid1"); + MachineGroup group1 = new MachineGroup("groupName", "userdefined", machineList); + group1.SetGroupAttribute(attribute); + group1.SetCreateTime(543211); + group1.SetLastModifyTime(543212); + + String groupJsonStr = group1.ToJsonString(); + JSONObject groupJsonObj = JSONObject.parseObject(groupJsonStr); + + assertEquals("groupName", groupJsonObj.getString("groupName")); + assertEquals(543211, groupJsonObj.getIntValue("createTime")); + assertEquals(543212, groupJsonObj.getIntValue("lastModifyTime")); + + assertEquals("groupTopic2", groupJsonObj.getJSONObject("groupAttribute").getString("groupTopic")); + + assertEquals(1, groupJsonObj.getJSONArray("machineList").size()); + String machine1 = groupJsonObj.getJSONArray("machineList").getString(0); + assertEquals("uuid1", machine1); + + try { + group1.FromJsonString("af"); + } catch (LogException e) { + assertEquals("FailToGenerateMachineGroup", e.GetErrorCode()); + } + + Config config1 = new Config("configName"); + config1.SetCreateTime(32321); + config1.SetLastModifyTime(32322); + JSONObject configObj = JSONObject.parseObject(config1.ToJsonString()); + assertEquals("configName", configObj.getString("configName")); + assertEquals(32321, configObj.getIntValue("createTime")); + assertEquals(32322, configObj.getIntValue("lastModifyTime")); + + try { + config1.FromJsonString("af"); + } catch (LogException e) { + assertEquals("FailToGenerateConfig", e.GetErrorCode()); + } + + ACLPrivileges privileges = new ACLPrivileges(); + String privilegesStr = "[\"READ\",\"WRITE\",\"READ\"]"; + try { + privileges.FromJsonString(privilegesStr); + assertEquals(2, privileges.GetPrivileges().size()); + assertEquals(ACLPrivilege.READ, privileges.GetPrivileges().get(0)); + assertEquals(ACLPrivilege.WRITE, privileges.GetPrivileges().get(1)); + } catch (LogException e) { + assertTrue(e.GetErrorMessage(), false); + } + + try { + privileges.FromJsonString("fsad"); + } catch (LogException e) { + assertEquals("FailToGenerateACLPrivileges", e.GetErrorCode()); + } + + ACL acl1 = new ACL(); + try { + acl1.FromJsonString("fsad"); + } catch (LogException e) { + assertEquals("FailToGenerateACL", e.GetErrorCode()); + } + + acl1.SetCreateTime(3321); + acl1.SetLastModifyTime(3322); + + acl1.SetPrinciple("principle"); + acl1.SetPrivilege(privileges); + + try { + JSONObject aclDict = JSONObject.parseObject(acl1.ToJsonString()); + assertEquals(3321, aclDict.getIntValue("createTime")); + assertEquals(3322, aclDict.getIntValue("lastModifyTime")); + assertEquals("principle", aclDict.getString("principle")); + + JSONArray privilegesArray = aclDict.getJSONArray("privilege"); + assertEquals(2, privilegesArray.size()); + assertEquals("READ", privilegesArray.getString(0)); + assertEquals("WRITE", privilegesArray.getString(1)); + } catch (LogException e) { + assertTrue(e.GetErrorMessage(), false); + } + + try { + acl1.SetPrivilege(new ACLPrivileges()); + acl1.ToRequestJson(); + } catch (LogException e) { + assertEquals("BadResponse", e.GetErrorCode()); + assertEquals("ACL privilege must have at least one value", e.GetErrorMessage()); + }*/ } /** diff --git a/src/test/java/com/aliyun/openservices/log/functiontest/SlsScmFunctionTest.java b/src/test/java/com/aliyun/openservices/log/functiontest/SlsScmFunctionTest.java index 6269bff9..6e2348f5 100755 --- a/src/test/java/com/aliyun/openservices/log/functiontest/SlsScmFunctionTest.java +++ b/src/test/java/com/aliyun/openservices/log/functiontest/SlsScmFunctionTest.java @@ -36,600 +36,589 @@ import static org.junit.Assert.fail; public class SlsScmFunctionTest extends FunctionTest { - static private String project = "project-test-scm"; - static private String logStore = "test-java-sdk"; - static private String configName; - static private String syslogConfigName; - static private String apsaraConfigName; - static private String jsonConfigName; - static private String dilimeterConfigName; - static private String groupName; - static private String uuid1; - static private String uuid2; - @BeforeClass - public static void SetupOnce() { - int timestamp = getNowTimestamp(); - configName = "sdkftconfig" + timestamp; - syslogConfigName = "syslogConfig" + timestamp; - apsaraConfigName = "apsaraConfig" + timestamp; - jsonConfigName = "jsonConfig" + timestamp; - dilimeterConfigName = "dilimeterConfig" + timestamp; - - groupName = "sdkftgroup" + timestamp; - uuid1 = "uuid0" + timestamp; - uuid2 = "uuid1" + timestamp; - - LogStore logStoreRes = new LogStore(logStore, 1, 10); - reCreateLogStore(project, logStoreRes); - } + static private String project = "project-test-scm"; + static private String logStore = "test-java-sdk"; + static private String configName; + static private String syslogConfigName; + static private String apsaraConfigName; + static private String jsonConfigName; + static private String dilimeterConfigName; + static private String groupName; + static private String uuid1; + static private String uuid2; + @BeforeClass + public static void SetupOnce() { + int timestamp = getNowTimestamp(); + configName = "sdkftconfig" + timestamp; + syslogConfigName = "syslogConfig" + timestamp; + apsaraConfigName = "apsaraConfig" + timestamp; + jsonConfigName = "jsonConfig" + timestamp; + dilimeterConfigName = "dilimeterConfig" + timestamp; + + groupName = "sdkftgroup" + timestamp; + uuid1 = "uuid0" + timestamp; + uuid2 = "uuid1" + timestamp; + + LogStore logStoreRes = new LogStore(logStore, 1, 10); + reCreateLogStore(project, logStoreRes); + } @AfterClass - public static void CleanUpOnce() { - try { - client.DeleteConfig(project, configName); - } catch (LogException e) { - System.out.println(e.getMessage()); - } - - try { - client.DeleteMachineGroup(project, groupName); - } catch (LogException e) { - System.out.println(e.getMessage()); - } - } - - @Test - public void testSyslogConfigAPI() { - GetConfigResponse res = null; - String testConfigName = syslogConfigName; - try { - Config config = new Config(testConfigName); - config.SetInputType("syslog"); - StreamLogConfigInputDetail inputDetail = new StreamLogConfigInputDetail(); - inputDetail.SetLocalStorage(true); - ArrayList shardHashKey = new ArrayList(); - shardHashKey.add("__source__"); - inputDetail.SetShardHashKeyList(shardHashKey); - - config.SetInputDetail(inputDetail); - - ConfigOutputDetail outputDetail = new ConfigOutputDetail(); - - outputDetail.SetLogstoreName("perfcounter"); - config.SetOutputDetail(outputDetail); - - client.CreateConfig(project, config); - - res = client.GetConfig(project, testConfigName); - assertEquals("configName does not match", testConfigName, res.GetConfig().GetConfigName()); - - assertEquals("input type does not match", res.GetConfig().GetInputType(), "syslog"); - assertEquals("localStorage does not match", inputDetail.GetLocalStorage(), res.GetConfig().GetInputDetail().GetLocalStorage()); - assertEquals("logstoreName does not match", outputDetail.GetLogstoreName(), res.GetConfig().GetOutputDetail().GetLogstoreName()); - - } catch (LogException e) { + public static void CleanUpOnce() { + try { + client.DeleteConfig(project, configName); + } catch (LogException e) { + System.out.println(e.getMessage()); + } + + try { + client.DeleteMachineGroup(project, groupName); + } catch (LogException e) { + System.out.println(e.getMessage()); + } + } + + @Test + public void testSyslogConfigAPI() { + GetConfigResponse res = null; + String testConfigName = syslogConfigName; + try { + Config config = new Config(testConfigName); + config.SetInputType("syslog"); + StreamLogConfigInputDetail inputDetail = new StreamLogConfigInputDetail(); + inputDetail.SetLocalStorage(true); + ArrayList shardHashKey = new ArrayList(); + shardHashKey.add("__source__"); + inputDetail.SetShardHashKeyList(shardHashKey); + + config.SetInputDetail(inputDetail); + + ConfigOutputDetail outputDetail = new ConfigOutputDetail(); + + outputDetail.SetLogstoreName("perfcounter"); + config.SetOutputDetail(outputDetail); + + client.CreateConfig(project, config); + + res = client.GetConfig(project, testConfigName); + assertEquals("configName does not match", testConfigName, res.GetConfig().GetConfigName()); + + assertEquals("input type does not match", res.GetConfig().GetInputType(), "syslog"); + assertEquals("localStorage does not match", inputDetail.GetLocalStorage(), res.GetConfig().GetInputDetail().GetLocalStorage()); + assertEquals("logstoreName does not match", outputDetail.GetLogstoreName(), res.GetConfig().GetOutputDetail().GetLogstoreName()); + + } catch (LogException e) { fail(e.getMessage()); - } - } - - private void apsaraConfigAPI(String testConfigName) { - GetConfigResponse res = null; - try { - Config config = new Config(testConfigName); - ApsaraLogConfigInputDetail inputDetail = new ApsaraLogConfigInputDetail(); - inputDetail.SetLogType("apsara_log"); - inputDetail.SetLogPath("/apsara"); - inputDetail.SetFilePattern("apsara.log"); - inputDetail.SetLocalStorage(true); - inputDetail.SetTopicFormat("none"); - - ArrayList filterKey = new ArrayList(); - filterKey.add("number1"); - filterKey.add("seqno1"); - - ArrayList filterRegex = new ArrayList(); - filterRegex.add("number2"); - filterRegex.add("seqno2"); - inputDetail.SetFilterKeyRegex(filterKey, filterRegex); - - config.SetInputDetail(inputDetail); - - ConfigOutputDetail outputDetail = new ConfigOutputDetail(); - - outputDetail.SetLogstoreName("perfcounter"); - config.SetOutputDetail(outputDetail); - - client.CreateConfig(project, config); - - res = client.GetConfig(project, testConfigName); - assertEquals("configName does not match", testConfigName, res.GetConfig().GetConfigName()); - - assertEquals("logType does not match", inputDetail.GetLogType(), ((ApsaraLogConfigInputDetail)(res.GetConfig().GetInputDetail())).GetLogType()); - assertEquals("logPath does not match", inputDetail.GetLogPath(), ((ApsaraLogConfigInputDetail)res.GetConfig().GetInputDetail()).GetLogPath()); - assertEquals("filePattern does not match", inputDetail.GetFilePattern(), ((ApsaraLogConfigInputDetail)res.GetConfig().GetInputDetail()).GetFilePattern()); - assertEquals("localStorage does not match", inputDetail.GetLocalStorage(), res.GetConfig().GetInputDetail().GetLocalStorage()); - assertEquals("timeFormat does not match", inputDetail.GetTimeFormat(), ((ApsaraLogConfigInputDetail)res.GetConfig().GetInputDetail()).GetTimeFormat()); - assertEquals("topicFormat does not match", inputDetail.GetTopicFormat(), ((ApsaraLogConfigInputDetail)res.GetConfig().GetInputDetail()).GetTopicFormat()); - - List filterKeyRes = res.GetConfig().GetInputDetail().GetFilterKey(); - assertEquals("filterKey size does not match", filterKey.size(), filterKeyRes.size()); - for (int i = 0;i < filterKey.size();i++) { - assertEquals("filterKey " + i + " does not match", filterKey.get(0), filterKeyRes.get(0)); - } - - List filterRegexRes = res.GetConfig().GetInputDetail().GetFilterRegex(); - assertEquals("filterRegex size does not match", filterRegex.size(), filterRegexRes.size()); - for (int i = 0;i < filterRegex.size();i++) { - assertEquals("filterRegex " + i + " does not match", filterRegex.get(0), filterRegexRes.get(0)); - } - - assertEquals("logstoreName does not match", outputDetail.GetLogstoreName(), res.GetConfig().GetOutputDetail().GetLogstoreName()); - } catch (LogException e) { + } + } + + private void apsaraConfigAPI(String testConfigName) { + GetConfigResponse res = null; + try { + Config config = new Config(testConfigName); + ApsaraLogConfigInputDetail inputDetail = new ApsaraLogConfigInputDetail(); + inputDetail.SetLogType("apsara_log"); + inputDetail.SetLogPath("/apsara"); + inputDetail.SetFilePattern("apsara.log"); + inputDetail.SetLocalStorage(true); + inputDetail.SetTopicFormat("none"); + + ArrayList filterKey = new ArrayList(); + filterKey.add("number1"); + filterKey.add("seqno1"); + + ArrayList filterRegex = new ArrayList(); + filterRegex.add("number2"); + filterRegex.add("seqno2"); + inputDetail.SetFilterKeyRegex(filterKey, filterRegex); + + config.SetInputDetail(inputDetail); + + ConfigOutputDetail outputDetail = new ConfigOutputDetail(); + + outputDetail.SetLogstoreName("perfcounter"); + config.SetOutputDetail(outputDetail); + + client.CreateConfig(project, config); + + res = client.GetConfig(project, testConfigName); + assertEquals("configName does not match", testConfigName, res.GetConfig().GetConfigName()); + + assertEquals("logType does not match", inputDetail.GetLogType(), ((ApsaraLogConfigInputDetail)(res.GetConfig().GetInputDetail())).GetLogType()); + assertEquals("logPath does not match", inputDetail.GetLogPath(), ((ApsaraLogConfigInputDetail)res.GetConfig().GetInputDetail()).GetLogPath()); + assertEquals("filePattern does not match", inputDetail.GetFilePattern(), ((ApsaraLogConfigInputDetail)res.GetConfig().GetInputDetail()).GetFilePattern()); + assertEquals("localStorage does not match", inputDetail.GetLocalStorage(), res.GetConfig().GetInputDetail().GetLocalStorage()); + assertEquals("timeFormat does not match", inputDetail.GetTimeFormat(), ((ApsaraLogConfigInputDetail)res.GetConfig().GetInputDetail()).GetTimeFormat()); + assertEquals("topicFormat does not match", inputDetail.GetTopicFormat(), ((ApsaraLogConfigInputDetail)res.GetConfig().GetInputDetail()).GetTopicFormat()); + + List filterKeyRes = res.GetConfig().GetInputDetail().GetFilterKey(); + assertEquals("filterKey size does not match", filterKey.size(), filterKeyRes.size()); + for (int i = 0;i < filterKey.size();i++) { + assertEquals("filterKey " + i + " does not match", filterKey.get(0), filterKeyRes.get(0)); + } + + List filterRegexRes = res.GetConfig().GetInputDetail().GetFilterRegex(); + assertEquals("filterRegex size does not match", filterRegex.size(), filterRegexRes.size()); + for (int i = 0;i < filterRegex.size();i++) { + assertEquals("filterRegex " + i + " does not match", filterRegex.get(0), filterRegexRes.get(0)); + } + + assertEquals("logstoreName does not match", outputDetail.GetLogstoreName(), res.GetConfig().GetOutputDetail().GetLogstoreName()); + } catch (LogException e) { fail(e.getMessage()); - } - } - - @Test - public void testJsonConfigAPI() { - GetConfigResponse res; - final String testConfigName = jsonConfigName; - try { - Config config = new Config(testConfigName); - JsonConfigInputDetail inputDetail = new JsonConfigInputDetail(); - inputDetail.SetLogType("json_log"); - inputDetail.SetLogPath("/json"); - inputDetail.SetFilePattern("json.log"); - inputDetail.SetLocalStorage(true); - inputDetail.SetTopicFormat("none"); - inputDetail.SetTimeKey("time"); - inputDetail.SetTimeFormat("%H"); - - ArrayList filterKey = new ArrayList(); - filterKey.add("number1"); - filterKey.add("seqno1"); - - ArrayList filterRegex = new ArrayList(); - filterRegex.add("number2"); - filterRegex.add("seqno2"); - inputDetail.SetFilterKeyRegex(filterKey, filterRegex); - - config.SetInputDetail(inputDetail); - - ConfigOutputDetail outputDetail = new ConfigOutputDetail(); - - outputDetail.SetLogstoreName("perfcounter"); - config.SetOutputDetail(outputDetail); - - client.CreateConfig(project, config); - - res = client.GetConfig(project, testConfigName); - assertEquals("configName does not match", testConfigName, res.GetConfig().GetConfigName()); - - assertEquals("logType does not match", inputDetail.GetLogType(), ((JsonConfigInputDetail)(res.GetConfig().GetInputDetail())).GetLogType()); - assertEquals("logPath does not match", inputDetail.GetLogPath(), ((JsonConfigInputDetail)res.GetConfig().GetInputDetail()).GetLogPath()); - assertEquals("filePattern does not match", inputDetail.GetFilePattern(), ((JsonConfigInputDetail)res.GetConfig().GetInputDetail()).GetFilePattern()); - assertEquals("localStorage does not match", inputDetail.GetLocalStorage(), res.GetConfig().GetInputDetail().GetLocalStorage()); - assertEquals("timeFormat does not match", inputDetail.GetTimeFormat(), ((JsonConfigInputDetail)res.GetConfig().GetInputDetail()).GetTimeFormat()); - assertEquals("timeKey does not match", inputDetail.GetTimeKey(), ((JsonConfigInputDetail)res.GetConfig().GetInputDetail()).GetTimeKey()); - assertEquals("topicFormat does not match", inputDetail.GetTopicFormat(), ((JsonConfigInputDetail)res.GetConfig().GetInputDetail()).GetTopicFormat()); - - List filterKeyRes = res.GetConfig().GetInputDetail().GetFilterKey(); - assertEquals("filterKey size does not match", filterKey.size(), filterKeyRes.size()); - for (int i = 0;i < filterKey.size();i++) { - assertEquals("filterKey " + i + " does not match", filterKey.get(0), filterKeyRes.get(0)); - } - - List filterRegexRes = res.GetConfig().GetInputDetail().GetFilterRegex(); - assertEquals("filterRegex size does not match", filterRegex.size(), filterRegexRes.size()); - for (int i = 0;i < filterRegex.size();i++) { - assertEquals("filterRegex " + i + " does not match", filterRegex.get(0), filterRegexRes.get(0)); - } - - assertEquals("logstoreName does not match", outputDetail.GetLogstoreName(), res.GetConfig().GetOutputDetail().GetLogstoreName()); - - } catch (LogException e) { - e.printStackTrace(); + } + } + + @Test + public void testJsonConfigAPI() { + GetConfigResponse res; + final String testConfigName = jsonConfigName; + try { + Config config = new Config(testConfigName); + JsonConfigInputDetail inputDetail = new JsonConfigInputDetail(); + inputDetail.SetLogType("json_log"); + inputDetail.SetLogPath("/json"); + inputDetail.SetFilePattern("json.log"); + inputDetail.SetLocalStorage(true); + inputDetail.SetTopicFormat("none"); + inputDetail.SetTimeKey("time"); + inputDetail.SetTimeFormat("%H"); + + ArrayList filterKey = new ArrayList(); + filterKey.add("number1"); + filterKey.add("seqno1"); + + ArrayList filterRegex = new ArrayList(); + filterRegex.add("number2"); + filterRegex.add("seqno2"); + inputDetail.SetFilterKeyRegex(filterKey, filterRegex); + + config.SetInputDetail(inputDetail); + + ConfigOutputDetail outputDetail = new ConfigOutputDetail(); + + outputDetail.SetLogstoreName("perfcounter"); + config.SetOutputDetail(outputDetail); + + client.CreateConfig(project, config); + + res = client.GetConfig(project, testConfigName); + assertEquals("configName does not match", testConfigName, res.GetConfig().GetConfigName()); + + assertEquals("logType does not match", inputDetail.GetLogType(), ((JsonConfigInputDetail)(res.GetConfig().GetInputDetail())).GetLogType()); + assertEquals("logPath does not match", inputDetail.GetLogPath(), ((JsonConfigInputDetail)res.GetConfig().GetInputDetail()).GetLogPath()); + assertEquals("filePattern does not match", inputDetail.GetFilePattern(), ((JsonConfigInputDetail)res.GetConfig().GetInputDetail()).GetFilePattern()); + assertEquals("localStorage does not match", inputDetail.GetLocalStorage(), res.GetConfig().GetInputDetail().GetLocalStorage()); + assertEquals("timeFormat does not match", inputDetail.GetTimeFormat(), ((JsonConfigInputDetail)res.GetConfig().GetInputDetail()).GetTimeFormat()); + assertEquals("timeKey does not match", inputDetail.GetTimeKey(), ((JsonConfigInputDetail)res.GetConfig().GetInputDetail()).GetTimeKey()); + assertEquals("topicFormat does not match", inputDetail.GetTopicFormat(), ((JsonConfigInputDetail)res.GetConfig().GetInputDetail()).GetTopicFormat()); + + List filterKeyRes = res.GetConfig().GetInputDetail().GetFilterKey(); + assertEquals("filterKey size does not match", filterKey.size(), filterKeyRes.size()); + for (int i = 0;i < filterKey.size();i++) { + assertEquals("filterKey " + i + " does not match", filterKey.get(0), filterKeyRes.get(0)); + } + + List filterRegexRes = res.GetConfig().GetInputDetail().GetFilterRegex(); + assertEquals("filterRegex size does not match", filterRegex.size(), filterRegexRes.size()); + for (int i = 0;i < filterRegex.size();i++) { + assertEquals("filterRegex " + i + " does not match", filterRegex.get(0), filterRegexRes.get(0)); + } + + assertEquals("logstoreName does not match", outputDetail.GetLogstoreName(), res.GetConfig().GetOutputDetail().GetLogstoreName()); + + } catch (LogException e) { + e.printStackTrace(); fail(e.getMessage()); - } - } - - @Test - public void testDelimiterConfigAPI() { - GetConfigResponse res; - final String testConfigName = dilimeterConfigName; - try { - Config config = new Config(testConfigName); - DelimiterConfigInputDetail inputDetail = new DelimiterConfigInputDetail(); - inputDetail.SetLogPath("/dilimeterPath"); - inputDetail.SetFilePattern("dilimeter.log"); - inputDetail.SetLocalStorage(true); - inputDetail.SetTopicFormat("none"); - inputDetail.SetSeparator("\t"); - inputDetail.SetQuote(" "); - ArrayList key = new ArrayList(); - key.add("number"); - key.add("seqno"); - inputDetail.SetKey(key); - inputDetail.SetTimeKey(""); - inputDetail.SetTimeFormat("%H%m%S"); - - ArrayList filterKey = new ArrayList(); - filterKey.add("number1"); - filterKey.add("seqno1"); - - ArrayList filterRegex = new ArrayList(); - filterRegex.add("number2"); - filterRegex.add("seqno2"); - inputDetail.SetFilterKeyRegex(filterKey, filterRegex); - - config.SetInputDetail(inputDetail); - - ConfigOutputDetail outputDetail = new ConfigOutputDetail(); - - outputDetail.SetLogstoreName("perfcounter"); - config.SetOutputDetail(outputDetail); - - client.CreateConfig(project, config); - - res = client.GetConfig(project, testConfigName); - assertEquals("configName does not match", testConfigName, res.GetConfig().GetConfigName()); - - assertEquals("logType does not match", inputDetail.GetLogType(), ((DelimiterConfigInputDetail)(res.GetConfig().GetInputDetail())).GetLogType()); - assertEquals("logPath does not match", inputDetail.GetLogPath(), ((DelimiterConfigInputDetail)res.GetConfig().GetInputDetail()).GetLogPath()); - assertEquals("filePattern does not match", inputDetail.GetFilePattern(), ((DelimiterConfigInputDetail)res.GetConfig().GetInputDetail()).GetFilePattern()); - assertEquals("localStorage does not match", inputDetail.GetLocalStorage(), res.GetConfig().GetInputDetail().GetLocalStorage()); - assertEquals("timeFormat does not match", inputDetail.GetTimeFormat(), ((DelimiterConfigInputDetail)res.GetConfig().GetInputDetail()).GetTimeFormat()); - assertEquals("timeKey does not match", inputDetail.GetTimeKey(), ((DelimiterConfigInputDetail)res.GetConfig().GetInputDetail()).GetTimeKey()); - assertEquals("topicFormat does not match", inputDetail.GetTopicFormat(), ((DelimiterConfigInputDetail)res.GetConfig().GetInputDetail()).GetTopicFormat()); - assertEquals("seperator does not match", inputDetail.GetSeparator(), ((DelimiterConfigInputDetail)res.GetConfig().GetInputDetail()).GetSeparator()); - assertEquals("quote does not match", inputDetail.GetQuote(), ((DelimiterConfigInputDetail)res.GetConfig().GetInputDetail()).GetQuote()); - - List filterKeyRes = res.GetConfig().GetInputDetail().GetFilterKey(); - assertEquals("filterKey size does not match", filterKey.size(), filterKeyRes.size()); - for (int i = 0;i < filterKey.size();i++) { - assertEquals("filterKey " + i + " does not match", filterKey.get(0), filterKeyRes.get(0)); - } - - List filterRegexRes = res.GetConfig().GetInputDetail().GetFilterRegex(); - assertEquals("filterRegex size does not match", filterRegex.size(), filterRegexRes.size()); - for (int i = 0;i < filterRegex.size();i++) { - assertEquals("filterRegex " + i + " does not match", filterRegex.get(0), filterRegexRes.get(0)); - } - - assertEquals("logstoreName does not match", outputDetail.GetLogstoreName(), res.GetConfig().GetOutputDetail().GetLogstoreName()); - - } catch (LogException e) { + } + } + + @Test + public void testDelimiterConfigAPI() { + GetConfigResponse res; + final String testConfigName = dilimeterConfigName; + try { + Config config = new Config(testConfigName); + DelimiterConfigInputDetail inputDetail = new DelimiterConfigInputDetail(); + inputDetail.SetLogPath("/dilimeterPath"); + inputDetail.SetFilePattern("dilimeter.log"); + inputDetail.SetLocalStorage(true); + inputDetail.SetTopicFormat("none"); + inputDetail.SetSeparator("\t"); + inputDetail.SetQuote(" "); + ArrayList key = new ArrayList(); + key.add("number"); + key.add("seqno"); + inputDetail.SetKey(key); + inputDetail.SetTimeKey(""); + inputDetail.SetTimeFormat("%H%m%S"); + + ArrayList filterKey = new ArrayList(); + filterKey.add("number1"); + filterKey.add("seqno1"); + + ArrayList filterRegex = new ArrayList(); + filterRegex.add("number2"); + filterRegex.add("seqno2"); + inputDetail.SetFilterKeyRegex(filterKey, filterRegex); + + config.SetInputDetail(inputDetail); + + ConfigOutputDetail outputDetail = new ConfigOutputDetail(); + + outputDetail.SetLogstoreName("perfcounter"); + config.SetOutputDetail(outputDetail); + + client.CreateConfig(project, config); + + res = client.GetConfig(project, testConfigName); + assertEquals("configName does not match", testConfigName, res.GetConfig().GetConfigName()); + + assertEquals("logType does not match", inputDetail.GetLogType(), ((DelimiterConfigInputDetail)(res.GetConfig().GetInputDetail())).GetLogType()); + assertEquals("logPath does not match", inputDetail.GetLogPath(), ((DelimiterConfigInputDetail)res.GetConfig().GetInputDetail()).GetLogPath()); + assertEquals("filePattern does not match", inputDetail.GetFilePattern(), ((DelimiterConfigInputDetail)res.GetConfig().GetInputDetail()).GetFilePattern()); + assertEquals("localStorage does not match", inputDetail.GetLocalStorage(), res.GetConfig().GetInputDetail().GetLocalStorage()); + assertEquals("timeFormat does not match", inputDetail.GetTimeFormat(), ((DelimiterConfigInputDetail)res.GetConfig().GetInputDetail()).GetTimeFormat()); + assertEquals("timeKey does not match", inputDetail.GetTimeKey(), ((DelimiterConfigInputDetail)res.GetConfig().GetInputDetail()).GetTimeKey()); + assertEquals("topicFormat does not match", inputDetail.GetTopicFormat(), ((DelimiterConfigInputDetail)res.GetConfig().GetInputDetail()).GetTopicFormat()); + assertEquals("seperator does not match", inputDetail.GetSeparator(), ((DelimiterConfigInputDetail)res.GetConfig().GetInputDetail()).GetSeparator()); + assertEquals("quote does not match", inputDetail.GetQuote(), ((DelimiterConfigInputDetail)res.GetConfig().GetInputDetail()).GetQuote()); + + List filterKeyRes = res.GetConfig().GetInputDetail().GetFilterKey(); + assertEquals("filterKey size does not match", filterKey.size(), filterKeyRes.size()); + for (int i = 0;i < filterKey.size();i++) { + assertEquals("filterKey " + i + " does not match", filterKey.get(0), filterKeyRes.get(0)); + } + + List filterRegexRes = res.GetConfig().GetInputDetail().GetFilterRegex(); + assertEquals("filterRegex size does not match", filterRegex.size(), filterRegexRes.size()); + for (int i = 0;i < filterRegex.size();i++) { + assertEquals("filterRegex " + i + " does not match", filterRegex.get(0), filterRegexRes.get(0)); + } + + assertEquals("logstoreName does not match", outputDetail.GetLogstoreName(), res.GetConfig().GetOutputDetail().GetLogstoreName()); + + } catch (LogException e) { fail(e.getMessage()); - } - } - - private void configAPI(String testConfigName) { - - GetConfigResponse res = null; - try { - Config config = new Config(testConfigName); - { - ConfigInputDetail inputDetail = new ConfigInputDetail(); - inputDetail.SetLogType("common_reg_log"); - inputDetail.SetLogPath("/var/log/httpd/"); - inputDetail.SetFilePattern("access.log"); - inputDetail.SetLocalStorage(true); - inputDetail.SetTimeFormat("%H%m%S"); - inputDetail.SetLogBeginRegex("\\d+"); - inputDetail.SetRegex("(\\d+) (\\d+)"); - inputDetail.SetTopicFormat("none"); - inputDetail.SetMaxDepth(100); - - ArrayList key = new ArrayList(); - key.add("number"); - key.add("seqno"); - inputDetail.SetKey(key); - - ArrayList filterKey = new ArrayList(); - filterKey.add("number1"); - filterKey.add("seqno1"); - - ArrayList filterRegex = new ArrayList(); - filterRegex.add("number2"); - filterRegex.add("seqno2"); - inputDetail.SetFilterKeyRegex(filterKey, filterRegex); - - config.SetInputDetail(inputDetail); - - ConfigOutputDetail outputDetail = new ConfigOutputDetail(); - - outputDetail.SetLogstoreName("perfcounter"); - config.SetOutputDetail(outputDetail); - - client.CreateConfig(project, config); - - res = client.GetConfig(project, testConfigName); - assertEquals("configName does not match", testConfigName, res.GetConfig().GetConfigName()); - - assertEquals("logType does not match", inputDetail.GetLogType(), ((ConfigInputDetail)res.GetConfig().GetInputDetail()).GetLogType()); - assertEquals("logPath does not match", inputDetail.GetLogPath(), ((ConfigInputDetail)res.GetConfig().GetInputDetail()).GetLogPath()); - assertEquals("filePattern does not match", inputDetail.GetFilePattern(), ((ConfigInputDetail)res.GetConfig().GetInputDetail()).GetFilePattern()); - assertEquals("localStorage does not match", inputDetail.GetLocalStorage(), res.GetConfig().GetInputDetail().GetLocalStorage()); - assertEquals("timeFormat does not match", inputDetail.GetTimeFormat(), ((ConfigInputDetail)res.GetConfig().GetInputDetail()).GetTimeFormat()); - assertEquals("logBeginRegex does not match", inputDetail.GetLogBeginRegex(), ((ConfigInputDetail)res.GetConfig().GetInputDetail()).GetLogBeginRegex()); - assertEquals("regex does not match", inputDetail.GetRegex(), ((ConfigInputDetail)res.GetConfig().GetInputDetail()).GetRegex()); - assertEquals("topicFormat does not match", inputDetail.GetTopicFormat(), ((ConfigInputDetail)res.GetConfig().GetInputDetail()).GetTopicFormat()); - assertEquals("maxDepth dose not match", inputDetail.GetMaxDepth(), ((ConfigInputDetail)res.GetConfig().GetInputDetail()).GetMaxDepth()); - - List keyRes = ((ConfigInputDetail)res.GetConfig().GetInputDetail()).GetKey(); - assertEquals("key size does not match", key.size(), keyRes.size()); - for (int i = 0;i < key.size();i++) { - assertEquals("key " + i + " does not match", key.get(0), keyRes.get(0)); - } - - List filterKeyRes = res.GetConfig().GetInputDetail().GetFilterKey(); - assertEquals("filterKey size does not match", filterKey.size(), filterKeyRes.size()); - for (int i = 0;i < filterKey.size();i++) { - assertEquals("filterKey " + i + " does not match", filterKey.get(0), filterKeyRes.get(0)); - } - - List filterRegexRes = res.GetConfig().GetInputDetail().GetFilterRegex(); - assertEquals("filterRegex size does not match", filterRegex.size(), filterRegexRes.size()); - for (int i = 0;i < filterRegex.size();i++) { - assertEquals("filterRegex " + i + " does not match", filterRegex.get(0), filterRegexRes.get(0)); - } - - assertEquals("logstoreName does not match", outputDetail.GetLogstoreName(), res.GetConfig().GetOutputDetail().GetLogstoreName()); - } - - { - JSONObject inputDetailJson = new JSONObject(); - inputDetailJson.put("logType", "common_reg_log"); - inputDetailJson.put("logPath", "/var/log/httpd1/"); - inputDetailJson.put("filePattern", "access1.log"); - inputDetailJson.put("localStorage", false); - inputDetailJson.put("timeFormat", "%h"); - inputDetailJson.put("logBeginRegex", "\\w+"); - inputDetailJson.put("regex", "(\\w+) (\\w+)"); - inputDetailJson.put("topicFormat", "group_topic"); - - JSONArray keyJsonArray = new JSONArray(); - keyJsonArray.add("xname"); - keyJsonArray.add("xseqno"); - inputDetailJson.put("key", keyJsonArray); - - JSONArray filterKeyJsonArray = new JSONArray(); - filterKeyJsonArray.add("xnumber1"); - filterKeyJsonArray.add("xseqno1"); - inputDetailJson.put("filterKey", filterKeyJsonArray); - - JSONArray filterRegexJsonArray = new JSONArray(); - filterRegexJsonArray.add("xnumber2"); - filterRegexJsonArray.add("xseqno2"); - inputDetailJson.put("filterRegex", filterRegexJsonArray); - - config.SetInputDetail(inputDetailJson.toString()); - - JSONObject outputDetailJson = new JSONObject(); - outputDetailJson.put("projectName", "ay421"); - outputDetailJson.put("logstoreName", "perfcounter1"); - config.SetOutputDetail(outputDetailJson.toString()); - - client.UpdateConfig(project, config); - - res = client.GetConfig(project, testConfigName); - assertEquals("configName does not match", testConfigName, res.GetConfig().GetConfigName()); - - JSONObject inputDetailJsonRes = JSONObject.parseObject(((ConfigInputDetail)res.GetConfig().GetInputDetail()).ToJsonString()); - - assertEquals("logType does not match", inputDetailJson.getString("logType"), inputDetailJsonRes.getString("logType")); - assertEquals("logPath does not match", inputDetailJson.getString("logPath"), inputDetailJsonRes.getString("logPath")); - assertEquals("filePattern does not match", inputDetailJson.getString("filePattern"), inputDetailJsonRes.getString("filePattern")); - assertEquals("localStorage does not match", inputDetailJson.getBoolean("localStorage"), inputDetailJsonRes.getBoolean("localStorage")); - assertEquals("timeFormat does not match", inputDetailJson.getString("timeFormat"), inputDetailJsonRes.getString("timeFormat")); - assertEquals("logBeginRegex does not match", inputDetailJson.getString("logBeginRegex"), inputDetailJsonRes.getString("logBeginRegex")); - assertEquals("regex does not match", inputDetailJson.getString("regex"), inputDetailJsonRes.getString("regex")); - assertEquals("topicFormat does not match", inputDetailJson.getString("topicFormat"), inputDetailJsonRes.getString("topicFormat")); - - JSONArray keyJsonArrayRes = inputDetailJsonRes.getJSONArray("key"); - assertEquals("key size does not match", keyJsonArray.size(), keyJsonArrayRes.size()); - for (int i = 0;i < keyJsonArray.size();i++) { - assertEquals("key " + i + " does not match", keyJsonArray.getString(0), keyJsonArrayRes.getString(0)); - } - - JSONArray filterKeyJsonArrayRes = inputDetailJsonRes.getJSONArray("filterKey"); - assertEquals("filterKey size does not match", filterKeyJsonArray.size(), filterKeyJsonArrayRes.size()); - for (int i = 0;i < filterKeyJsonArray.size();i++) { - assertEquals("filterKey " + i + " does not match", filterKeyJsonArray.getString(0), filterKeyJsonArrayRes.getString(0)); - } - - JSONArray filterRegexJsonArrayRes = inputDetailJsonRes.getJSONArray("filterRegex"); - assertEquals("filterRegex size does not match", filterRegexJsonArray.size(), filterRegexJsonArrayRes.size()); - for (int i = 0;i < filterRegexJsonArray.size();i++) { - assertEquals("filterRegex " + i + " does not match", filterRegexJsonArray.getString(0), filterRegexJsonArrayRes.getString(0)); - } - - JSONObject outputDetailJsonRes = JSONObject.parseObject(res.GetConfig().GetOutputDetail().ToJsonString()); - //System.out.println(outputDetailJsonRes.toString()); - //assertEquals("projectName does not match"+outputDetailJson.getString("projectName"), outputDetailJson.getString("projectName"), outputDetailJsonRes.getString("projectName")); - assertEquals("logstoreName does not match", outputDetailJson.getString("logstoreName"), outputDetailJsonRes.getString("logstoreName")); - - } - - { - ListConfigResponse listRes = client.ListConfig(project, testConfigName, 0, 500); - assertEquals("configNum does not match", 1, listRes.GetConfigs().size()); - assertEquals("configName does not match", testConfigName, listRes.GetConfigs().get(0)); - } - } catch (LogException e) { + } + } + + private void configAPI(String testConfigName) { + + GetConfigResponse res = null; + try { + Config config = new Config(testConfigName); + { + ConfigInputDetail inputDetail = new ConfigInputDetail(); + inputDetail.SetLogType("common_reg_log"); + inputDetail.SetLogPath("/var/log/httpd/"); + inputDetail.SetFilePattern("access.log"); + inputDetail.SetLocalStorage(true); + inputDetail.SetTimeFormat("%H%m%S"); + inputDetail.SetLogBeginRegex("\\d+"); + inputDetail.SetRegex("(\\d+) (\\d+)"); + inputDetail.SetTopicFormat("none"); + inputDetail.SetMaxDepth(100); + + ArrayList key = new ArrayList(); + key.add("number"); + key.add("seqno"); + inputDetail.SetKey(key); + + ArrayList filterKey = new ArrayList(); + filterKey.add("number1"); + filterKey.add("seqno1"); + + ArrayList filterRegex = new ArrayList(); + filterRegex.add("number2"); + filterRegex.add("seqno2"); + inputDetail.SetFilterKeyRegex(filterKey, filterRegex); + + config.SetInputDetail(inputDetail); + + ConfigOutputDetail outputDetail = new ConfigOutputDetail(); + + outputDetail.SetLogstoreName("perfcounter"); + config.SetOutputDetail(outputDetail); + + client.CreateConfig(project, config); + + res = client.GetConfig(project, testConfigName); + assertEquals("configName does not match", testConfigName, res.GetConfig().GetConfigName()); + + assertEquals("logType does not match", inputDetail.GetLogType(), ((ConfigInputDetail)res.GetConfig().GetInputDetail()).GetLogType()); + assertEquals("logPath does not match", inputDetail.GetLogPath(), ((ConfigInputDetail)res.GetConfig().GetInputDetail()).GetLogPath()); + assertEquals("filePattern does not match", inputDetail.GetFilePattern(), ((ConfigInputDetail)res.GetConfig().GetInputDetail()).GetFilePattern()); + assertEquals("localStorage does not match", inputDetail.GetLocalStorage(), res.GetConfig().GetInputDetail().GetLocalStorage()); + assertEquals("timeFormat does not match", inputDetail.GetTimeFormat(), ((ConfigInputDetail)res.GetConfig().GetInputDetail()).GetTimeFormat()); + assertEquals("logBeginRegex does not match", inputDetail.GetLogBeginRegex(), ((ConfigInputDetail)res.GetConfig().GetInputDetail()).GetLogBeginRegex()); + assertEquals("regex does not match", inputDetail.GetRegex(), ((ConfigInputDetail)res.GetConfig().GetInputDetail()).GetRegex()); + assertEquals("topicFormat does not match", inputDetail.GetTopicFormat(), ((ConfigInputDetail)res.GetConfig().GetInputDetail()).GetTopicFormat()); + assertEquals("maxDepth dose not match", inputDetail.GetMaxDepth(), ((ConfigInputDetail)res.GetConfig().GetInputDetail()).GetMaxDepth()); + + List keyRes = ((ConfigInputDetail)res.GetConfig().GetInputDetail()).GetKey(); + assertEquals("key size does not match", key.size(), keyRes.size()); + for (int i = 0;i < key.size();i++) { + assertEquals("key " + i + " does not match", key.get(0), keyRes.get(0)); + } + + List filterKeyRes = res.GetConfig().GetInputDetail().GetFilterKey(); + assertEquals("filterKey size does not match", filterKey.size(), filterKeyRes.size()); + for (int i = 0;i < filterKey.size();i++) { + assertEquals("filterKey " + i + " does not match", filterKey.get(0), filterKeyRes.get(0)); + } + + List filterRegexRes = res.GetConfig().GetInputDetail().GetFilterRegex(); + assertEquals("filterRegex size does not match", filterRegex.size(), filterRegexRes.size()); + for (int i = 0;i < filterRegex.size();i++) { + assertEquals("filterRegex " + i + " does not match", filterRegex.get(0), filterRegexRes.get(0)); + } + + assertEquals("logstoreName does not match", outputDetail.GetLogstoreName(), res.GetConfig().GetOutputDetail().GetLogstoreName()); + } + + { + JSONObject inputDetailJson = new JSONObject(); + inputDetailJson.put("logType", "common_reg_log"); + inputDetailJson.put("logPath", "/var/log/httpd1/"); + inputDetailJson.put("filePattern", "access1.log"); + inputDetailJson.put("localStorage", false); + inputDetailJson.put("timeFormat", "%h"); + inputDetailJson.put("logBeginRegex", "\\w+"); + inputDetailJson.put("regex", "(\\w+) (\\w+)"); + inputDetailJson.put("topicFormat", "group_topic"); + + JSONArray keyJsonArray = new JSONArray(); + keyJsonArray.add("xname"); + keyJsonArray.add("xseqno"); + inputDetailJson.put("key", keyJsonArray); + + JSONArray filterKeyJsonArray = new JSONArray(); + filterKeyJsonArray.add("xnumber1"); + filterKeyJsonArray.add("xseqno1"); + inputDetailJson.put("filterKey", filterKeyJsonArray); + + JSONArray filterRegexJsonArray = new JSONArray(); + filterRegexJsonArray.add("xnumber2"); + filterRegexJsonArray.add("xseqno2"); + inputDetailJson.put("filterRegex", filterRegexJsonArray); + + config.SetInputDetail(inputDetailJson.toString()); + + JSONObject outputDetailJson = new JSONObject(); + outputDetailJson.put("projectName", "ay421"); + outputDetailJson.put("logstoreName", "perfcounter1"); + config.SetOutputDetail(outputDetailJson.toString()); + + client.UpdateConfig(project, config); + + res = client.GetConfig(project, testConfigName); + assertEquals("configName does not match", testConfigName, res.GetConfig().GetConfigName()); + + JSONObject inputDetailJsonRes = JSONObject.parseObject(((ConfigInputDetail)res.GetConfig().GetInputDetail()).ToJsonString()); + + assertEquals("logType does not match", inputDetailJson.getString("logType"), inputDetailJsonRes.getString("logType")); + assertEquals("logPath does not match", inputDetailJson.getString("logPath"), inputDetailJsonRes.getString("logPath")); + assertEquals("filePattern does not match", inputDetailJson.getString("filePattern"), inputDetailJsonRes.getString("filePattern")); + assertEquals("localStorage does not match", inputDetailJson.getBoolean("localStorage"), inputDetailJsonRes.getBoolean("localStorage")); + assertEquals("timeFormat does not match", inputDetailJson.getString("timeFormat"), inputDetailJsonRes.getString("timeFormat")); + assertEquals("logBeginRegex does not match", inputDetailJson.getString("logBeginRegex"), inputDetailJsonRes.getString("logBeginRegex")); + assertEquals("regex does not match", inputDetailJson.getString("regex"), inputDetailJsonRes.getString("regex")); + assertEquals("topicFormat does not match", inputDetailJson.getString("topicFormat"), inputDetailJsonRes.getString("topicFormat")); + + JSONArray keyJsonArrayRes = inputDetailJsonRes.getJSONArray("key"); + assertEquals("key size does not match", keyJsonArray.size(), keyJsonArrayRes.size()); + for (int i = 0;i < keyJsonArray.size();i++) { + assertEquals("key " + i + " does not match", keyJsonArray.getString(0), keyJsonArrayRes.getString(0)); + } + + JSONArray filterKeyJsonArrayRes = inputDetailJsonRes.getJSONArray("filterKey"); + assertEquals("filterKey size does not match", filterKeyJsonArray.size(), filterKeyJsonArrayRes.size()); + for (int i = 0;i < filterKeyJsonArray.size();i++) { + assertEquals("filterKey " + i + " does not match", filterKeyJsonArray.getString(0), filterKeyJsonArrayRes.getString(0)); + } + + JSONArray filterRegexJsonArrayRes = inputDetailJsonRes.getJSONArray("filterRegex"); + assertEquals("filterRegex size does not match", filterRegexJsonArray.size(), filterRegexJsonArrayRes.size()); + for (int i = 0;i < filterRegexJsonArray.size();i++) { + assertEquals("filterRegex " + i + " does not match", filterRegexJsonArray.getString(0), filterRegexJsonArrayRes.getString(0)); + } + + JSONObject outputDetailJsonRes = JSONObject.parseObject(res.GetConfig().GetOutputDetail().ToJsonString()); + //System.out.println(outputDetailJsonRes.toString()); + //assertEquals("projectName does not match"+outputDetailJson.getString("projectName"), outputDetailJson.getString("projectName"), outputDetailJsonRes.getString("projectName")); + assertEquals("logstoreName does not match", outputDetailJson.getString("logstoreName"), outputDetailJsonRes.getString("logstoreName")); + + } + + { + ListConfigResponse listRes = client.ListConfig(project, testConfigName, 0, 500); + assertEquals("configNum does not match", 1, listRes.GetConfigs().size()); + assertEquals("configName does not match", testConfigName, listRes.GetConfigs().get(0)); + } + } catch (LogException e) { fail(e.getMessage()); - } - } - - private void machineGroupAPI(String testGroupName, String testConfigName) { - try { - String groupType = "Armory"; - String externalName = "testgroup"; - String groupTopic = "groupTopic1"; - String machineIdentifyType = "userdefined"; - - ArrayList machineList = new ArrayList(); - machineList.add(uuid1); - machineList.add(uuid2); - - GroupAttribute groupAttribute = new GroupAttribute(externalName, groupTopic); - - MachineGroup group = new MachineGroup(testGroupName, "userdefined", machineList); - group.SetMachineIdentifyType(machineIdentifyType); - group.SetGroupType(groupType); - group.SetGroupAttribute(groupAttribute); - - GetMachineGroupResponse res = null; - - client.CreateMachineGroup(project, group); - - res = client.GetMachineGroup(project, testGroupName); - assertEquals("group name does not match", testGroupName, res.GetMachineGroup().GetGroupName()); - assertEquals("group type does not match", groupType, res.GetMachineGroup().GetGroupType()); - assertEquals("external name does not match", externalName, res.GetMachineGroup().GetGroupAttribute().GetExternalName()); - assertEquals("group topic does not match", groupTopic, res.GetMachineGroup().GetGroupAttribute().GetGroupTopic()); - - ArrayList mlRes = res.GetMachineGroup().GetMachineList(); - assertEquals("machineList size does not match", machineList.size(), mlRes.size()); - for (int i = 0;i < machineList.size();i++) { - assertTrue("machine " + i + " does not match", mlRes.contains(machineList.get(i))); - } - - groupType = ""; - externalName = "testgroup2"; - groupTopic = "groupTopic2"; - machineIdentifyType = "userdefined"; - - machineList = new ArrayList(); - machineList.add(uuid1); - - group = new MachineGroup(testGroupName, "userdefined", machineList); - group.SetMachineIdentifyType(machineIdentifyType); - group.SetGroupType(groupType); - group.SetExternalName(externalName); - group.SetGroupTopic(groupTopic); - - client.UpdateMachineGroup(project, group); - - res = client.GetMachineGroup(project, testGroupName); - assertEquals("group name does not match", testGroupName, res.GetMachineGroup().GetGroupName()); - assertEquals("group type does not match", groupType, res.GetMachineGroup().GetGroupType()); - assertEquals("external name does not match", externalName, res.GetMachineGroup().GetGroupAttribute().GetExternalName()); - assertEquals("group topic does not match", groupTopic, res.GetMachineGroup().GetGroupAttribute().GetGroupTopic()); - - ArrayList mlResUpdate = res.GetMachineGroup().GetMachineList(); - assertEquals("machineList size does not match", machineList.size(), mlResUpdate.size()); - for (int i = 0;i < machineList.size();i++) { - assertTrue("machine " + i + " does not match", mlResUpdate.contains(machineList.get(i))); - } - - ListMachineGroupResponse listRes = client.ListMachineGroup(project, testGroupName, 0, 500); - assertEquals("machine group num does not match", 1, listRes.GetMachineGroups().size()); - assertEquals("group name does not match", testGroupName, listRes.GetMachineGroups().get(0)); - - client.ApplyConfigToMachineGroup(project, testGroupName, testConfigName); - client.RemoveConfigFromMachineGroup(project, testGroupName, testConfigName); - } catch (LogException e) { + } + } + + private void machineGroupAPI(String testGroupName, String testConfigName) { + try { + String groupTopic = "groupTopic1"; + String machineIdentifyType = "userdefined"; + + ArrayList machineList = new ArrayList(); + machineList.add(uuid1); + machineList.add(uuid2); + + GroupAttribute groupAttribute = new GroupAttribute("", groupTopic); + + MachineGroup group = new MachineGroup(testGroupName, "userdefined", machineList); + group.SetMachineIdentifyType(machineIdentifyType); + group.SetGroupAttribute(groupAttribute); + + GetMachineGroupResponse res = null; + + client.CreateMachineGroup(project, group); + + res = client.GetMachineGroup(project, testGroupName); + assertEquals("group name does not match", testGroupName, res.GetMachineGroup().GetGroupName()); + assertEquals("group topic does not match", groupTopic, res.GetMachineGroup().GetGroupAttribute().GetGroupTopic()); + + ArrayList mlRes = res.GetMachineGroup().GetMachineList(); + assertEquals("machineList size does not match", machineList.size(), mlRes.size()); + for (int i = 0;i < machineList.size();i++) { + assertTrue("machine " + i + " does not match", mlRes.contains(machineList.get(i))); + } + + groupTopic = "groupTopic2"; + machineIdentifyType = "userdefined"; + + machineList = new ArrayList(); + machineList.add(uuid1); + + group = new MachineGroup(testGroupName, "userdefined", machineList); + group.SetMachineIdentifyType(machineIdentifyType); + group.SetGroupTopic(groupTopic); + + client.UpdateMachineGroup(project, group); + + res = client.GetMachineGroup(project, testGroupName); + assertEquals("group name does not match", testGroupName, res.GetMachineGroup().GetGroupName()); + assertEquals("group topic does not match", groupTopic, res.GetMachineGroup().GetGroupAttribute().GetGroupTopic()); + + ArrayList mlResUpdate = res.GetMachineGroup().GetMachineList(); + assertEquals("machineList size does not match", machineList.size(), mlResUpdate.size()); + for (int i = 0;i < machineList.size();i++) { + assertTrue("machine " + i + " does not match", mlResUpdate.contains(machineList.get(i))); + } + + ListMachineGroupResponse listRes = client.ListMachineGroup(project, testGroupName, 0, 500); + assertEquals("machine group num does not match", 1, listRes.GetMachineGroups().size()); + assertEquals("group name does not match", testGroupName, listRes.GetMachineGroups().get(0)); + + client.ApplyConfigToMachineGroup(project, testGroupName, testConfigName); + client.RemoveConfigFromMachineGroup(project, testGroupName, testConfigName); + } catch (LogException e) { fail(e.getMessage()); - } - } - - private void aclAPI() { - try { - String principle = "ANONYMOUS"; - - List privilegeList = new ArrayList(); - privilegeList.add(ACLPrivilege.READ); - ACLPrivileges privileges = new ACLPrivileges(privilegeList); - - ACL acl = new ACL(principle, privileges, ACLAction.GRANT); - - client.UpdateACL(project, acl); - - ListACLResponse listRes = client.ListACL(project); - assertEquals("acl num does not match", 2, listRes.GetACLs().size()); - boolean checked = false; - for (ACL aclRes:listRes.GetACLs()) { - if (aclRes.GetPrinciple().equals(principle)) { - checked = true; - assertEquals(principle, aclRes.GetPrinciple()); - assertTrue(aclRes.GetPrivilege().GetPrivileges().contains(ACLPrivilege.READ)); - } - } - assertTrue("expected ACL does not exist", checked); - - List privilegeList2 = new ArrayList(); - privilegeList2.add(ACLPrivilege.READ); - privilegeList2.add(ACLPrivilege.WRITE); - ACLPrivileges privileges2 = new ACLPrivileges(privilegeList2); - - ACL acl2 = new ACL(principle, privileges2, ACLAction.GRANT); - - client.UpdateACL(project, logStore, acl2); - - ListACLResponse listRes2 = client.ListACL(project, logStore); - assertEquals("acl num does not match", 1, listRes2.GetACLs().size()); - System.out.println(listRes2.GetCount()); - - assertEquals(principle, listRes2.GetACLs().get(0).GetPrinciple()); - assertTrue(listRes2.GetACLs().get(0).GetPrivilege().GetPrivileges().contains(ACLPrivilege.READ)); - assertTrue(listRes2.GetACLs().get(0).GetPrivilege().GetPrivileges().contains(ACLPrivilege.WRITE)); - - } catch (LogException e) { + } + } + + private void aclAPI() { + try { + String principle = "ANONYMOUS"; + + List privilegeList = new ArrayList(); + privilegeList.add(ACLPrivilege.READ); + ACLPrivileges privileges = new ACLPrivileges(privilegeList); + + ACL acl = new ACL(principle, privileges, ACLAction.GRANT); + + client.UpdateACL(project, acl); + + ListACLResponse listRes = client.ListACL(project); + assertEquals("acl num does not match", 2, listRes.GetACLs().size()); + boolean checked = false; + for (ACL aclRes:listRes.GetACLs()) { + if (aclRes.GetPrinciple().equals(principle)) { + checked = true; + assertEquals(principle, aclRes.GetPrinciple()); + assertTrue(aclRes.GetPrivilege().GetPrivileges().contains(ACLPrivilege.READ)); + } + } + assertTrue("expected ACL does not exist", checked); + + List privilegeList2 = new ArrayList(); + privilegeList2.add(ACLPrivilege.READ); + privilegeList2.add(ACLPrivilege.WRITE); + ACLPrivileges privileges2 = new ACLPrivileges(privilegeList2); + + ACL acl2 = new ACL(principle, privileges2, ACLAction.GRANT); + + client.UpdateACL(project, logStore, acl2); + + ListACLResponse listRes2 = client.ListACL(project, logStore); + assertEquals("acl num does not match", 1, listRes2.GetACLs().size()); + System.out.println(listRes2.GetCount()); + + assertEquals(principle, listRes2.GetACLs().get(0).GetPrinciple()); + assertTrue(listRes2.GetACLs().get(0).GetPrivilege().GetPrivileges().contains(ACLPrivilege.READ)); + assertTrue(listRes2.GetACLs().get(0).GetPrivilege().GetPrivileges().contains(ACLPrivilege.WRITE)); + + } catch (LogException e) { fail(e.GetErrorMessage()); - } - } - - private void testReleaseSCM(String testConfigName, String testMachineGroupName){ - try { - client.DeleteConfig(project, testConfigName); - client.DeleteConfig(project, syslogConfigName); - client.DeleteConfig(project, apsaraConfigName); - client.DeleteConfig(project, jsonConfigName); - client.DeleteConfig(project, dilimeterConfigName); - } catch (LogException e) { + } + } + + private void testReleaseSCM(String testConfigName, String testMachineGroupName){ + try { + client.DeleteConfig(project, testConfigName); + client.DeleteConfig(project, syslogConfigName); + client.DeleteConfig(project, apsaraConfigName); + client.DeleteConfig(project, jsonConfigName); + client.DeleteConfig(project, dilimeterConfigName); + } catch (LogException e) { fail(e.getMessage()); - } + } - try { - client.GetConfig(project, testConfigName); - } catch (LogException e) { - assertEquals("Error message does not match", "Config " + testConfigName + " not exist", e.getMessage()); - } + try { + client.GetConfig(project, testConfigName); + } catch (LogException e) { + assertEquals("Error message does not match", "Config " + testConfigName + " not exist", e.getMessage()); + } - try { - client.DeleteMachineGroup(project, testMachineGroupName); - } catch (LogException e) { + try { + client.DeleteMachineGroup(project, testMachineGroupName); + } catch (LogException e) { fail(e.getMessage()); - } - - try { - client.GetMachineGroup(project, testMachineGroupName); - } catch (LogException e) { - assertEquals("Error message does not match", "MachineGroup " + testMachineGroupName + " not exist", e.getMessage()); - } - } - - private void listAllProject() { - try { - ListProjectResponse response = client.ListProject(); - for (Project project:response.getProjects()) { - System.out.println(project.ToJsonString()); - } - System.out.println(response.getCount()); - System.out.println(response.getTotal()); - } catch (LogException e) { + } + + try { + client.GetMachineGroup(project, testMachineGroupName); + } catch (LogException e) { + assertEquals("Error message does not match", "MachineGroup " + testMachineGroupName + " not exist", e.getMessage()); + } + } + + private void listAllProject() { + try { + ListProjectResponse response = client.ListProject(); + for (Project project:response.getProjects()) { + System.out.println(project.ToJsonString()); + } + System.out.println(response.getCount()); + System.out.println(response.getTotal()); + } catch (LogException e) { fail(e.getMessage()); - } - } - - @Test - public void TestAll() { - listAllProject(); - aclAPI(); - apsaraConfigAPI(apsaraConfigName); - configAPI(configName); - machineGroupAPI(groupName, configName); - testReleaseSCM(configName, groupName); - } + } + } + + @Test + public void TestAll() { + listAllProject(); + aclAPI(); + apsaraConfigAPI(apsaraConfigName); + configAPI(configName); + machineGroupAPI(groupName, configName); + testReleaseSCM(configName, groupName); + } }