Search in sources :

Example 31 with FAILED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.

the class ClusterRecoveryService method validateStackStatus.

private RecoveryValidationV4Response validateStackStatus(Stack stack) {
    List<StackStatus> statusList = stackStatusService.findAllStackStatusesById(stack.getId());
    List<DetailedStackStatus> detailedStackStatusList = statusList.stream().map(StackStatus::getDetailedStackStatus).collect(Collectors.toList());
    int lastRecoverySuccess = getLastRecoverySuccess(detailedStackStatusList);
    int lastRecoveryFailure = getLastRecoveryFailure(detailedStackStatusList);
    int lastUpgradeSuccess = getLastUpgradeSuccess(detailedStackStatusList);
    int lastUpgradeFailure = getLastUpgradeFailure(detailedStackStatusList);
    String logMessage = Stream.of(createLogEntry(lastUpgradeSuccess, DetailedStackStatus.CLUSTER_UPGRADE_FINISHED), createLogEntry(lastUpgradeFailure, DetailedStackStatus.CLUSTER_UPGRADE_FAILED), createLogEntry(lastRecoverySuccess, DetailedStackStatus.CLUSTER_RECOVERY_FINISHED), createLogEntry(lastRecoveryFailure, DetailedStackStatus.CLUSTER_RECOVERY_FAILED)).flatMap(Optional::stream).collect(Collectors.joining(". "));
    LOGGER.debug(logMessage);
    int maximumInt = IntStream.of(lastUpgradeFailure, lastRecoveryFailure, lastRecoverySuccess, lastUpgradeSuccess).max().getAsInt();
    String reason;
    RecoveryStatus status;
    if (maximumInt == -1) {
        reason = "There has been no failed upgrades for this cluster hence recovery is not permitted.";
        status = NON_RECOVERABLE;
    } else if (maximumInt == lastRecoveryFailure) {
        reason = "Last cluster recovery has failed, recovery can be retried.";
        status = RECOVERABLE;
    } else if (maximumInt == lastUpgradeFailure) {
        reason = "Last cluster upgrade has failed, recovery can be launched to restore the cluster to its pre-upgrade state.";
        status = RECOVERABLE;
    } else {
        reason = "Cluster is not in a recoverable state now, neither uncorrected upgrade or recovery failures are present.";
        status = NON_RECOVERABLE;
    }
    LOGGER.info(reason);
    return new RecoveryValidationV4Response(reason, status);
}
Also used : RecoveryValidationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryValidationV4Response) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) RecoveryStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryStatus)

Example 32 with FAILED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.

the class ClusterUpgradeAvailabilityService method checkForUpgrades.

private UpgradeV4Response checkForUpgrades(Stack stack, boolean lockComponents, InternalUpgradeSettings internalUpgradeSettings) {
    String accountId = Crn.safeFromString(stack.getResourceCrn()).getAccountId();
    UpgradeV4Response upgradeOptions = new UpgradeV4Response();
    try {
        LOGGER.info(String.format("Retrieving images for upgrading stack %s", stack.getName()));
        com.sequenceiq.cloudbreak.cloud.model.Image currentImage = getImage(stack);
        CloudbreakImageCatalogV3 imageCatalog = getImagesFromCatalog(stack.getWorkspace(), currentImage.getImageCatalogName(), currentImage.getImageCatalogUrl());
        Image image = getCurrentImageFromCatalog(currentImage.getImageId(), imageCatalog);
        ImageFilterParams imageFilterParams = createImageFilterParams(image, lockComponents, stack, internalUpgradeSettings);
        ImageFilterResult imageFilterResult = filterImages(accountId, imageCatalog, imageFilterParams);
        LOGGER.info(String.format("%d possible image found for stack upgrade.", imageFilterResult.getImages().size()));
        upgradeOptions = createResponse(image, imageFilterResult, stack.getCloudPlatform(), stack.getRegion(), currentImage.getImageCatalogName());
    } catch (CloudbreakImageNotFoundException | CloudbreakImageCatalogException | NotFoundException e) {
        LOGGER.warn("Failed to get images", e);
        upgradeOptions.setReason(String.format("Failed to retrieve image due to %s", e.getMessage()));
    }
    return upgradeOptions;
}
Also used : CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageFilterParams(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams) ImageFilterResult(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult)

Example 33 with FAILED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.

the class SdxService method resizeSdx.

