Search in sources :

Example 1 with KeytabModel

use of com.sequenceiq.cloudbreak.orchestrator.model.KeytabModel in project cloudbreak by hortonworks.

the class KeytabConfigurationHandler method accept.

@Override
public void accept(Event<KeytabConfigurationRequest> keytabConfigurationRequestEvent) {
    Long stackId = keytabConfigurationRequestEvent.getData().getResourceId();
    Selectable response;
    try {
        Stack stack = stackService.getByIdWithListsInTransaction(stackId);
        Optional<KerberosConfig> kerberosConfigOptional = kerberosConfigService.get(stack.getEnvironmentCrn(), stack.getName());
        boolean childEnvironment = environmentConfigProvider.isChildEnvironment(stack.getEnvironmentCrn());
        if (kerberosDetailService.keytabsShouldBeUpdated(stack.cloudPlatform(), childEnvironment, kerberosConfigOptional)) {
            GatewayConfig primaryGatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
            ServiceKeytabResponse serviceKeytabResponse = keytabProvider.getServiceKeytabResponse(stack, primaryGatewayConfig);
            KeytabModel keytabModel = buildKeytabModel(serviceKeytabResponse);
            hostOrchestrator.uploadKeytabs(List.of(primaryGatewayConfig), Set.of(keytabModel), ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel(stackId, stack.getCluster().getId()));
        }
        response = new KeytabConfigurationSuccess(stackId);
    } catch (Exception e) {
        LOGGER.info("Error during keytab configuration, stackId: " + stackId, e);
        KeytabConfigurationException configurationException = new KeytabConfigurationException("Keytab generation failed with: " + e.getMessage(), e);
        response = new KeytabConfigurationFailed(stackId, configurationException);
    }
    eventBus.notify(response.selector(), new Event<>(keytabConfigurationRequestEvent.getHeaders(), response));
}
Also used : KerberosConfig(com.sequenceiq.cloudbreak.dto.KerberosConfig) KeytabConfigurationException(com.sequenceiq.cloudbreak.reactor.api.event.kerberos.KeytabConfigurationException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) KeytabModel(com.sequenceiq.cloudbreak.orchestrator.model.KeytabModel) KeytabConfigurationFailed(com.sequenceiq.cloudbreak.reactor.api.event.kerberos.KeytabConfigurationFailed) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) KeytabConfigurationException(com.sequenceiq.cloudbreak.reactor.api.event.kerberos.KeytabConfigurationException) ServiceKeytabResponse(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.ServiceKeytabResponse) KeytabConfigurationSuccess(com.sequenceiq.cloudbreak.reactor.api.event.kerberos.KeytabConfigurationSuccess) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 2 with KeytabModel

use of com.sequenceiq.cloudbreak.orchestrator.model.KeytabModel in project cloudbreak by hortonworks.

the class SaltOrchestrator method uploadKeytabs.

@Override
public void uploadKeytabs(List<GatewayConfig> allGatewayConfigs, Set<KeytabModel> keytabModels, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorFailedException {
    GatewayConfig primaryGatewayConfig = saltService.getPrimaryGatewayConfig(allGatewayConfigs);
    Set<String> gatewayTargets = getGatewayPrivateIps(allGatewayConfigs);
    try (SaltConnector sc = saltService.createSaltConnector(primaryGatewayConfig)) {
        Map<String, Object> properties = new HashMap<>();
        for (KeytabModel keytabModel : keytabModels) {
            uploadFileToTargets(sc, gatewayTargets, exitModel, keytabModel.getPath(), keytabModel.getFileName(), keytabModel.getKeytab());
            Map<String, String> keytabProps = Map.of("principal", keytabModel.getPrincipal(), "path", keytabModel.getPath() + "/" + keytabModel.getFileName());
            properties.put(keytabModel.getService(), keytabProps);
        }
        SaltPillarProperties saltPillarProperties = new SaltPillarProperties("/kerberos/keytab.sls", Collections.singletonMap("keytab", properties));
        OrchestratorBootstrap pillarSave = PillarSave.createCustomPillar(sc, gatewayTargets, saltPillarProperties);
        Callable<Boolean> runner = saltRunner.runner(pillarSave, exitCriteria, exitModel);
        runner.call();
    } catch (Exception e) {
        LOGGER.info("Error occurred during keytab upload", e);
        throw new CloudbreakOrchestratorFailedException(e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) OrchestratorBootstrap(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) SaltPillarProperties(com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakOrchestratorTimeoutException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorTimeoutException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) KeytabModel(com.sequenceiq.cloudbreak.orchestrator.model.KeytabModel) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Aggregations

GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)2 KeytabModel (com.sequenceiq.cloudbreak.orchestrator.model.KeytabModel)2 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 KerberosConfig (com.sequenceiq.cloudbreak.dto.KerberosConfig)1 OrchestratorBootstrap (com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap)1 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)1 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)1 CloudbreakOrchestratorTimeoutException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorTimeoutException)1 SaltPillarProperties (com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties)1 SaltConnector (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector)1 KeytabConfigurationException (com.sequenceiq.cloudbreak.reactor.api.event.kerberos.KeytabConfigurationException)1 KeytabConfigurationFailed (com.sequenceiq.cloudbreak.reactor.api.event.kerberos.KeytabConfigurationFailed)1 KeytabConfigurationSuccess (com.sequenceiq.cloudbreak.reactor.api.event.kerberos.KeytabConfigurationSuccess)1 ServiceKeytabResponse (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.ServiceKeytabResponse)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1