Search in sources :

Example 1 with DataItem

use of com.dexels.navajo.document.stream.DataItem in project navajo by Dexels.

the class ASTPipeDefinition method transformerElements.

@SuppressWarnings("unchecked")
private List<Object> transformerElements(List<String> problems, String originalExpression, Function<String, FunctionClassification> functionClassifier, Function<String, Optional<Node>> mapResolver) {
    int count = jjtGetNumChildren();
    List<Object> pipeElements = new ArrayList<>();
    for (int i = (partial ? 0 : 1); i < count; i++) {
        ContextExpression interpretToLambda = jjtGetChild(i).interpretToLambda(problems, originalExpression, functionClassifier, mapResolver);
        Object result = interpretToLambda.apply().value;
        if (result instanceof Function) {
            Function<StreamScriptContext, Function<DataItem, DataItem>> merger = (Function<StreamScriptContext, Function<DataItem, DataItem>>) result;
            pipeElements.add(merger);
        } else if (result instanceof ReactiveTransformer) {
            ReactiveTransformer transformer = (ReactiveTransformer) result;
            pipeElements.add(transformer);
        } else {
            logger.warn("huh? {}", result);
        // something weird
        }
    }
    return pipeElements;
}
Also used : Function(java.util.function.Function) ReactiveTransformer(com.dexels.navajo.reactive.api.ReactiveTransformer) DataItem(com.dexels.navajo.document.stream.DataItem) ContextExpression(com.dexels.navajo.expression.api.ContextExpression) ArrayList(java.util.ArrayList) StreamScriptContext(com.dexels.navajo.document.stream.api.StreamScriptContext)

Example 2 with DataItem

use of com.dexels.navajo.document.stream.DataItem in project navajo by Dexels.

the class HttpPushStreamTransformer method execute.

@Override
public FlowableTransformer<DataItem, DataItem> execute(StreamScriptContext context, Optional<ImmutableMessage> current, ImmutableMessage param) {
    ReactiveResolvedParameters resolved = parameters.resolve(context, current, param, metadata);
    String name = resolved.paramString("name");
    String id = resolved.paramString("id");
    String bucket = resolved.paramString("bucket");
    String type = resolved.optionalString("type").orElse("application/octetstream");
    return flow -> {
        Flowable<byte[]> in = flow.map(f -> f.data());
        return HttpResourceFactory.getInstance().getHttpResource(name).put(context.getTenant(), bucket, id, type, in).map(status -> ImmutableFactory.empty().with("code", status, Property.INTEGER_PROPERTY)).map(DataItem::of).toFlowable();
    };
}
Also used : ReactiveResolvedParameters(com.dexels.navajo.reactive.api.ReactiveResolvedParameters) ReactiveTransformer(com.dexels.navajo.reactive.api.ReactiveTransformer) ReactiveParameters(com.dexels.navajo.reactive.api.ReactiveParameters) DataItem(com.dexels.navajo.document.stream.DataItem) TransformerMetadata(com.dexels.navajo.reactive.api.TransformerMetadata) StreamScriptContext(com.dexels.navajo.document.stream.api.StreamScriptContext) ImmutableFactory(com.dexels.immutable.factory.ImmutableFactory) FlowableTransformer(io.reactivex.FlowableTransformer) HttpResourceFactory(com.dexels.navajo.resource.http.HttpResourceFactory) ReactiveResolvedParameters(com.dexels.navajo.reactive.api.ReactiveResolvedParameters) Flowable(io.reactivex.Flowable) Optional(java.util.Optional) Property(com.dexels.navajo.document.Property) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) DataItem(com.dexels.navajo.document.stream.DataItem) Flowable(io.reactivex.Flowable)

Example 3 with DataItem

use of com.dexels.navajo.document.stream.DataItem in project navajo by Dexels.

the class CallRemoteSource method execute.

