xiatian 5 yıl önce
ebeveyn
işleme
9e00b87e4a

+ 20 - 14
src/main/java/cn/com/qmth/examcloud/web/aliyun/AliyunSiteManager.java

@@ -28,7 +28,7 @@ public class AliyunSiteManager {
 	 
 	private static final Map<String, AliYunAccount> ACCOUNT_HOLDERS = new ConcurrentHashMap<>();
 
-	public static void init() {
+	public static void initSite() {
 		String resoucePath = PathUtil.getResoucePath("aliyun.xml");
 		File file = new File(resoucePath);
 
@@ -43,14 +43,23 @@ public class AliyunSiteManager {
 			List<AliyunSite> obj = (List<AliyunSite>) xStream.fromXML(file);
 			list = obj;
 		} catch (Exception e) {
-			throw new StatusException("520001", "aliyun.xml is wrong", e);
+			throw new StatusException("20001", "aliyun.xml is wrong", e);
 		}
 
 		for (AliyunSite aliyunSite : list) {
 
 			SITE_HOLDERS.put(aliyunSite.getId(), aliyunSite);
+		}
 
-			String aliyunId = aliyunSite.getAliyunId();
+	}
+	public static void initClient() {
+		String aliyunNum = PropertyHolder.getString("$aliyun.site.num");
+		if (StringUtils.isBlank(aliyunNum)) {
+			throw new StatusException("20021", "aliyunNum is not configured.");
+		}
+		int num=Integer.parseInt(aliyunNum);
+		for(int i=1;i<=num;i++) {
+			String aliyunId=i+"";
 			String bucket = PropertyHolder.getString("$aliyun.site." + aliyunId + ".bucket");
 			String ossEndpoint = PropertyHolder.getString("$aliyun.site." + aliyunId + ".ossEndpoint");
 
@@ -60,19 +69,19 @@ public class AliyunSiteManager {
 			String domainBackup = PropertyHolder.getString("$aliyun.site." + aliyunId + ".domain.backup");
 
 			if (StringUtils.isBlank(bucket)) {
-				throw new StatusException("520001", "bucket is not configured. aliyunId=" + aliyunId);
+				throw new StatusException("20001", "bucket is not configured. aliyunId=" + aliyunId);
 			}
 			if (StringUtils.isBlank(ossEndpoint)) {
-				throw new StatusException("520002", "ossEndpoint is not configured. aliyunId=" + aliyunId);
+				throw new StatusException("20002", "ossEndpoint is not configured. aliyunId=" + aliyunId);
 			}
 			if (StringUtils.isBlank(accessKeyId)) {
-				throw new StatusException("520003", "accessKeyId is not configured. aliyunId=" + aliyunId);
+				throw new StatusException("20003", "accessKeyId is not configured. aliyunId=" + aliyunId);
 			}
 			if (StringUtils.isBlank(accessKeySecret)) {
-				throw new StatusException("520004", "accessKeySecret is not configured. aliyunId=" + aliyunId);
+				throw new StatusException("20004", "accessKeySecret is not configured. aliyunId=" + aliyunId);
 			}
 			if (StringUtils.isBlank(domain)) {
-				throw new StatusException("520005", "domain is not configured. aliyunId=" + aliyunId);
+				throw new StatusException("20005", "domain is not configured. aliyunId=" + aliyunId);
 			}
 			if (null == ACCOUNT_HOLDERS.get(aliyunId)) {
 				AliYunAccount ac = new AliYunAccount(bucket, ossEndpoint, accessKeyId, accessKeySecret, domain,
@@ -83,11 +92,8 @@ public class AliyunSiteManager {
 				OSS ossClient = new OSSClientBuilder().build(ossEndpoint, accessKeyId, accessKeySecret);
 				CLIENT_HOLDERS.put(aliyunId, ossClient);
 			}
-			
 		}
-
 	}
-
 	/**
 	 * 方法注释
 	 *
@@ -99,7 +105,7 @@ public class AliyunSiteManager {
 		AliyunSite aliyunSite = SITE_HOLDERS.get(siteId);
 
 		if (null == aliyunSite) {
-			throw new StatusException("520006", "aliyunSite is null");
+			throw new StatusException("20006", "aliyunSite is null");
 		}
 		return aliyunSite;
 	}
@@ -108,7 +114,7 @@ public class AliyunSiteManager {
 		AliYunAccount ac = ACCOUNT_HOLDERS.get(aliyunId);
 
 		if (null == ac) {
-			throw new StatusException("520007", "AliYunAccount is null");
+			throw new StatusException("20007", "AliYunAccount is null");
 		}
 		return ac;
 	}
@@ -117,7 +123,7 @@ public class AliyunSiteManager {
 		OSS oss = CLIENT_HOLDERS.get(aliyunId);
 
 		if (null == oss) {
-			throw new StatusException("520008", "aliYunClient is null");
+			throw new StatusException("20008", "aliYunClient is null");
 		}
 		return oss;
 	}

+ 11 - 0
src/main/java/cn/com/qmth/examcloud/web/filestorage/FileStorageUtil.java

@@ -13,8 +13,10 @@ import org.apache.commons.lang3.StringUtils;
 
 import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.commons.util.MD5;
+import cn.com.qmth.examcloud.web.aliyun.AliyunSiteManager;
 import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
 import cn.com.qmth.examcloud.web.support.SpringContextHolder;
+import cn.com.qmth.examcloud.web.upyun.UpyunSiteManager;
 
 public class FileStorageUtil {
 
@@ -420,4 +422,13 @@ public class FileStorageUtil {
 		}
 		return rpath;
 	}
+	public static void initYunClient() {
+		UpyunSiteManager.initClient();
+		AliyunSiteManager.initClient();
+	}
+	public static void initYunSite() {
+		UpyunSiteManager.initSite();
+		AliyunSiteManager.initSite();
+	}
+	
 }

+ 0 - 6
src/main/java/cn/com/qmth/examcloud/web/filestorage/impl/UpyunFileStorageImpl.java

@@ -11,8 +11,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import cn.com.qmth.examcloud.commons.exception.StatusException;
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
 import cn.com.qmth.examcloud.web.filestorage.FileStorage;
 import cn.com.qmth.examcloud.web.filestorage.FileStoragePathEnvInfo;
 import cn.com.qmth.examcloud.web.filestorage.FileStorageType;
@@ -29,7 +27,6 @@ import cn.com.qmth.examcloud.web.upyun.UpyunSiteManager;
 
 @Service(value = "upyunFileStorage")
 public class UpyunFileStorageImpl implements FileStorage {
-	protected ExamCloudLog log = ExamCloudLogFactory.getLog(this.getClass());
 	@Autowired
 	private UpyunService upyunService;
 
@@ -43,11 +40,8 @@ public class UpyunFileStorageImpl implements FileStorage {
 
 	@Override
 	public String realPath(String path) {
-		log.error("path:"+path);
 		String upyunId=FileStorageUtil.getYunId(path);
-		log.error("upyunId:"+upyunId);
 		String urlpath=FileStorageUtil.getPath(path);
-		log.error("urlpath:"+urlpath);
 		UpYunClient c=UpyunSiteManager.getUpYunClientByUpyunId(upyunId);
 		return FileStorageUtil.getUrl(c.getDomain(), urlpath);
 	}

+ 21 - 15
src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunSiteManager.java

@@ -27,12 +27,12 @@ public class UpyunSiteManager {
 
 	private static final Map<String, UpyunSite> SITE_HOLDERS = new ConcurrentHashMap<>();
 
-	public static void init() {
+	public static void initSite() {
 		String resoucePath = PathUtil.getResoucePath("upyun.xml");
 		File file = new File(resoucePath);
 
 		XStream xStream = XStreamBuilder.newInstance().build();
-		xStream.allowTypes(new Class[]{UpyunSite.class, List.class});
+		xStream.allowTypes(new Class[] { UpyunSite.class, List.class });
 		xStream.alias("sites", List.class);
 		xStream.alias("site", UpyunSite.class);
 
@@ -48,8 +48,18 @@ public class UpyunSiteManager {
 		for (UpyunSite upyunSite : list) {
 
 			SITE_HOLDERS.put(upyunSite.getId(), upyunSite);
-
-			String upyunId = upyunSite.getUpyunId();
+			
+		}
+		
+	}
+	public static void initClient() {
+		String upyunNum = PropertyHolder.getString("$upyun.site.num");
+		if (StringUtils.isBlank(upyunNum)) {
+			throw new StatusException("520021", "upyunNum is not configured.");
+		}
+		int num=Integer.parseInt(upyunNum);
+		for(int i=1;i<=num;i++) {
+			String upyunId=i+"";
 			String bucketName = PropertyHolder.getString("$upyun.site." + upyunId + ".bucketName");
 			String userName = PropertyHolder.getString("$upyun.site." + upyunId + ".userName");
 			String password = PropertyHolder.getString("$upyun.site." + upyunId + ".password");
@@ -57,27 +67,23 @@ public class UpyunSiteManager {
 			String domainBackup = PropertyHolder.getString("$upyun.site." + upyunId + ".domain.backup");
 
 			if (StringUtils.isBlank(bucketName)) {
-				throw new StatusException("520002",
-						"bucketName is not configured. upyunId=" + upyunId);
+				throw new StatusException("520002", "bucketName is not configured. upyunId=" + upyunId);
 			}
 			if (StringUtils.isBlank(userName)) {
-				throw new StatusException("520003",
-						"userName is not configured. upyunId=" + upyunId);
+				throw new StatusException("520003", "userName is not configured. upyunId=" + upyunId);
 			}
 			if (StringUtils.isBlank(password)) {
-				throw new StatusException("520004",
-						"password is not configured. upyunId=" + upyunId);
+				throw new StatusException("520004", "password is not configured. upyunId=" + upyunId);
 			}
 			if (StringUtils.isBlank(domain)) {
 				throw new StatusException("520005", "domain is not configured. upyunId=" + upyunId);
 			}
 
 			if (null == CLIENT_HOLDERS.get(upyunId)) {
-				UpYunClient upYunClient = new UpYunClient(bucketName, userName, password, domain,domainBackup);
+				UpYunClient upYunClient = new UpYunClient(bucketName, userName, password, domain, domainBackup);
 				CLIENT_HOLDERS.put(upyunId, upYunClient);
 			}
 		}
-
 	}
 
 	/**
@@ -91,7 +97,7 @@ public class UpyunSiteManager {
 		UpYunClient upYunClient = CLIENT_HOLDERS.get(upyunId);
 
 		if (null == upYunClient) {
-			throw new StatusException("520005", "upYunClient is null");
+			throw new StatusException("520006", "upYunClient is null");
 		}
 		return upYunClient;
 	}
@@ -108,7 +114,7 @@ public class UpyunSiteManager {
 		UpYunClient upYunClient = CLIENT_HOLDERS.get(upyunSite.getUpyunId());
 
 		if (null == upYunClient) {
-			throw new StatusException("520005", "upYunClient is null");
+			throw new StatusException("520007", "upYunClient is null");
 		}
 		return upYunClient;
 	}
@@ -124,7 +130,7 @@ public class UpyunSiteManager {
 		UpyunSite upyunSite = SITE_HOLDERS.get(siteId);
 
 		if (null == upyunSite) {
-			throw new StatusException("520006", "upyunSite is null");
+			throw new StatusException("520008", "upyunSite is null");
 		}
 		return upyunSite;
 	}