Example usage for org.springframework.http HttpHeaders LOCATION

List of usage examples for org.springframework.http HttpHeaders LOCATION

Introduction

In this page you can find the example usage for org.springframework.http HttpHeaders LOCATION.

Prototype

String LOCATION

To view the source code for org.springframework.http HttpHeaders LOCATION.

Click Source Link

Document

The HTTP Location header field name.

Usage

From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java

/**
 * Test the job submit method for when the job is killed as it times out.
 *
 * @throws Exception If there is a problem.
 *///from   w  ww.ja v a2 s. c o  m
@Test
public void testSubmitJobMethodKillOnTimeout() throws Exception {
    Assume.assumeTrue(SystemUtils.IS_OS_UNIX);
    final List<String> commandArgs = Lists.newArrayList("-c", "'sleep 60'");

    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(commandArgs).withTimeout(5).withDisableLogArchival(true).build();

    final String id = 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.waitForDone(id);

    RestAssured.given(this.getRequestSpecification()).when().port(this.port).get(JOBS_API + "/{id}", id).then()
            .statusCode(Matchers.is(HttpStatus.OK.value()))
            .contentType(Matchers.is(MediaTypes.HAL_JSON_UTF8_VALUE)).body(ID_PATH, Matchers.is(id))
            .body(STATUS_PATH, Matchers.is(JobStatus.KILLED.toString()))
            .body(STATUS_MESSAGE_PATH, Matchers.is("Job exceeded timeout."));
}

From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java

/**
 * Test the job submit method for when the job fails.
 *
 * @throws Exception If there is a problem.
 *//*from  ww w . j  ava  2 s .c  o m*/
