Search in sources :

Example 16 with ZkConnection

use of com.emc.storageos.coordinator.common.impl.ZkConnection in project coprhd-controller by CoprHD.

the class UserInfoHelperTest method setup.

@Before
public void setup() throws Exception {
    List<URI> uri = new ArrayList<URI>();
    uri.add(URI.create(_coordinatorServer));
    ZkConnection connection = new ZkConnection();
    connection.setServer(uri);
    connection.build();
    _coordinatorClient.setZkConnection(connection);
    _coordinatorClient.start();
    String envVar = System.getenv(USER_WRONG_DOMAIN_CONFIG);
    if (StringUtils.isNotBlank(envVar)) {
        user_in_wrong_domain = envVar;
    }
    envVar = System.getenv(USER_DOESNT_EXIST_CONFIG);
    if (StringUtils.isNotBlank(envVar)) {
        user_doesnt_exist = envVar;
    }
    envVar = System.getenv(EXISTING_USER_CONFIG);
    if (StringUtils.isNotBlank(envVar)) {
        existing_user = envVar;
    }
    envVar = System.getenv(EXISTING_USER_NUM_OF_GROUPS_CONFIG);
    if (StringUtils.isNotBlank(envVar)) {
        try {
            num_of_groups = Integer.parseInt(envVar);
        } catch (NumberFormatException e) {
            num_of_groups = 3;
        }
    }
    userInfoHelper = new UserInfoHelper(_coordinatorClient);
}
Also used : ArrayList(java.util.ArrayList) URI(java.net.URI) ZkConnection(com.emc.storageos.coordinator.common.impl.ZkConnection) Before(org.junit.Before)

Example 17 with ZkConnection

use of com.emc.storageos.coordinator.common.impl.ZkConnection in project coprhd-controller by CoprHD.

the class PasswordServiceTest method getCoordinatorClient.

private CoordinatorClient getCoordinatorClient() throws Exception {
    DummyCoordinatorClient client = new DummyCoordinatorClient();
    ZkConnection zkConn = new ZkConnection();
    List<URI> uris = new ArrayList();
    uris.add(new URI("coordinator://localhost:2181"));
    zkConn.setServer(uris);
    zkConn.setTimeoutMs(10000);
    zkConn.build();
    client.setZkConnection(zkConn);
    return client;
}
Also used : ArrayList(java.util.ArrayList) URI(java.net.URI) ZkConnection(com.emc.storageos.coordinator.common.impl.ZkConnection)

Example 18 with ZkConnection

use of com.emc.storageos.coordinator.common.impl.ZkConnection in project coprhd-controller by CoprHD.

the class DistributedDoubleBarrierTest method testLeaveTimeout.

/**
 * Test return value of leave() in case of timeout
 *
 * If any one members doesn't leave correctly, the leave should return false.
 * In this test 5 threads enter a barrier at a time and then the first one leaves within timeout. Another one keeps sleeping.
 * Then Worker1's leave should return false, and all other workers leave with false as well
 */
