use of com.sequenceiq.cloudbreak.common.exception.NotFoundException 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.common.exception.NotFoundException 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.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class UpdateRecipeService method updateRecipeForCluster.
private void updateRecipeForCluster(Long workspaceId, Stack stack, String recipeName, String hostGroupName, boolean detach) {
Recipe recipe = recipeService.getByNameForWorkspaceId(recipeName, workspaceId);
HostGroup hostGroup = hostGroupService.getByClusterIdAndNameWithRecipes(stack.getCluster().getId(), hostGroupName);
if (hostGroup == null) {
throw new NotFoundException(String.format("Host group '%s' not found for workspace", hostGroupName));
}
Set<Recipe> existingRecipes = hostGroup.getRecipes();
Set<String> existingRecipeNames = existingRecipes.stream().map(Recipe::getName).collect(Collectors.toSet());
if (detach) {
detachRecipeFromHostGroup(recipe, hostGroup, existingRecipeNames);
} else {
attachRecipeToHostGroup(recipe, hostGroup, existingRecipeNames);
}
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class StackService method getByNameInWorkspaceWithEntries.
public StackV4Response getByNameInWorkspaceWithEntries(String name, Long workspaceId, Set<String> entries, User user, StackType stackType) {
try {
return transactionService.required(() -> {
Workspace workspace = workspaceService.get(workspaceId, user);
ShowTerminatedClustersAfterConfig showTerminatedClustersAfterConfig = showTerminatedClusterConfigService.get();
Optional<Stack> stack = findByNameAndWorkspaceIdWithLists(name, workspace.getId(), stackType, showTerminatedClustersAfterConfig);
if (stack.isEmpty()) {
throw new NotFoundException(format(STACK_NOT_FOUND_BY_NAME_EXCEPTION_MESSAGE, name));
}
StackV4Response stackResponse = stackToStackV4ResponseConverter.convert(stack.get());
stackResponse = stackResponseDecorator.decorate(stackResponse, stack.get(), entries);
return stackResponse;
});
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
}
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class StackService method getStackRequestByNameOrCrnInWorkspaceId.
public StackV4Request getStackRequestByNameOrCrnInWorkspaceId(NameOrCrn nameOrCrn, Long workspaceId) {
try {
return transactionService.required(() -> {
ShowTerminatedClustersAfterConfig showTerminatedClustersAfterConfig = showTerminatedClusterConfigService.get();
Optional<Stack> stack = findByNameOrCrnAndWorkspaceIdWithLists(nameOrCrn, workspaceId);
if (stack.isEmpty()) {
throw new NotFoundException(format(STACK_NOT_FOUND_BY_NAME_OR_CRN_EXCEPTION_MESSAGE, nameOrCrn));
}
StackV4Request request = stackToStackV4RequestConverter.convert(stack.get());
request.getCluster().setName(null);
request.setName(stack.get().getName());
return request;
});
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
}
}
Aggregations