REM:
1. 增加服务启动,停止脚本
2. 增加登录认证日志
3. 修改由于token超时不能注销的问题
4. 修正单测测试错误
5. 修改.gitignore配置
This commit is contained in:
HuangXin 2020-05-12 17:57:59 +08:00
parent 5ab1ae2a39
commit ee5e653ac6
8 changed files with 69 additions and 25 deletions

1
.gitignore vendored
View File

@ -116,3 +116,4 @@ buildNumber.properties
basedir/ basedir/
/.idea/ /.idea/
/phoenix_ddos_handle.iml /phoenix_ddos_handle.iml
/src/main/resources/git.properties

3
bin/log_clean.sh Normal file
View File

@ -0,0 +1,3 @@
# 把下面语句编辑到crontab里定时清理日志每天凌晨1点清理日志保留7天日志
0 1 * * * find /apprun/phoenix_ddos_handle/logs -mtime +7 -name "*.log.*" -exec rm -rf {} \;

26
bin/processor_check.sh Normal file
View File

@ -0,0 +1,26 @@
# crontab里加上进程自动拉起任务做个简单的监控
# */1 * * * * source /etc/profile;sh /apprun/${YOUR_APP_NAME}/bin/processor_check.sh
# processor_check.sh脚本内容如下
#!/bin/bash
APP_NAME=phoenix_ddos_handle.jar
WORK_PATH=$(cd `dirname $0`; pwd)
pids=`ps -ef | grep $APP_NAME | grep -v grep | wc -l`
if [ "$pids" -le 0 ]
then
echo "start $APP_NAME processor ......"
cd $WORK_PATH
cd ..
nohup sh bin/start.sh >/dev/null 2>&1 &
sleep 5
pids=`ps -ef | grep $APP_NAME | grep -v grep | wc -l`
if [ "$pids" -gt 0 ]
then
echo "$APP_NAME processor started"
else
echo "Failed to start $APP_NAME processor"
fi
else
echo "$APP_NAME processor is running ......"
fi

8
bin/start.sh Normal file
View File

@ -0,0 +1,8 @@
#!/bin/bash
JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=n "
JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false "
JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom -server -Xms512M -Xmx512M -Xss256K -XX:MetaspaceSize=16M -XX:MaxMetaspaceSize=128M -XX:MaxDirectMemorySize=1g -XX:SurvivorRatio=8 -XX:+UseG1GC -XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/heapdump.hprof"
WORK_PATH=$(cd `dirname $0`; pwd)
cd $WORK_PATH
cd ..
$JAVA_HOME/bin/java $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS $JAVA_OPTS -jar phoenix_ddos_handle.jar

15
bin/stop.sh Normal file
View File

@ -0,0 +1,15 @@
#!/bin/bash
APP_NAME=phoenix_ddos_handle.jar
pids=`ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}'`
for pid in $pids
do
echo stop $APP_NAME java process: $pid
kill -9 $pid
done
nr_pids=`ps -ef | grep $APP_NAME | grep -v grep | wc -l`
while [ $nr_pids -gt 0 ]
do
nr_pids=`ps -ef | grep $APP_NAME | grep -v grep | wc -l`
done

View File

