summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorralph isenmann2021-10-15 15:11:44 +0200
committerralph isenmann2021-10-15 15:11:44 +0200
commitc8ab09d70ed59123605ae9c007a29c6818168d43 (patch)
treeb33805cbc1a3d998800dcfdc5c2e55baf9ad7652
parent[virtualizer] Get rid of Generics for VirtualizationConfiguration (diff)
downloadmaster-sync-shared-c8ab09d70ed59123605ae9c007a29c6818168d43.tar.gz
master-sync-shared-c8ab09d70ed59123605ae9c007a29c6818168d43.tar.xz
master-sync-shared-c8ab09d70ed59123605ae9c007a29c6818168d43.zip
[container] Add ContainerBuildContextMehtod, refactoring
- add docker-tar - only persist dockerfile and not the internals.
-rw-r--r--src/main/java/org/openslx/virtualization/configuration/container/ContainerBuildContextMethod.java2
-rw-r--r--src/main/java/org/openslx/virtualization/configuration/container/ContainerDefinition.java72
2 files changed, 29 insertions, 45 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
index 760dc61..72b6c4c 100644
--- a/src/main/java/org/openslx/virtualization/configuration/container/ContainerBuildContextMethod.java
+++ b/src/main/java/org/openslx/virtualization/configuration/container/ContainerBuildContextMethod.java
@@ -2,7 +2,7 @@ package org.openslx.virtualization.configuration.container;
public enum ContainerBuildContextMethod {
- FILE, GIT_REPOSITORY,IMAGE_REPO;
+ FILE, GIT_REPOSITORY, IMAGE_REPO, DOCKER_TAR;
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..0ca629d 100644
--- a/src/main/java/org/openslx/virtualization/configuration/container/ContainerDefinition.java
+++ b/src/main/java/org/openslx/virtualization/configuration/container/ContainerDefinition.java
@@ -21,7 +21,6 @@ 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.
-
protected static final Logger LOGGER = Logger.getLogger(ContainerDefinition.class);
protected static final String CONTAINER_FILE = "dockerfile";
@@ -51,45 +50,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 +89,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 +159,7 @@ public class ContainerDefinition {
// replace windows by unix EOL
recipe = rawRecipe.replaceAll("\\r\\n", "\n");
-
+
bis.close();
} catch (IOException e) {
@@ -187,10 +174,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) {