Merge branch 'melanie'

httptests
Melanie Thielker 2017-03-31 14:50:14 +01:00
commit 5587ee4500
22 changed files with 12271 additions and 100 deletions

View File

@ -359,6 +359,42 @@ namespace OpenSim.ApplicationPlugins.RemoteController
notice = false; notice = false;
} }
if (startupConfig.GetBoolean("SkipDelayOnEmptyRegion", false))
{
m_log.Info("[RADMIN]: Counting affected avatars");
int agents = 0;
if (restartAll)
{
foreach (Scene s in m_application.SceneManager.Scenes)
{
foreach (ScenePresence sp in s.GetScenePresences())
{
if (!sp.IsChildAgent && !sp.IsNPC)
agents++;
}
}
}
else
{
foreach (ScenePresence sp in rebootedScene.GetScenePresences())
{
if (!sp.IsChildAgent && !sp.IsNPC)
agents++;
}
}
m_log.InfoFormat("[RADMIN]: Avatars in region: {0}", agents);
if (agents == 0)
{
m_log.Info("[RADMIN]: No avatars detected, shutting down without delay");
times.Clear();
times.Add(0);
}
}
List<Scene> restartList; List<Scene> restartList;
if (restartAll) if (restartAll)
@ -376,10 +412,10 @@ namespace OpenSim.ApplicationPlugins.RemoteController
} }
catch (Exception e) catch (Exception e)
{ {
// m_log.ErrorFormat("[RADMIN]: Restart region: failed: {0} {1}", e.Message, e.StackTrace); m_log.ErrorFormat("[RADMIN]: Restart region: failed: {0} {1}", e.Message, e.StackTrace);
responseData["rebooting"] = false; responseData["rebooting"] = false;
throw e; throw;
} }
m_log.Info("[RADMIN]: Restart Region request complete"); m_log.Info("[RADMIN]: Restart Region request complete");

View File

