提交 dc55de4e 编写于 作者: L lidongdai

1.0.2文档发布

上级 06acbe5f
...@@ -35,35 +35,7 @@ ...@@ -35,35 +35,7 @@
</exclusions> </exclusions>
</dependency> </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--> <!--springboot-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
...@@ -170,14 +142,21 @@ ...@@ -170,14 +142,21 @@
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId> <artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version> <version>2.9.2</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId> <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>
<dependency> <dependency>
<groupId>cn.analysys</groupId> <groupId>cn.analysys</groupId>
<artifactId>escheduler-rpc</artifactId> <artifactId>escheduler-rpc</artifactId>
...@@ -189,6 +168,11 @@ ...@@ -189,6 +168,11 @@
<version>4.12</version> <version>4.12</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>1.5.12</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -19,14 +19,19 @@ package cn.escheduler.api; ...@@ -19,14 +19,19 @@ package cn.escheduler.api;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication @SpringBootApplication
@ServletComponentScan @ServletComponentScan
@ComponentScan("cn.escheduler") @ComponentScan("cn.escheduler")
public class ApiApplicationServer { @EnableSwagger2
public class ApiApplicationServer extends SpringBootServletInitializer {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(ApiApplicationServer.class, args); SpringApplication.run(ApiApplicationServer.class, args);
} }
} }
...@@ -20,6 +20,12 @@ import cn.escheduler.api.interceptor.LoginHandlerInterceptor; ...@@ -20,6 +20,12 @@ import cn.escheduler.api.interceptor.LoginHandlerInterceptor;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*; 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 * application configuration
...@@ -31,24 +37,48 @@ public class AppConfiguration implements WebMvcConfigurer { ...@@ -31,24 +37,48 @@ public class AppConfiguration implements WebMvcConfigurer {
public static final String LOGIN_PATH_PATTERN = "/login"; public static final String LOGIN_PATH_PATTERN = "/login";
public static final String PATH_PATTERN = "/**"; 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 @Bean
public LoginHandlerInterceptor loginInterceptor() { public LoginHandlerInterceptor loginInterceptor() {
return new LoginHandlerInterceptor(); 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 @Override
public void addCorsMappings(CorsRegistry registry) { public void addCorsMappings(CorsRegistry registry) {
registry.addMapping(PATH_PATTERN).allowedOrigins("*").allowedMethods("*"); registry.addMapping(PATH_PATTERN).allowedOrigins("*").allowedMethods("*");
...@@ -64,4 +94,8 @@ public class AppConfiguration implements WebMvcConfigurer { ...@@ -64,4 +94,8 @@ public class AppConfiguration implements WebMvcConfigurer {
public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) { public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false); configurer.favorPathExtension(false);
} }
} }
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
*/ */
package cn.escheduler.api.configuration; package cn.escheduler.api.configuration;
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -35,7 +36,8 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; ...@@ -35,7 +36,8 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
*/ */
@Configuration @Configuration
@EnableSwagger2 @EnableSwagger2
public class Swagger2 implements WebMvcConfigurer { @EnableSwaggerBootstrapUI
public class SwaggerConfig implements WebMvcConfigurer {
@Bean @Bean
public Docket createRestApi() { public Docket createRestApi() {
...@@ -45,8 +47,8 @@ public class Swagger2 implements WebMvcConfigurer { ...@@ -45,8 +47,8 @@ public class Swagger2 implements WebMvcConfigurer {
} }
private ApiInfo apiInfo() { private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("api docs").description("easy scheduler api docs") return new ApiInfoBuilder().title("Easy Scheduler Api Docs").description("Easy Scheduler Api Docs")
.termsOfServiceUrl("https://www.analysys.com").version("1.0.0").build(); .version("1.0.0").build();
} }
......
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;
}
}
...@@ -23,6 +23,7 @@ import cn.escheduler.api.service.UsersService; ...@@ -23,6 +23,7 @@ import cn.escheduler.api.service.UsersService;
import cn.escheduler.api.utils.Constants; import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.Result; import cn.escheduler.api.utils.Result;
import cn.escheduler.dao.model.User; import cn.escheduler.dao.model.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -31,12 +32,16 @@ import org.apache.commons.lang3.StringUtils; ...@@ -31,12 +32,16 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; 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 org.springframework.web.bind.annotation.*;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.Locale;
import static cn.escheduler.api.enums.Status.*; import static cn.escheduler.api.enums.Status.*;
/** /**
...@@ -44,16 +49,22 @@ import static cn.escheduler.api.enums.Status.*; ...@@ -44,16 +49,22 @@ import static cn.escheduler.api.enums.Status.*;
*/ */
@RestController @RestController
@RequestMapping("") @RequestMapping("")
@Api(value = "", tags = {"中国"}, description = "中国")
public class LoginController extends BaseController { public class LoginController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(LoginController.class); private static final Logger logger = LoggerFactory.getLogger(LoginController.class);
private Locale locale = LocaleContextHolder.getLocale();
@Autowired @Autowired
private SessionService sessionService; private SessionService sessionService;
@Autowired @Autowired
private UsersService userService; private UsersService userService;
@Autowired
private MessageSource messageSource;
/** /**
* login * login
* *
...@@ -63,10 +74,10 @@ public class LoginController extends BaseController { ...@@ -63,10 +74,10 @@ public class LoginController extends BaseController {
* @param response * @param response
* @return * @return
*/ */
@ApiOperation(value="更新用户详细信息", notes="根据url的id来指定更新对象,并根据传过来的user信息来更新用户详细信息") @ApiOperation(value = "test", notes="loginNotes")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "userName", value = "用户名", required = true, dataType = "String"), @ApiImplicitParam(name = "userName", value = "userName", required = true, type = "String"),
@ApiImplicitParam(name = "userPassword", value = "密码", required = true, dataType = "String") @ApiImplicitParam(name = "userPassword", value = "userPassword", required = true, type ="String")
}) })
@RequestMapping(value = "/login") @RequestMapping(value = "/login")
public Result login(@RequestParam(value = "userName") String userName, public Result login(@RequestParam(value = "userName") String userName,
......
...@@ -12,3 +12,8 @@ spring.servlet.multipart.max-request-size=1024MB ...@@ -12,3 +12,8 @@ spring.servlet.multipart.max-request-size=1024MB
#post content #post content
server.jetty.max-http-post-size=5000000 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
welcome=hello, welcome !
test=test
userName=user name
userPassword=user password
loginNotes=login notes
\ No newline at end of file
welcome=hello, welcome !
test=test
userName=user name
userPassword=user password
loginNotes=login notes
\ No newline at end of file
welcome=您好,欢迎你!
test=测试
userName=用户名
userPassword=用户密码
loginNotes=登录xxx
\ No newline at end of file
...@@ -134,7 +134,6 @@ public class FetchTaskThread implements Runnable{ ...@@ -134,7 +134,6 @@ public class FetchTaskThread implements Runnable{
public void run() { public void run() {
while (Stopper.isRunning()){ while (Stopper.isRunning()){
long start = System.currentTimeMillis();
InterProcessMutex mutex = null; InterProcessMutex mutex = null;
try { try {
if(OSUtils.checkResource(this.conf, false)) { if(OSUtils.checkResource(this.conf, false)) {
...@@ -222,7 +221,6 @@ public class FetchTaskThread implements Runnable{ ...@@ -222,7 +221,6 @@ public class FetchTaskThread implements Runnable{
// submit task // submit task
workerExecService.submit(new TaskScheduleThread(taskInstance, processDao)); workerExecService.submit(new TaskScheduleThread(taskInstance, processDao));
logger.info("{} 耗时: {} ms",taskQueueStr,System.currentTimeMillis() - start );
} }
} }
......
...@@ -114,6 +114,11 @@ ...@@ -114,6 +114,11 @@
</dependency> </dependency>
<dependency>
<groupId>cn.analysys</groupId>
<artifactId>escheduler-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>cn.analysys</groupId> <groupId>cn.analysys</groupId>
<artifactId>escheduler-common</artifactId> <artifactId>escheduler-common</artifactId>
...@@ -326,7 +331,7 @@ ...@@ -326,7 +331,7 @@
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
<version>19.0</version> <version>20.0</version>
</dependency> </dependency>
<dependency> <dependency>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册