Search in sources :

Example 1 with CloudbreakImageCatalogException

use of com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException in project cloudbreak by hortonworks.

the class StackService method create.

@Transactional(TxType.NEVER)
public Stack create(IdentityUser user, Stack stack, String imageCatalog, Optional<String> imageId, Optional<Blueprint> blueprint) {
    Stack savedStack;
    stack.setOwner(user.getUserId());
    stack.setAccount(user.getAccount());
    stack.setGatewayPort(nginxPort);
    setPlatformVariant(stack);
    String stackName = stack.getName();
    MDCBuilder.buildMdcContext(stack);
    try {
        if (!stack.getStackAuthentication().passwordAuthenticationRequired() && !Strings.isNullOrEmpty(stack.getStackAuthentication().getPublicKey())) {
            long start = System.currentTimeMillis();
            rsaPublicKeyValidator.validate(stack.getStackAuthentication().getPublicKey());
            LOGGER.info("RSA key has been validated in {} ms fot stack {}", System.currentTimeMillis() - start, stackName);
        }
        if (stack.getOrchestrator() != null) {
            orchestratorRepository.save(stack.getOrchestrator());
        }
        stack.getStackAuthentication().setLoginUserName(SSH_USER_CB);
        long start = System.currentTimeMillis();
        String template = connector.getTemplate(stack);
        LOGGER.info("Get cluster template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        savedStack = stackRepository.save(stack);
        LOGGER.info("Stackrepository save took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        addTemplateForStack(stack, template);
        LOGGER.info("Save cluster template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        addCloudbreakDetailsForStack(stack);
        LOGGER.info("Add Cloudbreak template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        MDCBuilder.buildMdcContext(savedStack);
        start = System.currentTimeMillis();
        instanceGroupRepository.save(savedStack.getInstanceGroups());
        LOGGER.info("Instance groups saved in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        SecurityConfig securityConfig = tlsSecurityService.storeSSHKeys();
        LOGGER.info("Generating SSH keys took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        securityConfig.setSaltPassword(PasswordUtil.generatePassword());
        securityConfig.setSaltBootPassword(PasswordUtil.generatePassword());
        securityConfig.setKnoxMasterSecret(PasswordUtil.generatePassword());
        LOGGER.info("Generating salt passwords took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        securityConfig.setStack(stack);
        start = System.currentTimeMillis();
        securityConfigRepository.save(securityConfig);
        LOGGER.info("Security config save took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        savedStack.setSecurityConfig(securityConfig);
        start = System.currentTimeMillis();
        imageService.create(savedStack, connector.getPlatformParameters(stack), imageCatalog, imageId, blueprint);
        LOGGER.info("Image creation took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    } catch (DataIntegrityViolationException ex) {
        String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.STACK, getProperSqlErrorMessage(ex));
        throw new BadRequestException(msg);
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.error("Cloudbreak Image not found", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    } catch (CloudbreakImageCatalogException e) {
        LOGGER.error("Cloudbreak Image Catalog error", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    }
    return savedStack;
}
Also used : SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) CloudbreakApiException(com.sequenceiq.cloudbreak.controller.CloudbreakApiException) Stack(com.sequenceiq.cloudbreak.domain.Stack) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Transactional(javax.transaction.Transactional)

Example 2 with CloudbreakImageCatalogException

use of com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException in project cloudbreak by hortonworks.

the class ImageCatalogService method getImages.

public StatedImages getImages(String imageCatalogUrl, String imageCatalogName, Set<String> platforms, String cbVersion) throws CloudbreakImageCatalogException {
    LOGGER.info("Determine images for imageCatalogUrl: '{}', platforms: '{}' and Cloudbreak version: '{}'.", imageCatalogUrl, platforms, cbVersion);
    StatedImages images;
    CloudbreakImageCatalogV2 imageCatalog = imageCatalogProvider.getImageCatalogV2(imageCatalogUrl);
    if (imageCatalog != null) {
        Set<String> vMImageUUIDs = new HashSet<>();
        List<CloudbreakVersion> cloudbreakVersions = imageCatalog.getVersions().getCloudbreakVersions();
        String cbv = UNSPECIFIED_VERSION.equals(cbVersion) ? latestCloudbreakVersion(cloudbreakVersions) : cbVersion;
        List<CloudbreakVersion> exactMatchedImgs = cloudbreakVersions.stream().filter(cloudbreakVersion -> cloudbreakVersion.getVersions().contains(cbv)).collect(Collectors.toList());
        if (!exactMatchedImgs.isEmpty()) {
            exactMatchedImgs.forEach(cloudbreakVersion -> vMImageUUIDs.addAll(cloudbreakVersion.getImageIds()));
        } else {
            vMImageUUIDs.addAll(prefixMatchForCBVersion(cbVersion, cloudbreakVersions));
        }
        List<Image> baseImages = filterImagesByPlatforms(platforms, imageCatalog.getImages().getBaseImages(), vMImageUUIDs);
        List<Image> hdpImages = filterImagesByPlatforms(platforms, imageCatalog.getImages().getHdpImages(), vMImageUUIDs);
        List<Image> hdfImages = filterImagesByPlatforms(platforms, imageCatalog.getImages().getHdfImages(), vMImageUUIDs);
        images = statedImages(new Images(baseImages, hdpImages, hdfImages), imageCatalogUrl, imageCatalogName);
    } else {
        images = statedImages(emptyImages(), imageCatalogUrl, imageCatalogName);
    }
    return images;
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) UserProfileService(com.sequenceiq.cloudbreak.service.user.UserProfileService) LoggerFactory(org.slf4j.LoggerFactory) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) StatedImage.statedImage(com.sequenceiq.cloudbreak.service.image.StatedImage.statedImage) Matcher(java.util.regex.Matcher) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) CloudbreakVersion(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion) AuthenticatedUserService(com.sequenceiq.cloudbreak.controller.AuthenticatedUserService) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Images(com.sequenceiq.cloudbreak.cloud.model.catalog.Images) AuthorizationService(com.sequenceiq.cloudbreak.service.AuthorizationService) SqlUtil.getProperSqlErrorMessage(com.sequenceiq.cloudbreak.util.SqlUtil.getProperSqlErrorMessage) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) AccountPreferencesService(com.sequenceiq.cloudbreak.service.account.AccountPreferencesService) Logger(org.slf4j.Logger) ImmutableSet(com.google.common.collect.ImmutableSet) ImageCatalogRepository(com.sequenceiq.cloudbreak.repository.ImageCatalogRepository) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) StatedImages.statedImages(com.sequenceiq.cloudbreak.service.image.StatedImages.statedImages) Set(java.util.Set) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) Collectors(java.util.stream.Collectors) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Versioned(com.sequenceiq.cloudbreak.cloud.model.Versioned) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) List(java.util.List) Component(org.springframework.stereotype.Component) APIResourceType(com.sequenceiq.cloudbreak.common.type.APIResourceType) TreeMap(java.util.TreeMap) CollectionUtils(org.springframework.util.CollectionUtils) UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile) NameUtil.generateArchiveName(com.sequenceiq.cloudbreak.util.NameUtil.generateArchiveName) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Comparator(java.util.Comparator) SortedMap(java.util.SortedMap) StringUtils(org.springframework.util.StringUtils) CloudbreakVersion(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion) Images(com.sequenceiq.cloudbreak.cloud.model.catalog.Images) StatedImages.statedImages(com.sequenceiq.cloudbreak.service.image.StatedImages.statedImages) CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) StatedImage.statedImage(com.sequenceiq.cloudbreak.service.image.StatedImage.statedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) HashSet(java.util.HashSet)

Example 3 with CloudbreakImageCatalogException

use of com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException in project cloudbreak by hortonworks.

the class CachedImageCatalogProvider method getImageCatalogV2.

@Cacheable(cacheNames = "imageCatalogCache", key = "#catalogUrl")
public CloudbreakImageCatalogV2 getImageCatalogV2(String catalogUrl) throws CloudbreakImageCatalogException {
    CloudbreakImageCatalogV2 catalog = null;
    if (catalogUrl == null) {
        LOGGER.warn("No image catalog was defined!");
        return catalog;
    }
    try {
        long started = System.currentTimeMillis();
        if (catalogUrl.startsWith("http")) {
            Client client = RestClientUtil.get();
            WebTarget target = client.target(catalogUrl);
            Response response = target.request().get();
            catalog = checkResponse(target, response);
        } else {
            String content = readCatalogFromFile(catalogUrl);
            catalog = JsonUtil.readValue(content, CloudbreakImageCatalogV2.class);
        }
        validateImageCatalogUuids(catalog);
        validateCloudBreakVersions(catalog);
        cleanAndValidateMaps(catalog);
        long timeOfParse = System.currentTimeMillis() - started;
        LOGGER.info("ImageCatalog has been get and parsed from '{}' and took '{}' ms.", catalogUrl, timeOfParse);
    } catch (RuntimeException e) {
        throw new CloudbreakImageCatalogException("Failed to get image catalog", e);
    } catch (JsonMappingException e) {
        throw new CloudbreakImageCatalogException(e.getMessage(), e);
    } catch (IOException e) {
        throw new CloudbreakImageCatalogException(String.format("Failed to read image catalog from file: '%s'", catalogUrl), e);
    }
    return catalog;
}
Also used : Response(javax.ws.rs.core.Response) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) WebTarget(javax.ws.rs.client.WebTarget) IOException(java.io.IOException) Client(javax.ws.rs.client.Client) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)3 CloudbreakImageCatalogV2 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2)2 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)2 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)2 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Versioned (com.sequenceiq.cloudbreak.cloud.model.Versioned)1 CloudbreakVersion (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion)1 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)1 Images (com.sequenceiq.cloudbreak.cloud.model.catalog.Images)1 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)1 APIResourceType (com.sequenceiq.cloudbreak.common.type.APIResourceType)1 AuthenticatedUserService (com.sequenceiq.cloudbreak.controller.AuthenticatedUserService)1 CloudbreakApiException (com.sequenceiq.cloudbreak.controller.CloudbreakApiException)1 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)1 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)1 SecurityConfig (com.sequenceiq.cloudbreak.domain.SecurityConfig)1 Stack (com.sequenceiq.cloudbreak.domain.Stack)1 UserProfile (com.sequenceiq.cloudbreak.domain.UserProfile)1