Search in sources :

Example 41 with GNSClientCommands

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();
    }
}
Also used : GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) InputStreamReader(java.io.InputStreamReader) GNSClient(edu.umass.cs.gnsclient.client.GNSClient) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) RandomString(edu.umass.cs.gnscommon.utils.RandomString) File(java.io.File) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) BeforeClass(org.junit.BeforeClass)

Example 42 with GNSClientCommands

use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.

the class ServerConnectTest method setUpBeforeClass.

/**
   *
   * @throws Exception
   */
@BeforeClass
public static void setUpBeforeClass() throws Exception {
    if (System.getProperty("startServer") != null && System.getProperty("startServer").equals("true")) {
        // clear explicitly if gigapaxos
        if (useGPScript()) {
            RunCommand.command("kill -s TERM `ps -ef | grep GNS.jar | grep -v grep | " + "grep -v ServerConnectTest  | grep -v \"context\" | awk '{print $2}'`", ".");
            System.out.println(System.getProperty(DefaultProps.SERVER_COMMAND.key) + " " + getGigaPaxosOptions() + " forceclear all");
            RunCommand.command(System.getProperty(DefaultProps.SERVER_COMMAND.key) + " " + getGigaPaxosOptions() + " forceclear all", ".");
            /* We need to do this to limit the number of files used by mongo.
				 * Otherwise failed runs quickly lead to more failed runs because
				 * index files created in previous runs are not removed.
         */
            dropAllDatabases();
            options = getGigaPaxosOptions() + " restart all";
        } else {
            options = SCRIPTS_OPTIONS;
        }
        System.out.println(System.getProperty(DefaultProps.SERVER_COMMAND.key) + " " + options);
        ArrayList<String> output = RunCommand.command(System.getProperty(DefaultProps.SERVER_COMMAND.key) + " " + options, ".");
        if (output != null) {
            for (String line : output) {
                System.out.println(line);
            }
        } else {
            failWithStackTrace("Server command failure: ; aborting all tests.");
        }
    }
    String gpConfFile = System.getProperty(DefaultProps.GIGAPAXOS_CONFIG.key);
    String logFile = System.getProperty(DefaultProps.LOGGING_PROPERTIES.key);
    ArrayList<String> output = RunCommand.command("cat " + logFile + " | grep \"java.util.logging.FileHandler.pattern\" | sed 's/java.util.logging.FileHandler.pattern = //g'", ".", false);
    String logFiles = output.get(0) + "*";
    System.out.println("Waiting for servers to be ready...");
    output = RunCommand.command("cat " + gpConfFile + " | grep \"reconfigurator\\.\" | wc -l ", ".", false);
    int numRC = Integer.parseInt(output.get(0));
    output = RunCommand.command("cat " + gpConfFile + " | grep \"active\\.\" | wc -l ", ".", false);
    int numAR = Integer.parseInt(output.get(0));
    int numServers = numRC + numAR;
    output = RunCommand.command("cat " + logFiles + " | grep \"server ready\" | wc -l ", ".", false);
    int numServersUp = Integer.parseInt(output.get(0));
    while (numServersUp < numServers) {
        Thread.sleep(5000);
        output = RunCommand.command("cat " + logFiles + " | grep \"server ready\" | wc -l ", ".", false);
        numServersUp = Integer.parseInt(output.get(0));
        System.out.println(Integer.toString(numServersUp) + " out of " + Integer.toString(numServers) + " servers are ready.");
    }
    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) {
            e.printStackTrace();
            ThreadUtils.sleep((5 - tries) * 5000);
        }
    } while (!accountCreated && --tries > 0);
    if (accountCreated == false) {
        failWithStackTrace("Failure setting up account guid; aborting all tests.");
    }
}
Also used : GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) GNSClient(edu.umass.cs.gnsclient.client.GNSClient) RandomString(edu.umass.cs.gnscommon.utils.RandomString) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) BeforeClass(org.junit.BeforeClass)

Example 43 with GNSClientCommands

use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.

the class CreateDNSRecordExample method main.

/**
	 * @param args
	 * @throws Exception 
	 */
