Esempio n. 1
0
        public static void Main(string[] args)
        {
            System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);

            // create new management client USING NAMESPACE ADMINISTRATOR to obtain token
            using (ECSManagementClient client = new ECSManagementClient(MgmtFactory.MGMT_USER_NAME, MgmtFactory.MGMT_USER_PASSWORD, MgmtFactory.MGMT_ENDPOINT))
            {
                // authenticate
                client.Authenticate().Wait();

                // using authenticated client, obtain new instance of service client
                ECSManagementService service = client.CreateServiceClient();

                // delete namespace
                bool result = service.DeleteNamespace(MgmtFactory.NAMESPACE_NAME).Result;

                // print message to indicate namespace was deleted
                Console.WriteLine("Namespace {0} deleted.", result ? "was succssfully" : "was not successfully");

                Console.ReadLine();

                // log out
                client.LogOut();
            }
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);

            // create new management client to obtain token
            using (ECSManagementClient client = new ECSManagementClient(MgmtFactory.MGMT_USER_NAME, MgmtFactory.MGMT_USER_PASSWORD, MgmtFactory.MGMT_ENDPOINT))
            {
                // authenticate
                client.Authenticate().Wait();

                // using authenticated client, obtain new instance of service client
                ECSManagementService service = client.CreateServiceClient();

                // specify namespace administrator
                List <string> admns = new List <string>();
                admns.Add(MgmtFactory.NAMESPACE_ADMIN_NAME);

                // create new namespace
                namespaceRestRep result = service.CreateNamespace(MgmtFactory.NAMESPACE_NAME, admns, MgmtFactory.REPLICATION_GROUP, string.Empty, new List <string>(), new List <string>()).Result;

                // print namespace name for validation
                Console.WriteLine(string.Format("Successfully created namespace {0}.", result.name));
                Console.ReadLine();

                // log out
                client.LogOut();
            }
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);

            // create new management client USING NAMESPACE ADMINISTRATOR to obtain token
            using (ECSManagementClient client = new ECSManagementClient(MgmtFactory.NAMESPACE_ADMIN_NAME, MgmtFactory.NAMESPACE_ADMIN_PASSWORD, MgmtFactory.MGMT_ENDPOINT))
            {
                string   metricSizeUnit = "GB";
                DateTime startTime      = new DateTime(2014, 8, 1);
                DateTime endTime        = new DateTime(2016, 8, 31);

                // authenticate
                client.Authenticate().Wait();

                // using authenticated client, obtain new instance of service client
                ECSManagementService service = client.CreateServiceClient();

                // get metrics for specific bucket and specified timeframe
                bucketBillingSampleRestRep result = service.GetBucketBillingSample(MgmtFactory.NAMESPACE_NAME, MgmtFactory.BUCKET_NAME, startTime, endTime, metricSizeUnit).Result;

                // print bucket metrics
                Console.WriteLine("For timeframe {0} to {1} ...", startTime.ToString(), endTime.ToString());
                Console.WriteLine(string.Format("BUCKET: {0} OBJECTS: {1} SIZE: {2} {3} INGRESS: {4} EGRESS {5}.",
                                                result.name, result.total_objects, result.total_size, result.total_size_unit, result.ingress, result.egress));

                Console.ReadLine();

                // log out
                client.LogOut();
            }
        }
        public static void Main(string[] args)
        {
            System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);

            // create new management client USING NAMESPACE ADMINISTRATOR to obtain token
            using (ECSManagementClient client = new ECSManagementClient(MgmtFactory.NAMESPACE_ADMIN_NAME, MgmtFactory.NAMESPACE_ADMIN_PASSWORD, MgmtFactory.MGMT_ENDPOINT))
            {
                bool   includeBucketDetail = true;
                string metricSizeUnit      = "GB";

                // authenticate
                client.Authenticate().Wait();

                // using authenticated client, obtain new instance of service client
                ECSManagementService service = client.CreateServiceClient();

                // get metrics for specific namespace
                namespaceBillingRestRep result = service.GetNamespaceBillingInfo(MgmtFactory.NAMESPACE_NAME, metricSizeUnit, includeBucketDetail, null).Result;

                // print namespace metrics
                Console.WriteLine(string.Format("Namespace {0}: Total Objects: {1} Total Size: {2} {3}.",
                                                MgmtFactory.NAMESPACE_NAME, result.total_objects, result.total_size, result.total_size_unit));

                // print bucket metrics
                if (includeBucketDetail)
                {
                    foreach (var item in result.bucket_billing_info)
                    {
                        Console.WriteLine(string.Format("Bucket {0, -35} Total Objects: {1, 8} Total Size: {2, -4} {3, -2}",
                                                        item.name, item.total_objects, item.total_size, item.total_size_unit));
                    }
                }

                Console.ReadLine();

                // log out
                client.LogOut();
            }
        }
        public static void Main(string[] args)
        {
            System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);

            // create new management client to obtain token
            using (ECSManagementClient client = new ECSManagementClient(MgmtFactory.MGMT_USER_NAME, MgmtFactory.MGMT_USER_PASSWORD, MgmtFactory.MGMT_ENDPOINT))
            {
                // authenticate
                client.Authenticate().Wait();

                // using authenticated client, obtain new instance of service client
                ECSManagementService service = client.CreateServiceClient();

                // create new namespace administrator
                mgmtUserInfoRestRep result = service.CreateManagementUser(MgmtFactory.NAMESPACE_ADMIN_NAME, MgmtFactory.NAMESPACE_ADMIN_PASSWORD, false, false).Result;

                // print namespace admin userid for validation
                Console.WriteLine(string.Format("Successfully created namespace administrator {0}.", result.userId));
                Console.ReadLine();

                // log out
                client.LogOut();
            }
        }
