getClusterState($clusterName); if ($clusterStateResponse['result'] != 0) { print json_encode($clusterStateResponse); return; } $clusterState = json_decode($clusterStateResponse['state'], true); /* Run an actual deploy only if this cluster has passed the stage of * configuring its services (which means the next thing to do is to * kick off the deploy). */ if (($clusterState['state'] == 'CONFIGURATION_IN_PROGRESS') && ($clusterState['context']['stage'] == 'CONFIGURE_SERVICES')) { $deployResult = $hmc->deployHDP(); if ($deployResult["result"] != 0) { print json_encode($deployResult); return; } if (!isset($deployResult["txnId"])) { print json_encode ( array("result" => 1, "error" => "Could not obtain txn info for triggered command")); return; } $txnId = $deployResult["txnId"]; /* (And when we kick off the deploy is the only time to update the state of * the cluster). */ $state = "DEPLOYMENT_IN_PROGRESS"; $displayName = "Deployment in progress"; $context = array ( 'txnId' => $txnId ); $retval = updateClusterState($clusterName, $state, $displayName, $context); if ($retval['result'] != 0) { $result = $retval['result']; $error = $retval['error']; } } /* In case the deploy is already running or has ended, just return the txnId * from the DB instead of kicking off a fresh deploy - this is so we can use * this entrypoint to show the cluster's deploy progress at any time in the * future, not just during a live deploy. */ elseif (($clusterState['state'] == 'DEPLOYMENT_IN_PROGRESS') || ($clusterState['state'] == 'DEPLOYED')) { $txnId = $clusterState['context']['txnId']; } $thisHostName = trim(strtolower(exec('hostname -f'))); $nagiosGangliaCoHosted = FALSE; // check if nagios hosted on same server if (!$nagiosGangliaCoHosted) { // check if component mapped to this host $hostMap = $dbAccessor->getHostsForComponent($clusterName, "NAGIOS_SERVER"); if (isset($hostMap["hosts"][$thisHostName])) { $nagiosGangliaCoHosted = TRUE; } } // if still nothing then check if ganglia server installed on same server if (!$nagiosGangliaCoHosted) { // check if component mapped to this host $hostMap = $dbAccessor->getHostsForComponent($clusterName, "GANGLIA_MONITOR_SERVER"); if (isset($hostMap["hosts"][$thisHostName])) { $nagiosGangliaCoHosted = TRUE; } } /* Create the output data... */ $jsonOutput = array( 'clusterName' => $clusterName, 'txnId' => $txnId, 'nagiosGangliaCoHosted' => $nagiosGangliaCoHosted); /* ...and spit it out. */ header("Content-type: application/json"); print (json_encode(array("result" => $result, "error" => $error, "response" => $jsonOutput))); ?>