use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class ClouderaManagerClusterCreationSetupService method determineCdhRepoConfig.
private Set<ClouderaManagerProduct> determineCdhRepoConfig(Cluster cluster, List<Component> stackCdhRepoConfig, String osType, String blueprintCdhVersion, String imageCatalogName) throws CloudbreakImageCatalogException {
if (Objects.isNull(stackCdhRepoConfig) || stackCdhRepoConfig.isEmpty()) {
DefaultCDHInfo defaultCDHInfo = getDefaultCDHInfo(cluster, blueprintCdhVersion, osType, imageCatalogName);
Map<String, String> stack = defaultCDHInfo.getRepo().getStack();
Set<ClouderaManagerProduct> cdhProduct = Set.of(new ClouderaManagerProduct().withVersion(defaultCDHInfo.getVersion()).withName(stack.get("repoid").split("-")[0]).withParcel(stack.get(osType)));
LOGGER.debug("Determined CDH product: {}", cdhProduct);
return cdhProduct;
} else {
Set<ClouderaManagerProduct> products = stackCdhRepoConfig.stream().map(Component::getAttributes).map(json -> json.getSilent(ClouderaManagerProduct.class)).collect(Collectors.toSet());
return filterParcelsIfNecessary(cluster, products);
}
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class ClouderaManagerClusterCreationSetupService method getDefaultCDHInfo.
private DefaultCDHInfo getDefaultCDHInfo(Cluster cluster, String blueprintCdhVersion, String osType, String imageCatalogName) throws CloudbreakImageCatalogException {
DefaultCDHInfo defaultCDHInfo = null;
Stack stack = cluster.getStack();
ImageCatalogPlatform platformString = platformStringTransformer.getPlatformStringForImageCatalog(stack.getCloudPlatform(), stack.getPlatformVariant());
Map<String, ImageBasedDefaultCDHInfo> entries = imageBasedDefaultCDHEntries.getEntries(cluster.getWorkspace().getId(), platformString, imageCatalogName);
if (blueprintCdhVersion != null && entries.containsKey(blueprintCdhVersion)) {
defaultCDHInfo = entries.get(blueprintCdhVersion).getDefaultCDHInfo();
}
if (defaultCDHInfo == null) {
defaultCDHInfo = entries.entrySet().stream().filter(e -> Objects.nonNull(e.getValue().getDefaultCDHInfo().getRepo().getStack().get(osType))).max(ImageBasedDefaultCDHEntries.IMAGE_BASED_CDH_ENTRY_COMPARATOR).orElseThrow(notFound("Default Product Info with OS type:", osType)).getValue().getDefaultCDHInfo();
}
return defaultCDHInfo;
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class ClusterCommonService method getHostNamesAsIniString.
/**
* Get cluster host details (ips + cluster name) - ini format
*
* @param stack stack object that is used to fill the cluster details ini
* @param loginUser ssh username that will be used as a default user in the inventory
* @return Ini file content in string
*/
public String getHostNamesAsIniString(Stack stack, String loginUser) {
Cluster cluster = stack.getCluster();
String clusterName = cluster.getName();
String serverHost = cluster.getClusterManagerIp();
List<InstanceMetaData> agentHostsSet = instanceMetaDataService.getAllInstanceMetadataByStackId(stack.getId()).stream().filter(i -> i.getInstanceStatus() != InstanceStatus.TERMINATED).collect(Collectors.toList());
if (agentHostsSet.isEmpty()) {
throw new NotFoundException(String.format("Not found any agent hosts (yet) for cluster '%s'", cluster.getId()));
}
String agentHosts = agentHostsSet.stream().map(InstanceMetaData::getPublicIpWrapper).collect(Collectors.joining("\n"));
List<String> hostGroupHostsStrings = agentHostsSet.stream().collect(Collectors.groupingBy(InstanceMetaData::getInstanceGroupName)).entrySet().stream().map(s -> addSectionWithBody(s.getKey(), s.getValue().stream().map(InstanceMetaData::getPublicIpWrapper).collect(Collectors.joining("\n")))).collect(Collectors.toList());
return String.join("\n", addSectionWithBody("cluster", "name=" + clusterName), addSectionWithBody("server", serverHost), String.join("\n", hostGroupHostsStrings), addSectionWithBody("agent", agentHosts), addSectionWithBody("all:vars", String.join("\n", String.format("ansible_ssh_user=%s", loginUser), "ansible_ssh_common_args='-o StrictHostKeyChecking=no'", "ansible_become=yes")));
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class ClusterCommonService method setMaintenanceMode.
public FlowIdentifier setMaintenanceMode(Stack stack, MaintenanceModeStatus maintenanceMode) {
Cluster cluster = stack.getCluster();
if (cluster == null) {
throw new BadRequestException(String.format("Cluster does not exist on stack with '%s' id.", stack.getId()));
} else if (!stack.isAvailable() && !stack.isMaintenanceModeEnabled()) {
throw new BadRequestException(String.format("Cluster '%s' is currently in '%s' state. Maintenance mode can be set to a cluster if it is 'AVAILABLE'.", stack.getId(), stack.getStatus()));
}
FlowIdentifier flowIdentifier = FlowIdentifier.notTriggered();
switch(maintenanceMode) {
case ENABLED:
saveAndFireEventOnClusterStatusChange(stack, DetailedStackStatus.MAINTENANCE_MODE_ENABLED, ResourceEvent.MAINTENANCE_MODE_ENABLED);
break;
case DISABLED:
saveAndFireEventOnClusterStatusChange(stack, DetailedStackStatus.AVAILABLE, ResourceEvent.MAINTENANCE_MODE_DISABLED);
break;
case VALIDATION_REQUESTED:
if (!MAINTENANCE_MODE_ENABLED.equals(stack.getStatus())) {
throw new BadRequestException(String.format("Maintenance mode is not enabled for cluster '%s' (status:'%s'), it should be enabled before validation.", cluster.getId(), stack.getStatus()));
}
flowIdentifier = clusterOperationService.triggerMaintenanceModeValidation(stack);
clusterService.save(cluster);
break;
default:
// Nothing to do here
break;
}
return flowIdentifier;
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class ClusterCreationSetupService method prepare.
public Cluster prepare(ClusterV4Request request, Stack stack, Blueprint blueprint, User user) throws IOException, CloudbreakImageCatalogException, TransactionExecutionException {
String stackName = stack.getName();
Cluster clusterStub = stack.getCluster();
stack.setCluster(null);
if (request.getCloudStorage() != null) {
FileSystem fileSystem = cloudStorageConverter.requestToFileSystem(request.getCloudStorage());
measure(() -> fileSystemConfigService.createWithMdcContextRestore(fileSystem, stack.getWorkspace(), user), LOGGER, "File system saving took {} ms for stack {}", stackName);
}
clusterStub.setStack(stack);
clusterStub.setWorkspace(stack.getWorkspace());
Cluster cluster = measure(() -> clusterDecorator.decorate(clusterStub, request, blueprint, user, stack.getWorkspace(), stack), LOGGER, "Cluster decorator {} ms for stack {}", stackName);
List<ClusterComponent> components = multiCheckedMeasure((MultiCheckedSupplier<List<ClusterComponent>, IOException, CloudbreakImageCatalogException>) () -> {
if (blueprint != null) {
Set<Component> allComponent = componentConfigProviderService.getAllComponentsByStackIdAndType(stack.getId(), Sets.newHashSet(ComponentType.CM_REPO_DETAILS, ComponentType.CDH_PRODUCT_DETAILS, ComponentType.IMAGE));
Optional<Component> stackCmRepoConfig = allComponent.stream().filter(c -> c.getComponentType().equals(ComponentType.CM_REPO_DETAILS)).findAny();
List<Component> stackCdhRepoConfig = allComponent.stream().filter(c -> c.getComponentType().equals(ComponentType.CDH_PRODUCT_DETAILS)).collect(Collectors.toList());
Optional<Component> stackImageComponent = allComponent.stream().filter(c -> c.getComponentType().equals(ComponentType.IMAGE) && c.getName().equalsIgnoreCase(ComponentType.IMAGE.name())).findAny();
return clouderaManagerClusterCreationSetupService.prepareClouderaManagerCluster(request, cluster, stackCmRepoConfig, stackCdhRepoConfig, stackImageComponent);
}
return Collections.emptyList();
}, LOGGER, "Cluster components saved in {} ms for stack {}", stackName);
return clusterOperationService.create(stack, cluster, components, user);
}
Aggregations