void testSubmitJobMethodKill()

in genie-web/src/integTest/java/com/netflix/genie/web/apis/rest/v3/controllers/JobRestControllerIntegrationTest.java [1210:1315]


    void testSubmitJobMethodKill() throws Exception {
        Assumptions.assumeTrue(SystemUtils.IS_OS_UNIX);

        final List<ClusterCriteria> clusterCriteriaList = new ArrayList<>();
        final Set<String> clusterTags = Sets.newHashSet(LOCALHOST_CLUSTER_TAG);
        final ClusterCriteria clusterCriteria = new ClusterCriteria(clusterTags);
        clusterCriteriaList.add(clusterCriteria);

        final Set<String> commandCriteria = Sets.newHashSet(BASH_COMMAND_TAG);
        final JobRequest jobRequest = new JobRequest.Builder(
            JOB_NAME,
            JOB_USER,
            JOB_VERSION,
            clusterCriteriaList,
            commandCriteria
        )
            .withCommandArgs(SLEEP_60_COMMAND_ARGS)
            .withDisableLogArchival(true)
            .build();

        final String jobId = this.getIdFromLocation(
            RestAssured
                .given(this.getRequestSpecification())
                .contentType(MediaType.APPLICATION_JSON_VALUE)
                .body(GenieObjectMapper.getMapper().writeValueAsBytes(jobRequest))
                .when()
                .port(this.port)
                .post(JOBS_API)
                .then()
                .statusCode(Matchers.is(HttpStatus.ACCEPTED.value()))
                .header(HttpHeaders.LOCATION, Matchers.notNullValue())
                .extract()
                .header(HttpHeaders.LOCATION)
        );

        this.waitForRunning(jobId);

        // Make sure we can get output for a running job
        final ValidatableResponse outputResponse = RestAssured
            .given(this.getRequestSpecification())
            .accept(MediaType.APPLICATION_JSON_VALUE)
            .when()
            .port(this.port)
            .get(JOBS_API + "/{id}/output/{filePath}", jobId, "")
            .then()
            .statusCode(Matchers.is(HttpStatus.OK.value()))
            .contentType(Matchers.startsWith(MediaType.APPLICATION_JSON_VALUE))
            .body("parent", Matchers.is(Matchers.emptyOrNullString()))
            .body("directories[0].name", Matchers.is("genie/"));

        outputResponse
            .body("files[0].name", Matchers.is("run"))
            .body("files[1].name", Matchers.is("stderr"))
            .body("files[2].name", Matchers.is("stdout"));

        RestAssured
            .given(this.getRequestSpecification())
            .when()
            .port(this.port)
            .get(JOBS_API + "/{id}/output/{filePath}", jobId, "stdout")
            .then()
            .statusCode(Matchers.is(HttpStatus.OK.value()))
            .contentType(Matchers.containsString(ContentType.TEXT.toString()));

        // Let it run for a couple of seconds
        Thread.sleep(2000);

        // Send a kill request to the job.
        final RestDocumentationFilter killResultFilter = RestAssuredRestDocumentation.document(
            "{class-name}/killJob/",
            Snippets.ID_PATH_PARAM
        );

        RestAssured
            .given(this.getRequestSpecification())
            .filter(killResultFilter)
            .when()
            .port(this.port)
            .delete(JOBS_API + "/{id}", jobId)
            .then()
            .statusCode(Matchers.is(HttpStatus.ACCEPTED.value()));

        this.waitForDone(jobId);

        RestAssured
            .given(this.getRequestSpecification())
            .when()
            .port(this.port)
            .get(JOBS_API + "/{id}", jobId)
            .then()
            .statusCode(Matchers.is(HttpStatus.OK.value()))
            .contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
            .body(ID_PATH, Matchers.is(jobId))
            .body(STATUS_PATH, Matchers.is(JobStatus.KILLED.toString()))
            .body(STATUS_MESSAGE_PATH, Matchers.is(JobStatusMessages.JOB_KILLED_BY_USER));

        // Kill the job again to make sure it doesn't cause a problem.
        RestAssured
            .given(this.getRequestSpecification())
            .filter(killResultFilter)
            .when()
            .port(this.port)
            .delete(JOBS_API + "/{id}", jobId)
            .then()
            .statusCode(Matchers.is(HttpStatus.ACCEPTED.value()));
    }