Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
browser-backend
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
browser-backend
Commits
f41957ad
Commit
f41957ad
authored
Sep 04, 2024
by
SN150021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
对接腾讯云api
parent
eaaeee8c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
6 deletions
+108
-6
BrowserTask.java
...va/com/edgec/browserbackend/browser/task/BrowserTask.java
+108
-5
TenCentEcsClient.java
.../edgec/browserbackend/common/client/TenCentEcsClient.java
+0
-1
No files found.
src/main/java/com/edgec/browserbackend/browser/task/BrowserTask.java
View file @
f41957ad
...
@@ -36,6 +36,8 @@ import com.edgec.browserbackend.common.commons.utils.NotifyUtils;
...
@@ -36,6 +36,8 @@ import com.edgec.browserbackend.common.commons.utils.NotifyUtils;
import
com.edgec.browserbackend.common.enums.RegionMappingEnum
;
import
com.edgec.browserbackend.common.enums.RegionMappingEnum
;
import
com.edgec.browserbackend.common.utils.ThreadPoolUtils
;
import
com.edgec.browserbackend.common.utils.ThreadPoolUtils
;
import
com.edgec.browserbackend.common.utils.Trans
;
import
com.edgec.browserbackend.common.utils.Trans
;
import
com.tencentcloudapi.cvm.v20170312.models.ModifyInstancesChargeTypeResponse
;
import
com.tencentcloudapi.cvm.v20170312.models.TerminateInstancesResponse
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.time.ZoneId
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
...
@@ -294,7 +296,7 @@ public class BrowserTask {
...
@@ -294,7 +296,7 @@ public class BrowserTask {
Instance
instance
=
response
.
getBody
().
getInstances
()
Instance
instance
=
response
.
getBody
().
getInstances
()
.
getInstance
().
get
(
0
);
.
getInstance
().
get
(
0
);
if
(
instance
.
getInstanceChargeType
().
equals
(
"PrePaid"
))
{
if
(
instance
.
getInstanceChargeType
().
equals
(
"PrePaid"
))
{
//包年包
夜
更新ip状态
//包年包
月
更新ip状态
ipResource
.
setAddr
(
ipResource
.
setAddr
(
instance
.
getPublicIpAddress
().
getIpAddress
().
get
(
0
));
instance
.
getPublicIpAddress
().
getIpAddress
().
get
(
0
));
ipResource
.
setStatus
(
0
);
ipResource
.
setStatus
(
0
);
...
@@ -380,10 +382,84 @@ public class BrowserTask {
...
@@ -380,10 +382,84 @@ public class BrowserTask {
com
.
tencentcloudapi
.
cvm
.
v20170312
.
models
.
DescribeInstancesResponse
response
=
com
.
tencentcloudapi
.
cvm
.
v20170312
.
models
.
DescribeInstancesResponse
response
=
TenCentEcsClient
.
getDescribeInstances
(
ipResource
.
getOwner
(),
cloudPlatformOrder
.
getPlatformOrderId
(),
TenCentEcsClient
.
getDescribeInstances
(
ipResource
.
getOwner
(),
cloudPlatformOrder
.
getPlatformOrderId
(),
cloudPlatformOrder
.
getRegionId
());
cloudPlatformOrder
.
getRegionId
());
/* if (!response.getStatusCode().equals(200)) {
if
(
Objects
.
isNull
(
response
)
||
Objects
.
isNull
(
response
.
getInstanceSet
()))
{
log.error(", fail to query ip : {}",
log
.
error
(
"fail to query ip"
);
JSON.toJSON(response.getBody()));
}
}*/
com
.
tencentcloudapi
.
cvm
.
v20170312
.
models
.
Instance
instance
=
response
.
getInstanceSet
()[
0
];
if
(
instance
.
getInstanceChargeType
().
equals
(
"PREPAID"
))
{
//包年包月 更新ip状态
ipResource
.
setAddr
(
instance
.
getPublicIpAddresses
()[
0
]);
ipResource
.
setStatus
(
0
);
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd'T'HH:mmX"
);
Instant
instant
=
Instant
.
from
(
formatter
.
parse
(
instance
.
getExpiredTime
()));
ipResource
.
setValidTime
(
instant
.
toEpochMilli
());
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getRegion
())
&&
region
.
contains
(
ipResource
.
getRegion
()))
{
ipResource
.
setProxyUsername
(
ipResource
.
getAddr
());
ipResource
.
setProxyPassword
(
genRandom
(
3
,
12
));
ipResource
.
setSpecialLine
(
true
);
}
ipResourceRepository
.
save
(
ipResource
);
IpHistory
ipHistory
=
new
IpHistory
();
ipHistory
.
setIpNo
(
ipResource
.
getAddr
());
ipHistory
.
setPlatformType
(
cloudPlatformOrder
.
getPlatformType
());
ipHistory
.
setPurchasedTime
(
Instant
.
now
().
toEpochMilli
());
ipHistoryRepository
.
save
(
ipHistory
);
return
;
}
//查询是否为重复ip
String
ipNo
=
instance
.
getPublicIpAddresses
()[
0
];
LocalDateTime
localDateTime
=
LocalDateTime
.
now
().
minus
(
3
,
ChronoUnit
.
MONTHS
);
Instant
instant
=
localDateTime
.
atZone
(
ZoneId
.
systemDefault
()).
toInstant
();
List
<
IpHistory
>
ipHistoryList
=
ipHistoryRepository
.
findByIpNoAndPurchasedTimeAfter
(
ipNo
,
instant
.
toEpochMilli
());
if
(
CollectionUtils
.
isNotEmpty
(
ipHistoryList
)
&&
(
Objects
.
isNull
(
cloudPlatformOrder
.
getRetryCount
())
||
cloudPlatformOrder
.
getRetryCount
()
<
5
))
{
//重新分配ip(删除旧的 购买新的)
TenCentEcsClient
.
deleteInstance
(
ipResource
.
getOwner
(),
cloudPlatformOrder
.
getPlatformOrderId
(),
cloudPlatformOrder
.
getRegionId
());
CloudPlatformConfig
config
=
cloudPlatformConfigRepository
.
findByPlatformAndRegionId
(
"tenCent"
,
cloudPlatformOrder
.
getRegionId
());
com
.
tencentcloudapi
.
cvm
.
v20170312
.
models
.
RunInstancesResponse
response1
=
TenCentEcsClient
.
runInstances
(
ipResource
.
getOwner
(),
ipResource
.
getUsername
(),
ipResource
.
getPassword
(),
config
);
if
(
null
==
response1
||
null
==
response1
.
getInstanceIdSet
())
{
log
.
error
(
"queryIpNewTasks, fail to buy ip again : {}"
,
JSON
.
toJSON
(
response
));
}
else
{
int
oldRetryCount
=
Objects
.
isNull
(
cloudPlatformOrder
.
getRetryCount
())
?
0
:
cloudPlatformOrder
.
getRetryCount
();
cloudPlatformOrder
.
setRetryCount
(
oldRetryCount
+
1
);
cloudPlatformOrderRepository
.
save
(
cloudPlatformOrder
);
String
instanceId
=
response1
.
getInstanceIdSet
()[
0
];
cloudPlatformOrder
.
setPlatformOrderId
(
instanceId
);
ipResource
.
setStatus
(
3
);
ipResourceRepository
.
save
(
ipResource
);
cloudPlatformOrderRepository
.
save
(
cloudPlatformOrder
);
}
}
else
{
//将ip改为包年包月
//TODO 腾讯云目前只有包月
ModifyInstancesChargeTypeResponse
response1
=
TenCentEcsClient
.
modifyInstanceChargeType
(
ipResource
.
getOwner
(),
ipResource
.
getPeriod
(),
cloudPlatformOrder
.
getRegionId
(),
cloudPlatformOrder
.
getPlatformOrderId
());
if
(
null
==
response1
)
{
//TODO 目前先抛错误 待确认如何解决
log
.
error
(
"queryIpNewTasks, fail to buy ip again : {}"
,
JSON
.
toJSON
(
response
));
}
}
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
log
.
error
(
e
.
getMessage
(),
e
);
...
@@ -450,6 +526,26 @@ public class BrowserTask {
...
@@ -450,6 +526,26 @@ public class BrowserTask {
}
}
}
}
}
else
if
(
"tenCent"
.
equals
(
cloudPlatformOrder
.
getPlatformType
())){
com
.
tencentcloudapi
.
cvm
.
v20170312
.
models
.
DescribeInstancesResponse
describeInstances
=
TenCentEcsClient
.
getDescribeInstances
(
ipResource
.
getOwner
(),
cloudPlatformOrder
.
getPlatformOrderId
(),
cloudPlatformOrder
.
getRegionId
());
if
(
null
==
describeInstances
)
{
log
.
error
(
", fail to query ip "
);
}
assert
describeInstances
!=
null
;
if
(
Objects
.
nonNull
(
describeInstances
.
getInstanceSet
()))
{
//判断是否重复购买
com
.
tencentcloudapi
.
cvm
.
v20170312
.
models
.
Instance
instance
=
describeInstances
.
getInstanceSet
()[
0
];
if
(
instance
.
getInstanceChargeType
().
equals
(
"PREPAID"
))
{
//包年包夜 更新ip状态
ipResource
.
setStatus
(
0
);
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd'T'HH:mmX"
);
Instant
instant
=
Instant
.
from
(
formatter
.
parse
(
instance
.
getExpiredTime
()));
ipResource
.
setValidTime
(
instant
.
toEpochMilli
());
ipResourceRepository
.
save
(
ipResource
);
}
}
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
log
.
error
(
e
.
getMessage
(),
e
);
...
@@ -748,6 +844,13 @@ public class BrowserTask {
...
@@ -748,6 +844,13 @@ public class BrowserTask {
if
(
null
!=
response
&&
response
.
getStatusCode
().
equals
(
200
))
{
if
(
null
!=
response
&&
response
.
getStatusCode
().
equals
(
200
))
{
isDelet
=
true
;
isDelet
=
true
;
}
}
}
else
if
(
"tenCent"
.
equals
(
cloudPlatformOrder
.
getPlatformType
())){
String
aliRegion
=
RegionMappingEnum
.
getAliRegion
(
ipResource
.
getRegion
());
TerminateInstancesResponse
response
=
TenCentEcsClient
.
deleteInstance
(
ipResource
.
getOwner
(),
cloudPlatformOrder
.
getPlatformOrderId
(),
aliRegion
);
if
(
null
!=
response
)
{
isDelet
=
true
;
}
}
}
if
(
isDelet
){
if
(
isDelet
){
ipResource
.
setShopIds
(
null
);
ipResource
.
setShopIds
(
null
);
...
...
src/main/java/com/edgec/browserbackend/common/client/TenCentEcsClient.java
View file @
f41957ad
...
@@ -114,7 +114,6 @@ public class TenCentEcsClient {
...
@@ -114,7 +114,6 @@ public class TenCentEcsClient {
describeInstancesResponse
=
cvmClient
.
DescribeInstances
(
req
);
describeInstancesResponse
=
cvmClient
.
DescribeInstances
(
req
);
log
.
info
(
"调用TenCentEcs查询单个实例,响应参数:owner:{},response:{}"
,
owner
,
log
.
info
(
"调用TenCentEcs查询单个实例,响应参数:owner:{},response:{}"
,
owner
,
JSON
.
toJSON
(
describeInstancesResponse
));
JSON
.
toJSON
(
describeInstancesResponse
));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"fail to TenCentEcs getDescribeInstances {}"
,
e
.
getMessage
());
log
.
error
(
"fail to TenCentEcs getDescribeInstances {}"
,
e
.
getMessage
());
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment