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;
            }
        }
示例#2
0
        private void SubscribeToApplicationGrid()
        {
            try
            {
                Console.WriteLine("Subscribing to Application Grid at: " + Settings.ApplicationGridEndPointURL);

                MonoscapeCredentials credentials = new MonoscapeCredentials(Settings.MonoscapeAccessKey, Settings.MonoscapeSecretKey);
                ApSubscribeNodeRequest request = new ApSubscribeNodeRequest(credentials);
                IPAddress hostIp = MonoscapeUtil.FindHostIpAddress();
                request.IpAddress = hostIp.ToString();
                request.IpAddress_ = hostIp;
                request.ApplicationGridServiceUrl = Settings.ApplicationGridServiceUrl;
                request.FileTransferServiceUrl = Settings.FileServerServiceUrl + "/wsHttp";
                IApNodeControllerService channel = EndPoints.GetApNodeControllerService();
                ApSubscribeNodeResponse response = channel.SubscribeNode(request);
                Database.Node = response.Node;

                Console.WriteLine("Subscribed successfully");
            }
            catch (EndpointNotFoundException e)
            {
                throw new MonoscapeException("Could not connect to the Application Grid", e);
            }
        }