use of org.bf2.srs.fleetmanager.spi.ams.impl.model.response.Organization in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class AccountManagementServiceImpl method determineAllowedResourceType.
@Timed(value = Constants.AMS_DETERMINE_ALLOWED_INSTANCE_TIMER, description = Constants.AMS_TIMER_DESCRIPTION)
@Audited
@Timeout(FaultToleranceConstants.TIMEOUT_MS)
@RetryUnwrap
// 3 retries, 200ms jitter
@Retry(retryOn = { RetryWrapperException.class })
@RetryWrap
@Override
public ResourceType determineAllowedResourceType(AccountInfo accountInfo) throws AccountManagementServiceException {
try {
Organization organization = restClient.getOrganizationByExternalId(accountInfo.getOrganizationId());
String orgId = organization.getId();
// Check QuotaCostList for a RHOSR entry with "allowed" quota > 0. If found, then
// return "Standard" as the resource type to create.
QuotaCostList quotaCostList = restClient.getQuotaCostList(orgId, true);
if (quotaCostList.getSize() > 0) {
for (QuotaCost quotaCost : quotaCostList.getItems()) {
// We only care about QuotaCost with "allowed" > 0 and with at least one related resource.
if (quotaCost.getAllowed() != null && quotaCost.getAllowed() > 0 && quotaCost.getRelated_resources() != null && !quotaCost.getRelated_resources().isEmpty() && isRhosrStandardQuota(quotaCost)) {
return ResourceType.REGISTRY_INSTANCE_STANDARD;
}
}
}
// Default to only allow eval.
return ResourceType.REGISTRY_INSTANCE_EVAL;
} catch (AccountManagementSystemClientException ex) {
ExceptionConvert.convert(ex);
// Never returns
return null;
}
}
use of org.bf2.srs.fleetmanager.spi.ams.impl.model.response.Organization in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class AccountManagementSystemRestClientTest method getOrganizationByExternalId.
@Test
public void getOrganizationByExternalId() {
final Organization org = accountManagementSystemRestClient.getOrganizationByExternalId("12345");
Assertions.assertNotNull(org);
Assertions.assertEquals("1pcZDw72EPhdanw4pJEnrudOnyj", org.getId());
}
use of org.bf2.srs.fleetmanager.spi.ams.impl.model.response.Organization in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class AccountManagementSystemRestClient method getOrganizationByExternalId.
public Organization getOrganizationByExternalId(String externalOrgId) {
String search = "external_id='ORG_ID'".replace("ORG_ID", externalOrgId);
Map<String, List<String>> queryParams = new HashMap<>();
queryParams.put("search", Collections.singletonList(search));
OrganizationList rval = this.client.sendRequest(new Request.RequestBuilder<OrganizationList>().operation(Operation.GET).path(Paths.ORGANIZATIONS_PATH).queryParams(queryParams).responseType(new TypeReference<OrganizationList>() {
}).build());
if (rval.getTotal() < 1) {
throw new AccountManagementSystemClientException("Organization not found with external id: " + externalOrgId);
}
return rval.getItems().get(0);
}
use of org.bf2.srs.fleetmanager.spi.ams.impl.model.response.Organization in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class FileQuotaPlansService method init.
@Override
public void init() throws IOException {
log.debug("Using FileQuotaPlansService implementation of QuotaPlansService");
if (plansConfigFile.isEmpty()) {
throw new IllegalArgumentException("Error in static quota plans config: Property 'registry.quota.plans.config.file' is required.");
}
log.info("Loading registry quota plans config file from {}", plansConfigFile.get().getAbsolutePath());
YAMLMapper mapper = SerDesObjectMapperProducer.getYAMLMapper();
QuotaPlansConfigList quotaPlansConfigList = mapper.readValue(plansConfigFile.get(), QuotaPlansConfigList.class);
List<QuotaPlan> staticQuotaPlans = quotaPlansConfigList.getPlans();
Set<String> names = new HashSet<>();
List<String> duplicatedNames = staticQuotaPlans.stream().map(d -> {
Set<ConstraintViolation<QuotaPlan>> errors = validator.validate(d);
if (!errors.isEmpty()) {
throw new ConstraintViolationException(errors);
}
return d;
}).filter(d -> !names.add(d.getName())).map(d -> d.getName()).collect(Collectors.toList());
if (!duplicatedNames.isEmpty()) {
throw new IllegalArgumentException("Error in static quota plans config, duplicated plan name: " + duplicatedNames.toString());
}
if (!names.contains(defaultQuotaPlan)) {
throw new IllegalArgumentException("Error in static quota plans config, default plan does not exist in plans config, default plan name: " + defaultQuotaPlan);
}
for (QuotaPlan p : staticQuotaPlans) {
tmClient.validateConfig(p.getResources());
plans.put(p.getName(), p);
}
List<OrganizationAssignment> staticOrganizationAssignments = quotaPlansConfigList.getOrganizations();
if (staticOrganizationAssignments == null)
staticOrganizationAssignments = Collections.emptyList();
for (OrganizationAssignment assignment : staticOrganizationAssignments) {
if (!plans.containsKey(assignment.getPlan())) {
throw new IllegalStateException("Could not find quota plan named '" + assignment.getPlan() + "' intended for organization ID '" + assignment.getOrgId() + "'");
}
organizationAssignments.put(assignment.getOrgId(), assignment);
}
if (quotaPlansConfigList.getReconcile() != null && quotaPlansConfigList.getReconcile()) {
reconcile();
}
}
use of org.bf2.srs.fleetmanager.spi.ams.impl.model.response.Organization in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class RegistryServiceImpl method getRegistries.
@Override
public RegistryListDto getRegistries(Integer page, Integer size, String orderBy, String search) {
// Defaults
var sort = Sort.by("id", Sort.Direction.Ascending);
page = (page != null) ? page : 1;
size = (size != null) ? size : 10;
if (orderBy != null) {
var order = orderBy.split(" ");
if (order.length != 2) {
throw new ValidationException("invalid orderBy");
}
if ("asc".equals(order[1])) {
sort = Sort.by(order[0], Sort.Direction.Ascending);
} else {
sort = Sort.by(order[0], Sort.Direction.Descending);
}
}
List<Pair<String, Object>> conditions = new ArrayList<>();
if (search != null && !search.isEmpty()) {
var basicQuery = new BasicQuery(search, Arrays.asList("name", "status"));
conditions.add(Pair.of(basicQuery.getColumn(), basicQuery.getArgument()));
}
// list only registries from your organization or the ones the user owns
if (isResolvable(securityIdentity)) {
final AccountInfo accountInfo = authService.extractAccountInfo();
String orgId = accountInfo.getOrganizationId();
if (orgId != null) {
conditions.add(Pair.of("orgId", orgId));
} else {
conditions.add(Pair.of("ownerId", accountInfo.getAccountId()));
}
} else {
conditions.add(Pair.of("ownerId", OWNER_ID_PLACEHOLDER));
}
var query = new SearchQuery(conditions);
PanacheQuery<RegistryData> itemsQuery = storage.executeRegistrySearchQuery(query, sort);
var items = itemsQuery.page(Page.of(page - 1, size)).stream().map(convertRegistry::convert).collect(Collectors.toList());
return RegistryListDto.builder().items(items).page(page).size(size).total(itemsQuery.count()).build();
}
Aggregations