feat(制品库功能开发): 快照制品库创建接口开发

1. 完成Maven格式制品库的制品同步到快照库逻辑开发
- 从数据库中获取该制品库的制品记录,并转换为快照的制品记录
- 若制品记录不存在文件标识时,则通过repoUrl+制品path的方式从Nexus下载
- 调用Maven上传接口,将制品上传到快照库(Maven上传接口支持快照库制品上传)
2. 锁定制品库逻辑调整为根据制品库id进行锁定,防止制品库、产品库、快照库存在同名的情况
This commit is contained in:
OTTO 2024-07-15 16:33:34 +08:00
parent 416b9856af
commit 480ac9b376
12 changed files with 173 additions and 96 deletions

View File

@ -170,10 +170,10 @@ public class CacheConstants
/**
* 锁定企业下制品库 Key前缀
*/
public final static String LOCK_ENTERPRISE_IDENTIFIER_REPO_KEY = "lock_enterprise_identifier_repo_key:";
public final static String LOCK_ENTERPRISE_IDENTIFIER_REPO_ID_KEY = "lock_enterprise_identifier_repo_id_key:";
public static String getLockEnterpriseIdentifierRepoKey(String enterpriseIdentifier, String repoName) {
return LOCK_ENTERPRISE_IDENTIFIER_REPO_KEY + enterpriseIdentifier + ":" + repoName;
public static String getLockEnterpriseIdentifierRepoIdKey(String enterpriseIdentifier, Long repoId) {
return LOCK_ENTERPRISE_IDENTIFIER_REPO_ID_KEY + enterpriseIdentifier + ":" + repoId;
}
/**

View File

@ -35,11 +35,11 @@ public class PmsProductLibraryRepositoriesController extends BaseController {
* 获取制品库锁定状态
*/
// @RequiresPermissions("pms:pmsProductLibraryRepositories:list")
@GetMapping("/lockStatus/{repoName}")
@GetMapping("/lockStatus/{repoId}")
@ApiOperation(value = "获取制品库锁定状态")
public GenericsAjaxResult<Boolean> getRepoLockStatus(@PathVariable String enterpriseIdentifier,
@ApiParam(value = "制品库名称", required = true) @PathVariable String repoName) {
return GenericsAjaxResult.success(pmsProductLibraryRepositoriesService.getLockRepositoryStatus(enterpriseIdentifier, repoName));
@ApiParam(value = "制品库Id", required = true) @PathVariable Long repoId) {
return GenericsAjaxResult.success(pmsProductLibraryRepositoriesService.getLockRepositoryStatus(enterpriseIdentifier, repoId));
}
/**

View File

@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.microservices.common.core.utils.StringUtils;
import com.microservices.common.core.utils.sign.Base64;
import com.microservices.common.core.web.domain.BaseEntity;
import com.microservices.pms.productLibrary.domain.vo.AssetMavenInputVo;
import com.microservices.pms.productLibrary.domain.vo.ComponentMavenInputVo;
import com.microservices.pms.productLibrary.domain.vo.NexusMavenAssetVo;
import io.swagger.annotations.ApiModel;
@ -13,6 +14,9 @@ import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
/**
* 制品库-制品对象 pms_product_library_component
*
@ -133,8 +137,25 @@ public class PmsProductLibraryComponent extends BaseEntity {
this.setAttributes(JSONObject.toJSONString(nexusMavenAssetVo));
}
public ComponentMavenInputVo toComponentMavenInputVo() {
public ComponentMavenInputVo toComponentMavenInputVo(PmsProductLibraryRepositories snapshotRepo) {
ComponentMavenInputVo target = new ComponentMavenInputVo();
target.setRepoName(snapshotRepo.getName());
target.setSnapshotName(snapshotRepo.getSnapshotName());
target.setEnterpriseIdentifier(snapshotRepo.getPmsEnterpriseIdentifier());
JSONObject attributesObj = JSONObject.parseObject(this.getAttributes());
JSONObject mavenObj = attributesObj.getJSONObject("maven2");
AssetMavenInputVo assetMavenInputVo = new AssetMavenInputVo();
assetMavenInputVo.setClassifier(mavenObj.getString("classifier"));
assetMavenInputVo.setExtension(mavenObj.getString("extension"));
assetMavenInputVo.setFileIdentifier(this.getFileIdentifier());
List<AssetMavenInputVo> assetMavenInputVoList = new ArrayList<>();
assetMavenInputVoList.add(assetMavenInputVo);
target.setAssetList(assetMavenInputVoList);
target.setGroupId(mavenObj.getString("groupId"));
target.setArtifactId(mavenObj.getString("artifactId"));
target.setVersion(this.getVersion());
// 不自动生成POM文件
target.setGeneratePom(false);
return target;
}
}

View File

@ -167,7 +167,12 @@ public class PmsProductLibraryRepositories extends BaseEntity {
}
public String getNexusRepositoriesName() {
return getNexusRepositoriesName(pmsEnterpriseIdentifier, name);
if (StringUtils.isEmpty(snapshotName)) {
return getNexusRepositoriesName(pmsEnterpriseIdentifier, name);
} else {
return getNexusProductRepositoriesSnapshotName(pmsEnterpriseIdentifier, name, snapshotName);
}
}
public String getNexusProductRepositoriesName() {

View File

@ -23,6 +23,8 @@ public class AssetMavenInputVo {
@ApiModelProperty(value = "文件标识")
@NotBlank(message = "制品文件标识不能为空")
private String fileIdentifier;
@ApiModelProperty(value = "文件流", hidden = true)
private byte[] fileBytes;
public String getComponentAssetName(ComponentMavenInputVo componentMavenInputVo) {
return String.format("%s-%s-%s.%s",

View File

@ -21,6 +21,6 @@ public class AssetRawInputVo {
@ApiModelProperty(value = "文件标识")
@NotBlank(message = "文件标识不能为空")
private String fileIdentifier;
@ApiModelProperty(value = "文件标识", hidden = true)
@ApiModelProperty(value = "文件", hidden = true)
private byte[] fileBytes;
}

View File

@ -1,5 +1,6 @@
package com.microservices.pms.productLibrary.domain.vo;
import com.microservices.common.core.utils.StringUtils;
import com.microservices.pms.productLibrary.domain.PmsProductLibraryComponent;
import com.microservices.pms.productLibrary.domain.PmsProductLibraryRepositories;
import io.swagger.annotations.ApiModel;
@ -22,6 +23,8 @@ import java.util.List;
public class ComponentMavenInputVo {
@ApiModelProperty(value = "制品库名称", hidden = true)
private String repoName;
@ApiModelProperty(value = "快照库名称", hidden = true)
private String snapshotName;
@ApiModelProperty(value = "组织标识", hidden = true)
private String enterpriseIdentifier;
@ApiModelProperty(value = "文件列表")
@ -43,10 +46,19 @@ public class ComponentMavenInputVo {
private String packaging;
public String getNexusRepoName() {
return PmsProductLibraryRepositories.getNexusRepositoriesName(
enterpriseIdentifier,
repoName
);
if (StringUtils.isEmpty(snapshotName)) {
return PmsProductLibraryRepositories.getNexusRepositoriesName(
enterpriseIdentifier,
repoName
);
} else {
return PmsProductLibraryRepositories.getNexusProductRepositoriesSnapshotName(
enterpriseIdentifier,
repoName,
snapshotName
);
}
}
public String getPomComponentName() {

View File

@ -30,14 +30,6 @@ public interface IPmsProductLibraryComponentService {
*/
public NexusComponentResultVo<List<NexusResultDataVo>> selectPmsProductLibraryComponentListByNexus(String enterpriseIdentifier, ComponentSearchVo componentSearchVo, boolean isProduct);
/**
* 新增制品库-制品
*
* @param pmsProductLibraryComponent 制品库-制品
* @return 结果
*/
public int insertPmsProductLibraryComponent(PmsProductLibraryComponent pmsProductLibraryComponent);
/**
* 修改制品库-制品
*

View File

@ -167,11 +167,13 @@ public interface IPmsProductLibraryRepositoriesService {
*/
boolean insertPmsProductLibrarySnapshot(ProductRepositoriesSnapshotInputVo productRepositoriesSnapshotInputVo);
void checkLockRepositoryStatus(String enterpriseIdentifier, String repoName);
void checkLockRepositoryStatus(String enterpriseIdentifier, Long repoId);
void lockRepository(String enterpriseIdentifier, String repoName);
void lockRepository(String enterpriseIdentifier, Long repoId);
void unlockRepository(String enterpriseIdentifier, String repoName);
void unlockRepository(String enterpriseIdentifier, Long repoId);
Boolean getLockRepositoryStatus(String enterpriseIdentifier, String repoName);
Boolean getLockRepositoryStatus(String enterpriseIdentifier, Long repoId);
PmsProductLibraryRepositories selectPmsProductLibrarySnapshotByName(String enterpriseIdentifier, String repoName, String snapshotName);
}

