Search in sources :

Example 21 with ClusterService

use of com.hazelcast.internal.cluster.ClusterService in project hazelcast by hazelcast.

the class ClusterServiceMemberListTest method verifyMembersFromDataMember.

private void verifyMembersFromDataMember(final HazelcastInstance instance) {
    final Member localMember = getLocalMember(instance);
    final ClusterService clusterService = getClusterService(instance);
    final Collection<Member> liteMembers = clusterService.getMembers(LITE_MEMBER_SELECTOR);
    final Collection<Member> dataMembers = clusterService.getMembers(DATA_MEMBER_SELECTOR);
    assertContains(dataMembers, localMember);
    assertNotContains(liteMembers, localMember);
    final Collection<Member> dataMembersWithoutThis = clusterService.getMembers(MemberSelectors.and(DATA_MEMBER_SELECTOR, NON_LOCAL_MEMBER_SELECTOR));
    assertNotContains(dataMembersWithoutThis, localMember);
    final Collection<Member> liteMembersWithThis = clusterService.getMembers(MemberSelectors.or(LITE_MEMBER_SELECTOR, LOCAL_MEMBER_SELECTOR));
    assertContains(liteMembersWithThis, localMember);
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) Member(com.hazelcast.core.Member)

Example 22 with ClusterService

use of com.hazelcast.internal.cluster.ClusterService in project hazelcast by hazelcast.

the class ClusterServiceMemberListTest method verifySizeFromDataMember.

private void verifySizeFromDataMember(final HazelcastInstance instance) {
    final ClusterService clusterService = getClusterService(instance);
    assertEquals(1, clusterService.getSize(MemberSelectors.LITE_MEMBER_SELECTOR));
    assertEquals(2, clusterService.getSize(MemberSelectors.DATA_MEMBER_SELECTOR));
    assertEquals(1, clusterService.getSize(MemberSelectors.and(DATA_MEMBER_SELECTOR, NON_LOCAL_MEMBER_SELECTOR)));
    assertEquals(2, clusterService.getSize(MemberSelectors.or(LITE_MEMBER_SELECTOR, LOCAL_MEMBER_SELECTOR)));
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService)

Example 23 with ClusterService

use of com.hazelcast.internal.cluster.ClusterService in project hazelcast by hazelcast.

the class XAResourceImpl method recover.

@Override
public Xid[] recover(int flag) throws XAException {
    NodeEngine nodeEngine = getNodeEngine();
    XAService xaService = getService();
    OperationService operationService = nodeEngine.getOperationService();
    ClusterService clusterService = nodeEngine.getClusterService();
    Collection<Member> memberList = clusterService.getMembers();
    List<Future<SerializableList>> futureList = new ArrayList<Future<SerializableList>>();
    for (Member member : memberList) {
        if (member.localMember()) {
            continue;
        }
        CollectRemoteTransactionsOperation op = new CollectRemoteTransactionsOperation();
        Address address = member.getAddress();
        InternalCompletableFuture<SerializableList> future = operationService.invokeOnTarget(SERVICE_NAME, op, address);
        futureList.add(future);
    }
    HashSet<SerializableXID> xids = new HashSet<SerializableXID>();
    xids.addAll(xaService.getPreparedXids());
    for (Future<SerializableList> future : futureList) {
        try {
            SerializableList xidSet = future.get();
            for (Data xidData : xidSet) {
                SerializableXID xid = nodeEngine.toObject(xidData);
                xids.add(xid);
            }
        } catch (InterruptedException e) {
            throw new XAException(XAException.XAER_RMERR);
        } catch (MemberLeftException e) {
            logger.warning("Member left while recovering", e);
        } catch (ExecutionException e) {
            Throwable cause = e.getCause();
            if (cause instanceof HazelcastInstanceNotActiveException || cause instanceof TargetNotMemberException) {
                logger.warning("Member left while recovering", e);
            } else {
                throw new XAException(XAException.XAER_RMERR);
            }
        }
    }
    return xids.toArray(new SerializableXID[xids.size()]);
}
Also used : Address(com.hazelcast.nio.Address) SerializableList(com.hazelcast.spi.impl.SerializableList) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NodeEngine(com.hazelcast.spi.NodeEngine) CollectRemoteTransactionsOperation(com.hazelcast.transaction.impl.xa.operations.CollectRemoteTransactionsOperation) ExecutionException(java.util.concurrent.ExecutionException) Member(com.hazelcast.core.Member) HashSet(java.util.HashSet) MemberLeftException(com.hazelcast.core.MemberLeftException) XAException(javax.transaction.xa.XAException) Data(com.hazelcast.nio.serialization.Data) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) ClusterService(com.hazelcast.internal.cluster.ClusterService) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) Future(java.util.concurrent.Future) OperationService(com.hazelcast.spi.OperationService)

Example 24 with ClusterService

use of com.hazelcast.internal.cluster.ClusterService in project hazelcast by hazelcast.

the class TransactionImpl method purgeBackupLogs.

