use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.
the class SetDefaultGuid method parse.
@Override
public void parse(String commandText) throws Exception {
StringTokenizer st = new StringTokenizer(commandText.trim());
if (st.countTokens() != 1) {
wrongArguments();
return;
}
String aliasName = st.nextToken();
GNSClientCommands gnsClient = module.getGnsClient();
try {
try {
gnsClient.lookupGuid(aliasName);
} catch (ClientException e) {
console.printString("Alias " + aliasName + " is not registered in the GNS\n");
return;
}
if (!module.isSilent()) {
console.printString("Looking up alias " + aliasName + " GUID and certificates...\n");
}
GuidEntry myGuid = KeyPairUtils.getGuidEntry(module.getGnsInstance(), aliasName);
if (myGuid == null) {
console.printString("You do not have the private key for alias " + aliasName);
console.printNewline();
return;
}
// Success, let's update the console prompt with the new alias name
// module.setCurrentGuid(myGuid);
module.setDefaultGuidAndCheckForVerified(myGuid);
if (!module.isSilent()) {
console.printString("Default GUID set to " + aliasName + "\n");
}
} catch (IOException e) {
console.printString("Failed to access the GNS ( " + e + ")\n");
}
}
use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.
the class WriteReadBytesTest method test_01_CreateBytesField.
/**
*
*/
@Test
public void test_01_CreateBytesField() {
try {
testValue = RandomUtils.nextBytes(16000);
String encodedValue = Base64.encodeToString(testValue, true);
//System.out.println("Encoded string: " + encodedValue);
clientCommands.fieldUpdate(masterGuid, TEST_FIELD, encodedValue);
} catch (IOException | ClientException e) {
Utils.failWithStackTrace("Exception during create field: " + e);
}
}
use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.
the class HighConcurrencyReadsTest method setupClientsAndGuids.
private static void setupClientsAndGuids() throws Exception {
clients = new GNSClientCommands[numClients];
executor = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(numClients);
for (int i = 0; i < numClients; i++) {
clients[i] = new GNSClientCommands();
}
String gnsInstance = GNSClientCommands.getGNSProvider();
accountGuidEntries = new GuidEntry[numAccountGuids];
int numPreExisting = 0;
for (int i = 0; i < numAccountGuids; i++) {
LOGGER.log(Level.FINE, "Creating account GUID {0}", new Object[] { ACCOUNT_GUID_PREFIX + i });
try {
accountGuidEntries[i] = GuidUtils.lookupOrCreateAccountGuid(clients[0], ACCOUNT_GUID_PREFIX + i, PASSWORD);
LOGGER.log(Level.FINE, "Created account {0}", new Object[] { accountGuidEntries[i] });
assert (accountGuidEntries[i].getGuid().equals(KeyPairUtils.getGuidEntry(gnsInstance, ACCOUNT_GUID_PREFIX + i).getGuid()));
} catch (DuplicateNameException e) {
numPreExisting++;
accountGuidEntries[i] = KeyPairUtils.getGuidEntry(gnsInstance, ACCOUNT_GUID_PREFIX + i);
LOGGER.log(Level.INFO, "Found that account {0} already exists", new Object[] { accountGuidEntries[i] });
}
// any other exceptions should be thrown up
}
System.out.println("Created (" + (numAccountGuids - numPreExisting) + ") or found pre-existing (" + numPreExisting + ") a total of " + 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 = GuidUtils.lookupOrCreateGuid(clients[0], accountGuidEntries[i / numGuidsPerAccount], subGuid);
assert (created.getGuid().equals(KeyPairUtils.getGuidEntry(gnsInstance, subGuid).getGuid()));
} catch (DuplicateNameException de) {
// ignore, will retrieve it locally below
}
// any other exceptions should be thrown up
} else {
try {
// batch create
clients[0].guidBatchCreate(accountGuidEntries[i / numGuidsPerAccount], subGuids);
} catch (ClientException | IOException 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);
}
LOGGER.log(Level.FINE, "Created sub-guid(s) {0}", new Object[] { 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.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.
the class SelectTest method test_010_CreateGuids.
/**
* Create the guids
*/
@Test
public void test_010_CreateGuids() {
try {
String westyName = "westy" + RandomString.randomString(12);
String samName = "sam" + RandomString.randomString(12);
client.execute(GNSCommand.createGUID(masterGuid, westyName));
westyEntry = GuidUtils.getGUIDKeys(westyName);
client.execute(GNSCommand.createGUID(masterGuid, samName));
samEntry = GuidUtils.getGUIDKeys(samName);
// westyEntry = clientCommands.guidCreate(masterGuid, "westy" + RandomString.randomString(12));
// samEntry = clientCommands.guidCreate(masterGuid, "sam" + RandomString.randomString(12));
System.out.println("Created: " + westyEntry);
System.out.println("Created: " + samEntry);
} catch (ClientException | IOException e) {
Utils.failWithStackTrace("Exception registering guids: " + e);
}
}
use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.
the class SelectTest method test_053_QuerySelectWorldReadable.
/**
* Check a query select with world readable fields
*/
@Test
public void test_053_QuerySelectWorldReadable() {
String fieldName = "testQueryWorldReadable";
try {
for (int cnt = 0; cnt < 5; cnt++) {
String queryTestName = "queryTest-" + RandomString.randomString(12);
client.execute(GNSCommand.createGUID(masterGuid, queryTestName));
GuidEntry testEntry = GuidUtils.getGUIDKeys(queryTestName);
// save them so we can delete them later
CREATED_GUIDS.add(testEntry);
JSONArray array = new JSONArray(Arrays.asList(25));
client.execute(GNSCommand.fieldReplaceOrCreateList(testEntry.getGuid(), fieldName, array, testEntry));
}
waitSettle(WAIT_SETTLE);
} catch (ClientException | IOException e) {
Utils.failWithStackTrace("Exception while trying to create the guids: " + e);
}
try {
String query = "~" + fieldName + " : ($gt: 0)";
JSONArray result = client.execute(GNSCommand.selectQuery(query)).getResultJSONArray();
for (int i = 0; i < result.length(); i++) {
System.out.println(result.get(i).toString());
}
// best we can do should be at least 5, but possibly more objects in results
Assert.assertThat(result.length(), Matchers.greaterThanOrEqualTo(5));
} catch (ClientException | IOException | JSONException e) {
Utils.failWithStackTrace("Exception executing selectQuery: " + e);
}
}
Aggregations