You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@griffin.apache.org by gu...@apache.org on 2017/06/13 02:35:00 UTC

[1/2] incubator-griffin git commit: 20170613 10 30service

Repository: incubator-griffin
Updated Branches:
  refs/heads/master a45937dd0 -> ae6a308b2


http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/test/java/org/apache/griffin/core/measure/repo/MeasureControllerTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/measure/repo/MeasureControllerTest.java b/service/src/test/java/org/apache/griffin/core/measure/repo/MeasureControllerTest.java
deleted file mode 100644
index b5ca9d0..0000000
--- a/service/src/test/java/org/apache/griffin/core/measure/repo/MeasureControllerTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*-
- * Licensed 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.griffin.core.measure.repo;
-
-import org.apache.griffin.core.measure.*;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
-import org.springframework.boot.test.mock.mockito.MockBean;
-import org.springframework.http.MediaType;
-import org.springframework.test.context.junit4.SpringRunner;
-import org.springframework.test.web.servlet.MockMvc;
-
-import java.io.IOException;
-import java.util.HashMap;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.mockito.BDDMockito.given;
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
-
-@RunWith(SpringRunner.class)
-@WebMvcTest(value=MeasureController.class,secure = false)
-public class MeasureControllerTest {
-    @Autowired
-    private MockMvc mvc;
-
-    @MockBean
-    private MeasureService service;
-
-    @Before
-    public void setup(){
-    }
-
-
-    @Test
-    public void testGetAllMeasures() throws IOException,Exception{
-        Measure measure = createATestMeasure("viewitem_hourly","bullseye");
-
-        given(service.getMeasuresById(1L)).willReturn(measure);
-
-        mvc.perform(get("/measures/1").contentType(MediaType.APPLICATION_JSON))
-//                .andDo(print())
-                .andExpect(status().isOk())
-                .andExpect(jsonPath("$.name",is("viewitem_hourly")))
-        ;
-    }
-
-    @Test
-    public void testGetMeasureByName() throws IOException,Exception{
-
-        Measure measure = createATestMeasure("viewitem_hourly","bullseye");
-
-        given(service.getMeasuresByName("viewitem_hourly")).willReturn(measure);
-
-        mvc.perform(get("/measures/findByName/viewitem_hourly").contentType(MediaType.APPLICATION_JSON))
-//                .andDo(print())
-                .andExpect(status().isOk())
-                .andExpect(jsonPath("$.name",is("viewitem_hourly")))
-        ;
-    }
-
-    private Measure createATestMeasure(String name,String org)throws IOException,Exception{
-        HashMap<String,String> configMap1=new HashMap<>();
-        configMap1.put("database","default");
-        configMap1.put("table.name","test_data_src");
-        HashMap<String,String> configMap2=new HashMap<>();
-        configMap2.put("database","default");
-        configMap2.put("table.name","test_data_tgt");
-        String configJson1 = new ObjectMapper().writeValueAsString(configMap1);
-        String configJson2 = new ObjectMapper().writeValueAsString(configMap2);
-
-        DataConnector source = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson1);
-        DataConnector target = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson2);
-
-        String rules = "$source.uage > 100 AND $source.uid = $target.uid AND $source.uage + 12 = $target.uage + 10 + 2 AND $source.udes + 11 = $target.udes + 1 + 1";
-
-        EvaluateRule eRule = new EvaluateRule(1,rules);
-
-        Measure measure = new Measure(name,"bevssoj description", Measure.MearuseType.accuracy, org, source, target, eRule,"test1");
-
-        return measure;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/test/java/org/apache/griffin/core/measure/repo/MeasureRepoTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/measure/repo/MeasureRepoTest.java b/service/src/test/java/org/apache/griffin/core/measure/repo/MeasureRepoTest.java
index ce5ab72..0f63555 100644
--- a/service/src/test/java/org/apache/griffin/core/measure/repo/MeasureRepoTest.java
+++ b/service/src/test/java/org/apache/griffin/core/measure/repo/MeasureRepoTest.java
@@ -15,8 +15,6 @@ limitations under the License.
 
 package org.apache.griffin.core.measure.repo;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.griffin.core.measure.DataConnector;
 import org.apache.griffin.core.measure.EvaluateRule;
 import org.apache.griffin.core.measure.Measure;
@@ -44,97 +42,21 @@ public class MeasureRepoTest {
     private MeasureRepo measureRepo;
 
     @Before
-    public void setup(){
+    public void setup() throws Exception {
         entityManager.clear();
         entityManager.flush();
+        setEntityManager();
     }
 
     @Test
-    public void testFindAllOrganizations(){
-        HashMap<String,String> configMap1=new HashMap<>();
-        configMap1.put("database","default");
-        configMap1.put("table.name","test_data_src");
-        HashMap<String,String> configMap2=new HashMap<>();
-        configMap2.put("database","default");
-        configMap2.put("table.name","test_data_tgt");
-        String configJson1 = null;
-        String configJson2 = null;
-        try {
-            configJson1 = new ObjectMapper().writeValueAsString(configMap1);
-            configJson2 = new ObjectMapper().writeValueAsString(configMap2);
-        } catch (JsonProcessingException e) {
-            e.printStackTrace();
-        }
-
-        DataConnector source = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson1);
-        DataConnector target = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson2);
-
-        String rules = "$source.uage > 100 AND $source.uid = $target.uid AND $source.uage + 12 = $target.uage + 10 + 2 AND $source.udes + 11 = $target.udes + 1 + 1";
-
-        EvaluateRule eRule = new EvaluateRule(1,rules);
-
-        Measure measure = new Measure("m1","bevssoj description", Measure.MearuseType.accuracy, "bullseye", source, target, eRule,"owner1");
-        entityManager.persistAndFlush(measure);
-
-        DataConnector source2 = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson1);
-        DataConnector target2 = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson2);
-        EvaluateRule eRule2 = new EvaluateRule(1,rules);
-        Measure measure2 = new Measure("m2","test description", Measure.MearuseType.accuracy, "org1", source2, target2, eRule2,"owner1");
-        entityManager.persistAndFlush(measure2);
-
-        DataConnector source3 = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson1);
-        DataConnector target3 = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson2);
-        EvaluateRule eRule3 = new EvaluateRule(1,rules);
-        Measure measure3 = new Measure("m3","test_just_inthere description", Measure.MearuseType.accuracy, "org2", source3, target3, eRule3,"owner1");
-        entityManager.persistAndFlush(measure3);
-
-
+    public void testFindAllOrganizations() throws Exception {
         List<String> orgs = measureRepo.findOrganizations();
         assertThat(orgs.size()).isEqualTo(3);
-
     }
 
 
     @Test
-    public void testFindNameByOrganization(){
-        HashMap<String,String> configMap1=new HashMap<>();
-        configMap1.put("database","default");
-        configMap1.put("table.name","test_data_src");
-        HashMap<String,String> configMap2=new HashMap<>();
-        configMap2.put("database","default");
-        configMap2.put("table.name","test_data_tgt");
-        String configJson1 = null;
-        String configJson2 = null;
-        try {
-            configJson1 = new ObjectMapper().writeValueAsString(configMap1);
-            configJson2 = new ObjectMapper().writeValueAsString(configMap2);
-        } catch (JsonProcessingException e) {
-            e.printStackTrace();
-        }
-
-        DataConnector source = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson1);
-        DataConnector target = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson2);
-
-        String rules = "$source.uage > 100 AND $source.uid = $target.uid AND $source.uage + 12 = $target.uage + 10 + 2 AND $source.udes + 11 = $target.udes + 1 + 1";
-
-        EvaluateRule eRule = new EvaluateRule(1,rules);
-
-        Measure measure = new Measure("m1","bevssoj description", Measure.MearuseType.accuracy, "bullseye", source, target, eRule,"owner1");
-        entityManager.persistAndFlush(measure);
-
-        DataConnector source2 = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson1);
-        DataConnector target2 = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson2);
-        EvaluateRule eRule2 = new EvaluateRule(1,rules);
-        Measure measure2 = new Measure("m2","test description", Measure.MearuseType.accuracy, "org1", source2, target2, eRule2,"owner1");
-        entityManager.persistAndFlush(measure2);
-
-        DataConnector source3 = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson1);
-        DataConnector target3 = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson2);
-        EvaluateRule eRule3 = new EvaluateRule(1,rules);
-        Measure measure3 = new Measure("m3","test_just_inthere description", Measure.MearuseType.accuracy, "org2", source3, target3, eRule3,"owner1");
-        entityManager.persistAndFlush(measure3);
-
-
+    public void testFindNameByOrganization() throws Exception {
         List<String> orgs = measureRepo.findNameByOrganization("org1");
         assertThat(orgs.size()).isEqualTo(1);
         assertThat(orgs.get(0)).isEqualToIgnoringCase("m2");
@@ -142,21 +64,20 @@ public class MeasureRepoTest {
     }
 
     @Test
-    public void testFindOrgByName(){
+    public void testFindOrgByName() throws Exception {
+        String org = measureRepo.findOrgByName("m3");
+        assertThat(org).isEqualTo("org2");
+    }
+
+    private Measure createATestMeasure(String name,String org)throws Exception{
         HashMap<String,String> configMap1=new HashMap<>();
         configMap1.put("database","default");
         configMap1.put("table.name","test_data_src");
         HashMap<String,String> configMap2=new HashMap<>();
         configMap2.put("database","default");
         configMap2.put("table.name","test_data_tgt");
-        String configJson1 = null;
-        String configJson2 = null;
-        try {
-            configJson1 = new ObjectMapper().writeValueAsString(configMap1);
-            configJson2 = new ObjectMapper().writeValueAsString(configMap2);
-        } catch (JsonProcessingException e) {
-            e.printStackTrace();
-        }
+        String configJson1 = new org.codehaus.jackson.map.ObjectMapper().writeValueAsString(configMap1);
+        String configJson2 = new org.codehaus.jackson.map.ObjectMapper().writeValueAsString(configMap2);
 
         DataConnector source = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson1);
         DataConnector target = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson2);
@@ -165,24 +86,19 @@ public class MeasureRepoTest {
 
         EvaluateRule eRule = new EvaluateRule(1,rules);
 
-        Measure measure = new Measure("m1","bevssoj description", Measure.MearuseType.accuracy, "bullseye", source, target, eRule,"owner1");
+        Measure measure = new Measure(name,"bevssoj description", Measure.MearuseType.accuracy, org, source, target, eRule,"test1");
+
+        return measure;
+    }
+
+    public void setEntityManager() throws Exception {
+        Measure measure=createATestMeasure("m1","bullseye");
         entityManager.persistAndFlush(measure);
 
-        DataConnector source2 = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson1);
-        DataConnector target2 = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson2);
-        EvaluateRule eRule2 = new EvaluateRule(1,rules);
-        Measure measure2 = new Measure("m2","test description", Measure.MearuseType.accuracy, "org1", source2, target2, eRule2,"owner1");
+        Measure measure2=createATestMeasure("m2","org1");
         entityManager.persistAndFlush(measure2);
 
-        DataConnector source3 = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson1);
-        DataConnector target3 = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson2);
-        EvaluateRule eRule3 = new EvaluateRule(1,rules);
-        Measure measure3 = new Measure("m3","test_just_inthere description", Measure.MearuseType.accuracy, "org2", source3, target3, eRule3,"owner1");
+        Measure measure3=createATestMeasure("m3","org2");
         entityManager.persistAndFlush(measure3);