private void purgeBackupLogs() {
    if (!backupLogsCreated) {
        return;
    }
    OperationService operationService = nodeEngine.getOperationService();
    ClusterService clusterService = nodeEngine.getClusterService();
    for (Address backupAddress : backupAddresses) {
        if (clusterService.getMember(backupAddress) != null) {
            try {
                operationService.invokeOnTarget(SERVICE_NAME, createPurgeTxBackupLogOperation(), backupAddress);
            } catch (Throwable e) {
                logger.warning("Error during purging backups!", e);
            }
        }
    }
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) Address(com.hazelcast.nio.Address) OperationService(com.hazelcast.spi.OperationService)

Example 25 with ClusterService

use of com.hazelcast.internal.cluster.ClusterService in project hazelcast by hazelcast.

the class AbstractMapReduceTask method startSupervisionTask.

private void startSupervisionTask(JobTracker jobTracker) {
    final MapReduceService mapReduceService = getService(MapReduceService.SERVICE_NAME);
    final JobTrackerConfig config = ((AbstractJobTracker) jobTracker).getJobTrackerConfig();
    final boolean communicateStats = config.isCommunicateStats();
    final int chunkSize = getChunkSizeOrConfigChunkSize(config);
    final TopologyChangedStrategy topologyChangedStrategy = getTopologyChangedStrategyOrConfigTopologyChangedStrategy(config);
    final String name = getDistributedObjectName();
    final String jobId = getJobId();
    final KeyValueSource keyValueSource = getKeyValueSource();
    final Mapper mapper = getMapper();
    final CombinerFactory combinerFactory = getCombinerFactory();
    final ReducerFactory reducerFactory = getReducerFactory();
    final Collection keys = getKeys();
    final Collection<Object> keyObjects = getKeyObjects(keys);
    final KeyPredicate predicate = getPredicate();
    final ClusterService clusterService = nodeEngine.getClusterService();
    for (Member member : clusterService.getMembers(KeyValueJobOperation.MEMBER_SELECTOR)) {
        Operation operation = new KeyValueJobOperation(name, jobId, chunkSize, keyValueSource, mapper, combinerFactory, reducerFactory, communicateStats, topologyChangedStrategy);
        executeOperation(operation, member.getAddress(), mapReduceService, nodeEngine);
    }
    // After we prepared all the remote systems we can now start the processing
    for (Member member : clusterService.getMembers(DATA_MEMBER_SELECTOR)) {
        Operation operation = new StartProcessingJobOperation(name, jobId, keyObjects, predicate);
        executeOperation(operation, member.getAddress(), mapReduceService, nodeEngine);
    }
}
Also used : JobTrackerConfig(com.hazelcast.config.JobTrackerConfig) KeyValueJobOperation(com.hazelcast.mapreduce.impl.operation.KeyValueJobOperation) ReducerFactory(com.hazelcast.mapreduce.ReducerFactory) AbstractJobTracker(com.hazelcast.mapreduce.impl.AbstractJobTracker) StartProcessingJobOperation(com.hazelcast.mapreduce.impl.operation.StartProcessingJobOperation) Operation(com.hazelcast.spi.Operation) MapReduceUtil.executeOperation(com.hazelcast.mapreduce.impl.MapReduceUtil.executeOperation) KeyValueJobOperation(com.hazelcast.mapreduce.impl.operation.KeyValueJobOperation) KeyPredicate(com.hazelcast.mapreduce.KeyPredicate) KeyValueSource(com.hazelcast.mapreduce.KeyValueSource) CombinerFactory(com.hazelcast.mapreduce.CombinerFactory) Mapper(com.hazelcast.mapreduce.Mapper) TopologyChangedStrategy(com.hazelcast.mapreduce.TopologyChangedStrategy) ClusterService(com.hazelcast.internal.cluster.ClusterService) MapReduceService(com.hazelcast.mapreduce.impl.MapReduceService) Collection(java.util.Collection) StartProcessingJobOperation(com.hazelcast.mapreduce.impl.operation.StartProcessingJobOperation) Member(com.hazelcast.core.Member)

Aggregations

ClusterService (com.hazelcast.internal.cluster.ClusterService)32 Member (com.hazelcast.core.Member)8 ArrayList (java.util.ArrayList)8 Node (com.hazelcast.instance.Node)7 Address (com.hazelcast.nio.Address)7 OperationService (com.hazelcast.spi.OperationService)6 MemberImpl (com.hazelcast.instance.MemberImpl)5 StringUtil.bytesToString (com.hazelcast.util.StringUtil.bytesToString)5 Future (java.util.concurrent.Future)5 AbstractJobTracker (com.hazelcast.mapreduce.impl.AbstractJobTracker)4 NodeEngine (com.hazelcast.spi.NodeEngine)4 ILogger (com.hazelcast.logging.ILogger)3 Operation (com.hazelcast.spi.Operation)3 GroupConfig (com.hazelcast.config.GroupConfig)2 JobTrackerConfig (com.hazelcast.config.JobTrackerConfig)2 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)2 MapReduceService (com.hazelcast.mapreduce.impl.MapReduceService)2 MapReduceUtil.executeOperation (com.hazelcast.mapreduce.impl.MapReduceUtil.executeOperation)2 KeyValueJobOperation (com.hazelcast.mapreduce.impl.operation.KeyValueJobOperation)2 StartProcessingJobOperation (com.hazelcast.mapreduce.impl.operation.StartProcessingJobOperation)2