ReleaseController { @Transactional @PostMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases") public ReleaseDTO publish(@PathVariable("appId") String appId, @PathVariable("clusterName") String clusterName, @PathVariable("namespaceName") String namespaceName, @RequestParam("name") String releaseName, @RequestParam(name = "comment", required = false) String releaseComment, @RequestParam("operator") String operator, @RequestParam(name = "isEmergencyPublish", defaultValue = "false") boolean isEmergencyPublish) { Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName); if (namespace == null) { throw new NotFoundException(String.format("Could not find namespace for %s %s %s", appId, clusterName, namespaceName)); } Release release = releaseService.publish(namespace, releaseName, releaseComment, operator, isEmergencyPublish); Namespace parentNamespace = namespaceService.findParentNamespace(namespace); String messageCluster; if (parentNamespace != null) { messageCluster = parentNamespace.getClusterName(); } else { messageCluster = clusterName; } messageSender.sendMessage(ReleaseMessageKeyGenerator.generate(appId, messageCluster, namespaceName), Topics.APOLLO_RELEASE_TOPIC); return BeanUtils.transform(ReleaseDTO.class, release); } ReleaseController(
      final ReleaseService releaseService,
      final NamespaceService namespaceService,
      final MessageSender messageSender,
      final NamespaceBranchService namespaceBranchService); @GetMapping("/releases/{releaseId}") ReleaseDTO get(@PathVariable("releaseId") long releaseId); @GetMapping("/releases") List<ReleaseDTO> findReleaseByIds(@RequestParam("releaseIds") String releaseIds); @GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/all") List<ReleaseDTO> findAllReleases(@PathVariable("appId") String appId,
                                          @PathVariable("clusterName") String clusterName,
                                          @PathVariable("namespaceName") String namespaceName,
                                          Pageable page); @GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/active") List<ReleaseDTO> findActiveReleases(@PathVariable("appId") String appId,
                                             @PathVariable("clusterName") String clusterName,
                                             @PathVariable("namespaceName") String namespaceName,
                                             Pageable page); @GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/latest") ReleaseDTO getLatest(@PathVariable("appId") String appId,
                              @PathVariable("clusterName") String clusterName,
                              @PathVariable("namespaceName") String namespaceName); @Transactional @PostMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases") ReleaseDTO publish(@PathVariable("appId") String appId,
                            @PathVariable("clusterName") String clusterName,
                            @PathVariable("namespaceName") String namespaceName,
                            @RequestParam("name") String releaseName,
                            @RequestParam(name = "comment", required = false) String releaseComment,
                            @RequestParam("operator") String operator,
                            @RequestParam(name = "isEmergencyPublish", defaultValue = "false") boolean isEmergencyPublish); @Transactional @PostMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/updateAndPublish") ReleaseDTO updateAndPublish(@PathVariable("appId") String appId,
                                     @PathVariable("clusterName") String clusterName,
                                     @PathVariable("namespaceName") String namespaceName,
                                     @RequestParam("releaseName") String releaseName,
                                     @RequestParam("branchName") String branchName,
                                     @RequestParam(value = "deleteBranch", defaultValue = "true") boolean deleteBranch,
                                     @RequestParam(name = "releaseComment", required = false) String releaseComment,
                                     @RequestParam(name = "isEmergencyPublish", defaultValue = "false") boolean isEmergencyPublish,
                                     @RequestBody ItemChangeSets changeSets); @Transactional @PutMapping("/releases/{releaseId}/rollback") void rollback(@PathVariable("releaseId") long releaseId,
                       @RequestParam(name="toReleaseId", defaultValue = "-1") long toReleaseId,
                       @RequestParam("operator") String operator); @Transactional @PostMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/gray-del-releases") ReleaseDTO publish(@PathVariable("appId") String appId,
                            @PathVariable("clusterName") String clusterName,
                            @PathVariable("namespaceName") String namespaceName,
                            @RequestParam("operator") String operator,
                            @RequestParam("releaseName") String releaseName,
                            @RequestParam(name = "comment", required = false) String releaseComment,
                            @RequestParam(name = "isEmergencyPublish", defaultValue = "false") boolean isEmergencyPublish,
                            @RequestParam(name = "grayDelKeys") Set<String> grayDelKeys);  }
@Test public void testMessageSendAfterBuildRelease() throws Exception { String someAppId = "someAppId"; String someNamespaceName = "someNamespace"; String someCluster = "someCluster"; String someName = "someName"; String someComment = "someComment"; String someUserName = "someUser"; NamespaceService someNamespaceService = mock(NamespaceService.class); ReleaseService someReleaseService = mock(ReleaseService.class); MessageSender someMessageSender = mock(MessageSender.class); Namespace someNamespace = mock(Namespace.class); ReleaseController releaseController = new ReleaseController(someReleaseService, someNamespaceService, someMessageSender, null); when(someNamespaceService.findOne(someAppId, someCluster, someNamespaceName)) .thenReturn(someNamespace); releaseController .publish(someAppId, someCluster, someNamespaceName, someName, someComment, "test", false); verify(someMessageSender, times(1)) .sendMessage(Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR) .join(someAppId, someCluster, someNamespaceName), Topics.APOLLO_RELEASE_TOPIC); }