Search in sources :

Example 21 with Member

use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.

the class ClusterVersionJudgementTest method testPartMemberIsNewVersion.

@Test
public void testPartMemberIsNewVersion() {
    Collection<Member> allMembers = manager.allMembers();
    AtomicInteger count = new AtomicInteger();
    allMembers.forEach(member -> {
        if (count.get() == 0) {
            member.setExtendInfo(oldVersionMeta);
        } else {
            count.incrementAndGet();
            member.setExtendInfo(newVersionMeta);
        }
    });
    judgement = new ClusterVersionJudgement(manager);
    judgement.judge();
    Assert.assertFalse(judgement.allMemberIsNewVersion());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Member(com.alibaba.nacos.core.cluster.Member) Test(org.junit.Test)

Example 22 with Member

use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.

the class NotifyTaskProcessor method process.

@Override
public boolean process(NacosTask task) {
    NotifyTask notifyTask = (NotifyTask) task;
    String dataId = notifyTask.getDataId();
    String group = notifyTask.getGroup();
    String tenant = notifyTask.getTenant();
    long lastModified = notifyTask.getLastModified();
    boolean isok = true;
    for (Member ip : memberManager.allMembers()) {
        isok = notifyToDump(dataId, group, tenant, lastModified, ip.getAddress()) && isok;
    }
    return isok;
}
Also used : Member(com.alibaba.nacos.core.cluster.Member)

Example 23 with Member

use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.

the class ConfigSubService method runCollectionJob.

private List<SampleResult> runCollectionJob(String url, Map<String, String> params, CompletionService<SampleResult> completionService, List<SampleResult> resultList) {
    Collection<Member> ipList = memberManager.allMembers();
    List<SampleResult> collectionResult = new ArrayList<>(ipList.size());
    // Submit query task.
    for (Member ip : ipList) {
        try {
            completionService.submit(new Job(ip.getAddress(), url, params));
        } catch (Exception e) {
            // Send request failed.
            LogUtil.DEFAULT_LOG.warn("Get client info from {} with exception: {} during submit job", ip, e.getMessage());
        }
    }
    // Get and merge result.
    SampleResult sampleResults;
    for (Member member : ipList) {
        try {
            Future<SampleResult> f = completionService.poll(1000, TimeUnit.MILLISECONDS);
            try {
                if (f != null) {
                    sampleResults = f.get(500, TimeUnit.MILLISECONDS);
                    if (sampleResults != null) {
                        collectionResult.add(sampleResults);
                    }
                } else {
                    LogUtil.DEFAULT_LOG.warn("The task in ip: {}  did not completed in 1000ms ", member);
                }
            } catch (TimeoutException e) {
                f.cancel(true);
                LogUtil.DEFAULT_LOG.warn("get task result with TimeoutException: {} ", e.getMessage());
            }
        } catch (InterruptedException e) {
            LogUtil.DEFAULT_LOG.warn("get task result with InterruptedException: {} ", e.getMessage());
        } catch (ExecutionException e) {
            LogUtil.DEFAULT_LOG.warn("get task result with ExecutionException: {} ", e.getMessage());
        }
    }
    return collectionResult;
}
Also used : ArrayList(java.util.ArrayList) SampleResult(com.alibaba.nacos.config.server.model.SampleResult) ExecutionException(java.util.concurrent.ExecutionException) Member(com.alibaba.nacos.core.cluster.Member) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 24 with Member

use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.

the class ClientMetricsController method metric.

/**
 * get client metric.
 *
 * @param ip client ip .
 * @return ResponseEntity
 */
@GetMapping("/cluster")
public ResponseEntity metric(@RequestParam("ip") String ip, @RequestParam(value = "dataId", required = false) String dataId, @RequestParam(value = "group", required = false) String group, @RequestParam(value = "tenant", required = false) String tenant) {
    Loggers.CORE.info("Get cluster config metrics received, ip={},dataId={},group={},tenant={}", ip, dataId, group, tenant);
    Map<String, Object> responseMap = new HashMap<>(3);
    Collection<Member> members = serverMemberManager.allMembers();
    final NacosAsyncRestTemplate nacosAsyncRestTemplate = HttpClientBeanHolder.getNacosAsyncRestTemplate(Loggers.CLUSTER);
    CountDownLatch latch = new CountDownLatch(members.size());
    for (Member member : members) {
        String url = HttpUtils.buildUrl(false, member.getAddress(), EnvUtil.getContextPath(), Constants.METRICS_CONTROLLER_PATH, "current");
        Query query = Query.newInstance().addParam("ip", ip).addParam("dataId", dataId).addParam("group", group).addParam("tenant", tenant);
        nacosAsyncRestTemplate.get(url, Header.EMPTY, query, new GenericType<Map>() {
        }.getType(), new Callback<Map>() {

            @Override
            public void onReceive(RestResult<Map> result) {
                if (result.ok()) {
                    responseMap.putAll(result.getData());
                }
                latch.countDown();
            }

            @Override
            public void onError(Throwable throwable) {
                Loggers.CORE.error("Get config metrics error from member address={}, ip={},dataId={},group={},tenant={},error={}", member.getAddress(), ip, dataId, group, tenant, throwable);
                latch.countDown();
            }

            @Override
            public void onCancel() {
                latch.countDown();
            }
        });
    }
    try {
        latch.await(3L, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return ResponseEntity.ok().body(responseMap);
}
Also used : GenericType(com.alibaba.nacos.core.utils.GenericType) Query(com.alibaba.nacos.common.http.param.Query) HashMap(java.util.HashMap) NacosAsyncRestTemplate(com.alibaba.nacos.common.http.client.NacosAsyncRestTemplate) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.alibaba.nacos.core.cluster.Member) HashMap(java.util.HashMap) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 25 with Member

use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.

the class CurcuitFilter method listenerSelfInCluster.

private void listenerSelfInCluster() {
    protocol.protocolMetaData().subscribe(Constants.CONFIG_MODEL_RAFT_GROUP, MetadataKey.RAFT_GROUP_MEMBER, o -> {
        if (!(o instanceof ProtocolMetaData.ValueItem)) {
            return;
        }
        final List<String> peers = (List<String>) ((ProtocolMetaData.ValueItem) o).getData();
        if (CollectionUtils.isEmpty(peers)) {
            isOpenService = false;
            return;
        }
        final Member self = memberManager.getSelf();
        final String raftAddress = self.getIp() + ":" + self.getExtendVal(MemberMetaDataConstants.RAFT_PORT);
        // Only when you are in the cluster and the current Leader is
        // elected can you provide external services
        isOpenService = peers.contains(raftAddress);
    });
}
Also used : List(java.util.List) ProtocolMetaData(com.alibaba.nacos.consistency.ProtocolMetaData) Member(com.alibaba.nacos.core.cluster.Member)

Aggregations

Member (com.alibaba.nacos.core.cluster.Member)53 Test (org.junit.Test)17 NacosException (com.alibaba.nacos.api.exception.NacosException)11 HashMap (java.util.HashMap)11 Response (com.alibaba.nacos.api.remote.response.Response)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 DistroDataRequest (com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest)6 Map (java.util.Map)5 ServerLoaderInfoResponse (com.alibaba.nacos.api.remote.response.ServerLoaderInfoResponse)4 NacosAsyncRestTemplate (com.alibaba.nacos.common.http.client.NacosAsyncRestTemplate)4 DistroDataResponse (com.alibaba.nacos.naming.cluster.remote.response.DistroDataResponse)4 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 Before (org.junit.Before)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 ServerAbilities (com.alibaba.nacos.api.ability.ServerAbilities)3 RequestCallBack (com.alibaba.nacos.api.remote.RequestCallBack)3 ServerRemoteAbility (com.alibaba.nacos.api.remote.ability.ServerRemoteAbility)3 RestResult (com.alibaba.nacos.common.model.RestResult)3 GenericType (com.alibaba.nacos.core.utils.GenericType)3