コード例 #1
0
        public async Task <HttpResponseMessage> CreateCluster(string subscriptionId, string cloudServiceName, string resourceNamespace, string dnsName)
        {
            var requestMessage = this.Request;
            var rdfeResource   = await requestMessage.Content.ReadAsAsync <RDFEResource>();

            XmlNode node = rdfeResource.IntrinsicSettings[0];

            MemoryStream stm = new MemoryStream();
            StreamWriter stw = new StreamWriter(stm);

            stw.Write(node.OuterXml);
            stw.Flush();
            stm.Position = 0;
            DataContractSerializer  ser = new DataContractSerializer(typeof(ClusterCreateParameters));
            ClusterCreateParameters clusterCreateParams = (ClusterCreateParameters)ser.ReadObject(stm);

            // Spark cluster creation in introduced after schema version 3.0
            if (clusterCreateParams.Components.Any(c => c.GetType() == typeof(SparkComponent)))
            {
                if (!requestMessage.Headers.GetValues("SchemaVersion").Any(v => v.Equals("3.0")))
                {
                    throw new NotSupportedException(ClustersTestConstants.NotSupportedBySubscriptionException);
                }
            }

            var testCluster = new Cluster
            {
                ClusterRoleCollection = clusterCreateParams.ClusterRoleCollection,
                CreatedTime           = DateTime.UtcNow,
                Error = null,
                FullyQualifiedDnsName = clusterCreateParams.DnsName,
                State         = ClusterState.Running,
                UpdatedTime   = DateTime.UtcNow,
                DnsName       = clusterCreateParams.DnsName,
                Components    = clusterCreateParams.Components,
                ExtensionData = clusterCreateParams.ExtensionData,
                Location      = clusterCreateParams.Location,
                Version       = ClusterVersionUtils.TryGetVersionNumber(clusterCreateParams.Version),
                VirtualNetworkConfiguration = clusterCreateParams.VirtualNetworkConfiguration
            };

            List <Cluster> clusters;
            bool           subExists = _clustersAvailable.TryGetValue(subscriptionId, out clusters);

            if (subExists)
            {
                clusters.Add(testCluster);
                _clustersAvailable[subscriptionId] = clusters;
            }
            else
            {
                _clustersAvailable.Add(
                    new KeyValuePair <string, List <Cluster> >(subscriptionId, new List <Cluster> {
                    testCluster
                }));
            }

            return(this.Request.CreateResponse(HttpStatusCode.Created));
        }
コード例 #2
0
        /// <summary>
        /// Creates the wire contract request from user's cluster create parameters.
        /// </summary>
        /// <param name="cluster">The cluster.</param>
        /// <returns>An Instance of cluster create parameters.</returns>
        public static ClusterCreateParameters CreateWireClusterCreateParametersFromUserType(ClusterCreateParametersV2 cluster)
        {
            if (cluster == null)
            {
                throw new ArgumentNullException("cluster");
            }

            ClusterCreateParameters ccp = null;

            if (cluster.Version.Equals("default", StringComparison.OrdinalIgnoreCase) || new Version(ClusterVersionUtils.TryGetVersionNumber(cluster.Version)).Major >= 3)
            {
                switch (cluster.ClusterType)
                {
                case ClusterType.HBase:
                    ccp = HDInsightClusterRequestGenerator.Create3XClusterForMapReduceAndHBaseTemplate(cluster);
                    break;

                case ClusterType.Storm:
                    ccp = HDInsightClusterRequestGenerator.Create3XClusterForMapReduceAndStormTemplate(cluster);
                    break;

                case ClusterType.Hadoop:
                    ccp = HDInsightClusterRequestGenerator.Create3XClusterFromMapReduceTemplate(cluster);
                    break;

                case ClusterType.Spark:
                    ccp = HDInsightClusterRequestGenerator.Create3XClusterForMapReduceAndSparkTemplate(cluster);
                    break;

                default:
                    throw new InvalidDataException(
                              string.Format(
                                  CultureInfo.InvariantCulture,
                                  "Invalid cluster type '{0}' specified for cluster '{1}'",
                                  cluster.ClusterType,
                                  cluster.Name));
                }
            }
            else
            {
                if (cluster.ClusterType != ClusterType.Hadoop)
                {
                    throw new InvalidDataException(string.Format(CultureInfo.InvariantCulture, "Invalid cluster type '{0}' specified for cluster '{1}'", cluster.ClusterType, cluster.Name));
                }

                ccp = new Version(cluster.Version).Major > 1 ? HDInsightClusterRequestGenerator.Create2XClusterForMapReduceTemplate(cluster)
                                                             : HDInsightClusterRequestGenerator.Create1XClusterForMapReduceTemplate(cluster);
            }

            return(ccp);
        }
