Search in sources :

Example 6 with ClusterGroupEntity

use of com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity in project Sentinel by alibaba.

the class ClusterAssignServiceImpl method unbindClusterServer.

@Override
public ClusterAppAssignResultVO unbindClusterServer(String app, String machineId) {
    AssertUtil.assertNotBlank(app, "app cannot be blank");
    AssertUtil.assertNotBlank(machineId, "machineId cannot be blank");
    if (isMachineInApp(machineId)) {
        return handleUnbindClusterServerNotInApp(app, machineId);
    }
    Set<String> failedSet = new HashSet<>();
    try {
        ClusterGroupEntity entity = clusterConfigService.getClusterUniversalStateForAppMachine(app, machineId).get(10, TimeUnit.SECONDS);
        Set<String> toModifySet = new HashSet<>();
        toModifySet.add(machineId);
        if (entity.getClientSet() != null) {
            toModifySet.addAll(entity.getClientSet());
        }
        // Modify mode to NOT-STARTED for all chosen token servers and associated token clients.
        modifyToNonStarted(toModifySet, failedSet);
    } catch (Exception ex) {
        Throwable e = ex instanceof ExecutionException ? ex.getCause() : ex;
        LOGGER.error("Failed to unbind machine <{}>", machineId, e);
        failedSet.add(machineId);
    }
    return new ClusterAppAssignResultVO().setFailedClientSet(failedSet).setFailedServerSet(new HashSet<>());
}
Also used : ClusterGroupEntity(com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity) ExecutionException(java.util.concurrent.ExecutionException) ClusterAppAssignResultVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet)

Example 7 with ClusterGroupEntity

use of com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity in project Sentinel by alibaba.

the class ClusterConfigService method getClusterUniversalStateForAppMachine.

public CompletableFuture<ClusterGroupEntity> getClusterUniversalStateForAppMachine(String app, String machineId) {
    if (StringUtil.isBlank(app)) {
        return AsyncUtils.newFailedFuture(new IllegalArgumentException("app cannot be empty"));
    }
    AppInfo appInfo = appManagement.getDetailApp(app);
    if (appInfo == null || appInfo.getMachines() == null) {
        return AsyncUtils.newFailedFuture(new IllegalArgumentException("app does not have machines"));
    }
    boolean machineOk = appInfo.getMachines().stream().filter(e -> e.isHealthy()).map(e -> e.getIp() + '@' + e.getPort()).anyMatch(e -> e.equals(machineId));
    if (!machineOk) {
        return AsyncUtils.newFailedFuture(new IllegalStateException("machine does not exist or disconnected"));
    }
    return getClusterUniversalState(app).thenApply(ClusterEntityUtils::wrapToClusterGroup).thenCompose(e -> e.stream().filter(e1 -> e1.getMachineId().equals(machineId)).findAny().map(CompletableFuture::completedFuture).orElse(AsyncUtils.newFailedFuture(new IllegalStateException("not a server: " + machineId))));
}
Also used : AppManagement(com.alibaba.csp.sentinel.dashboard.discovery.AppManagement) ClusterServerModifyRequest(com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest) ClusterUniversalStateVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStateVO) ClusterGroupEntity(com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity) ClusterClientStateVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterClientStateVO) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) CompletableFuture(java.util.concurrent.CompletableFuture) Collectors(java.util.stream.Collectors) AppInfo(com.alibaba.csp.sentinel.dashboard.discovery.AppInfo) ArrayList(java.util.ArrayList) ClusterClientModifyRequest(com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest) AsyncUtils(com.alibaba.csp.sentinel.dashboard.util.AsyncUtils) StringUtil(com.alibaba.csp.sentinel.util.StringUtil) ServerFlowConfig(com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig) List(java.util.List) ServerTransportConfig(com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig) SentinelApiClient(com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient) Service(org.springframework.stereotype.Service) ClusterUniversalStatePairVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO) ClusterEntityUtils(com.alibaba.csp.sentinel.dashboard.util.ClusterEntityUtils) ClusterClientConfig(com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ClusterClientConfig) ClusterStateManager(com.alibaba.csp.sentinel.cluster.ClusterStateManager) CompletableFuture(java.util.concurrent.CompletableFuture) AppInfo(com.alibaba.csp.sentinel.dashboard.discovery.AppInfo)

