예제 #1
0
        public CollectService()
        {
            var diContainer = new UnityContainer().CreateChildContainer();
            lock (ScheduleInitLock)
            {
                var scheduler = new Quartz.Impl.StdSchedulerFactory().GetScheduler();
                if (ScheduleController == null)
                {
                    SchedulerContainer = diContainer.CreateChildContainer();
                    scheduler.JobFactory = new UnityJobFactory(SchedulerContainer);
                    ScheduleController = new ScheduleController(scheduler);
                    ScheduleController.ReschedulingAlreadyExecuted = false;
                }

                diContainer.RegisterType<IDataProvider, DataProvider>(new ContainerControlledLifetimeManager());
                diContainer.RegisterType<ICollectRequestRepository, CollectRequestRepository>(new ContainerControlledLifetimeManager());
                diContainer.RegisterType<IProbeManager, ProbeManager>();
                diContainer.RegisterType<ICollectRequestAssembler, CollectRequestAssembler>(new ContainerControlledLifetimeManager());
                diContainer.RegisterType<ICollectPackageAssembler, CollectPackageAssembler>(new ContainerControlledLifetimeManager());
                diContainer.RegisterType<ICollectResultAssembler, CollectResultAssembler>(new ContainerControlledLifetimeManager());
                diContainer.RegisterType<IDefinitionDocumentFactory, DefinitionDocumentFactory>(new ContainerControlledLifetimeManager());
                diContainer.RegisterInstance<IScheduler>(scheduler);
                diContainer.RegisterInstance<IScheduleController>(ScheduleController);

                CollectController = diContainer.Resolve<CollectController>();
            }
        }
예제 #2
0
 /// <summary>
 /// Schedules the execution using schedule information from CollectPackage.
 /// </summary>
 /// <param name="collectPackage">The collect package.</param>
 private void ScheduleExecution(Dictionary <string, string> ids, Package collectPackage)
 {
     foreach (var collectRequest in collectPackage.CollectRequests)
     {
         var collectRequestId = ids[collectRequest.RequestId];
         var collectionDueTo  = collectPackage.ScheduleInformation.ScheduleDate;
         ScheduleController.ScheduleCollection(collectRequestId, collectRequest.Address, collectionDueTo);
         Wait();
     }
 }
예제 #3
0
 public void Should_be_possible_to_schedule_a_request_collect_in_specific_date()
 {
     var collectRequest = new CollectRequestFactory().CreateCollectRequest(DataProvider.GetSession()).Item2;
     var scheduleInformation = new ScheduleInformation() { ScheduleDate = DateTime.Now.AddSeconds(1) };
     var scheduler = new StdSchedulerFactory().GetScheduler();
     var scheduleController = new ScheduleController(scheduler) { TypeOfExecutionJob = typeof(TestJob) };
     
     scheduleController.ScheduleCollection(collectRequest.Oid.ToString(), "", scheduleInformation.ScheduleDate);
     
     Assert.AreEqual(1, scheduleController.GetNumberOfCollectRequestScheduled());
     scheduler.Shutdown();
 }
예제 #4
0
        public void Should_be_possible_get_the_collectRequestIds_that_are_executing_in_the_scheduler()
        {
            var collectRequest = new CollectRequestFactory().CreateCollectRequest(DataProvider.GetSession()).Item2;
            var scheduleInformation = new ScheduleInformation() { ScheduleDate = DateTime.Now.AddSeconds(1) };
            this.SaveCollectRequest(collectRequest);
            var scheduler = new StdSchedulerFactory().GetScheduler();
            var scheduleController = new ScheduleController(scheduler) { TypeOfExecutionJob = typeof(TestJob) };

            scheduleController.ScheduleCollection(collectRequest.Oid.ToString(), "", scheduleInformation.ScheduleDate);
            Thread.Sleep(1000);

            var collectRequestIds = scheduleController.GetCollectRequestIdRunning();
            Assert.IsTrue(collectRequestIds.Count() > 0);
            scheduler.Shutdown();
        }
예제 #5
0
        private bool IsTargetAlreadyBeingCollected(JobExecutionContext jobExecutionContext)
        {
            var candidateCollectRequestId = string.Empty;
            var candidateTargetAddress    = string.Empty;

            try
            {
                candidateCollectRequestId = jobExecutionContext.MergedJobDataMap.GetString(JobInfoFields.REQUEST_ID);
                candidateTargetAddress    = jobExecutionContext.MergedJobDataMap.GetString(JobInfoFields.TARGET_ADDRESS);
                Func <string, string, bool> requestsByTargetAddres =
                    (requestId, targetAddress) =>
                    requestId != candidateCollectRequestId && targetAddress == candidateTargetAddress;

                var schedulerController = new ScheduleController(jobExecutionContext.Scheduler);
                var allScheduledCollectionByTargetAddress =
                    schedulerController
                    .GetAllScheduledRequests()
                    .Where(req => requestsByTargetAddres(req.Key, req.Value.Key));

                if (allScheduledCollectionByTargetAddress.Count() == 0)
                {
                    return(false);
                }

                var runningCollectRequestsIds = allScheduledCollectionByTargetAddress.Select(x => x.Key);
                using (var session = Repository.GetSession())
                {
                    var collectRequestsInExecution =
                        Repository
                        .GetCollectRequests(session, runningCollectRequestsIds.ToArray())
                        .Where(req => req.Status == Contract.CollectRequestStatus.Executing);

                    return(collectRequestsInExecution.Count() > 0);
                }
            }
            catch (Exception ex)
            {
                LogError(
                    ERROR_ON_CHECKING_IF_TARGET_IS_ALREADY_BEING_COLLECTED,
                    candidateCollectRequestId,
                    candidateTargetAddress,
                    ex.Message,
                    ex.StackTrace);

                return(false);
            }
        }
