diff options
author | ralph isenmann | 2021-10-28 14:41:32 +0200 |
---|---|---|
committer | ralph isenmann | 2021-10-28 14:41:32 +0200 |
commit | a26f7c31d5a7e5ce01959a841d518d64a16b79a0 (patch) | |
tree | d34664e6a8c733cafe5b4ff984827ccac326070f | |
parent | [virtualization.container] add mount_type to ContainerBindMount model (diff) | |
parent | [container] refactoring (diff) | |
download | master-sync-shared-a26f7c31d5a7e5ce01959a841d518d64a16b79a0.tar.gz master-sync-shared-a26f7c31d5a7e5ce01959a841d518d64a16b79a0.tar.xz master-sync-shared-a26f7c31d5a7e5ce01959a841d518d64a16b79a0.zip |
Merge branch 'master' into feature/docker-data-containerfeature/docker-data-container
4 files changed, 93 insertions, 100 deletions
diff --git a/src/main/java/org/openslx/virtualization/configuration/container/ContainerBuildContextMethod.java b/src/main/java/org/openslx/virtualization/configuration/container/ContainerBuildContextMethod.java deleted file mode 100644 index 760dc61..0000000 --- a/src/main/java/org/openslx/virtualization/configuration/container/ContainerBuildContextMethod.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.openslx.virtualization.configuration.container; - -public enum ContainerBuildContextMethod { - - FILE, GIT_REPOSITORY,IMAGE_REPO; - - public static ContainerBuildContextMethod fromInt(int index) { - return values()[index]; - } -} diff --git a/src/main/java/org/openslx/virtualization/configuration/container/ContainerDefinition.java b/src/main/java/org/openslx/virtualization/configuration/container/ContainerDefinition.java index ef493f9..167a11f 100644 --- a/src/main/java/org/openslx/virtualization/configuration/container/ContainerDefinition.java +++ b/src/main/java/org/openslx/virtualization/configuration/container/ContainerDefinition.java @@ -19,8 +19,8 @@ import java.util.zip.GZIPOutputStream; public class ContainerDefinition { // TODO database needs a refactoring to store container details - // TODO tar.gz of this object is not useful, for smaller dockerfiles it makes the package lager. - + // TODO refatoring: tar.gz of this object is not useful, for smaller dockerfiles it makes the package lager. + // remove the containerRecipe, ContainerMeta holds in build_context the dockerfile. protected static final Logger LOGGER = Logger.getLogger(ContainerDefinition.class); @@ -51,45 +51,6 @@ public class ContainerDefinition { containerMeta = new ContainerMeta(containerDef.getContainerMeta()); } - public String getContainerRecipe() { - return containerRecipe; - } - - public void setContainerRecipe(String containerRecipe) { - this.containerRecipe = containerRecipe; - } - - public void setContainerRecipe(File containerRecipeFile) { - this.containerRecipe = readContainerRecipe(containerRecipeFile); - } - - public void setContainerRecipe(byte[] rawContainerRecipe) { - this.containerRecipe = new String(rawContainerRecipe, StandardCharsets.UTF_8); - } - - public void setContainerMeta(byte[] containerMeta) { - Gson gson = new GsonBuilder().create(); - this.containerMeta = gson.fromJson(new JsonReader( - new InputStreamReader(new ByteArrayInputStream(containerMeta), StandardCharsets.UTF_8)), - ContainerMeta.class); - } - - public ContainerMeta getContainerMeta() { - return containerMeta; - } - -// public VirtualizationConfigurationDocker createVirtualizationConfig() { -// byte[] rawContainerRecipe = toByteBuffer().array(); -// try { -// return new VirtualizationConfigurationDocker(MetaDataCache.getOperatingSystems(), rawContainerRecipe, -// rawContainerRecipe.length); -// } catch (VirtualizationConfigurationException e) { -// e.printStackTrace(); -// LOGGER.error("Could not create ContainerMetaDataDummy"); -// } -// return null; -// } - /** * Utility function to create a {@link ContainerDefinition} object for a byte array downloaded from the server. * @@ -129,6 +90,33 @@ public class ContainerDefinition { return containerDef; } + public String getContainerRecipe() { + return containerRecipe; + } + + public void setContainerRecipe(String containerRecipe) { + this.containerRecipe = containerRecipe; + } + + public void setContainerRecipe(File containerRecipeFile) { + this.containerRecipe = readContainerRecipe(containerRecipeFile); + } + + public void setContainerRecipe(byte[] rawContainerRecipe) { + this.containerRecipe = new String(rawContainerRecipe, StandardCharsets.UTF_8); + } + + public ContainerMeta getContainerMeta() { + return containerMeta; + } + + public void setContainerMeta(byte[] containerMeta) { + Gson gson = new GsonBuilder().create(); + this.containerMeta = gson.fromJson(new JsonReader( + new InputStreamReader(new ByteArrayInputStream(containerMeta), StandardCharsets.UTF_8)), + ContainerMeta.class); + } + /** * Serializes the ContainerMeta and Container Description (e.g. dockerfile) into an tar.gz archive. * @@ -172,7 +160,7 @@ public class ContainerDefinition { // replace windows by unix EOL recipe = rawRecipe.replaceAll("\\r\\n", "\n"); - + bis.close(); } catch (IOException e) { @@ -187,10 +175,7 @@ public class ContainerDefinition { * @param destDir destination directory for containerRecipe and containerMeta. */ public void saveLocal(File destDir) { - writeFile(destDir, containerRecipe, CONTAINER_FILE); - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - writeFile(destDir, gson.toJson(containerMeta), CONTAINER_META_FILE); } private void writeFile(File destDir, String fileContent, String filename) { @@ -206,8 +191,8 @@ public class ContainerDefinition { } } - public ContainerBuildContextMethod getBuildContextMethod() { - return ContainerBuildContextMethod.fromInt(containerMeta.getBuildContextMethod()); + public ContainerImageContext getContainerImageContext() { + return ContainerImageContext.fromInt(containerMeta.getContainerImageContext()); } @Override public boolean equals(Object o) { diff --git a/src/main/java/org/openslx/virtualization/configuration/container/ContainerImageContext.java b/src/main/java/org/openslx/virtualization/configuration/container/ContainerImageContext.java new file mode 100644 index 0000000..f19d419 --- /dev/null +++ b/src/main/java/org/openslx/virtualization/configuration/container/ContainerImageContext.java @@ -0,0 +1,10 @@ +package org.openslx.virtualization.configuration.container; + +public enum ContainerImageContext { + + DOCKERFILE, GIT_REPOSITORY, IMAGE_REPOSITORY, DOCKER_ARCHIVE; + + public static ContainerImageContext fromInt(int index) { + return values()[index]; + } +} diff --git a/src/main/java/org/openslx/virtualization/configuration/container/ContainerMeta.java b/src/main/java/org/openslx/virtualization/configuration/container/ContainerMeta.java index 577a670..4dbf64b 100644 --- a/src/main/java/org/openslx/virtualization/configuration/container/ContainerMeta.java +++ b/src/main/java/org/openslx/virtualization/configuration/container/ContainerMeta.java @@ -5,37 +5,17 @@ import java.util.List; import java.util.Objects; /** - * ContainerMeta is used to store container specific information. - * An object of this class will be serialized with gson to a json file. + * ContainerMeta is used to store container specific information. An object of + * this class will be serialized with gson to a json file. * <p> - * TODO remove build_context_method - * no need to distinguish between methods - * TODO rename build_context_url to build_context + * TODO rename build_context_method to container_image_context, requires update + * in database(json) + * <p> + * TODO rename build_context_url to build_context TODO refactoring build_context + * is either a dockerfile or a git url with a dockerfile. */ public class ContainerMeta { - public enum ContainerImageType implements org.apache.thrift.TEnum { - LECTURE("Lecture"), BATCH("Batch"), DATA("Data"); - - private final String displayLable; - - ContainerImageType(String name) { - this.displayLable = name; - } - - public boolean equalNames(String other) { - return displayLable.equals(other); - } - - @Override public String toString() { - return this.displayLable; - } - - @Override public int getValue() { - return this.ordinal(); - } - } - private int build_context_method; private String image_repo; private String build_context_url; @@ -48,7 +28,7 @@ public class ContainerMeta { public ContainerMeta() { image_repo = ""; - build_context_method = ContainerBuildContextMethod.FILE.ordinal(); + build_context_method = ContainerImageContext.DOCKERFILE.ordinal(); build_context_url = ""; image_name = ""; run_options = ""; @@ -70,11 +50,11 @@ public class ContainerMeta { } - public int getBuildContextMethod() { + public int getContainerImageContext() { return build_context_method; } - public void setBuildContextMethod(int buildContextMethod) { + public void setContainerImageContext(int buildContextMethod) { this.build_context_method = buildContextMethod; } @@ -94,14 +74,14 @@ public class ContainerMeta { this.run_options = run_options; } - public void setRunCommand(String run_command) { - this.run_command = run_command; - } - public String getRunCommand() { return this.run_command; } + public void setRunCommand(String run_command) { + this.run_command = run_command; + } + public String getImageName() { return image_name; } @@ -130,29 +110,57 @@ public class ContainerMeta { if (image_type == null || image_type.length() == 0) return ContainerImageType.LECTURE; - // turn string representation into enum-var 'LECTURE' -> ContainerImageType.LECTURE + // turn string representation into enum-var 'LECTURE' -> + // ContainerImageType.LECTURE return ContainerImageType.valueOf(image_type); } public void setImageType(ContainerImageType image_type) { - // set constant representation of the enum-var e.g. ContainerImageType.LECTURE -> 'LECTURE' + // set constant representation of the enum-var e.g. ContainerImageType.LECTURE + // -> 'LECTURE' this.image_type = image_type.name(); } - @Override public boolean equals(Object o) { + @Override + public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ContainerMeta that = (ContainerMeta) o; - return Objects.equals(build_context_url, that.build_context_url) && Objects.equals(image_name, - that.image_name) && Objects.equals(run_options, that.run_options) && Objects.equals( - run_command, that.run_command) && Objects.equals(bind_mount_config, that.bind_mount_config) + return Objects.equals(build_context_url, that.build_context_url) && Objects.equals(image_name, that.image_name) + && Objects.equals(run_options, that.run_options) && Objects.equals(run_command, that.run_command) + && Objects.equals(bind_mount_config, that.bind_mount_config) && Objects.equals(image_repo, that.image_repo) && Objects.equals(image_type, that.image_type); } - @Override public int hashCode() { - return Objects.hash(build_context_url, image_name, run_options, run_command, bind_mount_config, - image_repo, image_type); + @Override + public int hashCode() { + return Objects.hash(build_context_url, image_name, run_options, run_command, bind_mount_config, image_repo, + image_type); + } + + public enum ContainerImageType implements org.apache.thrift.TEnum { + LECTURE("Lecture"), BATCH("Batch"), DATA("Data"); + + private final String displayLable; + + ContainerImageType(String name) { + this.displayLable = name; + } + + public boolean equalNames(String other) { + return displayLable.equals(other); + } + + @Override + public String toString() { + return this.displayLable; + } + + @Override + public int getValue() { + return this.ordinal(); + } } } |