コード例 #1
0
        static void Main(string[] args)
        {
            PeerApi peerApi = new PeerApi("http://10.30.10.121:6162");
            var     info    = peerApi.GetHubInfo();

            System.Console.WriteLine(info.ToString());

            string output = "";

            foreach (NetworkInterface item in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (item.NetworkInterfaceType == NetworkInterfaceType.Ethernet && item.OperationalStatus == OperationalStatus.Up)
                {
                    foreach (UnicastIPAddressInformation ip in item.GetIPProperties().UnicastAddresses)
                    {
                        if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
                        {
                            output = ip.Address.ToString();
                        }
                    }
                }
            }

            var myIP = Dns.GetHostAddresses(Dns.GetHostName());

            runServer();

            var peers = peerApi.ListPeers();

            int myPeer = -1;

            for (int i = 0; i < peers.Count; i++)
            {
                if (peers[i].PeerAddr.Contains("10.30.8.5"))
                {
                    myPeer = i;
                    break;
                }
            }

            if (myPeer == -1)
            {
                return;
            }

            {
                string hash = "SHA1:213fad4e430ded42e6a949f61cf560ac96ec9878";
                DeploymentSpecImage specImg = new DeploymentSpecImage(hash, "http://10.30.8.5:6000/generatedID/test1.hdi");
                DeploymentSpec      spec    = new DeploymentSpec(EnvType.Hd, specImg, "compiler", new List <string>()
                {
                    "dupa"
                });
                var    peer  = peers[myPeer];
                string depId = peerApi.CreateDeployment(peer.NodeId, spec);
                depId = depId.Replace("\"", "");

                // Run batch file
                var results = peerApi.UpdateDeployment(peer.NodeId, depId, new List <Command>()
                {
                    new ExecCommand("Debug/golemtest.bat", new List <string>())
                });

                // Upload output.zip
                results = peerApi.UpdateDeployment(peer.NodeId, depId, new List <Command>()
                {
                    new UploadFileCommand("http://10.30.8.5:6000/generatedID/", "output.zip")
                });

                peerApi.DropDeployment(peer.NodeId, depId);
                System.Console.WriteLine(depId);
                stopServer();
                return;
            }

            //session
            {
                SessionApi sessionApi = new SessionApi("http://10.30.10.121:6162");

                //create session
                var  body      = new HubSession();
                long?sessionId = sessionApi.CreateSession(body);
                body = sessionApi.GetSession(sessionId);
                //add peer
                var res1 = sessionApi.AddSessionPeers(sessionId, new List <string>()
                {
                    peers[0].NodeId
                });
                var sPeers = sessionApi.ListSessionPeers(sessionId);
                body = sessionApi.GetSession(sessionId);
                var deploymentSpec = new DeploymentInfo();
                deploymentSpec.Name = "dupa";
                string result = sessionApi.CreateDeployment(sessionId, peers[0].NodeId, deploymentSpec);
                System.Console.WriteLine(result);
            }
        }