コード例 #3
0
        private async Task ValidateClusterVersion(ClusterCreateParametersV2 cluster)
        {
            var overrideHandlers = ServiceLocator.Instance.Locate <IHDInsightClusterOverrideManager>().GetHandlers(this.credentials, this.Context, this.IgnoreSslErrors);

            // Validates the version for cluster creation
            if (!string.IsNullOrEmpty(cluster.Version) && !string.Equals(cluster.Version, DEFAULTHDINSIGHTVERSION, StringComparison.OrdinalIgnoreCase))
            {
                this.AssertSupportedVersion(overrideHandlers.PayloadConverter.ConvertStringToVersion(ClusterVersionUtils.TryGetVersionNumber(cluster.Version)));
                var availableVersions = await overrideHandlers.VersionFinder.ListAvailableVersions();

                if (availableVersions.All(hdinsightVersion => hdinsightVersion.Version != ClusterVersionUtils.TryGetVersionNumber(cluster.Version)))
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  "Cannot create a cluster with version '{0}'. Available Versions for your subscription are: {1}",
                                  cluster.Version,
                                  string.Join(",", availableVersions)));
                }

                // Clusters with OSType.Linux only supported from version 3.2 onwards
                var version = new Version(ClusterVersionUtils.TryGetVersionNumber(cluster.Version));
                if (cluster.OSType == OSType.Linux && version.CompareTo(new Version("3.2")) < 0)
                {
                    throw new NotSupportedException(string.Format("Clusters with OSType {0} are only supported from version 3.2", cluster.OSType));
                }

                // HBase cluster only supported after version 3.0
                if (version.CompareTo(new Version("3.0")) < 0 && cluster.ClusterType == ClusterType.HBase)
                {
                    throw new InvalidOperationException(
                              string.Format("Cannot create a HBase cluster with version '{0}'. HBase cluster only supported after version 3.0", cluster.Version));
                }

                // Cluster customization only supported after version 3.0
                if (version.CompareTo(new Version("3.0")) < 0 && cluster.ConfigActions != null && cluster.ConfigActions.Count > 0)
                {
                    throw new InvalidOperationException(
                              string.Format("Cannot create a customized cluster with version '{0}'. Customized clusters only supported after version 3.0", cluster.Version));
                }

                // Various VM sizes only supported starting with version 3.1
                if (version.CompareTo(new Version("3.1")) < 0 && createHasNewVMSizesSpecified(cluster))
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  "Cannot use various VM sizes with cluster version '{0}'. Custom VM sizes are only supported for cluster versions 3.1 and above.",
                                  cluster.Version));
                }

                // Spark cluster only supported after version 3.2
                if (version.CompareTo(new Version("3.2")) < 0 && cluster.ClusterType == ClusterType.Spark)
                {
                    throw new InvalidOperationException(
                              string.Format("Cannot create a Spark cluster with version '{0}'. Spark cluster only supported after version 3.2", cluster.Version));
                }
            }
            else
            {
                cluster.Version = DEFAULTHDINSIGHTVERSION;
            }
        }