public async Task <ProviderRegistration> RunActivity( [ActivityTrigger] ProviderRegisterCommand command, ILogger log) { if (command is null) { throw new ArgumentNullException(nameof(command)); } using (log.BeginCommandScope(command)) { try { var identity = await azureSessionService .GetIdentityAsync() .ConfigureAwait(false); var registration = new ProviderRegistration { PrincipalId = identity?.ObjectId }; return(registration); } catch (Exception exc) { log.LogError(exc, $"{nameof(ProviderRegisterActivity)} failed: {exc.Message}"); throw exc.AsSerializable(); } } }
public static ProviderRegistration RunActivity( [ActivityTrigger] ProviderRegisterCommand command, ILogger log) { if (command is null) { throw new ArgumentNullException(nameof(command)); } using (log.BeginCommandScope(command)) { try { var registration = new ProviderRegistration { PrincipalId = null // this provider does not talk to any azure resources yet }; return(registration); } catch (Exception exc) { log.LogError(exc, $"{nameof(ProviderRegisterActivity)} failed: {exc.Message}"); throw exc.AsSerializable(); } } }
public static async Task <ProviderRegistration> RunActivity( [ActivityTrigger] ProviderRegisterCommand command, ILogger log) { if (command is null) { throw new ArgumentNullException(nameof(command)); } var registration = new ProviderRegistration { PrincipalId = null // this provider does not talk to any azure resources yet }; return(registration); }
protected async Task RegisterAsync() { var user = await GetUserAsync() .ConfigureAwait(false); var command = new ProviderRegisterCommand(user, new ProviderConfiguration() { TeamCloudApplicationInsightsKey = Guid.Empty.ToString() }); var commandResult = await SendCommandAsync(command, true) .ConfigureAwait(false); Assert.Equal(command.CommandId, commandResult.CommandId); Assert.Equal(CommandRuntimeStatus.Completed, commandResult.RuntimeStatus); }
public async Task <ProviderRegistration> RunActivity( [ActivityTrigger] ProviderRegisterCommand command, ILogger log) { if (command is null) { throw new ArgumentNullException(nameof(command)); } var identity = await azureSessionService .GetIdentityAsync() .ConfigureAwait(false); var registration = new ProviderRegistration { PrincipalId = identity?.ObjectId }; return(registration); }
public static async Task RunOrchestration( [OrchestrationTrigger] IDurableOrchestrationContext functionContext, ILogger log) { if (functionContext is null) { throw new ArgumentNullException(nameof(functionContext)); } var(provider, command) = functionContext .GetInput <(ProviderDocument, ProviderRegisterCommand)>(); try { if (command is null) { // no command was given !!! // restart the orchestration // with a new command instance. var systemUser = await functionContext .CallActivityWithRetryAsync <UserDocument>(nameof(TeamCloudSystemUserActivity), null) .ConfigureAwait(true); var providerCommand = new ProviderRegisterCommand ( null, systemUser.PopulateExternalModel(), new ProviderConfiguration() ); functionContext .ContinueAsNew((provider, providerCommand)); } else if (provider is null) { // no provider was given !!! // fan out registration with // one orchestration per provider. functionContext.SetCustomStatus($"Register providers", log); var providers = await functionContext .ListProvidersAsync() .ConfigureAwait(true); if (providers.Any()) { var tasks = providers .Select(provider => functionContext.CallSubOrchestratorWithRetryAsync(nameof(ProviderRegisterOrchestration), (provider, command))); await Task .WhenAll(tasks) .ConfigureAwait(true); } } else { command.Payload .TeamCloudApplicationInsightsKey = await functionContext .GetInstrumentationKeyAsync() .ConfigureAwait(true); command.Payload .Properties = provider.Properties; var commandResult = await functionContext .SendProviderCommandAsync <ProviderRegisterCommand, ProviderRegisterCommandResult>(command, provider) .ConfigureAwait(true); if (commandResult?.Result != null) { using (await functionContext.LockContainerDocumentAsync(provider).ConfigureAwait(true)) { provider = await functionContext .GetProviderAsync(provider.Id) .ConfigureAwait(true); if (provider is null) { log.LogWarning($"Provider '{provider.Id}' registration skipped - provider no longer exists"); } else { provider.PrincipalId = commandResult.Result.PrincipalId; provider.CommandMode = commandResult.Result.CommandMode; provider.Registered = functionContext.CurrentUtcDateTime; provider.ResourceProviders = commandResult.Result.ResourceProviders; provider.Properties = provider.Properties.Override(commandResult.Result.Properties); provider = await functionContext .SetProviderAsync(provider) .ConfigureAwait(true); if (provider.PrincipalId.HasValue) { var providerUser = await functionContext .GetUserAsync(provider.PrincipalId.Value.ToString(), allowUnsafe : true) .ConfigureAwait(true); if (providerUser is null) { providerUser = new UserDocument { Id = provider.PrincipalId.Value.ToString(), Role = TeamCloudUserRole.Provider, UserType = UserType.Provider }; _ = await functionContext .SetUserTeamCloudInfoAsync(providerUser, allowUnsafe : true) .ConfigureAwait(false); } } functionContext.SetCustomStatus($"Provider '{provider.Id}' registration succeeded", log); } } } } } catch (Exception exc) { if (provider != null) { functionContext.SetCustomStatus($"Failed to register provider '{provider.Id}' - {exc.Message}", log, exc); } else if (command != null) { functionContext.SetCustomStatus($"Failed to register providers - {exc.Message}", log, exc); } else { functionContext.SetCustomStatus($"Failed to initiate provider registration - {exc.Message}", log, exc); } } }