Skip to content

Commit

Permalink
feat(OpenApi): notification by email when release by OpenApi
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackBear2003 committed Jan 24, 2025
1 parent 6c41ef0 commit f0e9a75
Showing 1 changed file with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
import com.ctrip.framework.apollo.openapi.util.OpenApiBeanUtils;
import com.ctrip.framework.apollo.portal.entity.model.NamespaceGrayDelReleaseModel;
import com.ctrip.framework.apollo.portal.entity.model.NamespaceReleaseModel;
import com.ctrip.framework.apollo.portal.listener.ConfigPublishEvent;
import com.ctrip.framework.apollo.portal.service.NamespaceBranchService;
import com.ctrip.framework.apollo.portal.service.ReleaseService;
import com.ctrip.framework.apollo.portal.spi.UserService;
import javax.servlet.http.HttpServletRequest;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -54,18 +56,21 @@ public class ReleaseController {
private final NamespaceBranchService namespaceBranchService;
private final ConsumerPermissionValidator consumerPermissionValidator;
private final ReleaseOpenApiService releaseOpenApiService;
private final ApplicationEventPublisher publisher;

public ReleaseController(
final ReleaseService releaseService,
final UserService userService,
final NamespaceBranchService namespaceBranchService,
final ConsumerPermissionValidator consumerPermissionValidator,
ReleaseOpenApiService releaseOpenApiService) {
ReleaseOpenApiService releaseOpenApiService,
ApplicationEventPublisher publisher) {
this.releaseService = releaseService;
this.userService = userService;
this.namespaceBranchService = namespaceBranchService;
this.consumerPermissionValidator = consumerPermissionValidator;
this.releaseOpenApiService = releaseOpenApiService;
this.publisher = publisher;
}

@PreAuthorize(value = "@consumerPermissionValidator.hasReleaseNamespacePermission(#request, #appId, #namespaceName, #env)")
Expand All @@ -83,7 +88,19 @@ public OpenReleaseDTO createRelease(@PathVariable String appId, @PathVariable St
throw BadRequestException.userNotExists(model.getReleasedBy());
}

return this.releaseOpenApiService.publishNamespace(appId, env, clusterName, namespaceName, model);
OpenReleaseDTO releaseDTO = this.releaseOpenApiService.publishNamespace(appId, env,
clusterName, namespaceName, model);

ConfigPublishEvent event = ConfigPublishEvent.instance();
event.withAppId(appId)
.withCluster(clusterName)
.withNamespace(namespaceName)
.withReleaseId(releaseDTO.getId())
.setNormalPublishEvent(true)
.setEnv(Env.valueOf(env));
publisher.publishEvent(event);

return releaseDTO;
}

@GetMapping(value = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/latest")
Expand Down Expand Up @@ -111,6 +128,16 @@ public OpenReleaseDTO merge(@PathVariable String appId, @PathVariable String env
model.getReleaseTitle(), model.getReleaseComment(),
model.isEmergencyPublish(), deleteBranch, model.getReleasedBy());


ConfigPublishEvent event = ConfigPublishEvent.instance();
event.withAppId(appId)
.withCluster(clusterName)
.withNamespace(namespaceName)
.withReleaseId(mergedRelease.getId())
.setMergeEvent(true)
.setEnv(Env.valueOf(env));
publisher.publishEvent(event);

return OpenApiBeanUtils.transformFromReleaseDTO(mergedRelease);
}

Expand All @@ -136,7 +163,18 @@ public OpenReleaseDTO createGrayRelease(@PathVariable String appId,
releaseModel.setClusterName(branchName);
releaseModel.setNamespaceName(namespaceName);

return OpenApiBeanUtils.transformFromReleaseDTO(releaseService.publish(releaseModel));
ReleaseDTO releaseDTO = releaseService.publish(releaseModel);

ConfigPublishEvent event = ConfigPublishEvent.instance();
event.withAppId(appId)
.withCluster(clusterName)
.withNamespace(namespaceName)
.withReleaseId(releaseDTO.getId())
.setGrayPublishEvent(true)
.setEnv(Env.valueOf(env));
publisher.publishEvent(event);

return OpenApiBeanUtils.transformFromReleaseDTO(releaseDTO);
}

@PreAuthorize(value = "@consumerPermissionValidator.hasReleaseNamespacePermission(#request, #appId, #namespaceName, #env)")
Expand Down Expand Up @@ -185,6 +223,16 @@ public void rollback(@PathVariable String env,
throw new AccessDeniedException("Forbidden operation. you don't have release permission");
}

ConfigPublishEvent event = ConfigPublishEvent.instance();
event.withAppId(release.getAppId())
.withCluster(release.getClusterName())
.withNamespace(release.getNamespaceName())
.withReleaseId(release.getId())
.setRollbackEvent(true)
.setEnv(Env.valueOf(env));
publisher.publishEvent(event);


this.releaseOpenApiService.rollbackRelease(env, releaseId, operator);
}

Expand Down

0 comments on commit f0e9a75

Please sign in to comment.