public Pair<SdxCluster, FlowIdentifier> resizeSdx(final String userCrn, final String clusterName, final SdxClusterResizeRequest sdxClusterResizeRequest) {
    LOGGER.info("Re-sizing SDX cluster with name {}", clusterName);
    String accountIdFromCrn = getAccountIdFromCrn(userCrn);
    String environmentName = sdxClusterResizeRequest.getEnvironment();
    SdxClusterShape shape = sdxClusterResizeRequest.getClusterShape();
    final SdxCluster sdxCluster = sdxClusterRepository.findByAccountIdAndClusterNameAndDeletedIsNullAndDetachedIsFalse(accountIdFromCrn, clusterName).orElseThrow(() -> notFound("SDX cluster", clusterName).get());
    MDCBuilder.buildMdcContext(sdxCluster);
    validateSdxResizeRequest(sdxCluster, accountIdFromCrn, shape);
    StackV4Response stackV4Response = getDetail(clusterName, Set.of(StackResponseEntries.HARDWARE_INFO.getEntryName(), StackResponseEntries.EVENTS.getEntryName()), accountIdFromCrn);
    DetailedEnvironmentResponse environment = validateAndGetEnvironment(environmentName);
    SdxCluster newSdxCluster = validateAndCreateNewSdxCluster(userCrn, clusterName, sdxCluster.getRuntime(), shape, sdxCluster.isRangerRazEnabled(), sdxCluster.isEnableMultiAz(), environment);
    newSdxCluster.setTags(sdxCluster.getTags());
    newSdxCluster.setCrn(sdxCluster.getCrn());
    CloudPlatform cloudPlatform = CloudPlatform.valueOf(environment.getCloudPlatform());
    if (!StringUtils.isBlank(sdxCluster.getCloudStorageBaseLocation())) {
        newSdxCluster.setCloudStorageBaseLocation(sdxCluster.getCloudStorageBaseLocation());
        newSdxCluster.setCloudStorageFileSystemType(sdxCluster.getCloudStorageFileSystemType());
    } else if (!CloudPlatform.YARN.equalsIgnoreCase(cloudPlatform.name()) && !CloudPlatform.GCP.equalsIgnoreCase(cloudPlatform.name()) && !CloudPlatform.MOCK.equalsIgnoreCase(cloudPlatform.name())) {
        throw new BadRequestException("Cloud storage parameter is required.");
    }
    newSdxCluster.setDatabaseAvailabilityType(sdxCluster.getDatabaseAvailabilityType());
    newSdxCluster.setDatabaseEngineVersion(sdxCluster.getDatabaseEngineVersion());
    StackV4Request stackRequest = getStackRequest(shape, sdxCluster.isRangerRazEnabled(), null, cloudPlatform, sdxCluster.getRuntime(), null);
    if (shape == SdxClusterShape.MEDIUM_DUTY_HA) {
        // This is added to make sure the host name used by Light and Medium duty are not the same.
        CustomDomainSettingsV4Request customDomainSettingsV4Request = new CustomDomainSettingsV4Request();
        customDomainSettingsV4Request.setHostname(sdxCluster.getClusterName() + SDX_RESIZE_NAME_SUFFIX);
        stackRequest.setCustomDomain(customDomainSettingsV4Request);
    }
    prepareCloudStorageForStack(stackRequest, stackV4Response, newSdxCluster, environment);
    prepareDefaultSecurityConfigs(null, stackRequest, cloudPlatform);
    try {
        if (!StringUtils.isBlank(sdxCluster.getStackRequestToCloudbreak())) {
            StackV4Request stackV4RequestOrig = JsonUtil.readValue(sdxCluster.getStackRequestToCloudbreak(), StackV4Request.class);
            stackRequest.setImage(stackV4RequestOrig.getImage());
        }
    } catch (IOException ioException) {
        LOGGER.error("Failed to re-use the image catalog. Will use default catalog", ioException);
    }
    stackRequest.setResourceCrn(newSdxCluster.getCrn());
    newSdxCluster.setStackRequest(stackRequest);
    FlowIdentifier flowIdentifier = sdxReactorFlowManager.triggerSdxResize(sdxCluster.getId(), newSdxCluster);
    return Pair.of(sdxCluster, flowIdentifier);
}
Also used : CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) CustomDomainSettingsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.customdomain.CustomDomainSettingsV4Request) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) IOException(java.io.IOException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) SdxClusterShape(com.sequenceiq.sdx.api.model.SdxClusterShape)

Example 34 with FAILED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.

the class BlueprintV4RequestToBlueprintConverterTest method rejectsBuiltinWithInvalidContent.

@Test
public void rejectsBuiltinWithInvalidContent() {
    BlueprintV4Request request = new BlueprintV4Request();
    request.setBlueprint("{ \"blueprint\": { \"cdhVersion\": \"7.0.0\", { } }");
    thrown.expect(BadRequestException.class);
    thrown.expectMessage("Invalid cluster template: Failed to parse JSON.");
    underTest.convert(request);
}
Also used : BlueprintV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request) Test(org.junit.Test) AbstractJsonConverterTest(com.sequenceiq.cloudbreak.converter.AbstractJsonConverterTest)

Example 35 with FAILED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.

the class ClusterToClusterV4ResponseConverter method convertContainerConfig.

private void convertContainerConfig(Cluster source, ClusterV4Response clusterResponse) {
    Json customContainerDefinition = source.getCustomContainerDefinition();
    if (customContainerDefinition != null && StringUtils.isNotEmpty(customContainerDefinition.getValue())) {
        try {
            Map<String, String> map = customContainerDefinition.get(Map.class);
            Map<String, String> result = new HashMap<>();
            for (Entry<String, String> stringStringEntry : map.entrySet()) {
                result.put(stringStringEntry.getKey(), stringStringEntry.getValue());
            }
            CustomContainerV4Response customContainers = new CustomContainerV4Response();
            customContainers.setDefinitions(result);
            clusterResponse.setCustomContainers(customContainers);
        } catch (IOException e) {
            LOGGER.info("Failed to add customContainerDefinition to response", e);
            throw new CloudbreakApiException("Failed to add customContainerDefinition to response", e);
        }
    }
}
Also used : CustomContainerV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.customcontainer.CustomContainerV4Response) HashMap(java.util.HashMap) Json(com.sequenceiq.cloudbreak.common.json.Json) IOException(java.io.IOException) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)20 List (java.util.List)19 Set (java.util.Set)18 Inject (javax.inject.Inject)18 Optional (java.util.Optional)17 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 Map (java.util.Map)16 Collectors (java.util.stream.Collectors)15 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)14 HashSet (java.util.HashSet)13 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)11 Collection (java.util.Collection)11 Collections (java.util.Collections)11 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)9 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)9 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)8 VolumeSetAttributes (com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes)8 ResourceAttributeUtil (com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil)8 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)8