Search in sources :

Example 6 with CloudbreakOrchestratorFailedException

use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.

the class SaltConnector method members.

public Map<String, String> members(List<String> privateIps) throws CloudbreakOrchestratorFailedException {
    Map<String, List<String>> clients = singletonMap("clients", privateIps);
    Response response = saltTarget.path(BOOT_HOSTNAME_ENDPOINT.getContextPath()).request().header(SIGN_HEADER, PkiUtil.generateSignature(signatureKey, toJson(clients).getBytes())).post(Entity.json(clients));
    GenericResponses responses = JaxRSUtil.response(response, GenericResponses.class);
    List<GenericResponse> failedResponses = responses.getResponses().stream().filter(genericResponse -> !ACCEPTED_STATUSES.contains(genericResponse.getStatusCode())).collect(Collectors.toList());
    if (!failedResponses.isEmpty()) {
        failedResponseErrorLog(failedResponses);
        String failedNodeAddresses = failedResponses.stream().map(GenericResponse::getAddress).collect(Collectors.joining(","));
        throw new CloudbreakOrchestratorFailedException("Hostname resolution failed for nodes: " + failedNodeAddresses);
    }
    return responses.getResponses().stream().collect(Collectors.toMap(GenericResponse::getAddress, GenericResponse::getStatus));
}
Also used : GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Response(javax.ws.rs.core.Response) MultiPart(org.glassfish.jersey.media.multipart.MultiPart) Arrays(java.util.Arrays) Form(javax.ws.rs.core.Form) Target(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.Target) Pillar(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Pillar) Client(javax.ws.rs.client.Client) LoggerFactory(org.slf4j.LoggerFactory) HttpStatus(org.apache.http.HttpStatus) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) MediaType(javax.ws.rs.core.MediaType) JaxRSUtil(com.sequenceiq.cloudbreak.util.JaxRSUtil) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) SaltAction(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Logger(org.slf4j.Logger) BOOT_HOSTNAME_ENDPOINT(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltEndpoint.BOOT_HOSTNAME_ENDPOINT) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Collectors(java.util.stream.Collectors) Entity(javax.ws.rs.client.Entity) Boundary(org.glassfish.jersey.media.multipart.Boundary) List(java.util.List) Response(javax.ws.rs.core.Response) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) Closeable(java.io.Closeable) StreamDataBodyPart(org.glassfish.jersey.media.multipart.file.StreamDataBodyPart) RestClientUtil(com.sequenceiq.cloudbreak.client.RestClientUtil) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Optional(java.util.Optional) WebTarget(javax.ws.rs.client.WebTarget) HttpAuthenticationFeature(org.glassfish.jersey.client.authentication.HttpAuthenticationFeature) PkiUtil(com.sequenceiq.cloudbreak.client.PkiUtil) Collections(java.util.Collections) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) List(java.util.List) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses)

Example 7 with CloudbreakOrchestratorFailedException

use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.

the class OrchestratorRecipeExecutor method postAmbariStartRecipes.

public void postAmbariStartRecipes(Stack stack) throws CloudbreakException {
    HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
    GatewayConfig gatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
    try {
        hostOrchestrator.postAmbariStartRecipes(gatewayConfig, collectNodes(stack), clusterDeletionBasedModel(stack.getId(), stack.getCluster().getId()));
    } catch (CloudbreakOrchestratorFailedException e) {
        throw new CloudbreakException(e);
    }
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 8 with CloudbreakOrchestratorFailedException

use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.

the class OrchestratorRecipeExecutor method uploadRecipes.

public void uploadRecipes(Stack stack, Collection<HostGroup> hostGroups) throws CloudbreakException {
    HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
    Map<String, List<RecipeModel>> recipeMap = hostGroups.stream().filter(hg -> !hg.getRecipes().isEmpty()).collect(Collectors.toMap(HostGroup::getName, h -> convert(h.getRecipes())));
    List<GatewayConfig> allGatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
    recipesEvent(stack.getId(), stack.getStatus(), recipeMap);
    try {
        hostOrchestrator.uploadRecipes(allGatewayConfigs, recipeMap, clusterDeletionBasedModel(stack.getId(), stack.getCluster().getId()));
    } catch (CloudbreakOrchestratorFailedException e) {
        throw new CloudbreakException(e);
    }
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Joiner(com.google.api.client.util.Joiner) Base64(org.apache.commons.codec.binary.Base64) ArrayList(java.util.ArrayList) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) RecipeModel(com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel) CloudbreakMessagesService(com.sequenceiq.cloudbreak.service.messages.CloudbreakMessagesService) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Status(com.sequenceiq.cloudbreak.api.model.Status) Map(java.util.Map) Stack(com.sequenceiq.cloudbreak.domain.Stack) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel(com.sequenceiq.cloudbreak.core.bootstrap.service.ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Collection(java.util.Collection) Set(java.util.Set) DEFAULT_RECIPES(com.sequenceiq.cloudbreak.service.cluster.flow.RecipeEngine.DEFAULT_RECIPES) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) Collectors(java.util.stream.Collectors) Recipe(com.sequenceiq.cloudbreak.domain.Recipe) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) List(java.util.List) Component(org.springframework.stereotype.Component) HostOrchestratorResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.host.HostOrchestratorResolver) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) Entry(java.util.Map.Entry) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Collections(java.util.Collections) CloudbreakEventService(com.sequenceiq.cloudbreak.service.events.CloudbreakEventService) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ArrayList(java.util.ArrayList) List(java.util.List) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 9 with CloudbreakOrchestratorFailedException

use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.

the class SaltJobIdTrackerTest method callWithInProgressAndJobIsRunning.

@Test
public void callWithInProgressAndJobIsRunning() 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(true);
    SaltJobIdTracker saltJobIdTracker = new SaltJobIdTracker(saltConnector, saltJobRunner);
    try {
        saltJobIdTracker.call();
    } catch (CloudbreakOrchestratorFailedException e) {
        assertThat(e.getMessage(), both(containsString("jobId='" + jobId + '\'')).and(containsString("is running")));
    }
    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 10 with CloudbreakOrchestratorFailedException

use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.

the class SaltJobIdTrackerTest method callWithNotStarted.

@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT")
@Test
public void callWithNotStarted() throws Exception {
    String jobId = "1";
    SaltConnector saltConnector = Mockito.mock(SaltConnector.class);
    SaltJobRunner saltJobRunner = Mockito.mock(SaltJobRunner.class);
    PowerMockito.mockStatic(SaltStates.class);
    PowerMockito.when(SaltStates.jobIsRunning(any(), any())).thenReturn(true);
    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);
    when(saltJobRunner.getJid()).thenReturn(JobId.jobId(jobId));
    when(saltJobRunner.getJobState()).thenReturn(JobState.NOT_STARTED, JobState.IN_PROGRESS);
    when(saltJobRunner.submit(any(SaltConnector.class))).thenReturn(jobId);
    SaltJobIdTracker saltJobIdTracker = new SaltJobIdTracker(saltConnector, saltJobRunner);
    try {
        saltJobIdTracker.call();
        fail("should throw exception");
    } catch (CloudbreakOrchestratorFailedException e) {
        assertThat(e.getMessage(), both(containsString("jobId='" + jobId + '\'')).and(containsString("is running")));
    }
    PowerMockito.verifyStatic();
    SaltStates.jobIsRunning(any(), eq(jobId));
    checkTargets(targets, targetCaptor.getAllValues());
    verify(saltJobRunner, times(2)).getJobState();
}
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) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

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