/// <summary>
        /// Registers the new shard and add tenant details to Tenants table in catalog
        /// </summary>
        /// <param name="tenantId">The tenant identifier.</param>
        /// <param name="databaseServerPort">The database server port.</param>
        /// <param name="servicePlan">The service plan.</param>
        /// <param name="shard">The shard which needs to be registered.</param>
        /// <returns></returns>
        public static async Task <bool> RegisterNewShard(int tenantId, string servicePlan, Shard shard)
        {
            try
            {
                // Register the mapping of the tenant to the shard in the shard map.
                // After this step, DDR on the shard map can be used
                PointMapping <int> mapping;
                if (!ShardMap.TryGetMappingForKey(tenantId, out mapping))
                {
                    var pointMapping = ShardMap.CreatePointMapping(tenantId, shard);

                    //convert from int to byte[] as tenantId has been set as byte[] in Tenants entity
                    var key = _utilities.ConvertIntKeyToBytesArray(pointMapping.Value);

                    //get tenant's venue name
                    var venueDetails = await _tenantRepository.GetVenueDetails(tenantId);

                    //add tenant to Tenants table
                    var tenant = new Tenants
                    {
                        ServicePlan = servicePlan,
                        TenantId    = key,
                        TenantName  = venueDetails.VenueName
                    };

                    _catalogRepository.Add(tenant);
                }
                return(true);
            }
            catch (Exception exception)
            {
                Trace.TraceError(exception.Message, "Error in registering new shard.");
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Registers the new shard.
        /// Verify if shard exists for the tenant. If not then create new shard and add tenant details to Tenants table in catalog
        /// </summary>
        /// <param name="tenantName">Name of the tenant.</param>
        /// <param name="tenantId">The tenant identifier.</param>
        /// <param name="tenantServer">The tenant server.</param>
        /// <param name="databaseServerPort">The database server port.</param>
        /// <param name="servicePlan">The service plan.</param>
        /// <returns></returns>
        public static async Task <bool> RegisterNewShard(string tenantName, int tenantId, string tenantServer, int databaseServerPort, string servicePlan)
        {
            try
            {
                Shard         shard;
                ShardLocation shardLocation = new ShardLocation(tenantServer, tenantName, SqlProtocol.Tcp, databaseServerPort);

                if (!ShardMap.TryGetShard(shardLocation, out shard))
                {
                    //create shard if it does not exist
                    shard = ShardMap.CreateShard(shardLocation);
                }

                // Register the mapping of the tenant to the shard in the shard map.
                // After this step, DDR on the shard map can be used
                PointMapping <int> mapping;
                if (!ShardMap.TryGetMappingForKey(tenantId, out mapping))
                {
                    var pointMapping = ShardMap.CreatePointMapping(tenantId, shard);

                    //convert from int to byte[] as tenantId has been set as byte[] in Tenants entity
                    var key = _utilities.ConvertIntKeyToBytesArray(pointMapping.Value);

                    //get tenant's venue name
                    var venueDetails = await _tenantRepository.GetHotelDetailsAsync(tenantId);

                    //add tenant to Tenants table
                    var tenant = new Tenants
                    {
                        ServicePlan   = servicePlan,
                        TenantId      = key,
                        TenantName    = venueDetails.HotelName,
                        RecoveryState = "n/a",
                        LastUpdated   = DateTime.Now
                    };

                    _catalogRepository.Add(tenant);
                }
                return(true);
            }
            catch (Exception exception)
            {
                Trace.TraceError(exception.Message, "Error in registering new shard.");
                return(false);
            }
        }