Browse Source

Merge pull request #1 from apache/dev

merge
pull/2/head
Tboy 5 years ago committed by GitHub
parent
commit
ac426f9025
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/FuncUtils.java
  2. 60
      dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/utils/FuncUtilsTest.java
  3. 112
      dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/utils/JSONUtilsTest.java
  4. 58
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/QueueService.java
  5. 14
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/UserMapper.java
  6. 10
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserMapper.xml
  7. 1
      dolphinscheduler-ui/src/view/home/index.html
  8. 1
      dolphinscheduler-ui/src/view/login/index.html
  9. 7
      pom.xml

7
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/FuncUtils.java

@ -16,9 +16,16 @@
*/
package org.apache.dolphinscheduler.alert.utils;
import org.apache.commons.lang.StringUtils;
public class FuncUtils {
static public String mkString(Iterable<String> list, String split) {
if (null == list || StringUtils.isEmpty(split)){
return null;
}
StringBuilder sb = new StringBuilder();
boolean first = true;
for (String item : list) {

60
dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/utils/FuncUtilsTest.java

@ -0,0 +1,60 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.alert.utils;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class FuncUtilsTest {
private static final Logger logger = LoggerFactory.getLogger(FuncUtilsTest.class);
/**
* Test mkString
*/
@Test
public void testMKString() {
//Define users list
Iterable<String> users = Arrays.asList("user1", "user2", "user3");
//Define split
String split = "|";
//Invoke mkString with correctParams
String result = FuncUtils.mkString(users, split);
logger.info(result);
//Expected result string
assertEquals(result, "user1|user2|user3");
//Null list expected return null
result = FuncUtils.mkString(null, split);
assertNull(result);
//Null split expected return null
result = FuncUtils.mkString(users, null);
assertNull(result);
}
}

112
dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/utils/JSONUtilsTest.java

@ -0,0 +1,112 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.alert.utils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class JSONUtilsTest {
private static final Logger logger = LoggerFactory.getLogger(JSONUtilsTest.class);
public List<LinkedHashMap<String, Object>> list = new ArrayList<>();
public String expected = null;
@Before
public void setUp() throws Exception {
//Define expected json string
expected = "[{\"mysql service name\":\"mysql200\",\"mysql address\":\"192.168.xx.xx\",\"port\":\"3306\",\"no index of number\":\"80\",\"database client connections\":\"190\"}]";
//Initial map
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
map.put("mysql service name","mysql200");
map.put("mysql address","192.168.xx.xx");
map.put("port","3306");
map.put("no index of number","80");
map.put("database client connections","190");
//Add map into list
list.add(map);
}
/**
* Test toJsonString
*/
@Test
public void testToJsonString() {
//Invoke toJsonString
String result = JSONUtils.toJsonString(list);
logger.info(result);
//Equal result with expected string
assertEquals(result,expected);
//If param is null, then return null string
result = JSONUtils.toJsonString(null);
logger.info(result);
assertEquals(result,"null");
}
/**
* Test toList
*/
@Test
public void testToList() {
//Invoke toList
List<LinkedHashMap> result = JSONUtils.toList(expected ,LinkedHashMap.class);
//Equal list size=1
assertEquals(result.size(),1);
//Transform entity to LinkedHashMap<String, Object>
LinkedHashMap<String, Object> entity = result.get(0);
//Equal expected values
assertEquals(entity.get("mysql service name"),"mysql200");
assertEquals(entity.get("mysql address"),"192.168.xx.xx");
assertEquals(entity.get("port"),"3306");
assertEquals(entity.get("no index of number"),"80");
assertEquals(entity.get("database client connections"),"190");
//If param is null, then return null
result = JSONUtils.toList(null ,LinkedHashMap.class);
assertNull(result);
//If param is incorrect, then return null and log error message
result = JSONUtils.toList("}{" ,LinkedHashMap.class);
assertNull(result);
}
}

58
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/QueueService.java

@ -26,6 +26,7 @@ import org.apache.dolphinscheduler.dao.mapper.QueueMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang.StringUtils;
import org.apache.dolphinscheduler.dao.mapper.UserMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -47,6 +48,9 @@ public class QueueService extends BaseService {
@Autowired
private QueueMapper queueMapper;
@Autowired
private UserMapper userMapper;
/**
* query queue list
*
@ -70,9 +74,9 @@ public class QueueService extends BaseService {
* query queue list paging
*
* @param loginUser login user
* @param pageNo page number
* @param pageNo page number
* @param searchVal search value
* @param pageSize page size
* @param pageSize page size
* @return queue list
*/
public Map<String, Object> queryList(User loginUser, String searchVal, Integer pageNo, Integer pageSize) {
@ -86,7 +90,7 @@ public class QueueService extends BaseService {
IPage<Queue> queueList = queueMapper.queryQueuePaging(page, searchVal);
Integer count = (int)queueList.getTotal();
Integer count = (int) queueList.getTotal();
PageInfo<Queue> pageInfo = new PageInfo<>(pageNo, pageSize);
pageInfo.setTotalCount(count);
pageInfo.setLists(queueList.getRecords());
@ -100,7 +104,7 @@ public class QueueService extends BaseService {
* create queue
*
* @param loginUser login user
* @param queue queue
* @param queue queue
* @param queueName queue name
* @return create result
*/
@ -110,12 +114,12 @@ public class QueueService extends BaseService {
return result;
}
if(StringUtils.isEmpty(queue)){
if (StringUtils.isEmpty(queue)) {
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, queue);
return result;
}
if(StringUtils.isEmpty(queueName)){
if (StringUtils.isEmpty(queueName)) {
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, queueName);
return result;
}
@ -148,8 +152,8 @@ public class QueueService extends BaseService {
* update queue
*
* @param loginUser login user
* @param queue queue
* @param id queue id
* @param queue queue
* @param id queue id
* @param queueName queue name
* @return update result code
*/
@ -173,7 +177,7 @@ public class QueueService extends BaseService {
// check queue name is exist
if (!queueName.equals(queueObj.getQueueName())) {
if(checkQueueNameExist(queueName)){
if (checkQueueNameExist(queueName)) {
putMsg(result, Status.QUEUE_NAME_EXIST, queueName);
return result;
}
@ -181,12 +185,19 @@ public class QueueService extends BaseService {
// check queue value is exist
if (!queue.equals(queueObj.getQueue())) {
if(checkQueueExist(queue)){
if (checkQueueExist(queue)) {
putMsg(result, Status.QUEUE_VALUE_EXIST, queue);
return result;
}
}
// check old queue using by any user
if (checkIfQueueIsInUsing(queueObj.getQueueName(), queueName)) {
//update user related old queue
Integer relatedUserNums = userMapper.updateUserQueue(queueObj.getQueueName(), queueName);
logger.info("old queue have related {} user, exec update user success.", relatedUserNums);
}
// update queue
Date now = new Date();
queueObj.setQueue(queue);
@ -194,6 +205,7 @@ public class QueueService extends BaseService {
queueObj.setUpdateTime(now);
queueMapper.updateById(queueObj);
putMsg(result, Status.SUCCESS);
return result;
@ -202,12 +214,12 @@ public class QueueService extends BaseService {
/**
* verify queue and queueName
*
* @param queue queue
* @param queue queue
* @param queueName queue name
* @return true if the queue name not exists, otherwise return false
*/
public Result verifyQueue(String queue, String queueName) {
Result result=new Result();
Result result = new Result();
if (StringUtils.isEmpty(queue)) {
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, queue);
@ -220,13 +232,13 @@ public class QueueService extends BaseService {
}
if(checkQueueNameExist(queueName)){
if (checkQueueNameExist(queueName)) {
logger.error("queue name {} has exist, can't create again.", queueName);
putMsg(result, Status.QUEUE_NAME_EXIST, queueName);
return result;
}
if(checkQueueExist(queue)){
if (checkQueueExist(queue)) {
logger.error("queue value {} has exist, can't create again.", queue);
putMsg(result, Status.QUEUE_VALUE_EXIST, queue);
return result;
@ -240,21 +252,35 @@ public class QueueService extends BaseService {
* check queue exist
* if exists return truenot exists return false
* check queue exist
*
* @param queue queue
* @return true if the queue not exists, otherwise return false
*/
private boolean checkQueueExist(String queue) {
return queueMapper.queryAllQueueList(queue, null).size()>0 ? true : false;
return queueMapper.queryAllQueueList(queue, null).size() > 0;
}
/**
* check queue name exist
* if exists return truenot exists return false
*
* @param queueName queue name
* @return true if the queue name not exists, otherwise return false
*/
private boolean checkQueueNameExist(String queueName) {
return queueMapper.queryAllQueueList(null ,queueName).size() > 0 ? true : false;
return queueMapper.queryAllQueueList(null, queueName).size() > 0;
}
/**
* check old queue name using by any user
* if need to update user
*
* @param oldQueue old queue name
* @param newQueue new queue name
* @return true if need to update user
*/
private boolean checkIfQueueIsInUsing (String oldQueue, String newQueue) {
return !oldQueue.equals(newQueue) && userMapper.queryUserListByQueue(oldQueue).size() > 0;
}
}

14
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/UserMapper.java

@ -95,4 +95,18 @@ public interface UserMapper extends BaseMapper<User> {
*/
User queryUserByToken(@Param("token") String token);
/**
* query user by queue name
* @param queueName queue name
* @return user list
*/
List<User> queryUserListByQueue(@Param("queueName") String queueName);
/**
* update user with old queue
* @param oldQueue old queue name
* @param newQueue new queue name
* @return update rows
*/
Integer updateUserQueue(@Param("oldQueue") String oldQueue, @Param("newQueue") String newQueue);
}

10
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserMapper.xml

@ -69,4 +69,14 @@
from t_ds_user u ,t_ds_access_token t
where u.id = t.user_id and token=#{token} and t.expire_time > NOW()
</select>
<select id="queryUserListByQueue" resultType="org.apache.dolphinscheduler.dao.entity.User">
select *
from t_ds_user
where queue = #{queueName}
</select>
<update id="updateUserQueue" parameterType="java.lang.String">
update t_ds_user
set queue = #{newQueue}
where queue = #{oldQueue}
</update>
</mapper>

1
dolphinscheduler-ui/src/view/home/index.html

@ -19,6 +19,7 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta http-equiv="Cache-Control" content="no-siteapp" />
<meta name="apple-mobile-web-app-capable" content="yes">

1
dolphinscheduler-ui/src/view/login/index.html

@ -19,6 +19,7 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta http-equiv="Cache-Control" content="no-siteapp" />
<meta name="apple-mobile-web-app-capable" content="yes">

7
pom.xml

@ -613,14 +613,15 @@
<configuration>
<includes>
<include>**/common/utils/*.java</include>
<include>**/api/utils/CheckUtilsTest.java</include>
<include>**/api/utils/FileUtilsTest.java</include>
<include>**/common/graph/*.java</include>
<include>**/common/queue/*.java</include>
<include>**/api/utils/CheckUtilsTest.java</include>
<include>**/api/utils/FileUtilsTest.java</include>
<include>**/alert/utils/ExcelUtilsTest.java</include>
<include>**/alert/utils/ExcelUtilsTest.java</include>
<include>**/alert/utils/FuncUtilsTest.java</include>
<include>**/alert/utils/JSONUtilsTest.java</include>
</includes>
<!-- <skip>true</skip> -->
</configuration>

Loading…
Cancel
Save