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

Implement connection management, gremlin query, execute histroy and g… #3

Merged
merged 7 commits into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ Apache License
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.

2. Grant of Copyright License. Subject to the conditions and conditions of
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.

3. Grant of Patent License. Subject to the conditions and conditions of
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
Expand Down Expand Up @@ -121,18 +121,18 @@ Apache License
as modifying the License.

You may add Your own copyright statement to Your modifications and
may provide additional or different license conditions and conditions
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.

5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the conditions and conditions of
this License, without any additional conditions or conditions.
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the conditions of any separate license agreement you may have executed
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.

6. Trademarks. This License does not grant permission to use the trade
Expand Down
106 changes: 31 additions & 75 deletions hubble-be/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
<artifactId>hubble-be</artifactId>

<properties>
<release.name>${project.artifactId}</release.name>
<final.name>${release.name}-${project.version}</final.name>
<assembly.dir>${project.basedir}/assembly</assembly.dir>
<assembly.descriptor.dir>${assembly.dir}/descriptor</assembly.descriptor.dir>
<assembly.static.dir>${assembly.dir}/static</assembly.static.dir>
<shell-executable>bash</shell-executable>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
Expand Down Expand Up @@ -81,6 +75,20 @@
<groupId>com.baidu.hugegraph</groupId>
<artifactId>hugegraph-client</artifactId>
<version>1.7.4</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

Expand All @@ -98,13 +106,29 @@

<build>
<plugins>
<!--
Linary marked this conversation as resolved.
Show resolved Hide resolved
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.baidu.hugegraph.HugeGraphHubbleApplication</mainClass>
<mainClass>com.baidu.hugegraph.HugeGraphHubble</mainClass>
</configuration>
</plugin>
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.baidu.hugegraph.HugeGraphHubble</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand All @@ -130,74 +154,6 @@
</execution>
</executions>
</plugin>

<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-assembly-plugin</artifactId>-->
<!-- <version>2.4</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>assembly-hugegraph-hubble</id>-->
<!-- <phase>package</phase>-->
<!-- <goals>-->
<!-- <goal>single</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <attach>false</attach>-->
<!-- <appendAssemblyId>false</appendAssemblyId>-->
<!-- <outputDirectory>${project.basedir}</outputDirectory>-->
<!-- <descriptor>${assembly.descriptor.dir}/assembly.xml</descriptor>-->
<!-- <finalName>${final.name}</finalName>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<!-- <plugin>-->
<!-- <artifactId>maven-antrun-plugin</artifactId>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <phase>package</phase>-->
<!-- <goals>-->
<!-- <goal>run</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <tasks>-->
<!-- <echo file="${project.basedir}/dist.sh">-->
<!-- tar -zcvf \-->
<!-- ${project.basedir}/${final.name}.tar.gz ${final.name} || exit 1-->
<!-- rm -f ${project.basedir}/dist.sh-->
<!-- echo -n "hubble tar.gz available at: "-->
<!-- echo "${project.basedir}/${final.name}.tar.gz"-->
<!-- </echo>-->
<!-- <exec executable="${shell-executable}"-->
<!-- dir="${project.basedir}" failonerror="true">-->
<!-- <arg line="./dist.sh"/>-->
<!-- </exec>-->
<!-- </tasks>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<!-- <plugin>-->
<!-- <artifactId>maven-clean-plugin</artifactId>-->
<!-- <version>3.0.0</version>-->
<!-- <configuration>-->
<!-- <filesets>-->
<!-- <fileset>-->
<!-- <directory>${project.basedir}</directory>-->
<!-- <includes>-->
<!-- <include>*.tar.gz</include>-->
<!-- <include>${final.name}/**</include>-->
<!-- </includes>-->
<!-- <followSymlinks>false</followSymlinks>-->
<!-- </fileset>-->
<!-- <fileset>-->
<!-- <directory>${final.name}</directory>-->
<!-- </fileset>-->
<!-- </filesets>-->
<!-- </configuration>-->
<!-- </plugin>-->
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,22 @@
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

import com.baidu.hugegraph.common.Constant;

@SpringBootApplication
@MapperScan("com.baidu.hugegraph.mapper")
public class HugeGraphHubbleApplication extends SpringBootServletInitializer {
public class HugeGraphHubble extends SpringBootServletInitializer {

public static void main(String[] args) {
SpringApplication.run(HugeGraphHubbleApplication.class, args);
if (args == null) {
args = new String[]{Constant.CONFIG_FILE};
}
SpringApplication.run(HugeGraphHubble.class, args);
}

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
protected SpringApplicationBuilder configure(SpringApplicationBuilder
Linary marked this conversation as resolved.
Show resolved Hide resolved
builder) {
return builder.sources(this.getClass());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public final class Constant {
"zh_CN"
);

public static final String MODULE_NAME = "hubble-be";
public static final String CONFIG_FILE = "hugegraph-hubble.properties";

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2017 HugeGraph Authors
*
* 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 com.baidu.hugegraph.config;

import java.io.File;

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 com.baidu.hugegraph.common.Constant;
import com.baidu.hugegraph.exception.ExternalException;
import com.baidu.hugegraph.options.HubbleOptions;

@Configuration
public class HubbleConfig {

@Autowired
private ApplicationArguments arguments;

@Bean
public HugeConfig hugeConfig() {
String[] args = this.arguments.getSourceArgs();
if (args.length != 1) {
throw new ExternalException(
"HugeGraphHubble must specify a config file");
}
// Register hubble config options
OptionSpace.register(Constant.MODULE_NAME, HubbleOptions.instance());

String conf = args[0];
try {
String path = HubbleConfig.class.getClassLoader()
.getResource(conf).getPath();
File file = new File(path);
if (file.exists() && file.isFile()) {
conf = path;
}
} catch (Exception ignored) {
}
return new HugeConfig(conf);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
* Unused
*/
@Configuration
public class SwaggerConfig {
Linary marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,39 @@

package com.baidu.hugegraph.config;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.apache.tomcat.util.http.LegacyCookieProcessor;
import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.stereotype.Component;

import com.baidu.hugegraph.exception.ExternalException;
import com.baidu.hugegraph.options.HubbleOptions;

/**
* Reference http://www.zizhixiaoshe.com/article/invalidcookie.html
*/
@Component
public class EmbeddedTomcatConfig implements WebServerFactoryCustomizer {
public class TomcatServletConfig
implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {

@Autowired
private HugeConfig config;

@Override
public void customize(WebServerFactory factory) {
TomcatServletWebServerFactory tomcatFactory =
(TomcatServletWebServerFactory) factory;
tomcatFactory.addContextCustomizers(context -> {
public void customize(TomcatServletWebServerFactory factory) {
// Use customized server port
String host = this.config.get(HubbleOptions.SERVER_HOST);
try {
factory.setAddress(InetAddress.getByName(host));
} catch (UnknownHostException e) {
throw new ExternalException(String.format("Unknown host %s", host));
}
factory.setPort(this.config.get(HubbleOptions.SERVER_PORT));
factory.addContextCustomizers(context -> {
context.setCookieProcessor(new LegacyCookieProcessor());
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
@Builder
public class GremlinResult {

@JsonProperty("type")
private Type type;
@JsonProperty("data")
private List<Object> data;
@JsonProperty("graph_view")
Expand All @@ -53,4 +55,17 @@ public static class GraphView {
@JsonProperty("edges")
private Collection<Edge> edges;
}

public enum Type {

EMPTY,

GENERAL,

VERTEX,

EDGE,

PATH
}
}
Loading