use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.
the class SaltJobIdTrackerTest method callWithInProgressAndMissingNodes.
@Test
public void callWithInProgressAndMissingNodes() throws Exception {
String jobId = "1";
SaltConnector saltConnector = Mockito.mock(SaltConnector.class);
SaltJobRunner saltJobRunner = Mockito.mock(BaseSaltJobRunner.class);
when(saltJobRunner.getJid()).thenReturn(JobId.jobId(jobId));
when(saltJobRunner.getJobState()).thenCallRealMethod();
doCallRealMethod().when(saltJobRunner).setJobState(any());
when(saltJobRunner.submit(any(SaltConnector.class))).thenReturn(jobId);
saltJobRunner.setJobState(JobState.IN_PROGRESS);
Set<String> targets = new HashSet<>();
targets.add("10.0.0.1");
targets.add("10.0.0.2");
targets.add("10.0.0.3");
when(saltJobRunner.getTarget()).thenReturn(targets);
PowerMockito.mockStatic(SaltStates.class);
PowerMockito.when(SaltStates.jobIsRunning(any(), any())).thenReturn(false);
Multimap<String, String> missingNodesWithReason = ArrayListMultimap.create();
String missingMachine = "10.0.0.1";
String errorMessage = "error happened";
missingNodesWithReason.put(missingMachine, errorMessage);
when(saltJobRunner.getNodesWithError()).thenReturn(missingNodesWithReason);
SaltJobIdTracker saltJobIdTracker = new SaltJobIdTracker(saltConnector, saltJobRunner);
try {
saltJobIdTracker.call();
fail("should throw exception");
} catch (CloudbreakOrchestratorFailedException e) {
assertThat(e.getMessage(), both(containsString(missingMachine)).and(containsString(errorMessage)));
}
PowerMockito.verifyStatic();
SaltStates.jobIsRunning(any(), eq(jobId));
checkTargets(targets, targetCaptor.getAllValues());
}
use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.
the class YarnContainerOrchestrator method runContainer.
@Override
public List<ContainerInfo> runContainer(ContainerConfig config, OrchestrationCredential cred, ContainerConstraint constraint, ExitCriteriaModel exitCriteriaModel) throws CloudbreakOrchestratorException {
// Create an application per component
List<ContainerInfo> containerInfos = new ArrayList<>();
for (int componentNumber = 1; componentNumber <= constraint.getInstances(); componentNumber++) {
try {
submitHandler.submitApplication(config, cred, constraint, componentNumber);
String applicationName = applicationUtils.getApplicationName(constraint, componentNumber);
OrchestratorBootstrap bootstrap = new YarnAppBootstrap(applicationName, cred.getApiEndpoint());
Callable<Boolean> runner = runner(bootstrap, getExitCriteria(), exitCriteriaModel);
Future<Boolean> appFuture = getParallelOrchestratorComponentRunner().submit(runner);
appFuture.get();
containerInfos.add(detailHandler.getContainerInfo(config, cred, constraint, componentNumber));
} catch (CloudbreakOrchestratorException | InterruptedException | ExecutionException e) {
throw new CloudbreakOrchestratorFailedException(e);
}
}
return containerInfos;
}
use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.
the class YarnContainerOrchestrator method deleteContainer.
@Override
public void deleteContainer(List<ContainerInfo> containerInfo, OrchestrationCredential cred) throws CloudbreakOrchestratorException {
for (ContainerInfo container : containerInfo) {
DeleteApplicationRequest deleteApplicationRequest = new DeleteApplicationRequest();
deleteApplicationRequest.setName(container.getName());
YarnClient yarnHttpClient = new YarnHttpClient(cred.getApiEndpoint());
try {
yarnHttpClient.deleteApplication(deleteApplicationRequest);
} catch (Exception e) {
throw new CloudbreakOrchestratorFailedException(e.getMessage(), e);
}
}
}
use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.
the class SaltBootstrap method call.
@Override
public Boolean call() throws Exception {
LOGGER.info("Bootstrapping of nodes [{}/{}]", originalTargets.size() - targets.size(), originalTargets.size());
if (!targets.isEmpty()) {
LOGGER.info("Missing targets for SaltBootstrap: {}", targets);
SaltAction saltAction = createBootstrap();
GenericResponses responses = sc.action(saltAction);
Set<Node> failedTargets = new HashSet<>();
LOGGER.info("SaltBootstrap responses: {}", responses);
for (GenericResponse genericResponse : responses.getResponses()) {
if (genericResponse.getStatusCode() != HttpStatus.OK.value()) {
LOGGER.info("Failed to distributed salt run to: " + genericResponse.getAddress());
String address = genericResponse.getAddress().split(":")[0];
failedTargets.addAll(originalTargets.stream().filter(a -> a.getPrivateIp().equals(address)).collect(Collectors.toList()));
}
}
targets = failedTargets;
if (!targets.isEmpty()) {
LOGGER.info("Missing nodes to run saltbootstrap: {}", targets);
throw new CloudbreakOrchestratorFailedException("There are missing nodes from saltbootstrap: " + targets);
}
}
String iFace = SaltStates.defaultRoute(sc, Glob.ALL).getGatewayInterfaceName();
Map<String, String> networkResult = SaltStates.networkInterfaceIP(sc, Glob.ALL, iFace).getResultGroupByIP();
originalTargets.forEach(node -> {
if (!networkResult.containsKey(node.getPrivateIp())) {
LOGGER.info("Salt-minion is not responding on host: {}, yet", node);
targets.add(node);
}
});
if (!targets.isEmpty()) {
throw new CloudbreakOrchestratorFailedException("There are missing nodes from salt network response: " + targets);
}
LOGGER.info("Bootstrapping of nodes completed: {}", originalTargets.size());
return true;
}
use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.
the class SaltJobIdTracker method call.
@Override
public Boolean call() throws Exception {
if (JobState.NOT_STARTED.equals(saltJobRunner.getJobState())) {
LOGGER.info("Job has not started in the cluster. Starting for first time.");
JobId jobIdObject = jobId(saltJobRunner.submit(saltConnector));
String jobId = jobIdObject.getJobId();
saltJobRunner.setJid(jobIdObject);
checkIsFinished(jobId);
} else if (JobState.IN_PROGRESS.equals(saltJobRunner.getJobState())) {
String jobId = saltJobRunner.getJid().getJobId();
LOGGER.info("Job: {} is running currently checking the current state.", jobId);
checkIsFinished(jobId);
} else if (!retryOnFail && JobState.FAILED == saltJobRunner.getJobState()) {
String jobId = saltJobRunner.getJid().getJobId();
LOGGER.info("Job: {} failed. Terminate execution on these targets: {}", jobId, saltJobRunner.getTarget());
throw new CloudbreakOrchestratorTerminateException(buildErrorMessage());
} else if (JobState.FAILED == saltJobRunner.getJobState() || JobState.AMBIGUOUS == saltJobRunner.getJobState()) {
String jobId = saltJobRunner.getJid().getJobId();
LOGGER.info("Job: {} failed in the previous time. Trigger again with these targets: {}", jobId, saltJobRunner.getTarget());
saltJobRunner.setJid(jobId(saltJobRunner.submit(saltConnector)));
saltJobRunner.setJobState(JobState.IN_PROGRESS);
return call();
}
if (JobState.IN_PROGRESS.equals(saltJobRunner.getJobState())) {
String jobIsRunningMessage = String.format("Job: %s is running currently", saltJobRunner.getJid());
throw new CloudbreakOrchestratorFailedException(jobIsRunningMessage);
}
if (JobState.FAILED == saltJobRunner.getJobState() || JobState.AMBIGUOUS == saltJobRunner.getJobState()) {
throw new CloudbreakOrchestratorFailedException(buildErrorMessage());
}
LOGGER.info("Job (jid: {}) was finished. Triggering next salt event.", saltJobRunner.getJid().getJobId());
return true;
}
Aggregations