private void AcknowledgeJob(FJobResourceConfirmation fJobResourceConfirmation) { _jobConfirmation = fJobResourceConfirmation.JobConfirmation; //Clear all previous states _resourceDistinctResourceStates.Clear(); Agent.DebugMessage($"AcknowledgeJob: Clear _resourceSetupStates _resourceProcessingStates _resourceDistinctResourceStates", CustomLogger.JOBSTATE, LogLevel.Warn); Agent.DebugMessage($"Acknowledge Proposal {_jobConfirmation.Job.Name} received", CustomLogger.PROPOSAL, LogLevel.Warn); foreach (var resourceScope in fJobResourceConfirmation.ScopeConfirmations) { var resourceRef = resourceScope.Key; var _jobConfirmationForResource = ((FJobConfirmation)_jobConfirmation).UpdateScopeConfirmation(resourceScope.Value); Agent.Send(instruction: Resource.Instruction.Default.AcceptedProposals.Create(_jobConfirmationForResource, target: resourceRef)); if (resourceScope.Value.Scopes.Length > 1) { _resourceDistinctResourceStates.Add(resourceScope.Key, new StateHandle(JobState.InQueue, true, true)); } else { switch (resourceScope.Value.Scopes.First()) { case FSetupSlot fs: _resourceDistinctResourceStates.Add(resourceScope.Key, new StateHandle(JobState.InQueue, true, false)); break; case FProcessingSlot ps: _resourceDistinctResourceStates.Add(resourceScope.Key, new StateHandle(JobState.InQueue, false, true)); break; default: throw new Exception("Wrong state implementation send."); } } } }
internal void ProposalFromResource(FProposal fProposal) { // get related operation and add proposal. var jobConfirmation = _bucketManager.GetConfirmationByBucketKey(fProposal.JobKey); if (jobConfirmation == null) { return; } var bucket = jobConfirmation.Job as FBucket; var resourceAgent = fProposal.ResourceAgent as IActorRef; var required = _proposalManager.AddProposal(fProposal, Agent.Sender); var schedules = fProposal.PossibleSchedule as List <FQueueingScope>; var propSet = _proposalManager.GetProposalForSetupDefinitionSet(fProposal.JobKey); Agent.DebugMessage(msg: $"Proposal({propSet.ReceivedProposals} of {propSet.RequiredProposals}) " + $"for {bucket.Name} {bucket.Key} with Schedule: {schedules.First().Scope.Start} " + $"JobKey: {fProposal.JobKey} from: {resourceAgent.Path.Name}!", CustomLogger.PROPOSAL, LogLevel.Warn); // if all resources replied if (propSet.AllProposalsReceived) { // item Postponed by All resources ? -> requeue after given amount of time. var proposalForCapabilityProvider = propSet.GetValidProposal(); if (proposalForCapabilityProvider.Count == 0) { var postponedFor = propSet.PostponedFor; _proposalManager.RemoveAllProposalsFor(bucket.Key); Agent.Send(instruction: Hub.Instruction.BucketScope.EnqueueBucket.Create(bucket.Key, target: Agent.Context.Self), waitFor: postponedFor); Agent.DebugMessage($"{bucket.Name} {bucket.Key} has been postponed for {postponedFor}", CustomLogger.PROPOSAL, LogLevel.Warn); return; } List <PossibleProcessingPosition> possibleProcessingPositions = _proposalManager.CreatePossibleProcessingPositions(proposalForCapabilityProvider, bucket); if (possibleProcessingPositions.Count == 0) { _proposalManager.RemoveAllProposalsFor(bucket.Key); //TODO check wether this can be adjustable var postponedFor = (long)(bucket.MaxBucketSize * 0.5); Agent.Send(instruction: Hub.Instruction.BucketScope.EnqueueBucket.Create(bucket.Key, target: Agent.Context.Self), waitFor: postponedFor); return; } var possiblePosition = possibleProcessingPositions.OrderBy(x => x._processingPosition).First(); jobConfirmation.CapabilityProvider = possiblePosition.ResourceCapabilityProvider; var jobResourceConfirmation = new FJobResourceConfirmation(jobConfirmation.ToImmutable(), new Dictionary <IActorRef, FScopeConfirmation>()); var setups = jobConfirmation.CapabilityProvider.ResourceSetups.Where(x => x.Resource.IsPhysical).ToList(); foreach (var setup in setups) { var resourceRef = setup.Resource.IResourceRef as IActorRef; var(actorRef, pos) = possiblePosition._queuingDictionary.FirstOrDefault(x => x.Key.Equals(setup.Resource.IResourceRef)); if (pos == null) { continue; } jobResourceConfirmation.ScopeConfirmations.Add(resourceRef, pos); } Agent.Send(Job.Instruction.AcknowledgeJob.Create(jobResourceConfirmation, jobConfirmation.JobAgentRef)); Agent.DebugMessage($"Send Acknwoledge Job for {jobResourceConfirmation.JobConfirmation.Job.Name}" , CustomLogger.PROPOSAL, LogLevel.Warn); _proposalManager.Remove(bucket.Key); } }
public static AcknowledgeJob Create(FJobResourceConfirmation message, IActorRef target) { return(new AcknowledgeJob(message: message, target: target)); }