Search in sources :

Example 6 with CloudbreakServiceException

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

the class StackRequestToBlueprintPreparationObjectConverter method convert.

@Override
public BlueprintPreparationObject convert(StackV2Request source) {
    try {
        IdentityUser identityUser = userDetailsService.getDetails(source.getOwner(), UserFilterField.USERID);
        FlexSubscription flexSubscription = getFlexSubscription(source);
        String smartsenseSubscriptionId = getSmartsenseSubscriptionId(source, flexSubscription);
        KerberosConfig kerberosConfig = getKerberosConfig(source);
        LdapConfig ldapConfig = getLdapConfig(source, identityUser);
        FileSystemConfigurationView fileSystemConfigurationView = getFileSystemConfigurationView(source);
        Set<RDSConfig> rdsConfigs = getRdsConfigs(source, identityUser);
        Blueprint blueprint = getBlueprint(source, identityUser);
        BlueprintStackInfo blueprintStackInfo = stackInfoService.blueprintStackInfo(blueprint.getBlueprintText());
        Set<HostgroupView> hostgroupViews = getHostgroupViews(source);
        BlueprintView blueprintView = new BlueprintView(blueprint.getBlueprintText(), blueprintStackInfo.getVersion(), blueprintStackInfo.getType());
        GeneralClusterConfigs generalClusterConfigs = generalClusterConfigsProvider.generalClusterConfigs(source, identityUser);
        return BlueprintPreparationObject.Builder.builder().withFlexSubscription(flexSubscription).withRdsConfigs(rdsConfigs).withHostgroupViews(hostgroupViews).withBlueprintView(blueprintView).withStackRepoDetailsHdpVersion(blueprintStackInfo.getVersion()).withFileSystemConfigurationView(fileSystemConfigurationView).withGeneralClusterConfigs(generalClusterConfigs).withSmartSenseSubscriptionId(smartsenseSubscriptionId).withLdapConfig(ldapConfig).withKerberosConfig(kerberosConfig).build();
    } catch (BlueprintProcessingException e) {
        throw new CloudbreakServiceException(e.getMessage(), e);
    } catch (IOException e) {
        throw new CloudbreakServiceException(e.getMessage(), e);
    }
}
Also used : BlueprintProcessingException(com.sequenceiq.cloudbreak.blueprint.BlueprintProcessingException) GeneralClusterConfigs(com.sequenceiq.cloudbreak.blueprint.templates.GeneralClusterConfigs) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) BlueprintView(com.sequenceiq.cloudbreak.blueprint.template.views.BlueprintView) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) KerberosConfig(com.sequenceiq.cloudbreak.domain.KerberosConfig) IOException(java.io.IOException) IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) LdapConfig(com.sequenceiq.cloudbreak.domain.LdapConfig) BlueprintStackInfo(com.sequenceiq.cloudbreak.blueprint.templates.BlueprintStackInfo) FlexSubscription(com.sequenceiq.cloudbreak.domain.FlexSubscription) FileSystemConfigurationView(com.sequenceiq.cloudbreak.blueprint.template.views.FileSystemConfigurationView) HostgroupView(com.sequenceiq.cloudbreak.blueprint.template.views.HostgroupView)

Example 7 with CloudbreakServiceException

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

the class StackToBlueprintPreparationObjectConverter method convert.

