Browse Source

Merge branch 'dev' of github.com:analysys/EasyScheduler into dev

pull/2/head
杨钦龙 6 years ago
parent
commit
91a8289c09
  1. 36
      escheduler-api/pom.xml
  2. 8
      escheduler-api/src/main/java/cn/escheduler/api/ApiApplicationServer.java
  3. 50
      escheduler-api/src/main/java/cn/escheduler/api/configuration/AppConfiguration.java
  4. 55
      escheduler-api/src/main/java/cn/escheduler/api/configuration/SwaggerConfig.java
  5. 52
      escheduler-api/src/main/java/cn/escheduler/api/configuration/SwaggerI18nPlugin.java
  6. 19
      escheduler-api/src/main/java/cn/escheduler/api/controller/LoginController.java
  7. 4
      escheduler-api/src/main/java/cn/escheduler/api/service/SchedulerService.java
  8. 5
      escheduler-api/src/main/resources/application.properties
  9. 5
      escheduler-api/src/main/resources/messages.properties
  10. 5
      escheduler-api/src/main/resources/messages_en_US.properties
  11. 5
      escheduler-api/src/main/resources/messages_zh_CN.properties
  12. 2
      escheduler-common/src/main/java/cn/escheduler/common/queue/ITaskQueue.java
  13. 2
      escheduler-dao/src/main/java/cn/escheduler/dao/mapper/ProcessInstanceMapperProvider.java
  14. 2
      escheduler-dao/src/main/java/cn/escheduler/dao/mapper/UserMapperProvider.java
  15. 6
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/UserMapperTest.java
  16. 5
      escheduler-server/pom.xml
  17. 4
      escheduler-server/src/main/java/cn/escheduler/server/master/MasterServer.java
  18. 6
      escheduler-server/src/main/java/cn/escheduler/server/quartz/ProcessScheduleJob.java
  19. 2
      escheduler-server/src/main/java/cn/escheduler/server/quartz/QuartzExecutors.java
  20. 3
      escheduler-server/src/main/java/cn/escheduler/server/worker/runner/FetchTaskThread.java
  21. 7
      pom.xml

36
escheduler-api/pom.xml

@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.analysys</groupId>
@ -10,13 +11,10 @@
<dependencies>
<dependency>
<groupId>cn.analysys</groupId>
<artifactId>escheduler-dao</artifactId>
</dependency>
<dependency>
<groupId>cn.analysys</groupId>
<artifactId>escheduler-common</artifactId>
<artifactId>escheduler-server</artifactId>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
@ -38,7 +36,6 @@
</dependency>
<!--springboot-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
@ -142,6 +139,24 @@
<artifactId>quartz-jobs</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>cn.analysys</groupId>
<artifactId>escheduler-rpc</artifactId>
@ -153,6 +168,11 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>1.5.12</version>
</dependency>
</dependencies>
<build>
@ -187,4 +207,4 @@
</plugin>
</plugins>
</build>
</project>
</project>

8
escheduler-api/src/main/java/cn/escheduler/api/ApiApplicationServer.java

@ -19,13 +19,19 @@ package cn.escheduler.api;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication
@ServletComponentScan
@ComponentScan("cn.escheduler")
public class ApiApplicationServer {
@EnableSwagger2
public class ApiApplicationServer extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(ApiApplicationServer.class, args);
}
}

50
escheduler-api/src/main/java/cn/escheduler/api/configuration/AppConfiguration.java

@ -20,6 +20,12 @@ import cn.escheduler.api.interceptor.LoginHandlerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import java.util.Locale;
/**
* application configuration
@ -31,16 +37,48 @@ public class AppConfiguration implements WebMvcConfigurer {
public static final String LOGIN_PATH_PATTERN = "/login";
public static final String PATH_PATTERN = "/**";
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(loginInterceptor()).addPathPatterns(LOGIN_INTERCEPTOR_PATH_PATTERN).excludePathPatterns(LOGIN_PATH_PATTERN);
}
@Bean
public LoginHandlerInterceptor loginInterceptor() {
return new LoginHandlerInterceptor();
}
//Cookie
@Bean
public LocaleResolver localeResolver() {
CookieLocaleResolver localeResolver = new CookieLocaleResolver();
localeResolver.setCookieName("localeCookie");
//设置默认区域
localeResolver.setDefaultLocale(Locale.ENGLISH);
localeResolver.setCookieMaxAge(3600);//设置cookie有效期.
return localeResolver;
}
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
// 参数名
lci.setParamName("lang");
return lci;
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(loginInterceptor()).addPathPatterns(LOGIN_INTERCEPTOR_PATH_PATTERN).excludePathPatterns(LOGIN_PATH_PATTERN,"/swagger-resources/**", "/webjars/**", "/v2/**", "/doc.html", "*.html");
//i18n
registry.addInterceptor(localeChangeInterceptor());
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping(PATH_PATTERN).allowedOrigins("*").allowedMethods("*");
@ -56,4 +94,8 @@ public class AppConfiguration implements WebMvcConfigurer {
public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false);
}
}

55
escheduler-api/src/main/java/cn/escheduler/api/configuration/SwaggerConfig.java

@ -0,0 +1,55 @@
/*
* 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 cn.escheduler.api.configuration;
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
*
* swager2 config class <br/>
*
*/
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfig implements WebMvcConfigurer {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
.apis(RequestHandlerSelectors.basePackage("cn.escheduler.api.controller")).paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("Easy Scheduler Api Docs").description("Easy Scheduler Api Docs")
.version("1.0.0").build();
}
}

