jiajunwang commented on a change in pull request #834: Complete the Routing
Table Provider for CustomizedView
URL: https://github.com/apache/helix/pull/834#discussion_r392534479
##########
File path:
helix-core/src/main/java/org/apache/helix/spectator/RoutingTableProvider.java
##########
@@ -376,50 +575,104 @@ public Object removeRoutingTableChangeListener(
* @return
*/
public Collection<LiveInstance> getLiveInstances() {
- return _routingTableRef.get().getLiveInstances();
+ // Since line instances will be the same across all _routingTableRefMap,
here one of the keys
+ // will be used without considering PropertyType
+ String key = null;
+ Iterator<String> iter = _routingTableRefMap.keySet().iterator();
+ if (iter.hasNext()) {
+ key = iter.next();
+ }
+ if (key == null) {
+ throw new HelixException("There is no key available in this
RoutingTableProvider.");
+ }
+ return _routingTableRefMap.get(key).get().getLiveInstances();
}
/**
* Return all instance's config in this cluster.
* @return
*/
public Collection<InstanceConfig> getInstanceConfigs() {
- return _routingTableRef.get().getInstanceConfigs();
+ // Since line instances will be the same across all _routingTableRefMap,
here one of the keys
+ // will be used without considering PropertyType
+ String key = null;
+ Iterator<String> iter = _routingTableRefMap.keySet().iterator();
+ if (iter.hasNext()) {
+ key = iter.next();
+ }
+ if (key == null) {
+ throw new HelixException("There is no key available in this
RoutingTableProvider.");
+ }
+ return _routingTableRefMap.get(key).get().getInstanceConfigs();
}
/**
- * Return names of all resources (shown in ExternalView) in this cluster.
+ * Return names of all resources (shown in ExternalView or CustomizedView)
in this cluster.
*/
public Collection<String> getResources() {
- return _routingTableRef.get().getResources();
+ String key = getRoutingTableKey(DEFAULT_PROPERTY, DEFAULT_TYPE);
+ return _routingTableRefMap.get(key).get().getResources();
+ }
+
+ public Collection<String> getResources(PropertyType propertyType, String
type) {
+ String key = getRoutingTableKey(propertyType.name(), type);
+ return _routingTableRefMap.get(key).get().getResources();
+ }
+
+
+ private String getRoutingTableKey(String propertyTypeName, String
customizedStateType) {
+ if (propertyTypeName.equals(DEFAULT_PROPERTY) &&
customizedStateType.equals(DEFAULT_TYPE)) {
+ // Check whether there exist only one snapshot (_routingTableRefMap)
+ if (_routingTableRefMap.keySet().size() == 1) {
+ return _routingTableRefMap.keySet().iterator().next();
+ } else {
+ throw new HelixException("There is none or more than one
RoutingTableSnapshot");
+ }
+ }
+
+ if (!propertyTypeName.equals(DEFAULT_PROPERTY) &&
customizedStateType.equals(DEFAULT_TYPE)) {
+ if (propertyTypeName.equals(PropertyType.CUSTOMIZEDVIEW.name())) {
+ throw new HelixException("Specific type needs to be used for
CUSTOMIZEDVIEW PropertyType");
+ }
+ }
+
+ String key = propertyTypeName + "_" + customizedStateType;
+ if (!_routingTableRefMap.containsKey(key)) {
+ throw new HelixException(
+ String.format("Currently there is no snapshot available for
PropertyType %s and type %s",
+ propertyTypeName, customizedStateType));
+ }
+ return key;
+
}
@Override
@PreFetch(enabled = false)
public void onExternalViewChange(List<ExternalView> externalViewList,
NotificationContext changeContext) {
HelixConstants.ChangeType changeType = changeContext.getChangeType();
- if (changeType != null &&
!changeType.getPropertyType().equals(_sourceDataType)) {
+ if (changeType != null &&
!_sourceDataTypeMap.containsKey(changeType.getPropertyType())) {
logger.warn(
- "onExternalViewChange called with mismatched change types. Source
data type {}, changed data type: {}",
- _sourceDataType, changeType);
+ "onExternalViewChange called with mismatched change types. Source
data types does not contain changed data type: {}",
+ changeType);
return;
}
// Refresh with full list of external view.
if (externalViewList != null && externalViewList.size() > 0) {
// keep this here for back-compatibility, application can call
onExternalViewChange directly
// with externalview list supplied.
- refresh(externalViewList, changeContext);
+ String keyReference = PropertyType.EXTERNALVIEW.name() + "_" +
DEFAULT_TYPE;
Review comment:
This formula is better to be done in a private method. Otherwise, if you
want to replace "_", it would be a headache.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]