Browse Source

1.0.2文档发布

pull/2/head
lidongdai 6 years ago
parent
commit
dc55de4e86
  1. 44
      escheduler-api/pom.xml
  2. 7
      escheduler-api/src/main/java/cn/escheduler/api/ApiApplicationServer.java
  3. 58
      escheduler-api/src/main/java/cn/escheduler/api/configuration/AppConfiguration.java
  4. 8
      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. 17
      escheduler-api/src/main/java/cn/escheduler/api/controller/LoginController.java
  7. 5
      escheduler-api/src/main/resources/application.properties
  8. 5
      escheduler-api/src/main/resources/messages.properties
  9. 5
      escheduler-api/src/main/resources/messages_en_US.properties
  10. 5
      escheduler-api/src/main/resources/messages_zh_CN.properties
  11. 2
      escheduler-server/src/main/java/cn/escheduler/server/worker/runner/FetchTaskThread.java
  12. 7
      pom.xml

44
escheduler-api/pom.xml

@ -35,35 +35,7 @@
</exclusions>
</dependency>
<!--<dependency>-->
<!--<groupId>cn.analysys</groupId>-->
<!--<artifactId>escheduler-dao</artifactId>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>cn.analysys</groupId>-->
<!--<artifactId>escheduler-common</artifactId>-->
<!--<exclusions>-->
<!--<exclusion>-->
<!--<groupId>io.netty</groupId>-->
<!--<artifactId>netty</artifactId>-->
<!--</exclusion>-->
<!--<exclusion>-->
<!--<groupId>io.netty</groupId>-->
<!--<artifactId>netty-all</artifactId>-->
<!--</exclusion>-->
<!--<exclusion>-->
<!--<groupId>com.google</groupId>-->
<!--<artifactId>netty</artifactId>-->
<!--</exclusion>-->
<!--<exclusion>-->
<!--<artifactId>leveldbjni-all</artifactId>-->
<!--<groupId>org.fusesource.leveldbjni</groupId>-->
<!--</exclusion>-->
<!--</exclusions>-->
<!--</dependency>-->
<!--springboot-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
@ -170,14 +142,21 @@
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
<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>
@ -189,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>

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

@ -19,14 +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);
}
}

58
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,24 +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,"/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html");
}
//
// @Override
// public void addResourceHandlers(ResourceHandlerRegistry registry) {
// registry.addResourceHandler("swagger-ui.html")
// .addResourceLocations("classpath:/META-INF/resources/");
// registry.addResourceHandler("/webjars/**")
// .addResourceLocations("classpath:/META-INF/resources/webjars/");
// }
@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("*");
@ -64,4 +94,8 @@ public class AppConfiguration implements WebMvcConfigurer {
public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false);
}
}

8
escheduler-api/src/main/java/cn/escheduler/api/configuration/Swagger2.java → escheduler-api/src/main/java/cn/escheduler/api/configuration/SwaggerConfig.java

@ -16,6 +16,7 @@
*/
package cn.escheduler.api.configuration;
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -35,7 +36,8 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
*/
@Configuration
@EnableSwagger2
public class Swagger2 implements WebMvcConfigurer {
@EnableSwaggerBootstrapUI
public class SwaggerConfig implements WebMvcConfigurer {
@Bean
public Docket createRestApi() {
@ -45,8 +47,8 @@ public class Swagger2 implements WebMvcConfigurer {
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("api docs").description("easy scheduler api docs")
.termsOfServiceUrl("https://www.analysys.com").version("1.0.0").build();
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;
}
}

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

@ -23,6 +23,7 @@ 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;
@ -31,12 +32,16 @@ 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.*;
/**
@ -44,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
*
@ -63,10 +74,10 @@ public class LoginController extends BaseController {
* @param response
* @return
*/
@ApiOperation(value="更新用户详细信息", notes="根据url的id来指定更新对象,并根据传过来的user信息来更新用户详细信息")
@ApiOperation(value = "test", notes="loginNotes")
@ApiImplicitParams({
@ApiImplicitParam(name = "userName", value = "用户名", required = true, dataType = "String"),
@ApiImplicitParam(name = "userPassword", value = "密码", required = true, dataType = "String")
@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,

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-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()){
long start = System.currentTimeMillis();
InterProcessMutex mutex = null;
try {
if(OSUtils.checkResource(this.conf, false)) {
@ -222,7 +221,6 @@ public class FetchTaskThread implements Runnable{
// submit task
workerExecService.submit(new TaskScheduleThread(taskInstance, processDao));
logger.info("{} 耗时: {} ms",taskQueueStr,System.currentTimeMillis() - start );
}
}

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