use of com.google.startupos.tools.reviewer.RegistryProtos.ReviewerRegistry in project startup-os by google.
the class ReviewerMetadataUpdaterTask method run.
@Override
public void run() {
if (lock.tryLock()) {
try {
GitRepo repo = gitRepoFactory.create(REPO_DIRECTORY);
if (fileUtils.folderEmptyOrNotExists(REPO_DIRECTORY)) {
repo.cloneRepo(repoUrl.get(), REPO_DIRECTORY);
} else {
repo.pull();
}
String globalRegistryFilePath = fileUtils.joinToAbsolutePath(REPO_DIRECTORY, GLOBAL_REGISTRY_FILE);
String newChecksum = md5ForFile(globalRegistryFilePath);
ReviewerRegistry registry = (ReviewerRegistry) fileUtils.readPrototxtUnchecked(globalRegistryFilePath, ReviewerRegistry.newBuilder());
if (!newChecksum.equals(registryChecksum)) {
if (firstRun) {
log.atInfo().log("Storing on first run, checksum: %s", newChecksum);
} else {
log.atInfo().log("New checksum not equal to stored one: new %s, stored %s", newChecksum, registryChecksum);
}
uploadReviewerRegistryToFirestore(registry);
registryChecksum = newChecksum;
} else {
log.atInfo().log("Checksum equals to stored one: %s,", registryChecksum);
}
String repoRegistryFilePath = fileUtils.joinToAbsolutePath(REPO_DIRECTORY, REPO_REGISTRY_FILE);
String newConfigChecksum = md5ForFile(repoRegistryFilePath);
ReviewerConfig config = (ReviewerConfig) fileUtils.readPrototxtUnchecked(repoRegistryFilePath, ReviewerConfig.newBuilder());
if (!newConfigChecksum.equals(configChecksum)) {
if (firstRun) {
log.atInfo().log("Storing in first run, configChecksum: %s", newConfigChecksum);
} else {
log.atInfo().log("New configChecksum not equal to stored one: new %s, stored %s", newConfigChecksum, configChecksum);
}
uploadReviewerConfigToFirestore(config);
configChecksum = newConfigChecksum;
} else {
log.atInfo().log("New ConfigChecksum is equal to stored one: %s,", configChecksum);
}
firstRun = false;
} catch (IOException exception) {
exception.printStackTrace();
} finally {
lock.unlock();
}
}
}
use of com.google.startupos.tools.reviewer.RegistryProtos.ReviewerRegistry in project startup-os by google.
the class InitCommand method run.
public boolean run(String basePath, String startuposRepo) {
if (basePath.isEmpty()) {
throw new IllegalArgumentException("--base_path must be set");
}
try {
if (!fileUtils.folderEmptyOrNotExists(basePath)) {
System.out.println("Base folder exists and is not empty");
return false;
}
baseFolderExistedBefore = fileUtils.folderExists(basePath);
// Create folders
fileUtils.mkdirs(fileUtils.joinToAbsolutePath(basePath, "head"));
fileUtils.mkdirs(fileUtils.joinToAbsolutePath(basePath, "ws"));
fileUtils.mkdirs(fileUtils.joinToAbsolutePath(basePath, "local"));
fileUtils.mkdirs(fileUtils.joinToAbsolutePath(basePath, "logs"));
// Write BASE file
fileUtils.writeString("", fileUtils.joinToAbsolutePath(basePath, BASE_FILENAME));
if (!startuposRepo.isEmpty()) {
// Clone StartupOS repo into head:
cloneRepoIntoHead("startup-os", startuposRepo);
try {
ReviewerRegistry registry = (ReviewerRegistry) fileUtils.readPrototxt(fileUtils.joinToAbsolutePath(getRepoPath("startup-os"), GLOBAL_REGISTRY_CONFIG), ReviewerRegistry.newBuilder());
for (ReviewerRegistryConfig config : registry.getReviewerConfigList()) {
// should not clone StartupOS twice
if (!config.getConfigRepo().equals(startuposRepo)) {
cloneRepoIntoHead(config.getId(), config.getConfigRepo());
}
}
} catch (IOException e) {
System.err.println("Error: Did not find global registry config");
}
} else {
System.out.println("Warning: StartupOS repo url is empty. Cloning skipped.");
}
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
System.out.println("Input flags:");
Flags.printUsage();
revertChanges();
return false;
} catch (Exception e) {
revertChanges();
e.printStackTrace();
}
return true;
}
Aggregations