Commit 55f900cd authored by renjie's avatar renjie

Merge branch 'dev-zrj' into 'staging'

1.删除未释放ip

See merge request !113
parents 61371356 c70c4e75
...@@ -167,4 +167,20 @@ public class IpControlloer { ...@@ -167,4 +167,20 @@ public class IpControlloer {
} }
return resultDto; return resultDto;
} }
@RequestMapping(value = "/releasedeleted", method = RequestMethod.PUT)
public ResultDto deleteUseless(Principal principal) {
ResultDto resultDto = new ResultDto();
try {
ipResourceService.releaseDeletedIp();
resultDto.setStatus(0);
} catch (Exception e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", 80001);
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
} }
package com.edgec.browserbackend.browser.repository; package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.IpResource; import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.IpType;
import com.edgec.browserbackend.browser.domain.Shop; import com.edgec.browserbackend.browser.domain.Shop;
import com.google.gson.internal.$Gson$Preconditions; import com.google.gson.internal.$Gson$Preconditions;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
...@@ -28,6 +29,8 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String ...@@ -28,6 +29,8 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String
Page<IpResource> findByIsDeletedAndIdInAndRegionCnLikeOrderByPurchasedTimeDesc(boolean isDeleted, List<String> ipIds, String region, Pageable pageable); Page<IpResource> findByIsDeletedAndIdInAndRegionCnLikeOrderByPurchasedTimeDesc(boolean isDeleted, List<String> ipIds, String region, Pageable pageable);
List<IpResource> findByIsDeletedAndShopIdInAndRegionCnLike(boolean isDeleted, List<String> shopIds, String regionCn); List<IpResource> findByIsDeletedAndShopIdInAndRegionCnLike(boolean isDeleted, List<String> shopIds, String regionCn);
List<IpResource> findByIsDeleted(boolean isDeleted);
List<IpResource> findByOwnerInAndSpecialLine(List<String> owners, boolean specialLine); List<IpResource> findByOwnerInAndSpecialLine(List<String> owners, boolean specialLine);
List<IpResource> findBySpecialLineAndIsDeleted(boolean specialLine, boolean isDeleted); List<IpResource> findBySpecialLineAndIsDeleted(boolean specialLine, boolean isDeleted);
......
...@@ -112,8 +112,8 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto ...@@ -112,8 +112,8 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
@Override @Override
public List<IpResource> sampleTasks(List<Integer> status) { public List<IpResource> sampleTasks(List<Integer> status) {
Criteria matchCriteria = new Criteria(); Criteria matchCriteria = new Criteria();
matchCriteria.orOperator(where("status").in(status).and("isLocked").is(false).and("isDeleted").is(false).and("healthLockTimestamp").lte(Instant.now().minusSeconds(60*30).toEpochMilli()), matchCriteria.orOperator(where("status").in(status).and("isLocked").is(false).and("validTime").lte(Instant.now().toEpochMilli()).and("isDeleted").is(false).and("healthLockTimestamp").lte(Instant.now().minusSeconds(60*30).toEpochMilli()),
where("status").in(status).and("isLocked").is(true).and("healthLockTimestamp").lte(Instant.now().minusSeconds(300).toEpochMilli()).and("isDeleted").is(false)); where("status").in(status).and("isLocked").is(true).and("healthLockTimestamp").lte(Instant.now().minusSeconds(600).toEpochMilli()).and("isDeleted").is(false));
MatchOperation match = Aggregation.match(matchCriteria); MatchOperation match = Aggregation.match(matchCriteria);
......
...@@ -801,4 +801,18 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -801,4 +801,18 @@ public class IpResourceServiceImpl implements IpResourceService {
ipResourceRepository.save(ipResource); ipResourceRepository.save(ipResource);
} }
} }
@Override
public void releaseDeletedIp() {
String URL = (profiles.equals("dev") || profiles.equals("staging"))? TESTURL : CLOUDAMURL;
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = buildGetHeader();
Map<String, String> params = new HashMap<String, String>();
HttpEntity<Map<String, String>> httpEntity = new HttpEntity<>(params, headers);
List<IpResource> ipResources = ipResourceRepository.findByIsDeleted(true);
for (IpResource ipResource : ipResources) {
ResponseEntity<String> result = restTemplate.exchange(URL + "/intelligroup/ipresources?accountId=browser&ip={ip}", HttpMethod.DELETE, httpEntity, String.class, ipResource.getAddr());
DeleteIpResultDto deleteIpResultDto = JSON.parseObject(result.getBody(), DeleteIpResultDto.class);
}
}
} }
...@@ -30,4 +30,6 @@ public interface IpResourceService { ...@@ -30,4 +30,6 @@ public interface IpResourceService {
IpResourceDto queryIp(String username, IpResourceRequestDto ipResourceRequestDto); IpResourceDto queryIp(String username, IpResourceRequestDto ipResourceRequestDto);
void setSpecialLine(); void setSpecialLine();
void releaseDeletedIp();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment