use of org.apache.helix.model.CustomizedState in project helix by apache.
the class TestCustomizedStateUpdate method beforeMethod.
@BeforeMethod
public void beforeMethod() {
_dataAccessor.removeProperty(_propertyKey);
CustomizedState customizedStates = _dataAccessor.getProperty(_propertyKey);
Assert.assertNull(customizedStates);
}
use of org.apache.helix.model.CustomizedState in project helix by apache.
the class CustomizedStateProvider method deletePerPartitionCustomizedState.
/**
* Delete the customized state for a specified resource and a specified partition
*/
public void deletePerPartitionCustomizedState(String customizedStateName, String resourceName, String partitionName) {
HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
PropertyKey propertyKey = keyBuilder.customizedState(_instanceName, customizedStateName, resourceName);
CustomizedState existingState = getCustomizedState(customizedStateName, resourceName);
ZNRecord rec = new ZNRecord(existingState.getId());
rec.getMapFields().put(partitionName, null);
ZNRecordDelta delta = new ZNRecordDelta(rec, ZNRecordDelta.MergeOperation.SUBTRACT);
List<ZNRecordDelta> deltaList = new ArrayList<ZNRecordDelta>();
deltaList.add(delta);
existingState.setDeltaList(deltaList);
if (!accessor.updateProperty(propertyKey, existingState)) {
throw new HelixException(String.format("Failed to delete customized state %s to zk for instance %s, resource %s, " + "partition %s", customizedStateName, _instanceName, resourceName, partitionName));
}
}
use of org.apache.helix.model.CustomizedState in project helix by apache.
the class CustomizedStateProvider method getCustomizedState.
/**
* Get the customized state for a specified resource
*/
public CustomizedState getCustomizedState(String customizedStateName, String resourceName) {
HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
return (CustomizedState) accessor.getProperty(keyBuilder.customizedState(_instanceName, customizedStateName, resourceName));
}
use of org.apache.helix.model.CustomizedState in project helix by apache.
the class CallbackHandler method invoke.
public void invoke(NotificationContext changeContext) throws Exception {
Type type = changeContext.getType();
long start = System.currentTimeMillis();
if (logger.isInfoEnabled()) {
logger.info("{} START: CallbackHandler {}, INVOKE {} listener: {} type: {}", Thread.currentThread().getId(), _uid, _path, _listener, type);
}
synchronized (this) {
if (!_expectTypes.contains(type)) {
logger.warn("Callback handler {} received event in wrong order. Listener: {}, path: {}, " + "expected types: {}, but was {}", _uid, _listener, _path, _expectTypes, type);
return;
}
_expectTypes = nextNotificationType.get(type);
if (type == Type.INIT || type == Type.FINALIZE || changeContext.getIsChildChange()) {
subscribeForChanges(changeContext.getType(), _path, _watchChild);
}
}
// potential improvement candidate.
synchronized (_manager) {
if (_changeType == IDEAL_STATE) {
IdealStateChangeListener idealStateChangeListener = (IdealStateChangeListener) _listener;
List<IdealState> idealStates = preFetch(_propertyKey);
idealStateChangeListener.onIdealStateChange(idealStates, changeContext);
} else if (_changeType == INSTANCE_CONFIG) {
if (_listener instanceof ConfigChangeListener) {
ConfigChangeListener configChangeListener = (ConfigChangeListener) _listener;
List<InstanceConfig> configs = preFetch(_propertyKey);
configChangeListener.onConfigChange(configs, changeContext);
} else if (_listener instanceof InstanceConfigChangeListener) {
InstanceConfigChangeListener listener = (InstanceConfigChangeListener) _listener;
List<InstanceConfig> configs = preFetch(_propertyKey);
listener.onInstanceConfigChange(configs, changeContext);
}
} else if (_changeType == RESOURCE_CONFIG) {
ResourceConfigChangeListener listener = (ResourceConfigChangeListener) _listener;
List<ResourceConfig> configs = preFetch(_propertyKey);
listener.onResourceConfigChange(configs, changeContext);
} else if (_changeType == CUSTOMIZED_STATE_CONFIG) {
CustomizedStateConfigChangeListener listener = (CustomizedStateConfigChangeListener) _listener;
CustomizedStateConfig config = null;
if (_preFetchEnabled) {
config = _accessor.getProperty(_propertyKey);
}
listener.onCustomizedStateConfigChange(config, changeContext);
} else if (_changeType == CLUSTER_CONFIG) {
ClusterConfigChangeListener listener = (ClusterConfigChangeListener) _listener;
ClusterConfig config = null;
if (_preFetchEnabled) {
config = _accessor.getProperty(_propertyKey);
}
listener.onClusterConfigChange(config, changeContext);
} else if (_changeType == CONFIG) {
ScopedConfigChangeListener listener = (ScopedConfigChangeListener) _listener;
List<HelixProperty> configs = preFetch(_propertyKey);
listener.onConfigChange(configs, changeContext);
} else if (_changeType == LIVE_INSTANCE) {
LiveInstanceChangeListener liveInstanceChangeListener = (LiveInstanceChangeListener) _listener;
List<LiveInstance> liveInstances = preFetch(_propertyKey);
liveInstanceChangeListener.onLiveInstanceChange(liveInstances, changeContext);
} else if (_changeType == CURRENT_STATE) {
CurrentStateChangeListener currentStateChangeListener = (CurrentStateChangeListener) _listener;
String instanceName = PropertyPathConfig.getInstanceNameFromPath(_path);
List<CurrentState> currentStates = preFetch(_propertyKey);
currentStateChangeListener.onStateChange(instanceName, currentStates, changeContext);
} else if (_changeType == TASK_CURRENT_STATE) {
TaskCurrentStateChangeListener taskCurrentStateChangeListener = (TaskCurrentStateChangeListener) _listener;
String instanceName = PropertyPathConfig.getInstanceNameFromPath(_path);
List<CurrentState> currentStates = preFetch(_propertyKey);
taskCurrentStateChangeListener.onTaskCurrentStateChange(instanceName, currentStates, changeContext);
} else if (_changeType == CUSTOMIZED_STATE_ROOT) {
CustomizedStateRootChangeListener customizedStateRootChangeListener = (CustomizedStateRootChangeListener) _listener;
String instanceName = PropertyPathConfig.getInstanceNameFromPath(_path);
List<String> customizedStateTypes = new ArrayList<>();
if (_preFetchEnabled) {
customizedStateTypes = _accessor.getChildNames(_accessor.keyBuilder().customizedStatesRoot(instanceName));
}
customizedStateRootChangeListener.onCustomizedStateRootChange(instanceName, customizedStateTypes, changeContext);
} else if (_changeType == CUSTOMIZED_STATE) {
CustomizedStateChangeListener customizedStateChangeListener = (CustomizedStateChangeListener) _listener;
String instanceName = PropertyPathConfig.getInstanceNameFromPath(_path);
List<CustomizedState> customizedStates = preFetch(_propertyKey);
customizedStateChangeListener.onCustomizedStateChange(instanceName, customizedStates, changeContext);
} else if (_changeType == MESSAGE) {
MessageListener messageListener = (MessageListener) _listener;
String instanceName = PropertyPathConfig.getInstanceNameFromPath(_path);
List<Message> messages = preFetch(_propertyKey);
messageListener.onMessage(instanceName, messages, changeContext);
} else if (_changeType == MESSAGES_CONTROLLER) {
MessageListener messageListener = (MessageListener) _listener;
List<Message> messages = preFetch(_propertyKey);
messageListener.onMessage(_manager.getInstanceName(), messages, changeContext);
} else if (_changeType == EXTERNAL_VIEW || _changeType == TARGET_EXTERNAL_VIEW) {
ExternalViewChangeListener externalViewListener = (ExternalViewChangeListener) _listener;
List<ExternalView> externalViewList = preFetch(_propertyKey);
externalViewListener.onExternalViewChange(externalViewList, changeContext);
} else if (_changeType == CUSTOMIZED_VIEW_ROOT) {
CustomizedViewRootChangeListener customizedViewRootChangeListener = (CustomizedViewRootChangeListener) _listener;
List<String> customizedViewTypes = new ArrayList<>();
if (_preFetchEnabled) {
customizedViewTypes = _accessor.getChildNames(_accessor.keyBuilder().customizedViews());
}
customizedViewRootChangeListener.onCustomizedViewRootChange(customizedViewTypes, changeContext);
} else if (_changeType == CUSTOMIZED_VIEW) {
CustomizedViewChangeListener customizedViewListener = (CustomizedViewChangeListener) _listener;
List<CustomizedView> customizedViewListList = preFetch(_propertyKey);
customizedViewListener.onCustomizedViewChange(customizedViewListList, changeContext);
} else if (_changeType == CONTROLLER) {
ControllerChangeListener controllerChangelistener = (ControllerChangeListener) _listener;
controllerChangelistener.onControllerChange(changeContext);
} else {
logger.warn("Callbackhandler {}, Unknown change type: {}", _uid, _changeType);
}
long end = System.currentTimeMillis();
if (logger.isInfoEnabled()) {
logger.info("{} END:INVOKE CallbackHandler {}, {} listener: {} type: {} Took: {}ms", Thread.currentThread().getId(), _uid, _path, _listener, type, (end - start));
}
if (_monitor != null) {
_monitor.increaseCallbackCounters(end - start);
}
}
}
use of org.apache.helix.model.CustomizedState in project helix by apache.
the class TestCustomizedViewStage method testLatencyCalculationWithEmptyTimestamp.
@Test
public void testLatencyCalculationWithEmptyTimestamp() throws Exception {
String clusterName = "CLUSTER_" + TestHelper.getTestMethodName();
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<>(_gZkClient));
HelixManager manager = new DummyClusterManager(clusterName, accessor);
setupIdealState(clusterName, new int[] { 0, 1 }, new String[] { "TestDB" }, 1, 2);
setupLiveInstances(clusterName, new int[] { 0, 1 });
setupStateModel(clusterName);
ClusterStatusMonitor clusterStatusMonitor = new ClusterStatusMonitor(clusterName);
ClusterEvent event = new ClusterEvent(clusterName, ClusterEventType.Unknown);
ResourceControllerDataProvider cache = new ResourceControllerDataProvider(clusterName);
ExecutorService executor = Executors.newSingleThreadExecutor();
cache.setAsyncTasksThreadPool(executor);
event.addAttribute(AttributeName.helixmanager.name(), manager);
event.addAttribute(AttributeName.ControllerDataProvider.name(), cache);
event.addAttribute(AttributeName.clusterStatusMonitor.name(), clusterStatusMonitor);
CustomizedStateConfig config = new CustomizedStateConfig();
List<String> aggregationEnabledTypes = new ArrayList<>();
aggregationEnabledTypes.add(CUSTOMIZED_STATE_NAME);
config.setAggregationEnabledTypes(aggregationEnabledTypes);
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.customizedStateConfig(), config);
CustomizedState customizedState = new CustomizedState(RESOURCE_NAME);
customizedState.setState(PARTITION_NAME, "STATE");
accessor.setProperty(keyBuilder.customizedState(INSTANCE_NAME, CUSTOMIZED_STATE_NAME, RESOURCE_NAME), customizedState);
Pipeline dataRefresh = new Pipeline();
dataRefresh.addStage(new ReadClusterDataStage());
runPipeline(event, dataRefresh, false);
runStage(event, new ResourceComputationStage());
runStage(event, new CustomizedStateComputationStage());
runStage(event, new CustomizedViewAggregationStage());
ObjectName objectName = new ObjectName(String.format("%s:%s=%s,%s=%s", MonitorDomainNames.AggregatedView.name(), "Type", "CustomizedView", "Cluster", clusterName));
Field customizedViewMonitor = ClusterStatusMonitor.class.getDeclaredField("_customizedViewMonitor");
Assert.assertNotNull(customizedViewMonitor);
boolean hasLatencyReported = TestHelper.verify(() -> (long) _server.getAttribute(objectName, CustomizedViewMonitor.UPDATE_TO_AGGREGATION_LATENCY_GAUGE + ".Max") != 0, TestHelper.WAIT_DURATION);
Assert.assertFalse(hasLatencyReported);
deleteLiveInstances(clusterName);
deleteCluster(clusterName);
executor.shutdownNow();
}
Aggregations