public override void ExecuteCmdlet()
        {
            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 (this.IsParameterBound(c => c.WorkspaceObject))
            {
                this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName;
                this.WorkspaceName     = this.WorkspaceObject.Name;
            }

            if (!string.IsNullOrEmpty(this.Name))
            {
                var result = new PSSynapseSqlPool(this.SynapseAnalyticsClient.GetSqlPool(this.ResourceGroupName, this.WorkspaceName, this.Name));
                WriteObject(result);
            }
            else
            {
                var result = this.SynapseAnalyticsClient.ListSqlPools(this.ResourceGroupName, this.WorkspaceName).Select(r => new PSSynapseSqlPool(r));
                WriteObject(result, true);
            }
        }
 private void RenameSqlPool()
 {
     if (this.ShouldProcess(this.Name, string.Format(Resources.UpdatingSynapseSqlPool, this.Name, this.ResourceGroupName, this.WorkspaceName)))
     {
         this.SynapseAnalyticsClient.RenameSqlPool(this.ResourceGroupName, this.WorkspaceName, this.Name, this.NewName);
         var result = new PSSynapseSqlPool(this.SynapseAnalyticsClient.GetSqlPool(this.ResourceGroupName, this.WorkspaceName, this.NewName));
         WriteObject(result);
     }
 }
示例#3
0
        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));
            }

            var createParams = new SqlPool
            {
                Location = existingWorkspace.Location
            };

            switch (this.ParameterSetName)
            {
            case RestoreFromBackupIdByNameParameterSet:
            case RestoreFromBackupIdByParentObjectParameterSet:
                createParams.CreateMode            = SynapseSqlPoolCreateMode.Recovery;
                createParams.RecoverableDatabaseId = this.ResourceId;
                break;

            case RestoreFromRestorePointIdByNameParameterSet:
            case RestoreFromRestorePointIdByParentObjectParameterSet:
                createParams.CreateMode         = SynapseSqlPoolCreateMode.PointInTimeRestore;
                createParams.SourceDatabaseId   = this.ResourceId;
                createParams.RestorePointInTime = this.RestorePoint.ToUniversalTime().ToString("o");
                createParams.Sku = new Sku
                {
                    Name = this.PerformanceLevel
                };

                break;

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

            if (this.ShouldProcess(this.Name, string.Format(Resources.RestoringSynapseSqlPool, this.ResourceId, 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);
            }
        }
        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);
            }

            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));
            }

            if (this.ShouldProcess(this.Name, string.Format(Resources.SuspendingSynapseSqlPool, this.Name, this.ResourceGroupName, this.WorkspaceName)))
            {
                this.SynapseAnalyticsClient.PauseSqlPool(this.ResourceGroupName, this.WorkspaceName, this.Name);
                var result = new PSSynapseSqlPool(this.ResourceGroupName, this.WorkspaceName, this.SynapseAnalyticsClient.GetSqlPool(this.ResourceGroupName, this.WorkspaceName, this.Name));
                WriteObject(result);
            }
        }
示例#5
0
        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));
            }

            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 RestoreFromBackupNameByNameParameterSet:
            case RestoreFromBackupNameByParentObjectParameterSet:
            case RestoreFromBackupIdByNameParameterSet:
            case RestoreFromBackupIdByParentObjectParameterSet:
            case RestoreFromBackupInputObjectByNameParameterSet:
                createParams.CreateMode            = SynapseSqlPoolCreateMode.Recovery;
                createParams.RecoverableDatabaseId = this.BackupResourceId;
                break;

            case RestoreFromRestorePointNameByNameParameterSet:
            case RestoreFromRestorePointNameByParentObjectParameterSet:
            case RestoreFromRestorePointIdByNameParameterSet:
            case RestoreFromRestorePointIdByParentObjectParameterSet:
            case RestoreFromRestorePointInputObjectByNameParameterSet:
                if (!this.IsParameterBound(c => c.RestorePoint))
                {
                    this.RestorePoint = GetNewestRestorePoint();
                }

                createParams.CreateMode         = SynapseSqlPoolCreateMode.PointInTimeRestore;
                createParams.SourceDatabaseId   = this.SourceResourceId;
                createParams.RestorePointInTime = this.RestorePoint.ToString();
                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.RestoringSynapseSqlPool, this.BackupSqlPoolName, 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);
            }
        }
        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);
                }
            }
        }