Example #1
0
        public bool RegisterService()
        {
            if (this.ServiceNo < 0)
            {
                throw new Exception("注册服务失败:服务号不能为负数");
            }

            StartRedirectService();

            Message msg = new Message((int)SOAMessageType.RegisterService);

            msg.MessageHeader.TransactionID = SocketApplicationComm.GetSeqNum();
            RegisterServiceRequest req = new RegisterServiceRequest();

            req.ServiceNo = this.ServiceNo;
            if (SupportTcpServiceRidrect)
            {
                req.RedirectTcpIps  = RedirectTcpServiceServer.GetBindIps();
                req.RedirectTcpPort = RedirectTcpServiceServer.GetBindTcpPort();
            }
            if (SupportUDPServiceRedirect)
            {
                req.RedirectUdpIps  = RedirectUpdServiceServer.GetBindIps();
                req.RedirectUdpPort = RedirectUpdServiceServer.GetBindUdpPort();
            }

            msg.SetMessageBody(req);

            bool boo = SendMessageAnsy <RegisterServiceResponse>(msg).IsSuccess;

            return(boo);
        }
        public async Task <string> RegisterService(RegisterServiceRequest registerServiceRequest)
        {
            var service = new Service
            {
                Id                      = DataUtil.GenerateUniqueId(),
                Name                    = registerServiceRequest.ServiceName,
                ServiceState            = ServiceState.Start,
                IpAddress               = registerServiceRequest.IpAddress,
                LoggerNotifyEnable      = registerServiceRequest.LoggerNotifyEnable,
                HealthCheckNotifyEnable = registerServiceRequest.HealthCheckNotifyEnable,
                LastCheckedDate         = DateTime.UtcNow,
                RegisteredDate          = DateTime.UtcNow,
                RunningVersion          = registerServiceRequest.Version,
                InstanceNo              = await _serviceRepository.GetLastInstanceNoOfService(registerServiceRequest.ServiceName)
            };

            service.ServiceHardwareInfo = new Entities.ServiceHardwareInfo
            {
                ServiceId        = service.Id,
                AllocationMemory = registerServiceRequest.ServiceHardwareInfo.MemoryAmount,
                Id             = DataUtil.GenerateUniqueId(),
                Directory      = registerServiceRequest.ServiceHardwareInfo.Directory,
                MachineName    = registerServiceRequest.ServiceHardwareInfo.MachineName,
                Os             = registerServiceRequest.ServiceHardwareInfo.Os,
                ProcessorCores = registerServiceRequest.ServiceHardwareInfo.ProcessorCores
            };

            service.CalculateRunningTime();

            await _serviceRepository.AddAsync(service);

            return(service.Id);
        }
        public override async Task <RegisterServiceResponse> Register(RegisterServiceRequest request, ServerCallContext context)
        {
            var result = await _serviceManagementProvider.RegisterService(request);

            return(new RegisterServiceResponse {
                Succeed = true, ServiceId = result
            });
        }
        /// <summary>
        /// Creates a new RegisterServiceRequest message.
        /// </summary>
        /// <param name="ServiceInfo">Description of the service to register.</param>
        /// <returns>RegisterServiceRequest message that is ready to be sent.</returns>
        public Message CreateRegisterServiceRequest(ServiceInfo ServiceInfo)
        {
            RegisterServiceRequest registerServiceRequest = new RegisterServiceRequest();

            registerServiceRequest.Service = ServiceInfo;

            Message res = CreateLocalServiceRequest();

            res.Request.LocalService.RegisterService = registerServiceRequest;

            return(res);
        }
