com.trendmicro.grid.acl.l0
Interface ProcessingService

All Superinterfaces:
Service

@ProcessingContext
@WebServlet(value="/ws/level-0/internal/processing")
public interface ProcessingService
extends Service

Defines TM reachable services to control the processing inside the GRID.

Version:
1.0
Author:
Juergen_Kellerer, 2010-04-23

Method Summary
 URL assignContentToProcessSource(SourceIdentifier sourceIdentifier)
          Returns a public reachable transfer URL that may be used to upload (HTTP-PUT) the binary content of the source.
 void assignExistingContentToProcessSource(SourceIdentifier sourceIdentifier, FileIdentifier contentIdentifier)
          Allows to assign content that is known to exist already inside the GRID avoiding any new uploads.
 SourceIdentifier assignProcessSource(UUID jobId, URI remoteSourceURI, Date lastModified, String contentTag, com.trendmicro.grid.acl.metadata.Metadata metadata)
          Adds or updates the remote source with the given Metadata, assigns it to a single processing job and returns the source identifier which may be used to upload source content if required.
 URL assignProcessSourceWithContent(UUID jobId, FileIdentifier contentIdentifier, URI remoteSourceURI, Date lastModified, String contentTag, com.trendmicro.grid.acl.metadata.Metadata metadata)
          Adds or updates the remote source with the given Metadata, assigns it to a single processing job and directly returns an upload URL if GRID does not yet know the content.
 void cancelPerparedJob(UUID jobId)
          Cancells the given job if it is still in prepared state.
 UUID cloneAndStartJob(UUID originalJobId)
          Clones the given job and starts the clone.
 void enforceStartJob(UUID jobId)
          Starts a prepared processing job after preparation was finished.
 List<Source> getAssignedSources(UUID jobId)
          Retrieves all sources that are currently assigned to the given job.
 Job getJob(UUID job)
          Returns the read & writable information on a job, identified by its id.
 JobDetails getJobDetails(UUID job)
          Returns the detailed information on a job, identified by its id.
 Collection<Job> getJobs(Collection<UUID> jobIds)
          Returns the read & writable information on the jobs, identified by their ids.
 UUIDListPage getJobsInState(Job.State jobState, int pageNumber)
          Returns a paged list of jobs that are in the given state.
 UUIDListPage getJobsInStateAndRange(Job.State jobState, DaysRange lastUpdatedRange, int pageNumber)
          Returns a paged list of jobs that are in the given state and were last updated within the given range.
 Collection<Job.State> getJobStates(Collection<UUID> jobIds)
          Returns the states of the jobs, identified by their ids.
 UUIDListPage getRunningJobs(int pageNumber)
          Returns a paged list of running jobs.
 UUID prepareJob()
          Prepares a new processing job and returns the job's GUID.
 UUID prepareSubJob(UUID parentJobId)
          Prepares a new processing job and returns the job's GUID.
 void setJobPriority(UUID jobId, int jobPriority)
          Sets the priority of a prepared job.
 void startJob(UUID jobId)
          Starts a prepared processing job after preparation was finished.
 UUID startReprocessingJob(FileIdentifier contentIdentifier, boolean assignAllExistingSources, int jobPriority)
          Initiates a reprocessing job on the given file and returns the job GUID for monitoring the progress.
 UUID startReprocessingJobWithSources(FileIdentifier contentIdentifier, Collection<SourceIdentifier> selectedSourceIdentifiers, int jobPriority)
          Initiates a reprocessing job on the given file and returns the job GUID for monitoring the progress.
 void storeProcessingResultsAndFinalizeJobs(Collection<ProcessPackageDataSet> processingResults)
          Receives a collection of final processing results, stores them inside the GRID CoreDB and performs the final update on the assigned jobs.
 void updateJob(Job job)
          Updates the given job inside the persistent store (= the database)
 

Method Detail

prepareJob

@RequiredRoles(value={"access.protected.services","process.content"})
UUID prepareJob()
                throws AuthenticationException
Prepares a new processing job and returns the job's GUID.

Returns:
The GUID of the job.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.

prepareSubJob

@RequiredRoles(value={"access.protected.services","process.content"})
UUID prepareSubJob(UUID parentJobId)
                   throws AuthenticationException
Prepares a new processing job and returns the job's GUID.

Parameters:
parentJobId - the GUID of the parent job.
Returns:
The GUID of the job.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.

cancelPerparedJob

@RequiredRoles(value={"access.protected.services","process.content"})
void cancelPerparedJob(UUID jobId)
                       throws AuthenticationException,
                              IllegalRequestException
Cancells the given job if it is still in prepared state.

Parameters:
jobId - The id of the job to cancel.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.
IllegalRequestException - In case of the job ID is invalid or the job is not in prepared state.