@Override
public Flowable<DataItem> execute(StreamScriptContext context, Optional<ImmutableMessage> current, ImmutableMessage param) {
    ReactiveResolvedParameters resolved = params.resolve(context, current, ImmutableFactory.empty(), metadata);
    String server = resolved.paramString("server");
    String username = resolved.paramString("username");
    String password = resolved.paramString("password");
    final String service = resolved.paramString("service");
    Flowable<NavajoStreamEvent> flow = client.callWithBodyToStream(server, e -> e.header("X-Navajo-Username", username).header("X-Navajo-Password", password).header("X-Navajo-Service", service).method(HttpMethod.POST), Flowable.<NavajoStreamEvent>empty().compose(StreamDocument.inNavajo(service, Optional.of(username), Optional.of(password))).lift(StreamDocument.serialize()), "text/xml").lift(XML.parseFlowable(10)).concatMap(e -> e).lift(StreamDocument.parse()).concatMap(e -> e).filter(e -> e.type() != NavajoStreamEvent.NavajoEventTypes.NAVAJO_STARTED && e.type() != NavajoStreamEvent.NavajoEventTypes.NAVAJO_DONE);
    Flowable<DataItem> fw = Flowable.just(DataItem.ofEventStream(flow));
    return fw;
}
Also used : ReactiveResolvedParameters(com.dexels.navajo.reactive.api.ReactiveResolvedParameters) Type(com.dexels.navajo.document.stream.DataItem.Type) ReactiveParameters(com.dexels.navajo.reactive.api.ReactiveParameters) DataItem(com.dexels.navajo.document.stream.DataItem) StreamScriptContext(com.dexels.navajo.document.stream.api.StreamScriptContext) ImmutableFactory(com.dexels.immutable.factory.ImmutableFactory) SourceMetadata(com.dexels.navajo.reactive.api.SourceMetadata) HttpMethod(org.eclipse.jetty.http.HttpMethod) NavajoStreamEvent(com.dexels.navajo.document.stream.events.NavajoStreamEvent) ReactiveResolvedParameters(com.dexels.navajo.reactive.api.ReactiveResolvedParameters) Flowable(io.reactivex.Flowable) Optional(java.util.Optional) XML(com.dexels.navajo.document.stream.xml.XML) JettyClient(com.dexels.navajo.client.stream.jetty.JettyClient) StreamDocument(com.dexels.navajo.document.stream.StreamDocument) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) ReactiveSource(com.dexels.navajo.reactive.api.ReactiveSource) DataItem(com.dexels.navajo.document.stream.DataItem) NavajoStreamEvent(com.dexels.navajo.document.stream.events.NavajoStreamEvent)

Example 4 with DataItem

use of com.dexels.navajo.document.stream.DataItem in project navajo by Dexels.

the class CallRemoteTransformer method execute.

@Override
public FlowableTransformer<DataItem, DataItem> execute(StreamScriptContext context, Optional<ImmutableMessage> current, ImmutableMessage param) {
    ReactiveResolvedParameters resolved = parameters.resolve(context, current, param, metadata);
    String server = resolved.paramString("server");
    String username = resolved.paramString("username");
    String password = resolved.paramString("password");
    final String service = resolved.paramString("service");
    return flow -> {
        Flowable<NavajoStreamEvent> result = client.callWithBodyToStream(server, e -> e.header("X-Navajo-Username", username).header("X-Navajo-Password", password).header("X-Navajo-Service", service), flow.map(di -> di.eventStream()).concatMap(e -> e).lift(StreamDocument.serialize()), "text/xml").lift(XML.parseFlowable(10)).concatMap(e -> e).lift(StreamDocument.parse()).concatMap(e -> e).filter(e -> e.type() != NavajoStreamEvent.NavajoEventTypes.NAVAJO_STARTED && e.type() != NavajoStreamEvent.NavajoEventTypes.NAVAJO_DONE);
        return Flowable.just(DataItem.ofEventStream(result));
    };
}
Also used : ReactiveResolvedParameters(com.dexels.navajo.reactive.api.ReactiveResolvedParameters) ReactiveTransformer(com.dexels.navajo.reactive.api.ReactiveTransformer) ReactiveParameters(com.dexels.navajo.reactive.api.ReactiveParameters) DataItem(com.dexels.navajo.document.stream.DataItem) TransformerMetadata(com.dexels.navajo.reactive.api.TransformerMetadata) StreamScriptContext(com.dexels.navajo.document.stream.api.StreamScriptContext) FlowableTransformer(io.reactivex.FlowableTransformer) NavajoStreamEvent(com.dexels.navajo.document.stream.events.NavajoStreamEvent) ReactiveResolvedParameters(com.dexels.navajo.reactive.api.ReactiveResolvedParameters) Flowable(io.reactivex.Flowable) Optional(java.util.Optional) XML(com.dexels.navajo.document.stream.xml.XML) JettyClient(com.dexels.navajo.client.stream.jetty.JettyClient) StreamDocument(com.dexels.navajo.document.stream.StreamDocument) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Flowable(io.reactivex.Flowable)

