private bool ValidateClusterCreationMetadata(Metastore hive, Metastore oozie)
 {
     return this.ValidateMetastoreConnection(hive) && this.ValidateMetastoreConnection(oozie);
 }
        private bool ValidateMetastoreConnection(Metastore metastore)
        {
            var creds = IntegrationTestBase.GetAllCredentials();
            var hiveStores = (from tc in creds
                              where tc.IsNotNull() && tc.Environments.IsNotNull()
                              from e in tc.Environments
                              where e.IsNotNull() && e.HiveStores.IsNotNull()
                              from h in e.HiveStores
                              where h.IsNotNull()
                              select new { Server = h.SqlServer, h.Database, UserName = tc.AzureUserName, Password = tc.AzurePassword }).ToList();
            var ozzieStores = (from tc in creds
                               where tc.IsNotNull() && tc.Environments.IsNotNull()
                               from e in tc.Environments
                               where e.IsNotNull() && e.OozieStores.IsNotNull()
                               from h in e.OozieStores
                               where h.IsNotNull()
                               select new { Server = h.SqlServer, h.Database, UserName = tc.AzureUserName, Password = tc.AzurePassword }).ToList();

            var stores = hiveStores.Union(ozzieStores).ToList();

            if (metastore == null)
            {
                return true;
            }

            return (from s in stores
                    where
                        s.Server == metastore.Server && s.Database == metastore.Database && s.UserName == metastore.User &&
                        s.Password == metastore.Password
                    select s).Any();
        }
 private ClusterErrorStatus ValidateHBaseClusterCreation(Microsoft.WindowsAzure.Management.HDInsight.Contracts.May2014.ClusterCreateParameters cluster)
 {
     HiveComponent hive = cluster.Components.OfType<HiveComponent>().Single();
     OozieComponent oozie = cluster.Components.OfType<OozieComponent>().Single();
     Metastore hiveMetastore = null;
     Metastore oozieMetastore = null;
     if (!hive.Metastore.ShouldProvisionNew)
     {
         var metaStore = (SqlAzureDatabaseCredentialBackedResource)hive.Metastore;
         hiveMetastore = new Metastore(
             metaStore.SqlServerName, metaStore.DatabaseName, metaStore.Credentials.Username, metaStore.Credentials.Password);
     }
     if (!oozie.Metastore.ShouldProvisionNew)
     {
         var metaStore = (SqlAzureDatabaseCredentialBackedResource)oozie.Metastore;
         oozieMetastore = new Metastore(
             metaStore.SqlServerName, metaStore.DatabaseName, metaStore.Credentials.Username, metaStore.Credentials.Password);
     }
     if (!this.ValidateClusterCreationMetadata(hiveMetastore, oozieMetastore))
     {
         return new ClusterErrorStatus(400, "Invalid metastores", "create");
     }
     return null;
 }