Search in sources :

Example 1 with YarnEndpoint

use of com.sequenceiq.cloudbreak.cloud.yarn.client.api.YarnEndpoint in project cloudbreak by hortonworks.

the class YarnHttpClient method validateApiEndpoint.

@Override
public void validateApiEndpoint() throws YarnClientException, MalformedURLException {
    YarnEndpoint dashEndpoint = new YarnEndpoint(apiEndpoint, YarnResourceConstants.APPLICATIONS_PATH);
    ClientConfig clientConfig = new DefaultClientConfig();
    Client client = Client.create(clientConfig);
    WebResource webResource = client.resource(dashEndpoint.getFullEndpointUrl().toString());
    ClientResponse response = webResource.accept("application/json").type("application/json").get(ClientResponse.class);
    // Validate HTTP 200 status code
    if (response.getStatus() != YarnResourceConstants.HTTP_SUCCESS) {
        String msg = String.format("Received %d status code from url %s, reason: %s", response.getStatus(), dashEndpoint.getFullEndpointUrl().toString(), response.getEntity(String.class));
        LOGGER.debug(msg);
        throw new YarnClientException(msg);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) YarnClientException(com.sequenceiq.cloudbreak.cloud.yarn.client.exception.YarnClientException) WebResource(com.sun.jersey.api.client.WebResource) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) Client(com.sun.jersey.api.client.Client) YarnEndpoint(com.sequenceiq.cloudbreak.cloud.yarn.client.api.YarnEndpoint)

Example 2 with YarnEndpoint

use of com.sequenceiq.cloudbreak.cloud.yarn.client.api.YarnEndpoint in project cloudbreak by hortonworks.

the class YarnHttpClient method getApplicationDetail.

@Override
public ResponseContext getApplicationDetail(ApplicationDetailRequest applicationDetailRequest) throws MalformedURLException {
    ResponseContext responseContext = new ResponseContext();
    // Add the application name to the URL
    YarnEndpoint dashEndpoint = new YarnEndpoint(apiEndpoint, YarnResourceConstants.APPLICATIONS_PATH + '/' + applicationDetailRequest.getName());
    // Construct the webresource and perform the get
    WebResource webResource = getNewWebResource(dashEndpoint.getFullEndpointUrl().toString());
    ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    responseContext.setStatusCode(response.getStatus());
    // Validate the results
    if (checkStatusCode(response, YarnResourceConstants.HTTP_SUCCESS)) {
        responseContext.setResponseObject(response.getEntity(ApplicationDetailResponse.class));
    } else {
        responseContext.setResponseError(response.getEntity(ApplicationErrorResponse.class));
    }
    return responseContext;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ApplicationDetailResponse(com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ApplicationDetailResponse) ResponseContext(com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ResponseContext) WebResource(com.sun.jersey.api.client.WebResource) ApplicationErrorResponse(com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ApplicationErrorResponse) YarnEndpoint(com.sequenceiq.cloudbreak.cloud.yarn.client.api.YarnEndpoint)

Example 3 with YarnEndpoint

use of com.sequenceiq.cloudbreak.cloud.yarn.client.api.YarnEndpoint in project cloudbreak by hortonworks.

the class YarnHttpClient method createApplication.

@Override
public ResponseContext createApplication(CreateApplicationRequest createApplicationRequest) throws MalformedURLException {
    YarnEndpoint dashEndpoint = new YarnEndpoint(apiEndpoint, YarnResourceConstants.APPLICATIONS_PATH);
    ResponseContext responseContext = new ResponseContext();
    // Construct the webresource and perform the get
    WebResource webResource = getNewWebResource(dashEndpoint.getFullEndpointUrl().toString());
    ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post(ClientResponse.class, createApplicationRequest);
    responseContext.setStatusCode(response.getStatus());
    // Validate the results
    if (responseContext.getStatusCode() == YarnResourceConstants.HTTP_ACCEPTED) {
        responseContext.setResponseObject(response.getEntity(ApplicationDetailResponse.class));
    } else {
        responseContext.setResponseError(response.getEntity(ApplicationErrorResponse.class));
    }
    return responseContext;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ApplicationDetailResponse(com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ApplicationDetailResponse) ResponseContext(com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ResponseContext) WebResource(com.sun.jersey.api.client.WebResource) ApplicationErrorResponse(com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ApplicationErrorResponse) YarnEndpoint(com.sequenceiq.cloudbreak.cloud.yarn.client.api.YarnEndpoint)

Example 4 with YarnEndpoint

use of com.sequenceiq.cloudbreak.cloud.yarn.client.api.YarnEndpoint in project cloudbreak by hortonworks.

the class YarnHttpClient method deleteApplication.

@Override
public void deleteApplication(DeleteApplicationRequest deleteApplicationRequest) throws YarnClientException, MalformedURLException {
    // Add the application name to the URL
    YarnEndpoint dashEndpoint = new YarnEndpoint(apiEndpoint, YarnResourceConstants.APPLICATIONS_PATH + '/' + deleteApplicationRequest.getName());
    ClientConfig clientConfig = new DefaultClientConfig();
    Client client = Client.create(clientConfig);
    // Delete the application
    WebResource webResource = client.resource(dashEndpoint.getFullEndpointUrl().toString());
    ClientResponse response = webResource.accept("application/json").type("application/json").delete(ClientResponse.class);
    // Validate HTTP 204 return
    String msg;
    switch(response.getStatus()) {
        case YarnResourceConstants.HTTP_NO_CONTENT:
            msg = String.format("Successfully deleted application %s", deleteApplicationRequest.getName());
            LOGGER.debug(msg);
            break;
        case YarnResourceConstants.HTTP_NOT_FOUND:
            msg = String.format("Application %s not found, already deleted?", deleteApplicationRequest.getName());
            LOGGER.debug(msg);
            break;
        default:
            msg = String.format("Received %d status code from url %s, reason: %s", response.getStatus(), dashEndpoint.getFullEndpointUrl().toString(), response.getEntity(String.class));
            LOGGER.debug(msg);
            throw new YarnClientException(msg);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) YarnClientException(com.sequenceiq.cloudbreak.cloud.yarn.client.exception.YarnClientException) WebResource(com.sun.jersey.api.client.WebResource) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) Client(com.sun.jersey.api.client.Client) YarnEndpoint(com.sequenceiq.cloudbreak.cloud.yarn.client.api.YarnEndpoint)

Aggregations

YarnEndpoint (com.sequenceiq.cloudbreak.cloud.yarn.client.api.YarnEndpoint)4 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 WebResource (com.sun.jersey.api.client.WebResource)4 YarnClientException (com.sequenceiq.cloudbreak.cloud.yarn.client.exception.YarnClientException)2 ApplicationDetailResponse (com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ApplicationDetailResponse)2 ApplicationErrorResponse (com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ApplicationErrorResponse)2 ResponseContext (com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ResponseContext)2 Client (com.sun.jersey.api.client.Client)2 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)2 DefaultClientConfig (com.sun.jersey.api.client.config.DefaultClientConfig)2