Ejemplo n.º 1
0
$start = __LINE__;
$status = $db->scan("test", null, function ($record) {
    if (array_key_exists('email', $record['bins']) && !is_null($record['bins']['email']) && array_key_exists('name', $record['bins']) && !is_null($record['bins']['name'])) {
        echo "\n({$record['key']['ns']},{$record['key']['set']}," . base64_encode($record['key']['digest']) . ")";
    }
});
if ($status != AEROSPIKE::OK) {
    echo standard_fail($db);
} else {
    echo success();
}
if (isset($args['a']) || isset($args['annotate'])) {
    display_code(__FILE__, $start, __LINE__);
}
if (isset($args['a']) || isset($args['clean'])) {
    $start = __LINE__;
    echo colorize("Removing the record ≻", 'black', true);
    $key = $db->initKey("test", "users", 1234);
    $status = $db->remove($key);
    $key = $db->initKey("test", "users", 2345);
    $status = $db->remove($key);
    if ($status == Aerospike::OK) {
        echo success();
    } else {
        echo standard_fail($db);
    }
    if (isset($args['a']) || isset($args['annotate'])) {
        display_code(__FILE__, $start, __LINE__);
    }
}
$db->close();
Ejemplo n.º 2
0
    if (!$has_pygmentize) {
        echo "for syntax highlighting please install Pygmentize\n";
    }
    exit(1);
}
$HOST_ADDR = isset($args["h"]) ? (string) $args["h"] : (isset($args["host"]) ? (string) $args["host"] : "127.0.0.1");
$HOST_PORT = isset($args["p"]) ? (int) $args["p"] : (isset($args["port"]) ? (string) $args["port"] : 3000);
if (isset($args['a']) || isset($args['annotate'])) {
    $annotate = true;
} else {
    $annotate = false;
}
echo colorize("***** Welcome to Aerospike Developer Training *****\n", 'blue', true);
echo colorize("Connecting to Aerospike cluster ≻", 'black', true);
if ($annotate) {
    display_code(__FILE__, __LINE__, 7);
}
$config = array("hosts" => array(array("addr" => $HOST_ADDR, "port" => $HOST_PORT)));
$client = new Aerospike($config, false);
if (!$client->isConnected()) {
    echo standard_fail($client);
    echo colorize("Connection to Aerospike cluster failed! Please check the server settings and try again!\n", 'red', true);
    exit(2);
}
echo success();
$selection = show_menu();
if ($selection === 0) {
    $client->close();
    exit(0);
}
$user_service = new \Aerospike\Training\UserService($client, $config, $annotate);
 /**
  * Displays all tweets using a scan operation
  * @throws \Aerospike\Training\Exception
  */
 public function scanAllTweets()
 {
     echo colorize("\nScan for tweets\n", 'blue', true);
     echo colorize("Pass scanned records to callback ≻\n", 'black', true);
     if ($this->annotate) {
         display_code(__FILE__, __LINE__, 7);
     }
     $status = $this->client->scan('test', 'tweets', function ($record) {
         var_dump($record['bins']['tweet']);
     }, array('tweet'));
     if ($status !== Aerospike::OK) {
         // throwing an \Aerospike\Training\Exception
         throw new Exception($this->client, "Failed to scan test.tweets");
     }
     echo colorize("Done", 'green', true) . success() . "\n";
 }
 /**
  * Updates the user with the tweet count and latest tweet info
  * @param string $username
  * @param int $ts
  * @param int $tweet_count
  * @return boolean whether the update succeeded
  * @throws \Aerospike\Training\Exception
  */
 private function updateUser($username, $ts, $tweet_count)
 {
     $key = $this->getUserKey($username);
     $bins = array('tweetcount' => $tweet_count, 'lasttweeted' => $ts);
     echo colorize("Updating the user record ≻", 'black', true);
     if ($this->annotate) {
         display_code(__FILE__, __LINE__, 6);
     }
     $status = $this->client->put($key, $bins);
     if ($status !== Aerospike::OK) {
         echo fail();
         // throwing an \Aerospike\Training\Exception
         throw new Exception($this->client, "Failed to get the user {$username}");
     }
     echo success();
     return true;
 }
Ejemplo n.º 5
0
 /**
  * Asks the developer for input and updates a user's password using the
  * check-and-set pattern
  * @throws \Aerospike\Training\Exception
  */
 public function updatePasswordUsingCAS()
 {
     echo colorize("\nUpdate a user's password using CAS\n", 'blue', true);
     // Get username
     echo colorize("Enter username (or hit Return to skip): ");
     $username = trim(readline());
     if ($username == '') {
         return;
     }
     // Get password
     echo colorize("Enter a new password for {$username}: ");
     $new_password = trim(readline());
     echo colorize("Getting the metadata for the record ≻", 'black', true);
     $key = $this->getUserKey($username);
     if ($this->annotate) {
         display_code(__FILE__, __LINE__, 1);
     }
     $status = $this->client->exists($key, $metadata);
     if ($status !== Aerospike::OK) {
         // throwing an \Aerospike\Training\Exception
         echo fail();
         throw new Exception($this->client, "Failed to retrieve metadata for the record");
     }
     echo success();
     var_dump($metadata);
     echo colorize("Updating the user's password if the generation matches ≻", 'black', true);
     if ($this->annotate) {
         display_code(__FILE__, __LINE__, 4);
     }
     $bins = array('password' => $new_password);
     $policy = array(Aerospike::OPT_POLICY_GEN => array(Aerospike::POLICY_GEN_EQ, $metadata['generation']));
     $status = $this->client->put($key, $bins, $metadata['ttl'], $policy);
     if ($status !== Aerospike::OK) {
         // throwing an \Aerospike\Training\Exception
         echo fail();
         throw new Exception($this->client, "Writing with POLICY_GEN_EQ failed due to generation mismatch");
     }
     echo success();
 }
