use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class FieldSet method parse.
@Override
public void parse(String commandText) throws Exception {
GNSClientCommands gnsClient = module.getGnsClient();
try {
StringTokenizer st = new StringTokenizer(commandText.trim());
String guid;
switch(st.countTokens()) {
case 3:
guid = module.getCurrentGuid().getGuid();
break;
case 4:
guid = st.nextToken();
if (!StringUtil.isValidGuidString(guid)) {
// We probably have an alias, lookup the GUID
guid = gnsClient.lookupGuid(guid);
}
break;
default:
wrongArguments();
return;
}
String indexStr = st.nextToken();
int index;
try {
index = Integer.valueOf(indexStr);
} catch (Exception e) {
index = -1;
}
if (index < 0) {
console.printString("Invalid index value.\n");
return;
}
String field = st.nextToken();
String value = st.nextToken();
gnsClient.fieldSetElement(guid, field, value, index, module.getCurrentGuid());
console.printString("Value '" + value + "' written at index " + index + " of field " + field + " for GUID " + guid);
console.printNewline();
} catch (IOException | ClientException e) {
console.printString("Failed to access GNS ( " + e + ")\n");
}
}
use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class FieldWriteList method parse.
@Override
public void parse(String commandText) throws Exception {
GNSClientCommands gnsClient = module.getGnsClient();
try {
StringTokenizer st = new StringTokenizer(commandText.trim());
String guid;
switch(st.countTokens()) {
case 2:
guid = module.getCurrentGuid().getGuid();
break;
case 3:
guid = st.nextToken();
if (!StringUtil.isValidGuidString(guid)) {
// We probably have an alias, lookup the GUID
guid = gnsClient.lookupGuid(guid);
}
break;
default:
wrongArguments();
return;
}
String field = st.nextToken();
String value = st.nextToken();
gnsClient.fieldReplaceOrCreateList(guid, field, new JSONArray().put(value), module.getCurrentGuid());
console.printString("Value '" + value + "' written to field " + field + " for GUID " + guid);
console.printNewline();
} catch (IOException | ClientException e) {
console.printString("Failed to access GNS ( " + e + ")\n");
}
}
use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class AdminBadAuthTest method setupBeforeClass.
/**
*
* @throws IOException
*/
@BeforeClass
public static void setupBeforeClass() throws IOException {
System.out.println("Starting client");
clientCommands = new GNSClientCommands();
// Make all the reads be coordinated
clientCommands.setForceCoordinatedReads(true);
// arun: connectivity check embedded in GNSClient constructor
boolean connected = clientCommands instanceof GNSClient;
if (connected) {
System.out.println("Client created and connected to server.");
}
badClient = new BadClient(ReconfigurationConfig.getReconfiguratorAddresses());
badClient.setForceCoordinatedReads(true);
connected = badClient instanceof GNSClient;
if (connected) {
System.out.println("BadClient created and connected to server.");
}
}
use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class SubGuidDeletesTest method cleanup.
/**
* @throws Exception
*/
@After
public void cleanup() throws Exception {
// sleep doesn't seem to help
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 {
LOGGER.log(Level.INFO, "{0} about to delete sub-guid {1}", new Object[] { this, guidEntry });
clients[0].guidRemove(guidEntry);
LOGGER.log(Level.INFO, "{0} deleted sub-guid {1}", new Object[] { this, guidEntry });
} catch (ClientException | IOException e) {
LOGGER.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);
LOGGER.log(Level.FINE, "{0} deleted account guid {1}", new Object[] { this, accGuidEntry });
} catch (ClientException | IOException e) {
LOGGER.log(Level.WARNING, "{0} failed to delete account guid {1}", new Object[] { this, accGuidEntry });
e.printStackTrace();
// continue with rest
}
}
for (GNSClientCommands clientCommands : clients) {
clientCommands.close();
}
}
use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class SubGuidDeletesTest method setupClientsAndGuids.
private void setupClientsAndGuids() throws Exception {
clients = new GNSClientCommands[numClients];
for (int i = 0; i < numClients; i++) {
clients[i] = new GNSClientCommands();
}
String gnsInstance = GNSClientCommands.getGNSProvider();
accountGuidEntries = new GuidEntry[numAccountGuids];
for (int i = 0; i < numAccountGuids; i++) {
LOGGER.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);
LOGGER.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);
LOGGER.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));
guidEntries = new GuidEntry[numGuids];
if (accountGuidsOnly) {
System.arraycopy(accountGuidEntries, 0, guidEntries, 0, accountGuidEntries.length);
return;
}
Set<String> subGuids = new HashSet<>();
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 (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, "{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));
}
Aggregations