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 return "ASDC Notification:" + System.lineSeparator() +
46 "DistributionID:" + testNull(asdcNotification.getDistributionID()) + System.lineSeparator() +
47 "ServiceName:" + testNull(asdcNotification.getServiceName()) + System.lineSeparator() +
48 "ServiceVersion:" + testNull(asdcNotification.getServiceVersion()) + System.lineSeparator() +
49 "ServiceUUID:" + testNull(asdcNotification.getServiceUUID()) + System.lineSeparator() +
50 "ServiceInvariantUUID:" + testNull(asdcNotification.getServiceInvariantUUID()) + System.lineSeparator() +
51 "ServiceDescription:" + testNull(asdcNotification.getServiceDescription()) + System.lineSeparator() +
52 "Service Artifacts List:" + System.lineSeparator() + testNull(dumpArtifactInfoList(asdcNotification.getServiceArtifacts())) + System.lineSeparator() +
53 "Resource Instances List:" + System.lineSeparator() + testNull(dumpASDCResourcesList(asdcNotification)) + System.lineSeparator();
56 public static String dumpCSARNotification(INotificationData asdcNotification, ToscaResourceStructure toscaResourceStructure) {
58 if (asdcNotification == null) {
63 StringBuilder buffer = new StringBuilder("CSAR Notification:");
64 buffer.append(System.lineSeparator());
65 buffer.append(System.lineSeparator());
68 ISdcCsarHelper csarHelper = toscaResourceStructure.getSdcCsarHelper();
71 buffer.append("Service Level Properties:");
72 buffer.append(System.lineSeparator());
73 buffer.append("Name:");
74 buffer.append(testNull(csarHelper.getServiceMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
75 buffer.append(System.lineSeparator());
76 buffer.append("Description:");
77 buffer.append(testNull(csarHelper.getServiceMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
78 buffer.append(System.lineSeparator());
79 buffer.append("Model UUID:");
80 buffer.append(testNull(csarHelper.getServiceMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
81 buffer.append(System.lineSeparator());
82 buffer.append("Model Version:");
83 buffer.append(testNull(csarHelper.getServiceMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
84 buffer.append(System.lineSeparator());
85 buffer.append("Model InvariantUuid:");
86 buffer.append(testNull(csarHelper.getServiceMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
87 buffer.append(System.lineSeparator());
88 buffer.append("Service Type:");
89 buffer.append(csarHelper.getServiceMetadata().getValue("serviceType"));
90 buffer.append(System.lineSeparator());
91 buffer.append("Service Role:");
92 buffer.append(csarHelper.getServiceMetadata().getValue("serviceRole"));
93 buffer.append(System.lineSeparator());
94 buffer.append("WorkLoad Context:");
95 buffer.append(asdcNotification.getWorkloadContext());
96 buffer.append(System.lineSeparator());
97 buffer.append("Environment Context:");
98 buffer.append(csarHelper.getServiceMetadata().getValue("environmentContext"));
100 buffer.append(System.lineSeparator());
101 buffer.append(System.lineSeparator());
102 buffer.append("VNF Level Properties:");
103 buffer.append(System.lineSeparator());
105 List<NodeTemplate> vfNodeTemplatesList = toscaResourceStructure.getSdcCsarHelper().getServiceVfList();
106 for (NodeTemplate vfNodeTemplate : vfNodeTemplatesList) {
108 buffer.append("Model Name:");
109 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
110 buffer.append(System.lineSeparator());
111 buffer.append("Description:");
112 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
113 buffer.append(System.lineSeparator());
114 buffer.append("Version:");
115 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
116 buffer.append(System.lineSeparator());
117 buffer.append("Type:");
118 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)));
119 buffer.append(System.lineSeparator());
120 buffer.append("InvariantUuid:");
121 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
122 buffer.append(System.lineSeparator());
123 buffer.append("Max Instances:");
124 buffer.append(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES));
125 buffer.append(System.lineSeparator());
126 buffer.append("Min Instances:");
127 buffer.append(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES));
128 buffer.append(System.lineSeparator());
130 buffer.append(System.lineSeparator());
131 buffer.append("VNF Customization Properties:");
132 buffer.append(System.lineSeparator());
134 buffer.append("Customization UUID:");
135 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
136 buffer.append(System.lineSeparator());
137 buffer.append("NFFunction:");
138 buffer.append(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
139 buffer.append(System.lineSeparator());
140 buffer.append("NFCode:");
141 buffer.append(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfNodeTemplate, "nf_naming_code"));
142 buffer.append(System.lineSeparator());
143 buffer.append("NFRole:");
144 buffer.append(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE));
145 buffer.append(System.lineSeparator());
146 buffer.append("NFType:");
147 buffer.append(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
148 buffer.append(System.lineSeparator());
149 buffer.append("MultiStageDesign:");
150 buffer.append(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfNodeTemplate, "multi_stage_design"));
152 buffer.append(System.lineSeparator());
153 buffer.append("VF Module Properties:");
154 buffer.append(System.lineSeparator());
155 List<Group> vfGroups = toscaResourceStructure.getSdcCsarHelper().getVfModulesByVf(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
157 for(Group group : vfGroups){
159 Metadata vfMetadata = group.getMetadata();
161 buffer.append("ModelInvariantUuid:");
162 buffer.append(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)));
163 buffer.append(System.lineSeparator());
164 buffer.append("ModelName:");
165 buffer.append(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELNAME)));
166 buffer.append(System.lineSeparator());
167 buffer.append("ModelUuid:");
168 buffer.append(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)));
169 buffer.append(System.lineSeparator());
170 buffer.append("ModelVersion:");
171 buffer.append(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)));
172 buffer.append(System.lineSeparator());
173 buffer.append("Description:");
174 buffer.append(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
175 buffer.append(System.lineSeparator());
181 List<NodeTemplate> nodeTemplatesVLList = toscaResourceStructure.getSdcCsarHelper().getServiceVlList();
183 if(nodeTemplatesVLList != null){
185 buffer.append(System.lineSeparator());
186 buffer.append("NETWORK Level Properties:");
187 buffer.append(System.lineSeparator());
189 for(NodeTemplate vlNode : nodeTemplatesVLList){
191 buffer.append("Model Name:");
192 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
193 buffer.append(System.lineSeparator());
194 buffer.append("Model InvariantUuid:");
195 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
196 buffer.append(System.lineSeparator());
197 buffer.append("Model UUID:");
198 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
199 buffer.append(System.lineSeparator());
200 buffer.append("Model Version:");
201 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
202 buffer.append(System.lineSeparator());
203 buffer.append("AIC Max Version:");
204 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
205 buffer.append(System.lineSeparator());
206 buffer.append("AIC Min Version:");
207 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
208 buffer.append(System.lineSeparator());
209 buffer.append("Tosca Node Type:");
210 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)));
211 buffer.append(System.lineSeparator());
212 buffer.append("Description:");
213 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
214 buffer.append(System.lineSeparator());
220 List<NodeTemplate> allottedResourceList = toscaResourceStructure.getSdcCsarHelper().getAllottedResources();
222 if(allottedResourceList != null){
224 buffer.append(System.lineSeparator());
225 buffer.append("Allotted Resource Properties:");
226 buffer.append(System.lineSeparator());
228 for(NodeTemplate allottedNode : allottedResourceList){
230 buffer.append("Model Name:");
231 buffer.append(testNull(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
232 buffer.append(System.lineSeparator());
233 buffer.append("Model Name:");
234 buffer.append(testNull(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
235 buffer.append(System.lineSeparator());
236 buffer.append("Model InvariantUuid:");
237 buffer.append(testNull(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
238 buffer.append(System.lineSeparator());
239 buffer.append("Model Version:");
240 buffer.append(testNull(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
241 buffer.append(System.lineSeparator());
242 buffer.append("Model UUID:");
243 buffer.append(testNull(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
244 buffer.append(System.lineSeparator());
245 buffer.append("Model Subcategory:");
246 buffer.append(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY));
247 buffer.append(System.lineSeparator());
248 buffer.append("Model Description:");
249 buffer.append(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
250 buffer.append(System.lineSeparator());
253 buffer.append("Allotted Resource Customization Properties:");
254 buffer.append(System.lineSeparator());
256 buffer.append("Model Cutomization UUID:");
257 buffer.append(testNull(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
258 buffer.append(System.lineSeparator());
259 buffer.append("NFFunction:");
260 buffer.append(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(allottedNode, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
261 buffer.append(System.lineSeparator());
262 buffer.append("NFCode:");
263 buffer.append(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(allottedNode, "nf_naming_code"));
264 buffer.append(System.lineSeparator());
265 buffer.append("NFRole:");
266 buffer.append(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(allottedNode, SdcPropertyNames.PROPERTY_NAME_NFROLE));
267 buffer.append(System.lineSeparator());
268 buffer.append("NFType:");
269 buffer.append(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(allottedNode, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
270 buffer.append(System.lineSeparator());
277 return buffer.toString();
280 public static String dumpVfModuleMetaDataList(List<IVfModuleData> moduleMetaDataList) {
281 if (moduleMetaDataList == null ) {
285 StringBuilder buffer = new StringBuilder("VfModuleMetaData List:");
286 buffer.append(System.lineSeparator());
290 for (IVfModuleData moduleMetaData:moduleMetaDataList) {
291 buffer.append(System.lineSeparator());
292 buffer.append(testNull(dumpVfModuleMetaData(moduleMetaData)));
293 buffer.append(System.lineSeparator());
297 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
299 buffer.append(System.lineSeparator());
301 return buffer.toString();
304 private static String dumpVfModuleMetaData(IVfModuleData moduleMetaData) {
306 if (moduleMetaData == null ) {
310 StringBuilder stringBuilder = new StringBuilder("VfModuleMetaData:");
311 stringBuilder.append(System.lineSeparator());
313 stringBuilder.append("VfModuleModelName:");
314 stringBuilder.append(testNull(moduleMetaData.getVfModuleModelName()));
315 stringBuilder.append(System.lineSeparator());
317 stringBuilder.append("VfModuleModelVersion:");
318 stringBuilder.append(testNull(moduleMetaData.getVfModuleModelVersion()));
319 stringBuilder.append(System.lineSeparator());
321 stringBuilder.append("VfModuleModelUUID:");
322 stringBuilder.append(testNull(moduleMetaData.getVfModuleModelUUID()));
323 stringBuilder.append(System.lineSeparator());
325 stringBuilder.append("VfModuleModelInvariantUUID:");
326 stringBuilder.append(testNull(moduleMetaData.getVfModuleModelInvariantUUID()));
327 stringBuilder.append(System.lineSeparator());
329 stringBuilder.append("VfModuleModelDescription:");
330 stringBuilder.append(testNull(moduleMetaData.getVfModuleModelDescription()));
331 stringBuilder.append(System.lineSeparator());
333 stringBuilder.append("Artifacts UUID List:");
335 if (moduleMetaData.getArtifacts() != null) {
336 stringBuilder.append("{");
338 for (String artifactUUID:moduleMetaData.getArtifacts()) {
339 stringBuilder.append(System.lineSeparator());
340 stringBuilder.append(testNull(artifactUUID));
341 stringBuilder.append(System.lineSeparator());
342 stringBuilder.append(",");
344 stringBuilder.replace(stringBuilder.length()-1,stringBuilder.length(), System.lineSeparator());
345 stringBuilder.append("}");
346 stringBuilder.append(System.lineSeparator());
348 stringBuilder.append("NULL");
351 if (moduleMetaData.getProperties() != null) {
352 Map<String, String> vfModuleMap = moduleMetaData.getProperties();
353 stringBuilder.append("Properties List:");
354 stringBuilder.append("{");
356 for (Map.Entry<String, String> entry : vfModuleMap.entrySet()) {
357 stringBuilder.append(System.lineSeparator());
358 stringBuilder.append(" ").append(entry.getKey()).append(" : ").append(entry.getValue());
360 stringBuilder.replace(stringBuilder.length()-1,stringBuilder.length(), System.lineSeparator());
361 stringBuilder.append("}");
362 stringBuilder.append(System.lineSeparator());
364 stringBuilder.append("NULL");
368 stringBuilder.append(System.lineSeparator());
370 stringBuilder.append("isBase:");
371 stringBuilder.append(moduleMetaData.isBase());
372 stringBuilder.append(System.lineSeparator());
374 return stringBuilder.toString();
377 private static String testNull(Object object) {
378 if (object == null) {
380 } else if (object instanceof Integer) {
381 return object.toString();
382 } else if (object instanceof String) {
383 return (String)object;
385 return "Type not recognized";
389 private static String dumpASDCResourcesList(INotificationData asdcNotification) {
390 if (asdcNotification == null || asdcNotification.getResources() == null) {
394 StringBuilder buffer = new StringBuilder();
397 for (IResourceInstance resourceInstanceElem:asdcNotification.getResources()) {
398 buffer.append(System.lineSeparator());
399 buffer.append(testNull(dumpASDCResourceInstance(resourceInstanceElem)));
400 buffer.append(System.lineSeparator());
403 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
405 buffer.append(System.lineSeparator());
407 return buffer.toString();
411 private static String dumpASDCResourceInstance(IResourceInstance resourceInstance) {
413 if (resourceInstance == null) {
417 return "Resource Instance Info:" + System.lineSeparator() +
418 "ResourceInstanceName:" + testNull(resourceInstance.getResourceInstanceName()) + System.lineSeparator() +
419 "ResourceCustomizationUUID:" + testNull(resourceInstance.getResourceCustomizationUUID()) + System.lineSeparator() +
420 "ResourceInvariantUUID:" + testNull(resourceInstance.getResourceInvariantUUID()) + System.lineSeparator() +
421 "ResourceName:" + testNull(resourceInstance.getResourceName()) + System.lineSeparator() +
422 "ResourceType:" + testNull(resourceInstance.getResourceType()) + System.lineSeparator() +
423 "ResourceUUID:" + testNull(resourceInstance.getResourceUUID()) + System.lineSeparator() +
424 "ResourceVersion:" + testNull(resourceInstance.getResourceVersion()) + System.lineSeparator() +
425 "Category:" + testNull(resourceInstance.getCategory()) + System.lineSeparator() +
426 "SubCategory:" + testNull(resourceInstance.getSubcategory()) + System.lineSeparator() +
427 "Resource Artifacts List:" + System.lineSeparator() + testNull(dumpArtifactInfoList(resourceInstance.getArtifacts())) + System.lineSeparator();
431 private static String dumpArtifactInfoList(List<IArtifactInfo> artifactsList) {
433 if (artifactsList == null || artifactsList.isEmpty()) {
437 StringBuilder buffer = new StringBuilder();
439 for (IArtifactInfo artifactInfoElem:artifactsList) {
440 buffer.append(System.lineSeparator());
441 buffer.append(testNull(dumpASDCArtifactInfo(artifactInfoElem)));
442 buffer.append(System.lineSeparator());
446 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
448 buffer.append(System.lineSeparator());
450 return buffer.toString();
453 private static String dumpASDCArtifactInfo(IArtifactInfo artifactInfo) {
455 if (artifactInfo == null) {
459 StringBuilder buffer = new StringBuilder("Service Artifacts Info:");
460 buffer.append(System.lineSeparator());
462 buffer.append("ArtifactName:");
463 buffer.append(testNull(artifactInfo.getArtifactName()));
464 buffer.append(System.lineSeparator());
466 buffer.append("ArtifactVersion:");
467 buffer.append(testNull(artifactInfo.getArtifactVersion()));
468 buffer.append(System.lineSeparator());
470 buffer.append("ArtifactType:");
471 buffer.append(testNull(artifactInfo.getArtifactType()));
472 buffer.append(System.lineSeparator());
474 buffer.append("ArtifactDescription:");
475 buffer.append(testNull(artifactInfo.getArtifactDescription()));
476 buffer.append(System.lineSeparator());
478 buffer.append("ArtifactTimeout:");
479 buffer.append(testNull(artifactInfo.getArtifactTimeout()));
480 buffer.append(System.lineSeparator());
482 buffer.append("ArtifactURL:");
483 buffer.append(testNull(artifactInfo.getArtifactURL()));
484 buffer.append(System.lineSeparator());
486 buffer.append("ArtifactUUID:");
487 buffer.append(testNull(artifactInfo.getArtifactUUID()));
488 buffer.append(System.lineSeparator());
490 buffer.append("ArtifactChecksum:");
491 buffer.append(testNull(artifactInfo.getArtifactChecksum()));
492 buffer.append(System.lineSeparator());
494 buffer.append("GeneratedArtifact:");
496 buffer.append(testNull(dumpASDCArtifactInfo(artifactInfo.getGeneratedArtifact())));
497 buffer.append(System.lineSeparator());
499 buffer.append(System.lineSeparator());
501 buffer.append("RelatedArtifacts:");
504 if (artifactInfo.getRelatedArtifacts() != null) {
506 buffer.append(System.lineSeparator());
507 for (IArtifactInfo artifactInfoElem:artifactInfo.getRelatedArtifacts()) {
509 buffer.append(testNull(dumpASDCArtifactInfo(artifactInfoElem)));
510 buffer.append(System.lineSeparator());
514 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
516 buffer.append(System.lineSeparator());
518 buffer.append("NULL");
521 buffer.append(System.lineSeparator());
523 return buffer.toString();