use of org.apache.samza.rest.proxy.job.JobInstance in project samza by apache.
the class LocalStoreMonitor method getHostAffinityEnabledJobs.
/**
* Helper method to find and return the list of host affinity enabled jobs on this NM.
* @param localStoreDirFile the location in which all stores of host affinity enabled jobs are persisted.
* @return the list of the host affinity enabled jobs that are installed on this NM.
*/
private static List<JobInstance> getHostAffinityEnabledJobs(File localStoreDirFile) {
List<JobInstance> jobInstances = new ArrayList<>();
for (File jobStore : localStoreDirFile.listFiles(File::isDirectory)) {
// Name of the jobStore(jobStorePath) is of the form : ${job.name}-${job.id}.
String jobStorePath = jobStore.getName();
int indexSeparator = jobStorePath.lastIndexOf("-");
if (indexSeparator != -1) {
jobInstances.add(new JobInstance(jobStorePath.substring(0, indexSeparator), jobStorePath.substring(indexSeparator + 1)));
}
}
return jobInstances;
}
use of org.apache.samza.rest.proxy.job.JobInstance in project samza by apache.
the class SimpleInstallationFinder method findJobInstances.
/**
* Finds all the job instances in the specified path and adds a corresponding {@link JobInstance} and
* {@link InstallationRecord} for each instance.
*
* @param jobInstallPath the path to search for job instances.
* @param jobs the map to which the job instances will be added.
*/
private void findJobInstances(final File jobInstallPath, final Map<JobInstance, InstallationRecord> jobs) {
try {
String jobInstallCanonPath = jobInstallPath.getCanonicalPath();
File configPath = Paths.get(jobInstallCanonPath, CFG_SUBPATH).toFile();
if (!(configPath.exists() && configPath.isDirectory())) {
log.debug("Config path not found: " + configPath);
return;
}
for (File configFile : configPath.listFiles()) {
if (configFile.isFile()) {
String configFilePath = configFile.getCanonicalPath();
Config config = jobConfigFactory.getConfig(new URI("file://" + configFilePath));
if (config.containsKey(JobConfig.JOB_NAME()) && config.containsKey(JobConfig.STREAM_JOB_FACTORY_CLASS())) {
String jobName = config.get(JobConfig.JOB_NAME());
String jobId = config.get(JobConfig.JOB_ID(), "1");
JobInstance jobInstance = new JobInstance(jobName, jobId);
if (jobs.containsKey(jobInstance)) {
throw new IllegalStateException(String.format("Found more than one job config with jobName:%s and jobId:%s", jobName, jobId));
}
InstallationRecord jobInstall = new InstallationRecord(jobName, jobId, jobInstallCanonPath, configFilePath, getBinPath(jobInstallCanonPath));
jobs.put(jobInstance, jobInstall);
}
}
}
} catch (Exception e) {
throw new SamzaException("Exception finding job instance in path: " + jobInstallPath, e);
}
}
use of org.apache.samza.rest.proxy.job.JobInstance in project samza by apache.
the class MockJobProxy method getAllJobInstances.
@Override
protected Set<JobInstance> getAllJobInstances() {
Set<JobInstance> validatedInstallations = new LinkedHashSet<>();
validatedInstallations.add(new JobInstance(JOB_INSTANCE_1_NAME, JOB_INSTANCE_1_ID));
validatedInstallations.add(new JobInstance(JOB_INSTANCE_2_NAME, JOB_INSTANCE_2_ID));
validatedInstallations.add(new JobInstance(JOB_INSTANCE_3_NAME, JOB_INSTANCE_3_ID));
validatedInstallations.add(new JobInstance(JOB_INSTANCE_4_NAME, JOB_INSTANCE_4_ID));
return validatedInstallations;
}
use of org.apache.samza.rest.proxy.job.JobInstance in project samza by apache.
the class JobsResource method updateJobStatus.
/**
*
* @param jobName the name of the job as configured in {@link org.apache.samza.config.JobConfig#JOB_NAME}.
* @param jobId the id of the job as configured in {@link org.apache.samza.config.JobConfig#JOB_ID}.
* @param status the {@link JobStatus} to which the job will transition.
* @return a {@link javax.ws.rs.core.Response.Status#ACCEPTED} {@link javax.ws.rs.core.Response}
* containing a {@link Job} for the Samza job if it is
* installed on this host. {@link javax.ws.rs.core.Response.Status#NOT_FOUND}
* {@link javax.ws.rs.core.Response.Status#BAD_REQUEST} and
* {@link javax.ws.rs.core.Response.Status#INTERNAL_SERVER_ERROR} can occur for corresponding errors.
*/
@PUT
@Path("/{jobName}/{jobId}")
@Produces(MediaType.APPLICATION_JSON)
public Response updateJobStatus(@PathParam("jobName") final String jobName, @PathParam("jobId") final String jobId, @QueryParam("status") String status) {
JobInstance jobInstance = new JobInstance(jobName, jobId);
try {
if (!jobProxy.jobExists(jobInstance)) {
return Response.status(Response.Status.NOT_FOUND).entity(Collections.singletonMap("message", String.format("Job %s instance %s is not installed on this host.", jobName, jobId))).build();
}
if (status == null) {
throw new IllegalArgumentException("Unrecognized status parameter: " + status);
}
JobStatus samzaStatus = JobStatus.valueOf(status.toUpperCase());
switch(samzaStatus) {
case STARTED:
log.info("Starting {}", jobInstance);
jobProxy.start(jobInstance);
Job infoStarted = jobProxy.getJobStatus(jobInstance);
return Response.accepted(infoStarted).build();
case STOPPED:
log.info("Stopping {}", jobInstance);
jobProxy.stop(jobInstance);
Job infoStopped = jobProxy.getJobStatus(jobInstance);
return Response.accepted(infoStopped).build();
default:
throw new IllegalArgumentException("Unsupported status: " + status);
}
} catch (IllegalArgumentException e) {
log.info(String.format("Illegal arguments updateJobStatus. JobName:%s JobId:%s Status=%s", jobName, jobId, status), e);
return Responses.badRequestResponse(e.getMessage());
} catch (Exception e) {
log.error("Error in updateJobStatus.", e);
return Responses.errorResponse(String.format("Error type: %s message: %s", e.toString(), e.getMessage()));
}
}
use of org.apache.samza.rest.proxy.job.JobInstance in project samza by apache.
the class TestLocalStoreMonitor method shouldContinueLocalStoreCleanUpAfterFailureToCleanUpStoreOfAJob.
@Test
public void shouldContinueLocalStoreCleanUpAfterFailureToCleanUpStoreOfAJob() throws Exception {
File testFailingJobDir = new File(System.getProperty("java.io.tmpdir") + File.separator + "samza-test-job/", "test-jobName-jobId-1");
File testFailingTaskStoreDir = new File(new File(testFailingJobDir, "test-store"), "test-task");
FileUtils.forceMkdir(testFailingTaskStoreDir);
// For job: test-jobName-jobId-1, throw up in getTasks call and
// expect the cleanup to succeed for other job: test-jobName-jobId.
Mockito.doThrow(new RuntimeException("Dummy exception message.")).when(jobsClientMock).getTasks(new JobInstance("test-jobName", "jobId-1"));
Task task = new Task("notLocalHost", "test-task", "0", new ArrayList<>(), ImmutableList.of("test-store"));
Mockito.when(jobsClientMock.getTasks(new JobInstance("test-jobName", "jobId"))).thenReturn(ImmutableList.of(task));
Map<String, String> configMap = new HashMap<>(config);
configMap.put(LocalStoreMonitorConfig.CONFIG_IGNORE_FAILURES, "true");
LocalStoreMonitor localStoreMonitor = new LocalStoreMonitor(new LocalStoreMonitorConfig(new MapConfig(configMap)), localStoreMonitorMetrics, jobsClientMock);
localStoreMonitor.monitor();
// Non failing job directory should be cleaned up.
assertTrue("Task store directory should not exist.", !taskStoreDir.exists());
FileUtils.deleteDirectory(testFailingJobDir);
}
Aggregations