forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSystemTemplateMetadata.java
More file actions
89 lines (71 loc) · 2.82 KB
/
SystemTemplateMetadata.java
File metadata and controls
89 lines (71 loc) · 2.82 KB
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
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.cluster.applicationtemplates;
import org.opensearch.common.annotation.ExperimentalApi;
import java.util.Objects;
/**
* Metadata information about a template available in a template repository.
*/
@ExperimentalApi
public class SystemTemplateMetadata {
private final long version;
private final String type;
private final String name;
private static final String DELIMITER = "@";
public static final String COMPONENT_TEMPLATE_TYPE = "@abc_template";
public SystemTemplateMetadata(long version, String type, String name) {
this.version = version;
this.type = type;
this.name = name;
}
public String type() {
return type;
}
public String name() {
return name;
}
public long version() {
return version;
}
/**
* Gets the metadata using fully qualified name for the template
* @param fullyQualifiedName (e.g. @abc_template@logs@1)
* @return Metadata object based on name
*/
public static SystemTemplateMetadata fromComponentTemplate(String fullyQualifiedName) {
assert fullyQualifiedName.length() > DELIMITER.length() * 3 + 2 + COMPONENT_TEMPLATE_TYPE.length()
: "System template name must have all defined components";
assert (DELIMITER + fullyQualifiedName.substring(1, fullyQualifiedName.indexOf(DELIMITER, 1))).equals(COMPONENT_TEMPLATE_TYPE);
return new SystemTemplateMetadata(
Long.parseLong(fullyQualifiedName.substring(fullyQualifiedName.lastIndexOf(DELIMITER) + 1)),
COMPONENT_TEMPLATE_TYPE,
fullyQualifiedName.substring(fullyQualifiedName.indexOf(DELIMITER, 2) + 1, fullyQualifiedName.lastIndexOf(DELIMITER))
);
}
public static SystemTemplateMetadata fromComponentTemplateInfo(String name, long version) {
return new SystemTemplateMetadata(version, COMPONENT_TEMPLATE_TYPE, name);
}
public final String fullyQualifiedName() {
return type + DELIMITER + name + DELIMITER + version;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SystemTemplateMetadata that = (SystemTemplateMetadata) o;
return version == that.version && Objects.equals(type, that.type) && Objects.equals(name, that.name);
}
@Override
public int hashCode() {
return Objects.hash(version, type, name);
}
@Override
public String toString() {
return "SystemTemplateMetadata{" + "version=" + version + ", type='" + type + '\'' + ", name='" + name + '\'' + '}';
}
}