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);
}
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;
}
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);
}
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);
}
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);
}
}
}
Aggregations