From 06acbe5fd5487d144e7f66eca64c200bc73642a7 Mon Sep 17 00:00:00 2001 From: lidongdai Date: Mon, 13 May 2019 20:27:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1.0.2=E6=96=87=E6=A1=A3=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- escheduler-api/pom.xml | 50 ++++++++++++++--- .../escheduler/api/ApiApplicationServer.java | 1 + .../api/configuration/AppConfiguration.java | 10 +++- .../api/configuration/Swagger2.java | 53 +++++++++++++++++++ .../api/controller/LoginController.java | 8 +++ .../api/service/SchedulerService.java | 4 +- .../escheduler/common/queue/ITaskQueue.java | 2 +- .../mapper/ProcessInstanceMapperProvider.java | 2 +- .../dao/mapper/UserMapperProvider.java | 2 +- .../escheduler/dao/mapper/UserMapperTest.java | 6 +++ escheduler-server/pom.xml | 5 +- .../server/master/MasterServer.java | 4 +- .../server}/quartz/ProcessScheduleJob.java | 6 +-- .../server}/quartz/QuartzExecutors.java | 2 +- .../server/worker/runner/FetchTaskThread.java | 5 +- 15 files changed, 136 insertions(+), 24 deletions(-) create mode 100644 escheduler-api/src/main/java/cn/escheduler/api/configuration/Swagger2.java rename {escheduler-api/src/main/java/cn/escheduler/api => escheduler-server/src/main/java/cn/escheduler/server}/quartz/ProcessScheduleJob.java (96%) rename {escheduler-api/src/main/java/cn/escheduler/api => escheduler-server/src/main/java/cn/escheduler/server}/quartz/QuartzExecutors.java (99%) diff --git a/escheduler-api/pom.xml b/escheduler-api/pom.xml index ec94e30b27..e0e8c54a3b 100644 --- a/escheduler-api/pom.xml +++ b/escheduler-api/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 cn.analysys @@ -10,13 +11,10 @@ + cn.analysys - escheduler-dao - - - cn.analysys - escheduler-common + escheduler-server io.netty @@ -37,6 +35,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -142,6 +167,17 @@ quartz-jobs + + io.springfox + springfox-swagger2 + 2.8.0 + + + + io.springfox + springfox-swagger-ui + 2.8.0 + cn.analysys escheduler-rpc @@ -187,4 +223,4 @@ - + \ No newline at end of file diff --git a/escheduler-api/src/main/java/cn/escheduler/api/ApiApplicationServer.java b/escheduler-api/src/main/java/cn/escheduler/api/ApiApplicationServer.java index 1c66e2d4ed..5ddc72ffbc 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/ApiApplicationServer.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/ApiApplicationServer.java @@ -20,6 +20,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.context.annotation.ComponentScan; +import springfox.documentation.swagger2.annotations.EnableSwagger2; @SpringBootApplication @ServletComponentScan diff --git a/escheduler-api/src/main/java/cn/escheduler/api/configuration/AppConfiguration.java b/escheduler-api/src/main/java/cn/escheduler/api/configuration/AppConfiguration.java index 148efc1894..00272ea5a7 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/configuration/AppConfiguration.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/configuration/AppConfiguration.java @@ -33,8 +33,16 @@ public class AppConfiguration implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(loginInterceptor()).addPathPatterns(LOGIN_INTERCEPTOR_PATH_PATTERN).excludePathPatterns(LOGIN_PATH_PATTERN); + 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() { diff --git a/escheduler-api/src/main/java/cn/escheduler/api/configuration/Swagger2.java b/escheduler-api/src/main/java/cn/escheduler/api/configuration/Swagger2.java new file mode 100644 index 0000000000..1e5b9b8fcb --- /dev/null +++ b/escheduler-api/src/main/java/cn/escheduler/api/configuration/Swagger2.java @@ -0,0 +1,53 @@ +/* + * 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 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
+ * + */ +@Configuration +@EnableSwagger2 +public class Swagger2 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("api docs").description("easy scheduler api docs") + .termsOfServiceUrl("https://www.analysys.com").version("1.0.0").build(); + } + + +} diff --git a/escheduler-api/src/main/java/cn/escheduler/api/controller/LoginController.java b/escheduler-api/src/main/java/cn/escheduler/api/controller/LoginController.java index 60530c5376..061a2d404d 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/controller/LoginController.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/controller/LoginController.java @@ -23,6 +23,9 @@ 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.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; @@ -60,6 +63,11 @@ public class LoginController extends BaseController { * @param response * @return */ + @ApiOperation(value="更新用户详细信息", notes="根据url的id来指定更新对象,并根据传过来的user信息来更新用户详细信息") + @ApiImplicitParams({ + @ApiImplicitParam(name = "userName", value = "用户名", required = true, dataType = "String"), + @ApiImplicitParam(name = "userPassword", value = "密码", required = true, dataType = "String") + }) @RequestMapping(value = "/login") public Result login(@RequestParam(value = "userName") String userName, @RequestParam(value = "userPassword") String userPassword, diff --git a/escheduler-api/src/main/java/cn/escheduler/api/service/SchedulerService.java b/escheduler-api/src/main/java/cn/escheduler/api/service/SchedulerService.java index 232b9d7b15..ad6cfc7f50 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/service/SchedulerService.java +++ b/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; diff --git a/escheduler-common/src/main/java/cn/escheduler/common/queue/ITaskQueue.java b/escheduler-common/src/main/java/cn/escheduler/common/queue/ITaskQueue.java index 42629324a2..106d6ff915 100644 --- a/escheduler-common/src/main/java/cn/escheduler/common/queue/ITaskQueue.java +++ b/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); diff --git a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/ProcessInstanceMapperProvider.java b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/ProcessInstanceMapperProvider.java index cd9daa3781..7e078b995b 100644 --- a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/ProcessInstanceMapperProvider.java +++ b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/ProcessInstanceMapperProvider.java @@ -220,7 +220,7 @@ public class ProcessInstanceMapperProvider { public String queryDetailById(Map 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"); diff --git a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/UserMapperProvider.java b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/UserMapperProvider.java index d060f46dd2..cc404c5c5c 100644 --- a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/UserMapperProvider.java +++ b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/UserMapperProvider.java @@ -208,7 +208,7 @@ public class UserMapperProvider { public String queryDetailsById(Map 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"); diff --git a/escheduler-dao/src/test/java/cn/escheduler/dao/mapper/UserMapperTest.java b/escheduler-dao/src/test/java/cn/escheduler/dao/mapper/UserMapperTest.java index adede0c329..d85a25f175 100644 --- a/escheduler-dao/src/test/java/cn/escheduler/dao/mapper/UserMapperTest.java +++ b/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); + } + } diff --git a/escheduler-server/pom.xml b/escheduler-server/pom.xml index 3047296e09..53d6b6f8c5 100644 --- a/escheduler-server/pom.xml +++ b/escheduler-server/pom.xml @@ -46,10 +46,7 @@ - - cn.analysys - escheduler-api - + cn.analysys escheduler-rpc diff --git a/escheduler-server/src/main/java/cn/escheduler/server/master/MasterServer.java b/escheduler-server/src/main/java/cn/escheduler/server/master/MasterServer.java index f877104cc1..e137824814 100644 --- a/escheduler-server/src/main/java/cn/escheduler/server/master/MasterServer.java +++ b/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; diff --git a/escheduler-api/src/main/java/cn/escheduler/api/quartz/ProcessScheduleJob.java b/escheduler-server/src/main/java/cn/escheduler/server/quartz/ProcessScheduleJob.java similarity index 96% rename from escheduler-api/src/main/java/cn/escheduler/api/quartz/ProcessScheduleJob.java rename to escheduler-server/src/main/java/cn/escheduler/server/quartz/ProcessScheduleJob.java index 96e283d7d5..3e546bea7c 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/quartz/ProcessScheduleJob.java +++ b/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 diff --git a/escheduler-api/src/main/java/cn/escheduler/api/quartz/QuartzExecutors.java b/escheduler-server/src/main/java/cn/escheduler/server/quartz/QuartzExecutors.java similarity index 99% rename from escheduler-api/src/main/java/cn/escheduler/api/quartz/QuartzExecutors.java rename to escheduler-server/src/main/java/cn/escheduler/server/quartz/QuartzExecutors.java index 92e351d5cd..9a72fb95cb 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/quartz/QuartzExecutors.java +++ b/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; diff --git a/escheduler-server/src/main/java/cn/escheduler/server/worker/runner/FetchTaskThread.java b/escheduler-server/src/main/java/cn/escheduler/server/worker/runner/FetchTaskThread.java index f163364b06..6ad3b71f04 100644 --- a/escheduler-server/src/main/java/cn/escheduler/server/worker/runner/FetchTaskThread.java +++ b/escheduler-server/src/main/java/cn/escheduler/server/worker/runner/FetchTaskThread.java @@ -134,7 +134,7 @@ 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)) { @@ -221,7 +221,10 @@ public class FetchTaskThread implements Runnable{ logger.info("task : {} ready to submit to task scheduler thread",taskId); // submit task workerExecService.submit(new TaskScheduleThread(taskInstance, processDao)); + + logger.info("{} 耗时: {} ms",taskQueueStr,System.currentTimeMillis() - start ); } + } } From dc55de4e8600087e650b65049ff5e58f77b0ca93 Mon Sep 17 00:00:00 2001 From: lidongdai Date: Wed, 15 May 2019 15:38:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?1.0.2=E6=96=87=E6=A1=A3=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- escheduler-api/pom.xml | 44 +++++--------- .../escheduler/api/ApiApplicationServer.java | 7 ++- .../api/configuration/AppConfiguration.java | 58 +++++++++++++++---- .../{Swagger2.java => SwaggerConfig.java} | 8 ++- .../api/configuration/SwaggerI18nPlugin.java | 52 +++++++++++++++++ .../api/controller/LoginController.java | 17 +++++- .../src/main/resources/application.properties | 5 ++ .../src/main/resources/messages.properties | 5 ++ .../main/resources/messages_en_US.properties | 5 ++ .../main/resources/messages_zh_CN.properties | 5 ++ .../server/worker/runner/FetchTaskThread.java | 2 - pom.xml | 7 ++- 12 files changed, 163 insertions(+), 52 deletions(-) rename escheduler-api/src/main/java/cn/escheduler/api/configuration/{Swagger2.java => SwaggerConfig.java} (85%) create mode 100644 escheduler-api/src/main/java/cn/escheduler/api/configuration/SwaggerI18nPlugin.java create mode 100644 escheduler-api/src/main/resources/messages.properties create mode 100644 escheduler-api/src/main/resources/messages_en_US.properties create mode 100644 escheduler-api/src/main/resources/messages_zh_CN.properties diff --git a/escheduler-api/pom.xml b/escheduler-api/pom.xml index e0e8c54a3b..31120c3883 100644 --- a/escheduler-api/pom.xml +++ b/escheduler-api/pom.xml @@ -35,35 +35,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.springframework.boot spring-boot-starter-web @@ -170,14 +142,21 @@ io.springfox springfox-swagger2 - 2.8.0 + 2.9.2 io.springfox springfox-swagger-ui - 2.8.0 + 2.9.2 + + + + com.github.xiaoymin + swagger-bootstrap-ui + 1.9.3 + cn.analysys escheduler-rpc @@ -189,6 +168,11 @@ 4.12 test + + io.swagger + swagger-jaxrs + 1.5.12 + diff --git a/escheduler-api/src/main/java/cn/escheduler/api/ApiApplicationServer.java b/escheduler-api/src/main/java/cn/escheduler/api/ApiApplicationServer.java index 5ddc72ffbc..9b84c7f2f7 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/ApiApplicationServer.java +++ b/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); } + + } diff --git a/escheduler-api/src/main/java/cn/escheduler/api/configuration/AppConfiguration.java b/escheduler-api/src/main/java/cn/escheduler/api/configuration/AppConfiguration.java index 00272ea5a7..74a29a13b5 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/configuration/AppConfiguration.java +++ b/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); } + + + + } diff --git a/escheduler-api/src/main/java/cn/escheduler/api/configuration/Swagger2.java b/escheduler-api/src/main/java/cn/escheduler/api/configuration/SwaggerConfig.java similarity index 85% rename from escheduler-api/src/main/java/cn/escheduler/api/configuration/Swagger2.java rename to escheduler-api/src/main/java/cn/escheduler/api/configuration/SwaggerConfig.java index 1e5b9b8fcb..f55d04ab92 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/configuration/Swagger2.java +++ b/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(); } diff --git a/escheduler-api/src/main/java/cn/escheduler/api/configuration/SwaggerI18nPlugin.java b/escheduler-api/src/main/java/cn/escheduler/api/configuration/SwaggerI18nPlugin.java new file mode 100644 index 0000000000..4e4be961e5 --- /dev/null +++ b/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 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; + } + +} diff --git a/escheduler-api/src/main/java/cn/escheduler/api/controller/LoginController.java b/escheduler-api/src/main/java/cn/escheduler/api/controller/LoginController.java index 061a2d404d..cd46574d50 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/controller/LoginController.java +++ b/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, diff --git a/escheduler-api/src/main/resources/application.properties b/escheduler-api/src/main/resources/application.properties index 2709f419ef..118b70e616 100644 --- a/escheduler-api/src/main/resources/application.properties +++ b/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 diff --git a/escheduler-api/src/main/resources/messages.properties b/escheduler-api/src/main/resources/messages.properties new file mode 100644 index 0000000000..89ddfd5201 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/escheduler-api/src/main/resources/messages_en_US.properties b/escheduler-api/src/main/resources/messages_en_US.properties new file mode 100644 index 0000000000..89ddfd5201 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/escheduler-api/src/main/resources/messages_zh_CN.properties b/escheduler-api/src/main/resources/messages_zh_CN.properties new file mode 100644 index 0000000000..4c21e73399 --- /dev/null +++ b/escheduler-api/src/main/resources/messages_zh_CN.properties @@ -0,0 +1,5 @@ +welcome=您好,欢迎你! +test=测试 +userName=用户名 +userPassword=用户密码 +loginNotes=登录xxx \ No newline at end of file diff --git a/escheduler-server/src/main/java/cn/escheduler/server/worker/runner/FetchTaskThread.java b/escheduler-server/src/main/java/cn/escheduler/server/worker/runner/FetchTaskThread.java index 6ad3b71f04..3ecafde57a 100644 --- a/escheduler-server/src/main/java/cn/escheduler/server/worker/runner/FetchTaskThread.java +++ b/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 ); } } diff --git a/pom.xml b/pom.xml index 4e9cc32dca..ee2b1b3626 100644 --- a/pom.xml +++ b/pom.xml @@ -114,6 +114,11 @@ + + cn.analysys + escheduler-server + ${project.version} + cn.analysys escheduler-common @@ -326,7 +331,7 @@ com.google.guava guava - 19.0 + 20.0