junkaixue commented on code in PR #2658: URL: https://github.com/apache/helix/pull/2658#discussion_r1481841947
########## helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/PerClusterDataProvider.java: ########## @@ -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; Review Comment: Do we need ResourceConfig cache? ########## helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/PerClusterDataProvider.java: ########## @@ -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; Review Comment: Why not use meta client. ########## helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/HelixRestDataProviderManager.java: ########## @@ -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() { Review Comment: Close should pair with connect / start. Do you want to make it as thread based class? ########## helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/PerClusterDataProvider.java: ########## @@ -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 Review Comment: Typo: Dara -> Data ideal stats -> ideal states ########## helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/HelixRestDataProviderManager.java: ########## @@ -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 + * + */ Review Comment: Wrong place for comments. ########## helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/RestCurrentStateCache.java: ########## @@ -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) { + } +} Review Comment: NIT: extra new line. ########## helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/RestCurrentStateCache.java: ########## @@ -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. Review Comment: Why not CurrentStateCache instead of building its own? ########## helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/RestServiceDataProvider.java: ########## @@ -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 ; Review Comment: make it concurrent? What if remove cluster and read together? ########## helix-rest/src/main/java/org/apache/helix/rest/common/dataprovider/PerClusterDataProvider.java: ########## @@ -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; Review Comment: Do we need this? -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
