Exemplo n.º 1
0
 /// <summary>
 /// Create a cluster containing just the local machine.
 /// </summary>
 /// <param name="config">Configuration for the local machine.</param>
 public AzureDfsClusterStatus(ClusterConfiguration config)
     : base(config)
 {
     if (!(config is AzureDfsClusterConfiguration))
         throw new ArgumentException("Expected a AzureDfsClusterConfiguration, got a " + config.GetType());
     this.config = config as AzureDfsClusterConfiguration;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Create a File URI from a file path.
 /// </summary>
 /// <param name="path">Path to file.</param>
 /// <returns>The File uri.</returns>
 /// <param name="config">Azure cluster configuration.</param>
 public static Uri UriFromPath(AzureDfsClusterConfiguration config, string path)
 {
     if (path.StartsWith(config.Container))
         throw new InvalidOperationException("Path contains container name");
     var retval = Microsoft.Research.Peloponnese.Azure.Utils.ToAzureUri(config.AccountName, config.Container, path, null, config.AccountKey);
     //Console.WriteLine("Uri {0}", retval);
     return retval;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Create a path from a URI.
 /// </summary>
 /// <param name="uri">URI of an HDFS file.</param>
 /// <returns>The path to the file.</returns>
 /// <param name="config">Azure cluster configuration.</param>
 public static string PathFromUri(AzureDfsClusterConfiguration config, Uri uri)
 {
     string path = uri.LocalPath;
     path = path.Trim('/');
     if (path.StartsWith(config.Container))
         path = path.Substring(config.Container.Length);
     path = path.Trim('/'); 
     return path;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Enumerate all the clusters this user is subscribed to.
        /// </summary>
        /// <returns>The list of clusters this user is subscribed to.</returns>
        public static List<ClusterConfiguration> EnumerateAzureDfsSubscribedClusters()
        {
            List<ClusterConfiguration> configList = new List<ClusterConfiguration>();

            var store = new X509Store();
            store.Open(OpenFlags.ReadOnly);
            var configDir = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                "Windows Azure Powershell");
            var defaultFile = Path.Combine(configDir, "WindowsAzureProfile.xml");
            if (File.Exists(defaultFile))
            {
                using (FileStream s = new FileStream(defaultFile, FileMode.Open, FileAccess.Read))
                {
                    XDocument doc = XDocument.Load(s);
                    XNamespace ns = doc.Root.GetDefaultNamespace();
                    IEnumerable<XElement> subs = doc.Descendants(ns + "AzureSubscriptionData");
                    foreach (XElement sub in subs)
                    {
                        string thumbprint = sub.Descendants(ns + "ManagementCertificate").Single().Value;
                        string subId = sub.Descendants(ns + "SubscriptionId").Single().Value;
                        Guid subGuid = new Guid(subId);

                        X509Certificate2 cert = store.Certificates.Cast<X509Certificate2>().First(item => item.Thumbprint == thumbprint);

                        HDInsightCertificateCredential sCred = new HDInsightCertificateCredential(subGuid, cert);
                        IHDInsightClient sClient = HDInsightClient.Connect(sCred);
                        var clusters = sClient.ListClusters();
                        foreach (var cluster in clusters)
                        {
                            var account = cluster.DefaultStorageAccount;
                            var accountName = account.Name.Split('.').First();
                            Console.WriteLine("Cluster " + cluster.Name + " uses account " + accountName + " with key " + account.Key);

                            AzureDfsClusterConfiguration config = null;
                            try
                            {
                                config = new AzureDfsClusterConfiguration();
                                config.AzureClient = new AzureDfsClient(accountName, account.Key, config.Container);
                                config.Name = cluster.Name;
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Exception while reconstructing cluster " + cluster.Name + ": " + ex);
                            }

                            if (config != null)
                                configList.Add(config);
                        }
                    }
                }
            }

            return configList;
        }