Fix healthcheck to check specific deployments

Change-Id: Idc6a3eece4e3aaba83a0b2388f2ae6c2407471a5
Issue-ID: DCAEGEN2-493
Signed-off-by: Jack Lucas <jflucas@research.att.com>
diff --git a/healthcheck-container/get-status.js b/healthcheck-container/get-status.js
index 2ed1d3d..034ff9d 100644
--- a/healthcheck-container/get-status.js
+++ b/healthcheck-container/get-status.js
@@ -96,6 +96,30 @@
 	});
 };
 
+const getStatusSinglePromise = function (item) {
+	// Expect item to be of the form {namespace: "namespace", deployment: "deployment_name"}
+	return new Promise(function(resolve, reject){
+		const path = K8S_PATH + item.namespace + '/deployments/' + item.deployment;
+		queryKubernetes(path, function(error, res, body){
+			if (error) {
+				reject(error);
+			}
+			else if (res.statusCode === 404) {
+				// Treat absent deployment as if it's an unhealthy deployment
+				resolve ({
+					metadata: {name: item.deployment},
+					status: {unavailableReplicas: 1}
+				});
+			}
+			else if (res.statusCode != 200) {
+				reject(body);
+			}
+			else {
+				resolve(body);
+			}
+		});
+	});
+}
 exports.getStatusNamespace = function (namespace, callback) {
 	// Get readiness information for all deployments in namespace
 	const path = K8S_PATH + namespace + '/deployments';
@@ -106,4 +130,12 @@
 	// Get readiness information for a single deployment
 	const path = K8S_PATH + namespace + '/deployments/' + deployment;
 	getStatus(path, summarizeDeployment, callback);
-};
\ No newline at end of file
+};
+
+exports.getStatusListPromise = function (list) {
+	// List is of the form [{namespace: "namespace", deployment: "deployment_name"}, ... ]
+	const p = Promise.all(list.map(getStatusSinglePromise))
+	return p.then(function(results) {
+	    return summarizeDeploymentList({items: results});
+	});
+}
\ No newline at end of file