|
|
@ -421,6 +421,41 @@ public class ResourcesService extends BaseService { |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* verify resource by name and type |
|
|
|
|
|
|
|
* @param name |
|
|
|
|
|
|
|
* @param type |
|
|
|
|
|
|
|
* @param loginUser |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public Result verifyResourceName(String name, ResourceType type,User loginUser) { |
|
|
|
|
|
|
|
Result result = new Result(); |
|
|
|
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
|
|
|
Resource resource = resourcesMapper.queryResourceByNameAndType(name, type.ordinal()); |
|
|
|
|
|
|
|
if (resource != null) { |
|
|
|
|
|
|
|
logger.error("resource type:{} name:{} has exist, can't create again.", type, name); |
|
|
|
|
|
|
|
putMsg(result, Status.RESOURCE_EXIST); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// query tenant
|
|
|
|
|
|
|
|
String tenantCode = tenantMapper.queryById(loginUser.getTenantId()).getTenantCode(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
String hdfsFilename = getHdfsFileName(type,tenantCode,name); |
|
|
|
|
|
|
|
if(HadoopUtils.getInstance().exists(hdfsFilename)){ |
|
|
|
|
|
|
|
logger.error("resource type:{} name:{} has exist in hdfs {}, can't create again.", type, name,hdfsFilename); |
|
|
|
|
|
|
|
putMsg(result, Status.RESOURCE_FILE_EXIST,hdfsFilename); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
logger.error(e.getMessage(),e); |
|
|
|
|
|
|
|
putMsg(result,Status.HDFS_OPERATION_ERROR); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* verify resource by name and type |
|
|
|
* verify resource by name and type |
|
|
|
* |
|
|
|
* |
|
|
@ -481,6 +516,7 @@ public class ResourcesService extends BaseService { |
|
|
|
String hdfsFileName = HadoopUtils.getHdfsFilename(tenantCode, resource.getAlias()); |
|
|
|
String hdfsFileName = HadoopUtils.getHdfsFilename(tenantCode, resource.getAlias()); |
|
|
|
logger.info("resource hdfs path is {} ", hdfsFileName); |
|
|
|
logger.info("resource hdfs path is {} ", hdfsFileName); |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
if(HadoopUtils.getInstance().exists(hdfsFileName)){ |
|
|
|
List<String> content = HadoopUtils.getInstance().catFile(hdfsFileName, skipLineNum, limit); |
|
|
|
List<String> content = HadoopUtils.getInstance().catFile(hdfsFileName, skipLineNum, limit); |
|
|
|
|
|
|
|
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
@ -488,6 +524,11 @@ public class ResourcesService extends BaseService { |
|
|
|
map.put(ALIAS, resource.getAlias()); |
|
|
|
map.put(ALIAS, resource.getAlias()); |
|
|
|
map.put(CONTENT, StringUtils.join(content.toArray(), "\n")); |
|
|
|
map.put(CONTENT, StringUtils.join(content.toArray(), "\n")); |
|
|
|
result.setData(map); |
|
|
|
result.setData(map); |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
logger.error("read file {} not exist in hdfs", hdfsFileName); |
|
|
|
|
|
|
|
putMsg(result, Status.RESOURCE_FILE_NOT_EXIST,hdfsFileName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error(String.format("Resource %s read failed", hdfsFileName), e); |
|
|
|
logger.error(String.format("Resource %s read failed", hdfsFileName), e); |
|
|
|
putMsg(result, Status.HDFS_OPERATION_ERROR); |
|
|
|
putMsg(result, Status.HDFS_OPERATION_ERROR); |
|
|
@ -531,17 +572,14 @@ public class ResourcesService extends BaseService { |
|
|
|
|
|
|
|
|
|
|
|
String name = fileName.trim() + "." + nameSuffix; |
|
|
|
String name = fileName.trim() + "." + nameSuffix; |
|
|
|
|
|
|
|
|
|
|
|
//check file already exists
|
|
|
|
result = verifyResourceName(name,type,loginUser); |
|
|
|
Resource resource = resourcesMapper.queryResourceByNameAndType(name, type.ordinal()); |
|
|
|
if (!result.getCode().equals(Status.SUCCESS.getCode())) { |
|
|
|
if (resource != null) { |
|
|
|
|
|
|
|
logger.error("resource {} has exist, can't recreate .", name); |
|
|
|
|
|
|
|
putMsg(result, Status.RESOURCE_EXIST); |
|
|
|
|
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// save data
|
|
|
|
// save data
|
|
|
|
Date now = new Date(); |
|
|
|
Date now = new Date(); |
|
|
|
resource = new Resource(name,name,desc,loginUser.getId(),type,content.getBytes().length,now,now); |
|
|
|
Resource resource = new Resource(name,name,desc,loginUser.getId(),type,content.getBytes().length,now,now); |
|
|
|
|
|
|
|
|
|
|
|
resourcesMapper.insert(resource); |
|
|
|
resourcesMapper.insert(resource); |
|
|
|
|
|
|
|
|
|
|
@ -570,6 +608,7 @@ public class ResourcesService extends BaseService { |
|
|
|
* @param resourceId |
|
|
|
* @param resourceId |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Transactional(value = "TransactionManager",rollbackFor = Exception.class) |
|
|
|
public Result updateResourceContent(int resourceId, String content) { |
|
|
|
public Result updateResourceContent(int resourceId, String content) { |
|
|
|
Result result = new Result(); |
|
|
|
Result result = new Result(); |
|
|
|
|
|
|
|
|
|
|
@ -598,6 +637,10 @@ public class ResourcesService extends BaseService { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resource.setSize(content.getBytes().length); |
|
|
|
|
|
|
|
resource.setUpdateTime(new Date()); |
|
|
|
|
|
|
|
resourcesMapper.update(resource); |
|
|
|
|
|
|
|
|
|
|
|
User user = userMapper.queryDetailsById(resource.getUserId()); |
|
|
|
User user = userMapper.queryDetailsById(resource.getUserId()); |
|
|
|
String tenantCode = tenantMapper.queryById(user.getTenantId()).getTenantCode(); |
|
|
|
String tenantCode = tenantMapper.queryById(user.getTenantId()).getTenantCode(); |
|
|
|
|
|
|
|
|
|
|
@ -644,6 +687,7 @@ public class ResourcesService extends BaseService { |
|
|
|
logger.error("{} is not exist", resourcePath); |
|
|
|
logger.error("{} is not exist", resourcePath); |
|
|
|
result.setCode(Status.HDFS_OPERATION_ERROR.getCode()); |
|
|
|
result.setCode(Status.HDFS_OPERATION_ERROR.getCode()); |
|
|
|
result.setMsg(String.format("%s is not exist", resourcePath)); |
|
|
|
result.setMsg(String.format("%s is not exist", resourcePath)); |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error(e.getMessage(), e); |
|
|
|
logger.error(e.getMessage(), e); |
|
|
@ -810,6 +854,23 @@ public class ResourcesService extends BaseService { |
|
|
|
return hdfsFileName; |
|
|
|
return hdfsFileName; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* get hdfs file name |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param resourceType |
|
|
|
|
|
|
|
* @param tenantCode |
|
|
|
|
|
|
|
* @param hdfsFileName |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private String getHdfsFileName(ResourceType resourceType, String tenantCode, String hdfsFileName) { |
|
|
|
|
|
|
|
if (resourceType.equals(ResourceType.FILE)) { |
|
|
|
|
|
|
|
hdfsFileName = HadoopUtils.getHdfsFilename(tenantCode, hdfsFileName); |
|
|
|
|
|
|
|
} else if (resourceType.equals(ResourceType.UDF)) { |
|
|
|
|
|
|
|
hdfsFileName = HadoopUtils.getHdfsUdfFilename(tenantCode, hdfsFileName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return hdfsFileName; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get authorized resource list |
|
|
|
* get authorized resource list |
|
|
|
* |
|
|
|
* |
|
|
|