Ejemplo n.º 1
0
    void InitButtonClicked()
    {
        Pitaya.Logger.SetLevel(LogLevel.DEBUG);
        Console.WriteLine("c# prog running");

        SDConfig            sdConfig        = new SDConfig("127.0.0.1:2379", 30, "pitaya/", 30, true, 60);
        NatsRPCClientConfig rpcClientConfig = new NatsRPCClientConfig("nats://localhost:4222", 10, 5000);
        // TODO does it makes sense to give freedom to set reconnectionRetries and messagesBufferSize?
        NatsRPCServerConfig rpcServerConfig = new NatsRPCServerConfig("nats://localhost:4222", 10, 75);

        PitayaCluster.Init(
            sdConfig,
            rpcClientConfig,
            rpcServerConfig,
            new Server(
                System.Guid.NewGuid().ToString(),
                "unity",
                "{\"ip\":\"127.0.0.1\"}",
                false)
            );

        TestRemote tr = new TestRemote();

        PitayaCluster.RegisterRemote(tr);
    }
    private void Init()
    {
        Debug.Log("Init button clicked!");

        NPitaya.Models.Logger.SetLevel(LogLevel.DEBUG);
        Console.WriteLine("c# prog running");

        string serverId = Guid.NewGuid().ToString();

        var sdConfig = new SDConfig(
            endpoints: "http://10.0.21.167:2379",
            etcdPrefix: "pitaya/",
            serverTypeFilters: new List <string>(),
            heartbeatTTLSec: 60,
            logHeartbeat: false,
            logServerSync: true,
            logServerDetails: false,
            syncServersIntervalSec: 60,
            maxNumberOfRetries: 10,
            retryDelayMilliseconds: 100);

        var grpcConfig = new GrpcConfig(
            host: "127.0.0.1",
            port: 3000,
            serverShutdownDeadlineMs: 3000,
            serverMaxNumberOfRpcs: 1000,
            clientRpcTimeoutMs: 4000
            );

        var sv = new Server(
            serverId,
            "csharp",
            "{\"ip\":\"127.0.0.1\"}",
            "localhost",
            false);

        var nc = new NatsConfig(
            endpoint: "127.0.0.1:4222",
            connectionTimeoutMs: 2000,
            requestTimeoutMs: 2000,
            serverShutdownDeadlineMs: 4000,
            serverMaxNumberOfRpcs: 1000,
            maxConnectionRetries: 10,
            maxPendingMessages: 100,
            reconnectBufSize: 4 * 1024 * 1024);

        Debug.Log("Adding signal handler");
        Debug.Log("Adding signal handler DONE");

        try
        {
            Debug.Log("Initializing PitayaCluster");
            // PitayaCluster.Initialize(sdConfig, nc, sv);

            var listener = new PitayaCluster.ServiceDiscoveryListener((action, server) =>
            {
                switch (action)
                {
                case PitayaCluster.ServiceDiscoveryAction.ServerAdded:
                    Debug.Log("Server added:");
                    Debug.Log("    id:  " + server.id);
                    Debug.Log("    type:" + server.type);
                    break;

                case PitayaCluster.ServiceDiscoveryAction.ServerRemoved:
                    Debug.Log("Server removed:");
                    Debug.Log("    id:  " + server.id);
                    Debug.Log("    type:" + server.type);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(action), action, null);
                }
            });
                    #if UNITY_EDITOR
            PitayaCluster.Initialize(nc, sdConfig, sv, NativeLogLevel.Debug, listener, "MY_LOG_FILE.txt");
                    #else
            PitayaCluster.Initialize(grpcConfig, sdConfig, sv, NativeLogLevel.Debug, listener);
            #endif
        }
        catch (PitayaException e)
        {
            Debug.LogError($"Failed to create cluster {e.Message}");
            Application.Quit();
            return;
        }

        NPitaya.Models.Logger.Info("pitaya lib initialized successfully :)");

        var tr = new TestRemote();
        PitayaCluster.RegisterRemote(tr);
    }
Ejemplo n.º 3
0
        public static void ExecOneTest(SourceCode.Job cfgj, string[] ExecArgs, bool verbose)
        {
            if (verbose)
            {
                Console.WriteLine("[{0}]        [Test: {2}]", System.DateTime.Now.ToString(), System.DateTime.Now.Millisecond, cfgj.NarrativeName);
            }

            //string SlaveIP = IPAddressUtil.GetIPv4Address(cfgj.IOSettings.LocalHost);

            int BlockID = 0;

            string logname = Surrogate.SafeTextPath(cfgj.NarrativeName) + "_" + Guid.NewGuid().ToString() + ".j" + sjid + "_log.txt";

            try
            {
                string     outputguid     = Guid.NewGuid().ToString();
                TestRemote dobj           = new TestRemote(cfgj.NarrativeName + "_test");
                string     outputfilename = outputguid + ".local";
                dobj.SetJID(jid, CurrentJobFileName + " Test: " + cfgj.NarrativeName);
                dobj.AddBlock(@"127.0.0.1|" + outputfilename + @".log|slaveid=0");
                string codectx = (@"
    public const int DSpace_BlockID = 0;
    public const int DSpace_ProcessID = DSpace_BlockID;
    public const int Qizmt_ProcessID = DSpace_ProcessID;

    public const int DSpace_BlocksTotalCount = 1;
    public const int DSpace_ProcessCount = DSpace_BlocksTotalCount;
    public const int Qizmt_ProcessCount = DSpace_ProcessCount;

    public const string DSpace_SlaveHost = `localhost`;
    public const string DSpace_MachineHost = DSpace_SlaveHost;
    public const string Qizmt_MachineHost = DSpace_MachineHost;

    public const string DSpace_SlaveIP = `127.0.0.1`;
    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_ExecDir = @`" + System.Environment.CurrentDirectory + @"`;
    public const string Qizmt_ExecDir = DSpace_ExecDir;


    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);
    }


    public static void Qizmt_Log(string line) { DSpace_Log(line); }
    public static void DSpace_Log(string line)
    {
        Console.WriteLine(line);
    }

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

").Replace('`', '"') + MySpace.DataMining.DistributedObjects.CommonCs.CommonDynamicCsCode;
                dobj.LocalExec(codectx + "\r\n" + cfgj.Test, cfgj.Usings, "Test");
                string fullsource = dobj.RemoteSource;

                System.Reflection.Assembly asm = null;
                try
                {
                    dobj.CompilePluginSource(fullsource, true, ref asm);
                }
                catch (BadImageFormatException)
                {
                }
                // dobj.RemoteClassName is of type IRemote

                MySpace.DataMining.DistributedObjects.IRemote iface = _LoadPluginInterface <MySpace.DataMining.DistributedObjects.IRemote>(asm, dobj.RemoteClassName);
                iface.OnRemote(); // !

                if (verbose)
                {
                    Console.Write('*');
                    ConsoleFlush();
                }
            }
            finally
            {
                //CheckUserLogs(new string[] { SlaveIP }, logname);
            }

            if (verbose)
            {
                Console.WriteLine();
                Console.WriteLine("[{0}]        Done", System.DateTime.Now.ToString(), System.DateTime.Now.Millisecond);
            }
        }