52
escheduler-api/src/main/java/cn/escheduler/api/configuration/SwaggerI18nPlugin.java

@ -0,0 +1,52 @@
package cn.escheduler.api.configuration;
import java.util.List;
import java.util.Locale;
import com.fasterxml.classmate.TypeResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.OperationBuilderPlugin;
import springfox.documentation.spi.service.contexts.OperationContext;
@Component
@Order(Ordered.HIGHEST_PRECEDENCE - 10)
public class SwaggerI18nPlugin implements OperationBuilderPlugin {
private static final Logger logger = LoggerFactory.getLogger(SwaggerI18nPlugin.class);
@Autowired
private MessageSource messageSource;
@Override
public void apply(OperationContext context) {
Locale locale = LocaleContextHolder.getLocale();
List<ApiOperation> list = context.findAllAnnotations(ApiOperation.class);
if (list.size() > 0) {
for(ApiOperation api : list){
context.operationBuilder().summary(messageSource.getMessage(api.value(), null, locale));
context.operationBuilder().notes(messageSource.getMessage(api.notes(), null, locale));
}
}
}
@Override
public boolean supports(DocumentationType delimiter) {
return true;
}
}

19
escheduler-api/src/main/java/cn/escheduler/api/controller/LoginController.java

@ -23,17 +23,25 @@ import cn.escheduler.api.service.UsersService;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.Result;
import cn.escheduler.dao.model.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;
import static cn.escheduler.api.enums.Status.*;
/**
@ -41,16 +49,22 @@ import static cn.escheduler.api.enums.Status.*;
*/
@RestController
@RequestMapping("")
@Api(value = "", tags = {"中国"}, description = "中国")
public class LoginController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(LoginController.class);
private Locale locale = LocaleContextHolder.getLocale();
@Autowired
private SessionService sessionService;
@Autowired
private UsersService userService;
@Autowired
private MessageSource messageSource;
/**
* login
*
@ -60,6 +74,11 @@ public class LoginController extends BaseController {
* @param response
* @return
*/
@ApiOperation(value = "test", notes="loginNotes")
@ApiImplicitParams({
@ApiImplicitParam(name = "userName", value = "userName", required = true, type = "String"),
@ApiImplicitParam(name = "userPassword", value = "userPassword", required = true, type ="String")
})
@RequestMapping(value = "/login")
public Result login(@RequestParam(value = "userName") String userName,
@RequestParam(value = "userPassword") String userPassword,

4
escheduler-api/src/main/java/cn/escheduler/api/service/SchedulerService.java

@ -19,8 +19,8 @@ package cn.escheduler.api.service;
import cn.escheduler.api.dto.ScheduleParam;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.quartz.ProcessScheduleJob;
import cn.escheduler.api.quartz.QuartzExecutors;
import cn.escheduler.server.quartz.ProcessScheduleJob;
import cn.escheduler.server.quartz.QuartzExecutors;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.PageInfo;
import cn.escheduler.common.enums.FailureStrategy;

5
escheduler-api/src/main/resources/application.properties

@ -12,3 +12,8 @@ spring.servlet.multipart.max-request-size=1024MB
#post content
server.jetty.max-http-post-size=5000000
spring.messages.encoding=UTF-8
#i18n classpath folder , file prefix messages, if have many files, use "," seperator
spring.messages.basename=messages

5
escheduler-api/src/main/resources/messages.properties

@ -0,0 +1,5 @@
welcome=hello, welcome !
test=test
userName=user name
userPassword=user password
loginNotes=login notes

5
escheduler-api/src/main/resources/messages_en_US.properties

@ -0,0 +1,5 @@
welcome=hello, welcome !
test=test
userName=user name
userPassword=user password
loginNotes=login notes

5
escheduler-api/src/main/resources/messages_zh_CN.properties

@ -0,0 +1,5 @@
welcome=您好,欢迎你!
test=测试
userName=用户名
userPassword=用户密码
loginNotes=登录xxx

2
escheduler-common/src/main/java/cn/escheduler/common/queue/ITaskQueue.java

@ -54,7 +54,7 @@ public interface ITaskQueue {
* an element pops out of the queue
*
* @param key queue name
* @param remove where remove the element
* @param remove whether remove the element
* @return
*/
String poll(String key, boolean remove);

2
escheduler-dao/src/main/java/cn/escheduler/dao/mapper/ProcessInstanceMapperProvider.java

@ -220,7 +220,7 @@ public class ProcessInstanceMapperProvider {
public String queryDetailById(Map<String, Object> parameter) {
return new SQL() {
{
SELECT("inst.*,q.queue_name as queue,t.tenant_code as tenantCode,UNIX_TIMESTAMP(inst.end_time)-UNIX_TIMESTAMP(inst.start_time) as duration");
SELECT("inst.*,q.queue_name as queue,t.tenant_code,UNIX_TIMESTAMP(inst.end_time)-UNIX_TIMESTAMP(inst.start_time) as duration");
FROM(TABLE_NAME + " inst, t_escheduler_user u,t_escheduler_tenant t,t_escheduler_queue q");

2
escheduler-dao/src/main/java/cn/escheduler/dao/mapper/UserMapperProvider.java

@ -208,7 +208,7 @@ public class UserMapperProvider {
public String queryDetailsById(Map<String, Object> parameter) {
return new SQL() {
{
SELECT("u.*,q.queue_name as queueName,t.tenant_name as tenantName");
SELECT("u.*,q.queue_name,t.tenant_name");
FROM(TABLE_NAME + " u,t_escheduler_tenant t,t_escheduler_queue q");

6
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/UserMapperTest.java

@ -72,4 +72,10 @@ public class UserMapperTest {
Assert.assertEquals(user.getUserName(), "qiaozhanwei");
}
@Test
public void test(){
User user = userMapper.queryDetailsById(19);
System.out.println(user);
}
}

5
escheduler-server/pom.xml

@ -46,10 +46,7 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>cn.analysys</groupId>
<artifactId>escheduler-api</artifactId>
</dependency>
<dependency>
<groupId>cn.analysys</groupId>
<artifactId>escheduler-rpc</artifactId>

4
escheduler-server/src/main/java/cn/escheduler/server/master/MasterServer.java

@ -16,8 +16,8 @@
*/
package cn.escheduler.server.master;
import cn.escheduler.api.quartz.ProcessScheduleJob;
import cn.escheduler.api.quartz.QuartzExecutors;
import cn.escheduler.server.quartz.ProcessScheduleJob;
import cn.escheduler.server.quartz.QuartzExecutors;
import cn.escheduler.common.Constants;
import cn.escheduler.common.IStoppable;
import cn.escheduler.common.thread.Stopper;

6
escheduler-api/src/main/java/cn/escheduler/api/quartz/ProcessScheduleJob.java → escheduler-server/src/main/java/cn/escheduler/server/quartz/ProcessScheduleJob.java

@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.api.quartz;
package cn.escheduler.server.quartz;
import cn.escheduler.common.Constants;
@ -31,8 +31,8 @@ import org.springframework.util.Assert;
import java.util.Date;
import static cn.escheduler.api.quartz.QuartzExecutors.buildJobGroupName;
import static cn.escheduler.api.quartz.QuartzExecutors.buildJobName;
import static cn.escheduler.server.quartz.QuartzExecutors.buildJobGroupName;
import static cn.escheduler.server.quartz.QuartzExecutors.buildJobName;
/**
* process schedule job

2
escheduler-api/src/main/java/cn/escheduler/api/quartz/QuartzExecutors.java → escheduler-server/src/main/java/cn/escheduler/server/quartz/QuartzExecutors.java

@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.api.quartz;
package cn.escheduler.server.quartz;
import cn.escheduler.common.Constants;
import cn.escheduler.common.utils.JSONUtils;

3
escheduler-server/src/main/java/cn/escheduler/server/worker/runner/FetchTaskThread.java

@ -134,7 +134,6 @@ public class FetchTaskThread implements Runnable{
public void run() {
while (Stopper.isRunning()){
InterProcessMutex mutex = null;
try {
if(OSUtils.checkResource(this.conf, false)) {
@ -221,7 +220,9 @@ public class FetchTaskThread implements Runnable{
logger.info("task : {} ready to submit to task scheduler thread",taskId);
// submit task
workerExecService.submit(new TaskScheduleThread(taskInstance, processDao));
}
}
}

7
pom.xml

@ -114,6 +114,11 @@
</dependency>
<dependency>
<groupId>cn.analysys</groupId>
<artifactId>escheduler-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>cn.analysys</groupId>
<artifactId>escheduler-common</artifactId>
@ -326,7 +331,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
<version>20.0</version>
</dependency>
<dependency>

Loading…
Cancel
Save