setJobPriority

@RequiredRoles(value={"access.protected.services","process.content"})
void setJobPriority(UUID jobId,
                                       int jobPriority)
                    throws AuthenticationException,
                           IllegalRequestException
Sets the priority of a prepared job.

Parameters:
jobId - The id of the job to modify.
jobPriority - the priority of the job as an integer value between 1 <= x <= 7. 1 is the lowest priority, 7 the highest and 4 is the default value.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.
IllegalRequestException - In case of the job is not in prepared state.

startJob

@RequiredRoles(value={"access.protected.services","process.content"})
void startJob(UUID jobId)
              throws AuthenticationException,
                     IllegalRequestException
Starts a prepared processing job after preparation was finished.

Note: Jobs are started when sources were assigned and when the source information contains any changes when compared to the information that exists inside the GRID.

Parameters:
jobId - The id of the job to start.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.
IllegalRequestException - In case of the job ID is invalid or the job has no assigned sources.

enforceStartJob

@RequiredRoles(value={"access.protected.services","process.content"})
void enforceStartJob(UUID jobId)
                     throws AuthenticationException,
                            IllegalRequestException
Starts a prepared processing job after preparation was finished.

This method enforces starting the job even if the information in the GRID appears to be the same.

Parameters:
jobId - The id of the job to start.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.
IllegalRequestException - In case of the job ID is invalid or the job has no assigned sources.

startReprocessingJob

@RequiredRoles(value={"access.protected.services","process.content"})
UUID startReprocessingJob(FileIdentifier contentIdentifier,
                                             boolean assignAllExistingSources,
                                             int jobPriority)
                          throws AuthenticationException,
                                 IllegalRequestException
Initiates a reprocessing job on the given file and returns the job GUID for monitoring the progress.

Note: This method is similar to running the code below, with the major difference that the operation is atomic and transaction safe:


 UUID jobId = prepareJob();
 

SourceIdentiferListPage sourceIds = sourceService.getReferencingSources(fileId, 0); SourceIdentifier sid = sourceIds.getElements().get(0); Source source = sourceService.getSource(sid); SourceInformation info = source.getSourceInformation();

sid = assignProcessSource(jobId, source.getRemoteURI(), info.getLastModified(), info.getContentTag(), source.getMetadata()); assignExistingContentToProcessSource(sid, fileId);

enforceStartJob(jobId);

Parameters:
contentIdentifier - The identifier of a previously stored file content.
assignAllExistingSources - Whether the newly created job will get the most recent or all stored sources assigned.
jobPriority - the priority of the job as an integer value between 1 <= x <= 7. 1 is the lowest priority, 7 the highest and 4 is the default value.
Returns:
The GUID of the job.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.
IllegalRequestException - If the content identifier does not point to an existing file content or when no public source URIs were assigned to the file.

startReprocessingJobWithSources

@RequiredRoles(value={"access.protected.services","process.content"})
UUID startReprocessingJobWithSources(FileIdentifier contentIdentifier,
                                                        Collection<SourceIdentifier> selectedSourceIdentifiers,
                                                        int jobPriority)
                                     throws AuthenticationException,
                                            IllegalRequestException
Initiates a reprocessing job on the given file and returns the job GUID for monitoring the progress.

This method is similar to startReprocessingJob(FileIdentifier, boolean, int) with the major difference that it allows to explicitly select which of the sources assigned with the package will be used for reprocessing.

Note: Calling this method with a source identifier that has not been assigned to the file will result in throwing an IllegalRequestException. Only assigned sources are allowed to be used as method parameters.

Parameters:
contentIdentifier - The identifier of a previously stored file content.
selectedSourceIdentifiers - A list of identifiers to assign with the reprocessing job.
jobPriority - the priority of the job as an integer value between 1 <= x <= 7. 1 is the lowest priority, 7 the highest and 4 is the default value.
Returns:
The GUID of the job.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.
IllegalRequestException - If the content identifier does not point to an existing file content or when no public source URIs were assigned to the file.

cloneAndStartJob

@RequiredRoles(value={"access.protected.services","process.content"})
UUID cloneAndStartJob(UUID originalJobId)
                      throws AuthenticationException,
                             IllegalRequestException
Clones the given job and starts the clone.

The clone contains the same sources and settings as the original. If the latter if not yet closed, its state will be set to Job.State#ABORTED, in order to avoid double retrieval of the same processing results.

This method is useful to restart stale jobs (jobs running for a very long time without an update). Note: Closing a job does not abort processing, it only sets the ABORTED flag within the DB. Processing services outside of the ACL need to query this state if they need to act on the event of closing a job.

