/** * Partially updates the fields appearing in the given IdealState (input). * @param clusterName * @param resourceName * @param idealState */ @Override public void updateIdealState(String clusterName, String resourceName, IdealState idealState) { if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) { throw new HelixException( "updateIdealState failed. Cluster: " + clusterName + " is NOT setup properly."); } String zkPath = PropertyPathBuilder.idealState(clusterName, resourceName); if (!_zkClient.exists(zkPath)) { throw new HelixException(String.format( "updateIdealState failed. The IdealState for the given resource does not already exist. Resource name: %s", resourceName)); } // Update by way of merge ZKUtil.createOrUpdate(_zkClient, zkPath, idealState.getRecord(), true, true); }
private void updateClusterConfig(String clusterName, ClusterConfig clusterConfig, boolean overwrite) { if (!ZKUtil.isClusterSetup(clusterName, zkClient)) { throw new HelixException("fail to update config. cluster: " + clusterName + " is NOT setup."); } HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(clusterName).build(); String zkPath = scope.getZkPath(); if (overwrite) { ZKUtil.createOrReplace(zkClient, zkPath, clusterConfig.getRecord(), true); } else { ZKUtil.createOrUpdate(zkClient, zkPath, clusterConfig.getRecord(), true, true); } }
private void updateClusterConfig(String clusterName, ClusterConfig clusterConfig, boolean overwrite) { if (!ZKUtil.isClusterSetup(clusterName, zkClient)) { throw new HelixException("fail to update config. cluster: " + clusterName + " is NOT setup."); } HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(clusterName).build(); String zkPath = scope.getZkPath(); if (overwrite) { ZKUtil.createOrReplace(zkClient, zkPath, clusterConfig.getRecord(), true); } else { ZKUtil.createOrUpdate(zkClient, zkPath, clusterConfig.getRecord(), true, true); } }
private void updateInstanceConfig(String clusterName, String instanceName, InstanceConfig instanceConfig, boolean overwrite) { if (!ZKUtil.isClusterSetup(clusterName, zkClient)) { throw new HelixException("fail to setup config. cluster: " + clusterName + " is NOT setup."); } HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT).forCluster(clusterName) .forParticipant(instanceName).build(); String zkPath = scope.getZkPath(); if (overwrite) { ZKUtil.createOrReplace(zkClient, zkPath, instanceConfig.getRecord(), true); } else { ZKUtil.createOrUpdate(zkClient, zkPath, instanceConfig.getRecord(), true, true); } } }
private void updateResourceConfig(String clusterName, String resourceName, ResourceConfig resourceConfig, boolean overwrite) { if (!ZKUtil.isClusterSetup(clusterName, zkClient)) { throw new HelixException("fail to setup config. cluster: " + clusterName + " is NOT setup."); } HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE).forCluster(clusterName) .forResource(resourceName).build(); String zkPath = scope.getZkPath(); if (overwrite) { ZKUtil.createOrReplace(zkClient, zkPath, resourceConfig.getRecord(), true); } else { ZKUtil.createOrUpdate(zkClient, zkPath, resourceConfig.getRecord(), true, true); } }
private void updateResourceConfig(String clusterName, String resourceName, ResourceConfig resourceConfig, boolean overwrite) { if (!ZKUtil.isClusterSetup(clusterName, zkClient)) { throw new HelixException("fail to setup config. cluster: " + clusterName + " is NOT setup."); } HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE).forCluster(clusterName) .forResource(resourceName).build(); String zkPath = scope.getZkPath(); if (overwrite) { ZKUtil.createOrReplace(zkClient, zkPath, resourceConfig.getRecord(), true); } else { ZKUtil.createOrUpdate(zkClient, zkPath, resourceConfig.getRecord(), true, true); } }
private void updateInstanceConfig(String clusterName, String instanceName, InstanceConfig instanceConfig, boolean overwrite) { if (!ZKUtil.isClusterSetup(clusterName, zkClient)) { throw new HelixException("fail to setup config. cluster: " + clusterName + " is NOT setup."); } HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT).forCluster(clusterName) .forParticipant(instanceName).build(); String zkPath = scope.getZkPath(); if (!zkClient.exists(zkPath)) { throw new HelixException( "updateInstanceConfig failed. Given InstanceConfig does not already exist. instance: " + instanceName); } if (overwrite) { ZKUtil.createOrReplace(zkClient, zkPath, instanceConfig.getRecord(), true); } else { ZKUtil.createOrUpdate(zkClient, zkPath, instanceConfig.getRecord(), true, true); } } }
List<String> list = Arrays.asList("value1", "value2"); record.setListField("list", list); ZKUtil.createOrUpdate(_gZkClient, path, record, true, true); record = _gZkClient.readData(path); AssertJUnit.assertEquals(list, record.getListField("list")); List<String> list2 = Arrays.asList("value3", "value4"); record.setListField("list", list2); ZKUtil.createOrUpdate(_gZkClient, path, record, true, true); record = _gZkClient.readData(path); AssertJUnit.assertEquals(list2, record.getListField("list")); ZKUtil.createOrUpdate(_gZkClient, path, record, true, true); record = _gZkClient.readData(path); AssertJUnit.assertEquals(map, record.getMapField("map")); Map<String, String> map2 = new HashMap<String, String>() {{put("k2", "v2");}}; record.setMapField("map", map2); ZKUtil.createOrUpdate(_gZkClient, path, record, true, true); record = _gZkClient.readData(path); AssertJUnit.assertEquals(new HashMap<String, String>() {{