public void UserSuppliedVersionTooHigh()
        {
            var userVersion = new Version(HDInsightSDKSupportedVersions.MaxVersion.Major, HDInsightSDKSupportedVersions.MaxVersion.Minor + 1, 0, 0);
            var client      = new VersionFinderClient(IntegrationTestBase.GetValidCredentials(), GetAbstractionContext(), false);

            Assert.AreEqual(client.GetVersionStatus(userVersion), VersionStatus.ToolsUpgradeRequired);
        }
        public void UserSuppliedVersionValid_LowLimit()
        {
            var userVersion = new Version(HDInsightSDKSupportedVersions.MinVersion.Major, HDInsightSDKSupportedVersions.MinVersion.Minor, 0, 0);
            var client      = new VersionFinderClient(IntegrationTestBase.GetValidCredentials(), GetAbstractionContext(), false);

            Assert.AreEqual(client.GetVersionStatus(userVersion), VersionStatus.Compatible);
        }
        public void ICanPerformA_PositiveAdditionalProppertiesXmlParsing_VersionFinderXmlParsing()
        {
            var capabilities = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("CAPABILITY_VERSION_1.2.0.0.LARGESKU-AMD64-134231", "CAPABILITY_VERSION_1.2.0.0.LARGESKU-AMD64-134231"),
                new KeyValuePair <string, string>("MyProperty", "MyProperty")
            };
            var versions = VersionFinderClient.ParseVersions(capabilities);

            Assert.AreEqual(1, versions.Count);
            Assert.AreEqual("1.2.0.0.LARGESKU-AMD64-134231", versions[0].Version);
        }
        public void ICanPerformA_PositiveCase_VersionFinderXmlParsing()
        {
            var capabilities = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("CAPABILITY_VERSION_1.2", "CAPABILITY_VERSION_1.2.0.0.LARGESKU-AMD64-134231"),
                new KeyValuePair <string, string>("CAPABILITY_VERSION_1.0", "CAPABILITY_VERSION_1.0"),
                new KeyValuePair <string, string>("CAPABILITY_VERSION_1.3", "CAPABILITY_VERSION_1.3.0.5.LARGESKU-AMD64-134231")
            };

            var versions = VersionFinderClient.ParseVersions(capabilities).Select(v => v.Version).ToList();

            Assert.AreEqual(3, versions.Count);
            Assert.AreEqual(1, versions.Count(version => version == "1.2"));
            Assert.AreEqual(1, versions.Count(version => version == "1.0"));
            Assert.AreEqual(1, versions.Count(version => version == "1.3"));
        }
