Skip to content

Commit

Permalink
Modify class name, move files from center to common for uniform usage; (
Browse files Browse the repository at this point in the history
  • Loading branch information
olivershen-wow authored Mar 1, 2023
1 parent ed52dae commit f530d16
Show file tree
Hide file tree
Showing 33 changed files with 155 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import com.microsoft.hydralab.agent.config.AppOptions;
import com.microsoft.hydralab.agent.runner.TestTaskRunCallback;
import com.microsoft.hydralab.agent.socket.AgentWebSocketClient;
import com.microsoft.hydralab.common.entity.center.AgentUser;
import com.microsoft.hydralab.common.entity.center.TestTaskSpec;
import com.microsoft.hydralab.common.entity.common.AgentUser;
import com.microsoft.hydralab.common.entity.common.TestTaskSpec;
import com.microsoft.hydralab.common.entity.common.*;
import com.microsoft.hydralab.common.monitor.MetricPushGateway;
import com.microsoft.hydralab.common.util.Const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.microsoft.hydralab.agent.runner.DeviceTaskControlExecutor;
import com.microsoft.hydralab.common.entity.agent.DeviceTaskControl;
import com.microsoft.hydralab.common.entity.agent.MobileDevice;
import com.microsoft.hydralab.common.entity.center.AgentUser;
import com.microsoft.hydralab.common.entity.common.AgentUser;
import com.microsoft.hydralab.common.entity.common.DeviceInfo;
import com.microsoft.hydralab.common.entity.common.Message;
import com.microsoft.hydralab.common.management.DeviceManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.microsoft.hydralab.agent.runner.t2c.T2CRunner;
import com.microsoft.hydralab.agent.util.FileLoadUtil;
import com.microsoft.hydralab.common.entity.agent.DeviceTaskControl;
import com.microsoft.hydralab.common.entity.center.TestTaskSpec;
import com.microsoft.hydralab.common.entity.common.TestTaskSpec;
import com.microsoft.hydralab.common.entity.common.*;
import com.microsoft.hydralab.common.management.DeviceManager;
import com.microsoft.hydralab.common.util.AttachmentService;
Expand Down Expand Up @@ -185,7 +185,7 @@ public void onOneDeviceComplete(TestTask testTask, DeviceInfo deviceControl, Log
File deviceTestResultFolder = result.getResultFolder();

File[] files = deviceTestResultFolder.listFiles();
List<BlobFileInfo> attachments = new ArrayList<>();
List<StorageFileInfo> attachments = new ArrayList<>();
Assert.notNull(files, "should have result file to upload");
for (File file : files) {
if (file.isDirectory()) {
Expand All @@ -208,9 +208,9 @@ public void onDeviceOffline(TestTask testTask) {
log.warn("device disconnected, test task {} will be re-queue, no data will be saved", testTask.getId());
}

private BlobFileInfo saveFileToBlob(File file, File folder, Logger logger) {
BlobFileInfo blobFileInfo = new BlobFileInfo(file, "test/result/" + folder.getParentFile().getName() + "/" + folder.getName(), BlobFileInfo.FileType.COMMON_FILE);
return attachmentService.addFileInfo(blobFileInfo, file, EntityFileRelation.EntityType.TEST_RESULT, logger);
private StorageFileInfo saveFileToBlob(File file, File folder, Logger logger) {
StorageFileInfo storageFileInfo = new StorageFileInfo(file, "test/result/" + folder.getParentFile().getName() + "/" + folder.getName(), StorageFileInfo.FileType.COMMON_FILE);
return attachmentService.addFileInfo(storageFileInfo, file, EntityFileRelation.EntityType.TEST_RESULT, logger);
}

private void processAndSaveDeviceTestResultBlobUrl(TestRun result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package com.microsoft.hydralab.agent.util;

import com.microsoft.hydralab.agent.config.AppOptions;
import com.microsoft.hydralab.common.entity.common.BlobFileInfo;
import com.microsoft.hydralab.common.entity.common.StorageFileInfo;
import com.microsoft.hydralab.common.entity.common.TestTask;
import com.microsoft.hydralab.common.util.CommandOutputReceiver;
import com.microsoft.hydralab.common.util.FileUtil;
Expand All @@ -18,7 +18,6 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

@Service
Expand All @@ -30,12 +29,12 @@ public class FileLoadUtil {
BlobStorageClient blobStorageClient;

public void clearAttachments(TestTask testTask) {
List<BlobFileInfo> attachments = testTask.getTestFileSet().getAttachments();
List<StorageFileInfo> attachments = testTask.getTestFileSet().getAttachments();
if (attachments == null) {
return;
}
for (BlobFileInfo attachment : attachments) {
if (BlobFileInfo.FileType.COMMON_FILE.equals(attachment.getFileType())) {
for (StorageFileInfo attachment : attachments) {
if (StorageFileInfo.FileType.COMMON_FILE.equals(attachment.getFileType())) {
File loadFolder = new File(appOptions.getLocation() + "/" + attachment.getLoadDir());
FileUtil.deleteFile(loadFolder);
}
Expand All @@ -44,29 +43,29 @@ public void clearAttachments(TestTask testTask) {
}

public void loadAttachments(TestTask testTask) {
List<BlobFileInfo> attachments = testTask.getTestFileSet().getAttachments();
List<StorageFileInfo> attachments = testTask.getTestFileSet().getAttachments();
if (attachments == null) {
return;
}
for (BlobFileInfo attachment : attachments) {
for (StorageFileInfo attachment : attachments) {
switch (attachment.getFileType()) {
case BlobFileInfo.FileType.WINDOWS_APP:
case StorageFileInfo.FileType.WINDOWS_APP:
installWinApp(attachment);
break;
case BlobFileInfo.FileType.COMMON_FILE:
case StorageFileInfo.FileType.COMMON_FILE:
loadCommonFile(attachment);
break;
case BlobFileInfo.FileType.APP_FILE:
case StorageFileInfo.FileType.APP_FILE:
File appFile = downloadFromBlob(attachment);
Assert.isTrue(appFile != null && appFile.exists(), "Download app file failed!");
testTask.setAppFile(appFile);
break;
case BlobFileInfo.FileType.TEST_APP_FILE:
case StorageFileInfo.FileType.TEST_APP_FILE:
File testAppFile = downloadFromBlob(attachment);
Assert.isTrue(testAppFile != null && testAppFile.exists(), "Download test app file failed!");
testTask.setTestAppFile(testAppFile);
break;
case BlobFileInfo.FileType.T2C_JSON_FILE:
case StorageFileInfo.FileType.T2C_JSON_FILE:
File testJsonFile = downloadFromBlob(attachment);
Assert.isTrue(testJsonFile != null && testJsonFile.exists(), "Download test json file failed!");
testTask.addTestJsonFile(testJsonFile);
Expand All @@ -77,7 +76,7 @@ public void loadAttachments(TestTask testTask) {
}
}

public void installWinApp(BlobFileInfo attachment) {
public void installWinApp(StorageFileInfo attachment) {
try {
Runtime runtime = Runtime.getRuntime();
File attachmentFile = downloadFromBlob(attachment, appOptions.getTestPackageLocation(), attachment.getBlobPath());
Expand All @@ -99,13 +98,13 @@ public void installWinApp(BlobFileInfo attachment) {

}

public void loadCommonFile(BlobFileInfo attachment) {
public void loadCommonFile(StorageFileInfo attachment) {
try {
File loadFolder = new File(appOptions.getLocation() + "/" + attachment.getLoadDir());
Assert.isTrue(!loadFolder.exists(), "Load file error : folder has been existed!");
log.info("Load common file start filename:{} path:{}", attachment.getFileName(), loadFolder.getAbsolutePath());
File attachmentFile = downloadFromBlob(attachment, appOptions.getLocation(), attachment.getLoadDir() + "/" + attachment.getFileName());
if (BlobFileInfo.LoadType.UNZIP.equalsIgnoreCase(attachment.getLoadType())) {
if (StorageFileInfo.LoadType.UNZIP.equalsIgnoreCase(attachment.getLoadType())) {
FileUtil.unzipFile(attachmentFile.getAbsolutePath(), loadFolder.getAbsolutePath());
}
log.info("Load common file success");
Expand All @@ -114,14 +113,14 @@ public void loadCommonFile(BlobFileInfo attachment) {
}
}

private File downloadFromBlob(BlobFileInfo attachment, String location, String targetFilePath) throws IOException {
private File downloadFromBlob(StorageFileInfo attachment, String location, String targetFilePath) throws IOException {
File file = new File(location, targetFilePath);
log.debug("download file from {} to {}", attachment.getBlobUrl(), file.getAbsolutePath());
blobStorageClient.downloadFileFromBlob(file, attachment.getBlobContainer(), attachment.getBlobPath());
return file;
}

private File downloadFromBlob(BlobFileInfo attachment) {
private File downloadFromBlob(StorageFileInfo attachment) {
File file = null;
try {
file = downloadFromBlob(attachment, appOptions.getTestPackageLocation(), attachment.getBlobPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.microsoft.hydralab.agent.runner.TestRunner;
import com.microsoft.hydralab.agent.runner.espresso.EspressoRunner;
import com.microsoft.hydralab.agent.test.BaseTest;
import com.microsoft.hydralab.common.entity.center.TestTaskSpec;
import com.microsoft.hydralab.common.entity.common.TestTaskSpec;
import com.microsoft.hydralab.common.entity.common.TestFileSet;
import com.microsoft.hydralab.common.entity.common.TestTask;
import com.microsoft.hydralab.common.management.DeviceManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.alibaba.fastjson.JSONObject;
import com.microsoft.hydralab.center.service.*;
import com.microsoft.hydralab.common.entity.agent.Result;
import com.microsoft.hydralab.common.entity.center.AgentUser;
import com.microsoft.hydralab.common.entity.common.AgentUser;
import com.microsoft.hydralab.common.entity.center.SysTeam;
import com.microsoft.hydralab.common.entity.center.SysUser;
import com.microsoft.hydralab.common.entity.common.AgentUpdateTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.microsoft.hydralab.common.entity.center.SysTeam;
import com.microsoft.hydralab.common.entity.center.SysUser;
import com.microsoft.hydralab.common.entity.common.*;
import com.microsoft.hydralab.common.entity.common.BlobFileInfo.ParserKey;
import com.microsoft.hydralab.common.entity.common.StorageFileInfo.ParserKey;
import com.microsoft.hydralab.common.util.*;
import com.microsoft.hydralab.common.util.PkgUtil.FILE_SUFFIX;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -108,7 +108,7 @@ public Result add(@CurrentSecurityContext SysUser requestor,

//Save app file to server
File tempAppFile = attachmentService.verifyAndSaveFile(appFile, CENTER_FILE_BASE_DIR + relativePath, false, null, new String[]{FILE_SUFFIX.APK_FILE, FILE_SUFFIX.IPA_FILE});
BlobFileInfo appBlobFile = new BlobFileInfo(tempAppFile, relativePath, BlobFileInfo.FileType.APP_FILE);
StorageFileInfo appBlobFile = new StorageFileInfo(tempAppFile, relativePath, StorageFileInfo.FileType.APP_FILE);
//Upload app file
appBlobFile = attachmentService.addAttachment(testFileSet.getId(), EntityFileRelation.EntityType.APP_FILE_SET, appBlobFile, tempAppFile, logger);
JSONObject appFileParser = appBlobFile.getFileParser();
Expand All @@ -121,7 +121,7 @@ public Result add(@CurrentSecurityContext SysUser requestor,
if (testAppFile != null && !testAppFile.isEmpty()) {
File tempTestAppFile = attachmentService.verifyAndSaveFile(testAppFile, CENTER_FILE_BASE_DIR + relativePath, false, null, new String[]{FILE_SUFFIX.APK_FILE, FILE_SUFFIX.JAR_FILE, FILE_SUFFIX.JSON_FILE});

BlobFileInfo testAppBlobFile = new BlobFileInfo(tempTestAppFile, relativePath, BlobFileInfo.FileType.TEST_APP_FILE);
StorageFileInfo testAppBlobFile = new StorageFileInfo(tempTestAppFile, relativePath, StorageFileInfo.FileType.TEST_APP_FILE);
//Upload app file
testAppBlobFile = attachmentService.addAttachment(testFileSet.getId(), EntityFileRelation.EntityType.APP_FILE_SET, testAppBlobFile, tempTestAppFile, logger);
testFileSet.getAttachments().add(testAppBlobFile);
Expand Down Expand Up @@ -213,8 +213,8 @@ public Result uploadAgentPackage(@RequestParam("packageFile") MultipartFile pack
String parentDir = CENTER_FILE_BASE_DIR + fileRelativePath;
try {
File savedPkg = attachmentService.verifyAndSaveFile(packageFile, parentDir, false, null, new String[]{FILE_SUFFIX.JAR_FILE});
BlobFileInfo blobFileInfo = new BlobFileInfo(savedPkg, fileRelativePath, BlobFileInfo.FileType.AGENT_PACKAGE);
return Result.ok(attachmentService.addFileInfo(blobFileInfo, savedPkg, EntityFileRelation.EntityType.AGENT_PACKAGE, logger));
StorageFileInfo storageFileInfo = new StorageFileInfo(savedPkg, fileRelativePath, StorageFileInfo.FileType.AGENT_PACKAGE);
return Result.ok(attachmentService.addFileInfo(storageFileInfo, savedPkg, EntityFileRelation.EntityType.AGENT_PACKAGE, logger));
} catch (HydraLabRuntimeException e) {
return Result.error(e.getCode(), e);
} catch (Exception e) {
Expand Down Expand Up @@ -332,7 +332,7 @@ public Result<List<TestJsonInfo>> testJsonHistory(@CurrentSecurityContext SysUse
@PostMapping("/api/package/queryAgentPackage")
public Result queryAgentPackage() {

return Result.ok(attachmentService.queryBlobFileByType(BlobFileInfo.FileType.AGENT_PACKAGE));
return Result.ok(attachmentService.queryBlobFileByType(StorageFileInfo.FileType.AGENT_PACKAGE));
}

/**
Expand Down Expand Up @@ -363,18 +363,18 @@ public Result addAttachment(@CurrentSecurityContext SysUser requestor,

String[] limitFileTypes = null;
switch (fileType) {
case BlobFileInfo.FileType.WINDOWS_APP:
case StorageFileInfo.FileType.WINDOWS_APP:
limitFileTypes = new String[]{FILE_SUFFIX.APPX_FILE};
break;
case BlobFileInfo.FileType.COMMON_FILE:
case StorageFileInfo.FileType.COMMON_FILE:
Assert.notNull(loadType, "loadType is required");
Assert.notNull(loadDir, "loadDir is required");
Assert.isTrue(FileUtil.isLegalFolderPath(loadDir), "illegal loadDir");
if (BlobFileInfo.LoadType.UNZIP.equals(loadType)) {
if (StorageFileInfo.LoadType.UNZIP.equals(loadType)) {
limitFileTypes = new String[]{FILE_SUFFIX.ZIP_FILE};
}
break;
case BlobFileInfo.FileType.T2C_JSON_FILE:
case StorageFileInfo.FileType.T2C_JSON_FILE:
limitFileTypes = new String[]{FILE_SUFFIX.JSON_FILE};
break;
default:
Expand All @@ -386,8 +386,8 @@ public Result addAttachment(@CurrentSecurityContext SysUser requestor,
String parentDir = CENTER_FILE_BASE_DIR + fileRelativePath;

File savedAttachment = attachmentService.verifyAndSaveFile(attachment, parentDir, false, newFileName, limitFileTypes);
BlobFileInfo blobFileInfo = new BlobFileInfo(savedAttachment, fileRelativePath, fileType, loadType, loadDir);
attachmentService.addAttachment(fileSetId, EntityFileRelation.EntityType.APP_FILE_SET, blobFileInfo, savedAttachment, logger);
StorageFileInfo storageFileInfo = new StorageFileInfo(savedAttachment, fileRelativePath, fileType, loadType, loadDir);
attachmentService.addAttachment(fileSetId, EntityFileRelation.EntityType.APP_FILE_SET, storageFileInfo, savedAttachment, logger);
testFileSet.setAttachments(attachmentService.getAttachments(fileSetId, EntityFileRelation.EntityType.APP_FILE_SET));
testFileSetService.saveFileSetToMem(testFileSet);
return Result.ok(testFileSet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.microsoft.hydralab.common.entity.agent.Result;
import com.microsoft.hydralab.common.entity.center.SysUser;
import com.microsoft.hydralab.common.entity.center.TestTaskQueuedInfo;
import com.microsoft.hydralab.common.entity.center.TestTaskSpec;
import com.microsoft.hydralab.common.entity.common.TestTaskSpec;
import com.microsoft.hydralab.common.entity.common.CriteriaType;
import com.microsoft.hydralab.common.entity.common.TestFileSet;
import com.microsoft.hydralab.common.entity.common.TestTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.
package com.microsoft.hydralab.center.repository;

import com.microsoft.hydralab.common.entity.center.AgentUser;
import com.microsoft.hydralab.common.entity.common.AgentUser;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.microsoft.hydralab.center.repository.AgentUserRepository;
import com.microsoft.hydralab.center.util.CenterConstant;
import com.microsoft.hydralab.center.util.SecretGenerator;
import com.microsoft.hydralab.common.entity.center.AgentUser;
import com.microsoft.hydralab.common.entity.common.AgentUser;
import com.microsoft.hydralab.common.entity.center.SysUser;
import com.microsoft.hydralab.common.entity.common.CriteriaType;
import com.microsoft.hydralab.common.util.CriteriaTypeUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.microsoft.hydralab.common.entity.agent.MobileDevice;
import com.microsoft.hydralab.common.entity.center.*;
import com.microsoft.hydralab.common.entity.common.*;
import com.microsoft.hydralab.common.repository.BlobFileInfoRepository;
import com.microsoft.hydralab.common.repository.StorageFileInfoRepository;
import com.microsoft.hydralab.common.repository.StatisticDataRepository;
import com.microsoft.hydralab.common.util.*;
import com.microsoft.hydralab.common.util.blob.BlobStorageClient;
Expand Down Expand Up @@ -73,7 +73,7 @@ public class DeviceAgentManagementService {
@Resource
TestTaskService testTaskService;
@Resource
BlobFileInfoRepository blobFileInfoRepository;
StorageFileInfoRepository storageFileInfoRepository;
@Resource
AttachmentService attachmentService;
@Resource
Expand Down Expand Up @@ -675,7 +675,7 @@ public JSONObject runTestTaskBySpec(TestTaskSpec testTaskSpec) {
private JSONObject runT2CTest(TestTaskSpec testTaskSpec) {
// TODO: upgrade to assign task to agent and check the available device count on the agent
JSONObject result = new JSONObject();
BlobFileInfo testAppFileInfo = attachmentService.filterFirstAttachment(testTaskSpec.testFileSet.getAttachments(), BlobFileInfo.FileType.TEST_APP_FILE);
StorageFileInfo testAppFileInfo = attachmentService.filterFirstAttachment(testTaskSpec.testFileSet.getAttachments(), StorageFileInfo.FileType.TEST_APP_FILE);
if (testAppFileInfo != null) {
File testApkFile = new File(CENTER_FILE_BASE_DIR, testAppFileInfo.getBlobPath());
TestInfo testInfo;
Expand Down Expand Up @@ -915,8 +915,8 @@ public void updateAgentPackage(String agentId, String fileId) throws Exception {
//check is agent connected
AgentSessionInfo agentSessionInfoByAgentId = getAgentSessionInfoByAgentId(agentId);
Assert.notNull(agentSessionInfoByAgentId, "Agent Offline!");
BlobFileInfo packageInfo = blobFileInfoRepository.findById(fileId).get();
if (packageInfo == null || !BlobFileInfo.FileType.AGENT_PACKAGE.equals(packageInfo.getFileType())) {
StorageFileInfo packageInfo = storageFileInfoRepository.findById(fileId).get();
if (packageInfo == null || !StorageFileInfo.FileType.AGENT_PACKAGE.equals(packageInfo.getFileType())) {
throw new Exception("Error file info!");
}
AgentUser agentUser = agentSessionInfoByAgentId.agentUser;
Expand Down
Loading

0 comments on commit f530d16

Please sign in to comment.