// "/eureka/apps/{appName}/{instanceID}/status?value={status}&lastDirtyTimestamp=1568746948343" public ActionResult <string> ChangeInstanceStatus([FromRoute] string appName, [FromRoute] string instanceID, [FromQuery] string value, [FromQuery] long lastDirtyTimestamp, [FromServices] IPublishChangesService publishService, [FromServices] IMemoryDiscoveryClientRepository clientRepo, [FromServices] IPublishClientsService clientPublishService) { var tenantId = this.GetTenantIdFromRouteData(); var clientHostname = Request.HttpContext.Connection.RemoteIpAddress.ToString(); clientRepo.Add(new DiscoveryClient(clientHostname)); clientPublishService.PublishClientDiscoveryActivity(tenantId, clientHostname); MemoryServicesRepository repo = new MemoryServicesRepository(tenantId, Program.InstanceConfig.EvictionInSecs); if (lastDirtyTimestamp == 0) { lastDirtyTimestamp = DateTimeConversions.ToJavaMillis(DateTime.UtcNow); } var instance = repo.ChangeStatus(appName, instanceID, value, lastDirtyTimestamp); if (instance != null) { publishService.PublishInstanceStatusChange(instance.TenantId, appName, instanceID, value, lastDirtyTimestamp); this.HttpContext.Response.StatusCode = 200; } else { this.HttpContext.Response.StatusCode = 500; } return(string.Empty); }
public ActionResult <string> DeleteInstance([FromRoute] string appName, [FromRoute] string instanceID, [FromServices] IPublishChangesService publishService, [FromServices] IMemoryDiscoveryClientRepository clientRepo, [FromServices] IPublishClientsService clientPublishService) { var tenantId = this.GetTenantIdFromRouteData(); var clientHostname = Request.HttpContext.Connection.RemoteIpAddress.ToString(); clientRepo.Add(new DiscoveryClient(clientHostname)); clientPublishService.PublishClientDiscoveryActivity(tenantId, clientHostname); MemoryServicesRepository repo = new MemoryServicesRepository(tenantId, Program.InstanceConfig.EvictionInSecs); var instance = repo.Delete(appName, instanceID); if (instance != null) { publishService.PublishDeletedInstance(instance.TenantId, appName, instanceID); this.HttpContext.Response.StatusCode = 200; } else { this.HttpContext.Response.StatusCode = 500; } return(string.Empty); }
public ActionResult <Application> GetApp([FromRoute] string appName, [FromServices] IMemoryDiscoveryClientRepository clientRepo, [FromServices] IPublishClientsService clientPublishService) { var tenantId = this.GetTenantIdFromRouteData(); var clientHostname = Request.HttpContext.Connection.RemoteIpAddress.ToString(); clientRepo.Add(new DiscoveryClient(clientHostname)); clientPublishService.PublishClientDiscoveryActivity(tenantId, clientHostname); MemoryServicesRepository repo = new MemoryServicesRepository(tenantId, Program.InstanceConfig.EvictionInSecs); return(repo.GetByAppName(appName)); }
// "/eureka/apps/{appName}/{instanceID}?status=UP&lastDirtyTimestamp=1568804226113" public ActionResult <string> ReceiveInstanceHeartbeat([FromRoute] string appName, [FromRoute] string instanceID, [FromQuery] long lastDirtyTimestamp, [FromServices] IPublishChangesService publishService, [FromServices] IMemoryDiscoveryClientRepository clientRepo, [FromServices] IPublishClientsService clientPublishService) { var tenantId = this.GetTenantIdFromRouteData(); var clientHostname = Request.HttpContext.Connection.RemoteIpAddress.ToString(); clientRepo.Add(new DiscoveryClient(clientHostname)); clientPublishService.PublishClientDiscoveryActivity(tenantId, clientHostname); MemoryServicesRepository repo = new MemoryServicesRepository(this.GetTenantIdFromRouteData(), Program.InstanceConfig.EvictionInSecs); var status = string.Empty; if (lastDirtyTimestamp == 0) { lastDirtyTimestamp = DateTimeConversions.ToJavaMillis(DateTime.UtcNow); } if (Request.QueryString.Value.ToString().IndexOf("status") >= 0) { // status change request var queryDictionary = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(Request.QueryString.Value.ToString()); var items = queryDictionary.SelectMany(x => x.Value, (col, value) => new KeyValuePair <string, string>(col.Key, value)).ToList(); var statusItem = items.SingleOrDefault(q => q.Key.CompareTo("status") == 0); if (statusItem.Key != null) { status = statusItem.Value; } var dirtyItem = items.SingleOrDefault(q => q.Key.CompareTo("lastDirtyTimestamp") == 0); if (dirtyItem.Key != null) { lastDirtyTimestamp = Convert.ToInt64(dirtyItem.Value); } } var instance = repo.SaveInstanceHearbeat(appName, instanceID, status, lastDirtyTimestamp); if (instance != null) { publishService.PublishAddedOrUpdatedInstance(instance, "UPDATE_INSTANCE"); this.HttpContext.Response.StatusCode = 200; } else { this.HttpContext.Response.StatusCode = 404; } return(string.Empty); }
public ActionResult <List <int> > GeCountries([FromServices] IMemoryDiscoveryClientRepository clientRepo, [FromServices] IPublishClientsService clientPublishService) { var tenantId = this.GetTenantIdFromRouteData(); var clientHostname = Request.HttpContext.Connection.RemoteIpAddress.ToString(); clientRepo.Add(new DiscoveryClient(clientHostname)); clientPublishService.PublishClientDiscoveryActivity(tenantId, clientHostname); MemoryServicesRepository repo = new MemoryServicesRepository(this.GetTenantIdFromRouteData(), Program.InstanceConfig.EvictionInSecs); List <int> list = repo.GetCountries(); return(list); }
public ActionResult <string> AddAppInstance([FromRoute] string appName, [FromBody] ServiceInstaceRegisterRequest request, [FromServices] IPublishChangesService publishService, [FromServices] IMemoryDiscoveryClientRepository clientRepo, [FromServices] IPublishClientsService clientPublishService) { var tenantId = this.GetTenantIdFromRouteData(); var clientHostname = Request.HttpContext.Connection.RemoteIpAddress.ToString(); clientRepo.Add(new DiscoveryClient(clientHostname)); clientPublishService.PublishClientDiscoveryActivity(tenantId, clientHostname); request.instance.AppName = appName; MemoryServicesRepository repo = new MemoryServicesRepository(tenantId, Program.InstanceConfig.EvictionInSecs); Instance instance = repo.Add(request.instance); publishService.PublishAddedOrUpdatedInstance(instance, "ADD_INSTANCE"); this.HttpContext.Response.StatusCode = 204; return(string.Empty); }
public ActionResult <List <Instance> > GetInstancesForSVipAddress([FromRoute] string svipAddress, [FromServices] IMemoryDiscoveryClientRepository clientRepo, [FromServices] IPublishClientsService clientPublishService) { var tenantId = this.GetTenantIdFromRouteData(); var clientHostname = Request.HttpContext.Connection.RemoteIpAddress.ToString(); clientRepo.Add(new DiscoveryClient(clientHostname)); clientPublishService.PublishClientDiscoveryActivity(tenantId, clientHostname); MemoryServicesRepository repo = new MemoryServicesRepository(tenantId, Program.InstanceConfig.EvictionInSecs); List <Instance> list = repo.GetInstancesForSVipAddress(svipAddress); if (list.Count > 0) { this.HttpContext.Response.StatusCode = 200; } else { this.HttpContext.Response.StatusCode = 404; } return(list); }