Search in sources :

Example 1 with GetCloudParameterException

use of com.sequenceiq.cloudbreak.cloud.service.GetCloudParameterException in project cloudbreak by hortonworks.

the class UserDataService method createUserData.

private void createUserData(Stack stack, Supplier<CcmConnectivityParameters> ccmParametersSupplier) {
    DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
    Credential credential = credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn());
    Future<PlatformParameters> platformParametersFuture = intermediateBuilderExecutor.submit(() -> platformParameterService.getPlatformParameters(stack, credential));
    SecurityConfig securityConfig = stack.getSecurityConfig();
    SaltSecurityConfig saltSecurityConfig = securityConfig.getSaltSecurityConfig();
    String cbPrivKey = saltSecurityConfig.getSaltBootSignPrivateKey();
    byte[] cbSshKeyDer = PkiUtil.getPublicKeyDer(new String(Base64.decodeBase64(cbPrivKey)));
    String sshUser = stack.getStackAuthentication().getLoginUserName();
    String cbCert = securityConfig.getClientCert();
    String saltBootPassword = saltSecurityConfig.getSaltBootPassword();
    try {
        PlatformParameters platformParameters = platformParametersFuture.get();
        CcmConnectivityParameters ccmParameters = ccmParametersSupplier.get();
        Optional<ProxyConfig> proxyConfig = proxyConfigDtoService.getByEnvironmentCrn(stack.getEnvironmentCrn());
        String userData = userDataBuilder.buildUserData(stack.getAccountId(), environment, Platform.platform(stack.getCloudPlatform()), cbSshKeyDer, sshUser, platformParameters, saltBootPassword, cbCert, ccmParameters, proxyConfig.orElse(null));
        imageService.decorateImageWithUserDataForStack(stack, userData);
    } catch (InterruptedException | ExecutionException e) {
        LOGGER.error("Failed to get Platform parameters", e);
        throw new GetCloudParameterException("Failed to get Platform parameters", e);
    }
}
Also used : Credential(com.sequenceiq.freeipa.dto.Credential) GetCloudParameterException(com.sequenceiq.cloudbreak.cloud.service.GetCloudParameterException) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) SaltSecurityConfig(com.sequenceiq.freeipa.entity.SaltSecurityConfig) CcmConnectivityParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters) SaltSecurityConfig(com.sequenceiq.freeipa.entity.SaltSecurityConfig) SecurityConfig(com.sequenceiq.freeipa.entity.SecurityConfig) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) PlatformParameters(com.sequenceiq.cloudbreak.cloud.PlatformParameters) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with GetCloudParameterException

use of com.sequenceiq.cloudbreak.cloud.service.GetCloudParameterException in project cloudbreak by hortonworks.

the class UserDataService method createUserData.

public void createUserData(Long stackId) throws CloudbreakImageNotFoundException {
    Stack stack = stackService.getByIdWithLists(stackId);
    String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
    Future<PlatformParameters> platformParametersFuture = intermediateBuilderExecutor.submit(() -> connector.getPlatformParameters(stack, userCrn));
    SecurityConfig securityConfig = securityConfigService.generateAndSaveSecurityConfig(stack);
    stack.setSecurityConfig(securityConfig);
    stackService.save(stack);
    SaltSecurityConfig saltSecurityConfig = securityConfig.getSaltSecurityConfig();
    String cbPrivKey = saltSecurityConfig.getSaltBootSignPrivateKey();
    byte[] cbSshKeyDer = PkiUtil.getPublicKeyDer(new String(Base64.decodeBase64(cbPrivKey)));
    String sshUser = stack.getStackAuthentication().getLoginUserName();
    String cbCert = securityConfig.getClientCert();
    String saltBootPassword = saltSecurityConfig.getSaltBootPassword();
    try {
        PlatformParameters platformParameters = platformParametersFuture.get();
        CcmConnectivityParameters ccmParameters = ccmUserDataService.fetchAndSaveCcmParameters(stack);
        Optional<ProxyConfig> proxyConfig = proxyConfigDtoService.getByEnvironmentCrn(stack.getEnvironmentCrn());
        Map<InstanceGroupType, String> userData = userDataBuilder.buildUserData(Platform.platform(stack.getCloudPlatform()), cbSshKeyDer, sshUser, platformParameters, saltBootPassword, cbCert, ccmParameters, proxyConfig.orElse(null));
        imageService.decorateImageWithUserDataForStack(stack, userData);
    } catch (InterruptedException | ExecutionException e) {
        LOGGER.error("Failed to get Platform parmaters", e);
        throw new GetCloudParameterException("Failed to get Platform parmaters", e);
    }
}
Also used : InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) GetCloudParameterException(com.sequenceiq.cloudbreak.cloud.service.GetCloudParameterException) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) SaltSecurityConfig(com.sequenceiq.cloudbreak.domain.SaltSecurityConfig) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CcmConnectivityParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters) SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) SaltSecurityConfig(com.sequenceiq.cloudbreak.domain.SaltSecurityConfig) PlatformParameters(com.sequenceiq.cloudbreak.cloud.PlatformParameters) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with GetCloudParameterException

use of com.sequenceiq.cloudbreak.cloud.service.GetCloudParameterException in project cloudbreak by hortonworks.

the class EnvironmentValidatorService method validateSecurityGroups.

public ValidationResult validateSecurityGroups(EnvironmentEditDto editDto, Environment environment) {
    ValidationResultBuilder validationResultBuilder = ValidationResult.builder();
    getSecurityGroupIdSet(editDto).forEach(sg -> {
        try {
            fetchSecurityGroup(editDto, environment, sg);
        } catch (BadRequestException e) {
            LOGGER.info("Security group cannot be fetched, because BadRequest occurred with: " + e.getMessage());
            validationResultBuilder.error(e.getMessage());
        } catch (GetCloudParameterException e) {
            LOGGER.info("Security group cannot be fetched, because: " + e.getMessage());
            validationResultBuilder.error(e.getCause().getMessage());
        }
    });
    return validationResultBuilder.build();
}
Also used : GetCloudParameterException(com.sequenceiq.cloudbreak.cloud.service.GetCloudParameterException) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) BadRequestException(javax.ws.rs.BadRequestException)

Aggregations

GetCloudParameterException (com.sequenceiq.cloudbreak.cloud.service.GetCloudParameterException)3 CcmConnectivityParameters (com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters)2 PlatformParameters (com.sequenceiq.cloudbreak.cloud.PlatformParameters)2 ProxyConfig (com.sequenceiq.cloudbreak.dto.ProxyConfig)2 ExecutionException (java.util.concurrent.ExecutionException)2 SaltSecurityConfig (com.sequenceiq.cloudbreak.domain.SaltSecurityConfig)1 SecurityConfig (com.sequenceiq.cloudbreak.domain.SecurityConfig)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)1 InstanceGroupType (com.sequenceiq.common.api.type.InstanceGroupType)1 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)1 Credential (com.sequenceiq.freeipa.dto.Credential)1 SaltSecurityConfig (com.sequenceiq.freeipa.entity.SaltSecurityConfig)1 SecurityConfig (com.sequenceiq.freeipa.entity.SecurityConfig)1 BadRequestException (javax.ws.rs.BadRequestException)1