mirror of
https://github.com/apache/rocketmq-dashboard.git
synced 2025-09-12 13:39:10 +08:00
Co-authored-by: zhangjidi2016 <zhangjidi@cmss.chinamobile.com>
This commit is contained in:
@@ -16,7 +16,9 @@
|
||||
*/
|
||||
package org.apache.rocketmq.dashboard.controller;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import javax.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.rocketmq.dashboard.permisssion.Permission;
|
||||
import org.apache.rocketmq.dashboard.service.OpsService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -46,6 +48,15 @@ public class OpsController {
|
||||
return true;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/addNameSvrAddr.do", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object addNameSvrAddr(@RequestParam String newNamesrvAddr) {
|
||||
Preconditions.checkArgument(StringUtils.isNotEmpty(newNamesrvAddr),
|
||||
"namesrvAddr can not be blank");
|
||||
opsService.addNameSvrAddr(newNamesrvAddr);
|
||||
return true;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/updateIsVIPChannel.do", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object updateIsVIPChannel(@RequestParam String useVIPChannel) {
|
||||
@@ -53,14 +64,12 @@ public class OpsController {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/rocketMqStatus.query", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object clusterStatus() {
|
||||
return opsService.rocketMqStatusCheck();
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/updateUseTLS.do", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object updateUseTLS(@RequestParam String useTLS) {
|
||||
|
@@ -31,4 +31,6 @@ public interface OpsService {
|
||||
boolean updateIsVIPChannel(String useVIPChannel);
|
||||
|
||||
boolean updateUseTLS(boolean useTLS);
|
||||
|
||||
void addNameSvrAddr(String namesrvAddr);
|
||||
}
|
||||
|
@@ -73,7 +73,8 @@ public class OpsServiceImpl extends AbstractCommonService implements OpsService
|
||||
return checkResultMap;
|
||||
}
|
||||
|
||||
@Override public boolean updateIsVIPChannel(String useVIPChannel) {
|
||||
@Override
|
||||
public boolean updateIsVIPChannel(String useVIPChannel) {
|
||||
configure.setIsVIPChannel(useVIPChannel);
|
||||
mqAdminExtPool.clear();
|
||||
return true;
|
||||
@@ -85,4 +86,13 @@ public class OpsServiceImpl extends AbstractCommonService implements OpsService
|
||||
mqAdminExtPool.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNameSvrAddr(String namesrvAddr) {
|
||||
List<String> namesrvAddrs = configure.getNamesrvAddrs();
|
||||
if (namesrvAddrs != null && !namesrvAddrs.contains(namesrvAddr)) {
|
||||
namesrvAddrs.add(namesrvAddr);
|
||||
}
|
||||
configure.setNamesrvAddrs(namesrvAddrs);
|
||||
}
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ app.controller('opsController', ['$scope', '$location', '$http', 'Notification',
|
||||
$scope.userRole = $window.sessionStorage.getItem("userrole");
|
||||
$scope.writeOperationEnabled = $scope.userRole == null ? true : ($scope.userRole == 1 ? true : false);
|
||||
$scope.inputReadonly = !$scope.writeOperationEnabled;
|
||||
$scope.newNamesrvAddr = "";
|
||||
$http({
|
||||
method: "GET",
|
||||
url: "ops/homePage.query"
|
||||
@@ -53,6 +54,26 @@ app.controller('opsController', ['$scope', '$location', '$http', 'Notification',
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.addNameSvrAddr = function () {
|
||||
$http({
|
||||
method: "POST",
|
||||
url: "ops/addNameSvrAddr.do",
|
||||
params: {newNamesrvAddr: $scope.newNamesrvAddr}
|
||||
}).success(function (resp) {
|
||||
if (resp.status == 0) {
|
||||
if ($scope.namesvrAddrList.indexOf($scope.newNamesrvAddr) == -1) {
|
||||
$scope.namesvrAddrList.push($scope.newNamesrvAddr);
|
||||
}
|
||||
$("#namesrvAddr").val("");
|
||||
$scope.newNamesrvAddr = "";
|
||||
Notification.info({message: "SUCCESS", delay: 2000});
|
||||
} else {
|
||||
Notification.error({message: resp.errMsg, delay: 2000});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.updateIsVIPChannel = function () {
|
||||
$http({
|
||||
method: "POST",
|
||||
|
@@ -28,6 +28,15 @@
|
||||
ng-click="updateNameSvrAddr()">{{'UPDATE' | translate}}
|
||||
</button>
|
||||
</div>
|
||||
<form class="form-inline pull-left" style="margin-left: 20px" ng-show="{{writeOperationEnabled}}">
|
||||
<div class="form-group" style="margin: 0">
|
||||
<label for="namesrvAddr">NamesrvAddr:</label>
|
||||
<input id="namesrvAddr" class="form-control" style="width: 300px; margin: 0 10px 0 10px" type="text" ng-model="newNamesrvAddr" required/>
|
||||
<button class="btn btn-raised btn-sm btn-primary" type="button"
|
||||
ng-click="addNameSvrAddr()"> {{ 'ADD' | translate}}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<br/>
|
||||
<br/>
|
||||
<h2 class="md-title">IsUseVIPChannel</h2>
|
||||
|
@@ -63,7 +63,7 @@ public abstract class BaseControllerTest extends BaseTest {
|
||||
when(configure.getAccessKey()).thenReturn("12345678");
|
||||
when(configure.getSecretKey()).thenReturn("rocketmq");
|
||||
when(configure.getNamesrvAddr()).thenReturn("127.0.0.1:9876");
|
||||
when(configure.getNamesrvAddrs()).thenReturn(Lists.asList("127.0.0.1:9876", new String[] {"127.0.0.2:9876"}));
|
||||
when(configure.getNamesrvAddrs()).thenReturn(Lists.newArrayList("127.0.0.1:9876", "127.0.0.2:9876"));
|
||||
when(configure.isACLEnabled()).thenReturn(true);
|
||||
when(configure.isUseTLS()).thenReturn(false);
|
||||
}
|
||||
|
@@ -35,6 +35,7 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
@@ -83,6 +84,20 @@ public class OpsControllerTest extends BaseControllerTest {
|
||||
Assert.assertEquals(configure.getNamesrvAddr(), "127.0.0.1:9876");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddNameSvrAddr() throws Exception {
|
||||
final String url = "/ops/addNameSvrAddr.do";
|
||||
{
|
||||
doNothing().when(configure).setNamesrvAddrs(any());
|
||||
}
|
||||
requestBuilder = MockMvcRequestBuilders.post(url);
|
||||
requestBuilder.param("newNamesrvAddr", "127.0.0.3:9876");
|
||||
perform = mockMvc.perform(requestBuilder);
|
||||
perform.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data").value(true));
|
||||
Assert.assertEquals(configure.getNamesrvAddrs().size(), 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateIsVIPChannel() throws Exception {
|
||||
final String url = "/ops/updateIsVIPChannel.do";
|
||||
|
Reference in New Issue
Block a user