本文整理汇总了Java中org.apache.helix.model.IdealState.setRebalanceMode方法的典型用法代码示例。如果您正苦于以下问题:Java IdealState.setRebalanceMode方法的具体用法?Java IdealState.setRebalanceMode怎么用?Java IdealState.setRebalanceMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.helix.model.IdealState
的用法示例。
在下文中一共展示了IdealState.setRebalanceMode方法的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: setupUnbalancedDB
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
private void setupUnbalancedDB() throws InterruptedException {
// Start with Full-Auto mode to create the partitions, Semi-Auto won't create partitions.
_setupTool.addResourceToCluster(CLUSTER_NAME, UNBALANCED_DB_NAME, 50, MASTER_SLAVE_STATE_MODEL,
IdealState.RebalanceMode.FULL_AUTO.toString());
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, UNBALANCED_DB_NAME, 1);
// Set preference list to put all partitions to one instance.
IdealState idealState = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME,
UNBALANCED_DB_NAME);
Set<String> partitions = idealState.getPartitionSet();
for (String partition : partitions) {
idealState.setPreferenceList(partition, Lists.newArrayList(_blockedParticipant.getInstanceName()));
}
idealState.setRebalanceMode(IdealState.RebalanceMode.SEMI_AUTO);
_setupTool.getClusterManagementTool().setResourceIdealState(CLUSTER_NAME, UNBALANCED_DB_NAME, idealState);
HelixClusterVerifier clusterVerifier =
new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkClient(_gZkClient).build();
Assert.assertTrue(clusterVerifier.verify(10000));
}
示例6: cleanUpResource
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
private boolean cleanUpResource(String resource, String resourceDir, FileSetInfo fileSetInfo)
throws Exception {
if (isResourceOfflined(resource)) {
LOG.info("Dropping resource " + resource);
helixAdmin.dropResource(clusterName, resource);
zkManager.deleteViewInfo(resource);
// Perform a recursive delete of the version directory.
LOG.info("Cleaning up " + resourceDir);
hdfsClient.delete(resourceDir, true);
return true;
} else {
LOG.info("Offlining " + resourceDir);
boolean enableZkCompression = configuration.getBoolean(
Constants.ENABLE_ZK_COMPRESSION, Constants.ENABLE_ZK_COMPRESSION_DEFAULT);
int bucketSize = TerrapinUtil.getBucketSize(
fileSetInfo.servingInfo.numPartitions, enableZkCompression);
if (bucketSize > 0) {
LOG.info("Disabling resource " + resource);
helixAdmin.enableResource(clusterName, resource, false);
} else {
CustomModeISBuilder offlineStateBuilder = new CustomModeISBuilder(resource);
offlineStateBuilder.setStateModel("OnlineOffline");
offlineStateBuilder.setNumReplica(configuration.getInt(Constants.NUM_SERVING_REPLICAS, 3));
offlineStateBuilder.setNumPartitions(fileSetInfo.servingInfo.numPartitions);
IdealState offlinedState = offlineStateBuilder.build();
offlinedState.setRebalanceMode(IdealState.RebalanceMode.CUSTOMIZED);
if (enableZkCompression) {
TerrapinUtil.compressIdealState(offlinedState);
}
helixAdmin.setResourceIdealState(clusterName, resource, offlinedState);
}
return false;
}
}
示例7: generateNewIdealState
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
private IdealState generateNewIdealState(String resourceName, IdealState currentIdealState,
ZNRecord newMapping) {
IdealState newIdealState = new IdealState(resourceName);
newIdealState.getRecord().setSimpleFields(currentIdealState.getRecord().getSimpleFields());
newIdealState.setRebalanceMode(currentIdealState.getRebalanceMode());
newIdealState.getRecord().setListFields(newMapping.getListFields());
return newIdealState;
}
示例8: testEnableDisablePartitions
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
@Test
public void testEnableDisablePartitions() throws InterruptedException {
HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
admin.enablePartition(false, CLUSTER_NAME, (PARTICIPANT_PREFIX + "_" + _startPort),
WorkflowGenerator.DEFAULT_TGT_DB, Arrays.asList(new String[] { "TestDB_0", "TestDB_2" }));
IdealState idealState =
admin.getResourceIdealState(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB);
List<String> preferenceList =
Arrays.asList(new String[] { "localhost_12919", "localhost_12918" });
for (String partitionName : idealState.getPartitionSet()) {
idealState.setPreferenceList(partitionName, preferenceList);
}
idealState.setRebalanceMode(IdealState.RebalanceMode.SEMI_AUTO);
admin.setResourceIdealState(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB, idealState);
String workflowName = TestHelper.getTestMethodName();
Workflow.Builder builder = new Workflow.Builder(workflowName);
JobConfig.Builder jobBuilder =
new JobConfig.Builder().setWorkflow(workflowName).setCommand(MockTask.TASK_COMMAND)
.setTargetResource(WorkflowGenerator.DEFAULT_TGT_DB)
.setTargetPartitionStates(Collections.singleton("SLAVE"));
builder.addJob("JOB", jobBuilder);
_driver.start(builder.build());
Thread.sleep(2000L);
JobContext jobContext =
_driver.getJobContext(TaskUtil.getNamespacedJobName(workflowName, "JOB"));
Assert.assertEquals(jobContext.getPartitionState(0), null);
Assert.assertEquals(jobContext.getPartitionState(1), TaskPartitionState.COMPLETED);
Assert.assertEquals(jobContext.getPartitionState(2), null);
}
示例9: 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;
}
示例10: 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);
}
示例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: testLoadFileSet
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
@Test
@PrepareForTest({ControllerUtil.class})
public void testLoadFileSet() throws Exception {
PowerMockito.mockStatic(ControllerUtil.class);
TerrapinLoadRequest request =
new TerrapinLoadRequest("fileset", "/terrapin/data/fileset/12345564534", 200);
Options requestOptions = new Options();
requestOptions.setNumVersionsToKeep(2);
request.setOptions(requestOptions);
FileSetInfo fileSetInfo = new FileSetInfo(
request.getFileSet(), "/terrapin/data/fileset/12345563434",
request.getExpectedNumPartitions(),
Lists.newArrayList(mock(FileSetInfo.ServingInfo.class)), new Options()
);
String resourceName = TerrapinUtil.hdfsDirToHelixResource(request.getHdfsDirectory());
CustomModeISBuilder idealStateBuilder = new CustomModeISBuilder(resourceName);
idealStateBuilder.assignInstanceAndState(resourceName + "$0", "host0", "ONLINE");
idealStateBuilder.assignInstanceAndState(resourceName + "$1", "host1", "ONLINE");
idealStateBuilder.setStateModel("OnlineOffline");
idealStateBuilder.setNumReplica(2);
idealStateBuilder.setNumPartitions(request.getExpectedNumPartitions());
IdealState is = idealStateBuilder.build();
is.setBucketSize(2);
is.setRebalanceMode(IdealState.RebalanceMode.CUSTOMIZED);
ViewInfo viewInfo1 = mock(ViewInfo.class);
ViewInfo viewInfo2 = mock(ViewInfo.class);
when(configuration.getInt(eq(Constants.NUM_SERVING_REPLICAS), eq(3))).thenReturn(3);
when(zkManager.getFileSetInfo(eq(request.getFileSet()))).thenReturn(fileSetInfo);
when(zkManager.getViewInfo(eq(resourceName))).thenReturn(viewInfo1).thenReturn(viewInfo2);
doNothing().when(zkManager).setFileSetInfo(eq(request.getFileSet()), any(FileSetInfo.class));
when(viewInfo1.getNumOnlinePartitions()).thenReturn(request.getExpectedNumPartitions() / 2);
when(viewInfo2.getNumOnlinePartitions()).thenReturn(request.getExpectedNumPartitions());
when(helixAdmin.getResourcesInCluster(CLUSTER)).thenReturn(new ArrayList<String>());
when(ControllerUtil.buildIdealStateForHdfsDir(any(DFSClient.class),
anyString(), anyString(), any(PartitionerType.class), anyInt(), anyBoolean())).
thenReturn(is);
doNothing().when(helixAdmin).addResource(eq(CLUSTER), eq(resourceName), eq(is));
doNothing().when(helixAdmin).addResource(eq(CLUSTER), eq(resourceName),
eq(is.getNumPartitions()), eq("OnlineOffline"), eq("CUSTOMIZED"), eq(is.getBucketSize()));
doNothing().when(helixAdmin).setResourceIdealState(eq(CLUSTER), eq(resourceName), eq(is));
serviceImpl.loadFileSet(request).apply();
ArgumentCaptor<FileSetInfo> fileSetInfoCaptor = ArgumentCaptor.forClass(FileSetInfo.class);
verify(zkManager).setFileSetInfo(eq(request.getFileSet()), fileSetInfoCaptor.capture());
FileSetInfo capturedInfo = fileSetInfoCaptor.getValue();
assertEquals(request.getFileSet(), capturedInfo.fileSetName);
assertEquals(request.getExpectedNumPartitions(), capturedInfo.servingInfo.numPartitions);
assertEquals(Lists.newArrayList(fileSetInfo.servingInfo),
(ArrayList)capturedInfo.oldServingInfoList);
}
示例13: 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;
}
示例14: testListenerOnBucketizedResource
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
@Test
public void testListenerOnBucketizedResource() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
String dbName = "TestDB0";
List<String> instanceNames =
Arrays.asList("localhost_0", "localhost_1", "localhost_2", "localhost_3", "localhost_4");
int n = instanceNames.size();
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, _baseAccessor);
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
setupCluster(clusterName, instanceNames, dbName, 3, 10, 2);
// start controller
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName);
controller.syncStart();
// start participants
MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceNames.get(i));
participants[i].syncStart();
}
HelixClusterVerifier _clusterVerifier =
new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).build();
Assert.assertTrue(_clusterVerifier.verify());
// add an external view listener
TestExternalViewListener listener = new TestExternalViewListener();
controller.addExternalViewChangeListener(listener);
// remove "TestDB0"
_gSetupTool.dropResourceFromCluster(clusterName, dbName);
Assert.assertTrue(_clusterVerifier.verify());
// wait callback to finish
int waitTime =0;
do {
Thread.sleep(100);
waitTime += 100;
if (waitTime > 30000) {
break;
}
} while (listener.cbCnt == 0);
listener.cbCnt = 0;
// add a new db
String newDbName = "TestDB1";
int r = 3;
ZNRecord idealStateRec =
DefaultIdealStateCalculator.calculateIdealState(instanceNames, 10, r - 1, newDbName,
"MASTER", "SLAVE");
IdealState idealState = new IdealState(idealStateRec);
idealState.setBucketSize(2);
idealState.setStateModelDefRef("MasterSlave");
idealState.setRebalanceMode(IdealState.RebalanceMode.CUSTOMIZED);
idealState.setReplicas(Integer.toString(r));
accessor.setProperty(keyBuilder.idealStates(newDbName), idealState);
Assert.assertTrue(_clusterVerifier.verify());
Thread.sleep(200);
Assert.assertTrue(listener.cbCnt > 0);
// clean up
controller.syncStop();
for (MockParticipantManager participant : participants) {
participant.syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
示例15: missingEVPartitionPushTest
import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
@Test
public void missingEVPartitionPushTest() throws Exception {
final String tableName = "myTable_OFFLINE";
List<String> allTableNames = new ArrayList<String>();
allTableNames.add(tableName);
IdealState idealState = new IdealState(tableName);
idealState.setPartitionState("myTable_0", "pinot1", "ONLINE");
idealState.setPartitionState("myTable_1", "pinot1", "ONLINE");
idealState.setPartitionState("myTable_1", "pinot2", "ONLINE");
idealState.setReplicas("2");
idealState.setRebalanceMode(IdealState.RebalanceMode.CUSTOMIZED);
ExternalView externalView = new ExternalView(tableName);
externalView.setState("myTable_1","pinot1","ONLINE");
externalView.setState("myTable_1","pinot2","ONLINE");
HelixAdmin helixAdmin;
{
helixAdmin = mock(HelixAdmin.class);
when(helixAdmin.getResourceIdealState("StatusChecker","myTable_OFFLINE")).thenReturn(idealState);
when(helixAdmin.getResourceExternalView("StatusChecker","myTable_OFFLINE")).thenReturn(externalView);
}
ZNRecord znrecord = new ZNRecord("myTable_0");
znrecord.setSimpleField(CommonConstants.Segment.SEGMENT_NAME,"myTable_0");
znrecord.setSimpleField(CommonConstants.Segment.TABLE_NAME, "myTable_OFFLINE");
znrecord.setSimpleField(CommonConstants.Segment.INDEX_VERSION, "v1");
znrecord.setEnumField(CommonConstants.Segment.SEGMENT_TYPE, CommonConstants.Segment.SegmentType.OFFLINE);
znrecord.setLongField(CommonConstants.Segment.START_TIME, 1000);
znrecord.setLongField(CommonConstants.Segment.END_TIME, 2000);
znrecord.setSimpleField(CommonConstants.Segment.TIME_UNIT, TimeUnit.HOURS.toString());
znrecord.setLongField(CommonConstants.Segment.TOTAL_DOCS, 10000);
znrecord.setLongField(CommonConstants.Segment.CRC, 1234);
znrecord.setLongField(CommonConstants.Segment.CREATION_TIME, 3000);
znrecord.setSimpleField(CommonConstants.Segment.Offline.DOWNLOAD_URL, "http://localhost:8000/myTable_0");
znrecord.setLongField(CommonConstants.Segment.Offline.PUSH_TIME, System.currentTimeMillis());
znrecord.setLongField(CommonConstants.Segment.Offline.REFRESH_TIME,System.currentTimeMillis());
ZkHelixPropertyStore<ZNRecord> propertyStore;
{
propertyStore = (ZkHelixPropertyStore<ZNRecord>) mock(ZkHelixPropertyStore.class);
when(propertyStore.get("/SEGMENTS/myTable_OFFLINE/myTable_0",null, AccessOption.PERSISTENT)).thenReturn(znrecord);
}
{
helixResourceManager = mock(PinotHelixResourceManager.class);
when(helixResourceManager.isLeader()).thenReturn(true);
when(helixResourceManager.getAllTables()).thenReturn(allTableNames);
when(helixResourceManager.getHelixClusterName()).thenReturn("StatusChecker");
when(helixResourceManager.getHelixAdmin()).thenReturn(helixAdmin);
when(helixResourceManager.getPropertyStore()).thenReturn(propertyStore);
}
{
config = mock(ControllerConf.class);
when(config.getStatusCheckerFrequencyInSeconds()).thenReturn(300);
when(config.getStatusCheckerWaitForPushTimeInSeconds()).thenReturn(300);
}
metricsRegistry = new MetricsRegistry();
controllerMetrics = new ControllerMetrics(metricsRegistry);
segmentStatusChecker = new SegmentStatusChecker(helixResourceManager, config);
segmentStatusChecker.setMetricsRegistry(controllerMetrics);
segmentStatusChecker.runSegmentMetrics();
Assert.assertEquals(controllerMetrics.getValueOfTableGauge(externalView.getId(),
ControllerGauge.SEGMENTS_IN_ERROR_STATE), 0);
Assert.assertEquals(controllerMetrics.getValueOfTableGauge(externalView.getId(),
ControllerGauge.NUMBER_OF_REPLICAS), 2);
Assert.assertEquals(controllerMetrics.getValueOfTableGauge(externalView.getId(),
ControllerGauge.PERCENT_OF_REPLICAS), 100);
Assert.assertEquals(controllerMetrics.getValueOfTableGauge(externalView.getId(),
ControllerGauge.PERCENT_SEGMENTS_AVAILABLE), 100);
segmentStatusChecker.stop();
}