-
-
-        String org = measureRepo.findOrgByName("m3");
-        assertThat(org).isEqualTo("org2");
-
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/test/java/org/apache/griffin/core/metastore/HiveMetastoreControllerTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/metastore/HiveMetastoreControllerTest.java b/service/src/test/java/org/apache/griffin/core/metastore/HiveMetastoreControllerTest.java
index 2f8801d..a848233 100644
--- a/service/src/test/java/org/apache/griffin/core/metastore/HiveMetastoreControllerTest.java
+++ b/service/src/test/java/org/apache/griffin/core/metastore/HiveMetastoreControllerTest.java
@@ -35,7 +35,7 @@ public class HiveMetastoreControllerTest {
     private MockMvc mockMvc;
 
     @Mock
-    HiveMetastoreService hiveMetastoreService;
+    HiveMetastoreServiceImpl hiveMetastoreService;
 
     @InjectMocks
     private HiveMetastoreController hiveMetastoreController;

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/test/java/org/apache/griffin/core/metastore/HiveMetastoreServiceImplTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/metastore/HiveMetastoreServiceImplTest.java b/service/src/test/java/org/apache/griffin/core/metastore/HiveMetastoreServiceImplTest.java
new file mode 100644
index 0000000..9934e5d
--- /dev/null
+++ b/service/src/test/java/org/apache/griffin/core/metastore/HiveMetastoreServiceImplTest.java
@@ -0,0 +1,118 @@
+/*-
+ * Licensed 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.griffin.core.metastore;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.fail;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.BDDMockito.given;
+
+
+@RunWith(SpringRunner.class)
+//@TestPropertySource(properties = {"hive.metastore.uris=thrift://10.9.246.187:9083"})
+public class HiveMetastoreServiceImplTest {
+
+    @TestConfiguration
+    public static class HiveMetastoreServiceConfiguration{
+        @Bean
+        public HiveMetastoreServiceImpl service(){
+            return new HiveMetastoreServiceImpl();
+        }
+    }
+
+    @MockBean
+    private HiveMetaStoreClient client;
+
+    @Autowired
+    private HiveMetastoreServiceImpl service;
+
+    @Before
+    public void setup(){
+
+    }
+
+    @Test
+    public void testGetAllDatabases(){
+        try {
+            Iterable<String> tmp = service.getAllDatabases();
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot get all tables from all dbs");
+        }
+    }
+
+
+    @Test
+    public void testGetAllTableNames(){
+        try {
+            Iterable<String> tmp = service.getAllTableNames("default");
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot get all tables in db default");
+        }
+    }
+
+    @Test
+    public void testGetAllTableByDBName(){
+        try {
+            String useDbName="default";
+            given(client.getAllTables(useDbName)).willReturn(Arrays.asList("cout","cout1"));
+            List<Table> tmp = service.getAllTable(useDbName);
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot get all tables in default db");
+        }
+    }
+
+    @Test
+    public void testGetAllTable(){
+        try {
+            Iterable<String> dbs=new ArrayList<>();
+            given(service.getAllDatabases()).willReturn(Arrays.asList("default","griffin"));
+            String useDbName="default";
+            given(client.getAllTables(useDbName)).willReturn(Arrays.asList("cout","cout1"));
+            Map<String, List<Table>> tmp = service.getAllTable();
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot get all table in map format");
+        }
+    }
+
+    @Test
+    public void testGetDesignatedTable(){
+        try {
+            Table tmp = service.getTable("default","xxx");
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot get xxx table in default db");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/test/java/org/apache/griffin/core/metastore/HiveMetastoreServiceTests.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/metastore/HiveMetastoreServiceTests.java b/service/src/test/java/org/apache/griffin/core/metastore/HiveMetastoreServiceTests.java
deleted file mode 100644
index 7444f09..0000000
--- a/service/src/test/java/org/apache/griffin/core/metastore/HiveMetastoreServiceTests.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*-
- * Licensed 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.griffin.core.metastore;
-
-import org.apache.hadoop.hive.conf.HiveConf;
-import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
-import org.apache.hadoop.hive.metastore.api.MetaException;
-import org.apache.hadoop.hive.metastore.api.Table;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.test.context.TestConfiguration;
-import org.springframework.context.annotation.Bean;
-import org.springframework.test.context.TestPropertySource;
-import org.springframework.test.context.junit4.SpringRunner;
-
-import java.util.List;
-import java.util.Map;
-
-import static org.assertj.core.api.Assertions.fail;
-import static org.junit.Assert.assertTrue;
-
-
-@RunWith(SpringRunner.class)
-@TestPropertySource(properties = {"hive.metastore.uris=thrift://10.9.246.187:9083"})
-public class HiveMetastoreServiceTests {
-
-    @TestConfiguration
-    public static class HiveMetastoreServiceConfiguration{
-        @Bean
-        public HiveMetastoreService service(){
-            return new HiveMetastoreService();
-        }
-
-        @Value("${hive.metastore.uris}")
-        String urls;
-        @Bean
-        public HiveMetaStoreClient client(){
-
-                HiveMetaStoreClient client = null;
-                HiveConf hiveConf = new HiveConf();
-                hiveConf.set("hive.metastore.local", "false");
-                hiveConf.setIntVar(HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES, 3);
-                hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, urls);
-                try {
-                    client= new HiveMetaStoreClient(hiveConf);
-                } catch (MetaException e) {
-                    client = null;
-                }
-
-                return client;
-
-        }
-    }
-    @Autowired private HiveMetastoreService service;
-
-
-    @Before
-    public void setup(){
-
-    }
-
-    @Test
-    public void testGetAllTables(){
-
-        try {
-            Iterable<String> tmp = service.getAllDatabases();
-            assertTrue(true);
-        }catch (Throwable t){
-            fail("Cannot get all tables from all dbs");
-        }
-    }
-
-
-    @Test
-    public void testGetAllTableNames(){
-        try {
-            Iterable<String> tmp = service.getAllTableNames("default");
-            assertTrue(true);
-        }catch (Throwable t){
-            fail("Cannot get all tables in db default");
-        }
-    }
-
-    @Test
-    public void testGetAllTableByDBName(){
-        try {
-            List<Table> tmp = service.getAllTable("default");
-            assertTrue(true);
-        }catch (Throwable t){
-            fail("Cannot get all tables in default db");
-        }
-    }
-
-    @Test
-    public void testGetAllTable(){
-        try {
-            Map<String, List<Table>> tmp = service.getAllTable();
-            assertTrue(true);
-        }catch (Throwable t){
-            fail("Cannot get all table in map format");
-        }
-    }
-
-    @Test
-    public void testGetDesignatedTable(){
-        try {
-            Table tmp = service.getTable("default","xxx");
-            assertTrue(true);
-        }catch (Throwable t){
-            fail("Cannot get xxx table in default db");
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/test/java/org/apache/griffin/core/metastore/KafkaSchemaControllerTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/metastore/KafkaSchemaControllerTest.java b/service/src/test/java/org/apache/griffin/core/metastore/KafkaSchemaControllerTest.java
index d50438b..5ef2580 100644
--- a/service/src/test/java/org/apache/griffin/core/metastore/KafkaSchemaControllerTest.java
+++ b/service/src/test/java/org/apache/griffin/core/metastore/KafkaSchemaControllerTest.java
@@ -37,7 +37,7 @@ public class KafkaSchemaControllerTest {
     private MockMvc mockMvc;
 
     @Mock
-    KafkaSchemaService kafkaSchemaService;
+    KafkaSchemaServiceImpl kafkaSchemaService;
 
     @InjectMocks
     private KafkaSchemaController kafkaSchemaController;

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/test/java/org/apache/griffin/core/metastore/KafkaSchemaServiceImplTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/metastore/KafkaSchemaServiceImplTest.java b/service/src/test/java/org/apache/griffin/core/metastore/KafkaSchemaServiceImplTest.java
new file mode 100644
index 0000000..56a0a8c
--- /dev/null
+++ b/service/src/test/java/org/apache/griffin/core/metastore/KafkaSchemaServiceImplTest.java
@@ -0,0 +1,111 @@
+/*-
+ * Licensed 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.griffin.core.metastore;
+
+import io.confluent.kafka.schemaregistry.client.rest.entities.Config;
+import io.confluent.kafka.schemaregistry.client.rest.entities.Schema;
+import io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.web.client.RestTemplate;
+
+import static org.assertj.core.api.Assertions.fail;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(SpringRunner.class)
+public class KafkaSchemaServiceImplTest {
+    @TestConfiguration
+    public static class KafkaSchemaServiceConfiguration {
+        @Bean
+        public KafkaSchemaServiceImpl service() {
+            return new KafkaSchemaServiceImpl();
+        }
+    }
+
+    @Autowired
+    private KafkaSchemaServiceImpl service;
+
+    @Before
+    public void setup(){
+        service.restTemplate= Mockito.mock(RestTemplate.class);
+    }
+
+    @Test
+    public void testGetSchemaString(){
+        try {
+            SchemaString tmp = service.getSchemaString(1);
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot get all tables from all dbs");
+        }
+    }
+
+    @Test
+    public void testGetSubjects(){
+        try {
+            Iterable<String> tmp = service.getSubjects();
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot get all tables from all dbs");
+        }
+    }
+
+    @Test
+    public void testGetSubjectVersions(){
+        try {
+            Iterable<Integer> tmp = service.getSubjectVersions("");
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot get all tables from all dbs");
+        }
+    }
+
+    @Test
+    public void testGetSubjectSchema(){
+        try {
+            Schema tmp = service.getSubjectSchema("","");
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot get all tables from all dbs");
+        }
+    }
+
+    @Test
+    public void testGetTopLevelConfig(){
+        try {
+            Config tmp = service.getTopLevelConfig();
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot get all tables from all dbs");
+        }
+    }
+
+    @Test
+    public void testGetSubjectLevelConfig(){
+        try {
+            Config tmp = service.getSubjectLevelConfig("");
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot get all tables from all dbs");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/test/java/org/apache/griffin/core/metric/MetricServiceImplTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/metric/MetricServiceImplTest.java b/service/src/test/java/org/apache/griffin/core/metric/MetricServiceImplTest.java
new file mode 100644
index 0000000..671808a
--- /dev/null
+++ b/service/src/test/java/org/apache/griffin/core/metric/MetricServiceImplTest.java
@@ -0,0 +1,49 @@
+package org.apache.griffin.core.metric;
+
+import org.apache.griffin.core.measure.repo.MeasureRepo;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.assertj.core.api.Assertions.fail;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Created by xiangrchen on 6/7/17.
+ */
+@RunWith(SpringRunner.class)
+public class MetricServiceImplTest {
+    @TestConfiguration
+    static class MetricServiceConfiguration{
+        @Bean
+        public MetricServiceImpl service(){
+            return new MetricServiceImpl();
+        }
+    }
+
+    @MockBean
+    private MeasureRepo measureRepo;
+
+    @Autowired
+    private MetricServiceImpl service;
+
+    @Before
+    public void setup(){
+    }
+
+    @Test
+    public void testGetOrgByMeasureName(){
+        try {
+            String measureName="viewitem_hourly";
+            String tmp = service.getOrgByMeasureName(measureName);
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot get org by measure name viewitem_hourly");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/test/java/org/apache/griffin/core/schedule/SchedulerControllerTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/schedule/SchedulerControllerTest.java b/service/src/test/java/org/apache/griffin/core/schedule/SchedulerControllerTest.java
new file mode 100644
index 0000000..c4eb3ec
--- /dev/null
+++ b/service/src/test/java/org/apache/griffin/core/schedule/SchedulerControllerTest.java
@@ -0,0 +1,104 @@
+package org.apache.griffin.core.schedule;
+
+import org.codehaus.jackson.map.ObjectMapper;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.MediaType;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.servlet.MockMvc;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.mockito.BDDMockito.given;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+/**
+ * Created by xiangrchen on 6/7/17.
+ */
+@RunWith(SpringRunner.class)
+@WebMvcTest(value = SchedulerController.class,secure = false)
+public class SchedulerControllerTest {
+    @Autowired
+    private MockMvc mvc;
+
+    @MockBean
+    private SchedulerService service;
+
+    @Before
+    public void setup(){
+    }
+
+    @Test
+    public void testGetJobs() throws Exception {
+        Map<String, Serializable> map=new HashMap<String, Serializable>();
+        map.put("jobName", "job1");
+        map.put("groupName", "BA");
+        given(service.getJobs()).willReturn(Arrays.asList(map));
+
+        mvc.perform(get("/jobs/").contentType(MediaType.APPLICATION_JSON))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.[0].jobName",is("job1")))
+        ;
+    }
+
+    @Test
+    public void testAddJob() throws Exception {
+        String groupName="BA";
+        String jobName="job1";
+        String measureName="viewitem_hourly";
+        SchedulerRequestBody schedulerRequestBody=new SchedulerRequestBody("YYYYMMdd-HH","YYYYMMdd-HH","111","20170607","100");
+        ObjectMapper mapper=new ObjectMapper();
+        String schedulerRequestBodyJson=mapper.writeValueAsString(schedulerRequestBody);
+        given(service.addJob(groupName,jobName,measureName,schedulerRequestBody)).willReturn(true);
+
+        mvc.perform(post("/jobs/add/BA/job1/viewitem_hourly").contentType(MediaType.APPLICATION_JSON).content(schedulerRequestBodyJson))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$",is(true)))
+        ;
+    }
+
+    @Test
+    public void testDeleteJob() throws Exception {
+        String groupName="BA";
+        String jobName="job1";
+        given(service.deleteJob(groupName,jobName)).willReturn(true);
+        mvc.perform(delete("/jobs/del/BA/job1").contentType(MediaType.APPLICATION_JSON))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$",is(true)))
+        ;
+    }
+
+    @Test
+    public void testFindInstancesOfJob() throws Exception {
+        String group="BA";
+        String job="job1";
+        int page=0;
+        int size=2;
+        ScheduleState scheduleState=new ScheduleState(group, job, 1, "NORMAL", "", System.currentTimeMillis());
+        given(service.findInstancesOfJob(group,job,page,size)).willReturn(Arrays.asList(scheduleState));
+        mvc.perform(get("/jobs/instances/BA/job1/0/2").contentType(MediaType.APPLICATION_JSON))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.[0].groupName",is("BA")))
+        ;
+    }
+
+    @Test
+    public void testGetHealthInfo() throws Exception {
+        JobHealth jobHealth=new JobHealth(1,2,3);
+        given(service.getHealthInfo()).willReturn(jobHealth);
+        mvc.perform(get("/jobs/statics").contentType(MediaType.APPLICATION_JSON))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.health",is(1)))
+        ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/test/java/org/apache/griffin/core/schedule/SchedulerServiceImplTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/schedule/SchedulerServiceImplTest.java b/service/src/test/java/org/apache/griffin/core/schedule/SchedulerServiceImplTest.java
new file mode 100644
index 0000000..066777e
--- /dev/null
+++ b/service/src/test/java/org/apache/griffin/core/schedule/SchedulerServiceImplTest.java
@@ -0,0 +1,178 @@
+/*-
+ * Licensed 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.griffin.core.schedule;
+
+import org.apache.griffin.core.schedule.Repo.ScheduleStateRepo;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.quartz.*;
+import org.quartz.impl.matchers.GroupMatcher;
+import org.quartz.impl.triggers.CronTriggerImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.scheduling.quartz.SchedulerFactoryBean;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.io.Serializable;
+import java.util.*;
+
+import static org.assertj.core.api.Assertions.fail;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.BDDMockito.given;
+
+@RunWith(SpringRunner.class)
+public class SchedulerServiceImplTest {
+
+    @TestConfiguration
+    public static class SchedulerServiceConfiguration{
+        @Bean
+        public SchedulerServiceImpl service(){
+            return new SchedulerServiceImpl();
+        }
+        @Bean
+        public SchedulerFactoryBean factoryBean(){
+            return new SchedulerFactoryBean();
+        }
+    }
+
+    @MockBean
+    private ScheduleStateRepo scheduleStateRepo;
+
+
+    @MockBean
+    private SchedulerFactoryBean factory;
+
+    @Autowired
+    private SchedulerServiceImpl service;
+
+    @Before
+    public void setup(){
+    }
+
+    @Test
+    public void testGetJobs(){
+        try {
+            Scheduler scheduler=Mockito.mock(Scheduler.class);
+            given(factory.getObject()).willReturn(scheduler);
+            List<Map<String, Serializable>> tmp = service.getJobs();
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot get all jobs info from dbs");
+        }
+    }
+
+    @Test
+    public void testSetJobsByKey() throws SchedulerException {
+        List<Map<String, Serializable>> list=new ArrayList<Map<String, Serializable>>();
+        Scheduler scheduler=Mockito.mock(Scheduler.class);
+        JobKey jobKey= new JobKey("TEST");
+        List<Trigger> triggers=new ArrayList<Trigger>();
+        Trigger trigger=new CronTriggerImpl();
+        triggers.add(trigger);
+        given((List<Trigger>) scheduler.getTriggersOfJob(jobKey)).willReturn(triggers);
+
+        JobDetail jd=Mockito.mock(JobDetail.class);
+        given(scheduler.getJobDetail(jobKey)).willReturn(jd);
+
+        JobDataMap jobDataMap=Mockito.mock(JobDataMap.class);
+        given(jd.getJobDataMap()).willReturn(jobDataMap);
+
+        service.setJobsByKey(list,scheduler,jobKey);
+
+    }
+
+    @Test
+    public void testAddJob(){
+        try {
+            String groupName="BA";
+            String jobName="job1";
+            String measureName="m1";
+            SchedulerRequestBody schedulerRequestBody=new SchedulerRequestBody();
+            Scheduler scheduler=Mockito.mock(Scheduler.class);
+            given(factory.getObject()).willReturn(scheduler);
+            Boolean tmp = service.addJob(groupName,jobName,measureName,schedulerRequestBody);
+            assertEquals(tmp,false);
+            assertTrue(true);
+
+            SchedulerRequestBody schedulerRequestBody1=new SchedulerRequestBody("YYYYMMdd-HH","YYYYMMdd-HH",
+                    System.currentTimeMillis()+"","20170605 15:29:30","1000");
+            Scheduler scheduler1=Mockito.mock(Scheduler.class);
+            given(factory.getObject()).willReturn(scheduler1);
+            Boolean tmp1 = service.addJob(groupName,jobName,measureName,schedulerRequestBody1);
+            assertEquals(tmp1,true);
+        }catch (Throwable t){
+            fail("Cannot add job ");
+        }
+    }
+
+    @Test
+    public void testDeleteJob(){
+        try {
+            String groupName="BA";
+            String jobName="job1";
+            Scheduler scheduler=Mockito.mock(Scheduler.class);
+            given(factory.getObject()).willReturn(scheduler);
+            Boolean tmp = service.deleteJob(groupName,jobName);
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot delete job");
+        }
+    }
+
+    @Test
+    public void testFindInstancesOfJob(){
+        try {
+            String groupName="BA";
+            String jobName="job1";
+            int page=0;
+            int size=2;
+            List<ScheduleState> tmp = service.findInstancesOfJob(groupName,jobName,page,size);
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot find instances of Job");
+        }
+    }
+
+    @Test
+    public void testGetHealthInfo(){
+        try {
+            Scheduler scheduler=Mockito.mock(Scheduler.class);
+            given(factory.getObject()).willReturn(scheduler);
+            given(scheduler.getJobGroupNames()).willReturn(Arrays.asList("BA"));
+            JobKey jobKey= new JobKey("TEST");
+            Set<JobKey> jobKeySet=new HashSet<JobKey>();
+            jobKeySet.add(jobKey);
+            given(scheduler.getJobKeys(GroupMatcher.jobGroupEquals("BA"))).willReturn((jobKeySet));
+
+            Pageable pageRequest=new PageRequest(0,1, Sort.Direction.DESC,"timestamp");
+            List<ScheduleState> scheduleStateList=new ArrayList<ScheduleState>();
+            given(scheduleStateRepo.findByGroupNameAndJobName(jobKey.getGroup(),jobKey.getName(),pageRequest)).willReturn(scheduleStateList);
+            JobHealth tmp = service.getHealthInfo();
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot get Health info "+t);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/test/java/org/apache/griffin/core/schedule/SparkSubmitJobTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/schedule/SparkSubmitJobTest.java b/service/src/test/java/org/apache/griffin/core/schedule/SparkSubmitJobTest.java
index 18283b4..ce59858 100644
--- a/service/src/test/java/org/apache/griffin/core/schedule/SparkSubmitJobTest.java
+++ b/service/src/test/java/org/apache/griffin/core/schedule/SparkSubmitJobTest.java
@@ -16,17 +16,22 @@ limitations under the License.
 package org.apache.griffin.core.schedule;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.griffin.core.measure.DataConnector;
 import org.apache.griffin.core.measure.EvaluateRule;
 import org.apache.griffin.core.measure.Measure;
 import org.apache.griffin.core.measure.repo.MeasureRepo;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
 import org.quartz.JobDataMap;
 import org.quartz.JobDetail;
 import org.quartz.JobExecutionContext;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.client.RestTemplate;
 
 import java.io.IOException;
 import java.text.SimpleDateFormat;
@@ -37,11 +42,9 @@ import java.util.Map;
 import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.*;
 
-/**
- * Created by xiangrchen on 5/8/17.
- */
-//@RunWith(SpringJUnit4ClassRunner.class)
-public class SparkSubmitJobTest {
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(SparkSubmitJob.class)
+public class SparkSubmitJobTest{
 
     private SparkSubmitJob ssj;
 
@@ -55,7 +58,7 @@ public class SparkSubmitJobTest {
     }
 
     @Test
-    public void test_execute() throws JsonProcessingException {
+    public void test_execute() throws Exception {
         JobExecutionContext context=mock(JobExecutionContext.class);
         JobDetail jd = mock(JobDetail.class);
         when(context.getJobDetail()).thenReturn(jd);
@@ -69,35 +72,44 @@ public class SparkSubmitJobTest {
         when(jdmap.getString("dataStartTimestamp")).thenReturn("1460174400000");
         when(jdmap.getString("lastTime")).thenReturn("");
         when(jdmap.getString("periodTime")).thenReturn("10");
+        Measure measure = createATestMeasure("viewitem_hourly","bullseye");
+        when(ssj.measureRepo.findByName("bevssoj")).thenReturn(measure);
+
+        RestTemplate restTemplate =Mockito.mock(RestTemplate.class);
+        PowerMockito.whenNew(RestTemplate.class).withAnyArguments().thenReturn(restTemplate);
+        String uri="";
+        SparkJobDO sparkJobDO= Mockito.mock(SparkJobDO.class);
+        PowerMockito.when(restTemplate.postForObject(uri, sparkJobDO, String.class)).thenReturn(null);
+        ssj.execute(context);
+
+        long currentSystemTimestamp=System.currentTimeMillis();
+        long currentTimstamp = ssj.setCurrentTimestamp(currentSystemTimestamp);
+//
+        verify(ssj.measureRepo).findByName("bevssoj");
+        verify(jdmap,atLeast(2)).put("lastTime",currentTimstamp+"");
+
+    }
 
+    private Measure createATestMeasure(String name,String org)throws IOException,Exception{
         HashMap<String,String> configMap1=new HashMap<>();
         configMap1.put("database","default");
         configMap1.put("table.name","test_data_src");
         HashMap<String,String> configMap2=new HashMap<>();
         configMap2.put("database","default");
         configMap2.put("table.name","test_data_tgt");
-        String configJson1 = new ObjectMapper().writeValueAsString(configMap1);
-        String configJson2 = new ObjectMapper().writeValueAsString(configMap2);
+        String configJson1 = new org.codehaus.jackson.map.ObjectMapper().writeValueAsString(configMap1);
+        String configJson2 = new org.codehaus.jackson.map.ObjectMapper().writeValueAsString(configMap2);
+
         DataConnector source = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson1);
         DataConnector target = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson2);
+
         String rules = "$source.uage > 100 AND $source.uid = $target.uid AND $source.uage + 12 = $target.uage + 10 + 2 AND $source.udes + 11 = $target.udes + 1 + 1";
+
         EvaluateRule eRule = new EvaluateRule(1,rules);
-        Measure measure = new Measure("viewitem_hourly","bevssoj description", Measure.MearuseType.accuracy, "bullyeye", source, target, eRule,"test1");
 
-        when(ssj.measureRepo.findByName("bevssoj")).thenReturn(measure);
-//        ssj.execute(context);
-//
-//        RestTemplate restTemplate =mock(RestTemplate.class);
-//        String uri="http://10.9.246.187:8998/batches";
-//        SparkJobDO sparkJobDO=mock(SparkJobDO.class);
-//        when(restTemplate.postForObject(uri, sparkJobDO, String.class)).thenReturn(null);
-//
-//
-//        long currentSystemTimestamp=System.currentTimeMillis();
-//        long currentTimstamp = ssj.setCurrentTimestamp(currentSystemTimestamp);
-//
-//        verify(ssj.measureRepo).findByName("bevssoj");
-//        verify(jdmap,atLeast(2)).put("lastTime",currentTimstamp+"");
+        Measure measure = new Measure(name,"bevssoj description", Measure.MearuseType.accuracy, org, source, target, eRule,"test1");
+
+        return measure;
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/test/resources/application-test.properties
----------------------------------------------------------------------
diff --git a/service/src/test/resources/application-test.properties b/service/src/test/resources/application-test.properties
new file mode 100644
index 0000000..1af0ac9
--- /dev/null
+++ b/service/src/test/resources/application-test.properties
@@ -0,0 +1,58 @@
+#spring.datasource.url= jdbc:mysql://localhost:3306/griffintest?autoReconnect=true&useSSL=false
+#spring.datasource.username =root
+#spring.datasource.password =cxr123
+#
+#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
+#
+### Hibernate ddl auto (validate,create, create-drop, update)
+#
+#spring.jpa.hibernate.ddl-auto = update
+#spring.jpa.show-sql=true
+#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
+#
+##spring.jpa.hibernate.ddl-auto = create-drop
+##spring.jpa.database = HSQL
+##spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.HSQLDialect
+##spring.datasource.driverClassName = org.hsqldb.jdbcDriver
+##spring.datasource.url: jdbc:hsqldb:mem:scratchdb
+##spring.datasource.username = sa
+##spring.datasource.password =
+
+#spring.jpa.database: HSQL
+#
+##
+##
+### Naming strategy
+#spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
+#
+# hive metastore
+#hive.metastore.uris = thrift://10.9.246.187:9083
+#hive.metastore.dbname = default
+#
+## kafka schema registry
+#kafka.schema.registry.url = http://10.65.159.119:8081
+
+key=test
+
+spring.datasource.url= jdbc:mysql://localhost:3306/quartz?autoReconnect=true&useSSL=false
+spring.datasource.username =griffin
+spring.datasource.password =123456
+
+spring.datasource.driver-class-name=com.mysql.jdbc.Driver
+
+## Hibernate ddl auto (validate,create, create-drop, update)
+
+spring.jpa.hibernate.ddl-auto = update
+spring.jpa.show-sql=true
+spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
+#
+#
+## Naming strategy
+spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
+
+# hive metastore
+hive.metastore.uris = thrift://10.9.246.187:9083
+hive.metastore.dbname = default
+
+# kafka schema registry
+kafka.schema.registry.url = http://10.65.159.119:8081
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/test/resources/quartz.properties
----------------------------------------------------------------------
diff --git a/service/src/test/resources/quartz.properties b/service/src/test/resources/quartz.properties
new file mode 100644
index 0000000..a7c07ab
--- /dev/null
+++ b/service/src/test/resources/quartz.properties
@@ -0,0 +1,11 @@
+org.quartz.scheduler.instanceName=spring-boot-quartz
+org.quartz.scheduler.instanceId=AUTO
+org.quartz.threadPool.threadCount=5
+org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
+org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
+org.quartz.jobStore.useProperties=true
+org.quartz.jobStore.misfireThreshold=60000
+org.quartz.jobStore.tablePrefix=QRTZ_
+
+org.quartz.jobStore.isClustered=true
+org.quartz.jobStore.clusterCheckinInterval=20000
\ No newline at end of file


[2/2] incubator-griffin git commit: 20170613 10 30service

Posted by gu...@apache.org.
20170613 10 30service

Author: Chen <xi...@lm-shc-16501061.corp.ebay.com>

Closes #70 from justACT/20170613-10-30service.


Project: http://git-wip-us.apache.org/repos/asf/incubator-griffin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-griffin/commit/ae6a308b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-griffin/tree/ae6a308b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-griffin/diff/ae6a308b

Branch: refs/heads/master
Commit: ae6a308b2f35f6ecdaac1b03ae6f1b2e2a046c99
Parents: a45937d
Author: Chen <xi...@lm-shc-16501061.corp.ebay.com>
Authored: Tue Jun 13 10:34:49 2017 +0800
Committer: Lionel Liu <bh...@163.com>
Committed: Tue Jun 13 10:34:49 2017 +0800

----------------------------------------------------------------------
 README.md                                       |   1 +
 service/pom.xml                                 |  20 ++
 .../griffin/core/measure/DataConnector.java     |   1 -
 .../core/measure/MeasureServiceImpl.java        |   9 +-
 .../griffin/core/measure/repo/MeasureRepo.java  |   9 +
 .../core/metastore/HiveMetastoreController.java |  20 +-
 .../core/metastore/HiveMetastoreProxy.java      |  27 +--
 .../core/metastore/HiveMetastoreService.java    |  95 +-------
 .../metastore/HiveMetastoreServiceImpl.java     | 153 +++++++++++++
 .../core/metastore/KafkaSchemaController.java   |   2 +-
 .../core/metastore/KafkaSchemaService.java      | 112 +---------
 .../core/metastore/KafkaSchemaServiceImpl.java  | 140 ++++++++++++
 .../apache/griffin/core/schedule/JobHealth.java |   5 +-
 .../core/schedule/Repo/ScheduleStateRepo.java   |   6 +-
 .../core/schedule/SchedulerController.java      | 190 ++--------------
 .../core/schedule/SchedulerRequestBody.java     |  35 +++
 .../griffin/core/schedule/SchedulerService.java |  24 +++
 .../core/schedule/SchedulerServiceImpl.java     | 214 +++++++++++++++++++
 .../griffin/core/schedule/SparkSubmitJob.java   |  24 +--
 .../main/resources/application-dev.properties   |   2 +-
 .../core/measure/MeasureControllerTest.java     | 177 +++++++++++++++
 .../core/measure/MeasureServiceImplTest.java    | 192 +++++++++++++++++
 .../measure/repo/MeasureControllerTest.java     | 101 ---------
 .../core/measure/repo/MeasureRepoTest.java      | 126 ++---------
 .../metastore/HiveMetastoreControllerTest.java  |   2 +-
 .../metastore/HiveMetastoreServiceImplTest.java | 118 ++++++++++
 .../metastore/HiveMetastoreServiceTests.java    | 129 -----------
 .../metastore/KafkaSchemaControllerTest.java    |   2 +-
 .../metastore/KafkaSchemaServiceImplTest.java   | 111 ++++++++++
 .../core/metric/MetricServiceImplTest.java      |  49 +++++
 .../core/schedule/SchedulerControllerTest.java  | 104 +++++++++
 .../core/schedule/SchedulerServiceImplTest.java | 178 +++++++++++++++
 .../core/schedule/SparkSubmitJobTest.java       |  60 +++---
 .../test/resources/application-test.properties  |  58 +++++
 service/src/test/resources/quartz.properties    |  11 +
 35 files changed, 1732 insertions(+), 775 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 0eda770..274d5fb 100644
--- a/README.md
+++ b/README.md
@@ -86,6 +86,7 @@ Release:
     ```
     Create a directory in Hdfs, and put our measure package into it.
     ```
+    cp /measure/target/measure-0.1.3-incubating-SNAPSHOT.jar /measure/target/griffin-measure.jar
     hdfs dfs -put /measure/target/griffin-measure.jar <griffin measure path>/
     ```
     After all our environment services startup, we can start our server.

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/pom.xml
----------------------------------------------------------------------
diff --git a/service/pom.xml b/service/pom.xml
index 41696e4..c9847cc 100644
--- a/service/pom.xml
+++ b/service/pom.xml
@@ -73,6 +73,12 @@
             <artifactId>spring-boot-starter-data-jpa</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.springframework.retry</groupId>
+            <artifactId>spring-retry</artifactId>
+            <version>1.1.5.RELEASE</version>
+        </dependency>
+
         <!--dev db-->
 
         <!--<dependency>-->
@@ -152,6 +158,20 @@
             <scope>test</scope>
         </dependency>
 
+        <dependency>
+            <groupId>org.powermock</groupId>
+            <artifactId>powermock-api-mockito</artifactId>
+            <version>${powermock.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.powermock</groupId>
+            <artifactId>powermock-module-junit4</artifactId>
+            <version>${powermock.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+
     </dependencies>
     <profiles>
     </profiles>

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/main/java/org/apache/griffin/core/measure/DataConnector.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/measure/DataConnector.java b/service/src/main/java/org/apache/griffin/core/measure/DataConnector.java
index aaf9e40..b2b0ad0 100644
--- a/service/src/main/java/org/apache/griffin/core/measure/DataConnector.java
+++ b/service/src/main/java/org/apache/griffin/core/measure/DataConnector.java
@@ -101,7 +101,6 @@ public class DataConnector extends AuditableEntity  {
 
 
     public DataConnector() {
-        System.out.println();
     }
 
     public DataConnector(ConnectorType type,String version, Map<String,String> config){

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/main/java/org/apache/griffin/core/measure/MeasureServiceImpl.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/measure/MeasureServiceImpl.java b/service/src/main/java/org/apache/griffin/core/measure/MeasureServiceImpl.java
index ff74aa7..0b6b03a 100644
--- a/service/src/main/java/org/apache/griffin/core/measure/MeasureServiceImpl.java
+++ b/service/src/main/java/org/apache/griffin/core/measure/MeasureServiceImpl.java
@@ -87,7 +87,14 @@ public class MeasureServiceImpl implements MeasureService{
     }
 
     public GriffinOperationMessage updateMeasure(@RequestBody Measure measure) {
-
+//        Long measureId=measure.getId();
+//        if (measureRepo.findOne(measureId)==null){
+//            return GriffinOperationMessage.RESOURCE_NOT_FOUND;
+//        }else{
+//            measureRepo.updateMeasure(measureId,measure.getDescription(),measure.getOrganization(),measure.getSource(),measure.getTarget(),measure.getEvaluateRule());
+////            System.out.print(res);
+//            return GriffinOperationMessage.UPDATE_MEASURE_SUCCESS;
+//        }
         String name=measure.getName();
         Measure temp_mesaure=measureRepo.findByName(name);
         if (temp_mesaure==null){

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/main/java/org/apache/griffin/core/measure/repo/MeasureRepo.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/measure/repo/MeasureRepo.java b/service/src/main/java/org/apache/griffin/core/measure/repo/MeasureRepo.java
index 5bc84a4..1ed2fb2 100644
--- a/service/src/main/java/org/apache/griffin/core/measure/repo/MeasureRepo.java
+++ b/service/src/main/java/org/apache/griffin/core/measure/repo/MeasureRepo.java
@@ -16,7 +16,10 @@ limitations under the License.
 package org.apache.griffin.core.measure.repo;
 
 
+import org.apache.griffin.core.measure.DataConnector;
+import org.apache.griffin.core.measure.EvaluateRule;
 import org.apache.griffin.core.measure.Measure;
+import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.CrudRepository;
 import org.springframework.stereotype.Repository;
@@ -37,4 +40,10 @@ public interface MeasureRepo extends CrudRepository<Measure, Long> {
     @Query("select m.organization from Measure m "+
             "where m.name= ?1")
     String findOrgByName(String measureName);
+
+    @Modifying
+    @Query("update Measure m "+
+            "set m.description= ?2,m.organization= ?3,m.source= ?4,m.target= ?5,m.evaluateRule= ?6 where m.id= ?1")
+    void updateMeasure(Long Id, String description, String organization, DataConnector source, DataConnector target, EvaluateRule evaluateRule);
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/main/java/org/apache/griffin/core/metastore/HiveMetastoreController.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/metastore/HiveMetastoreController.java b/service/src/main/java/org/apache/griffin/core/metastore/HiveMetastoreController.java
index 85a2d36..911ccb8 100644
--- a/service/src/main/java/org/apache/griffin/core/metastore/HiveMetastoreController.java
+++ b/service/src/main/java/org/apache/griffin/core/metastore/HiveMetastoreController.java
@@ -16,7 +16,9 @@ limitations under the License.
 package org.apache.griffin.core.metastore;
 
 
+import org.apache.hadoop.hive.metastore.api.MetaException;
 import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.thrift.TException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -30,42 +32,40 @@ import java.util.Map;
 public class HiveMetastoreController {
 
     @Autowired
-    HiveMetastoreService hiveMetastoreService;
+    HiveMetastoreServiceImpl hiveMetastoreService;
 
     @RequestMapping("/db")
-    public Iterable<String> getAllDatabases() {
+    public Iterable<String> getAllDatabases() throws MetaException{
         return hiveMetastoreService.getAllDatabases();
     }
 
     @RequestMapping("/table")
-    public Iterable<String> getDefAllTables() {
+    public Iterable<String> getDefAllTables() throws MetaException{
         return hiveMetastoreService.getAllTableNames("");
     }
 
     @RequestMapping("/{db}/table")
-    public Iterable<String> getAllTableNamess(@PathVariable("db") String dbName) {
+    public Iterable<String> getAllTableNamess(@PathVariable("db") String dbName) throws MetaException{
         return hiveMetastoreService.getAllTableNames(dbName);
     }
 
     @RequestMapping("/{db}/alltables")
-    public List<Table> getAllTables(@PathVariable("db") String dbName) {
+    public List<Table> getAllTables(@PathVariable("db") String dbName) throws TException {
         return hiveMetastoreService.getAllTable(dbName);
     }
 
     @RequestMapping("/alltables")
-    public Map<String,List<Table>> getAllTables() {
+    public Map<String,List<Table>> getAllTables() throws TException{
         return hiveMetastoreService.getAllTable();
     }
 
     @RequestMapping("/table/{table}")
-    public Table getDefTable(@PathVariable("table") String tableName) {
+    public Table getDefTable(@PathVariable("table") String tableName) throws TException{
         return hiveMetastoreService.getTable("", tableName);
     }
 
     @RequestMapping("/{db}/table/{table}")
-    public Table getTable(@PathVariable("db") String dbName, @PathVariable("table") String tableName) {
+    public Table getTable(@PathVariable("db") String dbName, @PathVariable("table") String tableName) throws TException{
         return hiveMetastoreService.getTable(dbName, tableName);
     }
-
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/main/java/org/apache/griffin/core/metastore/HiveMetastoreProxy.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/metastore/HiveMetastoreProxy.java b/service/src/main/java/org/apache/griffin/core/metastore/HiveMetastoreProxy.java
index 185bc2b..c40c20e 100644
--- a/service/src/main/java/org/apache/griffin/core/metastore/HiveMetastoreProxy.java
+++ b/service/src/main/java/org/apache/griffin/core/metastore/HiveMetastoreProxy.java
@@ -24,6 +24,8 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.stereotype.Component;
 
+import javax.annotation.PreDestroy;
+
 @Component
 public class HiveMetastoreProxy
 {
@@ -37,20 +39,21 @@ public class HiveMetastoreProxy
 
     @Bean
     public HiveMetaStoreClient initHiveMetastoreClient(){
-    HiveConf hiveConf = new HiveConf();
-    hiveConf.set("hive.metastore.local", "false");
-    hiveConf.setIntVar(HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES, 3);
-    hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, uris);
-    try {
-        client= new HiveMetaStoreClient(hiveConf);
-    } catch (MetaException e) {
-        log.error("Failed to connect hive metastore",e.getMessage());
-        client = null;
+        HiveConf hiveConf = new HiveConf();
+        hiveConf.set("hive.metastore.local", "false");
+        hiveConf.setIntVar(HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES, 3);
+        hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, uris);
+        try {
+            client= new HiveMetaStoreClient(hiveConf);
+        } catch (MetaException e) {
+            log.error("Failed to connect hive metastore",e.getMessage());
+            client = null;
+        }
+
+        return client;
     }
 
-    return client;
-}
-
+    @PreDestroy
     public void destroy() throws Exception {
         if(null!=client) client.close();
     }

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/main/java/org/apache/griffin/core/metastore/HiveMetastoreService.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/metastore/HiveMetastoreService.java b/service/src/main/java/org/apache/griffin/core/metastore/HiveMetastoreService.java
index c907b45..40d6610 100644
--- a/service/src/main/java/org/apache/griffin/core/metastore/HiveMetastoreService.java
+++ b/service/src/main/java/org/apache/griffin/core/metastore/HiveMetastoreService.java
@@ -15,104 +15,23 @@ limitations under the License.
 
 package org.apache.griffin.core.metastore;
 
-import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
 import org.apache.hadoop.hive.metastore.api.MetaException;
 import org.apache.hadoop.hive.metastore.api.Table;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-import org.springframework.util.StringUtils;
+import org.apache.thrift.TException;
 
-import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+public interface HiveMetastoreService {
 
-@Service
-public class HiveMetastoreService {
+    public Iterable<String> getAllDatabases() throws MetaException;
 
-    private static final Logger log = LoggerFactory.getLogger(HiveMetastoreService.class);
+    public Iterable<String> getAllTableNames(String dbName) throws MetaException;
 
-    @Autowired
-    HiveMetaStoreClient client;
+    public List<Table> getAllTable(String db) throws TException;
 
-    @Value("${hive.metastore.dbname}")
-    private String defaultDbName;
-
-    private String getUseDbName(String dbName) {
-        if (!StringUtils.hasText(dbName)) return defaultDbName;
-        else return dbName;
-    }
-
-    public Iterable<String> getAllDatabases() {
-        Iterable<String> results = null;
-        try {
-            results = client.getAllDatabases();
-        } catch (MetaException e) {
-            log.error("Can not get databases : ",e.getMessage());
-        }
-        return results;
-    }
-
-    public Iterable<String> getAllTableNames(String dbName) {
-        Iterable<String> results = null;
-        String useDbName = getUseDbName(dbName);
-        try {
-            results = client.getAllTables(useDbName);
-        } catch (Exception e) {
-            log.warn("Exception fetching tables info" + e.getMessage());
-        }
-        return results;
-    }
-
-    public List<Table> getAllTable(String db){
-        List<Table> results = new ArrayList<Table>();
-        String useDbName = getUseDbName(db);
-        try {
-            Iterable<String> tables = client.getAllTables(useDbName);
-            for (String table: tables) {
-                Table tmp = client.getTable(db,table);
-                results.add(tmp);
-            }
-        } catch (Exception e) {
-            log.warn("Exception fetching tables info" + e.getMessage());
-        }
-        return results;
-    }
-
-    public Map<String,List<Table>> getAllTable(){
-        Map<String,List<Table>> results = new HashMap<String, List<Table>>();
-        Iterable<String> dbs = getAllDatabases();
-        for(String db: dbs){
-            List<Table> alltables = new ArrayList<Table>();
-            String useDbName = getUseDbName(db);
-            try {
-                Iterable<String> tables = client.getAllTables(useDbName);
-                for (String table: tables) {
-                    Table tmp = client.getTable(db,table);
-                    alltables.add(tmp);
-                }
-            } catch (Exception e) {
-                log.warn("Exception fetching tables info" + e.getMessage());
-            }
-            results.put(db,alltables);
-        }
-        return results;
-    }
-
-    public Table getTable(String dbName, String tableName) {
-        Table result = null;
-        String useDbName = getUseDbName(dbName);
-        try {
-            result = client.getTable(useDbName, tableName);
-        } catch (Exception e) {
-            log.warn("Exception fetching table info : " +tableName + " : " + e.getMessage());
-        }
-        return result;
-    }
+    public Map<String,List<Table>> getAllTable() throws TException;
 
+    public Table getTable(String dbName, String tableName) throws TException;
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/main/java/org/apache/griffin/core/metastore/HiveMetastoreServiceImpl.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/metastore/HiveMetastoreServiceImpl.java b/service/src/main/java/org/apache/griffin/core/metastore/HiveMetastoreServiceImpl.java
new file mode 100644
index 0000000..ef8db93
--- /dev/null
+++ b/service/src/main/java/org/apache/griffin/core/metastore/HiveMetastoreServiceImpl.java
@@ -0,0 +1,153 @@
+/*-
+ * Licensed 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.griffin.core.metastore;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.thrift.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.retry.annotation.Backoff;
+import org.springframework.retry.annotation.Retryable;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+@Service
+public class HiveMetastoreServiceImpl implements HiveMetastoreService{
+
+    private static final Logger log = LoggerFactory.getLogger(HiveMetastoreServiceImpl.class);
+
+    @Autowired
+    HiveMetaStoreClient client;
+
+    @Value("${hive.metastore.dbname}")
+    private String defaultDbName;
+
+    private String getUseDbName(String dbName) {
+        if (!StringUtils.hasText(dbName)) return defaultDbName;
+        else return dbName;
+    }
+
+    @Retryable(value = { MetaException.class },
+            maxAttempts = 2,
+            backoff = @Backoff(delay = 5000))
+    @Override
+    public Iterable<String> getAllDatabases() throws MetaException{
+        Iterable<String> results = null;
+        try {
+            results = client.getAllDatabases();
+        } catch (MetaException e) {
+            reconnect();
+            log.error("Can not get databases : ",e.getMessage());
+            throw e;
+        }
+        return results;
+    }
+
+    @Retryable(value = { MetaException.class },
+            maxAttempts = 2,
+            backoff = @Backoff(delay = 5000))
+    @Override
+    public Iterable<String> getAllTableNames(String dbName) throws MetaException{
+        Iterable<String> results = null;
+        String useDbName = getUseDbName(dbName);
+        try {
+            results = client.getAllTables(useDbName);
+        } catch (Exception e) {
+            reconnect();
+            log.warn("Exception fetching tables info" + e.getMessage());
+            throw e;
+        }
+        return results;
+    }
+
+    @Retryable(value = { TException.class },
+            maxAttempts = 2,
+            backoff = @Backoff(delay = 5000))
+    @Override
+    public List<Table> getAllTable(String db) throws TException{
+        List<Table> results = new ArrayList<Table>();
+        String useDbName = getUseDbName(db);
+        try {
+            Iterable<String> tables = client.getAllTables(useDbName);
+            for (String table: tables) {
+                Table tmp = client.getTable(db,table);
+                results.add(tmp);
+            }
+        } catch (Exception e) {
+            reconnect();
+            log.warn("Exception fetching tables info" + e.getMessage());
+            throw e;
+        }
+        return results;
+    }
+
+    @Retryable(value = { TException.class },
+            maxAttempts = 2,
+            backoff = @Backoff(delay = 5000))
+    @Override
+    public Map<String,List<Table>> getAllTable() throws TException{
+        Map<String,List<Table>> results = new HashMap<String, List<Table>>();
+        Iterable<String> dbs = getAllDatabases();
+        for(String db: dbs){
+            List<Table> alltables = new ArrayList<Table>();
+            String useDbName = getUseDbName(db);
+            try {
+                Iterable<String> tables = client.getAllTables(useDbName);
+                for (String table: tables) {
+                    Table tmp = client.getTable(db,table);
+                    alltables.add(tmp);
+                }
+            } catch (Exception e) {
+                reconnect();
+                log.warn("Exception fetching tables info" + e.getMessage());
+                throw e;
+            }
+            results.put(db,alltables);
+        }
+        return results;
+    }
+
+    @Retryable(value = { TException.class },
+            maxAttempts = 2,
+            backoff = @Backoff(delay = 5000))
+    @Override
+    public Table getTable(String dbName, String tableName) throws TException{
+        Table result = null;
+        String useDbName = getUseDbName(dbName);
+        try {
+            result = client.getTable(useDbName, tableName);
+        } catch (Exception e) {
+            reconnect();
+            log.warn("Exception fetching table info : " +tableName + " : " + e.getMessage());
+            throw e;
+        }
+        return result;
+    }
+
+    private void reconnect() throws MetaException{
+        client.reconnect();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/main/java/org/apache/griffin/core/metastore/KafkaSchemaController.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/metastore/KafkaSchemaController.java b/service/src/main/java/org/apache/griffin/core/metastore/KafkaSchemaController.java
index f4ae18d..11149a0 100644
--- a/service/src/main/java/org/apache/griffin/core/metastore/KafkaSchemaController.java
+++ b/service/src/main/java/org/apache/griffin/core/metastore/KafkaSchemaController.java
@@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
 public class KafkaSchemaController {
 
     @Autowired
-    KafkaSchemaService kafkaSchemaService;
+    KafkaSchemaServiceImpl kafkaSchemaService;
 
     @RequestMapping("/schema/{id}")
     public SchemaString getSchemaString(@PathVariable("id") Integer id) {

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/main/java/org/apache/griffin/core/metastore/KafkaSchemaService.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/metastore/KafkaSchemaService.java b/service/src/main/java/org/apache/griffin/core/metastore/KafkaSchemaService.java
index fc1e693..bccfc50 100644
--- a/service/src/main/java/org/apache/griffin/core/metastore/KafkaSchemaService.java
+++ b/service/src/main/java/org/apache/griffin/core/metastore/KafkaSchemaService.java
@@ -18,116 +18,18 @@ package org.apache.griffin.core.metastore;
 import io.confluent.kafka.schemaregistry.client.rest.entities.Config;
 import io.confluent.kafka.schemaregistry.client.rest.entities.Schema;
 import io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.http.ResponseEntity;
-import org.springframework.stereotype.Service;
-import org.springframework.util.StringUtils;
-import org.springframework.web.client.RestTemplate;
 
-import java.util.Arrays;
+public interface KafkaSchemaService {
+    public SchemaString getSchemaString(Integer id);
 
-@Service
-public class KafkaSchemaService {
+    public Iterable<String> getSubjects();
 
-    private static final Logger log = LoggerFactory.getLogger(KafkaSchemaService.class);
+    public Iterable<Integer> getSubjectVersions(String subject);
 
-    @Value("${kafka.schema.registry.url}")
-    private String url;
+    public Schema getSubjectSchema(String subject, String version);
 
+    public Config getTopLevelConfig();
 
-    private String registryUrl(final String path) {
-        if (StringUtils.hasText(path)) {
-            String usePath = path;
-            if (!path.startsWith("/")) usePath = "/" + path;
-            return this.url + usePath;
-        }
-        return "";
-    }
+    public Config getSubjectLevelConfig(String subject);
 
-    public SchemaString getSchemaString(Integer id) {
-        String path = "/schemas/ids/" + id;
-        String regUrl = registryUrl(path);
-        SchemaString result = null;
-        try {
-            RestTemplate restTemplate = new RestTemplate();
-            ResponseEntity<SchemaString> res = restTemplate.getForEntity(regUrl, SchemaString.class);
-            result = res.getBody();
-        } catch (Exception e) {
-            log.error("Exception getting schema of id " + id + " : ", e.getMessage());
-        }
-        return result;
-    }
-
-    public Iterable<String> getSubjects() {
-        String path = "/subjects";
-        String regUrl = registryUrl(path);
-        Iterable<String> result = null;
-        try {
-            RestTemplate restTemplate = new RestTemplate();
-            ResponseEntity<String[]> res = restTemplate.getForEntity(regUrl, String[].class);
-            result = Arrays.asList(res.getBody());
-        } catch (Exception e) {
-            log.error("Exception getting subjects : ", e.getMessage());
-        }
-        return result;
-    }
-
-    public Iterable<Integer> getSubjectVersions(String subject) {
-        String path = "/subjects/" + subject + "/versions";
-        String regUrl = registryUrl(path);
-        Iterable<Integer> result = null;
-        try {
-            RestTemplate restTemplate = new RestTemplate();
-            ResponseEntity<Integer[]> res = restTemplate.getForEntity(regUrl, Integer[].class);
-            result = Arrays.asList(res.getBody());
-        } catch (Exception e) {
-            log.error("Exception getting subject " + subject + " versions : ", e.getMessage());
-        }
-        return result;
-    }
-
-    public Schema getSubjectSchema(String subject, String version) {
-        String path = "/subjects/" + subject + "/versions/" + version;
-        String regUrl = registryUrl(path);
-        Schema result = null;
-        try {
-            RestTemplate restTemplate = new RestTemplate();
-            ResponseEntity<Schema> res = restTemplate.getForEntity(regUrl, Schema.class);
-            result = res.getBody();
-        } catch (Exception e) {
-            log.error("Exception getting subject " + subject + " with version " + version + " : ", e.getMessage());
-        }
-        return result;
-    }
-
-    public Config getTopLevelConfig() {
-        String path = "/config";
-        String regUrl = registryUrl(path);
-        Config result = null;
-        try {
-            RestTemplate restTemplate = new RestTemplate();
-            ResponseEntity<Config> res = restTemplate.getForEntity(regUrl, Config.class);
-            result = res.getBody();
-        } catch (Exception e) {
-            log.error("Exception getting top level config : ", e.getMessage());
-        }
-        return result;
-    }
-
-    public Config getSubjectLevelConfig(String subject) {
-        String path = "/config/" + subject;
-        String regUrl = registryUrl(path);
-        Config result = null;
-        try {
-            RestTemplate restTemplate = new RestTemplate();
-            ResponseEntity<Config> res = restTemplate.getForEntity(regUrl, Config.class);
-            result = res.getBody();
-        } catch (Exception e) {
-            log.error("Exception getting subject " + subject + " level config : ", e.getMessage());
-        }
-        return result;
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/main/java/org/apache/griffin/core/metastore/KafkaSchemaServiceImpl.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/metastore/KafkaSchemaServiceImpl.java b/service/src/main/java/org/apache/griffin/core/metastore/KafkaSchemaServiceImpl.java
new file mode 100644
index 0000000..87209c2
--- /dev/null
+++ b/service/src/main/java/org/apache/griffin/core/metastore/KafkaSchemaServiceImpl.java
@@ -0,0 +1,140 @@
+/*-
+ * Licensed 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.griffin.core.metastore;
+
+import io.confluent.kafka.schemaregistry.client.rest.entities.Config;
+import io.confluent.kafka.schemaregistry.client.rest.entities.Schema;
+import io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.Arrays;
+
+@Service
+public class KafkaSchemaServiceImpl implements KafkaSchemaService{
+
+    private static final Logger log = LoggerFactory.getLogger(KafkaSchemaServiceImpl.class);
+
+    @Value("${kafka.schema.registry.url}")
+    private String url;
+
+    RestTemplate restTemplate = new RestTemplate();
+
+    private String registryUrl(final String path) {
+        if (StringUtils.hasText(path)) {
+            String usePath = path;
+            if (!path.startsWith("/")) usePath = "/" + path;
+            return this.url + usePath;
+        }
+        return "";
+    }
+
+    @Override
+    public SchemaString getSchemaString(Integer id) {
+        String path = "/schemas/ids/" + id;
+        String regUrl = registryUrl(path);
+        SchemaString result = null;
+        try {
+//            RestTemplate restTemplate = new RestTemplate();
+            ResponseEntity<SchemaString> res = restTemplate.getForEntity(regUrl, SchemaString.class);
+            result = res.getBody();
+        } catch (Exception e) {
+            log.error("Exception getting schema of id " + id + " : ", e.getMessage());
+        }
+        return result;
+    }
+
+    @Override
+    public Iterable<String> getSubjects() {
+        String path = "/subjects";
+        String regUrl = registryUrl(path);
+        Iterable<String> result = null;
+        try {
+//            RestTemplate restTemplate = new RestTemplate();
+            ResponseEntity<String[]> res = restTemplate.getForEntity(regUrl, String[].class);
+            result = Arrays.asList(res.getBody());
+        } catch (Exception e) {
+            log.error("Exception getting subjects : ", e.getMessage());
+        }
+        return result;
+    }
+
+    @Override
+    public Iterable<Integer> getSubjectVersions(String subject) {
+        String path = "/subjects/" + subject + "/versions";
+        String regUrl = registryUrl(path);
+        Iterable<Integer> result = null;
+        try {
+//            RestTemplate restTemplate = new RestTemplate();
+            ResponseEntity<Integer[]> res = restTemplate.getForEntity(regUrl, Integer[].class);
+            result = Arrays.asList(res.getBody());
+        } catch (Exception e) {
+            log.error("Exception getting subject " + subject + " versions : ", e.getMessage());
+        }
+        return result;
+    }
+
+    @Override
+    public Schema getSubjectSchema(String subject, String version) {
+        String path = "/subjects/" + subject + "/versions/" + version;
+        String regUrl = registryUrl(path);
+        Schema result = null;
+        try {
+//            RestTemplate restTemplate = new RestTemplate();
+            ResponseEntity<Schema> res = restTemplate.getForEntity(regUrl, Schema.class);
+            result = res.getBody();
+        } catch (Exception e) {
+            log.error("Exception getting subject " + subject + " with version " + version + " : ", e.getMessage());
+        }
+        return result;
+    }
+
+    @Override
+    public Config getTopLevelConfig() {
+        String path = "/config";
+        String regUrl = registryUrl(path);
+        Config result = null;
+        try {
+//            RestTemplate restTemplate = new RestTemplate();
+            ResponseEntity<Config> res = restTemplate.getForEntity(regUrl, Config.class);
+
+            result = res.getBody();
+        } catch (Exception e) {
+            log.error("Exception getting top level config : ", e.getMessage());
+        }
+        return result;
+    }
+
+    @Override
+    public Config getSubjectLevelConfig(String subject) {
+        String path = "/config/" + subject;
+        String regUrl = registryUrl(path);
+        Config result = null;
+        try {
+//            RestTemplate restTemplate = new RestTemplate();
+            ResponseEntity<Config> res = restTemplate.getForEntity(regUrl, Config.class);
+            result = res.getBody();
+        } catch (Exception e) {
+            log.error("Exception getting subject " + subject + " level config : ", e.getMessage());
+        }
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/main/java/org/apache/griffin/core/schedule/JobHealth.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/schedule/JobHealth.java b/service/src/main/java/org/apache/griffin/core/schedule/JobHealth.java
index 56ed981..f9af7cc 100644
--- a/service/src/main/java/org/apache/griffin/core/schedule/JobHealth.java
+++ b/service/src/main/java/org/apache/griffin/core/schedule/JobHealth.java
@@ -10,13 +10,10 @@ 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.griffin.core.schedule;
 
-/**
- * Created by xiangrchen on 6/1/17.
- */
+
 public class JobHealth {
     private int health;
     private int invalid;

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/main/java/org/apache/griffin/core/schedule/Repo/ScheduleStateRepo.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/schedule/Repo/ScheduleStateRepo.java b/service/src/main/java/org/apache/griffin/core/schedule/Repo/ScheduleStateRepo.java
index 4ab04f7..e49901d 100644
--- a/service/src/main/java/org/apache/griffin/core/schedule/Repo/ScheduleStateRepo.java
+++ b/service/src/main/java/org/apache/griffin/core/schedule/Repo/ScheduleStateRepo.java
@@ -10,10 +10,10 @@ 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.griffin.core.schedule.Repo;
 
+
 import org.apache.griffin.core.schedule.ScheduleState;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.Query;
@@ -22,9 +22,7 @@ import org.springframework.stereotype.Repository;
 
 import java.util.List;
 
-/**
- * Created by xiangrchen on 5/31/17.
- */
+
 @Repository
 public interface ScheduleStateRepo extends CrudRepository<ScheduleState,Long>{
     @Query("select s from ScheduleState s " +

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/main/java/org/apache/griffin/core/schedule/SchedulerController.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/schedule/SchedulerController.java b/service/src/main/java/org/apache/griffin/core/schedule/SchedulerController.java
index beae5b7..6447fa9 100644
--- a/service/src/main/java/org/apache/griffin/core/schedule/SchedulerController.java
+++ b/service/src/main/java/org/apache/griffin/core/schedule/SchedulerController.java
@@ -15,29 +15,18 @@ limitations under the License.
 
 package org.apache.griffin.core.schedule;
 
-import org.apache.griffin.core.schedule.Repo.ScheduleStateRepo;
-import org.quartz.*;
-import org.quartz.impl.matchers.GroupMatcher;
+import org.quartz.SchedulerException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.domain.Sort;
-import org.springframework.scheduling.quartz.SchedulerFactoryBean;
 import org.springframework.web.bind.annotation.*;
 
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import java.io.Serializable;
 import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.*;
-
-import static org.quartz.JobBuilder.newJob;
-import static org.quartz.JobKey.jobKey;
-import static org.quartz.TriggerBuilder.newTrigger;
-import static org.quartz.TriggerKey.triggerKey;
+import java.util.List;
+import java.util.Map;
 
 @RestController
 @RequestMapping("/jobs")
@@ -45,187 +34,38 @@ public class SchedulerController {
     private static final Logger LOGGER = LoggerFactory.getLogger(SchedulerController.class);
 
     @Autowired
-    private SchedulerFactoryBean factory;
-    @Autowired
-    private ScheduleStateRepo scheduleStateRepo;
-
-    public static final String ACCURACY_BATCH_GROUP = "BA";
+    SchedulerService schedulerService;
 
     @RequestMapping("/")
-    public List<Map<String, Serializable>> jobs() throws SchedulerException,
+    public List<Map<String, Serializable>> getJobs() throws SchedulerException,
             ParseException {
-        Scheduler scheduler = factory.getObject();
-
-        List<Map<String, Serializable>> list = new ArrayList<>();
-        for (String groupName : scheduler.getJobGroupNames()) {
-            for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher
-                    .jobGroupEquals(groupName))) {
-                String jobName = jobKey.getName();
-                String jobGroup = jobKey.getGroup();
-
-                JobDetail jd = scheduler.getJobDetail(jobKey);
-
-                List<Trigger> triggers = (List<Trigger>) scheduler
-                        .getTriggersOfJob(jobKey);
-                Map<String, Serializable> map = new HashMap<>();
-
-                if (triggers.size() > 0) {
-                    //always get next run
-                    Date nextFireTime = triggers.get(0).getNextFireTime();
-                    Date previousFireTime=triggers.get(0).getPreviousFireTime();
-//                    triggers.get(0).getScheduleBuilder()
-
-                    Trigger.TriggerState triggerState=scheduler.getTriggerState(triggers.get(0).getKey());
-
-                    map.put("jobName", jobName);
-                    map.put("groupName", jobGroup);
-                    map.put("nextFireTime", nextFireTime.getTime());
-                    if (previousFireTime!=null)
-                        map.put("previousFireTime",previousFireTime.getTime());
-                    else
-                        map.put("previousFireTime",-1);
-                    map.put("triggerState",triggerState);
-
-                    map.put("measure", (String) jd.getJobDataMap().get("measure"));
-                    map.put("sourcePat",jd.getJobDataMap().getString("sourcePat"));
-                    map.put("targetPat",jd.getJobDataMap().getString("targetPat"));
-                    System.out.print("dataStartTimestamp:"+jd.getJobDataMap().getString("dataStartTimestamp"));
-                    if(jd.getJobDataMap().getString("dataStartTimestamp")!=null && !jd.getJobDataMap().getString("dataStartTimestamp").equals(""))
-                        map.put("dataStartTimestamp",jd.getJobDataMap().getString("dataStartTimestamp"));
-                    map.put("jobStartTime",jd.getJobDataMap().getString("jobStartTime"));
-                    map.put("periodTime",jd.getJobDataMap().getString("periodTime"));
-                    list.add(map);
-                }
-
-            }
-        }
-        return list;
-    }
-
-    @RequestMapping(value = "/{groupName}/{jobName}", method = RequestMethod.DELETE)
-    public String removeTask(@PathVariable String groupName, @PathVariable String jobName)
-            throws SchedulerException {
-        Scheduler scheduler = factory.getObject();
-        JobKey jobKey = new JobKey(jobName, groupName);
-        scheduler.deleteJob(jobKey);
-        return "task has been removed";
+        return schedulerService.getJobs();
     }
 
-    //@RequestMapping(value = "/add/{groupName}/{jobName}/{measureName}/{sourcePat}/{targetPat}")
     @RequestMapping(value = "/add/{groupName}/{jobName}/{measureName}", method = RequestMethod.POST)
     @ResponseBody
     @Produces(MediaType.APPLICATION_JSON)
-    public Boolean addTask(@PathVariable String groupName,
+    public boolean addJob(@PathVariable String groupName,
                            @PathVariable String jobName,
                            @PathVariable String measureName,
                            @RequestBody SchedulerRequestBody schedulerRequestBody) {
-        //@RequestParam(value = "sourcePat", required = false) String sourcePat,
-        //@RequestParam(value = "targetPat", required = false) String targetPat
-//        int jobStartTime = 0;
-        Date jobStartTime=null;
-        int periodTime = 0;
-        SimpleDateFormat format=new SimpleDateFormat("YYYYMMdd HH:mm:ss");
-        try{
-            periodTime = Integer.parseInt(schedulerRequestBody.getPeriodTime());
-            jobStartTime=format.parse(schedulerRequestBody.getJobStartTime());
-        }catch (Exception e){
-            LOGGER.info("jobStartTime or periodTime format error! "+e);
-            return false;
-        }
-        try {
-            Scheduler scheduler = factory.getObject();
-            TriggerKey triggerKey = triggerKey(jobName, groupName);
-
-            if (scheduler.checkExists(triggerKey)) {
-                scheduler.unscheduleJob(triggerKey);
-            }
-            JobKey jobKey = jobKey(jobName, groupName);
-            JobDetail jobDetail;
-            if (scheduler.checkExists(jobKey)) {
-                jobDetail = scheduler.getJobDetail(jobKey);
-                setJobDetail(jobDetail,schedulerRequestBody,measureName,groupName,jobName);
-                scheduler.addJob(jobDetail, true);
-            } else {
-                jobDetail = newJob(SparkSubmitJob.class)
-                        .storeDurably()
-                        .withIdentity(jobKey)
-                        .build();
-
-                setJobDetail(jobDetail,schedulerRequestBody,measureName,groupName,jobName);
-                scheduler.addJob(jobDetail, false);
-            }
-
-            Trigger trigger = newTrigger()
-                    .withIdentity(triggerKey)
-                    .forJob(jobDetail)
-                    //hardcode to
-//					.withSchedule(CronScheduleBuilder.cronSchedule("0 0/1 0 * * ?"))
-                    .withSchedule(SimpleScheduleBuilder.simpleSchedule()
-                            .withIntervalInSeconds(periodTime)
-                            .repeatForever())
-                    .startAt(jobStartTime)
-                    .build();
-            scheduler.scheduleJob(trigger);
-
-            return true;
-
-        } catch (SchedulerException e) {
-            LOGGER.error("", e);
-            return false;
-        }
-    }
-
-    private void setJobDetail(JobDetail jobDetail,SchedulerRequestBody schedulerRequestBody,String measureName,String groupName,String jobName){
-        jobDetail.getJobDataMap().put("measure", measureName);
-        jobDetail.getJobDataMap().put("sourcePat", schedulerRequestBody.getSourcePat());
-        jobDetail.getJobDataMap().put("targetPat", schedulerRequestBody.getTargetPat());
-        jobDetail.getJobDataMap().put("dataStartTimestamp", schedulerRequestBody.getDataStartTimestamp());
-        jobDetail.getJobDataMap().put("jobStartTime", schedulerRequestBody.getJobStartTime());
-        jobDetail.getJobDataMap().put("periodTime", schedulerRequestBody.getPeriodTime());
-        jobDetail.getJobDataMap().put("lastTime", "");
-        jobDetail.getJobDataMap().put("groupName",groupName);
-        jobDetail.getJobDataMap().put("jobName",jobName);
+        return schedulerService.addJob(groupName,jobName,measureName,schedulerRequestBody);
     }
 
-    @RequestMapping(value = "/groups/{group}/jobs/{name}", method = RequestMethod.DELETE)
+    @RequestMapping(value = "/del/{group}/{name}", method = RequestMethod.DELETE)
     public boolean deleteJob(@PathVariable String group, @PathVariable String name) {
-        try {
-            Scheduler scheduler = factory.getObject();
-            scheduler.deleteJob(new JobKey(name, group));
-            return true;
-        } catch (SchedulerException e) {
-            LOGGER.error(e.getMessage());
-            return false;
-        }
+        return schedulerService.deleteJob(group,name);
     }
 
-    @RequestMapping("/instances/groups/{group}/jobs/{name}/{page}/{size}")
-    public List<ScheduleState> findInstancesOfJob(@PathVariable String group,@PathVariable String name,@PathVariable int page,@PathVariable int size){
-        Pageable pageRequest=new PageRequest(page,size, Sort.Direction.DESC,"timestamp");
-        return scheduleStateRepo.findByGroupNameAndJobName(group,name,pageRequest);
+    @RequestMapping("/instances/{group}/{jobName}/{page}/{size}")
+    public List<ScheduleState> findInstancesOfJob(@PathVariable String group,@PathVariable String jobName,
+                                                  @PathVariable int page,@PathVariable int size){
+        return schedulerService.findInstancesOfJob(group,jobName,page,size);
     }
 
     @RequestMapping("/statics")
     public JobHealth getHealthInfo() throws SchedulerException {
-        Scheduler scheduler=factory.getObject();
-        int jobCount=scheduler.getJobGroupNames().size();
-        int health=0;
-        int invalid=0;
-        for (String groupName : scheduler.getJobGroupNames()){
-            for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))){
-                String jobName=jobKey.getName();
-                String jobGroup=jobKey.getGroup();
-                Pageable pageRequest=new PageRequest(0,1, Sort.Direction.DESC,"timestamp");
-                ScheduleState scheduleState=scheduleStateRepo.findByGroupNameAndJobName(jobGroup,jobName,pageRequest).get(0);
-                if(scheduleState.getState().equals("starting")){
-                    health++;
-                }else{
-                    invalid++;
-                }
-            }
-        }
-        JobHealth jobHealth=new JobHealth(health,invalid,jobCount);
-        return jobHealth;
+        return schedulerService.getHealthInfo();
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/main/java/org/apache/griffin/core/schedule/SchedulerRequestBody.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/schedule/SchedulerRequestBody.java b/service/src/main/java/org/apache/griffin/core/schedule/SchedulerRequestBody.java
index d33472f..a5671b4 100644
--- a/service/src/main/java/org/apache/griffin/core/schedule/SchedulerRequestBody.java
+++ b/service/src/main/java/org/apache/griffin/core/schedule/SchedulerRequestBody.java
@@ -65,4 +65,39 @@ public class SchedulerRequestBody {
         this.periodTime = periodTime;
     }
 
+    public SchedulerRequestBody(String sourcePat, String targetPat, String dataStartTimestamp, String jobStartTime, String periodTime) {
+        this.sourcePat = sourcePat;
+        this.targetPat = targetPat;
+        this.dataStartTimestamp = dataStartTimestamp;
+        this.jobStartTime = jobStartTime;
+        this.periodTime = periodTime;
+    }
+
+    public SchedulerRequestBody() {
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        SchedulerRequestBody that = (SchedulerRequestBody) o;
+
+        if (sourcePat != null ? !sourcePat.equals(that.sourcePat) : that.sourcePat != null) return false;
+        if (targetPat != null ? !targetPat.equals(that.targetPat) : that.targetPat != null) return false;
+        if (dataStartTimestamp != null ? !dataStartTimestamp.equals(that.dataStartTimestamp) : that.dataStartTimestamp != null)
+            return false;
+        if (jobStartTime != null ? !jobStartTime.equals(that.jobStartTime) : that.jobStartTime != null) return false;
+        return periodTime != null ? periodTime.equals(that.periodTime) : that.periodTime == null;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = sourcePat != null ? sourcePat.hashCode() : 0;
+        result = 31 * result + (targetPat != null ? targetPat.hashCode() : 0);
+        result = 31 * result + (dataStartTimestamp != null ? dataStartTimestamp.hashCode() : 0);
+        result = 31 * result + (jobStartTime != null ? jobStartTime.hashCode() : 0);
+        result = 31 * result + (periodTime != null ? periodTime.hashCode() : 0);
+        return result;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/main/java/org/apache/griffin/core/schedule/SchedulerService.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/schedule/SchedulerService.java b/service/src/main/java/org/apache/griffin/core/schedule/SchedulerService.java
new file mode 100644
index 0000000..5d57ba1
--- /dev/null
+++ b/service/src/main/java/org/apache/griffin/core/schedule/SchedulerService.java
@@ -0,0 +1,24 @@
+package org.apache.griffin.core.schedule;
+
+import org.quartz.SchedulerException;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by xiangrchen on 6/7/17.
+ */
+public interface SchedulerService {
+    public List<Map<String, Serializable>> getJobs() throws SchedulerException;
+
+    public Boolean addJob(String groupName,String jobName,String measureName,SchedulerRequestBody schedulerRequestBody);
+
+    public Boolean deleteJob(String groupName,String jobName);
+
+    public List<ScheduleState> findInstancesOfJob(String group,String name,int page,int size);
+
+    public JobHealth getHealthInfo() throws SchedulerException;
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/main/java/org/apache/griffin/core/schedule/SchedulerServiceImpl.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/schedule/SchedulerServiceImpl.java b/service/src/main/java/org/apache/griffin/core/schedule/SchedulerServiceImpl.java
new file mode 100644
index 0000000..7c70623
--- /dev/null
+++ b/service/src/main/java/org/apache/griffin/core/schedule/SchedulerServiceImpl.java
@@ -0,0 +1,214 @@
+/*-
+ * Licensed 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.griffin.core.schedule;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.griffin.core.schedule.Repo.ScheduleStateRepo;
+import org.quartz.*;
+import org.quartz.impl.matchers.GroupMatcher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.scheduling.quartz.SchedulerFactoryBean;
+import org.springframework.stereotype.Service;
+
+import java.io.Serializable;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+import static org.quartz.JobBuilder.newJob;
+import static org.quartz.JobKey.jobKey;
+import static org.quartz.TriggerBuilder.newTrigger;
+import static org.quartz.TriggerKey.triggerKey;
+
+@Service
+public class SchedulerServiceImpl implements SchedulerService{
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(SchedulerServiceImpl.class);
+
+    @Autowired
+    private SchedulerFactoryBean factory;
+    @Autowired
+    private ScheduleStateRepo scheduleStateRepo;
+
+    public static final String ACCURACY_BATCH_GROUP = "BA";
+
+
+    @Override
+    public List<Map<String, Serializable>> getJobs() throws SchedulerException {
+        Scheduler scheduler = factory.getObject();
+        List<Map<String, Serializable>> list = new ArrayList<>();
+        for (String groupName : scheduler.getJobGroupNames()) {
+            for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher
+                    .jobGroupEquals(groupName))) {
+                setJobsByKey(list,scheduler, jobKey);
+            }
+        }
+        return list;
+    }
+
+    public void setJobsByKey(List<Map<String, Serializable>> list,Scheduler scheduler, JobKey jobKey) throws SchedulerException {
+        List<Trigger> triggers = (List<Trigger>) scheduler.getTriggersOfJob(jobKey);
+        if (triggers.size() > 0) {
+            //always get next run
+            Map<String, Serializable> map = new HashMap<>();
+            setMap(map,scheduler,jobKey);
+            list.add(map);
+        }
+    }
+
+
+    public void setMap(Map<String, Serializable> map,Scheduler scheduler,JobKey jobKey) throws SchedulerException {
+        List<Trigger> triggers = (List<Trigger>) scheduler.getTriggersOfJob(jobKey);
+        JobDetail jd = scheduler.getJobDetail(jobKey);
+        Date nextFireTime = triggers.get(0).getNextFireTime();
+        Date previousFireTime=triggers.get(0).getPreviousFireTime();
+        Trigger.TriggerState triggerState=scheduler.getTriggerState(triggers.get(0).getKey());
+
+        map.put("jobName", jobKey.getName());
+        map.put("groupName", jobKey.getGroup());
+        if (nextFireTime!=null){
+            map.put("nextFireTime", nextFireTime.getTime());
+        }
+        else {
+            map.put("nextFireTime", -1);
+        }
+        if (previousFireTime!=null) {
+            map.put("previousFireTime", previousFireTime.getTime());
+        }
+        else {
+            map.put("previousFireTime", -1);
+        }
+        map.put("triggerState",triggerState);
+        map.put("measure", jd.getJobDataMap().getString("measure"));
+        map.put("sourcePat",jd.getJobDataMap().getString("sourcePat"));
+        map.put("targetPat",jd.getJobDataMap().getString("targetPat"));
+        if(StringUtils.isNotEmpty(jd.getJobDataMap().getString("dataStartTimestamp"))) {
+            map.put("dataStartTimestamp", jd.getJobDataMap().getString("dataStartTimestamp"));
+        }
+        map.put("jobStartTime",jd.getJobDataMap().getString("jobStartTime"));
+        map.put("periodTime",jd.getJobDataMap().getString("periodTime"));
+    }
+
+    @Override
+    public Boolean addJob(String groupName, String jobName, String measureName, SchedulerRequestBody schedulerRequestBody) {
+        Date jobStartTime=null;
+        int periodTime = 0;
+        SimpleDateFormat format=new SimpleDateFormat("YYYYMMdd HH:mm:ss");
+        try{
+            periodTime = Integer.parseInt(schedulerRequestBody.getPeriodTime());
+            jobStartTime=format.parse(schedulerRequestBody.getJobStartTime());
+        }catch (Exception e){
+            LOGGER.info("jobStartTime or periodTime format error! "+e);
+            return false;
+        }
+        try {
+            Scheduler scheduler = factory.getObject();
+            TriggerKey triggerKey = triggerKey(jobName, groupName);
+            if (scheduler.checkExists(triggerKey)) {
+                scheduler.unscheduleJob(triggerKey);
+            }
+            JobKey jobKey = jobKey(jobName, groupName);
+            JobDetail jobDetail;
+            if (scheduler.checkExists(jobKey)) {
+                jobDetail = scheduler.getJobDetail(jobKey);
+                setJobDetail(jobDetail,schedulerRequestBody,measureName,groupName,jobName);
+                scheduler.addJob(jobDetail, true);
+            } else {
+                jobDetail = newJob(SparkSubmitJob.class)
+                        .storeDurably()
+                        .withIdentity(jobKey)
+                        .build();
+                setJobDetail(jobDetail,schedulerRequestBody,measureName,groupName,jobName);
+                scheduler.addJob(jobDetail, false);
+            }
+            Trigger trigger = newTrigger()
+                    .withIdentity(triggerKey)
+                    .forJob(jobDetail)
+//					.withSchedule(CronScheduleBuilder.cronSchedule("0 0/1 0 * * ?"))
+                    .withSchedule(SimpleScheduleBuilder.simpleSchedule()
+                            .withIntervalInSeconds(periodTime)
+                            .repeatForever())
+                    .startAt(jobStartTime)
+                    .build();
+            scheduler.scheduleJob(trigger);
+            return true;
+        } catch (SchedulerException e) {
+            LOGGER.error("", e);
+            return false;
+        }
+    }
+
+    public void setJobDetail(JobDetail jobDetail,SchedulerRequestBody schedulerRequestBody,String measureName,String groupName,String jobName){
+        jobDetail.getJobDataMap().put("measure", measureName);
+        jobDetail.getJobDataMap().put("sourcePat", schedulerRequestBody.getSourcePat());
+        jobDetail.getJobDataMap().put("targetPat", schedulerRequestBody.getTargetPat());
+        jobDetail.getJobDataMap().put("dataStartTimestamp", schedulerRequestBody.getDataStartTimestamp());
+        jobDetail.getJobDataMap().put("jobStartTime", schedulerRequestBody.getJobStartTime());
+        jobDetail.getJobDataMap().put("periodTime", schedulerRequestBody.getPeriodTime());
+        jobDetail.getJobDataMap().put("lastTime", "");
+        jobDetail.getJobDataMap().put("groupName",groupName);
+        jobDetail.getJobDataMap().put("jobName",jobName);
+    }
+
+    @Override
+    public Boolean deleteJob(String group, String name) {
+        try {
+            Scheduler scheduler = factory.getObject();
+            scheduler.deleteJob(new JobKey(name, group));
+            return true;
+        } catch (SchedulerException e) {
+            LOGGER.error(e.getMessage());
+            return false;
+        }
+    }
+
+    @Override
+    public List<ScheduleState> findInstancesOfJob(String group, String name, int page, int size) {
+        Pageable pageRequest=new PageRequest(page,size, Sort.Direction.DESC,"timestamp");
+        return scheduleStateRepo.findByGroupNameAndJobName(group,name,pageRequest);
+    }
+
+    @Override
+    public JobHealth getHealthInfo() throws SchedulerException {
+        Scheduler scheduler=factory.getObject();
+        int jobCount=scheduler.getJobGroupNames().size();
+        int health=0;
+        int invalid=0;
+        for (String groupName : scheduler.getJobGroupNames()){
+            for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))){
+                String jobName=jobKey.getName();
+                String jobGroup=jobKey.getGroup();
+                Pageable pageRequest=new PageRequest(0,1, Sort.Direction.DESC,"timestamp");
+                ScheduleState scheduleState=new ScheduleState();
+                if (scheduleStateRepo.findByGroupNameAndJobName(jobGroup,jobName,pageRequest)!=null
+                        &&scheduleStateRepo.findByGroupNameAndJobName(jobGroup,jobName,pageRequest).size()>0){
+                    scheduleState=scheduleStateRepo.findByGroupNameAndJobName(jobGroup,jobName,pageRequest).get(0);
+                    if(scheduleState.getState().equals("starting")){
+                        health++;
+                    }else{
+                        invalid++;
+                    }
+                }
+            }
+        }
+        JobHealth jobHealth=new JobHealth(health,invalid,jobCount);
+        return jobHealth;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/main/java/org/apache/griffin/core/schedule/SparkSubmitJob.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/schedule/SparkSubmitJob.java b/service/src/main/java/org/apache/griffin/core/schedule/SparkSubmitJob.java
index ac533f7..f66c599 100644
--- a/service/src/main/java/org/apache/griffin/core/schedule/SparkSubmitJob.java
+++ b/service/src/main/java/org/apache/griffin/core/schedule/SparkSubmitJob.java
@@ -19,6 +19,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.ObjectWriter;
 import com.google.gson.Gson;
+import org.apache.commons.lang.StringUtils;
 import org.apache.griffin.core.measure.DataConnector;
 import org.apache.griffin.core.measure.Measure;
 import org.apache.griffin.core.measure.repo.MeasureRepo;
@@ -108,14 +109,14 @@ public class SparkSubmitJob implements Job {
         periodTime = jd.getJobDataMap().getString("periodTime");
         //prepare current system timestamp
         long currentSystemTimestamp = System.currentTimeMillis();
-
-        if (sourcePattern != null && !sourcePattern.equals("")) {
+        logger.info("currentSystemTimestamp: "+currentSystemTimestamp);
+        if (StringUtils.isNotEmpty(sourcePattern)) {
             sourcePatternItemSet = sourcePattern.split("-");
             long currentTimstamp = setCurrentTimestamp(currentSystemTimestamp);
             setDataConnectorPartitions(measure.getSource(), sourcePatternItemSet, partitionItemSet, currentTimstamp);
             jd.getJobDataMap().put("lastTime", currentTimstamp + "");
         }
-        if (targetPattern != null && !targetPattern.equals("")) {
+        if (StringUtils.isNotEmpty(targetPattern)) {
             targetPatternItemSet = targetPattern.split("-");
             long currentTimstamp = setCurrentTimestamp(currentSystemTimestamp);
             setDataConnectorPartitions(measure.getTarget(), targetPatternItemSet, partitionItemSet, currentTimstamp);
@@ -124,10 +125,9 @@ public class SparkSubmitJob implements Job {
         //final String uri = "http://10.9.246.187:8998/batches";
         RestTemplate restTemplate = new RestTemplate();
         setSparkJobDO();
-//        String result = restTemplate.postForObject(uri, sparkJobDO, String.class);
-        logger.info("measure: \n"+measure);
         String result = restTemplate.postForObject(uri, sparkJobDO, String.class);
         logger.info(result);
+        //save result info into DataBase
         ScheduleResult scheduleResult=new ScheduleResult();
         Gson gson=new Gson();
         try {
@@ -135,8 +135,10 @@ public class SparkSubmitJob implements Job {
         }catch (Exception e){
             logger.info("scheduleResult covert error!"+e);
         }
-        ScheduleState scheduleState=new ScheduleState(groupName,jobName,scheduleResult.getId(),scheduleResult.getState(),scheduleResult.getAppId(),System.currentTimeMillis());
-        scheduleStateRepo.save(scheduleState);
+        if(scheduleResult!=null) {
+            ScheduleState scheduleState = new ScheduleState(groupName, jobName, scheduleResult.getId(), scheduleResult.getState(), scheduleResult.getAppId(), System.currentTimeMillis());
+            scheduleStateRepo.save(scheduleState);
+        }
     }
 
     public Map<String, String> genPartitions(String[] patternItemSet, String[] partitionItemSet, long timestamp) {
@@ -170,14 +172,14 @@ public class SparkSubmitJob implements Job {
 
     public long setCurrentTimestamp(long currentSystemTimestamp) {
         long currentTimstamp=0;
-        if (eachJoblastTimestamp != null && !eachJoblastTimestamp.equals("")) {
+        if (StringUtils.isNotEmpty(eachJoblastTimestamp)) {
             try {
                 currentTimstamp = Long.parseLong(eachJoblastTimestamp) + Integer.parseInt(periodTime) * 1000;
             }catch (Exception e){
                 logger.info("lasttime or periodTime format problem! "+e);
             }
         } else {
-            if (dataStartTimestamp != null && !dataStartTimestamp.equals("")) {
+            if (StringUtils.isNotEmpty(dataStartTimestamp)) {
                 try{
                     currentTimstamp = Long.parseLong(dataStartTimestamp);
                 }catch (Exception e){
@@ -225,8 +227,6 @@ public class SparkSubmitJob implements Job {
         sparkJobDO.setJars(jars);
 
         List<String> files = new ArrayList<>();
-//        files.add(props.getProperty("sparkJob.files_1"));
-
         sparkJobDO.setFiles(files);
     }
 
@@ -245,7 +245,7 @@ public class SparkSubmitJob implements Job {
                 throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");
             }
         } catch (Exception e) {
-            System.out.println("Exception: " + e);
+            logger.info("Exception: " + e);
         } finally {
             inputStream.close();
         }

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/main/resources/application-dev.properties
----------------------------------------------------------------------
diff --git a/service/src/main/resources/application-dev.properties b/service/src/main/resources/application-dev.properties
index 12f8865..9574b38 100644
--- a/service/src/main/resources/application-dev.properties
+++ b/service/src/main/resources/application-dev.properties
@@ -6,7 +6,7 @@ spring.datasource.driver-class-name=com.mysql.jdbc.Driver
 
 ## Hibernate ddl auto (validate,create, create-drop, update)
 
-spring.jpa.hibernate.ddl-auto = create-drop
+spring.jpa.hibernate.ddl-auto = update
 spring.jpa.show-sql=true
 spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
 #

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/test/java/org/apache/griffin/core/measure/MeasureControllerTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/measure/MeasureControllerTest.java b/service/src/test/java/org/apache/griffin/core/measure/MeasureControllerTest.java
new file mode 100644
index 0000000..3da5d6f
--- /dev/null
+++ b/service/src/test/java/org/apache/griffin/core/measure/MeasureControllerTest.java
@@ -0,0 +1,177 @@
+/*-
+ * Licensed 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.griffin.core.measure;
+
+import org.apache.griffin.core.util.GriffinOperationMessage;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.MediaType;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.servlet.MockMvc;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.mockito.BDDMockito.given;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+@RunWith(SpringRunner.class)
+@WebMvcTest(value=MeasureController.class,secure = false)
+public class MeasureControllerTest {
+    @Autowired
+    private MockMvc mvc;
+
+    @MockBean
+    private MeasureService service;
+
+    @Before
+    public void setup(){
+    }
+
+    @Test
+    public void testGetAllMeasures() throws IOException,Exception{
+        Measure measure = createATestMeasure("viewitem_hourly","bullseye");
+
+        given(service.getAllMeasures()).willReturn(Arrays.asList(measure));
+
+        mvc.perform(get("/measures").contentType(MediaType.APPLICATION_JSON))
+//                .andDo(print())
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.[0].name",is("viewitem_hourly")))
+        ;
+    }
+
+
+    @Test
+    public void testGetMeasuresById() throws IOException,Exception{
+        Measure measure = createATestMeasure("viewitem_hourly","bullseye");
+
+        given(service.getMeasuresById(1L)).willReturn(measure);
+
+        mvc.perform(get("/measures/1").contentType(MediaType.APPLICATION_JSON))
+//                .andDo(print())
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.name",is("viewitem_hourly")))
+        ;
+    }
+
+    @Test
+    public void testGetMeasureByName() throws IOException,Exception{
+        Measure measure = createATestMeasure("viewitem_hourly","bullseye");
+
+        given(service.getMeasuresByName("viewitem_hourly")).willReturn(measure);
+
+        mvc.perform(get("/measures/findByName/viewitem_hourly").contentType(MediaType.APPLICATION_JSON))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.name",is("viewitem_hourly")))
+        ;
+    }
+    @Test
+    public void testDeleteMeasuresById() throws Exception{
+        Mockito.doNothing().when(service).deleteMeasuresById(1L);
+
+        mvc.perform(delete("/measures/deleteById/1").contentType(MediaType.APPLICATION_JSON))
+                .andExpect(status().isOk())
+        ;
+    }
+
+    @Test
+    public void testDeleteMeasuresByName() throws Exception{
+        String measureName="viewitem_hourly";
+        given(service.deleteMeasuresByName(measureName)).willReturn(GriffinOperationMessage.DELETE_MEASURE_BY_NAME_SUCCESS);
+
+        mvc.perform(delete("/measures/deleteByName/"+measureName).contentType(MediaType.APPLICATION_JSON))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$",is("DELETE_MEASURE_BY_NAME_SUCCESS")))
+        ;
+    }
+
+    @Test
+    public void testUpdateMeasure() throws Exception{
+        String measureName="viewitem_hourly";
+        String org="bullseye";
+        Measure measure=createATestMeasure(measureName,org);
+        ObjectMapper mapper=new ObjectMapper();
+        String measureJson=mapper.writeValueAsString(measure);
+        given(service.updateMeasure(measure)).willReturn(GriffinOperationMessage.UPDATE_MEASURE_SUCCESS);
+
+        mvc.perform(post("/measures/update").contentType(MediaType.APPLICATION_JSON).content(measureJson))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$",is("UPDATE_MEASURE_SUCCESS")))
+        ;
+    }
+
+    @Test
+    public void testGetAllMeasureNameOfOwner() throws Exception{
+        String Owner="test1";
+        String measureName="viewitem_hourly";
+        given(service.getAllMeasureNameByOwner(Owner)).willReturn(Arrays.asList(measureName));
+
+        mvc.perform(get("/measures/owner/"+Owner).contentType(MediaType.APPLICATION_JSON))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.[0]",is("viewitem_hourly")))
+        ;
+    }
+
+    @Test
+    public void testCreateNewMeasure() throws Exception{
+        String measureName="viewitem_hourly";
+        String org="bullseye";
+        Measure measure=createATestMeasure(measureName,org);
+        ObjectMapper mapper=new ObjectMapper();
+        String measureJson=mapper.writeValueAsString(measure);
+        given(service.createNewMeasure(measure)).willReturn(GriffinOperationMessage.CREATE_MEASURE_SUCCESS);
+
+        mvc.perform(post("/measures/add").contentType(MediaType.APPLICATION_JSON).content(measureJson))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$",is("CREATE_MEASURE_SUCCESS")))
+        ;
+    }
+
+    private Measure createATestMeasure(String name,String org)throws IOException,Exception{
+        HashMap<String,String> configMap1=new HashMap<>();
+        configMap1.put("database","default");
+        configMap1.put("table.name","test_data_src");
+        HashMap<String,String> configMap2=new HashMap<>();
+        configMap2.put("database","default");
+        configMap2.put("table.name","test_data_tgt");
+        String configJson1 = new ObjectMapper().writeValueAsString(configMap1);
+        String configJson2 = new ObjectMapper().writeValueAsString(configMap2);
+
+        DataConnector source = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson1);
+        DataConnector target = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson2);
+
+        String rules = "$source.uage > 100 AND $source.uid = $target.uid AND $source.uage + 12 = $target.uage + 10 + 2 AND $source.udes + 11 = $target.udes + 1 + 1";
+
+        EvaluateRule eRule = new EvaluateRule(1,rules);
+
+        Measure measure = new Measure(name,"bevssoj description", Measure.MearuseType.accuracy, org, source, target, eRule,"test1");
+
+        return measure;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ae6a308b/service/src/test/java/org/apache/griffin/core/measure/MeasureServiceImplTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/measure/MeasureServiceImplTest.java b/service/src/test/java/org/apache/griffin/core/measure/MeasureServiceImplTest.java
new file mode 100644
index 0000000..66ff5fe
--- /dev/null
+++ b/service/src/test/java/org/apache/griffin/core/measure/MeasureServiceImplTest.java
@@ -0,0 +1,192 @@
+/*-
+* Licensed 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.griffin.core.measure;
+
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.griffin.core.measure.repo.MeasureRepo;
+import org.apache.griffin.core.util.GriffinOperationMessage;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.fail;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.BDDMockito.given;
+
+@RunWith(SpringRunner.class)
+public class MeasureServiceImplTest {
+
+    @TestConfiguration
+    public static class MeasureServiceImplConfiguration{
+        @Bean
+        public MeasureServiceImpl service(){
+            return new MeasureServiceImpl();
+        }
+    }
+    @MockBean
+    private MeasureRepo measureRepo;
+
+    @Autowired
+    private MeasureServiceImpl service;
+
+    @Before
+    public void setup(){
+    }
+
+    @Test
+    public void testGetAllMeasures(){
+        try {
+            Iterable<Measure> tmp = service.getAllMeasures();
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot get all Measure from dbs");
+        }
+    }
+
+    @Test
+    public void testGetMeasuresById(){
+        try {
+            Measure tmp = service.getMeasuresById(1);
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot get Measure in db By Id: 1");
+        }
+    }
+
+    @Test
+    public void testGetMeasuresByName(){
+        try {
+            Measure tmp = service.getMeasuresByName("viewitem_hourly");
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot get Measure in db By name: viewitem_hourly");
+        }
+    }
+
+    @Test
+    public void testDeleteMeasuresById(){
+        try {
+            service.deleteMeasuresById(1L);
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot delete Measure in db By Id: 1");
+        }
+    }
+
+    @Test
+    public void testDeleteMeasuresByName(){
+        try {
+            String measureName="viewitem_hourly";
+            given(measureRepo.findByName(measureName)).willReturn(null);
+            GriffinOperationMessage message=service.deleteMeasuresByName("viewitem_hourly");
+            assertEquals(message,GriffinOperationMessage.RESOURCE_NOT_FOUND);
+            assertTrue(true);
+
+            String org="bullseye";
+            Measure measure=createATestMeasure(measureName,org);
+            given(measureRepo.findByName(measureName)).willReturn(measure);
+            GriffinOperationMessage message1=service.deleteMeasuresByName("viewitem_hourly");
+            assertEquals(message1,GriffinOperationMessage.DELETE_MEASURE_BY_NAME_SUCCESS);
+        }catch (Throwable t){
+            fail("Cannot delete Measure in db By name: viewitem_hourly");
+        }
+    }
+
+    @Test
+    public void testCreateNewMeasure(){
+        try {
+            String measureName="viewitem_hourly";
+            String org="bullseye";
+            Measure measure=createATestMeasure(measureName,org);
+            given(measureRepo.findByName(measureName)).willReturn(null);
+            GriffinOperationMessage message=service.createNewMeasure(measure);
+            assertEquals(message,GriffinOperationMessage.CREATE_MEASURE_FAIL);
+            assertTrue(true);
+
+            Measure measure1=createATestMeasure(measureName,"bullseye1");
+            given(measureRepo.findByName(measureName)).willReturn(measure1);
+            GriffinOperationMessage message1=service.createNewMeasure(measure);
+            assertEquals(message1,GriffinOperationMessage.CREATE_MEASURE_FAIL_DUPLICATE);
+
+            given(measureRepo.findByName(measureName)).willReturn(null);
+            given(measureRepo.save(measure)).willReturn(measure);
+            GriffinOperationMessage message2=service.createNewMeasure(measure);
+            assertEquals(message2,GriffinOperationMessage.CREATE_MEASURE_SUCCESS);
+        }catch (Throwable t){
+            fail("Cannot create new measure viewitem_hourly");
+        }
+    }
+
+    @Test
+    public void testGetAllMeasureNameByOwner(){
+        try {
+            String measureName="viewitem_hourly";
+            String org="bullseye";
+            Measure measure=createATestMeasure(measureName,org);
+            String owner="test1";
+            given(measureRepo.findAll()).willReturn(Arrays.asList(measure));
+            List<String> namelist=service.getAllMeasureNameByOwner(owner);
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot get all measure name by owner test1");
+        }
+    }
+
+    @Test
+    public void testUpdateMeasure(){
+        try {
+            String measureName="viewitem_hourly";
+            String org="bullseye";
+            Measure measure=createATestMeasure(measureName,org);
+            GriffinOperationMessage message=service.updateMeasure(measure);
+            assertTrue(true);
+        }catch (Throwable t){
+            fail("Cannot create new measure viewitem_hourly");
+        }
+    }
+
+    private Measure createATestMeasure(String name,String org)throws IOException,Exception{
+        HashMap<String,String> configMap1;
+        configMap1 = new HashMap<>();
+        configMap1.put("database","default");
+        configMap1.put("table.name","test_data_src");
+        HashMap<String,String> configMap2=new HashMap<>();
+        configMap2.put("database","default");
+        configMap2.put("table.name","test_data_tgt");
+        String configJson1 = new ObjectMapper().writeValueAsString(configMap1);
+        String configJson2 = new ObjectMapper().writeValueAsString(configMap2);
+        DataConnector source = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson1);
+        DataConnector target = new DataConnector(DataConnector.ConnectorType.HIVE, "1.2", configJson2);
+
+        String rules = "$source.uage > 100 AND $source.uid = $target.uid AND $source.uage + 12 = $target.uage + 10 + 2 AND $source.udes + 11 = $target.udes + 1 + 1";
+        EvaluateRule eRule = new EvaluateRule(1,rules);
+        Measure measure = new Measure(name,"bevssoj description", Measure.MearuseType.accuracy, org, source, target, eRule,"test1");
+        return measure;
+    }
+
+}