Search in sources :

Example 6 with ZkConnection

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

the class DistributedDoubleBarrierTest method testBasic.

/**
 * Test case port from Apache Curator
 */
@Test
public void testBasic() throws Exception {
    final Timing timing = new Timing();
    final List<Closeable> closeables = Lists.newArrayList();
    ZkConnection zkConnection = createConnection(10 * 1000);
    CuratorFramework client = zkConnection.curator();
    try {
        closeables.add(client);
        client.start();
        final CountDownLatch postEnterLatch = new CountDownLatch(QTY);
        final CountDownLatch postLeaveLatch = new CountDownLatch(QTY);
        final AtomicInteger count = new AtomicInteger(0);
        final AtomicInteger max = new AtomicInteger(0);
        List<Future<Void>> futures = Lists.newArrayList();
        ExecutorService service = Executors.newCachedThreadPool();
        for (int i = 0; i < QTY; ++i) {
            Future<Void> future = service.submit(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    DistributedDoubleBarrier barrier = new DistributedDoubleBarrier(client, "/barrier/testBasic", QTY);
                    Assert.assertTrue(barrier.enter(timing.seconds(), TimeUnit.SECONDS));
                    synchronized (DistributedDoubleBarrierTest.this) {
                        int thisCount = count.incrementAndGet();
                        if (thisCount > max.get()) {
                            max.set(thisCount);
                        }
                    }
                    postEnterLatch.countDown();
                    Assert.assertTrue(timing.awaitLatch(postEnterLatch));
                    Assert.assertEquals(count.get(), QTY);
                    Assert.assertTrue(barrier.leave(10, TimeUnit.SECONDS));
                    count.decrementAndGet();
                    postLeaveLatch.countDown();
                    Assert.assertTrue(timing.awaitLatch(postLeaveLatch));
                    return null;
                }
            });
            futures.add(future);
        }
        for (Future<Void> f : futures) {
            f.get();
        }
        Assert.assertEquals(count.get(), 0);
        Assert.assertEquals(max.get(), QTY);
    } finally {
        for (Closeable c : closeables) {
            CloseableUtils.closeQuietly(c);
        }
    }
}
Also used : Closeable(java.io.Closeable) 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 7 with ZkConnection

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

the class StorageOsPlugin method onApplicationStart.

/**
 * Called at application start (and at each reloading) Time to start stateful things.
 */
@Override
public void onApplicationStart() {
    // NOSONAR
    instance = this;
    // ("Suppressing Sonar violation of Lazy initialization of static fields should be synchronized for field instance")
    if (!isEnabled()) {
        return;
    }
    try {
        Logger.info("Connecting to Coordinator Service");
        // To using Spring profile feature
        context = new GenericXmlApplicationContext();
        context.getEnvironment().setActiveProfiles(System.getProperty("buildType"));
        context.load(getContextFiles());
        context.refresh();
        Logger.info("Connected to Coordinator Service");
        zkConnection = getBean("zkconn", ZkConnection.class);
        coordinatorClient = getBean("coordinator", CoordinatorClient.class);
        encryptionProvider = getBean("encryptionProvider", EncryptionProvider.class);
        authSvcEndPointLocator = getBean("authSvcEndpointLocator", AuthSvcEndPointLocator.class);
        Validator.setAuthSvcEndPointLocator(authSvcEndPointLocator);
        Validator.setCoordinator(coordinatorClient);
        // need reference to local-security-conf.xml to load this
        Validator.setStorageOSUserRepository(null);
        coordinatorClient.start();
        encryptionProvider.start();
        Logger.info("Started ViPR connection, version: %s", version);
        KeyStoreExporter keystoreExporter = getBean("keystoreExporter", KeyStoreExporter.class);
        keystoreExporter.export();
        // register node listener for catalog acl change
        coordinatorClient.addNodeListener(new CatalogAclListener());
        Logger.info("added CatalogAclListener");
    } catch (Exception e) {
        Logger.error(e, "Error initializing ViPR Connection");
        shutdown();
    }
}
Also used : AuthSvcEndPointLocator(com.emc.storageos.security.authentication.AuthSvcEndPointLocator) KeyStoreExporter(com.emc.storageos.security.keystore.KeyStoreExporter) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient) CatalogAclListener(controllers.util.CatalogAclListener) EncryptionProvider(com.emc.storageos.db.client.model.EncryptionProvider) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) ZkConnection(com.emc.storageos.coordinator.common.impl.ZkConnection)

Example 8 with ZkConnection

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

the class TestCoordinatorService method start.

public void start() throws Exception {
    zkServer = new TestingServer();
    zkConnection = new ZkConnection();
    zkConnection.setServer(Collections.singletonList(new URI("coordinator://localhost:" + zkServer.getPort())));
    zkConnection.build();
    coordinatorClient = new CoordinatorClientImpl();
    coordinatorClient.setZkConnection(zkConnection);
    coordinatorClient.setInetAddessLookupMap(StubCoordinatorClientImpl.createLocalAddressLookupMap());
    coordinatorClient.start();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) CoordinatorClientImpl(com.emc.storageos.coordinator.client.service.impl.CoordinatorClientImpl) StubCoordinatorClientImpl(com.emc.sa.model.mock.StubCoordinatorClientImpl) URI(java.net.URI) ZkConnection(com.emc.storageos.coordinator.common.impl.ZkConnection)

Example 9 with ZkConnection

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

the class KeyCertificatePairGeneratorTest method setup.

