use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.
the class SaltUpload method call.
@Override
public Boolean call() throws Exception {
LOGGER.info("Uploading files to: {}", targets);
if (!targets.isEmpty()) {
LOGGER.info("Current targets for upload: {}", targets);
GenericResponses responses = sc.upload(targets, path, fileName, content);
Set<String> failedTargets = new HashSet<>();
LOGGER.info("Salt file upload responses: {}", responses);
for (GenericResponse genericResponse : responses.getResponses()) {
if (genericResponse.getStatusCode() != HttpStatus.CREATED.value()) {
LOGGER.info("Failed upload attempt to: " + genericResponse.getAddress());
String address = genericResponse.getAddress().split(":")[0];
failedTargets.addAll(originalTargets.stream().filter(a -> a.equals(address)).collect(Collectors.toList()));
}
}
targets = failedTargets;
if (!targets.isEmpty()) {
LOGGER.info("Missing nodes for file upload: {}", targets);
throw new CloudbreakOrchestratorFailedException("There are missing nodes for file upload: " + targets);
}
}
LOGGER.info("File upload has been completed on nodes: {}", originalTargets);
return true;
}
use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.
the class YarnHttpClient method deleteApplication.
@Override
public void deleteApplication(DeleteApplicationRequest deleteApplicationRequest) throws CloudbreakOrchestratorFailedException, 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 CloudbreakOrchestratorFailedException(msg);
}
}
use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.
the class ApplicationSubmissionHandler method submitApplication.
public void submitApplication(ContainerConfig config, OrchestrationCredential cred, ContainerConstraint constraint, int componentNumber) throws CloudbreakOrchestratorFailedException {
// Set Ambari DB hostname, if available
if (ComponentType.AMBARIDB.equals(applicationUtils.getComponentType(constraint))) {
ambariDbHostname = applicationUtils.getComponentHostName(constraint, cred, componentNumber);
}
// Set Ambari Server hostname, if available
if (ComponentType.AMBARISERVER.equals(applicationUtils.getComponentType(constraint))) {
ambariServerHostname = applicationUtils.getComponentHostName(constraint, cred, componentNumber);
}
// Application level attributes
String applicationName = applicationUtils.getApplicationName(constraint, componentNumber);
CreateApplicationRequest createApplicationRequest = new CreateApplicationRequest();
createApplicationRequest.setName(applicationName);
createApplicationRequest.setQueue(config.getQueue());
createApplicationRequest.setLifetime(UNLIMITED);
// Define the artifact (docker image) for the component
Artifact artifact = new Artifact();
artifact.setId(getDockerImageName(config));
artifact.setType("DOCKER");
// Define the resources for the component
Resource resource = new Resource();
resource.setCpus(getCpusForContainerType(constraint));
resource.setMemory(getMemForContainerType(constraint));
// Add the component
List<YarnComponent> components = new ArrayList<>();
YarnComponent component = new YarnComponent();
component.setName(applicationUtils.getComponentName(constraint, componentNumber));
component.setNumberOfContainers(ONE);
component.setLaunchCommand(getFullEntrypoint(constraint, cred, componentNumber));
component.setArtifact(artifact);
component.setDependencies(new ArrayList<>());
component.setResource(resource);
component.setRunPrivilegedContainer(true);
components.add(component);
createApplicationRequest.setComponents(components);
// Submit the request
YarnClient yarnHttpClient = new YarnHttpClient(cred.getApiEndpoint());
try {
submitCreateApplicationRequest(createApplicationRequest, yarnHttpClient);
} catch (RuntimeException e) {
throw new CloudbreakOrchestratorFailedException(e);
}
}
use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException 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.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.
the class ClusterBootstrapperErrorHandler method terminateFailedNodes.
public void terminateFailedNodes(HostOrchestrator hostOrchestrator, ContainerOrchestrator containerOrchestrator, Stack stack, GatewayConfig gatewayConfig, Set<Node> nodes) throws CloudbreakOrchestratorFailedException {
List<String> allAvailableNode;
allAvailableNode = hostOrchestrator != null ? hostOrchestrator.getAvailableNodes(gatewayConfig, nodes) : containerOrchestrator.getAvailableNodes(gatewayConfig, nodes);
List<Node> missingNodes = selectMissingNodes(nodes, allAvailableNode);
if (!missingNodes.isEmpty()) {
String message = cloudbreakMessagesService.getMessage(Msg.BOOTSTRAPPER_ERROR_BOOTSTRAP_FAILED_ON_NODES.code(), Collections.singletonList(missingNodes.size()));
LOGGER.info(message);
eventService.fireCloudbreakEvent(stack.getId(), Status.UPDATE_IN_PROGRESS.name(), message);
for (Node missingNode : missingNodes) {
InstanceMetaData instanceMetaData = instanceMetaDataRepository.findNotTerminatedByPrivateAddress(stack.getId(), missingNode.getPrivateIp());
InstanceGroup ig = instanceGroupRepository.findOneByGroupNameInStack(stack.getId(), instanceMetaData.getInstanceGroup().getGroupName());
ig.setNodeCount(ig.getNodeCount() - 1);
if (ig.getNodeCount() < 1) {
throw new CloudbreakOrchestratorFailedException(cloudbreakMessagesService.getMessage(Msg.BOOTSTRAPPER_ERROR_INVALID_NODECOUNT.code(), Collections.singletonList(ig.getGroupName())));
}
instanceGroupRepository.save(ig);
message = cloudbreakMessagesService.getMessage(Msg.BOOTSTRAPPER_ERROR_DELETING_NODE.code(), Arrays.asList(instanceMetaData.getInstanceId(), ig.getGroupName()));
LOGGER.info(message);
eventService.fireCloudbreakEvent(stack.getId(), Status.UPDATE_IN_PROGRESS.name(), message);
deleteResourceAndDependencies(stack, instanceMetaData);
deleteInstanceResourceFromDatabase(stack, instanceMetaData);
long timeInMillis = Calendar.getInstance().getTimeInMillis();
instanceMetaData.setTerminationDate(timeInMillis);
instanceMetaData.setInstanceStatus(InstanceStatus.TERMINATED);
instanceMetaDataRepository.save(instanceMetaData);
LOGGER.info("InstanceMetadata [name: {}, id: {}] status set to {}.", instanceMetaData.getId(), instanceMetaData.getInstanceId(), instanceMetaData.getInstanceStatus());
}
}
}
Aggregations