@Override public GenericServiceAPIResponseEntity<String> call() throws Exception { return client.search(request); } });
@Override public GenericServiceAPIResponseEntity<String> call() throws Exception { return client.search(request); } });
public <T> GenericServiceAPIResponseEntity<T> send() throws EagleServiceClientException { return client.search(this.request); } }
public <T> GenericServiceAPIResponseEntity<T> send() throws EagleServiceClientException { return client.search(this.request); } }
private long getServiceLatestUpdateTime(String serviceName, IEagleServiceClient client) throws Exception { String query = String.format("%s[@site=\"%s\"]<@site>{max(lastUpdateTime)}", serviceName, topologyCheckAppConfig.dataExtractorConfig.site); GenericServiceAPIResponseEntity response = client .search(query) .pageSize(10) .send(); List<Map<List<String>, List<Double>>> results = response.getObj(); if (results.size() == 0) { return Long.MAX_VALUE; } long currentProcessTimeStamp = results.get(0).get("value").get(0).longValue(); return currentProcessTimeStamp; } }
private List<HiveResourceSensitivityAPIEntity> load(JobDataMap jobDataMap) throws Exception { Map<String, Object> map = (Map<String,Object>)jobDataMap.get(EagleConfigConstants.EAGLE_SERVICE); String eagleServiceHost = (String)map.get(EagleConfigConstants.HOST); Integer eagleServicePort = Integer.parseInt(map.get(EagleConfigConstants.PORT).toString()); String username = map.containsKey(EagleConfigConstants.USERNAME) ? (String)map.get(EagleConfigConstants.USERNAME) : null; String password = map.containsKey(EagleConfigConstants.PASSWORD) ? (String)map.get(EagleConfigConstants.PASSWORD) : null; // load from eagle database LOG.info("Load hive resource sensitivity information from eagle service " + eagleServiceHost + ":" + eagleServicePort); IEagleServiceClient client = new EagleServiceClientImpl(eagleServiceHost, eagleServicePort, username, password); String query = "HiveResourceSensitivityService[]{*}"; GenericServiceAPIResponseEntity<HiveResourceSensitivityAPIEntity> response = client.search().pageSize(Integer.MAX_VALUE).query(query).send(); client.close(); if (response.getException() != null) throw new IllegalStateException(response.getException()); return response.getObj(); } }
@Override public List<GenericAuditEntity> findSiteAudit(String site) throws Exception { try { IEagleServiceClient client = new EagleServiceClientImpl(connector); String query = AuditConstants.AUDIT_SERVICE_ENDPOINT + "[@serviceName=\"AlertDataSourceService\" AND @site=\"" + site + "\"]{*}"; GenericServiceAPIResponseEntity<GenericAuditEntity> response = client.search().startTime(0).endTime(10 * DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).query(query).send(); client.close(); if (response.getException() != null) { throw new Exception("Exception in querying eagle service: " + response.getException()); } return response.getObj(); } catch (Exception exception) { LOG.error("Exception in retrieving audit entry: " + exception); throw new IllegalStateException(exception); } }
@Override public List<GenericAuditEntity> findUserServiceAudit(String userID) throws Exception { try { IEagleServiceClient client = new EagleServiceClientImpl(connector); String query = AuditConstants.AUDIT_SERVICE_ENDPOINT + "[@userID=\"" + userID + "\"]{*}"; GenericServiceAPIResponseEntity<GenericAuditEntity> response = client.search().startTime(0).endTime(10 * DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).query(query).send(); client.close(); if (response.getException() != null) { throw new Exception("Exception in querying eagle service: " + response.getException()); } return response.getObj(); } catch (Exception exception) { LOG.error("Exception in retrieving audit entry: " + exception); throw new IllegalStateException(exception); } }
@Override public List<GenericAuditEntity> findPolicyAudit(String site, String application) throws Exception { try { IEagleServiceClient client = new EagleServiceClientImpl(connector); String query = AuditConstants.AUDIT_SERVICE_ENDPOINT + "[@serviceName=\"AlertDefinitionService\" AND @site=\"" + site + "\" AND @application=\"" + application + "\"]{*}"; GenericServiceAPIResponseEntity<GenericAuditEntity> response = client.search().startTime(0).endTime(10 * DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).query(query).send(); client.close(); if (response.getException() != null) { throw new Exception("Exception in querying eagle service: " + response.getException()); } return response.getObj(); } catch (Exception exception) { LOG.error("Exception in retrieving audit entry: " + exception); throw new IllegalStateException(exception); } }
@Override public List<GenericAuditEntity> findDataSourceAudit(String application) throws Exception { try { IEagleServiceClient client = new EagleServiceClientImpl(connector); String query = AuditConstants.AUDIT_SERVICE_ENDPOINT + "[@serviceName=\"AlertDataSourceService\" AND @application=\"" + application + "\"]{*}"; GenericServiceAPIResponseEntity<GenericAuditEntity> response = client.search().startTime(0).endTime(10 * DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).query(query).send(); client.close(); if (response.getException() != null) { throw new Exception("Exception in querying eagle service: " + response.getException()); } return response.getObj(); } catch (Exception exception) { LOG.error("Exception in retrieving audit entry: " + exception); throw new IllegalStateException(exception); } }
@Override public List<GenericAuditEntity> findServiceAuditByUser(String serviceName, String userID) throws Exception { try { IEagleServiceClient client = new EagleServiceClientImpl(connector); String query = AuditConstants.AUDIT_SERVICE_ENDPOINT + "[@serviceName=\"" + serviceName + "\" AND @userID=\"" + userID + "\"]{*}"; GenericServiceAPIResponseEntity<GenericAuditEntity> response = client.search().startTime(0).endTime(10 * DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).query(query).send(); client.close(); if (response.getException() != null) { throw new Exception("Exception in querying eagle service: " + response.getException()); } return response.getObj(); } catch (Exception exception) { LOG.error("Exception in retrieving audit entry: " + exception); throw new IllegalStateException(exception); } }
@Override public List<GenericAuditEntity> findServiceAuditByAction(String serviceName, String action) throws Exception { try { IEagleServiceClient client = new EagleServiceClientImpl(connector); String query = AuditConstants.AUDIT_SERVICE_ENDPOINT + "[@serviceName=\"" + serviceName + "\" AND @actionTaken=\"" + action + "\"]{*}"; GenericServiceAPIResponseEntity<GenericAuditEntity> response = client.search().startTime(0).endTime(10 * DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).query(query).send(); client.close(); if (response.getException() != null) { throw new Exception("Exception in querying eagle service: " + response.getException()); } return response.getObj(); } catch (Exception exception) { LOG.error("Exception in retrieving audit entry: " + exception); throw new IllegalStateException(exception); } }
@Override public List<GenericAuditEntity> findServiceAudit(String serviceName) throws Exception { try { IEagleServiceClient client = new EagleServiceClientImpl(connector); String query = AuditConstants.AUDIT_SERVICE_ENDPOINT + "[@serviceName=\"" + serviceName + "\"]{*}"; GenericServiceAPIResponseEntity<GenericAuditEntity> response = client.search().startTime(0).endTime(10 * DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).query(query).send(); client.close(); if (response.getException() != null) { throw new Exception("Exception in querying eagle service: " + response.getException()); } return response.getObj(); } catch (Exception exception) { LOG.error("Exception in retrieving audit entry: " + exception); throw new IllegalStateException(exception); } }
@Override public List<GenericAuditEntity> findUserServiceAuditByAction(String userID, String action) throws Exception { try { IEagleServiceClient client = new EagleServiceClientImpl(connector); String query = AuditConstants.AUDIT_SERVICE_ENDPOINT + "[@userID=\"" + userID + "\" AND @actionTaken=\"" + action + "\"]{*}"; GenericServiceAPIResponseEntity<GenericAuditEntity> response = client.search().startTime(0).endTime(10 * DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).query(query).send(); client.close(); if (response.getException() != null) { throw new Exception("Exception in querying eagle service: " + response.getException()); } return response.getObj(); } catch (Exception exception) { LOG.error("Exception in retrieving audit entry: " + exception); throw new IllegalStateException(exception); } } }
@Override public List<HdfsUserCommandPatternEntity> findAllPatterns() throws Exception{ try { IEagleServiceClient client = new EagleServiceClientImpl(this.connector); String query = HdfsUserCommandPatternEntity.HDFS_USER_COMMAND_PATTERN_SERVICE + "[]{*}"; GenericServiceAPIResponseEntity<HdfsUserCommandPatternEntity> response = client.search() .pageSize(Integer.MAX_VALUE) .query(query) .send(); client.close(); if (response.getException() != null) { throw new Exception("Got an exception when query eagle service: " + response.getException()); } List<HdfsUserCommandPatternEntity> list = response.getObj(); return list; } catch (Exception ex) { LOG.error("Got an exception when query HdfsUserCommandPattern service", ex); throw ex; } }
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 testQuery() throws Exception { IEagleServiceClient client = new EagleServiceClientImpl("localhost", 9090); String site = "sandbox"; String query = "AuditService" + "[@serviceName=\"AlertDataSourceService\" AND @site=\"" + site + "\"]{*}"; SearchRequestBuilder searchRequestBuilder = client.search().startTime(0).endTime(10 * DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).query(query); Field requestField = SearchRequestBuilder.class.getDeclaredField("request"); requestField.setAccessible(true); EagleServiceSingleEntityQueryRequest request = (EagleServiceSingleEntityQueryRequest)requestField.get(searchRequestBuilder); String expected = "query=AuditService%5B%40serviceName%3D%22AlertDataSourceService%22+AND+%40site%3D%22sandbox%22%5D%7B*%7D&pageSize=2147483647&startTime=1970-01-01%2000:00:00&endTime=1970-01-11%2000:00:00&treeAgg=false"; Assert.assertEquals(expected, request.getQueryParameterString()); } }
@Test public void testQuery() throws Exception { EagleServiceConnector connector = mock(EagleServiceConnector.class); IEagleServiceClient client = new EagleServiceClientImpl(connector); String site = "sandbox"; String query = "AuditService" + "[@serviceName=\"AlertDataSourceService\" AND @site=\"" + site + "\"]{*}"; SearchRequestBuilder searchRequestBuilder = client.search().startRowkey("rowkey").startTime(0).endTime(10 * DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).filterIfMissing(true).metricName("metric").query(query); Field requestField = SearchRequestBuilder.class.getDeclaredField("request"); requestField.setAccessible(true); EagleServiceSingleEntityQueryRequest request = (EagleServiceSingleEntityQueryRequest) requestField.get(searchRequestBuilder); String expected = "query=AuditService%5B%40serviceName%3D%22AlertDataSourceService%22+AND+%40site%3D%22sandbox%22%5D%7B*%7D&startRowkey=rowkey&pageSize=2147483647&startTime=1970-01-01%2000:00:00&endTime=1970-01-11%2000:00:00&treeAgg=false&metricName=metric&filterIfMissing=true"; Assert.assertEquals(expected, request.getQueryParameterString()); } }
@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()); }
/** * Just compiling passed is ok */ //@Test @SuppressWarnings("unused") public void testCreate() throws IOException, EagleServiceClientException, IllegalAccessException, InstantiationException { EntityDefinition entityDefinition = EntityDefinitionManager.getEntityDefinitionByEntityClass(GenericMetricEntity.class); hbase.createTable(entityDefinition.getTable(), entityDefinition.getColumnFamily()); client = new EagleServiceClientImpl("localhost", EagleConfigFactory.load().getServicePort()); List<GenericMetricEntity> metricEntityList = new ArrayList<GenericMetricEntity>(); GenericServiceAPIResponseEntity<String> unTypedResponse = client.create(metricEntityList); GenericServiceAPIResponseEntity<String> weakTypedResponse = client.create(metricEntityList,GenericMetricEntity.GENERIC_METRIC_SERVICE); GenericServiceAPIResponseEntity<String> strongTypedResponse = client.create(metricEntityList,GenericMetricEntity.class); GenericServiceAPIResponseEntity<GenericMetricEntity> weakTypedSearchResponse = client.search("").send(); if(weakTypedSearchResponse!=null) { Class<GenericMetricEntity> typedClazz = weakTypedSearchResponse.getType(); List<GenericMetricEntity> typedEntities = weakTypedSearchResponse.getObj(); } }