Search in sources :

Example 1 with JobRequest

use of com.alibaba.pegasus.service.protocol.PegasusClient.JobRequest in project GraphScope by alibaba.

the class JobBuilder method main.

public static void main(String[] args) {
    JobConfig confPb = JobConfig.newBuilder().setJobId(1).setJobName("test").setWorkers(1).build();
    // should be converted from pb to bytes
    ByteString opBody = ByteString.EMPTY;
    JobBuilder jobBuilder = new JobBuilder(confPb, opBody);
    // for nested task
    JobBuilder plan = new JobBuilder();
    // build JobReq
    JobRequest jobReq = jobBuilder.map(opBody).flatMap(opBody).repeat(3, plan.flatMap(opBody).flatMap(opBody)).count().unfold(opBody).count().build();
    logger.info("send job req: {}", jobReq.toString());
}
Also used : JobRequest(com.alibaba.pegasus.service.protocol.PegasusClient.JobRequest) ByteString(com.google.protobuf.ByteString) JobConfig(com.alibaba.pegasus.service.protocol.PegasusClient.JobConfig)

Example 2 with JobRequest

use of com.alibaba.pegasus.service.protocol.PegasusClient.JobRequest in project GraphScope by alibaba.

the class ClientExample method main.

public static void main(String[] args) throws Exception {
    RpcChannel rpcChannel0 = new RpcChannel("localhost", 1234);
    RpcChannel rpcChannel1 = new RpcChannel("localhost", 1235);
    List<RpcChannel> channels = new ArrayList<>();
    channels.add(rpcChannel0);
    channels.add(rpcChannel1);
    RpcClient rpcClient = new RpcClient(channels);
    logger.info("Will try to send request");
    JobConfig confPb = JobConfig.newBuilder().setJobId(2).setJobName("ping_pong_example").setWorkers(2).setAll(PegasusClient.Empty.newBuilder().build()).build();
    // for job build
    JobBuilder jobBuilder = new JobBuilder(confPb);
    // for nested task
    JobBuilder start = new JobBuilder();
    // construct job
    jobBuilder.addSource(getSeed(0)).repeat(3, start.exchange(getRoute()).map(add(1)).flatMap(copy(8))).sink(getSink());
    JobRequest req = jobBuilder.build();
    CloseableIterator<JobResponse> iterator = rpcClient.submit(req);
    // process response
    try {
        while (iterator.hasNext()) {
            JobResponse response = iterator.next();
            process(response);
        }
    } catch (Exception e) {
        if (iterator != null) {
            try {
                iterator.close();
            } catch (IOException ioe) {
            // Ignore
            }
        }
        error(Status.fromThrowable(e));
        throw e;
    }
    finish();
    rpcClient.shutdown();
}
Also used : JobRequest(com.alibaba.pegasus.service.protocol.PegasusClient.JobRequest) ArrayList(java.util.ArrayList) JobBuilder(com.alibaba.pegasus.builder.JobBuilder) JobResponse(com.alibaba.pegasus.service.protocol.PegasusClient.JobResponse) IOException(java.io.IOException) JobConfig(com.alibaba.pegasus.service.protocol.PegasusClient.JobConfig) IOException(java.io.IOException)

Aggregations

JobConfig (com.alibaba.pegasus.service.protocol.PegasusClient.JobConfig)2 JobRequest (com.alibaba.pegasus.service.protocol.PegasusClient.JobRequest)2 JobBuilder (com.alibaba.pegasus.builder.JobBuilder)1 JobResponse (com.alibaba.pegasus.service.protocol.PegasusClient.JobResponse)1 ByteString (com.google.protobuf.ByteString)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1