use of com.sequenceiq.cloudbreak.common.exception.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.debug("Triggering event: {}", checkImageRequest);
eventBus.notify(checkImageRequest.selector(), eventFactory.createEvent(checkImageRequest));
CheckImageResult result = checkImageRequest.await();
sendNotificationIfNecessary(result, stack);
LOGGER.debug("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);
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class StackSyncService method updateInstances.
public void updateInstances(Stack stack, Iterable<InstanceMetaData> instanceMetaDataList, Collection<CloudVmInstanceStatus> instanceStatuses, SyncConfig syncConfig) {
try {
Map<InstanceSyncState, Integer> counts = initInstanceStateCounts();
Json imageJson = new Json(imageService.getImage(stack.getId()));
for (InstanceMetaData metaData : instanceMetaDataList) {
Optional<CloudVmInstanceStatus> status = instanceStatuses.stream().filter(is -> is != null && is.getCloudInstance().getInstanceId() != null && is.getCloudInstance().getInstanceId().equals(metaData.getInstanceId())).findFirst();
InstanceSyncState state;
if (status.isPresent()) {
CloudVmInstanceStatus cloudVmInstanceStatus = status.get();
CloudInstance cloudInstance = cloudVmInstanceStatus.getCloudInstance();
state = InstanceSyncState.getInstanceSyncState(cloudVmInstanceStatus.getStatus());
syncInstance(metaData, cloudInstance, imageJson);
} else {
state = InstanceSyncState.DELETED;
}
try {
syncInstanceStatusByState(stack, counts, metaData, state);
} catch (TransactionRuntimeExecutionException e) {
LOGGER.error("Can't sync instance status by state!", e);
}
}
handleSyncResult(stack, counts, syncConfig);
} catch (CloudbreakImageNotFoundException | IllegalArgumentException ex) {
LOGGER.info("Error during stack sync:", ex);
throw new CloudbreakServiceException("Stack sync failed", ex);
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class ClusterTemplateService method listInWorkspaceAndCleanUpInvalids.
public Set<ClusterTemplateViewV4Response> listInWorkspaceAndCleanUpInvalids(Long workspaceId, String accountId) {
try {
boolean internalTenant = entitlementService.internalTenant(accountId);
Set<ClusterTemplateView> views = transactionService.required(() -> clusterTemplateViewService.findAllActive(workspaceId, internalTenant));
Set<ClusterTemplateViewV4Response> responses = transactionService.required(() -> views.stream().map(v -> clusterTemplateViewToClusterTemplateViewV4ResponseConverter.convert(v)).collect(toSet()));
environmentServiceDecorator.prepareEnvironments(responses);
cleanUpInvalidClusterDefinitions(workspaceId, responses);
return responses.stream().filter(this::isUsableClusterTemplate).filter(this::isClusterTemplateHasValidCloudPlatform).collect(toSet());
} catch (TransactionExecutionException e) {
LOGGER.warn("Unable to find cluster definitions due to {}", e.getMessage());
LOGGER.warn("Unable to find cluster definitions", e);
throw new CloudbreakServiceException("Unable to obtain cluster definitions!");
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class ClusterHostServiceRunnerTest method collectAndCheckReachableNodesThrowsException.
@Test
void collectAndCheckReachableNodesThrowsException() throws NodesUnreachableException {
Set<String> unreachableNodes = new HashSet<>();
unreachableNodes.add("node1.example.com");
when(stackUtil.collectAndCheckReachableNodes(eq(stack), any())).thenThrow(new NodesUnreachableException("error", unreachableNodes));
CloudbreakServiceException cloudbreakServiceException = Assertions.assertThrows(CloudbreakServiceException.class, () -> underTest.runClusterServices(stack, cluster, Map.of()));
assertEquals("Can not run cluster services on new nodes because the configuration management service is not responding on these nodes: " + "[node1.example.com]", cloudbreakServiceException.getMessage());
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class CmSyncHandlerTest method testAcceptWhenStackNotFound.
@Test
void testAcceptWhenStackNotFound() {
Set<String> candidateImageUuids = Set.of(IMAGE_UUID_1);
HandlerEvent<CmSyncRequest> event = getCmSyncRequestHandlerEvent(candidateImageUuids);
Exception exception = new CloudbreakServiceException("errordetail");
when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenThrow(exception);
CmSyncResult result = (CmSyncResult) underTest.doAccept(event);
assertEquals("CMSYNCRESULT_ERROR", result.selector());
assertThat(result.getErrorDetails(), instanceOf(CloudbreakServiceException.class));
assertEquals("unexpected error: errordetail", result.getErrorDetails().getMessage());
assertEquals("unexpected error: errordetail", result.getStatusReason());
verify(stackService).getByIdWithListsInTransaction(STACK_ID);
verify(cmSyncImageCollectorService, never()).collectImages(anyString(), any(), any());
verify(cmSyncerService, never()).syncFromCmToDb(any(), any());
}
Aggregations