public static void main(String[] args) throws Exception {
    // initialize parameters
    DOMAIN = "example.com.";
    if (System.getProperty("domain") != null) {
        DOMAIN = System.getProperty("domain");
    }
    // if domain does not end with a dot, add a dot to its end
    if (!DOMAIN.endsWith(".")) {
        DOMAIN = DOMAIN + ".";
    }
    // use domain name and a random number as account
    ACCOUNT = DOMAIN;
    /**
		 *  default record file is "conf/activeCode/records", it list the IP addresses in separate lines as:
		 *  1.1.1.1
		 *  2.2.2.2
		 *  ...
		 */
    RECORD_FILE = "conf/activeCode/records";
    if (System.getProperty("record_file") != null) {
        RECORD_FILE = System.getProperty("record_file");
    }
    // read in records
    List<String> records = new ArrayList<String>();
    BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(RECORD_FILE)));
    String line = reader.readLine();
    while (line != null) {
        records.add(line);
        line = reader.readLine();
    }
    reader.close();
    // initialize client and create record for the domain
    try {
        client = new GNSClientCommands();
    } catch (IOException e) {
        e.printStackTrace();
    }
    GuidEntry accountGuid = GuidUtils.lookupOrCreateAccountGuid(client, ACCOUNT, "password", true);
    JSONObject recordObj = ManagedDNSServiceProxy.recordToCreate(records, TTL);
    client.execute(GNSCommand.fieldUpdate(accountGuid, "A", recordObj));
    System.out.println("A record for domain " + DOMAIN + " has been created.");
    System.exit(0);
}
Also used : GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) InputStreamReader(java.io.InputStreamReader) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry)

Example 44 with GNSClientCommands

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.");
    }
}
Also used : GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) GNSClient(edu.umass.cs.gnsclient.client.GNSClient) BeforeClass(org.junit.BeforeClass)

Example 45 with GNSClientCommands

use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.

