Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #58]Supports adding namesrvAddr cluster management #66

Merged
merged 1 commit into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,21 +48,28 @@ public Object updateNameSvrAddr(@RequestParam String nameSvrAddrList) {
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) {
opsService.updateIsVIPChannel(useVIPChannel);
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public interface OpsService {
boolean updateIsVIPChannel(String useVIPChannel);

boolean updateUseTLS(boolean useTLS);

void addNameSvrAddr(String namesrvAddr);
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public Map<CheckerType, Object> rocketMqStatusCheck() {
return checkResultMap;
}

@Override public boolean updateIsVIPChannel(String useVIPChannel) {
@Override
public boolean updateIsVIPChannel(String useVIPChannel) {
configure.setIsVIPChannel(useVIPChannel);
mqAdminExtPool.clear();
return true;
Expand All @@ -85,4 +86,13 @@ public boolean updateUseTLS(boolean useTLS) {
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);
}
}
21 changes: 21 additions & 0 deletions src/main/resources/static/src/ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/static/view/pages/ops.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ <h2 class="md-title">NameServerAddressList</h2>
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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected void mockRmqConfigure() {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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;
Expand Down Expand Up @@ -83,6 +84,20 @@ public void testUpdateNameSvrAddr() throws Exception {
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";
Expand Down