public virtual Response <DatabaseAccountSqlDatabaseContainerThroughputSetting> AddTag(string key, string value, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException($"{nameof(key)} provided cannot be null or a whitespace.", nameof(key)); } using var scope = _clientDiagnostics.CreateScope("DatabaseAccountSqlDatabaseContainerThroughputSetting.AddTag"); scope.Start(); try { var originalTags = TagResource.Get(cancellationToken); originalTags.Value.Data.Properties.TagsValue[key] = value; TagResource.CreateOrUpdate(originalTags.Value.Data, cancellationToken: cancellationToken); var originalResponse = _sqlResourcesRestClient.GetSqlContainerThroughput(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Parent.Parent.Name, Id.Parent.Parent.Name, Id.Parent.Name, cancellationToken); return(Response.FromValue(new DatabaseAccountSqlDatabaseContainerThroughputSetting(this, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual Response <SshPublicKey> AddTag(string key, string value, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException($"{nameof(key)} provided cannot be null or a whitespace.", nameof(key)); } using var scope = _clientDiagnostics.CreateScope("SshPublicKey.AddTag"); scope.Start(); try { var originalTags = TagResource.Get(cancellationToken); originalTags.Value.Data.Properties.TagsValue[key] = value; TagResource.CreateOrUpdate(originalTags.Value.Data, cancellationToken: cancellationToken); var originalResponse = _restClient.Get(Id.ResourceGroupName, Id.Name, cancellationToken); return(Response.FromValue(new SshPublicKey(this, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual Response <AvailabilitySet> RemoveTag(string key, CancellationToken cancellationToken = default) { if (key == null) { throw new ArgumentNullException(nameof(key)); } using var scope = _availabilitySetClientDiagnostics.CreateScope("AvailabilitySet.RemoveTag"); scope.Start(); try { var originalTags = TagResource.Get(cancellationToken); originalTags.Value.Data.Properties.TagsValue.Remove(key); TagResource.CreateOrUpdate(true, originalTags.Value.Data, cancellationToken: cancellationToken); var originalResponse = _availabilitySetRestClient.Get(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, cancellationToken); return(Response.FromValue(new AvailabilitySet(Client, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public async virtual Task <Response <DatabaseAccountGremlinDatabaseThroughputSetting> > RemoveTagAsync(string key, CancellationToken cancellationToken = default) { Argument.AssertNotNull(key, nameof(key)); using var scope = _databaseAccountGremlinDatabaseThroughputSettingGremlinResourcesClientDiagnostics.CreateScope("DatabaseAccountGremlinDatabaseThroughputSetting.RemoveTag"); scope.Start(); try { var originalTags = await TagResource.GetAsync(cancellationToken).ConfigureAwait(false); originalTags.Value.Data.TagValues.Remove(key); await TagResource.CreateOrUpdateAsync(true, originalTags.Value.Data, cancellationToken : cancellationToken).ConfigureAwait(false); var originalResponse = await _databaseAccountGremlinDatabaseThroughputSettingGremlinResourcesRestClient.GetGremlinDatabaseThroughputAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Parent.Name, Id.Parent.Name, cancellationToken).ConfigureAwait(false); return(Response.FromValue(new DatabaseAccountGremlinDatabaseThroughputSetting(Client, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual Response <VirtualMachineScaleSetRollingUpgrade> AddTag(string key, string value, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key), $"{nameof(key)} provided cannot be null or a whitespace."); } using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetRollingUpgrade.AddTag"); scope.Start(); try { var originalTags = TagResource.Get(cancellationToken); originalTags.Value.Data.Properties.TagsValue[key] = value; TagResource.CreateOrUpdate(true, originalTags.Value.Data, cancellationToken: cancellationToken); var originalResponse = _virtualMachineScaleSetRollingUpgradesRestClient.GetLatest(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, cancellationToken); return(Response.FromValue(new VirtualMachineScaleSetRollingUpgrade(this, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public async virtual Task <Response <CassandraTable> > AddTagAsync(string key, string value, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrWhiteSpace(key, nameof(key)); using var scope = _cassandraTableCassandraResourcesClientDiagnostics.CreateScope("CassandraTable.AddTag"); scope.Start(); try { var originalTags = await TagResource.GetAsync(cancellationToken).ConfigureAwait(false); originalTags.Value.Data.Properties.TagsValue[key] = value; await TagResource.CreateOrUpdateAsync(true, originalTags.Value.Data, cancellationToken : cancellationToken).ConfigureAwait(false); var originalResponse = await _cassandraTableCassandraResourcesRestClient.GetCassandraTableAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Parent.Name, Id.Parent.Name, Id.Name, cancellationToken).ConfigureAwait(false); return(Response.FromValue(new CassandraTable(ArmClient, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public async virtual Task <Response <VirtualMachineRunCommand> > RemoveTagAsync(string key, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrWhiteSpace(key, nameof(key)); using var scope = _virtualMachineRunCommandClientDiagnostics.CreateScope("VirtualMachineRunCommand.RemoveTag"); scope.Start(); try { var originalTags = await TagResource.GetAsync(cancellationToken).ConfigureAwait(false); originalTags.Value.Data.Properties.TagsValue.Remove(key); await TagResource.CreateOrUpdateAsync(true, originalTags.Value.Data, cancellationToken : cancellationToken).ConfigureAwait(false); var originalResponse = await _virtualMachineRunCommandRestClient.GetByVirtualMachineAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, null, cancellationToken).ConfigureAwait(false); return(Response.FromValue(new VirtualMachineRunCommand(ArmClient, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public async virtual Task <Response <CapacityReservationGroup> > RemoveTagAsync(string key, CancellationToken cancellationToken = default) { Argument.AssertNotNull(key, nameof(key)); using var scope = _capacityReservationGroupClientDiagnostics.CreateScope("CapacityReservationGroup.RemoveTag"); scope.Start(); try { var originalTags = await TagResource.GetAsync(cancellationToken).ConfigureAwait(false); originalTags.Value.Data.TagValues.Remove(key); await TagResource.CreateOrUpdateAsync(true, originalTags.Value.Data, cancellationToken : cancellationToken).ConfigureAwait(false); var originalResponse = await _capacityReservationGroupRestClient.GetAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, null, cancellationToken).ConfigureAwait(false); return(Response.FromValue(new CapacityReservationGroup(Client, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public async virtual Task <Response <SqlTrigger> > RemoveTagAsync(string key, CancellationToken cancellationToken = default) { Argument.AssertNotNull(key, nameof(key)); using var scope = _sqlTriggerSqlResourcesClientDiagnostics.CreateScope("SqlTrigger.RemoveTag"); scope.Start(); try { var originalTags = await TagResource.GetAsync(cancellationToken).ConfigureAwait(false); originalTags.Value.Data.Properties.TagsValue.Remove(key); await TagResource.CreateOrUpdateAsync(true, originalTags.Value.Data, cancellationToken : cancellationToken).ConfigureAwait(false); var originalResponse = await _sqlTriggerSqlResourcesRestClient.GetSqlTriggerAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Parent.Parent.Name, Id.Parent.Parent.Name, Id.Parent.Name, Id.Name, cancellationToken).ConfigureAwait(false); return(Response.FromValue(new SqlTrigger(Client, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public async virtual Task<Response<ServiceBusNamespace>> RemoveTagAsync(string key, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException($"{nameof(key)} provided cannot be null or a whitespace.", nameof(key)); } using var scope = _clientDiagnostics.CreateScope("ServiceBusNamespace.RemoveTag"); scope.Start(); try { var originalTags = await TagResource.GetAsync(cancellationToken).ConfigureAwait(false); originalTags.Value.Data.Properties.TagsValue.Remove(key); await TagResource.CreateOrUpdateAsync(originalTags.Value.Data, cancellationToken: cancellationToken).ConfigureAwait(false); var originalResponse = await _namespacesRestClient.GetAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, cancellationToken).ConfigureAwait(false); return Response.FromValue(new ServiceBusNamespace(this, originalResponse.Value), originalResponse.GetRawResponse()); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual Response <DedicatedHost> RemoveTag(string key, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException($"{nameof(key)} provided cannot be null or a whitespace.", nameof(key)); } using var scope = _clientDiagnostics.CreateScope("DedicatedHost.RemoveTag"); scope.Start(); try { var originalTags = TagResource.Get(cancellationToken); originalTags.Value.Data.Properties.TagsValue.Remove(key); TagResource.CreateOrUpdate(originalTags.Value.Data, cancellationToken: cancellationToken); var originalResponse = _dedicatedHostsRestClient.Get(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, null, cancellationToken); return(Response.FromValue(new DedicatedHost(this, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual async Task <Response <VaultKeyVersion> > RemoveTagAsync(string key, CancellationToken cancellationToken = default) { Argument.AssertNotNull(key, nameof(key)); using var scope = _vaultKeyVersionKeysClientDiagnostics.CreateScope("VaultKeyVersion.RemoveTag"); scope.Start(); try { var originalTags = await TagResource.GetAsync(cancellationToken).ConfigureAwait(false); originalTags.Value.Data.TagValues.Remove(key); await TagResource.CreateOrUpdateAsync(WaitUntil.Completed, originalTags.Value.Data, cancellationToken : cancellationToken).ConfigureAwait(false); var originalResponse = await _vaultKeyVersionKeysRestClient.GetVersionAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Parent.Name, Id.Parent.Name, Id.Name, cancellationToken).ConfigureAwait(false); return(Response.FromValue(new VaultKeyVersion(Client, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual Response <VirtualMachineExtensionImage> SetTags(IDictionary <string, string> tags, CancellationToken cancellationToken = default) { if (tags == null) { throw new ArgumentNullException($"{nameof(tags)} provided cannot be null.", nameof(tags)); } using var scope = _clientDiagnostics.CreateScope("VirtualMachineExtensionImage.SetTags"); scope.Start(); try { TagResource.Delete(cancellationToken: cancellationToken); var originalTags = TagResource.Get(cancellationToken); originalTags.Value.Data.Properties.TagsValue.ReplaceWith(tags); TagResource.CreateOrUpdate(originalTags.Value.Data, cancellationToken: cancellationToken); var originalResponse = _virtualMachineExtensionImagesRestClient.Get(Id.SubscriptionId, Id.Parent.Parent.Parent.Parent.Name, Id.Parent.Parent.Parent.Name, Id.Parent.Name, Id.Name, cancellationToken); return(Response.FromValue(new VirtualMachineExtensionImage(this, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public async virtual Task<Response<ServiceBusNamespace>> SetTagsAsync(IDictionary<string, string> tags, CancellationToken cancellationToken = default) { if (tags == null) { throw new ArgumentNullException($"{nameof(tags)} provided cannot be null.", nameof(tags)); } using var scope = _clientDiagnostics.CreateScope("ServiceBusNamespace.SetTags"); scope.Start(); try { await TagResource.DeleteAsync(cancellationToken: cancellationToken).ConfigureAwait(false); var originalTags = await TagResource.GetAsync(cancellationToken).ConfigureAwait(false); originalTags.Value.Data.Properties.TagsValue.ReplaceWith(tags); await TagResource.CreateOrUpdateAsync(originalTags.Value.Data, cancellationToken: cancellationToken).ConfigureAwait(false); var originalResponse = await _namespacesRestClient.GetAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, cancellationToken).ConfigureAwait(false); return Response.FromValue(new ServiceBusNamespace(this, originalResponse.Value), originalResponse.GetRawResponse()); } catch (Exception e) { scope.Failed(e); throw; } }
public async Task <IActionResult> UpdateTag(int id, [FromBody] TagResource tagResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var tag = await repository.GetTag(id); if (tag == null) { return(NotFound()); } mapper.Map <TagResource, Tag>(tagResource, tag); repository.UpdateTagProjects(tag, tagResource); await unitOfWork.Complete(); var result = mapper.Map <Tag, TagResource>(tag); return(Ok(result)); }
public virtual Response <StorageAccount> SetTags(IDictionary <string, string> tags, CancellationToken cancellationToken = default) { if (tags == null) { throw new ArgumentNullException($"{nameof(tags)} provided cannot be null.", nameof(tags)); } using var scope = _clientDiagnostics.CreateScope("StorageAccount.SetTags"); scope.Start(); try { TagResource.Delete(cancellationToken: cancellationToken); var originalTags = TagResource.Get(cancellationToken); originalTags.Value.Data.Properties.TagsValue.ReplaceWith(tags); TagContainer.CreateOrUpdate(originalTags.Value.Data, cancellationToken: cancellationToken); var originalResponse = _restClient.GetProperties(Id.ResourceGroupName, Id.Name, null, cancellationToken); return(Response.FromValue(new StorageAccount(this, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual async Task <Response <WebApplicationFirewallPolicy> > AddTagAsync(string key, string value, CancellationToken cancellationToken = default) { Argument.AssertNotNull(key, nameof(key)); Argument.AssertNotNull(value, nameof(value)); using var scope = _webApplicationFirewallPolicyClientDiagnostics.CreateScope("WebApplicationFirewallPolicy.AddTag"); scope.Start(); try { var originalTags = await TagResource.GetAsync(cancellationToken).ConfigureAwait(false); originalTags.Value.Data.TagValues[key] = value; await TagResource.CreateOrUpdateAsync(WaitUntil.Completed, originalTags.Value.Data, cancellationToken : cancellationToken).ConfigureAwait(false); var originalResponse = await _webApplicationFirewallPolicyRestClient.GetAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, cancellationToken).ConfigureAwait(false); return(Response.FromValue(new WebApplicationFirewallPolicy(Client, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public async virtual Task <Response <ExpressRouteGateway> > AddTagAsync(string key, string value, CancellationToken cancellationToken = default) { Argument.AssertNotNull(key, nameof(key)); Argument.AssertNotNull(value, nameof(value)); using var scope = _expressRouteGatewayClientDiagnostics.CreateScope("ExpressRouteGateway.AddTag"); scope.Start(); try { var originalTags = await TagResource.GetAsync(cancellationToken).ConfigureAwait(false); originalTags.Value.Data.Properties.TagsValue[key] = value; await TagResource.CreateOrUpdateAsync(true, originalTags.Value.Data, cancellationToken : cancellationToken).ConfigureAwait(false); var originalResponse = await _expressRouteGatewayRestClient.GetAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, cancellationToken).ConfigureAwait(false); return(Response.FromValue(new ExpressRouteGateway(Client, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual async Task <Response <DatabaseAccountSqlDatabaseContainerThroughputSetting> > AddTagAsync(string key, string value, CancellationToken cancellationToken = default) { Argument.AssertNotNull(key, nameof(key)); Argument.AssertNotNull(value, nameof(value)); using var scope = _databaseAccountSqlDatabaseContainerThroughputSettingSqlResourcesClientDiagnostics.CreateScope("DatabaseAccountSqlDatabaseContainerThroughputSetting.AddTag"); scope.Start(); try { var originalTags = await TagResource.GetAsync(cancellationToken).ConfigureAwait(false); originalTags.Value.Data.TagValues[key] = value; await TagResource.CreateOrUpdateAsync(WaitUntil.Completed, originalTags.Value.Data, cancellationToken : cancellationToken).ConfigureAwait(false); var originalResponse = await _databaseAccountSqlDatabaseContainerThroughputSettingSqlResourcesRestClient.GetSqlContainerThroughputAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Parent.Parent.Name, Id.Parent.Parent.Name, Id.Parent.Name, cancellationToken).ConfigureAwait(false); return(Response.FromValue(new DatabaseAccountSqlDatabaseContainerThroughputSetting(Client, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual Response <DatabaseAccountCassandraKeyspaceTableThroughputSetting> SetTags(IDictionary <string, string> tags, CancellationToken cancellationToken = default) { if (tags == null) { throw new ArgumentNullException($"{nameof(tags)} provided cannot be null.", nameof(tags)); } using var scope = _clientDiagnostics.CreateScope("DatabaseAccountCassandraKeyspaceTableThroughputSetting.SetTags"); scope.Start(); try { TagResource.Delete(cancellationToken: cancellationToken); var originalTags = TagResource.Get(cancellationToken); originalTags.Value.Data.Properties.TagsValue.ReplaceWith(tags); TagResource.CreateOrUpdate(originalTags.Value.Data, cancellationToken: cancellationToken); var originalResponse = _cassandraResourcesRestClient.GetCassandraTableThroughput(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Parent.Parent.Name, Id.Parent.Parent.Name, Id.Parent.Name, cancellationToken); return(Response.FromValue(new DatabaseAccountCassandraKeyspaceTableThroughputSetting(this, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual Response <GremlinDatabase> SetTags(IDictionary <string, string> tags, CancellationToken cancellationToken = default) { if (tags == null) { throw new ArgumentNullException(nameof(tags), $"{nameof(tags)} provided cannot be null."); } using var scope = _gremlinDatabaseGremlinResourcesClientDiagnostics.CreateScope("GremlinDatabase.SetTags"); scope.Start(); try { TagResource.Delete(true, cancellationToken: cancellationToken); var originalTags = TagResource.Get(cancellationToken); originalTags.Value.Data.Properties.TagsValue.ReplaceWith(tags); TagResource.CreateOrUpdate(true, originalTags.Value.Data, cancellationToken: cancellationToken); var originalResponse = _gremlinDatabaseGremlinResourcesRestClient.GetGremlinDatabase(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, cancellationToken); return(Response.FromValue(new GremlinDatabase(ArmClient, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual Response <Snapshot> SetTags(IDictionary <string, string> tags, CancellationToken cancellationToken = default) { if (tags == null) { throw new ArgumentNullException(nameof(tags)); } using var scope = _snapshotClientDiagnostics.CreateScope("Snapshot.SetTags"); scope.Start(); try { TagResource.Delete(true, cancellationToken: cancellationToken); var originalTags = TagResource.Get(cancellationToken); originalTags.Value.Data.Properties.TagsValue.ReplaceWith(tags); TagResource.CreateOrUpdate(true, originalTags.Value.Data, cancellationToken: cancellationToken); var originalResponse = _snapshotRestClient.Get(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, cancellationToken); return(Response.FromValue(new Snapshot(Client, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public async virtual Task <Response <MhsmPrivateEndpointConnection> > AddTagAsync(string key, string value, CancellationToken cancellationToken = default) { Argument.AssertNotNull(key, nameof(key)); Argument.AssertNotNull(value, nameof(value)); using var scope = _mhsmPrivateEndpointConnectionMHSMPrivateEndpointConnectionsClientDiagnostics.CreateScope("MhsmPrivateEndpointConnection.AddTag"); scope.Start(); try { var originalTags = await TagResource.GetAsync(cancellationToken).ConfigureAwait(false); originalTags.Value.Data.TagValues[key] = value; await TagResource.CreateOrUpdateAsync(true, originalTags.Value.Data, cancellationToken : cancellationToken).ConfigureAwait(false); var originalResponse = await _mhsmPrivateEndpointConnectionMHSMPrivateEndpointConnectionsRestClient.GetAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, cancellationToken).ConfigureAwait(false); return(Response.FromValue(new MhsmPrivateEndpointConnection(Client, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
protected override async Task Execute() { if (NumberOfProjects >= ProjectNames.Length) { throw new CommandException($"Please create up to {ProjectNames.Length} projects, we only have so many random names!"); } Log.Information("Building multi-tenant sample with {ProjectCount} projects, {CustomerCount} customers and {TesterCount} testers...", NumberOfProjects, NumberOfCustomers, NumberOfTesters); await EnsureMultitenancyFeature(); Log.Information("Setting up environments..."); var allEnvironmentsTasks = new[] { "MT Dev", "MT Test", "MT Beta", "MT Staging", "MT Production" } .Select(name => Repository.Environments.CreateOrModify(name, LipsumRobinsonoKruso.GenerateLipsum(1))) .ToArray(); var allEnvironments = (await Task.WhenAll(allEnvironmentsTasks)).Select(e => e.Instance).ToArray(); var normalLifecycle = await Repository.Lifecycles.CreateOrModify("MT Normal Lifecycle", "The normal lifecycle for the multi-tenant deployments sample"); await normalLifecycle.AsSimplePromotionLifecycle(allEnvironments.Where(e => e.Name != "MT Beta").ToArray()).Save(); var betaLifecycle = await Repository.Lifecycles.CreateOrModify("MT Beta Lifecycle", "The beta lifecycle for the multi-tenant deployments sample"); await betaLifecycle.AsSimplePromotionLifecycle(allEnvironments.Take(3).ToArray()).Save(); var projectGroup = await Repository.ProjectGroups.CreateOrModify("Multi-tenancy sample"); Log.Information("Setting up tags..."); var tagSetTenantType = await Repository.TagSets.CreateOrModify("Tenant type", "Allows you to categorize tenants"); await tagSetTenantType.AddOrUpdateTag("Internal", "These are internal tenants, like our test team") .AddOrUpdateTag("External", "These are external tenants, our real customers", TagResource.StandardColor.LightBlue) .Save(); var tagSetImportance = await Repository.TagSets.CreateOrModify("Tenant importance", "Allows you to have different customers that we should pay more or less attention to"); await tagSetImportance.AddOrUpdateTag("VIP", "Very important tenant - pay attention!", TagResource.StandardColor.DarkRed) .AddOrUpdateTag("Standard", "These are our standard customers") .AddOrUpdateTag("Trial", "These are trial customers", TagResource.StandardColor.DarkPurple) .Save(); var tagSetRing = await Repository.TagSets.CreateOrModify("Upgrade ring", "What kind of upgrade stability to these customers want"); await tagSetRing.AddOrUpdateTag("Tester", "These are our internal test team members", TagResource.StandardColor.LightCyan) .AddOrUpdateTag("Early adopter", "Upgrade these customers first", TagResource.StandardColor.LightYellow) .AddOrUpdateTag("Stable", "Upgrade these customers last", TagResource.StandardColor.LightGreen) .AddOrUpdateTag("Pinned", "Don't upgrade these customers until they come back to the stable ring", TagResource.StandardColor.DarkRed) .Save(); var tagSetEarlyAccessProgram = await Repository.TagSets.CreateOrModify("Early access program", "Provides tenants with access to certain early access programs."); await tagSetEarlyAccessProgram.AddOrUpdateTag("2.x Beta", "These customers are part of our 2.x beta program", TagResource.StandardColor.LightPurple) .Save(); var tagSetHosting = await Repository.TagSets.CreateOrModify("Hosting", "Allows you to define where the tenant software should be hosted"); await tagSetHosting.AddOrUpdateTag("Internal-Shared-Farm", "The internal test server farm") .AddOrUpdateTag("Shared-Farm-1", "Shared server farm 1", TagResource.StandardColor.LightGreen) .AddOrUpdateTag("Shared-Farm-2", "Shared server farm 2", TagResource.StandardColor.LightGreen) .AddOrUpdateTag("Shared-Farm-3", "Shared server farm 3", TagResource.StandardColor.LightGreen) .AddOrUpdateTag("Shared-Farm-4", "Shared server farm 4", TagResource.StandardColor.LightGreen) .AddOrUpdateTag("Dedicated", "This customer will have their own dedicated hardware", TagResource.StandardColor.DarkRed) .Save(); var allTags = new TagResource[0] .Concat(tagSetTenantType.Instance.Tags) .Concat(tagSetHosting.Instance.Tags) .Concat(tagSetImportance.Instance.Tags) .Concat(tagSetRing.Instance.Tags) .Concat(tagSetEarlyAccessProgram.Instance.Tags) .ToArray(); var getTag = new Func <string, TagResource>(name => allTags.FirstOrDefault(t => t.Name == name)); Log.Information("Setting up the untenanted host for the development..."); var untenantedHosts = Enumerable.Range(0, 1).Select(i => Repository.Machines.CreateOrModify( $"Untenanted Node {i}", new CloudRegionEndpointResource(), allEnvironments.Where(e => e.Name == "MT Dev").ToArray(), new[] { "web-server" })) .ToArray(); Log.Information("Setting up the shared hosts for the test environment..."); foreach (var internalSharedHostTag in tagSetHosting.Instance.Tags.Where(t => t.Name.StartsWith("Internal-Shared"))) { var sharedHosts = Enumerable.Range(0, 4).Select(i => Repository.Machines.CreateOrModify( $"{internalSharedHostTag.Name} Node {i}", new CloudRegionEndpointResource(), allEnvironments.Where(e => e.Name == "MT Test").ToArray(), new[] { "web-server" }, new TenantResource[0], new[] { internalSharedHostTag })) .ToArray(); } Log.Information("Setting up the shared hosts for the production environment..."); foreach (var sharedHostTag in tagSetHosting.Instance.Tags.Where(t => t.Name.StartsWith("Shared-Farm"))) { await Task.WhenAll( Enumerable.Range(0, 4) .Select(i => Repository.Machines.CreateOrModify( $"{sharedHostTag.Name} Node {i}", new CloudRegionEndpointResource(), allEnvironments.Where(e => e.Name == "MT Production").ToArray(), new[] { "web-server" }, new TenantResource[0], new[] { sharedHostTag })) .ToArray() ); } Log.Information("Setting up variables..."); var envVarEditor = await Repository.LibraryVariableSets.CreateOrModify("Environment variables", "The environment details we require for all projects"); foreach (var e in allEnvironments) { (await envVarEditor.Variables).AddOrUpdateVariableValue("Environment.Alias", e.Name.Replace("MT ", "").ToLowerInvariant(), new ScopeSpecification { { ScopeField.Environment, e.Id } }); } await envVarEditor.Save(); var stdTenantVarEditor = await Repository.LibraryVariableSets.CreateOrModify("Standard tenant details", "The standard details we require for all tenants"); stdTenantVarEditor.VariableTemplates .AddOrUpdateSingleLineTextTemplate(VariableKeys.StandardTenantDetails.TenantAlias, "Alias", defaultValue: null, helpText: "This alias will be used to build convention-based settings for the tenant") .AddOrUpdateSelectTemplate(VariableKeys.StandardTenantDetails.TenantRegion, "Region", Region.All.ToDictionary(x => x.Alias, x => x.DisplayName), defaultValue: null, helpText: "The geographic region where this tenant will be hosted") .AddOrUpdateSingleLineTextTemplate(VariableKeys.StandardTenantDetails.TenantContactEmail, "Contact email", defaultValue: null, helpText: "A comma-separated list of email addresses to send deployment notifications"); await stdTenantVarEditor.Save(); var libraryVariableSets = new[] { envVarEditor.Instance, stdTenantVarEditor.Instance }; Log.Information("Building {Count} sample projects...", NumberOfProjects); var projects = await Task.WhenAll( Enumerable.Range(0, NumberOfProjects) .Select(i => new { Name = ProjectNames[i], Alias = ProjectNames[i].ToLowerInvariant() }) .Select(async(x, i) => { Log.Information("Setting up project {ProjectName}...", x.Name); var projectEditor = await Repository.Projects.CreateOrModify(x.Name, projectGroup.Instance, normalLifecycle.Instance, LipsumTheRaven.GenerateLipsum(2)); projectEditor.IncludingLibraryVariableSets(libraryVariableSets); var image = SampleImageCache.GetRobotImage(x.Name); if (!string.IsNullOrWhiteSpace(image)) { projectEditor.SetLogo(image); } projectEditor.VariableTemplates .Clear() .AddOrUpdateSingleLineTextTemplate("Tenant.Database.Name", "Database name", $"{x.Alias}-#{{Environment.Alias}}-#{{Tenant.Alias}}", $"The environment-specific name of the {x.Name} database for this tenant.") .AddOrUpdateSingleLineTextTemplate("Tenant.Database.UserID", "Database username", $"{x.Alias}-#{{Environment.Alias}}-#{{Tenant.Alias}}", "The User ID used to connect to the tenant database.") .AddOrUpdateSensitiveTemplate(VariableKeys.ProjectTenantVariables.TenantDatabasePassword, "Database password", defaultValue: null, helpText: "The password used to connect to the tenant database.") .AddOrUpdateSingleLineTextTemplate("Tenant.Domain.Name", "Domain name", $"#{{Tenant.Alias}}.{x.Alias}.com", $"The environment-specific domain name for the {x.Name} web application for this tenant."); (await projectEditor.Variables) .AddOrUpdateVariableValue("DatabaseConnectionString", $"Server=db.{x.Alias}.com;Database=#{{Tenant.Database.Name}};User ID=#{{Tenant.Database.UserID}};Password=#{{Tenant.Database.Password}};") .AddOrUpdateVariableValue("HostURL", "https://#{Tenant.Domain.Name}"); // Create the channels for the sample project var channel = await projectEditor.Channels.CreateOrModify("1.x Normal", "The channel for stable releases that will be deployed to our production customers."); await channel.SetAsDefaultChannel() .AddOrUpdateTenantTags(getTag("Tester"), getTag("Early adopter"), getTag("Stable")) .Save(); var betaChannelEditor = await projectEditor.Channels.CreateOrModify("2.x Beta", "The channel for beta releases that will be deployed to our beta customers."); betaChannelEditor.UsingLifecycle(betaLifecycle.Instance) .AddOrUpdateTenantTags(getTag("2.x Beta")); // Delete the "default channel" if it exists await projectEditor.Channels.Delete("Default"); // Rebuild the process from scratch var deploymentProcess = await projectEditor.DeploymentProcess; deploymentProcess.ClearSteps(); deploymentProcess.AddOrUpdateStep("Deploy Application") .TargetingRoles("web-server") .AddOrUpdateScriptAction("Deploy Application", new InlineScriptActionFromFileInAssembly("MultiTenantSample.Deploy.ps1"), ScriptTarget.Target); deploymentProcess.AddOrUpdateStep("Deploy 2.x Beta Component") .TargetingRoles("web-server") .AddOrUpdateScriptAction("Deploy 2.x Beta Component", new InlineScriptActionFromFileInAssembly("MultiTenantSample.DeployBetaComponent.ps1"), ScriptTarget.Target) .ForChannels(betaChannelEditor.Instance); deploymentProcess.AddOrUpdateStep("Notify VIP Contact") .AddOrUpdateScriptAction("Notify VIP Contact", new InlineScriptActionFromFileInAssembly("MultiTenantSample.NotifyContact.ps1"), ScriptTarget.Server) .ForTenantTags(getTag("VIP")); projectEditor.Instance.TenantedDeploymentMode = ProjectTenantedDeploymentMode.TenantedOrUntenanted; await projectEditor.Save(); return(projectEditor.Instance); }) .ToArray() ); Log.Information("Building {Count} sample Testers...", NumberOfTesters); var testers = await Task.WhenAll( GetSampleTenantData("Tester", NumberOfTesters) .Select(async x => { Log.Information("Setting up tester {TenantName}...", x.Name); var tenantEditor = await Repository.Tenants.CreateOrModify(x.Name); tenantEditor.SetLogo(SampleImageCache.DownloadImage(x.LogoUrl)) .WithTag(getTag("Internal")) .WithTag(getTag("Tester")) .WithTag(getTag("Internal-Shared-Farm")) .WithTag(getTag("2.x Beta")); // Connect to projects/environments tenantEditor.ClearProjects(); var testEnvironments = allEnvironments.Where(e => e.Name == "MT Test").ToArray(); foreach (var project in projects) { tenantEditor.ConnectToProjectAndEnvironments(project, testEnvironments); } await tenantEditor.Save(); // Ensure project mapping is saved before we attempt to fill out variables - otherwise they won't exist await FillOutTenantVariablesByConvention(tenantEditor, projects, allEnvironments, libraryVariableSets); await tenantEditor.Save(); return(tenantEditor.Instance); }) .ToArray() ); Log.Information("Building {Count} sample Customers...", NumberOfCustomers); var customers = await Task.WhenAll( GetSampleTenantData("Customer", NumberOfCustomers) .Select(async x => { Log.Information("Setting up customer {TenantName}...", x.Name); var tenantEditor = await Repository.Tenants.CreateOrModify(x.Name); tenantEditor.SetLogo(SampleImageCache.DownloadImage(x.LogoUrl)); TagCustomerByConvention(tenantEditor.Instance, allTags); // Connect to projects/environments var customerEnvironments = GetEnvironmentsForCustomer(allEnvironments, tenantEditor.Instance); foreach (var project in projects) { tenantEditor.ConnectToProjectAndEnvironments(project, customerEnvironments); } await tenantEditor.Save(); // Ensure project mapping is saved before we attempt to fill out variables - otherwise they won't exist await FillOutTenantVariablesByConvention(tenantEditor, projects, allEnvironments, libraryVariableSets); await tenantEditor.Save(); return(tenantEditor.Instance); }) .ToArray() ); foreach (var customer in customers.Where(c => c.IsVIP())) { Log.Information("Setting up dedicated hosting for {VIP}...", customer.Name); await Task.WhenAll( Enumerable.Range(0, 2) .Select(i => Repository.Machines.CreateOrModify( $"{customer.Name} Host {i}", new CloudRegionEndpointResource(), GetEnvironmentsForCustomer(allEnvironments, customer), new[] { "web-server" }, new[] { customer }, new TagResource[0])) .ToArray() ); } Log.Information("Created {CustomerCount} customers and {TesterCount} testers and {ProjectCount} projects.", customers.Length, testers.Length, projects.Length); Log.Information("Customer tagging conventions: Names with 'v' will become 'VIP' (with dedicated hosting), names with 'u' will become 'Trial', names with 'e' will become 'Early adopter', everyone else will be 'Standard' and assigned to a random shared server pool."); }
public virtual TagResource GetTagResource(ResourceIdentifier id) { TagResource.ValidateResourceId(id); return(new TagResource(this, id)); }
public TenantEditor WithTag(TagResource tag) { Instance.WithTag(tag); return(this); }
protected override async Task Execute() { Log.Information("Building trucks sample with {TrucksCount} trucks using multi-tenant deployments...", NumberOfTrucks); await EnsureMultitenancyFeature(); Log.Information("Setting up environment..."); var environments = new[] { (await Repository.Environments.CreateOrModify("Trucks Production", LipsumRobinsonoKruso.GenerateLipsum(1))).Instance }; var normalLifecycle = await Repository.Lifecycles.CreateOrModify("Trucks Normal Lifecycle", "The normal lifecycle for the trucks sample"); await normalLifecycle.AsSimplePromotionLifecycle(environments.ToArray()).Save(); var projectGroup = await Repository.ProjectGroups.CreateOrModify("Trucks sample"); Log.Information("Setting up tags..."); var tagSetTruckType = await Repository.TagSets.CreateOrModify("Truck type", "Allows you to categorize tenants"); await tagSetTruckType.AddOrUpdateTag("General Waste", "These are the trucks that deal with general waste", TagResource.StandardColor.DarkRed) .AddOrUpdateTag("Green Waste", "These are the trucks that deal with green waste", TagResource.StandardColor.DarkGreen) .AddOrUpdateTag("Recycling", "These are the trucks that deal with recycling", TagResource.StandardColor.LightYellow) .Save(); var tagSetRing = await Repository.TagSets.CreateOrModify("Upgrade ring", "The order in which to upgrade sets of trucks"); await tagSetRing.AddOrUpdateTag("Canary", "Upgrade these trucks first", TagResource.StandardColor.LightYellow) .AddOrUpdateTag("Stable", "Upgrade these trucks last", TagResource.StandardColor.LightGreen) .Save(); var allTags = new TagResource[0] .Concat(tagSetTruckType.Instance.Tags) .Concat(tagSetRing.Instance.Tags) .ToArray(); var getTag = new Func <string, TagResource>(name => allTags.FirstOrDefault(t => t.Name == name)); Log.Information("Setting up variables..."); var standardTruckVarEditor = await Repository.LibraryVariableSets.CreateOrModify("Standard truck details", "The standard details we require for all trucks"); standardTruckVarEditor.VariableTemplates .AddOrUpdateSingleLineTextTemplate(VariableKeys.StandardTenantDetails.TruckAlias, "Alias", defaultValue: null, helpText: "This alias will be used to build convention-based settings for the truck"); await standardTruckVarEditor.Save(); var libraryVariableSets = new[] { standardTruckVarEditor.Instance }; await BuildServerProject(projectGroup.Instance, normalLifecycle.Instance); var clientProject = await BuildClientProject(projectGroup.Instance, normalLifecycle.Instance, libraryVariableSets, getTag); var logos = new Dictionary <string, string> { { "General Waste", "http://images.moc-pages.com/user_images/16939/1240756821m_SPLASH.jpg" }, { "Green Waste", "http://cache.lego.com/e/dynamic/is/image/LEGO/4432?$main$" }, { "Recycling", "http://lego.lk/wp-content/uploads/2016/03/Garbage-Truck.png" }, }; var proj = new[] { clientProject }; var env = environments.Where(e => e.Name.EndsWith("Production")).ToArray(); var trucks = await Task.WhenAll( Enumerable.Range(0, NumberOfTrucks) .Select(i => new { Name = $"Truck-{i:0000}", TruckType = tagSetTruckType.Instance.Tags.ElementAt(i % 3), UpgradeRing = i % 5 == 0 ? getTag("Canary") : getTag("Stable") }) .Select(async(x, i) => { Log.Information("Setting up tenant for truck {TruckName}...", x.Name); var tenantEditor = await Repository.Tenants.CreateOrModify(x.Name); await tenantEditor.SetLogo(SampleImageCache.DownloadImage(logos[x.TruckType.Name])); tenantEditor.ClearTags().WithTag(x.TruckType).WithTag(x.UpgradeRing); tenantEditor.ClearProjects(); foreach (var project in proj) { tenantEditor.ConnectToProjectAndEnvironments(project, env); } await tenantEditor.Save(); // Ensure the tenant is saved before we attempt to fill out variables - otherwise we don't know what projects they are connected to await FillOutTenantVariablesByConvention(tenantEditor, proj, env, libraryVariableSets); await tenantEditor.Save(); return(tenantEditor.Instance); }) .ToArray() ); foreach (var truck in trucks) { Log.Information("Setting up hosting for {TruckName}...", truck.Name); var dedicatedHost = Repository.Machines.CreateOrModify(truck.Name, new CloudRegionEndpointResource(), env, new[] { "truck" }, new[] { truck }, new TagResource[0], TenantedDeploymentMode.Tenanted); } Log.Information("Created {TruckCount} trucks.", trucks.Length); await StartTrucksMoving(trucks); }