You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hugegraph.apache.org by je...@apache.org on 2022/11/23 13:16:23 UTC
[incubator-hugegraph] 01/02: refact: adapt all to apache package and dependencies (Breaking Changes)
This is an automated email from the ASF dual-hosted git repository.
jermy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git
commit 67a689c86cc29b2e8a9a638373e8be014bcbb46b
Author: 青年 <10...@qq.com>
AuthorDate: Fri Nov 18 16:17:54 2022 +0800
refact: adapt all to apache package and dependencies (Breaking Changes)
---
.gitignore | 1 +
hugegraph-api/pom.xml | 15 +-
.../src/main/java/com/baidu/hugegraph/api/API.java | 195 -
.../com/baidu/hugegraph/api/auth/AccessAPI.java | 215 -
.../com/baidu/hugegraph/api/auth/BelongAPI.java | 206 -
.../com/baidu/hugegraph/api/auth/GroupAPI.java | 183 -
.../com/baidu/hugegraph/api/auth/LoginAPI.java | 161 -
.../com/baidu/hugegraph/api/auth/ProjectAPI.java | 274 -
.../com/baidu/hugegraph/api/auth/TargetAPI.java | 203 -
.../java/com/baidu/hugegraph/api/auth/UserAPI.java | 234 -
.../hugegraph/api/filter/AuthenticationFilter.java | 291 -
.../hugegraph/api/filter/CompressInterceptor.java | 111 -
.../api/filter/DecompressInterceptor.java | 58 -
.../hugegraph/api/filter/ExceptionFilter.java | 288 -
.../hugegraph/api/filter/LoadDetectFilter.java | 110 -
.../hugegraph/api/filter/LoadReleaseFilter.java | 48 -
.../baidu/hugegraph/api/filter/StatusFilter.java | 59 -
.../com/baidu/hugegraph/api/graph/BatchAPI.java | 169 -
.../com/baidu/hugegraph/api/graph/EdgeAPI.java | 574 --
.../com/baidu/hugegraph/api/graph/VertexAPI.java | 479 -
.../com/baidu/hugegraph/api/gremlin/CypherAPI.java | 113 -
.../baidu/hugegraph/api/gremlin/GremlinAPI.java | 87 -
.../baidu/hugegraph/api/gremlin/GremlinClient.java | 78 -
.../hugegraph/api/gremlin/GremlinQueryAPI.java | 109 -
.../com/baidu/hugegraph/api/job/AlgorithmAPI.java | 84 -
.../com/baidu/hugegraph/api/job/ComputerAPI.java | 87 -
.../com/baidu/hugegraph/api/job/GremlinAPI.java | 210 -
.../com/baidu/hugegraph/api/job/RebuildAPI.java | 98 -
.../java/com/baidu/hugegraph/api/job/TaskAPI.java | 187 -
.../baidu/hugegraph/api/metrics/MetricsAPI.java | 163 -
.../com/baidu/hugegraph/api/profile/GraphsAPI.java | 287 -
.../baidu/hugegraph/api/profile/ProfileAPI.java | 232 -
.../baidu/hugegraph/api/profile/VersionAPI.java | 53 -
.../java/com/baidu/hugegraph/api/raft/RaftAPI.java | 217 -
.../baidu/hugegraph/api/schema/EdgeLabelAPI.java | 274 -
.../baidu/hugegraph/api/schema/IndexLabelAPI.java | 294 -
.../baidu/hugegraph/api/schema/PropertyKeyAPI.java | 274 -
.../com/baidu/hugegraph/api/schema/SchemaAPI.java | 70 -
.../baidu/hugegraph/api/schema/VertexLabelAPI.java | 266 -
.../hugegraph/api/traversers/AdamicAdarAPI.java | 89 -
.../api/traversers/AllShortestPathsAPI.java | 95 -
.../baidu/hugegraph/api/traversers/CountAPI.java | 149 -
.../hugegraph/api/traversers/CrosspointsAPI.java | 91 -
.../api/traversers/CustomizedCrosspointsAPI.java | 200 -
.../api/traversers/CustomizedPathsAPI.java | 201 -
.../baidu/hugegraph/api/traversers/EdgesAPI.java | 126 -
.../api/traversers/FusiformSimilarityAPI.java | 170 -
.../api/traversers/JaccardSimilarityAPI.java | 147 -
.../hugegraph/api/traversers/KneighborAPI.java | 191 -
.../baidu/hugegraph/api/traversers/KoutAPI.java | 206 -
.../api/traversers/MultiNodeShortestPathAPI.java | 128 -
.../hugegraph/api/traversers/NeighborRankAPI.java | 154 -
.../baidu/hugegraph/api/traversers/PathsAPI.java | 185 -
.../hugegraph/api/traversers/PersonalRankAPI.java | 142 -
.../baidu/hugegraph/api/traversers/RaysAPI.java | 89 -
.../api/traversers/ResourceAllocationAPI.java | 90 -
.../baidu/hugegraph/api/traversers/RingsAPI.java | 92 -
.../hugegraph/api/traversers/SameNeighborsAPI.java | 84 -
.../hugegraph/api/traversers/ShortestPathAPI.java | 96 -
.../traversers/SingleSourceShortestPathAPI.java | 101 -
.../hugegraph/api/traversers/TemplatePathsAPI.java | 168 -
.../hugegraph/api/traversers/TraverserAPI.java | 63 -
.../baidu/hugegraph/api/traversers/Vertices.java | 88 -
.../hugegraph/api/traversers/VerticesAPI.java | 126 -
.../api/traversers/WeightedShortestPathAPI.java | 104 -
.../hugegraph/api/variables/VariablesAPI.java | 123 -
.../baidu/hugegraph/auth/ConfigAuthenticator.java | 105 -
.../baidu/hugegraph/auth/ContextGremlinServer.java | 168 -
.../baidu/hugegraph/auth/HugeAuthenticator.java | 501 --
.../baidu/hugegraph/auth/HugeFactoryAuthProxy.java | 335 -
.../baidu/hugegraph/auth/HugeGraphAuthProxy.java | 1882 ----
.../hugegraph/auth/StandardAuthenticator.java | 198 -
.../hugegraph/auth/WsAndHttpBasicAuthHandler.java | 160 -
.../com/baidu/hugegraph/config/ServerOptions.java | 269 -
.../com/baidu/hugegraph/core/GraphManager.java | 594 --
.../java/com/baidu/hugegraph/define/Checkable.java | 29 -
.../com/baidu/hugegraph/define/UpdateStrategy.java | 205 -
.../java/com/baidu/hugegraph/define/WorkLoad.java | 51 -
.../baidu/hugegraph/license/LicenseVerifier.java | 132 -
.../hugegraph/license/LicenseVerifyManager.java | 251 -
.../com/baidu/hugegraph/metrics/MetricsModule.java | 302 -
.../com/baidu/hugegraph/metrics/MetricsUtil.java | 56 -
.../baidu/hugegraph/metrics/ServerReporter.java | 115 -
.../com/baidu/hugegraph/metrics/SystemMetrics.java | 140 -
.../hugegraph/rpc/RpcClientProviderWithAuth.java | 46 -
.../baidu/hugegraph/serializer/JsonSerializer.java | 326 -
.../com/baidu/hugegraph/serializer/Serializer.java | 101 -
.../baidu/hugegraph/server/ApplicationConfig.java | 196 -
.../com/baidu/hugegraph/server/RestServer.java | 217 -
.../com/baidu/hugegraph/version/ApiVersion.java | 131 -
.../main/java/org/apache/hugegraph/api/API.java | 195 +
.../org/apache/hugegraph/api/auth/AccessAPI.java | 215 +
.../org/apache/hugegraph/api/auth/BelongAPI.java | 206 +
.../org/apache/hugegraph/api/auth/GroupAPI.java | 183 +
.../org/apache/hugegraph/api/auth/LoginAPI.java | 160 +
.../org/apache/hugegraph/api/auth/ProjectAPI.java | 274 +
.../org/apache/hugegraph/api/auth/TargetAPI.java | 203 +
.../org/apache/hugegraph/api/auth/UserAPI.java | 234 +
.../hugegraph/api/filter/AuthenticationFilter.java | 291 +
.../hugegraph/api/filter/CompressInterceptor.java | 112 +
.../api/filter/DecompressInterceptor.java | 58 +
.../hugegraph/api/filter/ExceptionFilter.java | 288 +
.../hugegraph/api/filter/LoadDetectFilter.java | 110 +
.../hugegraph/api/filter/LoadReleaseFilter.java | 48 +
.../apache/hugegraph/api/filter/StatusFilter.java | 59 +
.../org/apache/hugegraph/api/graph/BatchAPI.java | 169 +
.../org/apache/hugegraph/api/graph/EdgeAPI.java | 574 ++
.../org/apache/hugegraph/api/graph/VertexAPI.java | 479 +
.../apache/hugegraph/api/gremlin/CypherAPI.java | 113 +
.../apache/hugegraph/api/gremlin/GremlinAPI.java | 87 +
.../hugegraph/api/gremlin/GremlinClient.java | 78 +
.../hugegraph/api/gremlin/GremlinQueryAPI.java | 109 +
.../org/apache/hugegraph/api/job/AlgorithmAPI.java | 84 +
.../org/apache/hugegraph/api/job/ComputerAPI.java | 87 +
.../org/apache/hugegraph/api/job/GremlinAPI.java | 210 +
.../org/apache/hugegraph/api/job/RebuildAPI.java | 98 +
.../java/org/apache/hugegraph/api/job/TaskAPI.java | 187 +
.../apache/hugegraph/api/metrics/MetricsAPI.java | 163 +
.../apache/hugegraph/api/profile/GraphsAPI.java | 287 +
.../apache/hugegraph/api/profile/ProfileAPI.java | 232 +
.../apache/hugegraph/api/profile/VersionAPI.java | 53 +
.../org/apache/hugegraph/api/raft/RaftAPI.java | 217 +
.../apache/hugegraph/api/schema/EdgeLabelAPI.java | 274 +
.../apache/hugegraph/api/schema/IndexLabelAPI.java | 294 +
.../hugegraph/api/schema/PropertyKeyAPI.java | 274 +
.../org/apache/hugegraph/api/schema/SchemaAPI.java | 70 +
.../hugegraph/api/schema/VertexLabelAPI.java | 266 +
.../hugegraph/api/traversers/AdamicAdarAPI.java | 89 +
.../api/traversers/AllShortestPathsAPI.java | 95 +
.../apache/hugegraph/api/traversers/CountAPI.java | 149 +
.../hugegraph/api/traversers/CrosspointsAPI.java | 91 +
.../api/traversers/CustomizedCrosspointsAPI.java | 200 +
.../api/traversers/CustomizedPathsAPI.java | 201 +
.../apache/hugegraph/api/traversers/EdgesAPI.java | 126 +
.../api/traversers/FusiformSimilarityAPI.java | 170 +
.../api/traversers/JaccardSimilarityAPI.java | 147 +
.../hugegraph/api/traversers/KneighborAPI.java | 191 +
.../apache/hugegraph/api/traversers/KoutAPI.java | 206 +
.../api/traversers/MultiNodeShortestPathAPI.java | 128 +
.../hugegraph/api/traversers/NeighborRankAPI.java | 154 +
.../apache/hugegraph/api/traversers/PathsAPI.java | 185 +
.../hugegraph/api/traversers/PersonalRankAPI.java | 142 +
.../apache/hugegraph/api/traversers/RaysAPI.java | 89 +
.../api/traversers/ResourceAllocationAPI.java | 90 +
.../apache/hugegraph/api/traversers/RingsAPI.java | 92 +
.../hugegraph/api/traversers/SameNeighborsAPI.java | 84 +
.../hugegraph/api/traversers/ShortestPathAPI.java | 96 +
.../traversers/SingleSourceShortestPathAPI.java | 101 +
.../hugegraph/api/traversers/TemplatePathsAPI.java | 168 +
.../hugegraph/api/traversers/TraverserAPI.java | 63 +
.../apache/hugegraph/api/traversers/Vertices.java | 88 +
.../hugegraph/api/traversers/VerticesAPI.java | 126 +
.../api/traversers/WeightedShortestPathAPI.java | 104 +
.../hugegraph/api/variables/VariablesAPI.java | 123 +
.../apache/hugegraph/auth/ConfigAuthenticator.java | 105 +
.../hugegraph/auth/ContextGremlinServer.java | 168 +
.../apache/hugegraph/auth/HugeAuthenticator.java | 501 ++
.../hugegraph/auth/HugeFactoryAuthProxy.java | 339 +
.../apache/hugegraph/auth/HugeGraphAuthProxy.java | 1882 ++++
.../hugegraph/auth/StandardAuthenticator.java | 198 +
.../hugegraph/auth/WsAndHttpBasicAuthHandler.java | 160 +
.../org/apache/hugegraph/config/ServerOptions.java | 269 +
.../org/apache/hugegraph/core/GraphManager.java | 594 ++
.../org/apache/hugegraph/define/Checkable.java | 29 +
.../apache/hugegraph/define/UpdateStrategy.java | 205 +
.../java/org/apache/hugegraph/define/WorkLoad.java | 51 +
.../apache/hugegraph/license/LicenseVerifier.java | 132 +
.../hugegraph/license/LicenseVerifyManager.java | 251 +
.../apache/hugegraph/metrics/MetricsModule.java | 304 +
.../org/apache/hugegraph/metrics/MetricsUtil.java | 56 +
.../apache/hugegraph/metrics/ServerReporter.java | 115 +
.../apache/hugegraph/metrics/SystemMetrics.java | 140 +
.../hugegraph/rpc/RpcClientProviderWithAuth.java | 46 +
.../hugegraph/serializer/JsonSerializer.java | 326 +
.../apache/hugegraph/serializer/Serializer.java | 101 +
.../apache/hugegraph/server/ApplicationConfig.java | 196 +
.../org/apache/hugegraph/server/RestServer.java | 217 +
.../org/apache/hugegraph/version/ApiVersion.java | 131 +
hugegraph-cassandra/pom.xml | 13 +-
.../store/cassandra/CassandraBackendEntry.java | 43 -
.../store/cassandra/CassandraEntryIterator.java | 196 -
.../backend/store/cassandra/CassandraFeatures.java | 134 -
.../backend/store/cassandra/CassandraMetrics.java | 327 -
.../backend/store/cassandra/CassandraOptions.java | 135 -
.../store/cassandra/CassandraSerializer.java | 226 -
.../store/cassandra/CassandraSessionPool.java | 276 -
.../backend/store/cassandra/CassandraShard.java | 321 -
.../backend/store/cassandra/CassandraStore.java | 825 --
.../store/cassandra/CassandraStoreProvider.java | 77 -
.../backend/store/cassandra/CassandraTable.java | 683 --
.../backend/store/cassandra/CassandraTables.java | 996 ---
.../store/cassandra/CassandraBackendEntry.java | 43 +
.../store/cassandra/CassandraEntryIterator.java | 196 +
.../backend/store/cassandra/CassandraFeatures.java | 134 +
.../backend/store/cassandra/CassandraMetrics.java | 327 +
.../backend/store/cassandra/CassandraOptions.java | 135 +
.../store/cassandra/CassandraSerializer.java | 226 +
.../store/cassandra/CassandraSessionPool.java | 276 +
.../backend/store/cassandra/CassandraShard.java | 322 +
.../backend/store/cassandra/CassandraStore.java | 825 ++
.../store/cassandra/CassandraStoreProvider.java | 77 +
.../backend/store/cassandra/CassandraTable.java | 683 ++
.../backend/store/cassandra/CassandraTables.java | 996 +++
hugegraph-core/pom.xml | 6 +-
.../java/com/baidu/hugegraph/HugeException.java | 64 -
.../main/java/com/baidu/hugegraph/HugeFactory.java | 171 -
.../main/java/com/baidu/hugegraph/HugeGraph.java | 325 -
.../java/com/baidu/hugegraph/HugeGraphParams.java | 95 -
.../com/baidu/hugegraph/StandardHugeGraph.java | 1619 ----
.../com/baidu/hugegraph/analyzer/Analyzer.java | 27 -
.../baidu/hugegraph/analyzer/AnalyzerFactory.java | 100 -
.../com/baidu/hugegraph/analyzer/AnsjAnalyzer.java | 87 -
.../baidu/hugegraph/analyzer/HanLPAnalyzer.java | 106 -
.../com/baidu/hugegraph/analyzer/IKAnalyzer.java | 71 -
.../baidu/hugegraph/analyzer/JcsegAnalyzer.java | 82 -
.../baidu/hugegraph/analyzer/JiebaAnalyzer.java | 62 -
.../baidu/hugegraph/analyzer/MMSeg4JAnalyzer.java | 91 -
.../baidu/hugegraph/analyzer/SmartCNAnalyzer.java | 62 -
.../com/baidu/hugegraph/auth/AuthConstant.java | 29 -
.../java/com/baidu/hugegraph/auth/AuthManager.java | 131 -
.../com/baidu/hugegraph/auth/EntityManager.java | 200 -
.../java/com/baidu/hugegraph/auth/HugeAccess.java | 234 -
.../java/com/baidu/hugegraph/auth/HugeBelong.java | 201 -
.../java/com/baidu/hugegraph/auth/HugeGroup.java | 200 -
.../com/baidu/hugegraph/auth/HugePermission.java | 67 -
.../java/com/baidu/hugegraph/auth/HugeProject.java | 313 -
.../com/baidu/hugegraph/auth/HugeResource.java | 356 -
.../java/com/baidu/hugegraph/auth/HugeTarget.java | 263 -
.../java/com/baidu/hugegraph/auth/HugeUser.java | 286 -
.../baidu/hugegraph/auth/RelationshipManager.java | 243 -
.../com/baidu/hugegraph/auth/ResourceObject.java | 95 -
.../com/baidu/hugegraph/auth/ResourceType.java | 140 -
.../com/baidu/hugegraph/auth/RolePermission.java | 234 -
.../com/baidu/hugegraph/auth/SchemaDefine.java | 310 -
.../baidu/hugegraph/auth/StandardAuthManager.java | 729 --
.../com/baidu/hugegraph/auth/TokenGenerator.java | 70 -
.../com/baidu/hugegraph/auth/UserWithRole.java | 51 -
.../baidu/hugegraph/backend/BackendException.java | 54 -
.../com/baidu/hugegraph/backend/LocalCounter.java | 79 -
.../com/baidu/hugegraph/backend/Transaction.java | 33 -
.../hugegraph/backend/cache/AbstractCache.java | 300 -
.../com/baidu/hugegraph/backend/cache/Cache.java | 71 -
.../hugegraph/backend/cache/CacheManager.java | 156 -
.../hugegraph/backend/cache/CacheNotifier.java | 38 -
.../backend/cache/CachedBackendStore.java | 254 -
.../backend/cache/CachedGraphTransaction.java | 428 -
.../backend/cache/CachedSchemaTransaction.java | 446 -
.../baidu/hugegraph/backend/cache/LevelCache.java | 122 -
.../hugegraph/backend/cache/OffheapCache.java | 410 -
.../baidu/hugegraph/backend/cache/RamCache.java | 517 --
.../com/baidu/hugegraph/backend/id/EdgeId.java | 306 -
.../java/com/baidu/hugegraph/backend/id/Id.java | 88 -
.../baidu/hugegraph/backend/id/IdGenerator.java | 446 -
.../com/baidu/hugegraph/backend/id/IdUtil.java | 150 -
.../hugegraph/backend/id/SnowflakeIdGenerator.java | 178 -
.../hugegraph/backend/id/SplicingIdGenerator.java | 134 -
.../com/baidu/hugegraph/backend/page/IdHolder.java | 270 -
.../baidu/hugegraph/backend/page/IdHolderList.java | 65 -
.../hugegraph/backend/page/PageEntryIterator.java | 131 -
.../com/baidu/hugegraph/backend/page/PageIds.java | 58 -
.../com/baidu/hugegraph/backend/page/PageInfo.java | 119 -
.../baidu/hugegraph/backend/page/PageState.java | 113 -
.../baidu/hugegraph/backend/page/QueryList.java | 368 -
.../backend/page/SortByCountIdHolderList.java | 105 -
.../baidu/hugegraph/backend/query/Aggregate.java | 109 -
.../backend/query/BatchConditionQuery.java | 85 -
.../baidu/hugegraph/backend/query/Condition.java | 814 --
.../hugegraph/backend/query/ConditionQuery.java | 876 --
.../backend/query/ConditionQueryFlatten.java | 517 --
.../hugegraph/backend/query/IdPrefixQuery.java | 109 -
.../com/baidu/hugegraph/backend/query/IdQuery.java | 192 -
.../hugegraph/backend/query/IdRangeQuery.java | 113 -
.../com/baidu/hugegraph/backend/query/Query.java | 583 --
.../hugegraph/backend/query/QueryResults.java | 330 -
.../backend/serializer/AbstractSerializer.java | 94 -
.../backend/serializer/BinaryBackendEntry.java | 278 -
.../backend/serializer/BinaryEntryIterator.java | 144 -
.../serializer/BinaryScatterSerializer.java | 94 -
.../backend/serializer/BinarySerializer.java | 1316 ---
.../hugegraph/backend/serializer/BytesBuffer.java | 933 --
.../backend/serializer/GraphSerializer.java | 57 -
.../backend/serializer/MergeIterator.java | 103 -
.../backend/serializer/SchemaSerializer.java | 46 -
.../backend/serializer/SerializerFactory.java | 86 -
.../backend/serializer/TableBackendEntry.java | 298 -
.../backend/serializer/TableSerializer.java | 713 --
.../backend/serializer/TextBackendEntry.java | 379 -
.../backend/serializer/TextSerializer.java | 912 --
.../backend/store/AbstractBackendStore.java | 87 -
.../store/AbstractBackendStoreProvider.java | 245 -
.../hugegraph/backend/store/BackendAction.java | 50 -
.../hugegraph/backend/store/BackendEntry.java | 226 -
.../backend/store/BackendEntryIterator.java | 221 -
.../hugegraph/backend/store/BackendFeatures.java | 77 -
.../hugegraph/backend/store/BackendMetrics.java | 49 -
.../hugegraph/backend/store/BackendMutation.java | 346 -
.../backend/store/BackendProviderFactory.java | 111 -
.../hugegraph/backend/store/BackendSession.java | 124 -
.../backend/store/BackendSessionPool.java | 171 -
.../hugegraph/backend/store/BackendStore.java | 182 -
.../hugegraph/backend/store/BackendStoreInfo.java | 57 -
.../backend/store/BackendStoreProvider.java | 78 -
.../hugegraph/backend/store/BackendTable.java | 382 -
.../hugegraph/backend/store/MetaDispatcher.java | 47 -
.../baidu/hugegraph/backend/store/MetaHandler.java | 25 -
.../com/baidu/hugegraph/backend/store/Shard.java | 71 -
.../hugegraph/backend/store/SystemSchemaStore.java | 77 -
.../baidu/hugegraph/backend/store/TableDefine.java | 89 -
.../backend/store/memory/InMemoryDBStore.java | 499 --
.../store/memory/InMemoryDBStoreProvider.java | 108 -
.../backend/store/memory/InMemoryDBTable.java | 359 -
.../backend/store/memory/InMemoryDBTables.java | 570 --
.../backend/store/memory/InMemoryMetrics.java | 33 -
.../backend/store/raft/RaftAddPeerJob.java | 50 -
.../backend/store/raft/RaftBackendStore.java | 296 -
.../store/raft/RaftBackendStoreProvider.java | 278 -
.../hugegraph/backend/store/raft/RaftClosure.java | 95 -
.../hugegraph/backend/store/raft/RaftContext.java | 456 -
.../backend/store/raft/RaftException.java | 55 -
.../backend/store/raft/RaftGroupManager.java | 39 -
.../backend/store/raft/RaftGroupManagerImpl.java | 156 -
.../hugegraph/backend/store/raft/RaftNode.java | 367 -
.../backend/store/raft/RaftRemovePeerJob.java | 50 -
.../hugegraph/backend/store/raft/RaftResult.java | 65 -
.../backend/store/raft/RaftStoreClosure.java | 36 -
.../hugegraph/backend/store/raft/StoreCommand.java | 92 -
.../backend/store/raft/StoreSerializer.java | 150 -
.../backend/store/raft/StoreSnapshotFile.java | 246 -
.../backend/store/raft/StoreStateMachine.java | 251 -
.../backend/store/raft/rpc/ListPeersProcessor.java | 76 -
.../backend/store/raft/rpc/RpcForwarder.java | 162 -
.../backend/store/raft/rpc/SetLeaderProcessor.java | 70 -
.../store/raft/rpc/StoreCommandProcessor.java | 85 -
.../hugegraph/backend/store/ram/IntIntMap.java | 78 -
.../hugegraph/backend/store/ram/IntLongMap.java | 96 -
.../hugegraph/backend/store/ram/IntObjectMap.java | 90 -
.../baidu/hugegraph/backend/store/ram/RamMap.java | 35 -
.../hugegraph/backend/store/ram/RamTable.java | 593 --
.../hugegraph/backend/tx/AbstractTransaction.java | 432 -
.../backend/tx/GraphIndexTransaction.java | 1950 ----
.../hugegraph/backend/tx/GraphTransaction.java | 2091 -----
.../hugegraph/backend/tx/IndexableTransaction.java | 88 -
.../backend/tx/SchemaIndexTransaction.java | 122 -
.../hugegraph/backend/tx/SchemaTransaction.java | 686 --
.../com/baidu/hugegraph/config/AuthOptions.java | 131 -
.../com/baidu/hugegraph/config/CoreOptions.java | 631 --
.../java/com/baidu/hugegraph/election/Config.java | 35 -
.../election/RoleElectionStateMachine.java | 27 -
.../election/RoleElectionStateMachineImpl.java | 312 -
.../com/baidu/hugegraph/election/RoleTypeData.java | 91 -
.../hugegraph/election/RoleTypeDataAdapter.java | 29 -
.../hugegraph/election/StateMachineCallback.java | 35 -
.../hugegraph/election/StateMachineContext.java | 37 -
.../hugegraph/exception/ConnectionException.java | 40 -
.../hugegraph/exception/ExistedException.java | 36 -
.../hugegraph/exception/HugeGremlinException.java | 46 -
.../hugegraph/exception/LimitExceedException.java | 35 -
.../hugegraph/exception/NoIndexException.java | 35 -
.../hugegraph/exception/NotAllowException.java | 35 -
.../hugegraph/exception/NotFoundException.java | 39 -
.../hugegraph/exception/NotSupportException.java | 36 -
.../hugegraph/io/GraphSONSchemaSerializer.java | 131 -
.../baidu/hugegraph/io/HugeGraphIoRegistry.java | 44 -
.../com/baidu/hugegraph/io/HugeGraphSONModule.java | 601 --
.../com/baidu/hugegraph/io/HugeGryoModule.java | 201 -
.../java/com/baidu/hugegraph/job/AlgorithmJob.java | 71 -
.../java/com/baidu/hugegraph/job/ComputerJob.java | 76 -
.../java/com/baidu/hugegraph/job/EphemeralJob.java | 34 -
.../baidu/hugegraph/job/EphemeralJobBuilder.java | 86 -
.../java/com/baidu/hugegraph/job/GremlinJob.java | 133 -
.../src/main/java/com/baidu/hugegraph/job/Job.java | 27 -
.../java/com/baidu/hugegraph/job/JobBuilder.java | 101 -
.../main/java/com/baidu/hugegraph/job/SysJob.java | 45 -
.../main/java/com/baidu/hugegraph/job/UserJob.java | 45 -
.../hugegraph/job/algorithm/AbstractAlgorithm.java | 647 --
.../baidu/hugegraph/job/algorithm/Algorithm.java | 35 -
.../hugegraph/job/algorithm/AlgorithmPool.java | 102 -
.../hugegraph/job/algorithm/BfsTraverser.java | 154 -
.../baidu/hugegraph/job/algorithm/Consumers.java | 206 -
.../job/algorithm/CountEdgeAlgorithm.java | 80 -
.../job/algorithm/CountVertexAlgorithm.java | 80 -
.../job/algorithm/SubgraphStatAlgorithm.java | 223 -
.../job/algorithm/cent/AbstractCentAlgorithm.java | 211 -
.../cent/BetweennessCentralityAlgorithm.java | 150 -
.../cent/BetweennessCentralityAlgorithmV2.java | 176 -
.../cent/ClosenessCentralityAlgorithm.java | 108 -
.../cent/ClosenessCentralityAlgorithmV2.java | 135 -
.../algorithm/cent/DegreeCentralityAlgorithm.java | 164 -
.../cent/EigenvectorCentralityAlgorithm.java | 102 -
.../algorithm/cent/StressCentralityAlgorithm.java | 106 -
.../cent/StressCentralityAlgorithmV2.java | 182 -
.../job/algorithm/comm/AbstractCommAlgorithm.java | 80 -
.../comm/ClusterCoefficientAlgorithm.java | 85 -
.../job/algorithm/comm/KCoreAlgorithm.java | 294 -
.../job/algorithm/comm/LouvainAlgorithm.java | 123 -
.../job/algorithm/comm/LouvainTraverser.java | 922 --
.../hugegraph/job/algorithm/comm/LpaAlgorithm.java | 273 -
.../job/algorithm/comm/TriangleCountAlgorithm.java | 241 -
.../job/algorithm/comm/WeakConnectedComponent.java | 221 -
.../job/algorithm/path/RingsDetectAlgorithm.java | 148 -
.../job/algorithm/rank/PageRankAlgorithm.java | 338 -
.../similarity/FusiformSimilarityAlgorithm.java | 200 -
.../hugegraph/job/computer/AbstractComputer.java | 269 -
.../com/baidu/hugegraph/job/computer/Computer.java | 35 -
.../baidu/hugegraph/job/computer/ComputerPool.java | 55 -
.../hugegraph/job/computer/LouvainComputer.java | 128 -
.../baidu/hugegraph/job/computer/LpaComputer.java | 73 -
.../hugegraph/job/computer/PageRankComputer.java | 70 -
.../job/computer/TriangleCountComputer.java | 52 -
.../computer/WeakConnectedComponentComputer.java | 52 -
.../hugegraph/job/schema/EdgeLabelRemoveJob.java | 87 -
.../hugegraph/job/schema/IndexLabelRebuildJob.java | 193 -
.../hugegraph/job/schema/IndexLabelRemoveJob.java | 84 -
.../job/schema/OlapPropertyKeyClearJob.java | 93 -
.../job/schema/OlapPropertyKeyCreateJob.java | 42 -
.../job/schema/OlapPropertyKeyRemoveJob.java | 52 -
.../com/baidu/hugegraph/job/schema/SchemaJob.java | 126 -
.../hugegraph/job/schema/VertexLabelRemoveJob.java | 106 -
.../job/system/DeleteExpiredElementJob.java | 66 -
.../job/system/DeleteExpiredIndexJob.java | 96 -
.../hugegraph/job/system/DeleteExpiredJob.java | 90 -
.../baidu/hugegraph/job/system/JobCounters.java | 119 -
.../hugegraph/plugin/HugeGraphGremlinPlugin.java | 73 -
.../baidu/hugegraph/plugin/HugeGraphPlugin.java | 52 -
.../hugegraph/rpc/RpcServiceConfig4Client.java | 37 -
.../hugegraph/rpc/RpcServiceConfig4Server.java | 32 -
.../java/com/baidu/hugegraph/schema/EdgeLabel.java | 169 -
.../com/baidu/hugegraph/schema/IndexLabel.java | 285 -
.../com/baidu/hugegraph/schema/PropertyKey.java | 414 -
.../com/baidu/hugegraph/schema/SchemaElement.java | 222 -
.../com/baidu/hugegraph/schema/SchemaLabel.java | 181 -
.../com/baidu/hugegraph/schema/SchemaManager.java | 145 -
.../java/com/baidu/hugegraph/schema/Userdata.java | 66 -
.../com/baidu/hugegraph/schema/VertexLabel.java | 137 -
.../hugegraph/schema/builder/AbstractBuilder.java | 112 -
.../hugegraph/schema/builder/EdgeLabelBuilder.java | 627 --
.../schema/builder/IndexLabelBuilder.java | 760 --
.../schema/builder/PropertyKeyBuilder.java | 468 -
.../hugegraph/schema/builder/SchemaBuilder.java | 42 -
.../schema/builder/VertexLabelBuilder.java | 605 --
.../hugegraph/security/HugeSecurityManager.java | 508 --
.../com/baidu/hugegraph/structure/GraphType.java | 26 -
.../com/baidu/hugegraph/structure/HugeEdge.java | 541 --
.../hugegraph/structure/HugeEdgeProperty.java | 75 -
.../com/baidu/hugegraph/structure/HugeElement.java | 546 --
.../baidu/hugegraph/structure/HugeFeatures.java | 416 -
.../com/baidu/hugegraph/structure/HugeIndex.java | 299 -
.../baidu/hugegraph/structure/HugeProperty.java | 115 -
.../com/baidu/hugegraph/structure/HugeVertex.java | 708 --
.../hugegraph/structure/HugeVertexProperty.java | 88 -
.../com/baidu/hugegraph/task/HugeServerInfo.java | 334 -
.../java/com/baidu/hugegraph/task/HugeTask.java | 722 --
.../baidu/hugegraph/task/ServerInfoManager.java | 402 -
.../hugegraph/task/StandardTaskScheduler.java | 862 --
.../com/baidu/hugegraph/task/TaskCallable.java | 191 -
.../java/com/baidu/hugegraph/task/TaskManager.java | 360 -
.../com/baidu/hugegraph/task/TaskScheduler.java | 67 -
.../java/com/baidu/hugegraph/task/TaskStatus.java | 72 -
.../algorithm/CollectionPathsTraverser.java | 279 -
.../traversal/algorithm/CountTraverser.java | 139 -
.../algorithm/CustomizePathsTraverser.java | 239 -
.../algorithm/CustomizedCrosspointsTraverser.java | 222 -
.../algorithm/FusiformSimilarityTraverser.java | 322 -
.../traversal/algorithm/HugeTraverser.java | 744 --
.../algorithm/JaccardSimilarTraverser.java | 212 -
.../traversal/algorithm/KneighborTraverser.java | 106 -
.../traversal/algorithm/KoutTraverser.java | 149 -
.../algorithm/MultiNodeShortestPathTraverser.java | 127 -
.../traversal/algorithm/NeighborRankTraverser.java | 307 -
.../traversal/algorithm/OltpTraverser.java | 180 -
.../traversal/algorithm/PathTraverser.java | 226 -
.../traversal/algorithm/PathsTraverser.java | 181 -
.../traversal/algorithm/PersonalRankTraverser.java | 172 -
.../traversal/algorithm/PredictionTraverser.java | 83 -
.../traversal/algorithm/SameNeighborTraverser.java | 62 -
.../traversal/algorithm/ShortestPathTraverser.java | 252 -
.../SingleSourceShortestPathTraverser.java | 295 -
.../traversal/algorithm/SubGraphTraverser.java | 304 -
.../algorithm/TemplatePathsTraverser.java | 281 -
.../algorithm/records/AbstractRecords.java | 83 -
.../records/DoubleWayMultiPathsRecords.java | 207 -
.../algorithm/records/KneighborRecords.java | 75 -
.../traversal/algorithm/records/KoutRecords.java | 66 -
.../traversal/algorithm/records/PathsRecords.java | 60 -
.../traversal/algorithm/records/Records.java | 41 -
.../algorithm/records/ShortestPathRecords.java | 117 -
.../records/SingleWayMultiPathsRecords.java | 187 -
.../algorithm/records/record/Int2ArrayRecord.java | 67 -
.../algorithm/records/record/Int2IntRecord.java | 76 -
.../algorithm/records/record/Int2SetRecord.java | 75 -
.../traversal/algorithm/records/record/Record.java | 37 -
.../algorithm/records/record/RecordFactory.java | 50 -
.../algorithm/records/record/RecordType.java | 69 -
.../algorithm/records/record/SyncRecord.java | 87 -
.../traversal/algorithm/steps/EdgeStep.java | 147 -
.../traversal/algorithm/steps/RepeatEdgeStep.java | 108 -
.../algorithm/steps/WeightedEdgeStep.java | 104 -
.../strategy/ConcurrentTraverseStrategy.java | 73 -
.../algorithm/strategy/SingleTraverseStrategy.java | 75 -
.../algorithm/strategy/TraverseStrategy.java | 51 -
.../hugegraph/traversal/optimize/ConditionP.java | 57 -
.../traversal/optimize/HugeCountStep.java | 79 -
.../traversal/optimize/HugeCountStepStrategy.java | 126 -
.../traversal/optimize/HugeGraphStep.java | 222 -
.../traversal/optimize/HugeGraphStepStrategy.java | 79 -
.../traversal/optimize/HugeScriptTraversal.java | 122 -
.../traversal/optimize/HugeVertexStep.java | 255 -
.../traversal/optimize/HugeVertexStepByBatch.java | 140 -
.../traversal/optimize/HugeVertexStepStrategy.java | 135 -
.../hugegraph/traversal/optimize/QueryHolder.java | 73 -
.../baidu/hugegraph/traversal/optimize/Text.java | 34 -
.../traversal/optimize/TraversalUtil.java | 972 --
.../java/com/baidu/hugegraph/type/HugeType.java | 197 -
.../java/com/baidu/hugegraph/type/Idfiable.java | 27 -
.../java/com/baidu/hugegraph/type/Indexable.java | 29 -
.../java/com/baidu/hugegraph/type/Nameable.java | 30 -
.../com/baidu/hugegraph/type/Propertiable.java | 29 -
.../java/com/baidu/hugegraph/type/Typeable.java | 26 -
.../com/baidu/hugegraph/type/define/Action.java | 76 -
.../baidu/hugegraph/type/define/AggregateType.java | 93 -
.../baidu/hugegraph/type/define/Cardinality.java | 85 -
.../hugegraph/type/define/CollectionType.java | 67 -
.../com/baidu/hugegraph/type/define/DataType.java | 220 -
.../baidu/hugegraph/type/define/Directions.java | 117 -
.../com/baidu/hugegraph/type/define/Frequency.java | 51 -
.../com/baidu/hugegraph/type/define/GraphMode.java | 74 -
.../baidu/hugegraph/type/define/GraphReadMode.java | 50 -
.../com/baidu/hugegraph/type/define/HugeKeys.java | 105 -
.../baidu/hugegraph/type/define/IdStrategy.java | 71 -
.../com/baidu/hugegraph/type/define/IndexType.java | 122 -
.../com/baidu/hugegraph/type/define/NodeRole.java | 63 -
.../baidu/hugegraph/type/define/SchemaStatus.java | 65 -
.../baidu/hugegraph/type/define/SerialEnum.java | 69 -
.../com/baidu/hugegraph/type/define/WriteType.java | 67 -
.../main/java/com/baidu/hugegraph/util/Blob.java | 70 -
.../com/baidu/hugegraph/util/CompressUtil.java | 247 -
.../java/com/baidu/hugegraph/util/ConfigUtil.java | 152 -
.../java/com/baidu/hugegraph/util/Consumers.java | 319 -
.../java/com/baidu/hugegraph/util/CopyUtil.java | 88 -
.../main/java/com/baidu/hugegraph/util/Events.java | 35 -
.../util/FixedTimerWindowRateLimiter.java | 62 -
.../util/FixedWatchWindowRateLimiter.java | 62 -
.../java/com/baidu/hugegraph/util/GZipUtil.java | 76 -
.../java/com/baidu/hugegraph/util/JsonUtil.java | 159 -
.../java/com/baidu/hugegraph/util/KryoUtil.java | 99 -
.../java/com/baidu/hugegraph/util/LZ4Util.java | 95 -
.../java/com/baidu/hugegraph/util/LockUtil.java | 353 -
.../com/baidu/hugegraph/util/ParameterUtil.java | 78 -
.../java/com/baidu/hugegraph/util/RateLimiter.java | 45 -
.../java/com/baidu/hugegraph/util/Reflection.java | 116 -
.../com/baidu/hugegraph/util/StringEncoding.java | 208 -
.../util/collection/CollectionFactory.java | 283 -
.../com/baidu/hugegraph/util/collection/IdSet.java | 120 -
.../hugegraph/util/collection/Int2IntsMap.java | 218 -
.../hugegraph/util/collection/IntIterator.java | 213 -
.../baidu/hugegraph/util/collection/IntMap.java | 602 --
.../baidu/hugegraph/util/collection/IntSet.java | 593 --
.../util/collection/ObjectIntMapping.java | 29 -
.../util/collection/ObjectIntMappingFactory.java | 138 -
.../baidu/hugegraph/variables/HugeVariables.java | 393 -
.../com/baidu/hugegraph/version/CoreVersion.java | 47 -
.../java/org/apache/hugegraph/HugeException.java | 64 +
.../java/org/apache/hugegraph/HugeFactory.java | 171 +
.../main/java/org/apache/hugegraph/HugeGraph.java | 325 +
.../java/org/apache/hugegraph/HugeGraphParams.java | 95 +
.../org/apache/hugegraph/StandardHugeGraph.java | 1617 ++++
.../org/apache/hugegraph/analyzer/Analyzer.java | 27 +
.../apache/hugegraph/analyzer/AnalyzerFactory.java | 100 +
.../apache/hugegraph/analyzer/AnsjAnalyzer.java | 87 +
.../apache/hugegraph/analyzer/HanLPAnalyzer.java | 106 +
.../org/apache/hugegraph/analyzer/IKAnalyzer.java | 71 +
.../apache/hugegraph/analyzer/JcsegAnalyzer.java | 82 +
.../apache/hugegraph/analyzer/JiebaAnalyzer.java | 62 +
.../apache/hugegraph/analyzer/MMSeg4JAnalyzer.java | 91 +
.../apache/hugegraph/analyzer/SmartCNAnalyzer.java | 62 +
.../org/apache/hugegraph/auth/AuthConstant.java | 29 +
.../org/apache/hugegraph/auth/AuthManager.java | 131 +
.../org/apache/hugegraph/auth/EntityManager.java | 200 +
.../java/org/apache/hugegraph/auth/HugeAccess.java | 234 +
.../java/org/apache/hugegraph/auth/HugeBelong.java | 201 +
.../java/org/apache/hugegraph/auth/HugeGroup.java | 200 +
.../org/apache/hugegraph/auth/HugePermission.java | 67 +
.../org/apache/hugegraph/auth/HugeProject.java | 313 +
.../org/apache/hugegraph/auth/HugeResource.java | 356 +
.../java/org/apache/hugegraph/auth/HugeTarget.java | 263 +
.../java/org/apache/hugegraph/auth/HugeUser.java | 286 +
.../apache/hugegraph/auth/RelationshipManager.java | 243 +
.../org/apache/hugegraph/auth/ResourceObject.java | 95 +
.../org/apache/hugegraph/auth/ResourceType.java | 140 +
.../org/apache/hugegraph/auth/RolePermission.java | 234 +
.../org/apache/hugegraph/auth/SchemaDefine.java | 311 +
.../apache/hugegraph/auth/StandardAuthManager.java | 729 ++
.../org/apache/hugegraph/auth/TokenGenerator.java | 70 +
.../org/apache/hugegraph/auth/UserWithRole.java | 51 +
.../apache/hugegraph/backend/BackendException.java | 54 +
.../org/apache/hugegraph/backend/LocalCounter.java | 79 +
.../org/apache/hugegraph/backend/Transaction.java | 33 +
.../hugegraph/backend/cache/AbstractCache.java | 300 +
.../org/apache/hugegraph/backend/cache/Cache.java | 71 +
.../hugegraph/backend/cache/CacheManager.java | 156 +
.../hugegraph/backend/cache/CacheNotifier.java | 38 +
.../backend/cache/CachedBackendStore.java | 254 +
.../backend/cache/CachedGraphTransaction.java | 428 +
.../backend/cache/CachedSchemaTransaction.java | 446 +
.../apache/hugegraph/backend/cache/LevelCache.java | 122 +
.../hugegraph/backend/cache/OffheapCache.java | 410 +
.../apache/hugegraph/backend/cache/RamCache.java | 517 ++
.../org/apache/hugegraph/backend/id/EdgeId.java | 306 +
.../java/org/apache/hugegraph/backend/id/Id.java | 88 +
.../apache/hugegraph/backend/id/IdGenerator.java | 446 +
.../org/apache/hugegraph/backend/id/IdUtil.java | 150 +
.../hugegraph/backend/id/SnowflakeIdGenerator.java | 178 +
.../hugegraph/backend/id/SplicingIdGenerator.java | 134 +
.../apache/hugegraph/backend/page/IdHolder.java | 270 +
.../hugegraph/backend/page/IdHolderList.java | 65 +
.../hugegraph/backend/page/PageEntryIterator.java | 131 +
.../org/apache/hugegraph/backend/page/PageIds.java | 58 +
.../apache/hugegraph/backend/page/PageInfo.java | 119 +
.../apache/hugegraph/backend/page/PageState.java | 113 +
.../apache/hugegraph/backend/page/QueryList.java | 368 +
.../backend/page/SortByCountIdHolderList.java | 105 +
.../apache/hugegraph/backend/query/Aggregate.java | 109 +
.../backend/query/BatchConditionQuery.java | 85 +
.../apache/hugegraph/backend/query/Condition.java | 814 ++
.../hugegraph/backend/query/ConditionQuery.java | 875 ++
.../backend/query/ConditionQueryFlatten.java | 517 ++
.../hugegraph/backend/query/IdPrefixQuery.java | 109 +
.../apache/hugegraph/backend/query/IdQuery.java | 192 +
.../hugegraph/backend/query/IdRangeQuery.java | 113 +
.../org/apache/hugegraph/backend/query/Query.java | 583 ++
.../hugegraph/backend/query/QueryResults.java | 330 +
.../backend/serializer/AbstractSerializer.java | 94 +
.../backend/serializer/BinaryBackendEntry.java | 278 +
.../backend/serializer/BinaryEntryIterator.java | 144 +
.../serializer/BinaryScatterSerializer.java | 94 +
.../backend/serializer/BinarySerializer.java | 1314 +++
.../hugegraph/backend/serializer/BytesBuffer.java | 932 ++
.../backend/serializer/GraphSerializer.java | 57 +
.../backend/serializer/MergeIterator.java | 103 +
.../backend/serializer/SchemaSerializer.java | 46 +
.../backend/serializer/SerializerFactory.java | 86 +
.../backend/serializer/TableBackendEntry.java | 298 +
.../backend/serializer/TableSerializer.java | 713 ++
.../backend/serializer/TextBackendEntry.java | 379 +
.../backend/serializer/TextSerializer.java | 911 ++
.../backend/store/AbstractBackendStore.java | 87 +
.../store/AbstractBackendStoreProvider.java | 245 +
.../hugegraph/backend/store/BackendAction.java | 50 +
.../hugegraph/backend/store/BackendEntry.java | 226 +
.../backend/store/BackendEntryIterator.java | 221 +
.../hugegraph/backend/store/BackendFeatures.java | 77 +
.../hugegraph/backend/store/BackendMetrics.java | 49 +
.../hugegraph/backend/store/BackendMutation.java | 346 +
.../backend/store/BackendProviderFactory.java | 111 +
.../hugegraph/backend/store/BackendSession.java | 124 +
.../backend/store/BackendSessionPool.java | 171 +
.../hugegraph/backend/store/BackendStore.java | 182 +
.../hugegraph/backend/store/BackendStoreInfo.java | 57 +
.../backend/store/BackendStoreProvider.java | 78 +
.../hugegraph/backend/store/BackendTable.java | 382 +
.../hugegraph/backend/store/MetaDispatcher.java | 47 +
.../hugegraph/backend/store/MetaHandler.java | 25 +
.../org/apache/hugegraph/backend/store/Shard.java | 71 +
.../hugegraph/backend/store/SystemSchemaStore.java | 77 +
.../hugegraph/backend/store/TableDefine.java | 89 +
.../backend/store/memory/InMemoryDBStore.java | 500 ++
.../store/memory/InMemoryDBStoreProvider.java | 108 +
.../backend/store/memory/InMemoryDBTable.java | 359 +
.../backend/store/memory/InMemoryDBTables.java | 570 ++
.../backend/store/memory/InMemoryMetrics.java | 33 +
.../backend/store/raft/RaftAddPeerJob.java | 50 +
.../backend/store/raft/RaftBackendStore.java | 296 +
.../store/raft/RaftBackendStoreProvider.java | 278 +
.../hugegraph/backend/store/raft/RaftClosure.java | 95 +
.../hugegraph/backend/store/raft/RaftContext.java | 456 +
.../backend/store/raft/RaftException.java | 55 +
.../backend/store/raft/RaftGroupManager.java | 39 +
.../backend/store/raft/RaftGroupManagerImpl.java | 156 +
.../hugegraph/backend/store/raft/RaftNode.java | 367 +
.../backend/store/raft/RaftRemovePeerJob.java | 50 +
.../hugegraph/backend/store/raft/RaftResult.java | 65 +
.../backend/store/raft/RaftStoreClosure.java | 36 +
.../hugegraph/backend/store/raft/StoreCommand.java | 92 +
.../backend/store/raft/StoreSerializer.java | 150 +
.../backend/store/raft/StoreSnapshotFile.java | 246 +
.../backend/store/raft/StoreStateMachine.java | 251 +
.../backend/store/raft/rpc/ListPeersProcessor.java | 76 +
.../backend/store/raft/rpc/RpcForwarder.java | 162 +
.../backend/store/raft/rpc/SetLeaderProcessor.java | 70 +
.../store/raft/rpc/StoreCommandProcessor.java | 85 +
.../hugegraph/backend/store/ram/IntIntMap.java | 78 +
.../hugegraph/backend/store/ram/IntLongMap.java | 96 +
.../hugegraph/backend/store/ram/IntObjectMap.java | 90 +
.../apache/hugegraph/backend/store/ram/RamMap.java | 35 +
.../hugegraph/backend/store/ram/RamTable.java | 593 ++
.../hugegraph/backend/tx/AbstractTransaction.java | 432 +
.../backend/tx/GraphIndexTransaction.java | 1951 ++++
.../hugegraph/backend/tx/GraphTransaction.java | 2091 +++++
.../hugegraph/backend/tx/IndexableTransaction.java | 88 +
.../backend/tx/SchemaIndexTransaction.java | 122 +
.../hugegraph/backend/tx/SchemaTransaction.java | 686 ++
.../org/apache/hugegraph/config/AuthOptions.java | 131 +
.../org/apache/hugegraph/config/CoreOptions.java | 632 ++
.../java/org/apache/hugegraph/election/Config.java | 35 +
.../election/RoleElectionStateMachine.java | 27 +
.../election/RoleElectionStateMachineImpl.java | 312 +
.../apache/hugegraph/election/RoleTypeData.java | 91 +
.../hugegraph/election/RoleTypeDataAdapter.java | 29 +
.../hugegraph/election/StateMachineCallback.java | 35 +
.../hugegraph/election/StateMachineContext.java | 37 +
.../hugegraph/exception/ConnectionException.java | 40 +
.../hugegraph/exception/ExistedException.java | 36 +
.../hugegraph/exception/HugeGremlinException.java | 46 +
.../hugegraph/exception/LimitExceedException.java | 35 +
.../hugegraph/exception/NoIndexException.java | 35 +
.../hugegraph/exception/NotAllowException.java | 35 +
.../hugegraph/exception/NotFoundException.java | 39 +
.../hugegraph/exception/NotSupportException.java | 36 +
.../hugegraph/io/GraphSONSchemaSerializer.java | 131 +
.../apache/hugegraph/io/HugeGraphIoRegistry.java | 44 +
.../apache/hugegraph/io/HugeGraphSONModule.java | 601 ++
.../org/apache/hugegraph/io/HugeGryoModule.java | 200 +
.../org/apache/hugegraph/job/AlgorithmJob.java | 71 +
.../java/org/apache/hugegraph/job/ComputerJob.java | 76 +
.../org/apache/hugegraph/job/EphemeralJob.java | 34 +
.../apache/hugegraph/job/EphemeralJobBuilder.java | 86 +
.../java/org/apache/hugegraph/job/GremlinJob.java | 133 +
.../main/java/org/apache/hugegraph/job/Job.java | 27 +
.../java/org/apache/hugegraph/job/JobBuilder.java | 101 +
.../main/java/org/apache/hugegraph/job/SysJob.java | 45 +
.../java/org/apache/hugegraph/job/UserJob.java | 45 +
.../hugegraph/job/algorithm/AbstractAlgorithm.java | 647 ++
.../apache/hugegraph/job/algorithm/Algorithm.java | 35 +
.../hugegraph/job/algorithm/AlgorithmPool.java | 102 +
.../hugegraph/job/algorithm/BfsTraverser.java | 154 +
.../apache/hugegraph/job/algorithm/Consumers.java | 206 +
.../job/algorithm/CountEdgeAlgorithm.java | 80 +
.../job/algorithm/CountVertexAlgorithm.java | 80 +
.../job/algorithm/SubgraphStatAlgorithm.java | 223 +
.../job/algorithm/cent/AbstractCentAlgorithm.java | 211 +
.../cent/BetweennessCentralityAlgorithm.java | 150 +
.../cent/BetweennessCentralityAlgorithmV2.java | 176 +
.../cent/ClosenessCentralityAlgorithm.java | 108 +
.../cent/ClosenessCentralityAlgorithmV2.java | 135 +
.../algorithm/cent/DegreeCentralityAlgorithm.java | 164 +
.../cent/EigenvectorCentralityAlgorithm.java | 102 +
.../algorithm/cent/StressCentralityAlgorithm.java | 106 +
.../cent/StressCentralityAlgorithmV2.java | 182 +
.../job/algorithm/comm/AbstractCommAlgorithm.java | 80 +
.../comm/ClusterCoefficientAlgorithm.java | 85 +
.../job/algorithm/comm/KCoreAlgorithm.java | 294 +
.../job/algorithm/comm/LouvainAlgorithm.java | 123 +
.../job/algorithm/comm/LouvainTraverser.java | 922 ++
.../hugegraph/job/algorithm/comm/LpaAlgorithm.java | 273 +
.../job/algorithm/comm/TriangleCountAlgorithm.java | 241 +
.../job/algorithm/comm/WeakConnectedComponent.java | 221 +
.../job/algorithm/path/RingsDetectAlgorithm.java | 148 +
.../job/algorithm/rank/PageRankAlgorithm.java | 338 +
.../similarity/FusiformSimilarityAlgorithm.java | 200 +
.../hugegraph/job/computer/AbstractComputer.java | 270 +
.../apache/hugegraph/job/computer/Computer.java | 35 +
.../hugegraph/job/computer/ComputerPool.java | 55 +
.../hugegraph/job/computer/LouvainComputer.java | 128 +
.../apache/hugegraph/job/computer/LpaComputer.java | 73 +
.../hugegraph/job/computer/PageRankComputer.java | 70 +
.../job/computer/TriangleCountComputer.java | 52 +
.../computer/WeakConnectedComponentComputer.java | 52 +
.../hugegraph/job/schema/EdgeLabelRemoveJob.java | 87 +
.../hugegraph/job/schema/IndexLabelRebuildJob.java | 193 +
.../hugegraph/job/schema/IndexLabelRemoveJob.java | 84 +
.../job/schema/OlapPropertyKeyClearJob.java | 93 +
.../job/schema/OlapPropertyKeyCreateJob.java | 42 +
.../job/schema/OlapPropertyKeyRemoveJob.java | 52 +
.../org/apache/hugegraph/job/schema/SchemaJob.java | 126 +
.../hugegraph/job/schema/VertexLabelRemoveJob.java | 106 +
.../job/system/DeleteExpiredElementJob.java | 66 +
.../job/system/DeleteExpiredIndexJob.java | 96 +
.../hugegraph/job/system/DeleteExpiredJob.java | 90 +
.../apache/hugegraph/job/system/JobCounters.java | 119 +
.../hugegraph/plugin/HugeGraphGremlinPlugin.java | 73 +
.../apache/hugegraph/plugin/HugeGraphPlugin.java | 52 +
.../hugegraph/rpc/RpcServiceConfig4Client.java | 37 +
.../hugegraph/rpc/RpcServiceConfig4Server.java | 32 +
.../org/apache/hugegraph/schema/EdgeLabel.java | 169 +
.../org/apache/hugegraph/schema/IndexLabel.java | 285 +
.../org/apache/hugegraph/schema/PropertyKey.java | 414 +
.../org/apache/hugegraph/schema/SchemaElement.java | 222 +
.../org/apache/hugegraph/schema/SchemaLabel.java | 181 +
.../org/apache/hugegraph/schema/SchemaManager.java | 145 +
.../java/org/apache/hugegraph/schema/Userdata.java | 66 +
.../org/apache/hugegraph/schema/VertexLabel.java | 137 +
.../hugegraph/schema/builder/AbstractBuilder.java | 112 +
.../hugegraph/schema/builder/EdgeLabelBuilder.java | 627 ++
.../schema/builder/IndexLabelBuilder.java | 760 ++
.../schema/builder/PropertyKeyBuilder.java | 468 +
.../hugegraph/schema/builder/SchemaBuilder.java | 42 +
.../schema/builder/VertexLabelBuilder.java | 605 ++
.../hugegraph/security/HugeSecurityManager.java | 508 ++
.../org/apache/hugegraph/structure/GraphType.java | 26 +
.../org/apache/hugegraph/structure/HugeEdge.java | 541 ++
.../hugegraph/structure/HugeEdgeProperty.java | 75 +
.../apache/hugegraph/structure/HugeElement.java | 546 ++
.../apache/hugegraph/structure/HugeFeatures.java | 415 +
.../org/apache/hugegraph/structure/HugeIndex.java | 299 +
.../apache/hugegraph/structure/HugeProperty.java | 115 +
.../org/apache/hugegraph/structure/HugeVertex.java | 708 ++
.../hugegraph/structure/HugeVertexProperty.java | 88 +
.../org/apache/hugegraph/task/HugeServerInfo.java | 334 +
.../java/org/apache/hugegraph/task/HugeTask.java | 720 ++
.../apache/hugegraph/task/ServerInfoManager.java | 403 +
.../hugegraph/task/StandardTaskScheduler.java | 862 ++
.../org/apache/hugegraph/task/TaskCallable.java | 191 +
.../org/apache/hugegraph/task/TaskManager.java | 358 +
.../org/apache/hugegraph/task/TaskScheduler.java | 67 +
.../java/org/apache/hugegraph/task/TaskStatus.java | 72 +
.../algorithm/CollectionPathsTraverser.java | 279 +
.../traversal/algorithm/CountTraverser.java | 139 +
.../algorithm/CustomizePathsTraverser.java | 239 +
.../algorithm/CustomizedCrosspointsTraverser.java | 222 +
.../algorithm/FusiformSimilarityTraverser.java | 322 +
.../traversal/algorithm/HugeTraverser.java | 744 ++
.../algorithm/JaccardSimilarTraverser.java | 212 +
.../traversal/algorithm/KneighborTraverser.java | 106 +
.../traversal/algorithm/KoutTraverser.java | 149 +
.../algorithm/MultiNodeShortestPathTraverser.java | 127 +
.../traversal/algorithm/NeighborRankTraverser.java | 307 +
.../traversal/algorithm/OltpTraverser.java | 180 +
.../traversal/algorithm/PathTraverser.java | 226 +
.../traversal/algorithm/PathsTraverser.java | 181 +
.../traversal/algorithm/PersonalRankTraverser.java | 172 +
.../traversal/algorithm/PredictionTraverser.java | 83 +
.../traversal/algorithm/SameNeighborTraverser.java | 62 +
.../traversal/algorithm/ShortestPathTraverser.java | 252 +
.../SingleSourceShortestPathTraverser.java | 295 +
.../traversal/algorithm/SubGraphTraverser.java | 304 +
.../algorithm/TemplatePathsTraverser.java | 281 +
.../algorithm/records/AbstractRecords.java | 83 +
.../records/DoubleWayMultiPathsRecords.java | 207 +
.../algorithm/records/KneighborRecords.java | 74 +
.../traversal/algorithm/records/KoutRecords.java | 65 +
.../traversal/algorithm/records/PathsRecords.java | 60 +
.../traversal/algorithm/records/Records.java | 41 +
.../algorithm/records/ShortestPathRecords.java | 117 +
.../records/SingleWayMultiPathsRecords.java | 186 +
.../algorithm/records/record/Int2ArrayRecord.java | 67 +
.../algorithm/records/record/Int2IntRecord.java | 76 +
.../algorithm/records/record/Int2SetRecord.java | 74 +
.../traversal/algorithm/records/record/Record.java | 37 +
.../algorithm/records/record/RecordFactory.java | 50 +
.../algorithm/records/record/RecordType.java | 69 +
.../algorithm/records/record/SyncRecord.java | 87 +
.../traversal/algorithm/steps/EdgeStep.java | 147 +
.../traversal/algorithm/steps/RepeatEdgeStep.java | 108 +
.../algorithm/steps/WeightedEdgeStep.java | 104 +
.../strategy/ConcurrentTraverseStrategy.java | 73 +
.../algorithm/strategy/SingleTraverseStrategy.java | 75 +
.../algorithm/strategy/TraverseStrategy.java | 51 +
.../hugegraph/traversal/optimize/ConditionP.java | 56 +
.../traversal/optimize/HugeCountStep.java | 79 +
.../traversal/optimize/HugeCountStepStrategy.java | 125 +
.../traversal/optimize/HugeGraphStep.java | 222 +
.../traversal/optimize/HugeGraphStepStrategy.java | 79 +
.../traversal/optimize/HugeScriptTraversal.java | 121 +
.../traversal/optimize/HugeVertexStep.java | 255 +
.../traversal/optimize/HugeVertexStepByBatch.java | 140 +
.../traversal/optimize/HugeVertexStepStrategy.java | 134 +
.../hugegraph/traversal/optimize/QueryHolder.java | 73 +
.../apache/hugegraph/traversal/optimize/Text.java | 34 +
.../traversal/optimize/TraversalUtil.java | 970 ++
.../java/org/apache/hugegraph/type/HugeType.java | 197 +
.../java/org/apache/hugegraph/type/Idfiable.java | 27 +
.../java/org/apache/hugegraph/type/Indexable.java | 29 +
.../java/org/apache/hugegraph/type/Nameable.java | 35 +
.../org/apache/hugegraph/type/Propertiable.java | 29 +
.../java/org/apache/hugegraph/type/Typeable.java | 26 +
.../org/apache/hugegraph/type/define/Action.java | 76 +
.../hugegraph/type/define/AggregateType.java | 93 +
.../apache/hugegraph/type/define/Cardinality.java | 90 +
.../hugegraph/type/define/CollectionType.java | 67 +
.../org/apache/hugegraph/type/define/DataType.java | 220 +
.../apache/hugegraph/type/define/Directions.java | 116 +
.../apache/hugegraph/type/define/Frequency.java | 51 +
.../apache/hugegraph/type/define/GraphMode.java | 74 +
.../hugegraph/type/define/GraphReadMode.java | 50 +
.../org/apache/hugegraph/type/define/HugeKeys.java | 105 +
.../apache/hugegraph/type/define/IdStrategy.java | 71 +
.../apache/hugegraph/type/define/IndexType.java | 122 +
.../org/apache/hugegraph/type/define/NodeRole.java | 63 +
.../apache/hugegraph/type/define/SchemaStatus.java | 65 +
.../apache/hugegraph/type/define/SerialEnum.java | 69 +
.../apache/hugegraph/type/define/WriteType.java | 67 +
.../main/java/org/apache/hugegraph/util/Blob.java | 70 +
.../org/apache/hugegraph/util/CompressUtil.java | 249 +
.../java/org/apache/hugegraph/util/ConfigUtil.java | 154 +
.../java/org/apache/hugegraph/util/Consumers.java | 319 +
.../java/org/apache/hugegraph/util/CopyUtil.java | 88 +
.../java/org/apache/hugegraph/util/Events.java | 35 +
.../util/FixedTimerWindowRateLimiter.java | 62 +
.../util/FixedWatchWindowRateLimiter.java | 62 +
.../java/org/apache/hugegraph/util/GZipUtil.java | 76 +
.../java/org/apache/hugegraph/util/JsonUtil.java | 159 +
.../java/org/apache/hugegraph/util/KryoUtil.java | 98 +
.../java/org/apache/hugegraph/util/LZ4Util.java | 95 +
.../java/org/apache/hugegraph/util/LockUtil.java | 353 +
.../org/apache/hugegraph/util/ParameterUtil.java | 80 +
.../org/apache/hugegraph/util/RateLimiter.java | 45 +
.../java/org/apache/hugegraph/util/Reflection.java | 116 +
.../org/apache/hugegraph/util/StringEncoding.java | 195 +
.../util/collection/CollectionFactory.java | 283 +
.../apache/hugegraph/util/collection/IdSet.java | 120 +
.../hugegraph/util/collection/Int2IntsMap.java | 218 +
.../hugegraph/util/collection/IntIterator.java | 213 +
.../apache/hugegraph/util/collection/IntMap.java | 602 ++
.../apache/hugegraph/util/collection/IntSet.java | 593 ++
.../util/collection/ObjectIntMapping.java | 29 +
.../util/collection/ObjectIntMappingFactory.java | 138 +
.../apache/hugegraph/variables/HugeVariables.java | 393 +
.../org/apache/hugegraph/version/CoreVersion.java | 47 +
...g.apache.tinkerpop.gremlin.jsr223.GremlinPlugin | 2 +-
.../src/main/resources/hugegraph.properties | 2 +-
hugegraph-core/src/main/resources/proto/raft.proto | 4 +-
.../backend/store/raft/rpc/RaftRequests.java | 5191 -----------
.../backend/store/raft/rpc/RaftRequests.java | 5015 +++++++++++
hugegraph-dist/pom.xml | 41 +-
.../scripts/dependency/known-dependencies.txt | 16 +-
.../src/assembly/static/bin/checksocket.sh | 2 +-
.../src/assembly/static/bin/dump-conf.sh | 2 +-
.../src/assembly/static/bin/dump-store.sh | 2 +-
.../src/assembly/static/bin/gremlin-console.sh | 2 +-
.../src/assembly/static/bin/hugegraph-server.sh | 4 +-
.../src/assembly/static/bin/init-store.sh | 2 +-
.../static/conf/graphs/hugegraph.properties | 4 +-
.../static/conf/gremlin-driver-settings.yaml | 2 +-
.../src/assembly/static/conf/gremlin-server.yaml | 66 +-
hugegraph-dist/src/assembly/static/conf/log4j2.xml | 6 +-
.../src/assembly/static/conf/remote-objects.yaml | 2 +-
.../src/assembly/static/conf/remote.yaml | 2 +-
.../assembly/static/conf/rest-server.properties | 4 +-
hugegraph-dist/src/assembly/static/ext/plugins.txt | 2 +-
.../src/assembly/static/scripts/example.groovy | 4 +-
hugegraph-dist/src/assembly/travis/build-report.sh | 8 +-
.../travis/conf-raft1/graphs/hugegraph.properties | 4 +-
.../assembly/travis/conf-raft1/gremlin-server.yaml | 68 +-
.../travis/conf-raft1/rest-server.properties | 2 +-
.../travis/conf-raft2/graphs/hugegraph.properties | 4 +-
.../assembly/travis/conf-raft2/gremlin-server.yaml | 68 +-
.../travis/conf-raft2/rest-server.properties | 2 +-
.../travis/conf-raft3/graphs/hugegraph.properties | 4 +-
.../assembly/travis/conf-raft3/gremlin-server.yaml | 68 +-
.../travis/conf-raft3/rest-server.properties | 2 +-
hugegraph-dist/src/assembly/travis/run-api-test.sh | 8 +-
.../java/com/baidu/hugegraph/cmd/ConfDumper.java | 74 -
.../java/com/baidu/hugegraph/cmd/InitStore.java | 145 -
.../java/com/baidu/hugegraph/cmd/StoreDumper.java | 102 -
.../java/com/baidu/hugegraph/dist/DistOptions.java | 50 -
.../com/baidu/hugegraph/dist/HugeGraphServer.java | 149 -
.../baidu/hugegraph/dist/HugeGremlinServer.java | 69 -
.../com/baidu/hugegraph/dist/HugeRestServer.java | 36 -
.../com/baidu/hugegraph/dist/RegisterUtil.java | 222 -
.../java/org/apache/hugegraph/cmd/ConfDumper.java | 74 +
.../java/org/apache/hugegraph/cmd/InitStore.java | 145 +
.../java/org/apache/hugegraph/cmd/StoreDumper.java | 102 +
.../org/apache/hugegraph/dist/DistOptions.java | 50 +
.../org/apache/hugegraph/dist/HugeGraphServer.java | 149 +
.../apache/hugegraph/dist/HugeGremlinServer.java | 69 +
.../org/apache/hugegraph/dist/HugeRestServer.java | 36 +
.../org/apache/hugegraph/dist/RegisterUtil.java | 222 +
hugegraph-dist/src/main/resources/log4j2.xml | 6 +-
hugegraph-example/pom.xml | 13 +-
.../java/com/baidu/hugegraph/example/Example1.java | 491 -
.../java/com/baidu/hugegraph/example/Example2.java | 264 -
.../java/com/baidu/hugegraph/example/Example3.java | 174 -
.../com/baidu/hugegraph/example/ExampleUtil.java | 110 -
.../hugegraph/example/GraphOfTheMoviesExample.java | 691 --
.../com/baidu/hugegraph/example/PerfExample1.java | 143 -
.../com/baidu/hugegraph/example/PerfExample2.java | 126 -
.../com/baidu/hugegraph/example/PerfExample3.java | 105 -
.../com/baidu/hugegraph/example/PerfExample4.java | 89 -
.../baidu/hugegraph/example/PerfExampleBase.java | 318 -
.../com/baidu/hugegraph/example/TaskExample.java | 111 -
.../hugegraph/example/ThreadRangePerfTest.java | 62 -
.../org/apache/hugegraph/example/Example1.java | 491 +
.../org/apache/hugegraph/example/Example2.java | 264 +
.../org/apache/hugegraph/example/Example3.java | 174 +
.../org/apache/hugegraph/example/ExampleUtil.java | 110 +
.../hugegraph/example/GraphOfTheMoviesExample.java | 691 ++
.../org/apache/hugegraph/example/PerfExample1.java | 143 +
.../org/apache/hugegraph/example/PerfExample2.java | 126 +
.../org/apache/hugegraph/example/PerfExample3.java | 105 +
.../org/apache/hugegraph/example/PerfExample4.java | 89 +
.../apache/hugegraph/example/PerfExampleBase.java | 318 +
.../org/apache/hugegraph/example/TaskExample.java | 111 +
.../hugegraph/example/ThreadRangePerfTest.java | 62 +
.../src/main/resources/hugegraph.properties | 2 +-
hugegraph-example/src/main/resources/log4j2.xml | 6 +-
hugegraph-hbase/pom.xml | 13 +-
.../backend/store/hbase/HbaseFeatures.java | 144 -
.../backend/store/hbase/HbaseMetrics.java | 203 -
.../backend/store/hbase/HbaseOptions.java | 165 -
.../backend/store/hbase/HbaseSerializer.java | 54 -
.../backend/store/hbase/HbaseSessions.java | 964 --
.../hugegraph/backend/store/hbase/HbaseStore.java | 594 --
.../backend/store/hbase/HbaseStoreProvider.java | 77 -
.../hugegraph/backend/store/hbase/HbaseTable.java | 408 -
.../hugegraph/backend/store/hbase/HbaseTables.java | 368 -
.../backend/store/hbase/HbaseFeatures.java | 144 +
.../backend/store/hbase/HbaseMetrics.java | 203 +
.../backend/store/hbase/HbaseOptions.java | 165 +
.../backend/store/hbase/HbaseSerializer.java | 54 +
.../backend/store/hbase/HbaseSessions.java | 964 ++
.../hugegraph/backend/store/hbase/HbaseStore.java | 593 ++
.../backend/store/hbase/HbaseStoreProvider.java | 74 +
.../hugegraph/backend/store/hbase/HbaseTable.java | 404 +
.../hugegraph/backend/store/hbase/HbaseTables.java | 366 +
hugegraph-mysql/pom.xml | 13 +-
.../backend/store/mysql/MysqlBackendEntry.java | 43 -
.../backend/store/mysql/MysqlEntryIterator.java | 199 -
.../backend/store/mysql/MysqlFeatures.java | 133 -
.../backend/store/mysql/MysqlMetrics.java | 33 -
.../backend/store/mysql/MysqlOptions.java | 119 -
.../backend/store/mysql/MysqlSerializer.java | 178 -
.../backend/store/mysql/MysqlSessions.java | 546 --
.../hugegraph/backend/store/mysql/MysqlStore.java | 516 --
.../backend/store/mysql/MysqlStoreProvider.java | 78 -
.../hugegraph/backend/store/mysql/MysqlTable.java | 851 --
.../hugegraph/backend/store/mysql/MysqlTables.java | 667 --
.../hugegraph/backend/store/mysql/MysqlUtil.java | 131 -
.../backend/store/mysql/ResultSetWrapper.java | 63 -
.../backend/store/mysql/WhereBuilder.java | 289 -
.../backend/store/mysql/MysqlBackendEntry.java | 43 +
.../backend/store/mysql/MysqlEntryIterator.java | 199 +
.../backend/store/mysql/MysqlFeatures.java | 133 +
.../backend/store/mysql/MysqlMetrics.java | 33 +
.../backend/store/mysql/MysqlOptions.java | 119 +
.../backend/store/mysql/MysqlSerializer.java | 178 +
.../backend/store/mysql/MysqlSessions.java | 546 ++
.../hugegraph/backend/store/mysql/MysqlStore.java | 516 ++
.../backend/store/mysql/MysqlStoreProvider.java | 78 +
.../hugegraph/backend/store/mysql/MysqlTable.java | 849 ++
.../hugegraph/backend/store/mysql/MysqlTables.java | 666 ++
.../hugegraph/backend/store/mysql/MysqlUtil.java | 131 +
.../backend/store/mysql/ResultSetWrapper.java | 63 +
.../backend/store/mysql/WhereBuilder.java | 289 +
hugegraph-palo/pom.xml | 18 +-
.../hugegraph/backend/store/palo/PaloFeatures.java | 136 -
.../hugegraph/backend/store/palo/PaloFile.java | 194 -
.../backend/store/palo/PaloHttpClient.java | 78 -
.../hugegraph/backend/store/palo/PaloLoadInfo.java | 192 -
.../hugegraph/backend/store/palo/PaloOptions.java | 110 -
.../backend/store/palo/PaloSerializer.java | 47 -
.../hugegraph/backend/store/palo/PaloSessions.java | 319 -
.../hugegraph/backend/store/palo/PaloStore.java | 53 -
.../backend/store/palo/PaloStoreProvider.java | 177 -
.../hugegraph/backend/store/palo/PaloTable.java | 116 -
.../hugegraph/backend/store/palo/PaloTables.java | 474 -
.../hugegraph/backend/store/palo/PaloFeatures.java | 136 +
.../hugegraph/backend/store/palo/PaloFile.java | 194 +
.../backend/store/palo/PaloHttpClient.java | 78 +
.../hugegraph/backend/store/palo/PaloLoadInfo.java | 192 +
.../hugegraph/backend/store/palo/PaloOptions.java | 110 +
.../backend/store/palo/PaloSerializer.java | 47 +
.../hugegraph/backend/store/palo/PaloSessions.java | 319 +
.../hugegraph/backend/store/palo/PaloStore.java | 53 +
.../backend/store/palo/PaloStoreProvider.java | 177 +
.../hugegraph/backend/store/palo/PaloTable.java | 116 +
.../hugegraph/backend/store/palo/PaloTables.java | 474 +
hugegraph-postgresql/pom.xml | 18 +-
.../store/postgresql/PostgresqlOptions.java | 51 -
.../store/postgresql/PostgresqlSerializer.java | 61 -
.../store/postgresql/PostgresqlSessions.java | 137 -
.../backend/store/postgresql/PostgresqlStore.java | 37 -
.../store/postgresql/PostgresqlStoreProvider.java | 224 -
.../backend/store/postgresql/PostgresqlTable.java | 172 -
.../backend/store/postgresql/PostgresqlTables.java | 293 -
.../store/postgresql/PostgresqlOptions.java | 51 +
.../store/postgresql/PostgresqlSerializer.java | 61 +
.../store/postgresql/PostgresqlSessions.java | 137 +
.../backend/store/postgresql/PostgresqlStore.java | 37 +
.../store/postgresql/PostgresqlStoreProvider.java | 224 +
.../backend/store/postgresql/PostgresqlTable.java | 172 +
.../backend/store/postgresql/PostgresqlTables.java | 293 +
hugegraph-rocksdb/pom.xml | 13 +-
.../backend/store/rocksdb/OpenedRocksDB.java | 191 -
.../backend/store/rocksdb/RocksDBFeatures.java | 148 -
.../backend/store/rocksdb/RocksDBIngester.java | 109 -
.../backend/store/rocksdb/RocksDBIteratorPool.java | 185 -
.../backend/store/rocksdb/RocksDBMetrics.java | 239 -
.../backend/store/rocksdb/RocksDBOptions.java | 701 --
.../backend/store/rocksdb/RocksDBSessions.java | 138 -
.../backend/store/rocksdb/RocksDBStdSessions.java | 1359 ---
.../backend/store/rocksdb/RocksDBStore.java | 1164 ---
.../store/rocksdb/RocksDBStoreProvider.java | 103 -
.../backend/store/rocksdb/RocksDBTable.java | 372 -
.../backend/store/rocksdb/RocksDBTables.java | 480 -
.../store/rocksdbsst/RocksDBSstSessions.java | 449 -
.../backend/store/rocksdbsst/RocksDBSstStore.java | 116 -
.../store/rocksdbsst/RocksDBSstStoreProvider.java | 38 -
.../backend/store/rocksdb/OpenedRocksDB.java | 191 +
.../backend/store/rocksdb/RocksDBFeatures.java | 148 +
.../backend/store/rocksdb/RocksDBIngester.java | 109 +
.../backend/store/rocksdb/RocksDBIteratorPool.java | 185 +
.../backend/store/rocksdb/RocksDBMetrics.java | 239 +
.../backend/store/rocksdb/RocksDBOptions.java | 701 ++
.../backend/store/rocksdb/RocksDBSessions.java | 138 +
.../backend/store/rocksdb/RocksDBStdSessions.java | 1358 +++
.../backend/store/rocksdb/RocksDBStore.java | 1163 +++
.../store/rocksdb/RocksDBStoreProvider.java | 100 +
.../backend/store/rocksdb/RocksDBTable.java | 370 +
.../backend/store/rocksdb/RocksDBTables.java | 479 +
.../store/rocksdbsst/RocksDBSstSessions.java | 449 +
.../backend/store/rocksdbsst/RocksDBSstStore.java | 116 +
.../store/rocksdbsst/RocksDBSstStoreProvider.java | 37 +
hugegraph-scylladb/pom.xml | 13 +-
.../backend/store/scylladb/ScyllaDBFeatures.java | 35 -
.../backend/store/scylladb/ScyllaDBMetrics.java | 72 -
.../store/scylladb/ScyllaDBStoreProvider.java | 176 -
.../store/scylladb/ScyllaDBTablesWithMV.java | 303 -
.../backend/store/scylladb/ScyllaDBFeatures.java | 35 +
.../backend/store/scylladb/ScyllaDBMetrics.java | 72 +
.../store/scylladb/ScyllaDBStoreProvider.java | 176 +
.../store/scylladb/ScyllaDBTablesWithMV.java | 303 +
hugegraph-test/pom.xml | 43 +-
.../java/com/baidu/hugegraph/api/ApiTestSuite.java | 52 -
.../java/com/baidu/hugegraph/api/BaseApiTest.java | 648 --
.../com/baidu/hugegraph/api/CypherApiTest.java | 86 -
.../java/com/baidu/hugegraph/api/EdgeApiTest.java | 209 -
.../com/baidu/hugegraph/api/EdgeLabelApiTest.java | 140 -
.../com/baidu/hugegraph/api/GremlinApiTest.java | 224 -
.../com/baidu/hugegraph/api/IndexLabelApiTest.java | 157 -
.../java/com/baidu/hugegraph/api/LoginApiTest.java | 170 -
.../com/baidu/hugegraph/api/MetricsApiTest.java | 292 -
.../com/baidu/hugegraph/api/ProjectApiTest.java | 264 -
.../baidu/hugegraph/api/PropertyKeyApiTest.java | 91 -
.../com/baidu/hugegraph/api/SchemaApiTest.java | 39 -
.../java/com/baidu/hugegraph/api/TaskApiTest.java | 167 -
.../java/com/baidu/hugegraph/api/UserApiTest.java | 183 -
.../com/baidu/hugegraph/api/VertexApiTest.java | 102 -
.../baidu/hugegraph/api/VertexLabelApiTest.java | 127 -
.../api/traversers/AdamicAdarAPITest.java | 58 -
.../api/traversers/AllShortestPathsApiTest.java | 66 -
.../hugegraph/api/traversers/CountApiTest.java | 62 -
.../api/traversers/CrosspointsApiTest.java | 62 -
.../traversers/CustomizedCrosspointsApiTest.java | 67 -
.../hugegraph/api/traversers/EdgesApiTest.java | 91 -
.../api/traversers/FusiformSimilarityApiTest.java | 74 -
.../api/traversers/JaccardSimilarityApiTest.java | 86 -
.../hugegraph/api/traversers/KneighborApiTest.java | 87 -
.../hugegraph/api/traversers/KoutApiTest.java | 101 -
.../traversers/MultiNodeShortestPathApiTest.java | 68 -
.../api/traversers/NeighborRankApiTest.java | 59 -
.../hugegraph/api/traversers/PathsApiTest.java | 87 -
.../api/traversers/PersonalRankApiTest.java | 58 -
.../hugegraph/api/traversers/RaysApiTest.java | 65 -
.../api/traversers/ResourceAllocationAPITest.java | 58 -
.../hugegraph/api/traversers/RingsApiTest.java | 59 -
.../api/traversers/SameNeighborsApiTest.java | 62 -
.../api/traversers/ShortestPathApiTest.java | 63 -
.../SingleSourceShortestPathApiTest.java | 57 -
.../api/traversers/TemplatePathsApiTest.java | 88 -
.../api/traversers/TraversersApiTestSuite.java | 51 -
.../traversers/WeightedShortestPathApiTest.java | 68 -
.../java/com/baidu/hugegraph/core/AuthTest.java | 1578 ----
.../com/baidu/hugegraph/core/BaseCoreTest.java | 125 -
.../com/baidu/hugegraph/core/CoreTestSuite.java | 97 -
.../com/baidu/hugegraph/core/EdgeCoreTest.java | 7530 ----------------
.../baidu/hugegraph/core/EdgeLabelCoreTest.java | 1387 ---
.../baidu/hugegraph/core/IndexLabelCoreTest.java | 1887 ----
.../com/baidu/hugegraph/core/MultiGraphsTest.java | 415 -
.../com/baidu/hugegraph/core/PropertyCoreTest.java | 804 --
.../baidu/hugegraph/core/PropertyKeyCoreTest.java | 726 --
.../com/baidu/hugegraph/core/RamTableTest.java | 837 --
.../com/baidu/hugegraph/core/RestoreCoreTest.java | 728 --
.../core/RoleElectionStateMachineTest.java | 325 -
.../com/baidu/hugegraph/core/SchemaCoreTest.java | 163 -
.../com/baidu/hugegraph/core/TaskCoreTest.java | 714 --
.../com/baidu/hugegraph/core/VertexCoreTest.java | 9343 --------------------
.../baidu/hugegraph/core/VertexLabelCoreTest.java | 1220 ---
.../com/baidu/hugegraph/testutil/FakeObjects.java | 86 -
.../java/com/baidu/hugegraph/testutil/Utils.java | 114 -
.../hugegraph/tinkerpop/ProcessBasicSuite.java | 301 -
.../hugegraph/tinkerpop/ProcessStandardTest.java | 29 -
.../tinkerpop/ProcessTestGraphProvider.java | 31 -
.../hugegraph/tinkerpop/StructureBasicSuite.java | 126 -
.../hugegraph/tinkerpop/StructureStandardTest.java | 29 -
.../tinkerpop/StructureTestGraphProvider.java | 31 -
.../com/baidu/hugegraph/tinkerpop/TestGraph.java | 951 --
.../hugegraph/tinkerpop/TestGraphFactory.java | 30 -
.../hugegraph/tinkerpop/TestGraphProvider.java | 448 -
.../tinkerpop/tests/HugeGraphWriteTest.java | 49 -
.../com/baidu/hugegraph/unit/BaseUnitTest.java | 85 -
.../java/com/baidu/hugegraph/unit/FakeObjects.java | 216 -
.../com/baidu/hugegraph/unit/UnitTestSuite.java | 156 -
.../hugegraph/unit/cache/CacheManagerTest.java | 315 -
.../com/baidu/hugegraph/unit/cache/CacheTest.java | 774 --
.../unit/cache/CachedGraphTransactionTest.java | 224 -
.../unit/cache/CachedSchemaTransactionTest.java | 203 -
.../baidu/hugegraph/unit/cache/RamTableTest.java | 284 -
.../hugegraph/unit/cassandra/CassandraTest.java | 197 -
.../baidu/hugegraph/unit/core/AnalyzerTest.java | 206 -
.../hugegraph/unit/core/BackendMutationTest.java | 358 -
.../hugegraph/unit/core/BackendStoreInfoTest.java | 50 -
.../unit/core/ConditionQueryFlattenTest.java | 262 -
.../baidu/hugegraph/unit/core/ConditionTest.java | 647 --
.../baidu/hugegraph/unit/core/DataTypeTest.java | 88 -
.../baidu/hugegraph/unit/core/DirectionsTest.java | 79 -
.../baidu/hugegraph/unit/core/ExceptionTest.java | 45 -
.../baidu/hugegraph/unit/core/LocksTableTest.java | 309 -
.../baidu/hugegraph/unit/core/PageStateTest.java | 90 -
.../com/baidu/hugegraph/unit/core/QueryTest.java | 171 -
.../com/baidu/hugegraph/unit/core/RangeTest.java | 172 -
.../hugegraph/unit/core/RolePermissionTest.java | 584 --
.../com/baidu/hugegraph/unit/core/RowLockTest.java | 101 -
.../hugegraph/unit/core/SecurityManagerTest.java | 328 -
.../baidu/hugegraph/unit/core/SerialEnumTest.java | 45 -
.../hugegraph/unit/core/SystemSchemaStoreTest.java | 59 -
.../hugegraph/unit/core/TraversalUtilTest.java | 341 -
.../com/baidu/hugegraph/unit/id/EdgeIdTest.java | 119 -
.../java/com/baidu/hugegraph/unit/id/IdTest.java | 225 -
.../com/baidu/hugegraph/unit/id/IdUtilTest.java | 160 -
.../hugegraph/unit/id/SplicingIdGeneratorTest.java | 112 -
.../baidu/hugegraph/unit/mysql/MysqlUtilTest.java | 62 -
.../hugegraph/unit/mysql/WhereBuilderTest.java | 125 -
.../unit/rocksdb/BaseRocksDBUnitTest.java | 131 -
.../unit/rocksdb/RocksDBCountersTest.java | 126 -
.../hugegraph/unit/rocksdb/RocksDBPerfTest.java | 253 -
.../hugegraph/unit/rocksdb/RocksDBSessionTest.java | 655 --
.../unit/rocksdb/RocksDBSessionsTest.java | 223 -
.../unit/serializer/BinaryBackendEntryTest.java | 115 -
.../serializer/BinaryScatterSerializerTest.java | 94 -
.../unit/serializer/BinarySerializerTest.java | 133 -
.../hugegraph/unit/serializer/BytesBufferTest.java | 1078 ---
.../unit/serializer/SerializerFactoryTest.java | 97 -
.../unit/serializer/StoreSerializerTest.java | 92 -
.../unit/serializer/TableBackendEntryTest.java | 194 -
.../unit/serializer/TextBackendEntryTest.java | 96 -
.../hugegraph/unit/util/CompressUtilTest.java | 135 -
.../baidu/hugegraph/unit/util/JsonUtilTest.java | 312 -
.../baidu/hugegraph/unit/util/RateLimiterTest.java | 174 -
.../hugegraph/unit/util/StringEncodingTest.java | 186 -
.../com/baidu/hugegraph/unit/util/VersionTest.java | 44 -
.../util/collection/CollectionFactoryTest.java | 387 -
.../hugegraph/unit/util/collection/IdSetTest.java | 327 -
.../unit/util/collection/Int2IntsMapTest.java | 196 -
.../hugegraph/unit/util/collection/IntMapTest.java | 424 -
.../hugegraph/unit/util/collection/IntSetTest.java | 185 -
.../unit/util/collection/ObjectIntMappingTest.java | 143 -
.../org/apache/hugegraph/api/ApiTestSuite.java | 52 +
.../java/org/apache/hugegraph/api/BaseApiTest.java | 648 ++
.../org/apache/hugegraph/api/CypherApiTest.java | 86 +
.../java/org/apache/hugegraph/api/EdgeApiTest.java | 209 +
.../org/apache/hugegraph/api/EdgeLabelApiTest.java | 140 +
.../org/apache/hugegraph/api/GremlinApiTest.java | 224 +
.../apache/hugegraph/api/IndexLabelApiTest.java | 157 +
.../org/apache/hugegraph/api/LoginApiTest.java | 170 +
.../org/apache/hugegraph/api/MetricsApiTest.java | 292 +
.../org/apache/hugegraph/api/ProjectApiTest.java | 264 +
.../apache/hugegraph/api/PropertyKeyApiTest.java | 91 +
.../org/apache/hugegraph/api/SchemaApiTest.java | 39 +
.../java/org/apache/hugegraph/api/TaskApiTest.java | 167 +
.../java/org/apache/hugegraph/api/UserApiTest.java | 183 +
.../org/apache/hugegraph/api/VertexApiTest.java | 102 +
.../apache/hugegraph/api/VertexLabelApiTest.java | 127 +
.../api/traversers/AdamicAdarAPITest.java | 58 +
.../api/traversers/AllShortestPathsApiTest.java | 66 +
.../hugegraph/api/traversers/CountApiTest.java | 62 +
.../api/traversers/CrosspointsApiTest.java | 62 +
.../traversers/CustomizedCrosspointsApiTest.java | 67 +
.../hugegraph/api/traversers/EdgesApiTest.java | 91 +
.../api/traversers/FusiformSimilarityApiTest.java | 74 +
.../api/traversers/JaccardSimilarityApiTest.java | 86 +
.../hugegraph/api/traversers/KneighborApiTest.java | 87 +
.../hugegraph/api/traversers/KoutApiTest.java | 101 +
.../traversers/MultiNodeShortestPathApiTest.java | 68 +
.../api/traversers/NeighborRankApiTest.java | 59 +
.../hugegraph/api/traversers/PathsApiTest.java | 87 +
.../api/traversers/PersonalRankApiTest.java | 58 +
.../hugegraph/api/traversers/RaysApiTest.java | 65 +
.../api/traversers/ResourceAllocationAPITest.java | 58 +
.../hugegraph/api/traversers/RingsApiTest.java | 59 +
.../api/traversers/SameNeighborsApiTest.java | 62 +
.../api/traversers/ShortestPathApiTest.java | 63 +
.../SingleSourceShortestPathApiTest.java | 57 +
.../api/traversers/TemplatePathsApiTest.java | 88 +
.../api/traversers/TraversersApiTestSuite.java | 51 +
.../traversers/WeightedShortestPathApiTest.java | 68 +
.../java/org/apache/hugegraph/core/AuthTest.java | 1578 ++++
.../org/apache/hugegraph/core/BaseCoreTest.java | 125 +
.../org/apache/hugegraph/core/CoreTestSuite.java | 97 +
.../org/apache/hugegraph/core/EdgeCoreTest.java | 7530 ++++++++++++++++
.../apache/hugegraph/core/EdgeLabelCoreTest.java | 1387 +++
.../apache/hugegraph/core/IndexLabelCoreTest.java | 1887 ++++
.../org/apache/hugegraph/core/MultiGraphsTest.java | 415 +
.../apache/hugegraph/core/PropertyCoreTest.java | 804 ++
.../apache/hugegraph/core/PropertyKeyCoreTest.java | 726 ++
.../org/apache/hugegraph/core/RamTableTest.java | 837 ++
.../org/apache/hugegraph/core/RestoreCoreTest.java | 728 ++
.../core/RoleElectionStateMachineTest.java | 325 +
.../org/apache/hugegraph/core/SchemaCoreTest.java | 163 +
.../org/apache/hugegraph/core/TaskCoreTest.java | 714 ++
.../org/apache/hugegraph/core/VertexCoreTest.java | 9343 ++++++++++++++++++++
.../apache/hugegraph/core/VertexLabelCoreTest.java | 1220 +++
.../org/apache/hugegraph/testutil/FakeObjects.java | 86 +
.../java/org/apache/hugegraph/testutil/Utils.java | 112 +
.../hugegraph/tinkerpop/ProcessBasicSuite.java | 301 +
.../hugegraph/tinkerpop/ProcessStandardTest.java | 29 +
.../tinkerpop/ProcessTestGraphProvider.java | 31 +
.../hugegraph/tinkerpop/StructureBasicSuite.java | 126 +
.../hugegraph/tinkerpop/StructureStandardTest.java | 29 +
.../tinkerpop/StructureTestGraphProvider.java | 31 +
.../org/apache/hugegraph/tinkerpop/TestGraph.java | 951 ++
.../hugegraph/tinkerpop/TestGraphFactory.java | 30 +
.../hugegraph/tinkerpop/TestGraphProvider.java | 448 +
.../tinkerpop/tests/HugeGraphWriteTest.java | 49 +
.../org/apache/hugegraph/unit/BaseUnitTest.java | 85 +
.../org/apache/hugegraph/unit/FakeObjects.java | 216 +
.../org/apache/hugegraph/unit/UnitTestSuite.java | 156 +
.../hugegraph/unit/cache/CacheManagerTest.java | 315 +
.../org/apache/hugegraph/unit/cache/CacheTest.java | 774 ++
.../unit/cache/CachedGraphTransactionTest.java | 224 +
.../unit/cache/CachedSchemaTransactionTest.java | 203 +
.../apache/hugegraph/unit/cache/RamTableTest.java | 284 +
.../hugegraph/unit/cassandra/CassandraTest.java | 197 +
.../apache/hugegraph/unit/core/AnalyzerTest.java | 206 +
.../hugegraph/unit/core/BackendMutationTest.java | 358 +
.../hugegraph/unit/core/BackendStoreInfoTest.java | 50 +
.../unit/core/ConditionQueryFlattenTest.java | 262 +
.../apache/hugegraph/unit/core/ConditionTest.java | 647 ++
.../apache/hugegraph/unit/core/DataTypeTest.java | 88 +
.../apache/hugegraph/unit/core/DirectionsTest.java | 79 +
.../apache/hugegraph/unit/core/ExceptionTest.java | 45 +
.../apache/hugegraph/unit/core/LocksTableTest.java | 309 +
.../apache/hugegraph/unit/core/PageStateTest.java | 90 +
.../org/apache/hugegraph/unit/core/QueryTest.java | 171 +
.../org/apache/hugegraph/unit/core/RangeTest.java | 172 +
.../hugegraph/unit/core/RolePermissionTest.java | 584 ++
.../apache/hugegraph/unit/core/RowLockTest.java | 101 +
.../hugegraph/unit/core/SecurityManagerTest.java | 328 +
.../apache/hugegraph/unit/core/SerialEnumTest.java | 45 +
.../hugegraph/unit/core/SystemSchemaStoreTest.java | 59 +
.../hugegraph/unit/core/TraversalUtilTest.java | 341 +
.../org/apache/hugegraph/unit/id/EdgeIdTest.java | 119 +
.../java/org/apache/hugegraph/unit/id/IdTest.java | 225 +
.../org/apache/hugegraph/unit/id/IdUtilTest.java | 160 +
.../hugegraph/unit/id/SplicingIdGeneratorTest.java | 112 +
.../apache/hugegraph/unit/mysql/MysqlUtilTest.java | 62 +
.../hugegraph/unit/mysql/WhereBuilderTest.java | 125 +
.../unit/rocksdb/BaseRocksDBUnitTest.java | 131 +
.../unit/rocksdb/RocksDBCountersTest.java | 126 +
.../hugegraph/unit/rocksdb/RocksDBPerfTest.java | 253 +
.../hugegraph/unit/rocksdb/RocksDBSessionTest.java | 655 ++
.../unit/rocksdb/RocksDBSessionsTest.java | 223 +
.../unit/serializer/BinaryBackendEntryTest.java | 115 +
.../serializer/BinaryScatterSerializerTest.java | 94 +
.../unit/serializer/BinarySerializerTest.java | 133 +
.../hugegraph/unit/serializer/BytesBufferTest.java | 1078 +++
.../unit/serializer/SerializerFactoryTest.java | 97 +
.../unit/serializer/StoreSerializerTest.java | 92 +
.../unit/serializer/TableBackendEntryTest.java | 194 +
.../unit/serializer/TextBackendEntryTest.java | 96 +
.../hugegraph/unit/util/CompressUtilTest.java | 137 +
.../apache/hugegraph/unit/util/JsonUtilTest.java | 312 +
.../hugegraph/unit/util/RateLimiterTest.java | 174 +
.../hugegraph/unit/util/StringEncodingTest.java | 186 +
.../apache/hugegraph/unit/util/VersionTest.java | 44 +
.../util/collection/CollectionFactoryTest.java | 389 +
.../hugegraph/unit/util/collection/IdSetTest.java | 327 +
.../unit/util/collection/Int2IntsMapTest.java | 196 +
.../hugegraph/unit/util/collection/IntMapTest.java | 424 +
.../hugegraph/unit/util/collection/IntSetTest.java | 185 +
.../unit/util/collection/ObjectIntMappingTest.java | 143 +
.../src/main/resources/hugegraph.properties | 2 +-
hugegraph-test/src/main/resources/log4j2.xml | 6 +-
pom.xml | 29 +-
1373 files changed, 166551 insertions(+), 166687 deletions(-)
diff --git a/.gitignore b/.gitignore
index f7bcdbf5a..782c85270 100644
--- a/.gitignore
+++ b/.gitignore
@@ -64,6 +64,7 @@ output/
*.tar.gz
tree.txt
*.versionsBackup
+.flattened-pom.xml
# eclipse ignore
.settings/
diff --git a/hugegraph-api/pom.xml b/hugegraph-api/pom.xml
index d7f2ce7b3..bdf5c3e59 100644
--- a/hugegraph-api/pom.xml
+++ b/hugegraph-api/pom.xml
@@ -19,23 +19,28 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
+ <groupId>org.apache.hugegraph</groupId>
<artifactId>hugegraph</artifactId>
- <groupId>com.baidu.hugegraph</groupId>
- <version>0.13.0</version>
+ <version>${revision}</version>
+ <relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hugegraph-api</artifactId>
+ <properties>
+ <hugegraph-core-version>1.0.0</hugegraph-core-version>
+ </properties>
+
<dependencies>
<dependency>
- <groupId>com.baidu.hugegraph</groupId>
+ <groupId>org.apache.hugegraph</groupId>
<artifactId>hugegraph-core</artifactId>
- <version>${project.version}</version>
+ <version>${hugegraph-core-version}</version>
</dependency>
<dependency>
- <groupId>com.baidu.hugegraph</groupId>
+ <groupId>org.apache.hugegraph</groupId>
<artifactId>hugegraph-rpc</artifactId>
<exclusions>
<!-- conflict with jraft -->
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/API.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/API.java
deleted file mode 100644
index ab84acad2..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/API.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * 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.api;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.Callable;
-import java.util.function.Consumer;
-
-import jakarta.ws.rs.ForbiddenException;
-import jakarta.ws.rs.NotFoundException;
-import jakarta.ws.rs.NotSupportedException;
-import jakarta.ws.rs.core.MediaType;
-
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeException;
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.define.Checkable;
-import com.baidu.hugegraph.metrics.MetricsUtil;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.JsonUtil;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.Meter;
-import com.google.common.collect.ImmutableMap;
-
-public class API {
-
- protected static final Logger LOG = Log.logger(API.class);
-
- public static final String CHARSET = "UTF-8";
-
- public static final String TEXT_PLAIN = MediaType.TEXT_PLAIN;
- public static final String APPLICATION_JSON = MediaType.APPLICATION_JSON;
- public static final String APPLICATION_JSON_WITH_CHARSET =
- APPLICATION_JSON + ";charset=" + CHARSET;
- public static final String JSON = MediaType.APPLICATION_JSON_TYPE
- .getSubtype();
-
- public static final String ACTION_APPEND = "append";
- public static final String ACTION_ELIMINATE = "eliminate";
- public static final String ACTION_CLEAR = "clear";
-
- private static final Meter SUCCEED_METER =
- MetricsUtil.registerMeter(API.class, "commit-succeed");
- private static final Meter ILLEGAL_ARG_ERROR_METER =
- MetricsUtil.registerMeter(API.class, "illegal-arg");
- private static final Meter EXPECTED_ERROR_METER =
- MetricsUtil.registerMeter(API.class, "expected-error");
- private static final Meter UNKNOWN_ERROR_METER =
- MetricsUtil.registerMeter(API.class, "unknown-error");
-
- public static HugeGraph graph(GraphManager manager, String graph) {
- HugeGraph g = manager.graph(graph);
- if (g == null) {
- throw new NotFoundException(String.format(
- "Graph '%s' does not exist", graph));
- }
- return g;
- }
-
- public static HugeGraph graph4admin(GraphManager manager, String graph) {
- return graph(manager, graph).hugegraph();
- }
-
- public static <R> R commit(HugeGraph g, Callable<R> callable) {
- Consumer<Throwable> rollback = (error) -> {
- if (error != null) {
- LOG.error("Failed to commit", error);
- }
- try {
- g.tx().rollback();
- } catch (Throwable e) {
- LOG.error("Failed to rollback", e);
- }
- };
-
- try {
- R result = callable.call();
- g.tx().commit();
- SUCCEED_METER.mark();
- return result;
- } catch (IllegalArgumentException | NotFoundException |
- ForbiddenException e) {
- ILLEGAL_ARG_ERROR_METER.mark();
- rollback.accept(null);
- throw e;
- } catch (RuntimeException e) {
- EXPECTED_ERROR_METER.mark();
- rollback.accept(e);
- throw e;
- } catch (Throwable e) {
- UNKNOWN_ERROR_METER.mark();
- rollback.accept(e);
- // TODO: throw the origin exception 'e'
- throw new HugeException("Failed to commit", e);
- }
- }
-
- public static void commit(HugeGraph g, Runnable runnable) {
- commit(g, () -> {
- runnable.run();
- return null;
- });
- }
-
- public static Object[] properties(Map<String, Object> properties) {
- Object[] list = new Object[properties.size() * 2];
- int i = 0;
- for (Map.Entry<String, Object> prop : properties.entrySet()) {
- list[i++] = prop.getKey();
- list[i++] = prop.getValue();
- }
- return list;
- }
-
- protected static void checkCreatingBody(Checkable body) {
- E.checkArgumentNotNull(body, "The request body can't be empty");
- body.checkCreate(false);
- }
-
- protected static void checkUpdatingBody(Checkable body) {
- E.checkArgumentNotNull(body, "The request body can't be empty");
- body.checkUpdate();
- }
-
- protected static void checkCreatingBody(
- Collection<? extends Checkable> bodies) {
- E.checkArgumentNotNull(bodies, "The request body can't be empty");
- for (Checkable body : bodies) {
- E.checkArgument(body != null,
- "The batch body can't contain null record");
- body.checkCreate(true);
- }
- }
-
- protected static void checkUpdatingBody(
- Collection<? extends Checkable> bodies) {
- E.checkArgumentNotNull(bodies, "The request body can't be empty");
- for (Checkable body : bodies) {
- E.checkArgumentNotNull(body,
- "The batch body can't contain null record");
- body.checkUpdate();
- }
- }
-
- @SuppressWarnings("unchecked")
- protected static Map<String, Object> parseProperties(String properties) {
- if (properties == null || properties.isEmpty()) {
- return ImmutableMap.of();
- }
-
- Map<String, Object> props = null;
- try {
- props = JsonUtil.fromJson(properties, Map.class);
- } catch (Exception ignored) {
- // ignore
- }
-
- // If properties is the string "null", props will be null
- E.checkArgument(props != null,
- "Invalid request with properties: %s", properties);
- return props;
- }
-
- public static boolean checkAndParseAction(String action) {
- E.checkArgumentNotNull(action, "The action param can't be empty");
- if (action.equals(ACTION_APPEND)) {
- return true;
- } else if (action.equals(ACTION_ELIMINATE)) {
- return false;
- } else {
- throw new NotSupportedException(
- String.format("Not support action '%s'", action));
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/AccessAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/AccessAPI.java
deleted file mode 100644
index b616d6dd9..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/AccessAPI.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * 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.api.auth;
-
-import java.util.List;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.DELETE;
-import jakarta.ws.rs.DefaultValue;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.PUT;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Path;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.StatusFilter.Status;
-import com.baidu.hugegraph.auth.HugeAccess;
-import com.baidu.hugegraph.auth.HugePermission;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.define.Checkable;
-import com.baidu.hugegraph.exception.NotFoundException;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-@Path("graphs/{graph}/auth/accesses")
-@Singleton
-@Tag(name = "AccessAPI")
-public class AccessAPI extends API {
-
- private static final Logger LOG = Log.logger(AccessAPI.class);
-
- @POST
- @Timed
- @Status(Status.CREATED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String create(@Context GraphManager manager,
- @PathParam("graph") String graph,
- JsonAccess jsonAccess) {
- LOG.debug("Graph [{}] create access: {}", graph, jsonAccess);
- checkCreatingBody(jsonAccess);
-
- HugeGraph g = graph(manager, graph);
- HugeAccess access = jsonAccess.build();
- access.id(manager.authManager().createAccess(access));
- return manager.serializer(g).writeAuthElement(access);
- }
-
- @PUT
- @Timed
- @Path("{id}")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String update(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id,
- JsonAccess jsonAccess) {
- LOG.debug("Graph [{}] update access: {}", graph, jsonAccess);
- checkUpdatingBody(jsonAccess);
-
- HugeGraph g = graph(manager, graph);
- HugeAccess access;
- try {
- access = manager.authManager().getAccess(UserAPI.parseId(id));
- } catch (NotFoundException e) {
- throw new IllegalArgumentException("Invalid access id: " + id);
- }
- access = jsonAccess.build(access);
- manager.authManager().updateAccess(access);
- return manager.serializer(g).writeAuthElement(access);
- }
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String list(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("group") String group,
- @QueryParam("target") String target,
- @QueryParam("limit") @DefaultValue("100") long limit) {
- LOG.debug("Graph [{}] list belongs by group {} or target {}",
- graph, group, target);
- E.checkArgument(group == null || target == null,
- "Can't pass both group and target at the same time");
-
- HugeGraph g = graph(manager, graph);
- List<HugeAccess> belongs;
- if (group != null) {
- Id id = UserAPI.parseId(group);
- belongs = manager.authManager().listAccessByGroup(id, limit);
- } else if (target != null) {
- Id id = UserAPI.parseId(target);
- belongs = manager.authManager().listAccessByTarget(id, limit);
- } else {
- belongs = manager.authManager().listAllAccess(limit);
- }
- return manager.serializer(g).writeAuthElements("accesses", belongs);
- }
-
- @GET
- @Timed
- @Path("{id}")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String get(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id) {
- LOG.debug("Graph [{}] get access: {}", graph, id);
-
- HugeGraph g = graph(manager, graph);
- HugeAccess access = manager.authManager().getAccess(UserAPI.parseId(id));
- return manager.serializer(g).writeAuthElement(access);
- }
-
- @DELETE
- @Timed
- @Path("{id}")
- @Consumes(APPLICATION_JSON)
- public void delete(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id) {
- LOG.debug("Graph [{}] delete access: {}", graph, id);
-
- @SuppressWarnings("unused") // just check if the graph exists
- HugeGraph g = graph(manager, graph);
- try {
- manager.authManager().deleteAccess(UserAPI.parseId(id));
- } catch (NotFoundException e) {
- throw new IllegalArgumentException("Invalid access id: " + id);
- }
- }
-
- @JsonIgnoreProperties(value = {"id", "access_creator",
- "access_create", "access_update"})
- private static class JsonAccess implements Checkable {
-
- @JsonProperty("group")
- private String group;
- @JsonProperty("target")
- private String target;
- @JsonProperty("access_permission")
- private HugePermission permission;
- @JsonProperty("access_description")
- private String description;
-
- public HugeAccess build(HugeAccess access) {
- E.checkArgument(this.group == null ||
- access.source().equals(UserAPI.parseId(this.group)),
- "The group of access can't be updated");
- E.checkArgument(this.target == null ||
- access.target().equals(UserAPI.parseId(this.target)),
- "The target of access can't be updated");
- E.checkArgument(this.permission == null ||
- access.permission().equals(this.permission),
- "The permission of access can't be updated");
- if (this.description != null) {
- access.description(this.description);
- }
- return access;
- }
-
- public HugeAccess build() {
- HugeAccess access = new HugeAccess(UserAPI.parseId(this.group),
- UserAPI.parseId(this.target));
- access.permission(this.permission);
- access.description(this.description);
- return access;
- }
-
- @Override
- public void checkCreate(boolean isBatch) {
- E.checkArgumentNotNull(this.group,
- "The group of access can't be null");
- E.checkArgumentNotNull(this.target,
- "The target of access can't be null");
- E.checkArgumentNotNull(this.permission,
- "The permission of access can't be null");
- }
-
- @Override
- public void checkUpdate() {
- E.checkArgumentNotNull(this.description,
- "The description of access can't be null");
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/BelongAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/BelongAPI.java
deleted file mode 100644
index 0435c6088..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/BelongAPI.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * 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.api.auth;
-
-import java.util.List;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.DELETE;
-import jakarta.ws.rs.DefaultValue;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.PUT;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-
-import jakarta.inject.Singleton;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.StatusFilter.Status;
-import com.baidu.hugegraph.auth.HugeBelong;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.define.Checkable;
-import com.baidu.hugegraph.exception.NotFoundException;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-@Path("graphs/{graph}/auth/belongs")
-@Singleton
-@Tag(name = "BelongAPI")
-public class BelongAPI extends API {
-
- private static final Logger LOG = Log.logger(BelongAPI.class);
-
- @POST
- @Timed
- @Status(Status.CREATED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String create(@Context GraphManager manager,
- @PathParam("graph") String graph,
- JsonBelong jsonBelong) {
- LOG.debug("Graph [{}] create belong: {}", graph, jsonBelong);
- checkCreatingBody(jsonBelong);
-
- HugeGraph g = graph(manager, graph);
- HugeBelong belong = jsonBelong.build();
- belong.id(manager.authManager().createBelong(belong));
- return manager.serializer(g).writeAuthElement(belong);
- }
-
- @PUT
- @Timed
- @Path("{id}")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String update(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id,
- JsonBelong jsonBelong) {
- LOG.debug("Graph [{}] update belong: {}", graph, jsonBelong);
- checkUpdatingBody(jsonBelong);
-
- HugeGraph g = graph(manager, graph);
- HugeBelong belong;
- try {
- belong = manager.authManager().getBelong(UserAPI.parseId(id));
- } catch (NotFoundException e) {
- throw new IllegalArgumentException("Invalid belong id: " + id);
- }
- belong = jsonBelong.build(belong);
- manager.authManager().updateBelong(belong);
- return manager.serializer(g).writeAuthElement(belong);
- }
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String list(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("user") String user,
- @QueryParam("group") String group,
- @QueryParam("limit") @DefaultValue("100") long limit) {
- LOG.debug("Graph [{}] list belongs by user {} or group {}",
- graph, user, group);
- E.checkArgument(user == null || group == null,
- "Can't pass both user and group at the same time");
-
- HugeGraph g = graph(manager, graph);
- List<HugeBelong> belongs;
- if (user != null) {
- Id id = UserAPI.parseId(user);
- belongs = manager.authManager().listBelongByUser(id, limit);
- } else if (group != null) {
- Id id = UserAPI.parseId(group);
- belongs = manager.authManager().listBelongByGroup(id, limit);
- } else {
- belongs = manager.authManager().listAllBelong(limit);
- }
- return manager.serializer(g).writeAuthElements("belongs", belongs);
- }
-
- @GET
- @Timed
- @Path("{id}")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String get(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id) {
- LOG.debug("Graph [{}] get belong: {}", graph, id);
-
- HugeGraph g = graph(manager, graph);
- HugeBelong belong = manager.authManager().getBelong(UserAPI.parseId(id));
- return manager.serializer(g).writeAuthElement(belong);
- }
-
- @DELETE
- @Timed
- @Path("{id}")
- @Consumes(APPLICATION_JSON)
- public void delete(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id) {
- LOG.debug("Graph [{}] delete belong: {}", graph, id);
-
- @SuppressWarnings("unused") // just check if the graph exists
- HugeGraph g = graph(manager, graph);
- try {
- manager.authManager().deleteBelong(UserAPI.parseId(id));
- } catch (NotFoundException e) {
- throw new IllegalArgumentException("Invalid belong id: " + id);
- }
- }
-
- @JsonIgnoreProperties(value = {"id", "belong_creator",
- "belong_create", "belong_update"})
- private static class JsonBelong implements Checkable {
-
- @JsonProperty("user")
- private String user;
- @JsonProperty("group")
- private String group;
- @JsonProperty("belong_description")
- private String description;
-
- public HugeBelong build(HugeBelong belong) {
- E.checkArgument(this.user == null ||
- belong.source().equals(UserAPI.parseId(this.user)),
- "The user of belong can't be updated");
- E.checkArgument(this.group == null ||
- belong.target().equals(UserAPI.parseId(this.group)),
- "The group of belong can't be updated");
- if (this.description != null) {
- belong.description(this.description);
- }
- return belong;
- }
-
- public HugeBelong build() {
- HugeBelong belong = new HugeBelong(UserAPI.parseId(this.user),
- UserAPI.parseId(this.group));
- belong.description(this.description);
- return belong;
- }
-
- @Override
- public void checkCreate(boolean isBatch) {
- E.checkArgumentNotNull(this.user,
- "The user of belong can't be null");
- E.checkArgumentNotNull(this.group,
- "The group of belong can't be null");
- }
-
- @Override
- public void checkUpdate() {
- E.checkArgumentNotNull(this.description,
- "The description of belong can't be null");
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/GroupAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/GroupAPI.java
deleted file mode 100644
index 943a5d8bb..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/GroupAPI.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * 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.api.auth;
-
-import java.util.List;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.DELETE;
-import jakarta.ws.rs.DefaultValue;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.PUT;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-
-import jakarta.inject.Singleton;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.StatusFilter.Status;
-import com.baidu.hugegraph.auth.HugeGroup;
-import com.baidu.hugegraph.backend.id.IdGenerator;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.define.Checkable;
-import com.baidu.hugegraph.exception.NotFoundException;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-@Path("graphs/{graph}/auth/groups")
-@Singleton
-@Tag(name = "GroupAPI")
-public class GroupAPI extends API {
-
- private static final Logger LOG = Log.logger(GroupAPI.class);
-
- @POST
- @Timed
- @Status(Status.CREATED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String create(@Context GraphManager manager,
- @PathParam("graph") String graph,
- JsonGroup jsonGroup) {
- LOG.debug("Graph [{}] create group: {}", graph, jsonGroup);
- checkCreatingBody(jsonGroup);
-
- HugeGraph g = graph(manager, graph);
- HugeGroup group = jsonGroup.build();
- group.id(manager.authManager().createGroup(group));
- return manager.serializer(g).writeAuthElement(group);
- }
-
- @PUT
- @Timed
- @Path("{id}")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String update(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id,
- JsonGroup jsonGroup) {
- LOG.debug("Graph [{}] update group: {}", graph, jsonGroup);
- checkUpdatingBody(jsonGroup);
-
- HugeGraph g = graph(manager, graph);
- HugeGroup group;
- try {
- group = manager.authManager().getGroup(UserAPI.parseId(id));
- } catch (NotFoundException e) {
- throw new IllegalArgumentException("Invalid group id: " + id);
- }
- group = jsonGroup.build(group);
- manager.authManager().updateGroup(group);
- return manager.serializer(g).writeAuthElement(group);
- }
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String list(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("limit") @DefaultValue("100") long limit) {
- LOG.debug("Graph [{}] list groups", graph);
-
- HugeGraph g = graph(manager, graph);
- List<HugeGroup> groups = manager.authManager().listAllGroups(limit);
- return manager.serializer(g).writeAuthElements("groups", groups);
- }
-
- @GET
- @Timed
- @Path("{id}")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String get(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id) {
- LOG.debug("Graph [{}] get group: {}", graph, id);
-
- HugeGraph g = graph(manager, graph);
- HugeGroup group = manager.authManager().getGroup(IdGenerator.of(id));
- return manager.serializer(g).writeAuthElement(group);
- }
-
- @DELETE
- @Timed
- @Path("{id}")
- @Consumes(APPLICATION_JSON)
- public void delete(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id) {
- LOG.debug("Graph [{}] delete group: {}", graph, id);
-
- @SuppressWarnings("unused") // just check if the graph exists
- HugeGraph g = graph(manager, graph);
- try {
- manager.authManager().deleteGroup(IdGenerator.of(id));
- } catch (NotFoundException e) {
- throw new IllegalArgumentException("Invalid group id: " + id);
- }
- }
-
- @JsonIgnoreProperties(value = {"id", "group_creator",
- "group_create", "group_update"})
- private static class JsonGroup implements Checkable {
-
- @JsonProperty("group_name")
- private String name;
- @JsonProperty("group_description")
- private String description;
-
- public HugeGroup build(HugeGroup group) {
- E.checkArgument(this.name == null || group.name().equals(this.name),
- "The name of group can't be updated");
- if (this.description != null) {
- group.description(this.description);
- }
- return group;
- }
-
- public HugeGroup build() {
- HugeGroup group = new HugeGroup(this.name);
- group.description(this.description);
- return group;
- }
-
- @Override
- public void checkCreate(boolean isBatch) {
- E.checkArgumentNotNull(this.name,
- "The name of group can't be null");
- }
-
- @Override
- public void checkUpdate() {
- E.checkArgumentNotNull(this.description,
- "The description of group can't be null");
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/LoginAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/LoginAPI.java
deleted file mode 100644
index 08e190393..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/LoginAPI.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * 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.api.auth;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.inject.Singleton;
-import javax.security.sasl.AuthenticationException;
-import jakarta.ws.rs.BadRequestException;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.DELETE;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.HeaderParam;
-import jakarta.ws.rs.NotAuthorizedException;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.core.Context;
-import jakarta.ws.rs.core.HttpHeaders;
-
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.AuthenticationFilter;
-import com.baidu.hugegraph.api.filter.StatusFilter;
-import com.baidu.hugegraph.api.filter.StatusFilter.Status;
-import com.baidu.hugegraph.auth.AuthConstant;
-import com.baidu.hugegraph.auth.UserWithRole;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.define.Checkable;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.collect.ImmutableMap;
-
-@Path("graphs/{graph}/auth")
-@Singleton
-@Tag(name = "LoginAPI")
-public class LoginAPI extends API {
-
- private static final Logger LOG = Log.logger(LoginAPI.class);
-
- @POST
- @Timed
- @Path("login")
- @Status(StatusFilter.Status.OK)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String login(@Context GraphManager manager,
- @PathParam("graph") String graph,
- JsonLogin jsonLogin) {
- LOG.debug("Graph [{}] user login: {}", graph, jsonLogin);
- checkCreatingBody(jsonLogin);
-
- try {
- String token = manager.authManager()
- .loginUser(jsonLogin.name, jsonLogin.password);
- HugeGraph g = graph(manager, graph);
- return manager.serializer(g)
- .writeMap(ImmutableMap.of("token", token));
- } catch (AuthenticationException e) {
- throw new NotAuthorizedException(e.getMessage(), e);
- }
- }
-
- @DELETE
- @Timed
- @Path("logout")
- @Status(StatusFilter.Status.OK)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public void logout(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @HeaderParam(HttpHeaders.AUTHORIZATION) String auth) {
- E.checkArgument(StringUtils.isNotEmpty(auth),
- "Request header Authorization must not be null");
- LOG.debug("Graph [{}] user logout: {}", graph, auth);
-
- if (!auth.startsWith(AuthenticationFilter.BEARER_TOKEN_PREFIX)) {
- throw new BadRequestException(
- "Only HTTP Bearer authentication is supported");
- }
-
- String token = auth.substring(AuthenticationFilter.BEARER_TOKEN_PREFIX
- .length());
-
- manager.authManager().logoutUser(token);
- }
-
- @GET
- @Timed
- @Path("verify")
- @Status(StatusFilter.Status.OK)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String verifyToken(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @HeaderParam(HttpHeaders.AUTHORIZATION)
- String token) {
- E.checkArgument(StringUtils.isNotEmpty(token),
- "Request header Authorization must not be null");
- LOG.debug("Graph [{}] get user: {}", graph, token);
-
- if (!token.startsWith(AuthenticationFilter.BEARER_TOKEN_PREFIX)) {
- throw new BadRequestException(
- "Only HTTP Bearer authentication is supported");
- }
-
- token = token.substring(AuthenticationFilter.BEARER_TOKEN_PREFIX
- .length());
- UserWithRole userWithRole = manager.authManager().validateUser(token);
-
- HugeGraph g = graph(manager, graph);
- return manager.serializer(g)
- .writeMap(ImmutableMap.of(AuthConstant.TOKEN_USER_NAME,
- userWithRole.username(),
- AuthConstant.TOKEN_USER_ID,
- userWithRole.userId()));
- }
-
- private static class JsonLogin implements Checkable {
-
- @JsonProperty("user_name")
- private String name;
- @JsonProperty("user_password")
- private String password;
-
- @Override
- public void checkCreate(boolean isBatch) {
- E.checkArgument(!StringUtils.isEmpty(this.name),
- "The name of user can't be null");
- E.checkArgument(!StringUtils.isEmpty(this.password),
- "The password of user can't be null");
- }
-
- @Override
- public void checkUpdate() {
- // pass
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java
deleted file mode 100644
index 6ecbe8de5..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java
+++ /dev/null
@@ -1,274 +0,0 @@
-/*
- * 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.api.auth;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.DELETE;
-import jakarta.ws.rs.DefaultValue;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.PUT;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.StatusFilter;
-import com.baidu.hugegraph.auth.AuthManager;
-import com.baidu.hugegraph.auth.HugeProject;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.define.Checkable;
-import com.baidu.hugegraph.exception.NotFoundException;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-@Path("graphs/{graph}/auth/projects")
-@Singleton
-@Tag(name = "ProjectAPI")
-public class ProjectAPI extends API {
-
- private static final Logger LOG = Log.logger(ProjectAPI.class);
- private static final String ACTION_ADD_GRAPH = "add_graph";
- private static final String ACTION_REMOVE_GRAPH = "remove_graph";
-
- @POST
- @Timed
- @StatusFilter.Status(StatusFilter.Status.CREATED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String create(@Context GraphManager manager,
- @PathParam("graph") String graph,
- JsonProject jsonProject) {
- LOG.debug("Graph [{}] create project: {}", graph, jsonProject);
- checkCreatingBody(jsonProject);
-
- HugeGraph g = graph(manager, graph);
- HugeProject project = jsonProject.build();
- Id projectId = manager.authManager().createProject(project);
- /*
- * Some fields of project(like admin_group) can only be known after
- * created
- */
- project = manager.authManager().getProject(projectId);
- return manager.serializer(g).writeAuthElement(project);
- }
-
- @PUT
- @Timed
- @Path("{id}")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String update(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id,
- @QueryParam("action") String action,
- JsonProject jsonProject) {
- LOG.debug("Graph [{}] update {} project: {}", graph, action,
- jsonProject);
- checkUpdatingBody(jsonProject);
-
- HugeGraph g = graph(manager, graph);
- HugeProject project;
- Id projectId = UserAPI.parseId(id);
- AuthManager authManager = manager.authManager();
- try {
- project = authManager.getProject(projectId);
- } catch (NotFoundException e) {
- throw new IllegalArgumentException("Invalid project id: " + id);
- }
- if (ProjectAPI.isAddGraph(action)) {
- project = jsonProject.buildAddGraph(project);
- } else if (ProjectAPI.isRemoveGraph(action)) {
- project = jsonProject.buildRemoveGraph(project);
- } else {
- E.checkArgument(StringUtils.isEmpty(action),
- "The action parameter can only be either " +
- "%s or %s or '', but got '%s'",
- ProjectAPI.ACTION_ADD_GRAPH,
- ProjectAPI.ACTION_REMOVE_GRAPH,
- action);
- project = jsonProject.buildUpdateDescription(project);
- }
- authManager.updateProject(project);
- return manager.serializer(g).writeAuthElement(project);
- }
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String list(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("limit") @DefaultValue("100") long limit) {
- LOG.debug("Graph [{}] list project", graph);
-
- HugeGraph g = graph(manager, graph);
- List<HugeProject> projects = manager.authManager()
- .listAllProject(limit);
- return manager.serializer(g).writeAuthElements("projects", projects);
- }
-
- @GET
- @Timed
- @Path("{id}")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String get(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id) {
- LOG.debug("Graph [{}] get project: {}", graph, id);
-
- HugeGraph g = graph(manager, graph);
- HugeProject project;
- try {
- project = manager.authManager().getProject(UserAPI.parseId(id));
- } catch (NotFoundException e) {
- throw new IllegalArgumentException("Invalid project id: " + id);
- }
- return manager.serializer(g).writeAuthElement(project);
- }
-
- @DELETE
- @Timed
- @Path("{id}")
- @Consumes(APPLICATION_JSON)
- public void delete(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id) {
- LOG.debug("Graph [{}] delete project: {}", graph, id);
-
- @SuppressWarnings("unused") // just check if the graph exists
- HugeGraph g = graph(manager, graph);
- try {
- manager.authManager().deleteProject(UserAPI.parseId(id));
- } catch (NotFoundException e) {
- throw new IllegalArgumentException("Invalid project id: " + id);
- }
- }
-
- public static boolean isAddGraph(String action) {
- return ACTION_ADD_GRAPH.equals(action);
- }
-
- public static boolean isRemoveGraph(String action) {
- return ACTION_REMOVE_GRAPH.equals(action);
- }
-
- @JsonIgnoreProperties(value = {"id", "target_creator",
- "target_create", "target_update",
- "project_admin_group", "project_op_group",
- "project_target"})
- private static class JsonProject implements Checkable {
-
- @JsonProperty("project_name")
- private String name;
- @JsonProperty("project_graphs")
- private Set<String> graphs;
- @JsonProperty("project_description")
- private String description;
-
- public HugeProject build() {
- HugeProject project = new HugeProject(this.name, this.description);
- return project;
- }
-
- private HugeProject buildAddGraph(HugeProject project) {
- E.checkArgument(this.name == null ||
- this.name.equals(project.name()),
- "The name of project can't be updated");
- E.checkArgument(!CollectionUtils.isEmpty(this.graphs),
- "The graphs of project can't be empty " +
- "when adding graphs");
- E.checkArgument(StringUtils.isEmpty(this.description),
- "The description of project can't be updated " +
- "when adding graphs");
- Set<String> sourceGraphs = new HashSet<>(project.graphs());
- E.checkArgument(!sourceGraphs.containsAll(this.graphs),
- "There are graphs '%s' of project '%s' that " +
- "have been added in the graph collection",
- this.graphs, project.id());
- sourceGraphs.addAll(this.graphs);
- project.graphs(sourceGraphs);
- return project;
- }
-
- private HugeProject buildRemoveGraph(HugeProject project) {
- E.checkArgument(this.name == null ||
- this.name.equals(project.name()),
- "The name of project can't be updated");
- E.checkArgument(!CollectionUtils.isEmpty(this.graphs),
- "The graphs of project can't be empty " +
- "when removing graphs");
- E.checkArgument(StringUtils.isEmpty(this.description),
- "The description of project can't be updated " +
- "when removing graphs");
- Set<String> sourceGraphs = new HashSet<>(project.graphs());
- sourceGraphs.removeAll(this.graphs);
- project.graphs(sourceGraphs);
- return project;
- }
-
- private HugeProject buildUpdateDescription(HugeProject project) {
- E.checkArgument(this.name == null ||
- this.name.equals(project.name()),
- "The name of project can't be updated");
- E.checkArgumentNotNull(this.description,
- "The description of project " +
- "can't be null");
- E.checkArgument(CollectionUtils.isEmpty(this.graphs),
- "The graphs of project can't be updated");
- project.description(this.description);
- return project;
- }
-
- @Override
- public void checkCreate(boolean isBatch) {
- E.checkArgumentNotNull(this.name,
- "The name of project can't be null");
- E.checkArgument(CollectionUtils.isEmpty(this.graphs),
- "The graphs '%s' of project can't be added when" +
- "creating the project '%s'",
- this.graphs, this.name);
- }
-
- @Override
- public void checkUpdate() {
- E.checkArgument(!CollectionUtils.isEmpty(this.graphs) ||
- this.description != null,
- "Must specify 'graphs' or 'description' " +
- "field that need to be updated");
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/TargetAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/TargetAPI.java
deleted file mode 100644
index c19facc8e..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/TargetAPI.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * 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.api.auth;
-
-import java.util.List;
-import java.util.Map;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.DELETE;
-import jakarta.ws.rs.DefaultValue;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.PUT;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.StatusFilter.Status;
-import com.baidu.hugegraph.auth.HugeTarget;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.define.Checkable;
-import com.baidu.hugegraph.exception.NotFoundException;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.JsonUtil;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-@Path("graphs/{graph}/auth/targets")
-@Singleton
-@Tag(name = "TargetAPI")
-public class TargetAPI extends API {
-
- private static final Logger LOG = Log.logger(TargetAPI.class);
-
- @POST
- @Timed
- @Status(Status.CREATED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String create(@Context GraphManager manager,
- @PathParam("graph") String graph,
- JsonTarget jsonTarget) {
- LOG.debug("Graph [{}] create target: {}", graph, jsonTarget);
- checkCreatingBody(jsonTarget);
-
- HugeGraph g = graph(manager, graph);
- HugeTarget target = jsonTarget.build();
- target.id(manager.authManager().createTarget(target));
- return manager.serializer(g).writeAuthElement(target);
- }
-
- @PUT
- @Timed
- @Path("{id}")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String update(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id,
- JsonTarget jsonTarget) {
- LOG.debug("Graph [{}] update target: {}", graph, jsonTarget);
- checkUpdatingBody(jsonTarget);
-
- HugeGraph g = graph(manager, graph);
- HugeTarget target;
- try {
- target = manager.authManager().getTarget(UserAPI.parseId(id));
- } catch (NotFoundException e) {
- throw new IllegalArgumentException("Invalid target id: " + id);
- }
- target = jsonTarget.build(target);
- manager.authManager().updateTarget(target);
- return manager.serializer(g).writeAuthElement(target);
- }
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String list(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("limit") @DefaultValue("100") long limit) {
- LOG.debug("Graph [{}] list targets", graph);
-
- HugeGraph g = graph(manager, graph);
- List<HugeTarget> targets = manager.authManager().listAllTargets(limit);
- return manager.serializer(g).writeAuthElements("targets", targets);
- }
-
- @GET
- @Timed
- @Path("{id}")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String get(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id) {
- LOG.debug("Graph [{}] get target: {}", graph, id);
-
- HugeGraph g = graph(manager, graph);
- HugeTarget target = manager.authManager().getTarget(UserAPI.parseId(id));
- return manager.serializer(g).writeAuthElement(target);
- }
-
- @DELETE
- @Timed
- @Path("{id}")
- @Consumes(APPLICATION_JSON)
- public void delete(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id) {
- LOG.debug("Graph [{}] delete target: {}", graph, id);
-
- @SuppressWarnings("unused") // just check if the graph exists
- HugeGraph g = graph(manager, graph);
- try {
- manager.authManager().deleteTarget(UserAPI.parseId(id));
- } catch (NotFoundException e) {
- throw new IllegalArgumentException("Invalid target id: " + id);
- }
- }
-
- @JsonIgnoreProperties(value = {"id", "target_creator",
- "target_create", "target_update"})
- private static class JsonTarget implements Checkable {
-
- @JsonProperty("target_name")
- private String name;
- @JsonProperty("target_graph")
- private String graph;
- @JsonProperty("target_url")
- private String url;
- @JsonProperty("target_resources") // error when List<HugeResource>
- private List<Map<String, Object>> resources;
-
- public HugeTarget build(HugeTarget target) {
- E.checkArgument(this.name == null ||
- target.name().equals(this.name),
- "The name of target can't be updated");
- E.checkArgument(this.graph == null ||
- target.graph().equals(this.graph),
- "The graph of target can't be updated");
- if (this.url != null) {
- target.url(this.url);
- }
- if (this.resources != null) {
- target.resources(JsonUtil.toJson(this.resources));
- }
- return target;
- }
-
- public HugeTarget build() {
- HugeTarget target = new HugeTarget(this.name, this.graph, this.url);
- if (this.resources != null) {
- target.resources(JsonUtil.toJson(this.resources));
- }
- return target;
- }
-
- @Override
- public void checkCreate(boolean isBatch) {
- E.checkArgumentNotNull(this.name,
- "The name of target can't be null");
- E.checkArgumentNotNull(this.graph,
- "The graph of target can't be null");
- E.checkArgumentNotNull(this.url,
- "The url of target can't be null");
- }
-
- @Override
- public void checkUpdate() {
- E.checkArgument(this.url != null ||
- this.resources != null,
- "Expect one of target url/resources");
-
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/UserAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/UserAPI.java
deleted file mode 100644
index ce4fe3b31..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/UserAPI.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * 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.api.auth;
-
-import java.util.List;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.DELETE;
-import jakarta.ws.rs.DefaultValue;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.PUT;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.StatusFilter.Status;
-import com.baidu.hugegraph.auth.HugeUser;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.backend.id.IdGenerator;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.define.Checkable;
-import com.baidu.hugegraph.exception.NotFoundException;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.baidu.hugegraph.util.StringEncoding;
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-@Path("graphs/{graph}/auth/users")
-@Singleton
-@Tag(name = "UserAPI")
-public class UserAPI extends API {
-
- private static final Logger LOG = Log.logger(UserAPI.class);
-
- @POST
- @Timed
- @Status(Status.CREATED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String create(@Context GraphManager manager,
- @PathParam("graph") String graph,
- JsonUser jsonUser) {
- LOG.debug("Graph [{}] create user: {}", graph, jsonUser);
- checkCreatingBody(jsonUser);
-
- HugeGraph g = graph(manager, graph);
- HugeUser user = jsonUser.build();
- user.id(manager.authManager().createUser(user));
- return manager.serializer(g).writeAuthElement(user);
- }
-
- @PUT
- @Timed
- @Path("{id}")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String update(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id,
- JsonUser jsonUser) {
- LOG.debug("Graph [{}] update user: {}", graph, jsonUser);
- checkUpdatingBody(jsonUser);
-
- HugeGraph g = graph(manager, graph);
- HugeUser user;
- try {
- user = manager.authManager().getUser(UserAPI.parseId(id));
- } catch (NotFoundException e) {
- throw new IllegalArgumentException("Invalid user id: " + id);
- }
- user = jsonUser.build(user);
- manager.authManager().updateUser(user);
- return manager.serializer(g).writeAuthElement(user);
- }
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String list(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("limit") @DefaultValue("100") long limit) {
- LOG.debug("Graph [{}] list users", graph);
-
- HugeGraph g = graph(manager, graph);
- List<HugeUser> users = manager.authManager().listAllUsers(limit);
- return manager.serializer(g).writeAuthElements("users", users);
- }
-
- @GET
- @Timed
- @Path("{id}")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String get(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id) {
- LOG.debug("Graph [{}] get user: {}", graph, id);
-
- HugeGraph g = graph(manager, graph);
- HugeUser user = manager.authManager().getUser(IdGenerator.of(id));
- return manager.serializer(g).writeAuthElement(user);
- }
-
- @GET
- @Timed
- @Path("{id}/role")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String role(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id) {
- LOG.debug("Graph [{}] get user role: {}", graph, id);
-
- @SuppressWarnings("unused") // just check if the graph exists
- HugeGraph g = graph(manager, graph);
- HugeUser user = manager.authManager().getUser(IdGenerator.of(id));
- return manager.authManager().rolePermission(user).toJson();
- }
-
- @DELETE
- @Timed
- @Path("{id}")
- @Consumes(APPLICATION_JSON)
- public void delete(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id) {
- LOG.debug("Graph [{}] delete user: {}", graph, id);
-
- @SuppressWarnings("unused") // just check if the graph exists
- HugeGraph g = graph(manager, graph);
- try {
- manager.authManager().deleteUser(IdGenerator.of(id));
- } catch (NotFoundException e) {
- throw new IllegalArgumentException("Invalid user id: " + id);
- }
- }
-
- protected static Id parseId(String id) {
- return IdGenerator.of(id);
- }
-
- @JsonIgnoreProperties(value = {"id", "user_creator",
- "user_create", "user_update"})
- private static class JsonUser implements Checkable {
-
- @JsonProperty("user_name")
- private String name;
- @JsonProperty("user_password")
- private String password;
- @JsonProperty("user_phone")
- private String phone;
- @JsonProperty("user_email")
- private String email;
- @JsonProperty("user_avatar")
- private String avatar;
- @JsonProperty("user_description")
- private String description;
-
- public HugeUser build(HugeUser user) {
- E.checkArgument(this.name == null || user.name().equals(this.name),
- "The name of user can't be updated");
- if (this.password != null) {
- user.password(StringEncoding.hashPassword(this.password));
- }
- if (this.phone != null) {
- user.phone(this.phone);
- }
- if (this.email != null) {
- user.email(this.email);
- }
- if (this.avatar != null) {
- user.avatar(this.avatar);
- }
- if (this.description != null) {
- user.description(this.description);
- }
- return user;
- }
-
- public HugeUser build() {
- HugeUser user = new HugeUser(this.name);
- user.password(StringEncoding.hashPassword(this.password));
- user.phone(this.phone);
- user.email(this.email);
- user.avatar(this.avatar);
- user.description(this.description);
- return user;
- }
-
- @Override
- public void checkCreate(boolean isBatch) {
- E.checkArgument(!StringUtils.isEmpty(this.name),
- "The name of user can't be null");
- E.checkArgument(!StringUtils.isEmpty(this.password),
- "The password of user can't be null");
- }
-
- @Override
- public void checkUpdate() {
- E.checkArgument(!StringUtils.isEmpty(this.password) ||
- this.phone != null ||
- this.email != null ||
- this.avatar != null,
- "Expect one of user password/phone/email/avatar]");
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/AuthenticationFilter.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/AuthenticationFilter.java
deleted file mode 100644
index 14a5690bc..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/AuthenticationFilter.java
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * 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.api.filter;
-
-import java.io.IOException;
-import java.security.Principal;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import jakarta.annotation.Priority;
-import jakarta.ws.rs.BadRequestException;
-import jakarta.ws.rs.NotAuthorizedException;
-import jakarta.ws.rs.Priorities;
-import jakarta.ws.rs.container.ContainerRequestContext;
-import jakarta.ws.rs.container.ContainerRequestFilter;
-import jakarta.ws.rs.container.PreMatching;
-import jakarta.ws.rs.core.Context;
-import jakarta.ws.rs.core.HttpHeaders;
-import jakarta.ws.rs.core.SecurityContext;
-import jakarta.ws.rs.core.UriInfo;
-import jakarta.ws.rs.ext.Provider;
-import javax.xml.bind.DatatypeConverter;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.tinkerpop.gremlin.server.auth.AuthenticationException;
-import org.glassfish.grizzly.http.server.Request;
-import org.glassfish.grizzly.utils.Charsets;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.auth.HugeAuthenticator;
-import com.baidu.hugegraph.auth.HugeAuthenticator.RequiredPerm;
-import com.baidu.hugegraph.auth.HugeAuthenticator.RolePerm;
-import com.baidu.hugegraph.auth.HugeAuthenticator.User;
-import com.baidu.hugegraph.auth.RolePermission;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.google.common.collect.ImmutableList;
-
-@Provider
-@PreMatching
-@Priority(Priorities.AUTHENTICATION)
-public class AuthenticationFilter implements ContainerRequestFilter {
-
- public static final String BASIC_AUTH_PREFIX = "Basic ";
- public static final String BEARER_TOKEN_PREFIX = "Bearer ";
-
- private static final Logger LOG = Log.logger(AuthenticationFilter.class);
-
- private static final List<String> WHITE_API_LIST = ImmutableList.of(
- "auth/login",
- "versions"
- );
-
- @Context
- private jakarta.inject.Provider<GraphManager> managerProvider;
-
- @Context
- private jakarta.inject.Provider<Request> requestProvider;
-
- @Override
- public void filter(ContainerRequestContext context) throws IOException {
- if (AuthenticationFilter.isWhiteAPI(context)) {
- return;
- }
- User user = this.authenticate(context);
- Authorizer authorizer = new Authorizer(user, context.getUriInfo());
- context.setSecurityContext(authorizer);
- }
-
- protected User authenticate(ContainerRequestContext context) {
- GraphManager manager = this.managerProvider.get();
- E.checkState(manager != null, "Context GraphManager is absent");
-
- if (!manager.requireAuthentication()) {
- // Return anonymous user with admin role if disable authentication
- return User.ANONYMOUS;
- }
-
- // Get peer info
- Request request = this.requestProvider.get();
- String peer = null;
- String path = null;
- if (request != null) {
- peer = request.getRemoteAddr() + ":" + request.getRemotePort();
- path = request.getRequestURI();
- }
-
- Map<String, String> credentials = new HashMap<>();
- // Extract authentication credentials
- String auth = context.getHeaderString(HttpHeaders.AUTHORIZATION);
- if (auth == null) {
- throw new NotAuthorizedException(
- "Authentication credentials are required",
- "Missing authentication credentials");
- }
-
- if (auth.startsWith(BASIC_AUTH_PREFIX)) {
- auth = auth.substring(BASIC_AUTH_PREFIX.length());
- auth = new String(DatatypeConverter.parseBase64Binary(auth),
- Charsets.ASCII_CHARSET);
- String[] values = auth.split(":");
- if (values.length != 2) {
- throw new BadRequestException(
- "Invalid syntax for username and password");
- }
-
- final String username = values[0];
- final String password = values[1];
-
- if (StringUtils.isEmpty(username) ||
- StringUtils.isEmpty(password)) {
- throw new BadRequestException(
- "Invalid syntax for username and password");
- }
-
- credentials.put(HugeAuthenticator.KEY_USERNAME, username);
- credentials.put(HugeAuthenticator.KEY_PASSWORD, password);
- } else if (auth.startsWith(BEARER_TOKEN_PREFIX)) {
- String token = auth.substring(BEARER_TOKEN_PREFIX.length());
- credentials.put(HugeAuthenticator.KEY_TOKEN, token);
- } else {
- throw new BadRequestException(
- "Only HTTP Basic or Bearer authentication is supported");
- }
-
- credentials.put(HugeAuthenticator.KEY_ADDRESS, peer);
- credentials.put(HugeAuthenticator.KEY_PATH, path);
-
- // Validate the extracted credentials
- try {
- return manager.authenticate(credentials);
- } catch (AuthenticationException e) {
- throw new NotAuthorizedException("Authentication failed",
- e.getMessage());
- }
- }
-
- public static class Authorizer implements SecurityContext {
-
- private final UriInfo uri;
- private final User user;
- private final Principal principal;
-
- public Authorizer(final User user, final UriInfo uri) {
- E.checkNotNull(user, "user");
- E.checkNotNull(uri, "uri");
- this.uri = uri;
- this.user = user;
- this.principal = new UserPrincipal();
- }
-
- public String username() {
- return this.user.username();
- }
-
- public RolePermission role() {
- return this.user.role();
- }
-
- @Override
- public Principal getUserPrincipal() {
- return this.principal;
- }
-
- @Override
- public boolean isUserInRole(String required) {
- if (required.equals(HugeAuthenticator.KEY_DYNAMIC)) {
- // Let the resource itself determine dynamically
- return true;
- } else {
- return this.matchPermission(required);
- }
- }
-
- @Override
- public boolean isSecure() {
- return "https".equals(this.uri.getRequestUri().getScheme());
- }
-
- @Override
- public String getAuthenticationScheme() {
- return SecurityContext.BASIC_AUTH;
- }
-
- private boolean matchPermission(String required) {
- boolean valid;
- RequiredPerm requiredPerm;
-
- if (!required.startsWith(HugeAuthenticator.KEY_OWNER)) {
- // Permission format like: "admin"
- requiredPerm = new RequiredPerm();
- requiredPerm.owner(required);
- } else {
- // The required like: $owner=graph1 $action=vertex_write
- requiredPerm = RequiredPerm.fromPermission(required);
-
- /*
- * Replace owner value(it may be a variable) if the permission
- * format like: "$owner=$graph $action=vertex_write"
- */
- String owner = requiredPerm.owner();
- if (owner.startsWith(HugeAuthenticator.VAR_PREFIX)) {
- // Replace `$graph` with graph name like "graph1"
- int prefixLen = HugeAuthenticator.VAR_PREFIX.length();
- assert owner.length() > prefixLen;
- owner = owner.substring(prefixLen);
- owner = this.getPathParameter(owner);
- requiredPerm.owner(owner);
- }
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("Verify permission {} {} for user '{}' with role {}",
- requiredPerm.action().string(),
- requiredPerm.resourceObject(),
- this.user.username(), this.user.role());
- }
-
- // verify role permission
- valid = RolePerm.match(this.role(), requiredPerm);
-
- if (!valid && LOG.isInfoEnabled() &&
- !required.equals(HugeAuthenticator.USER_ADMIN)) {
- LOG.info("User '{}' is denied to {} {}",
- this.user.username(), requiredPerm.action().string(),
- requiredPerm.resourceObject());
- }
- return valid;
- }
-
- private String getPathParameter(String key) {
- List<String> params = this.uri.getPathParameters().get(key);
- E.checkState(params != null && params.size() == 1,
- "There is no matched path parameter: '%s'", key);
- return params.get(0);
- }
-
- private final class UserPrincipal implements Principal {
-
- @Override
- public String getName() {
- return Authorizer.this.user.getName();
- }
-
- @Override
- public String toString() {
- return Authorizer.this.user.toString();
- }
-
- @Override
- public int hashCode() {
- return Authorizer.this.user.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- return Authorizer.this.user.equals(obj);
- }
- }
- }
-
- public static boolean isWhiteAPI(ContainerRequestContext context) {
- String path = context.getUriInfo().getPath();
-
- for (String whiteApi : WHITE_API_LIST) {
- if (path.endsWith(whiteApi)) {
- return true;
- }
- }
- return false;
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/CompressInterceptor.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/CompressInterceptor.java
deleted file mode 100644
index b7c3f24cf..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/CompressInterceptor.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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.api.filter;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.util.zip.GZIPOutputStream;
-
-import jakarta.ws.rs.NameBinding;
-import jakarta.ws.rs.WebApplicationException;
-import jakarta.ws.rs.core.MultivaluedMap;
-import jakarta.ws.rs.ext.Provider;
-import jakarta.ws.rs.ext.WriterInterceptor;
-import jakarta.ws.rs.ext.WriterInterceptorContext;
-import jakarta.inject.Singleton;
-
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.util.Log;
-
-@Provider
-@Singleton
-@CompressInterceptor.Compress
-public class CompressInterceptor implements WriterInterceptor {
-
- public static final String GZIP = "gzip";
-
- private static final Logger LOG = Log.logger(CompressInterceptor.class);
-
- // Set compress output buffer size to 4KB (about 40~600 vertices)
- public static final int BUFFER_SIZE = 1024 * 4;
-
- @Override
- public void aroundWriteTo(WriterInterceptorContext context)
- throws IOException, WebApplicationException {
- // If there is no annotation(like exception), we don't compress it
- if (context.getAnnotations().length > 0) {
- try {
- this.compress(context);
- } catch (Throwable e) {
- LOG.warn("Failed to compress response", e);
- /*
- * FIXME: This will cause java.lang.IllegalStateException:
- * Illegal attempt to call getOutputStream() after getWriter()
- */
- throw e;
- }
- }
-
- context.proceed();
- }
-
- private void compress(WriterInterceptorContext context)
- throws IOException {
- // Get compress info from the @Compress annotation
- final Compress compression = getCompressAnnotation(context);
- final String encoding = compression.value();
- final int buffer = compression.buffer();
-
- // Update header
- MultivaluedMap<String,Object> headers = context.getHeaders();
- headers.remove("Content-Length");
- headers.add("Content-Encoding", encoding);
-
- // Replace output stream with new compression stream
- OutputStream output = null;
- if (encoding.equalsIgnoreCase(GZIP)) {
- output = new GZIPOutputStream(context.getOutputStream(), buffer);
- } else {
- // NOTE: Currently we just support GZIP.
- throw new WebApplicationException("Can't support: " + encoding);
- }
- context.setOutputStream(output);
- }
-
- private static Compress getCompressAnnotation(WriterInterceptorContext c) {
- for (Annotation annotation : c.getAnnotations()) {
- if (annotation.annotationType() == Compress.class) {
- return (Compress) annotation;
- }
- }
- throw new AssertionError("Unable find @Compress annotation");
- }
-
- @NameBinding
- @Retention(RetentionPolicy.RUNTIME)
- public @interface Compress {
- String value() default GZIP;
- int buffer() default BUFFER_SIZE;
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/DecompressInterceptor.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/DecompressInterceptor.java
deleted file mode 100644
index 496cf6ecd..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/DecompressInterceptor.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.api.filter;
-
-import java.io.IOException;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.util.zip.GZIPInputStream;
-
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.NameBinding;
-import jakarta.ws.rs.ext.Provider;
-import jakarta.ws.rs.ext.ReaderInterceptor;
-import jakarta.ws.rs.ext.ReaderInterceptorContext;
-
-@Provider
-@Singleton
-@DecompressInterceptor.Decompress
-public class DecompressInterceptor implements ReaderInterceptor {
-
- public static final String GZIP = "gzip";
-
- @Override
- public Object aroundReadFrom(ReaderInterceptorContext context)
- throws IOException {
- // NOTE: Currently we just support GZIP
- String encoding = context.getHeaders().getFirst("Content-Encoding");
- if (!GZIP.equalsIgnoreCase(encoding)) {
- return context.proceed();
- }
- context.setInputStream(new GZIPInputStream(context.getInputStream()));
- return context.proceed();
- }
-
-
- @NameBinding
- @Retention(RetentionPolicy.RUNTIME)
- public @interface Decompress {
- String value() default GZIP;
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/ExceptionFilter.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/ExceptionFilter.java
deleted file mode 100644
index 2b26f391b..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/ExceptionFilter.java
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
- * 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.api.filter;
-
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-
-import javax.json.Json;
-import javax.json.JsonArrayBuilder;
-import javax.json.JsonObjectBuilder;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.annotation.security.RolesAllowed;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.PUT;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.WebApplicationException;
-import jakarta.ws.rs.core.Context;
-import jakarta.ws.rs.core.MediaType;
-import jakarta.ws.rs.core.MultivaluedMap;
-import jakarta.ws.rs.core.Response;
-import jakarta.ws.rs.ext.ExceptionMapper;
-import jakarta.ws.rs.ext.Provider;
-
-import org.apache.commons.lang3.StringUtils;
-import org.glassfish.hk2.api.MultiException;
-
-import com.baidu.hugegraph.HugeException;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.config.HugeConfig;
-import com.baidu.hugegraph.config.ServerOptions;
-import com.baidu.hugegraph.exception.HugeGremlinException;
-import com.baidu.hugegraph.exception.NotFoundException;
-import com.codahale.metrics.annotation.Timed;
-import com.google.common.collect.ImmutableMap;
-
-public class ExceptionFilter {
-
- private static final int BAD_REQUEST_ERROR =
- Response.Status.BAD_REQUEST.getStatusCode();
- private static final int NOT_FOUND_ERROR =
- Response.Status.NOT_FOUND.getStatusCode();
- private static final int INTERNAL_SERVER_ERROR =
- Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
-
- public static class TracedExceptionMapper extends API {
-
- private static boolean forcedTrace = false;
-
- @Context
- private jakarta.inject.Provider<HugeConfig> configProvider;
-
- protected boolean trace() {
- if (forcedTrace) {
- return true;
- }
- HugeConfig config = this.configProvider.get();
- if (config == null) {
- return false;
- }
- return config.get(ServerOptions.ALLOW_TRACE);
- }
- }
-
- @Path("exception/trace")
- @Singleton
- @Tag(name = "TracedExceptionAPI")
- public static class TracedExceptionAPI extends API {
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin"})
- public Object get() {
- return ImmutableMap.of("trace", TracedExceptionMapper.forcedTrace);
- }
-
- @PUT
- @Timed
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin"})
- public Object trace(boolean trace) {
- TracedExceptionMapper.forcedTrace = trace;
- return ImmutableMap.of("trace", TracedExceptionMapper.forcedTrace);
- }
- }
-
- @Provider
- public static class HugeExceptionMapper
- extends TracedExceptionMapper
- implements ExceptionMapper<HugeException> {
-
- @Override
- public Response toResponse(HugeException exception) {
- return Response.status(BAD_REQUEST_ERROR)
- .type(MediaType.APPLICATION_JSON)
- .entity(formatException(exception, this.trace()))
- .build();
- }
- }
-
- @Provider
- public static class IllegalArgumentExceptionMapper
- extends TracedExceptionMapper
- implements ExceptionMapper<IllegalArgumentException> {
-
- @Override
- public Response toResponse(IllegalArgumentException exception) {
- return Response.status(BAD_REQUEST_ERROR)
- .type(MediaType.APPLICATION_JSON)
- .entity(formatException(exception, this.trace()))
- .build();
- }
- }
-
- @Provider
- public static class NotFoundExceptionMapper
- extends TracedExceptionMapper
- implements ExceptionMapper<NotFoundException> {
-
- @Override
- public Response toResponse(NotFoundException exception) {
- return Response.status(NOT_FOUND_ERROR)
- .type(MediaType.APPLICATION_JSON)
- .entity(formatException(exception, this.trace()))
- .build();
- }
- }
-
- @Provider
- public static class NoSuchElementExceptionMapper
- extends TracedExceptionMapper
- implements ExceptionMapper<NoSuchElementException> {
-
- @Override
- public Response toResponse(NoSuchElementException exception) {
- return Response.status(NOT_FOUND_ERROR)
- .type(MediaType.APPLICATION_JSON)
- .entity(formatException(exception, this.trace()))
- .build();
- }
- }
-
- @Provider
- public static class WebApplicationExceptionMapper
- extends TracedExceptionMapper
- implements ExceptionMapper<WebApplicationException> {
-
- @Override
- public Response toResponse(WebApplicationException exception) {
- Response response = exception.getResponse();
- if (response.hasEntity()) {
- return response;
- }
- MultivaluedMap<String, Object> headers = response.getHeaders();
- boolean trace = this.trace(response.getStatus());
- response = Response.status(response.getStatus())
- .type(MediaType.APPLICATION_JSON)
- .entity(formatException(exception, trace))
- .build();
- response.getHeaders().putAll(headers);
- return response;
- }
-
- private boolean trace(int status) {
- return this.trace() && status == INTERNAL_SERVER_ERROR;
- }
- }
-
- @Provider
- public static class HugeGremlinExceptionMapper
- extends TracedExceptionMapper
- implements ExceptionMapper<HugeGremlinException> {
-
- @Override
- public Response toResponse(HugeGremlinException exception) {
- return Response.status(exception.statusCode())
- .type(MediaType.APPLICATION_JSON)
- .entity(formatGremlinException(exception,
- this.trace()))
- .build();
- }
- }
-
- @Provider
- public static class AssertionErrorMapper extends TracedExceptionMapper
- implements ExceptionMapper<AssertionError> {
-
- @Override
- public Response toResponse(AssertionError exception) {
- return Response.status(INTERNAL_SERVER_ERROR)
- .type(MediaType.APPLICATION_JSON)
- .entity(formatException(exception, true))
- .build();
- }
- }
-
- @Provider
- public static class UnknownExceptionMapper extends TracedExceptionMapper
- implements ExceptionMapper<Throwable> {
-
- @Override
- public Response toResponse(Throwable exception) {
- if (exception instanceof MultiException &&
- ((MultiException) exception).getErrors().size() == 1) {
- exception = ((MultiException) exception).getErrors().get(0);
- }
- return Response.status(INTERNAL_SERVER_ERROR)
- .type(MediaType.APPLICATION_JSON)
- .entity(formatException(exception, this.trace()))
- .build();
- }
- }
-
- public static String formatException(Throwable exception, boolean trace) {
- String clazz = exception.getClass().toString();
- String message = exception.getMessage() != null ?
- exception.getMessage() : "";
- String cause = exception.getCause() != null ?
- exception.getCause().toString() : "";
-
- JsonObjectBuilder json = Json.createObjectBuilder()
- .add("exception", clazz)
- .add("message", message)
- .add("cause", cause);
-
- if (trace) {
- JsonArrayBuilder traces = Json.createArrayBuilder();
- for (StackTraceElement i : exception.getStackTrace()) {
- traces.add(i.toString());
- }
- json.add("trace", traces);
- }
-
- return json.build().toString();
- }
-
- public static String formatGremlinException(HugeGremlinException exception,
- boolean trace) {
- Map<String, Object> map = exception.response();
- String message = (String) map.get("message");
- String exClassName = (String) map.get("Exception-Class");
- @SuppressWarnings("unchecked")
- List<String> exceptions = (List<String>) map.get("exceptions");
- String stackTrace = (String) map.get("stackTrace");
-
- message = message != null ? message : "";
- exClassName = exClassName != null ? exClassName : "";
- String cause = exceptions != null ? exceptions.toString() : "";
-
- JsonObjectBuilder json = Json.createObjectBuilder()
- .add("exception", exClassName)
- .add("message", message)
- .add("cause", cause);
-
- if (trace && stackTrace != null) {
- JsonArrayBuilder traces = Json.createArrayBuilder();
- for (String part : StringUtils.split(stackTrace, '\n')) {
- traces.add(part);
- }
- json.add("trace", traces);
- }
-
- return json.build().toString();
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/LoadDetectFilter.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/LoadDetectFilter.java
deleted file mode 100644
index ba59f1ab8..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/LoadDetectFilter.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * 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.api.filter;
-
-import java.util.List;
-import java.util.Set;
-
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.ServiceUnavailableException;
-import jakarta.ws.rs.container.ContainerRequestContext;
-import jakarta.ws.rs.container.ContainerRequestFilter;
-import jakarta.ws.rs.container.PreMatching;
-import jakarta.ws.rs.core.Context;
-import jakarta.ws.rs.core.PathSegment;
-import jakarta.ws.rs.ext.Provider;
-
-import com.baidu.hugegraph.config.HugeConfig;
-import com.baidu.hugegraph.config.ServerOptions;
-import com.baidu.hugegraph.define.WorkLoad;
-import com.baidu.hugegraph.util.Bytes;
-import com.baidu.hugegraph.util.E;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.util.concurrent.RateLimiter;
-
-@Provider
-@Singleton
-@PreMatching
-public class LoadDetectFilter implements ContainerRequestFilter {
-
- private static final Set<String> WHITE_API_LIST = ImmutableSet.of(
- "",
- "apis",
- "metrics",
- "versions"
- );
-
- // Call gc every 30+ seconds if memory is low and request frequently
- private static final RateLimiter GC_RATE_LIMITER =
- RateLimiter.create(1.0 / 30);
-
- @Context
- private jakarta.inject.Provider<HugeConfig> configProvider;
- @Context
- private jakarta.inject.Provider<WorkLoad> loadProvider;
-
- @Override
- public void filter(ContainerRequestContext context) {
- if (LoadDetectFilter.isWhiteAPI(context)) {
- return;
- }
-
- HugeConfig config = this.configProvider.get();
-
- int maxWorkerThreads = config.get(ServerOptions.MAX_WORKER_THREADS);
- WorkLoad load = this.loadProvider.get();
- // There will be a thread doesn't work, dedicated to statistics
- if (load.incrementAndGet() >= maxWorkerThreads) {
- throw new ServiceUnavailableException(String.format(
- "The server is too busy to process the request, " +
- "you can config %s to adjust it or try again later",
- ServerOptions.MAX_WORKER_THREADS.name()));
- }
-
- long minFreeMemory = config.get(ServerOptions.MIN_FREE_MEMORY);
- long allocatedMem = Runtime.getRuntime().totalMemory() -
- Runtime.getRuntime().freeMemory();
- long presumableFreeMem = (Runtime.getRuntime().maxMemory() -
- allocatedMem) / Bytes.MB;
- if (presumableFreeMem < minFreeMemory) {
- gcIfNeeded();
- throw new ServiceUnavailableException(String.format(
- "The server available memory %s(MB) is below than " +
- "threshold %s(MB) and can't process the request, " +
- "you can config %s to adjust it or try again later",
- presumableFreeMem, minFreeMemory,
- ServerOptions.MIN_FREE_MEMORY.name()));
- }
- }
-
- public static boolean isWhiteAPI(ContainerRequestContext context) {
- List<PathSegment> segments = context.getUriInfo().getPathSegments();
- E.checkArgument(segments.size() > 0, "Invalid request uri '%s'",
- context.getUriInfo().getPath());
- String rootPath = segments.get(0).getPath();
- return WHITE_API_LIST.contains(rootPath);
- }
-
- private static void gcIfNeeded() {
- if (GC_RATE_LIMITER.tryAcquire(1)) {
- System.gc();
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/LoadReleaseFilter.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/LoadReleaseFilter.java
deleted file mode 100644
index 210f996c1..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/LoadReleaseFilter.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.api.filter;
-
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.container.ContainerRequestContext;
-import jakarta.ws.rs.container.ContainerResponseContext;
-import jakarta.ws.rs.container.ContainerResponseFilter;
-import jakarta.ws.rs.core.Context;
-import jakarta.ws.rs.ext.Provider;
-
-import com.baidu.hugegraph.define.WorkLoad;
-
-@Provider
-@Singleton
-public class LoadReleaseFilter implements ContainerResponseFilter {
-
- @Context
- private jakarta.inject.Provider<WorkLoad> loadProvider;
-
- @Override
- public void filter(ContainerRequestContext requestContext,
- ContainerResponseContext responseContext) {
- if (LoadDetectFilter.isWhiteAPI(requestContext)) {
- return;
- }
-
- WorkLoad load = this.loadProvider.get();
- load.decrementAndGet();
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/StatusFilter.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/StatusFilter.java
deleted file mode 100644
index 3d93b9ef9..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/StatusFilter.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.api.filter;
-
-import java.io.IOException;
-import java.lang.annotation.Annotation;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-import jakarta.ws.rs.NameBinding;
-import jakarta.ws.rs.container.ContainerRequestContext;
-import jakarta.ws.rs.container.ContainerResponseContext;
-import jakarta.ws.rs.container.ContainerResponseFilter;
-import jakarta.ws.rs.ext.Provider;
-
-@Provider
-public class StatusFilter implements ContainerResponseFilter {
-
- @Override
- public void filter(ContainerRequestContext requestContext,
- ContainerResponseContext responseContext)
- throws IOException {
- if (responseContext.getStatus() == 200) {
- for (Annotation i : responseContext.getEntityAnnotations()) {
- if (i instanceof Status) {
- responseContext.setStatus(((Status) i).value());
- break;
- }
- }
- }
- }
-
- @NameBinding
- @Retention(RetentionPolicy.RUNTIME)
- public @interface Status {
- int OK = 200;
- int CREATED = 201;
- int ACCEPTED = 202;
-
- int value();
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/BatchAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/BatchAPI.java
deleted file mode 100644
index 515b1ca6b..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/BatchAPI.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * 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.api.graph;
-
-import java.util.Map;
-import java.util.concurrent.Callable;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.apache.tinkerpop.gremlin.structure.Element;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeException;
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.config.HugeConfig;
-import com.baidu.hugegraph.config.ServerOptions;
-import com.baidu.hugegraph.define.Checkable;
-import com.baidu.hugegraph.define.UpdateStrategy;
-import com.baidu.hugegraph.metrics.MetricsUtil;
-import com.baidu.hugegraph.server.RestServer;
-import com.baidu.hugegraph.structure.HugeElement;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.Meter;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class BatchAPI extends API {
-
- private static final Logger LOG = Log.logger(BatchAPI.class);
-
- // NOTE: VertexAPI and EdgeAPI should share a counter
- private static final AtomicInteger BATCH_WRITE_THREADS = new AtomicInteger(0);
-
- static {
- MetricsUtil.registerGauge(RestServer.class, "batch-write-threads",
- () -> BATCH_WRITE_THREADS.intValue());
- }
-
- private final Meter batchMeter;
-
- public BatchAPI() {
- this.batchMeter = MetricsUtil.registerMeter(this.getClass(),
- "batch-commit");
- }
-
- public <R> R commit(HugeConfig config, HugeGraph g, int size,
- Callable<R> callable) {
- int maxWriteThreads = config.get(ServerOptions.MAX_WRITE_THREADS);
- int writingThreads = BATCH_WRITE_THREADS.incrementAndGet();
- if (writingThreads > maxWriteThreads) {
- BATCH_WRITE_THREADS.decrementAndGet();
- throw new HugeException("The rest server is too busy to write");
- }
-
- LOG.debug("The batch writing threads is {}", BATCH_WRITE_THREADS);
- try {
- R result = commit(g, callable);
- this.batchMeter.mark(size);
- return result;
- } finally {
- BATCH_WRITE_THREADS.decrementAndGet();
- }
- }
-
- @JsonIgnoreProperties(value = {"type"})
- protected abstract static class JsonElement implements Checkable {
-
- @JsonProperty("id")
- public Object id;
- @JsonProperty("label")
- public String label;
- @JsonProperty("properties")
- public Map<String, Object> properties;
- @JsonProperty("type")
- public String type;
-
- @Override
- public abstract void checkCreate(boolean isBatch);
-
- @Override
- public abstract void checkUpdate();
-
- protected abstract Object[] properties();
- }
-
- protected void updateExistElement(JsonElement oldElement,
- JsonElement newElement,
- Map<String, UpdateStrategy> strategies) {
- if (oldElement == null) {
- return;
- }
- E.checkArgument(newElement != null, "The json element can't be null");
-
- for (Map.Entry<String, UpdateStrategy> kv : strategies.entrySet()) {
- String key = kv.getKey();
- UpdateStrategy updateStrategy = kv.getValue();
- if (oldElement.properties.get(key) != null &&
- newElement.properties.get(key) != null) {
- Object value = updateStrategy.checkAndUpdateProperty(
- oldElement.properties.get(key),
- newElement.properties.get(key));
- newElement.properties.put(key, value);
- } else if (oldElement.properties.get(key) != null &&
- newElement.properties.get(key) == null) {
- // If new property is null & old is present, use old property
- newElement.properties.put(key, oldElement.properties.get(key));
- }
- }
- }
-
- protected void updateExistElement(HugeGraph g,
- Element oldElement,
- JsonElement newElement,
- Map<String, UpdateStrategy> strategies) {
- if (oldElement == null) {
- return;
- }
- E.checkArgument(newElement != null, "The json element can't be null");
-
- for (Map.Entry<String, UpdateStrategy> kv : strategies.entrySet()) {
- String key = kv.getKey();
- UpdateStrategy updateStrategy = kv.getValue();
- if (oldElement.property(key).isPresent() &&
- newElement.properties.get(key) != null) {
- Object value = updateStrategy.checkAndUpdateProperty(
- oldElement.property(key).value(),
- newElement.properties.get(key));
- value = g.propertyKey(key).validValueOrThrow(value);
- newElement.properties.put(key, value);
- } else if (oldElement.property(key).isPresent() &&
- newElement.properties.get(key) == null) {
- // If new property is null & old is present, use old property
- newElement.properties.put(key, oldElement.value(key));
- }
- }
- }
-
- protected static void updateProperties(HugeElement element,
- JsonElement jsonElement,
- boolean append) {
- for (Map.Entry<String, Object> e : jsonElement.properties.entrySet()) {
- String key = e.getKey();
- Object value = e.getValue();
- if (append) {
- element.property(key, value);
- } else {
- element.property(key).remove();
- }
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java
deleted file mode 100644
index 1f9e94741..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java
+++ /dev/null
@@ -1,574 +0,0 @@
-/*
- * 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.api.graph;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.annotation.security.RolesAllowed;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.DELETE;
-import jakarta.ws.rs.DefaultValue;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.PUT;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
-import org.apache.tinkerpop.gremlin.structure.Direction;
-import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.util.function.TriFunction;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.CompressInterceptor.Compress;
-import com.baidu.hugegraph.api.filter.DecompressInterceptor.Decompress;
-import com.baidu.hugegraph.api.filter.StatusFilter.Status;
-import com.baidu.hugegraph.backend.id.EdgeId;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.backend.query.ConditionQuery;
-import com.baidu.hugegraph.config.HugeConfig;
-import com.baidu.hugegraph.config.ServerOptions;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.define.UpdateStrategy;
-import com.baidu.hugegraph.exception.NotFoundException;
-import com.baidu.hugegraph.schema.EdgeLabel;
-import com.baidu.hugegraph.schema.PropertyKey;
-import com.baidu.hugegraph.schema.VertexLabel;
-import com.baidu.hugegraph.structure.HugeEdge;
-import com.baidu.hugegraph.structure.HugeVertex;
-import com.baidu.hugegraph.traversal.optimize.QueryHolder;
-import com.baidu.hugegraph.traversal.optimize.TraversalUtil;
-import com.baidu.hugegraph.type.define.Directions;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-@Path("graphs/{graph}/graph/edges")
-@Singleton
-@Tag(name = "EdgeAPI")
-public class EdgeAPI extends BatchAPI {
-
- private static final Logger LOG = Log.logger(EdgeAPI.class);
-
- @POST
- @Timed(name = "single-create")
- @Status(Status.CREATED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=edge_write"})
- public String create(@Context GraphManager manager,
- @PathParam("graph") String graph,
- JsonEdge jsonEdge) {
- LOG.debug("Graph [{}] create edge: {}", graph, jsonEdge);
- checkCreatingBody(jsonEdge);
-
- HugeGraph g = graph(manager, graph);
-
- if (jsonEdge.sourceLabel != null && jsonEdge.targetLabel != null) {
- /*
- * NOTE: If the vertex id is correct but label not match with id,
- * we allow to create it here
- */
- vertexLabel(g, jsonEdge.sourceLabel,
- "Invalid source vertex label '%s'");
- vertexLabel(g, jsonEdge.targetLabel,
- "Invalid target vertex label '%s'");
- }
-
- Vertex srcVertex = getVertex(g, jsonEdge.source, jsonEdge.sourceLabel);
- Vertex tgtVertex = getVertex(g, jsonEdge.target, jsonEdge.targetLabel);
-
- Edge edge = commit(g, () -> {
- return srcVertex.addEdge(jsonEdge.label, tgtVertex,
- jsonEdge.properties());
- });
-
- return manager.serializer(g).writeEdge(edge);
- }
-
- @POST
- @Timed(name = "batch-create")
- @Decompress
- @Path("batch")
- @Status(Status.CREATED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=edge_write"})
- public String create(@Context HugeConfig config,
- @Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("check_vertex")
- @DefaultValue("true") boolean checkVertex,
- List<JsonEdge> jsonEdges) {
- LOG.debug("Graph [{}] create edges: {}", graph, jsonEdges);
- checkCreatingBody(jsonEdges);
- checkBatchSize(config, jsonEdges);
-
- HugeGraph g = graph(manager, graph);
-
- TriFunction<HugeGraph, Object, String, Vertex> getVertex =
- checkVertex ? EdgeAPI::getVertex : EdgeAPI::newVertex;
-
- return this.commit(config, g, jsonEdges.size(), () -> {
- List<Id> ids = new ArrayList<>(jsonEdges.size());
- for (JsonEdge jsonEdge : jsonEdges) {
- /*
- * NOTE: If the query param 'checkVertex' is false,
- * then the label is correct and not matched id,
- * it will be allowed currently
- */
- Vertex srcVertex = getVertex.apply(g, jsonEdge.source,
- jsonEdge.sourceLabel);
- Vertex tgtVertex = getVertex.apply(g, jsonEdge.target,
- jsonEdge.targetLabel);
- Edge edge = srcVertex.addEdge(jsonEdge.label, tgtVertex,
- jsonEdge.properties());
- ids.add((Id) edge.id());
- }
- return manager.serializer(g).writeIds(ids);
- });
- }
-
- /**
- * Batch update steps are same like vertices
- */
- @PUT
- @Timed(name = "batch-update")
- @Decompress
- @Path("batch")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=edge_write"})
- public String update(@Context HugeConfig config,
- @Context GraphManager manager,
- @PathParam("graph") String graph,
- BatchEdgeRequest req) {
- BatchEdgeRequest.checkUpdate(req);
- LOG.debug("Graph [{}] update edges: {}", graph, req);
- checkUpdatingBody(req.jsonEdges);
- checkBatchSize(config, req.jsonEdges);
-
- HugeGraph g = graph(manager, graph);
- Map<Id, JsonEdge> map = new HashMap<>(req.jsonEdges.size());
- TriFunction<HugeGraph, Object, String, Vertex> getVertex =
- req.checkVertex ? EdgeAPI::getVertex : EdgeAPI::newVertex;
-
- return this.commit(config, g, map.size(), () -> {
- // 1.Put all newEdges' properties into map (combine first)
- req.jsonEdges.forEach(newEdge -> {
- Id newEdgeId = getEdgeId(graph(manager, graph), newEdge);
- JsonEdge oldEdge = map.get(newEdgeId);
- this.updateExistElement(oldEdge, newEdge,
- req.updateStrategies);
- map.put(newEdgeId, newEdge);
- });
-
- // 2.Get all oldEdges and update with new ones
- Object[] ids = map.keySet().toArray();
- Iterator<Edge> oldEdges = g.edges(ids);
- oldEdges.forEachRemaining(oldEdge -> {
- JsonEdge newEdge = map.get(oldEdge.id());
- this.updateExistElement(g, oldEdge, newEdge,
- req.updateStrategies);
- });
-
- // 3.Add all finalEdges
- List<Edge> edges = new ArrayList<>(map.size());
- map.values().forEach(finalEdge -> {
- Vertex srcVertex = getVertex.apply(g, finalEdge.source,
- finalEdge.sourceLabel);
- Vertex tgtVertex = getVertex.apply(g, finalEdge.target,
- finalEdge.targetLabel);
- edges.add(srcVertex.addEdge(finalEdge.label, tgtVertex,
- finalEdge.properties()));
- });
-
- // If return ids, the ids.size() maybe different with the origins'
- return manager.serializer(g).writeEdges(edges.iterator(), false);
- });
- }
-
- @PUT
- @Timed(name = "single-update")
- @Path("{id}")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=edge_write"})
- public String update(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id,
- @QueryParam("action") String action,
- JsonEdge jsonEdge) {
- LOG.debug("Graph [{}] update edge: {}", graph, jsonEdge);
- checkUpdatingBody(jsonEdge);
-
- if (jsonEdge.id != null) {
- E.checkArgument(id.equals(jsonEdge.id),
- "The ids are different between url and " +
- "request body ('%s' != '%s')", id, jsonEdge.id);
- }
-
- // Parse action param
- boolean append = checkAndParseAction(action);
-
- HugeGraph g = graph(manager, graph);
- HugeEdge edge = (HugeEdge) g.edge(id);
- EdgeLabel edgeLabel = edge.schemaLabel();
-
- for (String key : jsonEdge.properties.keySet()) {
- PropertyKey pkey = g.propertyKey(key);
- E.checkArgument(edgeLabel.properties().contains(pkey.id()),
- "Can't update property for edge '%s' because " +
- "there is no property key '%s' in its edge label",
- id, key);
- }
-
- commit(g, () -> updateProperties(edge, jsonEdge, append));
-
- return manager.serializer(g).writeEdge(edge);
- }
-
- @GET
- @Timed
- @Compress
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=edge_read"})
- public String list(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("vertex_id") String vertexId,
- @QueryParam("direction") String direction,
- @QueryParam("label") String label,
- @QueryParam("properties") String properties,
- @QueryParam("keep_start_p")
- @DefaultValue("false") boolean keepStartP,
- @QueryParam("offset") @DefaultValue("0") long offset,
- @QueryParam("page") String page,
- @QueryParam("limit") @DefaultValue("100") long limit) {
- LOG.debug("Graph [{}] query edges by vertex: {}, direction: {}, " +
- "label: {}, properties: {}, offset: {}, page: {}, limit: {}",
- graph, vertexId, direction,
- label, properties, offset, page, limit);
-
- Map<String, Object> props = parseProperties(properties);
- if (page != null) {
- E.checkArgument(offset == 0,
- "Not support querying edges based on paging " +
- "and offset together");
- }
-
- Id vertex = VertexAPI.checkAndParseVertexId(vertexId);
- Direction dir = parseDirection(direction);
-
- HugeGraph g = graph(manager, graph);
-
- GraphTraversal<?, Edge> traversal;
- if (vertex != null) {
- if (label != null) {
- traversal = g.traversal().V(vertex).toE(dir, label);
- } else {
- traversal = g.traversal().V(vertex).toE(dir);
- }
- } else {
- if (label != null) {
- traversal = g.traversal().E().hasLabel(label);
- } else {
- traversal = g.traversal().E();
- }
- }
-
- // Convert relational operator like P.gt()/P.lt()
- for (Map.Entry<String, Object> prop : props.entrySet()) {
- Object value = prop.getValue();
- if (!keepStartP && value instanceof String &&
- ((String) value).startsWith(TraversalUtil.P_CALL)) {
- prop.setValue(TraversalUtil.parsePredicate((String) value));
- }
- }
-
- for (Map.Entry<String, Object> entry : props.entrySet()) {
- traversal = traversal.has(entry.getKey(), entry.getValue());
- }
-
- if (page == null) {
- traversal = traversal.range(offset, offset + limit);
- } else {
- traversal = traversal.has(QueryHolder.SYSPROP_PAGE, page)
- .limit(limit);
- }
-
- try {
- return manager.serializer(g).writeEdges(traversal, page != null);
- } finally {
- if (g.tx().isOpen()) {
- g.tx().close();
- }
- }
- }
-
- @GET
- @Timed
- @Path("{id}")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=edge_read"})
- public String get(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id) {
- LOG.debug("Graph [{}] get edge by id '{}'", graph, id);
-
- HugeGraph g = graph(manager, graph);
- try {
- Edge edge = g.edge(id);
- return manager.serializer(g).writeEdge(edge);
- } finally {
- if (g.tx().isOpen()) {
- g.tx().close();
- }
- }
- }
-
- @DELETE
- @Timed
- @Path("{id}")
- @Consumes(APPLICATION_JSON)
- @RolesAllowed({"admin", "$owner=$graph $action=edge_delete"})
- public void delete(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String id,
- @QueryParam("label") String label) {
- LOG.debug("Graph [{}] remove vertex by id '{}'", graph, id);
-
- HugeGraph g = graph(manager, graph);
- commit(g, () -> {
- try {
- g.removeEdge(label, id);
- } catch (NotFoundException e) {
- throw new IllegalArgumentException(String.format(
- "No such edge with id: '%s', %s", id, e));
- } catch (NoSuchElementException e) {
- throw new IllegalArgumentException(String.format(
- "No such edge with id: '%s'", id));
- }
- });
- }
-
- private static void checkBatchSize(HugeConfig config,
- List<JsonEdge> edges) {
- int max = config.get(ServerOptions.MAX_EDGES_PER_BATCH);
- if (edges.size() > max) {
- throw new IllegalArgumentException(String.format(
- "Too many edges for one time post, " +
- "the maximum number is '%s'", max));
- }
- if (edges.size() == 0) {
- throw new IllegalArgumentException(
- "The number of edges can't be 0");
- }
- }
-
- private static Vertex getVertex(HugeGraph graph,
- Object id, String label) {
- HugeVertex vertex;
- try {
- vertex = (HugeVertex) graph.vertices(id).next();
- } catch (NoSuchElementException e) {
- throw new IllegalArgumentException(String.format(
- "Invalid vertex id '%s'", id));
- }
- if (label != null && !vertex.label().equals(label)) {
- throw new IllegalArgumentException(String.format(
- "The label of vertex '%s' is unmatched, users expect " +
- "label '%s', actual label stored is '%s'",
- id, label, vertex.label()));
- }
- // Clone a new vertex to support multi-thread access
- return vertex.copy();
- }
-
- private static Vertex newVertex(HugeGraph g, Object id, String label) {
- VertexLabel vl = vertexLabel(g, label, "Invalid vertex label '%s'");
- Id idValue = HugeVertex.getIdValue(id);
- return new HugeVertex(g, idValue, vl);
- }
-
- private static VertexLabel vertexLabel(HugeGraph graph, String label,
- String message) {
- try {
- // NOTE: don't use SchemaManager because it will throw 404
- return graph.vertexLabel(label);
- } catch (IllegalArgumentException e) {
- throw new IllegalArgumentException(String.format(message, label));
- }
- }
-
- public static Direction parseDirection(String direction) {
- if (direction == null || direction.isEmpty()) {
- return Direction.BOTH;
- }
- try {
- return Direction.valueOf(direction);
- } catch (Exception e) {
- throw new IllegalArgumentException(String.format(
- "Direction value must be in [OUT, IN, BOTH], " +
- "but got '%s'", direction));
- }
- }
-
- private Id getEdgeId(HugeGraph g, JsonEdge newEdge) {
- String sortKeys = "";
- Id labelId = g.edgeLabel(newEdge.label).id();
- List<Id> sortKeyIds = g.edgeLabel(labelId).sortKeys();
- if (!sortKeyIds.isEmpty()) {
- List<Object> sortKeyValues = new ArrayList<>(sortKeyIds.size());
- sortKeyIds.forEach(skId -> {
- PropertyKey pk = g.propertyKey(skId);
- String sortKey = pk.name();
- Object sortKeyValue = newEdge.properties.get(sortKey);
- E.checkArgument(sortKeyValue != null,
- "The value of sort key '%s' can't be null",
- sortKey);
- sortKeyValue = pk.validValueOrThrow(sortKeyValue);
- sortKeyValues.add(sortKeyValue);
- });
- sortKeys = ConditionQuery.concatValues(sortKeyValues);
- }
- EdgeId edgeId = new EdgeId(HugeVertex.getIdValue(newEdge.source),
- Directions.OUT, labelId, sortKeys,
- HugeVertex.getIdValue(newEdge.target));
- if (newEdge.id != null) {
- E.checkArgument(edgeId.asString().equals(newEdge.id),
- "The ids are different between server and " +
- "request body ('%s' != '%s'). And note the sort " +
- "key values should either be null or equal to " +
- "the origin value when specified edge id",
- edgeId, newEdge.id);
- }
- return edgeId;
- }
-
- protected static class BatchEdgeRequest {
-
- @JsonProperty("edges")
- public List<JsonEdge> jsonEdges;
- @JsonProperty("update_strategies")
- public Map<String, UpdateStrategy> updateStrategies;
- @JsonProperty("check_vertex")
- public boolean checkVertex = false;
- @JsonProperty("create_if_not_exist")
- public boolean createIfNotExist = true;
-
- private static void checkUpdate(BatchEdgeRequest req) {
- E.checkArgumentNotNull(req, "BatchEdgeRequest can't be null");
- E.checkArgumentNotNull(req.jsonEdges,
- "Parameter 'edges' can't be null");
- E.checkArgument(req.updateStrategies != null &&
- !req.updateStrategies.isEmpty(),
- "Parameter 'update_strategies' can't be empty");
- E.checkArgument(req.createIfNotExist == true,
- "Parameter 'create_if_not_exist' " +
- "dose not support false now");
- }
-
- @Override
- public String toString() {
- return String.format("BatchEdgeRequest{jsonEdges=%s," +
- "updateStrategies=%s," +
- "checkVertex=%s,createIfNotExist=%s}",
- this.jsonEdges, this.updateStrategies,
- this.checkVertex, this.createIfNotExist);
- }
- }
-
- private static class JsonEdge extends JsonElement {
-
- @JsonProperty("outV")
- public Object source;
- @JsonProperty("outVLabel")
- public String sourceLabel;
- @JsonProperty("inV")
- public Object target;
- @JsonProperty("inVLabel")
- public String targetLabel;
-
- @Override
- public void checkCreate(boolean isBatch) {
- E.checkArgumentNotNull(this.label, "Expect the label of edge");
- E.checkArgumentNotNull(this.source, "Expect source vertex id");
- E.checkArgumentNotNull(this.target, "Expect target vertex id");
- if (isBatch) {
- E.checkArgumentNotNull(this.sourceLabel,
- "Expect source vertex label");
- E.checkArgumentNotNull(this.targetLabel,
- "Expect target vertex label");
- } else {
- E.checkArgument(this.sourceLabel == null &&
- this.targetLabel == null ||
- this.sourceLabel != null &&
- this.targetLabel != null,
- "The both source and target vertex label " +
- "are either passed in, or not passed in");
- }
- this.checkUpdate();
- }
-
- @Override
- public void checkUpdate() {
- E.checkArgumentNotNull(this.properties,
- "The properties of edge can't be null");
-
- for (Map.Entry<String, Object> entry : this.properties.entrySet()) {
- String key = entry.getKey();
- Object value = entry.getValue();
- E.checkArgumentNotNull(value, "Not allowed to set value of " +
- "property '%s' to null for edge '%s'",
- key, this.id);
- }
- }
-
- @Override
- public Object[] properties() {
- return API.properties(this.properties);
- }
-
- @Override
- public String toString() {
- return String.format("JsonEdge{label=%s, " +
- "source-vertex=%s, source-vertex-label=%s, " +
- "target-vertex=%s, target-vertex-label=%s, " +
- "properties=%s}",
- this.label, this.source, this.sourceLabel,
- this.target, this.targetLabel,
- this.properties);
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/VertexAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/VertexAPI.java
deleted file mode 100644
index 2adcee773..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/VertexAPI.java
+++ /dev/null
@@ -1,479 +0,0 @@
-/*
- * 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.api.graph;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.annotation.security.RolesAllowed;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.DELETE;
-import jakarta.ws.rs.DefaultValue;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.PUT;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
-import org.apache.tinkerpop.gremlin.structure.T;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.CompressInterceptor.Compress;
-import com.baidu.hugegraph.api.filter.DecompressInterceptor.Decompress;
-import com.baidu.hugegraph.api.filter.StatusFilter.Status;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.backend.id.SplicingIdGenerator;
-import com.baidu.hugegraph.backend.query.ConditionQuery;
-import com.baidu.hugegraph.config.HugeConfig;
-import com.baidu.hugegraph.config.ServerOptions;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.define.UpdateStrategy;
-import com.baidu.hugegraph.exception.NotFoundException;
-import com.baidu.hugegraph.schema.PropertyKey;
-import com.baidu.hugegraph.schema.VertexLabel;
-import com.baidu.hugegraph.structure.HugeVertex;
-import com.baidu.hugegraph.traversal.optimize.QueryHolder;
-import com.baidu.hugegraph.traversal.optimize.Text;
-import com.baidu.hugegraph.traversal.optimize.TraversalUtil;
-import com.baidu.hugegraph.type.define.IdStrategy;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.JsonUtil;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-@Path("graphs/{graph}/graph/vertices")
-@Singleton
-@Tag(name = "VertexAPI")
-public class VertexAPI extends BatchAPI {
-
- private static final Logger LOG = Log.logger(VertexAPI.class);
-
- @POST
- @Timed(name = "single-create")
- @Status(Status.CREATED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=vertex_write"})
- public String create(@Context GraphManager manager,
- @PathParam("graph") String graph,
- JsonVertex jsonVertex) {
- LOG.debug("Graph [{}] create vertex: {}", graph, jsonVertex);
- checkCreatingBody(jsonVertex);
-
- HugeGraph g = graph(manager, graph);
- Vertex vertex = commit(g, () -> g.addVertex(jsonVertex.properties()));
-
- return manager.serializer(g).writeVertex(vertex);
- }
-
- @POST
- @Timed(name = "batch-create")
- @Decompress
- @Path("batch")
- @Status(Status.CREATED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=vertex_write"})
- public String create(@Context HugeConfig config,
- @Context GraphManager manager,
- @PathParam("graph") String graph,
- List<JsonVertex> jsonVertices) {
- LOG.debug("Graph [{}] create vertices: {}", graph, jsonVertices);
- checkCreatingBody(jsonVertices);
- checkBatchSize(config, jsonVertices);
-
- HugeGraph g = graph(manager, graph);
-
- return this.commit(config, g, jsonVertices.size(), () -> {
- List<Id> ids = new ArrayList<>(jsonVertices.size());
- for (JsonVertex vertex : jsonVertices) {
- ids.add((Id) g.addVertex(vertex.properties()).id());
- }
- return manager.serializer(g).writeIds(ids);
- });
- }
-
- /**
- * Batch update steps like:
- * 1. Get all newVertices' ID & combine first
- * 2. Get all oldVertices & update
- * 3. Add the final vertex together
- */
- @PUT
- @Timed(name = "batch-update")
- @Decompress
- @Path("batch")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=vertex_write"})
- public String update(@Context HugeConfig config,
- @Context GraphManager manager,
- @PathParam("graph") String graph,
- BatchVertexRequest req) {
- BatchVertexRequest.checkUpdate(req);
- LOG.debug("Graph [{}] update vertices: {}", graph, req);
- checkUpdatingBody(req.jsonVertices);
- checkBatchSize(config, req.jsonVertices);
-
- HugeGraph g = graph(manager, graph);
- Map<Id, JsonVertex> map = new HashMap<>(req.jsonVertices.size());
-
- return this.commit(config, g, map.size(), () -> {
- /*
- * 1.Put all newVertices' properties into map (combine first)
- * - Consider primary-key & user-define ID mode first
- */
- req.jsonVertices.forEach(newVertex -> {
- Id newVertexId = getVertexId(g, newVertex);
- JsonVertex oldVertex = map.get(newVertexId);
- this.updateExistElement(oldVertex, newVertex,
- req.updateStrategies);
- map.put(newVertexId, newVertex);
- });
-
- // 2.Get all oldVertices and update with new vertices
- Object[] ids = map.keySet().toArray();
- Iterator<Vertex> oldVertices = g.vertices(ids);
- oldVertices.forEachRemaining(oldVertex -> {
- JsonVertex newVertex = map.get(oldVertex.id());
- this.updateExistElement(g, oldVertex, newVertex,
- req.updateStrategies);
- });
-
- // 3.Add finalVertices and return them
- List<Vertex> vertices = new ArrayList<>(map.size());
- map.values().forEach(finalVertex -> {
- vertices.add(g.addVertex(finalVertex.properties()));
- });
-
- // If return ids, the ids.size() maybe different with the origins'
- return manager.serializer(g)
- .writeVertices(vertices.iterator(), false);
- });
- }
-
- @PUT
- @Timed(name = "single-update")
- @Path("{id}")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=vertex_write"})
- public String update(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String idValue,
- @QueryParam("action") String action,
- JsonVertex jsonVertex) {
- LOG.debug("Graph [{}] update vertex: {}", graph, jsonVertex);
- checkUpdatingBody(jsonVertex);
-
- Id id = checkAndParseVertexId(idValue);
- // Parse action param
- boolean append = checkAndParseAction(action);
-
- HugeGraph g = graph(manager, graph);
- HugeVertex vertex = (HugeVertex) g.vertex(id);
- VertexLabel vertexLabel = vertex.schemaLabel();
-
- for (String key : jsonVertex.properties.keySet()) {
- PropertyKey pkey = g.propertyKey(key);
- E.checkArgument(vertexLabel.properties().contains(pkey.id()),
- "Can't update property for vertex '%s' because " +
- "there is no property key '%s' in its vertex label",
- id, key);
- }
-
- commit(g, () -> updateProperties(vertex, jsonVertex, append));
-
- return manager.serializer(g).writeVertex(vertex);
- }
-
- @GET
- @Timed
- @Compress
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=vertex_read"})
- public String list(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("label") String label,
- @QueryParam("properties") String properties,
- @QueryParam("keep_start_p")
- @DefaultValue("false") boolean keepStartP,
- @QueryParam("offset") @DefaultValue("0") long offset,
- @QueryParam("page") String page,
- @QueryParam("limit") @DefaultValue("100") long limit) {
- LOG.debug("Graph [{}] query vertices by label: {}, properties: {}, " +
- "offset: {}, page: {}, limit: {}",
- graph, label, properties, offset, page, limit);
-
- Map<String, Object> props = parseProperties(properties);
- if (page != null) {
- E.checkArgument(offset == 0,
- "Not support querying vertices based on paging " +
- "and offset together");
- }
-
- HugeGraph g = graph(manager, graph);
-
- GraphTraversal<Vertex, Vertex> traversal = g.traversal().V();
- if (label != null) {
- traversal = traversal.hasLabel(label);
- }
-
- // Convert relational operator like P.gt()/P.lt()
- for (Map.Entry<String, Object> prop : props.entrySet()) {
- Object value = prop.getValue();
- if (!keepStartP && value instanceof String &&
- ((String) value).startsWith(TraversalUtil.P_CALL)) {
- prop.setValue(TraversalUtil.parsePredicate((String) value));
- }
- }
-
- for (Map.Entry<String, Object> entry : props.entrySet()) {
- traversal = traversal.has(entry.getKey(), entry.getValue());
- }
-
- if (page == null) {
- traversal = traversal.range(offset, offset + limit);
- } else {
- traversal = traversal.has(QueryHolder.SYSPROP_PAGE, page)
- .limit(limit);
- }
-
- try {
- return manager.serializer(g).writeVertices(traversal,
- page != null);
- } finally {
- if (g.tx().isOpen()) {
- g.tx().close();
- }
- }
- }
-
- @GET
- @Timed
- @Path("{id}")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=vertex_read"})
- public String get(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String idValue) {
- LOG.debug("Graph [{}] get vertex by id '{}'", graph, idValue);
-
- Id id = checkAndParseVertexId(idValue);
- HugeGraph g = graph(manager, graph);
- try {
- Vertex vertex = g.vertex(id);
- return manager.serializer(g).writeVertex(vertex);
- } finally {
- if (g.tx().isOpen()) {
- g.tx().close();
- }
- }
- }
-
- @DELETE
- @Timed
- @Path("{id}")
- @Consumes(APPLICATION_JSON)
- @RolesAllowed({"admin", "$owner=$graph $action=vertex_delete"})
- public void delete(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") String idValue,
- @QueryParam("label") String label) {
- LOG.debug("Graph [{}] remove vertex by id '{}'", graph, idValue);
-
- Id id = checkAndParseVertexId(idValue);
- HugeGraph g = graph(manager, graph);
- commit(g, () -> {
- try {
- g.removeVertex(label, id);
- } catch (NotFoundException e) {
- throw new IllegalArgumentException(String.format(
- "No such vertex with id: '%s', %s", id, e));
- } catch (NoSuchElementException e) {
- throw new IllegalArgumentException(String.format(
- "No such vertex with id: '%s'", id));
- }
- });
- }
-
- public static Id checkAndParseVertexId(String idValue) {
- if (idValue == null) {
- return null;
- }
- boolean uuid = idValue.startsWith("U\"");
- if (uuid) {
- idValue = idValue.substring(1);
- }
- try {
- Object id = JsonUtil.fromJson(idValue, Object.class);
- return uuid ? Text.uuid((String) id) : HugeVertex.getIdValue(id);
- } catch (Exception e) {
- throw new IllegalArgumentException(String.format(
- "The vertex id must be formatted as Number/String/UUID" +
- ", but got '%s'", idValue));
- }
- }
-
- private static void checkBatchSize(HugeConfig config,
- List<JsonVertex> vertices) {
- int max = config.get(ServerOptions.MAX_VERTICES_PER_BATCH);
- if (vertices.size() > max) {
- throw new IllegalArgumentException(String.format(
- "Too many vertices for one time post, " +
- "the maximum number is '%s'", max));
- }
- if (vertices.size() == 0) {
- throw new IllegalArgumentException(
- "The number of vertices can't be 0");
- }
- }
-
- private static Id getVertexId(HugeGraph g, JsonVertex vertex) {
- VertexLabel vertexLabel = g.vertexLabel(vertex.label);
- String labelId = vertexLabel.id().asString();
- IdStrategy idStrategy = vertexLabel.idStrategy();
- E.checkArgument(idStrategy != IdStrategy.AUTOMATIC,
- "Automatic Id strategy is not supported now");
-
- if (idStrategy == IdStrategy.PRIMARY_KEY) {
- List<Id> pkIds = vertexLabel.primaryKeys();
- List<Object> pkValues = new ArrayList<>(pkIds.size());
- for (Id pkId : pkIds) {
- String propertyKey = g.propertyKey(pkId).name();
- Object propertyValue = vertex.properties.get(propertyKey);
- E.checkArgument(propertyValue != null,
- "The value of primary key '%s' can't be null",
- propertyKey);
- pkValues.add(propertyValue);
- }
-
- String value = ConditionQuery.concatValues(pkValues);
- return SplicingIdGenerator.splicing(labelId, value);
- } else if (idStrategy == IdStrategy.CUSTOMIZE_UUID) {
- return Text.uuid(String.valueOf(vertex.id));
- } else {
- assert idStrategy == IdStrategy.CUSTOMIZE_NUMBER ||
- idStrategy == IdStrategy.CUSTOMIZE_STRING;
- return HugeVertex.getIdValue(vertex.id);
- }
- }
-
- private static class BatchVertexRequest {
-
- @JsonProperty("vertices")
- public List<JsonVertex> jsonVertices;
- @JsonProperty("update_strategies")
- public Map<String, UpdateStrategy> updateStrategies;
- @JsonProperty("create_if_not_exist")
- public boolean createIfNotExist = true;
-
- private static void checkUpdate(BatchVertexRequest req) {
- E.checkArgumentNotNull(req, "BatchVertexRequest can't be null");
- E.checkArgumentNotNull(req.jsonVertices,
- "Parameter 'vertices' can't be null");
- E.checkArgument(req.updateStrategies != null &&
- !req.updateStrategies.isEmpty(),
- "Parameter 'update_strategies' can't be empty");
- E.checkArgument(req.createIfNotExist,
- "Parameter 'create_if_not_exist' " +
- "dose not support false now");
- }
-
- @Override
- public String toString() {
- return String.format("BatchVertexRequest{jsonVertices=%s," +
- "updateStrategies=%s,createIfNotExist=%s}",
- this.jsonVertices, this.updateStrategies,
- this.createIfNotExist);
- }
- }
-
- private static class JsonVertex extends JsonElement {
-
- @Override
- public void checkCreate(boolean isBatch) {
- this.checkUpdate();
- }
-
- @Override
- public void checkUpdate() {
- E.checkArgumentNotNull(this.properties,
- "The properties of vertex can't be null");
-
- for (Map.Entry<String, Object> e : this.properties.entrySet()) {
- String key = e.getKey();
- Object value = e.getValue();
- E.checkArgumentNotNull(value, "Not allowed to set value of " +
- "property '%s' to null for vertex '%s'",
- key, this.id);
- }
- }
-
- @Override
- public Object[] properties() {
- Object[] props = API.properties(this.properties);
- int newSize = props.length;
- int appendIndex = newSize;
- if (this.label != null) {
- newSize += 2;
- }
- if (this.id != null) {
- newSize += 2;
- }
- if (newSize == props.length) {
- return props;
- }
-
- Object[] newProps = Arrays.copyOf(props, newSize);
- if (this.label != null) {
- newProps[appendIndex++] = T.label;
- newProps[appendIndex++] = this.label;
- }
- if (this.id != null) {
- newProps[appendIndex++] = T.id;
- // Keep value++ to avoid code trap
- newProps[appendIndex++] = this.id;
- }
- return newProps;
- }
-
- @Override
- public String toString() {
- return String.format("JsonVertex{label=%s, properties=%s}",
- this.label, this.properties);
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/CypherAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/CypherAPI.java
deleted file mode 100644
index 082ff6bc7..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/CypherAPI.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * 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.api.gremlin;
-
-import org.opencypher.gremlin.translation.TranslationFacade;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.api.filter.CompressInterceptor;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-import jakarta.ws.rs.core.HttpHeaders;
-import jakarta.ws.rs.core.Response;
-
-@Path("graphs/{graph}/cypher")
-@Singleton
-@Tag(name = "CypherAPI")
-public class CypherAPI extends GremlinQueryAPI {
-
- private static final Logger LOG = Log.logger(CypherAPI.class);
-
- @GET
- @Timed
- @CompressInterceptor.Compress(buffer = (1024 * 40))
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public Response query(@PathParam("graph") String graph,
- @Context HttpHeaders headers,
- @QueryParam("cypher") String cypher) {
- LOG.debug("Graph [{}] query by cypher: {}", graph, cypher);
-
- return this.queryByCypher(graph, headers, cypher);
- }
-
- @POST
- @Timed
- @CompressInterceptor.Compress
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public Response post(@PathParam("graph") String graph,
- @Context HttpHeaders headers,
- String cypher) {
- LOG.debug("Graph [{}] query by cypher: {}", graph, cypher);
- return this.queryByCypher(graph, headers, cypher);
- }
-
- private Response queryByCypher(String graph,
- HttpHeaders headers,
- String cypher) {
- E.checkArgument(cypher != null && !cypher.isEmpty(),
- "The cypher parameter can't be null or empty");
-
- String gremlin = this.translateCpyher2Gremlin(graph, cypher);
- LOG.debug("translated gremlin is {}", gremlin);
-
- String auth = headers.getHeaderString(HttpHeaders.AUTHORIZATION);
- String request = "{" +
- "\"gremlin\":\"" + gremlin + "\"," +
- "\"bindings\":{}," +
- "\"language\":\"gremlin-groovy\"," +
- "\"aliases\":{\"g\":\"__g_" + graph + "\"}}";
-
- Response response = this.client().doPostRequest(auth, request);
- return transformResponseIfNeeded(response);
- }
-
- private String translateCpyher2Gremlin(String graph, String cypher) {
- TranslationFacade translator = new TranslationFacade();
- String gremlin = translator.toGremlinGroovy(cypher);
- gremlin = this.buildQueryableGremlin(graph, gremlin);
- return gremlin;
- }
-
- private String buildQueryableGremlin(String graph, String gremlin) {
- /*
- * `CREATE (a:person { name : 'test', age: 20) return a`
- * would be translated to:
- * `g.addV('person').as('a').property(single, 'name', 'test') ...`,
- * but hugegraph don't support `.property(single, k, v)`,
- * so we replace it to `.property(k, v)` here
- */
- gremlin = gremlin.replace(".property(single,", ".property(");
-
- return gremlin;
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/GremlinAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/GremlinAPI.java
deleted file mode 100644
index f1283f8f5..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/GremlinAPI.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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.api.gremlin;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.core.Context;
-import jakarta.ws.rs.core.HttpHeaders;
-import jakarta.ws.rs.core.MultivaluedMap;
-import jakarta.ws.rs.core.Response;
-import jakarta.ws.rs.core.UriInfo;
-
-import com.baidu.hugegraph.api.filter.CompressInterceptor.Compress;
-import com.baidu.hugegraph.config.HugeConfig;
-import com.baidu.hugegraph.metrics.MetricsUtil;
-import com.codahale.metrics.Histogram;
-import com.codahale.metrics.annotation.Timed;
-import jakarta.inject.Singleton;
-
-@Path("gremlin")
-@Singleton
-@Tag(name = "GremlinAPI")
-public class GremlinAPI extends GremlinQueryAPI {
-
- private static final Histogram GREMLIN_INPUT_HISTOGRAM =
- MetricsUtil.registerHistogram(GremlinAPI.class, "gremlin-input");
- private static final Histogram GREMLIN_OUTPUT_HISTOGRAM =
- MetricsUtil.registerHistogram(GremlinAPI.class, "gremlin-output");
-
- @POST
- @Timed
- @Compress
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public Response post(@Context HugeConfig conf,
- @Context HttpHeaders headers,
- String request) {
- /* The following code is reserved for forwarding request */
- // context.getRequestDispatcher(location).forward(request, response);
- // return Response.seeOther(UriBuilder.fromUri(location).build())
- // .build();
- // Response.temporaryRedirect(UriBuilder.fromUri(location).build())
- // .build();
- String auth = headers.getHeaderString(HttpHeaders.AUTHORIZATION);
- Response response = this.client().doPostRequest(auth, request);
- GREMLIN_INPUT_HISTOGRAM.update(request.length());
- GREMLIN_OUTPUT_HISTOGRAM.update(response.getLength());
- return transformResponseIfNeeded(response);
- }
-
- @GET
- @Timed
- @Compress(buffer = (1024 * 40))
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public Response get(@Context HugeConfig conf,
- @Context HttpHeaders headers,
- @Context UriInfo uriInfo) {
- String auth = headers.getHeaderString(HttpHeaders.AUTHORIZATION);
- String query = uriInfo.getRequestUri().getRawQuery();
- MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
- Response response = this.client().doGetRequest(auth, params);
- GREMLIN_INPUT_HISTOGRAM.update(query.length());
- GREMLIN_OUTPUT_HISTOGRAM.update(response.getLength());
- return transformResponseIfNeeded(response);
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/GremlinClient.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/GremlinClient.java
deleted file mode 100644
index b2b2725f8..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/GremlinClient.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.api.gremlin;
-
-import java.util.List;
-import java.util.Map;
-
-import jakarta.ws.rs.client.Entity;
-import jakarta.ws.rs.client.WebTarget;
-import jakarta.ws.rs.core.HttpHeaders;
-import jakarta.ws.rs.core.MediaType;
-import jakarta.ws.rs.core.MultivaluedMap;
-import jakarta.ws.rs.core.Response;
-
-import com.baidu.hugegraph.api.filter.CompressInterceptor;
-import com.baidu.hugegraph.rest.AbstractRestClient;
-import com.baidu.hugegraph.testutil.Whitebox;
-import com.baidu.hugegraph.util.E;
-
-public class GremlinClient extends AbstractRestClient {
-
- private final WebTarget webTarget;
-
- public GremlinClient(String url, int timeout,
- int maxTotal, int maxPerRoute) {
- super(url, timeout, maxTotal, maxPerRoute);
- this.webTarget = Whitebox.getInternalState(this, "target");
- E.checkNotNull(this.webTarget, "target");
- }
-
- @Override
- protected void checkStatus(Response response, Response.Status... statuses) {
- // pass
- }
-
- public Response doPostRequest(String auth, String req) {
- Entity<?> body = Entity.entity(req, MediaType.APPLICATION_JSON);
- return this.webTarget.request()
- .header(HttpHeaders.AUTHORIZATION, auth)
- .accept(MediaType.APPLICATION_JSON)
- .acceptEncoding(CompressInterceptor.GZIP)
- .post(body);
- }
-
- public Response doGetRequest(String auth,
- MultivaluedMap<String, String> params) {
- WebTarget target = this.webTarget;
- for (Map.Entry<String, List<String>> entry : params.entrySet()) {
- E.checkArgument(entry.getValue().size() == 1,
- "Invalid query param '%s', can only accept " +
- "one value, but got %s",
- entry.getKey(), entry.getValue());
- target = target.queryParam(entry.getKey(), entry.getValue().get(0));
- }
- return target.request()
- .header(HttpHeaders.AUTHORIZATION, auth)
- .accept(MediaType.APPLICATION_JSON)
- .acceptEncoding(CompressInterceptor.GZIP)
- .get();
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/GremlinQueryAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/GremlinQueryAPI.java
deleted file mode 100644
index 6aa0b8b98..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/GremlinQueryAPI.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.api.gremlin;
-
-import java.util.Map;
-import java.util.Set;
-
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.config.HugeConfig;
-import com.baidu.hugegraph.config.ServerOptions;
-import com.baidu.hugegraph.exception.HugeGremlinException;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-
-import jakarta.inject.Provider;
-import jakarta.ws.rs.core.Context;
-import jakarta.ws.rs.core.HttpHeaders;
-import jakarta.ws.rs.core.MediaType;
-import jakarta.ws.rs.core.Response;
-
-public class GremlinQueryAPI extends API {
-
- private static final Set<String> FORBIDDEN_REQUEST_EXCEPTIONS =
- ImmutableSet.of("java.lang.SecurityException",
- "jakarta.ws.rs.ForbiddenException");
- private static final Set<String> BAD_REQUEST_EXCEPTIONS = ImmutableSet.of(
- "java.lang.IllegalArgumentException",
- "java.util.concurrent.TimeoutException",
- "groovy.lang.",
- "org.codehaus.",
- "com.baidu.hugegraph."
- );
-
- @Context
- private Provider<HugeConfig> configProvider;
-
- private GremlinClient client;
-
- public GremlinClient client() {
- if (this.client != null) {
- return this.client;
- }
- HugeConfig config = this.configProvider.get();
- String url = config.get(ServerOptions.GREMLIN_SERVER_URL);
- int timeout = config.get(ServerOptions.GREMLIN_SERVER_TIMEOUT) * 1000;
- int maxRoutes = config.get(ServerOptions.GREMLIN_SERVER_MAX_ROUTE);
- this.client = new GremlinClient(url, timeout, maxRoutes, maxRoutes);
- return this.client;
- }
-
- protected static Response transformResponseIfNeeded(Response response) {
- MediaType mediaType = response.getMediaType();
- if (mediaType != null) {
- // Append charset
- assert MediaType.APPLICATION_JSON_TYPE.equals(mediaType);
- response.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE,
- mediaType.withCharset(CHARSET));
- }
-
- Response.StatusType status = response.getStatusInfo();
- if (status.getStatusCode() < 400) {
- // No need to transform if normal response without error
- return response;
- }
-
- if (mediaType == null || !JSON.equals(mediaType.getSubtype())) {
- String message = response.readEntity(String.class);
- throw new HugeGremlinException(status.getStatusCode(),
- ImmutableMap.of("message", message));
- }
-
- @SuppressWarnings("unchecked")
- Map<String, Object> map = response.readEntity(Map.class);
- String exClassName = (String) map.get("Exception-Class");
- if (FORBIDDEN_REQUEST_EXCEPTIONS.contains(exClassName)) {
- status = Response.Status.FORBIDDEN;
- } else if (matchBadRequestException(exClassName)) {
- status = Response.Status.BAD_REQUEST;
- }
- throw new HugeGremlinException(status.getStatusCode(), map);
- }
-
- private static boolean matchBadRequestException(String exClass) {
- if (exClass == null) {
- return false;
- }
- if (BAD_REQUEST_EXCEPTIONS.contains(exClass)) {
- return true;
- }
- return BAD_REQUEST_EXCEPTIONS.stream().anyMatch(exClass::startsWith);
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/AlgorithmAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/AlgorithmAPI.java
deleted file mode 100644
index b0e0d0692..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/AlgorithmAPI.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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.api.job;
-
-import java.util.Map;
-
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.StatusFilter.Status;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.job.AlgorithmJob;
-import com.baidu.hugegraph.job.JobBuilder;
-import com.baidu.hugegraph.server.RestServer;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.JsonUtil;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.google.common.collect.ImmutableMap;
-
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.NotFoundException;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.core.Context;
-
-@Path("graphs/{graph}/jobs/algorithm")
-@Singleton
-public class AlgorithmAPI extends API {
-
- private static final Logger LOG = Log.logger(RestServer.class);
-
- @POST
- @Timed
- @Path("/{name}")
- @Status(Status.CREATED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public Map<String, Id> post(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("name") String algorithm,
- Map<String, Object> parameters) {
- LOG.debug("Graph [{}] schedule algorithm job: {}", graph, parameters);
- E.checkArgument(algorithm != null && !algorithm.isEmpty(),
- "The algorithm name can't be empty");
- if (parameters == null) {
- parameters = ImmutableMap.of();
- }
- if (!AlgorithmJob.check(algorithm, parameters)) {
- throw new NotFoundException("Not found algorithm: " + algorithm);
- }
-
- HugeGraph g = graph(manager, graph);
- Map<String, Object> input = ImmutableMap.of("algorithm", algorithm,
- "parameters", parameters);
- JobBuilder<Object> builder = JobBuilder.of(g);
- builder.name("algorithm:" + algorithm)
- .input(JsonUtil.toJson(input))
- .job(new AlgorithmJob());
- return ImmutableMap.of("task_id", builder.schedule().id());
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/ComputerAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/ComputerAPI.java
deleted file mode 100644
index f3825f893..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/ComputerAPI.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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.api.job;
-
-import java.util.Map;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.NotFoundException;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.core.Context;
-
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.StatusFilter.Status;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.job.ComputerJob;
-import com.baidu.hugegraph.job.JobBuilder;
-import com.baidu.hugegraph.task.HugeTask;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.JsonUtil;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.google.common.collect.ImmutableMap;
-
-@Path("graphs/{graph}/jobs/computer")
-@Singleton
-@Tag(name = "ComputerAPI")
-public class ComputerAPI extends API {
-
- private static final Logger LOG = Log.logger(ComputerAPI.class);
-
- @POST
- @Timed
- @Path("/{name}")
- @Status(Status.CREATED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public Map<String, Id> post(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("name") String computer,
- Map<String, Object> parameters) {
- LOG.debug("Graph [{}] schedule computer job: {}", graph, parameters);
- E.checkArgument(computer != null && !computer.isEmpty(),
- "The computer name can't be empty");
- if (parameters == null) {
- parameters = ImmutableMap.of();
- }
- if (!ComputerJob.check(computer, parameters)) {
- throw new NotFoundException("Not found computer: " + computer);
- }
-
- HugeGraph g = graph(manager, graph);
- Map<String, Object> input = ImmutableMap.of("computer", computer,
- "parameters", parameters);
- JobBuilder<Object> builder = JobBuilder.of(g);
- builder.name("computer:" + computer)
- .input(JsonUtil.toJson(input))
- .job(new ComputerJob());
- HugeTask<Object> task = builder.schedule();
- return ImmutableMap.of("task_id", task.id());
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/GremlinAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/GremlinAPI.java
deleted file mode 100644
index 46039271a..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/GremlinAPI.java
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * 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.api.job;
-
-import java.nio.ByteBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CodingErrorAction;
-import java.util.HashMap;
-import java.util.Map;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.annotation.security.RolesAllowed;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.core.Context;
-
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeException;
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.StatusFilter.Status;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.define.Checkable;
-import com.baidu.hugegraph.job.GremlinJob;
-import com.baidu.hugegraph.job.JobBuilder;
-import com.baidu.hugegraph.metrics.MetricsUtil;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.JsonUtil;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.Histogram;
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.collect.ImmutableMap;
-
-@Path("graphs/{graph}/jobs/gremlin")
-@Singleton
-@Tag(name = "GremlinAPI")
-public class GremlinAPI extends API {
-
- private static final Logger LOG = Log.logger(GremlinAPI.class);
-
- private static final int MAX_NAME_LENGTH = 256;
-
- private static final Histogram GREMLIN_JOB_INPUT_HISTOGRAM =
- MetricsUtil.registerHistogram(GremlinAPI.class, "gremlin-input");
-
- @POST
- @Timed
- @Status(Status.CREATED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=gremlin_execute"})
- public Map<String, Id> post(@Context GraphManager manager,
- @PathParam("graph") String graph,
- GremlinRequest request) {
- LOG.debug("Graph [{}] schedule gremlin job: {}", graph, request);
- checkCreatingBody(request);
- GREMLIN_JOB_INPUT_HISTOGRAM.update(request.gremlin.length());
-
- HugeGraph g = graph(manager, graph);
- request.aliase(graph, "graph");
- JobBuilder<Object> builder = JobBuilder.of(g);
- builder.name(request.name())
- .input(request.toJson())
- .job(new GremlinJob());
- return ImmutableMap.of("task_id", builder.schedule().id());
- }
-
- public static class GremlinRequest implements Checkable {
-
- // See org.apache.tinkerpop.gremlin.server.channel.HttpChannelizer
- @JsonProperty
- private String gremlin;
- @JsonProperty
- private Map<String, Object> bindings = new HashMap<>();
- @JsonProperty
- private String language = "gremlin-groovy";
- @JsonProperty
- private Map<String, String> aliases = new HashMap<>();
-
- public String gremlin() {
- return this.gremlin;
- }
-
- public void gremlin(String gremlin) {
- this.gremlin = gremlin;
- }
-
- public Map<String, Object> bindings() {
- return this.bindings;
- }
-
- public void bindings(Map<String, Object> bindings) {
- this.bindings = bindings;
- }
-
- public void binding(String name, Object value) {
- this.bindings.put(name, value);
- }
-
- public String language() {
- return this.language;
- }
-
- public void language(String language) {
- this.language = language;
- }
-
- public Map<String, String> aliases() {
- return this.aliases;
- }
-
- public void aliases(Map<String, String> aliases) {
- this.aliases = aliases;
- }
-
- public void aliase(String key, String value) {
- this.aliases.put(key, value);
- }
-
- public String name() {
- // Get the first line of script as the name
- String firstLine = this.gremlin.split("\r\n|\r|\n", 2)[0];
- final Charset charset = Charset.forName(CHARSET);
- final byte[] bytes = firstLine.getBytes(charset);
- if (bytes.length <= MAX_NAME_LENGTH) {
- return firstLine;
- }
-
- /*
- * Reference https://stackoverflow.com/questions/3576754/truncating-strings-by-bytes
- */
- CharsetDecoder decoder = charset.newDecoder();
- decoder.onMalformedInput(CodingErrorAction.IGNORE);
- decoder.reset();
-
- ByteBuffer buffer = ByteBuffer.wrap(bytes, 0, MAX_NAME_LENGTH);
- try {
- return decoder.decode(buffer).toString();
- } catch (CharacterCodingException e) {
- throw new HugeException("Failed to decode truncated bytes of " +
- "gremlin first line", e);
- }
- }
-
- @Override
- public void checkCreate(boolean isBatch) {
- E.checkArgumentNotNull(this.gremlin,
- "The gremlin parameter can't be null");
- E.checkArgumentNotNull(this.language,
- "The language parameter can't be null");
- E.checkArgument(this.aliases == null || this.aliases.isEmpty(),
- "There is no need to pass gremlin aliases");
- }
-
- public String toJson() {
- Map<String, Object> map = new HashMap<>();
- map.put("gremlin", this.gremlin);
- map.put("bindings", this.bindings);
- map.put("language", this.language);
- map.put("aliases", this.aliases);
- return JsonUtil.toJson(map);
- }
-
- public static GremlinRequest fromJson(String json) {
- @SuppressWarnings("unchecked")
- Map<String, Object> map = JsonUtil.fromJson(json, Map.class);
- String gremlin = (String) map.get("gremlin");
- @SuppressWarnings("unchecked")
- Map<String, Object> bindings = (Map<String, Object>)
- map.get("bindings");
- String language = (String) map.get("language");
- @SuppressWarnings("unchecked")
- Map<String, String> aliases = (Map<String, String>)
- map.get("aliases");
-
- GremlinRequest request = new GremlinRequest();
- request.gremlin(gremlin);
- request.bindings(bindings);
- request.language(language);
- request.aliases(aliases);
- return request;
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/RebuildAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/RebuildAPI.java
deleted file mode 100644
index fa5376ec8..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/RebuildAPI.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.api.job;
-
-import java.util.Map;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.annotation.security.RolesAllowed;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.PUT;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.core.Context;
-
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.StatusFilter.Status;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.google.common.collect.ImmutableMap;
-
-@Path("graphs/{graph}/jobs/rebuild")
-@Singleton
-@Tag(name = "RebuildAPI")
-public class RebuildAPI extends API {
-
- private static final Logger LOG = Log.logger(RebuildAPI.class);
-
- @PUT
- @Timed
- @Path("vertexlabels/{name}")
- @Status(Status.ACCEPTED)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=index_write"})
- public Map<String, Id> vertexLabelRebuild(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("name") String name) {
- LOG.debug("Graph [{}] rebuild vertex label: {}", graph, name);
-
- HugeGraph g = graph(manager, graph);
- return ImmutableMap.of("task_id",
- g.schema().vertexLabel(name).rebuildIndex());
- }
-
- @PUT
- @Timed
- @Path("edgelabels/{name}")
- @Status(Status.ACCEPTED)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=index_write"})
- public Map<String, Id> edgeLabelRebuild(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("name") String name) {
- LOG.debug("Graph [{}] rebuild edge label: {}", graph, name);
-
- HugeGraph g = graph(manager, graph);
- return ImmutableMap.of("task_id",
- g.schema().edgeLabel(name).rebuildIndex());
- }
-
- @PUT
- @Timed
- @Path("indexlabels/{name}")
- @Status(Status.ACCEPTED)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=index_write"})
- public Map<String, Id> indexLabelRebuild(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("name") String name) {
- LOG.debug("Graph [{}] rebuild index label: {}", graph, name);
-
- HugeGraph g = graph(manager, graph);
- return ImmutableMap.of("task_id",
- g.schema().indexLabel(name).rebuild());
- }
-}
\ No newline at end of file
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/TaskAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/TaskAPI.java
deleted file mode 100644
index bdd7bdc8d..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/TaskAPI.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * 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.api.job;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.BadRequestException;
-import jakarta.ws.rs.DELETE;
-import jakarta.ws.rs.DefaultValue;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.NotSupportedException;
-import jakarta.ws.rs.PUT;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-
-import org.apache.groovy.util.Maps;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.StatusFilter.Status;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.backend.id.IdGenerator;
-import com.baidu.hugegraph.backend.page.PageInfo;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.task.HugeTask;
-import com.baidu.hugegraph.task.TaskScheduler;
-import com.baidu.hugegraph.task.TaskStatus;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-
-@Path("graphs/{graph}/tasks")
-@Singleton
-@Tag(name = "TaskAPI")
-public class TaskAPI extends API {
-
- private static final Logger LOG = Log.logger(TaskAPI.class);
- private static final long NO_LIMIT = -1L;
-
- public static final String ACTION_CANCEL = "cancel";
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public Map<String, Object> list(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("status") String status,
- @QueryParam("ids") List<Long> ids,
- @QueryParam("limit")
- @DefaultValue("100") long limit,
- @QueryParam("page") String page) {
- LOG.debug("Graph [{}] list tasks with status {}, ids {}, " +
- "limit {}, page {}", graph, status, ids, limit, page);
-
- TaskScheduler scheduler = graph(manager, graph).taskScheduler();
-
- Iterator<HugeTask<Object>> iter;
-
- if (!ids.isEmpty()) {
- E.checkArgument(status == null,
- "Not support status when query task by ids, " +
- "but got status='%s'", status);
- E.checkArgument(page == null,
- "Not support page when query task by ids, " +
- "but got page='%s'", page);
- // Set limit to NO_LIMIT to ignore limit when query task by ids
- limit = NO_LIMIT;
- List<Id> idList = ids.stream().map(IdGenerator::of)
- .collect(Collectors.toList());
- iter = scheduler.tasks(idList);
- } else {
- if (status == null) {
- iter = scheduler.tasks(null, limit, page);
- } else {
- iter = scheduler.tasks(parseStatus(status), limit, page);
- }
- }
-
- List<Object> tasks = new ArrayList<>();
- while (iter.hasNext()) {
- tasks.add(iter.next().asMap(false));
- }
- if (limit != NO_LIMIT && tasks.size() > limit) {
- tasks = tasks.subList(0, (int) limit);
- }
-
- if (page == null) {
- return Maps.of("tasks", tasks);
- } else {
- return Maps.of("tasks", tasks, "page", PageInfo.pageInfo(iter));
- }
- }
-
- @GET
- @Timed
- @Path("{id}")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public Map<String, Object> get(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") long id) {
- LOG.debug("Graph [{}] get task: {}", graph, id);
-
- TaskScheduler scheduler = graph(manager, graph).taskScheduler();
- return scheduler.task(IdGenerator.of(id)).asMap();
- }
-
- @DELETE
- @Timed
- @Path("{id}")
- public void delete(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") long id) {
- LOG.debug("Graph [{}] delete task: {}", graph, id);
-
- TaskScheduler scheduler = graph(manager, graph).taskScheduler();
- HugeTask<?> task = scheduler.delete(IdGenerator.of(id));
- E.checkArgument(task != null, "There is no task with id '%s'", id);
- }
-
- @PUT
- @Timed
- @Path("{id}")
- @Status(Status.ACCEPTED)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public Map<String, Object> update(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("id") long id,
- @QueryParam("action") String action) {
- LOG.debug("Graph [{}] cancel task: {}", graph, id);
-
- if (!ACTION_CANCEL.equals(action)) {
- throw new NotSupportedException(String.format(
- "Not support action '%s'", action));
- }
-
- TaskScheduler scheduler = graph(manager, graph).taskScheduler();
- HugeTask<?> task = scheduler.task(IdGenerator.of(id));
- if (!task.completed() && !task.cancelling()) {
- scheduler.cancel(task);
- if (task.cancelling() || task.cancelled()) {
- return task.asMap();
- }
- }
-
- assert task.completed() || task.cancelling();
- throw new BadRequestException(String.format(
- "Can't cancel task '%s' which is completed or cancelling",
- id));
- }
-
- private static TaskStatus parseStatus(String status) {
- try {
- return TaskStatus.valueOf(status.toUpperCase());
- } catch (Exception e) {
- throw new IllegalArgumentException(String.format(
- "Status value must be in %s, but got '%s'",
- Arrays.asList(TaskStatus.values()), status));
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/metrics/MetricsAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/metrics/MetricsAPI.java
deleted file mode 100644
index 60ef91281..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/metrics/MetricsAPI.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * 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.api.metrics;
-
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static java.util.concurrent.TimeUnit.SECONDS;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.annotation.security.RolesAllowed;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.core.Context;
-
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.backend.store.BackendMetrics;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.metrics.MetricsModule;
-import com.baidu.hugegraph.metrics.ServerReporter;
-import com.baidu.hugegraph.metrics.SystemMetrics;
-import com.baidu.hugegraph.util.InsertionOrderUtil;
-import com.baidu.hugegraph.util.JsonUtil;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.Metric;
-import com.codahale.metrics.annotation.Timed;
-
-@Singleton
-@Path("metrics")
-@Tag(name = "MetricsAPI")
-public class MetricsAPI extends API {
-
- private static final Logger LOG = Log.logger(MetricsAPI.class);
-
- private SystemMetrics systemMetrics;
-
- static {
- JsonUtil.registerModule(new MetricsModule(SECONDS, MILLISECONDS, false));
- }
-
- public MetricsAPI() {
- this.systemMetrics = new SystemMetrics();
- }
-
- @GET
- @Timed
- @Path("system")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner= $action=metrics_read"})
- public String system() {
- return JsonUtil.toJson(this.systemMetrics.metrics());
- }
-
- @GET
- @Timed
- @Path("backend")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner= $action=metrics_read"})
- public String backend(@Context GraphManager manager) {
- Map<String, Map<String, Object>> results = InsertionOrderUtil.newMap();
- for (String graph : manager.graphs()) {
- HugeGraph g = manager.graph(graph);
- Map<String, Object> metrics = InsertionOrderUtil.newMap();
- metrics.put(BackendMetrics.BACKEND, g.backend());
- try {
- metrics.putAll(g.metadata(null, "metrics"));
- } catch (Throwable e) {
- metrics.put(BackendMetrics.EXCEPTION, e.toString());
- LOG.debug("Failed to get backend metrics", e);
- }
- results.put(graph, metrics);
- }
- return JsonUtil.toJson(results);
- }
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner= $action=metrics_read"})
- public String all() {
- ServerReporter reporter = ServerReporter.instance();
- Map<String, Map<String, ? extends Metric>> result = new LinkedHashMap<>();
- result.put("gauges", reporter.gauges());
- result.put("counters", reporter.counters());
- result.put("histograms", reporter.histograms());
- result.put("meters", reporter.meters());
- result.put("timers", reporter.timers());
- return JsonUtil.toJson(result);
- }
-
- @GET
- @Timed
- @Path("gauges")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner= $action=metrics_read"})
- public String gauges() {
- ServerReporter reporter = ServerReporter.instance();
- return JsonUtil.toJson(reporter.gauges());
- }
-
- @GET
- @Timed
- @Path("counters")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner= $action=metrics_read"})
- public String counters() {
- ServerReporter reporter = ServerReporter.instance();
- return JsonUtil.toJson(reporter.counters());
- }
-
- @GET
- @Timed
- @Path("histograms")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner= $action=metrics_read"})
- public String histograms() {
- ServerReporter reporter = ServerReporter.instance();
- return JsonUtil.toJson(reporter.histograms());
- }
-
- @GET
- @Timed
- @Path("meters")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner= $action=metrics_read"})
- public String meters() {
- ServerReporter reporter = ServerReporter.instance();
- return JsonUtil.toJson(reporter.meters());
- }
-
- @GET
- @Timed
- @Path("timers")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner= $action=metrics_read"})
- public String timers() {
- ServerReporter reporter = ServerReporter.instance();
- return JsonUtil.toJson(reporter.timers());
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/profile/GraphsAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/profile/GraphsAPI.java
deleted file mode 100644
index d59a9afaa..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/profile/GraphsAPI.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * 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.api.profile;
-
-import java.io.File;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.annotation.security.RolesAllowed;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.DELETE;
-import jakarta.ws.rs.ForbiddenException;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.NotSupportedException;
-import jakarta.ws.rs.PUT;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-import jakarta.ws.rs.core.SecurityContext;
-
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.auth.HugeAuthenticator.RequiredPerm;
-import com.baidu.hugegraph.auth.HugePermission;
-import com.baidu.hugegraph.config.HugeConfig;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.type.define.GraphMode;
-import com.baidu.hugegraph.type.define.GraphReadMode;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.JsonUtil;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.google.common.collect.ImmutableMap;
-
-@Path("graphs")
-@Singleton
-@Tag(name = "GraphsAPI")
-public class GraphsAPI extends API {
-
- private static final Logger LOG = Log.logger(GraphsAPI.class);
-
- private static final String CONFIRM_CLEAR = "I'm sure to delete all data";
- private static final String CONFIRM_DROP = "I'm sure to drop the graph";
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$dynamic"})
- public Object list(@Context GraphManager manager,
- @Context SecurityContext sc) {
- Set<String> graphs = manager.graphs();
- // Filter by user role
- Set<String> filterGraphs = new HashSet<>();
- for (String graph : graphs) {
- String role = RequiredPerm.roleFor(graph, HugePermission.READ);
- if (sc.isUserInRole(role)) {
- try {
- HugeGraph g = graph(manager, graph);
- filterGraphs.add(g.name());
- } catch (ForbiddenException ignored) {
- // ignore
- }
- }
- }
- return ImmutableMap.of("graphs", filterGraphs);
- }
-
- @GET
- @Timed
- @Path("{name}")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$name"})
- public Object get(@Context GraphManager manager,
- @PathParam("name") String name) {
- LOG.debug("Get graph by name '{}'", name);
-
- HugeGraph g = graph(manager, name);
- return ImmutableMap.of("name", g.name(), "backend", g.backend());
- }
-
- @DELETE
- @Timed
- @Path("{name}")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin"})
- public void drop(@Context GraphManager manager,
- @PathParam("name") String name,
- @QueryParam("confirm_message") String message) {
- LOG.debug("Drop graph by name '{}'", name);
-
- E.checkArgument(CONFIRM_DROP.equals(message),
- "Please take the message: %s", CONFIRM_DROP);
- manager.dropGraph(name);
- }
-
- @POST
- @Timed
- @Path("{name}")
- @Consumes(TEXT_PLAIN)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin"})
- public Object create(@Context GraphManager manager,
- @PathParam("name") String name,
- @QueryParam("clone_graph_name") String clone,
- String configText) {
- LOG.debug("Create graph '{}' with clone graph '{}', config text '{}'",
- name, clone, configText);
- HugeGraph graph;
- if (StringUtils.isNotEmpty(clone)) {
- graph = manager.cloneGraph(clone, name, configText);
- } else {
- graph = manager.createGraph(name, configText);
- }
- return ImmutableMap.of("name", graph.name(),
- "backend", graph.backend());
- }
-
- @GET
- @Timed
- @Path("{name}/conf")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed("admin")
- public File getConf(@Context GraphManager manager,
- @PathParam("name") String name) {
- LOG.debug("Get graph configuration by name '{}'", name);
-
- HugeGraph g = graph4admin(manager, name);
-
- HugeConfig config = (HugeConfig) g.configuration();
- File file = config.file();
- if (file == null) {
- throw new NotSupportedException("Can't access the api in " +
- "a node which started with non local file config.");
- }
- return file;
- }
-
- @DELETE
- @Timed
- @Path("{name}/clear")
- @Consumes(APPLICATION_JSON)
- @RolesAllowed("admin")
- public void clear(@Context GraphManager manager,
- @PathParam("name") String name,
- @QueryParam("confirm_message") String message) {
- LOG.debug("Clear graph by name '{}'", name);
-
- E.checkArgument(CONFIRM_CLEAR.equals(message),
- "Please take the message: %s", CONFIRM_CLEAR);
- HugeGraph g = graph(manager, name);
- g.truncateBackend();
- }
-
- @PUT
- @Timed
- @Path("{name}/snapshot_create")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$name"})
- public Object createSnapshot(@Context GraphManager manager,
- @PathParam("name") String name) {
- LOG.debug("Create snapshot for graph '{}'", name);
-
- HugeGraph g = graph(manager, name);
- g.createSnapshot();
- return ImmutableMap.of(name, "snapshot_created");
- }
-
- @PUT
- @Timed
- @Path("{name}/snapshot_resume")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$name"})
- public Object resumeSnapshot(@Context GraphManager manager,
- @PathParam("name") String name) {
- LOG.debug("Resume snapshot for graph '{}'", name);
-
- HugeGraph g = graph(manager, name);
- g.resumeSnapshot();
- return ImmutableMap.of(name, "snapshot_resumed");
- }
-
- @PUT
- @Timed
- @Path("{name}/compact")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin"})
- public String compact(@Context GraphManager manager,
- @PathParam("name") String name) {
- LOG.debug("Manually compact graph '{}'", name);
-
- HugeGraph g = graph(manager, name);
- return JsonUtil.toJson(g.metadata(null, "compact"));
- }
-
- @PUT
- @Timed
- @Path("{name}/mode")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$name"})
- public Map<String, GraphMode> mode(@Context GraphManager manager,
- @PathParam("name") String name,
- GraphMode mode) {
- LOG.debug("Set mode to: '{}' of graph '{}'", mode, name);
-
- E.checkArgument(mode != null, "Graph mode can't be null");
- HugeGraph g = graph(manager, name);
- g.mode(mode);
- return ImmutableMap.of("mode", mode);
- }
-
- @GET
- @Timed
- @Path("{name}/mode")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$name"})
- public Map<String, GraphMode> mode(@Context GraphManager manager,
- @PathParam("name") String name) {
- LOG.debug("Get mode of graph '{}'", name);
-
- HugeGraph g = graph(manager, name);
- return ImmutableMap.of("mode", g.mode());
- }
-
- @PUT
- @Timed
- @Path("{name}/graph_read_mode")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed("admin")
- public Map<String, GraphReadMode> graphReadMode(
- @Context GraphManager manager,
- @PathParam("name") String name,
- GraphReadMode readMode) {
- LOG.debug("Set graph-read-mode to: '{}' of graph '{}'",
- readMode, name);
-
- E.checkArgument(readMode != null,
- "Graph-read-mode can't be null");
- HugeGraph g = graph(manager, name);
- g.readMode(readMode);
- return ImmutableMap.of("graph_read_mode", readMode);
- }
-
- @GET
- @Timed
- @Path("{name}/graph_read_mode")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$name"})
- public Map<String, GraphReadMode> graphReadMode(
- @Context GraphManager manager,
- @PathParam("name") String name) {
- LOG.debug("Get graph-read-mode of graph '{}'", name);
-
- HugeGraph g = graph(manager, name);
- return ImmutableMap.of("graph_read_mode", g.readMode());
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/profile/ProfileAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/profile/ProfileAPI.java
deleted file mode 100644
index 5f20dc4be..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/profile/ProfileAPI.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * 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.api.profile;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.TreeSet;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.core.Application;
-import jakarta.ws.rs.core.Context;
-import jakarta.ws.rs.core.MediaType;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.tinkerpop.shaded.jackson.annotation.JsonProperty;
-import org.glassfish.jersey.model.Parameter.Source;
-import org.glassfish.jersey.server.model.Parameter;
-import org.glassfish.jersey.server.model.Resource;
-import org.glassfish.jersey.server.model.ResourceMethod;
-
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.InsertionOrderUtil;
-import com.baidu.hugegraph.util.JsonUtil;
-import com.baidu.hugegraph.version.CoreVersion;
-import com.codahale.metrics.annotation.Timed;
-
-@Path("/")
-@Singleton
-@Tag(name = "ProfileAPI")
-public class ProfileAPI {
-
- private static final String SERVICE = "hugegraph";
- private static final String DOC = "https://hugegraph.github.io/hugegraph-doc/";
- private static final String API_DOC = DOC + "clients/hugegraph-api.html";
-
- private static String SERVER_PROFILES = null;
- private static String API_PROFILES = null;
-
- @GET
- @Timed
- @Produces(MediaType.APPLICATION_JSON)
- public String getProfile(@Context Application application) {
- // May init multi times by multi threads, but no effect on the results
- if (SERVER_PROFILES != null) {
- return SERVER_PROFILES;
- }
-
- Map<String, Object> profiles = InsertionOrderUtil.newMap();
- profiles.put("service", SERVICE);
- profiles.put("version", CoreVersion.VERSION.toString());
- profiles.put("doc", DOC);
- profiles.put("api_doc", API_DOC);
- Set<String> apis = new TreeSet<>();
- for (Class<?> clazz : application.getClasses()) {
- if (!isAnnotatedPathClass(clazz)) {
- continue;
- }
- Resource resource = Resource.from(clazz);
- APICategory apiCategory = APICategory.parse(resource.getName());
- apis.add(apiCategory.dir);
- }
- profiles.put("apis", apis);
- SERVER_PROFILES = JsonUtil.toJson(profiles);
- return SERVER_PROFILES;
- }
-
- @GET
- @Path("apis")
- @Timed
- @Produces(MediaType.APPLICATION_JSON)
- public String showAllAPIs(@Context Application application) {
- if (API_PROFILES != null) {
- return API_PROFILES;
- }
-
- APIProfiles apiProfiles = new APIProfiles();
- for (Class<?> clazz : application.getClasses()) {
- if (!isAnnotatedPathClass(clazz)) {
- continue;
- }
-
- Resource resource = Resource.from(clazz);
- APICategory apiCategory = APICategory.parse(resource.getName());
-
- String url = resource.getPath();
- // List all methods of this resource
- for (ResourceMethod rm : resource.getResourceMethods()) {
- APIProfile profile = APIProfile.parse(url, rm);
- apiProfiles.put(apiCategory, profile);
- }
- // List all methods of this resource's child resources
- for (Resource childResource : resource.getChildResources()) {
- String childUrl = url + "/" + childResource.getPath();
- for (ResourceMethod rm : childResource.getResourceMethods()) {
- APIProfile profile = APIProfile.parse(childUrl, rm);
- apiProfiles.put(apiCategory, profile);
- }
- }
- }
- API_PROFILES = JsonUtil.toJson(apiProfiles);
- return API_PROFILES;
- }
-
- private static boolean isAnnotatedPathClass(Class<?> clazz) {
- if (clazz.isAnnotationPresent(Path.class)) {
- return true;
- }
- for (Class<?> i : clazz.getInterfaces()) {
- if (i.isAnnotationPresent(Path.class)) {
- return true;
- }
- }
- return false;
- }
-
- private static class APIProfiles {
-
- @JsonProperty("apis")
- private final Map<String, Map<String, List<APIProfile>>> apis;
-
- public APIProfiles() {
- this.apis = new TreeMap<>();
- }
-
- public void put(APICategory category, APIProfile profile) {
- Map<String, List<APIProfile>> categories;
- categories = this.apis.computeIfAbsent(category.dir,
- k -> new TreeMap<>());
- List<APIProfile> profiles = categories.computeIfAbsent(
- category.category,
- k -> new ArrayList<>());
- profiles.add(profile);
- }
- }
-
- private static class APIProfile {
-
- @JsonProperty("url")
- private final String url;
- @JsonProperty("method")
- private final String method;
- @JsonProperty("parameters")
- private final List<ParamInfo> parameters;
-
- public APIProfile(String url, String method,
- List<ParamInfo> parameters) {
- this.url = url;
- this.method = method;
- this.parameters = parameters;
- }
-
- public static APIProfile parse(String url, ResourceMethod resource) {
- String method = resource.getHttpMethod();
- List<ParamInfo> params = new ArrayList<>();
- for (Parameter param : resource.getInvocable().getParameters()) {
- if (param.getSource() == Source.QUERY) {
- String name = param.getSourceName();
- String type = param.getType().getTypeName();
- String defaultValue = param.getDefaultValue();
- params.add(new ParamInfo(name, type, defaultValue));
- } else if (param.getSource() == Source.ENTITY) {
- String type = param.getType().getTypeName();
- params.add(new ParamInfo("body", type));
- }
- }
- return new APIProfile(url, method, params);
- }
-
- private static class ParamInfo {
-
- @JsonProperty("name")
- private final String name;
- @JsonProperty("type")
- private final String type;
- @JsonProperty("default_value")
- private final String defaultValue;
-
- public ParamInfo(String name, String type) {
- this(name, type, null);
- }
-
- public ParamInfo(String name, String type, String defaultValue) {
- this.name = name;
- this.type = type;
- this.defaultValue = defaultValue;
- }
- }
- }
-
- private static class APICategory {
-
- private final String dir;
- private final String category;
-
- public APICategory(String dir, String category) {
- this.dir = dir;
- this.category = category;
- }
-
- public static APICategory parse(String fullName) {
- String[] parts = StringUtils.split(fullName, ".");
- E.checkState(parts.length >= 2, "Invalid api name");
- String dir = parts[parts.length - 2];
- String category = parts[parts.length - 1];
- return new APICategory(dir, category);
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/profile/VersionAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/profile/VersionAPI.java
deleted file mode 100644
index 0bf8fdcc9..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/profile/VersionAPI.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.api.profile;
-
-import java.util.Map;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.annotation.security.PermitAll;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.Produces;
-
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.version.ApiVersion;
-import com.baidu.hugegraph.version.CoreVersion;
-import com.codahale.metrics.annotation.Timed;
-import com.google.common.collect.ImmutableMap;
-
-@Path("versions")
-@Singleton
-@Tag(name = "VersionAPI")
-public class VersionAPI extends API {
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @PermitAll
- public Object list() {
- Map<String, String> versions = ImmutableMap.of("version", "v1",
- "core", CoreVersion.VERSION.toString(),
- "gremlin", CoreVersion.GREMLIN_VERSION,
- "api", ApiVersion.VERSION.toString());
- return ImmutableMap.of("versions", versions);
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/raft/RaftAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/raft/RaftAPI.java
deleted file mode 100644
index d8cce6e26..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/raft/RaftAPI.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * 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.api.raft;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.annotation.security.RolesAllowed;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.DefaultValue;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeException;
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.StatusFilter.Status;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.backend.store.raft.RaftAddPeerJob;
-import com.baidu.hugegraph.backend.store.raft.RaftGroupManager;
-import com.baidu.hugegraph.backend.store.raft.RaftRemovePeerJob;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.job.JobBuilder;
-import com.baidu.hugegraph.util.DateUtil;
-import com.baidu.hugegraph.util.JsonUtil;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.google.common.collect.ImmutableMap;
-
-@Path("graphs/{graph}/raft")
-@Singleton
-@Tag(name = "RaftAPI")
-public class RaftAPI extends API {
-
- private static final Logger LOG = Log.logger(RaftAPI.class);
-
- @GET
- @Timed
- @Path("list_peers")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin"})
- public Map<String, List<String>> listPeers(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("group")
- @DefaultValue("default")
- String group) {
- LOG.debug("Graph [{}] prepare to get leader", graph);
-
- HugeGraph g = graph(manager, graph);
- RaftGroupManager raftManager = raftGroupManager(g, group, "list_peers");
- List<String> peers = raftManager.listPeers();
- return ImmutableMap.of(raftManager.group(), peers);
- }
-
- @GET
- @Timed
- @Path("get_leader")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin"})
- public Map<String, String> getLeader(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("group")
- @DefaultValue("default")
- String group) {
- LOG.debug("Graph [{}] prepare to get leader", graph);
-
- HugeGraph g = graph(manager, graph);
- RaftGroupManager raftManager = raftGroupManager(g, group, "get_leader");
- String leaderId = raftManager.getLeader();
- return ImmutableMap.of(raftManager.group(), leaderId);
- }
-
- @POST
- @Timed
- @Status(Status.OK)
- @Path("transfer_leader")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin"})
- public Map<String, String> transferLeader(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("group")
- @DefaultValue("default")
- String group,
- @QueryParam("endpoint")
- String endpoint) {
- LOG.debug("Graph [{}] prepare to transfer leader to: {}",
- graph, endpoint);
-
- HugeGraph g = graph(manager, graph);
- RaftGroupManager raftManager = raftGroupManager(g, group,
- "transfer_leader");
- String leaderId = raftManager.transferLeaderTo(endpoint);
- return ImmutableMap.of(raftManager.group(), leaderId);
- }
-
- @POST
- @Timed
- @Status(Status.OK)
- @Path("set_leader")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin"})
- public Map<String, String> setLeader(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("group")
- @DefaultValue("default")
- String group,
- @QueryParam("endpoint")
- String endpoint) {
- LOG.debug("Graph [{}] prepare to set leader to: {}",
- graph, endpoint);
-
- HugeGraph g = graph(manager, graph);
- RaftGroupManager raftManager = raftGroupManager(g, group, "set_leader");
- String leaderId = raftManager.setLeader(endpoint);
- return ImmutableMap.of(raftManager.group(), leaderId);
- }
-
- @POST
- @Timed
- @Status(Status.OK)
- @Path("add_peer")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin"})
- public Map<String, Id> addPeer(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("group") @DefaultValue("default")
- String group,
- @QueryParam("endpoint") String endpoint) {
- LOG.debug("Graph [{}] prepare to add peer: {}", graph, endpoint);
-
- HugeGraph g = graph(manager, graph);
- RaftGroupManager raftManager = raftGroupManager(g, group, "add_peer");
-
- JobBuilder<String> builder = JobBuilder.of(g);
- String name = String.format("raft-group-[%s]-add-peer-[%s]-at-[%s]",
- raftManager.group(), endpoint,
- DateUtil.now());
- Map<String, String> inputs = new HashMap<>();
- inputs.put("endpoint", endpoint);
- builder.name(name)
- .input(JsonUtil.toJson(inputs))
- .job(new RaftAddPeerJob());
- return ImmutableMap.of("task_id", builder.schedule().id());
- }
-
- @POST
- @Timed
- @Status(Status.OK)
- @Path("remove_peer")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin"})
- public Map<String, Id> removePeer(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("group")
- @DefaultValue("default") String group,
- @QueryParam("endpoint") String endpoint) {
- LOG.debug("Graph [{}] prepare to remove peer: {}", graph, endpoint);
-
- HugeGraph g = graph(manager, graph);
- RaftGroupManager raftManager = raftGroupManager(g, group,
- "remove_peer");
- JobBuilder<String> builder = JobBuilder.of(g);
- String name = String.format("raft-group-[%s]-remove-peer-[%s]-at-[%s]",
- raftManager.group(), endpoint,
- DateUtil.now());
- Map<String, String> inputs = new HashMap<>();
- inputs.put("endpoint", endpoint);
- builder.name(name)
- .input(JsonUtil.toJson(inputs))
- .job(new RaftRemovePeerJob());
- return ImmutableMap.of("task_id", builder.schedule().id());
- }
-
- private static RaftGroupManager raftGroupManager(HugeGraph graph,
- String group,
- String operation) {
- RaftGroupManager raftManager = graph.raftGroupManager();
- if (raftManager == null) {
- throw new HugeException("Allowed %s operation only when " +
- "working on raft mode", operation);
- }
- return raftManager;
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/schema/EdgeLabelAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/schema/EdgeLabelAPI.java
deleted file mode 100644
index b173c3687..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/schema/EdgeLabelAPI.java
+++ /dev/null
@@ -1,274 +0,0 @@
-/*
- * 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.api.schema;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.annotation.security.RolesAllowed;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.DELETE;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.PUT;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.StatusFilter.Status;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.define.Checkable;
-import com.baidu.hugegraph.schema.EdgeLabel;
-import com.baidu.hugegraph.schema.Userdata;
-import com.baidu.hugegraph.type.define.Frequency;
-import com.baidu.hugegraph.type.define.GraphMode;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.collect.ImmutableMap;
-
-@Path("graphs/{graph}/schema/edgelabels")
-@Singleton
-@Tag(name = "EdgeLabelAPI")
-public class EdgeLabelAPI extends API {
-
- private static final Logger LOG = Log.logger(EdgeLabelAPI.class);
-
- @POST
- @Timed
- @Status(Status.CREATED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=edge_label_write"})
- public String create(@Context GraphManager manager,
- @PathParam("graph") String graph,
- JsonEdgeLabel jsonEdgeLabel) {
- LOG.debug("Graph [{}] create edge label: {}", graph, jsonEdgeLabel);
- checkCreatingBody(jsonEdgeLabel);
-
- HugeGraph g = graph(manager, graph);
- EdgeLabel.Builder builder = jsonEdgeLabel.convert2Builder(g);
- EdgeLabel edgeLabel = builder.create();
- return manager.serializer(g).writeEdgeLabel(edgeLabel);
- }
-
- @PUT
- @Timed
- @Path("{name}")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=edge_label_write"})
- public String update(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("name") String name,
- @QueryParam("action") String action,
- JsonEdgeLabel jsonEdgeLabel) {
- LOG.debug("Graph [{}] {} edge label: {}",
- graph, action, jsonEdgeLabel);
-
- checkUpdatingBody(jsonEdgeLabel);
- E.checkArgument(name.equals(jsonEdgeLabel.name),
- "The name in url(%s) and body(%s) are different",
- name, jsonEdgeLabel.name);
- // Parse action param
- boolean append = checkAndParseAction(action);
-
- HugeGraph g = graph(manager, graph);
- EdgeLabel.Builder builder = jsonEdgeLabel.convert2Builder(g);
- EdgeLabel edgeLabel = append ? builder.append() : builder.eliminate();
- return manager.serializer(g).writeEdgeLabel(edgeLabel);
- }
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=edge_label_read"})
- public String list(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("names") List<String> names) {
- boolean listAll = CollectionUtils.isEmpty(names);
- if (listAll) {
- LOG.debug("Graph [{}] list edge labels", graph);
- } else {
- LOG.debug("Graph [{}] get edge labels by names {}", graph, names);
- }
-
- HugeGraph g = graph(manager, graph);
- List<EdgeLabel> labels;
- if (listAll) {
- labels = g.schema().getEdgeLabels();
- } else {
- labels = new ArrayList<>(names.size());
- for (String name : names) {
- labels.add(g.schema().getEdgeLabel(name));
- }
- }
- return manager.serializer(g).writeEdgeLabels(labels);
- }
-
- @GET
- @Timed
- @Path("{name}")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=edge_label_read"})
- public String get(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("name") String name) {
- LOG.debug("Graph [{}] get edge label by name '{}'", graph, name);
-
- HugeGraph g = graph(manager, graph);
- EdgeLabel edgeLabel = g.schema().getEdgeLabel(name);
- return manager.serializer(g).writeEdgeLabel(edgeLabel);
- }
-
- @DELETE
- @Timed
- @Path("{name}")
- @Status(Status.ACCEPTED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=edge_label_delete"})
- public Map<String, Id> delete(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("name") String name) {
- LOG.debug("Graph [{}] remove edge label by name '{}'", graph, name);
-
- HugeGraph g = graph(manager, graph);
- // Throw 404 if not exists
- g.schema().getEdgeLabel(name);
- return ImmutableMap.of("task_id",
- g.schema().edgeLabel(name).remove());
- }
-
- /**
- * JsonEdgeLabel is only used to receive create and append requests
- */
- @JsonIgnoreProperties(value = {"index_labels", "status"})
- private static class JsonEdgeLabel implements Checkable {
-
- @JsonProperty("id")
- public long id;
- @JsonProperty("name")
- public String name;
- @JsonProperty("source_label")
- public String sourceLabel;
- @JsonProperty("target_label")
- public String targetLabel;
- @JsonProperty("frequency")
- public Frequency frequency;
- @JsonProperty("properties")
- public String[] properties;
- @JsonProperty("sort_keys")
- public String[] sortKeys;
- @JsonProperty("nullable_keys")
- public String[] nullableKeys;
- @JsonProperty("ttl")
- public long ttl;
- @JsonProperty("ttl_start_time")
- public String ttlStartTime;
- @JsonProperty("enable_label_index")
- public Boolean enableLabelIndex;
- @JsonProperty("user_data")
- public Userdata userdata;
- @JsonProperty("check_exist")
- public Boolean checkExist;
-
- @Override
- public void checkCreate(boolean isBatch) {
- E.checkArgumentNotNull(this.name,
- "The name of edge label can't be null");
- }
-
- private EdgeLabel.Builder convert2Builder(HugeGraph g) {
- EdgeLabel.Builder builder = g.schema().edgeLabel(this.name);
- if (this.id != 0) {
- E.checkArgument(this.id > 0,
- "Only positive number can be assign as " +
- "edge label id");
- E.checkArgument(g.mode() == GraphMode.RESTORING,
- "Only accept edge label id when graph in " +
- "RESTORING mode, but '%s' is in mode '%s'",
- g, g.mode());
- builder.id(this.id);
- }
- if (this.sourceLabel != null) {
- builder.sourceLabel(this.sourceLabel);
- }
- if (this.targetLabel != null) {
- builder.targetLabel(this.targetLabel);
- }
- if (this.frequency != null) {
- builder.frequency(this.frequency);
- }
- if (this.properties != null) {
- builder.properties(this.properties);
- }
- if (this.sortKeys != null) {
- builder.sortKeys(this.sortKeys);
- }
- if (this.nullableKeys != null) {
- builder.nullableKeys(this.nullableKeys);
- }
- if (this.enableLabelIndex != null) {
- builder.enableLabelIndex(this.enableLabelIndex);
- }
- if (this.userdata != null) {
- builder.userdata(this.userdata);
- }
- if (this.checkExist != null) {
- builder.checkExist(this.checkExist);
- }
- if (this.ttl != 0) {
- builder.ttl(this.ttl);
- }
- if (this.ttlStartTime != null) {
- E.checkArgument(this.ttl > 0,
- "Only set ttlStartTime when ttl is " +
- "positive, but got ttl: %s", this.ttl);
- builder.ttlStartTime(this.ttlStartTime);
- }
- return builder;
- }
-
- @Override
- public String toString() {
- return String.format("JsonEdgeLabel{" +
- "name=%s, sourceLabel=%s, targetLabel=%s, frequency=%s, " +
- "sortKeys=%s, nullableKeys=%s, properties=%s, ttl=%s, " +
- "ttlStartTime=%s}",
- this.name, this.sourceLabel, this.targetLabel,
- this.frequency, this.sortKeys, this.nullableKeys,
- this.properties, this.ttl, this.ttlStartTime);
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/schema/IndexLabelAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/schema/IndexLabelAPI.java
deleted file mode 100644
index 2f77ca021..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/schema/IndexLabelAPI.java
+++ /dev/null
@@ -1,294 +0,0 @@
-/*
- * 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.api.schema;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.annotation.security.RolesAllowed;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.DELETE;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.PUT;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.StatusFilter.Status;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.define.Checkable;
-import com.baidu.hugegraph.schema.IndexLabel;
-import com.baidu.hugegraph.schema.SchemaElement;
-import com.baidu.hugegraph.schema.Userdata;
-import com.baidu.hugegraph.type.HugeType;
-import com.baidu.hugegraph.type.define.GraphMode;
-import com.baidu.hugegraph.type.define.IndexType;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.collect.ImmutableMap;
-
-@Path("graphs/{graph}/schema/indexlabels")
-@Singleton
-@Tag(name = "IndexLabelAPI")
-public class IndexLabelAPI extends API {
-
- private static final Logger LOG = Log.logger(IndexLabelAPI.class);
-
- @POST
- @Timed
- @Status(Status.ACCEPTED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=index_label_write"})
- public String create(@Context GraphManager manager,
- @PathParam("graph") String graph,
- JsonIndexLabel jsonIndexLabel) {
- LOG.debug("Graph [{}] create index label: {}", graph, jsonIndexLabel);
- checkCreatingBody(jsonIndexLabel);
-
- HugeGraph g = graph(manager, graph);
- IndexLabel.Builder builder = jsonIndexLabel.convert2Builder(g);
- SchemaElement.TaskWithSchema il = builder.createWithTask();
- il.indexLabel(mapIndexLabel(il.indexLabel()));
- return manager.serializer(g).writeTaskWithSchema(il);
- }
-
- @PUT
- @Timed
- @Path("{name}")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String update(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("name") String name,
- @QueryParam("action") String action,
- IndexLabelAPI.JsonIndexLabel jsonIndexLabel) {
- LOG.debug("Graph [{}] {} index label: {}",
- graph, action, jsonIndexLabel);
- checkUpdatingBody(jsonIndexLabel);
- E.checkArgument(name.equals(jsonIndexLabel.name),
- "The name in url(%s) and body(%s) are different",
- name, jsonIndexLabel.name);
- // Parse action parameter
- boolean append = checkAndParseAction(action);
-
- HugeGraph g = graph(manager, graph);
- IndexLabel.Builder builder = jsonIndexLabel.convert2Builder(g);
- IndexLabel indexLabel = append ? builder.append() : builder.eliminate();
- return manager.serializer(g).writeIndexlabel(mapIndexLabel(indexLabel));
- }
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=index_label_read"})
- public String list(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("names") List<String> names) {
- boolean listAll = CollectionUtils.isEmpty(names);
- if (listAll) {
- LOG.debug("Graph [{}] list index labels", graph);
- } else {
- LOG.debug("Graph [{}] get index labels by names {}", graph, names);
- }
-
- HugeGraph g = graph(manager, graph);
- List<IndexLabel> labels;
- if (listAll) {
- labels = g.schema().getIndexLabels();
- } else {
- labels = new ArrayList<>(names.size());
- for (String name : names) {
- labels.add(g.schema().getIndexLabel(name));
- }
- }
- return manager.serializer(g).writeIndexlabels(mapIndexLabels(labels));
- }
-
- @GET
- @Timed
- @Path("{name}")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=index_label_read"})
- public String get(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("name") String name) {
- LOG.debug("Graph [{}] get index label by name '{}'", graph, name);
-
- HugeGraph g = graph(manager, graph);
- IndexLabel indexLabel = g.schema().getIndexLabel(name);
- return manager.serializer(g).writeIndexlabel(mapIndexLabel(indexLabel));
- }
-
- @DELETE
- @Timed
- @Path("{name}")
- @Status(Status.ACCEPTED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=index_label_delete"})
- public Map<String, Id> delete(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("name") String name) {
- LOG.debug("Graph [{}] remove index label by name '{}'", graph, name);
-
- HugeGraph g = graph(manager, graph);
- // Throw 404 if not exists
- g.schema().getIndexLabel(name);
- return ImmutableMap.of("task_id",
- g.schema().indexLabel(name).remove());
- }
-
- private static List<IndexLabel> mapIndexLabels(List<IndexLabel> labels) {
- List<IndexLabel> results = new ArrayList<>(labels.size());
- for (IndexLabel il : labels) {
- results.add(mapIndexLabel(il));
- }
- return results;
- }
-
- /**
- * Map RANGE_INT/RANGE_FLOAT/RANGE_LONG/RANGE_DOUBLE to RANGE
- */
- private static IndexLabel mapIndexLabel(IndexLabel label) {
- if (label.indexType().isRange()) {
- label = (IndexLabel) label.copy();
- label.indexType(IndexType.RANGE);
- }
- return label;
- }
-
- /**
- * JsonIndexLabel is only used to receive create and append requests
- */
- @JsonIgnoreProperties(value = {"status"})
- private static class JsonIndexLabel implements Checkable {
-
- @JsonProperty("id")
- public long id;
- @JsonProperty("name")
- public String name;
- @JsonProperty("base_type")
- public HugeType baseType;
- @JsonProperty("base_value")
- public String baseValue;
- @JsonProperty("index_type")
- public IndexType indexType;
- @JsonProperty("fields")
- public String[] fields;
- @JsonProperty("user_data")
- public Userdata userdata;
- @JsonProperty("check_exist")
- public Boolean checkExist;
- @JsonProperty("rebuild")
- public Boolean rebuild;
-
- @Override
- public void checkCreate(boolean isBatch) {
- E.checkArgumentNotNull(this.name,
- "The name of index label can't be null");
- E.checkArgumentNotNull(this.baseType,
- "The base type of index label '%s' " +
- "can't be null", this.name);
- E.checkArgument(this.baseType == HugeType.VERTEX_LABEL ||
- this.baseType == HugeType.EDGE_LABEL,
- "The base type of index label '%s' can only be " +
- "either VERTEX_LABEL or EDGE_LABEL", this.name);
- E.checkArgumentNotNull(this.baseValue,
- "The base value of index label '%s' " +
- "can't be null", this.name);
- E.checkArgumentNotNull(this.indexType,
- "The index type of index label '%s' " +
- "can't be null", this.name);
- }
-
- @Override
- public void checkUpdate() {
- E.checkArgumentNotNull(this.name,
- "The name of index label can't be null");
- E.checkArgument(this.baseType == null,
- "The base type of index label '%s' must be null",
- this.name);
- E.checkArgument(this.baseValue == null,
- "The base value of index label '%s' must be null",
- this.name);
- E.checkArgument(this.indexType == null,
- "The index type of index label '%s' must be null",
- this.name);
- }
-
- private IndexLabel.Builder convert2Builder(HugeGraph g) {
- IndexLabel.Builder builder = g.schema().indexLabel(this.name);
- if (this.id != 0) {
- E.checkArgument(this.id > 0,
- "Only positive number can be assign as " +
- "index label id");
- E.checkArgument(g.mode() == GraphMode.RESTORING,
- "Only accept index label id when graph in " +
- "RESTORING mode, but '%s' is in mode '%s'",
- g, g.mode());
- builder.id(this.id);
- }
- if (this.baseType != null) {
- assert this.baseValue != null;
- builder.on(this.baseType, this.baseValue);
- }
- if (this.indexType != null) {
- builder.indexType(this.indexType);
- }
- if (this.fields != null && this.fields.length > 0) {
- builder.by(this.fields);
- }
- if (this.userdata != null) {
- builder.userdata(this.userdata);
- }
- if (this.checkExist != null) {
- builder.checkExist(this.checkExist);
- }
- if (this.rebuild != null) {
- builder.rebuild(this.rebuild);
- }
- return builder;
- }
-
- @Override
- public String toString() {
- return String.format("JsonIndexLabel{name=%s, baseType=%s," +
- "baseValue=%s, indexType=%s, fields=%s}",
- this.name, this.baseType, this.baseValue,
- this.indexType, this.fields);
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/schema/PropertyKeyAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/schema/PropertyKeyAPI.java
deleted file mode 100644
index 845733b8d..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/schema/PropertyKeyAPI.java
+++ /dev/null
@@ -1,274 +0,0 @@
-/*
- * 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.api.schema;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.annotation.security.RolesAllowed;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.DELETE;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.PUT;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.StatusFilter.Status;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.backend.id.IdGenerator;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.define.Checkable;
-import com.baidu.hugegraph.schema.PropertyKey;
-import com.baidu.hugegraph.schema.SchemaElement;
-import com.baidu.hugegraph.schema.Userdata;
-import com.baidu.hugegraph.type.define.AggregateType;
-import com.baidu.hugegraph.type.define.Cardinality;
-import com.baidu.hugegraph.type.define.DataType;
-import com.baidu.hugegraph.type.define.GraphMode;
-import com.baidu.hugegraph.type.define.WriteType;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.collect.ImmutableMap;
-
-@Path("graphs/{graph}/schema/propertykeys")
-@Singleton
-@Tag(name = "PropertyKeyAPI")
-public class PropertyKeyAPI extends API {
-
- private static final Logger LOG = Log.logger(PropertyKeyAPI.class);
-
- @POST
- @Timed
- @Status(Status.ACCEPTED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=property_key_write"})
- public String create(@Context GraphManager manager,
- @PathParam("graph") String graph,
- JsonPropertyKey jsonPropertyKey) {
- LOG.debug("Graph [{}] create property key: {}",
- graph, jsonPropertyKey);
- checkCreatingBody(jsonPropertyKey);
-
- HugeGraph g = graph(manager, graph);
- PropertyKey.Builder builder = jsonPropertyKey.convert2Builder(g);
- SchemaElement.TaskWithSchema pk = builder.createWithTask();
- return manager.serializer(g).writeTaskWithSchema(pk);
- }
-
- @PUT
- @Timed
- @Status(Status.ACCEPTED)
- @Path("{name}")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=property_key_write"})
- public String update(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("name") String name,
- @QueryParam("action") String action,
- PropertyKeyAPI.JsonPropertyKey jsonPropertyKey) {
- LOG.debug("Graph [{}] {} property key: {}",
- graph, action, jsonPropertyKey);
- checkUpdatingBody(jsonPropertyKey);
- E.checkArgument(name.equals(jsonPropertyKey.name),
- "The name in url(%s) and body(%s) are different",
- name, jsonPropertyKey.name);
-
- HugeGraph g = graph(manager, graph);
- if (ACTION_CLEAR.equals(action)) {
- PropertyKey propertyKey = g.propertyKey(name);
- E.checkArgument(propertyKey.olap(),
- "Only olap property key can do action clear, " +
- "but got '%s'", propertyKey);
- Id id = g.clearPropertyKey(propertyKey);
- SchemaElement.TaskWithSchema pk =
- new SchemaElement.TaskWithSchema(propertyKey, id);
- return manager.serializer(g).writeTaskWithSchema(pk);
- }
-
- // Parse action parameter
- boolean append = checkAndParseAction(action);
-
- PropertyKey.Builder builder = jsonPropertyKey.convert2Builder(g);
- PropertyKey propertyKey = append ?
- builder.append() :
- builder.eliminate();
- SchemaElement.TaskWithSchema pk =
- new SchemaElement.TaskWithSchema(propertyKey, IdGenerator.ZERO);
- return manager.serializer(g).writeTaskWithSchema(pk);
- }
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=property_key_read"})
- public String list(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("names") List<String> names) {
- boolean listAll = CollectionUtils.isEmpty(names);
- if (listAll) {
- LOG.debug("Graph [{}] list property keys", graph);
- } else {
- LOG.debug("Graph [{}] get property keys by names {}", graph, names);
- }
-
- HugeGraph g = graph(manager, graph);
- List<PropertyKey> propKeys;
- if (listAll) {
- propKeys = g.schema().getPropertyKeys();
- } else {
- propKeys = new ArrayList<>(names.size());
- for (String name : names) {
- propKeys.add(g.schema().getPropertyKey(name));
- }
- }
- return manager.serializer(g).writePropertyKeys(propKeys);
- }
-
- @GET
- @Timed
- @Path("{name}")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=property_key_read"})
- public String get(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("name") String name) {
- LOG.debug("Graph [{}] get property key by name '{}'", graph, name);
-
- HugeGraph g = graph(manager, graph);
- PropertyKey propertyKey = g.schema().getPropertyKey(name);
- return manager.serializer(g).writePropertyKey(propertyKey);
- }
-
- @DELETE
- @Timed
- @Status(Status.ACCEPTED)
- @Path("{name}")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=property_key_delete"})
- public Map<String, Id> delete(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("name") String name) {
- LOG.debug("Graph [{}] remove property key by name '{}'", graph, name);
-
- HugeGraph g = graph(manager, graph);
- // Throw 404 if not exists
- g.schema().getPropertyKey(name);
- return ImmutableMap.of("task_id",
- g.schema().propertyKey(name).remove());
- }
-
- /**
- * JsonPropertyKey is only used to receive create and append requests
- */
- @JsonIgnoreProperties(value = {"status"})
- private static class JsonPropertyKey implements Checkable {
-
- @JsonProperty("id")
- public long id;
- @JsonProperty("name")
- public String name;
- @JsonProperty("cardinality")
- public Cardinality cardinality;
- @JsonProperty("data_type")
- public DataType dataType;
- @JsonProperty("aggregate_type")
- public AggregateType aggregateType;
- @JsonProperty("write_type")
- public WriteType writeType;
- @JsonProperty("properties")
- public String[] properties;
- @JsonProperty("user_data")
- public Userdata userdata;
- @JsonProperty("check_exist")
- public Boolean checkExist;
-
- @Override
- public void checkCreate(boolean isBatch) {
- E.checkArgumentNotNull(this.name,
- "The name of property key can't be null");
- E.checkArgument(this.properties == null ||
- this.properties.length == 0,
- "Not allowed to pass properties when " +
- "creating property key since it doesn't " +
- "support meta properties currently");
- }
-
- private PropertyKey.Builder convert2Builder(HugeGraph g) {
- PropertyKey.Builder builder = g.schema().propertyKey(this.name);
- if (this.id != 0) {
- E.checkArgument(this.id > 0,
- "Only positive number can be assign as " +
- "property key id");
- E.checkArgument(g.mode() == GraphMode.RESTORING,
- "Only accept property key id when graph in " +
- "RESTORING mode, but '%s' is in mode '%s'",
- g, g.mode());
- builder.id(this.id);
- }
- if (this.cardinality != null) {
- builder.cardinality(this.cardinality);
- }
- if (this.dataType != null) {
- builder.dataType(this.dataType);
- }
- if (this.aggregateType != null) {
- builder.aggregateType(this.aggregateType);
- }
- if (this.writeType != null) {
- builder.writeType(this.writeType);
- }
- if (this.userdata != null) {
- builder.userdata(this.userdata);
- }
- if (this.checkExist != null) {
- builder.checkExist(this.checkExist);
- }
- return builder;
- }
-
- @Override
- public String toString() {
- return String.format("JsonPropertyKey{name=%s, cardinality=%s, " +
- "dataType=%s, aggregateType=%s, " +
- "writeType=%s, properties=%s}",
- this.name, this.cardinality,
- this.dataType, this.aggregateType,
- this.writeType, this.properties);
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/schema/SchemaAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/schema/SchemaAPI.java
deleted file mode 100644
index 0fbdf402a..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/schema/SchemaAPI.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.api.schema;
-
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.annotation.security.RolesAllowed;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.core.Context;
-
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.schema.SchemaManager;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-
-@Path("graphs/{graph}/schema")
-@Singleton
-@Tag(name = "SchemaAPI")
-public class SchemaAPI extends API {
-
- private static final Logger LOG = Log.logger(SchemaAPI.class);
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=schema_read"})
- public String list(@Context GraphManager manager,
- @PathParam("graph") String graph) {
- LOG.debug("Graph [{}] list all schema", graph);
-
- HugeGraph g = graph(manager, graph);
- SchemaManager schema = g.schema();
-
- Map<String, List<?>> schemaMap = new LinkedHashMap<>(4);
- schemaMap.put("propertykeys", schema.getPropertyKeys());
- schemaMap.put("vertexlabels", schema.getVertexLabels());
- schemaMap.put("edgelabels", schema.getEdgeLabels());
- schemaMap.put("indexlabels", schema.getIndexLabels());
-
- return manager.serializer(g).writeMap(schemaMap);
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/schema/VertexLabelAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/schema/VertexLabelAPI.java
deleted file mode 100644
index e52419eda..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/schema/VertexLabelAPI.java
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * 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.api.schema;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.annotation.security.RolesAllowed;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.DELETE;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.PUT;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.StatusFilter.Status;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.define.Checkable;
-import com.baidu.hugegraph.schema.Userdata;
-import com.baidu.hugegraph.schema.VertexLabel;
-import com.baidu.hugegraph.type.define.GraphMode;
-import com.baidu.hugegraph.type.define.IdStrategy;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.collect.ImmutableMap;
-
-@Path("graphs/{graph}/schema/vertexlabels")
-@Singleton
-@Tag(name = "VertexLabelAPI")
-public class VertexLabelAPI extends API {
-
- private static final Logger LOG = Log.logger(VertexLabelAPI.class);
-
- @POST
- @Timed
- @Status(Status.CREATED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=vertex_label_write"})
- public String create(@Context GraphManager manager,
- @PathParam("graph") String graph,
- JsonVertexLabel jsonVertexLabel) {
- LOG.debug("Graph [{}] create vertex label: {}",
- graph, jsonVertexLabel);
- checkCreatingBody(jsonVertexLabel);
-
- HugeGraph g = graph(manager, graph);
- VertexLabel.Builder builder = jsonVertexLabel.convert2Builder(g);
- VertexLabel vertexLabel = builder.create();
- return manager.serializer(g).writeVertexLabel(vertexLabel);
- }
-
- @PUT
- @Timed
- @Path("{name}")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=vertex_label_write"})
- public String update(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("name") String name,
- @QueryParam("action") String action,
- JsonVertexLabel jsonVertexLabel) {
- LOG.debug("Graph [{}] {} vertex label: {}",
- graph, action, jsonVertexLabel);
-
- checkUpdatingBody(jsonVertexLabel);
- E.checkArgument(name.equals(jsonVertexLabel.name),
- "The name in url(%s) and body(%s) are different",
- name, jsonVertexLabel.name);
- // Parse action parameter
- boolean append = checkAndParseAction(action);
-
- HugeGraph g = graph(manager, graph);
- VertexLabel.Builder builder = jsonVertexLabel.convert2Builder(g);
- VertexLabel vertexLabel = append ?
- builder.append() :
- builder.eliminate();
- return manager.serializer(g).writeVertexLabel(vertexLabel);
- }
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=vertex_label_read"})
- public String list(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("names") List<String> names) {
- boolean listAll = CollectionUtils.isEmpty(names);
- if (listAll) {
- LOG.debug("Graph [{}] list vertex labels", graph);
- } else {
- LOG.debug("Graph [{}] get vertex labels by names {}", graph, names);
- }
-
- HugeGraph g = graph(manager, graph);
- List<VertexLabel> labels;
- if (listAll) {
- labels = g.schema().getVertexLabels();
- } else {
- labels = new ArrayList<>(names.size());
- for (String name : names) {
- labels.add(g.schema().getVertexLabel(name));
- }
- }
- return manager.serializer(g).writeVertexLabels(labels);
- }
-
- @GET
- @Timed
- @Path("{name}")
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=vertex_label_read"})
- public String get(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("name") String name) {
- LOG.debug("Graph [{}] get vertex label by name '{}'", graph, name);
-
- HugeGraph g = graph(manager, graph);
- VertexLabel vertexLabel = g.schema().getVertexLabel(name);
- return manager.serializer(g).writeVertexLabel(vertexLabel);
- }
-
- @DELETE
- @Timed
- @Path("{name}")
- @Status(Status.ACCEPTED)
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- @RolesAllowed({"admin", "$owner=$graph $action=vertex_label_delete"})
- public Map<String, Id> delete(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @PathParam("name") String name) {
- LOG.debug("Graph [{}] remove vertex label by name '{}'", graph, name);
-
- HugeGraph g = graph(manager, graph);
- // Throw 404 if not exists
- g.schema().getVertexLabel(name);
- return ImmutableMap.of("task_id",
- g.schema().vertexLabel(name).remove());
- }
-
- /**
- * JsonVertexLabel is only used to receive create and append requests
- */
- @JsonIgnoreProperties(value = {"index_labels", "status"})
- private static class JsonVertexLabel implements Checkable {
-
- @JsonProperty("id")
- public long id;
- @JsonProperty("name")
- public String name;
- @JsonProperty("id_strategy")
- public IdStrategy idStrategy;
- @JsonProperty("properties")
- public String[] properties;
- @JsonProperty("primary_keys")
- public String[] primaryKeys;
- @JsonProperty("nullable_keys")
- public String[] nullableKeys;
- @JsonProperty("ttl")
- public long ttl;
- @JsonProperty("ttl_start_time")
- public String ttlStartTime;
- @JsonProperty("enable_label_index")
- public Boolean enableLabelIndex;
- @JsonProperty("user_data")
- public Userdata userdata;
- @JsonProperty("check_exist")
- public Boolean checkExist;
-
- @Override
- public void checkCreate(boolean isBatch) {
- E.checkArgumentNotNull(this.name,
- "The name of vertex label can't be null");
- }
-
- private VertexLabel.Builder convert2Builder(HugeGraph g) {
- VertexLabel.Builder builder = g.schema().vertexLabel(this.name);
- if (this.id != 0) {
- E.checkArgument(this.id > 0,
- "Only positive number can be assign as " +
- "vertex label id");
- E.checkArgument(g.mode() == GraphMode.RESTORING,
- "Only accept vertex label id when graph in " +
- "RESTORING mode, but '%s' is in mode '%s'",
- g, g.mode());
- builder.id(this.id);
- }
- if (this.idStrategy != null) {
- builder.idStrategy(this.idStrategy);
- }
- if (this.properties != null) {
- builder.properties(this.properties);
- }
- if (this.primaryKeys != null) {
- builder.primaryKeys(this.primaryKeys);
- }
- if (this.nullableKeys != null) {
- builder.nullableKeys(this.nullableKeys);
- }
- if (this.enableLabelIndex != null) {
- builder.enableLabelIndex(this.enableLabelIndex);
- }
- if (this.userdata != null) {
- builder.userdata(this.userdata);
- }
- if (this.checkExist != null) {
- builder.checkExist(this.checkExist);
- }
- if (this.ttl != 0) {
- builder.ttl(this.ttl);
- }
- if (this.ttlStartTime != null) {
- E.checkArgument(this.ttl > 0,
- "Only set ttlStartTime when ttl is " +
- "positive, but got ttl: %s", this.ttl);
- builder.ttlStartTime(this.ttlStartTime);
- }
- return builder;
- }
-
- @Override
- public String toString() {
- return String.format("JsonVertexLabel{" +
- "name=%s, idStrategy=%s, primaryKeys=%s, nullableKeys=%s, " +
- "properties=%s, ttl=%s, ttlStartTime=%s}",
- this.name, this.idStrategy, this.primaryKeys,
- this.nullableKeys, this.properties, this.ttl,
- this.ttlStartTime);
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/AdamicAdarAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/AdamicAdarAPI.java
deleted file mode 100644
index efd74cab2..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/AdamicAdarAPI.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright 2022 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.api.traversers;
-
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_ELEMENTS_LIMIT;
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.DefaultValue;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.graph.EdgeAPI;
-import com.baidu.hugegraph.api.graph.VertexAPI;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.traversal.algorithm.PredictionTraverser;
-import com.baidu.hugegraph.type.define.Directions;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.JsonUtil;
-import com.codahale.metrics.annotation.Timed;
-import com.google.common.collect.ImmutableMap;
-
-/**
- * AdamicAdar is one of the prediction algorithms in graph, you can get more
- * info and definition in:
- * https://en.wikipedia.org/wiki/Adamic/Adar_index
- */
-@Path("graphs/{graph}/traversers/adamicadar")
-@Singleton
-@Tag(name = "AdamicAdarAPI")
-public class AdamicAdarAPI extends API {
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String get(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("vertex") String current,
- @QueryParam("other") String other,
- @QueryParam("direction") String direction,
- @QueryParam("label") String edgeLabel,
- @QueryParam("max_degree")
- @DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree,
- @QueryParam("limit")
- @DefaultValue(DEFAULT_ELEMENTS_LIMIT) int limit) {
- LOG.debug("Graph [{}] get adamic adar between '{}' and '{}' with " +
- "direction {}, edge label {}, max degree '{}' and limit '{}'",
- graph, current, other, direction, edgeLabel, maxDegree,
- limit);
-
- Id sourceId = VertexAPI.checkAndParseVertexId(current);
- Id targetId = VertexAPI.checkAndParseVertexId(other);
- E.checkArgument(!current.equals(other),
- "The source and target vertex id can't be same");
- Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
-
- HugeGraph g = graph(manager, graph);
- try (PredictionTraverser traverser = new PredictionTraverser(g)) {
- double score = traverser.adamicAdar(sourceId, targetId, dir,
- edgeLabel, maxDegree, limit);
- return JsonUtil.toJson(ImmutableMap.of("adamic_adar", score));
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/AllShortestPathsAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/AllShortestPathsAPI.java
deleted file mode 100644
index 2b8660f90..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/AllShortestPathsAPI.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * 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.api.traversers;
-
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_CAPACITY;
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
-
-import java.util.List;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.DefaultValue;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.graph.EdgeAPI;
-import com.baidu.hugegraph.api.graph.VertexAPI;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.traversal.algorithm.HugeTraverser;
-import com.baidu.hugegraph.traversal.algorithm.ShortestPathTraverser;
-import com.baidu.hugegraph.type.define.Directions;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.google.common.collect.ImmutableList;
-
-@Path("graphs/{graph}/traversers/allshortestpaths")
-@Singleton
-@Tag(name = "AllShortestPathsAPI")
-public class AllShortestPathsAPI extends API {
-
- private static final Logger LOG = Log.logger(AllShortestPathsAPI.class);
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String get(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("source") String source,
- @QueryParam("target") String target,
- @QueryParam("direction") String direction,
- @QueryParam("label") String edgeLabel,
- @QueryParam("max_depth") int depth,
- @QueryParam("max_degree")
- @DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree,
- @QueryParam("skip_degree")
- @DefaultValue("0") long skipDegree,
- @QueryParam("capacity")
- @DefaultValue(DEFAULT_CAPACITY) long capacity) {
- LOG.debug("Graph [{}] get shortest path from '{}', to '{}' with " +
- "direction {}, edge label {}, max depth '{}', " +
- "max degree '{}', skipped degree '{}' and capacity '{}'",
- graph, source, target, direction, edgeLabel, depth,
- maxDegree, skipDegree, capacity);
-
- Id sourceId = VertexAPI.checkAndParseVertexId(source);
- Id targetId = VertexAPI.checkAndParseVertexId(target);
- Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
-
- HugeGraph g = graph(manager, graph);
-
- ShortestPathTraverser traverser = new ShortestPathTraverser(g);
- List<String> edgeLabels = edgeLabel == null ? ImmutableList.of() :
- ImmutableList.of(edgeLabel);
- HugeTraverser.PathSet paths = traverser.allShortestPaths(
- sourceId, targetId, dir, edgeLabels,
- depth, maxDegree, skipDegree, capacity);
- return manager.serializer(g).writePaths("paths", paths, false);
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CountAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CountAPI.java
deleted file mode 100644
index 3a0ebb2e6..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CountAPI.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * 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.api.traversers;
-
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_SKIP_DEGREE;
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.NO_LIMIT;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.core.Context;
-
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.structure.HugeVertex;
-import com.baidu.hugegraph.traversal.algorithm.CountTraverser;
-import com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep;
-import com.baidu.hugegraph.type.define.Directions;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.annotation.JsonAlias;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.collect.ImmutableMap;
-
-@Path("graphs/{graph}/traversers/count")
-@Singleton
-@Tag(name = "CountAPI")
-public class CountAPI extends API {
-
- private static final Logger LOG = Log.logger(CountAPI.class);
-
- @POST
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String post(@Context GraphManager manager,
- @PathParam("graph") String graph,
- CountRequest request) {
- LOG.debug("Graph [{}] get count from '{}' with request {}",
- graph, request);
-
- E.checkArgumentNotNull(request.source,
- "The source of request can't be null");
- Id sourceId = HugeVertex.getIdValue(request.source);
- E.checkArgumentNotNull(request.steps != null &&
- !request.steps.isEmpty(),
- "The steps of request can't be null or empty");
- E.checkArgumentNotNull(request.dedupSize == NO_LIMIT ||
- request.dedupSize >= 0L,
- "The dedup size of request " +
- "must >= 0 or == -1, but got: '%s'",
- request.dedupSize);
-
- HugeGraph g = graph(manager, graph);
- List<EdgeStep> steps = steps(g, request);
- CountTraverser traverser = new CountTraverser(g);
- long count = traverser.count(sourceId, steps, request.containsTraversed,
- request.dedupSize);
-
- return manager.serializer(g).writeMap(ImmutableMap.of("count", count));
- }
-
- private static List<EdgeStep> steps(HugeGraph graph, CountRequest request) {
- int stepSize = request.steps.size();
- List<EdgeStep> steps = new ArrayList<>(stepSize);
- for (Step step : request.steps) {
- steps.add(step.jsonToStep(graph));
- }
- return steps;
- }
-
- private static class CountRequest {
-
- @JsonProperty("source")
- public Object source;
- @JsonProperty("steps")
- public List<Step> steps;
- @JsonProperty("contains_traversed")
- public boolean containsTraversed = false;
- @JsonProperty("dedup_size")
- public long dedupSize = 1000000L;
-
- @Override
- public String toString() {
- return String.format("CountRequest{source=%s,steps=%s," +
- "containsTraversed=%s,dedupSize=%s}",
- this.source, this.steps,
- this.containsTraversed, this.dedupSize);
- }
- }
-
- private static class Step {
-
- @JsonProperty("direction")
- public Directions direction = Directions.BOTH;
- @JsonProperty("labels")
- public List<String> labels;
- @JsonProperty("properties")
- public Map<String, Object> properties;
- @JsonAlias("degree")
- @JsonProperty("max_degree")
- public long maxDegree = Long.parseLong(DEFAULT_MAX_DEGREE);
- @JsonProperty("skip_degree")
- public long skipDegree = Long.parseLong(DEFAULT_SKIP_DEGREE);
-
- @Override
- public String toString() {
- return String.format("Step{direction=%s,labels=%s,properties=%s" +
- "maxDegree=%s,skipDegree=%s}",
- this.direction, this.labels, this.properties,
- this.maxDegree, this.skipDegree);
- }
-
- private EdgeStep jsonToStep(HugeGraph graph) {
- return new EdgeStep(graph, this.direction, this.labels,
- this.properties, this.maxDegree,
- this.skipDegree);
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CrosspointsAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CrosspointsAPI.java
deleted file mode 100644
index 53daf2f1d..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CrosspointsAPI.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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.api.traversers;
-
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_CAPACITY;
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_PATHS_LIMIT;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.DefaultValue;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.graph.EdgeAPI;
-import com.baidu.hugegraph.api.graph.VertexAPI;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.traversal.algorithm.HugeTraverser;
-import com.baidu.hugegraph.traversal.algorithm.PathsTraverser;
-import com.baidu.hugegraph.type.define.Directions;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-
-@Path("graphs/{graph}/traversers/crosspoints")
-@Singleton
-@Tag(name = "CrosspointsAPI")
-public class CrosspointsAPI extends API {
-
- private static final Logger LOG = Log.logger(CrosspointsAPI.class);
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String get(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("source") String source,
- @QueryParam("target") String target,
- @QueryParam("direction") String direction,
- @QueryParam("label") String edgeLabel,
- @QueryParam("max_depth") int depth,
- @QueryParam("max_degree")
- @DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree,
- @QueryParam("capacity")
- @DefaultValue(DEFAULT_CAPACITY) long capacity,
- @QueryParam("limit")
- @DefaultValue(DEFAULT_PATHS_LIMIT) int limit) {
- LOG.debug("Graph [{}] get crosspoints with paths from '{}', to '{}' " +
- "with direction '{}', edge label '{}', max depth '{}', " +
- "max degree '{}', capacity '{}' and limit '{}'",
- graph, source, target, direction, edgeLabel,
- depth, maxDegree, capacity, limit);
-
- Id sourceId = VertexAPI.checkAndParseVertexId(source);
- Id targetId = VertexAPI.checkAndParseVertexId(target);
- Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
-
- HugeGraph g = graph(manager, graph);
- PathsTraverser traverser = new PathsTraverser(g);
- HugeTraverser.PathSet paths = traverser.paths(sourceId, dir, targetId,
- dir, edgeLabel, depth,
- maxDegree, capacity,
- limit);
- return manager.serializer(g).writePaths("crosspoints", paths, true);
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedCrosspointsAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedCrosspointsAPI.java
deleted file mode 100644
index c1699e9bd..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedCrosspointsAPI.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * 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.api.traversers;
-
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_CAPACITY;
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_PATHS_LIMIT;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.core.Context;
-
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.backend.query.QueryResults;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.traversal.algorithm.CustomizedCrosspointsTraverser;
-import com.baidu.hugegraph.traversal.algorithm.HugeTraverser;
-import com.baidu.hugegraph.type.define.Directions;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.annotation.JsonAlias;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-@Path("graphs/{graph}/traversers/customizedcrosspoints")
-@Singleton
-@Tag(name = "CustomizedCrosspointsAPI")
-public class CustomizedCrosspointsAPI extends API {
-
- private static final Logger LOG = Log.logger(CustomizedCrosspointsAPI.class);
-
- @POST
- @Timed
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String post(@Context GraphManager manager,
- @PathParam("graph") String graph,
- CrosspointsRequest request) {
- E.checkArgumentNotNull(request,
- "The crosspoints request body can't be null");
- E.checkArgumentNotNull(request.sources,
- "The sources of crosspoints request " +
- "can't be null");
- E.checkArgument(request.pathPatterns != null &&
- !request.pathPatterns.isEmpty(),
- "The steps of crosspoints request can't be empty");
-
- LOG.debug("Graph [{}] get customized crosspoints from source vertex " +
- "'{}', with path_pattern '{}', with_path '{}', with_vertex " +
- "'{}', capacity '{}' and limit '{}'", graph, request.sources,
- request.pathPatterns, request.withPath, request.withVertex,
- request.capacity, request.limit);
-
- HugeGraph g = graph(manager, graph);
- Iterator<Vertex> sources = request.sources.vertices(g);
- List<CustomizedCrosspointsTraverser.PathPattern> patterns;
- patterns = pathPatterns(g, request);
-
- CustomizedCrosspointsTraverser traverser =
- new CustomizedCrosspointsTraverser(g);
- CustomizedCrosspointsTraverser.CrosspointsPaths paths;
- paths = traverser.crosspointsPaths(sources, patterns, request.capacity,
- request.limit);
- Iterator<Vertex> iter = QueryResults.emptyIterator();
- if (!request.withVertex) {
- return manager.serializer(g).writeCrosspoints(paths, iter,
- request.withPath);
- }
- Set<Id> ids = new HashSet<>();
- if (request.withPath) {
- for (HugeTraverser.Path p : paths.paths()) {
- ids.addAll(p.vertices());
- }
- } else {
- ids = paths.crosspoints();
- }
- if (!ids.isEmpty()) {
- iter = g.vertices(ids.toArray());
- }
- return manager.serializer(g).writeCrosspoints(paths, iter,
- request.withPath);
- }
-
- private static List<CustomizedCrosspointsTraverser.PathPattern>
- pathPatterns(HugeGraph graph, CrosspointsRequest request) {
- int stepSize = request.pathPatterns.size();
- List<CustomizedCrosspointsTraverser.PathPattern> pathPatterns;
- pathPatterns = new ArrayList<>(stepSize);
- for (PathPattern pattern : request.pathPatterns) {
- CustomizedCrosspointsTraverser.PathPattern pathPattern;
- pathPattern = new CustomizedCrosspointsTraverser.PathPattern();
- for (Step step : pattern.steps) {
- pathPattern.add(step.jsonToStep(graph));
- }
- pathPatterns.add(pathPattern);
- }
- return pathPatterns;
- }
-
- private static class CrosspointsRequest {
-
- @JsonProperty("sources")
- public Vertices sources;
- @JsonProperty("path_patterns")
- public List<PathPattern> pathPatterns;
- @JsonProperty("capacity")
- public long capacity = Long.parseLong(DEFAULT_CAPACITY);
- @JsonProperty("limit")
- public int limit = Integer.parseInt(DEFAULT_PATHS_LIMIT);
- @JsonProperty("with_path")
- public boolean withPath = false;
- @JsonProperty("with_vertex")
- public boolean withVertex = false;
-
- @Override
- public String toString() {
- return String.format("CrosspointsRequest{sourceVertex=%s," +
- "pathPatterns=%s,withPath=%s,withVertex=%s," +
- "capacity=%s,limit=%s}", this.sources,
- this.pathPatterns, this.withPath,
- this.withVertex, this.capacity, this.limit);
- }
- }
-
- private static class PathPattern {
-
- @JsonProperty("steps")
- public List<Step> steps;
-
- @Override
- public String toString() {
- return String.format("PathPattern{steps=%s", this.steps);
- }
- }
-
- private static class Step {
-
- @JsonProperty("direction")
- public Directions direction;
- @JsonProperty("labels")
- public List<String> labels;
- @JsonProperty("properties")
- public Map<String, Object> properties;
- @JsonAlias("degree")
- @JsonProperty("max_degree")
- public long maxDegree = Long.parseLong(DEFAULT_MAX_DEGREE);
- @JsonProperty("skip_degree")
- public long skipDegree = 0L;
-
- @Override
- public String toString() {
- return String.format("Step{direction=%s,labels=%s,properties=%s," +
- "maxDegree=%s,skipDegree=%s}",
- this.direction, this.labels, this.properties,
- this.maxDegree, this.skipDegree);
- }
-
- private CustomizedCrosspointsTraverser.Step jsonToStep(HugeGraph g) {
- return new CustomizedCrosspointsTraverser.Step(g, this.direction,
- this.labels,
- this.properties,
- this.maxDegree,
- this.skipDegree);
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedPathsAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedPathsAPI.java
deleted file mode 100644
index 4e525f287..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedPathsAPI.java
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * 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.api.traversers;
-
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_CAPACITY;
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_PATHS_LIMIT;
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_SAMPLE;
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_WEIGHT;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.core.Context;
-
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.backend.query.QueryResults;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.traversal.algorithm.CustomizePathsTraverser;
-import com.baidu.hugegraph.traversal.algorithm.HugeTraverser;
-import com.baidu.hugegraph.traversal.algorithm.steps.WeightedEdgeStep;
-import com.baidu.hugegraph.type.define.Directions;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.annotation.JsonAlias;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-@Path("graphs/{graph}/traversers/customizedpaths")
-@Singleton
-@Tag(name = "CustomizedPathsAPI")
-public class CustomizedPathsAPI extends API {
-
- private static final Logger LOG = Log.logger(CustomizedPathsAPI.class);
-
- @POST
- @Timed
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String post(@Context GraphManager manager,
- @PathParam("graph") String graph,
- PathRequest request) {
- E.checkArgumentNotNull(request, "The path request body can't be null");
- E.checkArgumentNotNull(request.sources,
- "The sources of path request can't be null");
- E.checkArgument(request.steps != null && !request.steps.isEmpty(),
- "The steps of path request can't be empty");
- if (request.sortBy == null) {
- request.sortBy = SortBy.NONE;
- }
-
- LOG.debug("Graph [{}] get customized paths from source vertex '{}', " +
- "with steps '{}', sort by '{}', capacity '{}', limit '{}' " +
- "and with_vertex '{}'", graph, request.sources, request.steps,
- request.sortBy, request.capacity, request.limit,
- request.withVertex);
-
- HugeGraph g = graph(manager, graph);
- Iterator<Vertex> sources = request.sources.vertices(g);
- List<WeightedEdgeStep> steps = step(g, request);
- boolean sorted = request.sortBy != SortBy.NONE;
-
- CustomizePathsTraverser traverser = new CustomizePathsTraverser(g);
- List<HugeTraverser.Path> paths;
- paths = traverser.customizedPaths(sources, steps, sorted,
- request.capacity, request.limit);
-
- if (sorted) {
- boolean incr = request.sortBy == SortBy.INCR;
- paths = CustomizePathsTraverser.topNPath(paths, incr,
- request.limit);
- }
-
- if (!request.withVertex) {
- return manager.serializer(g).writePaths("paths", paths, false);
- }
-
- Set<Id> ids = new HashSet<>();
- for (HugeTraverser.Path p : paths) {
- ids.addAll(p.vertices());
- }
- Iterator<Vertex> iter = QueryResults.emptyIterator();
- if (!ids.isEmpty()) {
- iter = g.vertices(ids.toArray());
- }
- return manager.serializer(g).writePaths("paths", paths, false, iter);
- }
-
- private static List<WeightedEdgeStep> step(HugeGraph graph,
- PathRequest req) {
- int stepSize = req.steps.size();
- List<WeightedEdgeStep> steps = new ArrayList<>(stepSize);
- for (Step step : req.steps) {
- steps.add(step.jsonToStep(graph));
- }
- return steps;
- }
-
- private static class PathRequest {
-
- @JsonProperty("sources")
- public Vertices sources;
- @JsonProperty("steps")
- public List<Step> steps;
- @JsonProperty("sort_by")
- public SortBy sortBy;
- @JsonProperty("capacity")
- public long capacity = Long.parseLong(DEFAULT_CAPACITY);
- @JsonProperty("limit")
- public int limit = Integer.parseInt(DEFAULT_PATHS_LIMIT);
- @JsonProperty("with_vertex")
- public boolean withVertex = false;
-
- @Override
- public String toString() {
- return String.format("PathRequest{sourceVertex=%s,steps=%s," +
- "sortBy=%s,capacity=%s,limit=%s," +
- "withVertex=%s}", this.sources, this.steps,
- this.sortBy, this.capacity, this.limit,
- this.withVertex);
- }
- }
-
- private static class Step {
-
- @JsonProperty("direction")
- public Directions direction;
- @JsonProperty("labels")
- public List<String> labels;
- @JsonProperty("properties")
- public Map<String, Object> properties;
- @JsonAlias("degree")
- @JsonProperty("max_degree")
- public long maxDegree = Long.parseLong(DEFAULT_MAX_DEGREE);
- @JsonProperty("skip_degree")
- public long skipDegree = 0L;
- @JsonProperty("weight_by")
- public String weightBy;
- @JsonProperty("default_weight")
- public double defaultWeight = Double.parseDouble(DEFAULT_WEIGHT);
- @JsonProperty("sample")
- public long sample = Long.parseLong(DEFAULT_SAMPLE);
-
- @Override
- public String toString() {
- return String.format("Step{direction=%s,labels=%s,properties=%s," +
- "maxDegree=%s,skipDegree=%s," +
- "weightBy=%s,defaultWeight=%s,sample=%s}",
- this.direction, this.labels, this.properties,
- this.maxDegree, this.skipDegree,
- this.weightBy, this.defaultWeight,
- this.sample);
- }
-
- private WeightedEdgeStep jsonToStep(HugeGraph g) {
- return new WeightedEdgeStep(g, this.direction, this.labels,
- this.properties, this.maxDegree,
- this.skipDegree, this.weightBy,
- this.defaultWeight, this.sample);
- }
- }
-
- private enum SortBy {
- INCR,
- DECR,
- NONE
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/EdgesAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/EdgesAPI.java
deleted file mode 100644
index 200d0b1ae..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/EdgesAPI.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * 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.api.traversers;
-
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_PAGE_LIMIT;
-
-import java.util.Iterator;
-import java.util.List;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.DefaultValue;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-
-import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.api.filter.CompressInterceptor.Compress;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.backend.query.ConditionQuery;
-import com.baidu.hugegraph.backend.store.Shard;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.structure.HugeEdge;
-import com.baidu.hugegraph.type.HugeType;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-
-@Path("graphs/{graph}/traversers/edges")
-@Singleton
-@Tag(name = "EdgesAPI")
-public class EdgesAPI extends API {
-
- private static final Logger LOG = Log.logger(EdgesAPI.class);
-
- @GET
- @Timed
- @Compress
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String list(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("ids") List<String> stringIds) {
- LOG.debug("Graph [{}] get edges by ids: {}", graph, stringIds);
-
- E.checkArgument(stringIds != null && !stringIds.isEmpty(),
- "The ids parameter can't be null or empty");
-
- Object[] ids = new Id[stringIds.size()];
- for (int i = 0; i < ids.length; i++) {
- ids[i] = HugeEdge.getIdValue(stringIds.get(i), false);
- }
-
- HugeGraph g = graph(manager, graph);
-
- Iterator<Edge> edges = g.edges(ids);
- return manager.serializer(g).writeEdges(edges, false);
- }
-
- @GET
- @Timed
- @Path("shards")
- @Compress
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String shards(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("split_size") long splitSize) {
- LOG.debug("Graph [{}] get vertex shards with split size '{}'",
- graph, splitSize);
-
- HugeGraph g = graph(manager, graph);
- List<Shard> shards = g.metadata(HugeType.EDGE_OUT, "splits", splitSize);
- return manager.serializer(g).writeList("shards", shards);
- }
-
- @GET
- @Timed
- @Path("scan")
- @Compress
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String scan(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("start") String start,
- @QueryParam("end") String end,
- @QueryParam("page") String page,
- @QueryParam("page_limit")
- @DefaultValue(DEFAULT_PAGE_LIMIT) long pageLimit) {
- LOG.debug("Graph [{}] query edges by shard(start: {}, end: {}, " +
- "page: {}) ", graph, start, end, page);
-
- HugeGraph g = graph(manager, graph);
-
- ConditionQuery query = new ConditionQuery(HugeType.EDGE_OUT);
- query.scan(start, end);
- query.page(page);
- if (query.paging()) {
- query.limit(pageLimit);
- }
- Iterator<Edge> edges = g.edges(query);
-
- return manager.serializer(g).writeEdges(edges, query.paging());
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/FusiformSimilarityAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/FusiformSimilarityAPI.java
deleted file mode 100644
index 8e659c101..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/FusiformSimilarityAPI.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * 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.api.traversers;
-
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_CAPACITY;
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_PATHS_LIMIT;
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.NO_LIMIT;
-
-import java.util.Iterator;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.core.Context;
-
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator;
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.API;
-import com.baidu.hugegraph.backend.query.QueryResults;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.traversal.algorithm.FusiformSimilarityTraverser;
-import com.baidu.hugegraph.traversal.algorithm.FusiformSimilarityTraverser.SimilarsMap;
-import com.baidu.hugegraph.type.define.Directions;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-@Path("graphs/{graph}/traversers/fusiformsimilarity")
-@Singleton
-@Tag(name = "FusiformSimilarityAPI")
-public class FusiformSimilarityAPI extends API {
-
- private static final Logger LOG = Log.logger(FusiformSimilarityAPI.class);
-
- @POST
- @Timed
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String post(@Context GraphManager manager,
- @PathParam("graph") String graph,
- FusiformSimilarityRequest request) {
- E.checkArgumentNotNull(request, "The fusiform similarity " +
- "request body can't be null");
- E.checkArgumentNotNull(request.sources,
- "The sources of fusiform similarity " +
- "request can't be null");
- if (request.direction == null) {
- request.direction = Directions.BOTH;
- }
- E.checkArgument(request.minNeighbors > 0,
- "The min neighbor count must be > 0, but got: %s",
- request.minNeighbors);
- E.checkArgument(request.maxDegree > 0L || request.maxDegree == NO_LIMIT,
- "The max degree of request must be > 0 or == -1, " +
- "but got: %s", request.maxDegree);
- E.checkArgument(request.alpha > 0 && request.alpha <= 1.0,
- "The alpha of request must be in range (0, 1], " +
- "but got '%s'", request.alpha);
- E.checkArgument(request.minSimilars >= 1,
- "The min similar count of request must be >= 1, " +
- "but got: %s", request.minSimilars);
- E.checkArgument(request.top >= 0,
- "The top must be >= 0, but got: %s", request.top);
-
- LOG.debug("Graph [{}] get fusiform similars from '{}' with " +
- "direction '{}', edge label '{}', min neighbor count '{}', " +
- "alpha '{}', min similar count '{}', group property '{}' " +
- "and min group count '{}'",
- graph, request.sources, request.direction, request.label,
- request.minNeighbors, request.alpha, request.minSimilars,
- request.groupProperty, request.minGroups);
-
- HugeGraph g = graph(manager, graph);
- Iterator<Vertex> sources = request.sources.vertices(g);
- E.checkArgument(sources != null && sources.hasNext(),
- "The source vertices can't be empty");
-
- FusiformSimilarityTraverser traverser =
- new FusiformSimilarityTraverser(g);
- SimilarsMap result = traverser.fusiformSimilarity(
- sources, request.direction, request.label,
- request.minNeighbors, request.alpha,
- request.minSimilars, request.top,
- request.groupProperty, request.minGroups,
- request.maxDegree, request.capacity,
- request.limit, request.withIntermediary);
-
- CloseableIterator.closeIterator(sources);
-
- Iterator<Vertex> iterator = QueryResults.emptyIterator();
- if (request.withVertex && !result.isEmpty()) {
- iterator = g.vertices(result.vertices().toArray());
- }
- return manager.serializer(g).writeSimilars(result, iterator);
- }
-
- private static class FusiformSimilarityRequest {
-
- @JsonProperty("sources")
- public Vertices sources;
- @JsonProperty("label")
- public String label;
- @JsonProperty("direction")
- public Directions direction;
- @JsonProperty("min_neighbors")
- public int minNeighbors;
- @JsonProperty("alpha")
- public double alpha;
- @JsonProperty("min_similars")
- public int minSimilars = 1;
- @JsonProperty("top")
- public int top;
- @JsonProperty("group_property")
- public String groupProperty;
- @JsonProperty("min_groups")
- public int minGroups;
- @JsonProperty("max_degree")
- public long maxDegree = Long.parseLong(DEFAULT_MAX_DEGREE);
- @JsonProperty("capacity")
- public long capacity = Long.parseLong(DEFAULT_CAPACITY);
- @JsonProperty("limit")
- public int limit = Integer.parseInt(DEFAULT_PATHS_LIMIT);
- @JsonProperty("with_intermediary")
- public boolean withIntermediary = false;
- @JsonProperty("with_vertex")
- public boolean withVertex = false;
-
- @Override
- public String toString() {
- return String.format("FusiformSimilarityRequest{sources=%s," +
- "label=%s,direction=%s,minNeighbors=%s," +
- "alpha=%s,minSimilars=%s,top=%s," +
- "groupProperty=%s,minGroups=%s," +
- "maxDegree=%s,capacity=%s,limit=%s," +
- "withIntermediary=%s,withVertex=%s}",
- this.sources, this.label, this.direction,
- this.minNeighbors, this.alpha,
- this.minSimilars, this.top,
- this.groupProperty, this.minGroups,
- this.maxDegree, this.capacity, this.limit,
- this.withIntermediary, this.withVertex);
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/JaccardSimilarityAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/JaccardSimilarityAPI.java
deleted file mode 100644
index 3a31cf4eb..000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/JaccardSimilarityAPI.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * 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.api.traversers;
-
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_CAPACITY;
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
-import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_LIMIT;
-
-import java.util.Map;
-
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.DefaultValue;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.Context;
-
-import org.slf4j.Logger;
-
-import com.baidu.hugegraph.HugeGraph;
-import com.baidu.hugegraph.api.graph.EdgeAPI;
-import com.baidu.hugegraph.api.graph.VertexAPI;
-import com.baidu.hugegraph.backend.id.Id;
-import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.structure.HugeVertex;
-import com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep;
-import com.baidu.hugegraph.traversal.algorithm.JaccardSimilarTraverser;
-import com.baidu.hugegraph.type.define.Directions;
-import com.baidu.hugegraph.util.E;
-import com.baidu.hugegraph.util.JsonUtil;
-import com.baidu.hugegraph.util.Log;
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.collect.ImmutableMap;
-
-@Path("graphs/{graph}/traversers/jaccardsimilarity")
-@Singleton
-@Tag(name = "JaccardSimilarityAPI")
-public class JaccardSimilarityAPI extends TraverserAPI {
-
- private static final Logger LOG = Log.logger(JaccardSimilarityAPI.class);
-
- @GET
- @Timed
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String get(@Context GraphManager manager,
- @PathParam("graph") String graph,
- @QueryParam("vertex") String vertex,
- @QueryParam("other") String other,
- @QueryParam("direction") String direction,
- @QueryParam("label") String edgeLabel,
- @QueryParam("max_degree")
- @DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree) {
- LOG.debug("Graph [{}] get jaccard similarity between '{}' and '{}' " +
- "with direction {}, edge label {} and max degree '{}'",
- graph, vertex, other, direction, edgeLabel, maxDegree);
-
- Id sourceId = VertexAPI.checkAndParseVertexId(vertex);
- Id targetId = VertexAPI.checkAndParseVertexId(other);
- Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
-
- HugeGraph g = graph(manager, graph);
- double similarity;
- try (JaccardSimilarTraverser traverser =
- new JaccardSimilarTraverser(g)) {
- similarity = traverser.jaccardSimilarity(sourceId, targetId, dir,
- edgeLabel, maxDegree);
- }
- return JsonUtil.toJson(ImmutableMap.of("jaccard_similarity",
- similarity));
- }
-
- @POST
- @Timed
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON_WITH_CHARSET)
- public String post(@Context GraphManager manager,
- @PathParam("graph") String graph,
- Request request) {
- E.checkArgumentNotNull(request, "The request body can't be null");
- E.checkArgumentNotNull(request.vertex,
- "The source vertex of request can't be null");
- E.checkArgument(request.step != null,
- "The steps of request can't be null");
- E.checkArgument(request.top >= 0,
- "The top must be >= 0, but got: %s", request.top);
-
- LOG.debug("Graph [{}] get jaccard similars from source vertex '{}', " +
- "with step '{}', top '{}' and capacity '{}'",
- graph, request.vertex, request.step,
- request.top, request.capacity);
-
- HugeGraph g = graph(manager, graph);
- Id sourceId = HugeVertex.getIdValue(request.vertex);
-
- EdgeStep step = step(g, request.step);
-
- Map<Id, Double> results;
- try (JaccardSimilarTraverser traverser =
- new JaccardSimilarTraverser(g)) {
- results = traverser.jaccardSimilars(sourceId, step, request.top,
- request.capacity);
- }
- return manager.serializer(g).writeMap(results);
- }
-
- private static class Request {
-
... 333457 lines suppressed ...