use of org.bf2.admin.kafka.systemtest.Environment.CONFIG 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.admin.kafka.systemtest.Environment.CONFIG in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class RegistryProvisioningIT method testProvisionRegistry.
@Test
void testProvisionRegistry() {
FleetManagerApi.verifyApiIsSecured();
var alice = new AccountInfo("testProvisionRegistry", "alice", false, 10L);
// verify static deployments config file feature
var deployment = new RegistryDeploymentCreateRest();
deployment.setName("test-deployment");
deployment.setTenantManagerUrl(infra.getTenantManagerUri());
deployment.setRegistryDeploymentUrl("http://registry-test");
FleetManagerApi.verifyCreateDeploymentNotAllowed(deployment, alice);
var registry1 = new RegistryCreate();
registry1.setName("test-registry-1");
var registry1Result = FleetManagerApi.createRegistry(registry1, alice);
assertNotEquals(RegistryStatusValue.failed, registry1Result.getStatus());
Awaitility.await("registry available").atMost(30, TimeUnit.SECONDS).pollInterval(5, TimeUnit.SECONDS).until(() -> {
var reg = FleetManagerApi.getRegistry(registry1Result.getId(), alice);
return reg.getStatus().equals(RegistryStatusValue.ready);
});
Registry registry = FleetManagerApi.getRegistry(registry1Result.getId(), alice);
TenantManagerClient tenantManager = Utils.createTenantManagerClient();
var internalTenant = tenantManager.getTenant(registry.getId());
var resources = internalTenant.getResources();
TenantResource maxTotalSchemas = null;
for (var r : resources) {
if (r.getType() == ResourceType.MAX_TOTAL_SCHEMAS_COUNT) {
maxTotalSchemas = r;
}
}
assertNotNull(maxTotalSchemas);
assertEquals(10, maxTotalSchemas.getLimit());
// TODO e2e test check limits are applied
// Delete
FleetManagerApi.deleteRegistry(registry1Result.getId(), alice);
}
use of org.bf2.admin.kafka.systemtest.Environment.CONFIG in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class ConnectorDeploymentProvisioner method createManagedConnector.
private ManagedConnector createManagedConnector(String uow, ConnectorDeployment deployment, HasMetadata owner) {
ManagedConnector connector = fleetShard.getConnector(deployment).orElseGet(() -> {
LOGGER.info("Connector not found (cluster_id: {}, connector_id: {}, deployment_id: {}, resource_version: {}), creating a new one", fleetShard.getClusterId(), deployment.getSpec().getConnectorId(), deployment.getId(), deployment.getMetadata().getResourceVersion());
return Connectors.newConnector(fleetShard.getClusterId(), deployment.getSpec().getConnectorId(), deployment.getId(), Map.of());
});
// TODO: change APIs to include a single operator
// move operator one level up
// include full operator info in ConnectorDeployment APIs
ArrayNode operatorsMeta = deployment.getSpec().getShardMetadata().withArray("operators");
if (operatorsMeta.size() != 1) {
throw new IllegalArgumentException("Multiple selectors are not yet supported");
}
OperatorSelector operatorSelector = new OperatorSelector(deployment.getSpec().getOperatorId(), operatorsMeta.get(0).requiredAt("/type").asText(), operatorsMeta.get(0).requiredAt("/version").asText());
if (operatorSelector.getId() == null) {
final OperatorSelector currentSelector = connector.getSpec().getOperatorSelector();
// don't select a new operator if previously set.
if (currentSelector != null && currentSelector.getId() != null) {
operatorSelector.setId(currentSelector.getId());
} else {
OperatorSelectorUtil.assign(operatorSelector, fleetShard.lookupOperators()).map(Operator::getId).ifPresent(operatorSelector::setId);
}
}
if (operatorSelector.getId() != null) {
Resources.setLabel(connector, Resources.LABEL_OPERATOR_ASSIGNED, operatorSelector.getId());
}
if (operatorSelector.getType() != null) {
Resources.setLabel(connector, Resources.LABEL_OPERATOR_TYPE, operatorSelector.getType());
}
if (config != null) {
config.connectors().labels().forEach((k, v) -> {
Resources.setLabel(connector, k, v);
});
config.connectors().annotations().forEach((k, v) -> {
Resources.setAnnotation(connector, k, v);
});
}
connector.getMetadata().setOwnerReferences(List.of(new OwnerReferenceBuilder().withApiVersion(owner.getApiVersion()).withKind(owner.getKind()).withName(owner.getMetadata().getName()).withUid(owner.getMetadata().getUid()).withBlockOwnerDeletion(true).build()));
// add resource version to label
Resources.setLabel(connector, Resources.LABEL_DEPLOYMENT_RESOURCE_VERSION, "" + deployment.getMetadata().getResourceVersion());
// add uow
Resources.setLabel(connector, Resources.LABEL_UOW, uow);
connector.getSpec().getDeployment().setDeploymentResourceVersion(deployment.getMetadata().getResourceVersion());
connector.getSpec().getDeployment().setDesiredState(deployment.getSpec().getDesiredState());
connector.getSpec().getDeployment().setConnectorTypeId(deployment.getSpec().getConnectorTypeId());
connector.getSpec().getDeployment().setConnectorResourceVersion(deployment.getSpec().getConnectorResourceVersion());
KafkaConnectionSettings kafkaConnectionSettings = deployment.getSpec().getKafka();
if (kafkaConnectionSettings != null) {
connector.getSpec().getDeployment().setKafka(new KafkaSpecBuilder().withId(kafkaConnectionSettings.getId()).withUrl(kafkaConnectionSettings.getUrl()).build());
}
SchemaRegistryConnectionSettings schemaRegistryConnectionSettings = deployment.getSpec().getSchemaRegistry();
if (schemaRegistryConnectionSettings != null) {
connector.getSpec().getDeployment().setSchemaRegistry(new SchemaRegistrySpecBuilder().withId(schemaRegistryConnectionSettings.getId()).withUrl(schemaRegistryConnectionSettings.getUrl()).build());
}
connector.getSpec().getDeployment().setConnectorResourceVersion(deployment.getSpec().getConnectorResourceVersion());
connector.getSpec().getDeployment().setSecret(Secrets.generateConnectorSecretId(deployment.getId()));
connector.getSpec().getDeployment().setUnitOfWork(uow);
connector.getSpec().setOperatorSelector(operatorSelector);
LOGGER.info("Provisioning connector id={} rv={} - {}/{}: {}", connector.getMetadata().getName(), connector.getSpec().getDeployment().getDeploymentResourceVersion(), fleetShard.getConnectorsNamespace(), connector.getSpec().getConnectorId(), Serialization.asJson(connector.getSpec()));
try {
return fleetShard.createConnector(connector);
} catch (Exception e) {
LOGGER.warn("", e);
throw e;
}
}
Aggregations