示例#1
0
        public override void ExecuteCmdlet()
        {
            string resourceGroupName = ResourceGroupName;
            string clusterName       = ClusterName;
            string databaseName      = Name;

            if (!string.IsNullOrEmpty(ResourceId))
            {
                KustoUtils.GetResourceGroupNameAndClusterNameFromClusterId(ResourceId, out resourceGroupName, out clusterName);
            }

            if (InputObject != null)
            {
                KustoUtils.GetResourceGroupNameAndClusterNameFromClusterId(InputObject.Id, out resourceGroupName, out clusterName);
            }

            if (!string.IsNullOrEmpty(databaseName))
            {
                // Get for single cluster
                var capacity = KustoClient.GetDatabase(resourceGroupName, clusterName, databaseName);
                WriteObject(capacity);
            }
            else
            {
                // List all capacities in given resource group if available otherwise all capacities in the subscription
                var list = KustoClient.ListDatabases(resourceGroupName, clusterName).ToArray();
                WriteObject(list, true);
            }
        }
        public override void ExecuteCmdlet()
        {
            string clusterName       = Name;
            string resourceGroupName = ResourceGroupName;

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

            EnsureClusterAndResourceGroupSpecified(resourceGroupName, clusterName);

            if (ShouldProcess(clusterName, Resources.SuspendingKustoCluster))
            {
                PSKustoCluster cluster = null;
                if (!KustoClient.CheckIfClusterExists(resourceGroupName, clusterName, out cluster))
                {
                    throw new InvalidOperationException(string.Format(Resources.ClusterDoesNotExist, clusterName));
                }

                KustoClient.SuspendKustoCluster(resourceGroupName, clusterName);

                if (PassThru.IsPresent)
                {
                    WriteObject(true);
                }
            }
        }
        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);
                }
            }
        }
        public override void ExecuteCmdlet()
        {
            string resourceGroupName = ResourceGroupName;
            string clusterName       = ClusterName;
            string databaseName      = Name;
            string location          = null;

            if (ShouldProcess(Name, Resources.CreateNewKustoCluster))
            {
                try
                {
                    if (!string.IsNullOrEmpty(ResourceId))
                    {
                        KustoUtils.GetResourceGroupNameAndClusterNameFromClusterId(ResourceId, out resourceGroupName, out clusterName);
                    }

                    if (InputObject != null)
                    {
                        KustoUtils.GetResourceGroupNameAndClusterNameFromClusterId(InputObject.Id, out resourceGroupName, out clusterName);
                    }

                    var cluser = KustoClient.GetCluster(resourceGroupName, clusterName);
                    if (cluser == null)
                    {
                        throw new CloudException(string.Format(Resources.KustoClusterNotExist, clusterName));
                    }

                    location = cluser.Location;

                    var database = KustoClient.GetDatabase(resourceGroupName, clusterName, databaseName);
                    if (database != null)
                    {
                        throw new CloudException(string.Format(Resources.KustoClusterExists, Name));
                    }
                }
                catch (CloudException ex)
                {
                    if (ex.Body != null && !string.IsNullOrEmpty(ex.Body.Code) && ex.Body.Code == "ResourceNotFound" ||
                        ex.Message.Contains("ResourceNotFound"))
                    {
                        // there are 2 options:
                        // -database does not exists so go ahead and create one
                        // -cluster does not exist, so continue and let the command fail
                    }
                    else if (ex.Body != null && !string.IsNullOrEmpty(ex.Body.Code) &&
                             ex.Body.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound"))
                    {
                        // resource group not found, let create throw error don't throw from here
                    }
                    else
                    {
                        // all other exceptions should be thrown
                        throw;
                    }
                }

                var createdDatabase = KustoClient.CreateOrUpdateDatabase(resourceGroupName, clusterName, databaseName, HotCachePeriodInDays, SoftDeletePeriodInDays, location);
                WriteObject(createdDatabase);
            }
        }
        public override void ExecuteCmdlet()
        {
            string resourceGroupName = ResourceGroupName;
            string clusterName       = Name;

            if (!string.IsNullOrEmpty(ResourceId))
            {
                KustoUtils.GetResourceGroupNameAndClusterNameFromClusterId(ResourceId, out resourceGroupName, out clusterName);
            }

            if (string.IsNullOrEmpty(resourceGroupName))
            {
                throw new CloudException(Resources.ResourceGroupNotSpecified);
            }

            if (!string.IsNullOrEmpty(clusterName))
            {
                // Get for single cluster
                var capacity = KustoClient.GetCluster(resourceGroupName, clusterName);
                WriteObject(capacity);
            }
            else
            {
                // List all capacities in given resource group if available otherwise all capacities in the subscription
                var list = KustoClient.ListClusters(resourceGroupName).ToArray();
                WriteObject(list, true);
            }
        }
示例#6
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);
            }
        }
        public override void ExecuteCmdlet()
        {
            string clusterName       = Name;
            int?   capacity          = null;
            string resourceGroupName = ResourceGroupName;
            string location          = null;
            string skuName           = null;

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

            if (ShouldProcess(clusterName, Resources.UpdatingKustoCluster))
            {
                try
                {
                    var cluster = KustoClient.GetCluster(resourceGroupName, clusterName);
                    if (cluster == null)
                    {
                        throw new CloudException(string.Format(Resources.KustoClusterNotExist, Name));
                    }

                    location = cluster.Location;
                    skuName  = string.IsNullOrEmpty(SkuName) ? cluster.Sku : SkuName;
                    capacity = Capacity ?? cluster.Capacity;
                }
                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.KustoClusterNotExist, Name));
                    }
                    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 updatedCluster = KustoClient.CreateOrUpdateCluster(resourceGroupName, clusterName, location, skuName, capacity);
                WriteObject(updatedCluster);
            }
        }