Skip to content
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

BREAKING CHANGE(hubble): upgrade to new version 2.0 [WIP] #632

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
307 changes: 275 additions & 32 deletions hugegraph-hubble/hubble-be/pom.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,34 @@
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.time.ZoneOffset;
import java.util.TimeZone;

@SpringBootApplication
@EnableScheduling
@MapperScan("org.apache.hugegraph.mapper")
public class HugeGraphHubble extends SpringBootServletInitializer {

public static void main(String[] args) {
System.out.println("user.dir ==> " + System.getProperty("user.dir"));
initEnv();
TimeZone.setDefault(TimeZone.getTimeZone(ZoneOffset.of("+8")));
SpringApplication.run(HugeGraphHubble.class, args);
}

public static void initEnv() {
String hubbleHomePath = System.getProperty("hubble.home.path");
Ex.check(StringUtils.isNotEmpty(hubbleHomePath),
"The system property 'hubble.home.path' must be set");
"The system property 'hubble.home.path' must be set");
String loaderHomePath = System.getProperty("loader.home.path");
if (StringUtils.isEmpty(loaderHomePath)) {
System.setProperty("loader.home.path", hubbleHomePath);
}
}

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
protected SpringApplicationBuilder configure(
SpringApplicationBuilder builder) {
return builder.sources(this.getClass());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
*
* 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.common;


import org.apache.hugegraph.type.define.SerialEnum;

public enum AppName implements SerialEnum {
GREMLIN(1, "GREMLIN"),

VERTEX_UPDATE(2, "VERTEX_UPDATE"),

EDGE_UPDATE(3, "EDGE_UPDATE")
;

private final byte code;
private final String name;

static {
SerialEnum.register(AppName.class);
}

AppName(int code, String name) {
assert code < 256;
this.code = (byte) code;
this.name = name;
}

@Override
public byte code() {
return this.code;
}

public String string() {
return this.name;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
*
* 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.common;


import org.apache.hugegraph.type.define.SerialEnum;

public enum AppType implements SerialEnum {
// 通用功能
GENERAL(1, "GENERAL"),

// 定制功能
CUSTOMIZED(2, "CUSTOMIZED"),

;

private final byte code;
private final String name;

static {
SerialEnum.register(AppName.class);
}

AppType(int code, String name) {
assert code < 256;
this.code = (byte) code;
this.name = name;
}

@Override
public byte code() {
return this.code;
}

public String string() {
return this.name;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

package org.apache.hugegraph.common;

import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.collect.ImmutableSet;

import java.nio.charset.Charset;
import java.util.Set;
import java.util.regex.Pattern;

import com.google.common.collect.ImmutableSet;
import static java.nio.charset.StandardCharsets.UTF_8;

public final class Constant {

Expand All @@ -39,12 +39,13 @@ public final class Constant {
public static final String CONFIG_FILE = "hugegraph-hubble.properties";

public static final String CONTROLLER_PACKAGE =
"org.apache.hugegraph.controller";
"com.baidu.hugegraph.controller";

public static final String COOKIE_USER = "user";
public static final String API_V1_1 = "/api/v1.1/";
public static final String API_V1_2 = "/api/v1.2/";
public static final String API_VERSION = API_V1_2;
public static final String API_V1_3 = "/api/v1.3/";
public static final String API_VERSION = API_V1_3;

public static final String EDITION_COMMUNITY = "community";
public static final String EDITION_COMMERCIAL = "commercial";
Expand All @@ -58,6 +59,8 @@ public final class Constant {
public static final int STATUS_ILLEGAL_GREMLIN = 460;
public static final int STATUS_INTERNAL_ERROR = 500;

public static final String TOKEN_KEY = "auth_token";

public static final int NO_LIMIT = -1;

public static final Pattern COMMON_NAME_PATTERN = Pattern.compile(
Expand All @@ -73,4 +76,6 @@ public final class Constant {
);

public static final String[] LIKE_WILDCARDS = {"%", "_", "^", "[", "]"};

public static final String BUILT_IN = "neizhianli";
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@
package org.apache.hugegraph.common;

public interface Mergeable {

}
Original file line number Diff line number Diff line change
@@ -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.common;


import org.apache.hugegraph.type.define.SerialEnum;

public enum OptionType implements SerialEnum {


DELETE(1, "DELETE"),

ADD(2, "ADD"),

UPDATE(3, "UPDATE"),

;

private final byte code;
private final String name;

static {
SerialEnum.register(OptionType.class);
}

OptionType(int code, String name) {
assert code < 256;
this.code = (byte) code;
this.name = name;
}

@Override
public byte code() {
return this.code;
}

public String string() {
return this.name;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public class CacheConfig {
public enum Caches {

// No used
GREMLIN_QUERY;
GREMLIN_QUERY,

// es query cached
ES_QUERY(DEFAULT_MAXSIZE, 60);

private int maxSize = DEFAULT_MAXSIZE;
private int ttl = DEFAULT_TTL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,19 @@

package org.apache.hugegraph.config;

import java.io.File;

import org.apache.hugegraph.common.Constant;
import org.apache.hugegraph.exception.ExternalException;
import org.apache.hugegraph.options.HubbleOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.File;

@Configuration
public class HubbleConfig {

private static final Logger LOG = LoggerFactory.getLogger(HubbleConfig.class);

@Autowired
private ApplicationArguments arguments;

Expand All @@ -43,7 +39,7 @@ public HugeConfig hugeConfig() {
String[] args = this.arguments.getSourceArgs();
if (args.length > 1) {
throw new ExternalException(
"HugeGraphHubble accept up to one param as config file");
"HugeGraphHubble accept up to one param as config file");
} else if (args.length == 0) {
args = new String[]{Constant.CONFIG_FILE};
}
Expand All @@ -59,7 +55,6 @@ public HugeConfig hugeConfig() {
conf = path;
}
} catch (Exception ignored) {
LOG.error("hugeConfig exception");
}
return new HugeConfig(conf);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
*
* 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.config;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicHttpResponse;
import org.apache.hugegraph.common.Constant;
import org.mitre.dsmiley.httpproxy.ProxyServlet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class IngestionProxyServlet extends ProxyServlet {
@Override
protected String rewriteQueryStringFromRequest(
HttpServletRequest servletRequest, String queryString) {
String username =
(String) servletRequest.getSession().getAttribute("username");

String requestQueryString = servletRequest.getQueryString();

if (StringUtils.isEmpty(requestQueryString)) {
requestQueryString = String.format("user=%s", username);
} else {
requestQueryString += String.format("&user=%s", username);
}

return requestQueryString;
}

@Override
protected HttpResponse doExecute(HttpServletRequest servletRequest,
HttpServletResponse servletResponse,
HttpRequest proxyRequest) throws IOException {
String username =
(String) servletRequest.getSession().getAttribute("username");

if (username == null) {
// check user login
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
Constant.STATUS_OK,
"{\"status\": 401}");

response.setEntity(new StringEntity("{\"status\": 401}"));

return response;
}

return super.doExecute(servletRequest, servletResponse, proxyRequest);
}
}
Loading
Loading