@Override protected JobSpec doPut(JobSpec jobSpec) { return this.jobSpecs.put(jobSpec.getUri(), jobSpec); }
private Map<URI, JobSpec> parseJobs(Collection<JobSpec> jobSpecs) { ImmutableMap.Builder<URI, JobSpec> mapBuilder = ImmutableMap.builder(); for (JobSpec jobSpec : jobSpecs) { mapBuilder.put(jobSpec.getUri(), jobSpec); } return mapBuilder.build(); }
@VisibleForTesting static String getJobName(JobSpec jobSpec) { return jobSpec.getUri().toString().replaceAll("[/.:]", "_"); }
@Override public boolean apply(JobSpec input) { Preconditions.checkNotNull(input); boolean res = true; if (this.uriPredicate.isPresent()) { res &= this.uriPredicate.get().apply(input.getUri()); } if (res && this.versionPredicate.isPresent()) { res &= this.versionPredicate.get().apply(input.getVersion()); } return res; }
public static String constructProjectName(JobSpec jobSpec, Config config) { String projectNamePrefix = ConfigUtils.getString(config, ServiceAzkabanConfigKeys.AZKABAN_PROJECT_NAME_PREFIX_KEY, ""); String projectNamePostfix = null == jobSpec.getUri() ? "" : jobSpec.getUri().toString().replaceAll("_", "-").replaceAll("[^A-Za-z0-9\\-]", "_"); return trimProjectName(String.format("%s_%s", projectNamePrefix, projectNamePostfix)); }
public String toShortString() { return getUri().toString() + "/" + getVersion(); }
/** * Create a {@link Trigger} from the given {@link JobSpec} */ private Trigger createTrigger(JobKey jobKey, JobSpec jobSpec) { // Build a trigger for the job with the given cron-style schedule return TriggerBuilder.newTrigger() .withIdentity("Cron for " + jobSpec.getUri()) .forJob(jobKey) .withSchedule(CronScheduleBuilder.cronSchedule( jobSpec.getConfig().getString(ConfigurationKeys.JOB_SCHEDULE_KEY))) .build(); }
/** {@inheritDoc} */ @Override public JobSpecSchedule scheduleOnce(JobSpec jobSpec, Runnable jobRunnable) { _log.info("Scheduling once JobSpec " + jobSpec); Runnable runOnceRunnable = new RunOnceRunnable(jobSpec.getUri(), jobRunnable); return scheduleJob(jobSpec, runOnceRunnable); }
@Override public void remove(URI uri) { Preconditions.checkState(state() == State.RUNNING, String.format("%s is not running.", this.getClass().getName())); Preconditions.checkNotNull(uri); JobSpec jobSpec = doRemove(uri); if (null != jobSpec) { this.listeners.onDeleteJob(jobSpec.getUri(), jobSpec.getVersion()); } }
public String toLongString() { return getUri().toString() + "/" + getVersion() + "[" + getDescription() + "]"; }
@Override public Void answer(InvocationOnMock invocation) throws Throwable { JobSpec spec = (JobSpec) invocation.getArguments()[0]; specs.put(spec.getUri(), spec); return null; } }).when(l).onAddJob(Mockito.any(JobSpec.class));
@Override public Void answer(InvocationOnMock invocation) throws Throwable { JobSpec spec = (JobSpec) invocation.getArguments()[0]; specs.put(spec.getUri(), spec); return null; } }).when(l).onUpdateJob(Mockito.any(JobSpec.class));
@Override public Void answer(InvocationOnMock invocation) throws Throwable { JobSpec jobSpec = (JobSpec) invocation.getArguments()[0]; jobSpecs.put(jobSpec.getUri(), jobSpec); return null; } }).when(jobCatalog).put(Mockito.any(JobSpec.class));
@Override public Void answer(InvocationOnMock invocation) throws Throwable { JobSpec spec = (JobSpec) invocation.getArguments()[0]; specs.put(spec.getUri(), spec); return null; } }).when(l).onAddJob(Mockito.any(JobSpec.class));
@Override public Void answer(InvocationOnMock invocation) throws Throwable { JobSpec spec = (JobSpec) invocation.getArguments()[0]; specs.put(spec.getUri(), spec); return null; } }).when(l).onUpdateJob(Mockito.any(JobSpec.class));
private void submitTrackingEvent(JobSpec job, String operType) { submitTrackingEvent(job.getUri(), job.getVersion(), operType); }
public static JobExecutionUpdatable createFromJobSpec(JobSpec jobSpec) { return new JobExecutionUpdatable(jobSpec.getUri(), jobSpec.getVersion(), System.currentTimeMillis(), JobLauncherUtils.newJobId(JobState.getJobNameFromProps(jobSpec.getConfigAsProperties()))); } }
@Override public JobExecutionMonitor launchJob(JobSpec jobSpec) { Preconditions.checkNotNull(jobSpec); if (!(jobSpec instanceof ResolvedJobSpec)) { try { jobSpec = new ResolvedJobSpec(jobSpec); } catch (JobTemplate.TemplateException | SpecNotFoundException exc) { throw new RuntimeException("Can't launch job " + jobSpec.getUri(), exc); } } JobLauncherExecutionDriver driver = JobLauncherExecutionDriver.create(getSysConfig(), jobSpec, _jobLauncherType, Optional.of(getLog(jobSpec)), isInstrumentationEnabled(), getMetrics(), getInstanceBroker()); return new JobExecutionMonitorAndDriver(driver); }
private AvroJobSpec convertToAvroJobSpec(Spec spec, SpecExecutor.Verb verb) { if (spec instanceof JobSpec) { JobSpec jobSpec = (JobSpec) spec; AvroJobSpec.Builder avroJobSpecBuilder = AvroJobSpec.newBuilder(); avroJobSpecBuilder.setUri(jobSpec.getUri().toString()).setVersion(jobSpec.getVersion()) .setDescription(jobSpec.getDescription()).setProperties(Maps.fromProperties(jobSpec.getConfigAsProperties())) .setMetadata(ImmutableMap.of(VERB_KEY, verb.name())); if (jobSpec.getTemplateURI().isPresent()) { avroJobSpecBuilder.setTemplateUri(jobSpec.getTemplateURI().get().toString()); } return avroJobSpecBuilder.build(); } else { throw new RuntimeException("Unsupported spec type " + spec.getClass()); } } }
/** * Resolve the job spec using classpath templates as well as any templates available in the input {@link JobCatalog}. */ public ResolvedJobSpec(JobSpec other, JobCatalog catalog) throws SpecNotFoundException, JobTemplate.TemplateException { super(other.getUri(), other.getVersion(), other.getDescription(), resolveConfig(other, catalog), ConfigUtils.configToProperties(resolveConfig(other, catalog)), other.getTemplateURI(), other.getMetadata()); this.originalJobSpec = other; }