Esempio n. 1
0
        public static INcApplicationGridService GetNcApplicationGridService(Node node)
        {
            try
            {
                string serviceUrl = node.ApplicationGridServiceUrl;
                string hostIpAddress = MonoscapeUtil.FindHostIpAddress().ToString();
                if (node.IpAddress.Equals(hostIpAddress) && (serviceUrl.Contains(node.IpAddress)))
                {
                    Log.Debug(typeof(EndPoints), "Node " + node.ToString() + " is running on the same host as the Application Grid");
                    serviceUrl.Replace(node.IpAddress, "localhost");
                }

                Log.Debug(typeof(EndPoints), "Creating INcApplicationGridService channel to node: " + serviceUrl);
                var binding = MonoscapeServiceHost.GetBinding();
                var address = new EndpointAddress(serviceUrl);
                ChannelFactory<INcApplicationGridService> factory = new ChannelFactory<INcApplicationGridService>(binding, address);
                INcApplicationGridService channel = factory.CreateChannel();
                return channel;
            }
            catch (Exception e)
            {
                MonoscapeException me = new MonoscapeException("Could not connect to the node", e);
                Log.Error(typeof(EndPoints), me);
                throw me;
            }
        }
Esempio n. 2
0
        private void UploadApplicationToNode(int applicationId, Node node)
        {
            Log.Debug(this, "Uploading application " + applicationId + " to node " + node.ToString());

            Application app = FindApplication(applicationId);
            if (app != null)
            {
                string filePath = Path.Combine(Settings.ApplicationStorePath, app.FileName);
                if (File.Exists(filePath))
                {
                    Log.Debug(this, "Transferring application package...");
                    NcFileTransferSocket socket = new NcFileTransferSocket(node.IpAddress_, Settings.NcFileTransferSocketPort);
                    socket.SendFile(filePath);

                    Log.Debug(this, "Transferring application data...");
                    NcAddApplicationRequest request = new NcAddApplicationRequest(Credentials);
                    request.Application = app;
                    EndPoints.GetNcApplicationGridService(node).AddApplication(request);
                }
                else
                {
                    throw new MonoscapeException("File not found: " + app.FileName);
                }
            }
            else
            {
                throw new MonoscapeException("Application not found: " + app.Name);
            }
        }
        public ApSubscribeNodeResponse SubscribeNode(ApSubscribeNodeRequest request)
        {
            Log.Debug(typeof(ApNodeControllerService), "SubscribeNode()");

            try
            {
                // Remove existing node instance if already subscribed
                Node existing = Database.GetInstance().Nodes.Find(x => x.IpAddress.Equals(request.IpAddress));
                if (existing != null)
                    Database.GetInstance().Nodes.Remove(existing);

                Node node = new Node();
                // Initialize Node Id
                // Multiple nodes may exist in the same host
                node.Id = GetNextNodeId();

                // Initialize node IP Address
                node.IpAddress = request.IpAddress;
                node.IpAddress_ = request.IpAddress_;

                // Find node's virtual machine instance id from IaaS
                node.InstanceId = FindInstanceId(request.IpAddress);

                node.ApplicationGridServiceUrl = request.ApplicationGridServiceUrl;
                node.FileTransferServiceUrl = request.FileTransferServiceUrl;
                node.SubscribedOn = DateTime.Now;

                // Update database
                Database.GetInstance().Nodes.Add(node);

                ApSubscribeNodeResponse response = new ApSubscribeNodeResponse();
                // Send node information back
                response.Node = node;

                Log.Debug(typeof(ApNodeControllerService), "Node " + node.ToString() + " subscribed successfully");
                return response;
            }
            catch (Exception e)
            {
                Log.Error(this, e);
                throw e;
            }
        }