use of com.google.privacy.dlp.v2.JobTrigger in project pentaho-platform by pentaho.
the class EmbeddedVersionCheckSystemListener method scheduleJob.
protected void scheduleJob(final int versionRequestFlags, final int repeatSeconds) throws Exception {
// $NON-NLS-1$
IScheduler scheduler = PentahoSystem.get(IScheduler.class, "IScheduler2", null);
deleteJobIfNecessary();
Map<String, Serializable> parms = new HashMap<String, Serializable>();
parms.put(VersionCheckerAction.VERSION_REQUEST_FLAGS, new Integer(versionRequestFlags));
JobTrigger trigger = new SimpleJobTrigger(new Date(), null, -1, repeatSeconds);
scheduler.createJob(EmbeddedVersionCheckSystemListener.VERSION_CHECK_JOBNAME, VersionCheckerAction.class, parms, trigger);
}
use of com.google.privacy.dlp.v2.JobTrigger in project pentaho-platform by pentaho.
the class QuartzScheduler method createJob.
/**
* {@inheritDoc}
*/
protected Job createJob(String jobName, Map<String, Serializable> jobParams, IJobTrigger trigger, IBackgroundExecutionStreamProvider outputStreamProvider) throws SchedulerException {
String curUser = getCurrentUser();
// determine if the job params tell us who owns the job
Serializable jobOwner = jobParams.get(RESERVEDMAPKEY_ACTIONUSER);
if (jobOwner != null && jobOwner.toString().length() > 0) {
curUser = jobOwner.toString();
}
QuartzJobKey jobId = new QuartzJobKey(jobName, curUser);
Trigger quartzTrigger = createQuartzTrigger(trigger, jobId);
if (trigger.getEndTime() != null) {
quartzTrigger.setEndTime(trigger.getEndTime());
}
Calendar triggerCalendar = quartzTrigger instanceof CronTrigger ? createQuartzCalendar((ComplexJobTrigger) trigger) : null;
if (outputStreamProvider != null) {
jobParams.put(RESERVEDMAPKEY_STREAMPROVIDER, outputStreamProvider);
}
if (trigger.getUiPassParam() != null) {
jobParams.put(RESERVEDMAPKEY_UIPASSPARAM, trigger.getUiPassParam());
}
if (!jobParams.containsKey(RESERVEDMAPKEY_LINEAGE_ID)) {
String uuid = UUID.randomUUID().toString();
jobParams.put(RESERVEDMAPKEY_LINEAGE_ID, uuid);
}
JobDetail jobDetail = createJobDetails(jobId, jobParams);
try {
Scheduler scheduler = getQuartzScheduler();
if (triggerCalendar != null) {
scheduler.addCalendar(jobId.toString(), triggerCalendar, false, false);
quartzTrigger.setCalendarName(jobId.toString());
}
logger.debug(MessageFormat.format("Scheduling job {0} with trigger {1} and job parameters [ {2} ]", jobId.toString(), trigger, // $NON-NLS-1$
prettyPrintMap(jobParams)));
scheduler.scheduleJob(jobDetail, quartzTrigger);
} catch (org.quartz.SchedulerException e) {
throw new SchedulerException(Messages.getInstance().getString("QuartzScheduler.ERROR_0001_FAILED_TO_SCHEDULE_JOB", jobName), // $NON-NLS-1$
e);
}
Job job = new Job();
job.setJobParams(jobParams);
job.setJobTrigger((JobTrigger) trigger);
job.setNextRun(quartzTrigger.getNextFireTime());
job.setLastRun(quartzTrigger.getPreviousFireTime());
job.setJobId(jobId.toString());
job.setJobName(jobName);
job.setUserName(curUser);
job.setState(JobState.NORMAL);
return job;
}
use of com.google.privacy.dlp.v2.JobTrigger in project java-docs-samples by GoogleCloudPlatform.
the class Triggers method createTrigger.
// [START dlp_create_trigger]
/**
* Schedule a DLP inspection trigger for a GCS location.
*
* @param triggerId (Optional) name of the trigger to be created
* @param displayName (Optional) display name for the trigger to be created
* @param description (Optional) description for the trigger to be created
* @param scanPeriod How often to wait between scans, in days (minimum = 1 day)
* @param infoTypes infoTypes of information to match eg. InfoType.PHONE_NUMBER,
* InfoType.EMAIL_ADDRESS
* @param minLikelihood minimum likelihood required before returning a match
* @param maxFindings maximum number of findings to report per request (0 = server maximum)
* @param projectId The project ID to run the API call under
*/
private static void createTrigger(String triggerId, String displayName, String description, String bucketName, String fileName, int scanPeriod, List<InfoType> infoTypes, Likelihood minLikelihood, int maxFindings, String projectId) throws Exception {
// instantiate a client
DlpServiceClient dlpServiceClient = DlpServiceClient.create();
try {
CloudStorageOptions cloudStorageOptions = CloudStorageOptions.newBuilder().setFileSet(CloudStorageOptions.FileSet.newBuilder().setUrl("gs://" + bucketName + "/" + fileName)).build();
StorageConfig storageConfig = StorageConfig.newBuilder().setCloudStorageOptions(cloudStorageOptions).build();
InspectConfig.FindingLimits findingLimits = InspectConfig.FindingLimits.newBuilder().setMaxFindingsPerRequest(maxFindings).build();
InspectConfig inspectConfig = InspectConfig.newBuilder().addAllInfoTypes(infoTypes).setMinLikelihood(minLikelihood).setLimits(findingLimits).build();
InspectJobConfig inspectJobConfig = InspectJobConfig.newBuilder().setInspectConfig(inspectConfig).setStorageConfig(storageConfig).build();
// Schedule scan of GCS bucket every scanPeriod number of days (minimum = 1 day)
Duration duration = Duration.newBuilder().setSeconds(scanPeriod * 24 * 3600).build();
Schedule schedule = Schedule.newBuilder().setRecurrencePeriodDuration(duration).build();
JobTrigger.Trigger trigger = JobTrigger.Trigger.newBuilder().setSchedule(schedule).build();
JobTrigger jobTrigger = JobTrigger.newBuilder().setInspectJob(inspectJobConfig).setName(triggerId).setDisplayName(displayName).setDescription(description).setStatus(JobTrigger.Status.HEALTHY).addTriggers(trigger).build();
// Create scan request
CreateJobTriggerRequest createJobTriggerRequest = CreateJobTriggerRequest.newBuilder().setParent(ProjectName.of(projectId).toString()).setJobTrigger(jobTrigger).build();
JobTrigger createdJobTrigger = dlpServiceClient.createJobTrigger(createJobTriggerRequest);
System.out.println("Created Trigger: " + createdJobTrigger.getName());
} catch (Exception e) {
System.out.println("Error creating trigger: " + e.getMessage());
}
}
Aggregations