提交 ae32da32 编写于 作者: L ligang

Initial module escheduler-api commit

上级 a2dccd16
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.analysys</groupId>
<artifactId>escheduler</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>escheduler-api</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>cn.analysys</groupId>
<artifactId>escheduler-dao</artifactId>
</dependency>
<dependency>
<groupId>cn.analysys</groupId>
<artifactId>escheduler-common</artifactId>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</exclusion>
<exclusion>
<groupId>com.google</groupId>
<artifactId>netty</artifactId>
</exclusion>
<exclusion>
<artifactId>leveldbjni-all</artifactId>
<groupId>org.fusesource.leveldbjni</groupId>
</exclusion>
</exclusions>
</dependency>
<!--springboot-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- use jetty -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
<exclusions>
<exclusion>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server-impl</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-jobs</artifactId>
</dependency>
<dependency>
<groupId>cn.analysys</groupId>
<artifactId>escheduler-rpc</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/package.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
maven 打包
mvn -U clean package assembly:assembly -Dmaven.test.skip=true
note : 如果启动springboot发生如下的错误
Unable to start embedded container; nested exception is java.lang.NoSuchMethodError: javax.servlet.ServletContext.addServlet(Ljava/lang/String;Ljavax/servlet/Servlet;)Ljavax/servlet/ServletRegistration$Dynamic;
solve method :
File -> Project Structure -> escheduler-server -> Dependencies remove servlet-api 2.5
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>cluster</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.json</include>
</includes>
<outputDirectory>conf</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.parent.basedir}/escheduler-common/src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.json</include>
</includes>
<outputDirectory>conf</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.parent.basedir}/escheduler-common/src/main/resources/bin</directory>
<includes>
<include>*.*</include>
</includes>
<directoryMode>755</directoryMode>
<outputDirectory>bin</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.parent.basedir}/escheduler-dao/src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.json</include>
</includes>
<outputDirectory>conf</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.parent.basedir}/escheduler-api/src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.json</include>
</includes>
<outputDirectory>conf</outputDirectory>
</fileSet>
<fileSet>
<directory>target/</directory>
<includes>
<include>escheduler-api-${project.version}.jar</include>
</includes>
<outputDirectory>lib</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<excludes>
<exclude>javax.servlet:servlet-api</exclude>
<exclude>org.eclipse.jetty.aggregate:jetty-all</exclude>
<exclude>org.slf4j:slf4j-log4j12</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
\ No newline at end of file
/*
* 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;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ServletComponentScan
@ComponentScan("cn.escheduler")
public class ApiApplicationServer {
public static void main(String[] args) {
SpringApplication.run(ApiApplicationServer.class, args);
}
}
/*
* 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 cn.escheduler.api.interceptor.LoginHandlerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* application configuration
*/
@Configuration
public class AppConfiguration extends WebMvcConfigurerAdapter {
public static final String LOGIN_INTERCEPTOR_PATH_PATTERN = "/**/*";
public static final String LOGIN_PATH_PATTERN = "/login";
public static final String PATH_PATTERN = "/**";
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(loginInterceptor()).addPathPatterns(LOGIN_INTERCEPTOR_PATH_PATTERN).excludePathPatterns(LOGIN_PATH_PATTERN);
}
@Bean
public LoginHandlerInterceptor loginInterceptor() {
return new LoginHandlerInterceptor();
}
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping(PATH_PATTERN).allowedOrigins("*").allowedMethods("*");
}
/**
* Turn off suffix-based content negotiation
*
* @param configurer
*/
@Override
public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false);
}
}
/*
* 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.controller;
import cn.escheduler.api.service.AlertGroupService;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.Result;
import cn.escheduler.common.enums.AlertType;
import cn.escheduler.dao.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
import static cn.escheduler.api.enums.Status.*;
@RestController
@RequestMapping("alert-group")
public class AlertGroupController extends BaseController{
private static final Logger logger = LoggerFactory.getLogger(AlertGroupController.class);
@Autowired
private AlertGroupService alertGroupService;
/**
* create alert group
* @param loginUser
* @param groupName
* @param groupType
* @param desc
* @return
*/
@PostMapping(value = "/create")
@ResponseStatus(HttpStatus.CREATED)
public Result createAlertgroup(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "groupName") String groupName,
@RequestParam(value = "groupType") AlertType groupType,
@RequestParam(value = "desc",required = false) String desc) {
logger.info("loginUser user {}, create alertgroup, groupName: {}, groupType: {}, desc: {}",
loginUser.getUserName(), groupName, groupType,desc);
try {
Map<String, Object> result = alertGroupService.createAlertgroup(loginUser, groupName, groupType,desc);
return returnDataList(result);
}catch (Exception e){
logger.error(CREATE_ALERT_GROUP_ERROR.getMsg(),e);
return error(CREATE_ALERT_GROUP_ERROR.getCode(),CREATE_ALERT_GROUP_ERROR.getMsg());
}
}
/**
* alert group list
* @param loginUser
* @return
*/
@GetMapping(value = "/list")
@ResponseStatus(HttpStatus.OK)
public Result list(@RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
logger.info("login user {}, query all alertGroup",
loginUser.getUserName());
try{
HashMap<String, Object> result = alertGroupService.queryAlertgroup();
return returnDataList(result);
}catch (Exception e){
logger.error(QUERY_ALL_ALERTGROUP_ERROR.getMsg(),e);
return error(QUERY_ALL_ALERTGROUP_ERROR.getCode(),QUERY_ALL_ALERTGROUP_ERROR.getMsg());
}
}
/**
* paging query alarm group list
*
* @param loginUser
* @param pageNo
* @param searchVal
* @param pageSize
* @return
*/
@GetMapping(value="/list-paging")
@ResponseStatus(HttpStatus.OK)
public Result listPaging(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("pageNo") Integer pageNo,
@RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageSize") Integer pageSize){
logger.info("login user {}, list paging, pageNo: {}, searchVal: {}, pageSize: {}",
loginUser.getUserName(),pageNo,searchVal,pageSize);
try{
Map<String, Object> result = checkPageParams(pageNo, pageSize);
if(result.get(Constants.STATUS) != SUCCESS){
return returnDataListPaging(result);
}
result = alertGroupService.listPaging(loginUser, searchVal, pageNo, pageSize);
return returnDataListPaging(result);
}catch (Exception e){
logger.error(LIST_PAGING_ALERT_GROUP_ERROR.getMsg(),e);
return error(LIST_PAGING_ALERT_GROUP_ERROR.getCode(),LIST_PAGING_ALERT_GROUP_ERROR.getMsg());
}
}
/**
* updateProcessInstance alert group
* @param loginUser
* @param id
* @param groupName
* @param groupType
* @param desc
* @return
*/
@PostMapping(value = "/update")
@ResponseStatus(HttpStatus.OK)
public Result updateAlertgroup(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id") int id,
@RequestParam(value = "groupName") String groupName,
@RequestParam(value = "groupType") AlertType groupType,
@RequestParam(value = "desc",required = false) String desc) {
logger.info("login user {}, updateProcessInstance alertgroup, groupName: {}, groupType: {}, desc: {}",
loginUser.getUserName(), groupName, groupType,desc);
try {
Map<String, Object> result = alertGroupService.updateAlertgroup(loginUser, id, groupName, groupType, desc);
return returnDataList(result);
}catch (Exception e){
logger.error(UPDATE_ALERT_GROUP_ERROR.getMsg(),e);
return error(UPDATE_ALERT_GROUP_ERROR.getCode(),UPDATE_ALERT_GROUP_ERROR.getMsg());
}
}
/**
* delete alert group by id
* @param loginUser
* @param id
* @return
*/
@PostMapping(value = "/delete")
@ResponseStatus(HttpStatus.OK)
public Result delAlertgroupById(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id") int id) {
logger.info("login user {}, delete AlertGroup, id: {},", loginUser.getUserName(), id);
try {
Map<String, Object> result = alertGroupService.delAlertgroupById(loginUser, id);
return returnDataList(result);
}catch (Exception e){
logger.error(DELETE_ALERT_GROUP_ERROR.getMsg(),e);
return error(DELETE_ALERT_GROUP_ERROR.getCode(),DELETE_ALERT_GROUP_ERROR.getMsg());
}
}
/**
* check alert group exist
* @param loginUser
* @param groupName
* @return
*/
@GetMapping(value = "/verify-group-name")
@ResponseStatus(HttpStatus.OK)
public Result verifyGroupName(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value ="groupName") String groupName
) {
logger.info("login user {}, verfiy group name: {}",
loginUser.getUserName(),groupName);
return alertGroupService.verifyGroupName(loginUser, groupName);
}
/**
* grant user
*
* @param loginUser
* @param userIds
* @return
*/
@PostMapping(value = "/grant-user")
@ResponseStatus(HttpStatus.OK)
public Result grantUser(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "alertgroupId") int alertgroupId,
@RequestParam(value = "userIds") String userIds) {
logger.info("login user {}, grant user, alertGroupId: {},userIds : {}", loginUser.getUserName(), alertgroupId,userIds);
try {
Map<String, Object> result = alertGroupService.grantUser(loginUser, alertgroupId, userIds);
return returnDataList(result);
}catch (Exception e){
logger.error(ALERT_GROUP_GRANT_USER_ERROR.getMsg(),e);
return error(ALERT_GROUP_GRANT_USER_ERROR.getCode(),ALERT_GROUP_GRANT_USER_ERROR.getMsg());
}
}
}
/*
* 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.controller;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.PageInfo;
import cn.escheduler.api.utils.Result;
import cn.escheduler.dao.model.Resource;
import org.apache.commons.lang3.StringUtils;
import javax.servlet.http.HttpServletRequest;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import static cn.escheduler.common.Constants.*;
/**
* base controller
*/
public class BaseController {
/**
* check params
*
* @param pageNo
* @param pageSize
* @return
*/
public Map<String, Object> checkPageParams(int pageNo, int pageSize) {
Map<String, Object> result = new HashMap<>(2);
Status resultEnum = Status.SUCCESS;
String msg = Status.SUCCESS.getMsg();
if (pageNo <= 0) {
resultEnum = Status.REQUEST_PARAMS_NOT_VALID_ERROR;
msg = MessageFormat.format(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getMsg(), Constants.PAGE_NUMBER);
} else if (pageSize <= 0) {
resultEnum = Status.REQUEST_PARAMS_NOT_VALID_ERROR;
msg = MessageFormat.format(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getMsg(), Constants.PAGE_SIZE);
}
result.put(Constants.STATUS, resultEnum);
result.put(Constants.MSG, msg);
return result;
}
/**
* get ip address in the http request
*
* @param request
* @return client ip address
*/
public static String getClientIpAddress(HttpServletRequest request) {
String clientIp = request.getHeader(HTTP_X_FORWARDED_FOR);
if (StringUtils.isNotEmpty(clientIp) && !StringUtils.equalsIgnoreCase(HTTP_HEADER_UNKNOWN, clientIp)) {
int index = clientIp.indexOf(COMMA);
if (index != -1) {
return clientIp.substring(0, index);
} else {
return clientIp;
}
}
clientIp = request.getHeader(HTTP_X_REAL_IP);
if (StringUtils.isNotEmpty(clientIp) && !StringUtils.equalsIgnoreCase(HTTP_HEADER_UNKNOWN, clientIp)) {
return clientIp;
}
return request.getRemoteAddr();
}
/**
* return data list
*
* @param result
* @return
*/
public Result returnDataList(Map<String, Object> result) {
Status status = (Status) result.get(Constants.STATUS);
if (status == Status.SUCCESS) {
String msg = Status.SUCCESS.getMsg();
Object datalist = result.get(Constants.DATA_LIST);
return success(msg, datalist);
} else {
Integer code = status.getCode();
String msg = (String) result.get(Constants.MSG);
return error(code, msg);
}
}
/**
* return data list with paging
* @param result
* @return
*/
public Result returnDataListPaging(Map<String, Object> result) {
Status status = (Status) result.get(Constants.STATUS);
if (status == Status.SUCCESS) {
result.put(Constants.MSG, Status.SUCCESS.getMsg());
PageInfo<Resource> pageInfo = (PageInfo<Resource>) result.get(Constants.DATA_LIST);
return success(pageInfo.getLists(), pageInfo.getCurrentPage(), pageInfo.getTotalCount(),
pageInfo.getTotalPage());
} else {
Integer code = status.getCode();
String msg = (String) result.get(Constants.MSG);
return error(code, msg);
}
}
/**
* success
*
* @return
*/
public Result success() {
Result result = new Result();
result.setCode(Status.SUCCESS.getCode());
result.setMsg(Status.SUCCESS.getMsg());
return result;
}
/**
* success does not need to return data
*
* @param msg
* @return
*/
public Result success(String msg) {
Result result = new Result();
result.setCode(Status.SUCCESS.getCode());
result.setMsg(msg);
return result;
}
/**
* return data no paging
*
* @param msg
* @param list
* @return
*/
public Result success(String msg, Object list) {
Result result = getResult(msg, list);
return result;
}
/**
* return data no paging
*
* @param list
* @return
*/
public Result success(Object list) {
Result result = getResult(Status.SUCCESS.getMsg(), list);
return result;
}
/**
* return the data use Map format, for example, passing the value of key, value, passing a value
* eg. "/user/add" then return user name: zhangsan
*
* @param msg
* @param object
* @return
*/
public Result success(String msg, Map<String, Object> object) {
Result result = getResult(msg, object);
return result;
}
/**
* return data with paging
*
* @param totalList
* @param currentPage
* @param total
* @return
*/
public Result success(Object totalList, Integer currentPage,
Integer total, Integer totalPage) {
Result result = new Result();
result.setCode(Status.SUCCESS.getCode());
result.setMsg(Status.SUCCESS.getMsg());
Map<String, Object> map = new HashMap<>(4);
map.put(Constants.TOTAL_LIST, totalList);
map.put(Constants.CURRENT_PAGE, currentPage);
map.put(Constants.TOTAL_PAGE, totalPage);
map.put(Constants.TOTAL, total);
result.setData(map);
return result;
}
/**
* error handle
*
* @param code
* @param msg
* @return
*/
public Result error(Integer code, String msg) {
Result result = new Result();
result.setCode(code);
result.setMsg(msg);
return result;
}
/**
* put message to map
*
* @param result
* @param status
* @param statusParams
*/
protected void putMsg(Map<String, Object> result, Status status, Object... statusParams) {
result.put(Constants.STATUS, status);
if (statusParams != null && statusParams.length > 0) {
result.put(Constants.MSG, MessageFormat.format(status.getMsg(), statusParams));
} else {
result.put(Constants.MSG, status.getMsg());
}
}
/**
* put message to result object
*
* @param result
* @param status
*/
protected void putMsg(Result result, Status status, Object... statusParams) {
result.setCode(status.getCode());
if (statusParams != null && statusParams.length > 0) {
result.setMsg(MessageFormat.format(status.getMsg(), statusParams));
} else {
result.setMsg(status.getMsg());
}
}
/**
* get result
* @param msg
* @param list
* @return
*/
private Result getResult(String msg, Object list) {
Result result = new Result();
result.setCode(Status.SUCCESS.getCode());
result.setMsg(msg);
result.setData(list);
return result;
}
}
\ No newline at end of file
/*
* 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.controller;
import cn.escheduler.api.service.DataAnalysisService;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.Result;
import cn.escheduler.dao.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import static cn.escheduler.api.enums.Status.*;
/**
* data analysis controller
*/
@RestController
@RequestMapping("projects/analysis")
public class DataAnalysisController extends BaseController{
private static final Logger logger = LoggerFactory.getLogger(DataAnalysisController.class);
@Autowired
DataAnalysisService dataAnalysisService;
/**
* statistical task instance status data
*
* @param loginUser
* @param projectId
* @return
*/
@GetMapping(value="/task-state-count")
@ResponseStatus(HttpStatus.OK)
public Result countTaskState(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value="startDate", required=false) String startDate,
@RequestParam(value="endDate", required=false) String endDate,
@RequestParam(value="projectId", required=false, defaultValue = "0") int projectId
){
try{
logger.info("count task state, user:{}, start date: {}, end date:{}, project id {}",
loginUser.getUserName(), startDate, endDate, projectId);
Map<String, Object> result = dataAnalysisService.countTaskStateByProject(loginUser,projectId, startDate, endDate);
return returnDataList(result);
}catch (Exception e){
logger.error(TASK_INSTANCE_STATE_COUNT_ERROR.getMsg(),e);
return error(TASK_INSTANCE_STATE_COUNT_ERROR.getCode(), TASK_INSTANCE_STATE_COUNT_ERROR.getMsg());
}
}
/**
* statistical process instance status data
*
* @param loginUser
* @param projectId
* @return
*/
@GetMapping(value="/process-state-count")
@ResponseStatus(HttpStatus.OK)
public Result countProcessInstanceState(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value="startDate", required=false) String startDate,
@RequestParam(value="endDate", required=false) String endDate,
@RequestParam(value="projectId", required=false, defaultValue = "0") int projectId
){
try{
logger.info("count process instance state, user:{}, start date: {}, end date:{}, project id",
loginUser.getUserName(), startDate, endDate, projectId);
Map<String, Object> result = dataAnalysisService.countProcessInstanceStateByProject(loginUser,projectId, startDate, endDate);
return returnDataList(result);
}catch (Exception e){
logger.error(COUNT_PROCESS_INSTANCE_STATE_ERROR.getMsg(),e);
return error(COUNT_PROCESS_INSTANCE_STATE_ERROR.getCode(), COUNT_PROCESS_INSTANCE_STATE_ERROR.getMsg());
}
}
/**
* statistics the process definition quantities of certain person
*
* @param loginUser
* @param projectId
* @return
*/
@GetMapping(value="/define-user-count")
@ResponseStatus(HttpStatus.OK)
public Result countDefinitionByUser(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value="projectId", required=false, defaultValue = "0") int projectId
){
try{
logger.info("count process definition , user:{}, project id",
loginUser.getUserName(), projectId);
Map<String, Object> result = dataAnalysisService.countDefinitionByUser(loginUser, projectId);
return returnDataList(result);
}catch (Exception e){
logger.error(COUNT_PROCESS_DEFINITION_USER_ERROR.getMsg(),e);
return error(COUNT_PROCESS_DEFINITION_USER_ERROR.getCode(), COUNT_PROCESS_DEFINITION_USER_ERROR.getMsg());
}
}
}
/*
* 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.controller;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.service.DataSourceService;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.Result;
import cn.escheduler.common.enums.DbType;
import cn.escheduler.dao.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import static cn.escheduler.api.enums.Status.*;
/**
* data source controller
*/
@RestController
@RequestMapping("datasources")
public class DataSourceController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(DataSourceController.class);
@Autowired
private DataSourceService dataSourceService;
/**
* create data source
* 创建数据源
*
* @param loginUser
* @param name
* @param note
* @param type
* @param other
* @return
*/
@PostMapping(value = "/create")
@ResponseStatus(HttpStatus.CREATED)
public Result createDataSource(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("name") String name,
@RequestParam(value = "note", required = false) String note,
@RequestParam(value = "type") DbType type,
@RequestParam(value = "host") String host,
@RequestParam(value = "port") String port,
@RequestParam(value = "database") String database,
@RequestParam(value = "userName") String userName,
@RequestParam(value = "password") String password,
@RequestParam(value = "other") String other) {
logger.info("login user {} create datasource ame: {}, note: {}, type: {}, other: {}",
loginUser.getUserName(), name, note, type, other);
try {
String parameter = dataSourceService.buildParameter(name, note, type, host, port, database, userName, password, other);
Map<String, Object> result = dataSourceService.createDataSource(loginUser, name, note, type, parameter);
return returnDataList(result);
} catch (Exception e) {
logger.error(CREATE_DATASOURCE_ERROR.getMsg(),e);
return error(Status.CREATE_DATASOURCE_ERROR.getCode(), Status.CREATE_DATASOURCE_ERROR.getMsg());
}
}
/**
* updateProcessInstance data source
*
* @param loginUser
* @param name
* @param note
* @param type
* @param other
* @return
*/
@PostMapping(value = "/update")
@ResponseStatus(HttpStatus.OK)
public Result updateDataSource(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("id") int id,
@RequestParam("name") String name,
@RequestParam(value = "note", required = false) String note,
@RequestParam(value = "type") DbType type,
@RequestParam(value = "host") String host,
@RequestParam(value = "port") String port,
@RequestParam(value = "database") String database,
@RequestParam(value = "userName") String userName,
@RequestParam(value = "password") String password,
@RequestParam(value = "other") String other) {
logger.info("login user {} updateProcessInstance datasource name: {}, note: {}, type: {}, other: {}",
loginUser.getUserName(), name, note, type, other);
try {
String parameter = dataSourceService.buildParameter(name, note, type, host, port, database, userName, password, other);
Map<String, Object> dataSource = dataSourceService.updateDataSource(id, loginUser, name, note, type, parameter);
return returnDataList(dataSource);
} catch (Exception e) {
logger.error(UPDATE_DATASOURCE_ERROR.getMsg(),e);
return error(UPDATE_DATASOURCE_ERROR.getCode(), UPDATE_DATASOURCE_ERROR.getMsg());
}
}
/**
* query data source
*
* @param loginUser
* @param id
* @return
*/
@PostMapping(value = "/update-ui")
@ResponseStatus(HttpStatus.OK)
public Result queryDataSource(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("id") int id) {
logger.info("login user {}, query datasource: {}",
loginUser.getUserName(), id);
try {
Map<String, Object> result = dataSourceService.queryDataSource(id);
return returnDataList(result);
} catch (Exception e) {
logger.error(QUERY_DATASOURCE_ERROR.getMsg(),e);
return error(Status.QUERY_DATASOURCE_ERROR.getCode(), Status.QUERY_DATASOURCE_ERROR.getMsg());
}
}
/**
* query datasouce by type
*
* @param loginUser
* @return
*/
@GetMapping(value = "/list")
@ResponseStatus(HttpStatus.OK)
public Result queryDataSourceList(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("type") DbType type) {
try {
Map<String, Object> result = dataSourceService.queryDataSourceList(loginUser, type.ordinal());
return returnDataList(result);
} catch (Exception e) {
logger.error(QUERY_DATASOURCE_ERROR.getMsg(),e);
return error(Status.QUERY_DATASOURCE_ERROR.getCode(), Status.QUERY_DATASOURCE_ERROR.getMsg());
}
}
/**
* query datasource with paging
*
* @param loginUser
* @param searchVal
* @param pageNo
* @param pageSize
* @return
*/
@GetMapping(value = "/list-paging")
@ResponseStatus(HttpStatus.OK)
public Result queryDataSourceListPaging(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize) {
try {
Map<String, Object> result = checkPageParams(pageNo, pageSize);
if (result.get(Constants.STATUS) != Status.SUCCESS) {
return returnDataListPaging(result);
}
result = dataSourceService.queryDataSourceListPaging(loginUser, searchVal, pageNo, pageSize);
return returnDataListPaging(result);
} catch (Exception e) {
logger.error(QUERY_DATASOURCE_ERROR.getMsg(),e);
return error(QUERY_DATASOURCE_ERROR.getCode(), QUERY_DATASOURCE_ERROR.getMsg());
}
}
/**
* connec datasource
*
* @param loginUser
* @param name
* @param note
* @param type
* @param other
* @return
*/
@PostMapping(value = "/connect")
@ResponseStatus(HttpStatus.OK)
public Result connectDataSource(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("name") String name,
@RequestParam(value = "note", required = false) String note,
@RequestParam(value = "type") DbType type,
@RequestParam(value = "host") String host,
@RequestParam(value = "port") String port,
@RequestParam(value = "database") String database,
@RequestParam(value = "userName") String userName,
@RequestParam(value = "password") String password,
@RequestParam(value = "other") String other) {
logger.info("login user {}, connect datasource: {} failure, note: {}, type: {}, other: {}",
loginUser.getUserName(), name, note, type, other);
try {
String parameter = dataSourceService.buildParameter(name, note, type, host, port, database, userName, password, other);
Boolean isConnection = dataSourceService.checkConnection(type, parameter);
Result result = new Result();
if (isConnection) {
putMsg(result, SUCCESS);
} else {
putMsg(result, CONNECT_DATASOURCE_FAILURE);
}
return result;
} catch (Exception e) {
logger.error(CONNECT_DATASOURCE_FAILURE.getMsg(),e);
return error(CONNECT_DATASOURCE_FAILURE.getCode(), CONNECT_DATASOURCE_FAILURE.getMsg());
}
}
/**
* connection test
*
* @param loginUser
* @return
*/
@GetMapping(value = "/connect-by-id")
@ResponseStatus(HttpStatus.OK)
public Result connectionTest(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("id") int id) {
logger.info("connection test, login user:{}, id:{}", loginUser.getUserName(), id);
try {
Boolean isConnection = dataSourceService.connectionTest(loginUser, id);
Result result = new Result();
if (isConnection) {
putMsg(result, SUCCESS);
} else {
putMsg(result, CONNECTION_TEST_FAILURE);
}
return result;
} catch (Exception e) {
logger.error(CONNECTION_TEST_FAILURE.getMsg(),e);
return error(CONNECTION_TEST_FAILURE.getCode(), CONNECTION_TEST_FAILURE.getMsg());
}
}
/**
* delete datasource by id
*
* @param loginUser
* @param id datasource id
* @return
*/
@GetMapping(value = "/delete")
@ResponseStatus(HttpStatus.OK)
public Result delete(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("id") int id) {
try {
logger.info("delete datasource,login user:{}, id:{}", loginUser.getUserName(), id);
return dataSourceService.delete(loginUser, id);
} catch (Exception e) {
logger.error(DELETE_DATA_SOURCE_FAILURE.getMsg(),e);
return error(DELETE_DATA_SOURCE_FAILURE.getCode(), DELETE_DATA_SOURCE_FAILURE.getMsg());
}
}
/**
* verify datasource name
*
* @param loginUser
* @param name
* @return
*/
@GetMapping(value = "/verify-name")
@ResponseStatus(HttpStatus.OK)
public Result verifyDataSourceName(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "name") String name
) {
logger.info("login user {}, verfiy datasource name: {}",
loginUser.getUserName(), name);
try {
return dataSourceService.verifyDataSourceName(loginUser, name);
} catch (Exception e) {
logger.error(VERFIY_DATASOURCE_NAME_FAILURE.getMsg(),e);
return error(VERFIY_DATASOURCE_NAME_FAILURE.getCode(), VERFIY_DATASOURCE_NAME_FAILURE.getMsg());
}
}
/**
* unauthorized datasource
*
* @param loginUser
* @param userId
* @return
*/
@GetMapping(value = "/unauth-datasource")
@ResponseStatus(HttpStatus.OK)
public Result unauthDatasource(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("userId") Integer userId) {
try {
logger.info("unauthorized datasource, login user:{}, unauthorized userId:{}",
loginUser.getUserName(), userId);
Map<String, Object> result = dataSourceService.unauthDatasource(loginUser, userId);
return returnDataList(result);
} catch (Exception e) {
logger.error(UNAUTHORIZED_DATASOURCE.getMsg(),e);
return error(UNAUTHORIZED_DATASOURCE.getCode(), UNAUTHORIZED_DATASOURCE.getMsg());
}
}
/**
* authorized datasource
*
* @param loginUser
* @param userId
* @return
*/
@GetMapping(value = "/authed-datasource")
@ResponseStatus(HttpStatus.OK)
public Result authedDatasource(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("userId") Integer userId) {
try {
logger.info("authorized data source, login user:{}, authorized useId:{}",
loginUser.getUserName(), userId);
Map<String, Object> result = dataSourceService.authedDatasource(loginUser, userId);
return returnDataList(result);
} catch (Exception e) {
logger.error(AUTHORIZED_DATA_SOURCE.getMsg(),e);
return error(AUTHORIZED_DATA_SOURCE.getCode(), AUTHORIZED_DATA_SOURCE.getMsg());
}
}
}
/*
* 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.controller;
import cn.escheduler.api.enums.ExecuteType;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.service.ExecutorService;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.Result;
import cn.escheduler.common.enums.*;
import cn.escheduler.dao.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import static cn.escheduler.api.enums.Status.*;
/**
* execute task controller
*/
@RestController
@RequestMapping("projects/{projectName}/executors")
public class ExecutorController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(ExecutorController.class);
@Autowired
private ExecutorService execService;
/**
* execute process instance
*/
@PostMapping(value = "start-process-instance")
@ResponseStatus(HttpStatus.OK)
public Result startProcessInstance(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam(value = "processDefinitionId") int processDefinitionId,
@RequestParam(value = "scheduleTime", required = false) String scheduleTime,
@RequestParam(value = "failureStrategy", required = true) FailureStrategy failureStrategy,
@RequestParam(value = "startNodeList", required = false) String startNodeList,
@RequestParam(value = "taskDependType", required = false) TaskDependType taskDependType,
@RequestParam(value = "execType", required = false) CommandType execType,
@RequestParam(value = "warningType", required = true) WarningType warningType,
@RequestParam(value = "warningGroupId", required = false) int warningGroupId,
@RequestParam(value = "receivers", required = false) String receivers,
@RequestParam(value = "receiversCc", required = false) String receiversCc,
@RequestParam(value = "runMode", required = false) RunMode runMode,
@RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority,
@RequestParam(value = "timeout", required = false) Integer timeout) {
try {
logger.info("login user {}, start process instance, project name: {}, process definition id: {}, schedule time: {}, "
+ "failure policy: {}, node name: {}, node dep: {}, notify type: {}, "
+ "notify group id: {},receivers:{},receiversCc:{}, run mode: {},process instance priority:{}, timeout: {}",
loginUser.getUserName(), projectName, processDefinitionId, scheduleTime, failureStrategy,
taskDependType, warningType, warningGroupId,receivers,receiversCc,runMode,processInstancePriority,timeout);
if (timeout == null) {
timeout = cn.escheduler.common.Constants.MAX_TASK_TIMEOUT;
}
Map<String, Object> result = execService.execProcessInstance(loginUser, projectName, processDefinitionId, scheduleTime, execType, failureStrategy,
startNodeList, taskDependType, warningType,
warningGroupId,receivers,receiversCc, runMode,processInstancePriority,timeout);
return returnDataList(result);
} catch (Exception e) {
logger.error(START_PROCESS_INSTANCE_ERROR.getMsg(),e);
return error(Status.START_PROCESS_INSTANCE_ERROR.getCode(), Status.START_PROCESS_INSTANCE_ERROR.getMsg());
}
}
/**
* do action to process instance:pause, stop, repeat, recover from pause, recover from stop
*
* @param loginUser
* @param projectName
* @param processInstanceId
* @return
*/
@PostMapping(value = "/execute")
@ResponseStatus(HttpStatus.OK)
public Result execute(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam("processInstanceId") Integer processInstanceId,
@RequestParam("executeType") ExecuteType executeType
) {
try {
logger.info("execute command, login user: {}, project:{}, process instance id:{}, execute type:{}",
loginUser.getUserName(), projectName, processInstanceId, executeType.toString());
Map<String, Object> result = execService.execute(loginUser, projectName, processInstanceId, executeType);
return returnDataList(result);
} catch (Exception e) {
logger.error(EXECUTE_PROCESS_INSTANCE_ERROR.getMsg(),e);
return error(EXECUTE_PROCESS_INSTANCE_ERROR.getCode(), EXECUTE_PROCESS_INSTANCE_ERROR.getMsg());
}
}
/**
* check process definition and all of the son process definitions is on line.
*
* @param loginUser
* @param processDefinitionId
* @return
*/
@PostMapping(value = "/start-check")
@ResponseStatus(HttpStatus.OK)
public Result startCheckProcessDefinition(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "processDefinitionId") int processDefinitionId) {
logger.info("login user {}, check process definition", loginUser.getUserName(), processDefinitionId);
try {
Map<String, Object> result = execService.startCheckByProcessDefinedId(processDefinitionId);
return returnDataList(result);
} catch (Exception e) {
logger.error(CHECK_PROCESS_DEFINITION_ERROR.getMsg(),e);
return error(CHECK_PROCESS_DEFINITION_ERROR.getCode(), CHECK_PROCESS_DEFINITION_ERROR.getMsg());
}
}
/**
* query recipients and copyers by process definition ID
*
* @param loginUser
* @param processDefinitionId
* @return
*/
@GetMapping(value = "/get-receiver-cc")
@ResponseStatus(HttpStatus.OK)
public Result getReceiverCc(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "processDefinitionId") int processDefinitionId){
logger.info("login user {}, get process definition receiver and cc", loginUser.getUserName());
try {
Map<String, Object> result = execService.getReceiverCc(processDefinitionId);
return returnDataList(result);
} catch (Exception e) {
logger.error(QUERY_RECIPIENTS_AND_COPYERS_BY_PROCESS_DEFINITION_ERROR.getMsg(),e);
return error(QUERY_RECIPIENTS_AND_COPYERS_BY_PROCESS_DEFINITION_ERROR.getCode(), QUERY_RECIPIENTS_AND_COPYERS_BY_PROCESS_DEFINITION_ERROR.getMsg());
}
}
}
/*
* 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.controller;
import cn.escheduler.api.service.LoggerService;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.Result;
import cn.escheduler.dao.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import static cn.escheduler.api.enums.Status.DOWNLOAD_TASK_INSTANCE_LOG_FILE_ERROR;
import static cn.escheduler.api.enums.Status.QUERY_TASK_INSTANCE_LOG_ERROR;
/**
* log controller
*/
@RestController
@RequestMapping("/log")
public class LoggerController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(LoggerController.class);
@Autowired
private LoggerService loggerService;
/**
* query task log
*/
@GetMapping(value = "/detail")
@ResponseStatus(HttpStatus.OK)
public Result queryLog(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "taskInstId") int taskInstanceId,
@RequestParam(value = "skipLineNum") int skipNum,
@RequestParam(value = "limit") int limit) {
try {
logger.info(
"login user {}, view {} task instance log ,skipLineNum {} , limit {}", loginUser.getUserName(), taskInstanceId, skipNum, limit);
return loggerService.queryLog(taskInstanceId, skipNum, limit);
} catch (Exception e) {
logger.error(QUERY_TASK_INSTANCE_LOG_ERROR.getMsg(), e);
return error(QUERY_TASK_INSTANCE_LOG_ERROR.getCode(), QUERY_TASK_INSTANCE_LOG_ERROR.getMsg());
}
}
/**
* download log file
*
* @param loginUser
* @param taskInstanceId
*/
@GetMapping(value = "/download-log")
@ResponseBody
public ResponseEntity downloadTaskLog(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "taskInstId") int taskInstanceId) {
try {
byte[] logBytes = loggerService.getLogBytes(taskInstanceId);
return ResponseEntity
.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + System.currentTimeMillis() + ".queryLog" + "\"")
.body(logBytes);
} catch (Exception e) {
logger.error(DOWNLOAD_TASK_INSTANCE_LOG_FILE_ERROR.getMsg(), e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(DOWNLOAD_TASK_INSTANCE_LOG_FILE_ERROR.getMsg());
}
}
}
/*
* 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.controller;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.service.SessionService;
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 org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import static cn.escheduler.api.enums.Status.*;
/**
* user login controller
*/
@RestController
@RequestMapping("")
public class LoginController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(LoginController.class);
@Autowired
private SessionService sessionService;
@Autowired
private UsersService userService;
/**
* login
*
* @param userName
* @param userPassword
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/login")
public Result login(@RequestParam(value = "userName") String userName,
@RequestParam(value = "userPassword") String userPassword,
HttpServletRequest request,
HttpServletResponse response) {
try {
logger.info("login user name: {} ", userName);
//user name check
if (StringUtils.isEmpty(userName)) {
return error(Status.USER_NAME_NULL.getCode(),
Status.USER_NAME_NULL.getMsg());
}
// user ip check
String ip = getClientIpAddress(request);
if (StringUtils.isEmpty(ip)) {
return error(IP_IS_EMPTY.getCode(), IP_IS_EMPTY.getMsg());
}
// verify username and password
User user = userService.queryUser(userName, userPassword);
if (user == null) {
return error(Status.USER_NAME_PASSWD_ERROR.getCode(),Status.USER_NAME_PASSWD_ERROR.getMsg()
);
}
// create session
String sessionId = sessionService.createSession(user, ip);
if (sessionId == null) {
return error(Status.LOGIN_SESSION_FAILED.getCode(),
Status.LOGIN_SESSION_FAILED.getMsg()
);
}
response.setStatus(HttpStatus.SC_OK);
response.addCookie(new Cookie(Constants.SESSION_ID, sessionId));
logger.info("sessionId = " + sessionId);
return success(LOGIN_SUCCESS.getMsg(), sessionId);
} catch (Exception e) {
logger.error(USER_LOGIN_FAILURE.getMsg(),e);
return error(USER_LOGIN_FAILURE.getCode(), USER_LOGIN_FAILURE.getMsg());
}
}
/**
* sign out
*
* @param loginUser
* @return
*/
@PostMapping(value = "/signOut")
public Result signOut(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
HttpServletRequest request) {
try {
logger.info("login user:{} sign out", loginUser.getUserName());
String ip = getClientIpAddress(request);
sessionService.signOut(ip, loginUser);
//clear session
request.removeAttribute(Constants.SESSION_USER);
return success();
} catch (Exception e) {
logger.error(SIGN_OUT_ERROR.getMsg(),e);
return error(SIGN_OUT_ERROR.getCode(), SIGN_OUT_ERROR.getMsg());
}
}
}
/*
* 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.controller;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.service.ProcessDefinitionService;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.Result;
import cn.escheduler.dao.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import static cn.escheduler.api.enums.Status.*;
/**
* process definition controller
*/
@RestController
@RequestMapping("projects/{projectName}/process")
public class ProcessDefinitionController extends BaseController{
private static final Logger logger = LoggerFactory.getLogger(ProcessDefinitionController.class);
@Autowired
private ProcessDefinitionService processDefinitionService;
/**
* create process definition
*
* @param loginUser
* @param projectName
* @param name
* @param json process definition json
* @param desc
* @return
*/
@PostMapping(value = "/save")
@ResponseStatus(HttpStatus.CREATED)
public Result createProcessDefinition(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam(value = "name", required = true) String name,
@RequestParam(value = "processDefinitionJson", required = true) String json,
@RequestParam(value = "locations", required = false) String locations,
@RequestParam(value = "connects", required = false) String connects,
@RequestParam(value = "desc", required = false) String desc) {
try {
logger.info("login user {}, create process definition, project name: {}, process definition name: {}, " +
"process_definition_json: {}, desc: {} locations:{}, connects:{}",
loginUser.getUserName(), projectName, name, json,desc, locations, connects);
Map<String, Object> result = processDefinitionService.createProcessDefinition(loginUser, projectName, name, json,
desc, locations, connects );
return returnDataList(result);
}catch (Exception e){
logger.error(CREATE_PROCESS_DEFINITION.getMsg(),e);
return error(CREATE_PROCESS_DEFINITION.getCode(), CREATE_PROCESS_DEFINITION.getMsg());
}
}
/**
* verify process definition name unique
*
* @param loginUser
* @param projectName
* @param name
* @return
*/
@GetMapping(value = "/verify-name")
@ResponseStatus(HttpStatus.OK)
public Result verifyProccessDefinitionName(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam(value = "name", required = true) String name){
try {
logger.info("verify process definition name unique, user:{}, project name:{}, process definition name:{}",
loginUser.getUserName(), projectName, name);
Map<String, Object> result = processDefinitionService.verifyProccessDefinitionName(loginUser, projectName, name);
return returnDataList(result);
}catch (Exception e){
logger.error(VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR.getMsg(),e);
return error(VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR.getCode(), Status.VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR.getMsg());
}
}
/**
* update process definition
*
* @param loginUser
* @param projectName
* @param name
* @param id
* @param processDefinitionJson
* @param desc
* @return
*/
@PostMapping(value = "/update")
@ResponseStatus(HttpStatus.OK)
public Result updateProccessDefinition(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam(value = "name", required = true) String name,
@RequestParam(value = "id", required = true) int id,
@RequestParam(value = "processDefinitionJson", required = true) String processDefinitionJson,
@RequestParam(value = "locations", required = false) String locations,
@RequestParam(value = "connects", required = false) String connects,
@RequestParam(value = "desc", required = false) String desc) {
try {
logger.info("login user {}, update process define, project name: {}, process define name: {}, " +
"process_definition_json: {}, desc: {}, locations:{}, connects:{}",
loginUser.getUserName(), projectName, name, processDefinitionJson,desc, locations, connects);
Map<String, Object> result = processDefinitionService.updateProccessDefinition(loginUser, projectName, id, name,
processDefinitionJson, desc, locations, connects);
return returnDataList(result);
}catch (Exception e){
logger.error(UPDATE_PROCESS_DEFINITION_ERROR.getMsg(),e);
return error(UPDATE_PROCESS_DEFINITION_ERROR.getCode(), Status.UPDATE_PROCESS_DEFINITION_ERROR.getMsg());
}
}
/**
* release process definition
*
* @param loginUser
* @param projectName
* @param processId
* @param releaseState
* @return
*/
@PostMapping(value = "/release")
@ResponseStatus(HttpStatus.OK)
public Result releaseProccessDefinition(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam(value = "processId", required = true) int processId,
@RequestParam(value = "releaseState", required = true) int releaseState) {
try {
logger.info("login user {}, release process definition, project name: {}, release state: {}",
loginUser.getUserName(), projectName, releaseState);
Map<String, Object> result = processDefinitionService.releaseProcessDefinition(loginUser, projectName, processId, releaseState);
return returnDataList(result);
}catch (Exception e){
logger.error(RELEASE_PROCESS_DEFINITION_ERROR.getMsg(),e);
return error(RELEASE_PROCESS_DEFINITION_ERROR.getCode(), Status.RELEASE_PROCESS_DEFINITION_ERROR.getMsg());
}
}
/**
* query datail of process definition
*
* @param loginUser
* @param projectName
* @param processId
* @return
*/
@GetMapping(value="/select-by-id")
@ResponseStatus(HttpStatus.OK)
public Result queryProccessDefinitionById(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam("processId") Integer processId
){
try{
logger.info("query datail of process definition, login user:{}, project name:{}, process definition id:{}",
loginUser.getUserName(), projectName, processId);
Map<String, Object> result = processDefinitionService.queryProccessDefinitionById(loginUser, projectName, processId);
return returnDataList(result);
}catch (Exception e){
logger.error(QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR.getMsg(),e);
return error(QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR.getCode(), Status.QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR.getMsg());
}
}
/**
* query proccess definition list
*
* @param loginUser
* @param projectName
* @return
*/
@GetMapping(value="/list")
@ResponseStatus(HttpStatus.OK)
public Result queryProccessDefinitionList(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName
){
try{
logger.info("query proccess definition list, login user:{}, project name:{}",
loginUser.getUserName(), projectName);
Map<String, Object> result = processDefinitionService.queryProccessDefinitionList(loginUser, projectName);
return returnDataList(result);
}catch (Exception e){
logger.error(QUERY_PROCCESS_DEFINITION_LIST.getMsg(),e);
return error(QUERY_PROCCESS_DEFINITION_LIST.getCode(), QUERY_PROCCESS_DEFINITION_LIST.getMsg());
}
}
/**
* query proccess definition list paging
* @param loginUser
* @param projectName
* @param pageNo
* @param pageSize
* @return
*/
@GetMapping(value="/list-paging")
@ResponseStatus(HttpStatus.OK)
public Result queryProcessDefinitionListPaging(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam("pageNo") Integer pageNo,
@RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam(value = "userId", required = false, defaultValue = "0") Integer userId,
@RequestParam("pageSize") Integer pageSize){
try{
logger.info("query proccess definition list paging, login user:{}, project name:{}", loginUser.getUserName(), projectName);
Map<String, Object> result = checkPageParams(pageNo, pageSize);
if(result.get(Constants.STATUS) != Status.SUCCESS){
return returnDataListPaging(result);
}
result = processDefinitionService.queryProcessDefinitionListPaging(loginUser, projectName, searchVal, pageNo, pageSize, userId);
return returnDataListPaging(result);
}catch (Exception e){
logger.error(QUERY_PROCCESS_DEFINITION_LIST_PAGING_ERROR.getMsg(),e);
return error(QUERY_PROCCESS_DEFINITION_LIST_PAGING_ERROR.getCode(), QUERY_PROCCESS_DEFINITION_LIST_PAGING_ERROR.getMsg());
}
}
/**
* encapsulation treeview structure
*
* @param loginUser
* @param projectName
* @param id
* @return
*/
@GetMapping(value="/view-tree")
@ResponseStatus(HttpStatus.OK)
public Result viewTree(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam("processId") Integer id,
@RequestParam("limit") Integer limit){
try{
Map<String, Object> result = processDefinitionService.viewTree(id, limit);
return returnDataList(result);
}catch (Exception e){
logger.error(ENCAPSULATION_TREEVIEW_STRUCTURE_ERROR.getMsg(),e);
return error(ENCAPSULATION_TREEVIEW_STRUCTURE_ERROR.getCode(),ENCAPSULATION_TREEVIEW_STRUCTURE_ERROR.getMsg());
}
}
/**
*
* get tasks list by process definition id
*
*
* @param loginUser
* @param projectName
* @param processDefinitionId
* @return
*/
@GetMapping(value="gen-task-list")
@ResponseStatus(HttpStatus.OK)
public Result getNodeListByDefinitionId(
@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam("processDefinitionId") Integer processDefinitionId){
try {
logger.info("query task node name list by definitionId, login user:{}, project name:{}, id : {}",
loginUser.getUserName(), projectName, processDefinitionId);
Map<String, Object> result = processDefinitionService.getTaskNodeListByDefinitionId(processDefinitionId);
return returnDataList(result);
}catch (Exception e){
logger.error(GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR.getMsg(), e);
return error(GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR.getCode(), GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR.getMsg());
}
}
/**
*
* get tasks list by process definition id
*
*
* @param loginUser
* @param projectName
* @param processDefinitionIdList
* @return
*/
@GetMapping(value="get-task-list")
@ResponseStatus(HttpStatus.OK)
public Result getNodeListByDefinitionIdList(
@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam("processDefinitionIdList") String processDefinitionIdList){
try {
logger.info("query task node name list by definitionId list, login user:{}, project name:{}, id list: {}",
loginUser.getUserName(), projectName, processDefinitionIdList);
Map<String, Object> result = processDefinitionService.getTaskNodeListByDefinitionIdList(processDefinitionIdList);
return returnDataList(result);
}catch (Exception e){
logger.error(GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR.getMsg(), e);
return error(GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR.getCode(), GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR.getMsg());
}
}
}
/*
* 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.controller;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.service.ProcessInstanceService;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.Result;
import cn.escheduler.common.enums.ExecutionStatus;
import cn.escheduler.common.enums.Flag;
import cn.escheduler.dao.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import static cn.escheduler.api.enums.Status.*;
/**
* process instance controller
*/
@RestController
@RequestMapping("projects/{projectName}/instance")
public class ProcessInstanceController extends BaseController{
private static final Logger logger = LoggerFactory.getLogger(ProcessInstanceController.class);
@Autowired
ProcessInstanceService processInstanceService;
/**
* query process instance list paging
*
* @param loginUser
* @param projectName
* @param pageNo
* @param pageSize
* @return
*/
@GetMapping(value="list-paging")
@ResponseStatus(HttpStatus.OK)
public Result queryProcessInstanceList(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam(value = "processDefinitionId", required = false, defaultValue = "0") Integer processDefinitionId,
@RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam(value = "stateType", required = false) ExecutionStatus stateType,
@RequestParam(value = "host", required = false) String host,
@RequestParam(value = "startDate", required = false) String startTime,
@RequestParam(value = "endDate", required = false) String endTime,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize){
try{
logger.info("query all process instance list, login user:{},project name:{}, define id:{}," +
"search value:{},state type:{},host:{},start time:{}, end time:{},page number:{}, page size:{}",
loginUser.getUserName(), projectName, processDefinitionId, searchVal, stateType,host,
startTime, endTime, pageNo, pageSize);
Map<String, Object> result = processInstanceService.queryProcessInstanceList(
loginUser, projectName, processDefinitionId, startTime, endTime, searchVal, stateType, host, pageNo, pageSize);
return returnDataListPaging(result);
}catch (Exception e){
logger.error(QUERY_PROCESS_INSTANCE_LIST_PAGING_ERROR.getMsg(),e);
return error(Status.QUERY_PROCESS_INSTANCE_LIST_PAGING_ERROR.getCode(), Status.QUERY_PROCESS_INSTANCE_LIST_PAGING_ERROR.getMsg());
}
}
/**
* query task list by process instance id
*
* @param loginUser
* @param projectName
* @param workflowId
* @return
*/
@GetMapping(value="/task-list-by-process-id")
@ResponseStatus(HttpStatus.OK)
public Result queryTaskListByProcessId(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam("processInstanceId") Integer workflowId
) {
try{
logger.info("query task instance list by process instance id, login user:{}, project name:{}, work instance id:{}",
loginUser.getUserName(), projectName, workflowId);
Map<String, Object> result = processInstanceService.queryTaskListByProcessId(loginUser, projectName, workflowId);
return returnDataList(result);
}catch (Exception e){
logger.error(QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_ERROR.getMsg(),e);
return error(QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_ERROR.getCode(), QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_ERROR.getMsg());
}
}
/**
* update process instance
*
* @param loginUser
* @param projectName
* @param processInstanceJson
* @param processInstanceId
* @param scheduleTime
* @param syncDefine
* @param flag
* @return
*/
@PostMapping(value="/update")
@ResponseStatus(HttpStatus.OK)
public Result updateProcessInstance(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam( value = "processInstanceJson", required = false) String processInstanceJson,
@RequestParam( value = "processInstanceId") Integer processInstanceId,
@RequestParam( value = "scheduleTime", required = false) String scheduleTime,
@RequestParam( value = "syncDefine", required = true) Boolean syncDefine,
@RequestParam(value = "locations", required = false) String locations,
@RequestParam(value = "connects", required = false) String connects,
@RequestParam( value = "flag", required = false) Flag flag
){
try{
logger.info("updateProcessInstance process instance, login user:{}, project name:{}, process instance json:{}," +
"process instance id:{}, schedule time:{}, sync define:{}, flag:{}, locations:{}, connects:{}",
loginUser.getUserName(), projectName, processInstanceJson, processInstanceId, scheduleTime,
syncDefine, flag, locations, connects);
Map<String, Object> result = processInstanceService.updateProcessInstance(loginUser, projectName,
processInstanceId, processInstanceJson, scheduleTime, syncDefine, flag, locations, connects);
return returnDataList(result);
}catch (Exception e){
logger.error(UPDATE_PROCESS_INSTANCE_ERROR.getMsg(),e);
return error(Status.UPDATE_PROCESS_INSTANCE_ERROR.getCode(), Status.UPDATE_PROCESS_INSTANCE_ERROR.getMsg());
}
}
/**
* query process instance by id
*
* @param loginUser
* @param projectName
* @param processInstanceId
* @return
*/
@GetMapping(value="/select-by-id")
@ResponseStatus(HttpStatus.OK)
public Result queryProcessInstanceById(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam("processInstanceId") Integer processInstanceId
){
try{
logger.info("query process instance detail by id, login user:{},project name:{}, process instance id:{}",
loginUser.getUserName(), projectName, processInstanceId);
Map<String, Object> result = processInstanceService.queryProcessInstanceById(loginUser, projectName, processInstanceId);
return returnDataList(result);
}catch (Exception e){
logger.error(QUERY_PROCESS_INSTANCE_BY_ID_ERROR.getMsg(),e);
return error(Status.QUERY_PROCESS_INSTANCE_BY_ID_ERROR.getCode(), Status.QUERY_PROCESS_INSTANCE_BY_ID_ERROR.getMsg());
}
}
/**
* delete process instance by id, at the same time,
* delete task instance and their mapping relation data
*
* @param loginUser
* @param projectName
* @param processInstanceId
* @return
*/
@GetMapping(value="/delete")
@ResponseStatus(HttpStatus.OK)
public Result deleteProcessInstanceById(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam("processInstanceId") Integer processInstanceId
){
try{
logger.info("delete process instance by id, login user:{}, project name:{}, process instance id:{}",
loginUser.getUserName(), projectName, processInstanceId);
Map<String, Object> result = processInstanceService.deleteProcessInstanceById(loginUser, projectName, processInstanceId);
return returnDataList(result);
}catch (Exception e){
logger.error(DELETE_PROCESS_INSTANCE_BY_ID_ERROR.getMsg(),e);
return error(Status.DELETE_PROCESS_INSTANCE_BY_ID_ERROR.getCode(), Status.DELETE_PROCESS_INSTANCE_BY_ID_ERROR.getMsg());
}
}
/**
* query sub process instance detail info by task id
*
* @param loginUser
* @param projectName
* @param taskId
* @return
*/
@GetMapping(value="/select-sub-process")
@ResponseStatus(HttpStatus.OK)
public Result querySubProcessInstanceByTaskId(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam("taskId") Integer taskId){
try{
Map<String, Object> result = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectName, taskId);
return returnDataList(result);
}catch (Exception e){
logger.error(QUERY_SUB_PROCESS_INSTANCE_DETAIL_INFO_BY_TASK_ID_ERROR.getMsg(),e);
return error(Status.QUERY_SUB_PROCESS_INSTANCE_DETAIL_INFO_BY_TASK_ID_ERROR.getCode(), Status.QUERY_SUB_PROCESS_INSTANCE_DETAIL_INFO_BY_TASK_ID_ERROR.getMsg());
}
}
/**
* query parent process instance detail info by sub process instance id
*
* @param loginUser
* @param projectName
* @param subId
* @return
*/
@GetMapping(value="/select-parent-process")
@ResponseStatus(HttpStatus.OK)
public Result queryParentInstanceBySubId(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam("subId") Integer subId){
try{
Map<String, Object> result = processInstanceService.queryParentInstanceBySubId(loginUser, projectName, subId);
return returnDataList(result);
}catch (Exception e){
logger.error(QUERY_PARENT_PROCESS_INSTANCE_DETAIL_INFO_BY_SUB_PROCESS_INSTANCE_ID_ERROR.getMsg(),e);
return error(Status.QUERY_PARENT_PROCESS_INSTANCE_DETAIL_INFO_BY_SUB_PROCESS_INSTANCE_ID_ERROR.getCode(), Status.QUERY_PARENT_PROCESS_INSTANCE_DETAIL_INFO_BY_SUB_PROCESS_INSTANCE_ID_ERROR.getMsg());
}
}
/**
* query process instance global variables and local variables
*
* @param loginUser
* @param processInstanceId
* @return
*/
@GetMapping(value="/view-variables")
@ResponseStatus(HttpStatus.OK)
public Result viewVariables(@RequestAttribute(value = Constants.SESSION_USER) User loginUser
, @RequestParam("processInstanceId") Integer processInstanceId){
try{
Map<String, Object> result = processInstanceService.viewVariables(processInstanceId);
return returnDataList(result);
}catch (Exception e){
logger.error(QUERY_PROCESS_INSTANCE_ALL_VARIABLES_ERROR.getMsg(),e);
return error(Status.QUERY_PROCESS_INSTANCE_ALL_VARIABLES_ERROR.getCode(), Status.QUERY_PROCESS_INSTANCE_ALL_VARIABLES_ERROR.getMsg());
}
}
/**
* encapsulation gantt structure
*
* @param loginUser
* @param projectName
* @param processInstanceId
* @return
*/
@GetMapping(value="/view-gantt")
@ResponseStatus(HttpStatus.OK)
public Result viewTree(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam("processInstanceId") Integer processInstanceId){
try{
Map<String, Object> result = processInstanceService.viewGantt(processInstanceId);
return returnDataList(result);
}catch (Exception e){
logger.error(ENCAPSULATION_PROCESS_INSTANCE_GANTT_STRUCTURE_ERROR.getMsg(),e);
return error(Status.ENCAPSULATION_PROCESS_INSTANCE_GANTT_STRUCTURE_ERROR.getCode(),ENCAPSULATION_PROCESS_INSTANCE_GANTT_STRUCTURE_ERROR.getMsg());
}
}
}
/*
* 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.controller;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.service.ProjectService;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.Result;
import cn.escheduler.dao.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import static cn.escheduler.api.enums.Status.*;
/**
* project controller
*/
@RestController
@RequestMapping("projects")
public class ProjectController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(ProjectController.class);
@Autowired
private ProjectService projectService;
/**
* create project
*
* @param loginUser
* @param projectName
* @param desc
* @return returns an error if it exists
*/
@PostMapping(value = "/create")
@ResponseStatus(HttpStatus.CREATED)
public Result createProject(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("projectName") String projectName,
@RequestParam(value = "desc", required = false) String desc) {
try {
logger.info("login user {}, create project name: {}, desc: {}", loginUser.getUserName(), projectName, desc);
Map<String, Object> result = projectService.createProject(loginUser, projectName, desc);
return returnDataList(result);
} catch (Exception e) {
logger.error(CREATE_PROJECT_ERROR.getMsg(), e);
return error(CREATE_PROJECT_ERROR.getCode(), CREATE_PROJECT_ERROR.getMsg());
}
}
/**
* updateProcessInstance project
*
* @param loginUser
* @param projectId
* @param projectName
* @param desc
* @return
*/
@PostMapping(value = "/update")
@ResponseStatus(HttpStatus.OK)
public Result updateProject(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("projectId") Integer projectId,
@RequestParam("projectName") String projectName,
@RequestParam(value = "desc", required = false) String desc) {
try {
logger.info("login user {} , updateProcessInstance project name: {}, desc: {}", loginUser.getUserName(), projectName, desc);
Map<String, Object> result = projectService.update(loginUser, projectId, projectName, desc);
return returnDataList(result);
} catch (Exception e) {
logger.error(UPDATE_PROJECT_ERROR.getMsg(), e);
return error(UPDATE_PROJECT_ERROR.getCode(), UPDATE_PROJECT_ERROR.getMsg());
}
}
/**
* query project details by id
*
* @param loginUser
* @param projectId
* @return
*/
@GetMapping(value = "/query-by-id")
@ResponseStatus(HttpStatus.OK)
public Result queryProjectById(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("projectId") Integer projectId) {
logger.info("login user {}, query project by id: {}", loginUser.getUserName(), projectId);
try {
Map<String, Object> result = projectService.queryById(projectId);
return returnDataList(result);
} catch (Exception e) {
logger.error(QUERY_PROJECT_DETAILS_BY_ID_ERROR.getMsg(), e);
return error(QUERY_PROJECT_DETAILS_BY_ID_ERROR.getCode(), QUERY_PROJECT_DETAILS_BY_ID_ERROR.getMsg());
}
}
/**
* query project list paging
*
* @param loginUser
* @param searchVal
* @param pageSize
* @param pageNo
* @return
*/
@GetMapping(value = "/list-paging")
@ResponseStatus(HttpStatus.OK)
public Result queryProjectListPaging(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageSize") Integer pageSize,
@RequestParam("pageNo") Integer pageNo
) {
try {
logger.info("login user {}, query project list paging", loginUser.getUserName());
Map<String, Object> result = projectService.queryProjectListPaging(loginUser, pageSize, pageNo, searchVal);
return returnDataListPaging(result);
} catch (Exception e) {
logger.error(LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR.getMsg(), e);
return error(Status.LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR.getCode(), Status.LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR.getMsg());
}
}
/**
* delete project by id
*
* @param loginUser
* @param projectId
* @return
*/
@GetMapping(value = "/delete")
@ResponseStatus(HttpStatus.OK)
public Result deleteProject(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("projectId") Integer projectId
) {
try {
logger.info("login user {}, delete project: {}.", loginUser.getUserName(), projectId);
Map<String, Object> result = projectService.deleteProject(loginUser, projectId);
return returnDataList(result);
} catch (Exception e) {
logger.error(DELETE_PROJECT_ERROR.getMsg(), e);
return error(DELETE_PROJECT_ERROR.getCode(), DELETE_PROJECT_ERROR.getMsg());
}
}
/**
* query unauthorized project
*
* @param loginUser
* @param userId
* @return
*/
@GetMapping(value = "/unauth-project")
@ResponseStatus(HttpStatus.OK)
public Result queryUnauthorizedProject(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("userId") Integer userId) {
try {
logger.info("login user {}, query unauthorized project by user id: {}.", loginUser.getUserName(), userId);
Map<String, Object> result = projectService.queryUnauthorizedProject(loginUser, userId);
return returnDataList(result);
} catch (Exception e) {
logger.error(QUERY_UNAUTHORIZED_PROJECT_ERROR.getMsg(), e);
return error(QUERY_UNAUTHORIZED_PROJECT_ERROR.getCode(), QUERY_UNAUTHORIZED_PROJECT_ERROR.getMsg());
}
}
/**
* query authorized project
*
* @param loginUser
* @param userId
* @return
*/
@GetMapping(value = "/authed-project")
@ResponseStatus(HttpStatus.OK)
public Result queryAuthorizedProject(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("userId") Integer userId) {
try {
logger.info("login user {}, query authorized project by user id: {}.", loginUser.getUserName(), userId);
Map<String, Object> result = projectService.queryAuthorizedProject(loginUser, userId);
return returnDataList(result);
} catch (Exception e) {
logger.error(QUERY_AUTHORIZED_PROJECT.getMsg(), e);
return error(QUERY_AUTHORIZED_PROJECT.getCode(), QUERY_AUTHORIZED_PROJECT.getMsg());
}
}
}
/*
* 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.controller;
import cn.escheduler.api.service.QueueService;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.Result;
import cn.escheduler.dao.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import static cn.escheduler.api.enums.Status.QUERY_QUEUE_LIST_ERROR;
/**
* queue controller
*/
@RestController
@RequestMapping("/queue")
public class QueueController extends BaseController{
private static final Logger logger = LoggerFactory.getLogger(QueueController.class);
@Autowired
private QueueService queueService;
/**
* query queue list
* @param loginUser
* @return
*/
@GetMapping(value="/list")
@ResponseStatus(HttpStatus.OK)
public Result queryList(@RequestAttribute(value = Constants.SESSION_USER) User loginUser){
try{
logger.info("login user {}, query queue list", loginUser.getUserName());
Map<String, Object> result = queueService.queryList(loginUser);
return returnDataList(result);
}catch (Exception e){
logger.error(QUERY_QUEUE_LIST_ERROR.getMsg(),e);
return error(QUERY_QUEUE_LIST_ERROR.getCode(), QUERY_QUEUE_LIST_ERROR.getMsg());
}
}
}
/*
* 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.controller;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.service.SchedulerService;
import cn.escheduler.api.utils.Result;
import cn.escheduler.common.enums.FailureStrategy;
import cn.escheduler.common.enums.Priority;
import cn.escheduler.common.enums.ReleaseState;
import cn.escheduler.common.enums.WarningType;
import cn.escheduler.dao.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import static cn.escheduler.api.enums.Status.*;
import static cn.escheduler.api.utils.Constants.SESSION_USER;
/**
* schedule controller
*/
@RestController
@RequestMapping("/projects/{projectName}/schedule")
public class SchedulerController extends BaseController{
private static final Logger logger = LoggerFactory.getLogger(SchedulerController.class);
public static final String DEFAULT_WARNING_TYPE = "NONE";
public static final String DEFAULT_NOTIFY_GROUP_ID = "1";
public static final String DEFAULT_MAX_TRY_TIMES = "0";
public static final String DEFAULT_FAILURE_POLICY = "CONTINUE";
@Autowired
private SchedulerService schedulerService;
/**
* create schedule
*
* @param loginUser
* @param projectName
* @param processDefinitionId
* @param schedule
* @param warningType
* @param warningGroupId
* @param failureStrategy
* @return
*/
@PostMapping("/create")
@ResponseStatus(HttpStatus.CREATED)
public Result createSchedule(@RequestAttribute(value = SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam(value = "processDefinitionId") Integer processDefinitionId,
@RequestParam(value = "schedule") String schedule,
@RequestParam(value = "warningType", required = false,defaultValue = DEFAULT_WARNING_TYPE) WarningType warningType,
@RequestParam(value = "warningGroupId", required = false,defaultValue = DEFAULT_NOTIFY_GROUP_ID) int warningGroupId,
@RequestParam(value = "failureStrategy", required = false, defaultValue = DEFAULT_FAILURE_POLICY) FailureStrategy failureStrategy,
@RequestParam(value = "receivers", required = false) String receivers,
@RequestParam(value = "receiversCc", required = false) String receiversCc,
@RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority) {
logger.info("login user {}, project name: {}, process name: {}, create schedule: {}, warning type: {}, warning group id: {}," +
"failure policy: {},receivers : {},receiversCc : {},processInstancePriority : {}",
loginUser.getUserName(), projectName, processDefinitionId, schedule, warningType, warningGroupId, failureStrategy,receivers,receiversCc,processInstancePriority);
try {
Map<String, Object> result = schedulerService.insertSchedule(loginUser, projectName, processDefinitionId, schedule,
warningType, warningGroupId, failureStrategy, receivers,receiversCc,processInstancePriority);
return returnDataList(result);
}catch (Exception e){
logger.error(CREATE_SCHEDULE_ERROR.getMsg(),e);
return error(CREATE_SCHEDULE_ERROR.getCode(), CREATE_SCHEDULE_ERROR.getMsg());
}
}
/**
* updateProcessInstance schedule
*
* @param loginUser
* @param projectName
* @param id
* @param schedule
* @param warningType
* @param warningGroupId
* @param failureStrategy
* @return
*/
@PostMapping("/update")
public Result updateSchedule(@RequestAttribute(value = SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam(value = "id") Integer id,
@RequestParam(value = "schedule") String schedule,
@RequestParam(value = "warningType", required = false, defaultValue = DEFAULT_WARNING_TYPE) WarningType warningType,
@RequestParam(value = "warningGroupId", required = false) int warningGroupId,
@RequestParam(value = "failureStrategy", required = false, defaultValue = "END") FailureStrategy failureStrategy,
@RequestParam(value = "receivers", required = false) String receivers,
@RequestParam(value = "receiversCc", required = false) String receiversCc,
@RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority) {
logger.info("login user {}, project name: {},id: {}, updateProcessInstance schedule: {}, notify type: {}, notify mails: {}, " +
"failure policy: {},receivers : {},receiversCc : {},processInstancePriority : {}",
loginUser.getUserName(), projectName, id, schedule, warningType, warningGroupId, failureStrategy,receivers,receiversCc,processInstancePriority);
try {
Map<String, Object> result = schedulerService.updateSchedule(loginUser, projectName, id, schedule,
warningType, warningGroupId, failureStrategy, receivers,receiversCc,null,processInstancePriority);
return returnDataList(result);
}catch (Exception e){
logger.error(UPDATE_SCHEDULE_ERROR.getMsg(),e);
return error(Status.UPDATE_SCHEDULE_ERROR.getCode(), Status.UPDATE_SCHEDULE_ERROR.getMsg());
}
}
/**
* publish schedule setScheduleState
*
* @param loginUser
* @param projectName
* @param id
* @return
* @throws Exception
*/
@PostMapping("/online")
public Result online(@RequestAttribute(value = SESSION_USER) User loginUser,
@PathVariable("projectName") String projectName,
@RequestParam("id") Integer id) {
logger.info("login user {}, schedule setScheduleState, project name: {}, id: {}",
loginUser.getUserName(), projectName, id);
try {
Map<String, Object> result = schedulerService.setScheduleState(loginUser, projectName, id, ReleaseState.ONLINE);
return returnDataList(result);
}catch (Exception e){
logger.error(PUBLISH_SCHEDULE_ONLINE_ERROR.getMsg(),e);
return error(Status.PUBLISH_SCHEDULE_ONLINE_ERROR.getCode(), Status.PUBLISH_SCHEDULE_ONLINE_ERROR.getMsg());
}
}
/**
* offline schedule
*
* @param loginUser
* @param projectName
* @param id
* @return
*/
@PostMapping("/offline")
public Result offline(@RequestAttribute(value = SESSION_USER) User loginUser,
@PathVariable("projectName") String projectName,
@RequestParam("id") Integer id) {
logger.info("login user {}, schedule offline, project name: {}, process definition id: {}",
loginUser.getUserName(), projectName, id);
try {
Map<String, Object> result = schedulerService.setScheduleState(loginUser, projectName, id, ReleaseState.OFFLINE);
return returnDataList(result);
}catch (Exception e){
logger.error(OFFLINE_SCHEDULE_ERROR.getMsg(),e);
return error(Status.OFFLINE_SCHEDULE_ERROR.getCode(), Status.OFFLINE_SCHEDULE_ERROR.getMsg());
}
}
/**
* query schedule list paging
*
* @param loginUser
* @param projectName
* @param processDefinitionId
* @return
*/
@GetMapping("/list-paging")
public Result querySchedule(@RequestAttribute(value = SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam Integer processDefinitionId,
@RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize) {
logger.info("login user {}, query schedule, project name: {}, process definition id: {}",
loginUser.getUserName(), projectName, processDefinitionId);
try {
Map<String, Object> result = schedulerService.querySchedule(loginUser, projectName, processDefinitionId, searchVal, pageNo, pageSize);
return returnDataListPaging(result);
}catch (Exception e){
logger.error(QUERY_SCHEDULE_LIST_PAGING_ERROR.getMsg(),e);
return error(Status.QUERY_SCHEDULE_LIST_PAGING_ERROR.getCode(), Status.QUERY_SCHEDULE_LIST_PAGING_ERROR.getMsg());
}
}
/**
* query schedule list
*
* @param loginUser
* @param projectName
* @return
*/
@PostMapping("/list")
public Result queryScheduleList(@RequestAttribute(value = SESSION_USER) User loginUser,
@PathVariable String projectName) {
try{
logger.info("login user {}, query schedule list, project name: {}",
loginUser.getUserName(), projectName);
Map<String, Object> result = schedulerService.queryScheduleList(loginUser, projectName);
return returnDataList(result);
}catch (Exception e){
logger.error(QUERY_SCHEDULE_LIST_ERROR.getMsg(),e);
return error(Status.QUERY_SCHEDULE_LIST_ERROR.getCode(), Status.QUERY_SCHEDULE_LIST_ERROR.getMsg());
}
}
}
/*
* 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.controller;
import cn.escheduler.api.service.ServerService;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.Result;
import cn.escheduler.dao.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import static cn.escheduler.api.enums.Status.LIST_MASTERS_ERROR;
import static cn.escheduler.api.enums.Status.LIST_WORKERS_ERROR;
/**
* server controller
*/
@RestController
@RequestMapping("process")
public class ServerController extends BaseController{
private static final Logger logger = LoggerFactory.getLogger(ExecutorController.class);
@Autowired
private ServerService serverService;
/**
* master list
* @param loginUser
* @return
*/
@GetMapping(value = "/master/list")
@ResponseStatus(HttpStatus.OK)
public Result listMaster(@RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
logger.info("login user: {}, query all master", loginUser.getUserName());
try{
logger.info("list master, user:{}", loginUser.getUserName());
Map<String, Object> result = serverService.queryMaster(loginUser);
return returnDataList(result);
}catch (Exception e){
logger.error(LIST_MASTERS_ERROR.getMsg(),e);
return error(LIST_MASTERS_ERROR.getCode(),
LIST_MASTERS_ERROR.getMsg());
}
}
/**
* worker list
* @param loginUser
* @return
*/
@GetMapping(value = "/worker/list")
@ResponseStatus(HttpStatus.OK)
public Result listWorker(@RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
logger.info("login user: {}, query all workers", loginUser.getUserName());
try{
Map<String, Object> result = serverService.queryWorker(loginUser);
return returnDataList(result);
}catch (Exception e){
logger.error(LIST_WORKERS_ERROR.getMsg(),e);
return error(LIST_WORKERS_ERROR.getCode(),
LIST_WORKERS_ERROR.getMsg());
}
}
}
/*
* 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.controller;
import cn.escheduler.api.service.TaskInstanceService;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.Result;
import cn.escheduler.common.enums.ExecutionStatus;
import cn.escheduler.dao.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import static cn.escheduler.api.enums.Status.QUERY_TASK_LIST_PAGING_ERROR;
/**
* task instance controller
*/
@RestController
@RequestMapping("/projects/{projectName}/task-instance")
public class TaskInstanceController extends BaseController{
private static final Logger logger = LoggerFactory.getLogger(TaskInstanceController.class);
@Autowired
TaskInstanceService taskInstanceService;
/**
* query task list paging
*
* @param loginUser
* @return
*/
@GetMapping("/list-paging")
@ResponseStatus(HttpStatus.OK)
public Result queryTaskListPaging(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable String projectName,
@RequestParam(value = "processInstanceId", required = false, defaultValue = "0") Integer processInstanceId,
@RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam(value = "taskName", required = false) String taskName,
@RequestParam(value = "stateType", required = false) ExecutionStatus stateType,
@RequestParam(value = "host", required = false) String host,
@RequestParam(value = "startDate", required = false) String startTime,
@RequestParam(value = "endDate", required = false) String endTime,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize){
try{
logger.info("query task instance list, project name:{},process instance:{}, search value:{},task name:{}, state type:{}, host:{}, start:{}, end:{}",
projectName, processInstanceId, searchVal, taskName, stateType, host, startTime, endTime);
Map<String, Object> result = taskInstanceService.queryTaskListPaging(
loginUser, projectName, processInstanceId, taskName, startTime, endTime, searchVal, stateType, host, pageNo, pageSize);
return returnDataListPaging(result);
}catch (Exception e){
logger.error(QUERY_TASK_LIST_PAGING_ERROR.getMsg(),e);
return error(QUERY_TASK_LIST_PAGING_ERROR.getCode(), QUERY_TASK_LIST_PAGING_ERROR.getMsg());
}
}
}
/*
* 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.controller;
import cn.escheduler.api.service.TaskRecordService;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.Result;
import cn.escheduler.dao.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import static cn.escheduler.api.enums.Status.QUERY_TASK_RECORD_LIST_PAGING_ERROR;
/**
* task record controller
*/
@RestController
@RequestMapping("/projects/task-record")
public class TaskRecordController extends BaseController{
private static final Logger logger = LoggerFactory.getLogger(TaskRecordController.class);
@Autowired
TaskRecordService taskRecordService;
/**
* query task record list paging
*
* @param loginUser
* @return
*/
@GetMapping("/list-paging")
@ResponseStatus(HttpStatus.OK)
public Result queryTaskRecordListPaging(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "taskName", required = false) String taskName,
@RequestParam(value = "state", required = false) String state,
@RequestParam(value = "sourceTable", required = false) String sourceTable,
@RequestParam(value = "destTable", required = false) String destTable,
@RequestParam(value = "taskDate", required = false) String taskDate,
@RequestParam(value = "startDate", required = false) String startTime,
@RequestParam(value = "endDate", required = false) String endTime,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize
){
try{
logger.info("query task record list, task name:{}, state :{}, taskDate: {}, start:{}, end:{}",
taskName, state, taskDate, startTime, endTime);
Map<String, Object> result = taskRecordService.queryTaskRecordListPaging(taskName, startTime, taskDate, sourceTable, destTable, endTime,state, pageNo, pageSize);
return returnDataListPaging(result);
}catch (Exception e){
logger.error(QUERY_TASK_RECORD_LIST_PAGING_ERROR.getMsg(),e);
return error(QUERY_TASK_RECORD_LIST_PAGING_ERROR.getCode(), QUERY_TASK_RECORD_LIST_PAGING_ERROR.getMsg());
}
}
}
/*
* 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.controller;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.service.TenantService;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.Result;
import cn.escheduler.dao.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import static cn.escheduler.api.enums.Status.*;
/**
* tenant controller
*/
@RestController
@RequestMapping("/tenant")
public class TenantController extends BaseController{
private static final Logger logger = LoggerFactory.getLogger(TenantController.class);
@Autowired
private TenantService tenantService;
/**
* create tenant
*
* @param loginUser
* @param tenantCode
* @param tenantName
* @param queueId
* @param desc
* @return
*/
@PostMapping(value = "/create")
@ResponseStatus(HttpStatus.CREATED)
public Result createTenant(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "tenantCode") String tenantCode,
@RequestParam(value = "tenantName") String tenantName,
@RequestParam(value = "queueId") int queueId,
@RequestParam(value = "desc",required = false) String desc) {
logger.info("login user {}, create tenant, tenantCode: {}, tenantName: {}, queueId: {}, desc: {}",
loginUser.getUserName(), tenantCode, tenantName, queueId,desc);
try {
Map<String, Object> result = tenantService.createTenant(loginUser,tenantCode,tenantName,queueId,desc);
return returnDataList(result);
}catch (Exception e){
logger.error(CREATE_TENANT_ERROR.getMsg(),e);
return error(CREATE_TENANT_ERROR.getCode(), CREATE_TENANT_ERROR.getMsg());
}
}
/**
* query tenant list paging
*
* @param loginUser
* @param pageNo
* @param searchVal
* @param pageSize
* @return
*/
@GetMapping(value="/list-paging")
@ResponseStatus(HttpStatus.OK)
public Result queryTenantlistPaging(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("pageNo") Integer pageNo,
@RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageSize") Integer pageSize){
logger.info("login user {}, list paging, pageNo: {}, searchVal: {}, pageSize: {}",
loginUser.getUserName(),pageNo,searchVal,pageSize);
try{
Map<String, Object> result = checkPageParams(pageNo, pageSize);
if(result.get(Constants.STATUS) != Status.SUCCESS){
return returnDataListPaging(result);
}
result = tenantService.queryTenantList(loginUser, searchVal, pageNo, pageSize);
return returnDataListPaging(result);
}catch (Exception e){
logger.error(QUERY_TENANT_LIST_PAGING_ERROR.getMsg(),e);
return error(Status.QUERY_TENANT_LIST_PAGING_ERROR.getCode(), Status.QUERY_TENANT_LIST_PAGING_ERROR.getMsg());
}
}
/**
* tenant list
*
* @param loginUser
* @return
*/
@GetMapping(value="/list")
@ResponseStatus(HttpStatus.OK)
public Result queryTenantlist(@RequestAttribute(value = Constants.SESSION_USER) User loginUser){
logger.info("login user {}, query tenant list");
try{
Map<String, Object> result = tenantService.queryTenantList(loginUser);
return returnDataList(result);
}catch (Exception e){
logger.error(QUERY_TENANT_LIST_ERROR.getMsg(),e);
return error(Status.QUERY_TENANT_LIST_ERROR.getCode(), Status.QUERY_TENANT_LIST_ERROR.getMsg());
}
}
/**
* udpate tenant
*
* @param loginUser
* @param tenantCode
* @param tenantName
* @param queueId
* @param desc
* @return
*/
@PostMapping(value = "/update")
@ResponseStatus(HttpStatus.OK)
public Result updateTenant(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id") int id,
@RequestParam(value = "tenantCode") String tenantCode,
@RequestParam(value = "tenantName") String tenantName,
@RequestParam(value = "queueId") int queueId,
@RequestParam(value = "desc",required = false) String desc) {
logger.info("login user {}, updateProcessInstance tenant, tenantCode: {}, tenantName: {}, queueId: {}, desc: {}",
loginUser.getUserName(), tenantCode, tenantName, queueId,desc);
try {
Map<String, Object> result = tenantService.updateTenant(loginUser,id,tenantCode, tenantName, queueId, desc);
return returnDataList(result);
}catch (Exception e){
logger.error(UPDATE_TENANT_ERROR.getMsg(),e);
return error(Status.UPDATE_TENANT_ERROR.getCode(),UPDATE_TENANT_ERROR.getMsg());
}
}
/**
* delete tenant by id
*
* @param loginUser
* @param id
* @return
*/
@PostMapping(value = "/delete")
@ResponseStatus(HttpStatus.OK)
public Result deleteTenantById(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id") int id) {
logger.info("login user {}, delete tenant, tenantCode: {},", loginUser.getUserName(), id);
try {
Map<String, Object> result = tenantService.deleteTenantById(loginUser,id);
return returnDataList(result);
}catch (Exception e){
logger.error(DELETE_TENANT_BY_ID_ERROR.getMsg(),e);
return error(Status.DELETE_TENANT_BY_ID_ERROR.getCode(), Status.DELETE_TENANT_BY_ID_ERROR.getMsg());
}
}
/**
* verify tenant code
*
* @param loginUser
* @param tenantCode
* @return
*/
@GetMapping(value = "/verify-tenant-code")
@ResponseStatus(HttpStatus.OK)
public Result verifyTenantCode(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value ="tenantCode") String tenantCode
) {
try{
logger.info("login user {}, verfiy tenant code: {}",
loginUser.getUserName(),tenantCode);
return tenantService.verifyTenantCode(tenantCode);
}catch (Exception e){
logger.error(VERIFY_TENANT_CODE_ERROR.getMsg(),e);
return error(Status.VERIFY_TENANT_CODE_ERROR.getCode(), Status.VERIFY_TENANT_CODE_ERROR.getMsg());
}
}
}
/*
* 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.controller;
import cn.escheduler.api.enums.Status;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import static cn.escheduler.api.enums.Status.*;
/**
* user controller
*/
@RestController
@RequestMapping("/users")
public class UsersController extends BaseController{
private static final Logger logger = LoggerFactory.getLogger(UsersController.class);
@Autowired
private UsersService usersService;
/**
* create user
*
* @param loginUser
* @param userName
* @param userPassword
* @param email
* @param tenantId
* @param phone
* @return
*/
@PostMapping(value = "/create")
@ResponseStatus(HttpStatus.CREATED)
public Result createUser(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "userName") String userName,
@RequestParam(value = "userPassword") String userPassword,
@RequestParam(value = "tenantId") int tenantId,
@RequestParam(value = "email") String email,
@RequestParam(value = "phone", required = false) String phone) {
logger.info("login user {}, create user, userName: {}, email: {}, tenantId: {}, userPassword: {}, phone: {}, proxyUsers: {}",
loginUser.getUserName(), userName, email, tenantId, Constants.PASSWORD_DEFAULT, phone);
try {
Map<String, Object> result = usersService.createUser(loginUser, userName, userPassword, email, tenantId, phone);
return returnDataList(result);
}catch (Exception e){
logger.error(CREATE_USER_ERROR.getMsg(),e);
return error(CREATE_USER_ERROR.getCode(), CREATE_USER_ERROR.getMsg());
}
}
/**
* query user list paging
*
* @param loginUser
* @param pageNo
* @param searchVal
* @param pageSize
* @return
*/
@GetMapping(value="/list-paging")
@ResponseStatus(HttpStatus.OK)
public Result queryUserList(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("pageNo") Integer pageNo,
@RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageSize") Integer pageSize){
logger.info("login user {}, list user paging, pageNo: {}, searchVal: {}, pageSize: {}",
loginUser.getUserName(),pageNo,searchVal,pageSize);
try{
Map<String, Object> result = checkPageParams(pageNo, pageSize);
if(result.get(Constants.STATUS) != Status.SUCCESS){
return returnDataListPaging(result);
}
result = usersService.queryUserList(loginUser, searchVal, pageNo, pageSize);
return returnDataListPaging(result);
}catch (Exception e){
logger.error(QUERY_USER_LIST_PAGING_ERROR.getMsg(),e);
return error(Status.QUERY_USER_LIST_PAGING_ERROR.getCode(), Status.QUERY_USER_LIST_PAGING_ERROR.getMsg());
}
}
/**
* updateProcessInstance user
*
* @param loginUser
* @param id
* @param userName
* @param userPassword
* @param email
* @param tenantId
* @param phone
* @return
*/
@PostMapping(value = "/update")
@ResponseStatus(HttpStatus.OK)
public Result updateUser(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id") int id,
@RequestParam(value = "userName") String userName,
@RequestParam(value = "userPassword") String userPassword,
@RequestParam(value = "email") String email,
@RequestParam(value = "tenantId") int tenantId,
@RequestParam(value = "phone", required = false) String phone) {
logger.info("login user {}, updateProcessInstance user, userName: {}, email: {}, tenantId: {}, userPassword: {}, phone: {}, proxyUsers: {}",
loginUser.getUserName(), userName, email, tenantId, Constants.PASSWORD_DEFAULT, phone);
try {
Map<String, Object> result = usersService.updateUser(id,userName,userPassword,email,tenantId,phone);
return returnDataList(result);
}catch (Exception e){
logger.error(UPDATE_USER_ERROR.getMsg(),e);
return error(Status.UPDATE_USER_ERROR.getCode(), Status.UPDATE_USER_ERROR.getMsg());
}
}
/**
* delete user by id
* @param loginUser
* @param id
* @return
*/
@PostMapping(value = "/delete")
@ResponseStatus(HttpStatus.OK)
public Result delUserById(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id") int id) {
logger.info("login user {}, delete user, userId: {},", loginUser.getUserName(), id);
try {
Map<String, Object> result = usersService.deleteUserById(loginUser, id);
return returnDataList(result);
}catch (Exception e){
logger.error(DELETE_USER_BY_ID_ERROR.getMsg(),e);
return error(Status.DELETE_USER_BY_ID_ERROR.getCode(), Status.DELETE_USER_BY_ID_ERROR.getMsg());
}
}
/**
* grant project
*
* @param loginUser
* @param userId
* @return
*/
@PostMapping(value = "/grant-project")
@ResponseStatus(HttpStatus.OK)
public Result grantProject(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "userId") int userId,
@RequestParam(value = "projectIds") String projectIds) {
logger.info("login user {}, grant project, userId: {},projectIds : {}", loginUser.getUserName(), userId,projectIds);
try {
Map<String, Object> result = usersService.grantProject(loginUser, userId, projectIds);
return returnDataList(result);
}catch (Exception e){
logger.error(GRANT_PROJECT_ERROR.getMsg(),e);
return error(Status.GRANT_PROJECT_ERROR.getCode(), Status.GRANT_PROJECT_ERROR.getMsg());
}
}
/**
* grant resource
*
* @param loginUser
* @param userId
* @return
*/
@PostMapping(value = "/grant-file")
@ResponseStatus(HttpStatus.OK)
public Result grantResource(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "userId") int userId,
@RequestParam(value = "resourceIds") String resourceIds) {
logger.info("login user {}, grant project, userId: {},resourceIds : {}", loginUser.getUserName(), userId,resourceIds);
try {
Map<String, Object> result = usersService.grantResources(loginUser, userId, resourceIds);
return returnDataList(result);
}catch (Exception e){
logger.error(GRANT_RESOURCE_ERROR.getMsg(),e);
return error(Status.GRANT_RESOURCE_ERROR.getCode(), Status.GRANT_RESOURCE_ERROR.getMsg());
}
}
/**
* grant udf function
*
* @param loginUser
* @param userId
* @return
*/
@PostMapping(value = "/grant-udf-func")
@ResponseStatus(HttpStatus.OK)
public Result grantUDFFunc(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "userId") int userId,
@RequestParam(value = "udfIds") String udfIds) {
logger.info("login user {}, grant project, userId: {},resourceIds : {}", loginUser.getUserName(), userId,udfIds);
try {
Map<String, Object> result = usersService.grantUDFFunction(loginUser, userId, udfIds);
return returnDataList(result);
}catch (Exception e){
logger.error(GRANT_UDF_FUNCTION_ERROR.getMsg(),e);
return error(Status.GRANT_UDF_FUNCTION_ERROR.getCode(), Status.GRANT_UDF_FUNCTION_ERROR.getMsg());
}
}
/**
* grant datasource
*
* @param loginUser
* @param userId
* @return
*/
@PostMapping(value = "/grant-datasource")
@ResponseStatus(HttpStatus.OK)
public Result grantDataSource(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "userId") int userId,
@RequestParam(value = "datasourceIds") String datasourceIds) {
logger.info("login user {}, grant project, userId: {},projectIds : {}", loginUser.getUserName(),userId,datasourceIds);
try {
Map<String, Object> result = usersService.grantDataSource(loginUser, userId, datasourceIds);
return returnDataList(result);
}catch (Exception e){
logger.error(GRANT_DATASOURCE_ERROR.getMsg(),e);
return error(Status.GRANT_DATASOURCE_ERROR.getCode(), Status.GRANT_DATASOURCE_ERROR.getMsg());
}
}
/**
* get user info
*
* @param loginUser
* @return
*/
@GetMapping(value="/get-user-info")
@ResponseStatus(HttpStatus.OK)
public Result getUserInfo(@RequestAttribute(value = Constants.SESSION_USER) User loginUser){
logger.info("login user {},get user info : {}", loginUser.getUserName());
try{
Map<String, Object> result = usersService.getUserInfo(loginUser);
return returnDataList(result);
}catch (Exception e){
logger.error(GET_USER_INFO_ERROR.getMsg(),e);
return error(Status.GET_USER_INFO_ERROR.getCode(), Status.GET_USER_INFO_ERROR.getMsg());
}
}
/**
* user list no paging
*
* @param loginUser
* @return
*/
@GetMapping(value="/list")
@ResponseStatus(HttpStatus.OK)
public Result listUser(@RequestAttribute(value = Constants.SESSION_USER) User loginUser){
logger.info("login user {}, user list");
try{
Map<String, Object> result = usersService.queryUserList(loginUser);
return returnDataList(result);
}catch (Exception e){
logger.error(USER_LIST_ERROR.getMsg(),e);
return error(Status.USER_LIST_ERROR.getCode(), Status.USER_LIST_ERROR.getMsg());
}
}
/**
* verify username
*
* @param loginUser
* @param userName
* @return
*/
@GetMapping(value = "/verify-user-name")
@ResponseStatus(HttpStatus.OK)
public Result verifyUserName(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value ="userName") String userName
) {
try{
logger.info("login user {}, verfiy user name: {}",
loginUser.getUserName(),userName);
return usersService.verifyUserName(userName);
}catch (Exception e){
logger.error(VERIFY_USERNAME_ERROR.getMsg(),e);
return error(Status.VERIFY_USERNAME_ERROR.getCode(), Status.VERIFY_USERNAME_ERROR.getMsg());
}
}
/**
* unauthorized user
*
* @param loginUser
* @param alertgroupId
* @return
*/
@GetMapping(value = "/unauth-user")
@ResponseStatus(HttpStatus.OK)
public Result unauthorizedUser(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("alertgroupId") Integer alertgroupId) {
try{
logger.info("unauthorized user, login user:{}, alert group id:{}",
loginUser.getUserName(), alertgroupId);
Map<String, Object> result = usersService.unauthorizedUser(loginUser, alertgroupId);
return returnDataList(result);
}catch (Exception e){
logger.error(UNAUTHORIZED_USER_ERROR.getMsg(),e);
return error(Status.UNAUTHORIZED_USER_ERROR.getCode(), Status.UNAUTHORIZED_USER_ERROR.getMsg());
}
}
/**
* authorized user
*
* @param loginUser
* @param alertgroupId
* @return
*/
@GetMapping(value = "/authed-user")
@ResponseStatus(HttpStatus.OK)
public Result authorizedUser(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("alertgroupId") Integer alertgroupId) {
try{
logger.info("authorized user , login user:{}, alert group id:{}",
loginUser.getUserName(), alertgroupId);
Map<String, Object> result = usersService.authorizedUser(loginUser, alertgroupId);
return returnDataList(result);
}catch (Exception e){
logger.error(AUTHORIZED_USER_ERROR.getMsg(),e);
return error(Status.AUTHORIZED_USER_ERROR.getCode(), Status.AUTHORIZED_USER_ERROR.getMsg());
}
}
}
/*
* 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.dto;
import cn.escheduler.dao.model.DefinitionGroupByUser;
import java.util.List;
/**
*
*/
public class DefineUserDto {
private int count;
private List<DefinitionGroupByUser> userList;
public DefineUserDto(List<DefinitionGroupByUser> defineGroupByUsers) {
for(DefinitionGroupByUser define : defineGroupByUsers){
count += define.getCount();
}
this.userList = defineGroupByUsers;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public List<DefinitionGroupByUser> getUserList() {
return userList;
}
public void setUserList(List<DefinitionGroupByUser> userList) {
this.userList = userList;
}
}
/*
* 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.dto;
import java.util.Date;
/**
* schedule parameters
* 调度参数
*/
public class ScheduleParam {
private Date startTime;
private Date endTime;
private String crontab;
public ScheduleParam() {
}
public ScheduleParam(Date startTime, Date endTime, String crontab) {
this.startTime = startTime;
this.endTime = endTime;
this.crontab = crontab;
}
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public Date getEndTime() {
return endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
public String getCrontab() {
return crontab;
}
public void setCrontab(String crontab) {
this.crontab = crontab;
}
@Override
public String toString() {
return "ScheduleParam{" +
"startTime=" + startTime +
", endTime=" + endTime +
", crontab='" + crontab + '\'' +
'}';
}
}
/*
* 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.dto;
import cn.escheduler.common.enums.ExecutionStatus;
import cn.escheduler.dao.model.ExecuteStatusCount;
import java.util.ArrayList;
import java.util.List;
/**
* task count dto
*/
public class TaskCountDto {
/**
* total count
*/
private int totalCount;
/**
*
*/
private List<TaskStateCount> taskCountDtos;
public TaskCountDto(List<ExecuteStatusCount> taskInstanceStateCounts) {
countTaskDtos(taskInstanceStateCounts);
}
private void countTaskDtos(List<ExecuteStatusCount> taskInstanceStateCounts){
int submitted_success = 0;
int running_exeution = 0;
int ready_pause = 0;
int pause = 0;
int ready_stop = 0;
int stop = 0;
int failure = 0;
int success = 0;
int need_fault_tolerance = 0;
int kill = 0;
int waitting_thread = 0;
int waitting_depend = 0;
for(ExecuteStatusCount taskInstanceStateCount : taskInstanceStateCounts){
ExecutionStatus status = taskInstanceStateCount.getExecutionStatus();
totalCount += taskInstanceStateCount.getCount();
switch (status){
case SUBMITTED_SUCCESS:
submitted_success += taskInstanceStateCount.getCount();
break;
case RUNNING_EXEUTION:
running_exeution += taskInstanceStateCount.getCount();
break;
case READY_PAUSE:
ready_pause += taskInstanceStateCount.getCount();
break;
case PAUSE:
pause += taskInstanceStateCount.getCount();
break;
case READY_STOP:
ready_stop += taskInstanceStateCount.getCount();
break;
case STOP:
stop += taskInstanceStateCount.getCount();
break;
case FAILURE:
failure += taskInstanceStateCount.getCount();
break;
case SUCCESS:
success += taskInstanceStateCount.getCount();
break;
case NEED_FAULT_TOLERANCE:
failure += taskInstanceStateCount.getCount();
break;
case KILL:
kill += taskInstanceStateCount.getCount();
break;
case WAITTING_THREAD:
kill += taskInstanceStateCount.getCount();
break;
case WAITTING_DEPEND:
kill += taskInstanceStateCount.getCount();
break;
default:
break;
}
}
this.taskCountDtos = new ArrayList<>();
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.SUBMITTED_SUCCESS, submitted_success));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.RUNNING_EXEUTION, running_exeution));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.READY_PAUSE, ready_pause));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.PAUSE, pause));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.READY_STOP, ready_stop));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.STOP, stop));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.FAILURE, failure));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.SUCCESS, success));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.NEED_FAULT_TOLERANCE, need_fault_tolerance));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.KILL, kill));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.WAITTING_THREAD, waitting_thread));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.WAITTING_DEPEND, waitting_depend));
}
public List<TaskStateCount> getTaskCountDtos(){
return taskCountDtos;
}
public void setTaskCountDtos(List<TaskStateCount> taskCountDtos) {
this.taskCountDtos = taskCountDtos;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
}
/*
* 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.dto;
import cn.escheduler.common.enums.ExecutionStatus;
/**
* task state count
*/
public class TaskStateCount {
private int count;
private ExecutionStatus taskStateType;
public TaskStateCount(ExecutionStatus taskStateType, int count) {
this.taskStateType = taskStateType;
this.count = count;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public ExecutionStatus getTaskStateType() {
return taskStateType;
}
public void setTaskStateType(ExecutionStatus taskStateType) {
this.taskStateType = taskStateType;
}
}
/*
* 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.dto.gantt;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* gantt DTO
* 甘特图 DTO
*/
public class GanttDto {
/**
* height
* 高度
*/
private int height;
/**
* tasks list
* 任务集合
*/
private List<Task> tasks = new ArrayList<>();
/**
* task name list
* 任务名称
*/
private List<String> taskNames;
/**
* task status map
* 任务状态
*/
private Map<String,String> taskStatus;
public GanttDto(){
this.taskStatus = new HashMap<>();
taskStatus.put("success","success");
}
public GanttDto(int height, List<Task> tasks, List<String> taskNames){
this();
this.height = height;
this.tasks = tasks;
this.taskNames = taskNames;;
}
public GanttDto(int height, List<Task> tasks, List<String> taskNames, Map<String, String> taskStatus) {
this.height = height;
this.tasks = tasks;
this.taskNames = taskNames;
this.taskStatus = taskStatus;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public List<Task> getTasks() {
return tasks;
}
public void setTasks(List<Task> tasks) {
this.tasks = tasks;
}
public List<String> getTaskNames() {
return taskNames;
}
public void setTaskNames(List<String> taskNames) {
this.taskNames = taskNames;
}
public Map<String, String> getTaskStatus() {
return taskStatus;
}
public void setTaskStatus(Map<String, String> taskStatus) {
this.taskStatus = taskStatus;
}
}
/*
* 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.dto.gantt;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* Task
* 任务
*/
public class Task {
/**
* task name
* 任务名称
*/
private String taskName;
/**
* task start date
* 任务开始时间
*/
private List<Long> startDate = new ArrayList<>();
/**
* task end date
* 任务结束时间
*/
private List<Long> endDate = new ArrayList<>();
/**
* task execution date
* 任务执行时间
*/
private Date executionDate;
/**
* task iso start
* 任务开始时间
*/
private Date isoStart;
/**
* task iso end
* 任务结束时间
*/
private Date isoEnd;
/**
* task status
* 执行状态
*/
private String status;
/**
* task duration
* 运行时长
*/
private String duration;
public String getTaskName() {
return taskName;
}
public void setTaskName(String taskName) {
this.taskName = taskName;
}
public List<Long> getStartDate() {
return startDate;
}
public void setStartDate(List<Long> startDate) {
this.startDate = startDate;
}
public List<Long> getEndDate() {
return endDate;
}
public void setEndDate(List<Long> endDate) {
this.endDate = endDate;
}
public Date getExecutionDate() {
return executionDate;
}
public void setExecutionDate(Date executionDate) {
this.executionDate = executionDate;
}
public Date getIsoStart() {
return isoStart;
}
public void setIsoStart(Date isoStart) {
this.isoStart = isoStart;
}
public Date getIsoEnd() {
return isoEnd;
}
public void setIsoEnd(Date isoEnd) {
this.isoEnd = isoEnd;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getDuration() {
return duration;
}
public void setDuration(String duration) {
this.duration = duration;
}
}
/*
* 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.dto.treeview;
import java.util.Date;
/**
* Instance
*/
public class Instance {
private int id;
/**
* node name
* 节点名称
*/
private String name;
/**
* node type
* 节点类型
*/
private String type;
/**
* node status
* 状态
*/
private String state;
/**
* node start time
* 开始时间
*/
private Date startTime;
/**
* node end time
* 结束时间
*/
private Date endTime;
/**
* node running on which host
* 运行机器
*/
private String host;
/**
* node duration
* 运行时长
*/
private String duration;
private int subflowId;
public Instance(){}
public Instance(int id,String name, String type){
this.id = id;
this.name = name;
this.type = type;
}
public Instance(int id,String name, String type,String state,Date startTime, Date endTime, String host, String duration,int subflowId) {
this.id = id;
this.name = name;
this.type = type;
this.state = state;
this.startTime = startTime;
this.endTime = endTime;
this.host = host;
this.duration = duration;
this.subflowId = subflowId;
}
public Instance(int id,String name, String type,String state,Date startTime, Date endTime, String host, String duration) {
this(id, name, type, state, startTime, endTime,host,duration,0);
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public Date getEndTime() {
return endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public String getDuration() {
return duration;
}
public void setDuration(String duration) {
this.duration = duration;
}
public int getSubflowId() {
return subflowId;
}
public void setSubflowId(int subflowId) {
this.subflowId = subflowId;
}
}
此差异已折叠。
# server port
server.port=12345
# session config
server.session.timeout=7200
server.context-path=/escheduler/
# file size limit for upload
spring.http.multipart.max-file-size=1024MB
spring.http.multipart.max-request-size=1024MB
#post content
server.max-http-post-size=5000000
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册