@Before
public void setup() throws IOException, URISyntaxException {
    ApplicationContextUtil.initContext(System.getProperty("buildType"), ApplicationContextUtil.SECURITY_CONTEXTS);
    List<URI> uri = new ArrayList<URI>();
    uri.add(URI.create(coordinatorServer));
    ZkConnection connection = new ZkConnection();
    connection.setServer(uri);
    connection.build();
    coordinatorClient.setZkConnection(connection);
    CoordinatorClientInetAddressMap map = new CoordinatorClientInetAddressMap();
    map.setNodeId("standalone");
    DualInetAddress localAddress = DualInetAddress.fromAddresses("127.0.0.1", "::1");
    map.setDualInetAddress(localAddress);
    Map<String, DualInetAddress> controllerNodeIPLookupMap = new HashMap<String, DualInetAddress>();
    controllerNodeIPLookupMap.put("localhost", localAddress);
    map.setControllerNodeIPLookupMap(controllerNodeIPLookupMap);
    coordinatorClient.setInetAddessLookupMap(map);
    coordinatorClient.start();
    FileInputStream is = new FileInputStream(defaultOvfPropsLocation);
    Properties defaultProp = new Properties();
    defaultProp.load(is);
    is.close();
    is = new FileInputStream(ovfPropsLocation);
    Properties ovfProps = new Properties();
    ovfProps.load(is);
    is.close();
    CoordinatorClientImpl.setDefaultProperties(defaultProp);
    CoordinatorClientImpl.setOvfProperties(ovfProps);
    defaultValues = new KeyCertificateAlgorithmValuesHolder(coordinatorClient);
    String envVar = System.getenv(LOCALHOST_IP);
    if (StringUtils.isNotBlank(envVar)) {
        localhostIP = envVar;
    }
    InetAddress localhost = InetAddress.getByName(localhostIP);
    localhostName = localhost.getCanonicalHostName();
}
Also used : URI(java.net.URI) ZkConnection(com.emc.storageos.coordinator.common.impl.ZkConnection) FileInputStream(java.io.FileInputStream) KeyCertificateAlgorithmValuesHolder(com.emc.storageos.security.keystore.impl.KeyCertificateAlgorithmValuesHolder) CoordinatorClientInetAddressMap(com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap) InetAddress(java.net.InetAddress) DualInetAddress(com.emc.storageos.coordinator.client.service.impl.DualInetAddress) DualInetAddress(com.emc.storageos.coordinator.client.service.impl.DualInetAddress) Before(org.junit.Before)

Example 10 with ZkConnection

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

the class KeystoreTest method setup.

@Before
public void setup() throws URISyntaxException, IOException {
    ApplicationContextUtil.initContext(System.getProperty("buildType"), ApplicationContextUtil.SECURITY_CONTEXTS);
    List<URI> uri = new ArrayList<URI>();
    uri.add(URI.create(coordinatorServer));
    ZkConnection connection = new ZkConnection();
    connection.setServer(uri);
    connection.build();
    coordinatorClient.setZkConnection(connection);
    CoordinatorClientInetAddressMap map = new CoordinatorClientInetAddressMap();
    map.setNodeId("standalone");
    DualInetAddress localAddress = DualInetAddress.fromAddresses("127.0.0.1", "::1");
    map.setDualInetAddress(localAddress);
    Map<String, DualInetAddress> controllerNodeIPLookupMap = new HashMap<String, DualInetAddress>();
    controllerNodeIPLookupMap.put("localhost", localAddress);
    map.setControllerNodeIPLookupMap(controllerNodeIPLookupMap);
    coordinatorClient.setInetAddessLookupMap(map);
    coordinatorClient.start();
    FileInputStream is = new FileInputStream(defaultOvfPropsLocation);
    Properties defaultProp = new Properties();
    defaultProp.load(is);
    is.close();
    is = new FileInputStream(ovfPropsLocation);
    Properties ovfProps = new Properties();
    ovfProps.load(is);
    is.close();
    CoordinatorClientImpl.setDefaultProperties(defaultProp);
    CoordinatorClientImpl.setOvfProperties(ovfProps);
    loadStoreParam = new DistributedLoadKeyStoreParam();
    loadStoreParam.setCoordinator(coordinatorClient);
    invalidLoadStoreParam = new LoadStoreParameter() {

        @Override
        public ProtectionParameter getProtectionParameter() {
            return null;
        }
    };
    gen = new KeyCertificatePairGenerator();
    KeyCertificateAlgorithmValuesHolder values = new KeyCertificateAlgorithmValuesHolder(coordinatorClient);
    gen.setKeyCertificateAlgorithmValuesHolder(values);
}
Also used : HashMap(java.util.HashMap) DistributedLoadKeyStoreParam(com.emc.storageos.security.keystore.impl.DistributedLoadKeyStoreParam) ArrayList(java.util.ArrayList) Properties(java.util.Properties) URI(java.net.URI) ZkConnection(com.emc.storageos.coordinator.common.impl.ZkConnection) FileInputStream(java.io.FileInputStream) LoadStoreParameter(java.security.KeyStore.LoadStoreParameter) KeyCertificateAlgorithmValuesHolder(com.emc.storageos.security.keystore.impl.KeyCertificateAlgorithmValuesHolder) KeyCertificatePairGenerator(com.emc.storageos.security.keystore.impl.KeyCertificatePairGenerator) CoordinatorClientInetAddressMap(com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap) DualInetAddress(com.emc.storageos.coordinator.client.service.impl.DualInetAddress) ProtectionParameter(java.security.KeyStore.ProtectionParameter) Before(org.junit.Before)

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