91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

nacos address中deleteCluster的原理及用法

發布時間:2021-06-24 11:50:05 來源:億速云 閱讀:189 作者:chen 欄目:大數據

本篇內容主要講解“nacos address中deleteCluster的原理及用法”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“nacos address中deleteCluster的原理及用法”吧!

本文主要研究一下nacos address的deleteCluster

AddressServerClusterController

nacos-1.1.3/address/src/main/java/com/alibaba/nacos/address/controller/AddressServerClusterController.java

@RestController
@RequestMapping({AddressServerConstants.ADDRESS_SERVER_REQUEST_URL + "/nodes"})
public class AddressServerClusterController {

    @Autowired
    private ServiceManager serviceManager;

    @Autowired
    private AddressServerManager addressServerManager;

    @Autowired
    private AddressServerGeneratorManager addressServerGeneratorManager;

    //......

    @RequestMapping(value = "", method = RequestMethod.DELETE)
    public ResponseEntity deleteCluster(@RequestParam(required = false) String product,
                                        @RequestParam(required = false) String cluster,
                                        @RequestParam String ips) {
        //1. prepare the storage name for product and cluster
        String productName = addressServerGeneratorManager.generateProductName(product);
        String clusterName = addressServerManager.getDefaultClusterNameIfEmpty(cluster);

        //2. prepare the response name for product and cluster to client
        String rawProductName = addressServerManager.getRawProductName(product);
        String rawClusterName = addressServerManager.getRawClusterName(cluster);
        ResponseEntity responseEntity = ResponseEntity.status(HttpStatus.OK).body("product=" + rawProductName + ", cluster=" + rawClusterName + " delete success.");
        try {

            String serviceName = addressServerGeneratorManager.generateNacosServiceName(productName);
            Service service = serviceManager.getService(Constants.DEFAULT_NAMESPACE_ID, serviceName);

            if (service == null) {
                responseEntity = ResponseEntity.status(HttpStatus.NOT_FOUND).body("product=" + rawProductName + " not found.");
            } else {

                if (StringUtils.isBlank(ips)) {
                    // delete all ips from the cluster
                    responseEntity = ResponseEntity.status(HttpStatus.BAD_REQUEST).body("ips must not be empty.");
                } else {
                    // delete specified ip list
                    String[] ipArray = addressServerManager.splitIps(ips);
                    String checkResult = AddressServerParamCheckUtil.checkIps(ipArray);
                    if (AddressServerParamCheckUtil.CHECK_OK.equals(checkResult)) {
                        List<Instance> instanceList = addressServerGeneratorManager.generateInstancesByIps(serviceName, rawProductName, clusterName, ipArray);
                        serviceManager.removeInstance(Constants.DEFAULT_NAMESPACE_ID, serviceName, false, instanceList.toArray(new Instance[instanceList.size()]));
                    } else {
                        responseEntity = ResponseEntity.status(HttpStatus.BAD_REQUEST).body(checkResult);
                    }
                }
            }
        } catch (Exception e) {

            responseEntity = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getCause());
        }

        return responseEntity;
    }

    //......
}
  • deleteCluster接收product、cluster、ips參數;其中productName通過addressServerGeneratorManager.generateProductName(product)生成;clusterName通過addressServerManager.getDefaultClusterNameIfEmpty(cluster)生成

  • 它首先通過serviceManager.getService獲取service,獲取不到則返回404;若ips為空,返回400;之后通過addressServerGeneratorManager.generateInstancesByIps(serviceName, rawProductName, clusterName, ipArray)獲取instanceList

  • 最后通過serviceManager.removeInstance(Constants.DEFAULT_NAMESPACE_ID, serviceName, false, instanceList.toArray(new Instance[instanceList.size()]))移除instance;注意這里的ephemeral參數為false

ServiceManager

nacos-1.1.3/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java

@Component
@DependsOn("nacosApplicationContext")
public class ServiceManager implements RecordListener<Service> {

    /**
     * Map<namespace, Map<group::serviceName, Service>>
     */
    private Map<String, Map<String, Service>> serviceMap = new ConcurrentHashMap<>();

    private LinkedBlockingDeque<ServiceKey> toBeUpdatedServicesQueue = new LinkedBlockingDeque<>(1024 * 1024);

    private Synchronizer synchronizer = new ServiceStatusSynchronizer();

    private final Lock lock = new ReentrantLock();

    @Resource(name = "consistencyDelegate")
    private ConsistencyService consistencyService;

    @Autowired
    private SwitchDomain switchDomain;

    @Autowired
    private DistroMapper distroMapper;

    @Autowired
    private ServerListManager serverListManager;

    @Autowired
    private PushService pushService;

    private final Object putServiceLock = new Object();

    //......

    public Service getService(String namespaceId, String serviceName) {
        if (serviceMap.get(namespaceId) == null) {
            return null;
        }
        return chooseServiceMap(namespaceId).get(serviceName);
    }

    public Map<String, Service> chooseServiceMap(String namespaceId) {
        return serviceMap.get(namespaceId);
    }

    public void removeInstance(String namespaceId, String serviceName, boolean ephemeral, Instance... ips) throws NacosException {
        Service service = getService(namespaceId, serviceName);
        removeInstance(namespaceId, serviceName, ephemeral, service, ips);
    }

    public void removeInstance(String namespaceId, String serviceName, boolean ephemeral, Service service, Instance... ips) throws NacosException {

        String key = KeyBuilder.buildInstanceListKey(namespaceId, serviceName, ephemeral);

        List<Instance> instanceList = substractIpAddresses(service, ephemeral, ips);

        Instances instances = new Instances();
        instances.setInstanceList(instanceList);

        consistencyService.put(key, instances);
    }

    //......
}
  • getService方法直接從serviceMap中根據namespaceId獲取map,然后再根據serviceName獲取Service;removeInstance方法先獲取service,然后再移除指定的instance,最后更新到consistencyService

小結

  • deleteCluster接收product、cluster、ips參數;其中productName通過addressServerGeneratorManager.generateProductName(product)生成;clusterName通過addressServerManager.getDefaultClusterNameIfEmpty(cluster)生成

  • 它首先通過serviceManager.getService獲取service,獲取不到則返回404;若ips為空,返回400;之后通過addressServerGeneratorManager.generateInstancesByIps(serviceName, rawProductName, clusterName, ipArray)獲取instanceList

  • 最后通過serviceManager.removeInstance(Constants.DEFAULT_NAMESPACE_ID, serviceName, false, instanceList.toArray(new Instance[instanceList.size()]))移除instance;注意這里的ephemeral參數為false

到此,相信大家對“nacos address中deleteCluster的原理及用法”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

积石山| 康马县| 潼关县| 大新县| 兰州市| 安徽省| 浏阳市| 南昌市| 响水县| 黑山县| 北京市| 社会| 合山市| 济宁市| 凤台县| 北安市| 施甸县| 集贤县| 玛曲县| 临江市| 和平县| 敦煌市| 上虞市| 阳山县| 南投市| 巴彦淖尔市| 应城市| 桂阳县| 潮安县| 宾阳县| 连州市| 莱阳市| 遂平县| 分宜县| 西青区| 屏东县| 靖西县| 汤阴县| 和顺县| 共和县| 孟州市|