Search in sources :

Example 6 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException 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 7 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException 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 8 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.

the class TlsSetupService method setupTls.

public void setupTls(Stack stack, InstanceMetaData gwInstance) throws CloudbreakException {
    try {
        SavingX509TrustManager x509TrustManager = new SavingX509TrustManager();
        TrustManager[] trustManagers = { x509TrustManager };
        SSLContext sslContext = SslConfigurator.newInstance().createSSLContext();
        sslContext.init(null, trustManagers, new SecureRandom());
        Client client = RestClientUtil.createClient(sslContext, false, null);
        Integer gatewayPort = stack.getGatewayPort();
        String ip = gatewayConfigService.getGatewayIp(stack, gwInstance);
        LOGGER.info("Trying to fetch the server's certificate: {}:{}", ip, gatewayPort);
        nginxPollerService.pollWithTimeoutSingleFailure(nginxCertListenerTask, new NginxPollerObject(stack, client, ip, gatewayPort, x509TrustManager), POLLING_INTERVAL, MAX_ATTEMPTS_FOR_HOSTS);
        WebTarget nginxTarget = client.target(String.format("https://%s:%d", ip, gatewayPort));
        nginxTarget.path("/").request().get();
        X509Certificate[] chain = x509TrustManager.getChain();
        String serverCert = PkiUtil.convert(chain[0]);
        InstanceMetaData metaData = instanceMetaDataRepository.findOne(gwInstance.getId());
        metaData.setServerCert(BaseEncoding.base64().encode(serverCert.getBytes()));
        instanceMetaDataRepository.save(metaData);
    } catch (Exception e) {
        throw new CloudbreakException("Failed to retrieve the server's certificate", e);
    }
}
Also used : SecureRandom(java.security.SecureRandom) SSLContext(javax.net.ssl.SSLContext) X509Certificate(java.security.cert.X509Certificate) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) TrustManager(javax.net.ssl.TrustManager) SavingX509TrustManager(com.sequenceiq.cloudbreak.client.CertificateTrustManager.SavingX509TrustManager) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) SavingX509TrustManager(com.sequenceiq.cloudbreak.client.CertificateTrustManager.SavingX509TrustManager) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client)

Example 9 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.

the class HostMetadataSetup method setupNewHostMetadata.

public void setupNewHostMetadata(Long stackId, Collection<String> newAddresses) throws CloudbreakException {
    LOGGER.info("Extending host metadata.");
    Stack stack = stackService.getByIdWithLists(stackId);
    if (!orchestratorTypeResolver.resolveType(stack.getOrchestrator()).containerOrchestrator()) {
        Set<InstanceMetaData> newInstanceMetadata = stack.getRunningInstanceMetaData().stream().filter(instanceMetaData -> newAddresses.contains(instanceMetaData.getPrivateIp())).collect(Collectors.toSet());
        updateWithHostData(stack, newInstanceMetadata);
        instanceMetaDataRepository.save(newInstanceMetadata);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CloudbreakSecuritySetupException(com.sequenceiq.cloudbreak.core.CloudbreakSecuritySetupException) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) Logger(org.slf4j.Logger) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) InstanceMetaDataRepository(com.sequenceiq.cloudbreak.repository.InstanceMetaDataRepository) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) List(java.util.List) OrchestratorTypeResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.OrchestratorTypeResolver) HostOrchestratorResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.host.HostOrchestratorResolver) Service(org.springframework.stereotype.Service) Map(java.util.Map) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Stack(com.sequenceiq.cloudbreak.domain.Stack) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 10 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.

the class ContainerConfigService method get.

public ContainerConfig get(Stack stack, DockerContainer dc) {
    try {
        Component component = componentConfigProvider.getComponent(stack.getId(), ComponentType.CONTAINER, dc.name());
        if (component == null) {
            component = create(stack, dc);
            LOGGER.info("Container component definition created: {}", component);
        } else {
            LOGGER.info("Container component definition found in database: {}", component);
        }
        return component.getAttributes().get(ContainerConfig.class);
    } catch (CloudbreakException | IOException ignored) {
        throw new CloudbreakServiceException(String.format("Failed to parse component ContainerConfig for stack: %d, container: %s", stack.getId(), dc.getName()));
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) IOException(java.io.IOException) Component(com.sequenceiq.cloudbreak.domain.Component)

Aggregations

CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)45 Stack (com.sequenceiq.cloudbreak.domain.Stack)23 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)22 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)18 PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)14 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)13 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)13 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)13 OrchestratorType (com.sequenceiq.cloudbreak.common.model.OrchestratorType)11 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)11 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)10 HashMap (java.util.HashMap)10 List (java.util.List)10 Map (java.util.Map)10 Set (java.util.Set)9 Inject (javax.inject.Inject)9 AmbariConnectionException (com.sequenceiq.ambari.client.AmbariConnectionException)8 Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)8 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)8