-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
377 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
...src/main/java/org/apache/helix/rest/common/dataprovider/HelixRestDataProviderManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.apache.helix.rest.common.dataprovider; | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
|
||
/** Init, register listener and manager callback handler for different | ||
* clusters manage the providers lifecycle | ||
* | ||
*/ | ||
|
||
import java.util.List; | ||
import org.apache.helix.HelixAdmin; | ||
import org.apache.helix.manager.zk.ZkBaseDataAccessor; | ||
import org.apache.helix.zookeeper.api.client.RealmAwareZkClient; | ||
|
||
|
||
public class HelixRestDataProviderManager { | ||
|
||
protected RealmAwareZkClient _zkclient; | ||
|
||
private HelixAdmin _helixAdmin; | ||
|
||
private RestServiceDataProvider _restServiceDataProvider; | ||
// list of callback handlers | ||
|
||
//TODO: create own zk client | ||
public HelixRestDataProviderManager(RealmAwareZkClient zkclient, HelixAdmin helixAdmin) { | ||
_zkclient = zkclient; | ||
_helixAdmin = helixAdmin; | ||
_restServiceDataProvider = new RestServiceDataProvider(); | ||
init(); | ||
} | ||
|
||
public RestServiceDataProvider getRestServiceDataProvider() { | ||
return _restServiceDataProvider; | ||
} | ||
|
||
private void init() { | ||
List<String> clusters = _helixAdmin.getClusters(); | ||
for (String cluster : clusters) { | ||
PerClusterDataProvider clusterDataProvider = | ||
new PerClusterDataProvider(cluster, _zkclient, new ZkBaseDataAccessor(_zkclient)); | ||
clusterDataProvider.initCache(); | ||
// register callback handler for each provider | ||
_restServiceDataProvider.addClusterDataProvider(cluster, clusterDataProvider); | ||
} | ||
} | ||
|
||
public void close() { | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
...-rest/src/main/java/org/apache/helix/rest/common/dataprovider/PerClusterDataProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package org.apache.helix.rest.common.dataprovider; | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import java.util.Map; | ||
import org.apache.helix.BaseDataAccessor; | ||
import org.apache.helix.HelixDataAccessor; | ||
import org.apache.helix.PropertyKey; | ||
import org.apache.helix.common.caches.PropertyCache; | ||
import org.apache.helix.manager.zk.ZKHelixDataAccessor; | ||
import org.apache.helix.model.ClusterConfig; | ||
import org.apache.helix.model.ClusterConstraints; | ||
import org.apache.helix.model.CurrentState; | ||
import org.apache.helix.model.ExternalView; | ||
import org.apache.helix.model.IdealState; | ||
import org.apache.helix.model.InstanceConfig; | ||
import org.apache.helix.model.LiveInstance; | ||
import org.apache.helix.model.ResourceConfig; | ||
import org.apache.helix.model.StateModelDefinition; | ||
import org.apache.helix.zookeeper.api.client.RealmAwareZkClient; | ||
|
||
|
||
/** | ||
* Dara cache for each Helix cluster. Configs, ideal stats and current states are read from ZK and updated | ||
* using event changes. External view are consolidated using current state. | ||
*/ | ||
public class PerClusterDataProvider { | ||
|
||
private HelixDataAccessor _accessor; | ||
|
||
private RealmAwareZkClient _zkclient; | ||
|
||
private final String _clusterName; | ||
|
||
// Simple caches | ||
private final RestPropertyCache<InstanceConfig> _instanceConfigCache; | ||
private final RestPropertyCache<ClusterConfig> _clusterConfigCache; | ||
private final RestPropertyCache<ResourceConfig> _resourceConfigCache; | ||
private final RestPropertyCache<LiveInstance> _liveInstanceCache; | ||
private final RestPropertyCache<IdealState> _idealStateCache; | ||
private final RestPropertyCache<StateModelDefinition> _stateModelDefinitionCache; | ||
|
||
// special caches | ||
private final RestCurrentStateCache _currentStateCache; | ||
|
||
// TODO: add external view caches | ||
|
||
public PerClusterDataProvider(String clusterName, RealmAwareZkClient zkClient, BaseDataAccessor baseDataAccessor) { | ||
_clusterName = clusterName; | ||
_accessor = new ZKHelixDataAccessor(clusterName, baseDataAccessor); | ||
|
||
_zkclient = zkClient; | ||
_instanceConfigCache = null; | ||
_clusterConfigCache = null; | ||
_resourceConfigCache = null; | ||
_liveInstanceCache = null; | ||
_idealStateCache = null; | ||
_stateModelDefinitionCache = null; | ||
_currentStateCache = null; | ||
} | ||
// TODO: consolidate EV from CSs | ||
public Map<String, ExternalView> consolidateExternalViews() { | ||
return null; | ||
} | ||
|
||
// Used for dummy cache. Remove later | ||
public void initCache(final HelixDataAccessor accessor) { | ||
|
||
} | ||
|
||
public void initCache() { | ||
|
||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...x-rest/src/main/java/org/apache/helix/rest/common/dataprovider/RestCurrentStateCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.apache.helix.rest.common.dataprovider; | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
import org.apache.helix.HelixDataAccessor; | ||
import org.apache.helix.model.CurrentState; | ||
|
||
|
||
/** | ||
* Special cache for instances current states. | ||
* | ||
*/ | ||
public class RestCurrentStateCache { | ||
|
||
//Map<instanceName, Map<ResourceName, CurrentState>> | ||
private ConcurrentHashMap<String, ConcurrentHashMap<String, CurrentState>> _objCache; | ||
|
||
public RestCurrentStateCache() { | ||
_objCache = new ConcurrentHashMap<>(); | ||
} | ||
|
||
public void init(final HelixDataAccessor accessor) { | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/RestPropertyCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.apache.helix.rest.common.dataprovider; | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import org.apache.helix.HelixDataAccessor; | ||
import org.apache.helix.HelixProperty; | ||
import org.apache.helix.PropertyKey; | ||
import org.apache.helix.common.caches.PropertyCache; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
/** | ||
* Class for caching simple HelixProperty objects. | ||
* @param <T> | ||
*/ | ||
public class RestPropertyCache<T extends HelixProperty> { | ||
private static final Logger LOG = LoggerFactory.getLogger(RestPropertyCache.class); | ||
|
||
private ConcurrentHashMap<String, T> _objCache; | ||
private final String _propertyDescription; | ||
|
||
private final RestPropertyCache.PropertyCacheKeyFuncs<T> _keyFuncs; | ||
|
||
public interface PropertyCacheKeyFuncs<O extends HelixProperty> { | ||
/** | ||
* Get PropertyKey for the root of this type of object, used for LIST all objects | ||
* @return property key to object root | ||
*/ | ||
PropertyKey getRootKey(HelixDataAccessor accessor); | ||
|
||
/** | ||
* Get PropertyKey for a single object of this type, used for GET single instance of the type | ||
* @param objName object name | ||
* @return property key to the object instance | ||
*/ | ||
PropertyKey getObjPropertyKey(HelixDataAccessor accessor, String objName); | ||
|
||
/** | ||
* Get the string to identify the object when we actually use them. It's not necessarily the | ||
* "id" field of HelixProperty, but could have more semantic meanings of that object type | ||
* @param obj object instance | ||
* @return object identifier | ||
*/ | ||
String getObjName(O obj); | ||
} | ||
|
||
public RestPropertyCache(String propertyDescription, RestPropertyCache.PropertyCacheKeyFuncs<T> keyFuncs) { | ||
_keyFuncs = keyFuncs; | ||
_propertyDescription = propertyDescription; | ||
} | ||
|
||
public void init(final HelixDataAccessor accessor) { | ||
_objCache = new ConcurrentHashMap<>(accessor.getChildValuesMap(_keyFuncs.getRootKey(accessor), true)); | ||
LOG.info("Init RestPropertyCache for {}. ", _propertyDescription); | ||
} | ||
|
||
public Map<String, T> getPropertyMap() { | ||
return Collections.unmodifiableMap(_objCache); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...rest/src/main/java/org/apache/helix/rest/common/dataprovider/RestServiceDataProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.apache.helix.rest.common.dataprovider; | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
|
||
public class RestServiceDataProvider { | ||
protected Map<String, PerClusterDataProvider> _clusterDataProviders ; | ||
|
||
|
||
public RestServiceDataProvider() { | ||
_clusterDataProviders = new HashMap<>(); | ||
} | ||
|
||
public PerClusterDataProvider getClusterData(String clusterName) { | ||
return _clusterDataProviders.get(clusterName); | ||
} | ||
|
||
public void addClusterDataProvider(String clusterName, PerClusterDataProvider clusterData) { | ||
_clusterDataProviders.put(clusterName, clusterData); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.