Esempio n. 5
0
        internal IEnumerable <ClusterDetails> DeserializeHDInsightClusterList(string payload, string deploymentNamespace, Guid subscriptionId)
        {
            payload.ArgumentNotNullOrEmpty("payload");
            var payloadDocument   = XDocument.Parse(payload);
            var clusterList       = new List <ClusterDetails>();
            var clusterEnumerable = from cloudServices in payloadDocument.Elements(CloudServicesElementName)
                                    from cloudService in cloudServices.Elements(CloudServiceElementName)
                                    let geoRegion = cloudService.Element(GeoRegionElementName)
                                                    from resource in cloudService.Descendants(ResourceElementName)
                                                    let resourceNamespace = this.GetStringValue(resource, ResourceProviderNamespaceElementName)
                                                                            let intrinsicSettings = this.GetIntrinsicSettings(resource)
                                                                                                    let storageAccounts = this.GetStorageAccounts(resource, intrinsicSettings)
                                                                                                                          let rdfeResourceType = this.GetStringValue(resource, TypeElementName)
                                                                                                                                                 where resourceNamespace == deploymentNamespace && rdfeResourceType.Equals(ContainersResourceType, StringComparison.OrdinalIgnoreCase)
                                                                                                                                                 let versionString = this.GetClusterProperty(resource, intrinsicSettings, VersionName)
                                                                                                                                                                     select new ClusterDetails()
            {
                Name                      = this.GetStringValue(resource, NameElementName),
                Location                  = geoRegion.Value,
                StateString               = this.GetStringValue(resource, SubStateElementName),
                RdpUserName               = this.GetClusterProperty(resource, intrinsicSettings, RdpUserName),
                HttpUserName              = this.GetClusterProperty(resource, intrinsicSettings, HttpUserName),
                HttpPassword              = this.GetClusterProperty(resource, intrinsicSettings, HttpPassword),
                ClusterSizeInNodes        = this.ExtractClusterPropertyIntValue(resource, intrinsicSettings, NodesCount),
                ConnectionUrl             = this.GetClusterProperty(resource, intrinsicSettings, ConnectionUrl),
                CreatedDate               = this.ExtractClusterPropertyDateTimeValue(resource, intrinsicSettings, CreatedDate),
                Version                   = versionString,
                VersionStatus             = VersionFinderClient.GetVersionStatus(versionString),
                DefaultStorageAccount     = this.GetDefaultStorageAccount(storageAccounts),
                AdditionalStorageAccounts = this.GetAdditionalStorageAccounts(storageAccounts),
                VersionNumber             = this.ConvertStringToVersion(versionString),
                Error                     = this.DeserializeClusterError(resource),
                SubscriptionId            = subscriptionId,
                ClusterType               = this.GetClusterType(resource, intrinsicSettings)
            };

            clusterList.AddRange(clusterEnumerable);
            return(clusterList);
        }
        public static ClusterDetails CreateClusterDetailsFromRdfeResourceOutput(string cloudServiceRegion, Resource resource)
        {
            if (resource == null)
            {
                throw new ArgumentNullException("resouceOutput");
            }

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

            string version = SafeGetValueFromOutputItem(resource.OutputItems, "Version");
            string osType  = SafeGetValueFromOutputItem(resource.OutputItems, "OsType");

            var clusterDetails = new ClusterDetails
            {
                Name        = resource.Name,
                Version     = version,
                StateString = resource.SubState,
                Location    = cloudServiceRegion,
            };

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

            clusterDetails.Version = clusterDetails.VersionNumber.ToString();

            //Operation status is populated with failed, then let us mark the state as error
            if (resource.OperationStatus != null && resource.OperationStatus.Result.Equals("Failed", StringComparison.OrdinalIgnoreCase))
            {
                clusterDetails.State = HDInsight.ClusterState.Error;
                string errorType = resource.OperationStatus.Type ?? string.Empty;
                clusterDetails.StateString = HDInsight.ClusterState.Error.ToString();
                if (resource.OperationStatus.Error != null)
                {
                    int    httpCode     = resource.OperationStatus.Error.HttpCode;
                    string errorMessage = resource.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(resource.SubState, true, out clusterState))
                {
                    clusterState = HDInsight.ClusterState.Unknown;
                }
                clusterDetails.State = clusterState;
            }

            return(clusterDetails);
        }
        public static ClusterDetails CreateClusterDetailsFromGetClustersResult(IaasCluster clusterDetailsFromServer)
        {
            if (clusterDetailsFromServer == null)
            {
                throw new ArgumentNullException("clusterDetailsFromServer");
            }

            ClusterDetails clusterDetails = new ClusterDetails();

            clusterDetails.CreatedDate  = clusterDetailsFromServer.CreatedDate;
            clusterDetails.Location     = clusterDetailsFromServer.Location;
            clusterDetails.Name         = clusterDetailsFromServer.Id;
            clusterDetails.Version      = clusterDetailsFromServer.HdiVersion;
            clusterDetails.StateString  = clusterDetailsFromServer.State.ToString();
            clusterDetails.DeploymentId = clusterDetailsFromServer.TenantId.ToString() ?? string.Empty;

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

            clusterDetails.Version = clusterDetails.VersionNumber.ToString();

            // TODO: Determine this from the documents?
            clusterDetails.ClusterType = ClusterType.Hadoop;

            // This code will only run for IaasCluster which only supports Linux today
            // We would need to put this information in one of the documents at some point
            clusterDetails.OSType = OSType.Linux;

            if (clusterDetailsFromServer.Errors != null && clusterDetailsFromServer.Errors.Any())
            {
                // Populate error details with the most recent one. These occur if the deployment workflow errors out
                string errorDescription = string.Join(", ", clusterDetailsFromServer.Errors.Select(x => string.Format("{0} : {1}", x.ErrorCode, x.ErrorDescription)));
                clusterDetails.Error = new ClusterErrorStatus(0, errorDescription, string.Empty);
            }

            AzureCsmDocumentManager            azureCsmDocumentManager            = new AzureCsmDocumentManager(clusterDetailsFromServer.DeploymentDocuments[IaasClusterDocumentTypes.EmbeddedAzureConfigurationDocument]);
            AmbariConfigurationDocumentManager ambariConfigurationDocumentManager = new AmbariConfigurationDocumentManager(clusterDetailsFromServer.DeploymentDocuments[IaasClusterDocumentTypes.EmbeddedAmbariConfigurationDocument]);

            // Populate user name, passowrd, and server address information
            clusterDetails.HttpUserName = "******";
            clusterDetails.HttpPassword = ambariConfigurationDocumentManager.GetPassword();
            if (clusterDetailsFromServer.ConnectivityEndpoints != null)
            {
                foreach (var endpoint in clusterDetailsFromServer.ConnectivityEndpoints)
                {
                    var webEndPoint = endpoint as WebConnectivityEndpoint;
                    if (webEndPoint != null)
                    {
                        clusterDetails.ConnectionUrl = String.Format("https://{0}{1}", webEndPoint.Location, webEndPoint.Port > 0 ? String.Format(":{0}", webEndPoint.Port) : "");
                        break;
                    }
                }
            }

            clusterDetails.DefaultStorageAccount = ambariConfigurationDocumentManager.GetDefaultStorageAccount();

            // Populate additional Storage Accounts
            clusterDetails.AdditionalStorageAccounts = ambariConfigurationDocumentManager.GetAdditionalStorageAccounts();

            // Populate Data Node Count
            clusterDetails.ClusterSizeInNodes = azureCsmDocumentManager.GetWorkerNodeCount();

            return(clusterDetails);
        }
        public static ClusterDetails CreateClusterDetailsFromGetClustersResult(Cluster clusterDetailsFromServer)
        {
            if (clusterDetailsFromServer == null)
            {
                throw new ArgumentNullException("clusterDetailsFromServer");
            }

            ClusterDetails clusterDetails = new ClusterDetails();

            clusterDetails.CreatedDate  = clusterDetailsFromServer.CreatedTime;
            clusterDetails.Location     = clusterDetailsFromServer.Location;
            clusterDetails.Name         = clusterDetailsFromServer.DnsName;
            clusterDetails.Version      = clusterDetailsFromServer.Version;
            clusterDetails.StateString  = clusterDetailsFromServer.State.ToString();
            clusterDetails.DeploymentId = clusterDetailsFromServer.DeploymentId ?? string.Empty;

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

            string componentListCommaSeperated = clusterDetailsFromServer.Components != null
                                                     ? string.Join(",", clusterDetailsFromServer.Components.Select(c => c.GetType().Name))
                                                     : string.Empty;

            clusterDetails.ClusterType = !string.IsNullOrEmpty(componentListCommaSeperated)
                                        ? GetClusterTypeFromComponentList(componentListCommaSeperated)
                                        : ClusterType.Unknown;

            // This code will only execute for PaaS clusters which only support Windows
            clusterDetails.OSType = OSType.Windows;

            if (clusterDetailsFromServer.Error != null)
            {
                //Populate error details with the most recent one. These occur if the deployment workflow errors out
                clusterDetails.Error = new ClusterErrorStatus(
                    (int)clusterDetailsFromServer.Error.StatusCode, clusterDetailsFromServer.Error.ErrorMessage ?? string.Empty, string.Empty);
            }

            //Populate Uri and HttpCreds from the gateway. This should not throw
            //even if the gateway component is null
            PopulateClusterUriAndHttpCredsFromGateway(clusterDetails, clusterDetailsFromServer.Components.OfType <GatewayComponent>().SingleOrDefault());

            //Look for Yarn for 3X clusters
            var yarn = clusterDetailsFromServer.Components.OfType <YarnComponent>().SingleOrDefault();
            //Look for MR for 2X clusters
            var mr = clusterDetailsFromServer.Components.OfType <MapReduceComponent>().SingleOrDefault();

            if (yarn != null)
            {
                clusterDetails.ClusterSizeInNodes = yarn.NodeManagerRole.InstanceCount;
                var mapReduceApplication = yarn.Applications.OfType <MapReduceApplication>().SingleOrDefault();
                if (mapReduceApplication != null)
                {
                    //ToWasbConfiguration returns null if DefaultStorageAccountAndContainer is null
                    clusterDetails.DefaultStorageAccount = mapReduceApplication.DefaultStorageAccountAndContainer.ToWabStorageAccountConfiguration();
                    if (mapReduceApplication.AdditionalStorageContainers != null)
                    {
                        clusterDetails.AdditionalStorageAccounts =
                            mapReduceApplication.AdditionalStorageContainers.Select(s => s.ToWabStorageAccountConfiguration()).ToList();
                    }
                }
            }
            else if (mr != null)
            {
                clusterDetails.ClusterSizeInNodes    = mr.WorkerNodeRole.InstanceCount;
                clusterDetails.DefaultStorageAccount = mr.DefaultStorageAccountAndContainer.ToWabStorageAccountConfiguration();
                if (mr.AdditionalStorageAccounts != null)
                {
                    clusterDetails.AdditionalStorageAccounts = mr.AdditionalStorageAccounts.Select(s => s.ToWabStorageAccountConfiguration()).ToList();
                }
            }

            //populate RDP user name. All roles will have the same RDP properties so we pick the first one
            if (clusterDetailsFromServer.ClusterRoleCollection != null &&
                clusterDetailsFromServer.ClusterRoleCollection.Any() &&
                clusterDetailsFromServer.ClusterRoleCollection.First().RemoteDesktopSettings.IsEnabled)
            {
                clusterDetails.RdpUserName =
                    clusterDetailsFromServer.ClusterRoleCollection.First().RemoteDesktopSettings.AuthenticationCredential.Username;
            }

            //populate virtual network info
            VirtualNetworkConfiguration vnetConfigFromServer = clusterDetailsFromServer.VirtualNetworkConfiguration;

            if (vnetConfigFromServer != null && !string.IsNullOrEmpty(vnetConfigFromServer.VirtualNetworkSite))
            {
                clusterDetails.VirtualNetworkId = vnetConfigFromServer.VirtualNetworkSite;
                //Populate the subnet name
                if (vnetConfigFromServer.AddressAssignments != null &&
                    vnetConfigFromServer.AddressAssignments.Any() &&
                    vnetConfigFromServer.AddressAssignments.First().Subnets != null &&
                    vnetConfigFromServer.AddressAssignments.First().Subnets.First() != null)
                {
                    if (vnetConfigFromServer.AddressAssignments.Any())
                    {
                        clusterDetails.SubnetName = vnetConfigFromServer.AddressAssignments.First().Subnets.First().Name;
                    }
                }
            }

            return(clusterDetails);
        }