@ -36,7 +36,7 @@ using MySql.Data.MySqlClient;
namespace OpenSim.Data.MySQL namespace OpenSim.Data.MySQL
{ {
/// <summary> /// <summary>
/// A database interface class to a user profile storage system /// Common code for a number of database modules
/// </summary> /// </summary>
public class MySqlFramework public class MySqlFramework
{ {
@ -44,14 +44,24 @@ namespace OpenSim.Data.MySQL
log4net.LogManager.GetLogger( log4net.LogManager.GetLogger(
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
protected string m_connectionString; protected string m_connectionString = String.Empty;
protected object m_dbLock = new object(); protected MySqlTransaction m_trans = null;
// Constructor using a connection string. Instances constructed
// this way will open a new connection for each call.
protected MySqlFramework(string connectionString) protected MySqlFramework(string connectionString)
{ {
m_connectionString = connectionString; m_connectionString = connectionString;
} }
// Constructor using a connection object. Instances constructed
// this way will use the connection object and never create
// new connections.
protected MySqlFramework(MySqlTransaction trans)
{
m_trans = trans;
}
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
// //
// All non queries are funneled through one connection // All non queries are funneled through one connection
@ -59,33 +69,48 @@ namespace OpenSim.Data.MySQL
// //
protected int ExecuteNonQuery(MySqlCommand cmd) protected int ExecuteNonQuery(MySqlCommand cmd)
{ {
lock (m_dbLock) if (m_trans == null)
{ {
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{ {
try dbcon.Open();
{ return ExecuteNonQueryWithConnection(cmd, dbcon);
dbcon.Open();
cmd.Connection = dbcon;
try
{
return cmd.ExecuteNonQuery();
}
catch (Exception e)
{
m_log.Error(e.Message, e);
m_log.Error(Environment.StackTrace.ToString());
return 0;
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return 0;
}
} }
} }
else
{
return ExecuteNonQueryWithTransaction(cmd, m_trans);
}
}
private int ExecuteNonQueryWithTransaction(MySqlCommand cmd, MySqlTransaction trans)
{
cmd.Transaction = trans;
return ExecuteNonQueryWithConnection(cmd, trans.Connection);
}
private int ExecuteNonQueryWithConnection(MySqlCommand cmd, MySqlConnection dbcon)
{
try
{
cmd.Connection = dbcon;
try
{
return cmd.ExecuteNonQuery();
}
catch (Exception e)
{
m_log.Error(e.Message, e);
m_log.Error(Environment.StackTrace.ToString());
return 0;
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return 0;
}
} }
} }
} }

View File

@ -53,14 +53,27 @@ namespace OpenSim.Data.MySQL
get { return GetType().Assembly; } get { return GetType().Assembly; }
} }
public MySQLGenericTableHandler(MySqlTransaction trans,
string realm, string storeName) : base(trans)
{
m_Realm = realm;
CommonConstruct(storeName);
}
public MySQLGenericTableHandler(string connectionString, public MySQLGenericTableHandler(string connectionString,
string realm, string storeName) : base(connectionString) string realm, string storeName) : base(connectionString)
{ {
m_Realm = realm; m_Realm = realm;
m_connectionString = connectionString;
CommonConstruct(storeName);
}
protected void CommonConstruct(string storeName)
{
if (storeName != String.Empty) if (storeName != String.Empty)
{ {
// We always use a new connection for any Migrations
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{ {
dbcon.Open(); dbcon.Open();
@ -110,6 +123,11 @@ namespace OpenSim.Data.MySQL
} }
public virtual T[] Get(string[] fields, string[] keys) public virtual T[] Get(string[] fields, string[] keys)
{
return Get(fields, keys, String.Empty);
}
public virtual T[] Get(string[] fields, string[] keys, string options)
{ {
if (fields.Length != keys.Length) if (fields.Length != keys.Length)
return new T[0]; return new T[0];
@ -126,8 +144,8 @@ namespace OpenSim.Data.MySQL
string where = String.Join(" and ", terms.ToArray()); string where = String.Join(" and ", terms.ToArray());
string query = String.Format("select * from {0} where {1}", string query = String.Format("select * from {0} where {1} {2}",
m_Realm, where); m_Realm, where, options);
cmd.CommandText = query; cmd.CommandText = query;
@ -136,73 +154,93 @@ namespace OpenSim.Data.MySQL
} }
protected T[] DoQuery(MySqlCommand cmd) protected T[] DoQuery(MySqlCommand cmd)
{
if (m_trans == null)
{
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
return DoQueryWithConnection(cmd, dbcon);
}
}
else
{
return DoQueryWithTransaction(cmd, m_trans);
}
}
protected T[] DoQueryWithTransaction(MySqlCommand cmd, MySqlTransaction trans)
{
cmd.Transaction = trans;
return DoQueryWithConnection(cmd, trans.Connection);
}
protected T[] DoQueryWithConnection(MySqlCommand cmd, MySqlConnection dbcon)
{ {
List<T> result = new List<T>(); List<T> result = new List<T>();
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) cmd.Connection = dbcon;
using (IDataReader reader = cmd.ExecuteReader())
{ {
dbcon.Open(); if (reader == null)
cmd.Connection = dbcon; return new T[0];
using (IDataReader reader = cmd.ExecuteReader()) CheckColumnNames(reader);
while (reader.Read())
{ {
if (reader == null) T row = new T();
return new T[0];
CheckColumnNames(reader); foreach (string name in m_Fields.Keys)
while (reader.Read())
{ {
T row = new T(); if (reader[name] is DBNull)
foreach (string name in m_Fields.Keys)
{ {
if (reader[name] is DBNull) continue;
{
continue;
}
if (m_Fields[name].FieldType == typeof(bool))
{
int v = Convert.ToInt32(reader[name]);
m_Fields[name].SetValue(row, v != 0 ? true : false);
}
else if (m_Fields[name].FieldType == typeof(UUID))
{
m_Fields[name].SetValue(row, DBGuid.FromDB(reader[name]));
}
else if (m_Fields[name].FieldType == typeof(int))
{
int v = Convert.ToInt32(reader[name]);
m_Fields[name].SetValue(row, v);
}
else if (m_Fields[name].FieldType == typeof(uint))
{
uint v = Convert.ToUInt32(reader[name]);
m_Fields[name].SetValue(row, v);
}
else
{
m_Fields[name].SetValue(row, reader[name]);
}
} }
if (m_Fields[name].FieldType == typeof(bool))
if (m_DataField != null)
{ {
Dictionary<string, string> data = int v = Convert.ToInt32(reader[name]);
new Dictionary<string, string>(); m_Fields[name].SetValue(row, v != 0 ? true : false);
}
foreach (string col in m_ColumnNames) else if (m_Fields[name].FieldType == typeof(UUID))
{ {
data[col] = reader[col].ToString(); m_Fields[name].SetValue(row, DBGuid.FromDB(reader[name]));
if (data[col] == null) }
data[col] = String.Empty; else if (m_Fields[name].FieldType == typeof(int))
} {
int v = Convert.ToInt32(reader[name]);
m_DataField.SetValue(row, data); m_Fields[name].SetValue(row, v);
}
else if (m_Fields[name].FieldType == typeof(uint))
{
uint v = Convert.ToUInt32(reader[name]);
m_Fields[name].SetValue(row, v);
}
else
{
m_Fields[name].SetValue(row, reader[name]);
} }
result.Add(row);
} }
if (m_DataField != null)
{
Dictionary<string, string> data =
new Dictionary<string, string>();
foreach (string col in m_ColumnNames)
{
data[col] = reader[col].ToString();
if (data[col] == null)
data[col] = String.Empty;
}
m_DataField.SetValue(row, data);
}
result.Add(row);
} }
} }
@ -357,14 +395,23 @@ namespace OpenSim.Data.MySQL
public object DoQueryScalar(MySqlCommand cmd) public object DoQueryScalar(MySqlCommand cmd)
{ {
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) if (m_trans == null)
{ {
dbcon.Open(); using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
cmd.Connection = dbcon; {
dbcon.Open();
cmd.Connection = dbcon;
return cmd.ExecuteScalar();
}
}
else
{
cmd.Connection = m_trans.Connection;
cmd.Transaction = m_trans;
return cmd.ExecuteScalar(); return cmd.ExecuteScalar();
} }
} }
} }
} }

View File

@ -212,7 +212,17 @@ namespace OpenSim.Framework
// Check that we are permitted to make calls to this endpoint. // Check that we are permitted to make calls to this endpoint.
bool foundIpv4Address = false; bool foundIpv4Address = false;
IPAddress[] addresses = Dns.GetHostAddresses(url.Host); IPAddress[] addresses = null;
try
{
addresses = Dns.GetHostAddresses(url.Host);
}
catch
{
// If there is a DNS error, we can't stop the script!
return true;
}
foreach (IPAddress addr in addresses) foreach (IPAddress addr in addresses)
{ {

View File

@ -57,6 +57,7 @@ namespace OpenSim.Framework.Servers
protected OpenSimAppender m_consoleAppender; protected OpenSimAppender m_consoleAppender;
protected FileAppender m_logFileAppender; protected FileAppender m_logFileAppender;
protected FileAppender m_statsLogFileAppender;
protected DateTime m_startuptime; protected DateTime m_startuptime;
protected string m_startupDirectory = Environment.CurrentDirectory; protected string m_startupDirectory = Environment.CurrentDirectory;
@ -156,6 +157,10 @@ namespace OpenSim.Framework.Servers
{ {
m_logFileAppender = (FileAppender)appender; m_logFileAppender = (FileAppender)appender;
} }
else if (appender.Name == "StatsLogFileAppender")
{
m_statsLogFileAppender = (FileAppender)appender;
}
} }
if (null == m_consoleAppender) if (null == m_consoleAppender)
@ -185,6 +190,18 @@ namespace OpenSim.Framework.Servers
m_log.InfoFormat("[SERVER BASE]: Logging started to file {0}", m_logFileAppender.File); m_log.InfoFormat("[SERVER BASE]: Logging started to file {0}", m_logFileAppender.File);
} }
if (m_statsLogFileAppender != null && startupConfig != null)
{
string cfgStatsFileName = startupConfig.GetString("StatsLogFile", null);
if (cfgStatsFileName != null)
{
m_statsLogFileAppender.File = cfgStatsFileName;
m_statsLogFileAppender.ActivateOptions();
}
m_log.InfoFormat("[SERVER BASE]: Stats Logging started to file {0}", m_statsLogFileAppender.File);
}
} }
/// <summary> /// <summary>

