@GET @Path("/assignments") public String getAssignments() throws Exception { ScheduleState state = alertCoordinator.getState(); return JsonUtils.writeValueAsString(state); }
@POST @Path("/validate") public String validate() throws Exception { ValidateState state = alertCoordinator.validate(); return JsonUtils.writeValueAsString(state); }
@POST @Path("/build") public String build() throws Exception { ScheduleOption option = new ScheduleOption(); ScheduleState state = alertCoordinator.schedule(option); return JsonUtils.writeValueAsString(state); }
LOG.debug("calculated schedule state: {}", JsonUtils.writeValueAsString(state));
private static Pair<Long, String> createFailureEntity(AtomicLong base, int hostIndex) { // TODO: add randomization IfEntity ie = new IfEntity(); ie.host = "boot-vm-0-" + hostIndex + ".datacenter.corp.com"; ie.instanceUuid = nextUuid; ie.message = "boot failure for when try start the given vm!"; ie.reqId = nextReqId; ie.timestamp = base.get(); base.addAndGet(2000);// simply some interval. return Pair.of(base.get(), JsonUtils.writeValueAsString(ie)); }
public String streamEventToJson(AlertStreamEvent event) { Map<String, Object> jsonMap = new HashMap<String, Object>(); jsonMap.put("policyId", event.getPolicyId()); jsonMap.put("streamId", event.getStreamId()); jsonMap.put("createBy", event.getCreatedBy()); jsonMap.put("createTime", event.getCreatedTime()); // data int size = event.getData().length; List<StreamColumn> columns = event.getSchema().getColumns(); for (int i = 0; i < size; i++) { if (columns.size() < i) { // redundant check to log inconsistency LOG.error(" stream event data have different lenght compare to column definition! "); } else { jsonMap.put(columns.get(i).getName(), event.getData()[i]); } } return JsonUtils.writeValueAsString(jsonMap); }
@Test public void testWriteValueAsString() { Map<String, Object> jsonMap = new HashMap<>(); jsonMap.put("policyId", "policyId"); jsonMap.put("streamId", "streamId"); jsonMap.put("createBy", "createBy"); jsonMap.put("createTime", "createTime"); Assert.assertEquals("{\"createBy\":\"createBy\",\"policyId\":\"policyId\",\"streamId\":\"streamId\",\"createTime\":\"createTime\"}", JsonUtils.writeValueAsString(jsonMap)); jsonMap = new HashMap<>(); Assert.assertEquals("{}", JsonUtils.writeValueAsString(jsonMap)); Assert.assertEquals("null", JsonUtils.writeValueAsString(null)); Assert.assertEquals("", JsonUtils.writeValueAsString(new Object())); } }
private static Pair<Long, String> createEntity(long base, String stream, int hostIndex) { // TODO : add randomization Entity e = new Entity(); e.colo = "LVS"; e.host = String.format(hostTemp, hostIndex); if (hostIndex < 3) { e.pool = "hadoop-eagle-prod"; } else { e.pool = "raptor-pool1"; } e.timestamp = base; e.metric = stream; e.value = 92.0; base = base + 1000; return Pair.of(base, JsonUtils.writeValueAsString(e)); }
private static Pair<Long, String> createLogEntity(AtomicLong base1, int hostIndex) { // TODO: add randomization LogEntity le = new LogEntity(); if (hostIndex < 3) { le.component = "NOVA"; le.host = "nova.000-" + hostIndex + ".datacenter.corp.com"; le.message = "RabbitMQ Exception - MQ not connectable!"; } else { le.component = "NEUTRON"; le.host = "neturon.000-" + (hostIndex - 3) + ".datacenter.corp.com"; le.message = "DNS Exception - Fail to connect to DNS!"; } le.instanceUuid = nextUuid; le.logLevel = "ERROR"; le.reqId = nextReqId; le.timestamp = base1.get(); base1.addAndGet(1000);// simply some interval. return Pair.of(base1.get(), JsonUtils.writeValueAsString(le)); }