Ejemplo n.º 1
0
 public PSSparkConfigProperties(SparkConfigProperties sparkConfigProperties)
 {
     this.Time              = sparkConfigProperties?.Time;
     this.Content           = sparkConfigProperties?.Content;
     this.Filename          = sparkConfigProperties?.Filename;
     this.ConfigurationType = sparkConfigProperties?.ConfigurationType;
 }
        public override void ExecuteCmdlet()
        {
            switch (ParameterSetName)
            {
            case CreateByNameAndEnableAutoScaleParameterSet:
            case CreateByParentObjectAndEnableAutoScaleParameterSet:
                this.enableAutoScale = true;
                break;
            }

            if (this.IsParameterBound(c => c.WorkspaceObject))
            {
                this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName;
                this.WorkspaceName     = this.WorkspaceObject.Name;
            }

            if (string.IsNullOrEmpty(this.ResourceGroupName))
            {
                this.ResourceGroupName = this.SynapseAnalyticsClient.GetResourceGroupByWorkspaceName(this.WorkspaceName);
            }

            BigDataPoolResourceInfo existingSparkPool = null;

            try
            {
                existingSparkPool = this.SynapseAnalyticsClient.GetSparkPool(this.ResourceGroupName, this.WorkspaceName, this.Name);
            }
            catch
            {
                existingSparkPool = null;
            }

            if (existingSparkPool != null)
            {
                throw new AzPSInvalidOperationException(string.Format(Resources.SynapseSparkPoolExists, this.Name, this.ResourceGroupName, this.WorkspaceName));
            }

            Workspace existingWorkspace = null;

            try
            {
                existingWorkspace = this.SynapseAnalyticsClient.GetWorkspace(this.ResourceGroupName, this.WorkspaceName);
            }
            catch
            {
                existingWorkspace = null;
            }

            if (existingWorkspace == null)
            {
                throw new AzPSResourceNotFoundCloudException(string.Format(Resources.WorkspaceDoesNotExist, this.WorkspaceName));
            }

            SparkConfigProperties sparkConfigProperties = null;

            if (this.IsParameterBound(c => c.SparkConfigFilePath))
            {
                string path     = this.TryResolvePath(SparkConfigFilePath);
                string filename = Path.GetFileNameWithoutExtension(path);
                sparkConfigProperties = new SparkConfigProperties()
                {
                    Content  = this.ReadFileAsText(this.SparkConfigFilePath),
                    Filename = filename
                };
            }

            var createParams = new BigDataPoolResourceInfo
            {
                Location       = existingWorkspace.Location,
                Tags           = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true),
                NodeCount      = this.enableAutoScale ? (int?)null : this.NodeCount,
                NodeSizeFamily = NodeSizeFamily.MemoryOptimized,
                NodeSize       = NodeSize,
                AutoScale      = !this.enableAutoScale ? new AutoScaleProperties {
                    Enabled = false
                } : new AutoScaleProperties
                {
                    Enabled      = this.enableAutoScale,
                    MinNodeCount = AutoScaleMinNodeCount,
                    MaxNodeCount = AutoScaleMaxNodeCount
                },
                AutoPause = !EnableAutoPause ? new AutoPauseProperties {
                    Enabled = false
                } : new AutoPauseProperties
                {
                    Enabled        = EnableAutoPause.IsPresent,
                    DelayInMinutes = AutoPauseDelayInMinute
                },
                SparkVersion          = this.SparkVersion,
                SparkConfigProperties = sparkConfigProperties
            };

            if (this.ShouldProcess(this.Name, string.Format(Resources.CreatingSynapseSparkPool, this.ResourceGroupName, this.WorkspaceName, this.Name)))
            {
                var result = new PSSynapseSparkPool(this.SynapseAnalyticsClient.CreateOrUpdateSparkPool(this.ResourceGroupName, this.WorkspaceName, this.Name, createParams));
                WriteObject(result);
            }
        }