beobal commented on code in PR #3637:
URL: https://github.com/apache/cassandra/pull/3637#discussion_r1818884992


##########
src/java/org/apache/cassandra/locator/AzureCloudLocationProvider.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+
+package org.apache.cassandra.locator;
+
+import java.io.IOException;
+
+import com.google.common.collect.ImmutableMap;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import 
org.apache.cassandra.locator.AbstractCloudMetadataServiceConnector.DefaultCloudMetadataServiceConnector;
+import org.apache.cassandra.tcm.membership.Location;
+import org.apache.cassandra.utils.JsonUtils;
+
+import static java.lang.String.format;
+import static 
org.apache.cassandra.locator.AbstractCloudMetadataServiceConnector.METADATA_URL_PROPERTY;
+
+public class AzureCloudLocationProvider extends CloudMetadataLocationProvider
+{
+    static final String DEFAULT_METADATA_SERVICE_URL = 
"http://169.254.169.254";;
+    static final String METADATA_QUERY_TEMPLATE = 
"/metadata/instance/compute?api-version=%s&format=json";
+    static final String METADATA_HEADER = "Metadata";
+    static final String API_VERSION_PROPERTY_KEY = "azure_api_version";
+    static final String DEFAULT_API_VERSION = "2021-12-13";
+
+    public AzureCloudLocationProvider() throws IOException
+    {
+        this(new SnitchProperties());
+    }
+
+    public AzureCloudLocationProvider(SnitchProperties properties) throws 
IOException
+    {
+        this(new 
DefaultCloudMetadataServiceConnector(properties.putIfAbsent(METADATA_URL_PROPERTY,
+                                                                             
DEFAULT_METADATA_SERVICE_URL)));
+    }
+
+    public AzureCloudLocationProvider(AbstractCloudMetadataServiceConnector 
connector) throws IOException
+    {
+        super(connector, resolveLocation(connector));
+    }
+
+    static Location resolveLocation(AbstractCloudMetadataServiceConnector 
connector) throws IOException
+    {
+        String apiVersion = 
connector.getProperties().get(API_VERSION_PROPERTY_KEY, DEFAULT_API_VERSION);
+        String response = connector.apiCall(format(METADATA_QUERY_TEMPLATE, 
apiVersion),
+                                            ImmutableMap.of(METADATA_HEADER, 
"true"));
+        JsonNode jsonNode = JsonUtils.JSON_OBJECT_MAPPER.readTree(response);
+
+        JsonNode location = jsonNode.get("location");
+        JsonNode zone = jsonNode.get("zone");
+        JsonNode platformFaultDomain = jsonNode.get("platformFaultDomain");
+
+        String datacenter;
+        String rack;
+
+        // TODO should we throw here if _initial_ location cannot be obtained?

Review Comment:
   could we do something similar to `StartupMode::get`? 
   I think `if (hasAnyEpoch && hasBootedBefore)` then we know that the node is 
already registered?
    



-- 
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]

Reply via email to