@GET @Path("/dailysnapshot/{day}") public Response getDailySnapshot(@PathParam("day") @NotNull String day) { OperationStats opStats = new OperationStats("cmdb_api", "get_dailysnapshot", new HashMap<>()); Map<String, String> tags = new HashMap<>(); try { DateTime time = DateTime.parse(day, DateTimeFormat.forPattern("yyyy-MM-dd")); DailySnapshotStore dailySnapshot = factory.getDailyStore(time); Iterator<EsDailySnapshotInstance> iter = dailySnapshot.getSnapshotInstances(); List<EsDailySnapshotInstance> ret = IteratorUtils.toList(iter); logger.info("Success: getDailySnapshot - {}", day); return Response.status(Response.Status.OK) .type(MediaType.APPLICATION_JSON) .entity(ret) .build(); } catch (Exception e) { return Utils.responseException(e, logger, opStats, tags); } } }
public Boolean call() throws Exception { OperationStats op = new OperationStats("job", "DailyRollupJob"); try { Iterator<EsDailySnapshotInstance> cmdbInstances = cmdbStore.getRunningAndRecentTerminatedInstances(0); DailySnapshotStore dailySnapshotStore = dailySnapshotStoreFactory.getDailyStore( DateTime.now(DateTimeZone.UTC)); Iterator<EsDailySnapshotInstance> currentDailySnapshot = dailySnapshotStore.getSnapshotInstances(); RollupUpdateSet updateSet = getUpdateset(cmdbInstances, currentDailySnapshot); logger.info("Have {} inserts and {} updates", updateSet.getInsertList().size(), updateSet.getUpdateList().size()); dailySnapshotStore.bulkInsert(updateSet.getInsertList()); dailySnapshotStore.bulkUpdate(updateSet.getUpdateList()); op.succeed(); return true; } catch (Exception ex) { op.failed(); throw ex; } }
private void syncWithDailySnapshot(NotificationEvent notificationEvent, EsInstance esInstance) throws Exception { EsDailySnapshotInstance snapshotInstance = new EsDailySnapshotInstance((PinterestEsInstance) esInstance); String state = notificationEvent.getDetail().getState(); //Processing event if (State.RUNNING.isState(state)) { DateTime snapshotTime = new DateTime(esInstance.getAwsLaunchTime()).toDateTime(DateTimeZone.UTC); DailySnapshotStore store = this.dailySnapshotStoreFactory.getDailyStore(snapshotTime); store.updateOrInsert(snapshotInstance); } else { DateTime snapshotTime = new DateTime(notificationEvent.getTime()).toDateTime(DateTimeZone.UTC); DailySnapshotStore store = this.dailySnapshotStoreFactory.getDailyStore(snapshotTime); EsDailySnapshotInstance inst = store.getInstanceById(esInstance.getId()); if (inst == null) { store.updateOrInsert(snapshotInstance); } else { store.update(snapshotInstance); } } }