@Test
public void testLeaveTimeout() throws Exception {
    final Timing timing = new Timing(2, TimeUnit.SECONDS);
    final AtomicInteger count = new AtomicInteger(0);
    final ExecutorService service = Executors.newCachedThreadPool();
    final List<Future<Void>> futures = Lists.newArrayList();
    Future<Void> worker1 = service.submit(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            ZkConnection zkConnection = createConnection(60 * 1000);
            CuratorFramework client = zkConnection.curator();
            try {
                zkConnection.connect();
                DistributedDoubleBarrier barrier = new DistributedDoubleBarrier(client, "/barrier/testLeaveTimeout", QTY);
                Assert.assertTrue("Return value of enter() should be true", barrier.enter(timing.seconds(), TimeUnit.SECONDS));
                count.incrementAndGet();
                log.info("Leaving with timeout {} seconds", timing.seconds());
                Assert.assertFalse("Return value of leave() should be false", barrier.leave(timing.seconds(), TimeUnit.SECONDS));
                log.info("Left with timeout");
                count.decrementAndGet();
                // keep the ZK connection until all other workers exit
                Thread.sleep(timing.seconds() * 5 * 1000);
            } finally {
                CloseableUtils.closeQuietly(client);
            }
            return null;
        }
    });
    futures.add(worker1);
    for (int i = 1; i < QTY; ++i) {
        Future<Void> worker = service.submit(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                ZkConnection zkConnection = createConnection(60 * 1000);
                CuratorFramework client = zkConnection.curator();
                try {
                    zkConnection.connect();
                    DistributedDoubleBarrier barrier = new DistributedDoubleBarrier(client, "/barrier/testLeaveTimeout", QTY);
                    Assert.assertTrue("Return value of enter() shoud be true", barrier.enter(timing.seconds(), TimeUnit.SECONDS));
                    count.incrementAndGet();
                    Thread.sleep(timing.seconds() * 1000);
                    log.info("Leaving with timeout {} seconds", timing.seconds());
                    Assert.assertFalse("Return value of leave() should be false", barrier.leave(timing.seconds(), TimeUnit.SECONDS));
                    count.decrementAndGet();
                    log.info("Left with timeout");
                    // keep the ZK connection until all other workers exit
                    Thread.sleep(timing.seconds() * 1000);
                } finally {
                    CloseableUtils.closeQuietly(client);
                }
                return null;
            }
        });
        futures.add(worker);
    }
    for (Future<Void> f : futures) {
        f.get();
    }
    Assert.assertEquals("enter/leave count", count.get(), 0);
}
Also used : ZkConnection(com.emc.storageos.coordinator.common.impl.ZkConnection) CuratorFramework(org.apache.curator.framework.CuratorFramework) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Timing(org.apache.curator.test.Timing) Test(org.junit.Test)

Example 19 with ZkConnection

use of com.emc.storageos.coordinator.common.impl.ZkConnection in project coprhd-controller by CoprHD.

the class DistributedDoubleBarrierTest method testOverSubscribed.

/**
 * Test case port from Apache Curator
 */
@Test
public void testOverSubscribed() throws Exception {
    final Timing timing = new Timing();
    ZkConnection zkConnection = createConnection(10 * 1000);
    CuratorFramework client = zkConnection.curator();
    ExecutorService service = Executors.newCachedThreadPool();
    ExecutorCompletionService<Void> completionService = new ExecutorCompletionService<Void>(service);
    try {
        client.start();
        final Semaphore semaphore = new Semaphore(0);
        final CountDownLatch latch = new CountDownLatch(1);
        for (int i = 0; i < (QTY + 1); ++i) {
            completionService.submit(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    DistributedDoubleBarrier barrier = new DistributedDoubleBarrier(client, "/barrier/testOverSubscribed", QTY) {

                        @Override
                        protected List<String> getChildrenForEntering() throws Exception {
                            semaphore.release();
                            Assert.assertTrue(timing.awaitLatch(latch));
                            return super.getChildrenForEntering();
                        }
                    };
                    Assert.assertTrue(barrier.enter(timing.seconds(), TimeUnit.SECONDS));
                    Assert.assertTrue(barrier.leave(timing.seconds(), TimeUnit.SECONDS));
                    return null;
                }
            });
        }
        // wait until all QTY+1 barriers are trying to enter
        Assert.assertTrue(semaphore.tryAcquire(QTY + 1, timing.seconds(), TimeUnit.SECONDS));
        latch.countDown();
        for (int i = 0; i < (QTY + 1); ++i) {
            // to check for assertions
            completionService.take().get();
        }
    } finally {
        service.shutdown();
        CloseableUtils.closeQuietly(client);
    }
}
Also used : ZkConnection(com.emc.storageos.coordinator.common.impl.ZkConnection) CuratorFramework(org.apache.curator.framework.CuratorFramework) List(java.util.List) Timing(org.apache.curator.test.Timing) Test(org.junit.Test)