Ejemplo n.º 6
0
 /**
  * Asks the developer for input and finds the aggregated users by region
  * that fit a tweet count range
  * @throws \Aerospike\Training\Exception
  */
 public function aggregateUsersByRegion()
 {
     echo colorize("\nAggregate user's by region whose tweet count is in a given range", 'blue', true) . "\n";
     echo colorize("Ensuring the UDF module is registered ≻", 'black', true);
     $ok = $this->ensureUdfModule('udf/aggregationByRegion.lua', 'aggregationByRegion.lua');
     if ($ok) {
         echo success();
     } else {
         echo fail();
     }
     $this->display_module('udf/aggregationByRegion.lua');
     echo colorize("Enter min tweet count (or hit Return to skip): ");
     $min = trim(readline());
     if ($min == '') {
         return;
     }
     echo colorize("Enter max tweet count: ");
     $max = trim(readline());
     if ($this->annotate) {
         display_code(__FILE__, __LINE__, 11);
     }
     $where = $this->client->predicateBetween('tweetcount', $min, $max);
     $args = array();
     echo colorize("Call the aggregation stream UDF ≻", 'black', true);
     // @todo call the stream UDF 'sum' in Lua module 'aggregationByRegion' on results of the query matching the predicate $where
     // set the results in a variable called $returned
     //$status =...
     if ($status !== Aerospike::OK) {
         echo fail();
         // throwing an \Aerospike\Training\Exception
         throw new Exception($this->client, "Failed to execute the stream UDF");
     }
     echo success();
     var_dump($returned);
 }
Ejemplo n.º 7
0
 /**
  * Checks for the existence of the UDF module
  * @param string $module_alias
  * @return boolean
  */
 private function has_module($module_alias)
 {
     if ($this->annotate) {
         display_code(__FILE__, __LINE__, 6);
     }
     $status = $this->client->listRegistered($modules);
     if ($status !== Aerospike::OK) {
         return false;
     }
     foreach ($modules as $module) {
         if ($module['name'] == $module_alias) {
             return true;
         }
     }
     return false;
 }
function display_main()
{
    if (!isset($_GET["display"])) {
        $_GET["display"] = "notice";
    }
    if ($_GET["display"] == "register") {
        display_register();
    } else {
        if ($_GET["display"] == "clarifications") {
            display_clarifications();
        } else {
            if ($_GET["display"] == "account") {
                display_account();
            } else {
                if ($_GET["display"] == "problem") {
                    display_problem();
                } else {
                    if ($_GET["display"] == "submissions") {
                        display_submissions();
                    } else {
                        if ($_GET["display"] == "rankings") {
                            display_rankings();
                        } else {
                            if ($_GET["display"] == "code") {
                                display_code();
                            } else {
                                if ($_GET["display"] == "scoreboard") {
                                    display_scoreboard();
                                } else {
                                    if ($_GET["display"] == "adminsettings") {
                                        display_adminsettings();
                                    } else {
                                        if ($_GET["display"] == "admindata") {
                                            display_admindata();
                                        } else {
                                            if ($_GET["display"] == "adminproblem") {
                                                display_adminproblem();
                                            } else {
                                                if ($_GET["display"] == "adminteam") {
                                                    display_adminteam();
                                                } else {
                                                    if ($_GET["display"] == "admingroup") {
                                                        display_admingroup();
                                                    } else {
                                                        if ($_GET["display"] == "adminlogs") {
                                                            display_adminlogs();
                                                        } else {
                                                            if ($_GET["display"] == "doc") {
                                                                display_doc();
                                                            } else {
                                                                if ($_GET["display"] == "faq") {
                                                                    display_faq();
                                                                } else {
                                                                    if ($_GET["display"] == "notice") {
                                                                        display_notice();
                                                                    } else {
                                                                        display_notice();
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Ejemplo n.º 9
0
 /**
  * Asks the developer for input and updates a user's password using a record UDF
  * @throws \Aerospike\Training\Exception
  */
 public function updatePasswordUsingUDF()
 {
     echo colorize("\nUpdate a user's password using a UDF\n", 'blue', true);
     // Get username
     echo colorize("Enter username (or hit Return to skip): ");
     $username = trim(readline());
     if ($username == '') {
         return;
     }
     // Get password
     echo colorize("Enter a new password for {$username}: ");
     $new_password = trim(readline());
     echo colorize("Ensuring the UDF module is registered ≻", 'black', true);
     $ok = $this->ensureUdfModule('udf/updateUserPwd.lua', 'updateUserPwd.lua');
     if ($ok) {
         echo success();
     } else {
         echo fail();
     }
     $this->display_module('udf/updateUserPwd.lua');
     echo colorize("Updating the user record ≻", 'black', true);
     $key = $this->getUserKey($username);
     if ($this->annotate) {
         display_code(__FILE__, __LINE__, 7);
     }
     $args = array($new_password);
     $status = $this->client->apply($key, 'updateUserPwd', 'updatePassword', $args);
     if ($status !== Aerospike::OK) {
         // throwing an \Aerospike\Training\Exception
         echo fail();
         throw new Exception($this->client, "Failed to update password for user {$username}");
     }
     echo success();
 }