You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/06/28 16:48:47 UTC
[shardingsphere-elasticjob-lite] branch master updated: Use spring
boot to refactor elastic-job-lite-console (#854)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob-lite.git
The following commit(s) were added to refs/heads/master by this push:
new e2329b4 Use spring boot to refactor elastic-job-lite-console (#854)
e2329b4 is described below
commit e2329b4b3253d02a34a3783abbd6f10e8fc592de
Author: keker <as...@163.com>
AuthorDate: Mon Jun 29 00:48:38 2020 +0800
Use spring boot to refactor elastic-job-lite-console (#854)
* Use spring boot to refactor elastic-job-lite-console.
* remove banner.
* add license for new file.
---
elastic-job-lite-console/pom.xml | 42 ++++++-
.../elasticjob/lite/console/ConsoleBootstrap.java | 37 ++----
.../lite/console/config/FilterRegisterConfig.java | 74 ++++++++++++
.../lite/console/config/WebMvcConfig.java | 49 ++++++++
.../EventTraceDataSourceController.java} | 104 ++++++++---------
.../EventTraceHistoryController.java} | 116 ++++++++++---------
.../JobConfigController.java} | 63 ++++++-----
.../JobOperationController.java} | 81 ++++++-------
.../RegistryCenterController.java} | 85 +++++++-------
.../ServerOperationController.java} | 87 +++++++-------
.../console/filter/GlobalConfigurationFilter.java | 16 +--
.../console/security/AuthenticationResult.java | 36 ++++++
.../security/UserAuthenticationService.java | 57 ++++++++++
.../lite/console}/security/WwwAuthFilter.java | 73 ++++--------
...entTraceDataSourceConfigurationServiceImpl.java | 2 +
.../console/service/impl/JobAPIServiceImpl.java | 2 +
.../RegistryCenterConfigurationServiceImpl.java | 2 +
.../auth.properties => application.properties} | 11 +-
.../src/main/resources/assembly/assembly.xml | 6 +-
.../src/main/resources/bin/start.bat | 2 +-
.../src/main/resources/bin/start.sh | 4 +-
elastic-job-lite-lifecycle/pom.xml | 6 +-
.../lite/lifecycle/restful/RESTfulAPIServer.java | 126 ---------------------
.../lite/lifecycle/restful/RestfulServerTest.java | 102 -----------------
.../lite/lifecycle/restful/fixture/TestFilter.java | 46 --------
pom.xml | 36 +++---
26 files changed, 581 insertions(+), 684 deletions(-)
diff --git a/elastic-job-lite-console/pom.xml b/elastic-job-lite-console/pom.xml
index 4608c17..6029ab7 100644
--- a/elastic-job-lite-console/pom.xml
+++ b/elastic-job-lite-console/pom.xml
@@ -25,14 +25,51 @@
<artifactId>elastic-job-lite-console</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
-
+
+ <properties>
+ <spring-boot.version>2.3.1.RELEASE</spring-boot.version>
+ <springframework.version>5.2.7.RELEASE</springframework.version>
+ </properties>
+
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere.elasticjob</groupId>
<artifactId>elastic-job-lite-lifecycle</artifactId>
<version>${project.parent.version}</version>
</dependency>
-
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ <version>${spring-boot.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${springframework.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>${springframework.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ <version>${springframework.version}</version>
+ <scope>compile</scope>
+ <exclusions>
+ <exclusion>
+ <artifactId>spring-web</artifactId>
+ <groupId>org.springframework</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>spring-context</artifactId>
+ <groupId>org.springframework</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
@@ -73,7 +110,6 @@
<directory>src/main/resources</directory>
<excludes>
<exclude>bin/*</exclude>
- <exclude>conf/*</exclude>
<exclude>assembly/*</exclude>
</excludes>
</resource>
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/ConsoleBootstrap.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/ConsoleBootstrap.java
index 53dd9fc..16e6531 100644
--- a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/ConsoleBootstrap.java
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/ConsoleBootstrap.java
@@ -17,44 +17,23 @@
package org.apache.shardingsphere.elasticjob.lite.console;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.elasticjob.lite.console.filter.GlobalConfigurationFilter;
-import org.apache.shardingsphere.elasticjob.lite.console.restful.JobOperationRESTfulAPI;
-import org.apache.shardingsphere.elasticjob.lite.lifecycle.restful.RESTfulAPIServer;
-import org.apache.shardingsphere.elasticjob.lite.lifecycle.security.WwwAuthFilter;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Console bootstrap.
*/
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-@Slf4j
-public final class ConsoleBootstrap {
-
- private static final String CONSOLE_PATH = "console";
-
+@SpringBootApplication
+public class ConsoleBootstrap {
+
/**
* Startup RESTful server.
- *
+ *
* @param args arguments
- * @throws Exception exception
*/
//CHECKSTYLE:OFF
- public static void main(final String[] args) throws Exception {
+ public static void main(final String[] args) {
//CHECKSTYLE:ON
- int port = 8899;
- if (1 == args.length) {
- try {
- port = Integer.parseInt(args[0]);
- } catch (final NumberFormatException ex) {
- log.warn("Wrong port format, using default port 8899 instead.");
- }
- }
- RESTfulAPIServer restfulServer = new RESTfulAPIServer(port);
- restfulServer.addFilter(GlobalConfigurationFilter.class, "*.html")
- .addFilter(WwwAuthFilter.class, "/")
- .addFilter(WwwAuthFilter.class, "*.html")
- .start(JobOperationRESTfulAPI.class.getPackage().getName(), CONSOLE_PATH);
+ SpringApplication.run(ConsoleBootstrap.class, args);
}
}
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/config/FilterRegisterConfig.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/config/FilterRegisterConfig.java
new file mode 100644
index 0000000..a35a41e
--- /dev/null
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/config/FilterRegisterConfig.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.shardingsphere.elasticjob.lite.console.config;
+
+import java.util.EnumSet;
+import javax.servlet.DispatcherType;
+import org.apache.shardingsphere.elasticjob.lite.console.filter.GlobalConfigurationFilter;
+import org.apache.shardingsphere.elasticjob.lite.console.security.UserAuthenticationService;
+import org.apache.shardingsphere.elasticjob.lite.console.security.WwwAuthFilter;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.web.servlet.FilterRegistrationBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * Filter register config.
+ **/
+@Configuration
+public class FilterRegisterConfig {
+
+ private UserAuthenticationService userAuthenticationService;
+
+ @Autowired
+ public FilterRegisterConfig(final UserAuthenticationService userAuthenticationService) {
+ this.userAuthenticationService = userAuthenticationService;
+ }
+
+ /**
+ * register global configuration filter.
+ *
+ * @return global configuration filter bean
+ */
+ @Bean
+ public FilterRegistrationBean<GlobalConfigurationFilter> globalConfigurationFilter() {
+ GlobalConfigurationFilter globalConfigurationFilter = new GlobalConfigurationFilter();
+ FilterRegistrationBean<GlobalConfigurationFilter> registration = new FilterRegistrationBean<>();
+ registration.setFilter(globalConfigurationFilter);
+ registration.addUrlPatterns("*.html");
+ registration.setDispatcherTypes(EnumSet.of(DispatcherType.REQUEST));
+ return registration;
+ }
+
+ /**
+ * register www auth filter.
+ *
+ * @return www auth filter bean
+ */
+ @Bean
+ public FilterRegistrationBean<WwwAuthFilter> wwwAuthFilter() {
+ WwwAuthFilter wwwAuthFilter = new WwwAuthFilter();
+ wwwAuthFilter.setUserAuthenticationService(userAuthenticationService);
+ FilterRegistrationBean<WwwAuthFilter> registration = new FilterRegistrationBean<>();
+ registration.setFilter(wwwAuthFilter);
+ registration.addUrlPatterns("/");
+ registration.addUrlPatterns("*.html");
+ registration.setDispatcherTypes(EnumSet.of(DispatcherType.REQUEST));
+ return registration;
+ }
+}
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/config/WebMvcConfig.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/config/WebMvcConfig.java
new file mode 100644
index 0000000..12ba2cb
--- /dev/null
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/config/WebMvcConfig.java
@@ -0,0 +1,49 @@
+/*
+ * 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.shardingsphere.elasticjob.lite.console.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.method.HandlerTypePredicate;
+import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+/**
+ * Web mvc config.
+ **/
+@Configuration
+public class WebMvcConfig implements WebMvcConfigurer {
+
+ @Override
+ public void configurePathMatch(final PathMatchConfigurer configurer) {
+ HandlerTypePredicate handlerTypePredicate = HandlerTypePredicate.forAnnotation(RestController.class);
+ configurer.addPathPrefix("/api", handlerTypePredicate);
+ }
+
+ @Override
+ public void addResourceHandlers(final ResourceHandlerRegistry registry) {
+ registry.addResourceHandler("/**").addResourceLocations("classpath:/console/");
+ }
+
+ @Override
+ public void addViewControllers(final ViewControllerRegistry registry) {
+ registry.addViewController("/").setViewName("/index.html");
+ }
+}
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/restful/config/EventTraceDataSourceRESTfulAPI.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/EventTraceDataSourceController.java
similarity index 66%
rename from elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/restful/config/EventTraceDataSourceRESTfulAPI.java
rename to elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/EventTraceDataSourceController.java
index 055eb1b..8e1e878 100644
--- a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/restful/config/EventTraceDataSourceRESTfulAPI.java
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/EventTraceDataSourceController.java
@@ -15,127 +15,121 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.lite.console.restful.config;
+package org.apache.shardingsphere.elasticjob.lite.console.controller;
-import org.apache.shardingsphere.elasticjob.lite.console.domain.EventTraceDataSourceConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.console.domain.EventTraceDataSourceFactory;
-import org.apache.shardingsphere.elasticjob.lite.console.service.EventTraceDataSourceConfigurationService;
-import org.apache.shardingsphere.elasticjob.lite.console.service.impl.EventTraceDataSourceConfigurationServiceImpl;
-import org.apache.shardingsphere.elasticjob.lite.console.util.SessionEventTraceDataSourceConfiguration;
import com.google.common.base.Optional;
-
+import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
-import java.util.Collection;
+import org.apache.shardingsphere.elasticjob.lite.console.domain.EventTraceDataSourceConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.console.domain.EventTraceDataSourceFactory;
+import org.apache.shardingsphere.elasticjob.lite.console.service.EventTraceDataSourceConfigurationService;
+import org.apache.shardingsphere.elasticjob.lite.console.util.SessionEventTraceDataSourceConfiguration;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
/**
* Event trace data source RESTful API.
*/
-@Path("/data-source")
-public final class EventTraceDataSourceRESTfulAPI {
-
+@RestController
+@RequestMapping("/data-source")
+public final class EventTraceDataSourceController {
+
public static final String DATA_SOURCE_CONFIG_KEY = "data_source_config_key";
-
- private EventTraceDataSourceConfigurationService eventTraceDataSourceConfigurationService = new EventTraceDataSourceConfigurationServiceImpl();
-
+
+ private EventTraceDataSourceConfigurationService eventTraceDataSourceConfigurationService;
+
+ @Autowired
+ public EventTraceDataSourceController(final EventTraceDataSourceConfigurationService eventTraceDataSourceConfigurationService) {
+ this.eventTraceDataSourceConfigurationService = eventTraceDataSourceConfigurationService;
+ }
+
/**
* Judge whether event trace data source is activated.
*
* @param request HTTP request
* @return event trace data source is activated or not
*/
- @GET
- @Path("/activated")
- public boolean activated(final @Context HttpServletRequest request) {
+ @GetMapping("/activated")
+ public boolean activated(@Context final HttpServletRequest request) {
return eventTraceDataSourceConfigurationService.loadActivated().isPresent();
}
-
+
/**
* Load event trace data source configuration.
- *
+ *
* @param request HTTP request
* @return event trace data source configurations
*/
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- public Collection<EventTraceDataSourceConfiguration> load(final @Context HttpServletRequest request) {
+ @GetMapping(produces = MediaType.APPLICATION_JSON)
+ public Collection<EventTraceDataSourceConfiguration> load(@Context final HttpServletRequest request) {
Optional<EventTraceDataSourceConfiguration> dataSourceConfig = eventTraceDataSourceConfigurationService.loadActivated();
if (dataSourceConfig.isPresent()) {
setDataSourceNameToSession(dataSourceConfig.get(), request.getSession());
}
return eventTraceDataSourceConfigurationService.loadAll().getEventTraceDataSourceConfiguration();
}
-
+
/**
* Add event trace data source configuration.
- *
+ *
* @param config event trace data source configuration
* @return success to added or not
*/
- @POST
- @Produces(MediaType.APPLICATION_JSON)
- @Consumes(MediaType.APPLICATION_JSON)
- public boolean add(final EventTraceDataSourceConfiguration config) {
+ @PostMapping(produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
+ public boolean add(@RequestBody final EventTraceDataSourceConfiguration config) {
return eventTraceDataSourceConfigurationService.add(config);
}
-
+
/**
* Delete event trace data source configuration.
- *
+ *
* @param config event trace data source configuration
*/
- @DELETE
- @Consumes(MediaType.APPLICATION_JSON)
- public void delete(final EventTraceDataSourceConfiguration config) {
+ @DeleteMapping(consumes = MediaType.APPLICATION_JSON)
+ public void delete(@RequestBody final EventTraceDataSourceConfiguration config) {
eventTraceDataSourceConfigurationService.delete(config.getName());
}
-
+
/**
* Test event trace data source connection.
*
- * @param config event trace data source configuration
+ * @param config event trace data source configuration
* @param request HTTP request
* @return success or not
*/
- @POST
- @Path("/connectTest")
- @Produces(MediaType.APPLICATION_JSON)
- @Consumes(MediaType.APPLICATION_JSON)
- public boolean connectTest(final EventTraceDataSourceConfiguration config, final @Context HttpServletRequest request) {
+ @PostMapping(value = "/connectTest", produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
+ public boolean connectTest(@RequestBody final EventTraceDataSourceConfiguration config, @Context final HttpServletRequest request) {
return setDataSourceNameToSession(config, request.getSession());
}
-
+
/**
* Connect event trace data source.
*
- * @param config event trace data source
+ * @param config event trace data source
* @param request HTTP request
* @return success or not
*/
- @POST
- @Path("/connect")
- @Produces(MediaType.APPLICATION_JSON)
- @Consumes(MediaType.APPLICATION_JSON)
- public boolean connect(final EventTraceDataSourceConfiguration config, final @Context HttpServletRequest request) {
+ @PostMapping(value = "/connect", produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
+ public boolean connect(@RequestBody final EventTraceDataSourceConfiguration config, @Context final HttpServletRequest request) {
boolean isConnected = setDataSourceNameToSession(eventTraceDataSourceConfigurationService.find(config.getName(), eventTraceDataSourceConfigurationService.loadAll()), request.getSession());
if (isConnected) {
eventTraceDataSourceConfigurationService.load(config.getName());
}
return isConnected;
}
-
+
private boolean setDataSourceNameToSession(final EventTraceDataSourceConfiguration dataSourceConfig, final HttpSession session) {
session.setAttribute(DATA_SOURCE_CONFIG_KEY, dataSourceConfig);
try {
- EventTraceDataSourceFactory.createEventTraceDataSource(dataSourceConfig.getDriver(), dataSourceConfig.getUrl(),
+ EventTraceDataSourceFactory.createEventTraceDataSource(dataSourceConfig.getDriver(), dataSourceConfig.getUrl(),
dataSourceConfig.getUsername(), Optional.fromNullable(dataSourceConfig.getPassword()));
SessionEventTraceDataSourceConfiguration.setDataSourceConfiguration((EventTraceDataSourceConfiguration) session.getAttribute(DATA_SOURCE_CONFIG_KEY));
// CHECKSTYLE:OFF
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/restful/EventTraceHistoryRESTfulAPI.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/EventTraceHistoryController.java
similarity index 57%
rename from elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/restful/EventTraceHistoryRESTfulAPI.java
rename to elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/EventTraceHistoryController.java
index f138d6f..5675738 100644
--- a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/restful/EventTraceHistoryRESTfulAPI.java
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/EventTraceHistoryController.java
@@ -15,80 +15,78 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.lite.console.restful;
+package org.apache.shardingsphere.elasticjob.lite.console.controller;
import com.google.common.base.Strings;
-import org.apache.commons.dbcp.BasicDataSource;
-import org.apache.shardingsphere.elasticjob.lite.console.domain.EventTraceDataSourceConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.console.service.EventTraceDataSourceConfigurationService;
-import org.apache.shardingsphere.elasticjob.lite.console.service.impl.EventTraceDataSourceConfigurationServiceImpl;
-import org.apache.shardingsphere.elasticjob.lite.console.util.SessionEventTraceDataSourceConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobExecutionEvent;
-import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobStatusTraceEvent;
-import org.apache.shardingsphere.elasticjob.lite.console.dao.search.RDBJobEventSearch;
-import org.apache.shardingsphere.elasticjob.lite.console.dao.search.RDBJobEventSearch.Result;
-
-import javax.sql.DataSource;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.UriInfo;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
+import javax.sql.DataSource;
+import javax.ws.rs.core.MediaType;
+import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.shardingsphere.elasticjob.lite.console.dao.search.RDBJobEventSearch;
+import org.apache.shardingsphere.elasticjob.lite.console.dao.search.RDBJobEventSearch.Result;
+import org.apache.shardingsphere.elasticjob.lite.console.domain.EventTraceDataSourceConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.console.service.EventTraceDataSourceConfigurationService;
+import org.apache.shardingsphere.elasticjob.lite.console.util.SessionEventTraceDataSourceConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobExecutionEvent;
+import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobStatusTraceEvent;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
/**
* Event trace history RESTful API.
*/
-@Path("/event-trace")
-public final class EventTraceHistoryRESTfulAPI {
-
+@RestController
+@RequestMapping("/event-trace")
+public final class EventTraceHistoryController {
+
private EventTraceDataSourceConfiguration eventTraceDataSourceConfiguration = SessionEventTraceDataSourceConfiguration.getEventTraceDataSourceConfiguration();
-
- private EventTraceDataSourceConfigurationService eventTraceDataSourceConfigurationService = new EventTraceDataSourceConfigurationServiceImpl();
-
+
+ private EventTraceDataSourceConfigurationService eventTraceDataSourceConfigurationService;
+
+ @Autowired
+ public EventTraceHistoryController(final EventTraceDataSourceConfigurationService eventTraceDataSourceConfigurationService) {
+ this.eventTraceDataSourceConfigurationService = eventTraceDataSourceConfigurationService;
+ }
+
/**
* Find job execution events.
- *
- * @param uriInfo query criteria
+ *
+ * @param requestParams query criteria
* @return job execution event trace result
* @throws ParseException parse exception
*/
- @GET
- @Path("/execution")
- @Produces(MediaType.APPLICATION_JSON)
- @Consumes(MediaType.APPLICATION_JSON)
- public Result<JobExecutionEvent> findJobExecutionEvents(@Context final UriInfo uriInfo) throws ParseException {
+ @GetMapping(value = "/execution", produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
+ public Result<JobExecutionEvent> findJobExecutionEvents(@RequestParam final MultiValueMap<String, String> requestParams) throws ParseException {
if (!eventTraceDataSourceConfigurationService.loadActivated().isPresent()) {
return new Result<>(0, new ArrayList<JobExecutionEvent>());
}
- return new RDBJobEventSearch(setUpEventTraceDataSource()).findJobExecutionEvents(buildCondition(uriInfo, new String[]{"jobName", "ip", "isSuccess"}));
+ return new RDBJobEventSearch(setUpEventTraceDataSource()).findJobExecutionEvents(buildCondition(requestParams, new String[]{"jobName", "ip", "isSuccess"}));
}
-
+
/**
* Find job status trace events.
*
- * @param uriInfo query criteria
+ * @param requestParams query criteria
* @return job status trace result
* @throws ParseException parse exception
*/
- @GET
- @Path("/status")
- @Produces(MediaType.APPLICATION_JSON)
- @Consumes(MediaType.APPLICATION_JSON)
- public Result<JobStatusTraceEvent> findJobStatusTraceEvents(@Context final UriInfo uriInfo) throws ParseException {
+ @GetMapping(value = "/status", produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
+ public Result<JobStatusTraceEvent> findJobStatusTraceEvents(@RequestParam final MultiValueMap<String, String> requestParams) throws ParseException {
if (!eventTraceDataSourceConfigurationService.loadActivated().isPresent()) {
return new Result<>(0, new ArrayList<JobStatusTraceEvent>());
}
- return new RDBJobEventSearch(setUpEventTraceDataSource()).findJobStatusTraceEvents(buildCondition(uriInfo, new String[]{"jobName", "source", "executionType", "state"}));
+ return new RDBJobEventSearch(setUpEventTraceDataSource()).findJobStatusTraceEvents(buildCondition(requestParams, new String[]{"jobName", "source", "executionType", "state"}));
}
-
+
private DataSource setUpEventTraceDataSource() {
BasicDataSource result = new BasicDataSource();
result.setDriverClassName(eventTraceDataSourceConfiguration.getDriver());
@@ -97,36 +95,36 @@ public final class EventTraceHistoryRESTfulAPI {
result.setPassword(eventTraceDataSourceConfiguration.getPassword());
return result;
}
-
- private RDBJobEventSearch.Condition buildCondition(final UriInfo info, final String[] params) throws ParseException {
+
+ private RDBJobEventSearch.Condition buildCondition(final MultiValueMap<String, String> requestParams, final String[] params) throws ParseException {
int perPage = 10;
int page = 1;
- if (!Strings.isNullOrEmpty(info.getQueryParameters().getFirst("per_page"))) {
- perPage = Integer.parseInt(info.getQueryParameters().getFirst("per_page"));
+ if (!Strings.isNullOrEmpty(requestParams.getFirst("per_page"))) {
+ perPage = Integer.parseInt(requestParams.getFirst("per_page"));
}
- if (!Strings.isNullOrEmpty(info.getQueryParameters().getFirst("page"))) {
- page = Integer.parseInt(info.getQueryParameters().getFirst("page"));
+ if (!Strings.isNullOrEmpty(requestParams.getFirst("page"))) {
+ page = Integer.parseInt(requestParams.getFirst("page"));
}
- String sort = info.getQueryParameters().getFirst("sort");
- String order = info.getQueryParameters().getFirst("order");
+ String sort = requestParams.getFirst("sort");
+ String order = requestParams.getFirst("order");
Date startTime = null;
Date endTime = null;
- Map<String, Object> fields = getQueryParameters(info, params);
+ Map<String, Object> fields = getQueryParameters(requestParams, params);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- if (!Strings.isNullOrEmpty(info.getQueryParameters().getFirst("startTime"))) {
- startTime = simpleDateFormat.parse(info.getQueryParameters().getFirst("startTime"));
+ if (!Strings.isNullOrEmpty(requestParams.getFirst("startTime"))) {
+ startTime = simpleDateFormat.parse(requestParams.getFirst("startTime"));
}
- if (!Strings.isNullOrEmpty(info.getQueryParameters().getFirst("endTime"))) {
- endTime = simpleDateFormat.parse(info.getQueryParameters().getFirst("endTime"));
+ if (!Strings.isNullOrEmpty(requestParams.getFirst("endTime"))) {
+ endTime = simpleDateFormat.parse(requestParams.getFirst("endTime"));
}
return new RDBJobEventSearch.Condition(perPage, page, sort, order, startTime, endTime, fields);
}
-
- private Map<String, Object> getQueryParameters(final UriInfo info, final String[] params) {
+
+ private Map<String, Object> getQueryParameters(final MultiValueMap<String, String> requestParams, final String[] params) {
final Map<String, Object> result = new HashMap<>();
for (String each : params) {
- if (!Strings.isNullOrEmpty(info.getQueryParameters().getFirst(each))) {
- result.put(each, info.getQueryParameters().getFirst(each));
+ if (!Strings.isNullOrEmpty(requestParams.getFirst(each))) {
+ result.put(each, requestParams.getFirst(each));
}
}
return result;
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/restful/config/JobConfigRESTfulAPI.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/JobConfigController.java
similarity index 55%
rename from elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/restful/config/JobConfigRESTfulAPI.java
rename to elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/JobConfigController.java
index 6ad67cb..89de1ea 100644
--- a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/restful/config/JobConfigRESTfulAPI.java
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/JobConfigController.java
@@ -15,61 +15,62 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.lite.console.restful.config;
+package org.apache.shardingsphere.elasticjob.lite.console.controller;
+import javax.ws.rs.core.MediaType;
import org.apache.shardingsphere.elasticjob.lite.console.service.JobAPIService;
-import org.apache.shardingsphere.elasticjob.lite.console.service.impl.JobAPIServiceImpl;
import org.apache.shardingsphere.elasticjob.lite.lifecycle.domain.JobSettings;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
/**
* Job configuration RESTful API.
*/
-@Path("/jobs/config")
-public final class JobConfigRESTfulAPI {
-
- private JobAPIService jobAPIService = new JobAPIServiceImpl();
-
+@RestController
+@RequestMapping("/jobs/config")
+public final class JobConfigController {
+
+ private JobAPIService jobAPIService;
+
+ @Autowired
+ public JobConfigController(final JobAPIService jobAPIService) {
+ this.jobAPIService = jobAPIService;
+ }
+
/**
* get job settings.
- *
+ *
* @param jobName job name
* @return job settings
*/
- @GET
- @Path("/{jobName}")
- @Produces(MediaType.APPLICATION_JSON)
- public JobSettings getJobSettings(@PathParam("jobName") final String jobName) {
+ @GetMapping(value = "/{jobName}", produces = MediaType.APPLICATION_JSON)
+ public JobSettings getJobSettings(@PathVariable("jobName") final String jobName) {
return jobAPIService.getJobSettingsAPI().getJobSettings(jobName);
}
-
+
/**
* Update job settings.
- *
+ *
* @param jobSettings job settings
*/
- @PUT
- @Consumes(MediaType.APPLICATION_JSON)
- public void updateJobSettings(final JobSettings jobSettings) {
+ @PutMapping(consumes = MediaType.APPLICATION_JSON)
+ public void updateJobSettings(@RequestBody final JobSettings jobSettings) {
jobAPIService.getJobSettingsAPI().updateJobSettings(jobSettings);
}
-
+
/**
* Remove job settings.
- *
+ *
* @param jobName job name
*/
- @DELETE
- @Path("/{jobName}")
- public void removeJob(@PathParam("jobName") final String jobName) {
+ @DeleteMapping("/{jobName}")
+ public void removeJob(@PathVariable("jobName") final String jobName) {
jobAPIService.getJobSettingsAPI().removeJobSettings(jobName);
}
}
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/restful/JobOperationRESTfulAPI.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/JobOperationController.java
similarity index 57%
rename from elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/restful/JobOperationRESTfulAPI.java
rename to elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/JobOperationController.java
index 78b9bd0..49c5379 100644
--- a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/restful/JobOperationRESTfulAPI.java
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/JobOperationController.java
@@ -15,37 +15,40 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.lite.console.restful;
+package org.apache.shardingsphere.elasticjob.lite.console.controller;
+import java.util.Collection;
+import javax.ws.rs.core.MediaType;
import org.apache.shardingsphere.elasticjob.lite.console.service.JobAPIService;
-import org.apache.shardingsphere.elasticjob.lite.console.service.impl.JobAPIServiceImpl;
import org.apache.shardingsphere.elasticjob.lite.lifecycle.domain.JobBriefInfo;
import org.apache.shardingsphere.elasticjob.lite.lifecycle.domain.ShardingInfo;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import java.util.Collection;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
/**
* Job operation RESTful API.
*/
-@Path("/jobs")
-public final class JobOperationRESTfulAPI {
-
- private JobAPIService jobAPIService = new JobAPIServiceImpl();
+@RestController
+@RequestMapping("/jobs")
+public final class JobOperationController {
+ private JobAPIService jobAPIService;
+
+ @Autowired
+ public JobOperationController(final JobAPIService jobAPIService) {
+ this.jobAPIService = jobAPIService;
+ }
+
/**
* Get jobs total count.
*
* @return jobs total count
*/
- @GET
- @Path("/count")
+ @GetMapping("/count")
public int getJobsTotalCount() {
return jobAPIService.getJobStatisticsAPI().getJobsTotalCount();
}
@@ -55,8 +58,7 @@ public final class JobOperationRESTfulAPI {
*
* @return all jobs brief info
*/
- @GET
- @Produces(MediaType.APPLICATION_JSON)
+ @GetMapping(produces = MediaType.APPLICATION_JSON)
public Collection<JobBriefInfo> getAllJobsBriefInfo() {
return jobAPIService.getJobStatisticsAPI().getAllJobsBriefInfo();
}
@@ -66,9 +68,8 @@ public final class JobOperationRESTfulAPI {
*
* @param jobName job name
*/
- @POST
- @Path("/{jobName}/trigger")
- public void triggerJob(@PathParam("jobName") final String jobName) {
+ @PostMapping("/{jobName}/trigger")
+ public void triggerJob(@PathVariable("jobName") final String jobName) {
jobAPIService.getJobOperatorAPI().trigger(jobName);
}
@@ -77,10 +78,8 @@ public final class JobOperationRESTfulAPI {
*
* @param jobName job name
*/
- @POST
- @Path("/{jobName}/disable")
- @Consumes(MediaType.APPLICATION_JSON)
- public void disableJob(@PathParam("jobName") final String jobName) {
+ @PostMapping(value = "/{jobName}/disable", consumes = MediaType.APPLICATION_JSON)
+ public void disableJob(@PathVariable("jobName") final String jobName) {
jobAPIService.getJobOperatorAPI().disable(jobName, null);
}
@@ -89,10 +88,8 @@ public final class JobOperationRESTfulAPI {
*
* @param jobName job name
*/
- @POST
- @Path("/{jobName}/enable")
- @Consumes(MediaType.APPLICATION_JSON)
- public void enableJob(@PathParam("jobName") final String jobName) {
+ @PostMapping(value = "/{jobName}/enable", consumes = MediaType.APPLICATION_JSON)
+ public void enableJob(@PathVariable("jobName") final String jobName) {
jobAPIService.getJobOperatorAPI().enable(jobName, null);
}
@@ -101,10 +98,8 @@ public final class JobOperationRESTfulAPI {
*
* @param jobName job name
*/
- @POST
- @Path("/{jobName}/shutdown")
- @Consumes(MediaType.APPLICATION_JSON)
- public void shutdownJob(@PathParam("jobName") final String jobName) {
+ @PostMapping(value = "/{jobName}/shutdown", consumes = MediaType.APPLICATION_JSON)
+ public void shutdownJob(@PathVariable("jobName") final String jobName) {
jobAPIService.getJobOperatorAPI().shutdown(jobName, null);
}
@@ -114,10 +109,8 @@ public final class JobOperationRESTfulAPI {
* @param jobName job name
* @return sharding info
*/
- @GET
- @Path("/{jobName}/sharding")
- @Produces(MediaType.APPLICATION_JSON)
- public Collection<ShardingInfo> getShardingInfo(@PathParam("jobName") final String jobName) {
+ @GetMapping(value = "/{jobName}/sharding", produces = MediaType.APPLICATION_JSON)
+ public Collection<ShardingInfo> getShardingInfo(@PathVariable("jobName") final String jobName) {
return jobAPIService.getShardingStatisticsAPI().getShardingInfo(jobName);
}
@@ -127,10 +120,8 @@ public final class JobOperationRESTfulAPI {
* @param jobName job name
* @param item sharding item
*/
- @POST
- @Path("/{jobName}/sharding/{item}/disable")
- @Consumes(MediaType.APPLICATION_JSON)
- public void disableSharding(@PathParam("jobName") final String jobName, @PathParam("item") final String item) {
+ @PostMapping(value = "/{jobName}/sharding/{item}/disable", consumes = MediaType.APPLICATION_JSON)
+ public void disableSharding(@PathVariable("jobName") final String jobName, @PathVariable("item") final String item) {
jobAPIService.getShardingOperateAPI().disable(jobName, item);
}
@@ -140,10 +131,8 @@ public final class JobOperationRESTfulAPI {
* @param jobName job name
* @param item sharding item
*/
- @POST
- @Path("/{jobName}/sharding/{item}/enable")
- @Consumes(MediaType.APPLICATION_JSON)
- public void enableSharding(@PathParam("jobName") final String jobName, @PathParam("item") final String item) {
+ @PostMapping(value = "/{jobName}/sharding/{item}/enable", consumes = MediaType.APPLICATION_JSON)
+ public void enableSharding(@PathVariable("jobName") final String jobName, @PathVariable("item") final String item) {
jobAPIService.getShardingOperateAPI().enable(jobName, item);
}
}
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/restful/config/RegistryCenterRESTfulAPI.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/RegistryCenterController.java
similarity index 69%
rename from elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/restful/config/RegistryCenterRESTfulAPI.java
rename to elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/RegistryCenterController.java
index b121f7c..390e89a 100644
--- a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/restful/config/RegistryCenterRESTfulAPI.java
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/RegistryCenterController.java
@@ -15,108 +15,105 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.lite.console.restful.config;
+package org.apache.shardingsphere.elasticjob.lite.console.controller;
import com.google.common.base.Optional;
+import java.util.Collection;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
import org.apache.shardingsphere.elasticjob.lite.console.domain.RegistryCenterConfiguration;
import org.apache.shardingsphere.elasticjob.lite.console.service.RegistryCenterConfigurationService;
-import org.apache.shardingsphere.elasticjob.lite.console.service.impl.RegistryCenterConfigurationServiceImpl;
import org.apache.shardingsphere.elasticjob.lite.console.util.SessionRegistryCenterConfiguration;
import org.apache.shardingsphere.elasticjob.lite.lifecycle.internal.reg.RegistryCenterFactory;
import org.apache.shardingsphere.elasticjob.lite.reg.exception.RegException;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import java.util.Collection;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
/**
* Registry center RESTful API.
*/
-@Path("/registry-center")
-public final class RegistryCenterRESTfulAPI {
-
+@RestController
+@RequestMapping("/registry-center")
+public final class RegistryCenterController {
+
public static final String REG_CENTER_CONFIG_KEY = "reg_center_config_key";
-
- private RegistryCenterConfigurationService regCenterService = new RegistryCenterConfigurationServiceImpl();
-
+
+ private RegistryCenterConfigurationService regCenterService;
+
+ @Autowired
+ public RegistryCenterController(final RegistryCenterConfigurationService regCenterService) {
+ this.regCenterService = regCenterService;
+ }
+
/**
* Judge whether registry center is activated.
*
- * @param request HTTP request
* @return registry center is activated or not
*/
- @GET
- @Path("/activated")
- public boolean activated(final @Context HttpServletRequest request) {
+ @GetMapping("/activated")
+ public boolean activated() {
return regCenterService.loadActivated().isPresent();
}
-
+
/**
* Load configuration from registry center.
*
* @param request HTTP request
* @return registry center configurations
*/
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- public Collection<RegistryCenterConfiguration> load(final @Context HttpServletRequest request) {
+ @GetMapping(produces = MediaType.APPLICATION_JSON)
+ public Collection<RegistryCenterConfiguration> load(final HttpServletRequest request) {
Optional<RegistryCenterConfiguration> regCenterConfig = regCenterService.loadActivated();
if (regCenterConfig.isPresent()) {
setRegistryCenterNameToSession(regCenterConfig.get(), request.getSession());
}
return regCenterService.loadAll().getRegistryCenterConfiguration();
}
-
+
/**
* Add registry center.
- *
+ *
* @param config registry center configuration
* @return success to add or not
*/
- @POST
- @Produces(MediaType.APPLICATION_JSON)
- public boolean add(final RegistryCenterConfiguration config) {
+ @PostMapping(produces = MediaType.APPLICATION_JSON)
+ public boolean add(@RequestBody final RegistryCenterConfiguration config) {
return regCenterService.add(config);
}
-
+
/**
* Delete registry center.
*
* @param config registry center configuration
*/
- @DELETE
- @Consumes(MediaType.APPLICATION_JSON)
- public void delete(final RegistryCenterConfiguration config) {
+ @DeleteMapping(consumes = MediaType.APPLICATION_JSON)
+ public void delete(@RequestBody final RegistryCenterConfiguration config) {
regCenterService.delete(config.getName());
}
/**
* Connect to registry center.
*
- * @param config config of registry center
+ * @param config config of registry center
* @param request HTTP request
* @return connected or not
*/
- @POST
- @Path("/connect")
- @Produces(MediaType.APPLICATION_JSON)
- @Consumes(MediaType.APPLICATION_JSON)
- public boolean connect(final RegistryCenterConfiguration config, final @Context HttpServletRequest request) {
+ @PostMapping(value = "/connect", consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON)
+ public boolean connect(@RequestBody final RegistryCenterConfiguration config, @Context final HttpServletRequest request) {
boolean isConnected = setRegistryCenterNameToSession(regCenterService.find(config.getName(), regCenterService.loadAll()), request.getSession());
if (isConnected) {
regCenterService.load(config.getName());
}
return isConnected;
}
-
+
private boolean setRegistryCenterNameToSession(final RegistryCenterConfiguration regCenterConfig, final HttpSession session) {
session.setAttribute(REG_CENTER_CONFIG_KEY, regCenterConfig);
try {
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/restful/ServerOperationRESTfulAPI.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/ServerOperationController.java
similarity index 59%
rename from elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/restful/ServerOperationRESTfulAPI.java
rename to elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/ServerOperationController.java
index 4b24a59..10bc2a2 100644
--- a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/restful/ServerOperationRESTfulAPI.java
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/ServerOperationController.java
@@ -15,37 +15,41 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.lite.console.restful;
+package org.apache.shardingsphere.elasticjob.lite.console.controller;
+import java.util.Collection;
+import javax.ws.rs.core.MediaType;
import org.apache.shardingsphere.elasticjob.lite.console.service.JobAPIService;
-import org.apache.shardingsphere.elasticjob.lite.console.service.impl.JobAPIServiceImpl;
import org.apache.shardingsphere.elasticjob.lite.lifecycle.domain.JobBriefInfo;
import org.apache.shardingsphere.elasticjob.lite.lifecycle.domain.ServerBriefInfo;
-
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import java.util.Collection;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
/**
* Server operation RESTful API.
*/
-@Path("/servers")
-public final class ServerOperationRESTfulAPI {
-
- private JobAPIService jobAPIService = new JobAPIServiceImpl();
+@RestController
+@RequestMapping("/servers")
+public final class ServerOperationController {
+ private JobAPIService jobAPIService;
+
+ @Autowired
+ public ServerOperationController(final JobAPIService jobAPIService) {
+ this.jobAPIService = jobAPIService;
+ }
+
/**
* Get servers total count.
*
* @return servers total count
*/
- @GET
- @Path("/count")
+ @GetMapping("/count")
public int getServersTotalCount() {
return jobAPIService.getServerStatisticsAPI().getServersTotalCount();
}
@@ -55,8 +59,7 @@ public final class ServerOperationRESTfulAPI {
*
* @return all servers brief info
*/
- @GET
- @Produces(MediaType.APPLICATION_JSON)
+ @GetMapping(produces = MediaType.APPLICATION_JSON)
public Collection<ServerBriefInfo> getAllServersBriefInfo() {
return jobAPIService.getServerStatisticsAPI().getAllServersBriefInfo();
}
@@ -66,9 +69,8 @@ public final class ServerOperationRESTfulAPI {
*
* @param serverIp server IP address
*/
- @POST
- @Path("/{serverIp}/disable")
- public void disableServer(@PathParam("serverIp") final String serverIp) {
+ @PostMapping("/{serverIp}/disable")
+ public void disableServer(@PathVariable("serverIp") final String serverIp) {
jobAPIService.getJobOperatorAPI().disable(null, serverIp);
}
@@ -77,9 +79,8 @@ public final class ServerOperationRESTfulAPI {
*
* @param serverIp server IP address
*/
- @POST
- @Path("/{serverIp}/enable")
- public void enableServer(@PathParam("serverIp") final String serverIp) {
+ @PostMapping("/{serverIp}/enable")
+ public void enableServer(@PathVariable("serverIp") final String serverIp) {
jobAPIService.getJobOperatorAPI().enable(null, serverIp);
}
@@ -88,9 +89,8 @@ public final class ServerOperationRESTfulAPI {
*
* @param serverIp server IP address
*/
- @POST
- @Path("/{serverIp}/shutdown")
- public void shutdownServer(@PathParam("serverIp") final String serverIp) {
+ @PostMapping("/{serverIp}/shutdown")
+ public void shutdownServer(@PathVariable("serverIp") final String serverIp) {
jobAPIService.getJobOperatorAPI().shutdown(null, serverIp);
}
@@ -99,9 +99,8 @@ public final class ServerOperationRESTfulAPI {
*
* @param serverIp server IP address
*/
- @DELETE
- @Path("/{serverIp}")
- public void removeServer(@PathParam("serverIp") final String serverIp) {
+ @DeleteMapping("/{serverIp}")
+ public void removeServer(@PathVariable("serverIp") final String serverIp) {
jobAPIService.getJobOperatorAPI().remove(null, serverIp);
}
@@ -111,10 +110,8 @@ public final class ServerOperationRESTfulAPI {
* @param serverIp server IP address
* @return Job brief info
*/
- @GET
- @Path("/{serverIp}/jobs")
- @Produces(MediaType.APPLICATION_JSON)
- public Collection<JobBriefInfo> getJobs(@PathParam("serverIp") final String serverIp) {
+ @GetMapping(value = "/{serverIp}/jobs", produces = MediaType.APPLICATION_JSON)
+ public Collection<JobBriefInfo> getJobs(@PathVariable("serverIp") final String serverIp) {
return jobAPIService.getJobStatisticsAPI().getJobsBriefInfo(serverIp);
}
@@ -124,9 +121,8 @@ public final class ServerOperationRESTfulAPI {
* @param serverIp server IP address
* @param jobName job name
*/
- @POST
- @Path("/{serverIp}/jobs/{jobName}/disable")
- public void disableServerJob(@PathParam("serverIp") final String serverIp, @PathParam("jobName") final String jobName) {
+ @PostMapping(value = "/{serverIp}/jobs/{jobName}/disable")
+ public void disableServerJob(@PathVariable("serverIp") final String serverIp, @PathVariable("jobName") final String jobName) {
jobAPIService.getJobOperatorAPI().disable(jobName, serverIp);
}
@@ -136,9 +132,8 @@ public final class ServerOperationRESTfulAPI {
* @param serverIp server IP address
* @param jobName job name
*/
- @POST
- @Path("/{serverIp}/jobs/{jobName}/enable")
- public void enableServerJob(@PathParam("serverIp") final String serverIp, @PathParam("jobName") final String jobName) {
+ @PostMapping("/{serverIp}/jobs/{jobName}/enable")
+ public void enableServerJob(@PathVariable("serverIp") final String serverIp, @PathVariable("jobName") final String jobName) {
jobAPIService.getJobOperatorAPI().enable(jobName, serverIp);
}
@@ -148,9 +143,8 @@ public final class ServerOperationRESTfulAPI {
* @param serverIp server IP address
* @param jobName job name
*/
- @POST
- @Path("/{serverIp}/jobs/{jobName}/shutdown")
- public void shutdownServerJob(@PathParam("serverIp") final String serverIp, @PathParam("jobName") final String jobName) {
+ @PostMapping("/{serverIp}/jobs/{jobName}/shutdown")
+ public void shutdownServerJob(@PathVariable("serverIp") final String serverIp, @PathVariable("jobName") final String jobName) {
jobAPIService.getJobOperatorAPI().shutdown(jobName, serverIp);
}
@@ -160,9 +154,8 @@ public final class ServerOperationRESTfulAPI {
* @param serverIp server IP address
* @param jobName job name
*/
- @DELETE
- @Path("/{serverIp}/jobs/{jobName}")
- public void removeServerJob(@PathParam("serverIp") final String serverIp, @PathParam("jobName") final String jobName) {
+ @DeleteMapping("/{serverIp}/jobs/{jobName}")
+ public void removeServerJob(@PathVariable("serverIp") final String serverIp, @PathVariable("jobName") final String jobName) {
jobAPIService.getJobOperatorAPI().remove(jobName, serverIp);
}
}
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/filter/GlobalConfigurationFilter.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/filter/GlobalConfigurationFilter.java
index b6992c0..85fae7c 100644
--- a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/filter/GlobalConfigurationFilter.java
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/filter/GlobalConfigurationFilter.java
@@ -21,8 +21,8 @@ import com.google.common.base.Optional;
import org.apache.shardingsphere.elasticjob.lite.console.domain.EventTraceDataSourceConfiguration;
import org.apache.shardingsphere.elasticjob.lite.console.domain.EventTraceDataSourceFactory;
import org.apache.shardingsphere.elasticjob.lite.console.domain.RegistryCenterConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.console.restful.config.EventTraceDataSourceRESTfulAPI;
-import org.apache.shardingsphere.elasticjob.lite.console.restful.config.RegistryCenterRESTfulAPI;
+import org.apache.shardingsphere.elasticjob.lite.console.controller.EventTraceDataSourceController;
+import org.apache.shardingsphere.elasticjob.lite.console.controller.RegistryCenterController;
import org.apache.shardingsphere.elasticjob.lite.console.service.EventTraceDataSourceConfigurationService;
import org.apache.shardingsphere.elasticjob.lite.console.service.RegistryCenterConfigurationService;
import org.apache.shardingsphere.elasticjob.lite.console.service.impl.EventTraceDataSourceConfigurationServiceImpl;
@@ -59,10 +59,10 @@ public final class GlobalConfigurationFilter implements Filter {
public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
HttpSession httpSession = httpRequest.getSession();
- if (null == httpSession.getAttribute(RegistryCenterRESTfulAPI.REG_CENTER_CONFIG_KEY)) {
+ if (null == httpSession.getAttribute(RegistryCenterController.REG_CENTER_CONFIG_KEY)) {
loadActivatedRegCenter(httpSession);
}
- if (null == httpSession.getAttribute(EventTraceDataSourceRESTfulAPI.DATA_SOURCE_CONFIG_KEY)) {
+ if (null == httpSession.getAttribute(EventTraceDataSourceController.DATA_SOURCE_CONFIG_KEY)) {
loadActivatedEventTraceDataSource(httpSession);
}
filterChain.doFilter(servletRequest, servletResponse);
@@ -80,10 +80,10 @@ public final class GlobalConfigurationFilter implements Filter {
}
private boolean setRegistryCenterNameToSession(final RegistryCenterConfiguration regCenterConfig, final HttpSession session) {
- session.setAttribute(RegistryCenterRESTfulAPI.REG_CENTER_CONFIG_KEY, regCenterConfig);
+ session.setAttribute(RegistryCenterController.REG_CENTER_CONFIG_KEY, regCenterConfig);
try {
RegistryCenterFactory.createCoordinatorRegistryCenter(regCenterConfig.getZkAddressList(), regCenterConfig.getNamespace(), regCenterConfig.getDigest());
- SessionRegistryCenterConfiguration.setRegistryCenterConfiguration((RegistryCenterConfiguration) session.getAttribute(RegistryCenterRESTfulAPI.REG_CENTER_CONFIG_KEY));
+ SessionRegistryCenterConfiguration.setRegistryCenterConfiguration((RegistryCenterConfiguration) session.getAttribute(RegistryCenterController.REG_CENTER_CONFIG_KEY));
} catch (final RegException ex) {
return false;
}
@@ -102,11 +102,11 @@ public final class GlobalConfigurationFilter implements Filter {
}
private boolean setEventTraceDataSourceNameToSession(final EventTraceDataSourceConfiguration dataSourceConfig, final HttpSession session) {
- session.setAttribute(EventTraceDataSourceRESTfulAPI.DATA_SOURCE_CONFIG_KEY, dataSourceConfig);
+ session.setAttribute(EventTraceDataSourceController.DATA_SOURCE_CONFIG_KEY, dataSourceConfig);
try {
EventTraceDataSourceFactory.createEventTraceDataSource(dataSourceConfig.getDriver(), dataSourceConfig.getUrl(),
dataSourceConfig.getUsername(), Optional.fromNullable(dataSourceConfig.getPassword()));
- SessionEventTraceDataSourceConfiguration.setDataSourceConfiguration((EventTraceDataSourceConfiguration) session.getAttribute(EventTraceDataSourceRESTfulAPI.DATA_SOURCE_CONFIG_KEY));
+ SessionEventTraceDataSourceConfiguration.setDataSourceConfiguration((EventTraceDataSourceConfiguration) session.getAttribute(EventTraceDataSourceController.DATA_SOURCE_CONFIG_KEY));
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/security/AuthenticationResult.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/security/AuthenticationResult.java
new file mode 100644
index 0000000..751a6f3
--- /dev/null
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/security/AuthenticationResult.java
@@ -0,0 +1,36 @@
+/*
+ * 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.shardingsphere.elasticjob.lite.console.security;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import lombok.Setter;
+
+/**
+ * Authentication result.
+ **/
+@Getter
+@Setter
+@RequiredArgsConstructor
+public class AuthenticationResult {
+
+ private final boolean success;
+
+ private final boolean isGuest;
+
+}
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/security/UserAuthenticationService.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/security/UserAuthenticationService.java
new file mode 100644
index 0000000..77bacba
--- /dev/null
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/security/UserAuthenticationService.java
@@ -0,0 +1,57 @@
+/*
+ * 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.shardingsphere.elasticjob.lite.console.security;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+/**
+ * User authentication service.
+ **/
+@Component
+@ConfigurationProperties(prefix = "auth")
+@Getter
+@Setter
+public class UserAuthenticationService {
+
+ private String rootUsername;
+
+ private String rootPassword;
+
+ private String guestUsername;
+
+ private String guestPassword;
+
+ /**
+ * Check user.
+ *
+ * @param authorization authorization
+ * @return authorization result
+ */
+ public AuthenticationResult checkUser(final String authorization) {
+ if ((rootUsername + ":" + rootPassword).equals(authorization)) {
+ return new AuthenticationResult(true, false);
+ } else if ((guestUsername + ":" + guestPassword).equals(authorization)) {
+ return new AuthenticationResult(true, true);
+ } else {
+ return new AuthenticationResult(false, false);
+ }
+ }
+}
diff --git a/elastic-job-lite-lifecycle/src/main/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/security/WwwAuthFilter.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/security/WwwAuthFilter.java
similarity index 60%
rename from elastic-job-lite-lifecycle/src/main/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/security/WwwAuthFilter.java
rename to elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/security/WwwAuthFilter.java
index 19d96f4..696acc7 100644
--- a/elastic-job-lite-lifecycle/src/main/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/security/WwwAuthFilter.java
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/security/WwwAuthFilter.java
@@ -15,12 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.lite.lifecycle.security;
-
-import com.google.common.base.Joiner;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.codec.binary.Base64;
+package org.apache.shardingsphere.elasticjob.lite.console.security;
+import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@@ -29,59 +26,29 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.net.URL;
-import java.util.Properties;
+import lombok.Setter;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.codec.binary.Base64;
/**
* WWW auth filter.
*/
@Slf4j
public final class WwwAuthFilter implements Filter {
-
- private static final String FILE_SEPARATOR = System.getProperty("file.separator");
-
+
private static final String AUTH_PREFIX = "Basic ";
-
+
private static final String ROOT_IDENTIFY = "root";
-
- private static final String ROOT_DEFAULT_USERNAME = "root";
-
- private static final String ROOT_DEFAULT_PASSWORD = "root";
-
+
private static final String GUEST_IDENTIFY = "guest";
-
- private static final String GUEST_DEFAULT_USERNAME = "guest";
-
- private static final String GUEST_DEFAULT_PASSWORD = "guest";
-
- private String rootUsername;
-
- private String rootPassword;
-
- private String guestUsername;
-
- private String guestPassword;
-
+
+ @Setter
+ private UserAuthenticationService userAuthenticationService;
+
@Override
public void init(final FilterConfig filterConfig) {
- Properties props = new Properties();
- URL classLoaderURL = Thread.currentThread().getContextClassLoader().getResource("");
- if (null != classLoaderURL) {
- String configFilePath = Joiner.on(FILE_SEPARATOR).join(classLoaderURL.getPath(), "conf", "auth.properties");
- try {
- props.load(new FileInputStream(configFilePath));
- } catch (final IOException ex) {
- log.warn("Cannot found auth config file, use default auth config.");
- }
- }
- rootUsername = props.getProperty("root.username", ROOT_DEFAULT_USERNAME);
- rootPassword = props.getProperty("root.password", ROOT_DEFAULT_PASSWORD);
- guestUsername = props.getProperty("guest.username", GUEST_DEFAULT_USERNAME);
- guestPassword = props.getProperty("guest.password", GUEST_DEFAULT_PASSWORD);
}
-
+
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
@@ -89,11 +56,9 @@ public final class WwwAuthFilter implements Filter {
String authorization = httpRequest.getHeader("authorization");
if (null != authorization && authorization.length() > AUTH_PREFIX.length()) {
authorization = authorization.substring(AUTH_PREFIX.length());
- if ((rootUsername + ":" + rootPassword).equals(new String(Base64.decodeBase64(authorization)))) {
- authenticateSuccess(httpResponse, false);
- chain.doFilter(httpRequest, httpResponse);
- } else if ((guestUsername + ":" + guestPassword).equals(new String(Base64.decodeBase64(authorization)))) {
- authenticateSuccess(httpResponse, true);
+ AuthenticationResult authenticationResult = userAuthenticationService.checkUser(new String(Base64.decodeBase64(authorization)));
+ if (authenticationResult.isSuccess()) {
+ authenticateSuccess(httpResponse, authenticationResult.isGuest());
chain.doFilter(httpRequest, httpResponse);
} else {
needAuthenticate(httpResponse);
@@ -102,7 +67,7 @@ public final class WwwAuthFilter implements Filter {
needAuthenticate(httpResponse);
}
}
-
+
private void authenticateSuccess(final HttpServletResponse response, final boolean isGuest) {
response.setStatus(200);
response.setHeader("Pragma", "No-cache");
@@ -110,14 +75,14 @@ public final class WwwAuthFilter implements Filter {
response.setDateHeader("Expires", 0);
response.setHeader("identify", isGuest ? GUEST_IDENTIFY : ROOT_IDENTIFY);
}
-
+
private void needAuthenticate(final HttpServletResponse response) {
response.setStatus(401);
response.setHeader("Cache-Control", "no-store");
response.setDateHeader("Expires", 0);
response.setHeader("WWW-authenticate", AUTH_PREFIX + "Realm=\"Elastic Job Console Auth\"");
}
-
+
@Override
public void destroy() {
}
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/service/impl/EventTraceDataSourceConfigurationServiceImpl.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/service/impl/EventTraceDataSourceConfigurationServiceImpl.java
index 8031fcd..b1a5b83 100644
--- a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/service/impl/EventTraceDataSourceConfigurationServiceImpl.java
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/service/impl/EventTraceDataSourceConfigurationServiceImpl.java
@@ -24,10 +24,12 @@ import org.apache.shardingsphere.elasticjob.lite.console.repository.Configuratio
import org.apache.shardingsphere.elasticjob.lite.console.repository.impl.ConfigurationsXmlRepositoryImpl;
import org.apache.shardingsphere.elasticjob.lite.console.service.EventTraceDataSourceConfigurationService;
import com.google.common.base.Optional;
+import org.springframework.stereotype.Service;
/**
* Event trace data source configuration service implementation.
*/
+@Service
public final class EventTraceDataSourceConfigurationServiceImpl implements EventTraceDataSourceConfigurationService {
private ConfigurationsXmlRepository configurationsXmlRepository = new ConfigurationsXmlRepositoryImpl();
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/service/impl/JobAPIServiceImpl.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/service/impl/JobAPIServiceImpl.java
index daa47a1..4a02c77 100644
--- a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/service/impl/JobAPIServiceImpl.java
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/service/impl/JobAPIServiceImpl.java
@@ -27,10 +27,12 @@ import org.apache.shardingsphere.elasticjob.lite.lifecycle.api.JobStatisticsAPI;
import org.apache.shardingsphere.elasticjob.lite.lifecycle.api.ServerStatisticsAPI;
import org.apache.shardingsphere.elasticjob.lite.lifecycle.api.ShardingOperateAPI;
import org.apache.shardingsphere.elasticjob.lite.lifecycle.api.ShardingStatisticsAPI;
+import org.springframework.stereotype.Service;
/**
* Job API service implementation.
*/
+@Service
public final class JobAPIServiceImpl implements JobAPIService {
@Override
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/service/impl/RegistryCenterConfigurationServiceImpl.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/service/impl/RegistryCenterConfigurationServiceImpl.java
index 8b865db..92de22f 100644
--- a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/service/impl/RegistryCenterConfigurationServiceImpl.java
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/service/impl/RegistryCenterConfigurationServiceImpl.java
@@ -24,10 +24,12 @@ import org.apache.shardingsphere.elasticjob.lite.console.repository.Configuratio
import org.apache.shardingsphere.elasticjob.lite.console.repository.impl.ConfigurationsXmlRepositoryImpl;
import org.apache.shardingsphere.elasticjob.lite.console.service.RegistryCenterConfigurationService;
import com.google.common.base.Optional;
+import org.springframework.stereotype.Service;
/**
* Registry center configuration service implementation.
*/
+@Service
public final class RegistryCenterConfigurationServiceImpl implements RegistryCenterConfigurationService {
private ConfigurationsXmlRepository configurationsXmlRepository = new ConfigurationsXmlRepositoryImpl();
diff --git a/elastic-job-lite-console/src/main/resources/conf/auth.properties b/elastic-job-lite-console/src/main/resources/application.properties
similarity index 84%
rename from elastic-job-lite-console/src/main/resources/conf/auth.properties
rename to elastic-job-lite-console/src/main/resources/application.properties
index 0a9fee6..a2d2d0a 100644
--- a/elastic-job-lite-console/src/main/resources/conf/auth.properties
+++ b/elastic-job-lite-console/src/main/resources/application.properties
@@ -15,7 +15,10 @@
# limitations under the License.
#
-root.username=root
-root.password=root
-guest.username=guest
-guest.password=guest
+# Default web server port
+server.port=8899
+
+auth.root_username=root
+auth.root_password=root
+auth.guest_username=guest
+auth.guest_password=guest
diff --git a/elastic-job-lite-console/src/main/resources/assembly/assembly.xml b/elastic-job-lite-console/src/main/resources/assembly/assembly.xml
index e68368b..b0d2683 100644
--- a/elastic-job-lite-console/src/main/resources/assembly/assembly.xml
+++ b/elastic-job-lite-console/src/main/resources/assembly/assembly.xml
@@ -22,7 +22,11 @@
</formats>
<fileSets>
<fileSet>
- <directory>src/main/resources/conf</directory>
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>application.properties</include>
+ <include>logback.xml</include>
+ </includes>
<outputDirectory>conf</outputDirectory>
<directoryMode>0755</directoryMode>
<fileMode>0644</fileMode>
diff --git a/elastic-job-lite-console/src/main/resources/bin/start.bat b/elastic-job-lite-console/src/main/resources/bin/start.bat
index 2edc9a9..7adc7b7 100644
--- a/elastic-job-lite-console/src/main/resources/bin/start.bat
+++ b/elastic-job-lite-console/src/main/resources/bin/start.bat
@@ -13,7 +13,7 @@ set PORT=%1
:doStart
set CFG_DIR=%~dp0%..
set CLASSPATH=%CFG_DIR%
-set CLASSPATH=%~dp0..\lib\*;%~dp0..\ext-lib\*;%CLASSPATH%
+set CLASSPATH=%~dp0..\lib\*;%~dp0..\ext-lib\*;%~dp0..\conf;%CLASSPATH%
set CONSOLE_MAIN=org.apache.shardingsphere.elasticjob.lite.console.ConsoleBootstrap
echo on
if ""%PORT%"" == """" set PORT=8899
diff --git a/elastic-job-lite-console/src/main/resources/bin/start.sh b/elastic-job-lite-console/src/main/resources/bin/start.sh
index 9e50fbb..49ee8bf 100644
--- a/elastic-job-lite-console/src/main/resources/bin/start.sh
+++ b/elastic-job-lite-console/src/main/resources/bin/start.sh
@@ -28,7 +28,7 @@ fi
cd `dirname $0`
cd ..
DEPLOY_DIR=`pwd`
-LIB_DIR=${DEPLOY_DIR}/lib/*:${DEPLOY_DIR}/ext-lib/*
+CLASS_PATH=.:${DEPLOY_DIR}/conf:${DEPLOY_DIR}/lib/*:${DEPLOY_DIR}/ext-lib/*
CONSOLE_MAIN=org.apache.shardingsphere.elasticjob.lite.console.ConsoleBootstrap
-java -classpath ${LIB_DIR}:. ${CONSOLE_MAIN} $port
+java -classpath ${CLASS_PATH}:. ${CONSOLE_MAIN} $port
diff --git a/elastic-job-lite-lifecycle/pom.xml b/elastic-job-lite-lifecycle/pom.xml
index 9a525ae..c0d6815 100644
--- a/elastic-job-lite-lifecycle/pom.xml
+++ b/elastic-job-lite-lifecycle/pom.xml
@@ -53,11 +53,7 @@
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
- <dependency>
- <groupId>org.eclipse.jetty.aggregate</groupId>
- <artifactId>jetty-all-server</artifactId>
- </dependency>
-
+
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
diff --git a/elastic-job-lite-lifecycle/src/main/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/restful/RESTfulAPIServer.java b/elastic-job-lite-lifecycle/src/main/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/restful/RESTfulAPIServer.java
deleted file mode 100644
index db2dafa..0000000
--- a/elastic-job-lite-lifecycle/src/main/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/restful/RESTfulAPIServer.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * 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.shardingsphere.elasticjob.lite.lifecycle.restful;
-
-import com.google.common.base.Joiner;
-import com.google.common.base.Strings;
-import com.sun.jersey.api.core.PackagesResourceConfig;
-import com.sun.jersey.spi.container.servlet.ServletContainer;
-import lombok.extern.slf4j.Slf4j;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.handler.HandlerList;
-import org.eclipse.jetty.servlet.DefaultServlet;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.eclipse.jetty.servlet.ServletHolder;
-import org.eclipse.jetty.util.resource.Resource;
-
-import javax.servlet.DispatcherType;
-import javax.servlet.Filter;
-import java.util.EnumSet;
-
-/**
- * RESTful API server.
- */
-@Slf4j
-public final class RESTfulAPIServer {
-
- private final Server server;
-
- private final ServletContextHandler servletContextHandler;
-
- public RESTfulAPIServer(final int port) {
- server = new Server(port);
- servletContextHandler = buildServletContextHandler();
- }
-
- /**
- * Start server.
- *
- * @param packages packages of RESTful implementation classes
- * @param resourcePath resource path
- * @throws Exception server startup exception
- */
- public void start(final String packages, final String resourcePath) throws Exception {
- start(packages, resourcePath, "/api");
- }
-
- /**
- * Start server.
- *
- * @param packages packages of RESTful implementation classes
- * @param resourcePath resource path
- * @param servletPath servlet path
- * @throws Exception server startup exception
- */
- public void start(final String packages, final String resourcePath, final String servletPath) throws Exception {
- log.info("Elastic Job: Start RESTful server");
- HandlerList handlers = new HandlerList();
- if (!Strings.isNullOrEmpty(resourcePath)) {
- servletContextHandler.setBaseResource(Resource.newClassPathResource(resourcePath));
- servletContextHandler.addServlet(new ServletHolder(DefaultServlet.class), "/*");
- }
- String servletPathStr = servletPath + "/*";
- servletContextHandler.addServlet(getServletHolder(packages), servletPathStr);
- handlers.addHandler(servletContextHandler);
- server.setHandler(handlers);
- server.start();
- }
-
- /**
- * Add filter.
- *
- * @param filterClass filter implementation classes
- * @param urlPattern url pattern to be filtered
- * @return RESTful API server
- */
- public RESTfulAPIServer addFilter(final Class<? extends Filter> filterClass, final String urlPattern) {
- servletContextHandler.addFilter(filterClass, urlPattern, EnumSet.of(DispatcherType.REQUEST));
- return this;
- }
-
- private ServletContextHandler buildServletContextHandler() {
- ServletContextHandler result = new ServletContextHandler(ServletContextHandler.SESSIONS);
- result.setContextPath("/");
- return result;
- }
-
- private ServletHolder getServletHolder(final String packages) {
- ServletHolder result = new ServletHolder(ServletContainer.class);
- result.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES, Joiner.on(",").join(RESTfulAPIServer.class.getPackage().getName(), packages));
- result.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", PackagesResourceConfig.class.getName());
- result.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", Boolean.TRUE.toString());
- result.setInitParameter("resteasy.scan.providers", Boolean.TRUE.toString());
- result.setInitParameter("resteasy.use.builtin.providers", Boolean.FALSE.toString());
- return result;
- }
-
- /**
- * Stop server.
- *
- */
- public void stop() {
- log.info("Elastic Job: Stop RESTful server");
- try {
- server.stop();
- // CHECKSTYLE:OFF
- } catch (final Exception e) {
- // CHECKSTYLE:ON
- log.error("Elastic Job: Stop RESTful server error", e);
- }
- }
-}
diff --git a/elastic-job-lite-lifecycle/src/test/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/restful/RestfulServerTest.java b/elastic-job-lite-lifecycle/src/test/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/restful/RestfulServerTest.java
deleted file mode 100644
index 510b130..0000000
--- a/elastic-job-lite-lifecycle/src/test/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/restful/RestfulServerTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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.shardingsphere.elasticjob.lite.lifecycle.restful;
-
-import org.apache.shardingsphere.elasticjob.lite.lifecycle.restful.fixture.Caller;
-import org.apache.shardingsphere.elasticjob.lite.lifecycle.restful.fixture.TestFilter;
-import org.apache.shardingsphere.elasticjob.lite.lifecycle.restful.fixture.TestRESTfulApi;
-import org.eclipse.jetty.client.ContentExchange;
-import org.eclipse.jetty.client.HttpClient;
-import org.eclipse.jetty.io.ByteArrayBuffer;
-import org.hamcrest.core.StringStartsWith;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import javax.ws.rs.core.MediaType;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.verify;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class RestfulServerTest {
-
- private static final String URL = "http://127.0.0.1:17000/api/test/call";
-
- private static RESTfulAPIServer server;
-
- @Mock
- private Caller caller;
-
- @BeforeClass
- public static void setUpClass() throws Exception {
- server = new RESTfulAPIServer(17000);
- server.addFilter(TestFilter.class, "/*");
- server.start(TestRESTfulApi.class.getPackage().getName(), null);
- }
-
- @AfterClass
- public static void tearDown() {
- server.stop();
- }
-
- @Before
- public void setUp() {
- TestRESTfulApi.setCaller(caller);
- }
-
- @Test
- public void assertCallSuccess() throws Exception {
- ContentExchange actual = sentRequest("{\"string\":\"test\",\"integer\":1}");
- assertThat(actual.getResponseStatus(), is(200));
- assertThat(actual.getResponseContent(), is("{\"string\":\"test_processed\",\"integer\":\"1_processed\"}"));
- verify(caller).call("test");
- verify(caller).call(1);
- }
-
- @Test
- public void assertCallFailure() throws Exception {
- ContentExchange actual = sentRequest("{\"string\":\"test\",\"integer\":\"invalid_number\"}");
- assertThat(actual.getResponseStatus(), is(500));
- assertThat(actual.getResponseContent(), StringStartsWith.startsWith("java.lang.NumberFormatException"));
- verify(caller).call("test");
- }
-
- private static ContentExchange sentRequest(final String content) throws Exception {
- HttpClient httpClient = new HttpClient();
- try {
- httpClient.start();
- ContentExchange result = new ContentExchange();
- result.setMethod("POST");
- result.setRequestContentType(MediaType.APPLICATION_JSON);
- result.setRequestContent(new ByteArrayBuffer(content.getBytes("UTF-8")));
- httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
- result.setURL(URL);
- httpClient.send(result);
- result.waitForDone();
- return result;
- } finally {
- httpClient.stop();
- }
- }
-}
diff --git a/elastic-job-lite-lifecycle/src/test/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/restful/fixture/TestFilter.java b/elastic-job-lite-lifecycle/src/test/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/restful/fixture/TestFilter.java
deleted file mode 100644
index 4acf868..0000000
--- a/elastic-job-lite-lifecycle/src/test/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/restful/fixture/TestFilter.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.shardingsphere.elasticjob.lite.lifecycle.restful.fixture;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-public final class TestFilter implements Filter {
-
- @Override
- public void init(final FilterConfig filterConfig) {
- }
-
- @Override
- public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
- HttpServletRequest httpRequest = (HttpServletRequest) request;
- HttpServletResponse httpResponse = (HttpServletResponse) response;
- chain.doFilter(httpRequest, httpResponse);
- }
-
- @Override
- public void destroy() {
- }
-}
diff --git a/pom.xml b/pom.xml
index 6613404..838b547 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,7 +29,7 @@
<version>3.0.0.M1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
-
+
<modules>
<module>elastic-job-lite-core</module>
<module>elastic-job-lite-tracing</module>
@@ -37,15 +37,15 @@
<module>elastic-job-lite-lifecycle</module>
<module>elastic-job-lite-console</module>
</modules>
-
+
<properties>
<java.version>1.8</java.version>
<maven.version.range>[3.0.4,)</maven.version.range>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.locale>zh_CN</project.build.locale>
-
+
<springframework.version>[3.1.0.RELEASE,5.0.0.M1)</springframework.version>
-
+
<guava.version>18.0</guava.version>
<commons-lang3.version>3.4</commons-lang3.version>
<quartz.version>2.3.0</quartz.version>
@@ -59,13 +59,12 @@
<snakeyaml.version>1.26</snakeyaml.version>
<gson.version>2.6.1</gson.version>
<jersey.version>1.19</jersey.version>
- <jetty-all-server.version>8.1.19.v20160209</jetty-all-server.version>
<commons-dbcp.version>1.4</commons-dbcp.version>
<mysql-connector-java.version>5.1.30</mysql-connector-java.version>
<h2.version>1.4.184</h2.version>
<junit.version>4.12</junit.version>
<mockito.version>2.7.21</mockito.version>
-
+
<apache-rat-plugin.version>0.12</apache-rat-plugin.version>
<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
<maven-resources-plugin.version>2.7</maven-resources-plugin.version>
@@ -88,10 +87,10 @@
<jdepend-maven-plugin.version>2.0</jdepend-maven-plugin.version>
<taglist-maven-plugin.version>2.4</taglist-maven-plugin.version>
<maven-assembly-plugin.version>3.1.0</maven-assembly-plugin.version>
-
+
<javadocExecutable>${java.home}/../bin/javadoc</javadocExecutable>
</properties>
-
+
<dependencyManagement>
<dependencies>
<dependency>
@@ -136,7 +135,7 @@
<version>${curator.version}</version>
<scope>test</scope>
</dependency>
-
+
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
@@ -199,16 +198,11 @@
<version>${jersey.version}</version>
</dependency>
<dependency>
- <groupId>org.eclipse.jetty.aggregate</groupId>
- <artifactId>jetty-all-server</artifactId>
- <version>${jetty-all-server.version}</version>
- </dependency>
- <dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>${commons-dbcp.version}</version>
</dependency>
-
+
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
@@ -245,7 +239,7 @@
<version>${mysql-connector-java.version}</version>
<scope>provided</scope>
</dependency>
-
+
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
@@ -290,7 +284,7 @@
</dependency>
</dependencies>
</dependencyManagement>
-
+
<build>
<pluginManagement>
<plugins>
@@ -581,7 +575,7 @@
</plugin>
</plugins>
</build>
-
+
<reporting>
<plugins>
<plugin>
@@ -649,7 +643,7 @@
</plugin>
</plugins>
</reporting>
-
+
<url>http://shardingsphere.apache.org</url>
<description>Distributed scheduled job solution</description>
<licenses>
@@ -659,14 +653,14 @@
<distribution>repo</distribution>
</license>
</licenses>
-
+
<scm>
<connection>scm:git:https://github.com/apache/shardingsphere-elastic-job-lite.git</connection>
<developerConnection>scm:git:https://github.com/apache/shardingsphere-elastic-job-lite.git</developerConnection>
<url>https://github.com/apache/shardingsphere-elastic-job-lite.git</url>
<tag>HEAD</tag>
</scm>
-
+
<mailingLists>
<mailingList>
<name>ShardingSphere Developer List</name>