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;
}
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;
}
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;
}
Aggregations