Example #1
0
 /// <summary>
 /// Execute an incoming job.
 /// </summary>
 /// <param name="methodName">The name of the procedure to be executed.</param>
 /// <param name="typeName">The name of the type held within the assembly for with the procedure to be executed resides.</param>
 /// <param name="assemblyName">The name of the assembly the procedure resides in.</param>
 /// <param name="parameter">The parameter passed to the executed procedure.</param>
 /// <returns>The result of the execution serialized for transport.</returns>
 public byte[] ExecuteIncoming(string methodName, string typeName, string assemblyName, byte[] parameter)
 {
     SerializationEngine serializer = new SerializationEngine ();
     PrestoParameter param = (PrestoParameter)serializer.Deserialize(parameter);
     Assembly assembly = assemblies[assemblyName];
     Type type = assembly.GetType(typeName, false, true);
     MethodInfo method = type.GetMethod(methodName);
     PrestoResult res = (PrestoResult)method.Invoke(null, new object[] { param });
     return serializer.Serialize(res);
 }
Example #2
0
 /// <summary>
 /// Internal execute function to be called asynchronously.
 /// </summary>
 /// <param id="state">The server state object associated with the execution.</param>
 private static void execute(ServerState state)
 {
     Interlocked.Increment(ref runningJobs);
     //get the execution context
     SerializationEngine serializer = new SerializationEngine ();
     Transfers.ExecutionContext context = (Transfers.ExecutionContext)serializer.Deserialize(state.GetDataArray());
     byte[] res = DomainManager.ExecuteIncoming(context);
     Transfers.ExecutionResult result = new Transfers.ExecutionResult(res, context.ContextID, context.DomainKey, ClusterManager.NodeID);
     state.Write(MessageType.EXECUTION_COMPLETE, serializer.Serialize(result));
     Interlocked.Decrement(ref runningJobs);
 }
Example #3
0
 /// <summary>
 /// A dispatch event to be rasied upon reception of an assembly from another Presto server..
 /// </summary>
 /// <param id="state">The server state object recieved along with this event.</param>
 private static void recieveAssemblySlave(ServerState state)
 {
     //get the slave assembly struct
     SerializationEngine serializer = new SerializationEngine ();
     SlaveAssembly slaveAssembly = (SlaveAssembly)serializer.Deserialize(state.GetDataArray());
     //create the domain and add the assembly to it
     DomainManager.CreateDomain(slaveAssembly.DomainKey);
     if(!DomainManager.DomainHasAssembly(slaveAssembly.DomainKey, slaveAssembly.AssemblyName)){
         DomainManager.LoadAssemblyIntoDomain(slaveAssembly.DomainKey, slaveAssembly.AssemblyImage);
     }
     Presto.Remote.Node from = Nodes.GetNodeByID(slaveAssembly.NodeID);
     if (from != null)
     {
         from.SetLoadedAssembly(slaveAssembly.AssemblyName);
         from.SetLoadedDomain(slaveAssembly.DomainKey);
     }
     //send back assembly transfer complete message
     state.Write(MessageType.ASSEMBLY_TRANSFER_COMPLETE);
 }
Example #4
0
 /// <summary>
 /// A verification response has been returned.
 /// </summary>
 /// <param id="state">The state object of the response.</param>
 private void verificationResponse(ClientState state)
 {
     SerializationEngine serializer = new SerializationEngine ();
     Verification vResponse = (Verification)serializer.Deserialize(state.GetDataArray());
     NodeID = vResponse.NodeID;
     HostName = vResponse.HostName;
     DPI = vResponse.DPI;
     CPUCount = vResponse.CPUCount;
     RunningJobs = vResponse.JobCount;
     TotalMemory = vResponse.TotalMemory;
     //make sure the assembly and domain listing is good
     foreach (string assembly in loadedAssemblies)
     {
         if(!loadedAssemblies.Contains(assembly)){
             loadedAssemblies.Add(assembly);
         }
     }
     foreach (string domain in loadedDomains)
     {
         if (!loadedDomains.Contains(domain))
         {
             loadedDomains.Add(domain);
         }
     }
 }
Example #5
0
 /// <summary>
 /// A distributed job has completed succesfully and this is the response.
 /// </summary>
 /// <param id="state">The state object of the response.</param>
 private void returnExecution(ClientState state)
 {
     SerializationEngine serializer = new SerializationEngine ();
     ExecutionResult res = (ExecutionResult)serializer.Deserialize(state.GetDataArray());
     DomainManager.ReturnExecution(res);
 }
Example #6
0
        /// <summary>
        /// Write the status of the cluster to the console.
        /// </summary>
        public static void status()
        {
            TcpClient client = new TcpClient();
            client.Connect("127.0.0.1", Int32.Parse(Config.GetParameter("SERVER_PORT")));
            NetworkStream stream = client.GetStream();
            byte[] messageTypeEncoded = ASCIIEncoding.ASCII.GetBytes(MessageType.STATUS_TERMINAL);
            List<byte> message = new List<byte>(BitConverter.GetBytes((long)(8)));
            message.AddRange(messageTypeEncoded);
            stream.Write(message.ToArray(), 0, message.ToArray().Length);
            byte[] messageSize = new byte[8];
            stream.Read(messageSize, 0, 8);
            long size = BitConverter.ToInt64(messageSize, 0);
            int sizeInt = (int)size;
            byte[] dataArray = new byte[sizeInt];
            stream.Read(dataArray, 0, sizeInt);
            List<byte> datas = new List<byte>(dataArray);
            datas.RemoveRange(0, 8);
            SerializationEngine serializer = new SerializationEngine();
            ServerStatus status = (ServerStatus)serializer.Deserialize(datas.ToArray());

            //Console Writes
            Console.WriteLine("Node Count: " + status.NodeCount);
            Console.WriteLine("Cluster DPI: " + status.CDPI);
            Console.WriteLine("Total CPU Count: " + status.CPUCount);
            Console.WriteLine("Total Memory: " + status.TotalMemory);
        }
Example #7
0
 /// <summary>
 /// Return an execution back into the domain.
 /// </summary>
 /// <param name="contextID">The context ID of the execution.</param>
 /// <param name="nodeID">The node ID where the execution was run.</param>
 /// <param name="result">The serialized result of the excution.</param>
 public void ReturnExecution(string contextID, ClusterNode node, byte[] result)
 {
     SerializationEngine serializer = new SerializationEngine ();
     PrestoResult resultObj = (PrestoResult)serializer.Deserialize(result);
     resultObj.ExecutionNode = node;
     Cluster.ReturnExecution(contextID, resultObj);
 }
Example #8
0
 /// <summary>
 /// Recieve a user message from a remote node.
 /// </summary>
 /// <param name="state">The server state object of this transfer.</param>
 private static void receiveMessage(ServerState state)
 {
     SerializationEngine serializer = new SerializationEngine ();
     UserMessage message = (UserMessage)serializer.Deserialize(state.GetDataArray());
     DomainManager.DeliverMessage(message);
 }