Example #5
0
        /// <summary>
        /// Processes RegisterServiceRequest message from client.
        /// <para>Obtains information about the profile server's NodeProfile.</para>
        /// </summary>
        /// <param name="Client">TCP client that sent the request.</param>
        /// <param name="MessageBuilder">Client's message builder.</param>
        /// <param name="RequestMessage">Full request message.</param>
        /// <returns>Response message to be sent to the client.</returns>
        public Message ProcessMessageRegisterServiceRequest(TcpClient Client, MessageBuilderLocNet MessageBuilder, Message RequestMessage)
        {
            log.Trace("()");

            Message res = MessageBuilder.CreateRegisterServiceResponse(RequestMessage);

            RegisterServiceRequest registerServiceRequest = RequestMessage.Request.LocalService.RegisterService;

            profileServerPort = (int)registerServiceRequest.Service.Port;

            log.Trace("(-):*.Response.Status={0}", res.Response.Status);
            return(res);
        }
        /// <summary>
        /// Processes RegisterServiceRequest message from client.
        /// <para>Obtains information about the profile server's NodeProfile.</para>
        /// </summary>
        /// <param name="Client">TCP client that sent the request.</param>
        /// <param name="MessageBuilder">Client's message builder.</param>
        /// <param name="RequestMessage">Full request message.</param>
        /// <returns>Response message to be sent to the client.</returns>
        public LocProtocolMessage ProcessMessageRegisterServiceRequest(TcpClient Client, LocMessageBuilder MessageBuilder, LocProtocolMessage RequestMessage)
        {
            log.Trace("()");

            LocProtocolMessage res = MessageBuilder.CreateRegisterServiceResponse(RequestMessage);

            RegisterServiceRequest registerServiceRequest = RequestMessage.Request.LocalService.RegisterService;

            byte[] serverId = registerServiceRequest.Service.ServiceData.ToByteArray();
            if ((registerServiceRequest.Service.Type == ServiceType.Profile) && (serverId.Length == 32))
            {
                profileServer.SetNetworkId(serverId);
            }
            else
            {
                log.Error("Received register service request is invalid.");
            }

            log.Trace("(-):*.Response.Status={0}", res.Response.Status);
            return(res);
        }
Example #7
0
 public void Start(Action postAction)
 {
     try
     {
         var registerServiceRequest = new RegisterServiceRequest
         {
             ServiceName             = _serviceOptions.CurrentValue.Name,
             Version                 = _serviceOptions.CurrentValue.Version,
             LoggerNotifyEnable      = _loggerOptions.CurrentValue.NotifyOptions.Enable,
             HealthCheckNotifyEnable = _monitorOptions.CurrentValue.Enable,
             ServiceHardwareInfo     = new ServiceHardwareInfo
             {
                 Directory      = Environment.CurrentDirectory,
                 Environment    = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"),
                 Os             = Environment.OSVersion.VersionString,
                 MachineName    = Environment.MachineName,
                 ProcessorCores = Environment.ProcessorCount,
                 MemoryAmount   = Environment.WorkingSet
             }
         };
         var response = _monitorServiceClient.Register(registerServiceRequest);
         if (response.Succeed)
         {
             serviceId = response.ServiceId;
             if (postAction != null)
             {
                 postAction.Invoke();
             }
         }
         else
         {
             throw new MicroserviceClientException(MicroserviceClientCodes.FailedRegisterFromServer);
         }
     }
     catch (Exception ex)
     {
         throw new Exception("There are some erros when trying to connect Service Management, please check stack trace.", ex);
     }
 }
        public void Start(Action postAction)
        {
            var registerServiceRequest = new RegisterServiceRequest
            {
                ServiceName             = _selfOptions.ServerName,
                Version                 = runningVersion,
                LoggerNotifyEnable      = _loggerOptions.CurrentValue.NotifyOptions.Enable,
                HealthCheckNotifyEnable = _monitorOptions.CurrentValue.Enable,
                ServiceHardwareInfo     = new ServiceHardwareInfo
                {
                    Directory      = Environment.CurrentDirectory,
                    Environment    = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"),
                    Os             = Environment.OSVersion.VersionString,
                    MachineName    = Environment.MachineName,
                    ProcessorCores = Environment.ProcessorCount,
                    MemoryAmount   = Environment.WorkingSet
                }
            };
            var selfRegisterTask = _serviceManagementProvider.RegisterService(registerServiceRequest);

            selfRegisterTask.Wait();
            serviceId = selfRegisterTask.Result;
            Console.WriteLine("Self Server Id " + serviceId);
        }
Example #9
0
 public ActionResult Register([FromBody] RegisterServiceRequest request)
 {
     return(StatusCode(501));
 }