@GET // path prefix "bundles" is contained here and not in the path annotation of the class // See https://opencast.jira.com/browse/MH-9768 @Path("bundles/list") @Produces(APPLICATION_JSON) @RestQuery( name = "list", description = "Return a list of all running bundles on the whole cluster.", reponses = { @RestResponse(description = "A list of bundles.", responseCode = HttpServletResponse.SC_OK) }, returnDescription = "The search results, expressed as xml or json.") public Response getVersions() { final Monadics.ListMonadic<Jsons.Val> bundleInfos = mlist(getDb().getBundles()).map( Functions.<BundleInfo, Jsons.Val> co(bundleInfo)); return ok(obj(p("bundleInfos", arr(bundleInfos)), p("count", bundleInfos.value().size()))); }
@Override public Response apply(List<BundleInfo> infos) { final Set<BundleVersion> versions = set(); for (BundleInfo bundle : infos) { versions.add(bundle.getVersion()); } final BundleInfo example = infos.get(0); switch (versions.size()) { case 0: // no versions... throw new Error("bug"); case 1: // all versions align return ok(obj(p("consistent", true)).append(fullVersionJson.apply(example.getVersion()))); default: // multiple versions found return ok(obj(p("consistent", false), p("versions", arr(mlist(versions.iterator()) .map(Functions.<BundleVersion, Jsons.Val> co(fullVersionJson)))))); } } });