OCT
REM: 1. 增加服务启动,停止脚本 2. 增加登录认证日志 3. 修改由于token超时不能注销的问题 4. 修正单测测试错误 5. 修改.gitignore配置
This commit is contained in:
parent
5ab1ae2a39
commit
ee5e653ac6
|
@ -116,3 +116,4 @@ buildNumber.properties
|
|||
basedir/
|
||||
/.idea/
|
||||
/phoenix_ddos_handle.iml
|
||||
/src/main/resources/git.properties
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
# 把下面语句编辑到crontab里,定时清理日志,每天凌晨1点清理日志,保留7天日志
|
||||
|
||||
0 1 * * * find /apprun/phoenix_ddos_handle/logs -mtime +7 -name "*.log.*" -exec rm -rf {} \;
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -127,6 +127,7 @@ public class UserAccountCacheManagerImpl implements UserAccountCacheManager {
|
|||
|
||||
// 用户不存在
|
||||
if (!findRet.isPresent()) {
|
||||
log.error("User {} not exists", username);
|
||||
return ErrorCode.ERR_LOGOUT;
|
||||
}
|
||||
|
||||
|
@ -134,17 +135,21 @@ public class UserAccountCacheManagerImpl implements UserAccountCacheManager {
|
|||
|
||||
// 如果token为空说明用户没有登录
|
||||
if (uc.getToken().length() == 0) {
|
||||
log.error("User {} token is empty", username);
|
||||
return ErrorCode.ERR_LOGOUT;
|
||||
}
|
||||
|
||||
// 判断用户访问时间间隔是否超时
|
||||
if ((System.currentTimeMillis() - uc.getLastAccess())
|
||||
>= 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;
|
||||
}
|
||||
|
||||
// 判断token是否正确
|
||||
if (!uc.getToken().equals(token)) {
|
||||
log.error("User {} token {} is error", username, token);
|
||||
return ErrorCode.ERR_TOKENNOTFOUND;
|
||||
}
|
||||
|
||||
|
|
|
@ -124,9 +124,7 @@ public class UserAccountServiceImpl implements UserAccountService {
|
|||
// 注销
|
||||
ErrorCode err = userAccountCacheManager.verifyUserLogin(username, token);
|
||||
|
||||
if (err == ErrorCode.ERR_OK) {
|
||||
userAccountCacheManager.cleanUserToken(username);
|
||||
}
|
||||
userAccountCacheManager.cleanUserToken(username);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.dispose.controller;
|
|||
import com.dispose.Global.InitTestEnvironment;
|
||||
import com.dispose.common.ConstValue;
|
||||
import com.dispose.common.DeviceCapacity;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.IPAddrType;
|
||||
import com.dispose.manager.TaskCacheManager;
|
||||
import com.dispose.mapper.DisposeDeviceMapper;
|
||||
|
@ -38,6 +39,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
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.MockMvcResultMatchers.jsonPath;
|
||||
|
@ -335,7 +337,6 @@ public class TaskControllerTest extends InitTestEnvironment {
|
|||
.getResponse()
|
||||
.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);
|
||||
System.out.print("msgContent=" + msgContent);
|
||||
|
||||
|
@ -345,29 +346,16 @@ public class TaskControllerTest extends InitTestEnvironment {
|
|||
List<TaskInfoData> taskInfoList = taskStopByIpRsp.getItems();
|
||||
for (TaskInfoData task : taskInfoList
|
||||
) {
|
||||
Assert.assertNotNull(task.getId());
|
||||
Assert.assertNotNull(task.getTaskId());
|
||||
Assert.assertNotNull(task.getStatus());
|
||||
Assert.assertNotNull(task.getMessage());
|
||||
if (task.getStatus() == ErrorCode.ERR_OK.getCode()) {
|
||||
Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
|
||||
Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
|
||||
|
||||
if (task.getStatus() == 0) {
|
||||
Assert.assertEquals(String.valueOf(task.getStatus()), "0");
|
||||
Assert.assertEquals(task.getMessage(), "成功");
|
||||
Assert.assertNotNull(task.getId());
|
||||
Assert.assertNotNull(task.getTaskId());
|
||||
Assert.assertNotNull(task.getStatus());
|
||||
Assert.assertNotNull(task.getMessage());
|
||||
} else {
|
||||
Assert.assertNotEquals(String.valueOf(task.getStatus()), "0");
|
||||
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);
|
||||
Assert.assertNotEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue