Class AgentJobServiceImpl
- java.lang.Object
-
- com.netflix.genie.web.agent.services.impl.AgentJobServiceImpl
-
- All Implemented Interfaces:
AgentJobService
@Validated @Transactional public class AgentJobServiceImpl extends java.lang.Object implements AgentJobService
Default implementation ofAgentJobService
.- Since:
- 4.0.0
-
-
Constructor Summary
Constructors Constructor Description AgentJobServiceImpl(DataServices dataServices, JobResolverService jobResolverService, AgentFilterService agentFilterService, AgentConfigurationService agentConfigurationService, io.micrometer.core.instrument.MeterRegistry meterRegistry)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
claimJob(@NotBlank java.lang.String id, @Valid AgentClientMetadata agentClientMetadata)
Set a job identified byid
to be owned by the agent identified byagentClientMetadata
.JobSpecification
dryRunJobSpecificationResolution(@Valid JobRequest jobRequest)
Run the job specification resolution algorithm on the given input but save nothing in the system.java.util.Map<java.lang.String,java.lang.String>
getAgentProperties(@Valid AgentClientMetadata agentClientMetadata)
Provide configuration properties for an agent that is beginning to execute a job.JobSpecification
getJobSpecification(@NotBlank java.lang.String id)
Get a job specification if has been resolved.JobStatus
getJobStatus(@NotBlank java.lang.String id)
Retrieve the status of the job identified withid
.void
handshake(@Valid AgentClientMetadata agentClientMetadata)
Shake hands and allow a client or reject it based on the suppliedAgentClientMetadata
.java.lang.String
reserveJobId(@Valid JobRequest jobRequest, @Valid AgentClientMetadata agentClientMetadata)
Reserve a job id and persist job details in the database based on the suppliedJobRequest
.JobSpecification
resolveJobSpecification(@NotBlank java.lang.String id)
Resolve the job specification for job identified by the given id.void
updateJobArchiveStatus(@NotBlank java.lang.String id, ArchiveStatus newArchiveStatus)
Update the archive status status of the job identified withid
to benewStatus
.void
updateJobStatus(@NotBlank java.lang.String id, JobStatus currentStatus, JobStatus newStatus, java.lang.String newStatusMessage)
Update the status of the job identified withid
to benewStatus
provided that the current status of the job matchesnewStatus
.
-
-
-
Constructor Detail
-
AgentJobServiceImpl
public AgentJobServiceImpl(DataServices dataServices, JobResolverService jobResolverService, AgentFilterService agentFilterService, AgentConfigurationService agentConfigurationService, io.micrometer.core.instrument.MeterRegistry meterRegistry)
Constructor.- Parameters:
dataServices
- TheDataServices
instance to usejobResolverService
- The specification service to useagentFilterService
- The agent filter service to useagentConfigurationService
- The agent configuration servicemeterRegistry
- The metrics registry to use
-
-
Method Detail
-
handshake
public void handshake(@Valid @Valid AgentClientMetadata agentClientMetadata) throws GenieAgentRejectedException
Shake hands and allow a client or reject it based on the suppliedAgentClientMetadata
.- Specified by:
handshake
in interfaceAgentJobService
- Parameters:
agentClientMetadata
- The metadata about the agent starting to run a given job- Throws:
GenieAgentRejectedException
- If the server rejects the client based on its metadata
-
getAgentProperties
public java.util.Map<java.lang.String,java.lang.String> getAgentProperties(@Valid @Valid AgentClientMetadata agentClientMetadata)
Provide configuration properties for an agent that is beginning to execute a job.- Specified by:
getAgentProperties
in interfaceAgentJobService
- Parameters:
agentClientMetadata
- The metadata about the agent starting to run a given job- Returns:
- a map of properties for the agent
-
reserveJobId
public java.lang.String reserveJobId(@Valid @Valid JobRequest jobRequest, @Valid @Valid AgentClientMetadata agentClientMetadata)
Reserve a job id and persist job details in the database based on the suppliedJobRequest
.- Specified by:
reserveJobId
in interfaceAgentJobService
- Parameters:
jobRequest
- The job request containing all the metadata needed to reserve a job idagentClientMetadata
- The metadata about the agent driving this job request- Returns:
- The unique id of the job which was saved in the database
-
resolveJobSpecification
public JobSpecification resolveJobSpecification(@NotBlank @NotBlank java.lang.String id) throws GenieJobResolutionException, GenieJobResolutionRuntimeException
Resolve the job specification for job identified by the given id. This method will persist the job specification details to the database.- Specified by:
resolveJobSpecification
in interfaceAgentJobService
- Parameters:
id
- The id of the job to resolve the specification for. Must already have a reserved an id in the database- Returns:
- The job specification if one could be resolved
- Throws:
GenieJobResolutionException
- On error resolving the job given the input parameters and system stateGenieJobResolutionRuntimeException
- If job resolution fails due to a runtime error (as opposed to unsatisfiable constraints)
-
getJobSpecification
@Transactional(readOnly=true) public JobSpecification getJobSpecification(@NotBlank @NotBlank java.lang.String id)
Get a job specification if has been resolved.- Specified by:
getJobSpecification
in interfaceAgentJobService
- Parameters:
id
- the id of the job to retrieve the specification for- Returns:
- The job specification for the job
-
dryRunJobSpecificationResolution
@Transactional(readOnly=true) public JobSpecification dryRunJobSpecificationResolution(@Valid @Valid JobRequest jobRequest) throws GenieJobResolutionException
Run the job specification resolution algorithm on the given input but save nothing in the system.- Specified by:
dryRunJobSpecificationResolution
in interfaceAgentJobService
- Parameters:
jobRequest
- The job request containing all the metadata needed to resolve a job specification- Returns:
- The job specification that would have been resolved for the given input
- Throws:
GenieJobResolutionException
- On error resolving the job given the input parameters and system state
-
claimJob
public void claimJob(@NotBlank @NotBlank java.lang.String id, @Valid @Valid AgentClientMetadata agentClientMetadata)
Set a job identified byid
to be owned by the agent identified byagentClientMetadata
. The job status in the system will be set toJobStatus.CLAIMED
- Specified by:
claimJob
in interfaceAgentJobService
- Parameters:
id
- The id of the job to claim. Must exist in the system.agentClientMetadata
- The metadata about the client claiming the job
-
updateJobStatus
public void updateJobStatus(@NotBlank @NotBlank java.lang.String id, JobStatus currentStatus, JobStatus newStatus, @Nullable java.lang.String newStatusMessage)
Update the status of the job identified withid
to benewStatus
provided that the current status of the job matchesnewStatus
. Optionally a status message can be provided to provide more details to users. If thenewStatus
isJobStatus.RUNNING
the start time will be set. If thenewStatus
is a member ofJobStatus.getFinishedStatuses()
and the job had a started time set the finished time of the job will be set.- Specified by:
updateJobStatus
in interfaceAgentJobService
- Parameters:
id
- The id of the job to update status for. Must exist in the system.currentStatus
- The status the caller to this API thinks the job currently hasnewStatus
- The new status the caller would like to update the status tonewStatusMessage
- An optional status message to associate with this change
-
getJobStatus
public JobStatus getJobStatus(@NotBlank @NotBlank java.lang.String id)
Retrieve the status of the job identified withid
.- Specified by:
getJobStatus
in interfaceAgentJobService
- Parameters:
id
- The id of the job to look up.- Returns:
- the current status of the job, as seen by this node
-
updateJobArchiveStatus
public void updateJobArchiveStatus(@NotBlank @NotBlank java.lang.String id, ArchiveStatus newArchiveStatus)
Update the archive status status of the job identified withid
to benewStatus
. Notice this is a 'blind write', the currently persisted value will always be overwritten.- Specified by:
updateJobArchiveStatus
in interfaceAgentJobService
- Parameters:
id
- The id of the job to update status for. Must exist in the system.newArchiveStatus
- The new archive status the caller would like to update the status to
-
-