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 2018/03/01 08:48:01 UTC
incubator-griffin git commit: fix repeat submission and update
griffin version
Repository: incubator-griffin
Updated Branches:
refs/heads/master ada0add95 -> 4a9137d2e
fix repeat submission and update griffin version
1.fix front repeat submission
2.update griffin return version
Author: ahutsunshine <ah...@gmail.com>
Author: He Wang <wa...@qq.com>
Author: dodobel <12...@qq.com>
Closes #227 from ahutsunshine/master.
Project: http://git-wip-us.apache.org/repos/asf/incubator-griffin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-griffin/commit/4a9137d2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-griffin/tree/4a9137d2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-griffin/diff/4a9137d2
Branch: refs/heads/master
Commit: 4a9137d2eefddb11999a10d59a177314eeb5798f
Parents: ada0add
Author: ahutsunshine <ah...@gmail.com>
Authored: Thu Mar 1 16:47:47 2018 +0800
Committer: Lionel Liu <bh...@163.com>
Committed: Thu Mar 1 16:47:47 2018 +0800
----------------------------------------------------------------------
.../core/info/GriffinInfoController.java | 2 +-
.../apache/griffin/core/interceptor/Token.java | 28 ++++++++
.../core/interceptor/TokenInterceptor.java | 74 ++++++++++++++++++++
.../core/interceptor/WebAppConfigurer.java | 33 +++++++++
.../apache/griffin/core/job/JobController.java | 2 +
.../apache/griffin/core/job/JobInstance.java | 2 +
.../apache/griffin/core/job/JobServiceImpl.java | 2 +
.../apache/griffin/core/job/SparkSubmitJob.java | 14 ++--
.../griffin/core/measure/MeasureController.java | 2 +
.../measure/entity/AbstractAuditableEntity.java | 15 ++--
.../griffin/core/metric/MetricServiceImpl.java | 2 +-
.../core/info/GriffinInfoControllerTest.java | 2 +-
12 files changed, 160 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/4a9137d2/service/src/main/java/org/apache/griffin/core/info/GriffinInfoController.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/info/GriffinInfoController.java b/service/src/main/java/org/apache/griffin/core/info/GriffinInfoController.java
index a3d403a..5c3c87a 100644
--- a/service/src/main/java/org/apache/griffin/core/info/GriffinInfoController.java
+++ b/service/src/main/java/org/apache/griffin/core/info/GriffinInfoController.java
@@ -29,6 +29,6 @@ public class GriffinInfoController {
@RequestMapping(value = "/version", method = RequestMethod.GET)
public String greeting() {
- return "0.1.0";
+ return "0.2.0";
}
}
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/4a9137d2/service/src/main/java/org/apache/griffin/core/interceptor/Token.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/interceptor/Token.java b/service/src/main/java/org/apache/griffin/core/interceptor/Token.java
new file mode 100644
index 0000000..440d2a3
--- /dev/null
+++ b/service/src/main/java/org/apache/griffin/core/interceptor/Token.java
@@ -0,0 +1,28 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+package org.apache.griffin.core.interceptor;
+
+import java.lang.annotation.*;
+
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface Token {
+}
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/4a9137d2/service/src/main/java/org/apache/griffin/core/interceptor/TokenInterceptor.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/interceptor/TokenInterceptor.java b/service/src/main/java/org/apache/griffin/core/interceptor/TokenInterceptor.java
new file mode 100644
index 0000000..2e1ea39
--- /dev/null
+++ b/service/src/main/java/org/apache/griffin/core/interceptor/TokenInterceptor.java
@@ -0,0 +1,74 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+package org.apache.griffin.core.interceptor;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.method.HandlerMethod;
+import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.lang.reflect.Method;
+
+public class TokenInterceptor extends HandlerInterceptorAdapter {
+ private static final Logger LOGGER = LoggerFactory.getLogger(TokenInterceptor.class);
+ private static final String TOKEN = "token";
+
+ @Override
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+ if (handler instanceof HandlerMethod) {
+ Method method = ((HandlerMethod) handler).getMethod();
+ Token annotation = method.getAnnotation(Token.class);
+ if (annotation != null) {
+ if (isRepeatSubmit(request)) {
+ LOGGER.warn("Please don't repeat submit url {}.", request.getServletPath());
+ return false;
+ }
+ return true;
+ }
+ return true;
+ } else {
+ return super.preHandle(request, response, handler);
+ }
+
+ }
+
+ private boolean isRepeatSubmit(HttpServletRequest request) {
+ String curToken = request.getHeader(TOKEN);
+ HttpSession session = request.getSession();
+ Object preToken = session.getAttribute(TOKEN);
+ //if http header has no token,we ignore to deal with repeated submission.
+ if (curToken == null) {
+ return false;
+ } else if (preToken == null) {
+ session.setAttribute(TOKEN, curToken);
+ return false;
+ } else {
+ if (preToken.toString().equals(curToken)) {
+ return true;
+ } else {
+ session.setAttribute(TOKEN, curToken);
+ return false;
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/4a9137d2/service/src/main/java/org/apache/griffin/core/interceptor/WebAppConfigurer.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/interceptor/WebAppConfigurer.java b/service/src/main/java/org/apache/griffin/core/interceptor/WebAppConfigurer.java
new file mode 100644
index 0000000..4347c52
--- /dev/null
+++ b/service/src/main/java/org/apache/griffin/core/interceptor/WebAppConfigurer.java
@@ -0,0 +1,33 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+package org.apache.griffin.core.interceptor;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+
+@Configuration
+public class WebAppConfigurer extends WebMvcConfigurerAdapter {
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(new TokenInterceptor()).addPathPatterns("/api/v1/measures").addPathPatterns("/api/v1/jobs");
+ super.addInterceptors(registry);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/4a9137d2/service/src/main/java/org/apache/griffin/core/job/JobController.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/job/JobController.java b/service/src/main/java/org/apache/griffin/core/job/JobController.java
index 2d09d8b..37bac4f 100644
--- a/service/src/main/java/org/apache/griffin/core/job/JobController.java
+++ b/service/src/main/java/org/apache/griffin/core/job/JobController.java
@@ -19,6 +19,7 @@ under the License.
package org.apache.griffin.core.job;
+import org.apache.griffin.core.interceptor.Token;
import org.apache.griffin.core.job.entity.JobDataBean;
import org.apache.griffin.core.job.entity.JobHealth;
import org.apache.griffin.core.job.entity.JobInstanceBean;
@@ -48,6 +49,7 @@ public class JobController {
@RequestMapping(value = "/jobs", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
+ @Token
public JobSchedule addJob(@RequestBody JobSchedule jobSchedule) throws Exception {
return jobService.addJob(jobSchedule);
}
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/4a9137d2/service/src/main/java/org/apache/griffin/core/job/JobInstance.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/job/JobInstance.java b/service/src/main/java/org/apache/griffin/core/job/JobInstance.java
index 8df02af..f30bc0e 100644
--- a/service/src/main/java/org/apache/griffin/core/job/JobInstance.java
+++ b/service/src/main/java/org/apache/griffin/core/job/JobInstance.java
@@ -101,6 +101,7 @@ public class JobInstance implements Job {
}
+ @SuppressWarnings("unchecked")
private void setJobStartTime(JobDetail jobDetail) throws SchedulerException {
Scheduler scheduler = factory.getScheduler();
JobKey jobKey = jobDetail.getKey();
@@ -223,6 +224,7 @@ public class JobInstance implements Job {
return TimeZone.getTimeZone(timezone);
}
+ @SuppressWarnings("unchecked")
private boolean createJobInstance(Map<String, Object> confMap) throws Exception {
Map<String, Object> config = (Map<String, Object>) confMap.get("checkdonefile.schedule");
Long interval = TimeUtil.str2Long((String) config.get("interval"));
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/4a9137d2/service/src/main/java/org/apache/griffin/core/job/JobServiceImpl.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/job/JobServiceImpl.java b/service/src/main/java/org/apache/griffin/core/job/JobServiceImpl.java
index af1312c..e671c47 100644
--- a/service/src/main/java/org/apache/griffin/core/job/JobServiceImpl.java
+++ b/service/src/main/java/org/apache/griffin/core/job/JobServiceImpl.java
@@ -104,6 +104,7 @@ public class JobServiceImpl implements JobService {
return dataList;
}
+ @SuppressWarnings("unchecked")
private JobDataBean genJobData(JobKey jobKey, GriffinJob job) throws SchedulerException {
Scheduler scheduler = factory.getScheduler();
List<Trigger> triggers = (List<Trigger>) scheduler.getTriggersOfJob(jobKey);
@@ -538,6 +539,7 @@ public class JobServiceImpl implements JobService {
return jobHealth;
}
+ @SuppressWarnings("unchecked")
private List<Trigger> getTriggers(GriffinJob job) {
JobKey jobKey = new JobKey(job.getQuartzName(), job.getQuartzGroup());
List<Trigger> triggers;
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/4a9137d2/service/src/main/java/org/apache/griffin/core/job/SparkSubmitJob.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/job/SparkSubmitJob.java b/service/src/main/java/org/apache/griffin/core/job/SparkSubmitJob.java
index 88ea11d..8a4bfe2 100644
--- a/service/src/main/java/org/apache/griffin/core/job/SparkSubmitJob.java
+++ b/service/src/main/java/org/apache/griffin/core/job/SparkSubmitJob.java
@@ -85,7 +85,7 @@ public class SparkSubmitJob implements Job {
int repeatCount = simpleTrigger.getRepeatCount();
int fireCount = simpleTrigger.getTimesTriggered();
if (fireCount > repeatCount) {
- saveJobInstance(null, LivySessionStates.State.not_found, true);
+ saveJobInstance(null, LivySessionStates.State.not_found);
}
}
@@ -128,12 +128,14 @@ public class SparkSubmitJob implements Job {
setMeasureInstanceName(measure, jd);
}
+ @SuppressWarnings("unchecked")
private void setPredicates(String json) throws IOException {
if (StringUtils.isEmpty(json)) {
return;
}
List<Map<String, Object>> maps = JsonUtil.toEntity(json, new TypeReference<List<Map>>() {
});
+ assert maps != null;
for (Map<String, Object> map : maps) {
SegmentPredicate sp = new SegmentPredicate();
sp.setType((String) map.get("type"));
@@ -203,23 +205,23 @@ public class SparkSubmitJob implements Job {
jobService.pauseJob(group, name);
LOGGER.info("Delete predicate job({},{}) success.", group, name);
}
- saveJobInstance(result, LivySessionStates.State.found, true);
+ saveJobInstance(result, LivySessionStates.State.found);
}
- private void saveJobInstance(String result, LivySessionStates.State state, Boolean pauseStatus) throws IOException {
+ private void saveJobInstance(String result, LivySessionStates.State state) throws IOException {
TypeReference<HashMap<String, Object>> type = new TypeReference<HashMap<String, Object>>() {
};
Map<String, Object> resultMap = null;
if (result != null) {
resultMap = JsonUtil.toEntity(result, type);
}
- setJobInstance(resultMap, state, pauseStatus);
+ setJobInstance(resultMap, state);
jobInstanceRepo.save(jobInstance);
}
- private void setJobInstance(Map<String, Object> resultMap, LivySessionStates.State state, Boolean pauseStatus) {
+ private void setJobInstance(Map<String, Object> resultMap, LivySessionStates.State state) {
jobInstance.setState(state);
- jobInstance.setDeleted(pauseStatus);
+ jobInstance.setDeleted(true);
if (resultMap == null) {
return;
}
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/4a9137d2/service/src/main/java/org/apache/griffin/core/measure/MeasureController.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/measure/MeasureController.java b/service/src/main/java/org/apache/griffin/core/measure/MeasureController.java
index d7917e4..f8ba3bf 100644
--- a/service/src/main/java/org/apache/griffin/core/measure/MeasureController.java
+++ b/service/src/main/java/org/apache/griffin/core/measure/MeasureController.java
@@ -19,6 +19,7 @@ under the License.
package org.apache.griffin.core.measure;
+import org.apache.griffin.core.interceptor.Token;
import org.apache.griffin.core.measure.entity.Measure;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@@ -67,6 +68,7 @@ public class MeasureController {
@RequestMapping(value = "/measures", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
+ @Token
public Measure createMeasure(@RequestBody Measure measure) {
return measureService.createMeasure(measure);
}
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/4a9137d2/service/src/main/java/org/apache/griffin/core/measure/entity/AbstractAuditableEntity.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/measure/entity/AbstractAuditableEntity.java b/service/src/main/java/org/apache/griffin/core/measure/entity/AbstractAuditableEntity.java
index 015633e..72125de 100644
--- a/service/src/main/java/org/apache/griffin/core/measure/entity/AbstractAuditableEntity.java
+++ b/service/src/main/java/org/apache/griffin/core/measure/entity/AbstractAuditableEntity.java
@@ -38,7 +38,7 @@ public abstract class AbstractAuditableEntity implements Serializable {
private Long id;
@JsonIgnore
- private Timestamp createdDate = new Timestamp(System.currentTimeMillis());
+ private Long createdDate = System.currentTimeMillis();
@JsonIgnore
private Timestamp modifiedDate;
@@ -51,11 +51,11 @@ public abstract class AbstractAuditableEntity implements Serializable {
this.id = id;
}
- public Timestamp getCreatedDate() {
+ public Long getCreatedDate() {
return createdDate;
}
- public void setCreatedDate(Timestamp createdDate) {
+ public void setCreatedDate(Long createdDate) {
this.createdDate = createdDate;
}
@@ -88,13 +88,10 @@ public abstract class AbstractAuditableEntity implements Serializable {
}
AbstractAuditableEntity other = (AbstractAuditableEntity) obj;
if (id == null) {
- if (other.id != null) {
- return false;
- }
- } else if (!id.equals(other.id)) {
- return false;
+ return other.id == null;
+ } else {
+ return id.equals(other.id);
}
- return true;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/4a9137d2/service/src/main/java/org/apache/griffin/core/metric/MetricServiceImpl.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/metric/MetricServiceImpl.java b/service/src/main/java/org/apache/griffin/core/metric/MetricServiceImpl.java
index c126e29..a4d7cdd 100644
--- a/service/src/main/java/org/apache/griffin/core/metric/MetricServiceImpl.java
+++ b/service/src/main/java/org/apache/griffin/core/metric/MetricServiceImpl.java
@@ -70,7 +70,7 @@ public class MetricServiceImpl implements MetricService {
List<AbstractJob> jobList = entry.getValue();
List<Metric> metrics = new ArrayList<>();
for (AbstractJob job : jobList) {
- List<MetricValue> metricValues = getMetricValues(job.getMetricName(), 0, 300, job.getCreatedDate().getTime());
+ List<MetricValue> metricValues = getMetricValues(job.getMetricName(), 0, 300, job.getCreatedDate());
metrics.add(new Metric(job.getMetricName(), measure.getDqType(), measure.getOwner(), metricValues));
}
metricMap.put(measure.getName(), metrics);
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/4a9137d2/service/src/test/java/org/apache/griffin/core/info/GriffinInfoControllerTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/info/GriffinInfoControllerTest.java b/service/src/test/java/org/apache/griffin/core/info/GriffinInfoControllerTest.java
index 426d705..5ef2735 100644
--- a/service/src/test/java/org/apache/griffin/core/info/GriffinInfoControllerTest.java
+++ b/service/src/test/java/org/apache/griffin/core/info/GriffinInfoControllerTest.java
@@ -43,6 +43,6 @@ public class GriffinInfoControllerTest {
public void testGreeting() throws Exception {
mockMvc.perform(get(URLHelper.API_VERSION_PATH + "/version"))
.andExpect(status().isOk())
- .andExpect(jsonPath("$", is("0.1.0")));
+ .andExpect(jsonPath("$", is("0.2.0")));
}
}
\ No newline at end of file