Пример #1
0
        public override void ExecuteCmdlet()
        {
            try
            {
                if (SynapseAnalyticsClient.GetWorkspace(ResourceGroupName, Name) != null)
                {
                    throw new SynapseException(string.Format(Resources.SynapseWorkspaceExists, this.Name, this.ResourceGroupName));
                }
            }
            catch (NotFoundException ex)
            {
                var innerException = ex.InnerException as ErrorContractException;
                if (innerException.Body?.Error?.Code == "ResourceNotFound" || innerException.Body?.Error?.Message.Contains("ResourceNotFound") == true)
                {
                    // account does not exists so go ahead and create one
                }
                else if (innerException.Body?.Error?.Code == "ResourceGroupNotFound" || innerException.Body?.Error?.Message.Contains("ResourceGroupNotFound") == true)
                {
                    // resource group not found, throw error during creation. Don't throw from here.
                }
                else
                {
                    // all other exceptions should be thrown
                    throw;
                }
            }

            var defaultDataLakeStorageAccountUrl = string.Format(
                "https://{0}.dfs.{1}",
                this.DefaultDataLakeStorageAccountName,
                this.DefaultContext.Environment.StorageEndpointSuffix);
            var createParams = new Workspace
            {
                Tags     = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true),
                Identity = new ManagedIdentity
                {
                    Type = ResourceIdentityType.SystemAssigned
                },
                DefaultDataLakeStorage = new DataLakeStorageAccountDetails
                {
                    AccountUrl = defaultDataLakeStorageAccountUrl,
                    Filesystem = this.DefaultDataLakeStorageFilesystem
                },
                SqlAdministratorLogin         = this.SqlAdministratorLoginCredential.UserName,
                SqlAdministratorLoginPassword = this.SqlAdministratorLoginCredential.GetNetworkCredential().Password,
                ManagedVirtualNetwork         = this.ManagedVirtualNetwork,
                Location = this.Location
            };

            if (ShouldProcess(Name, string.Format(Resources.CreatingSynapseWorkspace, this.ResourceGroupName, this.Name)))
            {
                var workspace = new PSSynapseWorkspace(SynapseAnalyticsClient.CreateOrUpdateWorkspace(
                                                           this.ResourceGroupName,
                                                           this.Name,
                                                           createParams));

                this.WriteObject(workspace);
            }
        }
        public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => c.InputObject))
            {
                this.ResourceGroupName = new ResourceIdentifier(this.InputObject.Id).ResourceGroupName;
                this.Name = this.InputObject.Name;
            }

            if (this.IsParameterBound(c => c.ResourceId))
            {
                var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.Name = resourceIdentifier.ResourceName;
            }

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

            Workspace existingWorkspace = null;

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

            if (existingWorkspace == null)
            {
                throw new AzPSInvalidOperationException(string.Format(Resources.FailedToDiscoverWorkspace, this.Name, this.ResourceGroupName));
            }

            WorkspacePatchInfo patchInfo = new WorkspacePatchInfo();

            patchInfo.Tags = this.IsParameterBound(c => c.Tag) ? TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true) : TagsConversionHelper.CreateTagDictionary(this.InputObject?.Tags, validate: true);
            patchInfo.SqlAdministratorLoginPassword = this.IsParameterBound(c => c.SqlAdministratorLoginPassword) ? this.SqlAdministratorLoginPassword.ConvertToString() : null;

            if (ShouldProcess(this.Name, string.Format(Resources.UpdatingSynapseWorkspace, this.Name, this.ResourceGroupName)))
            {
                var workspace = new PSSynapseWorkspace(SynapseAnalyticsClient.UpdateWorkspace(
                                                           this.ResourceGroupName,
                                                           this.Name,
                                                           patchInfo));
                this.WriteObject(workspace);
            }
        }
        public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => c.InputObject))
            {
                this.ResourceGroupName = new ResourceIdentifier(this.InputObject.Id).ResourceGroupName;
                this.Name = this.InputObject.Name;
            }

            if (this.IsParameterBound(c => c.ResourceId))
            {
                var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.Name = resourceIdentifier.ResourceName;
            }

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

            Workspace existingWorkspace = null;

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

            if (existingWorkspace == null)
            {
                throw new SynapseException(string.Format(Resources.FailedToDiscoverWorkspace, this.Name, this.ResourceGroupName));
            }

            existingWorkspace.Tags = this.IsParameterBound(c => c.Tag) ? TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true) : existingWorkspace.Tags;

            if (ShouldProcess(this.Name, string.Format(Resources.UpdatingSynapseWorkspace, this.Name, this.ResourceGroupName)))
            {
                var workspace = new PSSynapseWorkspace(SynapseAnalyticsClient.CreateOrUpdateWorkspace(
                                                           this.ResourceGroupName,
                                                           this.Name,
                                                           existingWorkspace));
                this.WriteObject(workspace);
            }
        }
