admin服务列表在线靠前

pull/1/head
tanghc 5 years ago
parent d166e425c0
commit 3a2d591005
  1. 2
      sop-admin/sop-admin-vue/src/views/service/serviceList.vue
  2. 14
      sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/service/impl/RegistryServiceNacos.java
  3. 4
      sop-gateway/src/main/java/com/gitee/sop/gateway/loadbalancer/EnvironmentServerChooser.java

@ -82,8 +82,10 @@
<el-button v-if="!scope.row.metadata.env" type="text" size="mini" @click="onEnvPreOpen(scope.row)">开启预发布</el-button> <el-button v-if="!scope.row.metadata.env" type="text" size="mini" @click="onEnvPreOpen(scope.row)">开启预发布</el-button>
<el-button v-if="!scope.row.metadata.env" type="text" size="mini" @click="onEnvGrayOpen(scope.row)">开启灰度</el-button> <el-button v-if="!scope.row.metadata.env" type="text" size="mini" @click="onEnvGrayOpen(scope.row)">开启灰度</el-button>
</span> </span>
<span style="margin-left: 10px;">
<el-button v-if="scope.row.status === 'UP'" type="text" size="mini" @click="onDisable(scope.row)">禁用</el-button> <el-button v-if="scope.row.status === 'UP'" type="text" size="mini" @click="onDisable(scope.row)">禁用</el-button>
<el-button v-if="scope.row.status === 'OUT_OF_SERVICE'" type="text" size="mini" @click="onEnable(scope.row)">启用</el-button> <el-button v-if="scope.row.status === 'OUT_OF_SERVICE'" type="text" size="mini" @click="onEnable(scope.row)">启用</el-button>
</span>
</div> </div>
</template> </template>
</el-table-column> </el-table-column>

@ -11,6 +11,7 @@ import com.gitee.sop.registryapi.bean.HttpTool;
import com.gitee.sop.registryapi.bean.ServiceInfo; import com.gitee.sop.registryapi.bean.ServiceInfo;
import com.gitee.sop.registryapi.bean.ServiceInstance; import com.gitee.sop.registryapi.bean.ServiceInstance;
import com.gitee.sop.registryapi.service.RegistryService; import com.gitee.sop.registryapi.service.RegistryService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -19,7 +20,6 @@ import javax.annotation.PostConstruct;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -28,6 +28,7 @@ import java.util.Map;
* nacos接口实现, https://nacos.io/zh-cn/docs/open-api.html * nacos接口实现, https://nacos.io/zh-cn/docs/open-api.html
* @author tanghc * @author tanghc
*/ */
@Slf4j
public class RegistryServiceNacos implements RegistryService { public class RegistryServiceNacos implements RegistryService {
static HttpTool httpTool = new HttpTool(); static HttpTool httpTool = new HttpTool();
@ -72,7 +73,7 @@ public class RegistryServiceNacos implements RegistryService {
} }
serviceInfoList.add(serviceInfo); serviceInfoList.add(serviceInfo);
} }
serviceInfoList.sort(Comparator.comparingInt(o -> o.getInstances().size())); serviceInfoList.sort((o1, o2) -> o2.getInstances().size() - o1.getInstances().size());
return serviceInfoList; return serviceInfoList;
} }
@ -107,7 +108,10 @@ public class RegistryServiceNacos implements RegistryService {
protected void updateInstance(Instance instance) throws IOException { protected void updateInstance(Instance instance) throws IOException {
String json = JSON.toJSONString(instance); String json = JSON.toJSONString(instance);
JSONObject jsonObject = JSON.parseObject(json); 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("ip", serviceInstance.getIp());
params.put("port", String.valueOf(serviceInstance.getPort())); params.put("port", String.valueOf(serviceInstance.getPort()));
String instanceJson = httpTool.request("http://" + nacosAddr + "/nacos/v1/ns/instance", params, null, HttpTool.HTTPMethod.GET); 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;
} }
} }

@ -5,7 +5,7 @@ import com.gitee.sop.gatewaycommon.bean.SpringContext;
import com.gitee.sop.gatewaycommon.param.Param; import com.gitee.sop.gatewaycommon.param.Param;
import com.gitee.sop.gatewaycommon.zuul.loadbalancer.BaseServerChooser; import com.gitee.sop.gatewaycommon.zuul.loadbalancer.BaseServerChooser;
import com.netflix.loadbalancer.Server; 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 org.springframework.core.env.Environment;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -41,7 +41,7 @@ public class EnvironmentServerChooser extends BaseServerChooser {
private String getEnvValue(Server server) { private String getEnvValue(Server server) {
// eureka存储的metadata // eureka存储的metadata
Map<String, String> metadata = ((DiscoveryEnabledServer) server).getInstanceInfo().getMetadata(); Map<String, String> metadata = ((NacosServer) server).getMetadata();
return metadata.get(MEDATA_KEY_ENV); return metadata.get(MEDATA_KEY_ENV);
} }

Loading…
Cancel
Save