View File

@ -1192,7 +1192,7 @@ namespace OpenSim.Framework
{ {
foreach (IAppender appender in LogManager.GetRepository().GetAppenders()) foreach (IAppender appender in LogManager.GetRepository().GetAppenders())
{ {
if (appender is FileAppender) if (appender is FileAppender && appender.Name == "LogFileAppender")
{ {
return ((FileAppender)appender).File; return ((FileAppender)appender).File;
} }
@ -1201,6 +1201,19 @@ namespace OpenSim.Framework
return "./OpenSim.log"; return "./OpenSim.log";
} }
public static string statsLogFile()
{
foreach (IAppender appender in LogManager.GetRepository().GetAppenders())
{
if (appender is FileAppender && appender.Name == "StatsLogFileAppender")
{
return ((FileAppender)appender).File;
}
}
return "./OpenSimStats.log";
}
public static string logDir() public static string logDir()
{ {
return Path.GetDirectoryName(logFile()); return Path.GetDirectoryName(logFile());

View File

@ -806,6 +806,9 @@ namespace OpenSim.Region.CoreModules.Asset
return; return;
} }
catch (UnauthorizedAccessException e)
{
}
finally finally
{ {
if (stream != null) if (stream != null)

View File

@ -957,9 +957,14 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
public virtual bool IsLocalGridUser(UUID uuid) public virtual bool IsLocalGridUser(UUID uuid)
{ {
UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, uuid); lock (m_Scenes)
if (account == null || (account != null && !account.LocalToGrid)) {
return false; if (m_Scenes.Count == 0)
return true;
UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, uuid);
if (account == null || (account != null && !account.LocalToGrid))
return false;
}
return true; return true;
} }

View File

@ -2032,6 +2032,10 @@ namespace OpenSim.Region.CoreModules.World.Permissions
DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name); DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
if (m_bypassPermissions) return m_bypassPermissionsValue; if (m_bypassPermissions) return m_bypassPermissionsValue;
// A god is a god is a god
if (IsAdministrator(user))
return true;
if (objectID == UUID.Zero) // User inventory if (objectID == UUID.Zero) // User inventory
{ {
IInventoryService invService = m_scene.InventoryService; IInventoryService invService = m_scene.InventoryService;
@ -2121,6 +2125,10 @@ namespace OpenSim.Region.CoreModules.World.Permissions
DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name); DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
if (m_bypassPermissions) return m_bypassPermissionsValue; if (m_bypassPermissions) return m_bypassPermissionsValue;
// A god is a god is a god
if (IsAdministrator(user))
return true;
if (objectID == UUID.Zero) // User inventory if (objectID == UUID.Zero) // User inventory
{ {
IInventoryService invService = m_scene.InventoryService; IInventoryService invService = m_scene.InventoryService;

View File

@ -61,6 +61,8 @@ namespace OpenSim.Region.CoreModules.World.Region
protected IDialogModule m_DialogModule = null; protected IDialogModule m_DialogModule = null;
protected string m_MarkerPath = String.Empty; protected string m_MarkerPath = String.Empty;
private int[] m_CurrentAlerts = null; private int[] m_CurrentAlerts = null;
protected bool m_shortCircuitDelays = false;
protected bool m_rebootAll = false;
public void Initialise(IConfigSource config) public void Initialise(IConfigSource config)
{ {
@ -69,6 +71,9 @@ namespace OpenSim.Region.CoreModules.World.Region
{ {
m_MarkerPath = restartConfig.GetString("MarkerPath", String.Empty); m_MarkerPath = restartConfig.GetString("MarkerPath", String.Empty);
} }
IConfig startupConfig = config.Configs["Startup"];
m_shortCircuitDelays = startupConfig.GetBoolean("SkipDelayOnEmptyRegion", false);
m_rebootAll = startupConfig.GetBoolean("InworldRestartShutsDown", false);
} }
public void AddRegion(Scene scene) public void AddRegion(Scene scene)
@ -250,6 +255,14 @@ namespace OpenSim.Region.CoreModules.World.Region
private void OnTimer(object source, ElapsedEventArgs e) private void OnTimer(object source, ElapsedEventArgs e)
{ {
int nextInterval = DoOneNotice(true); int nextInterval = DoOneNotice(true);
if (m_shortCircuitDelays)
{
if (CountAgents() == 0)
{
m_Scene.RestartNow();
return;
}
}
SetTimer(nextInterval); SetTimer(nextInterval);
} }
@ -349,5 +362,35 @@ namespace OpenSim.Region.CoreModules.World.Region
{ {
} }
} }
int CountAgents()
{
m_log.Info("[RESTART MODULE]: Counting affected avatars");
int agents = 0;
if (m_rebootAll)
{
foreach (Scene s in SceneManager.Instance.Scenes)
{
foreach (ScenePresence sp in s.GetScenePresences())
{
if (!sp.IsChildAgent && !sp.IsNPC)
agents++;
}
}
}
else
{
foreach (ScenePresence sp in m_Scene.GetScenePresences())
{
if (!sp.IsChildAgent && !sp.IsNPC)
agents++;
}
}
m_log.InfoFormat("[RESTART MODULE]: Avatars in region: {0}", agents);
return agents;
}
} }
} }

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
public interface IEtcdModule
{
bool Store(string k, string v);
bool Store(string k, string v, int ttl);
string Get(string k);
void Watch(string k, Action<string> callback);
void Delete(string k);
}

