use of com.sequenceiq.cloudbreak.service.CloudbreakServiceException in project cloudbreak by hortonworks.
the class AmbariClusterService method upgrade.
@Override
public void upgrade(Long stackId, AmbariRepo ambariRepoUpgrade) {
if (ambariRepoUpgrade != null) {
Stack stack = stackService.getByIdWithLists(stackId);
Cluster cluster = clusterRepository.findById(stack.getCluster().getId());
if (cluster == null) {
throw new BadRequestException(String.format("Cluster does not exist on stack with '%s' id.", stackId));
}
if (!stack.isAvailable()) {
throw new BadRequestException(String.format("Stack '%s' is currently in '%s' state. Upgrade requests to a cluster can only be made if the underlying stack is 'AVAILABLE'.", stackId, stack.getStatus()));
}
if (!cluster.isAvailable()) {
throw new BadRequestException(String.format("Cluster '%s' is currently in '%s' state. Upgrade requests to a cluster can only be made if the underlying stack is 'AVAILABLE'.", stackId, stack.getStatus()));
}
AmbariRepo ambariRepo = clusterComponentConfigProvider.getAmbariRepo(cluster.getId());
if (ambariRepo == null) {
try {
clusterComponentConfigProvider.store(new ClusterComponent(ComponentType.AMBARI_REPO_DETAILS, new Json(ambariRepoUpgrade), stack.getCluster()));
} catch (JsonProcessingException ignored) {
throw new BadRequestException(String.format("Ambari repo details cannot be saved. %s", ambariRepoUpgrade));
}
} else {
ClusterComponent component = clusterComponentConfigProvider.getComponent(cluster.getId(), ComponentType.AMBARI_REPO_DETAILS);
ambariRepo.setBaseUrl(ambariRepoUpgrade.getBaseUrl());
ambariRepo.setGpgKeyUrl(ambariRepoUpgrade.getGpgKeyUrl());
ambariRepo.setPredefined(false);
ambariRepo.setVersion(ambariRepoUpgrade.getVersion());
try {
component.setAttributes(new Json(ambariRepo));
clusterComponentConfigProvider.store(component);
} catch (JsonProcessingException ignored) {
throw new BadRequestException(String.format("Ambari repo details cannot be saved. %s", ambariRepoUpgrade));
}
}
try {
flowManager.triggerClusterUpgrade(stack.getId());
} catch (RuntimeException e) {
throw new CloudbreakServiceException(e);
}
}
}
use of com.sequenceiq.cloudbreak.service.CloudbreakServiceException in project cloudbreak by hortonworks.
the class EmailSenderService method sendEmail.
private void sendEmail(IdentityUser user, String mail, String template, String subject, Map<String, Object> model) {
try {
String emailBody = processTemplateIntoString(freemarkerConfiguration.getTemplate(template, "UTF-8"), model);
LOGGER.debug("Sending email. Content: {}", emailBody);
mailSender.send(emailMimeMessagePreparator.prepareMessage(Strings.isNullOrEmpty(mail) ? user.getUsername() : mail, subject, emailBody));
} catch (Exception e) {
LOGGER.error("Could not send email. User: {}", user.getUserId());
throw new CloudbreakServiceException(e);
}
}
use of com.sequenceiq.cloudbreak.service.CloudbreakServiceException in project cloudbreak by hortonworks.
the class CheckImageAction method doExecute.
@Override
protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
CheckImageResult checkImageResult = stackCreationService.checkImage(context);
switch(checkImageResult.getImageStatus()) {
case IN_PROGRESS:
repeat(context);
break;
case CREATE_FINISHED:
sendEvent(context);
break;
case CREATE_FAILED:
LOGGER.error("Error during image status check: {}", payload);
int faultNum = getFaultNum(variables) + 1;
if (faultNum == FAULT_TOLERANCE) {
removeFaultNum(variables);
throw new CloudbreakServiceException("Image copy failed.");
} else {
setFaultNum(variables, faultNum);
repeat(context);
}
break;
default:
LOGGER.error("Unknown imagestatus: {}", checkImageResult.getImageStatus());
break;
}
}
use of com.sequenceiq.cloudbreak.service.CloudbreakServiceException in project cloudbreak by hortonworks.
the class StackCreationActions method prepareImageAction.
@Bean(name = "IMAGESETUP_STATE")
public Action<?, ?> prepareImageAction() {
return new AbstractStackCreationAction<SetupResult>(SetupResult.class) {
@Override
protected void doExecute(StackContext context, SetupResult payload, Map<Object, Object> variables) {
stackCreationService.prepareImage(context.getStack());
sendEvent(context);
}
@Override
protected Selectable createRequest(StackContext context) {
try {
CloudStack cloudStack = cloudStackConverter.convert(context.getStack());
Image image = imageService.getImage(context.getCloudContext().getId());
return new PrepareImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, image);
} catch (CloudbreakImageNotFoundException e) {
throw new CloudbreakServiceException(e);
}
}
};
}
use of com.sequenceiq.cloudbreak.service.CloudbreakServiceException in project cloudbreak by hortonworks.
the class StackCreationService method checkImage.
public CheckImageResult checkImage(StackContext context) {
try {
Stack stack = context.getStack();
Image image = imageService.getImage(stack.getId());
CheckImageRequest<CheckImageResult> checkImageRequest = new CheckImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStackConverter.convert(stack), image);
LOGGER.info("Triggering event: {}", checkImageRequest);
eventBus.notify(checkImageRequest.selector(), eventFactory.createEvent(checkImageRequest));
CheckImageResult result = checkImageRequest.await();
sendNotification(result, stack);
LOGGER.info("Result: {}", result);
return result;
} catch (InterruptedException e) {
LOGGER.error("Error while executing check image", e);
throw new OperationException(e);
} catch (CloudbreakImageNotFoundException e) {
throw new CloudbreakServiceException(e);
}
}
Aggregations