错误请求:"要求失败:会话未激活。"在Apache livy

时间:2017-12-29 09:45:23

标签: java apache livy

代码:

public class PiApp
{

public static void main(String[] args) throws Exception {

    LivyClient client = new LivyClientBuilder().setURI(new URI("http://localhost:8998/")).build();

    try {
        System.out.println("Uploading livy-example jar to the SparkContext...");
        for (String s : System.getProperty("java.class.path").split(File.pathSeparator)) {
            System.out.println("Enter to for");
            if (new File(s).getName().startsWith("livy_1")) {
                System.out.println("Enter to if");
                client.uploadJar(new File(s)).get();
                break;
            }
        }

        final int slices = Integer.parseInt("2");
        System.out.println("submitting");
        try {
            double pi = client.submit(new PiJob(slices)).get();

            System.out.println("Pi is roughly " + pi);
        } catch (Exception e) {
            System.out.println("Enter to catch");
            System.out.println(e.getMessage());
        }
    } finally {
        client.stop(true);
    }
}

}

@SuppressWarnings("serial")
class PiJob implements Job<Double>, Function<Integer, Integer>, 
Function2<Integer, Integer, Integer> {

private final int slices;
private final int samples;

public PiJob(int slices) {
    this.slices = slices;
    this.samples = (int) Math.min(100000L * slices, Integer.MAX_VALUE);
}

public Double call(JobContext ctx) throws Exception {
    List<Integer> sampleList = new ArrayList<Integer>();
    for (int i = 0; i < samples; i++) {
        sampleList.add(i);
    }

    return 4.0d * ctx.sc().parallelize(sampleList, slices).map(this).reduce(this) / samples;
}

public Integer call(Integer v1) {
    double x = Math.random() * 2 - 1;
    double y = Math.random() * 2 - 1;
    return (x * x + y * y < 1) ? 1 : 0;
}

public Integer call(Integer v1, Integer v2) {
    return v1 + v2;
}
}

当我在eclipse中运行这个程序时,我收到一个错误: -

java.io.IOException: Bad Request: "requirement failed: Session isn't active."

如何解决此错误?请告诉我。

0 个答案:

没有答案