diff --git a/README.md b/README.md new file mode 100644 index 000000000..5196a3285 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# IT490-004 | System Integration Project + + +### Overview +Class Project to demonstrate the creation of a full stack application. + +### Build diff --git a/dmz-processor/processor.php b/dmz-processor/processor.php new file mode 100644 index 000000000..2215c0477 --- /dev/null +++ b/dmz-processor/processor.php @@ -0,0 +1,146 @@ +#!/usr/bin/php + $method, + "api_key" => $api_key, + "format" => "json", ], $extras); + + $endpoint = $url . "?" . http_build_query($query); //creates url + + $data = file_get_contents($endpoint); + + return json_decode($data, true); //returns data +} + +function many_artists($url, $api) { //gets info for 300 artists + echo "Artists \n"; + + $top_artists = lastfm($url, $api, "chart.getTopArtists", ["limit" => 100000]); //limit # of artists + + if (!$top_artists || !isset($top_artists["artists"]["artist"])) { //error checking + echo "No Artists Data \n"; + return null; + } + + $results = []; + foreach ($top_artists["artists"]["artist"] as $artist) { //loop through each artist + $name = $artist["name"]; + + $artist_info = lastfm($url, $api, "artist.getInfo", ["artist" => $name]); //gets info + + if (!$artist_info || !isset($artist_info["artist"])) { //skips if no data + echo "No data for: $name \n"; + continue; + } + + $results[] = [ + "name" => $artist_info["artist"]["name"], + "listeners" => (int)($artist_info["artist"]["stats"]["listeners"]), + "play_count" => (int)($artist_info["artist"]["stats"]["playcount"]), + "bio" => trim(strip_tags($artist_info["artist"]["bio"]["summary"])), + "url" => $artist_info["artist"]["url"], + "mbid" => $artist_info["artist"]["mbid"] + ]; + } + echo "DONE \n"; + return [ + "type" => "many_artists", + "fetched_at" => date("Y-m-d"), + "payload" => $results + ]; +} + + +function many_tracks($url, $api) { //many tracks + echo "Tracks \n"; + + $top_tracks = lastfm($url, $api, "chart.getTopTracks",["limit" => 100000]) ; //chart.getTopTracks + + if (!$top_tracks || !isset($top_tracks["tracks"]["track"])) { //checks for error + echo "No Track Data"; + return null; + } + + $tracks = []; + foreach ($top_tracks["tracks"]["track"] as $track) { //puts them into a list + $tracks[] = [ + "track_name" => $track["name"], + "artist" => $track["artist"]["name"], + "play_count" => (int)($track["playcount"] ), + "url" => $track["url"], + "mbid" => $track["mbid"] + ]; + } + + echo "DONE \n"; + return [ //returns formatted list + "type" => "many_tracks", + "fetched_at" => date("Y-m-d"), + "payload" => $tracks + ]; +} + +function single_artist($url, $api, $name) { //gets the information on a certain artist + echo "Artist Info \n"; + + $artist = lastfm($url, $api, "artist.getInfo", ["artist" => $name]); //artst.getInfo + + if (!$artist || !isset($artist["artist"])) { //error checking + echo "Artist not found: $name\n"; + return null; + } + + $artist[] = [ + "name" => $artist["artist"]["name"], + "listeners" => (int)($artist["artist"]["stats"]["listeners"]), + "play_count" => (int)($artist["artist"]["stats"]["playcount"]), + "bio" => trim(strip_tags($artist["artist"]["bio"]["summary"])), + "url" => $artist["artist"]["url"], + "mbid" => $artist["artist"]["mbid"] + ]; + + echo "DONE \n"; + return [ //returns formatted info + "type" => "single_artist", + "fetched_at" => date("Y-m-d"), + "payload" => $artist + ]; +} + +function requests($request) { //handles the requests + global $API, $URL; + + if (!isset($request['type'])) { //error checking + return ["status" => "error", "message" => "unsupported type"]; + +} elseif ($request["type"] == "many_artists") { + $data = many_artists($URL, $API); + return ["status" => "success", "data" => $data]; + +} elseif ($request["type"] == "many_tracks") { + $data = many_tracks($URL,$API); + return ["status" => "success", "data" => $data]; + +} elseif ($request["type"] == "single_artist") { + $data = single_artist($URL,$API); + return ["status" => "success", "data" => $data]; + +} else { + echo "Unknown type: " . $request['type'] . "\n"; + } +} + +$server = new rabbitMQServer(__DIR__ . '/../testRabbitMQ.ini', 'testServer3'); //connection to the broker +echo "API ready \n"; +$server->process_requests('requests'); +exit(); +?> diff --git a/mysqlconnect.php b/mysqlconnect.php new file mode 100644 index 000000000..9ca5f1215 --- /dev/null +++ b/mysqlconnect.php @@ -0,0 +1,25 @@ +#!/usr/bin/php +errno != 0) +{ + echo "failed to connect to database: ". $mydb->error . PHP_EOL; + exit(0); +} + +echo "successfully connected to database".PHP_EOL; + +$query = "select * from students;"; + +$response = $mydb->query($query); +if ($mydb->errno != 0) +{ + echo "failed to execute query:".PHP_EOL; + echo __FILE__.':'.__LINE__.":error: ".$mydb->error.PHP_EOL; + exit(0); +} + + +?> \ No newline at end of file diff --git a/rabbitMQLib.inc b/rabbitMQLib.inc index 94c13c1f0..d86cb5c0f 100644 --- a/rabbitMQLib.inc +++ b/rabbitMQLib.inc @@ -34,12 +34,13 @@ class rabbitMQServer } $this->exchange = $this->machine[$server]["EXCHANGE"]; $this->queue = $this->machine[$server]["QUEUE"]; + $this->routing_key = $this->machine[$server]["ROUTING_KEY"]; } function process_message($msg) { // send the ack to clear the item from the queue - if ($msg->getRoutingKey() !== "*") + if ($msg->getRoutingKey() !== $this->routing_key) { return; } @@ -74,6 +75,7 @@ class rabbitMQServer $conn_queue = new AMQPQueue($channel); $conn_queue->setName($msg->getReplyTo()); $replykey = $this->routing_key.".response"; + $conn_queue->declare(); $conn_queue->bind($exchange->getName(),$replykey); $exchange->publish(json_encode($response),$replykey,AMQP_NOPARAM,array('correlation_id'=>$msg->getCorrelationId())); @@ -166,6 +168,7 @@ class rabbitMQClient } $this->exchange = $this->machine[$server]["EXCHANGE"]; $this->queue = $this->machine[$server]["QUEUE"]; + $this->routing_key = $this->machine[$server]["ROUTING_KEY"]; } function process_response($response) @@ -267,6 +270,7 @@ class rabbitMQClient die("failed to send message to exchange: ". $e->getMessage()."\n"); } } + } ?> diff --git a/testRabbitMQ.ini b/testRabbitMQ.ini index d63cd54f4..459368f8f 100644 --- a/testRabbitMQ.ini +++ b/testRabbitMQ.ini @@ -9,3 +9,26 @@ QUEUE = testQueue ;EXCHANGE_TYPE = ???? AUTO_DELETE = true +[testServer2] +BROKER_HOST = 100.88.147.61 +BROKER_PORT = 5672 +USER = test +PASSWORD = test +VHOST = testHost +EXCHANGE = testExchange +QUEUE = testQueue +ROUTING_KEY = us.frontend +;EXCHANGE_TYPE = ???? +AUTO_DELETE = true + +[testServer3] +BROKER_HOST = 100.116.117.114 +BROKER_PORT = 5672 +USER = test +PASSWORD = test +VHOST = testHost +EXCHANGE = testExchange +QUEUE = dmz_jobs +ROUTING_KEY = us.api +;EXCHANGE_TYPE = ???? +AUTO_DELETE = true diff --git a/testRabbitMQClient.php b/testRabbitMQClient.php index 2bbdc5224..241d999b5 100755 --- a/testRabbitMQClient.php +++ b/testRabbitMQClient.php @@ -4,7 +4,7 @@ require_once('get_host_info.inc'); require_once('rabbitMQLib.inc'); -$client = new rabbitMQClient("testRabbitMQ.ini","testServer"); +$client = new rabbitMQClient("testRabbitMQ.ini","testServer2"); if (isset($argv[1])) { $msg = $argv[1];