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 (this.Version == 3) { if (!string.IsNullOrEmpty(this.Name)) { var result = new PSSynapseSqlPoolV3(this.SynapseAnalyticsClient.GetSqlPoolV3(this.ResourceGroupName, this.WorkspaceName, this.Name)); WriteObject(result); } else { var result = this.SynapseAnalyticsClient.ListSqlPoolsV3(this.ResourceGroupName, this.WorkspaceName).Select(r => new PSSynapseSqlPoolV3(r)); WriteObject(result, true); } } else { if (!string.IsNullOrEmpty(this.Name)) { var result = new PSSynapseSqlPool(this.ResourceGroupName, this.WorkspaceName, 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(this.ResourceGroupName, this.WorkspaceName, r)); WriteObject(result, true); } } }
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); } } }
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); } } }