use of com.sequenceiq.cloudbreak.api.model.StackResponse in project cloudbreak by hortonworks.
the class StackService method getPublicStackJsonByName.
public StackResponse getPublicStackJsonByName(String name, IdentityUser identityUser, Collection<String> entries) {
Stack stack = stackRepository.findByNameInAccountWithLists(name, identityUser.getAccount());
if (stack == null) {
throw new NotFoundException(String.format(STACK_NOT_FOUND_EXCEPTION_FORMAT_TEXT, name));
}
authorizationService.hasReadPermission(stack);
StackResponse stackResponse = conversionService.convert(stack, StackResponse.class);
stackResponse = stackResponseDecorator.decorate(stackResponse, stack, entries);
return stackResponse;
}
use of com.sequenceiq.cloudbreak.api.model.StackResponse in project cloudbreak by hortonworks.
the class UpdateFailedHandler method reportAmbariServerFailure.
private void reportAmbariServerFailure(Cluster cluster, StackResponse stackResponse, CloudbreakClient cbClient) {
Optional<InstanceMetaDataJson> pgw = stackResponse.getInstanceGroups().stream().flatMap(ig -> ig.getMetadata().stream()).filter(im -> im.getInstanceType() == InstanceMetadataType.GATEWAY_PRIMARY && im.getInstanceStatus() != InstanceStatus.TERMINATED).findFirst();
if (pgw.isPresent()) {
FailureReport failureReport = new FailureReport();
failureReport.setFailedNodes(Collections.singletonList(pgw.get().getDiscoveryFQDN()));
try {
cbClient.clusterEndpoint().failureReport(cluster.getStackId(), failureReport);
} catch (Exception e) {
LOGGER.warn("Exception during failure report", e);
}
}
}
use of com.sequenceiq.cloudbreak.api.model.StackResponse in project cloudbreak by hortonworks.
the class UpdateFailedHandler method onApplicationEvent.
@Override
public void onApplicationEvent(UpdateFailedEvent event) {
long id = event.getClusterId();
Cluster cluster = clusterService.find(id);
MDCBuilder.buildMdcContext(cluster);
Integer failed = updateFailures.get(id);
if (failed == null) {
updateFailures.put(id, 1);
} else if (RETRY_THRESHOLD - 1 == failed) {
try {
CloudbreakClient cloudbreakClient = cloudbreakClientConfiguration.cloudbreakClient();
StackResponse stackResponse = cloudbreakClient.stackV1Endpoint().get(cluster.getStackId(), new HashSet<>());
String stackStatus = stackResponse.getStatus().name();
String clusterStatus = stackResponse.getCluster().getStatus().name();
if (stackStatus.startsWith(DELETE_STATUSES_PREFIX)) {
clusterService.removeById(id);
LOGGER.info("Delete cluster due to failing update attempts and Cloudbreak stack status");
} else if (stackStatus.equals(AVAILABLE) && clusterStatus.equals(AVAILABLE)) {
// Ambari server is unreacheable but the stack and cluster statuses are "AVAILABLE"
reportAmbariServerFailure(cluster, stackResponse, cloudbreakClient);
suspendCluster(cluster);
} else {
suspendCluster(cluster);
}
} catch (Exception ex) {
LOGGER.warn("Cluster status could not be verified by Cloudbreak for remove.", ex);
suspendCluster(cluster);
}
updateFailures.remove(id);
} else {
updateFailures.put(id, failed + 1);
}
}
use of com.sequenceiq.cloudbreak.api.model.StackResponse in project cloudbreak by hortonworks.
the class StackCreatorService method createStack.
public StackResponse createStack(IdentityUser user, StackRequest stackRequest, boolean publicInAccount) throws Exception {
stackRequest.setAccount(user.getAccount());
stackRequest.setOwner(user.getUserId());
stackRequest.setOwnerEmail(user.getUsername());
long start = System.currentTimeMillis();
Stack stack = conversionService.convert(stackRequest, Stack.class);
String stackName = stack.getName();
LOGGER.info("Stack request converted to stack in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
MDCBuilder.buildMdcContext(stack);
start = System.currentTimeMillis();
stack = stackSensitiveDataPropagator.propagate(stackRequest.getCredentialSource(), stack, user);
LOGGER.info("Stack propagated with sensitive data in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
stack = stackDecorator.decorate(stack, stackRequest, user);
LOGGER.info("Stack object has been decorated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
stack.setPublicInAccount(publicInAccount);
start = System.currentTimeMillis();
validateAccountPreferences(stack, user);
LOGGER.info("Account preferences has been validated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
if (stack.getOrchestrator() != null && stack.getOrchestrator().getApiEndpoint() != null) {
stackService.validateOrchestrator(stack.getOrchestrator());
}
for (InstanceGroup instanceGroup : stack.getInstanceGroups()) {
templateValidator.validateTemplateRequest(stack.getCredential(), instanceGroup.getTemplate(), stack.getRegion(), stack.getAvailabilityZone(), stack.getPlatformVariant());
}
Blueprint blueprint = null;
if (stackRequest.getClusterRequest() != null) {
start = System.currentTimeMillis();
StackValidationRequest stackValidationRequest = conversionService.convert(stackRequest, StackValidationRequest.class);
LOGGER.info("Stack validation request has been created in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
StackValidation stackValidation = conversionService.convert(stackValidationRequest, StackValidation.class);
LOGGER.info("Stack validation object has been created in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
blueprint = stackValidation.getBlueprint();
start = System.currentTimeMillis();
stackService.validateStack(stackValidation, stackRequest.getClusterRequest().getValidateBlueprint());
LOGGER.info("Stack has been validated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(stack.getCredential());
start = System.currentTimeMillis();
fileSystemValidator.validateFileSystem(stackValidationRequest.getPlatform(), cloudCredential, stackValidationRequest.getFileSystem());
LOGGER.info("Filesystem has been validated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
clusterCreationService.validate(stackRequest.getClusterRequest(), cloudCredential, stack, user);
LOGGER.info("Cluster has been validated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
}
start = System.currentTimeMillis();
stack = stackService.create(user, stack, stackRequest.getImageCatalog(), Optional.ofNullable(stackRequest.getImageId()), Optional.ofNullable(blueprint));
LOGGER.info("Stack object and its dependencies has been created in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
createClusterIfNeed(user, stackRequest, stack, stackName, blueprint);
start = System.currentTimeMillis();
StackResponse response = conversionService.convert(stack, StackResponse.class);
LOGGER.info("Stack response has been created in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
flowManager.triggerProvisioning(stack.getId());
LOGGER.info("Stack provision triggered in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
return response;
}
use of com.sequenceiq.cloudbreak.api.model.StackResponse in project cloudbreak by hortonworks.
the class StackService method getPrivateStackJsonByName.
public StackResponse getPrivateStackJsonByName(String name, IdentityUser identityUser, Collection<String> entries) {
Stack stack = stackRepository.findByNameInUserWithLists(name, identityUser.getUserId());
if (stack == null) {
throw new NotFoundException(String.format(STACK_NOT_FOUND_EXCEPTION_FORMAT_TEXT, name));
}
StackResponse stackResponse = conversionService.convert(stack, StackResponse.class);
stackResponse = stackResponseDecorator.decorate(stackResponse, stack, entries);
return stackResponse;
}
Aggregations