use of com.sequenceiq.cloudbreak.domain.stack.Component in project cloudbreak by hortonworks.
the class ClusterUpgradeTargetImageService method saveImage.
public void saveImage(Long stackId, StatedImage targetImage) {
Optional<Component> existingTargetImage = findTargetImageComponent(stackId);
if (existingTargetImage.isPresent() && isTheSameImage(targetImage, existingTargetImage.get())) {
LOGGER.debug("The target image {} is already present for stack {}", targetImage.getImage().getUuid(), stackId);
} else {
existingTargetImage.ifPresent(this::removeOldTargetImage);
Component targetImageComponent = createTargetImageComponent(stackId, targetImage);
LOGGER.debug("Saving target image component for cluster upgrade. {}", targetImageComponent);
componentConfigProviderService.store(targetImageComponent);
}
}
use of com.sequenceiq.cloudbreak.domain.stack.Component in project cloudbreak by hortonworks.
the class StackImageService method replaceStackImageComponent.
private void replaceStackImageComponent(Stack stack, StatedImage targetImage) {
try {
Image newImage = getImageModelFromStatedImage(stack, componentConfigProviderService.getImage(stack.getId()), targetImage);
Component imageComponent = new Component(ComponentType.IMAGE, ComponentType.IMAGE.name(), new Json(newImage), stack);
componentConfigProviderService.replaceImageComponentWithNew(imageComponent);
} catch (CloudbreakImageNotFoundException e) {
LOGGER.info("Could not find image", e);
throw new CloudbreakServiceException("Could not find image", e);
}
}
use of com.sequenceiq.cloudbreak.domain.stack.Component in project cloudbreak by hortonworks.
the class StackService method addCloudbreakDetailsForStack.
private void addCloudbreakDetailsForStack(Stack stack) {
CloudbreakDetails cbDetails = new CloudbreakDetails(cbVersion);
try {
Component cbDetailsComponent = new Component(ComponentType.CLOUDBREAK_DETAILS, ComponentType.CLOUDBREAK_DETAILS.name(), new Json(cbDetails), stack);
componentConfigProviderService.store(cbDetailsComponent);
} catch (IllegalArgumentException e) {
LOGGER.info("Could not create Cloudbreak details component.", e);
}
}
use of com.sequenceiq.cloudbreak.domain.stack.Component in project cloudbreak by hortonworks.
the class StackService method addTemplateForStack.
private void addTemplateForStack(Stack stack, String template) {
StackTemplate stackTemplate = new StackTemplate(template, cbVersion);
try {
Component stackTemplateComponent = new Component(ComponentType.STACK_TEMPLATE, ComponentType.STACK_TEMPLATE.name(), new Json(stackTemplate), stack);
componentConfigProviderService.store(stackTemplateComponent);
} catch (IllegalArgumentException e) {
LOGGER.info("Could not create Cloudbreak details component.", e);
}
}
use of com.sequenceiq.cloudbreak.domain.stack.Component in project cloudbreak by hortonworks.
the class StackService method create.
@Measure(StackService.class)
public Stack create(Stack stack, String platformString, StatedImage imgFromCatalog, User user, Workspace workspace, Optional<String> externalCrn) {
if (stack.getGatewayPort() == null) {
stack.setGatewayPort(nginxPort);
}
stack.setCreator(user);
stack.setWorkspace(workspace);
setPlatformVariant(stack);
String stackName = stack.getName();
MDCBuilder.buildMdcContext(stack);
GetPlatformTemplateRequest templateRequest = connector.triggerGetTemplate(stack);
if (!stack.getStackAuthentication().passwordAuthenticationRequired() && !Strings.isNullOrEmpty(stack.getStackAuthentication().getPublicKey())) {
rsaPublicKeyValidator.validate(stack.getStackAuthentication().getPublicKey());
}
if (stack.getOrchestrator() != null) {
orchestratorService.save(stack.getOrchestrator());
}
stack.getStackAuthentication().setLoginUserName(SSH_USER_CB);
String accountId = ThreadBasedUserCrnProvider.getAccountId();
if (externalCrn.isPresent()) {
// it means it is a DL cluster, double check it in sdx service
sdxClientService.getByCrn(externalCrn.get());
stack.setResourceCrn(externalCrn.get());
} else {
stack.setResourceCrn(createCRN(accountId));
}
setDefaultTags(stack);
Stack savedStack = measure(() -> stackRepository.save(stack), LOGGER, "Stackrepository save took {} ms for stack {}", stackName);
MDCBuilder.buildMdcContext(savedStack);
measure(() -> addCloudbreakDetailsForStack(savedStack), LOGGER, "Add Cloudbreak details took {} ms for stack {}", stackName);
measure(() -> storeTelemetryForStack(savedStack), LOGGER, "Add Telemetry settings took {} ms for stack {}", stackName);
measure(() -> instanceGroupService.saveAll(savedStack.getInstanceGroups()), LOGGER, "Instance groups saved in {} ms for stack {}", stackName);
measure(() -> instanceMetaDataService.saveAll(savedStack.getInstanceMetaDataAsList()), LOGGER, "Instance metadatas saved in {} ms for stack {}", stackName);
measure(() -> loadBalancerPersistenceService.saveAll(savedStack.getLoadBalancers()), LOGGER, "Load balancers saved in {} ms for stack {}", stackName);
measure(() -> targetGroupPersistenceService.saveAll(savedStack.getTargetGroupAsList()), LOGGER, "Target groups saved in {} ms for stack {}", stackName);
try {
Set<Component> components = imageService.create(stack, imgFromCatalog);
setRuntime(stack, components);
} catch (CloudbreakImageNotFoundException e) {
LOGGER.info("Cloudbreak Image not found", e);
throw new CloudbreakApiException(e.getMessage(), e);
} catch (CloudbreakImageCatalogException e) {
LOGGER.info("Cloudbreak Image Catalog error", e);
throw new CloudbreakApiException(e.getMessage(), e);
}
measure(() -> addTemplateForStack(savedStack, connector.waitGetTemplate(templateRequest)), LOGGER, "Save cluster template took {} ms for stack {}", stackName);
return savedStack;
}
Aggregations