use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class BatchCreateOpsFail method setupClientsAndGuids.
private void setupClientsAndGuids() throws Exception {
clients = new GNSClientCommands[numClients];
for (int i = 0; i < numClients; i++) {
clients[i] = new GNSClientCommands();
}
String gnsInstance = clients[0].getGNSProvider();
accountGuidEntries = new GuidEntry[numAccountGuids];
for (int i = 0; i < numAccountGuids; i++) {
log.log(Level.FINE, "{0} creating account GUID {1}", new Object[] { this, ACCOUNT_GUID_PREFIX + i });
try {
accountGuidEntries[i] = clients[0].accountGuidCreate(ACCOUNT_GUID_PREFIX + i, PASSWORD);
log.log(Level.FINE, "{0} created account ", new Object[] { this, accountGuidEntries[i] });
assert (accountGuidEntries[i].getGuid().equals(KeyPairUtils.getGuidEntry(gnsInstance, ACCOUNT_GUID_PREFIX + i).getGuid()));
} catch (DuplicateNameException e) {
accountGuidEntries[i] = KeyPairUtils.getGuidEntry(gnsInstance, ACCOUNT_GUID_PREFIX + i);
log.log(Level.INFO, "{0} found that account {1} already exists", new Object[] { this, accountGuidEntries[i] });
}
// any other exception should be throw up
}
System.out.println("Created or found pre-existing " + numAccountGuids + " account GUIDs: " + Arrays.asList(accountGuidEntries));
if (accountGuidsOnly) {
for (int i = 0; i < accountGuidEntries.length; i++) {
guidEntries[i] = accountGuidEntries[i];
}
return;
}
guidEntries = new GuidEntry[numGuids];
Set<String> subGuids = new HashSet<String>();
for (int i = 0, j = 0; i < numGuids; i++) {
subGuids.add(Config.getGlobalString(TC.TEST_GUID_PREFIX) + i);
if (subGuids.size() == numGuidsPerAccount || i == numGuids - 1) {
// because batch creation seems buggy
if (subGuids.size() == 1) {
String subGuid = subGuids.iterator().next();
try {
GuidEntry created = clients[0].guidCreate(accountGuidEntries[i / numGuidsPerAccount], subGuid);
assert (created.getGuid().equals(KeyPairUtils.getGuidEntry(gnsInstance, subGuid).getGuid()));
} catch (DuplicateNameException de) {
// ignore, will retrieve it locally below
}
// any other exception should be throw up
} else {
try {
// batch create
clients[0].guidBatchCreate(accountGuidEntries[i / numGuidsPerAccount], subGuids);
} catch (Exception e) {
for (String subGuid : subGuids) {
try {
clients[0].guidCreate(accountGuidEntries[i / numGuidsPerAccount], subGuid);
} catch (DuplicateNameException de) {
// ignore, will retrieve it locally below
}
// any other exception should be throw up
}
}
}
for (String subGuid : subGuids) {
guidEntries[j++] = KeyPairUtils.getGuidEntry(gnsInstance, subGuid);
}
log.log(Level.FINE, "{0} created sub-guid(s) {1}", new Object[] { this, subGuids });
subGuids.clear();
}
}
for (GuidEntry guidEntry : accountGuidEntries) {
assert (guidEntry != null);
}
for (GuidEntry guidEntry : guidEntries) {
assert (guidEntry != null);
}
System.out.println("Created or found " + guidEntries.length + " pre-existing sub-guids " + Arrays.asList(guidEntries));
}
use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class BatchCreateOpsFail method cleanup.
/**
*
* @throws Exception
*/
@After
public void cleanup() throws Exception {
Thread.sleep(2000);
assert (clients != null && clients[0] != null);
System.out.println("About to delete " + guidEntries.length + " sub-guids: " + Arrays.asList(guidEntries));
for (GuidEntry guidEntry : guidEntries) {
try {
log.log(Level.INFO, "{0} about to delete sub-guid {1}", new Object[] { this, guidEntry });
clients[0].guidRemove(guidEntry);
log.log(Level.INFO, "{0} deleted sub-guid {1}", new Object[] { this, guidEntry });
} catch (Exception e) {
log.log(Level.WARNING, "{0} failed to delete sub-guid {1}", new Object[] { this, guidEntry });
e.printStackTrace();
// continue with rest
}
}
System.out.println("About to delete " + accountGuidEntries.length + " account guids: " + Arrays.asList(accountGuidEntries));
for (GuidEntry accGuidEntry : accountGuidEntries) {
try {
clients[0].accountGuidRemove(accGuidEntry);
log.log(Level.FINE, "{0} deleted account guid {1}", new Object[] { this, accGuidEntry });
} catch (Exception e) {
log.log(Level.WARNING, "{0} failed to delete account guid {1}", new Object[] { this, accGuidEntry });
e.printStackTrace();
// continue with rest
}
}
for (GNSClientCommands client : clients) {
client.close();
}
}
use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class SomeReadsEncryptionFails method cleanup.
/**
* Removes all account and sub-guids created during the test.
*
* @throws Exception
*/
@AfterClass
public static void cleanup() throws Exception {
Thread.sleep(2000);
assert (clients != null && clients[0] != null);
if (!accountGuidsOnly) {
System.out.println("About to delete " + guidEntries.length + " sub-guids: " + Arrays.asList(guidEntries));
for (GuidEntry guidEntry : guidEntries) {
try {
log.log(Level.FINE, "About to delete sub-guid {0}", new Object[] { guidEntry });
clients[0].guidRemove(guidEntry);
log.log(Level.FINE, "Deleted sub-guid {0}", new Object[] { guidEntry });
} catch (Exception e) {
log.log(Level.WARNING, "Failed to delete sub-guid {0}", new Object[] { guidEntry });
e.printStackTrace();
// continue with rest
}
}
}
System.out.println("About to delete " + accountGuidEntries.length + " account guids: " + Arrays.asList(accountGuidEntries));
for (GuidEntry accGuidEntry : accountGuidEntries) {
try {
log.log(Level.FINE, "About to delete account guid {0}", new Object[] { accGuidEntry });
clients[0].accountGuidRemove(accGuidEntry);
log.log(Level.FINE, "Deleted account guid {0}", new Object[] { accGuidEntry });
} catch (Exception e) {
log.log(Level.WARNING, "Failed to delete account guid {0}", new Object[] { accGuidEntry });
e.printStackTrace();
// continue with rest
}
}
for (GNSClientCommands client : clients) {
client.close();
}
executor.shutdown();
}
use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class ContextAwareGroupGuidExample method main.
/**
*
* @param args
* @throws IOException
* @throws InvalidKeySpecException
* @throws NoSuchAlgorithmException
* @throws ClientException
* @throws InvalidKeyException
* @throws SignatureException
* @throws Exception
*/
public static void main(String[] args) throws IOException, InvalidKeySpecException, NoSuchAlgorithmException, ClientException, InvalidKeyException, SignatureException, Exception {
// BOILER PLATE FOR RUNNING AN EXAMPLE
// Start the client
client = new GNSClientCommands(null);
try {
// Create the account guid using your email address and password = "password"
masterGuid = lookupOrCreateAccountGuid(client, ACCOUNT_ALIAS, "password");
} catch (Exception e) {
System.out.println("Exception during accountGuid creation: " + e);
System.exit(1);
}
System.out.println("Client connected to GNS.");
// Create 5 guids each of which have the field using our fieldname with a value of 25
for (int cnt = 0; cnt < 5; cnt++) {
GuidEntry guidEntry = client.guidCreate(masterGuid, "valueField-" + cnt);
client.fieldUpdate(guidEntry, fieldName, 25);
}
//FIXME: THIS CODE IS OBSOLETE. THE INTERFACE HAS CHANGED.
// Create a guid for the first group
groupOneGuidEntry = client.guidCreate(masterGuid, "contextAware > 20 Group");
// Set up the group context with a query
String query = "~" + fieldName + " : {$gt: 20}";
// Note that the zero for the interval means that we will never get stale results (not a
// good idea to do in production code! The default is 60 (seconds))
JSONArray result = client.selectSetupGroupQuery(masterGuid, groupOneGuidEntry.getGuid(), query, 0);
// Show the values from the guids that we got back
System.out.println("Members of " + groupOneGuidEntry.getEntityName() + ":");
showFieldValuesInGuids(result, fieldName);
//FIXME: THIS CODE IS OBSOLETE. THE INTERFACE HAS CHANGED.
// Create a second group guid
groupTwoGuidEntry = client.guidCreate(masterGuid, "contextAware = 0 Group");
// Set up a second group with a different query
query = "~" + fieldName + " : 0";
// Note that the zero for the interval means that we will never get stale results (not a
// good idea to do in production code! The default is 60 (seconds))
JSONArray resultTwo = client.selectSetupGroupQuery(masterGuid, groupTwoGuidEntry.getGuid(), query, 0);
// Show the values from the guids that we got back
System.out.println("Members of " + groupTwoGuidEntry.getEntityName() + ": (should be empty)");
showFieldValuesInGuids(resultTwo, fieldName);
// Now we lookup the values of the first group again
JSONArray resultThree = client.selectLookupGroupQuery(groupOneGuidEntry.getGuid());
System.out.println("Members of " + groupOneGuidEntry.getEntityName() + ": (should still be 5 of them)");
showFieldValuesInGuids(resultThree, fieldName);
// THIS IS WHERE IT GETS INTERESTING
// And change the values of all but one of them
System.out.println("Changing 4 of the 5 guids to have a their " + fieldName + " field's value be 0");
for (int i = 0; i < result.length() - 1; i++) {
BasicGuidEntry guidInfo = new BasicGuidEntry(client.lookupGuidRecord(result.getString(i)));
GuidEntry entry = GuidUtils.lookupGuidEntryFromDatabase(client, guidInfo.getEntityName());
System.out.println("Changing value of " + fieldName + " field in " + entry.getEntityName() + " to 0");
client.fieldUpdate(entry, fieldName, 0);
}
// Now we lookup the values of the first group again - showing that there is only one guid in the group
JSONArray resultFour = client.selectLookupGroupQuery(groupOneGuidEntry.getGuid());
System.out.println("Members of " + groupOneGuidEntry.getEntityName() + ": (should only be one of them)");
showFieldValuesInGuids(resultFour, fieldName);
// Now we lookup the values of the second group again - this one now has 4 guids
JSONArray resultFive = client.selectLookupGroupQuery(groupTwoGuidEntry.getGuid());
System.out.println("Members of " + groupTwoGuidEntry.getEntityName() + ": (should be 4 of them)");
showFieldValuesInGuids(resultFive, fieldName);
// So we can run this again without duplicate name/guid errors.
cleanupAllGuids();
System.exit(0);
}
use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class ServerFailureTests method setUpBeforeClass.
/**
*
* @throws Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
String topDir = Paths.get(".").toAbsolutePath().normalize().toString();
//Set the running time (in seconds) for each round of throughput testing.
String inputRoundTime = System.getProperty("failureTest.roundTime");
if (inputRoundTime != null) {
TEST_TIME = Integer.parseInt(inputRoundTime) * 1000;
} else {
//Default to 10,000 ms
TEST_TIME = 10000;
}
//Parse gigapaxos.properties file for the active replica names
String gpPropPath = System.getProperty("gigapaxosConfig");
System.out.println("Using gigapaxos config: " + gpPropPath);
gpPropDir = topDir + "/" + gpPropPath;
File file = new File(gpPropDir);
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = reader.readLine();
while (line != null) {
if (line.startsWith("active.")) {
int idx = line.indexOf(".");
int idx2 = line.indexOf("=", idx);
String serverName = line.substring(idx + 1, idx2);
suite.serverNameArray.add(serverName);
}
line = reader.readLine();
}
reader.close();
numServers = suite.serverNameArray.size();
System.out.println("Active Replicas to be used: " + suite.serverNameArray.toString());
//Kill any running servers
Process startProcess = Runtime.getRuntime().exec("kill -s TERM `ps -ef | grep GNS.jar | grep -v grep | grep -v ServerIntegrationTest | grep -v \"context\" | awk '{print $2}'`");
InputStream serverLauncherOutput = startProcess.getInputStream();
BufferedReader output = new BufferedReader(new InputStreamReader(serverLauncherOutput));
line = output.readLine();
while (startProcess.isAlive() && (line != null)) {
System.out.println(line);
line = output.readLine();
}
startProcess.waitFor();
//Kill any saved state
execString = topDir + "/bin/gpServer.sh -DgigapaxosConfig=" + gpPropDir + " ";
System.out.println("Running " + execString + "forceclear all");
startProcess = Runtime.getRuntime().exec(execString + "forceclear all");
serverLauncherOutput = startProcess.getInputStream();
output = new BufferedReader(new InputStreamReader(serverLauncherOutput));
line = output.readLine();
while (startProcess.isAlive() && (line != null)) {
System.out.println(line);
line = output.readLine();
}
startProcess.waitFor();
//Start the servers
System.out.println("Running " + execString + "restart all");
startProcess = Runtime.getRuntime().exec(execString + "restart all");
serverLauncherOutput = startProcess.getInputStream();
output = new BufferedReader(new InputStreamReader(serverLauncherOutput));
line = output.readLine();
while (startProcess.isAlive() && (line != null)) {
System.out.println(line);
line = output.readLine();
}
startProcess.waitFor();
System.out.println("Servers started.");
Thread.sleep(5000);
System.out.println("Starting client");
client = new GNSClientCommands();
// Make all the reads be coordinated
client.setForceCoordinatedReads(true);
// arun: connectivity check embedded in GNSClient constructor
boolean connected = client instanceof GNSClient;
if (connected) {
System.out.println("Client created and connected to server.");
}
//
int tries = 5;
boolean accountCreated = false;
do {
try {
System.out.println("Creating account guid: " + (tries - 1) + " attempt remaining.");
masterGuid = GuidUtils.lookupOrCreateAccountGuid(client, accountAlias, PASSWORD, true);
accountCreated = true;
} catch (Exception e) {
ThreadUtils.sleep((5 - tries) * 5000);
}
} while (!accountCreated && --tries > 0);
if (accountCreated == false) {
fail("Failure setting up account guid; aborting all tests.");
}
//Begin emulating transport delays -- This was causing timeouts on everything so it's unused out for now.
if (EMULATING_DELAYS) {
JSONDelayEmulator.emulateDelays();
}
}
Aggregations