/* * Copyright (C) 2014 Stichting Akvo (Akvo Foundation) * * This file is part of Akvo FLOW. * * Akvo FLOW is free software: you can redistribute it and modify it under the terms of * the GNU Affero General Public License (AGPL) as published by the Free Software Foundation, * either version 3 of the License or any later version. * * Akvo FLOW is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Affero General Public License included below for more details. * * The full license text can also be seen at <http://www.gnu.org/licenses/agpl.html>. */ package org.akvo.gae.remoteapi; import java.io.File; import java.util.List; import com.google.appengine.api.datastore.DatastoreService; import com.google.appengine.api.datastore.DatastoreServiceFactory; import com.google.appengine.api.datastore.Entity; import com.google.appengine.api.datastore.PreparedQuery; import com.google.appengine.api.datastore.Query; import com.google.appengine.repackaged.org.apache.commons.io.FileUtils; import com.google.appengine.tools.remoteapi.RemoteApiInstaller; import com.google.appengine.tools.remoteapi.RemoteApiOptions; public class DeviceList { public static void main(String[] args) throws Exception { if (args.length != 2) { throw new IllegalArgumentException("Missing params"); } final String usr = args[0]; final String pwd = args[1]; final List<String> instances = FileUtils .readLines(new File("/tmp/instances.txt")); final File f = new File("/tmp/device-list.csv"); FileUtils.write(f, "Instance,Version,LastContact\n"); for (String i : instances) { final RemoteApiOptions options = new RemoteApiOptions().server(i + ".appspot.com", 443) .credentials(usr, pwd); final RemoteApiInstaller installer = new RemoteApiInstaller(); final StringBuffer sb = new StringBuffer(); installer.install(options); try { System.out.println("Processing: " + i); DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); Query q = new Query("Device"); PreparedQuery pq = ds.prepare(q); int j = 1; for (Entity e : pq.asIterable()) { if (j % 100 == 0) { System.out.println("."); } else { System.out.print("."); } sb.append( String.format("%s,%s,%s", i, e.getProperty("gallatinSoftwareManifest"), e.getProperty("lastLocationBeaconTime"))) .append("\n"); j++; } FileUtils.write(f, sb.toString(), true); } finally { installer.uninstall(); } System.out.println("\n"); } } }