diff --git a/sop-admin/sop-admin-vue/src/views/service/serviceList.vue b/sop-admin/sop-admin-vue/src/views/service/serviceList.vue index d4847174..225078a6 100644 --- a/sop-admin/sop-admin-vue/src/views/service/serviceList.vue +++ b/sop-admin/sop-admin-vue/src/views/service/serviceList.vue @@ -82,8 +82,10 @@ 开启预发布 开启灰度 - 禁用 - 启用 + + 禁用 + 启用 + diff --git a/sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/service/impl/RegistryServiceNacos.java b/sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/service/impl/RegistryServiceNacos.java index 00b31d85..03c0614d 100644 --- a/sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/service/impl/RegistryServiceNacos.java +++ b/sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/service/impl/RegistryServiceNacos.java @@ -11,6 +11,7 @@ import com.gitee.sop.registryapi.bean.HttpTool; import com.gitee.sop.registryapi.bean.ServiceInfo; import com.gitee.sop.registryapi.bean.ServiceInstance; import com.gitee.sop.registryapi.service.RegistryService; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.util.CollectionUtils; @@ -19,7 +20,6 @@ import javax.annotation.PostConstruct; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -28,6 +28,7 @@ import java.util.Map; * nacos接口实现, https://nacos.io/zh-cn/docs/open-api.html * @author tanghc */ +@Slf4j public class RegistryServiceNacos implements RegistryService { static HttpTool httpTool = new HttpTool(); @@ -72,7 +73,7 @@ public class RegistryServiceNacos implements RegistryService { } serviceInfoList.add(serviceInfo); } - serviceInfoList.sort(Comparator.comparingInt(o -> o.getInstances().size())); + serviceInfoList.sort((o1, o2) -> o2.getInstances().size() - o1.getInstances().size()); return serviceInfoList; } @@ -107,7 +108,10 @@ public class RegistryServiceNacos implements RegistryService { protected void updateInstance(Instance instance) throws IOException { String json = JSON.toJSONString(instance); JSONObject jsonObject = JSON.parseObject(json); - httpTool.request("http://" + nacosAddr + "/nacos/v1/ns/instance", jsonObject, null, HttpTool.HTTPMethod.PUT); + String response = httpTool.request("http://" + nacosAddr + "/nacos/v1/ns/instance", jsonObject, null, HttpTool.HTTPMethod.PUT); + if (!"ok".equalsIgnoreCase(response)) { + throw new RuntimeException(response); + } } /** @@ -122,6 +126,8 @@ public class RegistryServiceNacos implements RegistryService { params.put("ip", serviceInstance.getIp()); params.put("port", String.valueOf(serviceInstance.getPort())); String instanceJson = httpTool.request("http://" + nacosAddr + "/nacos/v1/ns/instance", params, null, HttpTool.HTTPMethod.GET); - return JSON.parseObject(instanceJson, Instance.class); + Instance instance = JSON.parseObject(instanceJson, Instance.class); + instance.setServiceName(serviceInstance.getServiceId()); + return instance; } } diff --git a/sop-gateway/src/main/java/com/gitee/sop/gateway/loadbalancer/EnvironmentServerChooser.java b/sop-gateway/src/main/java/com/gitee/sop/gateway/loadbalancer/EnvironmentServerChooser.java index addf958c..fbd1f74a 100644 --- a/sop-gateway/src/main/java/com/gitee/sop/gateway/loadbalancer/EnvironmentServerChooser.java +++ b/sop-gateway/src/main/java/com/gitee/sop/gateway/loadbalancer/EnvironmentServerChooser.java @@ -5,7 +5,7 @@ import com.gitee.sop.gatewaycommon.bean.SpringContext; import com.gitee.sop.gatewaycommon.param.Param; import com.gitee.sop.gatewaycommon.zuul.loadbalancer.BaseServerChooser; import com.netflix.loadbalancer.Server; -import com.netflix.niws.loadbalancer.DiscoveryEnabledServer; +import org.springframework.cloud.alibaba.nacos.ribbon.NacosServer; import org.springframework.core.env.Environment; import javax.servlet.http.HttpServletRequest; @@ -41,7 +41,7 @@ public class EnvironmentServerChooser extends BaseServerChooser { private String getEnvValue(Server server) { // eureka存储的metadata - Map metadata = ((DiscoveryEnabledServer) server).getInstanceInfo().getMetadata(); + Map metadata = ((NacosServer) server).getMetadata(); return metadata.get(MEDATA_KEY_ENV); }