private void checkResult(GenericServiceAPIResponseEntity result) throws Exception { if (!result.isSuccess()) { logger.error(result.getException()); throw new Exception("Entity creation fails going to EagleService"); } } }
private void deleteEntities(List<TopologyBaseAPIEntity> entities, String serviceName) { try { GenericServiceAPIResponseEntity response = client.delete(entities); if (!response.isSuccess()) { LOG.error("Got exception from eagle service: " + response.getException()); } else { LOG.info("Successfully delete {} entities for {}", entities.size(), serviceName); } } catch (Exception e) { LOG.error(e.getMessage(), e); } entities.clear(); }
private void writeEntities(List<TaggedLogAPIEntity> entities, DataType dataType, DataSource dataSource) { try { GenericServiceAPIResponseEntity response = client.create(entities); if (!response.isSuccess()) { LOG.error("Got exception from eagle service: " + response.getException()); } else { LOG.info("Successfully wrote {} items of {} for {}", entities.size(), dataType, dataSource); } } catch (Exception e) { LOG.error("cannot create {} entities", entities.size(), e); } entities.clear(); } }
public void flush() throws IOException, EagleServiceClientException { if(this.entityBucket.size() == 0 && LOG.isDebugEnabled()){ LOG.debug("No entities to flush"); return; } LOG.info("Writing "+this.entityBucket.size()+" entities"); GenericServiceAPIResponseEntity<String> response = this.client.create(this.entityBucket); if(!response.isSuccess()){ LOG.error("Got service exception: "+response.getException()); throw new IOException("Service exception"+response.getException()); }else{ this.entityBucket.clear(); } }
public void flush() throws IOException, EagleServiceClientException { if(this.entityBucket.size() == 0 && LOG.isDebugEnabled()){ LOG.debug("No entities to flush"); return; } LOG.info("Writing "+this.entityBucket.size()+" entities"); GenericServiceAPIResponseEntity<String> response = this.client.create(this.entityBucket); if(!response.isSuccess()){ LOG.error("Got service exception: "+response.getException()); throw new IOException("Service exception"+response.getException()); }else{ this.entityBucket.clear(); } }
public void emitMetric(GenericMetricEntity metricEntity) { entityBucket.add(metricEntity); if (entityBucket.size() < batchSize) { return; } try { GenericServiceAPIResponseEntity response = client.create(entityBucket); if (response.isSuccess()) { LOG.info("persist {} entities with the earliest time={}", entityBucket.size(), entityBucket.get(0).getTimestamp()); } else { LOG.error("Service side error: {}", response.getException()); } } catch (Exception e) { LOG.error(e.getMessage(), e); } finally { entityBucket.clear(); } }
@Override public <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> create(List<E> entities, String serviceName) throws IOException, EagleServiceClientException { checkNotNull(serviceName, "serviceName"); checkNotNull(entities, "entities"); final GenericServiceAPIResponseEntity<String> response; response = postEntitiesWithService(GENERIC_ENTITY_PATH, entities, serviceName); if (!response.isSuccess()) { LOG.error("Failed to create entities for service: " + serviceName); } return response; }
private Set<String> getSubQueueSet(String site, String parentQueue) throws IOException { GenericEntityServiceResource resource = new GenericEntityServiceResource(); String query = String.format("%s[@site=\"%s\" and @queue=\"%s\"]{*}", QUEUE_MAPPING_SERVICE_NAME, site, parentQueue); GenericServiceAPIResponseEntity<QueueStructureAPIEntity> responseEntity = resource.search(query, null, null, Integer.MAX_VALUE, null, false, false, 0L, 0, false, 0, null, false); if (!responseEntity.isSuccess() || responseEntity.getObj() == null) { throw new IOException(responseEntity.getException()); } Set<String> subQueues = new HashSet<>(); subQueues.add(parentQueue); subQueues.addAll(responseEntity.getObj().get(0).getAllSubQueues()); return subQueues; }
@Override public <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> create(List<E> entities, String serviceName) throws IOException,EagleServiceClientException { checkNotNull(serviceName,"serviceName"); checkNotNull(entities,"entities"); final GenericServiceAPIResponseEntity<String> response; response = postEntitiesWithService(GENERIC_ENTITY_PATH, entities, serviceName); if (!response.isSuccess()) { LOG.error("Failed to create entities for service: " + serviceName); } return response; }
private List<String> aggregateQuery(String query, String startTime, String endTime, String metricName) throws AttributeResolveException { List<String> result = new ArrayList<>(); GenericServiceAPIResponseEntity response = entityServiceResource.search(query, startTime, endTime, Integer.MAX_VALUE, null, false, false, 0, Integer.MAX_VALUE, true, 0, metricName, false); if (response.isSuccess()) { List objs = response.getObj(); for (Object item : objs) { // TODO: get keys as result throw new IllegalArgumentException("not implemented yet"); } } else { throw new AttributeResolveException(response.getException()); } return result; }
private List<JobExecutionAPIEntity> getRunningJobs(String site, long currentTime, String startTime, String endTime) throws Exception { GenericEntityServiceResource resource = new GenericEntityServiceResource(); String query = String.format("%s[@site=\"%s\" and @startTime<=%s and (@internalState=\"RUNNING\" or @endTime>%s)]{@jobId, @user, @queue, @allocatedMB}", MR_RUNNING_JOB_EXECUTION_SERVICE_NAME, site, currentTime, currentTime); GenericServiceAPIResponseEntity<JobExecutionAPIEntity> runningJobResponse = resource.search(query, startTime, endTime, Integer.MAX_VALUE, null, false, false, 0L, 0, false, 0, null, false); if (!runningJobResponse.isSuccess() || runningJobResponse.getObj() == null) { throw new IOException(runningJobResponse.getException()); } return runningJobResponse.getObj(); }
private List<org.apache.eagle.jpm.mr.historyentity.JobExecutionAPIEntity> getJobs(String site, long currentTime, String startTime, String endTime) throws Exception { GenericEntityServiceResource resource = new GenericEntityServiceResource(); String query = String.format("%s[@site=\"%s\" and @startTime<=%s and @endTime>%s]{@jobId}", MR_JOB_EXECUTION_SERVICE_NAME, site, currentTime, currentTime); GenericServiceAPIResponseEntity<org.apache.eagle.jpm.mr.historyentity.JobExecutionAPIEntity> response = resource.search(query, startTime, endTime, Integer.MAX_VALUE, null, false, false, 0L, 0, false, 0, null, false); if (!response.isSuccess() || response.getObj() == null) { throw new IOException(response.getException()); } return response.getObj(); }
private Map<String, Long> queryGroupByMetrics(String condition, long startTime, long endTime, int limit) { try { GenericServiceAPIResponseEntity response = client.search() .pageSize(Integer.MAX_VALUE) .query(condition) .startTime(startTime) .endTime(endTime).send(); if (!response.isSuccess()) { LOG.error(response.getException()); return null; } List<Map<List<String>, List<Double>>> result = response.getObj(); return parseQueryResult(result, limit); } catch (EagleServiceClientException e) { LOG.error(e.getMessage(), e); return new HashMap<>(); } }
@Test public void testAsyncSender() throws IOException, EagleServiceClientException, ExecutionException, InterruptedException { EagleServiceAsyncClient asyncClient = client.async(); Future<GenericServiceAPIResponseEntity<String>> future1 = asyncClient.create(Arrays.asList(newEntity())); GenericServiceAPIResponseEntity<String> response1 = future1.get(); Assert.assertTrue(response1.isSuccess()); Future<GenericServiceAPIResponseEntity<String>> future2 = asyncClient.update(Arrays.asList(newEntity())); GenericServiceAPIResponseEntity<String> response2 = future2.get(); Assert.assertTrue(response2.isSuccess()); Future<GenericServiceAPIResponseEntity<String>> future3 = asyncClient.delete(Arrays.asList(newEntity())); GenericServiceAPIResponseEntity<String> response3 = future3.get(); Assert.assertTrue(response3.isSuccess()); client.close(); }
@Test public void testGenericEntityServiceResourceSearchNullDataStorage() throws IllegalAccessException, InstantiationException, IOException, IllegalDataStorageTypeException { when(DataStorageManager.getDataStorageByEagleConfig()).thenReturn(null); GenericServiceAPIResponseEntity responseEntity = resources.client().resource("/entities/rowkey").queryParam("value", "test").queryParam("serviceName", "TestTimeSeriesAPIEntity").get(GenericServiceAPIResponseEntity.class); Assert.assertFalse(responseEntity.isSuccess()); Assert.assertEquals(null, responseEntity.getMeta()); Assert.assertEquals(null, responseEntity.getType()); Assert.assertEquals(null, responseEntity.getObj()); Assert.assertTrue(responseEntity.getException().startsWith("java.lang.Exception: org.apache.eagle.storage.exception.IllegalDataStorageException: data storage is null")); verify(dataStorage, never()).queryById(any(), any()); } }
@Test public void testGenericEntityServiceResourceSearchNullServiceName() throws IllegalAccessException, InstantiationException, IOException { GenericServiceAPIResponseEntity responseEntity = resources.client().resource("/entities/rowkey").queryParam("value", "test").get(GenericServiceAPIResponseEntity.class); Assert.assertFalse(responseEntity.isSuccess()); Assert.assertEquals(null, responseEntity.getMeta()); Assert.assertEquals(null, responseEntity.getType()); Assert.assertEquals(null, responseEntity.getObj()); Assert.assertTrue(responseEntity.getException().startsWith("java.lang.Exception: java.lang.IllegalArgumentException: serviceName is null")); verify(dataStorage, never()).queryById(any(), any()); }
@Test public void testSearch() throws EagleServiceClientException, IOException { GenericServiceAPIResponseEntity<TestTimeSeriesAPIEntity> response = client.search("TestTimeSeriesAPIEntity[]{*}").startTime(0).endTime(System.currentTimeMillis()+1000).pageSize(1000).send(); Assert.assertTrue(response.isSuccess()); GenericServiceAPIResponseEntity<Map> response2 = client.search("TestTimeSeriesAPIEntity[]<@cluster>{count}").startTime(0).endTime(System.currentTimeMillis()+1000).pageSize(1000).send(); Assert.assertTrue(response2.isSuccess()); GenericServiceAPIResponseEntity<GenericMetricEntity> response3 = client.search("GenericMetricService[@cluster = \"cluster4ut\" AND @datacenter = \"datacenter4ut\"]{*}").metricName("unit.test.metrics").startTime(0).endTime(System.currentTimeMillis()+1000).pageSize(1000).send(); Assert.assertTrue(response3.isSuccess()); }
@Test public void testGenericEntityServiceResourceupdateDatabaseNullDataStorage() throws IllegalDataStorageTypeException { when(DataStorageManager.getDataStorageByEagleConfig()).thenReturn(null); GenericServiceAPIResponseEntity responseEntity = genericEntityServiceResource.updateDatabase(null); Assert.assertFalse(responseEntity.isSuccess()); Assert.assertEquals(null, responseEntity.getMeta()); Assert.assertEquals(null, responseEntity.getType()); Assert.assertEquals(null, responseEntity.getObj()); Assert.assertTrue(responseEntity.getException().startsWith("org.apache.eagle.storage.exception.IllegalDataStorageException: Data storage is null")); }
@Test public void testGenericEntityServiceResourceSearchFalse() throws IllegalAccessException, InstantiationException, IOException { QueryResult<TestTimeSeriesAPIEntity> queryResult = new QueryResult<>(); queryResult.setSuccess(false); List<String> rowkeys = new ArrayList<>(); rowkeys.add("test"); EntityDefinition ed = EntityDefinitionManager.getEntityByServiceName("TestTimeSeriesAPIEntity"); when(dataStorage.queryById(rowkeys, ed)).thenReturn(queryResult); GenericServiceAPIResponseEntity responseEntity = resources.client().resource("/entities/rowkey").queryParam("value", "test").queryParam("serviceName", "TestTimeSeriesAPIEntity").get(GenericServiceAPIResponseEntity.class); Assert.assertFalse(responseEntity.isSuccess()); Assert.assertEquals(null, responseEntity.getMeta()); Assert.assertEquals(null, responseEntity.getType()); Assert.assertEquals(null, responseEntity.getObj()); Assert.assertEquals(null, responseEntity.getException()); verify(dataStorage).queryById(rowkeys, ed); }
@Test public void testGenericEntityServiceResourceupdateDatabaseFalse() throws IllegalDataStorageTypeException, IOException, IllegalAccessException, InstantiationException { TestTimeSeriesAPIEntity e = new TestTimeSeriesAPIEntity(); List<TestTimeSeriesAPIEntity> entities = new ArrayList<>(); entities.add(e); EntityDefinition ed = EntityDefinitionManager.getEntityByServiceName("TestTimeSeriesAPIEntity"); ModifyResult<String> modifyResult = new ModifyResult<>(); modifyResult.setSuccess(false); when(dataStorage.update(entities, ed)).thenReturn(modifyResult); GenericServiceAPIResponseEntity responseEntity = genericEntityServiceResource.updateDatabase(new UpdateStatement(entities, "TestTimeSeriesAPIEntity")); Assert.assertFalse(responseEntity.isSuccess()); Assert.assertEquals(null, responseEntity.getMeta()); Assert.assertEquals(null, responseEntity.getType()); Assert.assertEquals(null, responseEntity.getObj()); Assert.assertEquals(null, responseEntity.getException()); verify(dataStorage).update(entities, ed); }