[MSO-8] Update the maven dependency
[so.git] / asdc-controller / src / main / java / org / openecomp / mso / asdc / util / ASDCNotificationLogging.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.mso.asdc.util;
22
23
24 import java.util.List;
25 import java.util.Map;
26
27 import org.openecomp.sdc.api.notification.IArtifactInfo;
28 import org.openecomp.sdc.api.notification.INotificationData;
29 import org.openecomp.sdc.api.notification.IResourceInstance;
30
31 import org.openecomp.mso.asdc.installer.IVfModuleData;
32
33 public class ASDCNotificationLogging {
34
35         public static String dumpASDCNotification(INotificationData asdcNotification) {
36
37                 if (asdcNotification == null) {
38                         return "NULL";
39                 }
40                 StringBuffer buffer = new StringBuffer("ASDC Notification:");
41                 buffer.append(System.lineSeparator());
42
43                 buffer.append("DistributionID:");
44                 buffer.append(testNull(asdcNotification.getDistributionID()));
45                 buffer.append(System.lineSeparator());
46
47
48                 buffer.append("ServiceName:");
49                 buffer.append(testNull(asdcNotification.getServiceName()));
50                 buffer.append(System.lineSeparator());
51
52
53                 buffer.append("ServiceVersion:");
54                 buffer.append(testNull(asdcNotification.getServiceVersion()));
55                 buffer.append(System.lineSeparator());
56
57
58                 buffer.append("ServiceUUID:");
59                 buffer.append(testNull(asdcNotification.getServiceUUID()));
60                 buffer.append(System.lineSeparator());
61
62
63                 buffer.append("ServiceInvariantUUID:");
64                 buffer.append(testNull(asdcNotification.getServiceInvariantUUID()));
65                 buffer.append(System.lineSeparator());
66
67
68                 buffer.append("ServiceDescription:");
69                 buffer.append(testNull(asdcNotification.getServiceDescription()));
70                 buffer.append(System.lineSeparator());
71
72
73                 buffer.append("Service Artifacts List:");
74                 buffer.append(System.lineSeparator());
75                 buffer.append(testNull(dumpArtifactInfoList(asdcNotification.getServiceArtifacts())));
76                 buffer.append(System.lineSeparator());
77
78                 buffer.append("Resource Instances List:");
79                 buffer.append(System.lineSeparator());
80                 buffer.append(testNull(dumpASDCResourcesList(asdcNotification)));
81                 buffer.append(System.lineSeparator());
82
83
84                 return buffer.toString();
85         }
86
87         public static String dumpVfModuleMetaDataList(List<IVfModuleData> moduleMetaDataList) {
88                 if (moduleMetaDataList == null ) {
89                         return null;
90                 }
91
92                 StringBuffer buffer = new StringBuffer("VfModuleMetaData List:");
93                 buffer.append(System.lineSeparator());
94
95                 buffer.append("{");
96
97                 for (IVfModuleData moduleMetaData:moduleMetaDataList) {
98                         buffer.append(System.lineSeparator());
99                         buffer.append(testNull(dumpVfModuleMetaData(moduleMetaData)));
100                         buffer.append(System.lineSeparator());
101                         buffer.append(",");
102
103                 }
104                 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
105                 buffer.append("}");
106                 buffer.append(System.lineSeparator());
107
108                 return buffer.toString();
109         }
110
111         private static String dumpVfModuleMetaData(IVfModuleData moduleMetaData) {
112
113                 if (moduleMetaData == null ) {
114                         return "NULL";
115                 }
116
117                 StringBuffer buffer = new StringBuffer("VfModuleMetaData:");
118                 buffer.append(System.lineSeparator());
119
120                 buffer.append("VfModuleModelName:");
121                 buffer.append(testNull(moduleMetaData.getVfModuleModelName()));
122                 buffer.append(System.lineSeparator());
123
124                 buffer.append("VfModuleModelVersion:");
125                 buffer.append(testNull(moduleMetaData.getVfModuleModelVersion()));
126                 buffer.append(System.lineSeparator());
127
128                 buffer.append("VfModuleModelUUID:");
129                 buffer.append(testNull(moduleMetaData.getVfModuleModelUUID()));
130                 buffer.append(System.lineSeparator());
131
132                 buffer.append("VfModuleModelInvariantUUID:");
133                 buffer.append(testNull(moduleMetaData.getVfModuleModelInvariantUUID()));
134                 buffer.append(System.lineSeparator());
135
136                 buffer.append("VfModuleModelDescription:");
137                 buffer.append(testNull(moduleMetaData.getVfModuleModelDescription()));
138                 buffer.append(System.lineSeparator());
139
140                 buffer.append("Artifacts UUID List:");
141
142                 if (moduleMetaData.getArtifacts() != null) {
143                         buffer.append("{");
144
145                         for (String artifactUUID:moduleMetaData.getArtifacts()) {
146                                 buffer.append(System.lineSeparator());
147                                 buffer.append(testNull(artifactUUID));
148                                 buffer.append(System.lineSeparator());
149                                 buffer.append(",");
150                         }
151                         buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
152                         buffer.append("}");
153                         buffer.append(System.lineSeparator());
154                 } else {
155                         buffer.append("NULL");
156                 }
157
158                 if (moduleMetaData.getProperties() != null) {
159                         Map<String, String> vfModuleMap = moduleMetaData.getProperties();
160                         buffer.append("Properties List:");
161                         buffer.append("{");
162
163                         for (Map.Entry<String, String> entry : vfModuleMap.entrySet()) {
164                                 buffer.append(System.lineSeparator());
165                                 buffer.append("  " + entry.getKey() + " : " + entry.getValue());
166                         }
167                         buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
168                         buffer.append("}");
169                         buffer.append(System.lineSeparator());
170                 } else {
171                         buffer.append("NULL");
172                 }
173
174
175                 buffer.append(System.lineSeparator());
176
177                 buffer.append("isBase:");
178                 buffer.append(moduleMetaData.isBase());
179                 buffer.append(System.lineSeparator());
180
181                 return buffer.toString();
182         }
183
184         private static String testNull(Object object) {
185                 if (object == null) {
186                         return "NULL";
187                 } else if (object instanceof Integer) {
188                         return object.toString();
189                 } else if (object instanceof String) {
190                         return (String)object;
191                 } else {
192                         return "Type not recognized";
193                 }
194         }
195
196         private static String dumpASDCResourcesList(INotificationData asdcNotification) {
197                 if (asdcNotification == null || asdcNotification.getResources() == null) {
198                         return null;
199                 }
200
201                 StringBuffer buffer = new StringBuffer();
202                 buffer.append("{");
203
204                 for (IResourceInstance resourceInstanceElem:asdcNotification.getResources()) {
205                         buffer.append(System.lineSeparator());
206                         buffer.append(testNull(dumpASDCResourceInstance(resourceInstanceElem)));
207                         buffer.append(System.lineSeparator());
208                         buffer.append(",");
209                 }
210                 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
211                 buffer.append("}");
212                 buffer.append(System.lineSeparator());
213
214                 return buffer.toString();
215
216         }
217
218         private static String dumpASDCResourceInstance(IResourceInstance resourceInstance) {
219
220                 if (resourceInstance == null) {
221                         return null;
222                 }
223
224                 StringBuffer buffer = new StringBuffer("Resource Instance Info:");
225                 buffer.append(System.lineSeparator());
226
227                 buffer.append("ResourceInstanceName:");
228                 buffer.append(testNull(resourceInstance.getResourceInstanceName()));
229                 buffer.append(System.lineSeparator());
230
231                 buffer.append("ResourceCustomizationUUID:");
232                 buffer.append(testNull(resourceInstance.getResourceCustomizationUUID()));
233                 buffer.append(System.lineSeparator());
234
235                 buffer.append("ResourceInvariantUUID:");
236                 buffer.append(testNull(resourceInstance.getResourceInvariantUUID()));
237                 buffer.append(System.lineSeparator());
238
239                 buffer.append("ResourceName:");
240                 buffer.append(testNull(resourceInstance.getResourceName()));
241                 buffer.append(System.lineSeparator());
242
243                 buffer.append("ResourceType:");
244                 buffer.append(testNull(resourceInstance.getResourceType()));
245                 buffer.append(System.lineSeparator());
246
247                 buffer.append("ResourceUUID:");
248                 buffer.append(testNull(resourceInstance.getResourceUUID()));
249                 buffer.append(System.lineSeparator());
250
251                 buffer.append("ResourceVersion:");
252                 buffer.append(testNull(resourceInstance.getResourceVersion()));
253                 buffer.append(System.lineSeparator());
254
255                 buffer.append("Category:");
256                 buffer.append(testNull(resourceInstance.getCategory()));
257                 buffer.append(System.lineSeparator());
258
259                 buffer.append("SubCategory:");
260                 buffer.append(testNull(resourceInstance.getSubcategory()));
261                 buffer.append(System.lineSeparator());
262
263                 buffer.append("Resource Artifacts List:");
264                 buffer.append(System.lineSeparator());
265                 buffer.append(testNull(dumpArtifactInfoList(resourceInstance.getArtifacts())));
266                 buffer.append(System.lineSeparator());
267
268                 return buffer.toString();
269
270         }
271
272
273         private static String dumpArtifactInfoList(List<IArtifactInfo> artifactsList) {
274
275                 if (artifactsList == null || artifactsList.isEmpty()) {
276                         return null;
277                 }
278
279                 StringBuffer buffer = new StringBuffer();
280                 buffer.append("{");
281                 for (IArtifactInfo artifactInfoElem:artifactsList) {
282                         buffer.append(System.lineSeparator());
283                         buffer.append(testNull(dumpASDCArtifactInfo(artifactInfoElem)));
284                         buffer.append(System.lineSeparator());
285                         buffer.append(",");
286
287                 }
288                 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
289                 buffer.append("}");
290                 buffer.append(System.lineSeparator());
291
292                 return buffer.toString();
293         }
294
295         private static String dumpASDCArtifactInfo(IArtifactInfo artifactInfo) {
296
297                 if (artifactInfo == null) {
298                         return null;
299                 }
300
301                 StringBuffer buffer = new StringBuffer("Service Artifacts Info:");
302                 buffer.append(System.lineSeparator());
303
304                 buffer.append("ArtifactName:");
305                 buffer.append(testNull(artifactInfo.getArtifactName()));
306                 buffer.append(System.lineSeparator());
307
308                 buffer.append("ArtifactVersion:");
309                 buffer.append(testNull(artifactInfo.getArtifactVersion()));
310                 buffer.append(System.lineSeparator());
311
312                 buffer.append("ArtifactType:");
313                 buffer.append(testNull(artifactInfo.getArtifactType()));
314                 buffer.append(System.lineSeparator());
315
316                 buffer.append("ArtifactDescription:");
317                 buffer.append(testNull(artifactInfo.getArtifactDescription()));
318                 buffer.append(System.lineSeparator());
319
320                 buffer.append("ArtifactTimeout:");
321                 buffer.append(testNull(artifactInfo.getArtifactTimeout()));
322                 buffer.append(System.lineSeparator());
323
324                 buffer.append("ArtifactURL:");
325                 buffer.append(testNull(artifactInfo.getArtifactURL()));
326                 buffer.append(System.lineSeparator());
327
328                 buffer.append("ArtifactUUID:");
329                 buffer.append(testNull(artifactInfo.getArtifactUUID()));
330                 buffer.append(System.lineSeparator());
331
332                 buffer.append("ArtifactChecksum:");
333                 buffer.append(testNull(artifactInfo.getArtifactChecksum()));
334                 buffer.append(System.lineSeparator());
335
336                 buffer.append("GeneratedArtifact:");
337                 buffer.append("{");
338                 buffer.append(testNull(dumpASDCArtifactInfo(artifactInfo.getGeneratedArtifact())));
339                 buffer.append(System.lineSeparator());
340                 buffer.append("}");
341                 buffer.append(System.lineSeparator());
342
343                 buffer.append("RelatedArtifacts:");
344
345
346                 if (artifactInfo.getRelatedArtifacts() != null) {
347                         buffer.append("{");
348                         buffer.append(System.lineSeparator());
349                         for (IArtifactInfo artifactInfoElem:artifactInfo.getRelatedArtifacts()) {
350
351                                 buffer.append(testNull(dumpASDCArtifactInfo(artifactInfoElem)));
352                                 buffer.append(System.lineSeparator());
353                                 buffer.append(",");
354
355                         }
356                         buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
357                         buffer.append("}");
358                         buffer.append(System.lineSeparator());
359                 } else {
360                         buffer.append("NULL");
361                 }
362
363                 buffer.append(System.lineSeparator());
364
365                 return buffer.toString();
366         }
367 }