Commit ed132fe2 by Nepxion

增加图形化灰度发布功能

parent 788bb2ec
...@@ -113,6 +113,24 @@ public class ServiceController { ...@@ -113,6 +113,24 @@ public class ServiceController {
return result; return result;
} }
public static String remoteConfigUpdate(String group, String serviceId, String config) {
String url = getUrl() + "/console/remote-config/update/" + group + "/" + serviceId;
// 解决中文乱码
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
HttpEntity<String> entity = new HttpEntity<String>(config, headers);
String result = restTemplate.postForEntity(url, entity, String.class).getBody();
if (!StringUtils.equals(result, "OK") && !StringUtils.equals(result, "NO")) {
ServiceErrorHandler errorHandler = (ServiceErrorHandler) restTemplate.getErrorHandler();
result = errorHandler.getCause();
}
return result;
}
public static List<ResultEntity> configUpdate(String serviceId, String config) { public static List<ResultEntity> configUpdate(String serviceId, String config) {
String url = getUrl() + "/console/config/update-sync/" + serviceId; String url = getUrl() + "/console/config/update-sync/" + serviceId;
...@@ -145,6 +163,19 @@ public class ServiceController { ...@@ -145,6 +163,19 @@ public class ServiceController {
return result; return result;
} }
public static String remoteConfigClear(String group, String serviceId) {
String url = getUrl() + "/console/remote-config/clear/" + group + "/" + serviceId;
String result = restTemplate.postForEntity(url, null, String.class).getBody();
if (!StringUtils.equals(result, "OK") && !StringUtils.equals(result, "NO")) {
ServiceErrorHandler errorHandler = (ServiceErrorHandler) restTemplate.getErrorHandler();
result = errorHandler.getCause();
}
return result;
}
public static List<ResultEntity> configClear(String serviceId) { public static List<ResultEntity> configClear(String serviceId) {
String url = getUrl() + "/console/config/clear/" + serviceId; String url = getUrl() + "/console/config/clear/" + serviceId;
......
...@@ -19,18 +19,9 @@ import org.apache.commons.lang3.builder.ToStringStyle; ...@@ -19,18 +19,9 @@ import org.apache.commons.lang3.builder.ToStringStyle;
public class ResultEntity implements Serializable { public class ResultEntity implements Serializable {
private static final long serialVersionUID = -3322655604556025836L; private static final long serialVersionUID = -3322655604556025836L;
private String serviceId;
private String url; private String url;
private String result; private String result;
public String getServiceId() {
return serviceId;
}
public void setServiceId(String serviceId) {
this.serviceId = serviceId;
}
public String getUrl() { public String getUrl() {
return url; return url;
} }
......
...@@ -812,19 +812,21 @@ public class ServiceTopology extends AbstractTopology { ...@@ -812,19 +812,21 @@ public class ServiceTopology extends AbstractTopology {
this.group = group; this.group = group;
this.node = null; this.node = null;
boolean versionControlEnabled = false; boolean versionControlEnabled = ruleToConfigCenterRadioButtonMenuItem.isSelected();
boolean ruleControlEnabled = false; boolean ruleControlEnabled = ruleToConfigCenterRadioButtonMenuItem.isSelected();
for (Iterator<TNode> iterator = group.children(); iterator.hasNext();) { if (!versionControlEnabled && !ruleControlEnabled) {
TNode node = iterator.next(); for (Iterator<TNode> iterator = group.children(); iterator.hasNext();) {
InstanceEntity instance = (InstanceEntity) node.getUserObject(); TNode node = iterator.next();
InstanceEntity instance = (InstanceEntity) node.getUserObject();
boolean versionEnabled = instance.isDiscoveryControlEnabled(); boolean versionEnabled = instance.isDiscoveryControlEnabled();
if (versionEnabled) { if (versionEnabled) {
versionControlEnabled = true; versionControlEnabled = true;
} }
boolean ruleEnabled = instance.isDiscoveryControlEnabled() && instance.isConfigRestControlEnabled(); boolean ruleEnabled = instance.isDiscoveryControlEnabled() && instance.isConfigRestControlEnabled();
if (ruleEnabled) { if (ruleEnabled) {
ruleControlEnabled = true; ruleControlEnabled = true;
}
} }
} }
...@@ -865,7 +867,7 @@ public class ServiceTopology extends AbstractTopology { ...@@ -865,7 +867,7 @@ public class ServiceTopology extends AbstractTopology {
InstanceEntity instance = (InstanceEntity) node.getUserObject(); InstanceEntity instance = (InstanceEntity) node.getUserObject();
boolean versionControlEnabled = instance.isDiscoveryControlEnabled(); boolean versionControlEnabled = instance.isDiscoveryControlEnabled();
boolean ruleControlEnabled = instance.isDiscoveryControlEnabled() && instance.isConfigRestControlEnabled(); boolean ruleControlEnabled = instance.isDiscoveryControlEnabled() && instance.isConfigRestControlEnabled() && !ruleToConfigCenterRadioButtonMenuItem.isSelected();
if (versionTabbedPane.getTabCount() == 1) { if (versionTabbedPane.getTabCount() == 1) {
versionTabbedPane.addTab(ConsoleLocale.getString("label_local_version"), localVersionPanel, ConsoleLocale.getString("label_local_version")); versionTabbedPane.addTab(ConsoleLocale.getString("label_local_version"), localVersionPanel, ConsoleLocale.getString("label_local_version"));
...@@ -1009,18 +1011,35 @@ public class ServiceTopology extends AbstractTopology { ...@@ -1009,18 +1011,35 @@ public class ServiceTopology extends AbstractTopology {
if (group != null) { if (group != null) {
String serviceId = (String) group.getUserObject(); String serviceId = (String) group.getUserObject();
List<ResultEntity> results = null;
try {
results = ServiceController.configUpdate(serviceId, dynamicRule);
} catch (Exception ex) {
JExceptionDialog.traceException(HandleManager.getFrame(ServiceTopology.this), ConsoleLocale.getString("query_data_failure"), ex);
refreshGrayState(group); if (ruleToConfigCenterRadioButtonMenuItem.isSelected()) {
String filter = getFilter(group);
String result = null;
try {
result = ServiceController.remoteConfigUpdate(filter, serviceId, dynamicRule);
} catch (Exception ex) {
JExceptionDialog.traceException(HandleManager.getFrame(ServiceTopology.this), ConsoleLocale.getString("query_data_failure"), ex);
return; refreshGrayState(group);
}
showResult(results); return;
}
showResult(result);
} else {
List<ResultEntity> results = null;
try {
results = ServiceController.configUpdate(serviceId, dynamicRule);
} catch (Exception ex) {
JExceptionDialog.traceException(HandleManager.getFrame(ServiceTopology.this), ConsoleLocale.getString("query_data_failure"), ex);
refreshGrayState(group);
return;
}
showResult(results);
}
refreshGrayState(group); refreshGrayState(group);
} else if (node != null) { } else if (node != null) {
...@@ -1054,18 +1073,34 @@ public class ServiceTopology extends AbstractTopology { ...@@ -1054,18 +1073,34 @@ public class ServiceTopology extends AbstractTopology {
public void execute(ActionEvent e) { public void execute(ActionEvent e) {
if (group != null) { if (group != null) {
String serviceId = (String) group.getUserObject(); String serviceId = (String) group.getUserObject();
List<ResultEntity> results = null; if (ruleToConfigCenterRadioButtonMenuItem.isSelected()) {
try { String filter = getFilter(group);
results = ServiceController.configClear(serviceId); String result = null;
} catch (Exception ex) { try {
JExceptionDialog.traceException(HandleManager.getFrame(ServiceTopology.this), ConsoleLocale.getString("query_data_failure"), ex); result = ServiceController.remoteConfigClear(filter, serviceId);
} catch (Exception ex) {
JExceptionDialog.traceException(HandleManager.getFrame(ServiceTopology.this), ConsoleLocale.getString("query_data_failure"), ex);
refreshGrayState(group); refreshGrayState(group);
return; return;
} }
showResult(results); showResult(result);
} else {
List<ResultEntity> results = null;
try {
results = ServiceController.configClear(serviceId);
} catch (Exception ex) {
JExceptionDialog.traceException(HandleManager.getFrame(ServiceTopology.this), ConsoleLocale.getString("query_data_failure"), ex);
refreshGrayState(group);
return;
}
showResult(results);
}
refreshGrayState(group); refreshGrayState(group);
} else if (node != null) { } else if (node != null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment