use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class LoadBalancerConfigService method getKnoxGatewayGroups.
public Set<String> getKnoxGatewayGroups(Stack stack) {
LOGGER.debug("Fetching list of instance groups with Knox gateway installed");
Set<String> groupNames = new HashSet<>();
Cluster cluster = stack.getCluster();
if (cluster != null) {
LOGGER.debug("Checking if Knox gateway is explicitly defined");
CmTemplateProcessor cmTemplateProcessor = new CmTemplateProcessor(cluster.getBlueprint().getBlueprintText());
groupNames = cmTemplateProcessor.getHostGroupsWithComponent(KnoxRoles.KNOX_GATEWAY);
}
if (groupNames.isEmpty()) {
LOGGER.debug("Knox gateway is not explicitly defined; searching for CM gateway hosts");
groupNames = stack.getInstanceGroups().stream().filter(i -> InstanceGroupType.isGateway(i.getInstanceGroupType())).map(InstanceGroup::getGroupName).collect(Collectors.toSet());
}
if (groupNames.isEmpty()) {
LOGGER.info("No Knox gateway instance groups found");
}
return groupNames;
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class AltusMachineUserService method storeDataBusCredential.
/**
* Store databus access / secret keypair and machine user name in the cluster if altus credential exists
* @param altusCredential dto for databus access/private key
* @param stack component will be attached to this stack
* @return domain object that holds databus credential
*/
public DataBusCredential storeDataBusCredential(Optional<AltusCredential> altusCredential, Stack stack) {
if (altusCredential.isPresent()) {
DataBusCredential dataBusCredential = new DataBusCredential();
dataBusCredential.setMachineUserName(getFluentDatabusMachineUserName(stack));
dataBusCredential.setAccessKey(altusCredential.get().getAccessKey());
dataBusCredential.setPrivateKey(altusCredential.get().getPrivateKey() != null ? new String(altusCredential.get().getPrivateKey()) : null);
String databusCredentialJsonString = new Json(dataBusCredential).getValue();
Cluster cluster = stack.getCluster();
if (cluster != null) {
cluster.setDatabusCredential(databusCredentialJsonString);
clusterService.updateCluster(cluster);
}
return dataBusCredential;
}
return null;
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class BlueprintService method prepareDeletion.
@Override
protected void prepareDeletion(Blueprint blueprint) {
Set<Cluster> notDeletedClustersWithThisCd = getNotDeletedClustersWithBlueprint(blueprint);
if (!notDeletedClustersWithThisCd.isEmpty()) {
if (notDeletedClustersWithThisCd.size() > 1) {
List<String> clusters = notDeletedClustersWithThisCd.stream().filter(it -> !it.getStack().getType().equals(StackType.TEMPLATE)).map(it -> it.getStack().getName()).collect(Collectors.toList());
List<Long> stackTemplateIds = notDeletedClustersWithThisCd.stream().filter(it -> it.getStack().getType().equals(StackType.TEMPLATE)).map(it -> it.getStack().getId()).collect(Collectors.toList());
Set<String> clusterDefinitions = getClusterDefinitionNameByStackTemplateIds(stackTemplateIds);
throw new BadRequestException(String.format("There are clusters or cluster definitions associated with cluster template '%s'. " + "The cluster template used by %s cluster(s) (%s) and %s cluster definitions (%s). " + "Please remove these before deleting the cluster template.", blueprint.getName(), clusters.size(), String.join(", ", clusters), clusterDefinitions.size(), String.join(", ", clusterDefinitions)));
}
Cluster cluster = notDeletedClustersWithThisCd.iterator().next();
String clusterType = getClusterType(cluster);
String clusterDefinitionName = getClusterDefinitionNameByStackTemplateIds(List.of(cluster.getStack().getId())).stream().findFirst().orElseThrow(() -> new NotFoundException("Cannot find the cluster definition for the stack template"));
throw new BadRequestException(String.format("There is a %s ['%s'] which uses cluster template '%s'. Please remove this " + "cluster before deleting the cluster template.", clusterType, clusterDefinitionName, blueprint.getName()));
}
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class ClusterProxyRegistrationHandler method registerCluster.
private Selectable registerCluster(ClusterProxyRegistrationRequest request) {
Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
try {
if (!clusterProxyEnablementService.isClusterProxyApplicable(request.getCloudPlatform())) {
LOGGER.info("Cluster Proxy integration is DISABLED, skipping registering with Cluster Proxy service. Cluster CRN: {}", stack.getResourceCrn());
return new ClusterProxyRegistrationSuccess(request.getResourceId());
}
ConfigRegistrationResponse registerResponse = clusterProxyService.registerCluster(stack);
Cluster cluster = stack.getCluster();
if (cluster.hasGateway()) {
LOGGER.debug("Updating Gateway for cluster {} in environment {} with public key certificate retrieved from Cluster Proxy", cluster.getId(), stack.getEnvironmentCrn());
Gateway gateway = cluster.getGateway();
gateway.setTokenCert(registerResponse.getX509Unwrapped());
gatewayService.save(gateway);
}
return new ClusterProxyRegistrationSuccess(request.getResourceId());
} catch (Exception e) {
LOGGER.error("Error occurred when registering cluster {} in environment {} to cluster proxy", stack.getCluster().getId(), stack.getEnvironmentCrn(), e);
return new ClusterProxyRegistrationFailed(request.getResourceId(), e);
}
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class ClusterService method getStackRepositoryJson.
public String getStackRepositoryJson(Long stackId) {
Stack stack = stackService.getById(stackId);
Cluster cluster = stack.getCluster();
if (cluster == null) {
throw new BadRequestException(String.format("There is no cluster installed on stack '%s'.", stack.getName()));
}
StackRepoDetails repoDetails = clusterComponentConfigProvider.getStackRepoDetails(cluster.getId());
String stackRepoId = repoDetails.getStack().get(REPO_ID_TAG);
return clusterApiConnectors.getConnector(stack).clusterModificationService().getStackRepositoryJson(repoDetails, stackRepoId);
}
Aggregations