use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.
the class TenantController method bindingTenant.
@PostMapping(value = "/bindingTenant")
public R<Void> bindingTenant(@RequestBody ComponentBindTenantVO vo) throws Exception {
Cluster cluster = clusterService.getCluster(vo.getClusterId());
if (cluster == null) {
throw new RdosDefineException(ErrorCode.CANT_NOT_FIND_CLUSTER);
}
if (CollectionUtils.isNotEmpty(vo.getBindDBList())) {
for (ComponentBindDBVO bindDBVO : vo.getBindDBList()) {
if (Objects.isNull(bindDBVO.getComponentCode())) {
throw new RdosDefineException(String.format(ErrorCode.META_COMPONENT_NOT_EXISTS.getMsg(), EComponentType.SPARK_THRIFT.getName()));
}
}
}
tenantService.bindingTenant(vo.getTenantId(), vo.getClusterId(), vo.getQueueId(), cluster.getClusterName(), vo.getBindDBList());
return R.empty();
}
use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.
the class UploadController method addOrUpdateComponent.
@PostMapping(value = "/component/addOrUpdateComponent")
public R<ComponentVO> addOrUpdateComponent(@RequestParam("resources1") List<MultipartFile> files1, @RequestParam("resources2") List<MultipartFile> files2, @RequestParam("clusterId") Long clusterId, @RequestParam(value = "componentConfig") String componentConfig, @RequestParam("versionName") @NotNull String versionName, @RequestParam("kerberosFileName") String kerberosFileName, @RequestParam("componentTemplate") String componentTemplate, @RequestParam("componentCode") Integer componentCode, @RequestParam("storeType") Integer storeType, @RequestParam("principals") String principals, @RequestParam("principal") String principal, @RequestParam(value = "isMetadata", defaultValue = "false") Boolean isMetadata, @RequestParam(value = "isDefault", defaultValue = "false") Boolean isDefault, @RequestParam(value = "deployType") Integer deployType) {
List<Resource> resources = getResourcesFromFiles(files1);
List<Resource> resourcesAdd = getResourcesFromFiles(files2);
resources.addAll(resourcesAdd);
return new APITemplate<ComponentVO>() {
@Override
protected void checkParams() throws IllegalArgumentException {
if (null == componentCode) {
throw new RdosDefineException("Component type cannot be empty");
}
if (null == clusterId) {
throw new RdosDefineException("Cluster Id cannot be empty");
}
if (CollectionUtils.isNotEmpty(resources) && resources.size() >= 2 && StringUtils.isBlank(kerberosFileName)) {
// 上传二份文件 需要kerberosFileName文件名字段
throw new RdosDefineException("kerberosFileName不能为空");
}
// 校验引擎是否添加
if (EComponentType.deployTypeComponents.contains(componentCode) && null == deployType) {
throw new RdosDefineException(ErrorCode.EMPTY_PARAMETERS.getMsg() + ":deployType");
}
}
@Override
protected ComponentVO process() throws RdosDefineException {
// 校验引擎是否添加
EComponentType componentType = EComponentType.getByCode(componentCode);
if (EComponentType.deployTypeComponents.contains(componentType) && null == deployType) {
throw new RdosDefineException("deploy type cannot be empty");
}
return consoleComponentService.addOrUpdateComponent(clusterId, componentConfig, resources, versionName, kerberosFileName, componentTemplate, componentType, storeType, principals, principal, isMetadata, isDefault, deployType);
}
}.execute();
}
use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.
the class UploadController method getResourcesFromFiles.
private List<Resource> getResourcesFromFiles(List<MultipartFile> files) {
List<Resource> resources = new ArrayList<>(files.size());
for (MultipartFile file : files) {
String fileOriginalName = file.getOriginalFilename();
String path = uploadsDir + File.separator + fileOriginalName;
File saveFile = new File(path);
if (!saveFile.getParentFile().exists()) {
saveFile.getParentFile().mkdirs();
}
try {
file.transferTo(saveFile);
} catch (Exception e) {
LOGGER.error("", e);
throw new RdosDefineException("An error occurred while storing the file");
}
resources.add(new Resource(fileOriginalName, path, (int) file.getSize(), file.getContentType(), file.getName()));
}
return resources;
}
use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.
the class StoragePart method getPluginName.
@Override
public String getPluginName() {
List<Component> components = componentScheduleGroup.get(EComponentScheduleType.RESOURCE);
if (CollectionUtils.isEmpty(components)) {
throw new RdosDefineException(ErrorCode.RESOURCE_COMPONENT_NOT_CONFIG);
}
Component resourceComponent = components.get(0);
String resourceVersion = resourceComponent.getVersionName();
EComponentType resourceType = EComponentType.getByCode(resourceComponent.getComponentTypeCode());
Optional<JSONObject> resourceModelConfig = context.getModelConfig(resourceType, resourceVersion);
JSONObject storageModelConfig = resourceModelConfig.map(res -> res.getJSONObject(type.name())).orElseThrow(() -> new RdosDefineException(Strings.format(ErrorCode.RESOURCE_NOT_SUPPORT_COMPONENT_VERSION.getMsg(), resourceComponent.getComponentName(), type.name(), versionName)));
return storageModelConfig.getString(type.name());
}
use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.
the class BatchCatalogueService method initTemplateCatalogue.
/**
* 初始化任务开发下的 模板目录 和 模板任务
* @param oneCatalogue
* @param tenantId
* @param userId
* @return
*/
private List<BatchCatalogue> initTemplateCatalogue(BatchCatalogue oneCatalogue, Long tenantId, Long userId) {
List<BatchCatalogue> templateCatalogueList = new ArrayList<>(TemplateCatalogue.getValues().size());
// 需要初始化的模板任务所在的目录
BatchCatalogue batchTempTaskCatalogue = new BatchCatalogue();
batchTempTaskCatalogue.setLevel(CatalogueLevel.OTHER.getLevel());
batchTempTaskCatalogue.setNodePid(oneCatalogue.getId());
batchTempTaskCatalogue.setTenantId(tenantId);
batchTempTaskCatalogue.setCreateUserId(userId);
List<TemplateCatalogue> templateTaskCatalogues = TemplateCatalogue.getValues();
HashMap<String, Long> idsMap = new HashMap<>();
for (TemplateCatalogue templateCatalogue : templateTaskCatalogues) {
// 相同目录只创建一次
if (!idsMap.containsKey(templateCatalogue.getValue())) {
batchTempTaskCatalogue.setNodeName(templateCatalogue.getValue());
batchTempTaskCatalogue.setId(0L);
batchTempTaskCatalogue.setCatalogueType(RdosBatchCatalogueTypeEnum.NORAML.getType());
addOrUpdate(batchTempTaskCatalogue);
idsMap.put(templateCatalogue.getValue(), batchTempTaskCatalogue.getId());
}
templateCatalogueList.add(batchTempTaskCatalogue);
try {
String content = batchTaskTemplateService.getContentByType(EScheduleJobType.SPARK_SQL.getVal(), templateCatalogue.getType());
// 初始化任务
TaskResourceParam batchTask = new TaskResourceParam();
batchTask.setName(templateCatalogue.getFileName());
batchTask.setTaskType(EScheduleJobType.SPARK_SQL.getVal());
batchTask.setNodePid(idsMap.get(templateCatalogue.getValue()));
batchTask.setComputeType(ComputeType.BATCH.getType());
batchTask.setLockVersion(0);
batchTask.setVersion(0);
batchTask.setTenantId(tenantId);
batchTask.setUserId(userId);
batchTask.setCreateUserId(userId);
batchTask.setModifyUserId(userId);
if (StringUtils.isEmpty(content)) {
throw new RdosDefineException(ErrorCode.TEMPLATE_TASK_CONTENT_NOT_NULL);
}
batchTask.setSqlText(content);
// 添加init脚本中带有的任务参数
List<Map> taskVariables = new ArrayList<>();
Map<String, String> variable = new HashMap<>(3);
variable.put("paramCommand", PARAM_COMMAND);
variable.put("paramName", PARAM_NAME);
variable.put("type", TYPE4SYSTEM);
taskVariables.add(variable);
batchTask.setTaskVariables(taskVariables);
// SparkSQL任务支持多版本运行,添加默认的组件版本
List<BatchTaskGetComponentVersionResultVO> hadoopVersions = batchTaskService.getComponentVersionByTaskType(tenantId, EScheduleJobType.SPARK_SQL.getVal());
if (CollectionUtils.isNotEmpty(hadoopVersions)) {
batchTask.setComponentVersion(hadoopVersions.get(0).getComponentVersion());
}
batchTaskService.addOrUpdateTask(batchTask);
} catch (Exception e) {
LOGGER.error(ErrorCode.CATALOGUE_INIT_FAILED.getDescription(), e);
throw new RdosDefineException(ErrorCode.CATALOGUE_INIT_FAILED);
}
}
return templateCatalogueList;
}
Aggregations