org.apache.hadoop.fs.swift.exceptions.SwiftInvalidResponseException Java Examples

The following examples show how to use org.apache.hadoop.fs.swift.exceptions.SwiftInvalidResponseException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SwiftRestClient.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Create a container -if it already exists, do nothing
 *
 * @param containerName the container name
 * @throws IOException IO problems
 * @throws SwiftBadRequestException invalid container name
 * @throws SwiftInvalidResponseException error from the server
 */
public void createContainer(String containerName) throws IOException {
  SwiftObjectPath objectPath = new SwiftObjectPath(containerName, "");
  try {
    //see if the data is there
    headRequest("createContainer", objectPath, NEWEST);
  } catch (FileNotFoundException ex) {
    int status = 0;
    try {
      status = putRequest(objectPath);
    } catch (FileNotFoundException e) {
      //triggered by a very bad container name.
      //re-insert the 404 result into the status
      status = SC_NOT_FOUND;
    }
    if (status == SC_BAD_REQUEST) {
      throw new SwiftBadRequestException(
        "Bad request -authentication failure or bad container name?",
        status,
        "PUT",
        null);
    }
    if (!isStatusCodeExpected(status,
            SC_OK,
            SC_CREATED,
            SC_ACCEPTED,
            SC_NO_CONTENT)) {
      throw new SwiftInvalidResponseException("Couldn't create container "
              + containerName +
              " for storing data in Swift." +
              " Try to create container " +
              containerName + " manually ",
              status,
              "PUT",
              null);
    } else {
      throw ex;
    }
  }
}
 
Example #2
Source File: SwiftRestClient.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Create a container -if it already exists, do nothing
 *
 * @param containerName the container name
 * @throws IOException IO problems
 * @throws SwiftBadRequestException invalid container name
 * @throws SwiftInvalidResponseException error from the server
 */
public void createContainer(String containerName) throws IOException {
  SwiftObjectPath objectPath = new SwiftObjectPath(containerName, "");
  try {
    //see if the data is there
    headRequest("createContainer", objectPath, NEWEST);
  } catch (FileNotFoundException ex) {
    int status = 0;
    try {
      status = putRequest(objectPath);
    } catch (FileNotFoundException e) {
      //triggered by a very bad container name.
      //re-insert the 404 result into the status
      status = SC_NOT_FOUND;
    }
    if (status == SC_BAD_REQUEST) {
      throw new SwiftBadRequestException(
        "Bad request -authentication failure or bad container name?",
        status,
        "PUT",
        null);
    }
    if (!isStatusCodeExpected(status,
            SC_OK,
            SC_CREATED,
            SC_ACCEPTED,
            SC_NO_CONTENT)) {
      throw new SwiftInvalidResponseException("Couldn't create container "
              + containerName +
              " for storing data in Swift." +
              " Try to create container " +
              containerName + " manually ",
              status,
              "PUT",
              null);
    } else {
      throw ex;
    }
  }
}
 
Example #3
Source File: SwiftRestClient.java    From sahara-extra with Apache License 2.0 5 votes vote down vote up
/**
 * Create a container -if it already exists, do nothing
 *
 * @param containerName the container name
 * @throws IOException IO problems
 * @throws SwiftBadRequestException invalid container name
 * @throws SwiftInvalidResponseException error from the server
 */
public void createContainer(String containerName) throws IOException {
  SwiftObjectPath objectPath = new SwiftObjectPath(containerName, "");
  try {
    //see if the data is there
    headRequest("createContainer", objectPath, NEWEST);
  } catch (FileNotFoundException ex) {
    int status = 0;
    try {
      status = putRequest(objectPath);
    } catch (FileNotFoundException e) {
      //triggered by a very bad container name.
      //re-insert the 404 result into the status
      status = SC_NOT_FOUND;
    }
    if (status == SC_BAD_REQUEST) {
      throw new SwiftBadRequestException(
        "Bad request -authentication failure or bad container name?",
        status,
        "PUT",
        null);
    }
    if (!isStatusCodeExpected(status,
            SC_OK,
            SC_CREATED,
            SC_ACCEPTED,
            SC_NO_CONTENT)) {
      throw new SwiftInvalidResponseException("Couldn't create container "
              + containerName +
              " for storing data in Swift." +
              " Try to create container " +
              containerName + " manually ",
              status,
              "PUT",
              null);
    } else {
      throw ex;
    }
  }
}
 
Example #4
Source File: SwiftRestClient.java    From hadoop with Apache License 2.0 3 votes vote down vote up
/**
 * Performs the HTTP request, validates the response code and returns
 * the received data. HTTP Status codes are converted into exceptions.
 *
 * @param uri URI to source
 * @param processor HttpMethodProcessor
 * @param <M> method
 * @param <R> result type
 * @return result of HTTP request
 * @throws IOException IO problems
 * @throws SwiftBadRequestException the status code indicated "Bad request"
 * @throws SwiftInvalidResponseException the status code is out of range
 * for the action (excluding 404 responses)
 * @throws SwiftInternalStateException the internal state of this client
 * is invalid
 * @throws FileNotFoundException a 404 response was returned
 */
private <M extends HttpMethod, R> R perform(URI uri,
                    HttpMethodProcessor<M, R> processor)
  throws IOException,
         SwiftBadRequestException,
         SwiftInternalStateException,
         SwiftInvalidResponseException,
         FileNotFoundException {
  return perform("",uri, processor);
}
 
Example #5
Source File: SwiftRestClient.java    From big-c with Apache License 2.0 3 votes vote down vote up
/**
 * Performs the HTTP request, validates the response code and returns
 * the received data. HTTP Status codes are converted into exceptions.
 *
 * @param uri URI to source
 * @param processor HttpMethodProcessor
 * @param <M> method
 * @param <R> result type
 * @return result of HTTP request
 * @throws IOException IO problems
 * @throws SwiftBadRequestException the status code indicated "Bad request"
 * @throws SwiftInvalidResponseException the status code is out of range
 * for the action (excluding 404 responses)
 * @throws SwiftInternalStateException the internal state of this client
 * is invalid
 * @throws FileNotFoundException a 404 response was returned
 */
private <M extends HttpMethod, R> R perform(URI uri,
                    HttpMethodProcessor<M, R> processor)
  throws IOException,
         SwiftBadRequestException,
         SwiftInternalStateException,
         SwiftInvalidResponseException,
         FileNotFoundException {
  return perform("",uri, processor);
}
 
Example #6
Source File: SwiftRestClient.java    From sahara-extra with Apache License 2.0 3 votes vote down vote up
/**
 * Performs the HTTP request, validates the response code and returns
 * the received data. HTTP Status codes are converted into exceptions.
 *
 * @param uri URI to source
 * @param processor HttpMethodProcessor
 * @param <M> method
 * @param <R> result type
 * @return result of HTTP request
 * @throws IOException IO problems
 * @throws SwiftBadRequestException the status code indicated "Bad request"
 * @throws SwiftInvalidResponseException the status code is out of range
 * for the action (excluding 404 responses)
 * @throws SwiftInternalStateException the internal state of this client
 * is invalid
 * @throws FileNotFoundException a 404 response was returned
 */
private <M extends HttpMethod, R> R perform(URI uri,
                    HttpMethodProcessor<M, R> processor)
  throws IOException,
         SwiftBadRequestException,
         SwiftInternalStateException,
         SwiftInvalidResponseException,
         FileNotFoundException {
  return perform("",uri, processor);
}