Search in sources :

Example 1 with VerificationException

use of edu.umass.cs.gnscommon.exceptions.client.VerificationException in project GNS by MobilityFirst.

the class CreateMultiGuidClient method main.

/**
   * @param args
   * @throws Exception
   */
public static void main(String[] args) throws Exception {
    int node = Integer.parseInt(args[0]);
    BENIGN_CLIENT = Integer.parseInt(args[1]);
    NUM_CLIENT = Integer.parseInt(args[2]);
    boolean flag = Boolean.parseBoolean(args[3]);
    //Read in the code and serialize
    //		String code = new String(Files.readAllBytes(Paths.get(filename)));
    //		String code64 = Base64.encodeToString(code.getBytes("utf-8"), true);
    //		String mal_code = new String(Files.readAllBytes(Paths.get(mal_file)));		
    //		String mal_code64 = Base64.encodeToString(mal_code.getBytes("utf-8"), true);
    client = new GNSClientCommands();
    ExecutorService executor = Executors.newFixedThreadPool(numThread);
    for (int i = 0; i < NUM_CLIENT; i++) {
        String name = "test" + (node * 1000 + i) + ACCOUNT_ALIAS;
        GuidEntry guidAccount = null;
        try {
            guidAccount = lookupOrCreateAccountGuid(client, name, "password");
        } catch (VerificationException e) {
        // ignore verification exceptions
        } catch (Exception e) {
            System.out.println("Exception during accountGuid creation: " + e);
            System.exit(1);
        }
        System.out.println(name + ":" + guidAccount.getGuid());
        if (flag) {
            if (i < BENIGN_CLIENT) {
                executor.execute(new createGuidThread(client, guidAccount.getGuid(), guidAccount));
            } else {
                executor.execute(new createGuidThread(client, guidAccount.getGuid(), guidAccount));
            }
        }
    }
    while (createdGuid < NUM_CLIENT) {
        System.out.println(createdGuid + "/" + NUM_CLIENT + " guids have been created ...");
        Thread.sleep(1000);
    }
    System.out.println("Created all " + NUM_CLIENT + " guids.");
    System.exit(0);
}
Also used : GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) ExecutorService(java.util.concurrent.ExecutorService) VerificationException(edu.umass.cs.gnscommon.exceptions.client.VerificationException) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) JSONException(org.json.JSONException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) VerificationException(edu.umass.cs.gnscommon.exceptions.client.VerificationException)

Example 2 with VerificationException

use of edu.umass.cs.gnscommon.exceptions.client.VerificationException in project GNS by MobilityFirst.

the class AccountVerify method parse.

@Override
public void parse(String commandText) throws Exception {
    try {
        GNSClientCommands client = module.getGnsClient();
        StringTokenizer st = new StringTokenizer(commandText.trim());
        if (st.countTokens() != 2) {
            wrongArguments();
            return;
        }
        String alias = st.nextToken();
        GuidEntry guid = KeyPairUtils.getGuidEntry(module.getGnsInstance(), alias);
        if (guid == null) {
            printString("Unable to retrieve GUID for alias " + alias + "\n");
            return;
        }
        String code = st.nextToken();
        try {
            if (client.accountGuidVerify(guid, code).startsWith(GNSProtocol.OK_RESPONSE.toString())) {
                printString("Account verified.\n");
                module.setAccountVerified(true);
                return;
            }
        // this happens if it was already verified, but we didn't notice
        } catch (VerificationException e) {
            module.setAccountVerified(true);
            printString("Account already verified" + "\n");
            return;
        } catch (Exception e) {
            printString("Account not verified: " + e + "\n");
        }
    } catch (Exception e) {
        console.printString("Failed to access GNS ( " + e + ")\n");
    }
    module.setAccountVerified(false);
}
Also used : StringTokenizer(java.util.StringTokenizer) GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) VerificationException(edu.umass.cs.gnscommon.exceptions.client.VerificationException) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) VerificationException(edu.umass.cs.gnscommon.exceptions.client.VerificationException)

Example 3 with VerificationException

use of edu.umass.cs.gnscommon.exceptions.client.VerificationException in project GNS by MobilityFirst.

