Skip to content

Commit

Permalink
change distribution target for assemblies
Browse files Browse the repository at this point in the history
add license headers changes
  • Loading branch information
[email protected] committed Oct 24, 2019
1 parent 2b6a329 commit 05b0144
Show file tree
Hide file tree
Showing 20 changed files with 248 additions and 52 deletions.
4 changes: 4 additions & 0 deletions fuse-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
</dependency>

<!-- runtime -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed 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.
Expand All @@ -21,17 +21,26 @@
*/

import com.yangdb.fuse.dispatcher.resource.QueryResource;
import com.yangdb.fuse.model.transport.CreatePageRequest;
import com.yangdb.fuse.model.transport.cursor.CreateCursorRequest;
import com.yangdb.fuse.model.transport.cursor.LogicalGraphCursorRequest;
import org.reflections.Reflections;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional;
import java.util.Set;

/**
* Created by Roman on 02/04/2017.
*/
public interface CursorFactory {
interface Context {
QueryResource getQueryResource();

CreateCursorRequest getCursorRequest();

class Impl implements Context{
class Impl implements Context {
//region Constructors
public Impl(QueryResource queryResource, CreateCursorRequest cursorRequest) {
this.queryResource = queryResource;
Expand All @@ -57,4 +66,37 @@ public CreateCursorRequest getCursorRequest() {
}

Cursor createCursor(Context context);

/**
* resolve cursor request class name by CursorType value
* @param cursorTypeName
* @return
*/
static Class<? extends CreateCursorRequest> resolve(String cursorTypeName) {
Reflections reflections = new Reflections("com.yangdb.fuse");
Set<Class<? extends CreateCursorRequest>> allClasses = reflections.getSubTypesOf(CreateCursorRequest.class);
Optional<Class<? extends CreateCursorRequest>> cursorType = allClasses.stream().filter(clazz -> {
try {
//get value of static field member
return clazz.getField("CursorType").get(null).equals(cursorTypeName);
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
return false;
}).findFirst();

return cursorType.isPresent() ? cursorType.get() : LogicalGraphCursorRequest.class;
}

/**
* generate cursor request based on given params
* @param cursorTypeName
* @return
*/
static CreateCursorRequest request(String cursorTypeName, CreatePageRequest pageRequest) throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException {
Class<? extends CreateCursorRequest> cursor = resolve(cursorTypeName);
Constructor<? extends CreateCursorRequest> constructor = cursor.getConstructor(pageRequest.getClass());
return constructor.newInstance(pageRequest);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public interface QueryDriver {

Optional<QueryResourceInfo> createAndFetch(CreateQueryRequest queryRequest);

Optional<Object> run(Query query);
Optional<Object> run(Query query, int pageSize, String cursorType);

Optional<Object> run(String cypher, String ontology);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,19 @@
import com.yangdb.fuse.model.results.AssignmentsQueryResult;
import com.yangdb.fuse.model.transport.*;
import com.yangdb.fuse.model.transport.cursor.CreateCursorRequest;
import com.yangdb.fuse.model.transport.cursor.CreateGraphCursorRequest;
import com.yangdb.fuse.model.transport.cursor.CreatePathsCursorRequest;
import com.yangdb.fuse.model.transport.cursor.LogicalGraphCursorRequest;
import com.yangdb.fuse.model.validation.ValidationResult;
import javaslang.collection.Stream;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import javaslang.control.Option;

import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.stream.Collectors;

import static com.yangdb.fuse.dispatcher.cursor.CursorFactory.request;
import static com.yangdb.fuse.dispatcher.cursor.CursorFactory.resolve;
import static com.yangdb.fuse.model.Utils.getOrCreateId;
import static com.yangdb.fuse.model.asgQuery.AsgCompositeQuery.hasInnerQuery;
import static java.util.Collections.EMPTY_LIST;
Expand Down Expand Up @@ -93,10 +96,10 @@ public Optional<QueryResourceInfo> createAndFetch(CreateQueryRequest request) {
}

@Override
public Optional<Object> run(Query query) {
public Optional<Object> run(Query query, int pageSize, String cursorType) {
String id = UUID.randomUUID().toString();
try {
CreateQueryRequest queryRequest = createQueryRequest(query, id);
CreateQueryRequest queryRequest = new CreateQueryRequest(id, id, query, request(cursorType,new CreatePageRequest(pageSize)));
Optional<QueryResourceInfo> resourceInfo = create(queryRequest);
if (!resourceInfo.isPresent())
return Optional.empty();
Expand All @@ -105,17 +108,16 @@ public Optional<Object> run(Query query) {
return Optional.of(resourceInfo.get().getError());

return Optional.of(resourceInfo.get());
} catch (Throwable e) {
return Optional.of(new QueryResourceInfo().error(
new FuseError(Query.class.getSimpleName(), "failed building the cursor request " + cursorType)));
} finally {
//remove stateless query
// delete(id);
}

}

protected CreateQueryRequest createQueryRequest(Query query, String id) {
return new CreateQueryRequest(id, id, query, new LogicalGraphCursorRequest(new CreatePageRequest()));
}

@Override
public Optional<Object> run(String cypher, String ontology) {
String id = UUID.randomUUID().toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.yangdb.fuse.services.dispatcher.driver;

import com.google.inject.Inject;
import com.yangdb.fuse.client.export.GraphWriter;
import com.yangdb.fuse.client.export.GraphWriterStrategy;
import com.yangdb.fuse.dispatcher.cursor.CursorFactory;
import com.yangdb.fuse.dispatcher.driver.*;
Expand All @@ -20,10 +19,8 @@
import com.yangdb.fuse.model.results.QueryResultBase;
import com.yangdb.fuse.model.transport.CreateQueryRequest;
import com.yangdb.fuse.model.transport.cursor.CreateCursorRequest;
import com.yangdb.fuse.model.transport.cursor.LogicalGraphCursorRequest;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;

import java.util.Map;
import java.util.Optional;

/**
Expand Down Expand Up @@ -57,7 +54,7 @@ protected AsgQuery rewrite(AsgQuery asgQuery) {
}

@Override
public Optional<Object> run(com.yangdb.fuse.model.query.Query query) {
public Optional<Object> run(com.yangdb.fuse.model.query.Query query, int pageSize, String cursorType) {
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected CreateJsonQueryRequest createJsonQueryRequest(String cypher, String on
return new CreateJsonQueryRequest(id, id, cypher, ontology, new LogicalGraphCursorRequest(new CreatePageRequest()));
}

protected CreateQueryRequest createQueryRequest(Query query, String id) {
protected CreateQueryRequest createQueryRequest(Query query, String id, long pageSize) {
return new CreateQueryRequest(id, id, query, new LogicalGraphCursorRequest(new CreatePageRequest()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public ContentResponse<QueryResourceInfo> create(CreateJsonQueryRequest request)
}

@Override
public ContentResponse<Object> run(Query query) {
return controller.run(query);
public ContentResponse<Object> run(Query query, int pageSize, String cursorType) {
return controller.run(query,pageSize,cursorType );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.yangdb.fuse.unipop.controller.promise.appender.SizeSearchAppender;
import com.yangdb.fuse.unipop.controller.search.SearchBuilder;
import com.yangdb.fuse.unipop.controller.search.SearchOrderProviderFactory;
import com.yangdb.fuse.unipop.converter.SearchHitLivePageIterable;
import com.yangdb.fuse.unipop.converter.SearchHitScrollIterable;
import com.yangdb.fuse.unipop.predicates.SelectP;
import com.yangdb.fuse.unipop.promise.TraversalConstraint;
import com.yangdb.fuse.unipop.schemaProviders.GraphElementSchemaProvider;
Expand Down Expand Up @@ -118,12 +118,14 @@ public <E extends Element> Iterator<E> search(SearchQuery<E> searchQuery) {
searchAppender.append(searchBuilder, context);

SearchRequestBuilder searchRequest = searchBuilder.build(client, false);
SearchHitLivePageIterable searchHits = new SearchHitLivePageIterable(
SearchHitScrollIterable searchHits = new SearchHitScrollIterable(
client,
searchRequest,
orderProviderFactory.build(context),
searchBuilder.getLimit(),
searchBuilder.getScrollSize());
searchBuilder.getScrollSize(),
searchBuilder.getScrollTime()
);

ElementConverter<SearchHit, E> elementConverter = new DiscreteVertexConverter<>(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.yangdb.fuse.unipop.controller.search.SearchBuilder;
import com.yangdb.fuse.unipop.controller.search.SearchOrderProviderFactory;
import com.yangdb.fuse.unipop.controller.utils.traversal.TraversalValuesByKeyProvider;
import com.yangdb.fuse.unipop.converter.SearchHitLivePageIterable;
import com.yangdb.fuse.unipop.converter.SearchHitScrollIterable;
import com.yangdb.fuse.unipop.predicates.SelectP;
import com.yangdb.fuse.unipop.promise.Constraint;
import com.yangdb.fuse.unipop.promise.TraversalConstraint;
Expand Down Expand Up @@ -145,12 +145,14 @@ protected Iterator<Edge> search(SearchVertexQuery searchVertexQuery, Iterable<St
searchAppender.append(searchBuilder, context);

SearchRequestBuilder searchRequest = searchBuilder.build(client, false);
SearchHitLivePageIterable searchHits = new SearchHitLivePageIterable(
SearchHitScrollIterable searchHits = new SearchHitScrollIterable(
client,
searchRequest,
orderProviderFactory.build(context),
searchBuilder.getLimit(),
searchBuilder.getScrollSize());
searchBuilder.getScrollSize(),
searchBuilder.getScrollTime()
);

ElementConverter<DataItem, Edge> elementConverter = new CompositeElementConverter<>(
new DiscreteEdgeConverter<>(context, this.profiler));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import com.yangdb.fuse.unipop.controller.promise.appender.SizeSearchAppender;
import com.yangdb.fuse.unipop.controller.search.SearchBuilder;
import com.yangdb.fuse.unipop.controller.search.SearchOrderProviderFactory;
import com.yangdb.fuse.unipop.converter.SearchHitLivePageIterable;
import com.yangdb.fuse.unipop.converter.SearchHitScrollIterable;
import com.yangdb.fuse.unipop.predicates.SelectP;
import com.yangdb.fuse.unipop.promise.TraversalConstraint;
import com.yangdb.fuse.unipop.schemaProviders.GraphElementSchemaProvider;
Expand Down Expand Up @@ -131,12 +131,14 @@ private Iterator<Edge> filterVertices(

SearchRequestBuilder searchRequest = searchBuilder.build(client, true);

SearchHitLivePageIterable searchHits = new SearchHitLivePageIterable(
SearchHitScrollIterable searchHits = new SearchHitScrollIterable(
client,
searchRequest,
orderProviderFactory.build(context),
searchBuilder.getLimit(),
searchBuilder.getScrollSize());
searchBuilder.getScrollSize(),
searchBuilder.getScrollTime()
);

ElementConverter<SearchHit, Edge> converter = new DiscreteVertexFilterConverter(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import com.yangdb.fuse.unipop.controller.search.SearchBuilder;
import com.yangdb.fuse.unipop.controller.search.SearchOrderProviderFactory;
import com.yangdb.fuse.unipop.controller.utils.CollectionUtil;
import com.yangdb.fuse.unipop.converter.SearchHitLivePageIterable;
import com.yangdb.fuse.unipop.converter.SearchHitScrollIterable;
import com.yangdb.fuse.unipop.predicates.SelectP;
import com.yangdb.fuse.unipop.promise.Constraint;
import com.yangdb.fuse.unipop.promise.Promise;
Expand Down Expand Up @@ -185,12 +185,14 @@ private Iterator<Element> queryPromiseVertices(

//build
SearchRequestBuilder searchRequest = searchBuilder.build(client, false);
SearchHitLivePageIterable searchHits = new SearchHitLivePageIterable(
SearchHitScrollIterable searchHits = new SearchHitScrollIterable(
client,
searchRequest,
orderProviderFactory.build(context),
searchBuilder.getLimit(),
searchBuilder.getScrollSize());
searchBuilder.getScrollSize(),
searchBuilder.getScrollTime()
);

return convert(searchHits, new SearchHitPromiseVertexConverter(graph));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import com.yangdb.fuse.unipop.controller.promise.converter.SearchHitPromiseFilterEdgeConverter;
import com.yangdb.fuse.unipop.controller.search.SearchBuilder;
import com.yangdb.fuse.unipop.controller.search.SearchOrderProviderFactory;
import com.yangdb.fuse.unipop.converter.SearchHitLivePageIterable;
import com.yangdb.fuse.unipop.converter.SearchHitScrollIterable;
import com.yangdb.fuse.unipop.predicates.SelectP;
import com.yangdb.fuse.unipop.promise.TraversalConstraint;
import com.yangdb.fuse.unipop.schemaProviders.GraphElementSchemaProvider;
Expand Down Expand Up @@ -136,12 +136,14 @@ private Iterator<Edge> filterPromiseVertices(

SearchRequestBuilder searchRequest = searchBuilder.build(client, true).setSize(0);

SearchHitLivePageIterable searchHits = new SearchHitLivePageIterable(
SearchHitScrollIterable searchHits = new SearchHitScrollIterable(
client,
searchRequest,
orderProviderFactory.build(context),
searchBuilder.getLimit(),
searchBuilder.getScrollSize());
searchBuilder.getScrollSize(),
searchBuilder.getScrollTime()
);

ElementConverter<SearchHit, Edge> converter = new SearchHitPromiseFilterEdgeConverter(graph);
return Stream.ofAll(searchHits)
Expand Down
Loading

0 comments on commit 05b0144

Please sign in to comment.