Skip to content

Commit

Permalink
feat(apollo-portal): Remove server-side delete Namespace check
Browse files Browse the repository at this point in the history
  • Loading branch information
klboke committed Aug 12, 2022
1 parent 6c57b80 commit cb14888
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,25 @@
*/
package com.ctrip.framework.apollo.portal.service;

import com.ctrip.framework.apollo.common.dto.ClusterDTO;
import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
import com.ctrip.framework.apollo.common.entity.App;
import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.core.utils.StringUtils;
import com.ctrip.framework.apollo.portal.api.AdminServiceAPI;
import com.ctrip.framework.apollo.portal.api.AdminServiceAPI.NamespaceAPI;
import com.ctrip.framework.apollo.portal.component.PortalSettings;
import com.ctrip.framework.apollo.portal.entity.vo.NamespaceUsage;
import com.ctrip.framework.apollo.portal.environment.Env;
import com.ctrip.framework.apollo.portal.repository.AppNamespaceRepository;
import com.ctrip.framework.apollo.portal.spi.UserInfoHolder;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Objects;
import java.util.Set;

@Service
public class AppNamespaceService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,32 +170,7 @@ public NamespaceUsage getNamespaceUsageByEnv(String appId, String namespaceName,
@Transactional
public void deleteNamespace(String appId, Env env, String clusterName, String namespaceName) {

AppNamespace appNamespace = appNamespaceService.findByAppIdAndName(appId, namespaceName);

//1. check parent namespace has not instances
if (namespaceHasInstances(appId, env, clusterName, namespaceName)) {
throw new BadRequestException(
"Can not delete namespace because namespace has active instances");
}

//2. check child namespace has not instances
NamespaceDTO childNamespace = branchService
.findBranchBaseInfo(appId, env, clusterName, namespaceName);
if (childNamespace != null &&
namespaceHasInstances(appId, env, childNamespace.getClusterName(), namespaceName)) {
throw new BadRequestException(
"Can not delete namespace because namespace's branch has active instances");
}

//3. check public namespace has not associated namespace
if (appNamespace != null && appNamespace.isPublic() && publicAppNamespaceHasAssociatedNamespace(
namespaceName, env)) {
throw new BadRequestException(
"Can not delete public namespace which has associated namespaces");
}

String operator = userInfoHolder.getUser().getUserId();

namespaceAPI.deleteNamespace(env, appId, clusterName, namespaceName, operator);
}

Expand Down Expand Up @@ -279,11 +254,6 @@ public NamespaceBO loadNamespaceBO(String appId, Env env, String clusterName,
return transformNamespace2BO(env, namespace);
}

public boolean namespaceHasInstances(String appId, Env env, String clusterName,
String namespaceName) {
return instanceService.getInstanceCountByNamespace(appId, env, clusterName, namespaceName) > 0;
}

public boolean publicAppNamespaceHasAssociatedNamespace(String publicNamespaceName, Env env) {
return getPublicAppNamespaceHasAssociatedNamespace(publicNamespaceName, env) > 0;
}
Expand Down

0 comments on commit cb14888

Please sign in to comment.