javeme commented on code in PR #2130: URL: https://github.com/apache/incubator-hugegraph/pull/2130#discussion_r1120112239
########## hugegraph-core/src/main/java/org/apache/hugegraph/election/StandardRoleTypeDataAdapter.java: ########## @@ -43,9 +43,9 @@ public class StandardRoleTypeDataAdapter implements RoleTypeDataAdapter { private final HugeGraphParams graphParams; private final Schema schema; - public StandardRoleTypeDataAdapter(HugeGraphParams graphParams) { - this.graphParams = graphParams; - this.schema = new Schema(graphParams); + public StandardRoleTypeDataAdapter(HugeGraphParams graph) { + this.graphParams = graph; Review Comment: also rename this.graphParams ########## hugegraph-core/src/main/java/org/apache/hugegraph/election/GlobalMasterInfo.java: ########## @@ -0,0 +1,57 @@ +/* + * 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.hugegraph.election; + +public class GlobalMasterInfo { + + private boolean isMaster; + private String url; + + private volatile boolean featureSupport; + + private static GlobalMasterInfo instance = new GlobalMasterInfo(); Review Comment: can the GlobalMasterInfo instance be held GraphManager? ########## hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/RedirectFilter.java: ########## @@ -0,0 +1,76 @@ +/* + * 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.hugegraph.api.filter; + +import java.io.IOException; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.net.URI; +import java.net.URISyntaxException; + +import jakarta.ws.rs.NameBinding; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerRequestFilter; +import jakarta.ws.rs.core.Response; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.client.utils.URIBuilder; +import org.apache.hugegraph.election.GlobalMasterInfo; +import org.apache.hugegraph.util.Log; +import org.slf4j.Logger; + +public class RedirectFilter implements ContainerRequestFilter { + + private static final Logger LOG = Log.logger(RedirectFilter.class); + + @Override + public void filter(ContainerRequestContext requestContext) throws IOException { + GlobalMasterInfo instance = GlobalMasterInfo.instance(); + if (!instance.isFeatureSupport()) { + return; + } + + String url = ""; + synchronized (instance) { + if (instance.isMaster() || StringUtils.isEmpty(instance.url())) { + return; + } + url = instance.url(); + } + + URI redirectUri = null; + try { + URIBuilder redirectURIBuilder = new URIBuilder(requestContext.getUriInfo().getAbsolutePath()); Review Comment: shorten requestContext to context? ########## hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/RedirectFilter.java: ########## @@ -0,0 +1,76 @@ +/* + * 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.hugegraph.api.filter; + +import java.io.IOException; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.net.URI; +import java.net.URISyntaxException; + +import jakarta.ws.rs.NameBinding; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerRequestFilter; +import jakarta.ws.rs.core.Response; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.client.utils.URIBuilder; +import org.apache.hugegraph.election.GlobalMasterInfo; +import org.apache.hugegraph.util.Log; +import org.slf4j.Logger; + +public class RedirectFilter implements ContainerRequestFilter { + + private static final Logger LOG = Log.logger(RedirectFilter.class); + + @Override + public void filter(ContainerRequestContext requestContext) throws IOException { + GlobalMasterInfo instance = GlobalMasterInfo.instance(); Review Comment: get from graphManager.auth.masterInfo? ########## hugegraph-core/src/main/java/org/apache/hugegraph/config/CoreOptions.java: ########## @@ -635,6 +635,14 @@ public static synchronized CoreOptions instance() { 2 ); + public static final ConfigOption<String> NODE_EXTERNAL_URL = + new ConfigOption<>( + "server.role.node_external_url", + "The url of external accessibility", + disallowEmpty(), + "127.0.0.1:8080" Review Comment: we can pass it from restserver config to graph config, like rpc url -- 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: dev-unsubscr...@hugegraph.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org