Esempio n. 6
0
        public static void Main(string[] args)
        {
            System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);

            // create new management client USING NAMESPACE ADMINISTRATOR to obtain token
            using (ECSManagementClient client = new ECSManagementClient(MgmtFactory.NAMESPACE_ADMIN_NAME, MgmtFactory.NAMESPACE_ADMIN_PASSWORD, MgmtFactory.MGMT_ENDPOINT))
            {
                // authenticate
                client.Authenticate().Wait();

                // using authenticated client, obtain new instance of service client
                ECSManagementService service = client.CreateServiceClient();

                // create new object user
                secretKeyInfoRep result = service.CreateObjectUser(MgmtFactory.OBJECT_USER, MgmtFactory.NAMESPACE_NAME).Result;

                // print object user result for validation
                Console.WriteLine(string.Format("Successfully created object user {0}.", result.link.href));
                Console.ReadLine();

                // log out
                client.LogOut();
            }
        }
Esempio n. 7
0
        public static void Main(string[] args)
        {
            System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);

            // create new management client USING NAMESPACE ADMINISTRATOR to obtain token
            using (ECSManagementClient client = new ECSManagementClient(MgmtFactory.NAMESPACE_ADMIN_NAME, MgmtFactory.NAMESPACE_ADMIN_PASSWORD, MgmtFactory.MGMT_ENDPOINT))
            {
                // authenticate
                client.Authenticate().Wait();

                // using authenticated client, obtain new instance of service client
                ECSManagementService service = client.CreateServiceClient();

                // create the AWS S3 client
                AmazonS3Client s3 = MgmtFactory.getS3Client();

                // get current retention period
                bucketRetentionInfoRep retention = service.GetBucketRetention(MgmtFactory.BUCKET_NAME, MgmtFactory.NAMESPACE_NAME).Result;
                Console.WriteLine(string.Format("Current bucket retention period: {0} seconds", retention.period));

                // set retention period to 1 minute
                Console.WriteLine("Setting retention period to one minute");
                bool result = service.SetBucketRetention(MgmtFactory.BUCKET_NAME, MgmtFactory.NAMESPACE_NAME, 60).Result;
                if (result)
                {
                    // create object
                    PutObjectRequest request = new PutObjectRequest()
                    {
                        BucketName  = MgmtFactory.BUCKET_NAME,
                        ContentBody = "object content",
                        Key         = "object1"
                    };

                    // create the object in bucket
                    s3.PutObject(request);
                    Console.WriteLine("Object uploaded to bucket");
                    bool objectDeleted = false;

                    while (!objectDeleted)
                    {
                        Console.WriteLine("Trying to delete the object");
                        DeleteObjectRequest request2 = new DeleteObjectRequest()
                        {
                            BucketName = MgmtFactory.BUCKET_NAME,
                            Key        = "object1"
                        };
                        try
                        {
                            DeleteObjectResponse response = s3.DeleteObject(request2);
                            Console.WriteLine("--> Object deleted successfully");
                            objectDeleted = true;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error: {0}", e.Message);
                            System.Threading.Thread.Sleep(10000);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Could not set retention period. Exiting...");
                }

                Console.ReadLine();

                // log out
                client.LogOut();
            }
        }