View File

@ -12,6 +12,8 @@ import com.microservices.pms.productLibrary.service.IPmsProductLibraryRepositori
import com.microservices.pms.utils.CustomExecutorFactory;
import com.microservices.pms.utils.NexusRequestHelper;
import com.microservices.pms.utils.NexusRequestUrl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@ -25,6 +27,7 @@ import java.util.List;
@Service
public class PmsProductLibraryAsyncServiceImpl implements IPmsProductLibraryAsyncService {
private static final Logger log = LoggerFactory.getLogger(PmsProductLibraryAsyncServiceImpl.class);
@Autowired
private NexusRequestHelper nexusRequestHelper;
@Autowired
@ -68,7 +71,7 @@ public class PmsProductLibraryAsyncServiceImpl implements IPmsProductLibraryAsyn
@Override
public void asyncAddCommonAssetToProductRepo(PmsProductLibraryRepositories productRepo, PmsProductLibraryRepositories repo, List<NexusAssetResultDataVo> nexusAssetResultDataVoList) {
CustomExecutorFactory.threadPoolExecutor.execute(() -> {
pmsProductLibraryRepositoriesService.lockRepository(repo.getPmsEnterpriseIdentifier(), repo.getName());
pmsProductLibraryRepositoriesService.lockRepository(repo.getPmsEnterpriseIdentifier(), repo.getId());
for (NexusAssetResultDataVo nexusAssetResultDataVo : nexusAssetResultDataVoList) {
if (StringUtils.isEmpty(nexusAssetResultDataVo.getVersion())) {
nexusAssetResultDataVo.setVersion("");
@ -93,44 +96,73 @@ public class PmsProductLibraryAsyncServiceImpl implements IPmsProductLibraryAsyn
insertRawComponentToProductRepo(productRepo, repo, nexusAssetResultDataVo, assetRawInputVoList);
}
}
pmsProductLibraryRepositoriesService.unlockRepository(repo.getPmsEnterpriseIdentifier(), repo.getName());
pmsProductLibraryRepositoriesService.unlockRepository(repo.getPmsEnterpriseIdentifier(), repo.getId());
});
}
@Override
public void syncRepoToSnapshotRepo(PmsProductLibraryRepositories repo, PmsProductLibraryRepositories snapshotRepo) {
pmsProductLibraryRepositoriesService.lockRepository(repo.getPmsEnterpriseIdentifier(), repo.getName());
ProductLibraryRepositoriesFormatEnum formatEnum = ProductLibraryRepositoriesFormatEnum.getByKey(repo.getFormat());
switch (formatEnum) {
case MAVEN: {
CustomExecutorFactory.threadPoolExecutor.execute(() -> {
try {
pmsProductLibraryRepositoriesService.lockRepository(repo.getPmsEnterpriseIdentifier(), repo.getId());
ProductLibraryRepositoriesFormatEnum formatEnum = ProductLibraryRepositoriesFormatEnum.getByKey(repo.getFormat());
switch (formatEnum) {
case MAVEN: {
syncMavenRepoToSnapshotRepo(repo, snapshotRepo);
break;
}
case NPM: {
break;
}
case PYPI: {
break;
}
case RAW:
case GO:
case CONDA:
case XXXXX: {
break;
}
}
} catch (Exception e) {
log.error("同步制品库制品到快照库时失败(制品库id[{}],快照库id[{}]):{}", repo.getId(), snapshotRepo.getId(), e.getMessage());
} finally {
pmsProductLibraryRepositoriesService.unlockRepository(repo.getPmsEnterpriseIdentifier(), repo.getId());
}
break;
}
case NPM: {
break;
}
case PYPI: {
break;
}
case RAW:
case GO:
case CONDA:
case XXXXX: {
break;
}
}
pmsProductLibraryRepositoriesService.unlockRepository(repo.getPmsEnterpriseIdentifier(), repo.getName());
});
}
private void syncMavenRepoToSnapshotRepo(PmsProductLibraryRepositories repo, PmsProductLibraryRepositories snapshotRepo) {
List<PmsProductLibraryComponent> pmsProductLibraryComponentList =
pmsProductLibraryComponentService.selectPmsProductLibraryComponentListByDatabase(repo.getId());
for (PmsProductLibraryComponent pmsProductLibraryComponent : pmsProductLibraryComponentList) {
ComponentMavenInputVo componentMavenInputVo = pmsProductLibraryComponent.toComponentMavenInputVo();
pmsProductLibraryComponentService.insertMavenComponent(componentMavenInputVo);
ComponentMavenInputVo componentMavenInputVo = pmsProductLibraryComponent.toComponentMavenInputVo(snapshotRepo);
List<AssetMavenInputVo> assetMavenInputVoList = getAssetMavenInputVoList(repo, pmsProductLibraryComponent, componentMavenInputVo);
if (assetMavenInputVoList != null) {
componentMavenInputVo.setAssetList(assetMavenInputVoList);
pmsProductLibraryComponentService.insertMavenComponent(componentMavenInputVo);
}
}
}
private List<AssetMavenInputVo> getAssetMavenInputVoList(PmsProductLibraryRepositories repo, PmsProductLibraryComponent pmsProductLibraryComponent, ComponentMavenInputVo componentMavenInputVo) {
List<AssetMavenInputVo> assetMavenInputVoList = componentMavenInputVo.getAssetList();
for (AssetMavenInputVo assetMavenInputVo : assetMavenInputVoList) {
if (StringUtils.isEmpty(assetMavenInputVo.getFileIdentifier())) {
assetMavenInputVo.setFileIdentifier("");
String nexusFileUrl =
EscapeUtil.removeExtraSlashOfUrl(repo.getUrl() + "/" + pmsProductLibraryComponent.getPath());
byte[] fileBytes = nexusRequestHelper.getFileBytes(nexusFileUrl);
if (fileBytes == null) {
return null;
}
assetMavenInputVo.setFileBytes(fileBytes);
}
}
return assetMavenInputVoList;
}
private void insertRawComponentToProductRepo(PmsProductLibraryRepositories productRepo,
PmsProductLibraryRepositories repo,
NexusAssetResultDataVo nexusAssetResultDataVo,

View File

@ -63,14 +63,19 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
return pmsProductLibraryComponentMapper.selectPmsProductLibraryComponentById(id);
}
private PmsProductLibraryRepositories getPmsProductLibraryRepositoriesByIsProduct(Boolean isProduct, String enterpriseIdentifier, String repoName) {
private PmsProductLibraryRepositories getPmsProductLibraryRepositories(Boolean isProduct, String enterpriseIdentifier, String repoName, String snapshotName) {
PmsProductLibraryRepositories pmsProductLibraryRepositories;
if (isProduct) {
pmsProductLibraryRepositories =
pmsProductLibraryRepositoriesService.selectPmsProductLibraryByName(enterpriseIdentifier, repoName);
} else {
pmsProductLibraryRepositories =
pmsProductLibraryRepositoriesService.selectPmsProductLibraryRepositoriesByName(enterpriseIdentifier, repoName);
if (StringUtils.isNotEmpty(snapshotName)) {
pmsProductLibraryRepositories =
pmsProductLibraryRepositoriesService.selectPmsProductLibrarySnapshotByName(enterpriseIdentifier, repoName, snapshotName);
} else {
pmsProductLibraryRepositories =
pmsProductLibraryRepositoriesService.selectPmsProductLibraryRepositoriesByName(enterpriseIdentifier, repoName);
}
}
return pmsProductLibraryRepositories;
}
@ -86,7 +91,7 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
@Override
public NexusComponentResultVo<List<NexusResultDataVo>> selectPmsProductLibraryComponentListByNexus(String enterpriseIdentifier, ComponentSearchVo componentSearchVo, boolean isProduct) {
PmsProductLibraryRepositories pmsProductLibraryRepositories =
getPmsProductLibraryRepositoriesByIsProduct(isProduct, enterpriseIdentifier, componentSearchVo.getRepositoryName());
getPmsProductLibraryRepositories(isProduct, enterpriseIdentifier, componentSearchVo.getRepositoryName(), null);
componentSearchVo.setRepositoryName(pmsProductLibraryRepositories.getNexusRepositoriesName(isProduct));
NexusComponentSearchVo<ComponentSearchVo> nexusComponentSearchVo = NexusComponentSearchVo.toRead(componentSearchVo, nexusRequestHelper.getNexusTid());
@ -114,7 +119,7 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
@Override
public NexusComponentResultVo<List<NexusResultDataVo>> selectPmsProductLibraryKeyComponentList(String enterpriseIdentifier, ComponentSearchVo componentSearchVo) {
PmsProductLibraryRepositories repo =
getPmsProductLibraryRepositoriesByIsProduct(false, enterpriseIdentifier, componentSearchVo.getRepositoryName());
getPmsProductLibraryRepositories(false, enterpriseIdentifier, componentSearchVo.getRepositoryName(), null);
componentSearchVo.setRepositoryName(repo.getNexusRepositoriesName(false));
// Docker类型调用Nexus获取制品列表接口获取
if (ProductLibraryRepositoriesFormatEnum.DOCKER.getKey().equals(repo.getFormat())) {
@ -228,7 +233,7 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
@Override
public NexusComponentResultVo<NexusAssetResultDataVo> getAssetDetailByAssetId(String enterpriseIdentifier, String repoName, String assetId, boolean isProduct) {
PmsProductLibraryRepositories pmsProductLibraryRepositories = getPmsProductLibraryRepositoriesByIsProduct(isProduct, enterpriseIdentifier, repoName);
PmsProductLibraryRepositories pmsProductLibraryRepositories = getPmsProductLibraryRepositories(isProduct, enterpriseIdentifier, repoName, null);
NexusComponentSearchVo<String> nexusComponentSearchVo =
NexusComponentSearchVo.toReadAsset(pmsProductLibraryRepositories.getNexusRepositoriesName(isProduct), assetId, nexusRequestHelper.getNexusTid());
NexusComponentResultVo<NexusAssetResultDataVo> assetResultDataVo =
@ -281,7 +286,7 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
@Override
public NexusComponentResultVo<NexusComponentResultDataVo> getComponentDetailByComponentId(String enterpriseIdentifier, String repoName, String componentId, boolean isProduct) {
PmsProductLibraryRepositories pmsProductLibraryRepositories = getPmsProductLibraryRepositoriesByIsProduct(isProduct, enterpriseIdentifier, repoName);
PmsProductLibraryRepositories pmsProductLibraryRepositories = getPmsProductLibraryRepositories(isProduct, enterpriseIdentifier, repoName, null);
NexusComponentSearchVo<String> nexusComponentSearchVo =
NexusComponentSearchVo.toReadComponent(pmsProductLibraryRepositories.getNexusRepositoriesName(isProduct), componentId, nexusRequestHelper.getNexusTid());
NexusComponentResultVo<NexusComponentResultDataVo> componentResultVo =
@ -318,7 +323,7 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
@Override
public NexusComponentResultVo<Boolean> getCanDeleteFolderByNode(String enterpriseIdentifier, ComponentSearchVo componentSearchVo, boolean isProduct) {
PmsProductLibraryRepositories pmsProductLibraryRepositories = getPmsProductLibraryRepositoriesByIsProduct(isProduct, enterpriseIdentifier, componentSearchVo.getRepositoryName());
PmsProductLibraryRepositories pmsProductLibraryRepositories = getPmsProductLibraryRepositories(isProduct, enterpriseIdentifier, componentSearchVo.getRepositoryName(), null);
NexusComponentSearchVo<String> nexusComponentSearchVo =
NexusComponentSearchVo.toCanDeleteFolder(pmsProductLibraryRepositories.getNexusRepositoriesName(isProduct), componentSearchVo.getNode(), nexusRequestHelper.getNexusTid());
return nexusRequestHelper.doRequestToJavaObject(
@ -331,7 +336,7 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
@Override
public NexusComponentResultVo<Boolean> getCanDeleteComponentByComponentId(String enterpriseIdentifier, String repoName, String componentId, boolean isProduct) {
PmsProductLibraryRepositories pmsProductLibraryRepositories = getPmsProductLibraryRepositoriesByIsProduct(isProduct, enterpriseIdentifier, repoName);
PmsProductLibraryRepositories pmsProductLibraryRepositories = getPmsProductLibraryRepositories(isProduct, enterpriseIdentifier, repoName, null);
NexusComponentSearchVo<String> nexusComponentSearchVo =
NexusComponentSearchVo.toCanDeleteComponent(pmsProductLibraryRepositories.getNexusRepositoriesName(isProduct), componentId, nexusRequestHelper.getNexusTid());
return nexusRequestHelper.doRequestToJavaObject(
@ -344,7 +349,7 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
@Override
public NexusComponentResultVo<Boolean> getCanDeleteAssetByAssetId(String enterpriseIdentifier, String repoName, String assetId, boolean isProduct) {
PmsProductLibraryRepositories pmsProductLibraryRepositories = getPmsProductLibraryRepositoriesByIsProduct(isProduct, enterpriseIdentifier, repoName);
PmsProductLibraryRepositories pmsProductLibraryRepositories = getPmsProductLibraryRepositories(isProduct, enterpriseIdentifier, repoName, null);
NexusComponentSearchVo<String> nexusComponentSearchVo =
NexusComponentSearchVo.toCanDeleteAsset(pmsProductLibraryRepositories.getNexusRepositoriesName(), assetId, nexusRequestHelper.getNexusTid());
return nexusRequestHelper.doRequestToJavaObject(
@ -357,8 +362,8 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
@Override
public NexusComponentResultVo<List<String>> deleteAssetByAssetId(String enterpriseIdentifier, String repoName, String assetId, boolean isProduct) {
pmsProductLibraryRepositoriesService.checkLockRepositoryStatus(enterpriseIdentifier, repoName);
PmsProductLibraryRepositories pmsProductLibraryRepositories = getPmsProductLibraryRepositoriesByIsProduct(isProduct, enterpriseIdentifier, repoName);
PmsProductLibraryRepositories pmsProductLibraryRepositories = getPmsProductLibraryRepositories(isProduct, enterpriseIdentifier, repoName, null);
pmsProductLibraryRepositoriesService.checkLockRepositoryStatus(enterpriseIdentifier, pmsProductLibraryRepositories.getId());
NexusComponentSearchVo<String> nexusComponentSearchVo =
NexusComponentSearchVo.toDeleteAsset(pmsProductLibraryRepositories.getNexusRepositoriesName(isProduct), assetId, nexusRequestHelper.getNexusTid());
NexusComponentResultVo<List<String>> assetResultDataVo =
@ -374,8 +379,8 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
@Override
public NexusComponentResultVo<List<String>> deleteComponentByComponentId(String enterpriseIdentifier, String repoName, String componentId, boolean isProduct) {
pmsProductLibraryRepositoriesService.checkLockRepositoryStatus(enterpriseIdentifier, repoName);
PmsProductLibraryRepositories pmsProductLibraryRepositories = getPmsProductLibraryRepositoriesByIsProduct(isProduct, enterpriseIdentifier, repoName);
PmsProductLibraryRepositories pmsProductLibraryRepositories = getPmsProductLibraryRepositories(isProduct, enterpriseIdentifier, repoName, null);
pmsProductLibraryRepositoriesService.checkLockRepositoryStatus(enterpriseIdentifier, pmsProductLibraryRepositories.getId());
NexusComponentSearchVo<String> nexusComponentSearchVo =
NexusComponentSearchVo.toDeleteComponent(pmsProductLibraryRepositories.getNexusRepositoriesName(isProduct), componentId, nexusRequestHelper.getNexusTid());
NexusComponentResultVo<List<String>> assetResultDataVo =
@ -391,8 +396,8 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
@Override
public NexusComponentResultVo<Object> deleteFolderByNode(String enterpriseIdentifier, ComponentSearchVo componentSearchVo, boolean isProduct) {
pmsProductLibraryRepositoriesService.checkLockRepositoryStatus(enterpriseIdentifier, componentSearchVo.getRepositoryName());
PmsProductLibraryRepositories pmsProductLibraryRepositories = getPmsProductLibraryRepositoriesByIsProduct(isProduct, enterpriseIdentifier, componentSearchVo.getRepositoryName());
PmsProductLibraryRepositories pmsProductLibraryRepositories = getPmsProductLibraryRepositories(isProduct, enterpriseIdentifier, componentSearchVo.getRepositoryName(), null);
pmsProductLibraryRepositoriesService.checkLockRepositoryStatus(enterpriseIdentifier, pmsProductLibraryRepositories.getId());
NexusComponentSearchVo<String> nexusComponentSearchVo =
NexusComponentSearchVo.toDeleteFolder(pmsProductLibraryRepositories.getNexusRepositoriesName(isProduct), componentSearchVo.getNode(), nexusRequestHelper.getNexusTid());
NexusComponentResultVo<Object> assetResultDataVo =
@ -448,9 +453,7 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
* @param pmsProductLibraryComponent 制品库-制品
* @return 结果
*/
@Override
public int insertPmsProductLibraryComponent(PmsProductLibraryComponent pmsProductLibraryComponent) {
pmsProductLibraryRepositoriesService.checkLockRepositoryStatus(pmsProductLibraryComponent.getPmsEnterpriseIdentifier(), pmsProductLibraryComponent.getName());
PmsEnterprise pmsEnterprise = pmsEnterpriseService.selectPmsEnterpriseByIdentifier(pmsProductLibraryComponent.getPmsEnterpriseIdentifier());
PmsProductLibraryComponent oldPmsProductLibraryComponent =
pmsProductLibraryComponentMapper.selectPmsProductLibraryComponentByPath(
@ -478,7 +481,7 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
*/
@Override
public int updatePmsProductLibraryComponent(PmsProductLibraryComponent pmsProductLibraryComponent) {
pmsProductLibraryRepositoriesService.checkLockRepositoryStatus(pmsProductLibraryComponent.getPmsEnterpriseIdentifier(), pmsProductLibraryComponent.getName());
pmsProductLibraryRepositoriesService.checkLockRepositoryStatus(pmsProductLibraryComponent.getPmsEnterpriseIdentifier(), pmsProductLibraryComponent.getId());
pmsProductLibraryComponent.setUpdateBy(SecurityUtils.getUsername());
pmsProductLibraryComponent.setUpdateTime(DateUtils.getNowDate());
return pmsProductLibraryComponentMapper.updatePmsProductLibraryComponent(pmsProductLibraryComponent);
@ -488,11 +491,13 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
public Boolean insertMavenComponent(ComponentMavenInputVo componentMavenInputVo) {
// 构建制品列表用于数据库记录
List<PmsProductLibraryComponent> pmsProductLibraryComponents = new ArrayList<>();
PmsProductLibraryRepositories repo =
pmsProductLibraryRepositoriesService.selectPmsProductLibraryRepositoriesByName(
componentMavenInputVo.getEnterpriseIdentifier(),
componentMavenInputVo.getRepoName());
pmsProductLibraryRepositoriesService.checkLockRepositoryStatus(repo.getPmsEnterpriseIdentifier(), repo.getName());
PmsProductLibraryRepositories repo = getPmsProductLibraryRepositories(
false,
componentMavenInputVo.getEnterpriseIdentifier(),
componentMavenInputVo.getRepoName(),
componentMavenInputVo.getSnapshotName()
);
pmsProductLibraryRepositoriesService.checkLockRepositoryStatus(repo.getPmsEnterpriseIdentifier(), repo.getId());
if (!ProductLibraryRepositoriesFormatEnum.MAVEN.getKey().equals(repo.getFormat())) {
throw new ServiceException("该制品库非Maven格式无法上传(制品库名称[%s])", repo.getName());
}
@ -524,11 +529,17 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
pmsProductLibraryComponents.add(componentAsset);
addTextBody(builder, String.format("maven2.asset%d.extension", i + 1), assetMavenInputVo.getExtension());
addTextBody(builder, String.format("maven2.asset%d.classifier", i + 1), assetMavenInputVo.getClassifier());
SysFileBytes fileBytes = FeignUtils.getReturnData(
fileService.getFileEntityByIdentifier(assetMavenInputVo.getFileIdentifier(), SecurityConstants.INNER)
);
if (fileBytes == null) {
throw new ServiceException("制品文件读取失败");
SysFileBytes fileBytes = new SysFileBytes();
if (assetMavenInputVo.getFileBytes() != null) {
fileBytes.setFileBytes(assetMavenInputVo.getFileBytes());
fileBytes.setFileName(componentAssetName);
} else {
fileBytes = FeignUtils.getReturnData(
fileService.getFileEntityByIdentifier(assetMavenInputVo.getFileIdentifier(), SecurityConstants.INNER)
);
if (fileBytes == null) {
throw new ServiceException("制品文件读取失败");
}
}
builder.addBinaryBody(String.format("maven2.asset%d", i + 1), fileBytes.getFileBytes(), ContentType.DEFAULT_BINARY, fileBytes.getFileName());
}
@ -550,11 +561,11 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
public Boolean insertRawComponent(ComponentRawInputVo componentRawInputVo) {
// 构建制品列表用于数据库记录
List<PmsProductLibraryComponent> pmsProductLibraryComponents = new ArrayList<>();
PmsProductLibraryRepositories repo = getPmsProductLibraryRepositoriesByIsProduct(
PmsProductLibraryRepositories repo = getPmsProductLibraryRepositories(
ProductLibraryRepositoriesFormatEnum.isProduct(componentRawInputVo.getFormat()),
componentRawInputVo.getEnterpriseIdentifier(),
componentRawInputVo.getRepoName());
pmsProductLibraryRepositoriesService.checkLockRepositoryStatus(repo.getPmsEnterpriseIdentifier(), repo.getName());
componentRawInputVo.getRepoName(), null);
pmsProductLibraryRepositoriesService.checkLockRepositoryStatus(repo.getPmsEnterpriseIdentifier(), repo.getId());
if (!componentRawInputVo.getFormat().equals(repo.getFormat())) {
throw new ServiceException("该制品库非%s格式无法上传(制品库名称[%s])", componentRawInputVo.getFormat(), repo.getName());
@ -610,7 +621,7 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
pmsProductLibraryRepositoriesService.selectPmsProductLibraryRepositoriesByName(
componentInputVo.getEnterpriseIdentifier(),
componentInputVo.getRepoName());
pmsProductLibraryRepositoriesService.checkLockRepositoryStatus(repo.getPmsEnterpriseIdentifier(), repo.getName());
pmsProductLibraryRepositoriesService.checkLockRepositoryStatus(repo.getPmsEnterpriseIdentifier(), repo.getId());
if (!ProductLibraryRepositoriesFormatEnum.NPM.getKey().equals(repo.getFormat())) {
throw new ServiceException("该制品库非Npm格式无法上传(制品库名称[%s])", repo.getName());
}
@ -637,7 +648,7 @@ public class PmsProductLibraryComponentServiceImpl implements IPmsProductLibrary
pmsProductLibraryRepositoriesService.selectPmsProductLibraryRepositoriesByName(
componentInputVo.getEnterpriseIdentifier(),
componentInputVo.getRepoName());
pmsProductLibraryRepositoriesService.checkLockRepositoryStatus(repo.getPmsEnterpriseIdentifier(), repo.getName());
pmsProductLibraryRepositoriesService.checkLockRepositoryStatus(repo.getPmsEnterpriseIdentifier(), repo.getId());
if (!ProductLibraryRepositoriesFormatEnum.PYPI.getKey().equals(repo.getFormat())) {
throw new ServiceException("该制品库非Pypi格式无法上传(制品库名称[%s])", repo.getName());
}

View File

@ -62,7 +62,7 @@ public class PmsProductLibraryRepositoriesServiceImpl implements IPmsProductLibr
return pmsProductLibraryRepositories;
}
@Override
public PmsProductLibraryRepositories selectPmsProductLibrarySnapshotByName(String enterpriseIdentifier, String repoName, String snapshotName) {
PmsProductLibraryRepositories pmsProductLibraryRepositories =
pmsProductLibraryRepositoriesMapper.selectPmsProductLibrarySnapshotByName(enterpriseIdentifier, repoName, snapshotName);
@ -165,13 +165,13 @@ public class PmsProductLibraryRepositoriesServiceImpl implements IPmsProductLibr
@Override
public boolean insertPmsProductLibrarySnapshot(ProductRepositoriesSnapshotInputVo snapshotInputVo) {
checkLockRepositoryStatus(snapshotInputVo.getEnterpriseIdentifier(), snapshotInputVo.getRepoName());
// 未填快照库名称将根据时分秒生成名称
if (StringUtils.isEmpty(snapshotInputVo.getName())) {
snapshotInputVo.setName(DateUtils.dateTimeNow());
}
PmsProductLibraryRepositories repo =
selectPmsProductLibraryRepositoriesByName(snapshotInputVo.getEnterpriseIdentifier(), snapshotInputVo.getRepoName());
checkLockRepositoryStatus(snapshotInputVo.getEnterpriseIdentifier(), repo.getId());
if (ProductLibraryRepositoriesFormatEnum.DOCKER.getKey().equals(repo.getFormat())) {
throw new ServiceException("Docker格式制品库不支持创建快照");
}
@ -324,10 +324,10 @@ public class PmsProductLibraryRepositoriesServiceImpl implements IPmsProductLibr
*/
@Override
public int updateHostedPmsProductLibraryRepositories(HostedRepositoriesOperateVo hostedRepositoriesOperateVo) {
checkLockRepositoryStatus(hostedRepositoriesOperateVo.getEnterpriseIdentifier(), hostedRepositoriesOperateVo.getName());
PmsProductLibraryRepositories oldRepo = selectPmsProductLibraryRepositoriesByName(
hostedRepositoriesOperateVo.getEnterpriseIdentifier(),
hostedRepositoriesOperateVo.getName());
checkLockRepositoryStatus(hostedRepositoriesOperateVo.getEnterpriseIdentifier(), oldRepo.getId());
hostedRepositoriesOperateVo.setFormat(oldRepo.getFormat());
// 构建更新对象
PmsProductLibraryRepositories pmsProductLibraryRepositories = hostedRepositoriesOperateVo.toPmsProductLibraryRepositories();
@ -455,8 +455,8 @@ public class PmsProductLibraryRepositoriesServiceImpl implements IPmsProductLibr
@Override
public int deletePmsProductLibraryRepositoriesByName(String enterpriseIdentifier, String name) {
checkLockRepositoryStatus(enterpriseIdentifier, name);
PmsProductLibraryRepositories oldRepo = selectPmsProductLibraryRepositoriesByName(enterpriseIdentifier, name);
checkLockRepositoryStatus(enterpriseIdentifier, oldRepo.getId());
// 调用制品库删除接口删除制品库
nexusRequestHelper.doRequest(
NexusRequestUrl.DELETE_REPOSITORIES(PmsProductLibraryRepositories.getNexusRepositoriesName(enterpriseIdentifier, name))
@ -465,8 +465,8 @@ public class PmsProductLibraryRepositoriesServiceImpl implements IPmsProductLibr
}
@Override
public void lockRepository(String enterpriseIdentifier, String repoName) {
String lockRepoKey = CacheConstants.getLockEnterpriseIdentifierRepoKey(enterpriseIdentifier, repoName);
public void lockRepository(String enterpriseIdentifier, Long repoId) {
String lockRepoKey = CacheConstants.getLockEnterpriseIdentifierRepoIdKey(enterpriseIdentifier, repoId);
if (redisService.hasKey(lockRepoKey)) {
int count = redisService.getCacheObject(lockRepoKey);
redisService.setCacheObject(lockRepoKey, ++count);
@ -476,8 +476,8 @@ public class PmsProductLibraryRepositoriesServiceImpl implements IPmsProductLibr
}
@Override
public void unlockRepository(String enterpriseIdentifier, String repoName) {
String lockRepoKey = CacheConstants.getLockEnterpriseIdentifierRepoKey(enterpriseIdentifier, repoName);
public void unlockRepository(String enterpriseIdentifier, Long repoId) {
String lockRepoKey = CacheConstants.getLockEnterpriseIdentifierRepoIdKey(enterpriseIdentifier, repoId);
if (redisService.hasKey(lockRepoKey)) {
int count = redisService.getCacheObject(lockRepoKey);
count--;
@ -490,8 +490,8 @@ public class PmsProductLibraryRepositoriesServiceImpl implements IPmsProductLibr
}
@Override
public Boolean getLockRepositoryStatus(String enterpriseIdentifier, String repoName) {
String lockRepoKey = CacheConstants.getLockEnterpriseIdentifierRepoKey(enterpriseIdentifier, repoName);
public Boolean getLockRepositoryStatus(String enterpriseIdentifier, Long repoId) {
String lockRepoKey = CacheConstants.getLockEnterpriseIdentifierRepoIdKey(enterpriseIdentifier, repoId);
if (redisService.hasKey(lockRepoKey)) {
int count = redisService.getCacheObject(lockRepoKey);
return count > 0;
@ -500,9 +500,9 @@ public class PmsProductLibraryRepositoriesServiceImpl implements IPmsProductLibr
}
@Override
public void checkLockRepositoryStatus(String enterpriseIdentifier, String repoName) {
if (getLockRepositoryStatus(enterpriseIdentifier, repoName)) {
throw new ServiceException("该制品库锁定中,无法进行操作(制品库名称[%s])", repoName);
public void checkLockRepositoryStatus(String enterpriseIdentifier, Long repoId) {
if (getLockRepositoryStatus(enterpriseIdentifier, repoId)) {
throw new ServiceException("该制品库锁定中,无法进行操作(制品库Id[%s])", repoId);
}
}
}