17
17
import java .util .HashMap ;
18
18
import java .util .Map ;
19
19
20
- /** A Parser utility class to manipulate domain. yaml file */
20
+ /** A Domain CRD utility class to manipulate domain yaml files */
21
21
public class DomainCRD {
22
22
23
23
private final ObjectMapper objectMapper ;
@@ -37,24 +37,24 @@ public static void main(String args[]) throws IOException {
37
37
Map <String , String > cluster = new HashMap ();
38
38
cluster .put ("restartVersion" , "v1.1" );
39
39
crd .addObjectNodeToCluster ("cluster-1" , cluster );
40
- cluster = new HashMap ();
41
- cluster .put ("restartVersion2" , "v1.2" );
42
- crd .addObjectNodeToCluster ("cluster-1" , cluster );
43
40
System .out .println (crd .getYamlTree ());
44
41
45
42
Map <String , String > ms = new HashMap ();
46
43
ms .put ("restartVersion" , "v1.1" );
47
- crd .addObjectNodeToMS ("managedserver-1" , ms );
48
- ms = new HashMap ();
49
44
ms .put ("serverStartPolicy" , "IF_NEEDED" );
50
- crd .addObjectNodeToMS ("managedserver-1" , ms );
51
- ms = new HashMap ();
52
45
ms .put ("serverStartState" , "RUNNING" );
53
46
crd .addObjectNodeToMS ("managedserver-1" , ms );
54
47
55
48
System .out .println (crd .getYamlTree ());
56
49
}
57
50
51
+ /**
52
+ * Constructor to read the yaml file and initialize the root JsonNode with yaml equivalent of JSON
53
+ * tree
54
+ *
55
+ * @param yamlFile - Name of the yaml file containing the Domain CRD
56
+ * @throws IOException
57
+ */
58
58
public DomainCRD (String yamlFile ) throws IOException {
59
59
this .objectMapper = new ObjectMapper ();
60
60
@@ -66,20 +66,23 @@ public DomainCRD(String yamlFile) throws IOException {
66
66
this .root = objectMapper .readTree (writeValueAsString );
67
67
}
68
68
69
+ /**
70
+ * To convert the JSON tree back into Yaml and return it as a String
71
+ *
72
+ * @return - Domain CRD in Yaml format
73
+ * @throws JsonProcessingException when JSON tree cannot be converted as a Yaml string
74
+ */
69
75
public String getYamlTree () throws JsonProcessingException {
70
76
String jsonAsYaml = new YAMLMapper ().writerWithDefaultPrettyPrinter ().writeValueAsString (root );
71
77
return jsonAsYaml ;
72
78
}
73
79
74
80
/**
75
- * A utility method to add restartVersion attribute to domain in domain.yaml
81
+ * A utility method to add attributes to domain in domain.yaml
76
82
*
77
- * @param key Object key to add as a String
78
- * @param value Version value for the restartVersion attribute
79
- * @return Yaml String with added restartVersion attribute in domain
80
- * @throws IOException
83
+ * @param attributes - A HashMap of key value pairs
81
84
*/
82
- public void addObjectNodeToDomain (Map <String , String > attributes ) throws IOException {
85
+ public void addObjectNodeToDomain (Map <String , String > attributes ) {
83
86
// modify admin server restartVersion
84
87
JsonNode specNode = getSpecNode ();
85
88
for (Map .Entry <String , String > entry : attributes .entrySet ()) {
@@ -88,74 +91,56 @@ public void addObjectNodeToDomain(Map<String, String> attributes) throws IOExcep
88
91
}
89
92
90
93
/**
91
- * A utility method to add restartVersion attribute to administration server in domain.yaml
94
+ * A utility method to add attributes to adminServer node in domain.yaml
92
95
*
93
- * @param key Object key to add as a String
94
- * @param value Version value for the restartVersion attribute
95
- * @return Yaml String with added restartVersion attribute in administration server
96
- * @throws IOException
96
+ * @param attributes - A HashMap of key value pairs
97
97
*/
98
- public void addObjectNodeToAdminServer (Map <String , String > attributes ) throws IOException {
99
- // modify admin server restartVersion
100
- JsonNode adminServerNode = getAdminServerNode (root );
98
+ public void addObjectNodeToAdminServer (Map <String , String > attributes ) {
99
+
100
+ JsonNode adminServerNode = getAdminServerNode ();
101
101
for (Map .Entry <String , String > entry : attributes .entrySet ()) {
102
102
((ObjectNode ) adminServerNode ).put (entry .getKey (), entry .getValue ());
103
103
}
104
104
}
105
105
106
106
/**
107
- * A utility method to add restartVersion attribute to cluster in domain.yaml
107
+ * A utility method to add attributes to cluster node in domain.yaml
108
108
*
109
- * @param domainCRD String representation of the domain.yaml as JSON tree
110
- * @param ClusterName Name of the cluster in which to add the restartVersion attribute
111
- * @param version Version value for the restartVersion attribute
112
- * @return Yaml String with added restartVersion attribute in cluster
113
- * @throws IOException when the JSON tree cannot be read
109
+ * @param ClusterName - Name of the cluster to which the attributes to be added
110
+ * @param attributes - A HashMap of key value pairs
114
111
*/
115
- public void addObjectNodeToCluster (String ClusterName , Map <String , String > attributes )
116
- throws IOException {
117
- // modify cluster restartVersion
112
+ public void addObjectNodeToCluster (String ClusterName , Map <String , String > attributes ) {
113
+
118
114
JsonNode clusterNode = getClusterNode (ClusterName );
119
115
for (Map .Entry <String , String > entry : attributes .entrySet ()) {
120
116
((ObjectNode ) clusterNode ).put (entry .getKey (), entry .getValue ());
121
117
}
122
118
}
123
119
124
120
/**
125
- * A utility method to add restartVersion attribute to managed server in domain.yaml
121
+ * A utility method to add attributes to managed server node in domain.yaml
126
122
*
127
- * @param domainCRD domainCRD String representation of the domain.yaml as JSON tree
128
- * @param managedServerName Name of the managed server in which to add the restartVersion
129
- * attribute
130
- * @param version Version value for the restartVersion attribute
131
- * @return Yaml String with added restartVersion attribute in managed server
132
- * @throws IOException when the JSON tree cannot be read
123
+ * @param managedServerName - Name of the managed server to which the attributes to be added
124
+ * @param attributes - A HashMap of key value pairs
133
125
*/
134
- public void addObjectNodeToMS (String managedServerName , Map <String , String > attributes )
135
- throws IOException {
126
+ public void addObjectNodeToMS (String managedServerName , Map <String , String > attributes ) {
136
127
JsonNode managedServerNode = getManagedServerNode (managedServerName );
137
128
for (Map .Entry <String , String > entry : attributes .entrySet ()) {
138
129
((ObjectNode ) managedServerNode ).put (entry .getKey (), entry .getValue ());
139
130
}
140
131
}
141
132
142
- /**
143
- * Gets the spec node entry from Domain CRD JSON tree
144
- *
145
- * @param root - Root JSON node of the Domain CRD JSON tree
146
- * @return - spec node entry from Domain CRD JSON tree
147
- */
133
+ /** Gets the spec node entry from Domain CRD JSON tree */
148
134
private JsonNode getSpecNode () {
149
135
return root .path ("spec" );
150
136
}
151
137
152
138
/**
153
139
* Gets the administration server node entry from Domain CRD JSON tree
154
140
*
155
- * @param root - Root JSON node of the Domain CRD JSON tree
156
- * @return - administration server node entry from Domain CRD JSON tree
141
+ * @return
157
142
*/
158
- private JsonNode getAdminServerNode (JsonNode root ) {
143
+ private JsonNode getAdminServerNode () {
159
144
return root .path ("spec" ).path ("adminServer" );
160
145
}
161
146
@@ -166,6 +151,12 @@ private JsonNode getAdminServerNode(JsonNode root) {
166
151
* @param clusterName - Name of the cluster
167
152
* @return - cluster node entry from Domain CRD JSON tree
168
153
*/
154
+ /**
155
+ * Gets the cluster node entry from Domain CRD JSON tree for the given cluster name
156
+ *
157
+ * @param clusterName - Name of the cluster
158
+ * @return - JsonNode of named cluster
159
+ */
169
160
private JsonNode getClusterNode (String clusterName ) {
170
161
ArrayNode clusters = (ArrayNode ) root .path ("spec" ).path ("clusters" );
171
162
JsonNode clusterNode = null ;
@@ -181,10 +172,8 @@ private JsonNode getClusterNode(String clusterName) {
181
172
/**
182
173
* Gets the managed server node entry from Domain CRD JSON tree
183
174
*
184
- * @param objectMapper - Instance of the ObjectMapper to use for creating a missing node
185
- * @param root - Root JSON node of the Domain CRD JSON tree
186
- * @param managedServerName - Name of the managed server for which to get the JSON node
187
- * @return administration server node entry from Domain CRD JSON tree
175
+ * @param managedServerName Name of the managed server for which to get the JSON node
176
+ * @return managed server node entry from Domain CRD JSON tree
188
177
*/
189
178
private JsonNode getManagedServerNode (String managedServerName ) {
190
179
ArrayNode managedservers = null ;
0 commit comments