You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by jx...@apache.org on 2020/01/03 18:34:41 UTC
[helix] 02/02: add Helix cloud interface and implementation
skeleton methods
This is an automated email from the ASF dual-hosted git repository.
jxue pushed a commit to branch helix-cloud
in repository https://gitbox.apache.org/repos/asf/helix.git
commit b9a6c54f87071096db1bea8718cf2daac53e9d9c
Author: Meng Zhang <mn...@mnzhang-ld2.linkedin.biz>
AuthorDate: Wed Nov 13 09:43:04 2019 -0800
add Helix cloud interface and implementation skeleton methods
---
.../helix/api/cloud/CloudInstanceInformation.java | 40 +++++++++++
.../cloud/CloudInstanceInformationProcessor.java | 41 ++++++++++++
.../cloud/azure/AzureCloudInstanceInformation.java | 77 ++++++++++++++++++++++
.../AzureCloudInstanceInformationProcessor.java | 56 ++++++++++++++++
4 files changed, 214 insertions(+)
diff --git a/helix-core/src/main/java/org/apache/helix/api/cloud/CloudInstanceInformation.java b/helix-core/src/main/java/org/apache/helix/api/cloud/CloudInstanceInformation.java
new file mode 100644
index 0000000..b2429f9
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/api/cloud/CloudInstanceInformation.java
@@ -0,0 +1,40 @@
+package org.apache.helix.api.cloud;
+
+/*
+ * 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.
+ */
+
+/**
+ * Generic interface for cloud instance information
+ */
+public interface CloudInstanceInformation {
+ /**
+ * Get the the value of a specific cloud instance field by name
+ * @return the value of the field
+ */
+ String get(String key);
+
+ /**
+ * The enum contains all the required cloud instance field in Helix
+ */
+ enum CloudInstanceField {
+ INSTANCE_NAME,
+ FAULT_DOMAIN,
+ INSTANCE_SET_NAME
+ }
+}
diff --git a/helix-core/src/main/java/org/apache/helix/api/cloud/CloudInstanceInformationProcessor.java b/helix-core/src/main/java/org/apache/helix/api/cloud/CloudInstanceInformationProcessor.java
new file mode 100644
index 0000000..a365777
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/api/cloud/CloudInstanceInformationProcessor.java
@@ -0,0 +1,41 @@
+package org.apache.helix.api.cloud;
+
+/*
+ * 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.List;
+
+
+/**
+ * Generic interface to fetch and parse cloud instance information
+ */
+public interface CloudInstanceInformationProcessor<T extends Object> {
+
+ /**
+ * Get the raw cloud instance information
+ * @return raw cloud instance information
+ */
+ List<T> fetchCloudInstanceInformation();
+
+ /**
+ * Parse the raw cloud instance information in responses and compose required cloud instance information
+ * @return required cloud instance information
+ */
+ CloudInstanceInformation parseCloudInstanceInformation(List<T> responses);
+}
diff --git a/helix-core/src/main/java/org/apache/helix/cloud/azure/AzureCloudInstanceInformation.java b/helix-core/src/main/java/org/apache/helix/cloud/azure/AzureCloudInstanceInformation.java
new file mode 100644
index 0000000..511f3e3
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/cloud/azure/AzureCloudInstanceInformation.java
@@ -0,0 +1,77 @@
+package org.apache.helix.cloud.azure;
+
+/*
+ * 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.api.cloud.CloudInstanceInformation;
+
+
+public class AzureCloudInstanceInformation implements CloudInstanceInformation {
+ private Map<String, String> _cloudInstanceInfoMap;
+
+ /**
+ * Instantiate the AzureCloudInstanceInformation using each field individually.
+ * Users should use AzureCloudInstanceInformation.Builder to create information.
+ * @param cloudInstanceInfoMap
+ */
+ protected AzureCloudInstanceInformation(Map<String, String> cloudInstanceInfoMap) {
+ _cloudInstanceInfoMap = cloudInstanceInfoMap;
+ }
+
+ @Override
+ public String get(String key) {
+ return _cloudInstanceInfoMap.get(key);
+ }
+
+ public static class Builder {
+ private Map<String, String> _cloudInstanceInfoMap = null;
+
+ public AzureCloudInstanceInformation build() {
+ return new AzureCloudInstanceInformation(_cloudInstanceInfoMap);
+ }
+
+ /**
+ * Default constructor
+ */
+ public Builder() {
+ }
+
+ public Builder setInstanceName(String v) {
+ _cloudInstanceInfoMap.put(CloudInstanceField.INSTANCE_NAME.name(), v);
+ return this;
+ }
+
+ public Builder setFaultDomain(String v) {
+ _cloudInstanceInfoMap.put(CloudInstanceField.FAULT_DOMAIN.name(), v);
+ return this;
+ }
+
+ public Builder setInstanceSetName(String v) {
+ _cloudInstanceInfoMap.put(CloudInstanceField.INSTANCE_SET_NAME.name(), v);
+ return this;
+ }
+
+ public Builder setCloudInstanceInfoField(String key, String value) {
+ _cloudInstanceInfoMap.put(key, value);
+ return this;
+ }
+ }
+}
\ No newline at end of file
diff --git a/helix-core/src/main/java/org/apache/helix/cloud/azure/AzureCloudInstanceInformationProcessor.java b/helix-core/src/main/java/org/apache/helix/cloud/azure/AzureCloudInstanceInformationProcessor.java
new file mode 100644
index 0000000..84a102c
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/cloud/azure/AzureCloudInstanceInformationProcessor.java
@@ -0,0 +1,56 @@
+package org.apache.helix.cloud.azure;
+
+/*
+ * 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.api.cloud.CloudInstanceInformationProcessor;
+
+
+public class AzureCloudInstanceInformationProcessor implements CloudInstanceInformationProcessor<String> {
+
+ public AzureCloudInstanceInformationProcessor() {
+ }
+
+ /**
+ * fetch the raw Azure cloud instance information
+ * @return raw Azure cloud instance information
+ */
+ @Override
+ public List<String> fetchCloudInstanceInformation() {
+ List<String> response = new ArrayList<>();
+ //TODO: implement the fetching logic
+ return response;
+ }
+
+ /**
+ * Parse raw Azure cloud instance information.
+ * @return required azure cloud instance information
+ */
+ @Override
+ public AzureCloudInstanceInformation parseCloudInstanceInformation(List<String> responses) {
+ AzureCloudInstanceInformation azureCloudInstanceInformation = null;
+ //TODO: implement the parsing logic
+ return azureCloudInstanceInformation;
+ }
+}
+
+