public static void main(String[] args) throws IOException {
    Options options = getOptions(args);
    options.setIsAWSCloudPlatform(true);
    options.setRunner(SparkRunner.class);
    options.setStorageLevel("MEMORY_AND_DISK_SER");

    final Pipeline p = Pipeline.create(options);

    PipelineResult result = execute(options, p);
    if (result == null) {
        throw new RuntimeException("Pipeline Finished with no result.");
    }
    // Note: with Java 2.x your main program needs to explicitly call waitUntilFinish()
    // to interactively induce your main program to block until the pipeline has terminated
    if (options.getIsBlocking()) {
        result.waitUntilFinish();
        if (result.getState() != PipelineResult.State.DONE) {
            throw new RuntimeException("Pipeline Finished with Status: " + result.getState().name());
        }
    }
}

public PipelineResult execute(Options options, Pipeline p) {
    try {
        if (!createESIndexUsingESRestAPI("somename")) {
            return null;
        }
    } catch (Exception e) {
        log.error("index creation failed with exception!", e);
        return null;
    }

    return p.run();
}