Example 8 with ClusterGroupEntity

use of com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity in project pig by pig-mesh.

the class ClusterConfigService method getClusterUniversalStateForAppMachine.

public CompletableFuture<ClusterGroupEntity> getClusterUniversalStateForAppMachine(String app, String machineId) {
    if (StringUtil.isBlank(app)) {
        return AsyncUtils.newFailedFuture(new IllegalArgumentException("app cannot be empty"));
    }
    AppInfo appInfo = appManagement.getDetailApp(app);
    if (appInfo == null || appInfo.getMachines() == null) {
        return AsyncUtils.newFailedFuture(new IllegalArgumentException("app does not have machines"));
    }
    boolean machineOk = appInfo.getMachines().stream().filter(e -> e.isHealthy()).map(e -> e.getIp() + '@' + e.getPort()).anyMatch(e -> e.equals(machineId));
    if (!machineOk) {
        return AsyncUtils.newFailedFuture(new IllegalStateException("machine does not exist or disconnected"));
    }
    return getClusterUniversalState(app).thenApply(ClusterEntityUtils::wrapToClusterGroup).thenCompose(e -> e.stream().filter(e1 -> e1.getMachineId().equals(machineId)).findAny().map(CompletableFuture::completedFuture).orElse(AsyncUtils.newFailedFuture(new IllegalStateException("not a server: " + machineId))));
}
Also used : AppManagement(com.alibaba.csp.sentinel.dashboard.discovery.AppManagement) ClusterServerModifyRequest(com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest) ClusterUniversalStateVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStateVO) ClusterGroupEntity(com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity) ClusterClientStateVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterClientStateVO) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) CompletableFuture(java.util.concurrent.CompletableFuture) Collectors(java.util.stream.Collectors) AppInfo(com.alibaba.csp.sentinel.dashboard.discovery.AppInfo) ArrayList(java.util.ArrayList) ClusterClientModifyRequest(com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest) AsyncUtils(com.alibaba.csp.sentinel.dashboard.util.AsyncUtils) StringUtil(com.alibaba.csp.sentinel.util.StringUtil) ServerFlowConfig(com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig) List(java.util.List) ServerTransportConfig(com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig) SentinelApiClient(com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient) Service(org.springframework.stereotype.Service) ClusterUniversalStatePairVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO) ClusterEntityUtils(com.alibaba.csp.sentinel.dashboard.util.ClusterEntityUtils) ClusterClientConfig(com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ClusterClientConfig) ClusterStateManager(com.alibaba.csp.sentinel.cluster.ClusterStateManager) CompletableFuture(java.util.concurrent.CompletableFuture) AppInfo(com.alibaba.csp.sentinel.dashboard.discovery.AppInfo)

Example 9 with ClusterGroupEntity

use of com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity in project pig by pig-mesh.

the class ClusterAssignServiceImpl method unbindClusterServer.

@Override
public ClusterAppAssignResultVO unbindClusterServer(String app, String machineId) {
    AssertUtil.assertNotBlank(app, "app cannot be blank");
    AssertUtil.assertNotBlank(machineId, "machineId cannot be blank");
    if (isMachineInApp(machineId)) {
        return handleUnbindClusterServerNotInApp(app, machineId);
    }
    Set<String> failedSet = new HashSet<>();
    try {
        ClusterGroupEntity entity = clusterConfigService.getClusterUniversalStateForAppMachine(app, machineId).get(10, TimeUnit.SECONDS);
        Set<String> toModifySet = new HashSet<>();
        toModifySet.add(machineId);
        if (entity.getClientSet() != null) {
            toModifySet.addAll(entity.getClientSet());
        }
        // Modify mode to NOT-STARTED for all chosen token servers and associated
        // token clients.
        modifyToNonStarted(toModifySet, failedSet);
    } catch (Exception ex) {
        Throwable e = ex instanceof ExecutionException ? ex.getCause() : ex;
        LOGGER.error("Failed to unbind machine <{}>", machineId, e);
        failedSet.add(machineId);
    }
    return new ClusterAppAssignResultVO().setFailedClientSet(failedSet).setFailedServerSet(new HashSet<>());
}
Also used : ClusterGroupEntity(com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity) ExecutionException(java.util.concurrent.ExecutionException) ClusterAppAssignResultVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet)