In case of a job is closed and results still reach the method call storeProcessingResultsAndFinalizeJobs(java.util.Collection), the processing results of the relevant job will get discarded and warning will be logged as indication.

Parameters:
originalJobId - the job to clone and close.
Returns:
the UUID of the new, cloned job.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.
IllegalRequestException - If the jobId does not point to an existing job.

getAssignedSources

@RequiredRoles(value={"access.protected.services","process.content"})
List<Source> getAssignedSources(UUID jobId)
                                throws AuthenticationException
Retrieves all sources that are currently assigned to the given job.

Parameters:
jobId - the id of the job to query.
Returns:
all sources that are currently assigned to the given job.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.

assignProcessSource

@RequiredRoles(value={"access.protected.services","process.content"})
SourceIdentifier assignProcessSource(UUID jobId,
                                                        URI remoteSourceURI,
                                                        Date lastModified,
                                                        String contentTag,
                                                        com.trendmicro.grid.acl.metadata.Metadata metadata)
                                     throws AuthenticationException,
                                            IllegalRequestException
Adds or updates the remote source with the given Metadata, assigns it to a single processing job and returns the source identifier which may be used to upload source content if required.

Notes:

Parameters:
jobId - the id of the job to add the source to.
remoteSourceURI - The remote URI of the source.
lastModified - The remote last modified date of the source, if known (may be set to 'null').
contentTag - The remote content tag (e.g. ETAG) of the source, if known (may be set to 'null').
metadata - The metadata to store with the source.
Returns:
the identifier of the assigned process source.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.
IllegalRequestException - In case of the job ID is not pointing to a prepared job or if the source is already assigned to another job in the same session.

assignContentToProcessSource

@RequiredRoles(value={"access.protected.services","process.content","create.binary.content"})
URL assignContentToProcessSource(SourceIdentifier sourceIdentifier)
                                 throws AuthenticationException,
                                        IllegalRequestException
Returns a public reachable transfer URL that may be used to upload (HTTP-PUT) the binary content of the source.

Note: By uploading content to the returned URL via HTTP-PUT, the access layer will set the Meta elements "sourceContentSHA1" and "sourceContentMD5" inside the Metadata section of the assigned Source to the hash values that are automatically calculated on the data stream while uploading.

Parameters:
sourceIdentifier - The identifier of a previously assigned process source.
Returns:
a public reachable transfer URL that may be used to upload the binary content of the source using the method "HTTP PUT".
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.
IllegalRequestException - In case of the source identifier is not referring to a previously assigned process source.

assignExistingContentToProcessSource

@RequiredRoles(value={"access.protected.services","process.content"})
void assignExistingContentToProcessSource(SourceIdentifier sourceIdentifier,
                                                             FileIdentifier contentIdentifier)
                                          throws AuthenticationException,
                                                 IllegalRequestException
Allows to assign content that is known to exist already inside the GRID avoiding any new uploads.

Note: The implementation behind this method checks that the source is a previously assigned process source, and that the contentIdentifier is referring to a file that is contained inside the file content repository.

Parameters:
sourceIdentifier - The identifier of a previously assigned process source.
contentIdentifier - The identifier of a previously stored file content.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.
IllegalRequestException - In case of the source identifier is not referring to a previously assigned process source OR in case of the file identifier doesn't refer to a file stored inside the file content repository.

assignProcessSourceWithContent

@RequiredRoles(value={"access.protected.services","process.content","create.binary.content"})
URL assignProcessSourceWithContent(UUID jobId,
                                                      FileIdentifier contentIdentifier,
                                                      URI remoteSourceURI,
                                                      Date lastModified,
                                                      String contentTag,
                                                      com.trendmicro.grid.acl.metadata.Metadata metadata)
                                   throws AuthenticationException,
                                          IllegalRequestException
Adds or updates the remote source with the given Metadata, assigns it to a single processing job and directly returns an upload URL if GRID does not yet know the content.

This method is a convenience implementation that reduces the amount of API calls required to perform the default harvesting task, thus the following 2 code snippets lead to exactly the same results:

 SourceIdentifier sourceIdentifier = assignProcessSource(jobId, remoteSourceURI, lastModified, contentTag, metadata);
 boolean contentMayBeMissing = true;
 Source source = sourceService.getSource(sourceIdentifier);
 if (source != null) {
     FileIdentifier existingIdentifier = source.getSourceContentIdentifier();
     if (existingIdentifier != null) {
         contentMayBeMissing = !existingIdentifier.equals(contentIdentifier);
     }
 }
 URL putURL = null;
 if (contentMayBeMissing) {
     try {
         assignExistingContentToProcessSource(sourceIdentifier, contentIdentifier);
     } catch (IllegalRequestException ignored) {
         putURL = assignContentToProcessSource(sourceIdentifier);
     }
 }
 if (putURL != null) {
     //TODO: Do the upload
 }
 