@ -127,6 +127,7 @@ public class UserAccountCacheManagerImpl implements UserAccountCacheManager {
// 用户不存在 // 用户不存在
if (!findRet.isPresent()) { if (!findRet.isPresent()) {
log.error("User {} not exists", username);
return ErrorCode.ERR_LOGOUT; return ErrorCode.ERR_LOGOUT;
} }
@ -134,17 +135,21 @@ public class UserAccountCacheManagerImpl implements UserAccountCacheManager {
// 如果token为空说明用户没有登录 // 如果token为空说明用户没有登录
if (uc.getToken().length() == 0) { if (uc.getToken().length() == 0) {
log.error("User {} token is empty", username);
return ErrorCode.ERR_LOGOUT; return ErrorCode.ERR_LOGOUT;
} }
// 判断用户访问时间间隔是否超时 // 判断用户访问时间间隔是否超时
if ((System.currentTimeMillis() - uc.getLastAccess()) if ((System.currentTimeMillis() - uc.getLastAccess())
>= ConstValue.GlobalConfigure.TOKEN_TIMEOUT_MS) { >= ConstValue.GlobalConfigure.TOKEN_TIMEOUT_MS) {
log.error("User {} token is timeout: current {}, last access {}, timeout setting {}",
username, System.currentTimeMillis(), uc.getLastAccess(), ConstValue.GlobalConfigure.TOKEN_TIMEOUT_MS);
return ErrorCode.ERR_TOKENTIMEOUT; return ErrorCode.ERR_TOKENTIMEOUT;
} }
// 判断token是否正确 // 判断token是否正确
if (!uc.getToken().equals(token)) { if (!uc.getToken().equals(token)) {
log.error("User {} token {} is error", username, token);
return ErrorCode.ERR_TOKENNOTFOUND; return ErrorCode.ERR_TOKENNOTFOUND;
} }

View File

@ -124,9 +124,7 @@ public class UserAccountServiceImpl implements UserAccountService {
// 注销 // 注销
ErrorCode err = userAccountCacheManager.verifyUserLogin(username, token); ErrorCode err = userAccountCacheManager.verifyUserLogin(username, token);
if (err == ErrorCode.ERR_OK) {
userAccountCacheManager.cleanUserToken(username); userAccountCacheManager.cleanUserToken(username);
}
return err; return err;
} }

View File

@ -3,6 +3,7 @@ package com.dispose.controller;
import com.dispose.Global.InitTestEnvironment; import com.dispose.Global.InitTestEnvironment;
import com.dispose.common.ConstValue; import com.dispose.common.ConstValue;
import com.dispose.common.DeviceCapacity; import com.dispose.common.DeviceCapacity;
import com.dispose.common.ErrorCode;
import com.dispose.common.IPAddrType; import com.dispose.common.IPAddrType;
import com.dispose.manager.TaskCacheManager; import com.dispose.manager.TaskCacheManager;
import com.dispose.mapper.DisposeDeviceMapper; import com.dispose.mapper.DisposeDeviceMapper;
@ -38,6 +39,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
@ -335,7 +337,6 @@ public class TaskControllerTest extends InitTestEnvironment {
.getResponse() .getResponse()
.getContentAsString(); .getContentAsString();
String regex = "\\A(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}\\z";
String msgContent = verifyRep(taskStopByIp, reqTimeStamp); String msgContent = verifyRep(taskStopByIp, reqTimeStamp);
System.out.print("msgContent=" + msgContent); System.out.print("msgContent=" + msgContent);
@ -345,29 +346,16 @@ public class TaskControllerTest extends InitTestEnvironment {
List<TaskInfoData> taskInfoList = taskStopByIpRsp.getItems(); List<TaskInfoData> taskInfoList = taskStopByIpRsp.getItems();
for (TaskInfoData task : taskInfoList for (TaskInfoData task : taskInfoList
) { ) {
if (task.getStatus() == ErrorCode.ERR_OK.getCode()) {
Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
Assert.assertNotNull(task.getId()); Assert.assertNotNull(task.getId());
Assert.assertNotNull(task.getTaskId()); Assert.assertNotNull(task.getTaskId());
Assert.assertNotNull(task.getStatus()); Assert.assertNotNull(task.getStatus());
Assert.assertNotNull(task.getMessage()); Assert.assertNotNull(task.getMessage());
if (task.getStatus() == 0) {
Assert.assertEquals(String.valueOf(task.getStatus()), "0");
Assert.assertEquals(task.getMessage(), "成功");
} else { } else {
Assert.assertNotEquals(String.valueOf(task.getStatus()), "0"); Assert.assertNotEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertNotEquals(task.getMessage(), "成功");
}
if (task.getType() != null) {
Assert.assertNotEquals(String.valueOf(task.getType()), -1);
}
if (task.getDisposeIp() != null) {
Assert.assertTrue(task.getDisposeIp().matches(regex));
}
if (task.getDisposeTime() != null) {
Assert.assertNotEquals(String.valueOf(task.getDisposeTime()), -1);
} }
} }
} }