Skip to content
Permalink
Browse files
refact: adopt for release 0.12 (#336)
  • Loading branch information
imbajin committed Dec 31, 2021
1 parent 531b222 commit 7b53a4cd3e3b23f0e95b53bb40c2f4ce75b25555
Showing 11 changed files with 28 additions and 503 deletions.
@@ -5,7 +5,7 @@
<parent>
<artifactId>hugegraph-hubble</artifactId>
<groupId>com.baidu.hugegraph</groupId>
<version>1.5.0</version>
<version>1.6.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@@ -69,8 +69,8 @@

<dependency>
<groupId>com.baidu.hugegraph</groupId>
<artifactId>hugegraph-common</artifactId>
<version>1.8.8</version>
<artifactId>hugegraph-loader</artifactId>
<version>0.12.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
@@ -94,25 +94,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.baidu.hugegraph</groupId>
<artifactId>hugegraph-loader</artifactId>
<version>0.11.1</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>

<dependency>
<groupId>commons-fileupload</groupId>
@@ -22,40 +22,29 @@
import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baidu.hugegraph.common.Constant;
import com.baidu.hugegraph.handler.MessageSourceHandler;
import com.baidu.hugegraph.license.LicenseVerifier;
import com.baidu.hugegraph.util.Bytes;

@RestController
@RequestMapping("about")
// TODO: delete the class or keep it?
public class AboutController extends BaseController {

@Autowired
private MessageSourceHandler messageHandler;

@GetMapping
public Map<String, Object> about() {
LicenseVerifier verifier = LicenseVerifier.instance();
Map<String, Object> about = new LinkedHashMap<>();
about.put("name", Constant.SERVER_NAME);
about.put("version", "1.5.0");
about.put("edition", verifier.edition());
about.put("allowed_graphs", verifier.allowedGraphs());
long datasize = verifier.allowedDataSize();
if (datasize == -1) {
about.put("allowed_datasize",
this.messageHandler.getMessage("license.datasize.no-limit"));
} else {
about.put("allowed_datasize",
FileUtils.byteCountToDisplaySize(datasize * Bytes.MB));
}
about.put("allowed_datasize",
this.messageHandler.getMessage("license.datasize.no-limit"));
return about;
}
}
@@ -46,7 +46,6 @@
import com.baidu.hugegraph.service.GraphConnectionService;
import com.baidu.hugegraph.service.HugeClientPoolService;
import com.baidu.hugegraph.service.SettingSSLService;
import com.baidu.hugegraph.service.license.LicenseService;
import com.baidu.hugegraph.util.Ex;
import com.baidu.hugegraph.util.HubbleUtil;
import com.baidu.hugegraph.util.HugeClientUtil;
@@ -70,8 +69,6 @@ public class GraphConnectionController extends BaseController {
@Autowired
private HugeClientPoolService poolService;
@Autowired
private LicenseService licenseService;
@Autowired
private SettingSSLService sslService;

@GetMapping
@@ -85,25 +82,6 @@ public Response list(@RequestParam(name = "content", required = false)
int pageSize) {
IPage<GraphConnection> conns = this.connService.list(content, pageNo,
pageSize);
LicenseService.VerifyResult verifyResult;
verifyResult = this.licenseService.verifyGraphs((int) conns.getTotal());
// Verifed graphs failed, all connections marked as disabled
if (!verifyResult.isEnabled()) {
conns.getRecords().forEach(r -> r.setEnabled(false));
}
for (GraphConnection conn : conns.getRecords()) {
if (!conn.getEnabled()) {
verifyResult.setEnabled(false);
verifyResult.add(conn.getDisableReason());
}
}
// Verifed failed
if (!verifyResult.isEnabled()) {
// The first message is about graph connection count
return Response.builder().status(Constant.STATUS_UNAUTHORIZED)
.data(conns).message(verifyResult.getMessage())
.build();
}
return Response.builder().status(Constant.STATUS_OK).data(conns)
.build();
}
@@ -124,13 +102,6 @@ public GraphConnection get(@PathVariable("id") int id) {

@PostMapping
public GraphConnection create(@RequestBody GraphConnection newEntity) {
// Check graph connection count, if exceed limit, throw exception
LicenseService.VerifyResult verifyResult;
verifyResult = this.licenseService.verifyGraphs(
this.connService.count() + 1);
Ex.check(verifyResult.isEnabled(), Constant.STATUS_UNAUTHORIZED,
verifyResult.getMessage());

this.checkParamsValid(newEntity, true);
this.checkAddressSecurity(newEntity);
// Make sure the new entity doesn't conflict with exists
@@ -142,12 +113,6 @@ public GraphConnection create(@RequestBody GraphConnection newEntity) {
HugeClient client = HugeClientUtil.tryConnect(newEntity);
newEntity.setCreateTime(HubbleUtil.nowDate());

// Check current graph's data size
verifyResult = this.licenseService.verifyDataSize(
client, newEntity.getName(), newEntity.getGraph());
Ex.check(verifyResult.isEnabled(), Constant.STATUS_UNAUTHORIZED,
verifyResult.getMessage());

this.connService.save(newEntity);
this.poolService.put(newEntity, client);
return newEntity;
@@ -170,12 +135,6 @@ public GraphConnection update(@PathVariable("id") int id,
this.checkEntityUnique(entity, false);
this.sslService.configSSL(this.config, entity);
HugeClient client = HugeClientUtil.tryConnect(entity);
// Check current graph's data size
LicenseService.VerifyResult verifyResult;
verifyResult = this.licenseService.verifyDataSize(
client, entity.getName(), entity.getGraph());
Ex.check(verifyResult.isEnabled(), Constant.STATUS_UNAUTHORIZED,
verifyResult.getMessage());

this.connService.update(entity);
this.poolService.put(entity, client);
@@ -190,7 +149,6 @@ public GraphConnection delete(@PathVariable("id") int id) {
}
this.connService.remove(id);
this.poolService.remove(oldEntity);
this.licenseService.updateAllGraphStatus();
return oldEntity;
}

@@ -25,28 +25,22 @@
import org.springframework.stereotype.Component;

import com.baidu.hugegraph.config.HugeConfig;
import com.baidu.hugegraph.license.LicenseVerifier;
import com.baidu.hugegraph.license.ServerInfo;
import com.baidu.hugegraph.options.HubbleOptions;

import lombok.extern.log4j.Log4j2;

@Log4j2
@Component
// TODO: Why we need this class?
public class CustomApplicationRunner implements ApplicationRunner {

@Autowired
private HugeConfig config;

@Override
public void run(ApplicationArguments args) throws Exception {
public void run(ApplicationArguments args) throws Exception{
String serverId = this.config.get(HubbleOptions.SERVER_ID);
ServerInfo serverInfo = new ServerInfo(serverId);
log.info("The server info has been inited");
this.installLicense(serverInfo, "9662b261c388fc5923ace0ebe2a34b02");
}

private void installLicense(ServerInfo serverInfo, String md5) {
LicenseVerifier.instance().install(serverInfo, md5);
}
}
@@ -30,7 +30,6 @@
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.baidu.hugegraph.exception.InternalException;
import com.baidu.hugegraph.license.LicenseVerifier;
import com.baidu.hugegraph.service.license.LicenseService;

import lombok.extern.log4j.Log4j2;
@@ -59,11 +58,6 @@ public boolean preHandle(HttpServletRequest request,
if (StringUtils.isEmpty(connIdValue)) {
throw new InternalException("Not found conn id in url");
}

int connId = Integer.parseInt(connIdValue);
// Check graph connection valid
this.licenseService.checkGraphStatus(connId);
LicenseVerifier.instance().verifyIfNeeded();
return true;
}
}

0 comments on commit 7b53a4c

Please sign in to comment.