Пример #4
0
        public override void ExecuteCmdlet()
        {
            try
            {
                if (SynapseAnalyticsClient.GetWorkspace(ResourceGroupName, Name) != null)
                {
                    throw new AzPSInvalidOperationException(string.Format(Resources.SynapseWorkspaceExists, this.Name, this.ResourceGroupName));
                }
            }
            catch (AzPSResourceNotFoundCloudException ex)
            {
                var innerException = ex.InnerException as ErrorResponseException;
                if (innerException.Body?.Error?.Code == "ResourceNotFound" || innerException.Body?.Error?.Message.Contains("ResourceNotFound") == true)
                {
                    // account does not exists so go ahead and create one
                }
                else if (innerException.Body?.Error?.Code == "ResourceGroupNotFound" || innerException.Body?.Error?.Message.Contains("ResourceGroupNotFound") == true)
                {
                    // resource group not found, throw error during creation. Don't throw from here.
                }
                else
                {
                    // all other exceptions should be thrown
                    throw;
                }
            }

            var defaultDataLakeStorageAccountUrl = string.Format(
                "https://{0}.dfs.{1}",
                this.DefaultDataLakeStorageAccountName,
                this.DefaultContext.Environment.StorageEndpointSuffix);
            var createParams = new Workspace
            {
                Tags     = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true),
                Identity = new ManagedIdentity
                {
                    Type = ResourceIdentityType.SystemAssigned
                },
                DefaultDataLakeStorage = new DataLakeStorageAccountDetails
                {
                    AccountUrl = defaultDataLakeStorageAccountUrl,
                    Filesystem = this.DefaultDataLakeStorageFilesystem
                },
                SqlAdministratorLogin         = this.SqlAdministratorLoginCredential.UserName,
                SqlAdministratorLoginPassword = this.SqlAdministratorLoginCredential.GetNetworkCredential().Password,
                ManagedVirtualNetwork         = this.IsParameterBound(c => c.ManagedVirtualNetwork) ? SynapseConstants.DefaultName : null,
                Location = this.Location,
                ManagedVirtualNetworkSettings = this.IsParameterBound(c => c.ManagedVirtualNetwork) ? this.ManagedVirtualNetwork?.ToSdkObject() : null,
                ManagedResourceGroupName      = this.ManagedResourceGroupName,
                Encryption = this.IsParameterBound(c => c.EncryptionKeyIdentifier) ? new EncryptionDetails
                {
                    Cmk = new CustomerManagedKeyDetails
                    {
                        Key = new WorkspaceKeyDetails
                        {
                            Name        = this.EncryptionKeyName,
                            KeyVaultUrl = this.EncryptionKeyIdentifier
                        }
                    }
                } : null,
                WorkspaceRepositoryConfiguration = this.IsParameterBound(c => c.GitRepository) ? this.GitRepository.ToSdkObject() : null
            };

            if (ShouldProcess(Name, string.Format(Resources.CreatingSynapseWorkspace, this.ResourceGroupName, this.Name)))
            {
                var workspace = new PSSynapseWorkspace(SynapseAnalyticsClient.CreateWorkspace(
                                                           this.ResourceGroupName,
                                                           this.Name,
                                                           createParams));

                this.WriteObject(workspace);
            }
        }
        public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => c.InputObject))
            {
                this.ResourceGroupName = new ResourceIdentifier(this.InputObject.Id).ResourceGroupName;
                this.Name = this.InputObject.Name;
            }

            if (this.IsParameterBound(c => c.ResourceId))
            {
                var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.Name = resourceIdentifier.ResourceName;
            }

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

            Workspace existingWorkspace = null;

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

            if (existingWorkspace == null)
            {
                throw new AzPSInvalidOperationException(string.Format(Resources.FailedToDiscoverWorkspace, this.Name, this.ResourceGroupName));
            }

            WorkspacePatchInfo patchInfo = new WorkspacePatchInfo();

            patchInfo.Tags = this.IsParameterBound(c => c.Tag) ? TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true) : TagsConversionHelper.CreateTagDictionary(this.InputObject?.Tags, validate: true);
            patchInfo.SqlAdministratorLoginPassword = this.IsParameterBound(c => c.SqlAdministratorLoginPassword) ? this.SqlAdministratorLoginPassword.ConvertToString() : null;
            patchInfo.ManagedVirtualNetworkSettings = this.IsParameterBound(c => c.ManagedVirtualNetwork) ? this.ManagedVirtualNetwork?.ToSdkObject() : this.InputObject?.ManagedVirtualNetworkSettings?.ToSdkObject();
            string encrptionKeyName = this.IsParameterBound(c => c.EncryptionKeyName) ? this.EncryptionKeyName : this.InputObject?.Encryption?.CustomerManagedKeyDetails?.Key?.Name;

            patchInfo.Encryption = !string.IsNullOrEmpty(encrptionKeyName) ? new EncryptionDetails
            {
                Cmk = new CustomerManagedKeyDetails
                {
                    Key = new WorkspaceKeyDetails
                    {
                        Name = encrptionKeyName
                    }
                }
            } : null;
            patchInfo.WorkspaceRepositoryConfiguration = this.IsParameterBound(c => c.GitRepository) ? this.GitRepository.ToSdkObject() : null;

            if (ShouldProcess(this.Name, string.Format(Resources.UpdatingSynapseWorkspace, this.Name, this.ResourceGroupName)))
            {
                var workspace = new PSSynapseWorkspace(SynapseAnalyticsClient.UpdateWorkspace(
                                                           this.ResourceGroupName,
                                                           this.Name,
                                                           patchInfo));
                this.WriteObject(workspace);
            }
        }