Example 5 with DataItem

use of com.dexels.navajo.document.stream.DataItem in project navajo by Dexels.

the class HttpPushTransformer method execute.

@Override
public FlowableTransformer<DataItem, DataItem> execute(StreamScriptContext context, Optional<ImmutableMessage> current, ImmutableMessage param) {
    ReactiveResolvedParameters resolved = parameters.resolve(context, current, param, metadata);
    String name = resolved.paramString("name");
    int parallel = resolved.optionalInteger("parallel").orElse(1);
    HttpResource res = HttpResourceFactory.getInstance().getHttpResource(name);
    return flow -> {
        if (res == null) {
            throw new NullPointerException("Missing http resource: " + name);
        }
        return flow.map(f -> f.message()).observeOn(Schedulers.io()).map(msg -> {
            ReactiveResolvedParameters resInMsg = parameters.resolve(context, Optional.of(msg), ImmutableFactory.empty(), metadata);
            String id = resInMsg.paramString("id");
            String bucket = resInMsg.paramString("bucket");
            String property = resInMsg.paramString("property");
            Binary bin = (Binary) msg.columnValue(property);
            return res.put(context.getTenant(), bucket, id, bin).map(e -> e.toMessage()).toFlowable();
        }).flatMap(f -> f, parallel).map(DataItem::of);
    };
}
Also used : ReactiveResolvedParameters(com.dexels.navajo.reactive.api.ReactiveResolvedParameters) ReactiveTransformer(com.dexels.navajo.reactive.api.ReactiveTransformer) ReactiveParameters(com.dexels.navajo.reactive.api.ReactiveParameters) DataItem(com.dexels.navajo.document.stream.DataItem) TransformerMetadata(com.dexels.navajo.reactive.api.TransformerMetadata) StreamScriptContext(com.dexels.navajo.document.stream.api.StreamScriptContext) ImmutableFactory(com.dexels.immutable.factory.ImmutableFactory) FlowableTransformer(io.reactivex.FlowableTransformer) HttpResourceFactory(com.dexels.navajo.resource.http.HttpResourceFactory) ReactiveResolvedParameters(com.dexels.navajo.reactive.api.ReactiveResolvedParameters) Optional(java.util.Optional) Schedulers(io.reactivex.schedulers.Schedulers) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Binary(com.dexels.navajo.document.types.Binary) HttpResource(com.dexels.navajo.resource.http.HttpResource) HttpResource(com.dexels.navajo.resource.http.HttpResource) Binary(com.dexels.navajo.document.types.Binary)

Aggregations

DataItem (com.dexels.navajo.document.stream.DataItem)5 StreamScriptContext (com.dexels.navajo.document.stream.api.StreamScriptContext)5 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)4 ReactiveParameters (com.dexels.navajo.reactive.api.ReactiveParameters)4 ReactiveResolvedParameters (com.dexels.navajo.reactive.api.ReactiveResolvedParameters)4 ReactiveTransformer (com.dexels.navajo.reactive.api.ReactiveTransformer)4 Optional (java.util.Optional)4 ImmutableFactory (com.dexels.immutable.factory.ImmutableFactory)3 TransformerMetadata (com.dexels.navajo.reactive.api.TransformerMetadata)3 Flowable (io.reactivex.Flowable)3 FlowableTransformer (io.reactivex.FlowableTransformer)3 JettyClient (com.dexels.navajo.client.stream.jetty.JettyClient)2 StreamDocument (com.dexels.navajo.document.stream.StreamDocument)2 NavajoStreamEvent (com.dexels.navajo.document.stream.events.NavajoStreamEvent)2 XML (com.dexels.navajo.document.stream.xml.XML)2 HttpResourceFactory (com.dexels.navajo.resource.http.HttpResourceFactory)2 Property (com.dexels.navajo.document.Property)1 Type (com.dexels.navajo.document.stream.DataItem.Type)1 Binary (com.dexels.navajo.document.types.Binary)1 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)1