createCluster($clusterName, $version, $state); assert(is_array($result) && isset($result["clusterName"])); assert($result["clusterName"] == $clusterName); assert($result["result"] == 0); assert($result["error"] == ""); print "Add Hosts To Cluster\n"; print "Adding hrt9n22.cc1.ygridcore.net\n"; print "Adding hrt9n34.cc1.ygridcore.net\n"; print "Adding hrt9n35.cc1.ygridcore.net\n"; print "Adding hrt9n36.cc1.ygridcore.net\n"; print "Adding hrt9n37.cc1.ygridcore.net\n"; $hosts = array ( array ( "hostName" => "hrt9n22.cc1.ygridcore.net", "ip" => "127.0.0.1", "totalMem" => 64, "cpuCount" => 4, "osArch" => "x86_64", "osType" => "RHEL5", "os" => "RHEL5 32-bit", "disksInfo" => "foo", "discoveryStatus" => "success", "badHealthReason" => "no error" ), array ( "hostName" => "hrt9n34.cc1.ygridcore.net", "ip" => "127.0.0.2", "totalMem" => 32, "cpuCount" => 8, "osArch" => "x86_64", "osType" => "RHEL6", "os" => "RHEL6 64-bit", "disksInfo" => "bar", "discoveryStatus" => "success", "badHealthReason" => "no error" ), array ( "hostName" => "hrt9n35.cc1.ygridcore.net", "ip" => "127.0.0.3", "totalMem" => 32, "cpuCount" => 8, "osArch" => "x86_64", "osType" => "RHEL6", "os" => "RHEL6 64-bit", "disksInfo" => "bar", "discoveryStatus" => "success", "badHealthReason" => "no error" ), array ( "hostName" => "hrt9n36.cc1.ygridcore.net", "ip" => "127.0.0.4", "totalMem" => 32, "cpuCount" => 8, "osArch" => "x86_64", "osType" => "RHEL6", "os" => "RHEL6 64-bit", "disksInfo" => "bar", "discoveryStatus" => "success", "badHealthReason" => "no error" ), array ( "hostName" => "hrt9n37.cc1.ygridcore.net", "ip" => "127.0.0.5", "totalMem" => 32, "cpuCount" => 8, "osArch" => "x86_64", "osType" => "RHEL6", "os" => "RHEL6 64-bit", "disksInfo" => "bar", "discoveryStatus" => "success", "badHealthReason" => "no error" ) ); $result = $db->addHostsToCluster($clusterName, $hosts); assert(is_array($result)); assert($result["clusterName"] == $clusterName); assert($result["result"] == 0); assert($result["error"] == ""); assert(count($result["hosts"]) == 5); print "Add Services To Cluster\n"; $services = array( array ( "serviceName" => "HDFS", "state" => "UNINSTALLED", "isEnabled" => TRUE ), array ( "serviceName" => "MAPREDUCE", "state" => "UNINSTALLED", "isEnabled" => TRUE ), array ( "serviceName" => "HBASE", "state" => "UNKNOWN", "isEnabled" => FALSE ) ); $result = $db->addServicesToCluster($clusterName, $services); assert(is_array($result)); assert($result["result"] == 0); assert($result["error"] == ""); print "Add Service Components To Cluster\n"; $comps = array ( "HDFS" => array ( "NAMENODE" => array( "state" => "UNINSTALLED", "desiredState" => ""), "DATANODE" => array( "state" => "UNINSTALLED", "desiredState" => ""), "SNAMENODE" => array( "state" => "UNINSTALLED", "desiredState" => "") ), "MAPREDUCE" => array ( "JOBTRACKER" => array( "state" => "UNINSTALLED", "desiredState" => ""), "TASKTRACKER" => array( "state" => "UNINSTALLED", "desiredState" => "") ) ); $result = $db->addServiceComponentsToCluster($clusterName, $comps); assert(is_array($result)); assert($result["result"] == 0); assert($result["error"] == ""); print "Map Hosts to Roles\n"; $mapping = array ( "NAMENODE" => array ("hrt9n22.cc1.ygridcore.net"), "SNAMENODE" => array ("hrt9n22.cc1.ygridcore.net"), "DATANODE" => array ("hrt9n34.cc1.ygridcore.net", "hrt9n35.cc1.ygridcore.net", "hrt9n36.cc1.ygridcore.net"), "JOBTRACKER" => array ("hrt9n37.cc1.ygridcore.net"), "TASKTRACKER" => array ("hrt9n34.cc1.ygridcore.net", "hrt9n35.cc1.ygridcore.net", "hrt9n36.cc1.ygridcore.net") ); foreach ($mapping as $comp => $hosts) { $db->addHostsToComponent($clusterName, $comp, $hosts, "", ""); assert(is_array($result)); assert($result["result"] == 0); assert($result["error"] == ""); } print "Add Service Configs\n"; $query = "INSERT OR REPLACE INTO ServiceConfig ( cluster_name, key, value ) " . " SELECT \"" . $clusterName . "\" , key, default_value " . " FROM ConfigProperties "; $command = "sqlite3 $dbPath '" . $query . "'"; system($command); print "Verify Service Config Defaults Added to DB\n"; $result = $db->getServiceConfig($clusterName); assert(is_array($result)); assert($result["result"] == 0); assert($result["error"] == ""); assert(is_array($result["properties"]) && count($result["properties"]) > 0); print "HMC testing\n"; $startTime = time(); $hmc = new HMC($dbPath, $clusterName); $result = $hmc->deployHDP(); print_r($result); assert($result["result"] == 0); assert(isset($result["txnId"])); $txnId = $result["txnId"]; $counter = 0; do { sleep(3); $curTime = time(); $progress = $hmc->getProgress($txnId); print "Elapsed: " . ($curTime - $startTime) . " seconds \n"; print "Progress: \n"; //print_r($progress); $counter++; if (($counter%10) == 4) { file_put_contents("/tmp/hmc.foo.dump.".$counter, json_encode($progress)); } if (!is_array($progress) || $progress["result"] != 0 || !$progress["processRunning"]) { print "Breaking loop now. Action completed \n"; break; } } while ( 1 ); /* print "LOGS *******"; $logs = $hmc->getLogs($txnId); print_r($logs); */ $startTime = time(); $result = $hmc->stopAllServices(); print_r($result); assert($result["result"] == 0); assert(isset($result["txnId"])); $txnId = $result["txnId"]; $counter = 0; do { sleep(3); $curTime = time(); print "Elapsed: " . ($curTime - $startTime) . " seconds \n"; print "Progress: \n"; $progress = $hmc->getProgress($txnId); //print_r($progress); $counter++; if (!is_array($progress) || $progress["result"] != 0 || !$progress["processRunning"]) { print "Breaking loop now. Action completed \n"; break; } } while ( 1 ); $startTime = time(); $result = $hmc->startAllServices(); print_r($result); assert($result["result"] == 0); assert(isset($result["txnId"])); $txnId = $result["txnId"]; $counter = 0; do { sleep(3); $curTime = time(); print "Elapsed: " . ($curTime - $startTime) . " seconds \n"; print "Progress: \n"; $progress = $hmc->getProgress($txnId); //print_r($progress); $counter++; if (!is_array($progress) || $progress["result"] != 0 || !$progress["processRunning"]) { print "Breaking loop now. Action completed \n"; break; } } while ( 1 ); $startTime = time(); $result = $hmc->reconfigureServices(array ( "HDFS" )); print_r($result); assert($result["result"] == 0); assert(isset($result["txnId"])); $txnId = $result["txnId"]; $counter = 0; do { sleep(3); $curTime = time(); print "Elapsed: " . ($curTime - $startTime) . " seconds \n"; print "Progress: \n"; $progress = $hmc->getProgress($txnId); //print_r($progress); $counter++; if (!is_array($progress) || $progress["result"] != 0 || !$progress["processRunning"]) { print "Breaking loop now. Action completed \n"; break; } } while ( 1 ); $startTime = time(); $result = $hmc->stopServices(array ( "HDFS", "MAPREDUCE" )); print_r($result); assert($result["result"] == 0); assert(isset($result["txnId"])); $txnId = $result["txnId"]; $counter = 0; do { sleep(3); $curTime = time(); print "Elapsed: " . ($curTime - $startTime) . " seconds \n"; print "Progress: \n"; $progress = $hmc->getProgress($txnId); //print_r($progress); $counter++; if (!is_array($progress) || $progress["result"] != 0 || !$progress["processRunning"]) { print "Breaking loop now. Action completed \n"; break; } } while ( 1 ); $startTime = time(); $result = $hmc->startServices(array ( "MAPREDUCE" )); print_r($result); assert($result["result"] == 0); assert(isset($result["txnId"])); $txnId = $result["txnId"]; $counter = 0; do { sleep(3); $curTime = time(); print "Elapsed: " . ($curTime - $startTime) . " seconds \n"; print "Progress: \n"; $progress = $hmc->getProgress($txnId); //print_r($progress); $counter++; if (!is_array($progress) || $progress["result"] != 0 || !$progress["processRunning"]) { print "Breaking loop now. Action completed \n"; break; } } while ( 1 ); $startTime = time(); $result = $hmc->stopServices(array ( "MAPREDUCE" )); print_r($result); assert($result["result"] == 0); assert(isset($result["txnId"])); $txnId = $result["txnId"]; $counter = 0; do { sleep(3); $curTime = time(); print "Elapsed: " . ($curTime - $startTime) . " seconds \n"; print "Progress: \n"; $progress = $hmc->getProgress($txnId); //print_r($progress); $counter++; if (!is_array($progress) || $progress["result"] != 0 || !$progress["processRunning"]) { print "Breaking loop now. Action completed \n"; break; } } while ( 1 ); print "Add More Hosts To Cluster\n"; print "Adding hrt9n39.cc1.ygridcore.net\n"; print "Adding hrt9n38.cc1.ygridcore.net\n"; $hosts = array ( array ( "hostName" => "hrt9n38.cc1.ygridcore.net", "ip" => "127.0.0.1", "totalMem" => 64, "cpuCount" => 4, "osArch" => "x86_64", "osType" => "RHEL5", "os" => "RHEL5 32-bit", "disksInfo" => "foo", "discoveryStatus" => "success", "badHealthReason" => "no error" ), array ( "hostName" => "hrt9n39.cc1.ygridcore.net", "ip" => "127.0.0.2", "totalMem" => 32, "cpuCount" => 8, "osArch" => "x86_64", "osType" => "RHEL6", "os" => "RHEL6 64-bit", "disksInfo" => "bar", "discoveryStatus" => "success", "badHealthReason" => "no error" ) ); $result = $db->addHostsToCluster($clusterName, $hosts); assert(is_array($result)); assert($result["clusterName"] == $clusterName); assert($result["result"] == 0); assert($result["error"] == ""); assert(count($result["hosts"]) == 2); print "Map new Hosts to Roles\n"; $mapping = array ( "DATANODE" => array ("hrt9n38.cc1.ygridcore.net", "hrt9n39.cc1.ygridcore.net"), "TASKTRACKER" => array ("hrt9n38.cc1.ygridcore.net", "hrt9n39.cc1.ygridcore.net") ); foreach ($mapping as $comp => $hosts) { $db->addHostsToComponent($clusterName, $comp, $hosts, "UNKNOWN", "UNKNOWN"); assert(is_array($result)); assert($result["result"] == 0); assert($result["error"] == ""); } $startTime = time(); $result = $hmc->deployNodes(array ( "hrt9n38.cc1.ygridcore.net" , "hrt9n39.cc1.ygridcore.net" )); print_r($result); assert($result["result"] == 0); assert(isset($result["txnId"])); $txnId = $result["txnId"]; $counter = 0; do { $curTime = time(); print "Elapsed: " . ($curTime - $startTime) . " seconds \n"; print "Progress: \n"; $progress = $hmc->getProgress($txnId); print_r($progress); $counter++; if (!is_array($progress) || $progress["result"] != 0 || !$progress["processRunning"]) { print "Breaking loop now. Action completed \n"; break; } } while ( 1 ); $startTime = time(); print("Uninstall HDP\n"); $result = $hmc->uninstallHDP(); print_r($result); assert($result["result"] == 0); assert(isset($result["txnId"])); $txnId = $result["txnId"]; $counter = 0; do { $curTime = time(); print "Elapsed: " . ($curTime - $startTime) . " seconds \n"; print "Progress: \n"; $progress = $hmc->getProgress($txnId); print_r($progress); $counter++; if (!is_array($progress) || $progress["result"] !=0 || !$progress["processRunning"]) { print "Breaking loop now. Action Completed \n"; break; } } while (1); ?>