@Override
public BlueprintPreparationObject convert(Stack source) {
    try {
        Optional<SmartSenseSubscription> aDefault = smartSenseSubscriptionService.getDefault();
        Cluster cluster = clusterService.getById(source.getCluster().getId());
        FileSystem fileSystem = cluster.getFileSystem();
        LdapConfig ldapConfig = cluster.getLdapConfig();
        StackRepoDetails hdpRepo = clusterComponentConfigProvider.getHDPRepo(cluster.getId());
        String stackRepoDetailsHdpVersion = hdpRepo != null ? hdpRepo.getHdpVersion() : null;
        Map<String, List<InstanceMetaData>> groupInstances = instanceGroupMetadataCollector.collectMetadata(source);
        HdfConfigs hdfConfigs = hdfConfigProvider.createHdfConfig(cluster.getHostGroups(), groupInstances, cluster.getBlueprint().getBlueprintText());
        BlueprintStackInfo blueprintStackInfo = stackInfoService.blueprintStackInfo(cluster.getBlueprint().getBlueprintText());
        FileSystemConfigurationView fileSystemConfigurationView = null;
        if (source.getCluster().getFileSystem() != null) {
            fileSystemConfigurationView = new FileSystemConfigurationView(fileSystemConfigurationProvider.fileSystemConfiguration(fileSystem, source), fileSystem == null ? false : fileSystem.isDefaultFs());
        }
        IdentityUser identityUser = userDetailsService.getDetails(cluster.getOwner(), UserFilterField.USERID);
        return BlueprintPreparationObject.Builder.builder().withFlexSubscription(source.getFlexSubscription()).withRdsConfigs(postgresConfigService.createRdsConfigIfNeeded(source, cluster)).withHostgroups(hostGroupService.getByCluster(cluster.getId())).withGateway(cluster.getGateway()).withBlueprintView(new BlueprintView(cluster, blueprintStackInfo)).withStackRepoDetailsHdpVersion(stackRepoDetailsHdpVersion).withFileSystemConfigurationView(fileSystemConfigurationView).withGeneralClusterConfigs(generalClusterConfigsProvider.generalClusterConfigs(source, cluster, identityUser)).withSmartSenseSubscriptionId(aDefault.isPresent() ? aDefault.get().getSubscriptionId() : null).withLdapConfig(ldapConfig).withHdfConfigs(hdfConfigs).withKerberosConfig(cluster.isSecure() ? cluster.getKerberosConfig() : null).build();
    } catch (BlueprintProcessingException e) {
        throw new CloudbreakServiceException(e.getMessage(), e);
    } catch (IOException e) {
        throw new CloudbreakServiceException(e.getMessage(), e);
    }
}
Also used : BlueprintProcessingException(com.sequenceiq.cloudbreak.blueprint.BlueprintProcessingException) StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) HdfConfigs(com.sequenceiq.cloudbreak.blueprint.nifi.HdfConfigs) SmartSenseSubscription(com.sequenceiq.cloudbreak.domain.SmartSenseSubscription) BlueprintView(com.sequenceiq.cloudbreak.blueprint.template.views.BlueprintView) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) IOException(java.io.IOException) LdapConfig(com.sequenceiq.cloudbreak.domain.LdapConfig) IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) BlueprintStackInfo(com.sequenceiq.cloudbreak.blueprint.templates.BlueprintStackInfo) FileSystem(com.sequenceiq.cloudbreak.domain.FileSystem) FileSystemConfigurationView(com.sequenceiq.cloudbreak.blueprint.template.views.FileSystemConfigurationView) List(java.util.List)

Example 8 with CloudbreakServiceException

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

the class ContainerConfigService method create.

private Component create(Stack stack, DockerContainer dc) throws CloudbreakException {
    try {
        ContainerConfig config;
        ContainerOrchestrator orchestrator = containerOrchestratorResolver.get(stack.getOrchestrator().getType());
        Map<String, String> customContainerConfig = getCustomContainerConfig(stack);
        Optional<String> customContainerName = Optional.ofNullable(customContainerConfig.get(dc.name()));
        Optional<String> customQueue = getCustomQueue(stack);
        switch(dc) {
            case AMBARI_SERVER:
                config = new Builder(orchestrator.ambariServerContainer(customContainerName), customQueue).build();
                break;
            case AMBARI_AGENT:
                config = new Builder(orchestrator.ambariClientContainer(customContainerName), customQueue).build();
                break;
            case AMBARI_DB:
                config = new Builder(orchestrator.ambariDbContainer(customContainerName), customQueue).build();
                break;
            default:
                throw new CloudbreakServiceException(String.format("No configuration exist for %s", dc));
        }
        Component component = new Component(ComponentType.CONTAINER, dc.name(), new Json(config), stack);
        return componentConfigProvider.store(component);
    } catch (IOException ignored) {
        throw new CloudbreakServiceException(String.format("Failed to parse component ContainerConfig for stack: %d, container: %s", stack.getId(), dc.getName()));
    }
}
Also used : ContainerConfig(com.sequenceiq.cloudbreak.orchestrator.model.ContainerConfig) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) Builder(com.sequenceiq.cloudbreak.core.bootstrap.config.ContainerConfigBuilder.Builder) Json(com.sequenceiq.cloudbreak.domain.json.Json) IOException(java.io.IOException) Component(com.sequenceiq.cloudbreak.domain.Component)

