public virtual PSLinkedService CreatePSLinkedService(CreatePSLinkedServiceParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } PSLinkedService linkedService = null; Action createLinkedService = () => { linkedService = new PSLinkedService(CreateOrUpdateLinkedService(parameters.ResourceGroupName, parameters.DataFactoryName, parameters.Name, parameters.RawJsonContent)) { ResourceGroupName = parameters.ResourceGroupName, DataFactoryName = parameters.DataFactoryName }; }; if (parameters.Force) { // If user decides to overwrite anyway, then there is no need to check if the linked service exists or not. createLinkedService(); } else { bool linkedServiceExists = CheckLinkedServiceExists(parameters.ResourceGroupName, parameters.DataFactoryName, parameters.Name); parameters.ConfirmAction( !linkedServiceExists, // prompt only if the linked service exists string.Format( CultureInfo.InvariantCulture, Resources.LinkedServiceExists, parameters.Name, parameters.DataFactoryName), string.Format( CultureInfo.InvariantCulture, Resources.LinkedServiceCreating, parameters.Name, parameters.DataFactoryName), parameters.Name, createLinkedService); } if (!DataFactoryCommonUtilities.IsSucceededProvisioningState(linkedService.ProvisioningState)) { string errorMessage = linkedService.Properties == null ? string.Empty : linkedService.Properties.ErrorMessage; throw new ProvisioningFailedException(errorMessage); } return(linkedService); }
public override void ExecuteCmdlet() { PSLinkedService parameters = new PSLinkedService() { Tags = this.Tag, WriteAccessResourceId = this.WriteAccessResourceId, ResourceId = this.ResourceId }; if (ShouldProcess(this.LinkedServiceName, string.Format("Set linked service: {0} for workspace: {1}", this.LinkedServiceName, this.WorkspaceName))) { WriteObject(this.OperationalInsightsClient.SetPSLinkedService(this.ResourceGroupName, this.WorkspaceName, this.LinkedServiceName, parameters)); } }
public void CanGetLinkedService() { // Arrange PSLinkedService expected = new PSLinkedService() { LinkedServiceName = linkedServiceName, DataFactoryName = DataFactoryName, ResourceGroupName = ResourceGroupName }; dataFactoriesClientMock .Setup( c => c.FilterPSLinkedServices( It.Is <LinkedServiceFilterOptions>( options => options.ResourceGroupName == ResourceGroupName && options.DataFactoryName == DataFactoryName && options.Name == linkedServiceName))) .CallBase() .Verifiable(); dataFactoriesClientMock .Setup(c => c.GetLinkedService(ResourceGroupName, DataFactoryName, linkedServiceName)) .Returns(expected) .Verifiable(); // Action cmdlet.Name = " "; Exception whiteSpace = Assert.Throws <PSArgumentNullException>(() => cmdlet.ExecuteCmdlet()); cmdlet.Name = ""; Exception empty = Assert.Throws <PSArgumentNullException>(() => cmdlet.ExecuteCmdlet()); cmdlet.Name = linkedServiceName; cmdlet.ExecuteCmdlet(); // Assert dataFactoriesClientMock.VerifyAll(); Assert.Contains("Value cannot be null", whiteSpace.Message); Assert.Contains("Value cannot be null", empty.Message); commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once()); }
private bool CheckLinkedServiceExists(string resourceGroupName, string dataFactoryName, string linkedServiceName) { try { PSLinkedService linkedService = GetLinkedService(resourceGroupName, dataFactoryName, linkedServiceName); return(linkedService != null); } catch (ErrorResponseException e) { //Get throws Exception message with NotFound Status if (e.Response.StatusCode == HttpStatusCode.NotFound) { return(false); } else { throw; } } }
private bool CheckLinkedServiceExists(string resourceGroupName, string dataFactoryName, string linkedServiceName) { // ToDo: implement HEAD to check if the linked service exists try { PSLinkedService linkedService = GetLinkedService(resourceGroupName, dataFactoryName, linkedServiceName); return(true); } catch (CloudException e) { //Get throws Exception message with NotFound Status if (e.Response.StatusCode == HttpStatusCode.NotFound) { return(false); } else { throw; } } }
public virtual PSLinkedService CreatePSLinkedService(CreatePSAdfEntityParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } PSLinkedService linkedService = null; Action createLinkedService = () => { linkedService = new PSLinkedService(CreateOrUpdateLinkedService(parameters.ResourceGroupName, parameters.DataFactoryName, parameters.Name, parameters.RawJsonContent), parameters.ResourceGroupName, parameters.DataFactoryName ); }; parameters.ConfirmAction( parameters.Force, // prompt only if the linked service exists string.Format( CultureInfo.InvariantCulture, Resources.LinkedServiceExists, parameters.Name, parameters.DataFactoryName), string.Format( CultureInfo.InvariantCulture, Resources.LinkedServiceCreating, parameters.Name, parameters.DataFactoryName), parameters.Name, createLinkedService, () => CheckLinkedServiceExists(parameters.ResourceGroupName, parameters.DataFactoryName, parameters.Name)); return(linkedService); }
public virtual PSLinkedService SetPSLinkedService(string resourceGroupName, string workspaceName, string linkedServiceName, PSLinkedService parameters) { PSLinkedService existingLinkedService; try { existingLinkedService = GetPSLinkedService(resourceGroupName, workspaceName, linkedServiceName); } catch (RestException) { throw new System.ArgumentException($"linked service {linkedServiceName} for {workspaceName} is not existed"); } parameters.Tags = parameters.Tags == null ? existingLinkedService.Tags : parameters.Tags; parameters.ResourceId = string.IsNullOrEmpty(parameters.ResourceId) ? existingLinkedService.ResourceId : parameters.ResourceId; parameters.WriteAccessResourceId = string.IsNullOrEmpty(parameters.WriteAccessResourceId) ? existingLinkedService.WriteAccessResourceId : parameters.WriteAccessResourceId; return(new PSLinkedService(this.OperationalInsightsManagementClient.LinkedServices.CreateOrUpdate(resourceGroupName, workspaceName, linkedServiceName, parameters.getLinkedService()))); }
public virtual PSLinkedService SetPSLinkedService(string resourceGroupName, string workspaceName, string linkedServiceName, PSLinkedService parameters) { PSLinkedService existingLinkedService; try { existingLinkedService = GetPSLinkedService(resourceGroupName, workspaceName, linkedServiceName); } catch (RestException) { //linkedService was not found - do nothing existingLinkedService = null; } parameters.Tags = parameters.Tags == null ? existingLinkedService?.Tags : parameters.Tags; parameters.ResourceId = string.IsNullOrEmpty(parameters.ResourceId) ? existingLinkedService?.ResourceId : parameters.ResourceId; parameters.WriteAccessResourceId = string.IsNullOrEmpty(parameters.WriteAccessResourceId) ? existingLinkedService?.WriteAccessResourceId : parameters.WriteAccessResourceId; return(new PSLinkedService(this.OperationalInsightsManagementClient.LinkedServices.CreateOrUpdate(resourceGroupName, workspaceName, linkedServiceName, parameters.getLinkedService()))); }