use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class UserKeytabService method validateFreeIpaState.
private void validateFreeIpaState(String workloadUsername, String environmentCrn) {
String accountId = Crn.safeFromString(environmentCrn).getAccountId();
FreeIpaClient freeIpaClient;
try {
freeIpaClient = freeIpaClientFactory.getFreeIpaClientByAccountAndEnvironment(environmentCrn, accountId);
if (!FreeIpaCapabilities.hasSetPasswordHashSupport(freeIpaClient.getConfig())) {
throw new UnsupportedException("User keytab retrieval requires a newer environment and FreeIPA version");
}
Optional<User> user = freeIpaClient.userFind(workloadUsername);
if (user.isEmpty()) {
throw new NotFoundException(String.format("Workload user %s has not been synced into environment %s", workloadUsername, environmentCrn));
}
} catch (FreeIpaClientException e) {
throw new RuntimeException(e);
}
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class StackServiceTest method getByIdWithListsInTransactionNotFound.
@Test
void getByIdWithListsInTransactionNotFound() {
when(stackRepository.findOneWithLists(STACK_ID)).thenReturn(Optional.empty());
NotFoundException notFoundException = assertThrows(NotFoundException.class, () -> underTest.getByIdWithListsInTransaction(STACK_ID));
assertEquals("FreeIPA stack [" + STACK_ID + "] not found", notFoundException.getMessage());
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class StackServiceTest method getByEnvironmentCrnNotFound.
@Test
void getByEnvironmentCrnNotFound() {
when(stackRepository.findByEnvironmentCrnAndAccountId(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(Optional.empty());
when(childEnvironmentService.findParentByEnvironmentCrnAndAccountId(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(Optional.empty());
NotFoundException notFoundException = assertThrows(NotFoundException.class, () -> underTest.getByEnvironmentCrnAndAccountId(ENVIRONMENT_CRN, ACCOUNT_ID));
assertEquals("FreeIPA stack by environment [" + ENVIRONMENT_CRN + "] not found", notFoundException.getMessage());
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class DefaultModelService method createInstances.
public List<CloudVmMetaDataStatus> createInstances(String name, SpiDto spiDto, List<Group> groups) {
List<CloudVmMetaDataStatus> ret = new ArrayList<>();
String prefix = "192";
for (int groupIndex = 0; groupIndex < groups.size(); groupIndex++) {
List<Group> existedGroups = spiDto.getCloudStack().getGroups();
Group group = groups.get(groupIndex);
Optional<Group> existedGroupOpt = existedGroups.stream().filter(g -> group.getName().equals(g.getName())).findFirst();
if (existedGroupOpt.isEmpty()) {
throw new NotFoundException("Cannot find group with name: " + group.getName());
}
Group existedGroup = existedGroupOpt.get();
int indexOfExistedGroup = existedGroups.indexOf(existedGroup);
for (int instanceIndex = 0; instanceIndex < group.getInstances().size(); instanceIndex++) {
CloudInstance cloudInstance = group.getInstances().get(instanceIndex);
String address = generateAddress(prefix, spiDto, indexOfExistedGroup, ret);
String instanceId = String.format("instance-%s", address + "-" + UUID.randomUUID());
CloudInstance cloudInstanceWithId = new CloudInstance(instanceId, getTemplateCreated(cloudInstance), cloudInstance.getAuthentication(), cloudInstance.getSubnetId(), cloudInstance.getAvailabilityZone());
CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(cloudInstanceWithId, InstanceStatus.STARTED);
String publicIp = mockInfrastructureHost + ":10090/" + name;
CloudInstanceMetaData cloudInstanceMetaData = new CloudInstanceMetaData(address, publicIp, SSH_PORT, "MOCK");
CloudVmMetaDataStatus cloudVmMetaDataStatus = new CloudVmMetaDataStatus(cloudVmInstanceStatus, cloudInstanceMetaData);
ret.add(cloudVmMetaDataStatus);
}
}
return ret;
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class SaltOrchestrator method selectNewMasterReplacement.
private void selectNewMasterReplacement(SaltConnector sc, GatewayConfig primaryGateway, Set<String> unassignedHostnames, Set<String> existingFreeIpaReplicaHostnames, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel, Set<String> freeIpaMasterHostnames) throws Exception {
freeIpaMasterHostnames.add(unassignedHostnames.stream().findFirst().orElseGet(() -> choosePrimaryGatewayAsMasterReplacement(primaryGateway, existingFreeIpaReplicaHostnames).orElseThrow(() -> new NotFoundException("A primary FreeIPA instance is required and there are no unassigned roles to assign as a primary"))));
LOGGER.debug("Replacement primary FreeIPA: {}", freeIpaMasterHostnames);
saltCommandRunner.runModifyGrainCommand(sc, new GrainAddRunner(freeIpaMasterHostnames, allNodes, FREEIPA_MASTER_REPLACEMENT_ROLE), exitCriteriaModel, exitCriteria);
saltCommandRunner.runModifyGrainCommand(sc, new GrainRemoveRunner(freeIpaMasterHostnames, allNodes, FREEIPA_REPLICA_ROLE), exitCriteriaModel, exitCriteria);
}
Aggregations