From 7ec2d1053338dcfcd472367f1522e50c26762927 Mon Sep 17 00:00:00 2001 From: georgiano <15014186+georgiano@users.noreply.github.com> Date: Fri, 27 Nov 2020 14:15:07 +0400 Subject: [PATCH] [TH2-1105] Introduced New Resource Types --- .gitlab-ci.yml | 2 +- gradle.properties | 2 +- .../th2/inframgr/models/ResourceType.java | 13 +++++++------ .../th2/inframgr/repository/Repository.java | 17 ++++++++++++----- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6a74574e..119b9c06 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ variables: APP_NAME: "th2-infra-mgr" MAJOR_VERSION: "0" MINOR_VERSION: "8" - MAINTENANCE_VERSION: "5" + MAINTENANCE_VERSION: "6" DOCKER_PUBLISH_ENABLED: "true" include: diff --git a/gradle.properties b/gradle.properties index ba59dd3b..00d93e71 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -release_version = 0.8.5 \ No newline at end of file +release_version = 0.8.6 \ No newline at end of file diff --git a/src/main/java/com/exactpro/th2/inframgr/models/ResourceType.java b/src/main/java/com/exactpro/th2/inframgr/models/ResourceType.java index 39217497..536e18e5 100644 --- a/src/main/java/com/exactpro/th2/inframgr/models/ResourceType.java +++ b/src/main/java/com/exactpro/th2/inframgr/models/ResourceType.java @@ -23,9 +23,10 @@ public enum ResourceType { Th2Link("Th2Link", "links", "th2links", "th2.exactpro.com/v1"), Th2Dictionary("Th2Dictionary", "dictionaries", "th2dictionaries", "th2.exactpro.com/v1"), - Th2Mstore("Th2Mstore", "mstores", "th2mstores", "th2.exactpro.com/v1"), - Th2Estore("Th2Estore", "estores", "th2estores", "th2.exactpro.com/v1"), - Th2Generic("Th2Generic", "generics", "th2generics", "th2.exactpro.com/v1"), + Th2CoreBox("Th2CoreBox", "core", "th2coreboxes", "th2.exactpro.com/v1"), + Th2Mstore("Th2Mstore", "core", "th2mstores", "th2.exactpro.com/v1"), + Th2Estore("Th2Estore", "core", "th2estores", "th2.exactpro.com/v1"), + Th2Box("Th2Box", "boxes", "th2boxes", "th2.exactpro.com/v1"), SettingsFile("SettingsFile", "", null, null), UIFile("UIFile", "ui-files", null, null); @@ -58,7 +59,7 @@ public static ResourceType forKind(String kind) { } public static ResourceType forPath(String path) { - return pathes.get(path); + return paths.get(path); } public boolean isRepositoryResource() { @@ -69,11 +70,11 @@ public boolean isK8sResource() { } private static final Map kinds = new HashMap<>(); - private static final Map pathes = new HashMap<>(); + private static final Map paths = new HashMap<>(); static { for (ResourceType t : ResourceType.values()) { kinds.put(t.kind(), t); - pathes.put(t.path(), t); + paths.put(t.path(), t); } } } diff --git a/src/main/java/com/exactpro/th2/inframgr/repository/Repository.java b/src/main/java/com/exactpro/th2/inframgr/repository/Repository.java index 8382466e..9a4e91fc 100644 --- a/src/main/java/com/exactpro/th2/inframgr/repository/Repository.java +++ b/src/main/java/com/exactpro/th2/inframgr/repository/Repository.java @@ -57,13 +57,14 @@ private static Set loadBranchYMLFiles(File repositoryRoot) throws Logger logger = LoggerFactory.getLogger(Repository.class); Set resources = new HashSet<>(); + Set keys = new HashSet<>(); for (ResourceType t : ResourceType.values()) if (t.isRepositoryResource()) { File dir = new File(repositoryRoot.getAbsolutePath() + "/" + t.path()); if (dir.exists()) { if (!dir.isDirectory()) { - logger.warn("entry expected to be a directory: {}", dir.getAbsoluteFile()); + logger.warn("entry expected to be a directory: \"{}\"", dir.getAbsoluteFile()); continue; } @@ -72,18 +73,23 @@ private static Set loadBranchYMLFiles(File repositoryRoot) throws if (f.isFile() && (f.getAbsolutePath().endsWith(".yml") || f.getAbsolutePath().endsWith(".yaml"))) { ResourceEntry resourceEntry = Repository.loadYMLFile(f); - if (resourceEntry.getKind() != t) { + if (!extractName(f.getName()).equals(resourceEntry.getName())) { + logger.warn("skipping \"{}\" | resource name does not match filename", f.getAbsolutePath()); + continue; + } + + if (!resourceEntry.getKind().path().equals(t.path())) { logger.warn("skipping \"{}\" | resource is located in wrong directory. kind: {}, dir: {}" , f.getAbsolutePath(), resourceEntry.getKind().kind(), t.path()); continue; } - if (!extractName(f.getName()).equals(resourceEntry.getName())) { - logger.warn("skipping \"{}\" | resource name does not match filename", f.getAbsolutePath()); + String key = resourceEntry.getKind() + "/" + resourceEntry.getName(); + if (keys.contains(key)) continue; - } resources.add(resourceEntry); + keys.add(key); } } } @@ -91,6 +97,7 @@ private static Set loadBranchYMLFiles(File repositoryRoot) throws return resources; } + private static File getFile(Config.GitConfig config, String branch, ResourceEntry entry) { File file = new File (