-
Notifications
You must be signed in to change notification settings - Fork 245
Add CloudConfig operations #589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
25 changes: 25 additions & 0 deletions
25
helix-core/src/main/java/org/apache/helix/cloud/constants/CloudProvider.java
This file contains hidden or 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,25 @@ | ||
| package org.apache.helix.cloud.constants; | ||
|
|
||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| public enum CloudProvider { | ||
| AZURE, | ||
| CUSTOMIZED | ||
| } |
290 changes: 290 additions & 0 deletions
290
helix-core/src/main/java/org/apache/helix/model/CloudConfig.java
This file contains hidden or 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,290 @@ | ||
| package org.apache.helix.model; | ||
|
|
||
| /* | ||
| * 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.ArrayList; | ||
| import java.util.List; | ||
| import org.apache.helix.HelixException; | ||
| import org.apache.helix.HelixProperty; | ||
| import org.apache.helix.ZNRecord; | ||
| import org.apache.helix.cloud.constants.CloudProvider; | ||
|
|
||
| /** | ||
| * Cloud configurations | ||
| */ | ||
| public class CloudConfig extends HelixProperty { | ||
| /** | ||
| * Configurable characteristics of a cloud. | ||
| * NOTE: Do NOT use this field name directly, use its corresponding getter/setter in the | ||
| * CloudConfig. | ||
| */ | ||
| public enum CloudConfigProperty { | ||
| CLOUD_ENABLED, // determine whether the cluster is inside cloud environment. | ||
| CLOUD_PROVIDER, // the environment the cluster is in, e.g. Azure, AWS, or Customized | ||
| CLOUD_ID, // the cloud Id that belongs to this cluster. | ||
|
|
||
| // If user uses Helix supported default provider, the below entries will not be shown in | ||
| // CloudConfig. | ||
| CLOUD_INFO_SOURCE, // the source for retrieving the cloud information. | ||
alirezazamani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| CLOUD_INFO_PROCESSOR_NAME // the name of the function that processes the fetching and parsing of | ||
| // cloud information. | ||
| } | ||
|
|
||
| /* Default values */ | ||
| private static final boolean DEFAULT_CLOUD_ENABLED = false; | ||
|
|
||
| /** | ||
| * Instantiate the CloudConfig for the cloud | ||
| * @param cluster | ||
| */ | ||
| public CloudConfig(String cluster) { | ||
alirezazamani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| super(cluster); | ||
| } | ||
|
|
||
| /** | ||
| * Instantiate with a pre-populated record | ||
| * @param record a ZNRecord corresponding to a cloud configuration | ||
| */ | ||
| public CloudConfig(ZNRecord record) { | ||
| super(record); | ||
| } | ||
|
|
||
| /** | ||
| * Instantiate the config using each field individually. | ||
alirezazamani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * Users should use CloudConfig.Builder to create CloudConfig. | ||
| * @param cluster | ||
| * @param enabled | ||
| * @param cloudID | ||
| */ | ||
| public CloudConfig(String cluster, boolean enabled, CloudProvider cloudProvider, String cloudID, | ||
| List<String> cloudInfoSource, String cloudProcessorName) { | ||
| super(cluster); | ||
| _record.setBooleanField(CloudConfigProperty.CLOUD_ENABLED.name(), enabled); | ||
| _record.setSimpleField(CloudConfigProperty.CLOUD_PROVIDER.name(), cloudProvider.name()); | ||
| _record.setSimpleField(CloudConfigProperty.CLOUD_ID.name(), cloudID); | ||
| if (cloudProvider.equals(CloudProvider.CUSTOMIZED)) { | ||
| _record | ||
| .setSimpleField(CloudConfigProperty.CLOUD_INFO_PROCESSOR_NAME.name(), cloudProcessorName); | ||
| _record.setListField(CloudConfigProperty.CLOUD_INFO_SOURCE.name(), cloudInfoSource); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Enable/Disable the CLOUD_ENABLED field. | ||
| * @param enabled | ||
| */ | ||
| public void setCloudEnabled(boolean enabled) { | ||
| _record.setBooleanField(CloudConfigProperty.CLOUD_ENABLED.name(), enabled); | ||
| } | ||
|
|
||
| /** | ||
| * Whether CLOUD_ENABLED field is enabled or not. | ||
| * @return | ||
| */ | ||
| public boolean isCloudEnabled() { | ||
| return _record.getBooleanField(CloudConfigProperty.CLOUD_ENABLED.name(), false); | ||
| } | ||
|
|
||
| /** | ||
| * Set the cloudID field. | ||
| * @param cloudID | ||
| */ | ||
| public void setCloudID(String cloudID) { | ||
| _record.setSimpleField(CloudConfigProperty.CLOUD_ID.name(), cloudID); | ||
| } | ||
|
|
||
| /** | ||
| * Get the CloudID field. | ||
| * @return CloudID | ||
| */ | ||
| public String getCloudID() { | ||
| return _record.getSimpleField(CloudConfigProperty.CLOUD_ID.name()); | ||
| } | ||
|
|
||
| /** | ||
| * Set the CLOUD_INFO_SOURCE field. | ||
| * @param cloudInfoSources | ||
| */ | ||
| public void setCloudInfoSource(List<String> cloudInfoSources) { | ||
| _record.setListField(CloudConfigProperty.CLOUD_INFO_SOURCE.name(), cloudInfoSources); | ||
| } | ||
|
|
||
| /** | ||
| * Get the CLOUD_INFO_SOURCE field. | ||
| * @return CLOUD_INFO_SOURCE field. | ||
| */ | ||
| public List<String> getCloudInfoSources() { | ||
| return _record.getListField(CloudConfigProperty.CLOUD_INFO_SOURCE.name()); | ||
| } | ||
|
|
||
| /** | ||
| * Set the CLOUD_INFO_PROCESSOR_NAME field. | ||
| * @param cloudInfoProcessorName | ||
| */ | ||
| public void setCloudInfoFProcessorName(String cloudInfoProcessorName) { | ||
| _record.setSimpleField(CloudConfigProperty.CLOUD_INFO_PROCESSOR_NAME.name(), | ||
| cloudInfoProcessorName); | ||
| } | ||
|
|
||
| /** | ||
| * Get the CLOUD_INFO_PROCESSOR_NAME field. | ||
| * @return CLOUD_INFO_PROCESSOR_NAME field. | ||
| */ | ||
| public String getCloudInfoProcessorName() { | ||
| return _record.getSimpleField(CloudConfigProperty.CLOUD_INFO_PROCESSOR_NAME.name()); | ||
| } | ||
|
|
||
| /** | ||
| * Set the CLOUD_PROVIDER field. | ||
| * @param cloudProvider | ||
| */ | ||
| public void setCloudProvider(CloudProvider cloudProvider) { | ||
| _record.setSimpleField(CloudConfigProperty.CLOUD_PROVIDER.name(), cloudProvider.name()); | ||
| } | ||
|
|
||
| /** | ||
| * Get the CLOUD_PROVIDER field. | ||
| * @return CLOUD_PROVIDER field. | ||
| */ | ||
| public String getCloudProvider() { | ||
| return _record.getSimpleField(CloudConfigProperty.CLOUD_PROVIDER.name()); | ||
| } | ||
|
|
||
| public static class Builder { | ||
| private String _clusterName = null; | ||
| private CloudProvider _cloudProvider; | ||
| private boolean _cloudEnabled = DEFAULT_CLOUD_ENABLED; | ||
| private String _cloudID; | ||
| private List<String> _cloudInfoSources; | ||
| private String _cloudInfoProcessorName; | ||
|
|
||
| public CloudConfig build() { | ||
| validate(); | ||
| return new CloudConfig(_clusterName, _cloudEnabled, _cloudProvider, _cloudID, | ||
| _cloudInfoSources, _cloudInfoProcessorName); | ||
| } | ||
|
|
||
| /** | ||
| * Default constructor | ||
| */ | ||
| public Builder() { | ||
| } | ||
|
|
||
| /** | ||
| * Constructor with Cluster Name as input | ||
| * @param clusterName | ||
| */ | ||
| public Builder(String clusterName) { | ||
| _clusterName = clusterName; | ||
| } | ||
|
|
||
| /** | ||
| * Constructor with CloudConfig as input | ||
| * @param cloudConfig | ||
| */ | ||
| public Builder(CloudConfig cloudConfig) { | ||
| _cloudEnabled = cloudConfig.isCloudEnabled(); | ||
| _cloudProvider = CloudProvider.valueOf(cloudConfig.getCloudProvider()); | ||
| _cloudID = cloudConfig.getCloudID(); | ||
| _cloudInfoSources = cloudConfig.getCloudInfoSources(); | ||
| _cloudInfoProcessorName = cloudConfig.getCloudInfoProcessorName(); | ||
| } | ||
|
|
||
| public Builder setClusterName(String v) { | ||
| _clusterName = v; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setCloudEnabled(boolean isEnabled) { | ||
| _cloudEnabled = isEnabled; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setCloudProvider(CloudProvider cloudProvider) { | ||
| _cloudProvider = cloudProvider; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setCloudID(String v) { | ||
| _cloudID = v; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setCloudInfoSources(List<String> v) { | ||
| _cloudInfoSources = v; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder addCloudInfoSource(String v) { | ||
| if (_cloudInfoSources == null) { | ||
| _cloudInfoSources = new ArrayList<String>(); | ||
| } | ||
| _cloudInfoSources.add(v); | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setCloudInfoProcessorName(String v) { | ||
| _cloudInfoProcessorName = v; | ||
| return this; | ||
| } | ||
|
|
||
| public String getClusterName() { | ||
| return _clusterName; | ||
| } | ||
|
|
||
| public CloudProvider getCloudProvider() { | ||
| return _cloudProvider; | ||
| } | ||
|
|
||
| public boolean getCloudEnabled() { | ||
| return _cloudEnabled; | ||
| } | ||
|
|
||
| public String getCloudID() { | ||
| return _cloudID; | ||
| } | ||
|
|
||
| public List<String> getCloudInfoSources() { | ||
| return _cloudInfoSources; | ||
| } | ||
|
|
||
| public String getCloudInfoProcessorName() { | ||
| return _cloudInfoProcessorName; | ||
| } | ||
|
|
||
| private void validate() { | ||
| if (_cloudEnabled) { | ||
alirezazamani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (_cloudID == null) { | ||
| throw new HelixException( | ||
| "This Cloud Configuration is Invalid. The CloudID is missing from the config."); | ||
| } | ||
| if (_cloudProvider == null) { | ||
| throw new HelixException( | ||
| "This Cloud Configuration is Invalid. The Cloud Provider is missing from the config."); | ||
| } else if (_cloudProvider == CloudProvider.CUSTOMIZED) { | ||
| if (_cloudInfoProcessorName == null || _cloudInfoSources == null || _cloudInfoSources.size() == 0) { | ||
| throw new HelixException( | ||
| "This Cloud Configuration is Invalid. CUSTOMIZED provider has been chosen without defining CloudInfoProcessorName or CloudInfoSources"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.