use of com.sequenceiq.sdx.api.model.SdxClusterShape 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.sdx.api.model.SdxClusterShape in project cloudbreak by hortonworks.
the class SdxService method validateInternalSdxRequest.
private void validateInternalSdxRequest(StackV4Request stackv4Request, SdxClusterRequest sdxClusterRequest) {
ValidationResultBuilder validationResultBuilder = ValidationResult.builder();
if (stackv4Request != null) {
SdxClusterShape clusterShape = sdxClusterRequest.getClusterShape();
if (!clusterShape.equals(CUSTOM)) {
validationResultBuilder.error("Cluster shape '" + clusterShape + "' is not accepted on SDX Internal API. Use 'CUSTOM' cluster shape");
}
if (stackv4Request.getCluster() == null) {
validationResultBuilder.error("Cluster cannot be null.");
}
if (CollectionUtils.isNotEmpty(sdxClusterRequest.getCustomInstanceGroups())) {
validationResultBuilder.error("Custom instance group is not accepted on SDX Internal API.");
}
}
ValidationResult validationResult = validationResultBuilder.build();
if (validationResult.hasError()) {
LOGGER.error("Cannot create SDX via internal API: {}", validationResult.getFormattedErrors());
throw new BadRequestException(validationResult.getFormattedErrors());
}
}
use of com.sequenceiq.sdx.api.model.SdxClusterShape in project cloudbreak by hortonworks.
the class CDPConfigService method initCdpStackRequests.
@PostConstruct
public void initCdpStackRequests() {
PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
try {
Resource[] resources = pathMatchingResourcePatternResolver.getResources("classpath:duties/*/**/*.json");
for (Resource resource : resources) {
Matcher matcher = RESOURCE_TEMPLATE_PATTERN.matcher(resource.getURL().getPath());
if (matcher.find()) {
String runtimeVersion = matcher.group(RUNTIME_GROUP);
if (supportedRuntimes.isEmpty() || supportedRuntimes.contains(runtimeVersion)) {
CloudPlatform cloudPlatform = CloudPlatform.valueOf(matcher.group(CLOUDPLATFORM_GROUP).toUpperCase());
SdxClusterShape sdxClusterShape = SdxClusterShape.valueOf(matcher.group(CLUSTERSHAPE_GROUP).toUpperCase());
CDPConfigKey cdpConfigKey = new CDPConfigKey(cloudPlatform, sdxClusterShape, runtimeVersion);
String entitlementString = matcher.group(ENTITLEMENT_GROUP) != null ? StringUtils.substring(matcher.group(ENTITLEMENT_GROUP), 1) : null;
Optional<Entitlement> entitlementOptional = Arrays.stream(Entitlement.values()).filter(entitlement -> StringUtils.equals(entitlement.name().toLowerCase(), entitlementString)).findFirst();
String templateString = IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8.name());
if (!cdpStackRequests.containsKey(cdpConfigKey)) {
cdpStackRequests.put(cdpConfigKey, Maps.newHashMap());
}
cdpStackRequests.get(cdpConfigKey).putIfAbsent(entitlementOptional, templateString);
}
}
}
LOGGER.info("Cdp configs for datalakes: {}", cdpStackRequests);
} catch (IOException e) {
LOGGER.error("Can't read CDP template files", e);
throw new IllegalStateException("Can't read CDP template files", e);
}
}
use of com.sequenceiq.sdx.api.model.SdxClusterShape in project cloudbreak by hortonworks.
the class SdxResizeTests method validateShape.
private SdxInternalTestDto validateShape(SdxInternalTestDto dto) {
SdxClusterShape newShape = dto.getResponse().getClusterShape();
Log.log(LOGGER, format(" New shape: %s ", newShape.name()));
if (!SdxClusterShape.MEDIUM_DUTY_HA.equals(newShape)) {
throw new TestFailException(" The datalake shape is : " + newShape + " instead of: " + SdxClusterShape.MEDIUM_DUTY_HA.name());
}
return dto;
}
Aggregations