Search in sources :

Example 11 with CloudbreakOrchestratorFailedException

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());
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) StringContains.containsString(org.hamcrest.core.StringContains.containsString) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with CloudbreakOrchestratorFailedException

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;
}
Also used : OrchestratorBootstrap(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap) ArrayList(java.util.ArrayList) ContainerConstraint(com.sequenceiq.cloudbreak.orchestrator.model.ContainerConstraint) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) ContainerInfo(com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo) ExecutionException(java.util.concurrent.ExecutionException) YarnAppBootstrap(com.sequenceiq.cloudbreak.orchestrator.yarn.poller.YarnAppBootstrap)

Example 13 with CloudbreakOrchestratorFailedException

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);
        }
    }
}
Also used : YarnHttpClient(com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnHttpClient) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) ContainerInfo(com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo) DeleteApplicationRequest(com.sequenceiq.cloudbreak.orchestrator.yarn.model.request.DeleteApplicationRequest) YarnClient(com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnClient) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) ExecutionException(java.util.concurrent.ExecutionException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)

Example 14 with CloudbreakOrchestratorFailedException

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;
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) SaltAction(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction) HashSet(java.util.HashSet)

Example 15 with CloudbreakOrchestratorFailedException

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;
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) JobId(com.sequenceiq.cloudbreak.orchestrator.salt.domain.JobId) CloudbreakOrchestratorTerminateException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorTerminateException)

Aggregations

CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)39 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)14 SaltConnector (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector)14 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)12 ExecutionException (java.util.concurrent.ExecutionException)12 IOException (java.io.IOException)11 Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)10 OrchestratorBootstrap (com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap)9 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)9 HashSet (java.util.HashSet)9 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)7 SaltPillarProperties (com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties)6 GrainAddRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner)6 GrainRemoveRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner)6 HighStateRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateRunner)6 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)5 RecipeModel (com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel)5