예제 #6
0
        public void Should_be_possible_to_reschedule_the_collectRequest_that_was_not_collect()
        {
            var fakeSession = DataProvider.GetSession();
            var package1 = new CollectRequestFactory().CreateCollectRequest(fakeSession);
            var collectRequest = package1.Item2;
            this.SaveCollectRequest(collectRequest);
            var package2 = new CollectRequestFactory().CreateCollectRequest(fakeSession);
            var otherCollectRequest = package2.Item2;
            this.SaveCollectRequest(otherCollectRequest);
            package1.Item1.ScheduleInformation.ExecutionDate.AddSeconds(100);
            package2.Item1.ScheduleInformation.ExecutionDate.AddSeconds(100);
            var fakeRepository = new CollectRequestRepository(DataProvider);
            var scheduler = new StdSchedulerFactory().GetScheduler();
            var scheduleController = new ScheduleController(scheduler);
            scheduleController.TypeOfExecutionJob = typeof(TestJob);

            scheduleController.ReScheduleCollectRequests(
                fakeSession,
                new[] { collectRequest, otherCollectRequest },
                fakeRepository);

            Assert.AreEqual(2, scheduleController.GetNumberOfCollectRequestScheduled(), "the number of collectRequest schedule is not expected");
            scheduler.Shutdown();
        }
예제 #7
0
        public void Should_not_possible_schedule_the_collectRequest_if_already_exists_a_job_defined()
        {
            var scheduleInformation = new ScheduleInformation() { ScheduleDate = DateTime.Now.AddSeconds(1) };
            var collectRequest = new CollectRequestFactory().CreateCollectRequest(DataProvider.GetSession()).Item2;
            this.SaveCollectRequest(collectRequest);
            var scheduler = new StdSchedulerFactory().GetScheduler();
            var scheduleController = new ScheduleController(scheduler) { TypeOfExecutionJob = typeof(TestJob) };
            var collectRequestId = collectRequest.Oid.ToString();

            scheduleController.ScheduleCollection(collectRequestId, "", scheduleInformation.ScheduleDate);
            scheduleController.ScheduleCollection(collectRequestId, "", scheduleInformation.ScheduleDate);

            Assert.AreEqual(1, scheduleController.GetNumberOfCollectRequestScheduled());
            scheduler.Shutdown();
        }
예제 #8
0
        private bool IsTargetAlreadyBeingCollected(JobExecutionContext jobExecutionContext)
        {
            var candidateCollectRequestId = string.Empty;
            var candidateTargetAddress = string.Empty;
            try
            {
                candidateCollectRequestId = jobExecutionContext.MergedJobDataMap.GetString(JobInfoFields.REQUEST_ID);
                candidateTargetAddress = jobExecutionContext.MergedJobDataMap.GetString(JobInfoFields.TARGET_ADDRESS);
                Func<string, string, bool> requestsByTargetAddres =
                    (requestId, targetAddress) =>
                        requestId != candidateCollectRequestId && targetAddress == candidateTargetAddress;

                var schedulerController = new ScheduleController(jobExecutionContext.Scheduler);
                var allScheduledCollectionByTargetAddress =
                    schedulerController
                        .GetAllScheduledRequests()
                            .Where(req => requestsByTargetAddres(req.Key, req.Value.Key));
                
                if (allScheduledCollectionByTargetAddress.Count() == 0)
                    return false;

                var runningCollectRequestsIds = allScheduledCollectionByTargetAddress.Select(x => x.Key);
                using (var session = Repository.GetSession())
                {
                    var collectRequestsInExecution =
                        Repository
                            .GetCollectRequests(session, runningCollectRequestsIds.ToArray())
                            .Where(req => req.Status == Contract.CollectRequestStatus.Executing);

                    return collectRequestsInExecution.Count() > 0;
                }
            }
            catch (Exception ex)
            {
                LogError(
                    ERROR_ON_CHECKING_IF_TARGET_IS_ALREADY_BEING_COLLECTED, 
                    candidateCollectRequestId, 
                    candidateTargetAddress, 
                    ex.Message, 
                    ex.StackTrace);
                
                return false;
            }
        }