public HttpResponseMessage ListCloudServicesAsync(string subscriptionId)
        {
            var requestMessage = this.Request;
            var detailLevel = requestMessage.RequestUri.ParseQueryString()["detailLevel"];
            
            List<Cluster> clusters;
            bool subExists = _clustersAvailable.TryGetValue(subscriptionId, out clusters);
            if (!subExists)
            {
                return this.Request.CreateResponse(HttpStatusCode.Accepted, new CloudServiceList());
            }

            var clustersByLocation = clusters.GroupBy(c => c.Location);

            var cloudServiceList = new CloudServiceList();

            foreach (var locationcluster in clustersByLocation)
            {
                var cloudService = new CloudService();
                cloudService.Description = "test description";
                cloudService.GeoRegion = locationcluster.Key;
                cloudService.Label = "test label";
                cloudService.Resources = new ResourceList();
                foreach (Cluster cluster in locationcluster)
                {
                    var resource = new Resource();
                    resource.Name = cluster.DnsName;
                    resource.Type = ClustersPocoClient.ClustersResourceType;
                    resource.State = cluster.State.ToString();
                    resource.OutputItems = this.GetOutputItems(cluster);
                    cloudService.Resources.Add(resource);
                }
                cloudServiceList.Add(cloudService);
            }

            return this.Request.CreateResponse(HttpStatusCode.Accepted, cloudServiceList);;
        }
        public static ClusterDetails CreateClusterDetailsFromRdfeResourceOutput(string cloudServiceRegion, Resource resouceOutput)
        {
            if (resouceOutput == null)
            {
                throw new ArgumentNullException("resouceOutput");
            }

            if (string.IsNullOrEmpty(cloudServiceRegion))
            {
                throw new ArgumentException("CloudService region cannot be null or empty.");
            }

            string version = SafeGetValueFromOutputItem(resouceOutput.OutputItems, "Version");
            string components = SafeGetValueFromOutputItem(resouceOutput.OutputItems, "ClusterComponents");
            ClusterType clusterType = !string.IsNullOrEmpty(components) ? GetClusterTypeFromComponentList(components) : ClusterType.Unknown;
            
            var clusterDetails = new ClusterDetails
            {
                Name = resouceOutput.Name,
                Version = version,
                StateString = resouceOutput.SubState,
                Location = cloudServiceRegion,
                ClusterType = clusterType,
            };

            if (!string.IsNullOrEmpty(version))
            {
                clusterDetails.VersionStatus = VersionFinderClient.GetVersionStatus(version);
                clusterDetails.VersionNumber = new PayloadConverter().ConvertStringToVersion(version);
            }
            else
            {
                clusterDetails.VersionNumber = new Version(0, 0);
            }

            //Operation status is populated with failed, then let us mark the state as error
            if (resouceOutput.OperationStatus != null && resouceOutput.OperationStatus.Result.Equals("Failed", StringComparison.OrdinalIgnoreCase))
            {
                clusterDetails.State = HDInsight.ClusterState.Error;
                string errorType = resouceOutput.OperationStatus.Type ?? string.Empty;
                clusterDetails.StateString = HDInsight.ClusterState.Error.ToString();
                if (resouceOutput.OperationStatus.Error != null)
                {
                    int httpCode = resouceOutput.OperationStatus.Error.HttpCode;
                    string errorMessage = resouceOutput.OperationStatus.Error.Message ?? string.Empty;
                  
                    clusterDetails.Error = new ClusterErrorStatus(httpCode,
                        errorMessage,
                        errorType);
                }
                else
                {
                    clusterDetails.Error = new ClusterErrorStatus(0, "Unknown error occurred", errorType);
                }
            }
            else
            {
                HDInsight.ClusterState clusterState;
                if (!Enum.TryParse(resouceOutput.SubState, true, out clusterState))
                {
                    clusterState = HDInsight.ClusterState.Unknown;
                }
                clusterDetails.State = clusterState;
            }

            return clusterDetails;
        }