Java Code Examples for org.apache.helix.ConfigAccessor#getCustomizedStateConfig()
The following examples show how to use
org.apache.helix.ConfigAccessor#getCustomizedStateConfig() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestZkHelixAdmin.java From helix with Apache License 2.0 | 6 votes |
@Test public void testAddCustomizedStateConfig() { String className = TestHelper.getTestClassName(); String methodName = TestHelper.getTestMethodName(); String clusterName = className + "_" + methodName; HelixAdmin admin = new ZKHelixAdmin(ZK_ADDR); admin.addCluster(clusterName, true); CustomizedStateConfig.Builder builder = new CustomizedStateConfig.Builder(); builder.addAggregationEnabledType("mockType1"); CustomizedStateConfig customizedStateConfig = builder.build(); admin.addCustomizedStateConfig(clusterName, customizedStateConfig); // Read CustomizedStateConfig from Zookeeper and check the content ConfigAccessor _configAccessor = new ConfigAccessor(ZK_ADDR); CustomizedStateConfig configFromZk = _configAccessor.getCustomizedStateConfig(clusterName); List<String> listTypesFromZk = configFromZk.getAggregationEnabledTypes(); Assert.assertEquals(listTypesFromZk.get(0), "mockType1"); }
Example 2
Source File: ClusterAccessor.java From helix with Apache License 2.0 | 6 votes |
@GET @Path("{clusterId}/customized-state-config") public Response getCustomizedStateConfig(@PathParam("clusterId") String clusterId) { if (!doesClusterExist(clusterId)) { return notFound(String.format("Cluster %s does not exist", clusterId)); } ConfigAccessor configAccessor = getConfigAccessor(); CustomizedStateConfig customizedStateConfig = configAccessor.getCustomizedStateConfig(clusterId); if (customizedStateConfig != null) { return JSONRepresentation(customizedStateConfig.getRecord()); } return notFound(); }
Example 3
Source File: TestZkHelixAdmin.java From helix with Apache License 2.0 | 5 votes |
@Test public void testRemoveCustomizedStateConfig() throws Exception { String className = TestHelper.getTestClassName(); String methodName = TestHelper.getTestMethodName(); String clusterName = className + "_" + methodName; HelixAdmin admin = new ZKHelixAdmin(ZK_ADDR); admin.addCluster(clusterName, true); CustomizedStateConfig.Builder builder = new CustomizedStateConfig.Builder(); builder.addAggregationEnabledType("mockType1"); CustomizedStateConfig customizedStateConfig = builder.build(); admin.addCustomizedStateConfig(clusterName, customizedStateConfig); // Read CustomizedStateConfig from Zookeeper and check the content ConfigAccessor _configAccessor = new ConfigAccessor(ZK_ADDR); CustomizedStateConfig configFromZk = _configAccessor.getCustomizedStateConfig(clusterName); List<String> listTypesFromZk = configFromZk.getAggregationEnabledTypes(); Assert.assertEquals(listTypesFromZk.get(0), "mockType1"); // Remove CustomizedStateConfig Config and make sure it has been removed from // Zookeeper admin.removeCustomizedStateConfig(clusterName); configFromZk = _configAccessor.getCustomizedStateConfig(clusterName); Assert.assertNull(configFromZk); }
Example 4
Source File: TestZkHelixAdmin.java From helix with Apache License 2.0 | 5 votes |
@Test public void testUpdateCustomizedStateConfig() throws Exception { String className = TestHelper.getTestClassName(); String methodName = TestHelper.getTestMethodName(); String clusterName = className + "_" + methodName; HelixAdmin admin = new ZKHelixAdmin(ZK_ADDR); admin.addCluster(clusterName, true); CustomizedStateConfig.Builder builder = new CustomizedStateConfig.Builder(); builder.addAggregationEnabledType("mockType1"); CustomizedStateConfig customizedStateConfig = builder.build(); admin.addCustomizedStateConfig(clusterName, customizedStateConfig); // Read CustomizedStateConfig from Zookeeper and check the content ConfigAccessor _configAccessor = new ConfigAccessor(ZK_ADDR); CustomizedStateConfig configFromZk = _configAccessor.getCustomizedStateConfig(clusterName); List<String> listTypesFromZk = configFromZk.getAggregationEnabledTypes(); Assert.assertEquals(listTypesFromZk.get(0), "mockType1"); admin.addTypeToCustomizedStateConfig(clusterName, "mockType2"); admin.addTypeToCustomizedStateConfig(clusterName, "mockType3"); configFromZk = _configAccessor.getCustomizedStateConfig(clusterName); listTypesFromZk = configFromZk.getAggregationEnabledTypes(); Assert.assertEquals(listTypesFromZk.get(0), "mockType1"); Assert.assertEquals(listTypesFromZk.get(1), "mockType2"); Assert.assertEquals(listTypesFromZk.get(2), "mockType3"); admin.removeTypeFromCustomizedStateConfig(clusterName, "mockType1"); configFromZk = _configAccessor.getCustomizedStateConfig(clusterName); listTypesFromZk = configFromZk.getAggregationEnabledTypes(); Assert.assertEquals(listTypesFromZk.get(0), "mockType2"); Assert.assertEquals(listTypesFromZk.get(1), "mockType3"); }
Example 5
Source File: TestCustomizedStateConfig.java From helix with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = HelixException.class) public void TestCustomizedStateConfigNonExistentCluster() { String className = getShortClassName(); String clusterName = "CLUSTER_" + className; // Read CustomizedStateConfig from Zookeeper and get exception since cluster in not setup yet ConfigAccessor _configAccessor = new ConfigAccessor(ZK_ADDR); CustomizedStateConfig customizedStateConfig = _configAccessor.getCustomizedStateConfig(clusterName); }
Example 6
Source File: TestCustomizedStateConfig.java From helix with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = "TestCustomizedStateConfigNonExistentCluster") public void testCustomizedStateConfigNull() { String className = getShortClassName(); String clusterName = "CLUSTER_" + className; TestHelper.setupEmptyCluster(_gZkClient, clusterName); // Read CustomizedStateConfig from Zookeeper ConfigAccessor _configAccessor = new ConfigAccessor(ZK_ADDR); CustomizedStateConfig customizedStateConfigFromZk = _configAccessor.getCustomizedStateConfig(clusterName); Assert.assertNull(customizedStateConfigFromZk); }
Example 7
Source File: TestCustomizedStateConfig.java From helix with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = "testCustomizedStateConfigNull") public void testCustomizedStateConfig() { String className = getShortClassName(); String clusterName = "CLUSTER_" + className; TestHelper.setupEmptyCluster(_gZkClient, clusterName); // Create dummy CustomizedStateConfig object CustomizedStateConfig.Builder customizedStateConfigBuilder = new CustomizedStateConfig.Builder(); List<String> aggregationEnabledTypes = new ArrayList<String>(); aggregationEnabledTypes.add("mockType1"); aggregationEnabledTypes.add("mockType2"); customizedStateConfigBuilder.setAggregationEnabledTypes(aggregationEnabledTypes); CustomizedStateConfig customizedStateConfig = customizedStateConfigBuilder.build(); // Write the CustomizedStateConfig to Zookeeper ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(ZK_ADDR)); Builder keyBuilder = accessor.keyBuilder(); accessor.setProperty(keyBuilder.customizedStateConfig(), customizedStateConfig); // Read CustomizedStateConfig from Zookeeper and check the content ConfigAccessor _configAccessor = new ConfigAccessor(ZK_ADDR); CustomizedStateConfig customizedStateConfigFromZk = _configAccessor.getCustomizedStateConfig(clusterName); Assert.assertEquals(customizedStateConfigFromZk.getAggregationEnabledTypes().size(), 2); Assert.assertEquals(aggregationEnabledTypes.get(0), "mockType1"); Assert.assertEquals(aggregationEnabledTypes.get(1), "mockType2"); }
Example 8
Source File: TestCustomizedStateConfig.java From helix with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = "testCustomizedStateConfig") public void testCustomizedStateConfigBuilder() { String className = getShortClassName(); String clusterName = "CLUSTER_" + className; TestHelper.setupEmptyCluster(_gZkClient, clusterName); CustomizedStateConfig.Builder builder = new CustomizedStateConfig.Builder(); builder.addAggregationEnabledType("mockType1"); builder.addAggregationEnabledType("mockType2"); // Check builder getter methods List<String> aggregationEnabledTypes = builder.getAggregationEnabledTypes(); Assert.assertEquals(aggregationEnabledTypes.size(), 2); Assert.assertEquals(aggregationEnabledTypes.get(0), "mockType1"); Assert.assertEquals(aggregationEnabledTypes.get(1), "mockType2"); CustomizedStateConfig customizedStateConfig = builder.build(); ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(ZK_ADDR)); Builder keyBuilder = accessor.keyBuilder(); accessor.setProperty(keyBuilder.customizedStateConfig(), customizedStateConfig); // Read CustomizedStateConfig from Zookeeper and check the content ConfigAccessor _configAccessor = new ConfigAccessor(ZK_ADDR); CustomizedStateConfig customizedStateConfigFromZk = _configAccessor.getCustomizedStateConfig(clusterName); List<String> aggregationEnabledTypesFromZk = customizedStateConfigFromZk.getAggregationEnabledTypes(); Assert.assertEquals(aggregationEnabledTypesFromZk.get(0), "mockType1"); Assert.assertEquals(aggregationEnabledTypesFromZk.get(1), "mockType2"); }
Example 9
Source File: TestClusterAccessor.java From helix with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = "testAddCustomizedConfig") public void testDeleteCustomizedConfig() throws IOException { System.out.println("Start test :" + TestHelper.getTestMethodName()); _gSetupTool.addCluster("TestClusterCustomized", true); String urlBase = "clusters/TestClusterCustomized/customized-state-config/"; ZNRecord record = new ZNRecord("TestCustomizedStateConfig"); List<String> testList = new ArrayList<String>(); testList.add("mockType1"); record.setListField( CustomizedStateConfig.CustomizedStateProperty.AGGREGATION_ENABLED_TYPES .name(), testList); put(urlBase, null, Entity.entity(OBJECT_MAPPER.writeValueAsString(record), MediaType.APPLICATION_JSON_TYPE), Response.Status.OK.getStatusCode()); // Read CustomizedStateConfig from Zookeeper and make sure it exists ConfigAccessor _configAccessor = new ConfigAccessor(ZK_ADDR); CustomizedStateConfig customizedConfigFromZk = _configAccessor.getCustomizedStateConfig("TestClusterCustomized"); Assert.assertNotNull(customizedConfigFromZk); delete(urlBase, Response.Status.OK.getStatusCode()); customizedConfigFromZk = _configAccessor.getCustomizedStateConfig("TestClusterCustomized"); Assert.assertNull(customizedConfigFromZk); System.out.println("End test :" + TestHelper.getTestMethodName()); }
Example 10
Source File: TestClusterAccessor.java From helix with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = "testAddCustomizedConfigNonExistedCluster") public void testAddCustomizedConfig() throws Exception { System.out.println("Start test :" + TestHelper.getTestMethodName()); _gSetupTool.addCluster("TestClusterCustomized", true); String urlBase = "clusters/TestClusterCustomized/customized-state-config/"; ZNRecord record = new ZNRecord("TestCustomizedStateConfig"); List<String> testList = new ArrayList<String>(); testList.add("mockType1"); testList.add("mockType2"); record.setListField( CustomizedStateConfig.CustomizedStateProperty.AGGREGATION_ENABLED_TYPES .name(), testList); put(urlBase, null, Entity.entity(OBJECT_MAPPER.writeValueAsString(record), MediaType.APPLICATION_JSON_TYPE), Response.Status.OK.getStatusCode()); // Read CustomizedStateConfig from Zookeeper and check the content ConfigAccessor _configAccessor = new ConfigAccessor(ZK_ADDR); CustomizedStateConfig customizedConfigFromZk = _configAccessor.getCustomizedStateConfig("TestClusterCustomized"); List<String> listTypesFromZk = customizedConfigFromZk.getAggregationEnabledTypes(); Assert.assertEquals(listTypesFromZk.get(0), "mockType1"); Assert.assertEquals(listTypesFromZk.get(1), "mockType2"); // Now test the getCustomizedStateConfig method. String body = get(urlBase, null, Response.Status.OK.getStatusCode(), true); ZNRecord recordFromRest = new ObjectMapper().reader(ZNRecord.class).readValue(body); CustomizedStateConfig customizedConfigRest = new CustomizedStateConfig.Builder(recordFromRest).build(); CustomizedStateConfig customizedConfigZk = _configAccessor.getCustomizedStateConfig("TestClusterCustomized"); // Check that the CustomizedStateConfig from Zk and REST get method are equal Assert.assertEquals(customizedConfigRest, customizedConfigZk); // Check the fields individually List<String> listUrlFromRest = customizedConfigRest.getAggregationEnabledTypes(); Assert.assertEquals(listUrlFromRest.get(0), "mockType1"); Assert.assertEquals(listUrlFromRest.get(1), "mockType2"); System.out.println("End test :" + TestHelper.getTestMethodName()); }
Example 11
Source File: TestClusterAccessor.java From helix with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = "testDeleteCustomizedConfig") public void testUpdateCustomizedConfig() throws IOException { System.out.println("Start test :" + TestHelper.getTestMethodName()); _gSetupTool.addCluster("TestClusterCustomized", true); String urlBase = "clusters/TestClusterCustomized/customized-state-config/"; ZNRecord record = new ZNRecord("TestCustomizedStateConfig"); List<String> testList = new ArrayList<String>(); testList.add("mockType1"); record.setListField( CustomizedStateConfig.CustomizedStateProperty.AGGREGATION_ENABLED_TYPES .name(), testList); put(urlBase, null, Entity.entity(OBJECT_MAPPER.writeValueAsString(record), MediaType.APPLICATION_JSON_TYPE), Response.Status.OK.getStatusCode()); // Read CustomizedStateConfig from Zookeeper and make sure it exists ConfigAccessor _configAccessor = new ConfigAccessor(ZK_ADDR); CustomizedStateConfig customizedConfigFromZk = _configAccessor.getCustomizedStateConfig("TestClusterCustomized"); Assert.assertNotNull(customizedConfigFromZk); // Add new type to CustomizedStateConfig Map<String, String> map1 = new HashMap<>(); map1.put("command", Command.add.name()); map1.put("type", "mockType2"); post(urlBase, map1, Entity.entity("", MediaType.APPLICATION_JSON_TYPE), Response.Status.OK.getStatusCode()); customizedConfigFromZk = _configAccessor.getCustomizedStateConfig("TestClusterCustomized"); List<String> listTypesFromZk = customizedConfigFromZk.getAggregationEnabledTypes(); Assert.assertEquals(listTypesFromZk.get(0), "mockType1"); Assert.assertEquals(listTypesFromZk.get(1), "mockType2"); // Remove a type to CustomizedStateConfig Map<String, String> map2 = new HashMap<>(); map2.put("command", Command.delete.name()); map2.put("type", "mockType1"); post(urlBase, map2, Entity.entity("", MediaType.APPLICATION_JSON_TYPE), Response.Status.OK.getStatusCode()); customizedConfigFromZk = _configAccessor.getCustomizedStateConfig("TestClusterCustomized"); listTypesFromZk = customizedConfigFromZk.getAggregationEnabledTypes(); Assert.assertEquals(listTypesFromZk.get(0), "mockType2"); Assert.assertFalse(listTypesFromZk.contains("mockType1")); System.out.println("End test :" + TestHelper.getTestMethodName()); }