Example 10 with ClusterGroupEntity

use of com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity in project spring-boot-student by wyh-spring-ecosystem-student.

the class ClusterConfigService method getClusterUniversalStateForAppMachine.

public CompletableFuture<ClusterGroupEntity> getClusterUniversalStateForAppMachine(String app, String machineId) {
    if (StringUtil.isBlank(app)) {
        return AsyncUtils.newFailedFuture(new IllegalArgumentException("app cannot be empty"));
    }
    AppInfo appInfo = appManagement.getDetailApp(app);
    if (appInfo == null || appInfo.getMachines() == null) {
        return AsyncUtils.newFailedFuture(new IllegalArgumentException("app does not have machines"));
    }
    boolean machineOk = appInfo.getMachines().stream().filter(e -> e.isHealthy()).map(e -> e.getIp() + '@' + e.getPort()).anyMatch(e -> e.equals(machineId));
    if (!machineOk) {
        return AsyncUtils.newFailedFuture(new IllegalStateException("machine does not exist or disconnected"));
    }
    return getClusterUniversalState(app).thenApply(ClusterEntityUtils::wrapToClusterGroup).thenCompose(e -> e.stream().filter(e1 -> e1.getMachineId().equals(machineId)).findAny().map(CompletableFuture::completedFuture).orElse(AsyncUtils.newFailedFuture(new IllegalStateException("not a server: " + machineId))));
}
Also used : AppManagement(com.alibaba.csp.sentinel.dashboard.discovery.AppManagement) ClusterServerModifyRequest(com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest) ClusterUniversalStateVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStateVO) ClusterGroupEntity(com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity) ClusterClientStateVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterClientStateVO) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) CompletableFuture(java.util.concurrent.CompletableFuture) Collectors(java.util.stream.Collectors) AppInfo(com.alibaba.csp.sentinel.dashboard.discovery.AppInfo) ArrayList(java.util.ArrayList) ClusterClientModifyRequest(com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest) AsyncUtils(com.alibaba.csp.sentinel.dashboard.util.AsyncUtils) StringUtil(com.alibaba.csp.sentinel.util.StringUtil) ServerFlowConfig(com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig) List(java.util.List) ServerTransportConfig(com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig) SentinelApiClient(com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient) Service(org.springframework.stereotype.Service) ClusterUniversalStatePairVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO) ClusterEntityUtils(com.alibaba.csp.sentinel.dashboard.util.ClusterEntityUtils) ClusterClientConfig(com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ClusterClientConfig) ClusterStateManager(com.alibaba.csp.sentinel.cluster.ClusterStateManager) CompletableFuture(java.util.concurrent.CompletableFuture) AppInfo(com.alibaba.csp.sentinel.dashboard.discovery.AppInfo)

Aggregations

ClusterGroupEntity (com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity)15 ClusterUniversalStatePairVO (com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO)9 ArrayList (java.util.ArrayList)9 ClusterStateManager (com.alibaba.csp.sentinel.cluster.ClusterStateManager)5 SentinelApiClient (com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient)5 AppInfo (com.alibaba.csp.sentinel.dashboard.discovery.AppInfo)5 AppManagement (com.alibaba.csp.sentinel.dashboard.discovery.AppManagement)5 ClusterAppAssignResultVO (com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO)5 ClusterClientConfig (com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ClusterClientConfig)5 ServerFlowConfig (com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig)5 ServerTransportConfig (com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig)5 ClusterClientModifyRequest (com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest)5 ClusterServerModifyRequest (com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest)5 ClusterClientStateVO (com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterClientStateVO)5 ClusterUniversalStateVO (com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStateVO)5 AsyncUtils (com.alibaba.csp.sentinel.dashboard.util.AsyncUtils)5 ClusterEntityUtils (com.alibaba.csp.sentinel.dashboard.util.ClusterEntityUtils)5 StringUtil (com.alibaba.csp.sentinel.util.StringUtil)5 HashSet (java.util.HashSet)5 List (java.util.List)5