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