Search in sources :

Example 16 with StackResponse

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;
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) AutoscaleStackResponse(com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 17 with 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);
        }
    }
}
Also used : Logger(org.slf4j.Logger) Cluster(com.sequenceiq.periscope.domain.Cluster) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LoggerFactory(org.slf4j.LoggerFactory) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) ApplicationListener(org.springframework.context.ApplicationListener) UpdateFailedEvent(com.sequenceiq.periscope.monitor.event.UpdateFailedEvent) HashSet(java.util.HashSet) Inject(javax.inject.Inject) InstanceMetadataType(com.sequenceiq.cloudbreak.api.model.InstanceMetadataType) FailureReport(com.sequenceiq.cloudbreak.api.model.FailureReport) Component(org.springframework.stereotype.Component) Map(java.util.Map) InstanceStatus(com.sequenceiq.cloudbreak.api.model.InstanceStatus) MDCBuilder(com.sequenceiq.periscope.log.MDCBuilder) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) ClusterState(com.sequenceiq.periscope.api.model.ClusterState) Optional(java.util.Optional) InstanceMetaDataJson(com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson) Collections(java.util.Collections) CloudbreakClientConfiguration(com.sequenceiq.periscope.service.configuration.CloudbreakClientConfiguration) ClusterService(com.sequenceiq.periscope.service.ClusterService) FailureReport(com.sequenceiq.cloudbreak.api.model.FailureReport) InstanceMetaDataJson(com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson)

Example 18 with StackResponse

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);
    }
}
Also used : CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) Cluster(com.sequenceiq.periscope.domain.Cluster) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) HashSet(java.util.HashSet)

Example 19 with StackResponse

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;
}
Also used : StackValidationRequest(com.sequenceiq.cloudbreak.api.model.StackValidationRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) StackValidation(com.sequenceiq.cloudbreak.domain.StackValidation) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 20 with StackResponse

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;
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) AutoscaleStackResponse(com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Aggregations

StackResponse (com.sequenceiq.cloudbreak.api.model.StackResponse)32 Test (org.testng.annotations.Test)10 IntegrationTestContext (com.sequenceiq.it.IntegrationTestContext)9 Parameters (org.testng.annotations.Parameters)9 AbstractCloudbreakIntegrationTest (com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest)8 StackV1Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint)7 Map (java.util.Map)7 CredentialResponse (com.sequenceiq.cloudbreak.api.model.CredentialResponse)6 ImageJson (com.sequenceiq.cloudbreak.api.model.ImageJson)6 OrchestratorResponse (com.sequenceiq.cloudbreak.api.model.OrchestratorResponse)6 StackAuthenticationResponse (com.sequenceiq.cloudbreak.api.model.StackAuthenticationResponse)6 HashMap (java.util.HashMap)6 CloudbreakDetailsJson (com.sequenceiq.cloudbreak.api.model.CloudbreakDetailsJson)5 ClusterResponse (com.sequenceiq.cloudbreak.api.model.ClusterResponse)5 FailurePolicyResponse (com.sequenceiq.cloudbreak.api.model.FailurePolicyResponse)5 InstanceGroupRequest (com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest)5 InstanceMetaDataJson (com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson)5 NetworkResponse (com.sequenceiq.cloudbreak.api.model.NetworkResponse)5 CloudbreakClient (com.sequenceiq.cloudbreak.client.CloudbreakClient)5 Test (org.junit.Test)5