Initial OpenECOMP MSO commit
[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
26 import org.openecomp.sdc.api.notification.IArtifactInfo;
27 import org.openecomp.sdc.api.notification.INotificationData;
28 import org.openecomp.sdc.api.notification.IResourceInstance;
29 import org.openecomp.sdc.api.notification.IVfModuleMetadata;
30
31 public class ASDCNotificationLogging {
32
33         public static String dumpASDCNotification(INotificationData asdcNotification) {
34                 
35                 if (asdcNotification == null) {
36                         return "NULL";
37                 }
38                 StringBuffer buffer = new StringBuffer("ASDC Notification:");
39                 buffer.append(System.lineSeparator());
40                 
41                 buffer.append("DistributionID:");
42                 buffer.append(testNull(asdcNotification.getDistributionID()));
43                 buffer.append(System.lineSeparator());
44                 
45                 
46                 buffer.append("ServiceName:");
47                 buffer.append(testNull(asdcNotification.getServiceName()));
48                 buffer.append(System.lineSeparator());
49                 
50                 
51                 buffer.append("ServiceVersion:");
52                 buffer.append(testNull(asdcNotification.getServiceVersion()));
53                 buffer.append(System.lineSeparator());
54                 
55                 
56                 buffer.append("ServiceUUID:");
57                 buffer.append(testNull(asdcNotification.getServiceUUID()));
58                 buffer.append(System.lineSeparator());
59         
60                 
61                 buffer.append("ServiceInvariantUUID:");
62                 buffer.append(testNull(asdcNotification.getServiceInvariantUUID()));
63                 buffer.append(System.lineSeparator());
64                 
65                 
66                 buffer.append("ServiceDescription:");
67                 buffer.append(testNull(asdcNotification.getServiceDescription()));
68                 buffer.append(System.lineSeparator());
69         
70                 
71                 buffer.append("Service Artifacts List:");
72                 buffer.append(System.lineSeparator());
73                 buffer.append(testNull(dumpArtifactInfoList(asdcNotification.getServiceArtifacts())));
74                 buffer.append(System.lineSeparator());
75                 
76                 buffer.append("Resource Instances List:");
77                 buffer.append(System.lineSeparator());
78                 buffer.append(testNull(dumpASDCResourcesList(asdcNotification)));
79                 buffer.append(System.lineSeparator());
80                 
81                 
82                 return buffer.toString();
83         }
84         
85         public static String dumpVfModuleMetaDataList(List<IVfModuleMetadata> moduleMetaDataList) {
86                 if (moduleMetaDataList == null ) {
87                         return null;
88                 }
89                 
90                 StringBuffer buffer = new StringBuffer();               
91                 buffer.append("{");
92                 
93                 for (IVfModuleMetadata moduleMetaData:moduleMetaDataList) {
94                         buffer.append(System.lineSeparator());
95                         buffer.append(testNull(dumpVfModuleMetaData(moduleMetaData)));
96                         buffer.append(System.lineSeparator());
97                         buffer.append(",");
98                         
99                 }
100                 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
101                 buffer.append("}");
102                 buffer.append(System.lineSeparator());
103                 
104                 return buffer.toString();
105         }
106         
107         private static String dumpVfModuleMetaData(IVfModuleMetadata moduleMetaData) {
108                                 
109                 if (moduleMetaData == null ) {
110                         return "NULL";
111                 }
112                 
113                 StringBuffer buffer = new StringBuffer("VfModuleMetaData:");
114                 buffer.append(System.lineSeparator());
115                 
116                 buffer.append("VfModuleModelName:");
117                 buffer.append(testNull(moduleMetaData.getVfModuleModelName()));
118                 buffer.append(System.lineSeparator());
119                 
120                 buffer.append("VfModuleModelVersion:");
121                 buffer.append(testNull(moduleMetaData.getVfModuleModelVersion()));
122                 buffer.append(System.lineSeparator());
123                 
124                 buffer.append("VfModuleModelUUID:");
125                 buffer.append(testNull(moduleMetaData.getVfModuleModelUUID()));
126                 buffer.append(System.lineSeparator());
127                 
128                 buffer.append("VfModuleModelInvariantUUID:");
129                 buffer.append(testNull(moduleMetaData.getVfModuleModelInvariantUUID()));
130                 buffer.append(System.lineSeparator());
131                 
132                 buffer.append("VfModuleModelDescription:");
133                 buffer.append(testNull(moduleMetaData.getVfModuleModelDescription()));
134                 buffer.append(System.lineSeparator());
135                 
136                 buffer.append("Artifacts UUID List:");
137                 
138                 if (moduleMetaData.getArtifacts() != null) {
139                         buffer.append("{");
140                         
141                         for (String artifactUUID:moduleMetaData.getArtifacts()) {
142                                 buffer.append(System.lineSeparator());
143                                 buffer.append(testNull(artifactUUID));
144                                 buffer.append(System.lineSeparator());
145                                 buffer.append(",");
146                         }
147                         buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
148                         buffer.append("}");
149                         buffer.append(System.lineSeparator());
150                 } else {
151                         buffer.append("NULL");
152                 }
153                 
154                 
155                 buffer.append(System.lineSeparator());
156                 
157                 buffer.append("isBase:");
158                 buffer.append(moduleMetaData.isBase());
159                 buffer.append(System.lineSeparator());
160                 
161                 return buffer.toString();
162         }
163         
164         private static String testNull(Object object) {
165                 if (object == null) {
166                         return "NULL";
167                 } else if (object instanceof Integer) {
168                         return object.toString();
169                 } else if (object instanceof String) {
170                         return (String)object;
171                 } else {
172                         return "Type not recognized";
173                 }
174         }
175         
176         private static String dumpASDCResourcesList(INotificationData asdcNotification) {
177                 if (asdcNotification == null || asdcNotification.getResources() == null) {
178                         return null;
179                 }
180                 
181                 StringBuffer buffer = new StringBuffer();               
182                 buffer.append("{");
183                 
184                 for (IResourceInstance resourceInstanceElem:asdcNotification.getResources()) {
185                         buffer.append(System.lineSeparator());
186                         buffer.append(testNull(dumpASDCResourceInstance(resourceInstanceElem)));
187                         buffer.append(System.lineSeparator());
188                         buffer.append(",");
189                 }
190                 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
191                 buffer.append("}");
192                 buffer.append(System.lineSeparator());
193                 
194                 return buffer.toString();
195                 
196         }
197         
198         private static String dumpASDCResourceInstance(IResourceInstance resourceInstance) {
199                 
200                 if (resourceInstance == null) {
201                         return null;
202                 }
203                 
204                 StringBuffer buffer = new StringBuffer("Resource Instance Info:");
205                 buffer.append(System.lineSeparator());
206                 
207                 buffer.append("ResourceInstanceName:");
208                 buffer.append(testNull(resourceInstance.getResourceInstanceName()));
209                 buffer.append(System.lineSeparator());
210                 
211                 buffer.append("ResourceInvariantUUID:");
212                 buffer.append(testNull(resourceInstance.getResourceInvariantUUID()));
213                 buffer.append(System.lineSeparator());
214                 
215                 buffer.append("ResourceName:");
216                 buffer.append(testNull(resourceInstance.getResourceName()));
217                 buffer.append(System.lineSeparator());
218                 
219                 buffer.append("ResourceType:");
220                 buffer.append(testNull(resourceInstance.getResourceType()));
221                 buffer.append(System.lineSeparator());
222                 
223                 buffer.append("ResourceUUID:");
224                 buffer.append(testNull(resourceInstance.getResourceUUID()));
225                 buffer.append(System.lineSeparator());
226                 
227                 buffer.append("ResourceVersion:");
228                 buffer.append(testNull(resourceInstance.getResourceVersion()));
229                 buffer.append(System.lineSeparator());
230                 
231                 buffer.append("Resource Artifacts List:");
232                 buffer.append(System.lineSeparator());
233                 buffer.append(testNull(dumpArtifactInfoList(resourceInstance.getArtifacts())));
234                 buffer.append(System.lineSeparator());
235                 
236                 return buffer.toString();
237                 
238         }
239         
240         
241         private static String dumpArtifactInfoList(List<IArtifactInfo> artifactsList) {
242                 
243                 if (artifactsList == null || artifactsList.isEmpty()) {
244                         return null;
245                 }
246                 
247                 StringBuffer buffer = new StringBuffer();               
248                 buffer.append("{");
249                 for (IArtifactInfo artifactInfoElem:artifactsList) {
250                         buffer.append(System.lineSeparator());
251                         buffer.append(testNull(dumpASDCArtifactInfo(artifactInfoElem)));
252                         buffer.append(System.lineSeparator());
253                         buffer.append(",");
254                         
255                 }
256                 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
257                 buffer.append("}");
258                 buffer.append(System.lineSeparator());
259                 
260                 return buffer.toString();
261         }
262         
263         private static String dumpASDCArtifactInfo(IArtifactInfo artifactInfo) {
264                 
265                 if (artifactInfo == null) {
266                         return null;
267                 }
268                 
269                 StringBuffer buffer = new StringBuffer("Service Artifacts Info:");
270                 buffer.append(System.lineSeparator());
271                 
272                 buffer.append("ArtifactName:");
273                 buffer.append(testNull(artifactInfo.getArtifactName()));
274                 buffer.append(System.lineSeparator());
275                 
276                 buffer.append("ArtifactVersion:");
277                 buffer.append(testNull(artifactInfo.getArtifactVersion()));
278                 buffer.append(System.lineSeparator());
279                 
280                 buffer.append("ArtifactType:");
281                 buffer.append(testNull(artifactInfo.getArtifactType()));
282                 buffer.append(System.lineSeparator());
283                 
284                 buffer.append("ArtifactDescription:");
285                 buffer.append(testNull(artifactInfo.getArtifactDescription()));
286                 buffer.append(System.lineSeparator());
287                 
288                 buffer.append("ArtifactTimeout:");
289                 buffer.append(testNull(artifactInfo.getArtifactTimeout()));
290                 buffer.append(System.lineSeparator());
291                 
292                 buffer.append("ArtifactURL:");
293                 buffer.append(testNull(artifactInfo.getArtifactURL()));
294                 buffer.append(System.lineSeparator());
295                 
296                 buffer.append("ArtifactUUID:");
297                 buffer.append(testNull(artifactInfo.getArtifactUUID()));
298                 buffer.append(System.lineSeparator());
299                 
300                 buffer.append("ArtifactChecksum:");
301                 buffer.append(testNull(artifactInfo.getArtifactChecksum()));
302                 buffer.append(System.lineSeparator());
303                 
304                 buffer.append("GeneratedArtifact:");
305                 buffer.append("{");
306                 buffer.append(testNull(dumpASDCArtifactInfo(artifactInfo.getGeneratedArtifact())));
307                 buffer.append(System.lineSeparator());
308                 buffer.append("}");
309                 buffer.append(System.lineSeparator());
310                 
311                 buffer.append("RelatedArtifacts:");
312                 
313                 
314                 if (artifactInfo.getRelatedArtifacts() != null) {
315                         buffer.append("{");
316                         buffer.append(System.lineSeparator());
317                         for (IArtifactInfo artifactInfoElem:artifactInfo.getRelatedArtifacts()) {
318                                                         
319                                 buffer.append(testNull(dumpASDCArtifactInfo(artifactInfoElem)));
320                                 buffer.append(System.lineSeparator());
321                                 buffer.append(",");
322                         
323                         }
324                         buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
325                         buffer.append("}");
326                         buffer.append(System.lineSeparator());
327                 } else {
328                         buffer.append("NULL");
329                 }
330                 
331                 buffer.append(System.lineSeparator());
332                 
333                 return buffer.toString();
334         }
335 }