Search in sources :

Example 1 with ParallelCommandChain

use of com.ctrip.xpipe.command.ParallelCommandChain in project x-pipe by ctripcorp.

the class DcMetaBuilder method doExecute.

@Override
protected void doExecute() throws Exception {
    SequenceCommandChain sequenceCommandChain = new SequenceCommandChain(false);
    ParallelCommandChain parallelCommandChain = new ParallelCommandChain(executors);
    parallelCommandChain.add(retry3TimesUntilSuccess(new GetAllDcClusterShardDetailCommand(dcId)));
    parallelCommandChain.add(retry3TimesUntilSuccess(new Cluster2DcClusterMapCommand()));
    parallelCommandChain.add(retry3TimesUntilSuccess(new GetDcIdNameMapCommand()));
    sequenceCommandChain.add(parallelCommandChain);
    sequenceCommandChain.add(retry3TimesUntilSuccess(new BuildDcMetaCommand()));
    logger.info("[doExecute] commands: {}", sequenceCommandChain);
    sequenceCommandChain.future().addListener(commandFuture -> {
        if (commandFuture.isSuccess()) {
            future().setSuccess(dcMeta);
        } else {
            future().setFailure(commandFuture.cause());
        }
    });
    sequenceCommandChain.execute(executors);
}
Also used : ParallelCommandChain(com.ctrip.xpipe.command.ParallelCommandChain) SequenceCommandChain(com.ctrip.xpipe.command.SequenceCommandChain)

Example 2 with ParallelCommandChain

use of com.ctrip.xpipe.command.ParallelCommandChain in project x-pipe by ctripcorp.

the class AbstractRedisesSlaveofJob method doExecute.

@Override
protected void doExecute() throws CommandExecutionException {
    ParallelCommandChain commandChain = new ParallelCommandChain(executors);
    for (RedisMeta redisMeta : redises) {
        Command<?> backupCommand = createSlaveofCommand(redisMeta, masterHost, masterPort);
        commandChain.add(backupCommand);
    }
    commandChain.execute().addListener(new CommandFutureListener<Object>() {

        @Override
        public void operationComplete(CommandFuture<Object> commandFuture) throws Exception {
            if (commandFuture.isSuccess()) {
                future().setSuccess(null);
            } else {
                future().setFailure(commandFuture.cause());
            }
        }
    });
}
Also used : ParallelCommandChain(com.ctrip.xpipe.command.ParallelCommandChain) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException)

Example 3 with ParallelCommandChain

use of com.ctrip.xpipe.command.ParallelCommandChain in project x-pipe by ctripcorp.

the class KeyedOneThreadTaskExecutorTest method testHang.

@Test
public void testHang() throws TimeoutException, IOException {
    int threadCount = 10;
    int taskCount = threadCount;
    ExecutorService executorService = null;
    try {
        executorService = Executors.newFixedThreadPool(threadCount, XpipeThreadFactory.create("test-hang"));
        keyed = new KeyedOneThreadTaskExecutor<>(executorService);
        AtomicInteger completeCount = new AtomicInteger();
        for (int i = 0; i < taskCount; i++) {
            int finalI = i;
            ParallelCommandChain parallelCommandChain = new ParallelCommandChain(executorService);
            parallelCommandChain.add(new TestCommand("success:" + i, sleepInterval));
            parallelCommandChain.future().addListener(new CommandFutureListener<Object>() {

                @Override
                public void operationComplete(CommandFuture<Object> commandFuture) throws Exception {
                    logger.info("[operationComplete]{}", finalI);
                    completeCount.incrementAndGet();
                }
            });
            keyed.execute(String.valueOf(i), parallelCommandChain);
        }
        waitConditionUntilTimeOut(() -> completeCount.get() == taskCount);
    } finally {
        executorService.shutdownNow();
    }
}
Also used : ParallelCommandChain(com.ctrip.xpipe.command.ParallelCommandChain) TestCommand(com.ctrip.xpipe.command.TestCommand) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Example 4 with ParallelCommandChain

use of com.ctrip.xpipe.command.ParallelCommandChain in project x-pipe by ctripcorp.

the class AdvancedDcMetaService method getDcMeta.

@Override
public DcMeta getDcMeta(String dcName) {
    DcTbl dcTbl = dcService.find(dcName);
    DcMeta dcMeta = new DcMeta().setId(dcName).setLastModifiedTime(dcTbl.getDcLastModifiedTime());
    ParallelCommandChain chain = new ParallelCommandChain(executors);
    chain.add(retry3TimesUntilSuccess(new GetAllSentinelCommand(dcMeta)));
    chain.add(retry3TimesUntilSuccess(new GetAllKeeperContainerCommand(dcMeta)));
    DcMetaBuilder builder = new DcMetaBuilder(dcMeta, dcTbl.getId(), executors, redisMetaService, dcClusterService, clusterMetaService, dcClusterShardService, dcService, factory);
    chain.add(retry3TimesUntilSuccess(builder));
    try {
        chain.execute().get();
    } catch (Exception e) {
        logger.error("[queryDcMeta] ", e);
    }
    return dcMeta;
}
Also used : ParallelCommandChain(com.ctrip.xpipe.command.ParallelCommandChain) DcTbl(com.ctrip.xpipe.redis.console.model.DcTbl) DcMetaBuilder(com.ctrip.xpipe.redis.console.service.vo.DcMetaBuilder) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta)

Aggregations

ParallelCommandChain (com.ctrip.xpipe.command.ParallelCommandChain)4 AbstractTest (com.ctrip.xpipe.AbstractTest)1 CommandExecutionException (com.ctrip.xpipe.command.CommandExecutionException)1 SequenceCommandChain (com.ctrip.xpipe.command.SequenceCommandChain)1 TestCommand (com.ctrip.xpipe.command.TestCommand)1 DcTbl (com.ctrip.xpipe.redis.console.model.DcTbl)1 DcMetaBuilder (com.ctrip.xpipe.redis.console.service.vo.DcMetaBuilder)1 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)1 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)1 IOException (java.io.IOException)1 ExecutorService (java.util.concurrent.ExecutorService)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1