Exemplo n.º 1
0
 public PSSynapseSqlPoolV3(SqlPoolV3 sqlPool)
     : base(sqlPool?.Location, sqlPool?.Id, sqlPool?.Name, sqlPool?.Type, sqlPool?.Tags)
 {
     this.Sku  = sqlPool?.Sku != null ? new PSSynapseSku(sqlPool.Sku) : null;
     this.Kind = sqlPool?.Kind;
     this.CurrentServiceObjectiveName   = sqlPool?.CurrentServiceObjectiveName;
     this.RequestedServiceObjectiveName = sqlPool?.RequestedServiceObjectiveName;
     this.SqlPoolGuid = sqlPool?.SqlPoolGuid;
     this.SystemData  = sqlPool?.SystemData != null ? new PSSystemData(sqlPool.SystemData) : null;
     this.Status      = sqlPool?.Status;
 }
        private void UpdateSqlPoolV3(SqlPoolV3 existingSqlPool)
        {
            SqlPoolUpdate sqlPoolPatchInfo = new SqlPoolUpdate
            {
                Tags = this.IsParameterBound(c => c.Tag) ? TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true) : existingSqlPool.Tags,
                Sku  = !this.IsParameterBound(c => c.PerformanceLevel) ? existingSqlPool.Sku : new Sku
                {
                    Name = this.PerformanceLevel
                }
            };

            if (this.ShouldProcess(this.Name, string.Format(Resources.UpdatingSynapseSqlPool, this.Name, this.ResourceGroupName, this.WorkspaceName)))
            {
                this.SynapseAnalyticsClient.UpdateSqlPoolV3(this.ResourceGroupName, this.WorkspaceName, this.Name, sqlPoolPatchInfo);
                if (this.PassThru.IsPresent)
                {
                    var result = this.SynapseAnalyticsClient.GetSqlPoolV3(this.ResourceGroupName, this.WorkspaceName, this.Name);
                    WriteObject(result);
                }
            }
        }
        public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => c.WorkspaceObject))
            {
                this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName;
                this.WorkspaceName     = this.WorkspaceObject.Name;
            }

            if (this.IsParameterBound(c => c.InputObject))
            {
                var resourceIdentifier = new ResourceIdentifier(this.InputObject.Id);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.WorkspaceName     = resourceIdentifier.ParentResource;
                this.WorkspaceName     = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1);
                this.Name = resourceIdentifier.ResourceName;
            }

            if (this.IsParameterBound(c => c.ResourceId))
            {
                var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.WorkspaceName     = resourceIdentifier.ParentResource;
                this.WorkspaceName     = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1);
                this.Name = resourceIdentifier.ResourceName;
            }

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

            if (this.Version == 3)
            {
                SqlPoolV3 existingSqlPool = null;
                try
                {
                    existingSqlPool = this.SynapseAnalyticsClient.GetSqlPoolV3(this.ResourceGroupName, this.WorkspaceName, this.Name);
                }
                catch
                {
                    existingSqlPool = null;
                }

                if (existingSqlPool == null)
                {
                    throw new SynapseException(string.Format(Resources.FailedToDiscoverSqlPool, this.Name, this.ResourceGroupName, this.WorkspaceName));
                }

                switch (this.ParameterSetName)
                {
                case UpdateByNameParameterSet:
                case UpdateByInputObjectParameterSet:
                case UpdateByParentObjectParameterSet:
                case UpdateByResourceIdParameterSet:
                    UpdateSqlPoolV3(existingSqlPool);
                    break;

                default: throw new SynapseException(string.Format(Resources.InvalidParameterSet, this.ParameterSetName));
                }
            }
            else
            {
                SqlPool existingSqlPool = null;
                try
                {
                    existingSqlPool = this.SynapseAnalyticsClient.GetSqlPool(this.ResourceGroupName, this.WorkspaceName, this.Name);
                }
                catch
                {
                    existingSqlPool = null;
                }

                if (existingSqlPool == null)
                {
                    throw new SynapseException(string.Format(Resources.FailedToDiscoverSqlPool, this.Name, this.ResourceGroupName, this.WorkspaceName));
                }

                switch (this.ParameterSetName)
                {
                case UpdateByNameParameterSet:
                case UpdateByInputObjectParameterSet:
                case UpdateByParentObjectParameterSet:
                case UpdateByResourceIdParameterSet:
                    UpdateSqlPool(existingSqlPool);
                    break;

                case RenameByNameParameterSet:
                case RenameByInputObjectParameterSet:
                case RenameByParentObjectParameterSet:
                case RenameByResourceIdParameterSet:
                    RenameSqlPool();
                    break;

                default: throw new SynapseException(string.Format(Resources.InvalidParameterSet, this.ParameterSetName));
                }
            }
        }
        public override void ExecuteCmdlet()
        {
            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);
            }

            var existingWorkspace = this.SynapseAnalyticsClient.GetWorkspaceOrDefault(this.ResourceGroupName, this.WorkspaceName);

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

            if (this.Version == 3)
            {
                var existingSqlPool = this.SynapseAnalyticsClient.GetSqlPoolV3OrDefault(this.ResourceGroupName, this.WorkspaceName, this.Name);
                if (existingSqlPool != null)
                {
                    throw new AzPSInvalidOperationException(string.Format(Resources.SynapseSqlPoolExists, this.Name, this.ResourceGroupName, this.WorkspaceName));
                }

                var createParams = new SqlPoolV3
                {
                    Location = existingWorkspace.Location,
                    Tags     = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true)
                };

                switch (this.ParameterSetName)
                {
                case CreateByNameParameterSet:
                case CreateByParentObjectParameterSet:
                    createParams.Sku = new SkuV3
                    {
                        Name = this.PerformanceLevel
                    };
                    break;

                default: throw new AzPSInvalidOperationException(string.Format(Resources.InvalidParameterSet, this.ParameterSetName));
                }

                if (this.ShouldProcess(this.Name, string.Format(Resources.CreatingSynapseSqlPool, this.ResourceGroupName, this.WorkspaceName, this.Name)))
                {
                    var result = new PSSynapseSqlPoolV3(this.SynapseAnalyticsClient.CreateSqlPoolV3(this.ResourceGroupName, this.WorkspaceName, this.Name, createParams));
                    WriteObject(result);
                }
            }
            else
            {
                var existingSqlPool = this.SynapseAnalyticsClient.GetSqlPoolOrDefault(this.ResourceGroupName, this.WorkspaceName, this.Name);
                if (existingSqlPool != null)
                {
                    throw new AzPSInvalidOperationException(string.Format(Resources.SynapseSqlPoolExists, this.Name, this.ResourceGroupName, this.WorkspaceName));
                }

                var createParams = new SqlPool
                {
                    Location = existingWorkspace.Location,
                    Tags     = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true)
                };

                createParams.CreateMode = SynapseSqlPoolCreateMode.Default;
                createParams.Collation  = this.IsParameterBound(c => c.Collation) ? this.Collation : SynapseConstants.DefaultCollation;
                createParams.Sku        = new Sku
                {
                    Name = this.PerformanceLevel
                };

                if (this.ShouldProcess(this.Name, string.Format(Resources.CreatingSynapseSqlPool, this.ResourceGroupName, this.WorkspaceName, this.Name)))
                {
                    var result = new PSSynapseSqlPool(this.ResourceGroupName, this.WorkspaceName, this.SynapseAnalyticsClient.CreateSqlPool(this.ResourceGroupName, this.WorkspaceName, this.Name, createParams));
                    WriteObject(result);
                }
            }
        }
 /// <summary>
 /// Creates a new SqlPool or updates an existing SqlPool.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group. The name is case insensitive.
 /// </param>
 /// <param name='workspaceName'>
 /// The name of the workspace.
 /// </param>
 /// <param name='sqlPoolName'>
 /// The name of the sql pool.
 /// </param>
 /// <param name='parameters'>
 /// The requested SqlPool resource state.
 /// </param>
 public static SqlPoolV3 CreateOrUpdate(this ISqlPoolsV3Operations operations, string resourceGroupName, string workspaceName, string sqlPoolName, SqlPoolV3 parameters)
 {
     return(operations.CreateOrUpdateAsync(resourceGroupName, workspaceName, sqlPoolName, parameters).GetAwaiter().GetResult());
 }
 /// <summary>
 /// Creates a new SqlPool or updates an existing SqlPool.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group. The name is case insensitive.
 /// </param>
 /// <param name='workspaceName'>
 /// The name of the workspace.
 /// </param>
 /// <param name='sqlPoolName'>
 /// The name of the sql pool.
 /// </param>
 /// <param name='parameters'>
 /// The requested SqlPool resource state.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <SqlPoolV3> BeginCreateOrUpdateAsync(this ISqlPoolsV3Operations operations, string resourceGroupName, string workspaceName, string sqlPoolName, SqlPoolV3 parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, workspaceName, sqlPoolName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
        public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => c.WorkspaceObject))
            {
                this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName;
                this.WorkspaceName     = this.WorkspaceObject.Name;
            }

            if (this.IsParameterBound(c => c.BackupResourceId))
            {
                var resourceIdentifier = new ResourceIdentifier(this.BackupResourceId);
                this.BackupWorkspaceName = resourceIdentifier.ParentResource;
                this.BackupWorkspaceName = this.BackupWorkspaceName.Substring(this.BackupWorkspaceName.LastIndexOf('/') + 1);
                this.BackupSqlPoolName   = resourceIdentifier.ResourceName;
            }

            if (this.IsParameterBound(c => c.BackupSqlPoolObject))
            {
                var resourceIdentifier = new ResourceIdentifier(this.BackupSqlPoolObject.Id);
                this.BackupResourceId    = this.BackupSqlPoolObject.Id;
                this.BackupWorkspaceName = resourceIdentifier.ParentResource;
                this.BackupWorkspaceName = this.BackupWorkspaceName.Substring(this.BackupWorkspaceName.LastIndexOf('/') + 1);
                this.BackupSqlPoolName   = resourceIdentifier.ResourceName;
                this.PerformanceLevel    = this.IsParameterBound(c => c.PerformanceLevel) ? this.PerformanceLevel : this.BackupSqlPoolObject.Sku?.Name;
            }

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

            if (FromBackup.IsPresent || FromRestorePoint.IsPresent)
            {
                // Construct resource id from components.
                if (string.IsNullOrEmpty(this.BackupResourceId))
                {
                    if (string.IsNullOrEmpty(this.BackupResourceGroupName))
                    {
                        this.BackupResourceGroupName = this.SynapseAnalyticsClient.GetResourceGroupByWorkspaceName(this.BackupWorkspaceName);
                    }

                    this.BackupResourceId = ConstructSqlDatabaseResourceId(
                        this.DefaultContext.Subscription.Id,
                        this.BackupResourceGroupName,
                        this.BackupWorkspaceName,
                        this.BackupSqlPoolName,
                        this.FromBackup.IsPresent);
                }
            }

            var existingWorkspace = this.SynapseAnalyticsClient.GetWorkspaceOrDefault(this.ResourceGroupName, this.WorkspaceName);

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

            if (this.Version == 3)
            {
                var existingSqlPool = this.SynapseAnalyticsClient.GetSqlPoolV3OrDefault(this.ResourceGroupName, this.WorkspaceName, this.Name);
                if (existingSqlPool != null)
                {
                    throw new SynapseException(string.Format(Resources.SynapseSqlPoolExists, this.Name, this.ResourceGroupName, this.WorkspaceName));
                }

                var createParams = new SqlPoolV3
                {
                    Location = existingWorkspace.Location,
                    Tags     = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true)
                };

                switch (this.ParameterSetName)
                {
                case CreateByNameParameterSet:
                case CreateByParentObjectParameterSet:
                    createParams.Sku = new Sku
                    {
                        Name = this.PerformanceLevel
                    };
                    break;

                default: throw new SynapseException(string.Format(Resources.InvalidParameterSet, this.ParameterSetName));
                }

                if (this.ShouldProcess(this.Name, string.Format(Resources.CreatingSynapseSqlPool, this.ResourceGroupName, this.WorkspaceName, this.Name)))
                {
                    var result = new PSSynapseSqlPoolV3(this.SynapseAnalyticsClient.CreateSqlPoolV3(this.ResourceGroupName, this.WorkspaceName, this.Name, createParams));
                    WriteObject(result);
                }
            }
            else
            {
                var existingSqlPool = this.SynapseAnalyticsClient.GetSqlPoolOrDefault(this.ResourceGroupName, this.WorkspaceName, this.Name);
                if (existingSqlPool != null)
                {
                    throw new SynapseException(string.Format(Resources.SynapseSqlPoolExists, this.Name, this.ResourceGroupName, this.WorkspaceName));
                }

                var createParams = new SqlPool
                {
                    Location = existingWorkspace.Location,
                    Tags     = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true)
                };

                switch (this.ParameterSetName)
                {
                case CreateByNameParameterSet:
                case CreateByParentObjectParameterSet:
                    createParams.CreateMode = SynapseSqlPoolCreateMode.Default;
                    createParams.Collation  = this.IsParameterBound(c => c.Collation) ? this.Collation : SynapseConstants.DefaultCollation;
                    createParams.Sku        = new Sku
                    {
                        Name = this.PerformanceLevel
                    };
                    break;

                case CreateFromBackupNameByNameParameterSet:
                case CreateFromBackupNameByParentObjectParameterSet:
                case CreateFromBackupIdByNameParameterSet:
                case CreateFromBackupIdByParentObjectParameterSet:
                case CreateFromBackupInputObjectByNameParameterSet:
                    createParams.CreateMode            = SynapseSqlPoolCreateMode.Recovery;
                    createParams.RecoverableDatabaseId = this.BackupResourceId;
                    break;

                case CreateFromRestorePointNameByNameParameterSet:
                case CreateFromRestorePointNameByParentObjectParameterSet:
                case CreateFromRestorePointIdByNameParameterSet:
                case CreateFromRestorePointIdByParentObjectParameterSet:
                case CreateFromRestorePointInputObjectByNameParameterSet:
                    if (!this.IsParameterBound(c => c.RestorePoint))
                    {
                        this.RestorePoint = GetNewestRestorePoint();
                    }

                    createParams.CreateMode         = SynapseSqlPoolCreateMode.PointInTimeRestore;
                    createParams.SourceDatabaseId   = this.SourceResourceId;
                    createParams.RestorePointInTime = this.RestorePoint;
                    createParams.Sku = new Sku
                    {
                        Name = this.PerformanceLevel
                    };

                    break;

                default: throw new SynapseException(string.Format(Resources.InvalidParameterSet, this.ParameterSetName));
                }

                if (this.ShouldProcess(this.Name, string.Format(Resources.CreatingSynapseSqlPool, this.ResourceGroupName, this.WorkspaceName, this.Name)))
                {
                    var result = new PSSynapseSqlPool(this.SynapseAnalyticsClient.CreateSqlPool(this.ResourceGroupName, this.WorkspaceName, this.Name, createParams));
                    WriteObject(result);
                }
            }
        }
 public SqlPoolV3 CreateSqlPoolV3(string resourceGroupName, string workspaceName, string sqlPoolName, SqlPoolV3 createOrUpdateParams)
 {
     try
     {
         return(_synapseSqlV3ManagementClient.SqlPoolsV3.CreateOrUpdate(resourceGroupName, workspaceName, sqlPoolName, createOrUpdateParams));
     }
     catch (ErrorContractException ex)
     {
         throw GetSynapseException(ex);
     }
 }