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"
init-method="init"
destroy-method="close"
p:url="${yo.fs.datasource.url}"
p:username="${yo.fs.datasource.username}"
p:password="${yo.fs.datasource.password}"
p:url="${yo.freeswitch.datasource.url}"
p:username="${yo.freeswitch.datasource.username}"
p:password="${yo.freeswitch.datasource.password}"
/>
<!-- Transaction -->

View File

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

View File

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

View File

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

View File

@ -3,6 +3,7 @@ package com.pudonghot.yo.mapper;
import org.junit.Test;
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.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ -20,6 +21,6 @@ public class CallRecordingMapperTest {
@Test
public void testList() {
mapper.list(null);
mapper.list(new Search());
}
}

View File

@ -1,8 +1,9 @@
package com.pudonghot.yo.mapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
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.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ -20,6 +21,6 @@ public class QueueMapperTest {
@Test
public void testList() {
mapper.list(null);
mapper.list(new Search());
}
}

View File

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

View File

@ -1,5 +1,6 @@
package com.pudonghot.yo.mapper;
import me.chyxion.tigon.mybatis.Search;
import org.junit.Test;
import org.junit.runner.RunWith;
import lombok.extern.slf4j.Slf4j;
@ -20,6 +21,6 @@ public class WorkRecordMapperTest {
@Test
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;
import lombok.val;
import java.util.UUID;
import org.bson.types.ObjectId;
import com.wacai.tigon.sequence.IdSequence;
@ -24,8 +25,8 @@ public class IdSequenceSupport implements IdSequence {
*/
@Override
public String uuid() {
final UUID uuid = UUID.randomUUID();
return Long.toHexString(uuid.getMostSignificantBits())
+ Long.toHexString(uuid.getLeastSignificantBits());
val uuid = UUID.randomUUID();
return (Long.toHexString(uuid.getMostSignificantBits())
+ Long.toHexString(uuid.getLeastSignificantBits())).toUpperCase();
}
}

View File

@ -21,7 +21,7 @@
<jackson.version>2.12.0</jackson.version>
<spring.version>5.2.12.RELEASE</spring.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>
<modules>

View File

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

View File

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

View File

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

View File

@ -4,10 +4,10 @@
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>
<artifactId>yo-fsagent</artifactId>
<artifactId>yo-server</artifactId>
<version>0.0.1-RELEASE</version>
<name>Yo FreeSWITCH Agent</name>
<description>Yo FreeSWITCH Agent</description>
<name>Yo Server</name>
<description>Yo Server</description>
<packaging>jar</packaging>
<parent>
@ -18,7 +18,7 @@
</parent>
<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>
<dependencies>
@ -113,7 +113,7 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
<fork>true</fork>
<fork>false</fork>
</configuration>
</plugin>
<plugin>

View File

@ -1,4 +1,4 @@
package com.pudonghot.yo.fsagent;
package com.pudonghot.yo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
@ -10,13 +10,13 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
*/
@Slf4j
@SpringBootApplication
public class YoFsAgent {
public class YoServer {
/**
* main
* @param args 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;
@Value("${site.context-path:}")
private String siteContextPath;
@Value("${yo.fsa.server.port:}")
@Value("${yo.fsagent.server.port:}")
private String serverPort;
@Getter
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;
import com.pudonghot.yo.model.domain.AgentStatus;
import com.wacai.tigon.service.BaseCrudService;
import com.pudonghot.yo.model.domain.AgentStatus;
/**
* @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.mapper.CallDetailRecordMapper;
import com.pudonghot.yo.model.domain.CallDetailRecord;
import com.pudonghot.yo.service.LeaderElectionService;
import com.pudonghot.yo.state.service.AgentStatusService;
import static com.pudonghot.yo.model.domain.AgentStatus.*;
import org.springframework.beans.factory.annotation.Value;
@ -54,11 +55,19 @@ public class AgentStatusScheduleServiceImpl implements AgentStatusScheduleServic
private CommonAgentEventQueueService agentEventQueueService;
@Autowired
private CommonCampaignService commonCampaignService;
@Autowired
private LeaderElectionService leaderElectionService;
@Scheduled(initialDelayString = "${yo.state.agent.registration-check.init-delay:42000}",
fixedRateString = "${yo.state.agent.registration-check.rate:32000}")
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),
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 * * *}")
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(
new Date(), -agentIdleSignOutMinutes);

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