View File

@ -540,6 +540,9 @@ namespace OpenSim.Region.Framework.Scenes
private Timer m_mapGenerationTimer = new Timer(); private Timer m_mapGenerationTimer = new Timer();
private bool m_generateMaptiles; private bool m_generateMaptiles;
protected int m_lastHealth = -1;
protected int m_lastUsers = -1;
#endregion Fields #endregion Fields
#region Properties #region Properties
@ -1212,6 +1215,30 @@ namespace OpenSim.Region.Framework.Scenes
StatsReporter.OnSendStatsResult += SendSimStatsPackets; StatsReporter.OnSendStatsResult += SendSimStatsPackets;
StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats; StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats;
IConfig restartConfig = config.Configs["RestartModule"];
if (restartConfig != null)
{
string markerPath = restartConfig.GetString("MarkerPath", String.Empty);
if (markerPath != String.Empty)
{
string path = Path.Combine(markerPath, RegionInfo.RegionID.ToString() + ".started");
try
{
string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString();
FileStream fs = File.Create(path);
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
Byte[] buf = enc.GetBytes(pidstring);
fs.Write(buf, 0, buf.Length);
fs.Close();
}
catch (Exception)
{
}
}
}
StartTimerWatchdog();
} }
public Scene(RegionInfo regInfo) public Scene(RegionInfo regInfo)
@ -1482,6 +1509,14 @@ namespace OpenSim.Region.Framework.Scenes
return; return;
} }
IEtcdModule etcd = RequestModuleInterface<IEtcdModule>();
if (etcd != null)
{
etcd.Delete("Health");
etcd.Delete("HealthFlags");
etcd.Delete("RootAgents");
}
m_log.InfoFormat("[SCENE]: Closing down the single simulator: {0}", RegionInfo.RegionName); m_log.InfoFormat("[SCENE]: Closing down the single simulator: {0}", RegionInfo.RegionName);
@ -1520,6 +1555,8 @@ namespace OpenSim.Region.Framework.Scenes
m_log.Debug("[SCENE]: Persisting changed objects"); m_log.Debug("[SCENE]: Persisting changed objects");
Backup(true); Backup(true);
m_log.Debug("[SCENE]: Closing scene");
m_sceneGraph.Close(); m_sceneGraph.Close();
base.Close(); base.Close();
@ -3989,7 +4026,7 @@ namespace OpenSim.Region.Framework.Scenes
if (!LoginsEnabled) if (!LoginsEnabled)
{ {
reason = "Logins Disabled"; reason = "Logins to this region are disabled";
return false; return false;
} }
@ -5512,23 +5549,24 @@ Label_GroupsDone:
return 0; return 0;
} }
if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000) if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 2000)
{ {
health+=1; health+=1;
flags |= 1; flags |= 1;
} }
if (Util.EnvironmentTickCountSubtract(m_lastIncoming) < 1000) if (Util.EnvironmentTickCountSubtract(m_lastIncoming) < 2000)
{ {
health+=1; health+=1;
flags |= 2; flags |= 2;
} }
if (Util.EnvironmentTickCountSubtract(m_lastOutgoing) < 1000) if (Util.EnvironmentTickCountSubtract(m_lastOutgoing) < 2000)
{ {
health+=1; health+=1;
flags |= 4; flags |= 4;
} }
/*
else else
{ {
int pid = System.Diagnostics.Process.GetCurrentProcess().Id; int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
@ -5541,6 +5579,7 @@ proc.WaitForExit();
Thread.Sleep(1000); Thread.Sleep(1000);
Environment.Exit(1); Environment.Exit(1);
} }
*/
if (flags != 7) if (flags != 7)
return health; return health;
@ -6305,6 +6344,32 @@ Environment.Exit(1);
public void TimerWatchdog(object sender, ElapsedEventArgs e) public void TimerWatchdog(object sender, ElapsedEventArgs e)
{ {
CheckHeartbeat(); CheckHeartbeat();
IEtcdModule etcd = RequestModuleInterface<IEtcdModule>();
int flags;
string message;
if (etcd != null)
{
int health = GetHealth(out flags, out message);
if (health != m_lastHealth)
{
m_lastHealth = health;
etcd.Store("Health", health.ToString(), 300000);
etcd.Store("HealthFlags", flags.ToString(), 300000);
}
int roots = 0;
foreach (ScenePresence sp in GetScenePresences())
if (!sp.IsChildAgent && !sp.IsNPC)
roots++;
if (m_lastUsers != roots)
{
m_lastUsers = roots;
etcd.Store("RootAgents", roots.ToString(), 300000);
}
}
} }
/// This method deals with movement when an avatar is automatically moving (but this is distinct from the /// This method deals with movement when an avatar is automatically moving (but this is distinct from the