@Test
public void testSubmitJobMethodFailure() throws Exception {
    Assume.assumeTrue(SystemUtils.IS_OS_UNIX);
    final List<String> commandArgs = Lists.newArrayList("-c", "'exit 1'");

    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(commandArgs).withDisableLogArchival(true).build();

    final String id = 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.waitForDone(id);

    Assert.assertEquals(this.getStatus(id), "{\"status\":\"FAILED\"}");

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

From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java

/**
 * Test the response content types to ensure UTF-8.
 *
 * @throws Exception If there is a problem.
 *///from  w ww  .jav  a  2  s  .  c o m
@Test
public void testResponseContentType() throws Exception {
    Assume.assumeTrue(SystemUtils.IS_OS_UNIX);
    final List<String> commandArgs = Lists.newArrayList("-c", "'echo hello'");

    final JobRequest jobRequest = new JobRequest.Builder(JOB_NAME, JOB_USER, JOB_VERSION,
            Lists.newArrayList(new ClusterCriteria(Sets.newHashSet("localhost"))), Sets.newHashSet("bash"))
                    .withCommandArgs(commandArgs).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.waitForDone(jobId);

    RestAssured.given(this.getRequestSpecification()).when().port(this.port)
            .get(JOBS_API + "/" + jobId + "/output/genie/logs/env.log").then()
            .statusCode(Matchers.is(HttpStatus.OK.value()))
            .contentType(Matchers.containsString(MediaType.TEXT_PLAIN_VALUE))
            .contentType(Matchers.containsString("UTF-8"));

    RestAssured.given(this.getRequestSpecification()).when().port(this.port)
            .get(JOBS_API + "/" + jobId + "/output/genie/logs/genie.log").then()
            .statusCode(Matchers.is(HttpStatus.OK.value()))
            .contentType(Matchers.containsString(MediaType.TEXT_PLAIN_VALUE))
            .contentType(Matchers.containsString("UTF-8"));

    RestAssured.given(this.getRequestSpecification()).when().port(this.port)
            .get(JOBS_API + "/" + jobId + "/output/genie/genie.done").then()
            .statusCode(Matchers.is(HttpStatus.OK.value()))
            .contentType(Matchers.containsString(MediaType.TEXT_PLAIN_VALUE))
            .contentType(Matchers.containsString("UTF-8"));

    RestAssured.given(this.getRequestSpecification()).accept(MediaType.ALL_VALUE).when().port(this.port)
            .get(JOBS_API + "/" + jobId + "/output/stdout").then()
            .statusCode(Matchers.is(HttpStatus.OK.value()))
            .contentType(Matchers.containsString(MediaType.TEXT_PLAIN_VALUE))
            .contentType(Matchers.containsString("UTF-8"));

    RestAssured.given(this.getRequestSpecification()).accept(MediaType.ALL_VALUE).when().port(this.port)
            .get(JOBS_API + "/" + jobId + "/output/stderr").then()
            .statusCode(Matchers.is(HttpStatus.OK.value()))
            .contentType(Matchers.containsString(MediaType.TEXT_PLAIN_VALUE))
            .contentType(Matchers.containsString("UTF-8"));

    // Verify the file is served as UTF-8 even if it's not
    RestAssured.given(this.getRequestSpecification()).accept(MediaType.ALL_VALUE).when().port(this.port)
            .get(JOBS_API + "/" + jobId + "/output/genie/command/" + CMD1_ID + "/config/" + GB18030_TXT).then()
            .statusCode(Matchers.is(HttpStatus.OK.value()))
            .contentType(Matchers.containsString(MediaType.TEXT_PLAIN_VALUE))
            .contentType(Matchers.containsString("UTF-8"));
}

From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java

private void createAnApplication(final String id, final String appName) throws Exception {
    final String setUpFile = this.resourceLoader.getResource(BASE_DIR + id + FILE_DELIMITER + "setupfile")
            .getFile().getAbsolutePath();

    final String depFile1 = this.resourceLoader.getResource(BASE_DIR + id + FILE_DELIMITER + "dep1").getFile()
            .getAbsolutePath();//w  ww  . j  a  va  2s . c o m
    final String depFile2 = this.resourceLoader.getResource(BASE_DIR + id + FILE_DELIMITER + "dep2").getFile()
            .getAbsolutePath();
    final Set<String> app1Dependencies = Sets.newHashSet(depFile1, depFile2);

    final String configFile1 = this.resourceLoader.getResource(BASE_DIR + id + FILE_DELIMITER + "config1")
            .getFile().getAbsolutePath();
    final String configFile2 = this.resourceLoader.getResource(BASE_DIR + id + FILE_DELIMITER + "config2")
            .getFile().getAbsolutePath();
    final Set<String> app1Configs = Sets.newHashSet(configFile1, configFile2);

    final Application app = new Application.Builder(appName, APP1_USER, APP1_VERSION, ApplicationStatus.ACTIVE)
            .withId(id).withSetupFile(setUpFile).withConfigs(app1Configs).withDependencies(app1Dependencies)
            .build();

    RestAssured.given(this.getRequestSpecification()).contentType(MediaType.APPLICATION_JSON_VALUE)
            .body(GenieObjectMapper.getMapper().writeValueAsBytes(app)).when().port(this.port)
            .post(APPLICATIONS_API).then().statusCode(Matchers.is(HttpStatus.CREATED.value()))
            .header(HttpHeaders.LOCATION, Matchers.notNullValue());
}

From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java

private void createAllClusters() throws Exception {
    final String setUpFile = this.resourceLoader
            .getResource(BASE_DIR + CLUSTER1_ID + FILE_DELIMITER + "setupfile").getFile().getAbsolutePath();

    final String configFile1 = this.resourceLoader
            .getResource(BASE_DIR + CLUSTER1_ID + FILE_DELIMITER + "config1").getFile().getAbsolutePath();
    final String configFile2 = this.resourceLoader
            .getResource(BASE_DIR + CLUSTER1_ID + FILE_DELIMITER + "config2").getFile().getAbsolutePath();
    final Set<String> configs = Sets.newHashSet(configFile1, configFile2);

    final String depFile1 = this.resourceLoader.getResource(BASE_DIR + CLUSTER1_ID + FILE_DELIMITER + "dep1")
            .getFile().getAbsolutePath();
    final String depFile2 = this.resourceLoader.getResource(BASE_DIR + CLUSTER1_ID + FILE_DELIMITER + "dep2")
            .getFile().getAbsolutePath();
    final Set<String> clusterDependencies = Sets.newHashSet(depFile1, depFile2);
    final Set<String> tags = Sets.newHashSet(LOCALHOST_CLUSTER_TAG);

    final Cluster cluster = new Cluster.Builder(CLUSTER1_NAME, CLUSTER1_USER, CLUSTER1_VERSION,
            ClusterStatus.UP).withId(CLUSTER1_ID).withSetupFile(setUpFile).withConfigs(configs)
                    .withDependencies(clusterDependencies).withTags(tags).build();

    RestAssured.given(this.getRequestSpecification()).contentType(MediaType.APPLICATION_JSON_VALUE)
            .body(GenieObjectMapper.getMapper().writeValueAsBytes(cluster)).when().port(this.port)
            .post(CLUSTERS_API).then().statusCode(Matchers.is(HttpStatus.CREATED.value()))
            .header(HttpHeaders.LOCATION, Matchers.notNullValue());
}

From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java

private void createAllCommands() throws Exception {
    final String setUpFile = this.resourceLoader.getResource(BASE_DIR + CMD1_ID + FILE_DELIMITER + "setupfile")
            .getFile().getAbsolutePath();

    final String configFile1 = this.resourceLoader.getResource(BASE_DIR + CMD1_ID + FILE_DELIMITER + "config1")
            .getFile().getAbsolutePath();
    final String configFile2 = this.resourceLoader.getResource(BASE_DIR + CMD1_ID + FILE_DELIMITER + "config2")
            .getFile().getAbsolutePath();
    final String configFile3 = this.resourceLoader
            .getResource(BASE_DIR + CMD1_ID + FILE_DELIMITER + GB18030_TXT).getFile().getAbsolutePath();
    final Set<String> configs = Sets.newHashSet(configFile1, configFile2, configFile3);
    final String depFile1 = this.resourceLoader.getResource(BASE_DIR + CLUSTER1_ID + FILE_DELIMITER + "dep1")
            .getFile().getAbsolutePath();
    final String depFile2 = this.resourceLoader.getResource(BASE_DIR + CLUSTER1_ID + FILE_DELIMITER + "dep2")
            .getFile().getAbsolutePath();
    final Set<String> commandDependencies = Sets.newHashSet(depFile1, depFile2);

    final Set<String> tags = Sets.newHashSet(BASH_COMMAND_TAG);

    final Command cmd = new Command.Builder(CMD1_NAME, CMD1_USER, CMD1_VERSION, CommandStatus.ACTIVE,
            CMD1_EXECUTABLE, CHECK_DELAY).withId(CMD1_ID).withSetupFile(setUpFile).withConfigs(configs)
                    .withDependencies(commandDependencies).withTags(tags).build();

    RestAssured.given(this.getRequestSpecification()).contentType(MediaType.APPLICATION_JSON_VALUE)
            .body(GenieObjectMapper.getMapper().writeValueAsBytes(cmd)).when().port(this.port)
            .post(COMMANDS_API).then().statusCode(Matchers.is(HttpStatus.CREATED.value()))
            .header(HttpHeaders.LOCATION, Matchers.notNullValue());
}

From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTests.java

private void createAnApplication(final String id, final String appName) throws Exception {
    final String setUpFile = this.resourceLoader.getResource(BASE_DIR + id + FILE_DELIMITER + "setupfile")
            .getFile().getAbsolutePath();

    final Set<String> app1Dependencies = new HashSet<>();
    final String depFile1 = this.resourceLoader.getResource(BASE_DIR + id + FILE_DELIMITER + "dep1").getFile()
            .getAbsolutePath();//from   ww w . j a  v  a 2  s  .c  om
    final String depFile2 = this.resourceLoader.getResource(BASE_DIR + id + FILE_DELIMITER + "dep2").getFile()
            .getAbsolutePath();
    app1Dependencies.add(depFile1);
    app1Dependencies.add(depFile2);

    final Set<String> app1Configs = new HashSet<>();
    final String configFile1 = this.resourceLoader.getResource(BASE_DIR + id + FILE_DELIMITER + "config1")
            .getFile().getAbsolutePath();
    final String configFile2 = this.resourceLoader.getResource(BASE_DIR + id + FILE_DELIMITER + "config2")
            .getFile().getAbsolutePath();
    app1Configs.add(configFile1);
    app1Configs.add(configFile2);

    final Application app = new Application.Builder(appName, APP1_USER, APP1_VERSION, ApplicationStatus.ACTIVE)
            .withId(id).withSetupFile(setUpFile).withConfigs(app1Configs).withDependencies(app1Dependencies)
            .build();

    this.mvc.perform(MockMvcRequestBuilders.post(APPLICATIONS_API).contentType(MediaType.APPLICATION_JSON)
            .content(this.objectMapper.writeValueAsBytes(app)))
            .andExpect(MockMvcResultMatchers.status().isCreated())
            .andExpect(MockMvcResultMatchers.header().string(HttpHeaders.LOCATION, Matchers.notNullValue()));
}

From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTests.java

private void createAllClusters() throws Exception {
    final String setUpFile = this.resourceLoader
            .getResource(BASE_DIR + CLUSTER1_ID + FILE_DELIMITER + "setupfile").getFile().getAbsolutePath();

    final Set<String> configs = new HashSet<>();
    final String configFile1 = this.resourceLoader
            .getResource(BASE_DIR + CLUSTER1_ID + FILE_DELIMITER + "config1").getFile().getAbsolutePath();
    final String configFile2 = this.resourceLoader
            .getResource(BASE_DIR + CLUSTER1_ID + FILE_DELIMITER + "config2").getFile().getAbsolutePath();
    configs.add(configFile1);//from  w w w . jav a 2s .c  o m
    configs.add(configFile2);

    final Set<String> tags = new HashSet<>();
    tags.add("localhost");

    final Cluster cluster = new Cluster.Builder(CLUSTER1_NAME, CLUSTER1_USER, CLUSTER1_VERSION,
            ClusterStatus.UP).withId(CLUSTER1_ID).withSetupFile(setUpFile).withConfigs(configs).withTags(tags)
                    .build();

    this.mvc.perform(MockMvcRequestBuilders.post(CLUSTERS_API).contentType(MediaType.APPLICATION_JSON)
            .content(objectMapper.writeValueAsBytes(cluster)))
            .andExpect(MockMvcResultMatchers.status().isCreated())
            .andExpect(MockMvcResultMatchers.header().string(HttpHeaders.LOCATION, Matchers.notNullValue()));
}

From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTests.java

private void createAllCommands() throws Exception {
    final String setUpFile = this.resourceLoader.getResource(BASE_DIR + CMD1_ID + FILE_DELIMITER + "setupfile")
            .getFile().getAbsolutePath();

    final Set<String> configs = new HashSet<>();
    final String configFile1 = this.resourceLoader.getResource(BASE_DIR + CMD1_ID + FILE_DELIMITER + "config1")
            .getFile().getAbsolutePath();
    final String configFile2 = this.resourceLoader.getResource(BASE_DIR + CMD1_ID + FILE_DELIMITER + "config2")
            .getFile().getAbsolutePath();
    configs.add(configFile1);//from  w ww .  j  av  a 2  s . com
    configs.add(configFile2);

    final Set<String> tags = new HashSet<>();
    tags.add("bash");

    final Command cmd = new Command.Builder(CMD1_NAME, CMD1_USER, CMD1_VERSION, CommandStatus.ACTIVE,
            CMD1_EXECUTABLE, CHECK_DELAY).withId(CMD1_ID).withSetupFile(setUpFile).withConfigs(configs)
                    .withTags(tags).build();

    this.mvc.perform(MockMvcRequestBuilders.post(COMMANDS_API).contentType(MediaType.APPLICATION_JSON)
            .content(objectMapper.writeValueAsBytes(cmd))).andExpect(MockMvcResultMatchers.status().isCreated())
            .andExpect(MockMvcResultMatchers.header().string(HttpHeaders.LOCATION, Matchers.notNullValue()));
}

From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTests.java

/**
 * Test the job submit method for when the job is killed by sending a DELETE HTTP call.
 *
 * @throws Exception If there is a problem.
 *///from  www . j  a v a  2 s  .com
@Test
public void testSubmitJobMethodKill() throws Exception {
    Assume.assumeTrue(SystemUtils.IS_OS_UNIX);
    final String commandArgs = "-c 'sleep 60'";

    final List<ClusterCriteria> clusterCriteriaList = new ArrayList<>();
    final Set<String> clusterTags = new HashSet<>();
    clusterTags.add("localhost");
    final ClusterCriteria clusterCriteria = new ClusterCriteria(clusterTags);
    clusterCriteriaList.add(clusterCriteria);

    final Set<String> commandCriteria = new HashSet<>();
    commandCriteria.add("bash");
    final JobRequest jobRequest = new JobRequest.Builder(JOB_NAME, JOB_USER, JOB_VERSION, commandArgs,
            clusterCriteriaList, commandCriteria).withDisableLogArchival(true).build();

    final MvcResult result = this.mvc
            .perform(MockMvcRequestBuilders.post(JOBS_API).contentType(MediaType.APPLICATION_JSON)
                    .content(this.objectMapper.writeValueAsBytes(jobRequest)))
            .andExpect(MockMvcResultMatchers.status().isAccepted())
            .andExpect(MockMvcResultMatchers.header().string(HttpHeaders.LOCATION, Matchers.notNullValue()))
            .andReturn();

    final String jobId = this.getIdFromLocation(result.getResponse().getHeader(HttpHeaders.LOCATION));
    this.waitForRunning(jobId);

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

    // Send a kill request to the job.
    final RestDocumentationResultHandler killResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/killJob/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM);
    this.mvc.perform(RestDocumentationRequestBuilders.delete(JOBS_API + "/{id}", jobId))
            .andExpect(MockMvcResultMatchers.status().isAccepted()).andDo(killResultHandler);

    this.waitForDone(jobId);

    this.mvc.perform(MockMvcRequestBuilders.get(JOBS_API + "/" + jobId))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(ID_PATH, Matchers.is(jobId)))
            .andExpect(MockMvcResultMatchers.jsonPath(STATUS_PATH, Matchers.is(JobStatus.KILLED.toString())));

    // Kill the job again to make sure it doesn't cause a problem.
    this.mvc.perform(MockMvcRequestBuilders.delete(JOBS_API + "/" + jobId))
            .andExpect(MockMvcResultMatchers.status().isAccepted());
}