public DiscoveryModule(IAsyncDocumentSession session) : base("/api/discovery") { this.session = session; Get["/start"] = parameters => { var discoveryClient = new ClusterDiscoveryClient(SenderId, "http://localhost:9020/api/discovery/notify"); discoveryClient.PublishMyPresenceAsync(); return("started"); }; Post["/notify", true] = async(parameters, ct) => { var input = this.Bind <ServerRecord>("Id"); var server = await session.Query <ServerRecord>().Where(s => s.Url == input.Url).FirstOrDefaultAsync() ?? new ServerRecord(); this.BindTo(server, "Id"); await session.StoreAsync(server); await HealthMonitorTask.FetchServerDatabases(server, session.Advanced.DocumentStore); return("notified"); }; }
public CredentialsModule(IAsyncDocumentSession session) : base("/api/servers/credentials") { this.session = session; Post["/save", true] = async(parameters, ct) => { string serverId = Request.Query.ServerId; var serverRecord = await session.LoadAsync <ServerRecord>(serverId); if (serverRecord == null) { return(new NotFoundResponse()); } var credentials = this.Bind <ServerCredentials>(); await session.StoreAsync(credentials); serverRecord.CredentialsId = credentials.Id; await HealthMonitorTask.FetchServerDatabasesAsync(serverRecord, session); return(null); }; Post["/test", true] = async(parameters, ct) => { string serverId = Request.Query.ServerId; var serverRecord = await session.LoadAsync <ServerRecord>(serverId); if (serverRecord == null) { return(new NotFoundResponse()); } var credentials = this.Bind <ServerCredentials>(); var client = await ServerHelpers.CreateAsyncServerClient(session, serverRecord, credentials); try { var adminStatistics = await client.GlobalAdmin.GetStatisticsAsync(); } catch (AggregateException ex) { var exception = ex.ExtractSingleInnerException(); var webException = exception as WebException; if (webException != null) { var response = webException.Response as HttpWebResponse; if (response != null && response.StatusCode == HttpStatusCode.Unauthorized) { var failMessage = "Unauthorized. "; if (credentials.AuthenticationMode == AuthenticationMode.ApiKey) { failMessage += " Check that the Api Kay exists and enabled on the server."; } else { failMessage += " Check that the username exists in the server (or domain) and the password is correct and was not expired."; } return(new CredentialsTest { Success = false, Message = failMessage, Type = "Unauthorized", Exception = response.ToString(), }); } else { return(new CredentialsTest { Success = false, Message = "Not found. Check that the server is online and that you have access to it.", Type = "NotFound", Exception = exception.ToString(), }); } } return(new CredentialsTest { Success = false, Message = "An error occurred. See exception for more details.", Exception = exception.ToString(), }); } catch (Exception ex) { return(new CredentialsTest { Success = false, Message = "An error occurred.", Exception = ex.ToString(), }); } return(new CredentialsTest { Success = true, }); }; }
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { var store = container.Resolve <IDocumentStore>(); var healthMonitorTask = new HealthMonitorTask(store); }