View File

@ -376,6 +376,8 @@ namespace OpenSim.Region.Framework.Scenes
public bool m_dupeInProgress = false; public bool m_dupeInProgress = false;
internal Dictionary<UUID, string> m_savedScriptState; internal Dictionary<UUID, string> m_savedScriptState;
public UUID MonitoringObject { get; set; }
#region Properties #region Properties
/// <summary> /// <summary>

View File

@ -0,0 +1,195 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using log4net;
using Mono.Addins;
using Nini.Config;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using netcd;
using netcd.Serialization;
using netcd.Advanced;
using netcd.Advanced.Requests;
namespace OpenSim.Region.OptionalModules.Framework.Monitoring
{
/// <summary>
/// Allows to store monitoring data in etcd, a high availability
/// name-value store.
/// </summary>
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "EtcdMonitoringModule")]
public class EtcdMonitoringModule : INonSharedRegionModule, IEtcdModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
protected Scene m_scene;
protected IEtcdClient m_client;
protected bool m_enabled = false;
protected string m_etcdBasePath = String.Empty;
protected bool m_appendRegionID = true;
public string Name
{
get { return "EtcdMonitoringModule"; }
}
public Type ReplaceableInterface
{
get { return null; }
}
public void Initialise(IConfigSource source)
{
if (source.Configs["Etcd"] == null)
return;
IConfig etcdConfig = source.Configs["Etcd"];
string etcdUrls = etcdConfig.GetString("EtcdUrls", String.Empty);
if (etcdUrls == String.Empty)
return;
m_etcdBasePath = etcdConfig.GetString("BasePath", m_etcdBasePath);
m_appendRegionID = etcdConfig.GetBoolean("AppendRegionID", m_appendRegionID);
if (!m_etcdBasePath.EndsWith("/"))
m_etcdBasePath += "/";
try
{
string[] endpoints = etcdUrls.Split(new char[] {','});
List<Uri> uris = new List<Uri>();
foreach (string endpoint in endpoints)
uris.Add(new Uri(endpoint.Trim()));
m_client = new EtcdClient(uris.ToArray(), new DefaultSerializer(), new DefaultSerializer());
}
catch (Exception e)
{
m_log.DebugFormat("[ETCD]: Error initializing connection: " + e.ToString());
return;
}
m_log.DebugFormat("[ETCD]: Etcd module configured");
m_enabled = true;
}
public void Close()
{
//m_client = null;
m_scene = null;
}
public void AddRegion(Scene scene)
{
m_scene = scene;
if (m_enabled)
{
if (m_appendRegionID)
m_etcdBasePath += m_scene.RegionInfo.RegionID.ToString() + "/";
m_log.DebugFormat("[ETCD]: Using base path {0} for all keys", m_etcdBasePath);
try
{
m_client.Advanced.CreateDirectory(new CreateDirectoryRequest() {Key = m_etcdBasePath});
}
catch (Exception e)
{
m_log.ErrorFormat("Exception trying to create base path {0}: " + e.ToString(), m_etcdBasePath);
}
scene.RegisterModuleInterface<IEtcdModule>(this);
}
}
public void RemoveRegion(Scene scene)
{
}
public void RegionLoaded(Scene scene)
{
}
public bool Store(string k, string v)
{
return Store(k, v, 0);
}
public bool Store(string k, string v, int ttl)
{
Response resp = m_client.Advanced.SetKey(new SetKeyRequest() { Key = m_etcdBasePath + k, Value = v, TimeToLive = ttl });
if (resp == null)
return false;
if (resp.ErrorCode.HasValue)
{
m_log.DebugFormat("[ETCD]: Error {0} ({1}) storing {2} => {3}", resp.Cause, (int)resp.ErrorCode, m_etcdBasePath + k, v);
return false;
}
return true;
}
public string Get(string k)
{
Response resp = m_client.Advanced.GetKey(new GetKeyRequest() { Key = m_etcdBasePath + k });
if (resp == null)
return String.Empty;
if (resp.ErrorCode.HasValue)
{
m_log.DebugFormat("[ETCD]: Error {0} ({1}) getting {2}", resp.Cause, (int)resp.ErrorCode, m_etcdBasePath + k);
return String.Empty;
}
return resp.Node.Value;
}
public void Delete(string k)
{
m_client.Advanced.DeleteKey(new DeleteKeyRequest() { Key = m_etcdBasePath + k });
}
public void Watch(string k, Action<string> callback)
{
m_client.Advanced.WatchKey(new WatchKeyRequest() { Key = m_etcdBasePath + k, Callback = (x) => { callback(x.Node.Value); } });
}
}
}