can be replaced with:
 URL putURL = assignProcessSourceWithContent(jobId, contentIdentifier, remoteSourceURI, lastModified, contentTag, metadata);
 if (putURL != null) {
     //TODO: Do the upload
 }
 

Parameters:
jobId - the id of the job to add the source to.
remoteSourceURI - The remote URI of the source.
lastModified - The remote last modified date of the source, if known (may be set to 'null').
contentTag - The remote content tag (e.g. ETAG) of the source, if known (may be set to 'null').
metadata - The metadata to store with the source.
contentIdentifier - The identifier of a previously stored file content.
Returns:
'null' if the content is already known by GRID and does not require to get uploaded OR a public reachable transfer URL that may be used to upload the binary content of the source using the method "HTTP PUT".
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.
IllegalRequestException - In case of the job ID is not pointing to a prepared job or if the source is already assigned to another job in the same session.

storeProcessingResultsAndFinalizeJobs

@RequiredRoles(value={"access.protected.services","process.content"})
void storeProcessingResultsAndFinalizeJobs(Collection<ProcessPackageDataSet> processingResults)
                                           throws AuthenticationException,
                                                  StorageFailedException
Receives a collection of final processing results, stores them inside the GRID CoreDB and performs the final update on the assigned jobs.

Parameters:
processingResults - the processing results to update.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.
StorageFailedException - In case of the storage failed on one of the data sets.

getRunningJobs

@RequiredRoles(value="access.protected.services")
UUIDListPage getRunningJobs(int pageNumber)
                            throws AuthenticationException
Returns a paged list of running jobs.

Parameters:
pageNumber - The page number of the list page to return (0 is first page).
Returns:
A single list page for the given page number or 'null' if no jobs are running or the pageNumber is out of range.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.

getJobsInState

@RequiredRoles(value="access.protected.services")
UUIDListPage getJobsInState(Job.State jobState,
                                               int pageNumber)
                            throws AuthenticationException
Returns a paged list of jobs that are in the given state.

Parameters:
pageNumber - The page number of the list page to return (0 is first page).
jobState - The state of the jobs to query.
Returns:
A single list page for the given page number or 'null' if no jobs are running or the pageNumber is out of range.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.

getJobsInStateAndRange

@RequiredRoles(value="access.protected.services")
UUIDListPage getJobsInStateAndRange(Job.State jobState,
                                                       DaysRange lastUpdatedRange,
                                                       int pageNumber)
                                    throws AuthenticationException
Returns a paged list of jobs that are in the given state and were last updated within the given range.

Parameters:
pageNumber - The page number of the list page to return (0 is first page).
jobState - The state of the jobs to query.
lastUpdatedRange - The range when the last update was recorded.
Returns:
A single list page for the given page number or 'null' if no jobs are running or the pageNumber is out of range.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.

getJobStates

@ResponseWrapper(className="com.trendmicro.grid.acl.l0.wrappers.GetJobStatesResponse")
@RequiredRoles(value="access.protected.services")
Collection<Job.State> getJobStates(Collection<UUID> jobIds)
                                   throws AuthenticationException
Returns the states of the jobs, identified by their ids.

Parameters:
jobIds - The GUIDs of the jobs to return.
Returns:
the jobs, identified by their ids.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.

getJob

@RequiredRoles(value="access.protected.services")
Job getJob(UUID job)
           throws AuthenticationException
Returns the read & writable information on a job, identified by its id.

Parameters:
job - The GUID of the job to return the details from.
Returns:
the details on a job, identified by its id.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.

getJobs

@ResponseWrapper(className="com.trendmicro.grid.acl.l0.wrappers.GetJobsResponse")
@RequiredRoles(value="access.protected.services")
Collection<Job> getJobs(Collection<UUID> jobIds)
                        throws AuthenticationException
Returns the read & writable information on the jobs, identified by their ids.

Parameters:
jobIds - The GUIDs of the jobs to return.
Returns:
the jobs, identified by their ids.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.

updateJob

@RequiredRoles(value={"access.protected.services","process.content"})
void updateJob(Job job)
               throws AuthenticationException,
                      IllegalRequestException
Updates the given job inside the persistent store (= the database)

Parameters:
job - the details to update.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.
IllegalRequestException - In case of the values were changed to invalid settings.

getJobDetails

@RequiredRoles(value="access.protected.services")
JobDetails getJobDetails(UUID job)
                         throws AuthenticationException
Returns the detailed information on a job, identified by its id.

Parameters:
job - The GUID of the job to return the details for.
Returns:
the details on a job, identified by its id.
Throws:
AuthenticationException - In case of the current user is not authenticated or doesn't have the right to access the service.