Search in sources :

Example 1 with ConfigPublishEvent

use of com.ctrip.framework.apollo.portal.listener.ConfigPublishEvent in project apollo by ctripcorp.

the class ReleaseController method createRelease.

@PreAuthorize(value = "@permissionValidator.hasReleaseNamespacePermission(#appId, #namespaceName)")
@RequestMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/releases", method = RequestMethod.POST)
public ReleaseDTO createRelease(@PathVariable String appId, @PathVariable String env, @PathVariable String clusterName, @PathVariable String namespaceName, @RequestBody NamespaceReleaseModel model) {
    checkModel(Objects.nonNull(model));
    model.setAppId(appId);
    model.setEnv(env);
    model.setClusterName(clusterName);
    model.setNamespaceName(namespaceName);
    if (model.isEmergencyPublish() && !portalConfig.isEmergencyPublishAllowed(Env.valueOf(env))) {
        throw new BadRequestException(String.format("Env: %s is not supported emergency publish now", env));
    }
    ReleaseDTO createdRelease = releaseService.publish(model);
    ConfigPublishEvent event = ConfigPublishEvent.instance();
    event.withAppId(appId).withCluster(clusterName).withNamespace(namespaceName).withReleaseId(createdRelease.getId()).setNormalPublishEvent(true).setEnv(Env.valueOf(env));
    publisher.publishEvent(event);
    return createdRelease;
}
Also used : BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) ConfigPublishEvent(com.ctrip.framework.apollo.portal.listener.ConfigPublishEvent) ReleaseDTO(com.ctrip.framework.apollo.common.dto.ReleaseDTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ConfigPublishEvent

use of com.ctrip.framework.apollo.portal.listener.ConfigPublishEvent in project apollo by ctripcorp.

the class NamespaceBranchController method merge.

@PreAuthorize(value = "@permissionValidator.hasReleaseNamespacePermission(#appId, #namespaceName)")
@RequestMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/branches/{branchName}/merge", method = RequestMethod.POST)
public ReleaseDTO merge(@PathVariable String appId, @PathVariable String env, @PathVariable String clusterName, @PathVariable String namespaceName, @PathVariable String branchName, @RequestParam(value = "deleteBranch", defaultValue = "true") boolean deleteBranch, @RequestBody NamespaceReleaseModel model) {
    if (model.isEmergencyPublish() && !portalConfig.isEmergencyPublishAllowed(Env.fromString(env))) {
        throw new BadRequestException(String.format("Env: %s is not supported emergency publish now", env));
    }
    ReleaseDTO createdRelease = namespaceBranchService.merge(appId, Env.valueOf(env), clusterName, namespaceName, branchName, model.getReleaseTitle(), model.getReleaseComment(), model.isEmergencyPublish(), deleteBranch);
    ConfigPublishEvent event = ConfigPublishEvent.instance();
    event.withAppId(appId).withCluster(clusterName).withNamespace(namespaceName).withReleaseId(createdRelease.getId()).setMergeEvent(true).setEnv(Env.valueOf(env));
    publisher.publishEvent(event);
    return createdRelease;
}
Also used : BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) ConfigPublishEvent(com.ctrip.framework.apollo.portal.listener.ConfigPublishEvent) ReleaseDTO(com.ctrip.framework.apollo.common.dto.ReleaseDTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ConfigPublishEvent

use of com.ctrip.framework.apollo.portal.listener.ConfigPublishEvent in project apollo by ctripcorp.

the class ReleaseController method createGrayRelease.

@PreAuthorize(value = "@permissionValidator.hasReleaseNamespacePermission(#appId, #namespaceName)")
@RequestMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/branches/{branchName}/releases", method = RequestMethod.POST)
public ReleaseDTO createGrayRelease(@PathVariable String appId, @PathVariable String env, @PathVariable String clusterName, @PathVariable String namespaceName, @PathVariable String branchName, @RequestBody NamespaceReleaseModel model) {
    checkModel(Objects.nonNull(model));
    model.setAppId(appId);
    model.setEnv(env);
    model.setClusterName(branchName);
    model.setNamespaceName(namespaceName);
    if (model.isEmergencyPublish() && !portalConfig.isEmergencyPublishAllowed(Env.valueOf(env))) {
        throw new BadRequestException(String.format("Env: %s is not supported emergency publish now", env));
    }
    ReleaseDTO createdRelease = releaseService.publish(model);
    ConfigPublishEvent event = ConfigPublishEvent.instance();
    event.withAppId(appId).withCluster(clusterName).withNamespace(namespaceName).withReleaseId(createdRelease.getId()).setGrayPublishEvent(true).setEnv(Env.valueOf(env));
    publisher.publishEvent(event);
    return createdRelease;
}
Also used : BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) ConfigPublishEvent(com.ctrip.framework.apollo.portal.listener.ConfigPublishEvent) ReleaseDTO(com.ctrip.framework.apollo.common.dto.ReleaseDTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ConfigPublishEvent

use of com.ctrip.framework.apollo.portal.listener.ConfigPublishEvent in project apollo by ctripcorp.

the class ReleaseController method rollback.

@RequestMapping(path = "/envs/{env}/releases/{releaseId}/rollback", method = RequestMethod.PUT)
public void rollback(@PathVariable String env, @PathVariable long releaseId) {
    releaseService.rollback(Env.valueOf(env), releaseId);
    ReleaseDTO release = releaseService.findReleaseById(Env.valueOf(env), releaseId);
    if (Objects.isNull(release)) {
        return;
    }
    ConfigPublishEvent event = ConfigPublishEvent.instance();
    event.withAppId(release.getAppId()).withCluster(release.getClusterName()).withNamespace(release.getNamespaceName()).withPreviousReleaseId(releaseId).setRollbackEvent(true).setEnv(Env.valueOf(env));
    publisher.publishEvent(event);
}
Also used : ConfigPublishEvent(com.ctrip.framework.apollo.portal.listener.ConfigPublishEvent) ReleaseDTO(com.ctrip.framework.apollo.common.dto.ReleaseDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ReleaseDTO (com.ctrip.framework.apollo.common.dto.ReleaseDTO)4 ConfigPublishEvent (com.ctrip.framework.apollo.portal.listener.ConfigPublishEvent)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3