Search in sources :

Example 1 with ShortBlob

use of com.google.appengine.api.datastore.ShortBlob in project iosched by google.

the class APIUpdater method isUpToDate.

private boolean isUpToDate(byte[] newHash, UpdateRunLogger logger) {
    Entity lastUpdate = logger.getLastRun();
    byte[] currentHash = null;
    if (lastUpdate != null) {
        ShortBlob hash = (ShortBlob) lastUpdate.getProperty("hash");
        if (hash != null) {
            currentHash = hash.getBytes();
        }
    }
    return Arrays.equals(currentHash, newHash);
}
Also used : Entity(com.google.appengine.api.datastore.Entity) ShortBlob(com.google.appengine.api.datastore.ShortBlob)

Example 2 with ShortBlob

use of com.google.appengine.api.datastore.ShortBlob in project iosched by google.

the class UpdateRunLogger method logUpdateRun.

public void logUpdateRun(int majorVersion, int minorVersion, String filename, byte[] hash, JsonObject data, boolean forced) {
    Entity updateRun = new Entity(UPDATERUN_ENTITY_KIND);
    updateRun.setProperty("date", new Date());
    updateRun.setProperty("hash", new ShortBlob(hash));
    updateRun.setProperty("forced", forced);
    updateRun.setProperty("majorVersion", majorVersion);
    updateRun.setProperty("minorVersion", minorVersion);
    for (Entry<String, Long> performanceItem : timers.entrySet()) {
        updateRun.setProperty("time_" + performanceItem.getKey(), performanceItem.getValue());
    }
    updateRun.setProperty("filename", filename);
    StringBuilder sb = new StringBuilder();
    for (Entry<String, JsonElement> el : data.entrySet()) {
        if (el.getValue().isJsonArray()) {
            sb.append(el.getKey()).append("=").append(el.getValue().getAsJsonArray().size()).append(" ");
        }
    }
    if (sb.length() > 0) {
        // remove trailing space
        sb.deleteCharAt(sb.length() - 1);
    }
    updateRun.setProperty("summary", sb.toString());
    datastore.put(updateRun);
    timers.clear();
}
Also used : Entity(com.google.appengine.api.datastore.Entity) ShortBlob(com.google.appengine.api.datastore.ShortBlob) JsonElement(com.google.gson.JsonElement) Date(java.util.Date)

Example 3 with ShortBlob

use of com.google.appengine.api.datastore.ShortBlob in project iosched by google.

the class LogDataServlet method doGet.

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.setContentType("application/json");
    UpdateRunLogger logger = new UpdateRunLogger();
    JsonObject response = new JsonObject();
    int limitElements = 10;
    if (req.getParameter("limit") != null) {
        limitElements = Integer.parseInt(req.getParameter("limit"));
    }
    List<Entity> lastRunsEntities = logger.getMostRecentRuns(limitElements);
    JsonArray lastRuns = new JsonArray();
    for (Entity run : lastRunsEntities) {
        JsonObject obj = new JsonObject();
        JsonObject timings = new JsonObject();
        TreeMap<String, Object> sortedMap = new TreeMap<String, Object>(run.getProperties());
        for (Entry<String, Object> property : sortedMap.entrySet()) {
            Object value = property.getValue();
            String key = property.getKey();
            if (key.startsWith("time_")) {
                timings.add(key.substring("time_".length()), new JsonPrimitive((Number) value));
            } else {
                JsonPrimitive converted = null;
                if (value instanceof ShortBlob) {
                    converted = new JsonPrimitive(bytesToHex(((ShortBlob) value).getBytes()));
                } else if (value instanceof String) {
                    converted = new JsonPrimitive((String) value);
                } else if (value instanceof Number) {
                    converted = new JsonPrimitive((Number) value);
                } else if (value instanceof Boolean) {
                    converted = new JsonPrimitive((Boolean) value);
                } else if (value instanceof Character) {
                    converted = new JsonPrimitive((Character) value);
                } else if (value instanceof Date) {
                    converted = new JsonPrimitive(DateFormat.getDateTimeInstance().format((Date) value));
                }
                if (converted != null) {
                    obj.add(key, converted);
                }
            }
        }
        obj.add("timings", timings);
        lastRuns.add(obj);
    }
    response.add("lastruns", lastRuns);
    CloudFileManager cloudManager = new CloudFileManager();
    response.add("bucket", new JsonPrimitive(cloudManager.getBucketName()));
    response.add("productionManifest", new JsonPrimitive(cloudManager.getProductionManifestURL()));
    response.add("stagingManifest", new JsonPrimitive(cloudManager.getStagingManifestURL()));
    new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create().toJson(response, resp.getWriter());
}
Also used : Entity(com.google.appengine.api.datastore.Entity) JsonPrimitive(com.google.gson.JsonPrimitive) GsonBuilder(com.google.gson.GsonBuilder) UpdateRunLogger(com.google.samples.apps.iosched.server.schedule.server.UpdateRunLogger) JsonObject(com.google.gson.JsonObject) TreeMap(java.util.TreeMap) Date(java.util.Date) JsonArray(com.google.gson.JsonArray) ShortBlob(com.google.appengine.api.datastore.ShortBlob) CloudFileManager(com.google.samples.apps.iosched.server.schedule.server.cloudstorage.CloudFileManager) JsonObject(com.google.gson.JsonObject)

Aggregations

Entity (com.google.appengine.api.datastore.Entity)3 ShortBlob (com.google.appengine.api.datastore.ShortBlob)3 Date (java.util.Date)2 GsonBuilder (com.google.gson.GsonBuilder)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 UpdateRunLogger (com.google.samples.apps.iosched.server.schedule.server.UpdateRunLogger)1 CloudFileManager (com.google.samples.apps.iosched.server.schedule.server.cloudstorage.CloudFileManager)1 TreeMap (java.util.TreeMap)1