Skip to content

Commit

Permalink
[TH2-1105] Introduced New Resource Types
Browse files Browse the repository at this point in the history
  • Loading branch information
georgiano authored Nov 27, 2020
1 parent cbed25b commit 7ec2d10
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
release_version = 0.8.5
release_version = 0.8.6
13 changes: 7 additions & 6 deletions src/main/java/com/exactpro/th2/inframgr/models/ResourceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand All @@ -69,11 +70,11 @@ public boolean isK8sResource() {
}

private static final Map<String, ResourceType> kinds = new HashMap<>();
private static final Map<String, ResourceType> pathes = new HashMap<>();
private static final Map<String, ResourceType> paths = new HashMap<>();
static {
for (ResourceType t : ResourceType.values()) {
kinds.put(t.kind(), t);
pathes.put(t.path(), t);
paths.put(t.path(), t);
}
}
}
17 changes: 12 additions & 5 deletions src/main/java/com/exactpro/th2/inframgr/repository/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ private static Set<ResourceEntry> loadBranchYMLFiles(File repositoryRoot) throws
Logger logger = LoggerFactory.getLogger(Repository.class);

Set<ResourceEntry> resources = new HashSet<>();
Set<String> 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;
}

Expand All @@ -72,25 +73,31 @@ private static Set<ResourceEntry> 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);
}
}
}
}
return resources;
}


private static File getFile(Config.GitConfig config, String branch, ResourceEntry entry) {

File file = new File (
Expand Down

0 comments on commit 7ec2d10

Please sign in to comment.