use of com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ResponseContext in project cloudbreak by hortonworks.
the class YarnApplicationPoller method waitForApplicationStart.
public void waitForApplicationStart(String appName, String apiEndpoint) throws CloudbreakOrchestratorException, MalformedURLException {
YarnClient dashHttpClient = new YarnHttpClient(apiEndpoint);
for (int i = 1; i <= RETRIES; i++) {
// Make the request
ResponseContext responseContext = dashHttpClient.getApplicationDetail(getApplicationDetailRequest(appName));
// If 404, application isn't ready, sleep
if (responseContext.getStatusCode() == YarnResourceConstants.HTTP_NOT_FOUND) {
handle404(appName, responseContext);
}
// If 200, check application state to ensure RUNNING
if (responseContext.getStatusCode() == YarnResourceConstants.HTTP_SUCCESS) {
if (null != responseContext.getResponseObject()) {
ApplicationDetailResponse applicationDetailResponse = (ApplicationDetailResponse) responseContext.getResponseObject();
// Validate the application is "RUNNING"
if (!applicationDetailResponse.getState().equals(ApplicationState.READY.name())) {
LOGGER.debug(String.format("Application %s not ready, in %s state, sleeping 1000 ms", appName, applicationDetailResponse.getState()));
sleep();
} else {
// Validate the container is running
if (!applicationDetailResponse.getContainers().isEmpty()) {
Container appContainer = applicationDetailResponse.getContainers().get(0);
if (!appContainer.getState().equals(ContainerState.READY.name())) {
String msg = String.format("Application %s not ready, in %s state, sleeping 1000 ms", appName, applicationDetailResponse.getState());
LOGGER.debug(msg);
sleep();
} else {
String msg = String.format("Application %s has now successfully started, in %s state", appName, applicationDetailResponse.getState());
LOGGER.debug(msg);
break;
}
}
}
}
}
if (i == RETRIES) {
String msg = String.format("ERROR: %s did not start in %d retries", appName, RETRIES);
throw new CloudbreakOrchestratorFailedException(msg);
}
}
}
use of com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ResponseContext 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;
}
use of com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ResponseContext 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;
}
use of com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ResponseContext in project cloudbreak by hortonworks.
the class ApplicationDetailHandler method getContainerInfo.
public ContainerInfo getContainerInfo(ContainerConfig config, OrchestrationCredential cred, ContainerConstraint constraint, int componentNumber) throws CloudbreakOrchestratorFailedException {
String applicationName = applicationUtils.getApplicationName(constraint, componentNumber);
// Build the ApplicationDetailRequest
ApplicationDetailRequest applicationDetailRequest = new ApplicationDetailRequest();
applicationDetailRequest.setName(applicationName);
try {
// Validate that the app exists
YarnClient yarnHttpClient = new YarnHttpClient(cred.getApiEndpoint());
ResponseContext appDetailResponseContext = yarnHttpClient.getApplicationDetail(applicationDetailRequest);
if (appDetailResponseContext.getResponseError() != null) {
ApplicationErrorResponse applicationErrorResponse = appDetailResponseContext.getResponseError();
throw new CloudbreakOrchestratorFailedException(String.format("ERROR: HTTP Return: %d Error: %s.", appDetailResponseContext.getStatusCode(), applicationErrorResponse.getDiagnostics()));
}
// Return the details
String componentHostName = applicationUtils.getComponentHostName(constraint, cred, componentNumber);
String image = String.format("%s:%s", config.getName(), config.getVersion());
return new ContainerInfo(applicationName, applicationName, componentHostName, image);
} catch (MalformedURLException e) {
String msg = String.format("ERROR: URL is malformed: %s", cred.getApiEndpoint());
throw new CloudbreakOrchestratorFailedException(msg, e);
}
}
use of com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ResponseContext in project cloudbreak by hortonworks.
the class ApplicationSubmissionHandler method submitCreateApplicationRequest.
private void submitCreateApplicationRequest(CreateApplicationRequest createApplicationRequest, YarnClient yarnHttpClient) throws CloudbreakOrchestratorFailedException {
try {
ResponseContext createAppResponseContext = yarnHttpClient.createApplication(createApplicationRequest);
if (createAppResponseContext.getResponseError() != null) {
ApplicationErrorResponse applicationErrorResponse = createAppResponseContext.getResponseError();
String msg = String.format("ERROR: HTTP Return: %d Error: %s", createAppResponseContext.getStatusCode(), applicationErrorResponse.getDiagnostics());
LOGGER.debug(msg);
throw new CloudbreakOrchestratorFailedException(msg);
}
} catch (Exception e) {
throw new CloudbreakOrchestratorFailedException(e);
}
}
Aggregations