2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.asdc.util;
24 import java.util.List;
27 import org.openecomp.sdc.api.notification.IArtifactInfo;
28 import org.openecomp.sdc.api.notification.INotificationData;
29 import org.openecomp.sdc.api.notification.IResourceInstance;
31 import org.openecomp.mso.asdc.installer.IVfModuleData;
33 public class ASDCNotificationLogging {
35 public static String dumpASDCNotification(INotificationData asdcNotification) {
37 if (asdcNotification == null) {
40 StringBuffer buffer = new StringBuffer("ASDC Notification:");
41 buffer.append(System.lineSeparator());
43 buffer.append("DistributionID:");
44 buffer.append(testNull(asdcNotification.getDistributionID()));
45 buffer.append(System.lineSeparator());
48 buffer.append("ServiceName:");
49 buffer.append(testNull(asdcNotification.getServiceName()));
50 buffer.append(System.lineSeparator());
53 buffer.append("ServiceVersion:");
54 buffer.append(testNull(asdcNotification.getServiceVersion()));
55 buffer.append(System.lineSeparator());
58 buffer.append("ServiceUUID:");
59 buffer.append(testNull(asdcNotification.getServiceUUID()));
60 buffer.append(System.lineSeparator());
63 buffer.append("ServiceInvariantUUID:");
64 buffer.append(testNull(asdcNotification.getServiceInvariantUUID()));
65 buffer.append(System.lineSeparator());
68 buffer.append("ServiceDescription:");
69 buffer.append(testNull(asdcNotification.getServiceDescription()));
70 buffer.append(System.lineSeparator());
73 buffer.append("Service Artifacts List:");
74 buffer.append(System.lineSeparator());
75 buffer.append(testNull(dumpArtifactInfoList(asdcNotification.getServiceArtifacts())));
76 buffer.append(System.lineSeparator());
78 buffer.append("Resource Instances List:");
79 buffer.append(System.lineSeparator());
80 buffer.append(testNull(dumpASDCResourcesList(asdcNotification)));
81 buffer.append(System.lineSeparator());
84 return buffer.toString();
87 public static String dumpVfModuleMetaDataList(List<IVfModuleData> moduleMetaDataList) {
88 if (moduleMetaDataList == null ) {
92 StringBuffer buffer = new StringBuffer("VfModuleMetaData List:");
93 buffer.append(System.lineSeparator());
97 for (IVfModuleData moduleMetaData:moduleMetaDataList) {
98 buffer.append(System.lineSeparator());
99 buffer.append(testNull(dumpVfModuleMetaData(moduleMetaData)));
100 buffer.append(System.lineSeparator());
104 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
106 buffer.append(System.lineSeparator());
108 return buffer.toString();
111 private static String dumpVfModuleMetaData(IVfModuleData moduleMetaData) {
113 if (moduleMetaData == null ) {
117 StringBuffer buffer = new StringBuffer("VfModuleMetaData:");
118 buffer.append(System.lineSeparator());
120 buffer.append("VfModuleModelName:");
121 buffer.append(testNull(moduleMetaData.getVfModuleModelName()));
122 buffer.append(System.lineSeparator());
124 buffer.append("VfModuleModelVersion:");
125 buffer.append(testNull(moduleMetaData.getVfModuleModelVersion()));
126 buffer.append(System.lineSeparator());
128 buffer.append("VfModuleModelUUID:");
129 buffer.append(testNull(moduleMetaData.getVfModuleModelUUID()));
130 buffer.append(System.lineSeparator());
132 buffer.append("VfModuleModelInvariantUUID:");
133 buffer.append(testNull(moduleMetaData.getVfModuleModelInvariantUUID()));
134 buffer.append(System.lineSeparator());
136 buffer.append("VfModuleModelDescription:");
137 buffer.append(testNull(moduleMetaData.getVfModuleModelDescription()));
138 buffer.append(System.lineSeparator());
140 buffer.append("Artifacts UUID List:");
142 if (moduleMetaData.getArtifacts() != null) {
145 for (String artifactUUID:moduleMetaData.getArtifacts()) {
146 buffer.append(System.lineSeparator());
147 buffer.append(testNull(artifactUUID));
148 buffer.append(System.lineSeparator());
151 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
153 buffer.append(System.lineSeparator());
155 buffer.append("NULL");
158 if (moduleMetaData.getProperties() != null) {
159 Map<String, String> vfModuleMap = moduleMetaData.getProperties();
160 buffer.append("Properties List:");
163 for (Map.Entry<String, String> entry : vfModuleMap.entrySet()) {
164 buffer.append(System.lineSeparator());
165 buffer.append(" " + entry.getKey() + " : " + entry.getValue());
167 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
169 buffer.append(System.lineSeparator());
171 buffer.append("NULL");
175 buffer.append(System.lineSeparator());
177 buffer.append("isBase:");
178 buffer.append(moduleMetaData.isBase());
179 buffer.append(System.lineSeparator());
181 return buffer.toString();
184 private static String testNull(Object object) {
185 if (object == null) {
187 } else if (object instanceof Integer) {
188 return object.toString();
189 } else if (object instanceof String) {
190 return (String)object;
192 return "Type not recognized";
196 private static String dumpASDCResourcesList(INotificationData asdcNotification) {
197 if (asdcNotification == null || asdcNotification.getResources() == null) {
201 StringBuffer buffer = new StringBuffer();
204 for (IResourceInstance resourceInstanceElem:asdcNotification.getResources()) {
205 buffer.append(System.lineSeparator());
206 buffer.append(testNull(dumpASDCResourceInstance(resourceInstanceElem)));
207 buffer.append(System.lineSeparator());
210 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
212 buffer.append(System.lineSeparator());
214 return buffer.toString();
218 private static String dumpASDCResourceInstance(IResourceInstance resourceInstance) {
220 if (resourceInstance == null) {
224 StringBuffer buffer = new StringBuffer("Resource Instance Info:");
225 buffer.append(System.lineSeparator());
227 buffer.append("ResourceInstanceName:");
228 buffer.append(testNull(resourceInstance.getResourceInstanceName()));
229 buffer.append(System.lineSeparator());
231 buffer.append("ResourceCustomizationUUID:");
232 buffer.append(testNull(resourceInstance.getResourceCustomizationUUID()));
233 buffer.append(System.lineSeparator());
235 buffer.append("ResourceInvariantUUID:");
236 buffer.append(testNull(resourceInstance.getResourceInvariantUUID()));
237 buffer.append(System.lineSeparator());
239 buffer.append("ResourceName:");
240 buffer.append(testNull(resourceInstance.getResourceName()));
241 buffer.append(System.lineSeparator());
243 buffer.append("ResourceType:");
244 buffer.append(testNull(resourceInstance.getResourceType()));
245 buffer.append(System.lineSeparator());
247 buffer.append("ResourceUUID:");
248 buffer.append(testNull(resourceInstance.getResourceUUID()));
249 buffer.append(System.lineSeparator());
251 buffer.append("ResourceVersion:");
252 buffer.append(testNull(resourceInstance.getResourceVersion()));
253 buffer.append(System.lineSeparator());
255 buffer.append("Category:");
256 buffer.append(testNull(resourceInstance.getCategory()));
257 buffer.append(System.lineSeparator());
259 buffer.append("SubCategory:");
260 buffer.append(testNull(resourceInstance.getSubcategory()));
261 buffer.append(System.lineSeparator());
263 buffer.append("Resource Artifacts List:");
264 buffer.append(System.lineSeparator());
265 buffer.append(testNull(dumpArtifactInfoList(resourceInstance.getArtifacts())));
266 buffer.append(System.lineSeparator());
268 return buffer.toString();
273 private static String dumpArtifactInfoList(List<IArtifactInfo> artifactsList) {
275 if (artifactsList == null || artifactsList.isEmpty()) {
279 StringBuffer buffer = new StringBuffer();
281 for (IArtifactInfo artifactInfoElem:artifactsList) {
282 buffer.append(System.lineSeparator());
283 buffer.append(testNull(dumpASDCArtifactInfo(artifactInfoElem)));
284 buffer.append(System.lineSeparator());
288 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
290 buffer.append(System.lineSeparator());
292 return buffer.toString();
295 private static String dumpASDCArtifactInfo(IArtifactInfo artifactInfo) {
297 if (artifactInfo == null) {
301 StringBuffer buffer = new StringBuffer("Service Artifacts Info:");
302 buffer.append(System.lineSeparator());
304 buffer.append("ArtifactName:");
305 buffer.append(testNull(artifactInfo.getArtifactName()));
306 buffer.append(System.lineSeparator());
308 buffer.append("ArtifactVersion:");
309 buffer.append(testNull(artifactInfo.getArtifactVersion()));
310 buffer.append(System.lineSeparator());
312 buffer.append("ArtifactType:");
313 buffer.append(testNull(artifactInfo.getArtifactType()));
314 buffer.append(System.lineSeparator());
316 buffer.append("ArtifactDescription:");
317 buffer.append(testNull(artifactInfo.getArtifactDescription()));
318 buffer.append(System.lineSeparator());
320 buffer.append("ArtifactTimeout:");
321 buffer.append(testNull(artifactInfo.getArtifactTimeout()));
322 buffer.append(System.lineSeparator());
324 buffer.append("ArtifactURL:");
325 buffer.append(testNull(artifactInfo.getArtifactURL()));
326 buffer.append(System.lineSeparator());
328 buffer.append("ArtifactUUID:");
329 buffer.append(testNull(artifactInfo.getArtifactUUID()));
330 buffer.append(System.lineSeparator());
332 buffer.append("ArtifactChecksum:");
333 buffer.append(testNull(artifactInfo.getArtifactChecksum()));
334 buffer.append(System.lineSeparator());
336 buffer.append("GeneratedArtifact:");
338 buffer.append(testNull(dumpASDCArtifactInfo(artifactInfo.getGeneratedArtifact())));
339 buffer.append(System.lineSeparator());
341 buffer.append(System.lineSeparator());
343 buffer.append("RelatedArtifacts:");
346 if (artifactInfo.getRelatedArtifacts() != null) {
348 buffer.append(System.lineSeparator());
349 for (IArtifactInfo artifactInfoElem:artifactInfo.getRelatedArtifacts()) {
351 buffer.append(testNull(dumpASDCArtifactInfo(artifactInfoElem)));
352 buffer.append(System.lineSeparator());
356 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
358 buffer.append(System.lineSeparator());
360 buffer.append("NULL");
363 buffer.append(System.lineSeparator());
365 return buffer.toString();