Example #1
0
        //Get Json and maybe put it in S3 Storage...
        public static void AddJsonFileToS3(string clusterName, Dictionary <string, TeamData> teamsStorage)
        {
            AmazonS3Client      client          = new AmazonS3Client();
            JsonFileConstructor jsonConstructor = new JsonFileConstructor();

            FinalJsonRoot jsonRootObj = jsonConstructor.GetFinalJsonStructure(teamsStorage);

            string jsonString = JsonConvert.SerializeObject(jsonRootObj);

            var currentDateTime = DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day;

            var jsonFileKey         = "leaderboard/elasticsearch.json";
            var jsonFileKeyWithDate = "leaderboard/elasticsearch-history/" + currentDateTime + ".json";



            PutObjectRequest putJsonRequest = new PutObjectRequest
            {
                BucketName  = "datalens-hub",
                Key         = jsonFileKey,
                ContentBody = jsonString,
            };

            PutObjectRequest putJsonRequestWithDate = new PutObjectRequest
            {
                BucketName  = "datalens-hub",
                Key         = jsonFileKeyWithDate,
                ContentBody = jsonString,
            };

            PutObjectResponse putJsonResponse  = client.PutObjectAsync(putJsonRequest).GetAwaiter().GetResult();
            PutObjectResponse putJsonResponse2 = client.PutObjectAsync(putJsonRequestWithDate).GetAwaiter().GetResult();

            Console.WriteLine("Uploaded json to s3. Response: " + putJsonResponse.HttpStatusCode + " destination: " + client.Config.DetermineServiceURL());
        }
        //Could add in new constructor here to alter meta/teamdata field names
        public JsonFileConstructor()
        {
            _meta = new MetaData
            {
                storageType   = "total_store_size",
                period        = "all_time",
                unit          = "bytes",
                name          = "Elastic_Search",
                dateEvaluated = DateTime.Now,
                costPerUnit   = 0
            };

            rootObj = new FinalJsonRoot()
            {
                meta = _meta
            };
        }