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);
}
}
}
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();
}
}
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();
}
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();
}
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);
}
Aggregations