public static String configJobRefShort(final JobId id) { return CONFIG_JOBREFS.path(id.getName() + ":" + id.getVersion()); }
public static String historyJobHostEventsTimestamp(final JobId jobId, final String host, final long timestamp) { return HISTORY_JOBS.path(jobId.toString(), HOSTS, host, EVENTS, String.valueOf(timestamp)); }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } final HostStatus that = (HostStatus) obj; if (host != null ? !host.equals(that.host) : that.host != null) { return false; } if (jobId != null ? !jobId.equals(that.jobId) : that.jobId != null) { return false; } if (state != that.state) { return false; } return true; }
/** * Validate the Job's JobId by checking name, version, and hash are * not null or empty, don't contain invalid characters. * * @param job The Job to check. * * @return A set of error Strings */ private Set<String> validateJobId(final Job job) { final Set<String> errors = Sets.newHashSet(); final JobId jobId = job.getId(); if (jobId == null) { errors.add("Job id was not specified."); return errors; } final String jobIdVersion = jobId.getVersion(); final String jobIdHash = jobId.getHash(); final JobId recomputedId = job.toBuilder().build().getId(); errors.addAll(validateJobName(jobId, recomputedId)); errors.addAll(validateJobVersion(jobIdVersion, recomputedId)); if (this.shouldValidateJobHash) { errors.addAll(validateJobHash(jobIdHash, recomputedId)); } return errors; }
public void task(final JobId jobId, final String host, final TaskStatus ts, final Deployment deployment) { final String goal = (deployment == null) ? "" : deployment.getGoal().toString(); final int maxContainerId = full ? Integer.MAX_VALUE : 7; final String jobIdString = full ? jobId.toString() : jobId.toShortString(); if (ts == null) { table.row(jobIdString, host, goal, "", "", ""); } else { final List<String> portMappings = new ArrayList<>(); for (final Map.Entry<String, PortMapping> entry : ts.getPorts().entrySet()) { final PortMapping portMapping = entry.getValue(); portMappings.add(String.format("%s=%d:%d", entry.getKey(), portMapping.getInternalPort(), portMapping.getExternalPort())); } String state = ts.getState().toString(); if (ts.getThrottled() != ThrottleState.NO) { state += " (" + ts.getThrottled() + ")"; } final String ports = Joiner.on(" ").join(portMappings); final String cid = truncate(fromNullable(ts.getContainerId()).or(""), maxContainerId, ""); table.row(jobIdString, host, goal, state, cid, ports); } }
final String env = Joiner.on(" ").withKeyValueSeparator("=").join(job.getEnv()); final JobStatus status = jobStatuses.get(jobId); table.row(full ? jobId : jobId.toShortString(), jobId.getName(), jobId.getVersion(), status != null ? status.getDeployments().keySet().size() : 0, command, env);
&& hostStatus.getJobId().equals(jobId); job = "-"; } else if (full) { job = hostStatus.getJobId().toString(); } else { job = hostStatus.getJobId().toShortString();
private void outputDeployedMessage(final String host, final String containerId) { final StrSubstitutor subst = new StrSubstitutor(new ImmutableMap.Builder<String, Object>() .put("host", host) .put("name", job.getId().getName()) .put("version", job.getId().getVersion()) .put("hash", job.getId().getHash()) .put("job", job.toString()) .put("containerId", containerId) .build() ); log.info("{}", subst.replace(jobDeployedMessageFormat)); } }
final JobId jobId = JobId.parse(CharMatcher.whitespace().trimFrom(output)); assertEquals(name, job.getId().getName()); assertEquals(version, job.getId().getVersion()); assertEquals(ports, job.getPorts()); assertEquals(env, job.getEnv());
.setCreatingUser(TEST_USER) .build(); final String inspectOutput = cli("inspect", "--json", jobId.toString()); final Job parsed = Json.read(inspectOutput, Job.class); assertJobEquals(expected, parsed); assertThat(cli("jobs", testJobName, "-q"), containsString(jobId.toString())); assertThat(cli("jobs", testJobName + ":" + testJobVersion, "-q"), containsString(jobId.toString())); assertEquals("job pattern foozbarz matched no jobs", cli("jobs", "foozbarz").trim()); assertTrue(cli("jobs", "foozbarz", "-q").isEmpty()); .setVersion(expected.getId().getVersion() + "-cloned") .build(); final JobId clonedJobId = JobId.parse(CharMatcher.whitespace().trimFrom( cli("create", "-q", "-t", testJobName + ":" + testJobVersion, testJobName + ":" + testJobVersion + "-cloned"))); final String clonedInspectOutput = cli("inspect", "--json", clonedJobId.toString()); final Job clonedParsed = Json.read(clonedInspectOutput, Job.class); assertJobEquals(expectedCloned, clonedParsed); final String statusString = cli("status", "--job", jobId.toString(), "--json"); final Map<JobId, JobStatus> statuses = Json.read(statusString, STATUSES_TYPE); final Job job = statuses.get(jobId).getJob(); assertThat(cli("undeploy", jobId.toString(), BOGUS_HOST), containsString("HOST_NOT_FOUND")); assertThat(cli("undeploy", BOGUS_JOB.toString(), testHost()), containsString("Unknown job"));
.setCreated(clock.now().getMillis()) .setHash(job.getId().getHash()); final Job actualJob = clone.build(); final Collection<String> errors = jobValidator.validate(actualJob); final String jobIdString = actualJob.getId().toString(); if (!errors.isEmpty()) { throw badRequest(new CreateJobResponse(INVALID_JOB_DEFINITION, ImmutableList.copyOf(errors),
/** * Generate a random container name. * * @return The random container name. */ public String containerName() { final String shortId = job.getId().toShortString(); final String escaped = CONTAINER_NAME_FORBIDDEN.matcher(shortId).replaceAll("_"); final String random = Integer.toHexString(new SecureRandom().nextInt()); return namespace + "-" + escaped + "_" + random; }
async ? " (async)" : "", name, jobId.toShortString(), actualParallelism, actualTimeout, if (!jobId.equals(status.getDeploymentGroup().getJobId())) { final TaskStatus.State state = hostStatus.getState(); final boolean done = hostJobId != null && hostJobId.equals(jobId) && state == TaskStatus.State.RUNNING;
private Set<String> validateJobName(final JobId jobId, final JobId recomputedId) { final Set<String> errors = Sets.newHashSet(); final String jobIdName = jobId.getName(); if (isNullOrEmpty(jobIdName)) { errors.add("Job name was not specified."); return errors; } // Check that the job name contains only allowed characters if (!NAME_VERSION_PATTERN.matcher(jobIdName).matches()) { errors.add(format("Job name may only contain [0-9a-zA-Z-_.] in job name [%s].", recomputedId.getName())); } // Check that the job id is correct if (!recomputedId.getName().equals(jobIdName)) { errors.add(format("Id name mismatch: %s != %s", jobIdName, recomputedId.getName())); } return errors; }
private JobId jobIdFromTaskPath(final String path) { final String prefix = Paths.configHostJobs(agent) + "/"; return JobId.fromString(path.replaceFirst(prefix, "")); }
private Set<String> validateJobVersion(final String jobIdVersion, final JobId recomputedId) { final Set<String> errors = Sets.newHashSet(); if (isNullOrEmpty(jobIdVersion)) { errors.add(format("Job version was not specified in job id [%s].", recomputedId)); return errors; } if (!NAME_VERSION_PATTERN.matcher(jobIdVersion).matches()) { // Check that the job version contains only allowed characters errors.add(format("Job version may only contain [0-9a-zA-Z-_.] in job version [%s].", recomputedId.getVersion())); } // Check that the job version is correct if (!recomputedId.getVersion().equals(jobIdVersion)) { errors.add(format("Id version mismatch: %s != %s", jobIdVersion, recomputedId.getVersion())); } return errors; }
private Set<String> validateJobHash(final String jobIdHash, final JobId recomputedId) { final Set<String> errors = Sets.newHashSet(); if (isNullOrEmpty(jobIdHash)) { errors.add(format("Job hash was not specified in job id [%s].", recomputedId)); return errors; } if (jobIdHash.indexOf(':') != -1) { // TODO (dxia) Are hashes allowed to have chars not in NAME_VERSION_PATTERN? errors.add(format("Job hash contains colon in job id [%s].", recomputedId)); } // Check that the job hash is correct if (!recomputedId.getHash().equals(jobIdHash)) { errors.add(format("Id hash mismatch: %s != %s", jobIdHash, recomputedId.getHash())); } return errors; }
/** * Returns the job status for the given job id. The job status includes things like where it's * deployed, and the status of the jobs where it's deployed, etc. * * @param id The job ID. * * @return The job status. */ @Path("{id}/status") @GET @Produces(APPLICATION_JSON) @Timed @ExceptionMetered public Optional<JobStatus> statusGet(@PathParam("id") @Valid final JobId id) { if (!id.isFullyQualified()) { throw badRequest("Invalid id"); } return Optional.fromNullable(model.getJobStatus(id)); }
final String env = Joiner.on(" ").withKeyValueSeparator("=").join(job.getEnv()); final JobStatus status = futures.get(jobId).get(); table.row(full ? jobId : jobId.toShortString(), jobId.getName(), jobId.getVersion(), status != null ? status.getDeployments().keySet().size() : 0, command, env);
hostStatus.getJobId().equals(jobId); job = "-"; } else if (full) { job = hostStatus.getJobId().toString(); } else { job = hostStatus.getJobId().toShortString();