Example 20 with ZkConnection

use of com.emc.storageos.coordinator.common.impl.ZkConnection in project coprhd-controller by CoprHD.

the class ZkSimulator method connectClient.

/**
 * Connects to Zookeeper server
 *
 * @return The instance of CoordinatorClient
 * @throws IOException
 */
private CoordinatorClient connectClient() throws IOException {
    CoordinatorClientImpl client = new CoordinatorClientImpl();
    ZkConnection conn = new ZkConnection();
    URI zkUri = URI.create(String.format("coordinator://localhost:%s", config.getClientPortAddress().getPort()));
    conn.setServer(Arrays.asList(zkUri));
    conn.setTimeoutMs(10 * 1000);
    conn.setSiteIdFile("build/data/zk/siteIdFile");
    log.info("Connecting with coordinator service...");
    conn.build();
    log.info("Connecting with coordinator service.");
    client.setZkConnection(conn);
    CoordinatorClientInetAddressMap inetAddressMap = new CoordinatorClientInetAddressMap();
    inetAddressMap.setNodeId("standalone");
    inetAddressMap.setDualInetAddress(DualInetAddress.fromAddress("127.0.0.1"));
    inetAddressMap.setCoordinatorClient(client);
    inetAddressMap.setControllerNodeIPLookupMap(new HashMap<String, DualInetAddress>());
    client.setInetAddessLookupMap(inetAddressMap);
    client.setSysSvcName("syssvc");
    client.setSysSvcVersion("1");
    client.setVdcShortId("vdc1");
    Properties properties = new Properties();
    properties.setProperty(BackupConstants.BACKUP_MAX_MANUAL_COPIES, "5");
    client.setDefaultProperties(properties);
    FileInputStream is = new FileInputStream(ovfPropsLocation);
    Properties ovfProps = new Properties();
    ovfProps.load(is);
    is.close();
    client.setOvfProperties(ovfProps);
    client.start();
    return client;
}
Also used : CoordinatorClientImpl(com.emc.storageos.coordinator.client.service.impl.CoordinatorClientImpl) CoordinatorClientInetAddressMap(com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap) Properties(java.util.Properties) URI(java.net.URI) ZkConnection(com.emc.storageos.coordinator.common.impl.ZkConnection) DualInetAddress(com.emc.storageos.coordinator.client.service.impl.DualInetAddress) FileInputStream(java.io.FileInputStream)

Aggregations

ZkConnection (com.emc.storageos.coordinator.common.impl.ZkConnection)20 URI (java.net.URI)12 CoordinatorClientInetAddressMap (com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap)9 DualInetAddress (com.emc.storageos.coordinator.client.service.impl.DualInetAddress)8 ArrayList (java.util.ArrayList)8 CoordinatorClientImpl (com.emc.storageos.coordinator.client.service.impl.CoordinatorClientImpl)6 FileInputStream (java.io.FileInputStream)6 Before (org.junit.Before)6 Properties (java.util.Properties)5 CuratorFramework (org.apache.curator.framework.CuratorFramework)5 Timing (org.apache.curator.test.Timing)5 Test (org.junit.Test)5 KeyCertificateAlgorithmValuesHolder (com.emc.storageos.security.keystore.impl.KeyCertificateAlgorithmValuesHolder)4 HashMap (java.util.HashMap)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 KeyCertificatePairGenerator (com.emc.storageos.security.keystore.impl.KeyCertificatePairGenerator)3 DbVersionInfo (com.emc.storageos.coordinator.client.model.DbVersionInfo)2 DistributedLoadKeyStoreParam (com.emc.storageos.security.keystore.impl.DistributedLoadKeyStoreParam)2 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)2 StubCoordinatorClientImpl (com.emc.sa.model.mock.StubCoordinatorClientImpl)1