Search in sources :

Example 1 with NamespaceCreationModel

use of com.ctrip.framework.apollo.portal.entity.model.NamespaceCreationModel in project apollo by ctripcorp.

the class NamespaceController method createNamespace.

@PreAuthorize(value = "@permissionValidator.hasCreateNamespacePermission(#appId)")
@PostMapping("/apps/{appId}/namespaces")
public ResponseEntity<Void> createNamespace(@PathVariable String appId, @RequestBody List<NamespaceCreationModel> models) {
    checkModel(!CollectionUtils.isEmpty(models));
    String namespaceName = models.get(0).getNamespace().getNamespaceName();
    String operator = userInfoHolder.getUser().getUserId();
    roleInitializationService.initNamespaceRoles(appId, namespaceName, operator);
    roleInitializationService.initNamespaceEnvRoles(appId, namespaceName, operator);
    for (NamespaceCreationModel model : models) {
        NamespaceDTO namespace = model.getNamespace();
        RequestPrecondition.checkArgumentsNotEmpty(model.getEnv(), namespace.getAppId(), namespace.getClusterName(), namespace.getNamespaceName());
        try {
            namespaceService.createNamespace(Env.valueOf(model.getEnv()), namespace);
        } catch (Exception e) {
            logger.error("create namespace fail.", e);
            Tracer.logError(String.format("create namespace fail. (env=%s namespace=%s)", model.getEnv(), namespace.getNamespaceName()), e);
        }
    }
    namespaceService.assignNamespaceRoleToOperator(appId, namespaceName, userInfoHolder.getUser().getUserId());
    return ResponseEntity.ok().build();
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) AppNamespaceDTO(com.ctrip.framework.apollo.common.dto.AppNamespaceDTO) NamespaceCreationModel(com.ctrip.framework.apollo.portal.entity.model.NamespaceCreationModel) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) PostMapping(org.springframework.web.bind.annotation.PostMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

AppNamespaceDTO (com.ctrip.framework.apollo.common.dto.AppNamespaceDTO)1 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)1 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)1 NamespaceCreationModel (com.ctrip.framework.apollo.portal.entity.model.NamespaceCreationModel)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1