/** * it is allowed that user can register their own entity definition * * @param entityDef entity definition * @throws IllegalArgumentException */ public static void registerEntity(EntityDefinition entityDef) { registerEntity(entityDef.getService(), entityDef); }
/** * it is allowed that user can register their own entity definition * @param entityDef entity definition * @throws IllegalArgumentException */ public static void registerEntity(EntityDefinition entityDef) { registerEntity(entityDef.getService(), entityDef); }
/** * Method to be invoked for firing audit event. * @param operation: HBase operation. Values like CREATE/UPDATE/DELETE. * @param entities: List of entities used in HBase operation. * @param encodedRowKeys: List of encodededRowKeys returned from successful HBase operation. To be passed only from deletebyID method. * @param entityDefinition: EntityDefinition object used in the HBaseOperation. */ public void auditOperation(String operation, List<? extends TaggedLogAPIEntity> entities, List<String> encodedRowKeys, EntityDefinition entityDefinition) { if (isAuditingRequired(entityDefinition.getService())) { List<GenericAuditEntity> auditEntities = buildAuditEntities(operation, entities, encodedRowKeys, entityDefinition); if (null != auditEntities && 0 != auditEntities.size()) auditSupport.fireAudit(entityDefinition.getService(), auditEntities); } }
/** * Method to be invoked for firing audit event. * * @param operation HBase operation. Values like CREATE/UPDATE/DELETE. * @param entities List of entities used in HBase operation. * @param encodedRowKeys List of encodededRowKeys returned from successful HBase operation. To be passed only from deletebyID method. * @param entityDefinition EntityDefinition object used in the HBaseOperation. */ public void auditOperation(String operation, List<? extends TaggedLogAPIEntity> entities, List<String> encodedRowKeys, EntityDefinition entityDefinition) { if (isAuditingRequired(entityDefinition.getService())) { List<GenericAuditEntity> auditEntities = buildAuditEntities(operation, entities, encodedRowKeys, entityDefinition); if (null != auditEntities && 0 != auditEntities.size()) { auditSupport.fireAudit(entityDefinition.getService(), auditEntities); } } }
private static void checkPrefix(EntityDefinition entityDef) { final Integer entityPrefixHashcode = entityDef.getPrefix().hashCode(); if (entityPrefixMap.containsKey(entityDef.getTable())) { final Map<Integer, EntityDefinition> entityHashMap = entityPrefixMap.get(entityDef.getTable()); if (entityHashMap.containsKey(entityPrefixHashcode) && (!entityDef.equals(entityHashMap.get(entityPrefixHashcode)))) { throw new IllegalArgumentException("Failed to register entity " + entityDef.getClass().getName() + ", because of the prefix hash code conflict! The entity prefix " + entityDef.getPrefix() + " has already been registered by entity service " + entityHashMap.get(entityPrefixHashcode).getService()); } final IndexDefinition[] indexes = entityDef.getIndexes(); if (indexes != null) { for (IndexDefinition index : indexes) { final Integer indexPrefixHashcode = index.getIndexPrefix().hashCode(); if (entityHashMap.containsKey(indexPrefixHashcode)) { throw new IllegalArgumentException("Failed to register entity " + entityDef.getClass().getName() + ", because of the prefix hash code conflict! The index prefix " + index.getIndexPrefix() + " has already been registered by entity " + entityHashMap.get(indexPrefixHashcode).getService()); } final Map<Integer, IndexDefinition> indexHashMap = indexPrefixMap.get(entityDef.getTable()); if (indexHashMap != null && indexHashMap.containsKey(indexPrefixHashcode) && (!index.equals(indexHashMap.get(indexPrefixHashcode)))) { throw new IllegalArgumentException("Failed to register entity " + entityDef.getClass().getName() + ", because of the prefix hash code conflict! The index prefix " + index.getIndexPrefix() + " has already been registered by entity " + indexHashMap.get(indexPrefixHashcode).getEntityDefinition().getService()); } } } } }
protected <E extends TaggedLogAPIEntity> Map<String,List<E>> groupEntitiesByService(List<E> entities) throws EagleServiceClientException { Map<String,List<E>> serviceEntityMap = new HashMap<String, List<E>>(); if(LOG.isDebugEnabled()) LOG.debug("Grouping entities by service name"); for(E entity: entities){ if(entity == null) { LOG.warn("Skip null entity"); continue; } try { EntityDefinition entityDefinition = EntityDefinitionManager.getEntityDefinitionByEntityClass(entity.getClass()); if(entityDefinition == null){ throw new EagleServiceClientException("Failed to find entity definition of class: "+entity.getClass()); } String serviceName = entityDefinition.getService(); List<E> bucket = serviceEntityMap.get(serviceName); if(bucket == null){ bucket = new LinkedList<E>(); serviceEntityMap.put(serviceName, bucket); } bucket.add(entity); } catch (InstantiationException e) { throw new EagleServiceClientException(e); } catch (IllegalAccessException e) { throw new EagleServiceClientException(e); } } return serviceEntityMap; }
protected <E extends TaggedLogAPIEntity> Map<String,List<E>> groupEntitiesByService(List<E> entities) throws EagleServiceClientException { Map<String,List<E>> serviceEntityMap = new HashMap<String, List<E>>(); if(LOG.isDebugEnabled()) LOG.debug("Grouping entities by service name"); for(E entity: entities) { if(entity == null) { LOG.warn("Skip null entity"); continue; } try { EntityDefinition entityDefinition = EntityDefinitionManager.getEntityDefinitionByEntityClass(entity.getClass()); if(entityDefinition == null){ throw new EagleServiceClientException("Failed to find entity definition of class: "+entity.getClass()); } String serviceName = entityDefinition.getService(); List<E> bucket = serviceEntityMap.get(serviceName); if(bucket == null){ bucket = new LinkedList<E>(); serviceEntityMap.put(serviceName, bucket); } bucket.add(entity); } catch (InstantiationException e) { throw new EagleServiceClientException(e); } catch (IllegalAccessException e) { throw new EagleServiceClientException(e); } } return serviceEntityMap; }
Class<? extends TaggedLogAPIEntity> clazz = ed.getEntityClass(); if (clazz == null) { throw new NullPointerException("Entity class of service " + ed.getService() + " is null");
protected <E extends TaggedLogAPIEntity> String getServiceNameByClass(Class<E> entityClass) throws EagleServiceClientException { EntityDefinition entityDefinition = null; try { entityDefinition = EntityDefinitionManager.getEntityDefinitionByEntityClass(entityClass); } catch (InstantiationException e) { throw new EagleServiceClientException(e); } catch (IllegalAccessException e) { throw new EagleServiceClientException(e); } if(entityDefinition == null){ throw new EagleServiceClientException("cannot find entity definition of class "+entityClass); } return entityDefinition.getService(); }
protected <E extends TaggedLogAPIEntity> String getServiceNameByClass(Class<E> entityClass) throws EagleServiceClientException { EntityDefinition entityDefinition = null; try { entityDefinition = EntityDefinitionManager.getEntityDefinitionByEntityClass(entityClass); } catch (InstantiationException e) { throw new EagleServiceClientException(e); } catch (IllegalAccessException e) { throw new EagleServiceClientException(e); } if(entityDefinition == null){ throw new EagleServiceClientException("cannot find entity definition of class "+entityClass); } return entityDefinition.getService(); }
@Override public AggregateResult aggregate(EntityDefinition entityDefinition, Scan scan, List<String> groupbyFields, List<byte[]> aggregateFuncTypes, List<String> aggregatedFields) throws IOException { checkNotNull(entityDefinition, "entityDefinition"); String serviceName = entityDefinition.getService(); LOG.info(this.getLogHeader() + " raw group aggregate on service: " + serviceName + " by: " + groupbyFields + " func: " + AggregateFunctionType.fromBytesList(aggregateFuncTypes) + " fields: " + aggregatedFields); if (LOG.isDebugEnabled()) { LOG.debug("SCAN: " + scan.toJSON()); } final long startTimestamp = System.currentTimeMillis(); final RawAggregator aggregator = new RawAggregator(groupbyFields, AggregateFunctionType.fromBytesList(aggregateFuncTypes), aggregatedFields, entityDefinition); InternalReadReport report = this.asyncStreamRead(entityDefinition, scan, aggregator); List<GroupbyKeyValue> keyValues = aggregator.getGroupbyKeyValues(); AggregateResult result = new AggregateResult(); result.setKeyValues(keyValues); result.setStartTimestamp(report.getStartTimestamp()); result.setStopTimestamp(report.getStopTimestamp()); long _stop = System.currentTimeMillis(); LOG.info(String.format("%s: scan = %d rows, group = %d keys, startTime = %d, endTime = %d, spend = %d ms", this.getLogHeader(), report.getCounter(), keyValues.size(), report.getStartTimestamp(), report.getStopTimestamp(), (_stop - startTimestamp))); return result; }
filterCondition.add("@" + attributeName + "~= \".*" + request.getQuery() + ".*\""); String query = entityDefinition.getService() + "[" + StringUtils.join(filterCondition, " AND ") + "]<@" + attributeName + ">{count}"; return aggregateQuery(query, DateTimeUtil.millisecondsToHumanDateWithSeconds(0), DateTimeUtil.millisecondsToHumanDateWithSeconds(System.currentTimeMillis()), request.getMetricName());
String serviceName = entityDefinition.getService(); LOG.info(this.getLogHeader() +" raw group aggregate on service: " + serviceName + " by: " + groupbyFields + " func: " + AggregateFunctionType.fromBytesList(aggregateFuncTypes) + " fields: " + aggregatedFields); if(LOG.isDebugEnabled()) LOG.debug("SCAN: "+scan.toJSON());
List<byte[]> aggregateFuncTypes, List<String> aggregatedFields, long startTime, long endTime, long intervalMin) throws IOException { checkNotNull(entityDefinition, "entityDefinition"); String serviceName = entityDefinition.getService(); LOG.info(this.getLogHeader() + " time series group aggregate on service: " + serviceName + " by: " + groupbyFields + " func: " + AggregateFunctionType.fromBytesList(aggregateFuncTypes)
private List<String> prepareMetricEntity(long startTime,int count) throws Exception { List<GenericMetricEntity> list = new ArrayList<GenericMetricEntity>(); EntityDefinition ed = EntityDefinitionManager.getEntityDefinitionByEntityClass(GenericMetricEntity.class); double[] value = new double[60]; for(int i=0;i<60;i++){ value[i] = 1; } for(int i=0;i<count;i++){ GenericMetricEntity e = new GenericMetricEntity(); e.setTimestamp(startTime+i*3600*1000); e.setValue(value); e.setTags(new HashMap<String, String>()); e.getTags().put("cluster", "test4UT"); e.getTags().put("datacenter", "dc1"); e.getTags().put("index", ""+i); e.getTags().put("jobId", "job_"+System.currentTimeMillis()); e.setPrefix("eagle.metric.test"); list.add(e); } GenericEntityWriter writer = new GenericEntityWriter(ed.getService()); List<String> result = writer.write(list); return result; }
public void setEntityDefinition(EntityDefinition ed) { this.entityClass = ed.getEntityClass(); this.table = ed.getTable(); this.columnFamily = ed.getColumnFamily(); this.prefix = ed.getPrefix(); this.service = ed.getService(); this.partitions = ed.getPartitions(); this.displayNameMap = ed.getDisplayNameMap(); this.qualifierGetterMap = ed.getQualifierGetterMap(); this.qualifierNameMap = ed.getQualifierNameMap(); this.isTimeSeries = ed.isTimeSeries(); this.metricDefinition = ed.metricDefinition; this.indexes = ed.getIndexes(); }
public void setEntityDefinition(EntityDefinition ed){ this.entityClass = ed.getEntityClass(); this.table = ed.getTable(); this.columnFamily = ed.getColumnFamily(); this.prefix = ed.getPrefix(); this.service = ed.getService(); this.partitions = ed.getPartitions(); this.displayNameMap = ed.getDisplayNameMap(); this.qualifierGetterMap = ed.getQualifierGetterMap(); this.qualifierNameMap = ed.getQualifierNameMap(); this.isTimeSeries = ed.isTimeSeries(); this.metricDefinition = ed.metricDefinition; this.indexes = ed.getIndexes(); }
GenericEntityWriter writer = new GenericEntityWriter(ed.getService()); LOG.info("Writing " + list.size() + " TestLogAPIEntity entities"); List<String> result = writer.write(list);
private List<String> prepareData(int count) throws Exception { List<TestTimeSeriesAPIEntity> list = new ArrayList<TestTimeSeriesAPIEntity>(); if (ed == null) { EntityDefinitionManager.registerEntity(TestTimeSeriesAPIEntity.class); ed = EntityDefinitionManager.getEntityDefinitionByEntityClass(TestTimeSeriesAPIEntity.class); } for (int i = 0; i < count; i++) { TestTimeSeriesAPIEntity e = new TestTimeSeriesAPIEntity(); e.setTimestamp(System.currentTimeMillis()); e.setField1(1); e.setField2(2); e.setField3(3); e.setField4(4L); e.setField5(5.0); e.setField6(5.0); e.setField7("7"); e.setTags(new HashMap<String, String>()); e.getTags().put("cluster", "test4UT"); e.getTags().put("datacenter", "dc1"); e.getTags().put("index", "" + i); e.getTags().put("jobId", "job_" + System.currentTimeMillis()); list.add(e); } GenericEntityWriter writer = new GenericEntityWriter(ed.getService()); List<String> result = writer.write(list); return result; }
@SuppressWarnings("unused") private List<String> prepareTestEntity(int count) throws Exception { List<TestTimeSeriesAPIEntity> list = new ArrayList<TestTimeSeriesAPIEntity>(); EntityDefinition ed = EntityDefinitionManager.getEntityDefinitionByEntityClass(TestTimeSeriesAPIEntity.class); if (ed == null) { EntityDefinitionManager.registerEntity(TestTimeSeriesAPIEntity.class); ed = EntityDefinitionManager.getEntityDefinitionByEntityClass(TestTimeSeriesAPIEntity.class); } for(int i=0;i<count;i++){ TestTimeSeriesAPIEntity e = new TestTimeSeriesAPIEntity(); e.setTimestamp(System.currentTimeMillis()); e.setField1(1); e.setField2(2); e.setField3(3); e.setField4(4L); e.setField5(5.0); e.setField6(5.0); e.setField7("7"); e.setTags(new HashMap<String, String>()); e.getTags().put("cluster", "test4UT"); e.getTags().put("datacenter", "dc1"); e.getTags().put("index", ""+i); e.getTags().put("jobId", "job_"+System.currentTimeMillis()); list.add(e); } GenericEntityWriter writer = new GenericEntityWriter(ed.getService()); List<String> result = writer.write(list); return result; }