use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException in project cloudbreak by hortonworks.
the class GatewayTopologyToGatewayTopologyV4RequestConverter method convert.
public GatewayTopologyV4Request convert(GatewayTopology gatewayTopology) {
GatewayTopologyV4Request gatewayTopologyJson = new GatewayTopologyV4Request();
gatewayTopologyJson.setTopologyName(gatewayTopology.getTopologyName());
Json exposedJson = gatewayTopology.getExposedServices();
if (exposedJson != null && StringUtils.isNotEmpty(exposedJson.getValue())) {
try {
gatewayTopologyJson.setExposedServices(exposedJson.get(ExposedServices.class).getServices());
} catch (IOException e) {
LOGGER.info("Failed to add exposedServices to response", e);
throw new CloudbreakApiException("Failed to add exposedServices to response", e);
}
}
return gatewayTopologyJson;
}
use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException in project cloudbreak by hortonworks.
the class StackImageUpdateService method getNewImageIfVersionsMatch.
public StatedImage getNewImageIfVersionsMatch(Stack stack, String newImageId, String imageCatalogName, String imageCatalogUrl) {
try {
restRequestThreadLocalService.setWorkspace(stack.getWorkspace());
Image currentImage = stackImageService.getCurrentImage(stack);
StatedImage newImage = getNewImage(newImageId, imageCatalogName, imageCatalogUrl, currentImage);
if (!isCloudPlatformMatches(stack, newImage)) {
String message = messagesService.getMessage(Msg.CLOUDPLATFORM_DIFFERENT.code(), Lists.newArrayList(String.join(",", newImage.getImage().getImageSetsByProvider().keySet()), stack.cloudPlatform()));
LOGGER.debug(message);
throw new OperationException(message);
}
if (!isOsVersionsMatch(currentImage, newImage)) {
String message = messagesService.getMessage(Msg.OSVERSION_DIFFERENT.code(), Lists.newArrayList(newImage.getImage().getOs(), newImage.getImage().getOsType(), currentImage.getOs(), currentImage.getOsType()));
LOGGER.debug(message);
throw new OperationException(message);
}
if (!isStackMatchIfPrewarmed(newImage)) {
String message = "Stack versions don't match on prewarmed image with cluster's";
LOGGER.debug(message);
throw new OperationException(message);
}
return newImage;
} 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);
}
}
use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException 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;
}
use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException in project cloudbreak by hortonworks.
the class SdxUpgradeRecoveryServiceTest method testGetClusterRecoverableByNameInternalThrowsExceptionShouldThrowApiException.
@Test
public void testGetClusterRecoverableByNameInternalThrowsExceptionShouldThrowApiException() {
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
WebApplicationException webApplicationException = new WebApplicationException();
doThrow(webApplicationException).when(stackV4Endpoint).getClusterRecoverableByNameInternal(WORKSPACE_ID, CLUSTER_NAME, USER_CRN);
when(exceptionMessageExtractor.getErrorMessage(webApplicationException)).thenReturn("web-error");
CloudbreakApiException actual = assertThrows(CloudbreakApiException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.validateRecovery(cluster)));
assertEquals("Stack recovery validation failed on cluster: [dummyCluster]. Message: [web-error]", actual.getMessage());
}
use of com.sequenceiq.cloudbreak.exception.CloudbreakApiException in project cloudbreak by hortonworks.
the class DatalakeFullRestoreWaitHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<DatalakeFullRestoreWaitRequest> event) {
DatalakeFullRestoreWaitRequest request = event.getData();
Long sdxId = request.getResourceId();
String userId = request.getUserId();
Selectable response;
try {
LOGGER.info("Start polling datalake full restore status for id: {}", sdxId);
PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
sdxBackupRestoreService.waitForDatalakeDrRestoreToComplete(sdxId, request.getOperationId(), request.getUserId(), pollingConfig, "Full restore");
response = new DatalakeRestoreSuccessEvent(sdxId, userId, request.getOperationId());
} catch (UserBreakException userBreakException) {
LOGGER.info("Full restore polling exited before timeout. Cause: ", userBreakException);
response = new DatalakeRestoreFailedEvent(sdxId, userId, userBreakException);
} catch (PollerStoppedException pollerStoppedException) {
LOGGER.info("Full restore poller stopped for cluster: {}", sdxId);
response = new DatalakeRestoreFailedEvent(sdxId, userId, new PollerStoppedException("Data lake restore timed out after " + durationInMinutes + " minutes"));
} catch (PollerException exception) {
LOGGER.info("Full restore polling failed for cluster: {}", sdxId);
response = new DatalakeRestoreFailedEvent(sdxId, userId, exception);
} catch (CloudbreakApiException exception) {
LOGGER.info("Datalake restore failed. Reason: " + exception.getMessage());
response = new DatalakeRestoreFailedEvent(sdxId, userId, exception);
}
return response;
}
Aggregations