Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ distro/solr/*.tgz
# emacs files
*#
*~

dashboardv3/node_modules
docs/package-lock.json
13 changes: 13 additions & 0 deletions common/src/main/java/org/apache/atlas/repository/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public final class Constants {
public static final String TYPE_NAME_INTERNAL = INTERNAL_PROPERTY_KEY_PREFIX + "internal";
public static final String ASSET_ENTITY_TYPE = "Asset";
public static final String OWNER_ATTRIBUTE = "owner";
public static final String REF_ASSET_TYPE = "Referenceable";

/**
* Atlan constants
*/
public static final String ATLAN_ASSET_TYPE = "AtlanAsset";

/**
* Entity type's super types property key.
Expand Down Expand Up @@ -148,6 +154,8 @@ public final class Constants {
*/
public static final String VERTEX_INDEX = "vertex_index";

public static final String INDEX_PREFIX = "janusgraph_";

/**
* search backing index name for edge labels.
*/
Expand Down Expand Up @@ -201,6 +209,11 @@ public final class Constants {
public static final String ATTR_NAME_REPLICATED_FROM = "replicatedFrom";
public static final Integer INCOMPLETE_ENTITY_VALUE = Integer.valueOf(1);

/*
* State values
*/
public static final String ACTIVE_STATE_VALUE = "ACTIVE";

/*
* All supported file-format extensions for Bulk Imports through file upload
*/
Expand Down
13 changes: 13 additions & 0 deletions graphdb/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,24 @@
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
</dependency>

<dependency>
<groupId>org.apache.tinkerpop</groupId>
<artifactId>gremlin-core</artifactId>
<version>${tinkerpop.version}</version>
</dependency>

<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>${elasticsearch.version}</version>
</dependency>

<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>${elasticsearch.version}</version>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.groovy.GroovyExpression;
import org.apache.atlas.type.AtlasType;
import org.elasticsearch.search.builder.SearchSourceBuilder;

import javax.script.ScriptEngine;
import javax.script.ScriptException;
Expand Down Expand Up @@ -194,6 +195,8 @@ public interface AtlasGraph<V, E> {
*/
AtlasIndexQuery<V, E> indexQuery(GraphIndexQueryParameters indexQueryParameters);

AtlasIndexQuery<V, E> esIndexQuery(String indexName, SearchSourceBuilder sourceBuilder);

/**
* Gets the management object associated with this graph and opens a transaction
* for changes that are made.
Expand Down
6 changes: 6 additions & 0 deletions graphdb/janus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@
<version>${elasticsearch.version}</version>
</dependency>

<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>${elasticsearch.version}</version>
</dependency>

<dependency>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-es</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.repository.graphdb.janus;

import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasException;
import org.apache.commons.configuration.Configuration;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

public class AtlasElasticsearchDatabase {
private static final Logger LOG = LoggerFactory.getLogger(RestHighLevelClient.class);
private static volatile RestHighLevelClient searchClient;
public static final String INDEX_BACKEND_CONF = "atlas.graph.index.search.hostname";

public static List<HttpHost> getHttpHosts() throws AtlasException {
List<HttpHost> httpHosts = new ArrayList<>();
Configuration configuration = ApplicationProperties.get();
String indexConf = configuration.getString(INDEX_BACKEND_CONF);
String[] hosts = indexConf.split(",");
for (String host: hosts) {
host = host.trim();
String[] hostAndPort = host.split(":");
if (hostAndPort.length == 1) {
httpHosts.add(new HttpHost(hostAndPort[0]));
} else if (hostAndPort.length == 2) {
httpHosts.add(new HttpHost(hostAndPort[0], Integer.parseInt(hostAndPort[1])));
} else {
throw new AtlasException("Invalid config");
}
}
return httpHosts;
}

public static RestHighLevelClient getClient() {
if (searchClient == null) {
synchronized (AtlasElasticsearchDatabase.class) {
if (searchClient == null) {
try {
List<HttpHost> httpHosts = getHttpHosts();

RestClientBuilder restClientBuilder = RestClient.builder(httpHosts.toArray(new HttpHost[0]));
searchClient =
new RestHighLevelClient(restClientBuilder);
} catch (AtlasException e) {

}
}
}
}
return searchClient;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.repository.graphdb.janus;

import org.apache.atlas.repository.graphdb.AtlasIndexQuery;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.commons.lang.NotImplementedException;
import org.apache.tinkerpop.gremlin.process.traversal.Order;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.janusgraph.util.encoding.LongEncoding;

import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.stream.Stream;

public class AtlasElasticsearchIndexQuery implements AtlasIndexQuery<AtlasJanusVertex, AtlasJanusEdge> {
private AtlasJanusGraph graph;
private RestHighLevelClient esClient;
private String index;
private SearchSourceBuilder sourceBuilder;
private SearchResponse searchResponse;

public AtlasElasticsearchIndexQuery(AtlasJanusGraph graph, RestHighLevelClient esClient, String index, SearchSourceBuilder sourceBuilder) {
this.esClient = esClient;
this.sourceBuilder = sourceBuilder;
this.index = index;
this.graph = graph;
searchResponse = null;
}

private SearchRequest getSearchRequest(String index, SearchSourceBuilder sourceBuilder) {
SearchRequest searchRequest = new SearchRequest(index);
searchRequest.source(sourceBuilder);
return searchRequest;
}

private Iterator<Result<AtlasJanusVertex, AtlasJanusEdge>> runQuery(SearchRequest searchRequest) {
Iterator<Result<AtlasJanusVertex, AtlasJanusEdge>> result = null;
try {
searchResponse = esClient.search(searchRequest, RequestOptions.DEFAULT);
Stream<Result<AtlasJanusVertex, AtlasJanusEdge>> resultStream = Arrays.stream(searchResponse.getHits().getHits())
.map(ResultImpl::new);
result = resultStream.iterator();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}

@Override
public Iterator<Result<AtlasJanusVertex, AtlasJanusEdge>> vertices() {
SearchRequest searchRequest = getSearchRequest(index, sourceBuilder);
return runQuery(searchRequest);
}

@Override
public Iterator<Result<AtlasJanusVertex, AtlasJanusEdge>> vertices(int offset, int limit, String sortBy, Order sortOrder) {
throw new NotImplementedException();
}

@Override
public Iterator<Result<AtlasJanusVertex, AtlasJanusEdge>> vertices(int offset, int limit) {
sourceBuilder.from(offset);
sourceBuilder.size(limit);
SearchRequest searchRequest = getSearchRequest(index, sourceBuilder);
return runQuery(searchRequest);
}

@Override
public Long vertexTotals() {
return searchResponse.getHits().getTotalHits().value;
}

public final class ResultImpl implements AtlasIndexQuery.Result<AtlasJanusVertex, AtlasJanusEdge> {
private SearchHit hit;

public ResultImpl(SearchHit hit) {
this.hit = hit;
}

@Override
public AtlasVertex<AtlasJanusVertex, AtlasJanusEdge> getVertex() {
long vertexId = LongEncoding.decode(hit.getId());
return graph.getVertex(String.valueOf(vertexId));
}

@Override
public double getScore() {
return hit.getScore();
}
}
}
Loading