public override void ExecuteCmdlet() { if (ShouldProcess(Name, Resources.CreateNewKustoCluster)) { try { if (KustoClient.GetCluster(ResourceGroupName, Name) != 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")) { // cluster does not exists so go ahead and create one } 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 createdCluster = KustoClient.CreateOrUpdateCluster(ResourceGroupName, Name, Location, Sku, Capacity, Tag, null); WriteObject(createdCluster); } }
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); } }
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); } }