Skip to content
Snippets Groups Projects

Draft: WIP

Files

package at.ac.tuwien.ifs.dbrepo;
import at.ac.tuwien.ifs.dbrepo.core.api.database.DatabaseBriefDto;
import at.ac.tuwien.ifs.dbrepo.core.api.database.DatabaseDto;
import at.ac.tuwien.ifs.dbrepo.core.api.database.ViewDto;
import at.ac.tuwien.ifs.dbrepo.core.api.database.table.TableDto;
import at.ac.tuwien.ifs.dbrepo.core.exception.*;
import at.ac.tuwien.ifs.dbrepo.gateway.MetadataServiceGateway;
import at.ac.tuwien.ifs.dbrepo.service.CacheService;
import at.ac.tuwien.ifs.dbrepo.service.ContainerService;
import at.ac.tuwien.ifs.dbrepo.service.DatabaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import java.sql.SQLException;
import java.util.List;
@Slf4j
@EnableScheduling
@SpringBootApplication
public class DataServiceApplication {
public class DataServiceApplication implements CommandLineRunner {
private final CacheService cacheService;
private final DatabaseService databaseService;
private final ContainerService containerService;
private final ApplicationContext applicationContext;
private final MetadataServiceGateway metadataServiceGateway;
@Autowired
public DataServiceApplication(CacheService cacheService, DatabaseService databaseService,
ContainerService containerService, ApplicationContext applicationContext,
MetadataServiceGateway metadataServiceGateway) {
this.cacheService = cacheService;
this.databaseService = databaseService;
this.containerService = containerService;
this.applicationContext = applicationContext;
this.metadataServiceGateway = metadataServiceGateway;
}
public static void main(String[] args) {
SpringApplication.run(DataServiceApplication.class, args);
}
@Override
public void run(String... args) throws MetadataServiceException, RemoteUnavailableException, SQLException,
DatabaseNotFoundException, QueryStoreCreateException, TableNotFoundException, DatabaseMalformedException,
ViewNotFoundException {
if (args.length == 0) {
return;
}
for (DatabaseBriefDto d : metadataServiceGateway.getDatabases()) {
final DatabaseDto database = cacheService.getDatabase(d.getId());
containerService.createQueryStore(database.getContainer(), database.getInternalName());
final List<TableDto> tables = databaseService.exploreTables(database);
if (database.getTables().size() != tables.size()) {
final List<TableDto> missingTables = tables.stream()
.filter(table -> database.getTables()
.stream()
.noneMatch(t -> table.getInternalName().equals(t.getInternalName())))
.toList();
if (!missingTables.isEmpty()) {
log.warn("Failed to obtain metadata on table(s): {}", missingTables);
metadataServiceGateway.updateTableSchemas(d.getId());
}
}
final List<ViewDto> views = databaseService.exploreViews(database);
if (database.getViews().size() != views.size()) {
final List<ViewDto> missingViews = views.stream()
.filter(view -> database.getTables()
.stream()
.noneMatch(v -> view.getInternalName().equals(v.getInternalName())))
.toList();
if (!missingViews.isEmpty()) {
log.warn("Failed to obtain metadata on view(s): {}", missingViews);
metadataServiceGateway.updateViewSchemas(d.getId());
}
}
}
log.info("Finished initialization");
SpringApplication.exit(applicationContext, () -> 0);
}
}
Loading