summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/virtualization/configuration/container/ContainerMeta.java
blob: 577a6703b99a3a5758efc31df5190a5de6cf4c71 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package org.openslx.virtualization.configuration.container;

import java.util.ArrayList;
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.
 * <p>
 * TODO remove build_context_method
 * no need to distinguish between methods
 * TODO rename build_context_url to build_context
 */
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;
	private String image_name;
	private String run_options;
	private String run_command;
	private String image_type;
	private List<ContainerBindMount> bind_mount_config = new ArrayList<>();

	public ContainerMeta() {

		image_repo = "";
		build_context_method = ContainerBuildContextMethod.FILE.ordinal();
		build_context_url = "";
		image_name = "";
		run_options = "";
		run_command = "";
		image_type = ContainerImageType.LECTURE.toString();
		bind_mount_config = new ArrayList<>();
	}

	public ContainerMeta(ContainerMeta containerMeta) {
		build_context_method = containerMeta.build_context_method;
		build_context_url = containerMeta.build_context_url;
		image_name = containerMeta.image_name;
		run_options = containerMeta.run_options;
		run_command = containerMeta.run_command;
		image_repo = containerMeta.image_repo;

		for (ContainerBindMount bm : containerMeta.bind_mount_config)
			bind_mount_config.add(new ContainerBindMount(bm.getSource(), bm.getTarget(), bm.getOptions()));

	}

	public int getBuildContextMethod() {
		return build_context_method;
	}

	public void setBuildContextMethod(int buildContextMethod) {
		this.build_context_method = buildContextMethod;
	}

	public String getBuildContextUrl() {
		return build_context_url;
	}

	public void setBuildContextUrl(String buildContextUrl) {
		this.build_context_url = buildContextUrl;
	}

	public String getRunOptions() {
		return run_options;
	}

	public void setRunOptions(String run_options) {
		this.run_options = run_options;
	}

	public void setRunCommand(String run_command) {
		this.run_command = run_command;
	}

	public String getRunCommand() {
		return this.run_command;
	}

	public String getImageName() {
		return image_name;
	}

	public void setImageName(String image_name) {
		this.image_name = image_name;
	}

	public List<ContainerBindMount> getBindMountConfig() {
		return bind_mount_config;
	}

	public void setBindMountConfig(List<ContainerBindMount> bindMountConfig) {
		this.bind_mount_config = bindMountConfig;
	}

	public String getImageRepo() {
		return image_repo;
	}

	public void setImageRepo(String from_image) {
		this.image_repo = from_image;
	}

	public ContainerImageType getImageType() {
		if (image_type == null || image_type.length() == 0)
			return 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'
		this.image_type = image_type.name();
	}

	@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)
				&& 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);
	}
}