Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.hugegraph.structure.constant.Direction;
import org.apache.hugegraph.structure.traverser.SingleSourceJaccardSimilarityRequest;


import org.apache.hugegraph.util.E;

public class JaccardSimilarityAPI extends TraversersAPI {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.hugegraph.exception;


import org.apache.hugegraph.rest.ClientException;

public class InvalidOperationException extends ClientException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@
import java.util.Map;

import org.apache.hugegraph.rest.RestResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jakarta.ws.rs.core.Response;

public class ServerException extends RuntimeException {

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

private static final long serialVersionUID = 6335623004322652358L;

private static final String[] EXCEPTION_KEYS = {"exception",
Expand Down Expand Up @@ -52,6 +56,7 @@ public static ServerException fromResponse(Response response) {
exception.cause = (String) getByKeys(json, CAUSE_KEYS);
exception.trace = getByKeys(json, TRACE_KEYS);
} catch (Exception ignored) {
LOG.error("ServerException fromResponse excepiton");
}

return exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public class HBaseSerializer {
private HugeClient client;
private GraphSchema graphSchema;


public HBaseSerializer(HugeClient client, int vertexPartitions, int edgePartitions){
public HBaseSerializer(HugeClient client, int vertexPartitions, int edgePartitions) {
this.client = client;
this.graphSchema = new GraphSchema(client);
this.edgeLogicPartitions = edgePartitions;
Expand All @@ -50,12 +49,12 @@ public HBaseSerializer(HugeClient client, int vertexPartitions, int edgePartitio

public byte[] getKeyBytes(GraphElement e) {
byte[] array = null;
if(e.type() == "vertex" && e.id() != null){
if (e.type() == "vertex" && e.id() != null) {
BytesBuffer buffer = BytesBuffer.allocate(2 + 1 + e.id().toString().length());
buffer.writeShort(getPartition(HugeType.VERTEX, IdGenerator.of(e.id())));
buffer.writeId(IdGenerator.of(e.id()));
array = buffer.bytes();
}else if ( e.type() == "edge" ){
} else if (e.type() == "edge") {
BytesBuffer buffer = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID);
Edge edge = (Edge)e;
buffer.writeShort(getPartition(HugeType.EDGE, IdGenerator.of(edge.sourceId())));
Expand All @@ -71,22 +70,22 @@ public byte[] getKeyBytes(GraphElement e) {

public byte[] getValueBytes(GraphElement e) {
byte[] array = null;
if(e.type() == "vertex"){
int propsCount = e.properties().size() ; //vertex.sizeOfProperties();
if (e.type() == "vertex") {
int propsCount = e.properties().size(); //vertex.sizeOfProperties();
BytesBuffer buffer = BytesBuffer.allocate(8 + 16 * propsCount);
buffer.writeId(IdGenerator.of(graphSchema.getVertexLabel(e.label()).id()));
buffer.writeVInt(propsCount);
for(Map.Entry<String, Object> entry : e.properties().entrySet()){
for (Map.Entry<String, Object> entry : e.properties().entrySet()) {
PropertyKey propertyKey = graphSchema.getPropertyKey(entry.getKey());
buffer.writeVInt(propertyKey.id().intValue());
buffer.writeProperty(propertyKey.dataType(),entry.getValue());
}
array = buffer.bytes();
} else if ( e.type() == "edge" ){
} else if (e.type() == "edge") {
int propsCount = e.properties().size();
BytesBuffer buffer = BytesBuffer.allocate(4 + 16 * propsCount);
buffer.writeVInt(propsCount);
for(Map.Entry<String, Object> entry : e.properties().entrySet()){
for (Map.Entry<String, Object> entry : e.properties().entrySet()) {
PropertyKey propertyKey = graphSchema.getPropertyKey(entry.getKey());
buffer.writeVInt(propertyKey.id().intValue());
buffer.writeProperty(propertyKey.dataType(),entry.getValue());
Expand All @@ -108,15 +107,15 @@ public short getPartition(HugeType type, Id id) {
return partition > 0 ? partition : (short) -partition;
}

public int getEdgeLogicPartitions(){
public int getEdgeLogicPartitions() {
return this.edgeLogicPartitions;
}

public int getVertexLogicPartitions(){
public int getVertexLogicPartitions() {
return this.vertexLogicPartitions;
}

public void close(){
public void close() {
this.client.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class BytesDemo {
static HugeClient client;
boolean bypassServer = true;
RocksDBSerializer ser;
HBaseSerializer HBaseSer;
HBaseSerializer hBaseSer;

public static void main(String[] args) {
BytesDemo ins = new BytesDemo();
Expand All @@ -54,7 +54,6 @@ void initGraph() {

SchemaManager schema = client.schema();


schema.propertyKey("name").asText().ifNotExist().create();
schema.propertyKey("age").asInt().ifNotExist().create();
schema.propertyKey("lang").asText().ifNotExist().create();
Expand Down Expand Up @@ -97,7 +96,7 @@ void initGraph() {
.ifNotExist()
.create();

HBaseSer = new HBaseSerializer(client, vertexLogicPartitions, edgeLogicPartitions);
hBaseSer = new HBaseSerializer(client, vertexLogicPartitions, edgeLogicPartitions);
writeGraphElements();

client.close();
Expand Down Expand Up @@ -130,7 +129,6 @@ private void writeGraphElements() {
add(vadasB);
}};


List<Edge> edges = new ArrayList<Edge>() {{
add(peterCreateLop);
}};
Expand All @@ -148,14 +146,14 @@ private void writeGraphElements() {
* */
void writeDirectly(List<Vertex> vertices, List<Edge> edges) {
for (Vertex vertex : vertices) {
byte[] rowkey = HBaseSer.getKeyBytes(vertex);
byte[] values = HBaseSer.getValueBytes(vertex);
byte[] rowkey = hBaseSer.getKeyBytes(vertex);
byte[] values = hBaseSer.getValueBytes(vertex);
sendRpcToHBase("vertex", rowkey, values);
}

for (Edge edge : edges) {
byte[] rowkey = HBaseSer.getKeyBytes(edge);
byte[] values = HBaseSer.getValueBytes(edge);
byte[] rowkey = hBaseSer.getKeyBytes(edge);
byte[] values = hBaseSer.getValueBytes(edge);
sendRpcToHBase("edge", rowkey, values);
}
}
Expand Down Expand Up @@ -185,10 +183,8 @@ boolean sendRpcToHBase(String type, byte[] rowkey, byte[] values) {
return flag;
}


boolean put(String type, byte[] rowkey, byte[] values) throws IOException {
// TODO: put to HBase
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ public abstract class IdGenerator {

public static final Id ZERO = IdGenerator.of(0L);

public final static Id of(String id) {
public static Id of(String id) {
return new StringId(id);
}

public final static Id of(UUID id) {
public static Id of(UUID id) {
return new UuidId(id);
}

public final static Id of(String id, boolean uuid) {
public static Id of(String id, boolean uuid) {
return uuid ? new UuidId(id) : new StringId(id);
}

public final static Id of(long id) {
public static Id of(long id) {
return new LongId(id);
}

Expand All @@ -57,7 +57,7 @@ public static Id of(Object id) {
return new ObjectId(id);
}

public final static Id of(byte[] bytes, Id.IdType type) {
public static Id of(byte[] bytes, Id.IdType type) {
switch (type) {
case LONG:
return new LongId(bytes);
Expand All @@ -70,7 +70,7 @@ public final static Id of(byte[] bytes, Id.IdType type) {
}
}

public final static Id ofStoredString(String id, Id.IdType type) {
public static Id ofStoredString(String id, Id.IdType type) {
switch (type) {
case LONG:
return of(LongEncoding.decodeSignedB64(id));
Expand All @@ -84,7 +84,7 @@ public final static Id ofStoredString(String id, Id.IdType type) {
}
}

public final static String asStoredString(Id id) {
public static String asStoredString(Id id) {
switch (id.type()) {
case LONG:
return LongEncoding.encodeSignedB64(id.asLong());
Expand All @@ -97,7 +97,7 @@ public final static String asStoredString(Id id) {
}
}

public final static Id.IdType idType(Id id) {
public static Id.IdType idType(Id id) {
if (id instanceof LongId) {
return Id.IdType.LONG;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ public static SplicingIdGenerator instance() {
/**
* Generate a string id of HugeVertex from Vertex name
*/
// public Id generate(HugeVertex vertex) {
// /*
// * Hash for row-key which will be evenly distributed.
// * We can also use LongEncoding.encode() to encode the int/long hash
// * if needed.
// * id = String.format("%s%s%s", HashUtil.hash(id), ID_SPLITOR, id);
// */
// // TODO: use binary Id with binary fields instead of string id
// return splicing(vertex.schemaLabel().id().asString(), vertex.name());
// }
// public Id generate(HugeVertex vertex) {
// /*
// * Hash for row-key which will be evenly distributed.
// * We can also use LongEncoding.encode() to encode the int/long hash
// * if needed.
// * id = String.format("%s%s%s", HashUtil.hash(id), ID_SPLITOR, id);
// */
// // TODO: use binary Id with binary fields instead of string id
// return splicing(vertex.schemaLabel().id().asString(), vertex.name());
// }

/**
* Concat multiple ids into one composite id with IDS_SPLITOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

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;
Expand All @@ -32,6 +34,8 @@
@Configuration
public class HubbleConfig {

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

@Autowired
private ApplicationArguments arguments;

Expand All @@ -56,6 +60,7 @@ 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
Expand Up @@ -244,7 +244,7 @@ public LoadTask retry(@PathVariable("connId") int connId,
return this.service.retry(taskId);
} finally {
jobEntity.setJobStatus(JobStatus.LOADING);
jobEntity.setUpdateTime( HubbleUtil.nowDate());
jobEntity.setUpdateTime(HubbleUtil.nowDate());
this.jobService.update(jobEntity);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

package org.apache.hugegraph.license;

import org.apache.hugegraph.license.MachineInfo;

public final class ServerInfo {

private final String serverId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.apache.hugegraph.mapper.load.LoadTaskMapper;
import org.apache.hugegraph.service.SettingSSLService;
import org.apache.hugegraph.util.Ex;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
Expand Down Expand Up @@ -421,8 +422,8 @@ private FileSource buildFileSource(FileMapping fileMapping) {
}

private List<org.apache.hugegraph.loader.mapping.VertexMapping>
buildVertexMappings(GraphConnection connection,
FileMapping fileMapping) {
buildVertexMappings(GraphConnection connection,
FileMapping fileMapping) {
int connId = connection.getId();
List<org.apache.hugegraph.loader.mapping.VertexMapping> vMappings =
new ArrayList<>();
Expand All @@ -435,7 +436,8 @@ private FileSource buildFileSource(FileMapping fileMapping) {
Ex.check(idFields.size() == 1,
"When the ID strategy is CUSTOMIZED, you must " +
"select a column in the file as the id");
vMapping = new org.apache.hugegraph.loader.mapping.VertexMapping(idFields.get(0), true);
vMapping = new org.apache.hugegraph.loader.mapping.VertexMapping(idFields.get(0),
true);
} else {
assert vl.getIdStrategy().isPrimaryKey();
List<String> primaryKeys = vl.getPrimaryKeys();
Expand Down Expand Up @@ -475,8 +477,8 @@ private FileSource buildFileSource(FileMapping fileMapping) {
}

private List<org.apache.hugegraph.loader.mapping.EdgeMapping>
buildEdgeMappings(GraphConnection connection,
FileMapping fileMapping) {
buildEdgeMappings(GraphConnection connection,
FileMapping fileMapping) {
int connId = connection.getId();
List<org.apache.hugegraph.loader.mapping.EdgeMapping> eMappings =
new ArrayList<>();
Expand Down Expand Up @@ -526,7 +528,7 @@ private FileSource buildFileSource(FileMapping fileMapping) {

org.apache.hugegraph.loader.mapping.EdgeMapping eMapping;
eMapping = new org.apache.hugegraph.loader.mapping.EdgeMapping(
sourceFields, unfoldSource, targetFields, unfoldTarget);
sourceFields, unfoldSource, targetFields, unfoldTarget);
// set label
eMapping.label(mapping.getLabel());
// set field_mapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.hugegraph.service.HugeClientPoolService;
import org.apache.hugegraph.structure.Task;
import org.apache.hugegraph.util.HubbleUtil;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
Expand Down Expand Up @@ -92,7 +93,6 @@ public IPage<ExecuteHistory> list(int connId, long current, long pageSize) {
return results;
}


public ExecuteHistory get(int connId, int id) {
HugeClient client = this.getClient(connId);
ExecuteHistory history = this.mapper.selectById(id);
Expand All @@ -111,9 +111,9 @@ public ExecuteHistory get(int connId, int id) {

@Transactional(isolation = Isolation.READ_COMMITTED)
public void save(ExecuteHistory history) {
if (this.mapper.insert(history) != 1) {
throw new InternalException("entity.insert.failed", history);
}
if (this.mapper.insert(history) != 1) {
throw new InternalException("entity.insert.failed", history);
}
}

@Transactional(isolation = Isolation.READ_COMMITTED)
Expand Down
Loading