Merge state & fsagent -> server

This commit is contained in:
Shaun Chyxion 2021-01-04 00:31:41 +08:00
parent 158994bd87
commit 53d8a98bbf
153 changed files with 159 additions and 282 deletions

View File

@ -9,9 +9,9 @@
class="com.alibaba.druid.pool.DruidDataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" init-method="init"
destroy-method="close" destroy-method="close"
p:url="${yo.fs.datasource.url}" p:url="${yo.freeswitch.datasource.url}"
p:username="${yo.fs.datasource.username}" p:username="${yo.freeswitch.datasource.username}"
p:password="${yo.fs.datasource.password}" p:password="${yo.freeswitch.datasource.password}"
/> />
<!-- Transaction --> <!-- Transaction -->

View File

@ -1,5 +1,6 @@
package com.pudonghot.yo.fs.mapper; package com.pudonghot.yo.fs.mapper;
import me.chyxion.tigon.mybatis.Search;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -20,6 +21,6 @@ public class SipRegistrationMapperTest {
@Test @Test
public void testList() { public void testList() {
mapper.list(null); mapper.list(new Search());
} }
} }

View File

@ -1,8 +1,9 @@
package com.pudonghot.yo.mapper; package com.pudonghot.yo.mapper;
import org.junit.Test; import org.junit.Test;
import lombok.extern.slf4j.Slf4j;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import lombok.extern.slf4j.Slf4j;
import me.chyxion.tigon.mybatis.Search;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ -20,6 +21,6 @@ public class AgentGroupCampaignWeightMapperTest {
@Test @Test
public void testList() { public void testList() {
mapper.list(null); mapper.list(new Search());
} }
} }

View File

@ -4,10 +4,10 @@ import lombok.val;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chyxion.tigon.mybatis.Search;
import com.pudonghot.yo.model.domain.Agent; import com.pudonghot.yo.model.domain.Agent;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/** /**
@ -23,7 +23,7 @@ public class AgentMapperTest {
@Test @Test
public void testList() { public void testList() {
val list = mapper.list(null); val list = mapper.list(new Search());
if (!list.isEmpty()) { if (!list.isEmpty()) {
val agent = list.iterator().next(); val agent = list.iterator().next();
agent.setUpdatedBy("donghuang"); agent.setUpdatedBy("donghuang");

View File

@ -34,7 +34,7 @@ public class CallDetailRecordMapperTest {
@Test @Test
public void testList() { public void testList() {
mapper.list(null); mapper.list(new Search());
} }
@Test @Test

View File

@ -3,6 +3,7 @@ package com.pudonghot.yo.mapper;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chyxion.tigon.mybatis.Search;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ -20,6 +21,6 @@ public class CallRecordingMapperTest {
@Test @Test
public void testList() { public void testList() {
mapper.list(null); mapper.list(new Search());
} }
} }

View File

@ -1,8 +1,9 @@
package com.pudonghot.yo.mapper; package com.pudonghot.yo.mapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import lombok.extern.slf4j.Slf4j;
import me.chyxion.tigon.mybatis.Search;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ -20,6 +21,6 @@ public class QueueMapperTest {
@Test @Test
public void testList() { public void testList() {
mapper.list(null); mapper.list(new Search());
} }
} }

View File

@ -1,8 +1,9 @@
package com.pudonghot.yo.mapper; package com.pudonghot.yo.mapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import lombok.extern.slf4j.Slf4j;
import me.chyxion.tigon.mybatis.Search;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ -20,6 +21,6 @@ public class TelecomVendorMapperTest {
@Test @Test
public void testList() { public void testList() {
mapper.list(null); mapper.list(new Search());
} }
} }

View File

@ -3,6 +3,7 @@ package com.pudonghot.yo.mapper;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chyxion.tigon.mybatis.Search;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ -20,6 +21,6 @@ public class TenantMapperTest {
@Test @Test
public void testList() { public void testList() {
mapper.list(null); mapper.list(new Search());
} }
} }

View File

@ -1,5 +1,6 @@
package com.pudonghot.yo.mapper; package com.pudonghot.yo.mapper;
import me.chyxion.tigon.mybatis.Search;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -20,6 +21,6 @@ public class WorkRecordMapperTest {
@Test @Test
public void testList() { public void testList() {
log.info("Result [{}].", mapper.list(null)); log.info("Result [{}].", mapper.list(new Search()));
} }
} }

View File

@ -1,5 +1,6 @@
package com.wacai.tigon.sequence.support; package com.wacai.tigon.sequence.support;
import lombok.val;
import java.util.UUID; import java.util.UUID;
import org.bson.types.ObjectId; import org.bson.types.ObjectId;
import com.wacai.tigon.sequence.IdSequence; import com.wacai.tigon.sequence.IdSequence;
@ -24,8 +25,8 @@ public class IdSequenceSupport implements IdSequence {
*/ */
@Override @Override
public String uuid() { public String uuid() {
final UUID uuid = UUID.randomUUID(); val uuid = UUID.randomUUID();
return Long.toHexString(uuid.getMostSignificantBits()) return (Long.toHexString(uuid.getMostSignificantBits())
+ Long.toHexString(uuid.getLeastSignificantBits()); + Long.toHexString(uuid.getLeastSignificantBits())).toUpperCase();
} }
} }

