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;
30 import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
31 import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames;
32 import org.openecomp.sdc.toscaparser.api.Group;
33 import org.openecomp.sdc.toscaparser.api.NodeTemplate;
34 import org.openecomp.sdc.toscaparser.api.elements.Metadata;
35 import org.openecomp.mso.asdc.installer.IVfModuleData;
36 import org.openecomp.mso.asdc.installer.ToscaResourceStructure;
38 public class ASDCNotificationLogging {
40 public static String dumpASDCNotification(INotificationData asdcNotification) {
42 if (asdcNotification == null) {
45 StringBuffer buffer = new StringBuffer("ASDC Notification:");
46 buffer.append(System.lineSeparator());
48 buffer.append("DistributionID:");
49 buffer.append(testNull(asdcNotification.getDistributionID()));
50 buffer.append(System.lineSeparator());
53 buffer.append("ServiceName:");
54 buffer.append(testNull(asdcNotification.getServiceName()));
55 buffer.append(System.lineSeparator());
58 buffer.append("ServiceVersion:");
59 buffer.append(testNull(asdcNotification.getServiceVersion()));
60 buffer.append(System.lineSeparator());
63 buffer.append("ServiceUUID:");
64 buffer.append(testNull(asdcNotification.getServiceUUID()));
65 buffer.append(System.lineSeparator());
68 buffer.append("ServiceInvariantUUID:");
69 buffer.append(testNull(asdcNotification.getServiceInvariantUUID()));
70 buffer.append(System.lineSeparator());
73 buffer.append("ServiceDescription:");
74 buffer.append(testNull(asdcNotification.getServiceDescription()));
75 buffer.append(System.lineSeparator());
78 buffer.append("Service Artifacts List:");
79 buffer.append(System.lineSeparator());
80 buffer.append(testNull(dumpArtifactInfoList(asdcNotification.getServiceArtifacts())));
81 buffer.append(System.lineSeparator());
83 buffer.append("Resource Instances List:");
84 buffer.append(System.lineSeparator());
85 buffer.append(testNull(dumpASDCResourcesList(asdcNotification)));
86 buffer.append(System.lineSeparator());
89 return buffer.toString();
92 public static String dumpCSARNotification(INotificationData asdcNotification, ToscaResourceStructure toscaResourceStructure) {
94 if (asdcNotification == null) {
99 StringBuffer buffer = new StringBuffer("CSAR Notification:");
100 buffer.append(System.lineSeparator());
101 buffer.append(System.lineSeparator());
104 ISdcCsarHelper csarHelper = toscaResourceStructure.getSdcCsarHelper();
107 buffer.append("Service Level Properties:");
108 buffer.append(System.lineSeparator());
109 buffer.append("Name:");
110 buffer.append(testNull(csarHelper.getServiceMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
111 buffer.append(System.lineSeparator());
112 buffer.append("Description:");
113 buffer.append(testNull(csarHelper.getServiceMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
114 buffer.append(System.lineSeparator());
115 buffer.append("Model UUID:");
116 buffer.append(testNull(csarHelper.getServiceMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
117 buffer.append(System.lineSeparator());
118 buffer.append("Model Version:");
119 buffer.append(testNull(csarHelper.getServiceMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
120 buffer.append(System.lineSeparator());
121 buffer.append("Model InvariantUuid:");
122 buffer.append(testNull(csarHelper.getServiceMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
124 buffer.append(System.lineSeparator());
125 buffer.append(System.lineSeparator());
126 buffer.append("VNF Level Properties:");
127 buffer.append(System.lineSeparator());
129 List<NodeTemplate> vfNodeTemplatesList = toscaResourceStructure.getSdcCsarHelper().getServiceVfList();
130 for (NodeTemplate vfNodeTemplate : vfNodeTemplatesList) {
132 buffer.append("Model Name:");
133 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME).trim()));
134 buffer.append(System.lineSeparator());
135 buffer.append("Description:");
136 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION).trim()));
137 buffer.append(System.lineSeparator());
138 buffer.append("Version:");
139 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION).trim()));
140 buffer.append(System.lineSeparator());
141 buffer.append("Type:");
142 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE).trim()));
143 buffer.append(System.lineSeparator());
144 buffer.append("InvariantUuid:");
145 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID).trim()));
146 buffer.append(System.lineSeparator());
147 buffer.append("Max Instances:");
148 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES).trim()));
149 buffer.append(System.lineSeparator());
150 buffer.append("Min Instances:");
151 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES).trim()));
152 buffer.append(System.lineSeparator());
154 buffer.append(System.lineSeparator());
155 buffer.append("VNF Customization Properties:");
156 buffer.append(System.lineSeparator());
158 buffer.append("Customization UUID:");
159 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID).trim()));
160 buffer.append(System.lineSeparator());
161 buffer.append("NFFunction:");
162 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NFFUNCTION).trim()));
163 buffer.append(System.lineSeparator());
164 buffer.append("NFCode:");
165 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NFCODE).trim()));
166 buffer.append(System.lineSeparator());
167 buffer.append("NFRole:");
168 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NFROLE).trim()));
169 buffer.append(System.lineSeparator());
170 buffer.append("NFType:");
171 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NFTYPE).trim()));
172 buffer.append(System.lineSeparator());
174 buffer.append(System.lineSeparator());
175 buffer.append("VF Module Properties:");
176 buffer.append(System.lineSeparator());
177 List<Group> vfGroups = toscaResourceStructure.getSdcCsarHelper().getVfModulesByVf(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID).trim()));
179 for(Group group : vfGroups){
181 Metadata vfMetadata = group.getMetadata();
183 buffer.append("ModelInvariantUuid:");
184 buffer.append(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID).trim()));
185 buffer.append(System.lineSeparator());
186 buffer.append("ModelName:");
187 buffer.append(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELNAME).trim()));
188 buffer.append(System.lineSeparator());
189 buffer.append("ModelUuid:");
190 buffer.append(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID).trim()));
191 buffer.append(System.lineSeparator());
192 buffer.append("ModelVersion:");
193 buffer.append(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION).trim()));
194 buffer.append(System.lineSeparator());
195 buffer.append("Description:");
196 buffer.append(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_DESCRIPTION).trim()));
197 buffer.append(System.lineSeparator());
203 List<NodeTemplate> nodeTemplatesVLList = toscaResourceStructure.getSdcCsarHelper().getServiceVlList();
205 if(nodeTemplatesVLList != null){
207 buffer.append(System.lineSeparator());
208 buffer.append("NETWORK Level Properties:");
209 buffer.append(System.lineSeparator());
211 for(NodeTemplate vlNode : nodeTemplatesVLList){
213 buffer.append("Model Name:");
214 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME).trim()));
215 buffer.append(System.lineSeparator());
216 buffer.append("Model InvariantUuid:");
217 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID).trim()));
218 buffer.append(System.lineSeparator());
219 buffer.append("Model UUID:");
220 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID).trim()));
221 buffer.append(System.lineSeparator());
222 buffer.append("Model Version:");
223 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION).trim()));
224 buffer.append(System.lineSeparator());
225 buffer.append("AIC Max Version:");
226 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES).trim()));
227 buffer.append(System.lineSeparator());
228 buffer.append("AIC Min Version:");
229 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES).trim()));
230 buffer.append(System.lineSeparator());
231 buffer.append("Tosca Node Type:");
232 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE).trim()));
233 buffer.append(System.lineSeparator());
234 buffer.append("Description:");
235 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION).trim()));
236 buffer.append(System.lineSeparator());
242 List<NodeTemplate> allottedResourceList = toscaResourceStructure.getSdcCsarHelper().getAllottedResources();
244 if(allottedResourceList != null){
246 buffer.append(System.lineSeparator());
247 buffer.append("Allotted Resource Properties:");
248 buffer.append(System.lineSeparator());
250 for(NodeTemplate allottedNode : allottedResourceList){
252 buffer.append("Model Name:");
253 buffer.append(testNull(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME).trim()));
254 buffer.append(System.lineSeparator());
255 buffer.append("Model Name:");
256 buffer.append(testNull(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME).trim()));
257 buffer.append(System.lineSeparator());
258 buffer.append("Model InvariantUuid:");
259 buffer.append(testNull(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID).trim()));
260 buffer.append(System.lineSeparator());
261 buffer.append("Model Version:");
262 buffer.append(testNull(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION).trim()));
263 buffer.append(System.lineSeparator());
264 buffer.append("Model UUID:");
265 buffer.append(testNull(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID).trim()));
266 buffer.append(System.lineSeparator());
269 buffer.append("Allotted Resource Customization Properties:");
270 buffer.append(System.lineSeparator());
272 buffer.append("Model Cutomization UUID:");
273 buffer.append(testNull(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID).trim()));
274 buffer.append(System.lineSeparator());
281 return buffer.toString();
284 public static String dumpVfModuleMetaDataList(List<IVfModuleData> moduleMetaDataList) {
285 if (moduleMetaDataList == null ) {
289 StringBuffer buffer = new StringBuffer("VfModuleMetaData List:");
290 buffer.append(System.lineSeparator());
294 for (IVfModuleData moduleMetaData:moduleMetaDataList) {
295 buffer.append(System.lineSeparator());
296 buffer.append(testNull(dumpVfModuleMetaData(moduleMetaData)));
297 buffer.append(System.lineSeparator());
301 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
303 buffer.append(System.lineSeparator());
305 return buffer.toString();
308 private static String dumpVfModuleMetaData(IVfModuleData moduleMetaData) {
310 if (moduleMetaData == null ) {
314 StringBuffer buffer = new StringBuffer("VfModuleMetaData:");
315 buffer.append(System.lineSeparator());
317 buffer.append("VfModuleModelName:");
318 buffer.append(testNull(moduleMetaData.getVfModuleModelName()));
319 buffer.append(System.lineSeparator());
321 buffer.append("VfModuleModelVersion:");
322 buffer.append(testNull(moduleMetaData.getVfModuleModelVersion()));
323 buffer.append(System.lineSeparator());
325 buffer.append("VfModuleModelUUID:");
326 buffer.append(testNull(moduleMetaData.getVfModuleModelUUID()));
327 buffer.append(System.lineSeparator());
329 buffer.append("VfModuleModelInvariantUUID:");
330 buffer.append(testNull(moduleMetaData.getVfModuleModelInvariantUUID()));
331 buffer.append(System.lineSeparator());
333 buffer.append("VfModuleModelDescription:");
334 buffer.append(testNull(moduleMetaData.getVfModuleModelDescription()));
335 buffer.append(System.lineSeparator());
337 buffer.append("Artifacts UUID List:");
339 if (moduleMetaData.getArtifacts() != null) {
342 for (String artifactUUID:moduleMetaData.getArtifacts()) {
343 buffer.append(System.lineSeparator());
344 buffer.append(testNull(artifactUUID));
345 buffer.append(System.lineSeparator());
348 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
350 buffer.append(System.lineSeparator());
352 buffer.append("NULL");
355 if (moduleMetaData.getProperties() != null) {
356 Map<String, String> vfModuleMap = moduleMetaData.getProperties();
357 buffer.append("Properties List:");
360 for (Map.Entry<String, String> entry : vfModuleMap.entrySet()) {
361 buffer.append(System.lineSeparator());
362 buffer.append(" " + entry.getKey() + " : " + entry.getValue());
364 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
366 buffer.append(System.lineSeparator());
368 buffer.append("NULL");
372 buffer.append(System.lineSeparator());
374 buffer.append("isBase:");
375 buffer.append(moduleMetaData.isBase());
376 buffer.append(System.lineSeparator());
378 return buffer.toString();
381 private static String testNull(Object object) {
382 if (object == null) {
384 } else if (object instanceof Integer) {
385 return object.toString();
386 } else if (object instanceof String) {
387 return (String)object;
389 return "Type not recognized";
393 private static String dumpASDCResourcesList(INotificationData asdcNotification) {
394 if (asdcNotification == null || asdcNotification.getResources() == null) {
398 StringBuffer buffer = new StringBuffer();
401 for (IResourceInstance resourceInstanceElem:asdcNotification.getResources()) {
402 buffer.append(System.lineSeparator());
403 buffer.append(testNull(dumpASDCResourceInstance(resourceInstanceElem)));
404 buffer.append(System.lineSeparator());
407 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
409 buffer.append(System.lineSeparator());
411 return buffer.toString();
415 private static String dumpASDCResourceInstance(IResourceInstance resourceInstance) {
417 if (resourceInstance == null) {
421 StringBuffer buffer = new StringBuffer("Resource Instance Info:");
422 buffer.append(System.lineSeparator());
424 buffer.append("ResourceInstanceName:");
425 buffer.append(testNull(resourceInstance.getResourceInstanceName()));
426 buffer.append(System.lineSeparator());
428 buffer.append("ResourceCustomizationUUID:");
429 buffer.append(testNull(resourceInstance.getResourceCustomizationUUID()));
430 buffer.append(System.lineSeparator());
432 buffer.append("ResourceInvariantUUID:");
433 buffer.append(testNull(resourceInstance.getResourceInvariantUUID()));
434 buffer.append(System.lineSeparator());
436 buffer.append("ResourceName:");
437 buffer.append(testNull(resourceInstance.getResourceName()));
438 buffer.append(System.lineSeparator());
440 buffer.append("ResourceType:");
441 buffer.append(testNull(resourceInstance.getResourceType()));
442 buffer.append(System.lineSeparator());
444 buffer.append("ResourceUUID:");
445 buffer.append(testNull(resourceInstance.getResourceUUID()));
446 buffer.append(System.lineSeparator());
448 buffer.append("ResourceVersion:");
449 buffer.append(testNull(resourceInstance.getResourceVersion()));
450 buffer.append(System.lineSeparator());
452 buffer.append("Category:");
453 buffer.append(testNull(resourceInstance.getCategory()));
454 buffer.append(System.lineSeparator());
456 buffer.append("SubCategory:");
457 buffer.append(testNull(resourceInstance.getSubcategory()));
458 buffer.append(System.lineSeparator());
460 buffer.append("Resource Artifacts List:");
461 buffer.append(System.lineSeparator());
462 buffer.append(testNull(dumpArtifactInfoList(resourceInstance.getArtifacts())));
463 buffer.append(System.lineSeparator());
465 return buffer.toString();
470 private static String dumpArtifactInfoList(List<IArtifactInfo> artifactsList) {
472 if (artifactsList == null || artifactsList.isEmpty()) {
476 StringBuffer buffer = new StringBuffer();
478 for (IArtifactInfo artifactInfoElem:artifactsList) {
479 buffer.append(System.lineSeparator());
480 buffer.append(testNull(dumpASDCArtifactInfo(artifactInfoElem)));
481 buffer.append(System.lineSeparator());
485 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
487 buffer.append(System.lineSeparator());
489 return buffer.toString();
492 private static String dumpASDCArtifactInfo(IArtifactInfo artifactInfo) {
494 if (artifactInfo == null) {
498 StringBuffer buffer = new StringBuffer("Service Artifacts Info:");
499 buffer.append(System.lineSeparator());
501 buffer.append("ArtifactName:");
502 buffer.append(testNull(artifactInfo.getArtifactName()));
503 buffer.append(System.lineSeparator());
505 buffer.append("ArtifactVersion:");
506 buffer.append(testNull(artifactInfo.getArtifactVersion()));
507 buffer.append(System.lineSeparator());
509 buffer.append("ArtifactType:");
510 buffer.append(testNull(artifactInfo.getArtifactType()));
511 buffer.append(System.lineSeparator());
513 buffer.append("ArtifactDescription:");
514 buffer.append(testNull(artifactInfo.getArtifactDescription()));
515 buffer.append(System.lineSeparator());
517 buffer.append("ArtifactTimeout:");
518 buffer.append(testNull(artifactInfo.getArtifactTimeout()));
519 buffer.append(System.lineSeparator());
521 buffer.append("ArtifactURL:");
522 buffer.append(testNull(artifactInfo.getArtifactURL()));
523 buffer.append(System.lineSeparator());
525 buffer.append("ArtifactUUID:");
526 buffer.append(testNull(artifactInfo.getArtifactUUID()));
527 buffer.append(System.lineSeparator());
529 buffer.append("ArtifactChecksum:");
530 buffer.append(testNull(artifactInfo.getArtifactChecksum()));
531 buffer.append(System.lineSeparator());
533 buffer.append("GeneratedArtifact:");
535 buffer.append(testNull(dumpASDCArtifactInfo(artifactInfo.getGeneratedArtifact())));
536 buffer.append(System.lineSeparator());
538 buffer.append(System.lineSeparator());
540 buffer.append("RelatedArtifacts:");
543 if (artifactInfo.getRelatedArtifacts() != null) {
545 buffer.append(System.lineSeparator());
546 for (IArtifactInfo artifactInfoElem:artifactInfo.getRelatedArtifacts()) {
548 buffer.append(testNull(dumpASDCArtifactInfo(artifactInfoElem)));
549 buffer.append(System.lineSeparator());
553 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
555 buffer.append(System.lineSeparator());
557 buffer.append("NULL");
560 buffer.append(System.lineSeparator());
562 return buffer.toString();