本文整理汇总了Java中org.apache.helix.model.IdealState.setStateModelDefRef方法的典型用法代码示例。如果您正苦于以下问题:Java IdealState.setStateModelDefRef方法的具体用法?Java IdealState.setStateModelDefRef怎么用?Java IdealState.setStateModelDefRef使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.helix.model.IdealState
的用法示例。
在下文中一共展示了IdealState.setStateModelDefRef方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInitialAssignment
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
public IdealState doInitialAssignment(String clusterName, List<String> instanceNames,
int replicationFactor) {
IdealState idealState = new IdealState(MySQLConstants.MASTER_SLAVE_RESOURCE_NAME);
idealState.setStateModelDefRef("MasterSlave");
idealState.setRebalanceMode(RebalanceMode.CUSTOMIZED);
if (instanceNames.size() % replicationFactor != 0) {
LOG.error(String.format(
"Number of instances (%s) in the cluster must be a multiple of replication factor (%s)",
instanceNames.size(), replicationFactor));
return null;
}
int numSlices = instanceNames.size() / replicationFactor;
idealState.setNumPartitions(numSlices);
idealState.setReplicas(String.valueOf(replicationFactor));
Collections.sort(instanceNames);
for (int i = 0; i < numSlices; i++) {
for (int j = 0; j < replicationFactor; j++) {
idealState.setPartitionState(MySQLConstants.MASTER_SLAVE_RESOURCE_NAME + "_" + i,
instanceNames.get(i * replicationFactor + j), (j == 0) ? "MASTER" : "SLAVE");
}
}
LOG.info("Creating initial assignment \n" + idealState);
_helixAdmin.setResourceIdealState(clusterName, MySQLConstants.MASTER_SLAVE_RESOURCE_NAME,
idealState);
return idealState;
}
示例2: addResource
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
@Override
public void addResource(String clusterName, String resourceName, int partitions,
String stateModelRef, String rebalancerMode, String rebalanceStrategy, int bucketSize,
int maxPartitionsPerInstance) {
if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
throw new HelixException("cluster " + clusterName + " is not setup yet");
}
IdealState idealState = new IdealState(resourceName);
idealState.setNumPartitions(partitions);
idealState.setStateModelDefRef(stateModelRef);
RebalanceMode mode =
idealState.rebalanceModeFromString(rebalancerMode, RebalanceMode.SEMI_AUTO);
idealState.setRebalanceMode(mode);
idealState.setRebalanceStrategy(rebalanceStrategy);
idealState.setReplicas("" + 0);
idealState.setStateModelFactoryName(HelixConstants.DEFAULT_STATE_MODEL_FACTORY);
if (maxPartitionsPerInstance > 0 && maxPartitionsPerInstance < Integer.MAX_VALUE) {
idealState.setMaxPartitionsPerInstance(maxPartitionsPerInstance);
}
if (bucketSize > 0) {
idealState.setBucketSize(bucketSize);
}
addResource(clusterName, resourceName, idealState);
}
示例3: createIdealStateForResourceGroup
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
/**
* Create an IdealState for a resource that belongs to a resource group We use
* "resourceGroupName$resourceInstanceTag" as the IdealState znode name to differetiate different
* resources from the same resourceGroup.
*/
public IdealState createIdealStateForResourceGroup(String resourceGroupName,
String resourceTag, int numPartition, int replica, String rebalanceMode, String stateModelDefName) {
String idealStateId = genIdealStateNameWithResourceTag(resourceGroupName, resourceTag);
IdealState idealState = new IdealState(idealStateId);
idealState.setNumPartitions(numPartition);
idealState.setStateModelDefRef(stateModelDefName);
IdealState.RebalanceMode mode =
idealState.rebalanceModeFromString(rebalanceMode, IdealState.RebalanceMode.SEMI_AUTO);
idealState.setRebalanceMode(mode);
idealState.setReplicas("" + replica);
idealState.setStateModelFactoryName(HelixConstants.DEFAULT_STATE_MODEL_FACTORY);
idealState.setResourceGroupName(resourceGroupName);
idealState.setInstanceGroupTag(resourceTag);
idealState.enableGroupRouting(true);
return idealState;
}
示例4: setupCluster
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
private void setupCluster(String clusterName, List<String> instanceNames, String dbName,
int replica, int partitions, int bucketSize) {
_gSetupTool.addCluster(clusterName, true);
_gSetupTool.addInstancesToCluster(clusterName,
instanceNames.toArray(new String[instanceNames.size()]));
// add a bucketized resource
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, _baseAccessor);
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
ZNRecord idealStateRec =
DefaultIdealStateCalculator.calculateIdealState(instanceNames, partitions, replica - 1,
dbName,
"MASTER", "SLAVE");
IdealState idealState = new IdealState(idealStateRec);
idealState.setBucketSize(bucketSize);
idealState.setStateModelDefRef("MasterSlave");
idealState.setRebalanceMode(IdealState.RebalanceMode.CUSTOMIZED);
idealState.setReplicas(Integer.toString(replica));
accessor.setProperty(keyBuilder.idealStates(dbName), idealState);
}
示例5: testIdealStateAssignment
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
@Test(dataProvider = "IdealStateInput")
public void testIdealStateAssignment(String clusterName,
List<String> instances, List<String> partitions, String numReplicas, String stateModeDef,
String strategyName, Map<String, Map<String, String>> expectedMapping)
throws IllegalAccessException, InstantiationException, ClassNotFoundException {
ClusterConfig clusterConfig = new ClusterConfig(clusterName);
List<InstanceConfig> instanceConfigs = new ArrayList<>();
for (String instance : instances) {
instanceConfigs.add(new InstanceConfig(instance));
}
IdealState idealState = new IdealState("TestResource");
idealState.setStateModelDefRef(stateModeDef);
idealState.setNumPartitions(partitions.size());
idealState.setReplicas(numReplicas);
Map<String, Map<String, String>> idealStateMapping = HelixUtil
.getIdealAssignmentForFullAuto(clusterConfig, instanceConfigs, instances, idealState,
partitions, strategyName);
Assert.assertEquals(idealStateMapping, expectedMapping);
}
示例6: addClusterToGrandCluster
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
@Override
public void addClusterToGrandCluster(String clusterName, String grandCluster) {
if (!ZKUtil.isClusterSetup(grandCluster, _zkClient)) {
throw new HelixException("Grand cluster " + grandCluster + " is not setup yet");
}
if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
throw new HelixException("Cluster " + clusterName + " is not setup yet");
}
IdealState idealState = new IdealState(clusterName);
idealState.setNumPartitions(1);
idealState.setStateModelDefRef("LeaderStandby");
List<String> controllers = getInstancesInCluster(grandCluster);
if (controllers.size() == 0) {
throw new HelixException("Grand cluster " + grandCluster + " has no instances");
}
idealState.setReplicas(Integer.toString(controllers.size()));
Collections.shuffle(controllers);
idealState.getRecord().setListField(clusterName, controllers);
idealState.setPartitionState(clusterName, controllers.get(0), "LEADER");
for (int i = 1; i < controllers.size(); i++) {
idealState.setPartitionState(clusterName, controllers.get(i), "STANDBY");
}
ZKHelixDataAccessor accessor =
new ZKHelixDataAccessor(grandCluster, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.idealStates(idealState.getResourceName()), idealState);
}
示例7: testSimple
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
/**
* Case where we have one resource in IdealState
* @throws Exception
*/
@Test
public void testSimple() throws Exception {
int nodes = 5;
List<String> instances = new ArrayList<String>();
for (int i = 0; i < nodes; i++) {
instances.add("localhost_" + i);
}
int partitions = 10;
int replicas = 1;
String resourceName = "testResource";
ZNRecord record =
DefaultIdealStateCalculator.calculateIdealState(instances, partitions, replicas,
resourceName, "MASTER", "SLAVE");
IdealState idealState = new IdealState(record);
idealState.setStateModelDefRef("MasterSlave");
HelixDataAccessor accessor = manager.getHelixDataAccessor();
Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.idealStates(resourceName), idealState);
ResourceComputationStage stage = new ResourceComputationStage();
runStage(event, new ReadClusterDataStage());
runStage(event, stage);
Map<String, Resource> resource = event.getAttribute(AttributeName.RESOURCES_TO_REBALANCE.name());
AssertJUnit.assertEquals(1, resource.size());
AssertJUnit.assertEquals(resource.keySet().iterator().next(), resourceName);
AssertJUnit.assertEquals(resource.values().iterator().next().getResourceName(), resourceName);
AssertJUnit.assertEquals(resource.values().iterator().next().getStateModelDefRef(),
idealState.getStateModelDefRef());
AssertJUnit
.assertEquals(resource.values().iterator().next().getPartitions().size(), partitions);
}
示例8: setupIdealState
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
protected List<IdealState> setupIdealState(int nodes, String[] resources, int partitions,
int replicas, RebalanceMode rebalanceMode, String stateModelName, String rebalanceClassName,
String rebalanceStrategyName) {
List<IdealState> idealStates = new ArrayList<IdealState>();
for (int i = 0; i < resources.length; i++) {
String resourceName = resources[i];
ZNRecord record = new ZNRecord(resourceName);
for (int p = 0; p < partitions; p++) {
List<String> value = new ArrayList<String>();
for (int r = 0; r < replicas; r++) {
value.add(HOSTNAME_PREFIX + (p + r + 1) % nodes);
}
record.setListField(resourceName + "_" + p, value);
}
IdealState idealState = new IdealState(record);
idealState.setStateModelDefRef(stateModelName);
if (rebalanceClassName != null) {
idealState.setRebalancerClassName(rebalanceClassName);
}
if (rebalanceStrategyName != null) {
idealState.setRebalanceStrategy(rebalanceStrategyName);
}
idealState.setRebalanceMode(rebalanceMode);
idealState.setNumPartitions(partitions);
idealStates.add(idealState);
idealState.setReplicas(String.valueOf(replicas));
Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.idealStates(resourceName), idealState);
}
return idealStates;
}
示例9: createIS
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
private void createIS(HelixDataAccessor accessor, String resourceId, String stateModelDefRef,
RebalanceMode rebalanceMode) {
IdealState idealState = new IdealState(resourceId);
idealState.setRebalanceMode(rebalanceMode);
idealState.setStateModelDefRef(stateModelDefRef);
idealState.setNumPartitions(1);
idealState.setReplicas("1");
idealState.getRecord().setListField(resourceId + "_0", ImmutableList.of(PARTICIPANT));
idealState.getRecord().setMapField(resourceId + "_0", ImmutableMap.of(PARTICIPANT, STATE));
accessor.setProperty(accessor.keyBuilder().idealStates(resourceId), idealState);
}
示例10: setupIdealStateDeprecated
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
protected List<IdealState> setupIdealStateDeprecated(int nodes, String[] resources,
int partitions, int replicas, IdealStateModeProperty mode) {
List<IdealState> idealStates = new ArrayList<IdealState>();
List<String> instances = new ArrayList<String>();
for (int i = 0; i < nodes; i++) {
instances.add("localhost_" + i);
}
for (int i = 0; i < resources.length; i++) {
String resourceName = resources[i];
ZNRecord record = new ZNRecord(resourceName);
for (int p = 0; p < partitions; p++) {
List<String> value = new ArrayList<String>();
for (int r = 0; r < replicas; r++) {
value.add("localhost_" + (p + r + 1) % nodes);
}
record.setListField(resourceName + "_" + p, value);
}
IdealState idealState = new IdealState(record);
idealState.setStateModelDefRef("MasterSlave");
idealState.setIdealStateMode(mode.toString());
idealState.setNumPartitions(partitions);
idealStates.add(idealState);
// System.out.println(idealState);
Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.idealStates(resourceName), idealState);
}
return idealStates;
}
示例11: setupIdealState
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
protected List<IdealState> setupIdealState(String clusterName, int[] nodes, String[] resources,
int partitions, int replicas) {
ZKHelixDataAccessor accessor =
new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
List<IdealState> idealStates = new ArrayList<IdealState>();
List<String> instances = new ArrayList<String>();
for (int i : nodes) {
instances.add("localhost_" + i);
}
for (String resourceName : resources) {
IdealState idealState = new IdealState(resourceName);
for (int p = 0; p < partitions; p++) {
List<String> value = new ArrayList<String>();
for (int r = 0; r < replicas; r++) {
int n = nodes[(p + r) % nodes.length];
value.add("localhost_" + n);
}
idealState.getRecord().setListField(resourceName + "_" + p, value);
}
idealState.setReplicas(Integer.toString(replicas));
idealState.setStateModelDefRef("MasterSlave");
idealState.setRebalanceMode(RebalanceMode.SEMI_AUTO);
idealState.setNumPartitions(partitions);
idealStates.add(idealState);
// System.out.println(idealState);
accessor.setProperty(keyBuilder.idealStates(resourceName), idealState);
}
return idealStates;
}
示例12: testGetResources
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
@Test
public void testGetResources() throws IOException {
final String clusterName = "TestTagAwareness_testGetResources";
final String TAG = "tag";
final String URL_BASE =
"http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/resourceGroups";
_gSetupTool.addCluster(clusterName, true);
HelixAdmin admin = _gSetupTool.getClusterManagementTool();
// Add a tagged resource
IdealState taggedResource = new IdealState("taggedResource");
taggedResource.setInstanceGroupTag(TAG);
taggedResource.setStateModelDefRef("OnlineOffline");
admin.addResource(clusterName, taggedResource.getId(), taggedResource);
// Add an untagged resource
IdealState untaggedResource = new IdealState("untaggedResource");
untaggedResource.setStateModelDefRef("OnlineOffline");
admin.addResource(clusterName, untaggedResource.getId(), untaggedResource);
// Now make a REST call for all resources
Reference resourceRef = new Reference(URL_BASE);
Request request = new Request(Method.GET, resourceRef);
Response response = _gClient.handle(request);
ZNRecord responseRecord =
ClusterRepresentationUtil.JsonToObject(ZNRecord.class, response.getEntityAsText());
// Ensure that the tagged resource has information and the untagged one doesn't
Assert.assertNotNull(responseRecord.getMapField("ResourceTags"));
Assert
.assertEquals(TAG, responseRecord.getMapField("ResourceTags").get(taggedResource.getId()));
Assert.assertFalse(responseRecord.getMapField("ResourceTags").containsKey(
untaggedResource.getId()));
}
示例13: handleMessageUsingScheduledTaskQueue
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
void handleMessageUsingScheduledTaskQueue(Criteria recipientCriteria, Message messageTemplate,
String controllerMsgId) {
HelixDataAccessor accessor = _manager.getHelixDataAccessor();
Builder keyBuilder = accessor.keyBuilder();
Map<String, String> sendSummary = new HashMap<String, String>();
sendSummary.put("MessageCount", "0");
Map<InstanceType, List<Message>> messages =
_manager.getMessagingService().generateMessage(recipientCriteria, messageTemplate);
// Calculate tasks, and put them into the idealState of the SCHEDULER_TASK_QUEUE resource.
// List field are the destination node, while the Message parameters are stored in the
// mapFields
// task throttling can be done on SCHEDULER_TASK_QUEUE resource
if (messages.size() > 0) {
String taskQueueName = _message.getRecord().getSimpleField(SCHEDULER_TASK_QUEUE);
if (taskQueueName == null) {
throw new HelixException("SchedulerTaskMessage need to have " + SCHEDULER_TASK_QUEUE
+ " specified.");
}
IdealState newAddedScheduledTasks = new IdealState(taskQueueName);
newAddedScheduledTasks.setBucketSize(TASKQUEUE_BUCKET_NUM);
newAddedScheduledTasks.setStateModelDefRef(SCHEDULER_TASK_QUEUE);
synchronized (_manager) {
int existingTopPartitionId = 0;
IdealState currentTaskQueue =
_manager.getHelixDataAccessor().getProperty(
accessor.keyBuilder().idealStates(newAddedScheduledTasks.getId()));
if (currentTaskQueue != null) {
existingTopPartitionId = findTopPartitionId(currentTaskQueue) + 1;
}
List<Message> taskMessages = (List<Message>) (messages.values().toArray()[0]);
for (Message task : taskMessages) {
String partitionId = taskQueueName + "_" + existingTopPartitionId;
existingTopPartitionId++;
String instanceName = task.getTgtName();
newAddedScheduledTasks.setPartitionState(partitionId, instanceName, "COMPLETED");
task.getRecord().setSimpleField(instanceName, "COMPLETED");
task.getRecord().setSimpleField(CONTROLLER_MSG_ID, controllerMsgId);
List<String> priorityList = new LinkedList<String>();
priorityList.add(instanceName);
newAddedScheduledTasks.getRecord().setListField(partitionId, priorityList);
newAddedScheduledTasks.getRecord().setMapField(partitionId,
task.getRecord().getSimpleFields());
_logger.info("Scheduling for controllerMsg " + controllerMsgId + " , sending task "
+ partitionId + " " + task.getMsgId() + " to " + instanceName);
if (_logger.isDebugEnabled()) {
_logger.debug(task.getRecord().getSimpleFields().toString());
}
}
_manager.getHelixDataAccessor().updateProperty(
accessor.keyBuilder().idealStates(newAddedScheduledTasks.getId()),
newAddedScheduledTasks);
sendSummary.put("MessageCount", "" + taskMessages.size());
}
}
// Record the number of messages sent into scheduler message status updates
ZNRecord statusUpdate =
accessor.getProperty(
keyBuilder.controllerTaskStatus(MessageType.SCHEDULER_MSG.name(),
_message.getMsgId())).getRecord();
statusUpdate.getMapFields().put("SentMessageCount", sendSummary);
accessor.updateProperty(keyBuilder.controllerTaskStatus(MessageType.SCHEDULER_MSG.name(),
_message.getMsgId()), new StatusUpdate(statusUpdate));
}
示例14: build
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
/**
* @return
*/
public IdealState build() {
IdealState idealstate = new IdealState(_record);
idealstate.setNumPartitions(numPartitions);
idealstate.setStateModelDefRef(stateModel);
idealstate.setStateModelFactoryName(stateModelFactoryName);
idealstate.setRebalanceMode(rebalancerMode);
idealstate.setReplicas("" + numReplica);
if (minActiveReplica >= 0) {
idealstate.setMinActiveReplicas(minActiveReplica);
}
if (rebalancerClassName != null) {
idealstate.setRebalancerClassName(rebalancerClassName);
}
if (rebalanceStrategy != null) {
idealstate.setRebalanceStrategy(rebalanceStrategy);
}
if (maxPartitionsPerNode > 0) {
idealstate.setMaxPartitionsPerInstance(maxPartitionsPerNode);
}
if (disableExternalView != null) {
idealstate.setDisableExternalView(disableExternalView);
}
if (enableGroupRouting != null) {
idealstate.enableGroupRouting(enableGroupRouting);
}
if (resourceGroupName != null) {
idealstate.setResourceGroupName(resourceGroupName);
}
if (resourceType != null) {
idealstate.setResourceType(resourceType);
}
if (rebalanceDelayInMs >= 0) {
idealstate.setRebalanceDelay(rebalanceDelayInMs);
}
if (delayRebalanceEnabled != null) {
idealstate.setDelayRebalanceEnabled(delayRebalanceEnabled);
}
if (!idealstate.isValid()) {
throw new HelixException("invalid ideal-state: " + idealstate);
}
return idealstate;
}
示例15: calculateRelayIdealState
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
public static IdealState calculateRelayIdealState(List<String> partitions,
List<String> instances, String resultRecordName, int replica, String firstValue,
String restValue, String stateModelName) {
Collections.sort(partitions);
Collections.sort(instances);
if (instances.size() % replica != 0) {
throw new HelixException("Instances must be divided by replica");
}
IdealState result = new IdealState(resultRecordName);
result.setNumPartitions(partitions.size());
result.setReplicas("" + replica);
result.setStateModelDefRef(stateModelName);
int groups = instances.size() / replica;
int remainder = instances.size() % replica;
int remainder2 = partitions.size() % groups;
int storageNodeGroupSize = partitions.size() / groups;
for (int i = 0; i < groups; i++) {
int relayStart = 0, relayEnd = 0, storageNodeStart = 0, storageNodeEnd = 0;
if (i < remainder) {
relayStart = (replica + 1) * i;
relayEnd = (replica + 1) * (i + 1);
} else {
relayStart = (replica + 1) * remainder + replica * (i - remainder);
relayEnd = relayStart + replica;
}
// System.out.println("relay start :" + relayStart + " relayEnd:" + relayEnd);
if (i < remainder2) {
storageNodeStart = (storageNodeGroupSize + 1) * i;
storageNodeEnd = (storageNodeGroupSize + 1) * (i + 1);
} else {
storageNodeStart =
(storageNodeGroupSize + 1) * remainder2 + storageNodeGroupSize * (i - remainder2);
storageNodeEnd = storageNodeStart + storageNodeGroupSize;
}
// System.out.println("storageNodeStart :" + storageNodeStart + " storageNodeEnd:" +
// storageNodeEnd);
List<String> snBatch = partitions.subList(storageNodeStart, storageNodeEnd);
List<String> relayBatch = instances.subList(relayStart, relayEnd);
Map<String, List<String>> sublistFields =
calculateSubIdealState(snBatch, relayBatch, replica);
result.getRecord().getListFields().putAll(sublistFields);
}
for (String snName : result.getRecord().getListFields().keySet()) {
Map<String, String> mapField = new TreeMap<String, String>();
List<String> relayCandidates = result.getRecord().getListField(snName);
mapField.put(relayCandidates.get(0), firstValue);
for (int i = 1; i < relayCandidates.size(); i++) {
mapField.put(relayCandidates.get(i), restValue);
}
result.getRecord().getMapFields().put(snName, mapField);
}
System.out.println();
return result;
}