Exemplo n.º 1
0
        private bool CheckWorkspaceExists(string resourceGroupName, string workspaceName)
        {
            try
            {
                PSWorkspace workspace = GetWorkspace(resourceGroupName, workspaceName);
                return(true);
            }
            catch (Rest.Azure.CloudException e)
            {
                // Get throws NotFound exception if workspace does not exist
                if (e.Response.StatusCode == HttpStatusCode.NotFound)
                {
                    return(false);
                }

                throw;
            }
            catch (ErrorResponseException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.NotFound)
                {
                    return(false);
                }

                throw;
            }
        }
Exemplo n.º 2
0
        public virtual PSWorkspace CreatePSWorkspace(CreatePSWorkspaceParameters parameters)
        {
            PSWorkspace workspace       = null;
            Action      createWorkspace = () =>
            {
                Dictionary <string, string> tags = new Dictionary <string, string>();
                if (parameters.Tags != null)
                {
                    tags = ToDictionary(parameters.Tags);
                }

                workspace =
                    new PSWorkspace(
                        CreateOrUpdateWorkspace(
                            parameters.ResourceGroupName,
                            parameters.WorkspaceName,
                            parameters.Location,
                            parameters.Sku ?? new PSWorkspaceSku(),
                            tags,
                            parameters.PublicNetworkAccessForIngestion,
                            parameters.PublicNetworkAccessForQuery,
                            retentionInDays: parameters.RetentionInDays,
                            forceCmkForQuery: parameters.ForceCmkForQuery,
                            features: parameters.WsFeatures),
                        parameters.ResourceGroupName);
                if (!string.Equals(workspace.ProvisioningState, Azure.OperationStatus.Succeeded.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    throw new ProvisioningFailedException(
                              string.Format(
                                  CultureInfo.InvariantCulture,
                                  Resources.WorkspaceProvisioningFailed,
                                  parameters.WorkspaceName,
                                  parameters.ResourceGroupName));
                }
            };

            parameters.ConfirmAction(
                parameters.Force,    // prompt only if the workspace exists
                string.Format(
                    CultureInfo.InvariantCulture,
                    Resources.WorkspaceExists,
                    parameters.WorkspaceName,
                    parameters.ResourceGroupName),
                string.Format(
                    CultureInfo.InvariantCulture,
                    Resources.WorkspaceCreating,
                    parameters.WorkspaceName,
                    parameters.ResourceGroupName),
                parameters.WorkspaceName,
                createWorkspace,
                () => CheckWorkspaceExists(parameters.ResourceGroupName, parameters.WorkspaceName));

            return(workspace);
        }
        public virtual PSWorkspace UpdatePSWorkspace(UpdatePSWorkspaceParameters parameters)
        {
            // Get the existing workspace
            PSWorkspace workspace = GetWorkspace(parameters.ResourceGroupName, parameters.WorkspaceName);

            // Execute the update
            Workspace updatedWorkspace = CreateOrUpdateWorkspace(
                parameters.ResourceGroupName,
                parameters.WorkspaceName,
                workspace.Location,
                string.IsNullOrWhiteSpace(parameters.Sku) ? workspace.Sku : parameters.Sku,
                workspace.CustomerId,
                parameters.Tags == null ? workspace.Tags : ToDictionary(parameters.Tags));

            return(new PSWorkspace(updatedWorkspace, parameters.ResourceGroupName));
        }
        public virtual PSWorkspace UpdatePSWorkspace(UpdatePSWorkspaceParameters parameters)
        {
            // Get the existing workspace
            PSWorkspace workspace = GetWorkspace(parameters.ResourceGroupName, parameters.WorkspaceName);

            // Execute the update
            Workspace updatedWorkspace = CreateOrUpdateWorkspace(
                parameters.ResourceGroupName,
                parameters.WorkspaceName,
                workspace.Location,
                string.IsNullOrWhiteSpace(parameters.Sku) ? workspace.Sku : parameters.Sku,
                parameters.Tags == null ? workspace.Tags : ToDictionary(parameters.Tags),
                string.IsNullOrWhiteSpace(parameters.PublicNetworkAccessForIngestion) ? workspace.PublicNetworkAccessForIngestion : parameters.PublicNetworkAccessForIngestion,
                string.IsNullOrWhiteSpace(parameters.PublicNetworkAccessForQuery) ? workspace.PublicNetworkAccessForQuery : parameters.PublicNetworkAccessForQuery,
                parameters.RetentionInDays,
                workspace.CustomerId);

            return(new PSWorkspace(updatedWorkspace, parameters.ResourceGroupName));
        }
        public virtual PSWorkspace CreatePSWorkspace(CreatePSWorkspaceParameters parameters)
        {
            PSWorkspace workspace       = null;
            Action      createWorkspace = () =>
            {
                Dictionary <string, string> tags = new Dictionary <string, string>();
                if (parameters.Tags != null)
                {
                    tags = ToDictionary(parameters.Tags);
                }

                workspace =
                    new PSWorkspace(
                        CreateOrUpdateWorkspace(
                            parameters.ResourceGroupName,
                            parameters.WorkspaceName,
                            parameters.Location,
                            parameters.Sku,
                            parameters.CustomerId,
                            tags),
                        parameters.ResourceGroupName);
            };

            if (parameters.Force)
            {
                // If user decides to overwrite anyway, then there is no need to check if the data factory exists or not.
                createWorkspace();
            }
            else
            {
                bool workspaceExists = CheckWorkspaceExists(parameters.ResourceGroupName, parameters.WorkspaceName);

                parameters.ConfirmAction(
                    !workspaceExists,    // prompt only if the workspace exists
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.WorkspaceExists,
                        parameters.WorkspaceName,
                        parameters.ResourceGroupName),
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.WorkspaceCreating,
                        parameters.WorkspaceName,
                        parameters.ResourceGroupName),
                    parameters.WorkspaceName,
                    createWorkspace);
            }

            // If the workspace did not transition to a succeeded provisioning state then throw
            if (!string.Equals(workspace.ProvisioningState, OperationStatus.Succeeded.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                throw new ProvisioningFailedException(
                          string.Format(
                              CultureInfo.InvariantCulture,
                              Resources.WorkspaceProvisioningFailed,
                              parameters.WorkspaceName,
                              parameters.ResourceGroupName));
            }

            return(workspace);
        }
 protected void WriteWorkspace(Workspace workspace)
 {
     this.WriteObject(PSWorkspace.Create(workspace));
 }