Ejemplo n.º 1
0
            internal void threadproc()
            {
                try
                {
                    string reason;
                    if (!Surrogate.IsHealthySlaveMachine(SlaveHost, out reason))
                    {
                        if (explicithost)
                        {
                            throw new Exception("Remote cannot connect to explicit host '" + SlaveHost + "': " + reason);
                        }

                        /*if (!failoverenabled)
                         * {
                         *  throw new Exception("Remote cannot connect to host '" + SlaveHost + "': " + reason);
                         * }
                         * else*/
                        {
                            SlaveHost = null;
                            int startsi = (new Random(DateTime.Now.Millisecond / (BlockID + 2))).Next() % slaves.Count;
                            for (int i = startsi; i < slaves.Count; i++)
                            {
                                if (Surrogate.IsHealthySlaveMachine(slaves[i], out reason))
                                {
                                    SlaveHost = slaves[i];
                                    rem.OutputStartingPoint = i;
                                    break;
                                }
                            }
                            if (null == SlaveHost)
                            {
                                for (int i = 0; i < startsi; i++)
                                {
                                    if (Surrogate.IsHealthySlaveMachine(slaves[i], out reason))
                                    {
                                        SlaveHost = slaves[i];
                                        rem.OutputStartingPoint = i;
                                        break;
                                    }
                                }
                                if (null == SlaveHost)
                                {
                                    throw new Exception("Remote cannot connect to any hosts; last reason: " + reason);
                                }
                            }
                        }
                    }
                    SlaveIP = IPAddressUtil.GetIPv4Address(SlaveHost); // !

                    rem.SetJID(jid, CurrentJobFileName + " Remote: " + cfgj.NarrativeName);
                    rem.AddBlock(SlaveIP + @"|"
                                 + (cfgj.ForceStandardError != null ? "&" : "") + logname + @"|slaveid=0");

                    string codectx = (@"
    public const int DSpace_BlockID = " + BlockID.ToString() + @";
    public const int DSpace_ProcessID = DSpace_BlockID;
    public const int Qizmt_ProcessID = DSpace_ProcessID;

    public const int DSpace_BlocksTotalCount = " + blockcount.ToString() + @";
    public const int DSpace_ProcessCount = DSpace_BlocksTotalCount;
    public const int Qizmt_ProcessCount = DSpace_ProcessCount;

    public const string DSpace_SlaveHost = `" + SlaveHost + @"`;
    public const string DSpace_MachineHost = DSpace_SlaveHost;
    public const string Qizmt_MachineHost = DSpace_MachineHost;

    public const string DSpace_SlaveIP = `" + SlaveIP + @"`;
    public const string DSpace_MachineIP = DSpace_SlaveIP;
    public const string Qizmt_MachineIP = DSpace_MachineIP;

    public static readonly string[] DSpace_ExecArgs = new string[] { " + ExecArgsCode(ExecArgs) + @" };
    public static readonly string[] Qizmt_ExecArgs = DSpace_ExecArgs;
    
    public const string DSpace_OutputFilePath = `" + DFSWriter + @"`; // Includes `dfs://` if in DFS.
    public const string Qizmt_OutputFilePath = DSpace_OutputFilePath;

    public static int DSpace_InputRecordLength { get { return MySpace.DataMining.DistributedObjects.StaticGlobals.DSpace_InputRecordLength; } }
    public static int Qizmt_InputRecordLength { get { return MySpace.DataMining.DistributedObjects.StaticGlobals.DSpace_InputRecordLength; } }

    public static int DSpace_OutputRecordLength { get { return MySpace.DataMining.DistributedObjects.StaticGlobals.DSpace_OutputRecordLength; } }
    public static int Qizmt_OutputRecordLength { get { return MySpace.DataMining.DistributedObjects.StaticGlobals.DSpace_OutputRecordLength; } }

    public const string Qizmt_Meta = @`" + Meta + @"`;

const string _userlogname = `" + logname + @"`;
static System.Threading.Mutex _logmutex = new System.Threading.Mutex(false, `distobjlog`);

    static string Shell(string line, bool suppresserrors)
    {
        return MySpace.DataMining.DistributedObjects.Exec.Shell(line, suppresserrors);
    }


    static string Shell(string line)
    {
        return MySpace.DataMining.DistributedObjects.Exec.Shell(line, false);
    }

private static int userlogsremain = " + AELight.maxuserlogs.ToString() + @";
public static void Qizmt_Log(string line) { DSpace_Log(line); }
public static void DSpace_Log(string line)
{
    if(--userlogsremain < 0)
    {
        return;
    }
    try
    {
        _logmutex.WaitOne();
    }
    catch (System.Threading.AbandonedMutexException)
    {
    }
    try
    {
        using (System.IO.StreamWriter fstm = System.IO.File.AppendText(_userlogname))
        {
            fstm.WriteLine(`{0}`, line);
        }
    }
    finally
    {
        _logmutex.ReleaseMutex();
    }
}

public static void Qizmt_LogResult(string line, bool passed) { DSpace_LogResult(line, passed); }
public static void DSpace_LogResult(string name, bool passed)
{
    if(passed)
    {
        DSpace_Log(`[\u00012PASSED\u00010] - ` + name);
    }
    else
    {
        DSpace_Log(`[\u00014FAILED\u00010] - ` + name);
    }
}

").Replace('`', '"') + CommonDynamicCsCode;


                    List <string> outputbasenames = new List <string>(DFSWriters.Count);
                    foreach (string writer in DFSWriters)
                    {
                        string dfsname = writer;
                        if (dfsname.StartsWith("dfs://", StringComparison.OrdinalIgnoreCase))
                        {
                            dfsname = dfsname.Substring(6);
                        }
                        outputbasenames.Add(GenerateZdFileDataNodeBaseName(dfsname));
                    }

                    rem.Open();

                    outputsizes      = new List <long>();
                    outputsizeses    = new List <List <long> >();
                    outputdfsnodeses = new List <List <string> >();
                    rem.RemoteExec(dfsinputpaths, outputdfsdirs, outputbasenames, baseoutputfilesize, codectx + cfgj.Remote, cfgj.Usings, outputsizeses, outputdfsnodeses, dfsinputfilenames, dfsinputnodesoffsets);

                    blockfail = false; // !

                    if (verbose)
                    {
                        Console.Write('*');
                        ConsoleFlush();
                    }
                }
                catch (Exception e)
                {
                    LogOutput("RemoteBlockInfo.threadproc exception: " + e.ToString());
                }
            }