public IActionResult Get(string id)
        {
            var service = serviceQuery.Get(id);

            if (service == null)
            {
                return(new StatusCodeResult(StatusCodes.Status404NotFound));
            }
            if (service.Type != (int)ServiceTypeEnum.Search)
            {
                return(new HttpStatusCodeWithErrorResult(StatusCodes.Status400BadRequest, string.Format(ServiceResources.InvalidServiceTypeOnly_0_ServicesAreValidForThisRequest, "Search")));
            }

            SearchActivateSettings activateSettings = null;
            SearchPrepareSettings  prepareSettings  = null;

            var searchSettingsElastic = serviceQuery.GetSettings <SearchSettingsWrapperElastic>(service.Id);

            if (searchSettingsElastic != null)
            {
                prepareSettings  = searchSettingsElastic.ToSearchPrepareSettingsModel();
                activateSettings = searchSettingsElastic.ToSearchActivateSettingsModel();
            }

            var respService = service.ToServiceModel <SearchService>();

            respService.ActualProcessId  = service.ProcessIdList.FirstOrDefault(pid => GlobalStore.Processes.IsExist(pid));
            respService.ActivateSettings = activateSettings;
            respService.PrepareSettings  = prepareSettings;

            return(new OkObjectResult(respService));
        }
Exemple #2
0
        public IActionResult Get(string id)
        {
            var service = serviceQuery.Get(id);

            if (service == null)
            {
                return(new StatusCodeResult(StatusCodes.Status404NotFound));
            }
            if (service.Type != (int)ServiceTypeEnum.Classifier)
            {
                return(new HttpStatusCodeWithErrorResult(StatusCodes.Status400BadRequest, string.Format(ServiceResources.InvalidServiceTypeOnly_0_ServicesAreValidForThisRequest, "Classifier")));
            }

            ClassifierActivateSettings activateSettings = null;
            ClassifierPrepareSettings  prepareSettings  = null;

            var classifierSettingsElastic = serviceQuery.GetSettings <ClassifierSettingsElastic>(service.Id);

            if (classifierSettingsElastic != null)
            {
                if (service.Status == (int)ServiceStatusEnum.Prepared || service.Status == (int)ServiceStatusEnum.Active)
                {
                    prepareSettings = new ClassifierPrepareSettings {
                        DataSetName      = GlobalStore.DataSets.Get(classifierSettingsElastic.DataSetName).AliasName,
                        NGramList        = classifierSettingsElastic.NGramList,
                        TagIdList        = classifierSettingsElastic.Tags.Select(t => t.Id).ToList(),
                        CompressSettings = CompressHelper.ToCompressSettings(classifierSettingsElastic.CompressSettings),
                        CompressLevel    = CompressHelper.ToCompressLevel(classifierSettingsElastic.CompressSettings)
                    };
                    if (service.Status == (int)ServiceStatusEnum.Active)
                    {
                        activateSettings = new ClassifierActivateSettings
                        {
                            TagIdList           = classifierSettingsElastic.ActivatedTagIdList,
                            EmphasizedTagIdList = classifierSettingsElastic.EmphasizedTagIdList,
                            NGramList           = classifierSettingsElastic.ActivatedNGramList
                        };
                    }
                }
            }

            var respService = service.ToServiceModel <ClassifierService>();

            respService.ActualProcessId  = service.ProcessIdList.FirstOrDefault(pid => GlobalStore.Processes.IsExist(pid));
            respService.ActivateSettings = activateSettings;
            respService.PrepareSettings  = prepareSettings;

            return(new OkObjectResult(respService));
        }
Exemple #3
0
        private void WarmUpService <TServiceSettings, THandler>(ServiceTypeEnum serviceType)
            where TServiceSettings : BaseServiceSettingsElastic
            where THandler : IServiceHandler <TServiceSettings>
        {
            var services = serviceQuery.GetByType((int)serviceType).ToList();

            var handler = serviceProvider.GetService <THandler>();

            foreach (var service in services)
            {
                ProcessTypeEnum processType;
                switch (serviceType)
                {
                case ServiceTypeEnum.Classifier:
                    processType = ProcessTypeEnum.ClassifierActivate;
                    break;

                case ServiceTypeEnum.Prc:
                    processType = ProcessTypeEnum.PrcActivate;
                    break;

                case ServiceTypeEnum.Search:
                    processType = ProcessTypeEnum.SearchActivate;
                    break;

                default:
                    throw new Exception("Try to warm up service with undefined process activation type!");
                }

                if (service.Status != (int)ServiceStatusEnum.Active)
                {
                    continue;
                }

                var settings = serviceQuery.GetSettings <TServiceSettings>(service.Id);
                var process  = processHandler.Create(
                    processType,
                    service.Id,
                    service,
                    string.Format(Resources.ServiceResources.Activating_0_Service_1, serviceType, service.Name));

                service.ProcessIdList.Add(process.Id);
                serviceQuery.Update(service.Id, service);

                processHandler.Start(process, (tokenSource) => handler.Activate(process.Id, settings, tokenSource.Token));
            }
        }
        public IActionResult Get(string id)
        {
            var service = serviceQuery.Get(id);

            if (service == null)
            {
                return(new StatusCodeResult(StatusCodes.Status404NotFound));
            }
            if (service.Type != (int)ServiceTypeEnum.Prc)
            {
                return(new HttpStatusCodeWithErrorResult(StatusCodes.Status400BadRequest, string.Format(ServiceResources.InvalidServiceTypeOnly_0_ServicesAreValidForThisRequest, "Prc")));
            }

            PrcActivateSettings activateSettings = null;
            PrcPrepareSettings  prepareSettings  = null;
            PrcIndexSettings    indexSettings    = null;

            var prcSettingsElastic = serviceQuery.GetSettings <PrcSettingsElastic>(service.Id);

            if (prcSettingsElastic != null)
            {
                if (service.Status == (int)ServiceStatusEnum.Prepared || service.Status == (int)ServiceStatusEnum.Active)
                {
                    prepareSettings = new PrcPrepareSettings
                    {
                        DataSetName      = GlobalStore.DataSets.Get(prcSettingsElastic.DataSetName).AliasName,
                        TagIdList        = prcSettingsElastic.Tags.Select(t => t.Id).ToList(),
                        CompressSettings = CompressHelper.ToCompressSettings(prcSettingsElastic.CompressSettings),
                        CompressLevel    = CompressHelper.ToCompressLevel(prcSettingsElastic.CompressSettings)
                    };
                    if (service.Status == (int)ServiceStatusEnum.Active)
                    {
                        activateSettings = new PrcActivateSettings
                        {
                            FieldsForRecommendation = prcSettingsElastic.FieldsForRecommendation
                        };

                        if (prcSettingsElastic?.IndexSettings?.IndexDate != null)
                        {
                            indexSettings = new PrcIndexSettings()
                            {
                                Filter = new Filter()
                                {
                                    Query     = prcSettingsElastic.IndexSettings.FilterQuery,
                                    TagIdList = prcSettingsElastic.IndexSettings.FilterTagIdList
                                }
                            };
                        }
                    }
                }
            }

            var respService = service.ToServiceModel <PrcService>();

            respService.ActualProcessId  = service.ProcessIdList.FirstOrDefault(pid => GlobalStore.Processes.IsExist(pid));
            respService.ActivateSettings = activateSettings;
            respService.PrepareSettings  = prepareSettings;
            respService.IndexSettings    = indexSettings;

            return(new OkObjectResult(respService));
        }