public override void ExecuteCmdlet()
        {
            string databaseName      = Name;
            string clusterName       = ClusterName;
            string resourceGroupName = ResourceGroupName;

            if (!string.IsNullOrEmpty(ResourceId))
            {
                KustoUtils.GetResourceGroupNameClusterNameAndDatabaseNameFromDatabaseId(ResourceId, out resourceGroupName, out clusterName, out databaseName);
            }
            else if (InputObject != null)
            {
                KustoUtils.GetResourceGroupNameClusterNameAndDatabaseNameFromDatabaseId(InputObject.Id, out resourceGroupName, out clusterName, out databaseName);
            }

            if (ShouldProcess(databaseName, Resources.RemovingKustoDatabase))
            {
                PSKustoDatabase database = null;
                if (!KustoClient.CheckIfDatabaseExists(resourceGroupName, clusterName, databaseName, out database))
                {
                    throw new InvalidOperationException(string.Format(Resources.KustoDatabaseNotExist, databaseName));
                }

                KustoClient.DeleteDatabase(resourceGroupName, clusterName, databaseName);

                if (PassThru.IsPresent)
                {
                    WriteObject(true);
                }
            }
        }
Beispiel #2
0
        public override void ExecuteCmdlet()
        {
            string databaseName              = Name;
            string clusterName               = ClusterName;
            string resourceGroupName         = ResourceGroupName;
            string location                  = null;
            int    hotCachePeriodInDays      = 0;
            int    softRetentionPeriodInDays = 0;

            if (!string.IsNullOrEmpty(ResourceId))
            {
                KustoUtils.GetResourceGroupNameClusterNameAndDatabaseNameFromDatabaseId(ResourceId, out resourceGroupName, out clusterName, out databaseName);
            }
            else if (InputObject != null)
            {
                KustoUtils.GetResourceGroupNameClusterNameAndDatabaseNameFromDatabaseId(InputObject.Id, out resourceGroupName, out clusterName, out databaseName);
            }

            EnsureDatabaseClusterResourceGroupSpecified(resourceGroupName, clusterName, databaseName);

            if (ShouldProcess(databaseName, Resources.UpdatingKustoDatabase))
            {
                try
                {
                    var database = KustoClient.GetDatabase(resourceGroupName, clusterName, databaseName);
                    if (database == null)
                    {
                        throw new CloudException(string.Format(Resources.KustoDatabaseNotExist, databaseName));
                    }

                    location                  = database.Location;
                    hotCachePeriodInDays      = HotCachePeriodInDays ?? database.HotCachePeriodInDays.GetValueOrDefault();
                    softRetentionPeriodInDays = SoftDeletePeriodInDays ?? database.SoftDeletePeriodInDays;
                }
                catch (CloudException ex)
                {
                    if (ex.Body != null && !string.IsNullOrEmpty(ex.Body.Code) && ex.Body.Code == "ResourceNotFound" ||
                        ex.Message.Contains("ResourceNotFound"))
                    {
                        throw new CloudException(string.Format(Resources.KustoDatabaseNotExist, databaseName));
                    }
                    else if (ex.Body != null && !string.IsNullOrEmpty(ex.Body.Code) &&
                             ex.Body.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound"))
                    {
                        throw new CloudException(string.Format(Resources.ResourceGroupNotExist, resourceGroupName));
                    }
                    else
                    {
                        // all other exceptions should be thrown
                        throw;
                    }
                }

                var updatedDatabase = KustoClient.CreateOrUpdateDatabase(resourceGroupName, clusterName, databaseName, hotCachePeriodInDays, softRetentionPeriodInDays, location);
                WriteObject(updatedDatabase);
            }
        }