Commit 81ecdf42 authored by ligang's avatar ligang
Browse files

update method deleteTenantById

parent 3f87b386
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -207,6 +207,8 @@ public enum Status {
    DELETE_SCHEDULE_CRON_BY_ID_ERROR(50024,"delete schedule by id error"),

    HDFS_NOT_STARTUP(60001,"hdfs not startup"),
    HDFS_TERANT_RESOURCES_FILE_EXISTS(60002,"resource file exists,please delete resource first"),
    HDFS_TERANT_UDFS_FILE_EXISTS(60003,"udf file exists,please delete resource first"),

    /**
     * for monitor
+15 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import cn.escheduler.dao.mapper.TenantMapper;
import cn.escheduler.dao.model.Tenant;
import cn.escheduler.dao.model.User;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.fs.FileStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -219,6 +220,7 @@ public class TenantService extends BaseService{
   * @param id
   * @return
   */
  @Transactional(value = "TransactionManager", rollbackFor = Exception.class)
  public Map<String, Object> deleteTenantById(User loginUser, int id) throws Exception {
    Map<String, Object> result = new HashMap<>(5);

@@ -229,6 +231,19 @@ public class TenantService extends BaseService{
    Tenant tenant = tenantMapper.queryById(id);

    String tenantPath = HadoopUtils.getHdfsDataBasePath() + "/" + tenant.getTenantCode();

    String resourcePath = HadoopUtils.getHdfsDir(tenant.getTenantCode());
    FileStatus[] fileStatus = HadoopUtils.getInstance().listFileStatus(resourcePath);
    if (fileStatus.length > 0) {
      putMsg(result, Status.HDFS_TERANT_RESOURCES_FILE_EXISTS);
      return result;
    }
    fileStatus = HadoopUtils.getInstance().listFileStatus(HadoopUtils.getHdfsUdfDir(tenant.getTenantCode()));
    if (fileStatus.length > 0) {
      putMsg(result, Status.HDFS_TERANT_UDFS_FILE_EXISTS);
      return result;
    }

    HadoopUtils.getInstance().delete(tenantPath, true);

    tenantMapper.deleteById(id);