Return-Path: X-Original-To: apmail-eagle-commits-archive@minotaur.apache.org Delivered-To: apmail-eagle-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 87DF0185BE for ; Thu, 19 Nov 2015 10:47:47 +0000 (UTC) Received: (qmail 34504 invoked by uid 500); 19 Nov 2015 10:47:47 -0000 Delivered-To: apmail-eagle-commits-archive@eagle.apache.org Received: (qmail 34480 invoked by uid 500); 19 Nov 2015 10:47:47 -0000 Mailing-List: contact commits-help@eagle.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@eagle.incubator.apache.org Delivered-To: mailing list commits@eagle.incubator.apache.org Received: (qmail 34467 invoked by uid 99); 19 Nov 2015 10:47:47 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Nov 2015 10:47:47 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id CB2BEC0EC7 for ; Thu, 19 Nov 2015 10:47:46 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.771 X-Spam-Level: * X-Spam-Status: No, score=1.771 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id TD8h3ZYd-AiA for ; Thu, 19 Nov 2015 10:47:26 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with SMTP id 7D39A24E6A for ; Thu, 19 Nov 2015 10:47:12 +0000 (UTC) Received: (qmail 31970 invoked by uid 99); 19 Nov 2015 10:47:09 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Nov 2015 10:47:09 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E59E5E17D0; Thu, 19 Nov 2015 10:47:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: hao@apache.org To: commits@eagle.incubator.apache.org Date: Thu, 19 Nov 2015 10:47:30 -0000 Message-Id: In-Reply-To: <52adcae0110e43338593830e27f8f2fb@git.apache.org> References: <52adcae0110e43338593830e27f8f2fb@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [23/55] [abbrv] [partial] incubator-eagle git commit: [EAGLE-46] Rename package name as "org.apache.eagle" http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/base/taggedlog/TaggedLogAPIEntity.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/base/taggedlog/TaggedLogAPIEntity.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/base/taggedlog/TaggedLogAPIEntity.java deleted file mode 100755 index 3dd2ba3..0000000 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/base/taggedlog/TaggedLogAPIEntity.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.log.base.taggedlog; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.Serializable; -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.codehaus.jackson.JsonFactory; -import org.codehaus.jackson.JsonGenerator; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.SerializerProvider; -import org.codehaus.jackson.map.annotate.JsonFilter; -import org.codehaus.jackson.map.ser.BeanPropertyWriter; -import org.codehaus.jackson.map.ser.FilterProvider; -import org.codehaus.jackson.map.ser.impl.SimpleBeanPropertyFilter; -import org.codehaus.jackson.map.ser.impl.SimpleFilterProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import eagle.log.entity.meta.EntityDefinitionManager; -import eagle.common.DateTimeUtil; - -/** - * rowkey: prefix + timestamp + tagNameValues - * as of now, all tags will be persisted as a column in hbase table - * tag name is column qualifier name - * tag value is column value - */ -@JsonFilter(TaggedLogAPIEntity.PropertyBeanFilterName) -public class TaggedLogAPIEntity implements PropertyChangeListener, Serializable{ - private static final Logger LOG = LoggerFactory.getLogger(TaggedLogAPIEntity.class); - private String prefix; - private long timestamp; - private Map tags; - - public void setExp(Map exp) { - this.exp = exp; - } - - public Map getExp() { - return this.exp; - } - - /** - * Extra dynamic attributes. - * TODO: can we move exp, _serializeAlias, _serializeVerbose to a wrapper class? - */ - private Map exp; - - private String encodedRowkey; - // track what qualifiers are changed - private Set _modifiedProperties = new HashSet(); - protected PropertyChangeSupport _pcs = new PropertyChangeSupport(this); - - - public Map getSerializeAlias() { - return _serializeAlias; - } - - public void setSerializeAlias(Map _serializeAlias) { - this._serializeAlias = _serializeAlias; - } - - private Map _serializeAlias = null; - - public boolean isSerializeVerbose() { - return _serializeVerbose; - } - - public void setSerializeVerbose(boolean _serializeVerbose) { - this._serializeVerbose = _serializeVerbose; - } - - private boolean _serializeVerbose = true; - - public TaggedLogAPIEntity(){ - _pcs.addPropertyChangeListener(this); - } - - public String getPrefix() { - return prefix; - } - public void setPrefix(String prefix) { - this.prefix = prefix; - } - public long getTimestamp() { - return timestamp; - } - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } - public Map getTags() { - return tags; - } - public void setTags(Map tags) { - this.tags = tags; - } - public String getEncodedRowkey() { - return encodedRowkey; - } - public void setEncodedRowkey(String encodedRowkey) { - this.encodedRowkey = encodedRowkey; - } - - protected void valueChanged(String fieldModified){ - _pcs.firePropertyChange(fieldModified, null, null); - } - - public void propertyChange(PropertyChangeEvent evt) { - _modifiedProperties.add(evt.getPropertyName()); - } - - public Set modifiedQualifiers(){ - return this._modifiedProperties; - } - - public String toString(){ - StringBuffer sb = new StringBuffer(); - sb.append("prefix:"); - sb.append(prefix); - sb.append(", timestamp:"); - sb.append(timestamp); - sb.append(", humanReadableDate:"); - sb.append(DateTimeUtil.millisecondsToHumanDateWithMilliseconds(timestamp)); - sb.append(", tags: "); - if(tags != null){ - for(Map.Entry entry : tags.entrySet()){ - sb.append(entry.toString()); - sb.append(","); - } - } - sb.append(", encodedRowkey:"); - sb.append(encodedRowkey); - return sb.toString(); - } - - private static Set getPropertyNames(){ - if(_propertyNames == null) { - Field[] fields = TaggedLogAPIEntity.class.getDeclaredFields(); - Set fieldName = new HashSet(); - for (Field f : fields) fieldName.add(f.getName()); - _propertyNames = fieldName; - } - return _propertyNames; - } - - private static class BeanPropertyFilter extends SimpleBeanPropertyFilter { - private final static String prefix = "prefix"; - private final static String encodedRowkey = "encodedRowkey"; - private final static String exp = "exp"; - private final static String timestamp = "timestamp"; - @SuppressWarnings("serial") - private final static Set verboseFields = new HashSet(){{ - add(prefix); - add(encodedRowkey); - }}; - - @Override - public void serializeAsField(Object bean, JsonGenerator jgen, SerializerProvider provider, BeanPropertyWriter writer) throws Exception { - if(bean instanceof TaggedLogAPIEntity){ - TaggedLogAPIEntity entity = (TaggedLogAPIEntity) bean; - Set modified = entity.modifiedQualifiers(); - Set basePropertyNames = getPropertyNames(); - String writerName = writer.getName(); - if(modified.contains(writerName) || basePropertyNames.contains(writerName)){ - if((!entity.isSerializeVerbose() && verboseFields.contains(writerName))|| // skip verbose fields - (timestamp.equals(writerName) && !EntityDefinitionManager.isTimeSeries(entity.getClass())) // skip timestamp for non-timeseries entity - ){ - // log skip - if(LOG.isDebugEnabled()) LOG.debug("skip field"); - }else{ - // if serializeAlias is not null and exp is not null - if (exp.equals(writerName) && entity.getSerializeAlias()!=null && entity.getExp()!=null) { - Map _exp = new HashMap(); - for (Map.Entry entry : entity.getExp().entrySet()) { - String alias = entity.getSerializeAlias().get(entry.getKey()); - if (alias != null) { - _exp.put(alias, entry.getValue()); - } else { - _exp.put(entry.getKey(), entry.getValue()); - } - } - entity.setExp(_exp); - } - // write included field into serialized json output - writer.serializeAsField(bean, jgen, provider); - } - } - }else{ - writer.serializeAsField(bean, jgen, provider); - } - } - } - - public static FilterProvider getFilterProvider(){ - if(_filterProvider == null){ - SimpleFilterProvider _provider = new SimpleFilterProvider(); - _provider.addFilter(PropertyBeanFilterName,new BeanPropertyFilter()); - _filterProvider = _provider; - } - return _filterProvider; - } - - ////////////////////////////////////// - // Static fields - ////////////////////////////////////// - private static Set _propertyNames = null; - private static FilterProvider _filterProvider = null; - final static String PropertyBeanFilterName = "TaggedLogPropertyBeanFilter"; - - public static ObjectMapper buildObjectMapper(){ - final JsonFactory factory = new JsonFactory(); - final ObjectMapper mapper = new ObjectMapper(factory); - mapper.setFilters(TaggedLogAPIEntity.getFilterProvider()); - return mapper; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/base/taggedlog/TaggedLogObjectMapper.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/base/taggedlog/TaggedLogObjectMapper.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/base/taggedlog/TaggedLogObjectMapper.java deleted file mode 100644 index bebcabc..0000000 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/base/taggedlog/TaggedLogObjectMapper.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.log.base.taggedlog; - -import java.util.Map; - -public interface TaggedLogObjectMapper { - /** - * when read, business logic should convert schema-less key/value into business object based on its own schema - * @param entity - * @param qualifierValues - */ - public void populateQualifierValues(TaggedLogAPIEntity entity, Map qualifierValues); - - /** - * when write, business logic should convert business object to schema-less key value - * @param entity - * @return - */ - public Map createQualifierValues(TaggedLogAPIEntity entity); -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/AbstractHBaseLogReader.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/AbstractHBaseLogReader.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/AbstractHBaseLogReader.java deleted file mode 100755 index d22b5b3..0000000 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/AbstractHBaseLogReader.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.log.entity; - -import eagle.common.config.EagleConfigFactory; -import eagle.log.entity.meta.EntityDefinition; -import eagle.common.ByteUtil; -import eagle.common.EagleBase64Wrapper; -import org.apache.hadoop.hbase.client.*; -import org.apache.hadoop.hbase.filter.Filter; -import org.apache.hadoop.hbase.filter.FilterList; -import org.apache.hadoop.hbase.filter.SingleColumnValueFilter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.Date; -import java.util.List; -import java.util.Map; - -/** - * HBase Log Reader basic initialization: - *
    - *
  1. Open HBase connection to target HBase table
  2. - *
  3. Generate HBase filter,start and stop row key, output qualifier and Scan
  4. - *
  5. onOpen(HTableInterface,Scan): Callback abstract method
  6. - *
  7. close: Close HBase connection
  8. - *
- * - * @param Reader entity class type - * - */ -public abstract class AbstractHBaseLogReader implements LogReader { - private static Logger LOG = LoggerFactory.getLogger(AbstractHBaseLogReader.class); - - protected byte[][] qualifiers; - private HTableInterface tbl; - private byte[] startKey; - private byte[] stopKey; - protected Map> searchTags; - private Filter filter; - private Date startTime; - private Date endTime; - -// protected ResultScanner rs; - private boolean isOpen = false; - - /** - * TODO it's ugly that both _ed and prefix fields can hold prefix information, - * prefix field should be in precedence over _ed - */ - private String _prefix; - protected EntityDefinition _ed; - - public AbstractHBaseLogReader(EntityDefinition ed, List partitions, Date startTime, Date endTime, - Filter filter, String lastScanKey, byte[][] outputQualifiers){ - this(ed, partitions, startTime, endTime, filter, lastScanKey, outputQualifiers, null); - } - /** - * This constructor supports partition. - * - * @param ed entity definition - * @param partitions partition values, which is sorted in partition definition order. TODO: in future we need to support - * multiple values for one partition field - * @param startTime start time of the query - * @param endTime end time of the query - * @param filter filter for the hbase scan - * @param lastScanKey the key of last scan - * @param outputQualifiers the bytes of output qualifier names - * @param prefix can be populated from outside world specifically for generic metric reader - */ - public AbstractHBaseLogReader(EntityDefinition ed, List partitions, Date startTime, Date endTime, - Filter filter, String lastScanKey, byte[][] outputQualifiers, String prefix){ - this.startTime = startTime; - this.endTime = endTime; - this._ed = ed; - if (_ed.getPartitions() != null) { - if (partitions == null || _ed.getPartitions().length != partitions.size()) { - throw new IllegalArgumentException("Invalid argument. Entity " + ed.getClass().getSimpleName() + " defined " - + "partitions, but argument partitions is null or number of partition values are different!"); - } - } - /** - * decide prefix field value - */ - if(prefix == null || prefix.isEmpty()){ - this._prefix = _ed.getPrefix(); - }else{ - this._prefix = prefix; - } - this.qualifiers = outputQualifiers; - this.filter = filter; - - this.startKey = buildRowKey(this._prefix, partitions, startTime); - - - /** - * startTime should be inclusive, -128 is max value for hbase Bytes comparison, see PureJavaComparer.compareTo - * as an alternative, we can use startTime-1000 and endTime-1000 to make sure startTime is inclusive and endTime is exclusive - */ - this.startKey = ByteUtil.concat(this.startKey, new byte[] {-1, -1,-1,-1}); - if (lastScanKey == null) { - this.stopKey = buildRowKey(this._prefix, partitions, endTime); - // endTime should be exclusive - this.stopKey = ByteUtil.concat(this.stopKey, new byte[] {-1,-1,-1,-1,-1}); - } else { - // build stop key - this.stopKey = EagleBase64Wrapper.decode(lastScanKey); - // TODO to-be-fixed, probably it's an issue because contacting 1 is not - // enough for lexicographical sorting - this.stopKey = ByteUtil.concat(this.stopKey, new byte[] { 1 }); - } - } - - /** - * TODO If the required field is null for a row, then this row will not be fetched. That could be a problem for counting - * Need another version of read to strictly get the number of rows which will return all the columns for a column family - */ - @Override - public void open() throws IOException { - if (isOpen) - return; // silently return - try { - tbl = EagleConfigFactory.load().getHTable(_ed.getTable()); - } catch (RuntimeException ex) { - throw new IOException(ex); - } - - Scan s1 = new Scan(); - // reverse timestamp, startRow is stopKey, and stopRow is startKey - s1.setStartRow(stopKey); - s1.setStopRow(startKey); - s1.setFilter(filter); - // TODO the # of cached rows should be minimum of (pagesize and 100) - int cs = EagleConfigFactory.load().getHBaseClientScanCacheSize(); - s1.setCaching(cs); - // TODO not optimized for all applications - s1.setCacheBlocks(true) - ; - // scan specified columnfamily and qualifiers - if(this.qualifiers == null) { - // Filter all - s1.addFamily(_ed.getColumnFamily().getBytes()); - }else{ - for (byte[] qualifier : qualifiers) { - s1.addColumn(_ed.getColumnFamily().getBytes(), qualifier); - } - } - // TODO: Work around https://issues.apache.org/jira/browse/HBASE-2198. More graceful implementation should use SingleColumnValueExcludeFilter, - // but it's complicated in current implementation. - workaroundHBASE2198(s1, filter); - if (LOG.isDebugEnabled()) { - LOG.debug(s1.toString()); - } -// rs = tbl.getScanner(s1); - this.onOpen(tbl,s1); - isOpen = true; - } - - /** - * HBase table connection callback function - * - * @param tbl HBase table connection - * @param scan HBase scan - * @throws IOException - */ - protected abstract void onOpen(HTableInterface tbl,Scan scan) throws IOException; - - /** - *

History

- *
    - *
  • Nov 19th, 2014: Fix for out put all qualifiers
  • - *
- * @param s1 - * @param filter - */ - protected void workaroundHBASE2198(Scan s1, Filter filter) { - if (filter instanceof SingleColumnValueFilter) { - if(this.qualifiers == null){ - s1.addFamily(((SingleColumnValueFilter) filter).getFamily()); - }else { - s1.addColumn(((SingleColumnValueFilter) filter).getFamily(), ((SingleColumnValueFilter) filter).getQualifier()); - } - return; - } - if (filter instanceof FilterList) { - for (Filter f : ((FilterList)filter).getFilters()) { - workaroundHBASE2198(s1, f); - } - } - } - - /** - *

Close:

- * 1. release current table connection - * - * @throws IOException - */ - @Override - public void close() throws IOException { - if(tbl != null){ - new HTableFactory().releaseHTableInterface(tbl); - } -// if(rs != null){ -// rs.close(); -// } - } - - private static byte[] buildRowKey(String prefix, List partitions, Date t){ - final int length = (partitions == null) ? (4 + 8) : (4 + 8 + partitions.size() * 4); - final byte[] key = new byte[length]; - int offset = 0; - ByteUtil.intToBytes(prefix.hashCode(), key, offset); - offset += 4; - if (partitions != null) { - for (String partition : partitions) { - ByteUtil.intToBytes(partition.hashCode(), key, offset); - offset += 4; - } - } - // reverse timestamp - long ts = Long.MAX_VALUE - t.getTime(); - ByteUtil.longToBytes(ts, key, offset); - return key; - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/BaseEntityRepository.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/BaseEntityRepository.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/BaseEntityRepository.java deleted file mode 100755 index 488524c..0000000 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/BaseEntityRepository.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.log.entity; - -import eagle.log.entity.repo.EntityRepository; - -public class BaseEntityRepository extends EntityRepository { - - public BaseEntityRepository() { - entitySet.add(GenericMetricEntity.class); - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/EntityCreationListener.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/EntityCreationListener.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/EntityCreationListener.java deleted file mode 100644 index 18244e9..0000000 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/EntityCreationListener.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.log.entity; - -import eagle.log.base.taggedlog.TaggedLogAPIEntity; - -/** - * Interface to notify creation event of an entity - */ -public interface EntityCreationListener { - public void entityCreated(TaggedLogAPIEntity entity) throws Exception; -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/EntityQualifierUtils.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/EntityQualifierUtils.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/EntityQualifierUtils.java deleted file mode 100755 index 0c4c2ad..0000000 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/EntityQualifierUtils.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.log.entity; - -import eagle.log.entity.meta.EntityDefinition; -import eagle.log.entity.meta.EntityDefinitionManager; -import eagle.log.entity.meta.EntitySerDeser; -import eagle.log.entity.meta.Qualifier; -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.hadoop.hbase.KeyValue; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class EntityQualifierUtils { - private final static Logger LOG = LoggerFactory.getLogger(EntityQualifierUtils.class); - - public static Map keyValuesToMap(List row,EntityDefinition ed){ - Map result = new HashMap(); - for(KeyValue kv:row){ - String qualifierName = new String(kv.getQualifier()); - if(!ed.isTag(qualifierName)){ - Qualifier qualifier = ed.getDisplayNameMap().get(qualifierName); - if(qualifier == null){ - qualifier = ed.getQualifierNameMap().get(qualifierName); - } - qualifierName = qualifier.getDisplayName(); - Object value = qualifier.getSerDeser().deserialize(kv.getValue()); - result.put(qualifierName,value); - }else{ - result.put(qualifierName,new String(kv.getValue())); - } - } - return result; - } - - public static Map keyValuesToDoubleMap(List row,EntityDefinition ed){ - Map result = new HashMap(); - for(KeyValue kv:row){ - String qualifierName = new String(kv.getQualifier()); - if(!ed.isTag(qualifierName)){ - Qualifier qualifier = ed.getDisplayNameMap().get(qualifierName); - if(qualifier == null){ - qualifier = ed.getQualifierNameMap().get(qualifierName); - } - qualifierName = qualifier.getDisplayName(); - Object value = qualifier.getSerDeser().deserialize(kv.getValue()); - result.put(qualifierName,convertObjToDouble(value)); - }else{ - result.put(qualifierName,Double.NaN); - } - } - return result; - } - - /** - * Map[Display Name,Double Value] - * - * @param map - * @param ed - * @return - */ - public static Map bytesMapToDoubleMap(Map map,EntityDefinition ed){ - Map result = new HashMap(); - for(Map.Entry entry:map.entrySet()){ - String qualifierName = entry.getKey(); - Qualifier qualifier = ed.getDisplayNameMap().get(qualifierName); - if(qualifier == null) qualifier = ed.getQualifierNameMap().get(qualifierName); - if(qualifier!=null && entry.getValue()!=null) { - qualifierName = qualifier.getDisplayName(); - Object value = qualifier.getSerDeser().deserialize(entry.getValue()); - result.put(qualifierName, convertObjToDouble(value)); - }else{ - result.put(qualifierName,null); - } - } - return result; - } - - public static byte[] toBytes(EntityDefinition ed, String qualifierName, String qualifierValueInStr){ - // Get field type from entity class - // and skip for not-found fields query expression - Object typedValue = null; - EntitySerDeser serDeser = null; - if(ed.isTag(qualifierName)){ - typedValue = qualifierValueInStr; - serDeser = EntityDefinitionManager.getSerDeser(String.class); - }else{ - try{ - Field field = ed.getEntityClass().getDeclaredField(qualifierName); - Class fieldType = field.getType(); - serDeser = EntityDefinitionManager.getSerDeser(fieldType); - if(serDeser == null){ - throw new IllegalArgumentException("Can't find EntitySerDeser for field: "+ qualifierName +"'s type: "+fieldType - +", so the field is not supported to be filtered yet"); - } - typedValue = convertStringToObject(qualifierValueInStr, fieldType); - } catch (NoSuchFieldException ex) { - // Handle the field not found exception in caller - LOG.error("Field " + qualifierName + " not found in " + ed.getEntityClass()); - throw new IllegalArgumentException("Field "+qualifierName+" not found in "+ed.getEntityClass(),ex); - } - } - return serDeser.serialize(typedValue); - } - - public static Class getType(EntityDefinition ed, String qualifierName) { - Field field; - try { - field = ed.getEntityClass().getDeclaredField(qualifierName); - } catch (NoSuchFieldException e) { - if(LOG.isDebugEnabled()) LOG.debug("Field "+qualifierName+" not found in "+ed.getEntityClass()); - return null; - } - return field.getType(); - } - - /** - * Not support negative numeric value: - * - http://en.wikipedia.org/wiki/Double-precision_floating-point_format - * - * @param value - * @param type - * @return - */ - public static Object convertStringToObject(String value, Class type){ - Object obj = null; - try{ - if(String.class.equals(type)){ - obj = value; - }if(Long.class.equals(type) || long.class.equals(type)){ - obj = Long.parseLong(value); - // if((Long) obj < 0) throw new IllegalArgumentException("Don't support negative Long yet: "+obj); - }else if(Integer.class.equals(type) || int.class.equals(type)){ - obj = Integer.parseInt(value); - // if((Integer) obj < 0) throw new IllegalArgumentException("Don't support negative Integer yet: "+obj); - }else if(Double.class.equals(type) || double.class.equals(type)){ - obj = Double.parseDouble(value); - // if((Double) obj < 0) throw new IllegalArgumentException("Don't support negative Double yet: "+obj); - }else if(Float.class.equals(type) || float.class.equals(type)){ - obj = Float.parseFloat(value); - // if((Double) obj < 0) throw new IllegalArgumentException("Don't support negative Float yet: "+obj); - } - if(obj != null) return obj; - }catch (NumberFormatException ex){ - throw new IllegalArgumentException("Fail to convert string: "+value +" into type of "+type,ex); - } - - throw new IllegalArgumentException("Fail to convert string: "+value +" into type of "+type+", illegal type: "+type); - } - - /** - * - * @param obj - * @return double value, otherwise Double.NaN - */ - public static double convertObjToDouble(Object obj){ - if(Long.class.equals(obj.getClass()) || long.class.equals(obj.getClass())){ - Long _value = (Long) obj; - return _value.doubleValue(); - }else if(Integer.class.equals(obj.getClass()) || int.class.equals(obj.getClass())){ - Integer _value = (Integer) obj; - return _value.doubleValue(); - }else if(Double.class.equals(obj.getClass()) || double.class.equals(obj.getClass())) { - return (Double) obj; - }else if(Float.class.equals(obj.getClass()) || float.class.equals(obj.getClass())) { - Float _value = (Float) obj; - return _value.doubleValue(); - }else if(Short.class.equals(obj.getClass()) || short.class.equals(obj.getClass())) { - Float _value = (Float) obj; - return _value.doubleValue(); - }else if(Byte.class.equals(obj.getClass()) || byte.class.equals(obj.getClass())) { - Byte _value = (Byte) obj; - return _value.doubleValue(); - } - LOG.warn("Failed to convert object " + obj.toString() + " in type of " + obj.getClass() + " to double"); - return Double.NaN; - } - - /** - * Parse List String as Set without duplicate items - * - *

- * Support: - *
    - *
  • normal string: ("a","b") => ["a","b"]
  • - *
  • number: (1.5,"b") => [1.5,"b"]
  • - *
  • inner string comma: ("va,lue","value",",") => ["va,lue","value",","]
  • - *
  • inner escaped chars: ("va\"lue","value") => ["va\"lue","value"]
  • - *
  • some bad formats list: ("va"lue","value") => ["va\"lue","value"]
  • - *
- * - * Warning: it will not throw exception if the format is not strictly valid - * - * @param listValue in format (item1,item2,...) - * @return - */ - public static List parseList(String listValue){ - Matcher matcher = SET_PATTERN.matcher(listValue); - if(matcher.find()){ - String content = matcher.group(1); - List result = new ArrayList(); - StringBuilder str = null; - STATE state = null; - char last = 0; - for(char c: content.toCharArray()){ - if(str == null) str = new StringBuilder(); - if(c == DOUBLE_QUOTE && last != SLASH){ - // Open or Close String - if(state == STATE.STRING) - state = null; - else state = STATE.STRING; - }else if(c == COMMA && state != STATE.STRING){ - result.add(unescape(str.toString())); - str = null; - last = c; - continue; - } - last = c; - str.append(c); - } - if(str!=null) result.add(unescape(str.toString())); - return result; - }else{ - LOG.error("Invalid list value: " + listValue); - throw new IllegalArgumentException("Invalid format of list value: "+listValue+", must be in format: (item1,item2,...)"); - } - } - - private static String unescape(String str){ - int start=0,end = str.length(); - if(str.startsWith("\"")) start = start +1; - if(str.endsWith("\"")) end = end -1; - str = str.substring(start,end); - return StringEscapeUtils.unescapeJava(str); - } - - private final static Pattern SET_PATTERN = Pattern.compile("^\\((.*)\\)$"); - private final static char COMMA = ','; - private final static char DOUBLE_QUOTE = '"'; - private final static char SLASH = '\\'; - private static enum STATE{ STRING } - - - -// TODO: NOT FINISHED -// private final static Map ESCAPE_REGEXP=new HashMap(){{ -// this.put("\\.","\\\\."); -// }}; -// -// public static String escapeRegExp(String value) { -// String _value = value; -// for(Map.Entry entry:ESCAPE_REGEXP.entrySet()){ -// _value = _value.replace(entry.getKey(),entry.getValue()); -// } -// return _value; -// } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/EntityUniq.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/EntityUniq.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/EntityUniq.java deleted file mode 100755 index af99861..0000000 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/EntityUniq.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * - */ -package eagle.log.entity; - -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - - -/** - * @since Sep 12, 2014 - */ -public class EntityUniq { - - public Map tags; - public Long timestamp; - public long createdTime; // for cache removal; - - public EntityUniq(Map tags, long timestamp) { - this.tags = new HashMap(tags); - this.timestamp = timestamp; - this.createdTime = System.currentTimeMillis(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof EntityUniq) { - EntityUniq au = (EntityUniq) obj; - if (tags.size() != au.tags.size()) return false; - for (Entry keyValue : au.tags.entrySet()) { - boolean keyExist = tags.containsKey(keyValue.getKey()); - if ( !keyExist || !tags.get(keyValue.getKey()).equals(keyValue.getValue())) { - return false; - } - } - if (!timestamp.equals(au.timestamp)) return false; - return true; - } - return false; - } - - @Override - public int hashCode() { - int hashCode = 0; - for (String value : tags.values()) { - hashCode ^= value.hashCode(); - } - return hashCode ^= timestamp.hashCode(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericCreateAPIResponseEntity.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericCreateAPIResponseEntity.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericCreateAPIResponseEntity.java deleted file mode 100644 index eae8b18..0000000 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericCreateAPIResponseEntity.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.log.entity; - -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.map.annotate.JsonSerialize; - -@XmlRootElement -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(propOrder = {"success", "exception", "encodedRowkeys"}) -@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) -@JsonIgnoreProperties(ignoreUnknown=true) -public class GenericCreateAPIResponseEntity{ - private boolean success; - private String exception; - private List encodedRowkeys; - - public List getEncodedRowkeys() { - return encodedRowkeys; - } - public void setEncodedRowkeys(List encodedRowkeys) { - this.encodedRowkeys = encodedRowkeys; - } - public boolean isSuccess() { - return success; - } - public void setSuccess(boolean success) { - this.success = success; - } - public String getException() { - return exception; - } - public void setException(String exception) { - this.exception = exception; - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityBatchReader.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityBatchReader.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityBatchReader.java deleted file mode 100755 index 7b52d11..0000000 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityBatchReader.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.log.entity; - -import eagle.log.base.taggedlog.TaggedLogAPIEntity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; - -public class GenericEntityBatchReader implements EntityCreationListener{ - private static final Logger LOG = LoggerFactory.getLogger(GenericEntityBatchReader.class); - - private List entities = new ArrayList(); - private StreamReader reader; - - public GenericEntityBatchReader(String serviceName, SearchCondition condition) throws InstantiationException, IllegalAccessException{ - reader = new GenericEntityStreamReader(serviceName, condition); - reader.register(this); - } - - public GenericEntityBatchReader(StreamReader reader) throws InstantiationException, IllegalAccessException{ - this.reader = reader; - reader.register(this); - } - - public long getLastTimestamp() { - return reader.getLastTimestamp(); - } - public long getFirstTimestamp(){ return reader.getFirstTimestamp();} - - @Override - public void entityCreated(TaggedLogAPIEntity entity){ - entities.add(entity); - } - - @SuppressWarnings("unchecked") - public List read() throws Exception{ - if(LOG.isDebugEnabled()) LOG.debug("Start reading as batch mode"); - reader.readAsStream(); - return (List)entities; - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityScanStreamReader.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityScanStreamReader.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityScanStreamReader.java deleted file mode 100755 index 58dd807..0000000 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityScanStreamReader.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.log.entity; - -import eagle.log.base.taggedlog.TaggedLogAPIEntity; -import eagle.log.entity.meta.EntityConstants; -import eagle.log.entity.meta.EntityDefinition; -import eagle.log.entity.meta.EntityDefinitionManager; -import eagle.common.DateTimeUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.Date; - -public class GenericEntityScanStreamReader extends StreamReader { - private static final Logger LOG = LoggerFactory.getLogger(GenericEntityScanStreamReader.class); - - private EntityDefinition entityDef; - private SearchCondition condition; - private String prefix; - private long lastTimestamp = 0; - private long firstTimestamp = 0; - - public GenericEntityScanStreamReader(String serviceName, SearchCondition condition, String prefix) throws InstantiationException, IllegalAccessException{ - this.prefix = prefix; - checkNotNull(serviceName, "serviceName"); - this.entityDef = EntityDefinitionManager.getEntityByServiceName(serviceName); - checkNotNull(entityDef, "EntityDefinition"); - this.condition = condition; - } - - public GenericEntityScanStreamReader(EntityDefinition entityDef, SearchCondition condition, String prefix) throws InstantiationException, IllegalAccessException{ - this.prefix = prefix; - checkNotNull(entityDef, "entityDef"); - this.entityDef = entityDef; - checkNotNull(entityDef, "EntityDefinition"); - this.condition = condition; - } - - public long getLastTimestamp() { - return lastTimestamp; - } - - private void checkNotNull(Object o, String message){ - if(o == null){ - throw new IllegalArgumentException(message + " should not be null"); - } - } - - public EntityDefinition getEntityDefinition() { - return entityDef; - } - - public SearchCondition getSearchCondition() { - return condition; - } - - @Override - public void readAsStream() throws Exception{ - Date start = null; - Date end = null; - // shortcut to avoid read when pageSize=0 - if(condition.getPageSize() <= 0){ - return; // return nothing - } - // Process the time range if needed - if(entityDef.isTimeSeries()){ - start = DateTimeUtil.humanDateToDate(condition.getStartTime()); - end = DateTimeUtil.humanDateToDate(condition.getEndTime()); - }else{ - start = DateTimeUtil.humanDateToDate(EntityConstants.FIXED_READ_START_HUMANTIME); - end = DateTimeUtil.humanDateToDate(EntityConstants.FIXED_READ_END_HUMANTIME); - } - byte[][] outputQualifiers = null; - if(!condition.isOutputAll()) { - // Generate the output qualifiers - outputQualifiers = HBaseInternalLogHelper.getOutputQualifiers(entityDef, condition.getOutputFields()); - } - HBaseLogReader2 reader = new HBaseLogReader2(entityDef, condition.getPartitionValues(), start, end, condition.getFilter(), condition.getStartRowkey(), outputQualifiers, this.prefix); - try{ - reader.open(); - InternalLog log; - int count = 0; - while ((log = reader.read()) != null) { - TaggedLogAPIEntity entity = HBaseInternalLogHelper.buildEntity(log, entityDef); - if (lastTimestamp < entity.getTimestamp()) { - lastTimestamp = entity.getTimestamp(); - } - if(firstTimestamp > entity.getTimestamp() || firstTimestamp == 0){ - firstTimestamp = entity.getTimestamp(); - } - - entity.setSerializeVerbose(condition.isOutputVerbose()); - entity.setSerializeAlias(condition.getOutputAlias()); - - for(EntityCreationListener l : _listeners){ - l.entityCreated(entity); - } - if(++count == condition.getPageSize()) - break; - } - }catch(IOException ioe){ - LOG.error("Fail reading log", ioe); - throw ioe; - }finally{ - reader.close(); - } - } - - @Override - public long getFirstTimestamp() { - return this.firstTimestamp; - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityStreamReader.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityStreamReader.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityStreamReader.java deleted file mode 100755 index 33c0268..0000000 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityStreamReader.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.log.entity; - -import eagle.log.entity.index.NonClusteredIndexStreamReader; -import eagle.log.entity.index.UniqueIndexStreamReader; -import eagle.log.entity.meta.EntityDefinition; -import eagle.log.entity.meta.EntityDefinitionManager; -import eagle.log.entity.meta.IndexDefinition; -import eagle.log.entity.meta.IndexDefinition.IndexType; -import eagle.query.parser.ORExpression; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; - -public class GenericEntityStreamReader extends StreamReader { - private static final Logger LOG = LoggerFactory.getLogger(GenericEntityStreamReader.class); - - private EntityDefinition entityDef; - private SearchCondition condition; - private String prefix; - private StreamReader readerAfterPlan; - - public GenericEntityStreamReader(String serviceName, SearchCondition condition) throws InstantiationException, IllegalAccessException{ - this(serviceName, condition, null); - } - - public GenericEntityStreamReader(EntityDefinition entityDef, SearchCondition condition) throws InstantiationException, IllegalAccessException{ - this(entityDef, condition, entityDef.getPrefix()); - } - - public GenericEntityStreamReader(String serviceName, SearchCondition condition, String prefix) throws InstantiationException, IllegalAccessException{ - this.prefix = prefix; - checkNotNull(serviceName, "serviceName"); - this.entityDef = EntityDefinitionManager.getEntityByServiceName(serviceName); - checkNotNull(entityDef, "EntityDefinition"); - this.condition = condition; - this.readerAfterPlan = selectQueryReader(); - } - - public GenericEntityStreamReader(EntityDefinition entityDef, SearchCondition condition, String prefix) throws InstantiationException, IllegalAccessException{ - this.prefix = prefix; - checkNotNull(entityDef, "entityDef"); - this.entityDef = entityDef; - checkNotNull(entityDef, "EntityDefinition"); - this.condition = condition; - this.readerAfterPlan = selectQueryReader(); - } - - private void checkNotNull(Object o, String message){ - if(o == null){ - throw new IllegalArgumentException(message + " should not be null"); - } - } - - public EntityDefinition getEntityDefinition() { - return entityDef; - } - - public SearchCondition getSearchCondition() { - return condition; - } - - @Override - public void readAsStream() throws Exception{ - readerAfterPlan._listeners.addAll(this._listeners); - readerAfterPlan.readAsStream(); - } - - private StreamReader selectQueryReader() throws InstantiationException, IllegalAccessException { - final ORExpression query = condition.getQueryExpression(); - IndexDefinition[] indexDefs = entityDef.getIndexes(); - - // Index just works with query condition - if (indexDefs != null && condition.getQueryExpression()!=null) { - List rowkeys = new ArrayList<>(); - for (IndexDefinition index : indexDefs) { - // Check unique index first - if (index.isUnique()) { - final IndexType type = index.canGoThroughIndex(query, rowkeys); - if (!IndexType.NON_INDEX.equals(type)) { - LOG.info("Selectd query unique index " + index.getIndexName() + " for query: " + condition.getQueryExpression()); - return new UniqueIndexStreamReader(index, condition, rowkeys); - } - } - } - for (IndexDefinition index : indexDefs) { - // Check non-clustered index - if (!index.isUnique()) { - final IndexType type = index.canGoThroughIndex(query, rowkeys); - if (!IndexType.NON_INDEX.equals(type)) { - LOG.info("Selectd query non clustered index " + index.getIndexName() + " for query: " + condition.getQueryExpression().toString()); - return new NonClusteredIndexStreamReader(index, condition, rowkeys); - } - } - } - } - return new GenericEntityScanStreamReader(entityDef, condition, this.prefix); - } - - @Override - public long getLastTimestamp() { - return readerAfterPlan.getLastTimestamp(); - } - - @Override - public long getFirstTimestamp() { - return readerAfterPlan.getFirstTimestamp(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityStreamReaderMT.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityStreamReaderMT.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityStreamReaderMT.java deleted file mode 100755 index d65959f..0000000 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityStreamReaderMT.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.log.entity; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.Future; - -import eagle.common.config.EagleConfigFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import eagle.log.entity.meta.EntityDefinition; -import eagle.log.entity.meta.EntityDefinitionManager; -import eagle.common.DateTimeUtil; - -/** - * multi-threading stream readers which only applies to time-series entity where we split the query into - * different time range - * - * When this class is used together with list query or aggregate query, be aware that the query's behavior could - * be changed for example pageSize does not work well, output sequence is not determined - */ -public class GenericEntityStreamReaderMT extends StreamReader{ - private static final Logger LOG = LoggerFactory.getLogger(GenericEntityStreamReaderMT.class); - private List readers = new ArrayList(); - - public GenericEntityStreamReaderMT(String serviceName, SearchCondition condition, int numThreads) throws Exception{ - checkIsTimeSeries(serviceName); - checkNumThreads(numThreads); - long queryStartTime = DateTimeUtil.humanDateToSeconds(condition.getStartTime())*1000; - long queryEndTime = DateTimeUtil.humanDateToSeconds(condition.getEndTime())*1000; - long subStartTime = queryStartTime; - long subEndTime = 0; - long interval = (queryEndTime-queryStartTime) / numThreads; - for(int i=0; i= 1"); - } - } - - /** - * default to 2 threads - * @param serviceName - * @param condition - */ - public GenericEntityStreamReaderMT(String serviceName, SearchCondition condition) throws Exception{ - this(serviceName, condition, 2); - } - - @Override - public void readAsStream() throws Exception{ - // populate listeners to all readers - for(EntityCreationListener l : _listeners){ - for(GenericEntityStreamReader r : readers){ - r.register(l); - } - } - - List> futures = new ArrayList>(); - for(GenericEntityStreamReader r : readers){ - SingleReader reader = new SingleReader(r); - Future readFuture = EagleConfigFactory.load().getExecutor().submit(reader); - futures.add(readFuture); - } - - // join threads and check exceptions - for(Future future : futures){ - try{ - future.get(); - }catch(Exception ex){ - LOG.error("Error in read", ex); - throw ex; - } - } - } - - private static class SingleReader implements Callable{ - private GenericEntityStreamReader reader; - public SingleReader(GenericEntityStreamReader reader){ - this.reader = reader; - } - @Override - public Void call() throws Exception{ - reader.readAsStream(); - return null; - } - } - - @Override - public long getLastTimestamp() { - long lastTimestamp = 0; - for (GenericEntityStreamReader reader : readers) { - if (lastTimestamp < reader.getLastTimestamp()) { - lastTimestamp = reader.getLastTimestamp(); - } - } - return lastTimestamp; - } - - @Override - public long getFirstTimestamp() { - long firstTimestamp = 0; - for (GenericEntityStreamReader reader : readers) { - if (firstTimestamp > reader.getLastTimestamp() || firstTimestamp == 0) { - firstTimestamp = reader.getLastTimestamp(); - } - } - return firstTimestamp; - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityWriter.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityWriter.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityWriter.java deleted file mode 100755 index 1bbecf0..0000000 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericEntityWriter.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.log.entity; - -import eagle.log.base.taggedlog.TaggedLogAPIEntity; -import eagle.log.entity.meta.EntityDefinition; -import eagle.log.entity.meta.EntityDefinitionManager; -import eagle.common.EagleBase64Wrapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; - -public class GenericEntityWriter { - private static final Logger LOG = LoggerFactory.getLogger(GenericEntityWriter.class); - private EntityDefinition entityDef; - - public GenericEntityWriter(String serviceName) throws InstantiationException, IllegalAccessException{ - this.entityDef = EntityDefinitionManager.getEntityByServiceName(serviceName); - checkNotNull(entityDef, "serviceName"); - } - - public GenericEntityWriter(EntityDefinition entityDef) throws InstantiationException, IllegalAccessException{ - this.entityDef = entityDef; - checkNotNull(entityDef, "serviceName"); - } - - private void checkNotNull(Object o, String message) { - if(o == null){ - throw new IllegalArgumentException(message + " should not be null"); - } - } - - /** - * @param entities - * @return row keys - * @throws Exception - */ - public List write(List entities) throws Exception{ - HBaseLogWriter writer = new HBaseLogWriter(entityDef.getTable(), entityDef.getColumnFamily()); - List rowkeys = new ArrayList(entities.size()); - List logs = new ArrayList(entities.size()); - - try{ - writer.open(); - for(TaggedLogAPIEntity entity : entities){ - final InternalLog entityLog = HBaseInternalLogHelper.convertToInternalLog(entity, entityDef); - logs.add(entityLog); - } - List bRowkeys = writer.write(logs); - for (byte[] rowkey : bRowkeys) { - rowkeys.add(EagleBase64Wrapper.encodeByteArray2URLSafeString(rowkey)); - } - - }catch(Exception ex){ - LOG.error("fail writing tagged log", ex); - throw ex; - }finally{ - writer.close(); - } - return rowkeys; - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericMetricEntity.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericMetricEntity.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericMetricEntity.java deleted file mode 100755 index bce6096..0000000 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericMetricEntity.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.log.entity; - -import eagle.log.base.taggedlog.TaggedLogAPIEntity; -import eagle.log.entity.meta.Column; -import eagle.log.entity.meta.ColumnFamily; -import eagle.log.entity.meta.Service; -import eagle.log.entity.meta.ServicePath; -import org.codehaus.jackson.map.annotate.JsonSerialize; - -import eagle.log.entity.meta.Metric; -import eagle.log.entity.meta.Partition; -import eagle.log.entity.meta.Prefix; -import eagle.log.entity.meta.Table; -import eagle.log.entity.meta.TimeSeries; - -/** - * GenericMetricEntity should use prefix field which is extended from TaggedLogAPIEntity as metric name - * metric name is used to partition the metric tables - */ -@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) -@Table("eagle_metric") -@ColumnFamily("f") -@Prefix(GenericMetricEntity.GENERIC_METRIC_PREFIX_PLACE_HOLDER) -@Service(GenericMetricEntity.GENERIC_METRIC_SERVICE) -@TimeSeries(true) -@Metric(interval=60000) -@ServicePath(path = "/metric") -public class GenericMetricEntity extends TaggedLogAPIEntity { - public static final String GENERIC_METRIC_SERVICE = "GenericMetricService"; - public static final String GENERIC_METRIC_PREFIX_PLACE_HOLDER = "GENERIC_METRIC_PREFIX_PLACEHODLER"; - public static final String VALUE_FIELD ="value"; - - @Column("a") - private double[] value; - - public double[] getValue() { - return value; - } - - public void setValue(double[] value) { - this.value = value; - _pcs.firePropertyChange("value", null, null); - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericMetricEntityBatchReader.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericMetricEntityBatchReader.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericMetricEntityBatchReader.java deleted file mode 100755 index 4a5b63f..0000000 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericMetricEntityBatchReader.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.log.entity; - -import eagle.log.base.taggedlog.TaggedLogAPIEntity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; - -public class GenericMetricEntityBatchReader implements EntityCreationListener{ - private static final Logger LOG = LoggerFactory.getLogger(GenericEntityBatchReader.class); - - private List entities = new ArrayList(); - private GenericEntityStreamReader reader; - - public GenericMetricEntityBatchReader(String metricName, SearchCondition condition) throws Exception{ - reader = new GenericEntityStreamReader(GenericMetricEntity.GENERIC_METRIC_SERVICE, condition, metricName); - } - - public long getLastTimestamp() { - return reader.getLastTimestamp(); - } - public long getFirstTimestamp() { - return reader.getFirstTimestamp(); - } - @Override - public void entityCreated(TaggedLogAPIEntity entity){ - entities.add(entity); - } - - @SuppressWarnings("unchecked") - public List read() throws Exception{ - if(LOG.isDebugEnabled()) LOG.debug("Start reading as batch mode"); - reader.register(this); - reader.readAsStream(); - return (List)entities; - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericMetricEntityDecompactionStreamReader.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericMetricEntityDecompactionStreamReader.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericMetricEntityDecompactionStreamReader.java deleted file mode 100755 index 901a019..0000000 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericMetricEntityDecompactionStreamReader.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.log.entity; - -import eagle.log.base.taggedlog.TaggedLogAPIEntity; -import eagle.log.entity.meta.EntityDefinition; -import eagle.log.entity.meta.EntityDefinitionManager; -import eagle.common.DateTimeUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.text.ParseException; - -public class GenericMetricEntityDecompactionStreamReader extends StreamReader implements EntityCreationListener{ - @SuppressWarnings("unused") - private static final Logger LOG = LoggerFactory.getLogger(GenericMetricEntityDecompactionStreamReader.class); - private GenericEntityStreamReader reader; - private EntityDefinition ed; - private String serviceName = GenericMetricEntity.GENERIC_METRIC_SERVICE; - private long start; - private long end; - private GenericMetricShadowEntity single = new GenericMetricShadowEntity(); - - /** - * it makes sense that serviceName should not be provided while metric name should be provided as prefix - * @param metricName - * @param condition - * @throws InstantiationException - * @throws IllegalAccessException - * @throws ParseException - */ - public GenericMetricEntityDecompactionStreamReader(String metricName, SearchCondition condition) throws InstantiationException, IllegalAccessException, ParseException{ - ed = EntityDefinitionManager.getEntityByServiceName(serviceName); - checkIsMetric(ed); - reader = new GenericEntityStreamReader(serviceName, condition, metricName); - start = DateTimeUtil.humanDateToSeconds(condition.getStartTime())*1000; - end = DateTimeUtil.humanDateToSeconds(condition.getEndTime())*1000; - } - - private void checkIsMetric(EntityDefinition ed){ - if(ed.getMetricDefinition() == null) - throw new IllegalArgumentException("Only metric entity comes here"); - } - - @Override - public void entityCreated(TaggedLogAPIEntity entity) throws Exception{ - GenericMetricEntity e = (GenericMetricEntity)entity; - double[] value = e.getValue(); - if(value != null) { - int count =value.length; - @SuppressWarnings("unused") - Class cls = ed.getMetricDefinition().getSingleTimestampEntityClass(); - for (int i = 0; i < count; i++) { - long ts = entity.getTimestamp() + i * ed.getMetricDefinition().getInterval(); - // exclude those entity which is not within the time range in search condition. [start, end) - if (ts < start || ts >= end) { - continue; - } - single.setTimestamp(ts); - single.setTags(entity.getTags()); - single.setValue(e.getValue()[i]); - for (EntityCreationListener l : _listeners) { - l.entityCreated(single); - } - } - } - } - - @Override - public void readAsStream() throws Exception{ - reader.register(this); - reader.readAsStream(); - } - - @Override - public long getLastTimestamp() { - return reader.getLastTimestamp(); - } - - @Override - public long getFirstTimestamp() { - return reader.getFirstTimestamp(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericMetricShadowEntity.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericMetricShadowEntity.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericMetricShadowEntity.java deleted file mode 100644 index b5d0529..0000000 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericMetricShadowEntity.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.log.entity; - -import eagle.log.base.taggedlog.TaggedLogAPIEntity; - -/** - * just a shadow class to avoid dynamically create the class and instantiate using reflection - */ -public class GenericMetricShadowEntity extends TaggedLogAPIEntity { - private double value; - - public double getValue() { - return value; - } - - public void setValue(double value) { - this.value = value; - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericServiceAPIResponseEntity.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericServiceAPIResponseEntity.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericServiceAPIResponseEntity.java deleted file mode 100644 index 85e4e13..0000000 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericServiceAPIResponseEntity.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.log.entity; - -import eagle.common.EagleExceptionWrapper; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.map.annotate.JsonDeserialize; -import org.codehaus.jackson.map.annotate.JsonSerialize; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; -import java.util.List; -import java.util.Map; - -/** - * The only GenericServiceAPIResponseEntity for both client and server side - * - * @see GenericServiceAPIResponseEntityDeserializer - */ -@XmlRootElement -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(propOrder = {"success","exception","meta","type","obj"}) -@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) -@JsonDeserialize(using = GenericServiceAPIResponseEntityDeserializer.class) -@JsonIgnoreProperties(ignoreUnknown=true) -public class GenericServiceAPIResponseEntity{ - /** - * Please use primitive type of value in meta as possible - */ - private Map meta; - private boolean success; - private String exception; - private List obj; - private Class type; - - public GenericServiceAPIResponseEntity(){ - // default constructor - } - public GenericServiceAPIResponseEntity(Class type){ - this.setType(type); - } - - public Map getMeta() { - return meta; - } - - public void setMeta(Map meta) { - this.meta = meta; - } - - public List getObj() { - return obj; - } - - public void setObj(List obj) { - this.obj = obj; - } - - public void setObj(List obj,Class type) { - this.setObj(obj); - this.setType(type); - } - - public Class getType() { - return type; - } - - /** - * Set the first object's class as type - */ - @SuppressWarnings("unused") - public void setTypeByObj(){ - for(T t:this.obj){ - if(this.type == null && t!=null){ - this.type = (Class) t.getClass(); - } - } - } - - /** - * can explicitly change type class - * - * @param type - */ - public void setType(Class type) { - this.type = type; - } - - public boolean isSuccess() { - return success; - } - public void setSuccess(boolean success) { - this.success = success; - } - public String getException() { - return exception; - } - public void setException(String exception) { - this.exception = exception; - } - - public void setException(Exception exception){ - if(exception!=null) this.exception = EagleExceptionWrapper.wrap(exception); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericServiceAPIResponseEntityDeserializer.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericServiceAPIResponseEntityDeserializer.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericServiceAPIResponseEntityDeserializer.java deleted file mode 100644 index 28bdf3e..0000000 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/eagle/log/entity/GenericServiceAPIResponseEntityDeserializer.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.log.entity; - -import org.codehaus.jackson.JsonNode; -import org.codehaus.jackson.JsonParser; -import org.codehaus.jackson.JsonProcessingException; -import org.codehaus.jackson.ObjectCodec; -import org.codehaus.jackson.map.DeserializationContext; -import org.codehaus.jackson.map.JsonDeserializer; -import org.codehaus.jackson.map.type.TypeFactory; -import org.codehaus.jackson.type.JavaType; - -import java.io.IOException; -import java.util.*; - -/** - * @since 3/18/15 - */ -public class GenericServiceAPIResponseEntityDeserializer extends JsonDeserializer { - private final static String META_FIELD="meta"; - private final static String SUCCESS_FIELD="success"; - private final static String EXCEPTION_FIELD="exception"; - private final static String OBJ_FIELD="obj"; - private final static String TYPE_FIELD="type"; - - @Override - public GenericServiceAPIResponseEntity deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { - GenericServiceAPIResponseEntity entity = new GenericServiceAPIResponseEntity(); - ObjectCodec objectCodec = jp.getCodec(); - - JsonNode rootNode = jp.getCodec().readTree(jp); - if(rootNode.isObject()){ - Iterator> fields = rootNode.getFields(); - JsonNode objNode = null; - while(fields.hasNext()){ - Map.Entry field = fields.next(); - if (META_FIELD.equals(field.getKey()) && field.getValue() != null) - entity.setMeta(objectCodec.readValue(field.getValue().traverse(), Map.class)); - else if(SUCCESS_FIELD.equals(field.getKey()) && field.getValue() != null){ - entity.setSuccess(field.getValue().getValueAsBoolean(false)); - }else if(EXCEPTION_FIELD.equals(field.getKey()) && field.getValue() != null){ - entity.setException(field.getValue().getTextValue()); - }else if(TYPE_FIELD.endsWith(field.getKey()) && field.getValue() != null){ - try { - entity.setType(Class.forName(field.getValue().getTextValue())); - } catch (ClassNotFoundException e) { - throw new IOException(e); - } - }else if(OBJ_FIELD.equals(field.getKey()) && field.getValue() != null){ - objNode = field.getValue(); - } - } - - if(objNode!=null) { - JavaType collectionType=null; - if (entity.getType() != null) { - collectionType = TypeFactory.defaultInstance().constructCollectionType(LinkedList.class, entity.getType()); - }else{ - collectionType = TypeFactory.defaultInstance().constructCollectionType(LinkedList.class, Map.class); - } - List obj = objectCodec.readValue(objNode.traverse(), collectionType); - entity.setObj(obj); - } - }else{ - throw new IOException("root node is not object"); - } - return entity; - } -} \ No newline at end of file