use of org.bf2.srs.fleetmanager.spi.tenants.model.Tenant in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class NamespaceProvisionerTest method nameIsSanitized.
@Test
void nameIsSanitized() {
//
// Given that no resources associated to the provided deployment exist
//
final ConnectorNamespace namespace = new ConnectorNamespace();
namespace.id(uid());
namespace.name("--eval");
ConnectorNamespaceTenant tenant = new ConnectorNamespaceTenant().id(uid()).kind(ConnectorNamespaceTenantKind.ORGANISATION);
namespace.setStatus(new ConnectorNamespaceStatus1().state(ConnectorNamespaceState.READY).connectorsDeployed(0));
namespace.setTenant(tenant);
namespace.setExpiration(new Date().toString());
final List<ManagedConnector> connectors = List.of();
final List<Secret> secrets = List.of();
final FleetShardClient fleetShard = ConnectorTestSupport.fleetShard(CLUSTER_ID, connectors, secrets);
final FleetManagerClient fleetManager = ConnectorTestSupport.fleetManagerClient();
final FleetShardSyncConfig config = ConnectorTestSupport.config();
final MeterRegistry registry = Mockito.mock(MeterRegistry.class);
final ConnectorNamespaceProvisioner provisioner = new ConnectorNamespaceProvisioner(config, fleetShard, fleetManager, registry);
final ArgumentCaptor<Namespace> nc = ArgumentCaptor.forClass(Namespace.class);
//
// When deployment is applied
//
provisioner.provision(namespace);
verify(fleetShard).createNamespace(nc.capture());
//
// Then resources must be created according to the deployment
//
assertThat(nc.getValue()).satisfies(val -> {
assertThat(val.getMetadata().getLabels()).containsEntry(LABEL_KUBERNETES_NAME, "a--eval");
});
}
use of org.bf2.srs.fleetmanager.spi.tenants.model.Tenant in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class SyncTestSupport method namespace.
public static ConnectorNamespace namespace(String id, String name) {
ConnectorNamespace answer = new ConnectorNamespace().id(id).name(name);
ConnectorNamespaceTenant tenant = new ConnectorNamespaceTenant().id(uid()).kind(ConnectorNamespaceTenantKind.ORGANISATION);
answer.setStatus(new ConnectorNamespaceStatus1().state(ConnectorNamespaceState.READY).connectorsDeployed(0));
answer.setTenant(tenant);
answer.setExpiration(new Date().toString());
return answer;
}
use of org.bf2.srs.fleetmanager.spi.tenants.model.Tenant in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class MigrationService method runMigration.
public void runMigration() throws TenantManagerServiceException {
if (deleteAll.isPresent() && deleteAll.get()) {
log.warn("Removing all data first");
TenantManagerConfig tm = TenantManagerConfig.builder().tenantManagerUrl("http://tenant-manager:8585").registryDeploymentUrl("https://service-registry-stage.apps.app-sre-stage-0.k3s7.p1.openshiftapps.com").build();
for (Tenant t : tenantManagerClient.getAllTenants(tm)) {
log.warn("Deleting tenant '{}'", t.getId());
try {
tenantManagerClient.deleteTenant(tm, t.getId());
} catch (TenantNotFoundServiceException ex) {
log.warn("Could not delete tenant '{}'. Tenant does not exist and may have been already deleted.", t.getId());
}
}
CleanResult cleanResult = flyway.clean();
log.info("Database clean result: " + "flywayVersion = '{}', " + "database = '{}', " + "schemasCleaned = '{}', " + "schemasDropped = '{}', " + "warnings = '{}'.", cleanResult.flywayVersion, cleanResult.database, cleanResult.schemasCleaned, cleanResult.schemasDropped, cleanResult.warnings);
}
MigrateResult migrateResult = flyway.migrate();
log.info("Database migrate result: " + "flywayVersion = '{}', " + "database = '{}', " + "initialSchemaVersion = '{}', " + "targetSchemaVersion = '{}', " + "migrations = '{}', " + "warnings = '{}'.", migrateResult.flywayVersion, migrateResult.database, migrateResult.initialSchemaVersion, migrateResult.targetSchemaVersion, migrateResult.migrations, migrateResult.warnings);
}
use of org.bf2.srs.fleetmanager.spi.tenants.model.Tenant in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class TestInfraManager method runTenantManager.
// TODO replace tenant manager with mock?
private void runTenantManager(boolean authEnabled) throws IOException {
Map<String, String> appEnv = new HashMap<>();
if (authEnabled) {
appEnv.put("AUTH_ENABLED", "true");
appEnv.put("KEYCLOAK_URL", getMandatoryEnvVar(MAS_SSO_URL));
appEnv.put("KEYCLOAK_REALM", getMandatoryEnvVar(MAS_SSO_REALM));
appEnv.put("KEYCLOAK_API_CLIENT_ID", getMandatoryEnvVar(MAS_SSO_CLIENT_ID));
}
String datasourceUrl = deployPostgresql("tenant-manager");
appEnv.put("DATASOURCE_URL", datasourceUrl);
appEnv.put("DATASOURCE_USERNAME", "postgres");
appEnv.put("DATASOURCE_PASSWORD", "postgres");
// registry is not deployed in purpose, it may still work
appEnv.put("REGISTRY_ROUTE_URL", "http://localhost:3888");
appEnv.put("LOG_LEVEL", "DEBUG");
String path = getTenantManagerJarPath();
LOGGER.info("Starting Tenant Manager app from: {}", path);
Exec executor = new Exec();
CompletableFuture.supplyAsync(() -> {
try {
List<String> cmd = new ArrayList<>();
cmd.add("java");
cmd.addAll(Arrays.asList("-jar", path));
int timeout = executor.execute(cmd, appEnv);
return timeout == 0;
} catch (Exception e) {
LOGGER.error("Failed to start tenant manager (could not find runner JAR).", e);
System.exit(1);
return false;
}
}, runnable -> new Thread(runnable).start());
processes.add(new TestInfraProcess() {
@Override
public String getName() {
return "tenant-manager";
}
@Override
public void close() throws Exception {
executor.stop();
}
@Override
public String getStdOut() {
return executor.stdOut();
}
@Override
public String getStdErr() {
return executor.stdErr();
}
@Override
public boolean isContainer() {
return false;
}
});
Awaitility.await("Tenant Manager is reachable").atMost(45, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).until(() -> HttpUtils.isReachable("localhost", 8585, "Tenant Manager"));
Awaitility.await("Tenant Manager is ready").atMost(45, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).until(() -> HttpUtils.isReady(this.tenantManagerUrl, "/q/health/ready", false, "Tenant Manager"));
}
use of org.bf2.srs.fleetmanager.spi.tenants.model.Tenant in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class RestClientTenantManagerServiceImpl method createTenant.
@Timed(value = Constants.TENANT_MANAGER_CREATE_TENANT_TIMER, description = Constants.TENANT_MANAGER_DESCRIPTION)
@Audited
// 3 retries, 200ms jitter
@Retry(retryOn = { TenantManagerServiceException.class })
@Override
public Tenant createTenant(TenantManagerConfig tm, CreateTenantRequest tenantRequest) throws TenantManagerServiceException {
try {
var client = getClient(tm);
NewRegistryTenantRequest req = new NewRegistryTenantRequest();
req.setOrganizationId(tenantRequest.getOrganizationId());
req.setTenantId(tenantRequest.getTenantId());
req.setCreatedBy(tenantRequest.getCreatedBy());
req.setResources(Optional.ofNullable(tenantRequest.getResources()).stream().flatMap(Collection::stream).map(r -> {
TenantResource tr = new TenantResource();
tr.setType(ResourceType.fromValue(r.getType()));
tr.setLimit(r.getLimit());
return tr;
}).collect(Collectors.toList()));
RegistryTenant tenant = client.createTenant(req);
return convert(tenant);
} catch (TenantManagerClientException ex) {
throw ExceptionConvert.convert(ex);
}
}
Aggregations