the class ClientACLExample 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 {
    client = new GNSClientCommands();
    System.out.println("[Client connected to GNS]\n");
    try {
        System.out.println("// account GUID creation\n" + "client.execute(" + ACCOUNT_NAME + ")");
        client.execute(GNSCommand.createAccount(ACCOUNT_NAME));
        GUID = GuidUtils.getGUIDKeys(ACCOUNT_NAME);
    } catch (Exception | Error e) {
        System.out.println("Exception during accountGuid creation: " + e);
        e.printStackTrace();
        System.exit(1);
    }
    // Create a JSON Object to initialize our guid record
    JSONObject json = new JSONObject("{\"name\":\"me\",\"location\":\"work\"}");
    // Write out the JSON Object
    client.execute(GNSCommand.update(GUID, json));
    System.out.println("\n// Update guid record\n" + "client.update(guid, record) // record=" + json);
    // Remove default read access from guid
    client.execute(GNSCommand.aclRemove(AclAccessType.READ_WHITELIST, GUID, GNSProtocol.ENTIRE_RECORD.toString(), GNSProtocol.ALL_GUIDS.toString()));
    System.out.println("\n// Remove default read access from guid\n" + "client.aclRemove(READ_WHITELIST, guid, ALL_FIELDS, ALL_GUIDS)");
    // Create phoneGuid
    // First we create an alias for the phoneGuid
    String phoneAlias = "phone" + RandomString.randomString(12);
    // Create a sub guid under our guid account
    client.execute(GNSCommand.guidCreate(GUID, phoneAlias));
    // Get the GuidEntry from the local database
    phoneGuid = GuidUtils.getGUIDKeys(phoneAlias);
    System.out.println("\n// Create phoneGuid\n" + "client.guidCreate(guid, phoneAlias) // phoneAlias=" + phoneAlias);
    // Give phoneGuid read access to fields in guid
    // If we had not removed the default read access from guid this step
    // would be unnecessary
    client.execute(GNSCommand.aclAdd(AclAccessType.READ_WHITELIST, GUID, GNSProtocol.ENTIRE_RECORD.toString(), phoneGuid.getGuid()));
    JSONObject result = client.execute(GNSCommand.read(GUID.getGuid(), phoneGuid)).getResultJSONObject();
    System.out.println("\n// Give phoneGuid read access to fields in guid and read guid entry as phoneGuid\n" + "client.aclAdd(READ_WHITELIST, guid, ALL_FIELDS, phoneGuid)\n" + "client.read(guid, phoneGuid) -> " + result);
    // Allow phoneGuid to write to the location field of guid
    client.execute(GNSCommand.aclAdd(AclAccessType.WRITE_WHITELIST, GUID, "location", phoneGuid.getGuid()));
    System.out.println("\n// Give phoneGuid write access to \"location\" field of guid\n" + "client.aclAdd(WRITE_WHITELIST, guid, \"location\", phoneGuid)");
    // As phoneGuid, update the location field on guid
    client.execute(GNSCommand.fieldUpdate(GUID.getGuid(), "location", "home", phoneGuid));
    String field_result = client.execute(GNSCommand.fieldRead(GUID.getGuid(), "location", phoneGuid)).getResultString();
    System.out.println("\n// Use phoneGuid to update \"location\" field of guid\n" + "client.fieldUpdate(guid, \"location\", \"home\", phoneGuid)\n" + "client.fieldRead(guid.getGuid(), \"location\", phoneGuid) -> " + field_result);
    // Remove phoneGuid from ACL
    client.execute(GNSCommand.aclRemove(AclAccessType.READ_WHITELIST, GUID, GNSProtocol.ENTIRE_RECORD.toString(), phoneGuid.getGuid()));
    client.execute(GNSCommand.aclRemove(AclAccessType.WRITE_WHITELIST, GUID, "location", phoneGuid.getGuid()));
    System.out.println("\n// Remove phoneGuid from guid's read and write whitelists \n" + "client.aclRemove(READ_WHITELIST, guid, ALL_FIELDS, phoneGuid))\n" + "client.aclRemove(WRITE_WHITELIST, guid, \"location\", phoneGuid);");
    // Verify phoneGuid can't read guid (exception expected)
    try {
        System.out.println("\n// Attempting to read from guid using phoneGuid (failure expected)\n" + "client.read(guid, phoneGuid)");
        result = client.execute(GNSCommand.read(GUID.getGuid(), phoneGuid)).getResultJSONObject();
        System.out.println("SOMETHING WENT WRONG. An exception should have been thrown. Terminating.");
        client.close();
        System.exit(1);
    } catch (AclException e) {
        System.out.println("// client.read failed as expected with the following AclException:\n" + e.getMessage());
    }
    // expected)
    try {
        System.out.println("\n// Attempting to update \"location\" field of guid using phoneGuid (failure expected)\n" + "client.fieldUpdate(guid.getGuid(), \"location\", \"vacation\", phoneGuid)");
        client.execute(GNSCommand.fieldUpdate(GUID.getGuid(), "location", "vacation", phoneGuid));
        System.out.println("\nSOMETHING WENT WRONG. An exception should have been thrown. Terminating.");
        client.close();
        System.exit(1);
    } catch (AclException e) {
        System.out.println("// client.fieldUpdate failed as expected with the following AclException:\n" + e.getMessage());
    }
    System.out.println("\n// Example complete, gracefully closing the client\n" + "client.close()");
    client.close();
}
Also used : GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) JSONObject(org.json.JSONObject) RandomString(edu.umass.cs.gnscommon.utils.RandomString) AclException(edu.umass.cs.gnscommon.exceptions.client.AclException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) AclException(edu.umass.cs.gnscommon.exceptions.client.AclException)

Aggregations

GNSClientCommands (edu.umass.cs.gnsclient.client.GNSClientCommands)70 IOException (java.io.IOException)55 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)50 StringTokenizer (java.util.StringTokenizer)35 GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)28 JSONArray (org.json.JSONArray)13 JSONException (org.json.JSONException)11 DuplicateNameException (edu.umass.cs.gnscommon.exceptions.client.DuplicateNameException)10 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)10 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)9 JSONObject (org.json.JSONObject)9 InvalidKeyException (java.security.InvalidKeyException)8 SignatureException (java.security.SignatureException)8 GNSClient (edu.umass.cs.gnsclient.client.GNSClient)6 PublicKey (java.security.PublicKey)6 HashSet (java.util.HashSet)6 BeforeClass (org.junit.BeforeClass)6 RandomString (edu.umass.cs.gnscommon.utils.RandomString)5 File (java.io.File)5 FileInputStream (java.io.FileInputStream)5