View File

@ -424,6 +424,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return lease; return lease;
} }
protected SceneObjectPart MonitoringObject()
{
UUID m = m_host.ParentGroup.MonitoringObject;
if (m == UUID.Zero)
return null;
SceneObjectPart p = m_ScriptEngine.World.GetSceneObjectPart(m);
if (p == null)
m_host.ParentGroup.MonitoringObject = UUID.Zero;
return p;
}
protected virtual void ScriptSleep(int delay) protected virtual void ScriptSleep(int delay)
{ {
delay = (int)((float)delay * m_ScriptDelayFactor); delay = (int)((float)delay * m_ScriptDelayFactor);

BIN
bin/Newtonsoft.Json.dll Normal file

Binary file not shown.

8626
bin/Newtonsoft.Json.xml Normal file

File diff suppressed because it is too large Load Diff

View File

@ -39,7 +39,8 @@
<acceptOnMatch value="false"/> <acceptOnMatch value="false"/>
</filter> </filter>
<layout type="log4net.Layout.PatternLayout"> <layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level (%thread) - %logger %message%newline" /> <!-- <conversionPattern value="%date %-5level (%thread) - %logger %message%newline" /> -->
<conversionPattern value="%date %-5level %message%newline" />
</layout> </layout>
</appender> </appender>

BIN
bin/RestSharp.dll Normal file

Binary file not shown.

3024
bin/RestSharp.xml Normal file

File diff suppressed because it is too large Load Diff

BIN
bin/netcd.dll Normal file

Binary file not shown.

View File

@ -1465,6 +1465,7 @@
<Reference name="OpenMetaverse.StructuredData" path="../../../bin/"/> <Reference name="OpenMetaverse.StructuredData" path="../../../bin/"/>
<Reference name="OpenMetaverse" path="../../../bin/"/> <Reference name="OpenMetaverse" path="../../../bin/"/>
<Reference name="Mono.Data.SqliteClient" path="../../../bin/"/> <Reference name="Mono.Data.SqliteClient" path="../../../bin/"/>
<Reference name="netcd" path="../../../bin/"/>
<Reference name="OpenSim.Capabilities"/> <Reference name="OpenSim.Capabilities"/>
<Reference name="OpenSim.Framework"/> <Reference name="OpenSim.Framework"/>
<Reference name="OpenSim.Data"/> <Reference name="OpenSim.Data"/>