-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial implementation of ResourceManager (#17)
* Add initial implementation of ResourceManager Signed-off-by: David Kornel <[email protected]>
- Loading branch information
Showing
34 changed files
with
1,153 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,9 @@ target/ | |
*.iml | ||
|
||
### Mac OS ### | ||
**.DS_Store | ||
**.DS_Store | ||
|
||
## Frame specific files | ||
**/*.kubeconfig | ||
*.env | ||
config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
test-frame-common/src/main/java/io/skodjob/testframe/LoggerUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Skodjob authors. | ||
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). | ||
*/ | ||
package io.skodjob.testframe; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Collections; | ||
|
||
public class LoggerUtils { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(LoggerUtils.class); | ||
static final String SEPARATOR_CHAR = "#"; | ||
|
||
public static final String RESOURCE_LOGGER_PATTERN = "{} {}/{}"; | ||
public static final String RESOURCE_WITH_NAMESPACE_LOGGER_PATTERN = "{} {}/{} in {}"; | ||
|
||
public static void logSeparator() { | ||
logSeparator(SEPARATOR_CHAR, 76); | ||
} | ||
|
||
public static void logSeparator(String delimiterChar, int length) { | ||
LOGGER.info(String.join("", Collections.nCopies(length, delimiterChar))); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
test-frame-common/src/main/java/io/skodjob/testframe/TestFrameConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.skodjob.testframe; | ||
|
||
import java.time.Duration; | ||
|
||
public class TestFrameConstants { | ||
private TestFrameConstants() { | ||
} | ||
public static final long GLOBAL_POLL_INTERVAL_LONG = Duration.ofSeconds(15).toMillis(); | ||
public static final long GLOBAL_POLL_INTERVAL_MEDIUM = Duration.ofSeconds(10).toMillis(); | ||
public static final long GLOBAL_POLL_INTERVAL_SHORT = Duration.ofSeconds(5).toMillis(); | ||
public static final long GLOBAL_POLL_INTERVAL_1_SEC = Duration.ofSeconds(1).toMillis(); | ||
public static final long GLOBAL_TIMEOUT = Duration.ofMinutes(10).toMillis(); | ||
public static final String OPENSHIFT_CLIENT = "oc"; | ||
public static final String KUBERNETES_CLIENT = "kubectl"; | ||
|
||
} |
97 changes: 97 additions & 0 deletions
97
test-frame-common/src/main/java/io/skodjob/testframe/TestFrameEnv.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright Skodjob authors. | ||
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). | ||
*/ | ||
package io.skodjob.testframe; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.yaml.snakeyaml.Yaml; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.nio.file.Paths; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Class which holds environment variables for system tests. | ||
*/ | ||
public class TestFrameEnv { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(TestFrameEnv.class); | ||
private static final Map<String, String> VALUES = new HashMap<>(); | ||
private static final Map<String, Object> YAML_DATA = loadConfigurationFile(); | ||
public static final String USER_PATH = System.getProperty("user.dir"); | ||
|
||
private static final String CONFIG_FILE_PATH_ENV = "ENV_FILE"; | ||
private static final String CLIENT_TYPE_ENV = "CLIENT_TYPE"; | ||
private static final String USERNAME_ENV = "KUBE_USERNAME"; | ||
private static final String PASSWORD_ENV = "KUBE_PASSWORD"; | ||
private static final String TOKEN_ENV = "KUBE_TOKEN"; | ||
private static final String URL_ENV = "KUBE_URL"; | ||
|
||
/** | ||
* Set values | ||
*/ | ||
public static final String CLIENT_TYPE = getOrDefault(CLIENT_TYPE_ENV, TestFrameConstants.KUBERNETES_CLIENT); | ||
public static final String KUBE_USERNAME = getOrDefault(USERNAME_ENV, null); | ||
public static final String KUBE_PASSWORD = getOrDefault(PASSWORD_ENV, null); | ||
public static final String KUBE_TOKEN = getOrDefault(TOKEN_ENV, null); | ||
public static final String KUBE_URL = getOrDefault(URL_ENV, null); | ||
|
||
private TestFrameEnv() { | ||
} | ||
|
||
static { | ||
String debugFormat = "{}: {}"; | ||
LoggerUtils.logSeparator("-", 30); | ||
LOGGER.info("Used environment variables:"); | ||
VALUES.entrySet().stream() | ||
.sorted(Map.Entry.comparingByKey()) | ||
.forEach(entry -> { | ||
if (!Objects.equals(entry.getValue(), "null")) { | ||
LOGGER.info(debugFormat, entry.getKey(), entry.getValue()); | ||
} | ||
}); | ||
LoggerUtils.logSeparator("-", 30); | ||
} | ||
|
||
public static void print() { | ||
} | ||
|
||
private static String getOrDefault(String varName, String defaultValue) { | ||
return getOrDefault(varName, String::toString, defaultValue); | ||
} | ||
|
||
private static <T> T getOrDefault(String var, Function<String, T> converter, T defaultValue) { | ||
String value = System.getenv(var) != null ? | ||
System.getenv(var) : | ||
(Objects.requireNonNull(YAML_DATA).get(var) != null ? | ||
YAML_DATA.get(var).toString() : | ||
null); | ||
T returnValue = defaultValue; | ||
if (value != null) { | ||
returnValue = converter.apply(value); | ||
} | ||
VALUES.put(var, String.valueOf(returnValue)); | ||
return returnValue; | ||
} | ||
|
||
private static Map<String, Object> loadConfigurationFile() { | ||
String config = System.getenv().getOrDefault(CONFIG_FILE_PATH_ENV, | ||
Paths.get(System.getProperty("user.dir"), "config.yaml").toAbsolutePath().toString()); | ||
Yaml yaml = new Yaml(); | ||
try { | ||
File yamlFile = new File(config).getAbsoluteFile(); | ||
return yaml.load(new FileInputStream(yamlFile)); | ||
} catch (IOException ex) { | ||
LOGGER.info("Yaml configuration not provider or not exists"); | ||
return Collections.emptyMap(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.