Example 9 with CloudbreakServiceException

use of com.sequenceiq.cloudbreak.service.CloudbreakServiceException 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)

Example 10 with CloudbreakServiceException

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

the class ImageService method create.

@Transactional(TxType.NEVER)
public void create(Stack stack, PlatformParameters params, String imageCatalog, Optional<String> imageId, Optional<Blueprint> blueprint) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    try {
        Platform platform = platform(stack.cloudPlatform());
        String platformString = platform(stack.cloudPlatform()).value().toLowerCase();
        String region = stack.getRegion();
        SecurityConfig securityConfig = stack.getSecurityConfig();
        String cbPrivKey = securityConfig.getCloudbreakSshPrivateKeyDecoded();
        byte[] cbSshKeyDer = PkiUtil.getPublicKeyDer(cbPrivKey);
        String sshUser = stack.getStackAuthentication().getLoginUserName();
        String cbCert = securityConfig.getClientCertRaw();
        Map<InstanceGroupType, String> userData = userDataBuilder.buildUserData(platform, cbSshKeyDer, sshUser, params, securityConfig.getSaltBootPassword(), cbCert);
        StatedImage imgFromCatalog = determineImageFromCatalog(imageId, platformString, imageCatalog, blueprint);
        LOGGER.info("Determined image from catalog: {}", imgFromCatalog);
        String imageName = determineImageName(platformString, region, imgFromCatalog.getImage());
        LOGGER.info("Selected VM image for CloudPlatform '{}' and region '{}' is: {} from: {} image catalog", platformString, region, imageName, imgFromCatalog.getImageCatalogUrl());
        List<Component> components = getComponents(stack, userData, imgFromCatalog.getImage(), imageName, imgFromCatalog.getImageCatalogUrl(), imgFromCatalog.getImageCatalogName(), imgFromCatalog.getImage().getUuid());
        componentConfigProvider.store(components);
    } catch (JsonProcessingException e) {
        throw new CloudbreakServiceException("Failed to create json", e);
    }
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) Component(com.sequenceiq.cloudbreak.domain.Component) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Transactional(javax.transaction.Transactional)

Aggregations

CloudbreakServiceException (com.sequenceiq.cloudbreak.service.CloudbreakServiceException)15 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)4 IOException (java.io.IOException)4 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)3 Component (com.sequenceiq.cloudbreak.domain.Component)3 Stack (com.sequenceiq.cloudbreak.domain.Stack)3 HttpResponseException (groovyx.net.http.HttpResponseException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 BlueprintProcessingException (com.sequenceiq.cloudbreak.blueprint.BlueprintProcessingException)2 BlueprintView (com.sequenceiq.cloudbreak.blueprint.template.views.BlueprintView)2 FileSystemConfigurationView (com.sequenceiq.cloudbreak.blueprint.template.views.FileSystemConfigurationView)2 BlueprintStackInfo (com.sequenceiq.cloudbreak.blueprint.templates.BlueprintStackInfo)2 CheckImageResult (com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult)2 Image (com.sequenceiq.cloudbreak.cloud.model.Image)2 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)2 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)2 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)2 KerberosConfig (com.sequenceiq.cloudbreak.domain.KerberosConfig)2 LdapConfig (com.sequenceiq.cloudbreak.domain.LdapConfig)2 Json (com.sequenceiq.cloudbreak.domain.json.Json)2