use of com.sequenceiq.cloudbreak.service.OperationException in project cloudbreak by hortonworks.
the class CredentialPrerequisiteService method getCloudbreakPrerequisites.
public CredentialPrerequisitesResponse getCloudbreakPrerequisites(String cloudPlatform, boolean govCloud, String deploymentAddress, CredentialType type) {
CloudContext cloudContext = CloudContext.Builder.builder().withPlatform(cloudPlatform).withGovCloud(govCloud).withWorkspaceId(TEMP_WORKSPACE_ID).build();
CredentialPrerequisitesRequest request = new CredentialPrerequisitesRequest(cloudContext, userPreferencesService.getExternalIdForCurrentUser(), userPreferencesService.getAuditExternalIdForCurrentUser(), deploymentAddress, type);
LOGGER.debug("Triggering event: {}", request);
eventBus.notify(request.selector(), eventFactory.createEvent(request));
String message = String.format("Failed to get prerequisites for platform '%s': ", cloudPlatform);
try {
CredentialPrerequisitesResult res = request.await();
LOGGER.debug("Result: {}", res);
if (res.getStatus() != EventStatus.OK) {
LOGGER.info(message, res.getErrorDetails());
throw new BadRequestException(message + res.getErrorDetails(), res.getErrorDetails());
}
return res.getCredentialPrerequisitesResponse();
} catch (InterruptedException e) {
LOGGER.error(message, e);
throw new OperationException(e);
}
}
use of com.sequenceiq.cloudbreak.service.OperationException in project cloudbreak by hortonworks.
the class ResourceDefinitionService method getResourceDefinition.
@Cacheable("resourceDefinitionCache")
public String getResourceDefinition(String cloudPlatform, String resource) {
LOGGER.debug("Sending request for {} {} resource property definition", cloudPlatform, resource);
CloudPlatformVariant platformVariant = new CloudPlatformVariant(Platform.platform(cloudPlatform), Variant.EMPTY);
ResourceDefinitionRequest request = requestProvider.getResourceDefinitionRequest(platformVariant, resource);
eventBus.notify(request.selector(), eventFactory.createEvent(request));
try {
ResourceDefinitionResult result = request.await();
LOGGER.debug("Resource property definition: {}", result);
return result.getDefinition();
} catch (InterruptedException e) {
LOGGER.info("Error while sending resource definition request", e);
throw new OperationException(e);
}
}
use of com.sequenceiq.cloudbreak.service.OperationException in project cloudbreak by hortonworks.
the class FreeIpaUpscaleActions method validateInstancesAction.
@Bean(name = "UPSCALE_VALIDATE_INSTANCES_STATE")
public Action<?, ?> validateInstancesAction() {
return new AbstractUpscaleAction<>(UpscaleStackResult.class) {
@Override
protected void doExecute(StackContext context, UpscaleStackResult payload, Map<Object, Object> variables) {
Stack stack = context.getStack();
stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Validating new instances");
try {
finishAddInstances(context, payload);
sendEvent(context, UPSCALE_VALIDATE_INSTANCES_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
} catch (Exception e) {
LOGGER.error("Failed to validate the instances", e);
sendEvent(context, UPSCALE_VALIDATE_INSTANCES_FAILED_EVENT.selector(), new UpscaleFailureEvent(stack.getId(), "Validating new instances", Set.of(), Map.of(), e));
}
}
private void finishAddInstances(StackContext context, UpscaleStackResult payload) {
LOGGER.debug("Upscale stack result: {}", payload);
List<CloudResourceStatus> results = payload.getResults();
validateResourceResults(context, payload.getErrorDetails(), results);
Set<Resource> resourceSet = transformResults(results, context.getStack());
if (resourceSet.isEmpty()) {
metadataSetupService.cleanupRequestedInstances(context.getStack());
throw new OperationException("Failed to upscale the cluster since all create request failed. Resource set is empty");
}
LOGGER.debug("Adding new instances to the stack is DONE");
}
private void validateResourceResults(StackContext context, Exception exception, List<CloudResourceStatus> results) {
if (exception != null) {
LOGGER.info(format("Failed to upscale stack: %s", context.getCloudContext()), exception);
throw new OperationException(exception);
}
List<CloudResourceStatus> missingResources = results.stream().filter(result -> CommonResourceType.TEMPLATE == result.getCloudResource().getType().getCommonResourceType()).filter(status -> status.isFailed() || status.isDeleted()).collect(Collectors.toList());
if (!missingResources.isEmpty()) {
StringBuilder message = new StringBuilder("Failed to upscale the stack for ").append(context.getCloudContext()).append(" due to: ");
missingResources.forEach(res -> message.append("[privateId: ").append(res.getPrivateId()).append(", statusReason: ").append(res.getStatusReason()).append("] "));
LOGGER.warn(message.toString());
throw new OperationException(message.toString());
}
}
private Set<Resource> transformResults(Iterable<CloudResourceStatus> cloudResourceStatuses, Stack stack) {
Set<Resource> retSet = new HashSet<>();
for (CloudResourceStatus cloudResourceStatus : cloudResourceStatuses) {
if (!cloudResourceStatus.isFailed()) {
CloudResource cloudResource = cloudResourceStatus.getCloudResource();
Resource resource = new Resource(cloudResource.getType(), cloudResource.getName(), cloudResource.getReference(), cloudResource.getStatus(), stack, null, cloudResource.getAvailabilityZone());
retSet.add(resource);
}
}
return retSet;
}
};
}
use of com.sequenceiq.cloudbreak.service.OperationException in project cloudbreak by hortonworks.
the class UpgradeCcmOnDatalakeHandler method accept.
@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
LOGGER.debug("In UpgradeCcmOnDatalakeHandler.accept");
EnvironmentDto environmentDto = environmentDtoEvent.getData();
try {
LOGGER.debug("Calling Upgrade CCM endpoint on data lake service");
SdxCcmUpgradeResponse ccmUpgradeResponse = sdxService.upgradeCcm(environmentDto.getResourceCrn());
switch(ccmUpgradeResponse.getResponseType()) {
case ERROR:
String message = String.format("Upgrade CCM returned with reason: %s", ccmUpgradeResponse.getReason());
LOGGER.warn(message);
sendFailedEvent(environmentDtoEvent, environmentDto, new OperationException(message));
return;
case TRIGGERED:
LOGGER.debug("Waiting for data lake Upgrade CCM flow to finish.");
pollerService.waitForUpgradeCcm(environmentDto.getId(), ccmUpgradeResponse.getResourceCrn());
break;
case SKIP:
LOGGER.debug("Upgrade CCM is skipped due to {}", ccmUpgradeResponse.getReason());
break;
default:
message = String.format("Unknown response type: %s", ccmUpgradeResponse.getResponseType());
LOGGER.warn(message);
sendFailedEvent(environmentDtoEvent, environmentDto, new OperationException(message));
return;
}
UpgradeCcmEvent upgradeCcmEvent = UpgradeCcmEvent.builder().withSelector(UpgradeCcmStateSelectors.UPGRADE_CCM_DATAHUB_EVENT.selector()).withResourceCrn(environmentDto.getResourceCrn()).withResourceId(environmentDto.getId()).withResourceName(environmentDto.getName()).build();
eventSender().sendEvent(upgradeCcmEvent, environmentDtoEvent.getHeaders());
LOGGER.debug("UPGRADE_CCM_DATAHUB_EVENT event sent");
} catch (Exception e) {
sendFailedEvent(environmentDtoEvent, environmentDto, e);
}
}
use of com.sequenceiq.cloudbreak.service.OperationException in project cloudbreak by hortonworks.
the class ServiceProviderCredentialAdapter method verify.
public CredentialVerification verify(Credential credential, String accountId, boolean creationVerification) {
boolean changed = false;
credential = credentialPrerequisiteService.decorateCredential(credential);
CloudContext cloudContext = CloudContext.Builder.builder().withId(credential.getId()).withName(credential.getName()).withCrn(credential.getResourceCrn()).withPlatform(credential.getCloudPlatform()).withVariant(credential.getCloudPlatform()).withAccountId(accountId).build();
CloudCredential cloudCredential = credentialConverter.convert(credential);
CredentialVerificationRequest request = requestProvider.getCredentialVerificationRequest(cloudContext, cloudCredential, creationVerification);
LOGGER.debug("Triggering event: {}", request);
eventBus.notify(request.selector(), eventFactory.createEvent(request));
try {
CredentialVerificationResult res = request.await();
String message = FAILED_CREDETIAL_VERIFICATION_MESSAGE;
LOGGER.debug("Result: {}", res);
if (res.getStatus() != EventStatus.OK) {
LOGGER.info(message, res.getErrorDetails());
throw new CredentialVerificationException(message + res.getErrorDetails(), res.getErrorDetails());
}
CloudCredentialStatus cloudCredentialStatus = res.getCloudCredentialStatus();
if (CredentialStatus.FAILED.equals(cloudCredentialStatus.getStatus())) {
return new CredentialVerification(credential, setNewStatusText(credential, cloudCredentialStatus));
}
changed = setNewStatusText(credential, cloudCredentialStatus);
CloudCredential cloudCredentialResponse = cloudCredentialStatus.getCloudCredential();
if (cloudCredentialStatus.isDefaultRegionChanged()) {
changed = mergeCloudProviderParameters(credential, cloudCredentialResponse, Collections.singleton(SMART_SENSE_ID));
}
changed = changed || mergeCloudProviderParameters(credential, cloudCredentialResponse, Collections.singleton(SMART_SENSE_ID));
} catch (InterruptedException e) {
LOGGER.error("Error while executing credential verification", e);
throw new OperationException(e);
}
return new CredentialVerification(credential, changed);
}
Aggregations