eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h..@apache.org
Subject [28/55] [abbrv] [partial] incubator-eagle git commit: [EAGLE-46] Rename package name as "org.apache.eagle"
Date Thu, 19 Nov 2015 10:47:35 GMT
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/impl/EagleServiceBaseClient.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/impl/EagleServiceBaseClient.java b/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/impl/EagleServiceBaseClient.java
deleted file mode 100644
index c1b8baf..0000000
--- a/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/impl/EagleServiceBaseClient.java
+++ /dev/null
@@ -1,341 +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.service.client.impl;
-
-import com.sun.jersey.api.client.AsyncWebResource;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.config.ClientConfig;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.client.urlconnection.URLConnectionClientHandler;
-import eagle.common.Base64;
-import eagle.log.base.taggedlog.TaggedLogAPIEntity;
-import eagle.log.entity.GenericServiceAPIResponseEntity;
-import eagle.log.entity.meta.EntityDefinition;
-import eagle.log.entity.meta.EntityDefinitionManager;
-import eagle.service.client.EagleServiceAsyncClient;
-import eagle.service.client.EagleServiceClientException;
-import eagle.service.client.IEagleServiceClient;
-import org.codehaus.jackson.JsonFactory;
-import org.codehaus.jackson.JsonGenerationException;
-import org.codehaus.jackson.jaxrs.JacksonJsonProvider;
-import org.codehaus.jackson.map.JsonMappingException;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.ws.rs.core.MediaType;
-import java.io.Closeable;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import static eagle.service.client.security.SecurityConstants.AUTHORIZATION;
-import static eagle.service.client.security.SecurityConstants.BASIC_AUTHORIZATION_HEADER_PREFIX;
-
-public abstract class EagleServiceBaseClient implements IEagleServiceClient {
-    public final static String SERVICE_NAME="serviceName";
-    public final static String DELETE_BY_ID="byId";
-
-    private final String host;
-    private final int port;
-    private final String basePath;
-    private String username;
-    private String password;
-    protected boolean silence = false;
-
-    public String getBaseEndpoint() {
-        return baseEndpoint;
-    }
-
-    private final String baseEndpoint;
-
-    private final static Logger LOG = LoggerFactory.getLogger(EagleServiceBaseClient.class);
-
-    protected static final String DEFAULT_BASE_PATH = "/eagle-service/rest";
-    protected static final MediaType DEFAULT_MEDIA_TYPE = MediaType.APPLICATION_JSON_TYPE;
-    protected static final String DEFAULT_HTTP_HEADER_CONTENT_TYPE = "application/json";
-    protected static final String CONTENT_TYPE = "Content-Type";
-
-    protected final static String GENERIC_ENTITY_PATH = "/entities";
-    protected final static String GENERIC_ENTITY_DELETE_PATH = GENERIC_ENTITY_PATH+"/delete";
-    private final Client client;
-    private final List<Closeable> closeables = new LinkedList<Closeable>();
-
-    private volatile boolean isStopped = false;
-
-    public EagleServiceBaseClient(String host, int port, String basePath, String username, String password) {
-        this.host = host;
-        this.port = port;
-        this.basePath = basePath;
-        this.baseEndpoint = buildBathPath().toString();
-        this.username = username;
-        this.password = password;
-
-        ClientConfig cc = new DefaultClientConfig();
-        cc.getProperties().put(DefaultClientConfig.PROPERTY_CONNECT_TIMEOUT, 60 * 1000);
-        cc.getProperties().put(DefaultClientConfig.PROPERTY_READ_TIMEOUT, 60 * 1000);
-        cc.getClasses().add(JacksonJsonProvider.class);
-        cc.getProperties().put(URLConnectionClientHandler.PROPERTY_HTTP_URL_CONNECTION_SET_METHOD_WORKAROUND, true);
-        this.client = Client.create(cc);
-        client.addFilter(new com.sun.jersey.api.client.filter.GZIPContentEncodingFilter());
-        //        Runtime.getRuntime().addShutdownHook(new EagleServiceClientShutdownHook(this));
-    }
-
-    public EagleServiceBaseClient(String host, int port, String basePath){
-        this(host, port, basePath, null);
-    }
-
-    public EagleServiceBaseClient(String host, int port, String username, String password){
-        this(host, port, DEFAULT_BASE_PATH, username, password);
-    }
-
-//    private class EagleServiceClientShutdownHook extends Thread{
-//        final IEagleServiceClient client;
-//        EagleServiceClientShutdownHook(IEagleServiceClient client){
-//            this.client = client;
-//        }
-//
-//        @Override
-//        public void run() {
-//            LOG.info("Client shutdown hook");
-//            try {
-//                this.client.close();
-//            } catch (IOException e) {
-//                LOG.error(e.getMessage(),e);
-//            }
-//        }
-//    }
-
-    public Client getJerseyClient(){
-        return client;
-    }
-
-    public EagleServiceBaseClient(String host, int port){
-        this(host,port,DEFAULT_BASE_PATH);
-    }
-
-    protected final StringBuilder buildBathPath() {
-        StringBuilder sb = new StringBuilder();
-        sb.append("http://");
-        sb.append(host);
-        sb.append(":");
-        sb.append(port);
-        sb.append(basePath);
-        return sb;
-    }
-
-    protected static String marshall(List<?> entities) throws JsonMappingException, JsonGenerationException, IOException {
-        final JsonFactory factory = new JsonFactory();
-        final ObjectMapper mapper = new ObjectMapper(factory);
-        mapper.setFilters(TaggedLogAPIEntity.getFilterProvider());
-        return mapper.writeValueAsString(entities);
-    }
-
-    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;
-    }
-
-    @Override
-    public SearchRequestBuilder search() {
-        return new SearchRequestBuilder(this);
-    }
-
-    @Override
-    public SearchRequestBuilder search(String query) {
-        return new SearchRequestBuilder(this).query(query);
-    }
-
-    protected void register(Closeable closeable){
-        this.closeables.add(closeable);
-    }
-
-    @Override
-    public MetricSender metric(String metricName) {
-        MetricSender metricGenerator = new MetricSender(this,metricName);
-        this.register(metricGenerator);
-        return metricGenerator;
-    }
-
-    protected WebResource getWebResource(String relativePath){
-        return this.getJerseyClient().resource(this.getBaseEndpoint() + relativePath);
-    }
-
-    protected AsyncWebResource getAsyncWebResource(String relativePath){
-        return this.getJerseyClient().asyncResource(this.getBaseEndpoint() + relativePath);
-    }
-
-    protected WebResource.Builder putAuthHeaderIfNeeded(WebResource.Builder r) {
-        if (username != null && password != null) {
-           r.header(AUTHORIZATION, BASIC_AUTHORIZATION_HEADER_PREFIX + Base64.encode(username + ":" + password));
-        }
-        return r;
-    }
-
-    /**
-     * Send HTTP POST request with entities and serviceName
-     *
-     * @param resourceURL
-     * @param entities
-     * @param serviceName
-     * @return
-     * @throws JsonMappingException
-     * @throws JsonGenerationException
-     * @throws IOException
-     */
-    @SuppressWarnings("unchecked")
-    protected GenericServiceAPIResponseEntity<String> postEntitiesWithService(String resourceURL, List<? extends TaggedLogAPIEntity> entities,String serviceName) throws JsonMappingException, JsonGenerationException, IOException {
-        final String json = marshall(entities);
-        final WebResource r = getWebResource(resourceURL);
-        return putAuthHeaderIfNeeded(r.queryParam(SERVICE_NAME,serviceName).accept(DEFAULT_MEDIA_TYPE))
-                .header(CONTENT_TYPE, DEFAULT_HTTP_HEADER_CONTENT_TYPE)
-                .post(GenericServiceAPIResponseEntity.class, json);
-    }
-
-    /**
-     * Send HTTP PUT request with entities and serviceName
-     *
-     * @param resourceURL
-     * @param entities
-     * @param serviceName
-     * @return
-     * @throws JsonMappingException
-     * @throws JsonGenerationException
-     * @throws IOException
-     */
-    @SuppressWarnings("unchecked")
-    protected GenericServiceAPIResponseEntity<String> putEntitiesWithService(String resourceURL, List<? extends TaggedLogAPIEntity> entities,String serviceName) throws JsonMappingException, JsonGenerationException, IOException {
-        final String json = marshall(entities);
-        final WebResource r = getWebResource(resourceURL);
-        return putAuthHeaderIfNeeded(r.queryParam(SERVICE_NAME,serviceName).accept(DEFAULT_MEDIA_TYPE))
-                .header(CONTENT_TYPE, DEFAULT_HTTP_HEADER_CONTENT_TYPE)
-                .put(GenericServiceAPIResponseEntity.class, json);
-    }
-
-
-    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 BatchSender batch(int batchSize) {
-        BatchSender batchSender = new BatchSender(this,batchSize);
-        this.register(batchSender);
-        return batchSender;
-    }
-
-    @Override
-    public EagleServiceAsyncClient async() {
-        EagleServiceAsyncClient async = new EagleServiceAsyncClientImpl(this);
-        this.register(async);
-        return async;
-    }
-
-    @Override
-    public ConcurrentSender parallel(int parallelNum) {
-        ConcurrentSender concurrentSender = new ConcurrentSender(this,parallelNum);
-        this.register(concurrentSender);
-        return concurrentSender;
-    }
-
-    @Override
-    public <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> delete(List<E> entities, Class<E> entityClass) throws IOException, EagleServiceClientException {
-        return delete(entities, getServiceNameByClass(entityClass));
-    }
-
-    @Override
-    public <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> create(List<E> entities, Class<E> entityClass) throws IOException, EagleServiceClientException {
-        return create(entities, getServiceNameByClass(entityClass));
-    }
-
-    @Override
-    public <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> update(List<E> entities, Class<E> entityClass) throws IOException, EagleServiceClientException {
-        return update(entities, getServiceNameByClass(entityClass));
-    }
-
-    @Override
-    public void close() throws IOException {
-        if(!this.isStopped) {
-            if(LOG.isDebugEnabled()) LOG.debug("Client is closing");
-            for (Closeable closeable : this.closeables) {
-                try {
-                    closeable.close();
-                } catch (IOException e) {
-                    LOG.error(e.getMessage(), e);
-                    throw e;
-                }
-            }
-        }
-        this.isStopped = true;
-    }
-
-    @Override
-    public DeleteRequestBuilder delete() {
-        return new DeleteRequestBuilder(this);
-    }
-
-    protected void checkNotNull(Object obj,String name) throws EagleServiceClientException{
-        if(obj == null) throw new EagleServiceClientException(name+" should not be null but given");
-    }
-
-    @Override
-    public EagleServiceBaseClient silence(boolean silence) {
-        this.silence = silence;
-        return this;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/impl/EagleServiceClientImpl.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/impl/EagleServiceClientImpl.java b/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/impl/EagleServiceClientImpl.java
deleted file mode 100644
index f70e983..0000000
--- a/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/impl/EagleServiceClientImpl.java
+++ /dev/null
@@ -1,196 +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.service.client.impl;
-
-import eagle.log.base.taggedlog.TaggedLogAPIEntity;
-import eagle.log.entity.GenericServiceAPIResponseEntity;
-import eagle.service.client.EagleServiceClientException;
-import eagle.service.client.EagleServiceSingleEntityQueryRequest;
-import com.sun.jersey.api.client.WebResource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-public class EagleServiceClientImpl extends EagleServiceBaseClient {
-    private final static Logger LOG = LoggerFactory.getLogger(EagleServiceClientImpl.class);
-
-    public EagleServiceClientImpl(String host, int port){
-        super(host, port);
-    }
-
-    public EagleServiceClientImpl(String host, int port, String username, String password){
-        super(host, port, username, password);
-    }
-
-    private String getWholePath(String urlString){
-    	return getBaseEndpoint() + urlString;
-    }
-
-    @Override
-    public <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> create(List<E> entities, String serviceName) throws IOException,EagleServiceClientException {
-        checkNotNull(serviceName,"serviceName");
-        checkNotNull(entities,"entities");
-
-        final GenericServiceAPIResponseEntity<String> response;
-        response = postEntitiesWithService(GENERIC_ENTITY_PATH, entities, serviceName);
-        if (!response.isSuccess()) {
-            LOG.error("Failed to create entities for service: " + serviceName);
-        }
-        return response;
-    }
-
-    @Override
-    public <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> create(List<E> entities) throws IOException, EagleServiceClientException {
-        checkNotNull(entities,"entities");
-
-        Map<String,List<E>> serviceEntityMap = groupEntitiesByService(entities);
-        if(LOG.isDebugEnabled()) LOG.debug("Creating entities for "+serviceEntityMap.keySet().size()+" services");
-
-        List<String> createdKeys = new LinkedList<String>();
-
-        for(Map.Entry<String,List<E>> entry: serviceEntityMap.entrySet()){
-            GenericServiceAPIResponseEntity<String> response = create(entry.getValue(),entry.getKey());
-            if(!response.isSuccess()){
-                throw new IOException("Service side exception: "+response.getException());
-            }else if(response.getObj()!=null){
-                createdKeys.addAll(response.getObj());
-            }
-        }
-        GenericServiceAPIResponseEntity<String> entity = new GenericServiceAPIResponseEntity<String>();
-        entity.setObj(createdKeys);
-        entity.setSuccess(true);
-        return entity;
-    }
-
-    @Override
-    public <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> delete(List<E> entities) throws IOException, EagleServiceClientException {
-        checkNotNull(entities,"entities");
-
-        Map<String,List<E>> serviceEntityMap = groupEntitiesByService(entities);
-        if(LOG.isDebugEnabled()) LOG.debug("Creating entities for "+serviceEntityMap.keySet().size()+" services");
-
-        List<String> deletedKeys = new LinkedList<String>();
-        for(Map.Entry<String,List<E>> entry: serviceEntityMap.entrySet()){
-            GenericServiceAPIResponseEntity<String> response = delete(entry.getValue(), entry.getKey());
-            if(!response.isSuccess()){
-                LOG.error("Got service exception: "+response.getException());
-                throw new IOException(response.getException());
-            }else if(response.getObj()!=null){
-                deletedKeys.addAll(response.getObj());
-            }
-        }
-        GenericServiceAPIResponseEntity<String> entity = new GenericServiceAPIResponseEntity<String>();
-        entity.setObj(deletedKeys);
-        entity.setSuccess(true);
-        return entity;
-    }
-
-    @SuppressWarnings("unchecked")
-    @Override
-    public <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> delete(List<E> entities, String serviceName) throws IOException,EagleServiceClientException {
-        checkNotNull(entities,"entities");
-        checkNotNull(serviceName,"serviceName");
-
-        return postEntitiesWithService(GENERIC_ENTITY_DELETE_PATH,entities,serviceName);
-    }
-
-    @SuppressWarnings("unchecked")
-    @Override
-    public GenericServiceAPIResponseEntity<String> delete(EagleServiceSingleEntityQueryRequest request) throws IOException,EagleServiceClientException {
-        String queryString = request.getQueryParameterString();
-        StringBuilder sb = new StringBuilder();
-        sb.append(GENERIC_ENTITY_PATH);
-        sb.append("?");
-        sb.append(queryString);
-        final String urlString =  sb.toString();
-
-        if(!this.silence) LOG.info("Going to delete by querying service: " + getWholePath(urlString));
-        WebResource r = getWebResource(urlString);
-        return putAuthHeaderIfNeeded(r.accept(DEFAULT_MEDIA_TYPE)
-                                      .header(CONTENT_TYPE, DEFAULT_HTTP_HEADER_CONTENT_TYPE))
-                                      .delete(GenericServiceAPIResponseEntity.class);
-    }
-
-    @SuppressWarnings("unchecked")
-    @Override
-    public GenericServiceAPIResponseEntity<String> deleteById(List<String> ids, String serviceName) throws EagleServiceClientException, IOException {
-        checkNotNull(serviceName,"serviceName");
-        checkNotNull(ids,"ids");
-
-        final String json = marshall(ids);
-        final WebResource r = getWebResource(GENERIC_ENTITY_DELETE_PATH);
-        return putAuthHeaderIfNeeded(r.queryParam(SERVICE_NAME,serviceName)
-                                       .queryParam(DELETE_BY_ID, "true")
-                                       .accept(DEFAULT_MEDIA_TYPE))
-                                       .header(CONTENT_TYPE, DEFAULT_HTTP_HEADER_CONTENT_TYPE)
-                                       .post(GenericServiceAPIResponseEntity.class, json);
-    }
-
-    @Override
-    public <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> update(List<E> entities) throws IOException, EagleServiceClientException {
-        checkNotNull(entities,"entities");
-
-        Map<String,List<E>> serviceEntityMap = groupEntitiesByService(entities);
-        if(LOG.isDebugEnabled()) LOG.debug("Updating entities for "+serviceEntityMap.keySet().size()+" services");
-
-        List<String> createdKeys = new LinkedList<String>();
-
-        for(Map.Entry<String,List<E>> entry: serviceEntityMap.entrySet()){
-            GenericServiceAPIResponseEntity<String> response = update(entry.getValue(), entry.getKey());
-            if(!response.isSuccess()){
-                throw new IOException("Got service exception when updating service "+entry.getKey()+" : "+response.getException());
-            }else{
-                if(response.getObj()!=null) {
-                    createdKeys.addAll(response.getObj());
-                }
-            }
-        }
-
-        GenericServiceAPIResponseEntity<String> entity = new GenericServiceAPIResponseEntity<String>();
-        entity.setObj(createdKeys);
-        entity.setSuccess(true);
-        return entity;
-    }
-
-    @Override
-    public <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> update(List<E> entities, String serviceName) throws IOException, EagleServiceClientException {
-        checkNotNull(entities,"entities");
-        checkNotNull(serviceName,"serviceName");
-
-        return putEntitiesWithService(GENERIC_ENTITY_PATH,entities,serviceName);
-    }
-
-    @Override
-    @SuppressWarnings("unchecked")
-    public <T extends Object> GenericServiceAPIResponseEntity<T> search(EagleServiceSingleEntityQueryRequest request) throws EagleServiceClientException {
-        String queryString = request.getQueryParameterString();
-        StringBuilder sb = new StringBuilder();
-        sb.append(GENERIC_ENTITY_PATH);
-        sb.append("?");
-        sb.append(queryString);
-        final String urlString =  sb.toString();
-        if(!this.silence) LOG.info("Going to query service: " + getWholePath(urlString));
-        WebResource r = getWebResource(urlString);
-        return putAuthHeaderIfNeeded(r.accept(DEFAULT_MEDIA_TYPE))
-                                       .header(CONTENT_TYPE, DEFAULT_HTTP_HEADER_CONTENT_TYPE)
-                                       .get(GenericServiceAPIResponseEntity.class);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/impl/MetricSender.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/impl/MetricSender.java b/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/impl/MetricSender.java
deleted file mode 100644
index 0c2e87e..0000000
--- a/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/impl/MetricSender.java
+++ /dev/null
@@ -1,75 +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.service.client.impl;
-
-import eagle.log.entity.GenericMetricEntity;
-import eagle.service.client.IEagleServiceClient;
-import eagle.service.client.EagleServiceClientException;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-public class MetricSender extends BatchSender {
-    private final String metricName;
-    private Map<String, String> tags;
-
-    public MetricSender(IEagleServiceClient client, String metricName) {
-        super(client,1);
-        this.metricName = metricName;
-    }
-
-    public MetricSender batch(int batchSize) {
-        super.setBatchSize(batchSize);
-        return this;
-    }
-
-    public MetricSender tags(Map<String,String> tags){
-        this.tags = tags;
-        return this;
-    }
-
-    public MetricSender send(String metricName,long timestamp,Map<String,String> tags,double ...values) throws IOException, EagleServiceClientException {
-        GenericMetricEntity metric = new GenericMetricEntity();
-        metric.setPrefix(metricName);
-        metric.setValue(values);
-        metric.setTimestamp(timestamp);
-        metric.setTags(tags);
-        super.send(metric);
-        return this;
-    }
-
-    public MetricSender send(Long timestamp,Map<String,String> tags,double ...values) throws IOException, EagleServiceClientException {
-        return this.send(this.metricName,timestamp,tags,values);
-    }
-
-    public MetricSender send(Long timestamp, double ... values) throws IOException, EagleServiceClientException {
-        return this.send(timestamp,new HashMap<String, String>(this.tags),values);
-    }
-
-//    public EagleServiceMetricSender send(String metricName,Map<String,String> tags,double ... values) throws IOException, EagleServiceClientException {
-//        return this.send(metricName,System.currentTimeMillis(),tags,values);
-//    }
-//
-//    public EagleServiceMetricSender send(Map<String,String> tags,double ...values) throws IOException, EagleServiceClientException {
-//        return this.send(this.metricName,System.currentTimeMillis(),tags,values);
-//    }
-//
-//    public EagleServiceMetricSender send(double ... values) throws IOException, EagleServiceClientException {
-//        return this.send(System.currentTimeMillis(), new HashMap<String, String>(this.tags), values);
-//    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/impl/SearchRequestBuilder.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/impl/SearchRequestBuilder.java b/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/impl/SearchRequestBuilder.java
deleted file mode 100644
index 9880b39..0000000
--- a/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/impl/SearchRequestBuilder.java
+++ /dev/null
@@ -1,97 +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.service.client.impl;
-
-import eagle.log.entity.GenericServiceAPIResponseEntity;
-import eagle.service.client.IEagleServiceClient;
-import eagle.service.client.EagleServiceClientException;
-import eagle.service.client.EagleServiceSingleEntityQueryRequest;
-import eagle.common.DateTimeUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-
-public class SearchRequestBuilder {
-    private final EagleServiceSingleEntityQueryRequest request;
-    private final IEagleServiceClient client;
-    private final static Logger LOG = LoggerFactory.getLogger(SearchRequestBuilder.class);
-
-    public SearchRequestBuilder(IEagleServiceClient client) {
-        this.request = new EagleServiceSingleEntityQueryRequest();
-        this.client = client;
-    }
-
-    public SearchRequestBuilder query(String query){
-        try {
-            this.request.setQuery(URLEncoder.encode(query,"UTF-8"));
-        } catch (UnsupportedEncodingException e) {
-            LOG.error(e.getMessage(),e);
-        }
-        return this;
-    }
-
-    public SearchRequestBuilder startRowkey(String startRowkey){
-        this.request.setStartRowkey(startRowkey);
-        return this;
-    }
-
-    public SearchRequestBuilder pageSize(int pageSize){
-        this.request.setPageSize(pageSize);
-        return this;
-    }
-
-    public SearchRequestBuilder startTime(long startTime){
-        this.request.setStartTime(startTime);
-        return this;
-    }
-
-    public SearchRequestBuilder startTime(String startTime){
-        this.request.setStartTime(DateTimeUtil.humanDateToMillisecondsWithoutException(startTime));
-        return this;
-    }
-
-    public SearchRequestBuilder endTime(long endTime){
-        this.request.setEndTime(endTime);
-        return this;
-    }
-
-    public SearchRequestBuilder endTime(String endTime){
-        this.request.setEndTime(DateTimeUtil.humanDateToMillisecondsWithoutException(endTime));
-        return this;
-    }
-
-    public SearchRequestBuilder treeAgg(boolean treeAgg){
-        this.request.setTreeAgg(treeAgg);
-        return this;
-    }
-
-    public SearchRequestBuilder metricName(String metricName){
-        this.request.setMetricName(metricName);
-        return this;
-    }
-
-    public SearchRequestBuilder filterIfMissing(Boolean filterIfMissing){
-        this.request.setFilterIfMissing(filterIfMissing);
-        return this;
-    }
-
-    public <T> GenericServiceAPIResponseEntity<T> send() throws EagleServiceClientException {
-        return client.search(this.request);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/security/SecurityConstants.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/security/SecurityConstants.java b/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/security/SecurityConstants.java
deleted file mode 100644
index 7818d1f..0000000
--- a/eagle-core/eagle-query/eagle-client-base/src/main/java/eagle/service/client/security/SecurityConstants.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package eagle.service.client.security;
-
-public class SecurityConstants {
-    public static final String AUTHORIZATION = "Authorization";
-    public static final String BASIC_AUTHORIZATION_HEADER_PREFIX = "Basic ";
-}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceAsyncClient.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceAsyncClient.java b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceAsyncClient.java
new file mode 100644
index 0000000..48e71f5
--- /dev/null
+++ b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceAsyncClient.java
@@ -0,0 +1,117 @@
+/*
+ * 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 org.apache.eagle.service.client;
+
+import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
+import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.Future;
+
+/**
+ * @see IEagleServiceClient
+ */
+public interface EagleServiceAsyncClient extends Closeable{
+    /**
+     *
+     * @param <E>
+     * @param entities
+     * @param serviceName
+     * @return
+     */
+    <E extends TaggedLogAPIEntity> Future<GenericServiceAPIResponseEntity<String>> create(final List<E> entities,final String serviceName) throws IOException, EagleServiceClientException;
+
+    /**
+     *
+     * @param entities
+     * @param entityClass
+     * @param <E>
+     * @return
+     */
+    <E extends TaggedLogAPIEntity> Future<GenericServiceAPIResponseEntity<String>> create(final List<E> entities,final Class<E> entityClass) throws IOException, EagleServiceClientException;
+
+    /**
+     *
+     * @param entities
+     * @param <E>
+     * @return
+     */
+    <E extends TaggedLogAPIEntity> Future<GenericServiceAPIResponseEntity<String>> create(final List<E> entities) throws IOException, EagleServiceClientException;
+
+    /**
+     *
+     * @param entities
+     * @param <E>
+     * @return
+     */
+    <E extends TaggedLogAPIEntity> Future<GenericServiceAPIResponseEntity<String>> delete(final List<E> entities) throws IOException, EagleServiceClientException;
+
+    /**
+     *
+     * @param entities
+     * @param <E>
+     * @return
+     */
+    <E extends TaggedLogAPIEntity> Future<GenericServiceAPIResponseEntity<String>> delete(final List<E> entities,final String serviceName) throws IOException, EagleServiceClientException;
+
+    /**
+     *
+     * @param entities
+     * @param <E>
+     * @return
+     */
+    <E extends TaggedLogAPIEntity> Future<GenericServiceAPIResponseEntity<String>> delete(final List<E> entities,final Class<E> entityClass) throws IOException, EagleServiceClientException;
+
+    /**
+     *
+     * @param request
+     * @return
+     */
+    Future<GenericServiceAPIResponseEntity<String>> delete(final EagleServiceSingleEntityQueryRequest request) throws EagleServiceClientException, IOException;
+
+    /**
+     * @param entities
+     * @param <E>
+     * @return
+     */
+    <E extends TaggedLogAPIEntity> Future<GenericServiceAPIResponseEntity<String>> update(final List<E> entities) throws IOException, EagleServiceClientException;
+
+    /**
+     *
+     * @param entities
+     * @param <E>
+     * @return
+     */
+    <E extends TaggedLogAPIEntity> Future<GenericServiceAPIResponseEntity<String>> update(final List<E> entities,final String serviceName) throws IOException, EagleServiceClientException;
+
+    /**
+     *
+     * @param entities
+     * @param <E>
+     * @return
+     */
+    <E extends TaggedLogAPIEntity> Future<GenericServiceAPIResponseEntity<String>> update(final List<E> entities,final Class<E> entityClass) throws IOException, EagleServiceClientException;
+
+    /**
+     *
+     * @param request
+     * @return
+     */
+    <E extends Object> Future<GenericServiceAPIResponseEntity<String>> search(final EagleServiceSingleEntityQueryRequest request) throws EagleServiceClientException;
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceClientException.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceClientException.java b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceClientException.java
new file mode 100644
index 0000000..d3845db
--- /dev/null
+++ b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceClientException.java
@@ -0,0 +1,64 @@
+/*
+ * 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 org.apache.eagle.service.client;
+
+/**
+ * Default Eagle service client exception class
+ */
+public class EagleServiceClientException extends Exception {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1710851110199812779L;
+
+	/**
+	 * Default constructor of EagleServiceClientException
+	 */
+    public EagleServiceClientException() {
+        super();
+    }
+
+    /**
+     * Constructor of EagleServiceClientException
+     * 
+     * @param message error message
+     */
+    public EagleServiceClientException(String message) {
+        super(message);
+    }
+
+    /**
+     * Constructor of EagleServiceClientException
+     * 
+     * @param message error message
+     * @param cause the cause of the exception
+     * 
+     */
+    public EagleServiceClientException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * Constructor of EagleServiceClientException
+     * 
+     * @param cause the cause of the exception
+     */
+    public EagleServiceClientException(Throwable cause) {
+        super(cause);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceGroupByQueryRequest.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceGroupByQueryRequest.java b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceGroupByQueryRequest.java
new file mode 100644
index 0000000..e9e58c3
--- /dev/null
+++ b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceGroupByQueryRequest.java
@@ -0,0 +1,173 @@
+/*
+ * 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 org.apache.eagle.service.client;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.List;
+
+public class EagleServiceGroupByQueryRequest {
+	
+	private String filter;
+	private String startRowkey;
+	private int pageSize;
+	private String startTime;
+	private String endTime;
+	private List<String> groupBys;
+	private List<String> returns;
+	private List<String> orderBys;
+	private String metricName;
+	private int intervalMin;
+	
+	public String getMetricName() {
+		return metricName;
+	}
+	public void setMetricName(String metricName) {
+		this.metricName = metricName;
+	}
+	public String getFilter() {
+		return filter;
+	}
+	public void setFilter(String filter) {
+		this.filter = filter;
+	}
+	public String getStartRowkey() {
+		return startRowkey;
+	}
+	public void setStartRowkey(String startRowkey) {
+		this.startRowkey = startRowkey;
+	}
+	public int getPageSize() {
+		return pageSize;
+	}
+	public void setPageSize(int pageSize) {
+		this.pageSize = pageSize;
+	}
+	public String getStartTime() {
+		return startTime;
+	}
+	public void setStartTime(String startTime) {
+		this.startTime = startTime;
+	}
+	public String getEndTime() {
+		return endTime;
+	}
+	public void setEndTime(String endTime) {
+		this.endTime = endTime;
+	}
+	public List<String> getGroupBys() {
+		return groupBys;
+	}
+	public void setGroupBys(List<String> groupBys) {
+		this.groupBys = groupBys;
+	}
+	public List<String> getOrderBys() {
+		return orderBys;
+	}
+	public void setOrderBys(List<String> orderBys) {
+		this.orderBys = orderBys;
+	}
+	public List<String> getReturns() {
+		return returns;
+	}
+	public void setReturns(List<String> returns) {
+		this.returns = returns;
+	}
+	
+	public String getQueryParameterString(String service) throws EagleServiceClientException {
+		if (pageSize <= 0) {
+			throw new EagleServiceClientException("pageSize can't be less than 1, pageSize: " + pageSize);
+		}
+		try {
+			final String query = getQuery();
+			final StringBuilder sb = new StringBuilder();
+			// query
+			sb.append("query=").append(service).append(URLEncoder.encode(query, "UTF-8"));
+			// startRowkey
+			if (startRowkey != null) {
+				sb.append("&startRowkey=").append(startRowkey);
+			}
+			// pageSize
+			sb.append("&pageSize=").append(this.pageSize);
+			if (startTime != null || endTime != null) {
+				sb.append("&startTime=").append(URLEncoder.encode(startTime, "UTF-8"));
+				sb.append("&endTime=").append(URLEncoder.encode(endTime, "UTF-8"));
+			}
+			
+			// metricName
+			if(metricName != null){
+				sb.append("&metricName=" + metricName);
+			}
+			
+			if (intervalMin != 0) {
+				sb.append("&timeSeries=true&intervalmin=" + intervalMin);
+			}
+			return sb.toString();
+		} catch (UnsupportedEncodingException e) {
+			throw new EagleServiceClientException("Got an UnsupportedEncodingException" + e.getMessage(), e);
+		}
+	}
+	
+	private String getQuery() {
+		final StringBuilder sb = new StringBuilder();
+		sb.append("[").append(filter).append("]<");
+		boolean first = true;
+		if (groupBys != null && groupBys.size() > 0) {
+			for (String groupBy : groupBys) {
+				if (first) {
+					first = false;
+				} else {
+					sb.append(",");
+				}
+				sb.append("@").append(groupBy);
+			}
+		}
+		sb.append(">{");
+		if (returns != null && returns.size() > 0) {
+			first = true;
+			for (String returnFiled : returns) {
+				if (first) {
+					first = false;
+				} else {
+					sb.append(",");
+				}
+				sb.append(returnFiled);
+			}
+		}
+		sb.append("}");
+		if (orderBys != null && orderBys.size() > 0) {
+			sb.append(".{");
+			first = true;
+			for (String orderBy : orderBys) {
+				if (first) {
+					first = false;
+				} else {
+					sb.append(",");
+				}
+				sb.append(orderBy);
+			}
+			sb.append("}");
+		}
+		return sb.toString();
+	}
+	public int getIntervalMin() {
+		return intervalMin;
+	}
+	public void setIntervalMin(int intervalMin) {
+		this.intervalMin = intervalMin;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceQueryBuilder.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceQueryBuilder.java b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceQueryBuilder.java
new file mode 100644
index 0000000..106ebc6
--- /dev/null
+++ b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceQueryBuilder.java
@@ -0,0 +1,107 @@
+/*
+ * 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 org.apache.eagle.service.client;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Builder helper class to create EagleServiceQueryRequest
+ */
+public final class EagleServiceQueryBuilder {
+
+	private final EagleServiceQueryRequest request = new EagleServiceQueryRequest();
+	
+	public EagleServiceQueryBuilder addSearchTag(String tagKey, String tagValue) throws EagleServiceClientException {
+		if (tagKey == null || tagValue == null) {
+			throw new EagleServiceClientException("tagKey or tagValue is null, tagKey: " + tagKey + ", tagValue: " + tagValue);
+		}
+		List<EagleServiceQueryRequest.Tag> searchTags = request.getSearchTags();
+		if (searchTags == null) {
+			searchTags = new ArrayList<EagleServiceQueryRequest.Tag>();
+			request.setSearchTags(searchTags);
+		}
+		if (!containsTag(tagKey, tagValue)) {
+			final EagleServiceQueryRequest.Tag tag = new EagleServiceQueryRequest.Tag();
+			tag.setKey(tagKey);
+			tag.setValue(tagValue);
+			searchTags.add(tag);
+		}
+		return this;
+	}
+	
+	public EagleServiceQueryRequest buildRequest() throws EagleServiceClientException {
+		return request;
+	}
+	
+	public EagleServiceQueryBuilder setStartTime(long startTime) {
+		request.setStartTime(startTime);
+		return this;
+	}
+	
+	public EagleServiceQueryBuilder setEndTime(long endTime) {
+		request.setEndTime(endTime);
+		return this;
+	}
+	
+	public EagleServiceQueryBuilder setPageSize(int pageSize) throws EagleServiceClientException {
+		if (pageSize <= 0) {
+			throw new EagleServiceClientException("pageSize can't be less than 1");
+		}
+		request.setPageSize(pageSize);
+		return this;
+	}
+
+	public EagleServiceQueryBuilder addReturnTag(String tagKey) throws EagleServiceClientException {
+		if (tagKey == null) {
+			throw new EagleServiceClientException("tagKey can't be null");
+		}
+		List<String> returnTags = request.getReturnTags();
+		if (returnTags == null) {
+			returnTags = new ArrayList<String>();
+			request.setReturnTags(returnTags);
+		}
+		if (!returnTags.contains(tagKey)) {
+			returnTags.add(tagKey);
+		}
+		return this;
+	}
+	
+	public EagleServiceQueryBuilder addReturnField(String field) throws EagleServiceClientException {
+		if (field == null) {
+			throw new EagleServiceClientException("field can't be null");
+		}
+		List<String> returnFields = request.getReturnFields();
+		if (returnFields == null) {
+			returnFields = new ArrayList<String>();
+			request.setReturnFields(returnFields);
+		}
+		if (!returnFields.contains(field)) {
+			returnFields.add(field);
+		}
+		return this;
+	}
+
+	private boolean containsTag(String tagKey, String tagValue) {
+		for (EagleServiceQueryRequest.Tag tag : request.getSearchTags()) {
+			if (tag.getKey().equals(tagKey) && tag.getValue().equals(tagValue)) {
+				return true;
+			}
+		}
+		return false;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceQueryRequest.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceQueryRequest.java b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceQueryRequest.java
new file mode 100644
index 0000000..37dcb44
--- /dev/null
+++ b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceQueryRequest.java
@@ -0,0 +1,151 @@
+/*
+ * 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 org.apache.eagle.service.client;
+
+import org.apache.eagle.common.config.EagleConfigFactory;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Eagle service query parameter request
+ */
+public class EagleServiceQueryRequest {
+
+	// instance members
+	private long startTime;
+	private long endTime;
+	private int pageSize;
+	private List<Tag> searchTags;
+	private List<String> returnTags;
+	private List<String> returnFields;
+
+	public static class Tag {
+		private String key;
+		private String value;
+		
+		public String getKey() {
+			return key;
+		}
+		public void setKey(String key) {
+			this.key = key;
+		}
+		public String getValue() {
+			return value;
+		}
+		public void setValue(String value) {
+			this.value = value;
+		}
+	}
+
+	public long getStartTime() {
+		return startTime;
+	}
+
+	public void setStartTime(long startTime) {
+		this.startTime = startTime;
+	}
+
+	public long getEndTime() {
+		return endTime;
+	}
+
+	public void setEndTime(long endTime) {
+		this.endTime = endTime;
+	}
+
+	public int getPageSize() {
+		return pageSize;
+	}
+
+	public void setPageSize(int pageSize) {
+		this.pageSize = pageSize;
+	}
+
+	public List<Tag> getSearchTags() {
+		return searchTags;
+	}
+
+	public void setSearchTags(List<Tag> searchTags) {
+		this.searchTags = searchTags;
+	}
+
+	public List<String> getReturnTags() {
+		return returnTags;
+	}
+
+	public void setReturnTags(List<String> returnTags) {
+		this.returnTags = returnTags;
+	}
+
+	public List<String> getReturnFields() {
+		return returnFields;
+	}
+
+	public void setReturnFields(List<String> returnFields) {
+		this.returnFields = returnFields;
+	}
+
+	public String getQueryParameterString() throws EagleServiceClientException {
+		if (pageSize <= 0) {
+			throw new EagleServiceClientException("pageSize can't be less than 1, pageSize: " + pageSize);
+		}
+		if (startTime > endTime || (startTime == endTime && startTime != 0)) {
+			throw new EagleServiceClientException("Invalid startTime and endTime, startTime: " + startTime + ", endTime: " + endTime);
+		}
+		int returnSize = 0;
+		if (returnTags != null) {
+			returnSize += returnTags.size();
+		}
+		if (returnFields != null) {
+			returnSize += returnFields.size();
+		}
+		if (returnSize == 0) {
+			throw new EagleServiceClientException("Invalid request, no return tag or field added");
+		}
+		final StringBuilder sb = new StringBuilder();
+		sb.append("pageSize=").append(this.pageSize);
+		if (endTime > 0) {
+			final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd%20HH:mm:ss");
+            format.setTimeZone(EagleConfigFactory.load().getTimeZone());
+			Date date = new Date(startTime);
+			String timeString = format.format(date);
+			sb.append("&startTime=").append(timeString);
+			date.setTime(endTime);
+			timeString = format.format(date);
+			sb.append("&endTime=").append(timeString);
+		}
+		if (searchTags != null) {
+			for (Tag tag : searchTags) {
+				sb.append("&tagNameValue=").append(tag.getKey()).append("%3D").append(tag.getValue());
+			}
+		}
+		if (returnTags != null) {
+			for (String tagKey : returnTags) {
+				sb.append("&outputTag=").append(tagKey);
+			}
+		}
+		if (returnFields != null) {
+			for (String field : returnFields) {
+				sb.append("&outputField=").append(field);
+			}
+		}
+		return sb.toString();
+	}
+	
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceSingleEntityQueryRequest.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceSingleEntityQueryRequest.java b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceSingleEntityQueryRequest.java
new file mode 100755
index 0000000..58b2764
--- /dev/null
+++ b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceSingleEntityQueryRequest.java
@@ -0,0 +1,211 @@
+/*
+ * 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 org.apache.eagle.service.client;
+
+import org.apache.eagle.common.config.EagleConfigFactory;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class EagleServiceSingleEntityQueryRequest {
+	private String query;
+	private String startRowkey;
+	private int pageSize;
+	private long startTime;
+	private long endTime;
+	private boolean treeAgg;
+	private String metricName;
+	private boolean filterIfMissing;
+
+    public boolean isVerbose() {
+        return verbose;
+    }
+
+    public void setVerbose(boolean verbose) {
+        this.verbose = verbose;
+    }
+
+    private boolean verbose;
+	
+	public String getMetricName() {
+		return metricName;
+	}
+
+	public void setMetricName(String metricName) {
+		this.metricName = metricName;
+	}
+
+	public String getQuery() {
+		return query;
+	}
+
+	public void setQuery(String query) {
+		this.query = query;
+	}
+
+	public String getStartRowkey() {
+		return startRowkey;
+	}
+
+	public void setStartRowkey(String startRowkey) {
+		this.startRowkey = startRowkey;
+	}
+
+	public boolean isTreeAgg() {
+		return treeAgg;
+	}
+
+	public void setTreeAgg(boolean treeAgg) {
+		this.treeAgg = treeAgg;
+	}
+
+	public long getStartTime() {
+		return startTime;
+	}
+
+	public void setStartTime(long startTime) {
+		this.startTime = startTime;
+	}
+
+	public long getEndTime() {
+		return endTime;
+	}
+
+	public void setEndTime(long endTime) {
+		this.endTime = endTime;
+	}
+
+	public int getPageSize() {
+		return pageSize;
+	}
+
+	public void setPageSize(int pageSize) {
+		this.pageSize = pageSize;
+	}
+	
+	public boolean getFilterIfMissing() {
+		return filterIfMissing;
+	}
+
+	public void setFilterIfMissing(boolean filterIfMissing) {
+		this.filterIfMissing = filterIfMissing;
+	}
+
+	public String getQueryParameterString() throws EagleServiceClientException {
+		if (pageSize < 0) {
+			throw new EagleServiceClientException("pageSize can't be less than 0, pageSize: " + pageSize);
+		}
+
+		// startTime and endTime is optional
+		
+		final StringBuilder sb = new StringBuilder();
+		// query
+//        try {
+//            sb.append("query=").append(URLEncoder.encode(query,"UTF-8"));
+            sb.append("query=").append(query);
+//        } catch (UnsupportedEncodingException e) {
+//            throw new EagleServiceClientException(e);
+//        }
+
+        // startRowkey
+		if (startRowkey != null) {
+			sb.append("&startRowkey=").append(startRowkey);
+		}
+		// pageSize
+		sb.append("&pageSize=").append(this.pageSize);
+		if (startTime !=0 || endTime != 0) {
+			Date date = new Date(startTime);
+			SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd%20HH:mm:ss");
+            dateFormatter.setTimeZone(EagleConfigFactory.load().getTimeZone());
+			String timeString = dateFormatter.format(date);
+			sb.append("&startTime=").append(timeString);
+			date.setTime(endTime);
+			timeString = dateFormatter.format(date);
+			sb.append("&endTime=").append(timeString);
+		}
+		// tree aggregate
+		sb.append("&treeAgg=").append(treeAgg);
+		
+		// for metric read
+		if(metricName != null){
+			sb.append("&metricName=").append(metricName);
+		}
+		
+		if (filterIfMissing == true) { 
+			sb.append("&filterIfMissing=").append("true");
+		}
+		return sb.toString();
+	}
+
+    public static Builder build(){
+        return new Builder();
+    }
+
+    public static class Builder{
+        private final EagleServiceSingleEntityQueryRequest rawQuery;
+        public Builder(){
+            this.rawQuery= new EagleServiceSingleEntityQueryRequest();
+        }
+        public EagleServiceSingleEntityQueryRequest done(){
+            return this.rawQuery;
+        }
+        public Builder query(String query) {
+            this.rawQuery.setQuery(query);
+            return this;
+        }
+
+        public Builder startTime(long startTime) {
+            this.rawQuery.setStartTime(startTime);
+            return this;
+        }
+
+        public Builder endTime(long endTime) {
+            this.rawQuery.setEndTime(endTime);
+            return this;
+        }
+
+        public Builder pageSize(int pageSize) {
+            this.rawQuery.setPageSize(pageSize);
+            return this;
+        }
+
+        public Builder startRowkey(String startRowkey) {
+            this.rawQuery.setStartRowkey(startRowkey);
+            return this;
+        }
+
+        public Builder treeAgg(boolean treeAgg) {
+            this.rawQuery.setTreeAgg(treeAgg);
+            return this;
+        }
+
+        public Builder filerIfMissing(boolean filterIfMissing) {
+            this.rawQuery.setFilterIfMissing(filterIfMissing);
+            return this;
+        }
+
+        public Builder metricName(String metricName) {
+            this.rawQuery.setMetricName(metricName);
+            return this;
+        }
+
+        public Builder verbose(Boolean verbose) {
+            this.rawQuery.setVerbose(verbose);
+            return this;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/IEagleServiceClient.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/IEagleServiceClient.java b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/IEagleServiceClient.java
new file mode 100644
index 0000000..ce62eee
--- /dev/null
+++ b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/IEagleServiceClient.java
@@ -0,0 +1,129 @@
+/*
+ * 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 org.apache.eagle.service.client;
+
+import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
+import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity;
+import com.sun.jersey.api.client.Client;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.List;
+
+public interface IEagleServiceClient extends IEagleServiceRequestBuilder, Closeable {
+
+    Client getJerseyClient();
+
+    IEagleServiceClient silence(boolean silence);
+
+    /**
+     *
+     * @param <E>
+     * @param entities
+     * @param serviceName
+     * @return
+     */
+    <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> create(List<E> entities,String serviceName) throws IOException, EagleServiceClientException;
+
+    /**
+     *
+     * @param entities
+     * @param entityClass
+     * @param <E>
+     * @return
+     */
+    <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> create(List<E> entities,Class<E> entityClass) throws IOException, EagleServiceClientException;
+
+    /**
+     *
+     * @param entities
+     * @param <E>
+     * @return
+     */
+    <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> create(List<E> entities) throws IOException, EagleServiceClientException;
+
+    /**
+     *
+     * @param entities
+     * @param <E>
+     * @return
+     */
+    <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> delete(List<E> entities) throws IOException, EagleServiceClientException;
+
+    /**
+     *
+     * @param entities
+     * @param <E>
+     * @return
+     */
+    <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> delete(List<E> entities,String serviceName) throws IOException, EagleServiceClientException;
+
+    /**
+     *
+     * @param entities
+     * @param <E>
+     * @return
+     */
+    <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> delete(List<E> entities,Class<E> entityClass) throws IOException, EagleServiceClientException;
+
+    /**
+     *
+     * @param request
+     * @return
+     */
+    GenericServiceAPIResponseEntity<String> delete(EagleServiceSingleEntityQueryRequest request) throws EagleServiceClientException, IOException;
+
+    /**
+     *
+     * @param ids
+     * @param serviceName
+     * @return
+     * @throws EagleServiceClientException
+     * @throws IOException
+     */
+    GenericServiceAPIResponseEntity<String> deleteById(List<String> ids,String serviceName) throws EagleServiceClientException, IOException;
+
+    /**
+     * @param entities
+     * @param <E>
+     * @return
+     */
+    <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> update(List<E> entities) throws IOException, EagleServiceClientException;
+
+    /**
+     *
+     * @param entities
+     * @param <E>
+     * @return
+     */
+    <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> update(List<E> entities,String serviceName) throws IOException, EagleServiceClientException;
+
+    /**
+     *
+     * @param entities
+     * @param <E>
+     * @return
+     */
+    <E extends TaggedLogAPIEntity> GenericServiceAPIResponseEntity<String> update(List<E> entities,Class<E> entityClass) throws IOException, EagleServiceClientException;
+
+    /**
+     *
+     * @param request
+     * @return
+     */
+    <E extends Object> GenericServiceAPIResponseEntity<E> search(EagleServiceSingleEntityQueryRequest request) throws EagleServiceClientException;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/IEagleServiceRequestBuilder.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/IEagleServiceRequestBuilder.java b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/IEagleServiceRequestBuilder.java
new file mode 100644
index 0000000..1264b30
--- /dev/null
+++ b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/IEagleServiceRequestBuilder.java
@@ -0,0 +1,83 @@
+/*
+ * 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 org.apache.eagle.service.client;
+
+import org.apache.eagle.service.client.impl.*;
+
+/**
+ *
+ * IEagleServiceClient extension interfaces
+ *
+ * @see IEagleServiceClient
+ */
+public interface IEagleServiceRequestBuilder {
+    /**
+     * Search pipe API
+     *
+     * @return
+     */
+    SearchRequestBuilder search();
+
+    /**
+     * Search pipe API
+     *
+     * @param query
+     * @return
+     */
+    SearchRequestBuilder search(String query);
+
+    /**
+     *
+     * Delete pipe API
+     *
+     * @return
+     */
+    DeleteRequestBuilder delete();
+
+    /**
+     * Metric sender
+     *
+     * @param metricName
+     * @return
+     */
+    MetricSender metric(String metricName);
+
+    /**
+     * Batch entities sender
+     *
+     * @param batchSize
+     * @return
+     */
+    BatchSender batch(int batchSize);
+
+    /**
+     * Async service client requester
+     *
+     * @return
+     */
+    EagleServiceAsyncClient async();
+
+    /**
+     * Parallel service client requester
+     *
+     * @param parallelNum
+     * @return
+     */
+    ConcurrentSender parallel(int parallelNum);
+
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/ListGroupByQueryAPIResponseEntity.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/ListGroupByQueryAPIResponseEntity.java b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/ListGroupByQueryAPIResponseEntity.java
new file mode 100644
index 0000000..e59513b
--- /dev/null
+++ b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/ListGroupByQueryAPIResponseEntity.java
@@ -0,0 +1,90 @@
+/*
+ * 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 org.apache.eagle.service.client;
+
+import java.util.List;
+import java.util.Map;
+
+public class ListGroupByQueryAPIResponseEntity {
+
+	private boolean success;
+	private String exception;
+	private int totalResults;
+	private long elapsedms;
+	private List<Entry> obj;
+	private long lastTimestamp;
+
+	public long getElapsedms() {
+		return elapsedms;
+	}
+	public void setElapsedms(long elapsedms) {
+		this.elapsedms = elapsedms;
+	}
+	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 int getTotalResults() {
+		return totalResults;
+	}
+	public void setTotalResults(int totalResults) {
+		this.totalResults = totalResults;
+	}
+	public List<Entry> getObj() {
+		return obj;
+	}
+	public void setObj(List<Entry> obj) {
+		this.obj = obj;
+	}
+	
+	public long getLastTimestamp() {
+		return lastTimestamp;
+	}
+
+	public void setLastTimestamp(long lastTimestamp) {
+		this.lastTimestamp = lastTimestamp;
+	}
+
+	public static class Entry implements Map.Entry<List<String>, List<Double>> {
+
+		private List<String> key;
+		private List<Double> value;
+		public List<String> getKey() {
+			return key;
+		}
+		public void setKey(List<String> key) {
+			this.key = key;
+		}
+		public List<Double> getValue() {
+			return value;
+		}
+		@Override
+		public List<Double> setValue(List<Double> value) {
+			List<Double> old = this.value;
+			this.value = value;
+			return old;
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/ListQueryAPIResponseConvertHelper.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/ListQueryAPIResponseConvertHelper.java b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/ListQueryAPIResponseConvertHelper.java
new file mode 100644
index 0000000..3e71f4e
--- /dev/null
+++ b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/ListQueryAPIResponseConvertHelper.java
@@ -0,0 +1,117 @@
+/*
+ * 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 org.apache.eagle.service.client;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
+import org.apache.eagle.log.entity.ListQueryAPIResponseEntity;
+
+/**
+ * TODO: It's just a temporary solution. We need fix jersy and jackson mapping issue so the class
+ * can be safely removed. 
+ *
+ */
+public final class ListQueryAPIResponseConvertHelper {
+
+	
+	private static final Map<Class<?>, Map<String, Method>> BEAN_SETTER_MAP = new ConcurrentHashMap<Class<?>, Map<String, Method>>();
+	private static final String SETTER_PREFIX = "set";
+	
+	@SuppressWarnings({ "unchecked" })
+	public static ListQueryAPIResponseEntity convert(Class<? extends TaggedLogAPIEntity> clazz, ListQueryAPIResponseEntity response) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, JsonGenerationException, JsonMappingException, IOException {
+		if (response == null || response.getObj() == null) {
+			return response;
+		}
+		final List<TaggedLogAPIEntity> entities = new ArrayList<TaggedLogAPIEntity>();
+		final Object obj = response.getObj();
+		final Map<String, Method> settings = getOrCreateSetterMap(clazz);
+		final Collection<Map<String, Object>> objs = (Collection<Map<String, Object>>) obj;
+		for (Map<String, Object> map : objs) {
+			final TaggedLogAPIEntity entity = clazz.newInstance();
+			for (Map.Entry<String, Object> entry : map.entrySet()) {
+				final String propertyName = entry.getKey();
+				Object value = entry.getValue();
+				final Method method = settings.get(propertyName);
+				final Type type = method.getGenericParameterTypes()[0];
+				if ((type == double.class || type == Double.class || type == long.class || type == Long.class)
+					&& (value.equals("NaN"))) {
+					value = 0;
+				}					
+				
+				final Class<?> parameterClass = method.getParameterTypes()[0];
+				if (value instanceof Number || value instanceof String || parameterClass.isInstance(value)) {
+					try {
+						method.invoke(entity, value);
+					}
+					catch (Exception e){
+						e.printStackTrace();
+					}
+				} else {
+					ObjectMapper om = new ObjectMapper();
+					String objJson = om.writeValueAsString(value);
+					value = om.readValue(objJson, parameterClass);
+					method.invoke(entity, value);
+				}
+			}
+			entities.add(entity);
+		}
+		response.setObj(entities);
+		return response;
+	}
+	
+	private static Map<String, Method> getOrCreateSetterMap(Class<?> clazz) {
+		Map<String, Method> setterMap = BEAN_SETTER_MAP.get(clazz);
+		if (setterMap == null) {
+			setterMap = createSetterMap(clazz);
+		}
+		return setterMap;
+	}
+
+	private static Map<String, Method> createSetterMap(Class<?> clazz) {
+		final Map<String, Method> setterMap = new HashMap<String, Method>();
+		final Method[] methods = clazz.getMethods();
+		final StringBuilder sb = new StringBuilder(100);
+		for (Method m : methods) {
+			final String methodName = m.getName();
+			if (methodName.startsWith(SETTER_PREFIX) && methodName.length() > SETTER_PREFIX.length()) {
+				sb.setLength(0);
+				final char c = methodName.charAt(3);
+				sb.append(Character.toLowerCase(c));
+				sb.append(methodName.substring(4));
+				String propertyName = sb.toString(); 
+				setterMap.put(propertyName, m);
+			}
+		}
+		BEAN_SETTER_MAP.put(clazz, setterMap);
+		return setterMap;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/ListTimeSeriesQueryAPIResponseEntity.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/ListTimeSeriesQueryAPIResponseEntity.java b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/ListTimeSeriesQueryAPIResponseEntity.java
new file mode 100644
index 0000000..80c6aeb
--- /dev/null
+++ b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/ListTimeSeriesQueryAPIResponseEntity.java
@@ -0,0 +1,84 @@
+/*
+ * 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 org.apache.eagle.service.client;
+
+import java.util.List;
+import java.util.Map;
+
+import org.codehaus.jackson.annotate.JsonPropertyOrder;
+
+@JsonPropertyOrder({ "success", "exception", "elapsems", "totalResults", "elapsedms", "obj" })
+public class ListTimeSeriesQueryAPIResponseEntity {
+
+	private boolean success;
+	private String exception;
+	private int totalResults;
+	private long elapsedms;
+	private List<Entry> obj;
+
+	public long getElapsedms() {
+		return elapsedms;
+	}
+	public void setElapsedms(long elapsedms) {
+		this.elapsedms = elapsedms;
+	}
+	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 int getTotalResults() {
+		return totalResults;
+	}
+	public void setTotalResults(int totalResults) {
+		this.totalResults = totalResults;
+	}
+	public List<Entry> getObj() {
+		return obj;
+	}
+	public void setObj(List<Entry> obj) {
+		this.obj = obj;
+	}
+	
+	public static class Entry implements Map.Entry<List<String>, List<double[]>> {
+
+		private List<String> key;
+		private List<double[]> value;
+		public List<String> getKey() {
+			return key;
+		}
+		public void setKey(List<String> key) {
+			this.key = key;
+		}
+		public List<double[]> getValue() {
+			return value;
+		}
+		@Override
+		public List<double[]> setValue(List<double[]> value) {
+			List<double[]> old = this.value;
+			this.value = value;
+			return old;
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/RowkeyQueryAPIResponseConvertHelper.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/RowkeyQueryAPIResponseConvertHelper.java b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/RowkeyQueryAPIResponseConvertHelper.java
new file mode 100644
index 0000000..7dc39f0
--- /dev/null
+++ b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/RowkeyQueryAPIResponseConvertHelper.java
@@ -0,0 +1,110 @@
+/*
+ * 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 org.apache.eagle.service.client;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
+import org.apache.eagle.log.entity.RowkeyQueryAPIResponseEntity;
+
+/**
+ * TODO: It's just a temporary solution. We need fix jersy and jackson mapping issue so the class
+ * can be safely removed. 
+ *
+ */
+public final class RowkeyQueryAPIResponseConvertHelper {
+
+	
+	private static final Map<Class<?>, Map<String, Method>> BEAN_SETTER_MAP = new ConcurrentHashMap<Class<?>, Map<String, Method>>();
+	private static final String SETTER_PREFIX = "set";
+	
+	@SuppressWarnings({ "unchecked" })
+	public static RowkeyQueryAPIResponseEntity convert(Class<? extends TaggedLogAPIEntity> clazz, RowkeyQueryAPIResponseEntity response) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, JsonGenerationException, JsonMappingException, IOException {
+		if (response == null || response.getObj() == null) {
+			return response;
+		}		
+		final Object obj = response.getObj();
+		final Map<String, Method> settings = getOrCreateSetterMap(clazz);
+		final Map<String, Object> map = (Map<String, Object>) obj;
+		final TaggedLogAPIEntity entity = clazz.newInstance();
+		for (Map.Entry<String, Object> entry : map.entrySet()) {
+			final String propertyName = entry.getKey();
+			Object value = entry.getValue();
+			final Method method = settings.get(propertyName);
+			final Type type = method.getGenericParameterTypes()[0];
+			if ((type == double.class || type == Double.class || type == long.class || type == Long.class)
+				&& (value.equals("NaN"))) {
+				value = 0;
+			}					
+			
+			final Class<?> parameterClass = method.getParameterTypes()[0];
+			if (value instanceof Number || value instanceof String || parameterClass.isInstance(value)) {
+				try {
+					method.invoke(entity, value);
+				}
+				catch (Exception e){
+					e.printStackTrace();
+				}
+			} else {
+				ObjectMapper om = new ObjectMapper();
+				String objJson = om.writeValueAsString(value);
+				value = om.readValue(objJson, parameterClass);
+				method.invoke(entity, value);
+			}
+		}
+		response.setObj(entity);
+		return response;
+	}
+	
+	private static Map<String, Method> getOrCreateSetterMap(Class<?> clazz) {
+		Map<String, Method> setterMap = BEAN_SETTER_MAP.get(clazz);
+		if (setterMap == null) {
+			setterMap = createSetterMap(clazz);
+		}
+		return setterMap;
+	}
+
+	private static Map<String, Method> createSetterMap(Class<?> clazz) {
+		final Map<String, Method> setterMap = new HashMap<String, Method>();
+		final Method[] methods = clazz.getMethods();
+		final StringBuilder sb = new StringBuilder(100);
+		for (Method m : methods) {
+			final String methodName = m.getName();
+			if (methodName.startsWith(SETTER_PREFIX) && methodName.length() > SETTER_PREFIX.length()) {
+				sb.setLength(0);
+				final char c = methodName.charAt(3);
+				sb.append(Character.toLowerCase(c));
+				sb.append(methodName.substring(4));
+				String propertyName = sb.toString(); 
+				setterMap.put(propertyName, m);
+			}
+		}
+		BEAN_SETTER_MAP.put(clazz, setterMap);
+		return setterMap;
+	}
+
+}


Mime
View raw message