View File

@ -21,7 +21,7 @@
<jackson.version>2.12.0</jackson.version> <jackson.version>2.12.0</jackson.version>
<spring.version>5.2.12.RELEASE</spring.version> <spring.version>5.2.12.RELEASE</spring.version>
<spring-boot.version>2.3.7.RELEASE</spring-boot.version> <spring-boot.version>2.3.7.RELEASE</spring-boot.version>
<tigon-mybatis.version>0.0.5</tigon-mybatis.version> <tigon-mybatis.version>0.0.6</tigon-mybatis.version>
</properties> </properties>
<modules> <modules>

View File

@ -11,7 +11,7 @@ public interface AgentService extends BaseCrudService<Integer, Agent> {
/** /**
* find valid agent * find valid agent
* @param tenantId tennat id * @param tenantId tenant id
* @param account account * @param account account
* @return agent * @return agent
*/ */

View File

@ -1,12 +1,13 @@
package com.pudonghot.yo.openapi.service.impl; package com.pudonghot.yo.openapi.service.impl;
import com.pudonghot.yo.model.exception.AssertUtils; import lombok.val;
import com.pudonghot.yo.model.exception.ErrorCode;
import com.pudonghot.yo.openapi.service.AgentService;
import me.chyxion.tigon.mybatis.Search; import me.chyxion.tigon.mybatis.Search;
import org.springframework.stereotype.Service;
import com.pudonghot.yo.mapper.AgentMapper; import com.pudonghot.yo.mapper.AgentMapper;
import com.pudonghot.yo.model.domain.Agent; import com.pudonghot.yo.model.domain.Agent;
import org.springframework.stereotype.Service;
import com.pudonghot.yo.model.exception.ErrorCode;
import com.pudonghot.yo.model.exception.AssertUtils;
import com.pudonghot.yo.openapi.service.AgentService;
import com.wacai.tigon.service.support.BaseCrudServiceSupport; import com.wacai.tigon.service.support.BaseCrudServiceSupport;
/** /**
@ -23,7 +24,7 @@ public class AgentServiceImpl
*/ */
@Override @Override
public Agent findValid(final Integer tenantId, final String account) { public Agent findValid(final Integer tenantId, final String account) {
final Agent agent = find( val agent = find(
new Search(Agent.TENANT_ID, tenantId) new Search(Agent.TENANT_ID, tenantId)
.eq(Agent.ACCOUNT, account)); .eq(Agent.ACCOUNT, account));
AssertUtils.state(agent != null, ErrorCode.AGENT_NOT_FOUND); AssertUtils.state(agent != null, ErrorCode.AGENT_NOT_FOUND);

View File

@ -30,8 +30,7 @@
<modules> <modules>
<module>lib</module> <module>lib</module>
<module>fsagent</module> <module>server</module>
<module>state</module>
<module>cms</module> <module>cms</module>
<module>openapi</module> <module>openapi</module>
<module>campaign</module> <module>campaign</module>

View File

@ -4,10 +4,10 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"> http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>yo-fsagent</artifactId> <artifactId>yo-server</artifactId>
<version>0.0.1-RELEASE</version> <version>0.0.1-RELEASE</version>
<name>Yo FreeSWITCH Agent</name> <name>Yo Server</name>
<description>Yo FreeSWITCH Agent</description> <description>Yo Server</description>
<packaging>jar</packaging> <packaging>jar</packaging>
<parent> <parent>
@ -18,7 +18,7 @@
</parent> </parent>
<properties> <properties>
<spring-boot.run.main-class>com.pudonghot.yo.fsagent.YoFsAgent</spring-boot.run.main-class> <spring-boot.run.main-class>com.pudonghot.yo.YoServer</spring-boot.run.main-class>
</properties> </properties>
<dependencies> <dependencies>
@ -113,7 +113,7 @@
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<configuration> <configuration>
<skip>false</skip> <skip>false</skip>
<fork>true</fork> <fork>false</fork>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

View File

@ -1,4 +1,4 @@
package com.pudonghot.yo.fsagent; package com.pudonghot.yo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
@ -10,13 +10,13 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
*/ */
@Slf4j @Slf4j
@SpringBootApplication @SpringBootApplication
public class YoFsAgent { public class YoServer {
/** /**
* main * main
* @param args args * @param args args
*/ */
public static void main(final String[] args) { public static void main(final String[] args) {
SpringApplication.run(YoFsAgent.class, args); SpringApplication.run(YoServer.class, args);
} }
} }

View File

@ -27,7 +27,7 @@ public class LocalApiServiceImpl
private final Environment env; private final Environment env;
@Value("${site.context-path:}") @Value("${site.context-path:}")
private String siteContextPath; private String siteContextPath;
@Value("${yo.fsa.server.port:}") @Value("${yo.fsagent.server.port:}")
private String serverPort; private String serverPort;
@Getter @Getter
private String basePath; private String basePath;

View File

@ -0,0 +1 @@
package com.pudonghot.yo.state;

View File

@ -1,7 +1,7 @@
package com.pudonghot.yo.state.service; package com.pudonghot.yo.state.service;
import com.pudonghot.yo.model.domain.AgentStatus;
import com.wacai.tigon.service.BaseCrudService; import com.wacai.tigon.service.BaseCrudService;
import com.pudonghot.yo.model.domain.AgentStatus;
/** /**
* @author Donghuang * @author Donghuang

View File

@ -17,6 +17,7 @@ import com.pudonghot.yo.model.agentevent.AgentEvent;
import com.pudonghot.yo.service.CommonCampaignService; import com.pudonghot.yo.service.CommonCampaignService;
import com.pudonghot.yo.mapper.CallDetailRecordMapper; import com.pudonghot.yo.mapper.CallDetailRecordMapper;
import com.pudonghot.yo.model.domain.CallDetailRecord; import com.pudonghot.yo.model.domain.CallDetailRecord;
import com.pudonghot.yo.service.LeaderElectionService;
import com.pudonghot.yo.state.service.AgentStatusService; import com.pudonghot.yo.state.service.AgentStatusService;
import static com.pudonghot.yo.model.domain.AgentStatus.*; import static com.pudonghot.yo.model.domain.AgentStatus.*;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -54,11 +55,19 @@ public class AgentStatusScheduleServiceImpl implements AgentStatusScheduleServic
private CommonAgentEventQueueService agentEventQueueService; private CommonAgentEventQueueService agentEventQueueService;
@Autowired @Autowired
private CommonCampaignService commonCampaignService; private CommonCampaignService commonCampaignService;
@Autowired
private LeaderElectionService leaderElectionService;
@Scheduled(initialDelayString = "${yo.state.agent.registration-check.init-delay:42000}", @Scheduled(initialDelayString = "${yo.state.agent.registration-check.init-delay:42000}",
fixedRateString = "${yo.state.agent.registration-check.rate:32000}") fixedRateString = "${yo.state.agent.registration-check.rate:32000}")
public void agentRegistrationCheck() { public void agentRegistrationCheck() {
val checkRegKey = idSeq.get(); log.debug("Check agent registration.");
if (!leaderElectionService.isLeader()) {
log.debug("Server is not leader, ignore agent registration check.");
return;
}
val checkRegKey = idSeq.uuid();
agentStatusMapper.update(checkRegKeyUpdate(checkRegKey), agentStatusMapper.update(checkRegKeyUpdate(checkRegKey),
new Search().isNull(AgentStatus.CHECK_REG_KEY)); new Search().isNull(AgentStatus.CHECK_REG_KEY));
@ -84,6 +93,12 @@ public class AgentStatusScheduleServiceImpl implements AgentStatusScheduleServic
@Scheduled(cron = "${yo.state.agent.status-check.cron:0 * 7-20 * * *}") @Scheduled(cron = "${yo.state.agent.status-check.cron:0 * 7-20 * * *}")
public void agentStatusCheck() { public void agentStatusCheck() {
log.debug("Check agent status.");
if (!leaderElectionService.isLeader()) {
log.debug("Server is not leader, ignore agent status check.");
return;
}
val dateMaxIdle = DateUtils.addMinutes( val dateMaxIdle = DateUtils.addMinutes(
new Date(), -agentIdleSignOutMinutes); new Date(), -agentIdleSignOutMinutes);

Some files were not shown because too many files have changed in this diff Show More