public void ProcessorNodeMetricsTest() { var serdes = new StringSerDes(); var rd = new Random(); int nbMessage = rd.Next(0, 4000); // simulate processing message for (int i = 0; i < nbMessage; ++i) { string key = "key" + i, value = "value" + i; var r = new ConsumeResult <byte[], byte[]>() { Message = new Message <byte[], byte[]>() { Key = serdes.Serialize(key, new SerializationContext()), Value = serdes.Serialize(value, new SerializationContext()), Timestamp = new Timestamp(DateTime.Now) }, Offset = i, IsPartitionEOF = false, Topic = topicPartition.Topic, Partition = topicPartition.Partition }; context.SetRecordMetaData(r); sourceProcessor.Process(key, value); } long now = DateTime.Now.GetMilliseconds(); var sensors = streamMetricsRegistry.GetThreadScopeSensor(threadId); var processorSensor = sourceProcessor.ProcessSensor; Assert.AreEqual(2, processorSensor.Metrics.Count()); Assert.AreEqual(nbMessage, processorSensor.Metrics[MetricName.NameAndGroup( ProcessorNodeMetrics.PROCESS + StreamMetricsRegistry.TOTAL_SUFFIX, StreamMetricsRegistry.PROCESSOR_NODE_LEVEL_GROUP)].Value); Assert.IsTrue( (double)processorSensor.Metrics[MetricName.NameAndGroup( ProcessorNodeMetrics.PROCESS + StreamMetricsRegistry.RATE_SUFFIX, StreamMetricsRegistry.PROCESSOR_NODE_LEVEL_GROUP)].Value > 0d); }
public List <string> GenerateScriptFromSourceServer(ServerConnection sc, List <DatabaseObject> objectList) { var dtStart = DateTime.Now; AsyncUpdateStatus updateStatus = GenScriptAsyncUpdateStatusHandler; var args = new AsyncNotificationEventArgs(NotificationEventFunctionCode.GenerateScriptFromSQLServer, 0, "", CommonFunc.FormatString("Process started at {0} -- UTC -> {1} ... ", dtStart.ToString(CultureInfo.CurrentUICulture), dtStart.ToUniversalTime().ToString(CultureInfo.CurrentUICulture)) + Environment.NewLine, Color.DarkBlue); StreamWriter swTSQL = null; SqlSmoObject[] smoTriggers = null; Object sender = System.Threading.Thread.CurrentThread; var smoScriptOpts = SMOScriptOptions.CreateFromConfig(); updateStatus(args); sc.Connect(); var ss = new Server(sc); var db = ss.Databases[sc.DatabaseName]; var sdb = new ScriptDatabase(); sdb.Initialize(ss, db, updateStatus, smoScriptOpts, swTSQL); args.DisplayText = ""; args.StatusMsg = "Sorting objects by dependency ..."; args.PercentComplete = 1; updateStatus(args); var sorted = GetSortedObjects(db, objectList); var sp = new SourceProcessor(); var tempPathForBCPData = Path.Combine(Path.GetTempPath(), "/BCPData"); Directory.CreateDirectory(tempPathForBCPData); sp.Initialize(sdb, smoScriptOpts, updateStatus, args, tempPathForBCPData); //NOTE: This is what does the magic! if (sp.Process(sorted, 30)) { return(output); } if (!Regex.IsMatch(smoScriptOpts.ScriptTableAndOrData, smoScriptOpts.GetLocalizedStringValue("ScriptOptionsTableData"), RegexOptions.IgnoreCase)) { if (sp.Process(DatabaseObjectsTypes.Triggers, smoTriggers, 95)) { return(output); } } var dtEnd = DateTime.Now; var tsDuration = dtEnd.Subtract(dtStart); var sHour = tsDuration.Minutes == 1 ? " hour, " : " hours, "; var sMin = tsDuration.Minutes == 1 ? " minute and " : " minutes and "; var sSecs = tsDuration.Seconds == 1 ? " second" : " seconds"; args.StatusMsg = "Done!"; args.DisplayColor = Color.DarkCyan; if (smoScriptOpts.CheckCompatibility() == 1) { args.DisplayText = CommonFunc.FormatString(@"No analysis done on script. Processing finished at {0} -- UTC -> {1} Total processing time: {2}", dtEnd.ToString(CultureInfo.CurrentUICulture), dtEnd.ToUniversalTime().ToString(CultureInfo.CurrentUICulture), tsDuration.Hours + sHour + tsDuration.Minutes.ToString(CultureInfo.CurrentUICulture) + sMin + tsDuration.Seconds.ToString(CultureInfo.CurrentUICulture) + sSecs); } else { args.DisplayText = CommonFunc.FormatString(@"Analysis completed at {0} -- UTC -> {1} Any issues discovered will be reported above. Total processing time: {2}", dtEnd.ToString(CultureInfo.CurrentUICulture), dtEnd.ToUniversalTime().ToString(CultureInfo.CurrentUICulture), tsDuration.Hours + sHour + tsDuration.Minutes.ToString(CultureInfo.CurrentUICulture) + sMin + tsDuration.Seconds.ToString(CultureInfo.CurrentUICulture) + sSecs); } args.PercentComplete = 100; updateStatus(args); return(output); }
public void GenerateScriptFromSourceServer(Server sourceServer, Database sourceDatabase, StreamWriter swTSQL, AsyncUpdateStatus updateStatus, string outputDir, ObjectSelector objectFilter) { _updateStatus = updateStatus; _smoScriptOpts = SMOScriptOptions.CreateFromConfig(); _ObjectSelector = objectFilter; //if (_smoScriptOpts.TargetServer == _smoScriptOpts.GetLocalizedStringValue("ServerType_AzureSQLDatabase")) //{ // _ObjectSelector.Assemblies.Script = false; // _ObjectSelector.SchemaCollections.Script = false; //} DateTime dtStart = DateTime.Now; AsyncNotificationEventArgs eventArgs = new AsyncNotificationEventArgs(NotificationEventFunctionCode.GenerateScriptFromSQLServer, 0, "", CommonFunc.FormatString(Properties.Resources.MessageProcessStarted, dtStart.ToString(CultureInfo.CurrentUICulture), dtStart.ToUniversalTime().ToString(CultureInfo.CurrentUICulture)) + Environment.NewLine, Color.DarkBlue); _updateStatus(eventArgs); ScriptDatabase sdb = new ScriptDatabase(); sdb.Initialize(sourceServer, sourceDatabase, _updateStatus, _smoScriptOpts, swTSQL, true); eventArgs.DisplayText = ""; eventArgs.StatusMsg = Properties.Resources.MessageSorting; eventArgs.PercentComplete = 1; _updateStatus(eventArgs); // Tables, Views, Stored Procedures, and Triggers can all have dependencies. GetSortedObjects returns // these objects in dependency order. SqlSmoObject[] smoAssemblies = GetAssemblies(sourceDatabase); SqlSmoObject[] smoPartitionFunctions = GetPartitionFunctions(sourceDatabase); SqlSmoObject[] smoPartitionSchemes = GetPartitionSchemes(sourceDatabase); SqlSmoObject[] smoTriggers = GetTriggers(sourceServer, sourceDatabase); SqlSmoObject[] smoRoles = GetRoles(sourceDatabase); SqlSmoObject[] smoSchemas = GetSchemas(sourceDatabase); SqlSmoObject[] smoSchemaCols = GetSchemaCollections(sourceServer, sourceDatabase); SqlSmoObject[] smoUDTs = GetUDTs(sourceDatabase); SqlSmoObject[] smoUDTTs = GetUDTTs(sourceDatabase); SqlSmoObject[] smoSynonyms = GetSynonyms(sourceDatabase); SqlSmoObject[] sorted = GetSortedObjects(sourceDatabase); if (Regex.IsMatch(_smoScriptOpts.ScriptDropCreate, _smoScriptOpts.GetLocalizedStringValue("SOSDrop"), RegexOptions.IgnoreCase) || Regex.IsMatch(_smoScriptOpts.ScriptDropCreate, _smoScriptOpts.GetLocalizedStringValue("SOSDropCreate"), RegexOptions.IgnoreCase)) { eventArgs.StatusMsg = Properties.Resources.MessageCreatingDropScripts; eventArgs.PercentComplete = 2; _updateStatus(eventArgs); ScriptDrops(sorted, smoRoles, smoSchemas, smoSchemaCols, smoUDTs, smoUDTTs, smoAssemblies, smoSynonyms, smoPartitionFunctions, smoPartitionSchemes, sdb); } if (Regex.IsMatch(_smoScriptOpts.ScriptDropCreate, _smoScriptOpts.GetLocalizedStringValue("SOSCreate"), RegexOptions.IgnoreCase) || Regex.IsMatch(_smoScriptOpts.ScriptDropCreate, _smoScriptOpts.GetLocalizedStringValue("SOSDropCreate"), RegexOptions.IgnoreCase)) { SourceProcessor sp = new SourceProcessor(); sp.Initialize(sdb, _smoScriptOpts, _updateStatus, eventArgs, outputDir); // Roles, Schemas, XML Schema Collections and UDT have no dependencies. Thus we process one at a time. if (!Regex.IsMatch(_smoScriptOpts.ScriptTableAndOrData, _smoScriptOpts.GetLocalizedStringValue("ScriptOptionsTableData"), RegexOptions.IgnoreCase)) { if (sp.Process(DatabaseObjectsTypes.Assemblies, smoAssemblies, 3)) { return; } if (sp.Process(DatabaseObjectsTypes.PartitionFunctions, smoPartitionFunctions, 6)) { return; } if (sp.Process(DatabaseObjectsTypes.PartitionSchemes, smoPartitionSchemes, 9)) { return; } if (sp.Process(DatabaseObjectsTypes.Roles, smoRoles, 12)) { return; } if (sp.Process(DatabaseObjectsTypes.Schemas, smoSchemas, 15)) { return; } if (sp.Process(DatabaseObjectsTypes.XMLSchemaCollections, smoSchemaCols, 20)) { return; } if (sp.Process(DatabaseObjectsTypes.UserDefinedDataTypes, smoUDTs, 25)) { return; } if (sp.Process(DatabaseObjectsTypes.UserDefinedTableTypes, smoUDTTs, 30)) { return; } if (sp.Process(DatabaseObjectsTypes.Synonyms, smoSynonyms, 35)) { return; } } if (sp.Process(sorted, 40)) { return; } if (!Regex.IsMatch(_smoScriptOpts.ScriptTableAndOrData, _smoScriptOpts.GetLocalizedStringValue("ScriptOptionsTableData"), RegexOptions.IgnoreCase)) { if (sp.Process(DatabaseObjectsTypes.Triggers, smoTriggers, 95)) { return; } } } if (swTSQL != null) { swTSQL.Flush(); swTSQL.Close(); } DateTime dtEnd = DateTime.Now; TimeSpan tsDuration = dtEnd.Subtract(dtStart); string sHour = tsDuration.Minutes == 1 ? Properties.Resources.MessageHour : Properties.Resources.MessageHours; string sMin = tsDuration.Minutes == 1 ? Properties.Resources.MessageMinute : Properties.Resources.MessageMinutes; string sSecs = tsDuration.Seconds == 1 ? Properties.Resources.MessageSecond : Properties.Resources.MessageSeconds; eventArgs.StatusMsg = Properties.Resources.Done; eventArgs.DisplayColor = Color.DarkCyan; if (_smoScriptOpts.CheckCompatibility() == 1) { eventArgs.DisplayText = CommonFunc.FormatString(Properties.Resources.MessageFinishedNoAnalysis, dtEnd.ToString(CultureInfo.CurrentUICulture), dtEnd.ToUniversalTime().ToString(CultureInfo.CurrentUICulture), tsDuration.Hours + sHour + tsDuration.Minutes.ToString(CultureInfo.CurrentUICulture) + sMin + tsDuration.Seconds.ToString(CultureInfo.CurrentUICulture) + sSecs); } else { eventArgs.DisplayText = CommonFunc.FormatString(Properties.Resources.MessageFinishedWithAnalysis, dtEnd.ToString(CultureInfo.CurrentUICulture), dtEnd.ToUniversalTime().ToString(CultureInfo.CurrentUICulture), tsDuration.Hours + sHour + tsDuration.Minutes.ToString(CultureInfo.CurrentUICulture) + sMin + tsDuration.Seconds.ToString(CultureInfo.CurrentUICulture) + sSecs); } eventArgs.PercentComplete = 100; _updateStatus(eventArgs); }