You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@gobblin.apache.org by GitBox <gi...@apache.org> on 2020/10/13 02:16:31 UTC

[GitHub] [incubator-gobblin] sv2000 commented on a change in pull request #3124: [GOBBLIN-1061] Add option to only accept requests to leader node and redirect requests in the client

sv2000 commented on a change in pull request #3124:
URL: https://github.com/apache/incubator-gobblin/pull/3124#discussion_r503607306



##########
File path: gobblin-restli/gobblin-flow-config-service/gobblin-flow-config-service-client/src/main/java/org/apache/gobblin/service/FlowConfigClient.java
##########
@@ -104,10 +104,8 @@ public void createFlowConfig(FlowConfig flowConfig)
 
     CreateIdRequest<ComplexResourceKey<FlowId, EmptyRecord>, FlowConfig> request =
         _flowconfigsRequestBuilders.create().input(flowConfig).build();
-    ResponseFuture<IdResponse<ComplexResourceKey<FlowId, EmptyRecord>>> flowConfigResponseFuture =
-        _restClient.get().sendRequest(request);
 
-    flowConfigResponseFuture.getResponse();
+    FlowClientUtils.sendRequestWithRetry(_restClient.get(), request, FlowconfigsRequestBuilders.getPrimaryResource());

Review comment:
       We should let FlowConfigClient untouched, since it is already deprecated. We should in fact remove this code soon.

##########
File path: gobblin-runtime/src/main/java/org/apache/gobblin/runtime/util/HelixLeaderUtils.java
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.gobblin.runtime.util;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.model.LiveInstance;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableMap;
+import com.linkedin.data.DataMap;
+import com.linkedin.restli.common.HttpStatus;
+import com.linkedin.restli.server.RestLiServiceException;
+import com.typesafe.config.Config;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.gobblin.service.ServiceConfigKeys;
+import org.apache.gobblin.util.ConfigUtils;
+
+
+/**
+ * Utils for storing/parsing helix URL in the helix instance name
+ */
+@Slf4j
+public class HelixLeaderUtils {
+  public static String HELIX_INSTANCE_NAME_SEPARATOR = "@";
+
+  /**
+   */
+  private static String getUrlFromHelixInstanceName(String helixInstanceName) {
+    if (!helixInstanceName.contains(HELIX_INSTANCE_NAME_SEPARATOR)) {
+      return null;
+    } else {
+      return helixInstanceName.substring(helixInstanceName.indexOf(HELIX_INSTANCE_NAME_SEPARATOR) + 1);
+    }
+  }
+
+  private static String getLeaderUrl(HelixManager helixManager) {
+    PropertyKey key = helixManager.getHelixDataAccessor().keyBuilder().controllerLeader();
+    LiveInstance leader = helixManager.getHelixDataAccessor().getProperty(key);
+    return getUrlFromHelixInstanceName(leader.getInstanceName());
+  }
+
+  /**
+   * If this host is not the leader, throw a {@link RestLiServiceException}, and include the URL of the leader host in
+   * the message and in the errorDetails under the key {@link ServiceConfigKeys#LEADER_URL}.
+   */
+  public static void throwErrorIfNotLeader(Optional<HelixManager> helixManager)  {
+    if (helixManager.isPresent() && !helixManager.get().isLeader()) {
+      String leaderUrl = getLeaderUrl(helixManager.get());
+      if (leaderUrl == null) {
+        return;
+      }
+      RestLiServiceException exception = new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "Request must be sent to leader node at URL " + leaderUrl);
+      exception.setErrorDetails(new DataMap(ImmutableMap.of(ServiceConfigKeys.LEADER_URL, leaderUrl)));
+      throw exception;
+    }
+  }
+
+  /**
+   * Build helix instance name by getting {@link org.apache.gobblin.service.ServiceConfigKeys#HELIX_INSTANCE_NAME_KEY}
+   * and appending the host, port, and service name with a separator
+   */
+  public static String buildHelixInstanceName(Config config, String defaultInstanceName) {
+    String helixInstanceName = ConfigUtils.getString(config, ServiceConfigKeys.HELIX_INSTANCE_NAME_KEY, defaultInstanceName);
+
+    String url = "";
+    try {
+      url = HELIX_INSTANCE_NAME_SEPARATOR + "https://" + InetAddress.getLocalHost().getHostName() + ":" + ConfigUtils.getString(config, ServiceConfigKeys.SERVICE_PORT, "")

Review comment:
       We should probably thrown an error if SERVICE_PORT is missing. 

##########
File path: gobblin-runtime/src/main/java/org/apache/gobblin/runtime/util/HelixLeaderUtils.java
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.gobblin.runtime.util;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.model.LiveInstance;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableMap;
+import com.linkedin.data.DataMap;
+import com.linkedin.restli.common.HttpStatus;
+import com.linkedin.restli.server.RestLiServiceException;
+import com.typesafe.config.Config;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.gobblin.service.ServiceConfigKeys;
+import org.apache.gobblin.util.ConfigUtils;
+
+
+/**
+ * Utils for storing/parsing helix URL in the helix instance name
+ */
+@Slf4j
+public class HelixLeaderUtils {

Review comment:
       Can this be moved into gobblin-service?

##########
File path: gobblin-runtime/build.gradle
##########
@@ -66,6 +66,7 @@ dependencies {
   compile externalDependency.gson
   compile externalDependency.guava
   compile externalDependency.guice
+  compile externalDependency.helix

Review comment:
       Hmm. I would avoid Helix dependency in gobblin-runtime. 

##########
File path: gobblin-runtime/build.gradle
##########
@@ -66,6 +66,7 @@ dependencies {
   compile externalDependency.gson
   compile externalDependency.guava
   compile externalDependency.guice
+  compile externalDependency.helix

Review comment:
       Can we move FlowStatusGenerator to gobblin-service module?




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org