public DatabaseInstance GenerateDatabaseInstance(ServerInstance serverInstance, Slice slice, DatabaseVersion databaseVersion) { return GenerateDatabaseInstance( serverInstance, slice, databaseVersion, databaseDefinition.DatabaseInstanceNamePattern, databaseDefinition.DatabaseNamePattern, databaseVersion.SizeMultiplier, true); }
public UserDatabaseInstance GenerateUserDatabaseInstance(DatabaseVersion databaseVersion) { // TODO: this part probably needs some optimization // Load server instances that can store user databases var ef = new EntityFactory(Context); var sis = ef.FindAll<ServerInstance>() .Where(i => i.ServerVersionReference.Guid == databaseVersion.ServerVersionReference.Guid) .OrderBy(i => i.Machine.Number) .ToArray(); if (sis.Length == 0) { throw new InvalidOperationException("At least one server instance has to configured for the database version."); // TODO } // Get current number of user databases var dd = databaseVersion.DatabaseDefinition; dd.LoadDatabaseInstances(false); var dbnum = dd.DatabaseInstances.Count; // Find a server that is available int off = 0; int sin = 0; while (off < sis.Length) { sin = (dbnum + 1 + off) % sis.Length; bool ok = true; var diag = sis[sin].RunDiagnostics(); foreach (var d in diag) { if (d.Status != DiagnosticMessageStatus.OK) { ok = false; break; } } if (ok) { break; } off++; } // Default slice (FULL) dd.LoadSlices(false); var sl = dd.Slices[Constants.FullSliceName]; // Create physical database instance var ddi = new DatabaseInstanceInstaller(databaseVersion.DatabaseDefinition); var di = ddi.GenerateDatabaseInstance( sis[sin], sl, databaseVersion); di.Save(); // Add user database mapping var udi = new UserDatabaseInstance(user); udi.DatabaseVersion = databaseVersion; udi.DatabaseInstance = di; udi.Save(); return udi; }
/// <summary> /// Creates a deep copy of the passed object. /// </summary> /// <param name="old">A <b>Database Version</b> object to create the deep copy from.</param> private void CopyMembers(DatabaseVersion old) { this.sizeMultiplier = old.sizeMultiplier; }
/// <summary> /// Copy contructor for doing deep copy of the <b>Database Version</b> objects. /// </summary> /// <param name="old">The <b>Database Version</b> to copy from.</param> public DatabaseVersion(DatabaseVersion old) : base(old) { CopyMembers(old); }
public DatabaseInstance GenerateDatabaseInstance(ServerInstance serverInstance, List<DiskVolume> dataDiskVolumes, List<DiskVolume> logDiskVolumes, Slice slice, DatabaseVersion databaseVersion, string namePattern, string databaseNamePattern, double sizeFactor, bool generateFileGroups) { // --- Create the new database instance and set name DatabaseInstance ndi = new DatabaseInstance(databaseDefinition); ndi.ServerInstanceReference.Guid = serverInstance.Guid; ndi.SliceReference.Guid = slice.Guid; ndi.DatabaseVersionReference.Guid = databaseVersion.Guid; ndi.Name = ExpressionProperty.ResolveExpression(ndi, namePattern); ndi.DatabaseName = ExpressionProperty.ResolveExpression(ndi, databaseNamePattern); ndi.Save(); if (generateFileGroups) { ndi.ServerInstance.Machine.LoadDiskVolumes(false); databaseDefinition.LoadFileGroups(false); slice.LoadPartitions(false); List<Partition> partitions = new List<Partition>(slice.Partitions.Values.OrderBy(i => i.Number)); List<FileGroup> filegroups = new List<FileGroup>(databaseDefinition.FileGroups.Values.OrderBy(i => i.Number)); for (int fi = 0; fi < filegroups.Count; fi++) { // --- Create data and "log" file groups --- if (filegroups[fi].LayoutType == FileGroupLayoutType.Monolithic || filegroups[fi].FileGroupType == FileGroupType.Log) { DatabaseInstanceFileGroup nfg = new DatabaseInstanceFileGroup(ndi); nfg.FileGroupType = filegroups[fi].FileGroupType; nfg.FileGroupName = nfg.Name = filegroups[fi].FileGroupName; nfg.FileGroupReference.Guid = filegroups[fi].Guid; nfg.PartitionReference.Guid = Guid.Empty; nfg.AllocatedSpace = (long)(filegroups[fi].AllocatedSpace * sizeFactor); nfg.Save(); nfg.GenerateInstanceFiles(dataDiskVolumes, sizeFactor); } else if (filegroups[fi].LayoutType == FileGroupLayoutType.Sliced) { for (int pi = 0; pi < partitions.Count; pi++) { DatabaseInstanceFileGroup nfg = new DatabaseInstanceFileGroup(ndi); nfg.FileGroupType = filegroups[fi].FileGroupType; nfg.FileGroupName = nfg.Name = string.Format("{0}_{1}", filegroups[fi].FileGroupName, pi); nfg.FileGroupReference.Guid = filegroups[fi].Guid; nfg.PartitionReference.Guid = partitions[pi].Guid; nfg.AllocatedSpace = (long)(filegroups[fi].AllocatedSpace * sizeFactor); nfg.Save(); nfg.GenerateInstanceFiles(dataDiskVolumes, sizeFactor); } } else { throw new NotImplementedException(); } } } return ndi; }
public DatabaseInstance GenerateDatabaseInstance(ServerInstance serverInstance, Slice slice, DatabaseVersion databaseVersion, string namePattern, string databaseNamePattern, double sizeFactor, bool generateFileGroups) { return GenerateDatabaseInstance(serverInstance, null, null, slice, databaseVersion, namePattern, databaseNamePattern, sizeFactor, generateFileGroups); }
// public DatabaseInstance GetDatabaseInstance(DatabaseVersion databaseVersion, long partitionKeyValue) { // *** TODO: partitioning key interval limits (inclusive, exclusive!) LoadSlices(false); Slice slice = this.Slices.Values.First(x => x.From <= partitionKeyValue && x.To >= partitionKeyValue); this.LoadDatabaseInstances(false); return this.DatabaseInstances.Values.First(x => x.DatabaseVersionReference.Guid == databaseVersion.Guid && x.Slice.Guid == slice.Guid); }
/// <summary> /// Constructor for creating a new entity with object context and parent entity set. /// </summary> /// <param name="context">An object context class containing session information.</param> /// <param name="parent">The parent entity in the entity hierarchy.</param> public UserDatabaseInstance(DatabaseVersion parent) : base(parent.Context, parent) { InitializeMembers(); }
/// <summary> /// Initializes a database definition. /// </summary> /// <param name="serverVersion"></param> public void GenerateDefaultChildren(ServerVersion serverVersion, string databaseVersionName) { // If not sliced, then create a default slice of FULL if (databaseDefinition.LayoutType == DatabaseLayoutType.Mirrored || databaseDefinition.LayoutType == DatabaseLayoutType.Monolithic) { Slice sl = new Slice(databaseDefinition) { Name = Constants.FullSliceName, System = databaseDefinition.System, }; sl.Save(); } else { throw new InvalidOperationException(); // Use slicing wizard instead } // Add primary filegroup FileGroupLayoutType fglayout; switch (databaseDefinition.LayoutType) { case DatabaseLayoutType.Sliced: fglayout = FileGroupLayoutType.Sliced; break; case DatabaseLayoutType.Monolithic: case DatabaseLayoutType.Mirrored: fglayout = FileGroupLayoutType.Monolithic; break; default: throw new NotImplementedException(); } FileGroup fg = new FileGroup(databaseDefinition) { Name = Constants.PrimaryFileGroupName, System = databaseDefinition.System, FileGroupType = FileGroupType.Data, LayoutType = fglayout, AllocationType = FileGroupAllocationType.CrossVolume, DiskVolumeType = DiskVolumeType.Data, FileGroupName = Constants.PrimaryFileGroupName, AllocatedSpace = Constants.PrimaryFileGroupSize, FileCount = 0, }; fg.Save(); // Add "log" file group fg = new FileGroup(databaseDefinition) { Name = Constants.LogFileGroupName, System = databaseDefinition.System, FileGroupType = FileGroupType.Log, LayoutType = FileGroupLayoutType.Monolithic, AllocationType = FileGroupAllocationType.CrossVolume, DiskVolumeType = DiskVolumeType.Log, FileGroupName = Constants.LogFileGroupName, AllocatedSpace = Constants.LogFileGroupSize, FileCount = 0 }; fg.Save(); // Create default database version DatabaseVersion dv = new DatabaseVersion(databaseDefinition) { Name = databaseVersionName, System = databaseDefinition.System, ServerVersion = serverVersion, SizeMultiplier = 1.0f, }; dv.Save(); }
protected void Page_Load(object sender, EventArgs e) { item = new DatabaseDefinition(RegistryContext); item.Guid = new Guid(Request.QueryString["guid"]); item.Load(); item.LoadDatabaseVersions(false); databaseVersions = new List<DatabaseVersion>(item.DatabaseVersions.Values); if (!IsPostBack) { RefreshDatabaseVersionList(); } // Load currently selected database version databaseVersion = new DatabaseVersion(RegistryContext); databaseVersion.Guid = new Guid(databaseVersionList.SelectedValue); databaseVersion.Load(); // Load server instances EntityFactory ef = new EntityFactory(RegistryContext); serverInstances = new List<ServerInstance>(ef.FindAll<ServerInstance>() .Where(i => i.ServerVersionReference.Guid == databaseVersion.ServerVersionReference.Guid) .OrderBy(i => i.Machine.Number)); // Load slices item.LoadSlices(false); slices = new List<Slice>(item.Slices.Values); if (!IsPostBack) { UpdateForm(); } GenerateTable(); }
protected void Ok_Click(object sender, EventArgs e) { double sizefactor = double.Parse(SizeFactor.Text); string postfix = String.Empty; DatabaseVersion rs = new DatabaseVersion(RegistryContext); rs.Guid = new Guid(databaseVersionList.SelectedValue); rs.Load(); int q = 0; for (int sli = 0; sli < slices.Count; sli++) { for (int ssi = 0; ssi < serverInstances.Count; ssi++) { CheckBox cb = (CheckBox)FindControlRecursive(string.Format("cb_{0}_{1}", sli, ssi)); if (cb.Checked) { switch (item.LayoutType) { case DatabaseLayoutType.Sliced: break; default: postfix = String.Format("{0}", q.ToString("00")); break; } var dii = new DatabaseInstanceInstaller(item); dii.GenerateDatabaseInstance(serverInstances[ssi], slices[sli], rs, NamePattern.Text.Replace("[$Number]", postfix), DatabaseNamePattern.Text.Replace("[$Number]", postfix), sizefactor, GenerateFileGroups.Checked); q++; } } } Response.Redirect(item.GetDetailsUrl(EntityGroup.Layout)); }
public DatabaseInstance GetUserDatabaseInstance(DatabaseVersion databaseVersion) { LoadUserDatabaseInstances(true); var udi = UserDatabaseInstances.Values.FirstOrDefault(i => i.DatabaseVersionReference.Guid == databaseVersion.Guid); if (udi != null) { return udi.DatabaseInstance; } else { return null; } }