|
|
@ -7,6 +7,7 @@ import net.educoder.util.JCloudUtil;
|
|
|
|
import net.educoder.util.ResponseResult;
|
|
|
|
import net.educoder.util.ResponseResult;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
@ -23,14 +24,15 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
public class CloudController {
|
|
|
|
public class CloudController {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${jcloud.password}")
|
|
|
|
@Value("${jcloud.username}")
|
|
|
|
private String username;
|
|
|
|
private String username;
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${jcloud.password}")
|
|
|
|
@Value("${jcloud.password}")
|
|
|
|
private String password;
|
|
|
|
private String password;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private Cache<String, String> cache;
|
|
|
|
@Qualifier("guavaCache")
|
|
|
|
|
|
|
|
private Cache<String, String> guavaCache;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -41,7 +43,7 @@ public class CloudController {
|
|
|
|
@PostMapping("/createCloudHost")
|
|
|
|
@PostMapping("/createCloudHost")
|
|
|
|
public ResponseResult<String> createCloudHost() {
|
|
|
|
public ResponseResult<String> createCloudHost() {
|
|
|
|
|
|
|
|
|
|
|
|
String apiToken = cache.getIfPresent(CommonConstants.API_TOKEN);
|
|
|
|
String apiToken = guavaCache.getIfPresent(CommonConstants.API_TOKEN);
|
|
|
|
if (StringUtils.isBlank(apiToken)) {
|
|
|
|
if (StringUtils.isBlank(apiToken)) {
|
|
|
|
apiToken = refreshApiToken();
|
|
|
|
apiToken = refreshApiToken();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -58,7 +60,7 @@ public class CloudController {
|
|
|
|
@PostMapping("/getCloudHostList")
|
|
|
|
@PostMapping("/getCloudHostList")
|
|
|
|
public ResponseResult<String> getCloudHostList() {
|
|
|
|
public ResponseResult<String> getCloudHostList() {
|
|
|
|
|
|
|
|
|
|
|
|
String apiToken = cache.getIfPresent(CommonConstants.API_TOKEN);
|
|
|
|
String apiToken = guavaCache.getIfPresent(CommonConstants.API_TOKEN);
|
|
|
|
if (StringUtils.isBlank(apiToken)) {
|
|
|
|
if (StringUtils.isBlank(apiToken)) {
|
|
|
|
apiToken = refreshApiToken();
|
|
|
|
apiToken = refreshApiToken();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -76,7 +78,7 @@ public class CloudController {
|
|
|
|
@PostMapping("/resetCloudHost")
|
|
|
|
@PostMapping("/resetCloudHost")
|
|
|
|
public ResponseResult resetCloudHost(String serverId) {
|
|
|
|
public ResponseResult resetCloudHost(String serverId) {
|
|
|
|
|
|
|
|
|
|
|
|
String apiToken = cache.getIfPresent(CommonConstants.API_TOKEN);
|
|
|
|
String apiToken = guavaCache.getIfPresent(CommonConstants.API_TOKEN);
|
|
|
|
if (StringUtils.isBlank(apiToken)) {
|
|
|
|
if (StringUtils.isBlank(apiToken)) {
|
|
|
|
apiToken = refreshApiToken();
|
|
|
|
apiToken = refreshApiToken();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -104,7 +106,7 @@ public class CloudController {
|
|
|
|
private String refreshApiToken() {
|
|
|
|
private String refreshApiToken() {
|
|
|
|
String apiToken = JCloudUtil.getApiToken(username, password);
|
|
|
|
String apiToken = JCloudUtil.getApiToken(username, password);
|
|
|
|
log.info("token refresh--------{}", apiToken);
|
|
|
|
log.info("token refresh--------{}", apiToken);
|
|
|
|
cache.put(CommonConstants.API_TOKEN, apiToken);
|
|
|
|
guavaCache.put(CommonConstants.API_TOKEN, apiToken);
|
|
|
|
|
|
|
|
|
|
|
|
return apiToken;
|
|
|
|
return apiToken;
|
|
|
|
}
|
|
|
|
}
|
|
|
|