the class CommandUtils method checkResponse.

/**
   *
   * @param command
   *
   * @param responsePacket
   * @return Response as a string.
   * @throws ClientException
   */
public static ResponsePacket checkResponse(ResponsePacket responsePacket, CommandPacket command) throws ClientException {
    ResponseCode code = responsePacket.getErrorCode();
    String returnValue = responsePacket.getReturnValue();
    // wants to return a null value.
    if (code.isOKResult()) {
        return (returnValue.startsWith(GNSProtocol.NULL_RESPONSE.toString())) ? null : //returnValue;
        responsePacket;
    }
    // else error
    String errorSummary = code + ": " + returnValue + //+ ": " + responsePacket.getSummary()
    (command != null ? " for command " + command.getSummary() : "");
    switch(code) {
        case SIGNATURE_ERROR:
            throw new EncryptionException(code, errorSummary);
        case BAD_GUID_ERROR:
        case BAD_ACCESSOR_ERROR:
        case BAD_ACCOUNT_ERROR:
            throw new InvalidGuidException(code, errorSummary);
        case FIELD_NOT_FOUND_ERROR:
            throw new FieldNotFoundException(code, errorSummary);
        case ACCESS_ERROR:
            throw new AclException(code, errorSummary);
        case VERIFICATION_ERROR:
            throw new VerificationException(code, errorSummary);
        case ALREADY_VERIFIED_EXCEPTION:
            throw new VerificationException(code, errorSummary);
        case DUPLICATE_ID_EXCEPTION:
            //case DUPLICATE_NAME_EXCEPTION:
            throw new DuplicateNameException(code, errorSummary);
        case DUPLICATE_FIELD_EXCEPTION:
            throw new InvalidFieldException(code, errorSummary);
        case ACTIVE_REPLICA_EXCEPTION:
            throw new InvalidGuidException(code, errorSummary);
        case NONEXISTENT_NAME_EXCEPTION:
            throw new InvalidGuidException(code, errorSummary);
        case TIMEOUT:
        case RECONFIGURATION_EXCEPTION:
            throw new ClientException(code, errorSummary);
        default:
            throw new ClientException(code, "Error received with an unknown response code: " + errorSummary);
    }
}
Also used : ResponseCode(edu.umass.cs.gnscommon.ResponseCode) DuplicateNameException(edu.umass.cs.gnscommon.exceptions.client.DuplicateNameException) InvalidGuidException(edu.umass.cs.gnscommon.exceptions.client.InvalidGuidException) EncryptionException(edu.umass.cs.gnscommon.exceptions.client.EncryptionException) FieldNotFoundException(edu.umass.cs.gnscommon.exceptions.client.FieldNotFoundException) VerificationException(edu.umass.cs.gnscommon.exceptions.client.VerificationException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) AclException(edu.umass.cs.gnscommon.exceptions.client.AclException) InvalidFieldException(edu.umass.cs.gnscommon.exceptions.client.InvalidFieldException)

Aggregations

VerificationException (edu.umass.cs.gnscommon.exceptions.client.VerificationException)3 GNSClientCommands (edu.umass.cs.gnsclient.client.GNSClientCommands)2 GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)2 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)2 ResponseCode (edu.umass.cs.gnscommon.ResponseCode)1 AclException (edu.umass.cs.gnscommon.exceptions.client.AclException)1 DuplicateNameException (edu.umass.cs.gnscommon.exceptions.client.DuplicateNameException)1 EncryptionException (edu.umass.cs.gnscommon.exceptions.client.EncryptionException)1 FieldNotFoundException (edu.umass.cs.gnscommon.exceptions.client.FieldNotFoundException)1 InvalidFieldException (edu.umass.cs.gnscommon.exceptions.client.InvalidFieldException)1 InvalidGuidException (edu.umass.cs.gnscommon.exceptions.client.InvalidGuidException)1 IOException (java.io.IOException)1 StringTokenizer (java.util.StringTokenizer)1 ExecutorService (java.util.concurrent.ExecutorService)1 JSONException (org.json.JSONException)1