Esempio n. 1
0
        // "/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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        // "/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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }