Search in sources :

Example 1 with GrayReleaseRuleDTO

use of com.ctrip.framework.apollo.common.dto.GrayReleaseRuleDTO in project apollo by ctripcorp.

the class OpenApiBeanUtils method transformToGrayReleaseRuleDTO.

public static GrayReleaseRuleDTO transformToGrayReleaseRuleDTO(OpenGrayReleaseRuleDTO openGrayReleaseRuleDTO) {
    Preconditions.checkArgument(openGrayReleaseRuleDTO != null);
    String appId = openGrayReleaseRuleDTO.getAppId();
    String branchName = openGrayReleaseRuleDTO.getBranchName();
    String clusterName = openGrayReleaseRuleDTO.getClusterName();
    String namespaceName = openGrayReleaseRuleDTO.getNamespaceName();
    GrayReleaseRuleDTO grayReleaseRuleDTO = new GrayReleaseRuleDTO(appId, clusterName, namespaceName, branchName);
    Set<OpenGrayReleaseRuleItemDTO> openGrayReleaseRuleItemDTOSet = openGrayReleaseRuleDTO.getRuleItems();
    openGrayReleaseRuleItemDTOSet.forEach(openGrayReleaseRuleItemDTO -> {
        String clientAppId = openGrayReleaseRuleItemDTO.getClientAppId();
        Set<String> clientIpList = openGrayReleaseRuleItemDTO.getClientIpList();
        Set<String> clientLabelList = openGrayReleaseRuleItemDTO.getClientLabelList();
        GrayReleaseRuleItemDTO ruleItem = new GrayReleaseRuleItemDTO(clientAppId, clientIpList, clientLabelList);
        grayReleaseRuleDTO.addRuleItem(ruleItem);
    });
    return grayReleaseRuleDTO;
}
Also used : OpenGrayReleaseRuleDTO(com.ctrip.framework.apollo.openapi.dto.OpenGrayReleaseRuleDTO) GrayReleaseRuleDTO(com.ctrip.framework.apollo.common.dto.GrayReleaseRuleDTO) OpenGrayReleaseRuleItemDTO(com.ctrip.framework.apollo.openapi.dto.OpenGrayReleaseRuleItemDTO) OpenGrayReleaseRuleItemDTO(com.ctrip.framework.apollo.openapi.dto.OpenGrayReleaseRuleItemDTO) GrayReleaseRuleItemDTO(com.ctrip.framework.apollo.common.dto.GrayReleaseRuleItemDTO)

Example 2 with GrayReleaseRuleDTO

use of com.ctrip.framework.apollo.common.dto.GrayReleaseRuleDTO in project apollo by ctripcorp.

the class NamespaceBranchController method updateBranchRules.

@PreAuthorize(value = "@consumerPermissionValidator.hasModifyNamespacePermission(#request, #appId, #namespaceName, #env)")
@PutMapping(value = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/branches/{branchName}/rules")
public void updateBranchRules(@PathVariable String appId, @PathVariable String env, @PathVariable String clusterName, @PathVariable String namespaceName, @PathVariable String branchName, @RequestBody OpenGrayReleaseRuleDTO rules, @RequestParam("operator") String operator, HttpServletRequest request) {
    RequestPrecondition.checkArguments(!StringUtils.isContainEmpty(operator), "operator can not be empty");
    if (userService.findByUserId(operator) == null) {
        throw new BadRequestException("operator " + operator + " not exists");
    }
    rules.setAppId(appId);
    rules.setClusterName(clusterName);
    rules.setNamespaceName(namespaceName);
    rules.setBranchName(branchName);
    GrayReleaseRuleDTO grayReleaseRuleDTO = OpenApiBeanUtils.transformToGrayReleaseRuleDTO(rules);
    namespaceBranchService.updateBranchGrayRules(appId, Env.valueOf(env.toUpperCase()), clusterName, namespaceName, branchName, grayReleaseRuleDTO, operator);
}
Also used : OpenGrayReleaseRuleDTO(com.ctrip.framework.apollo.openapi.dto.OpenGrayReleaseRuleDTO) GrayReleaseRuleDTO(com.ctrip.framework.apollo.common.dto.GrayReleaseRuleDTO) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) PutMapping(org.springframework.web.bind.annotation.PutMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with GrayReleaseRuleDTO

use of com.ctrip.framework.apollo.common.dto.GrayReleaseRuleDTO in project apollo by ctripcorp.

the class NamespaceBranchController method findBranchGrayRules.

@GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/branches/{branchName}/rules")
public GrayReleaseRuleDTO findBranchGrayRules(@PathVariable String appId, @PathVariable String clusterName, @PathVariable String namespaceName, @PathVariable String branchName) {
    checkBranch(appId, clusterName, namespaceName, branchName);
    GrayReleaseRule rules = namespaceBranchService.findBranchGrayRules(appId, clusterName, namespaceName, branchName);
    if (rules == null) {
        return null;
    }
    GrayReleaseRuleDTO ruleDTO = new GrayReleaseRuleDTO(rules.getAppId(), rules.getClusterName(), rules.getNamespaceName(), rules.getBranchName());
    ruleDTO.setReleaseId(rules.getReleaseId());
    ruleDTO.setRuleItems(GrayReleaseRuleItemTransformer.batchTransformFromJSON(rules.getRules()));
    return ruleDTO;
}
Also used : GrayReleaseRuleDTO(com.ctrip.framework.apollo.common.dto.GrayReleaseRuleDTO) GrayReleaseRule(com.ctrip.framework.apollo.biz.entity.GrayReleaseRule) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

GrayReleaseRuleDTO (com.ctrip.framework.apollo.common.dto.GrayReleaseRuleDTO)3 OpenGrayReleaseRuleDTO (com.ctrip.framework.apollo.openapi.dto.OpenGrayReleaseRuleDTO)2 GrayReleaseRule (com.ctrip.framework.apollo.biz.entity.GrayReleaseRule)1 GrayReleaseRuleItemDTO (com.ctrip.framework.apollo.common.dto.GrayReleaseRuleItemDTO)1 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)1 OpenGrayReleaseRuleItemDTO (com.ctrip.framework.apollo.openapi.dto.OpenGrayReleaseRuleItemDTO)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1