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)));
88 buffer.append(System.lineSeparator());
89 buffer.append(System.lineSeparator());
90 buffer.append("VNF Level Properties:");
91 buffer.append(System.lineSeparator());
93 List<NodeTemplate> vfNodeTemplatesList = toscaResourceStructure.getSdcCsarHelper().getServiceVfList();
94 for (NodeTemplate vfNodeTemplate : vfNodeTemplatesList) {
96 buffer.append("Model Name:");
97 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME).trim()));
98 buffer.append(System.lineSeparator());
99 buffer.append("Description:");
100 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION).trim()));
101 buffer.append(System.lineSeparator());
102 buffer.append("Version:");
103 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION).trim()));
104 buffer.append(System.lineSeparator());
105 buffer.append("Type:");
106 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE).trim()));
107 buffer.append(System.lineSeparator());
108 buffer.append("InvariantUuid:");
109 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID).trim()));
110 buffer.append(System.lineSeparator());
111 buffer.append("Max Instances:");
112 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES).trim()));
113 buffer.append(System.lineSeparator());
114 buffer.append("Min Instances:");
115 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES).trim()));
116 buffer.append(System.lineSeparator());
118 buffer.append(System.lineSeparator());
119 buffer.append("VNF Customization Properties:");
120 buffer.append(System.lineSeparator());
122 buffer.append("Customization UUID:");
123 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID).trim()));
124 buffer.append(System.lineSeparator());
125 buffer.append("NFFunction:");
126 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NFFUNCTION).trim()));
127 buffer.append(System.lineSeparator());
128 buffer.append("NFCode:");
129 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NFCODE).trim()));
130 buffer.append(System.lineSeparator());
131 buffer.append("NFRole:");
132 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NFROLE).trim()));
133 buffer.append(System.lineSeparator());
134 buffer.append("NFType:");
135 buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NFTYPE).trim()));
136 buffer.append(System.lineSeparator());
138 buffer.append(System.lineSeparator());
139 buffer.append("VF Module Properties:");
140 buffer.append(System.lineSeparator());
141 List<Group> vfGroups = toscaResourceStructure.getSdcCsarHelper().getVfModulesByVf(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID).trim()));
143 for(Group group : vfGroups){
145 Metadata vfMetadata = group.getMetadata();
147 buffer.append("ModelInvariantUuid:");
148 buffer.append(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID).trim()));
149 buffer.append(System.lineSeparator());
150 buffer.append("ModelName:");
151 buffer.append(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELNAME).trim()));
152 buffer.append(System.lineSeparator());
153 buffer.append("ModelUuid:");
154 buffer.append(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID).trim()));
155 buffer.append(System.lineSeparator());
156 buffer.append("ModelVersion:");
157 buffer.append(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION).trim()));
158 buffer.append(System.lineSeparator());
159 buffer.append("Description:");
160 buffer.append(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_DESCRIPTION).trim()));
161 buffer.append(System.lineSeparator());
167 List<NodeTemplate> nodeTemplatesVLList = toscaResourceStructure.getSdcCsarHelper().getServiceVlList();
169 if(nodeTemplatesVLList != null){
171 buffer.append(System.lineSeparator());
172 buffer.append("NETWORK Level Properties:");
173 buffer.append(System.lineSeparator());
175 for(NodeTemplate vlNode : nodeTemplatesVLList){
177 buffer.append("Model Name:");
178 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME).trim()));
179 buffer.append(System.lineSeparator());
180 buffer.append("Model InvariantUuid:");
181 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID).trim()));
182 buffer.append(System.lineSeparator());
183 buffer.append("Model UUID:");
184 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID).trim()));
185 buffer.append(System.lineSeparator());
186 buffer.append("Model Version:");
187 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION).trim()));
188 buffer.append(System.lineSeparator());
189 buffer.append("AIC Max Version:");
190 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES).trim()));
191 buffer.append(System.lineSeparator());
192 buffer.append("AIC Min Version:");
193 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES).trim()));
194 buffer.append(System.lineSeparator());
195 buffer.append("Tosca Node Type:");
196 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE).trim()));
197 buffer.append(System.lineSeparator());
198 buffer.append("Description:");
199 buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION).trim()));
200 buffer.append(System.lineSeparator());
206 List<NodeTemplate> allottedResourceList = toscaResourceStructure.getSdcCsarHelper().getAllottedResources();
208 if(allottedResourceList != null){
210 buffer.append(System.lineSeparator());
211 buffer.append("Allotted Resource Properties:");
212 buffer.append(System.lineSeparator());
214 for(NodeTemplate allottedNode : allottedResourceList){
216 buffer.append("Model Name:");
217 buffer.append(testNull(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME).trim()));
218 buffer.append(System.lineSeparator());
219 buffer.append("Model Name:");
220 buffer.append(testNull(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME).trim()));
221 buffer.append(System.lineSeparator());
222 buffer.append("Model InvariantUuid:");
223 buffer.append(testNull(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID).trim()));
224 buffer.append(System.lineSeparator());
225 buffer.append("Model Version:");
226 buffer.append(testNull(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION).trim()));
227 buffer.append(System.lineSeparator());
228 buffer.append("Model UUID:");
229 buffer.append(testNull(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID).trim()));
230 buffer.append(System.lineSeparator());
233 buffer.append("Allotted Resource Customization Properties:");
234 buffer.append(System.lineSeparator());
236 buffer.append("Model Cutomization UUID:");
237 buffer.append(testNull(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID).trim()));
238 buffer.append(System.lineSeparator());
245 return buffer.toString();
248 public static String dumpVfModuleMetaDataList(List<IVfModuleData> moduleMetaDataList) {
249 if (moduleMetaDataList == null ) {
253 StringBuilder buffer = new StringBuilder("VfModuleMetaData List:");
254 buffer.append(System.lineSeparator());
258 for (IVfModuleData moduleMetaData:moduleMetaDataList) {
259 buffer.append(System.lineSeparator());
260 buffer.append(testNull(dumpVfModuleMetaData(moduleMetaData)));
261 buffer.append(System.lineSeparator());
265 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
267 buffer.append(System.lineSeparator());
269 return buffer.toString();
272 private static String dumpVfModuleMetaData(IVfModuleData moduleMetaData) {
274 if (moduleMetaData == null ) {
278 StringBuilder stringBuilder = new StringBuilder("VfModuleMetaData:");
279 stringBuilder.append(System.lineSeparator());
281 stringBuilder.append("VfModuleModelName:");
282 stringBuilder.append(testNull(moduleMetaData.getVfModuleModelName()));
283 stringBuilder.append(System.lineSeparator());
285 stringBuilder.append("VfModuleModelVersion:");
286 stringBuilder.append(testNull(moduleMetaData.getVfModuleModelVersion()));
287 stringBuilder.append(System.lineSeparator());
289 stringBuilder.append("VfModuleModelUUID:");
290 stringBuilder.append(testNull(moduleMetaData.getVfModuleModelUUID()));
291 stringBuilder.append(System.lineSeparator());
293 stringBuilder.append("VfModuleModelInvariantUUID:");
294 stringBuilder.append(testNull(moduleMetaData.getVfModuleModelInvariantUUID()));
295 stringBuilder.append(System.lineSeparator());
297 stringBuilder.append("VfModuleModelDescription:");
298 stringBuilder.append(testNull(moduleMetaData.getVfModuleModelDescription()));
299 stringBuilder.append(System.lineSeparator());
301 stringBuilder.append("Artifacts UUID List:");
303 if (moduleMetaData.getArtifacts() != null) {
304 stringBuilder.append("{");
306 for (String artifactUUID:moduleMetaData.getArtifacts()) {
307 stringBuilder.append(System.lineSeparator());
308 stringBuilder.append(testNull(artifactUUID));
309 stringBuilder.append(System.lineSeparator());
310 stringBuilder.append(",");
312 stringBuilder.replace(stringBuilder.length()-1,stringBuilder.length(), System.lineSeparator());
313 stringBuilder.append("}");
314 stringBuilder.append(System.lineSeparator());
316 stringBuilder.append("NULL");
319 if (moduleMetaData.getProperties() != null) {
320 Map<String, String> vfModuleMap = moduleMetaData.getProperties();
321 stringBuilder.append("Properties List:");
322 stringBuilder.append("{");
324 for (Map.Entry<String, String> entry : vfModuleMap.entrySet()) {
325 stringBuilder.append(System.lineSeparator());
326 stringBuilder.append(" ").append(entry.getKey()).append(" : ").append(entry.getValue());
328 stringBuilder.replace(stringBuilder.length()-1,stringBuilder.length(), System.lineSeparator());
329 stringBuilder.append("}");
330 stringBuilder.append(System.lineSeparator());
332 stringBuilder.append("NULL");
336 stringBuilder.append(System.lineSeparator());
338 stringBuilder.append("isBase:");
339 stringBuilder.append(moduleMetaData.isBase());
340 stringBuilder.append(System.lineSeparator());
342 return stringBuilder.toString();
345 private static String testNull(Object object) {
346 if (object == null) {
348 } else if (object instanceof Integer) {
349 return object.toString();
350 } else if (object instanceof String) {
351 return (String)object;
353 return "Type not recognized";
357 private static String dumpASDCResourcesList(INotificationData asdcNotification) {
358 if (asdcNotification == null || asdcNotification.getResources() == null) {
362 StringBuilder buffer = new StringBuilder();
365 for (IResourceInstance resourceInstanceElem:asdcNotification.getResources()) {
366 buffer.append(System.lineSeparator());
367 buffer.append(testNull(dumpASDCResourceInstance(resourceInstanceElem)));
368 buffer.append(System.lineSeparator());
371 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
373 buffer.append(System.lineSeparator());
375 return buffer.toString();
379 private static String dumpASDCResourceInstance(IResourceInstance resourceInstance) {
381 if (resourceInstance == null) {
385 return "Resource Instance Info:" + System.lineSeparator() +
386 "ResourceInstanceName:" + testNull(resourceInstance.getResourceInstanceName()) + System.lineSeparator() +
387 "ResourceCustomizationUUID:" + testNull(resourceInstance.getResourceCustomizationUUID()) + System.lineSeparator() +
388 "ResourceInvariantUUID:" + testNull(resourceInstance.getResourceInvariantUUID()) + System.lineSeparator() +
389 "ResourceName:" + testNull(resourceInstance.getResourceName()) + System.lineSeparator() +
390 "ResourceType:" + testNull(resourceInstance.getResourceType()) + System.lineSeparator() +
391 "ResourceUUID:" + testNull(resourceInstance.getResourceUUID()) + System.lineSeparator() +
392 "ResourceVersion:" + testNull(resourceInstance.getResourceVersion()) + System.lineSeparator() +
393 "Category:" + testNull(resourceInstance.getCategory()) + System.lineSeparator() +
394 "SubCategory:" + testNull(resourceInstance.getSubcategory()) + System.lineSeparator() +
395 "Resource Artifacts List:" + System.lineSeparator() + testNull(dumpArtifactInfoList(resourceInstance.getArtifacts())) + System.lineSeparator();
399 private static String dumpArtifactInfoList(List<IArtifactInfo> artifactsList) {
401 if (artifactsList == null || artifactsList.isEmpty()) {
405 StringBuilder buffer = new StringBuilder();
407 for (IArtifactInfo artifactInfoElem:artifactsList) {
408 buffer.append(System.lineSeparator());
409 buffer.append(testNull(dumpASDCArtifactInfo(artifactInfoElem)));
410 buffer.append(System.lineSeparator());
414 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
416 buffer.append(System.lineSeparator());
418 return buffer.toString();
421 private static String dumpASDCArtifactInfo(IArtifactInfo artifactInfo) {
423 if (artifactInfo == null) {
427 StringBuilder buffer = new StringBuilder("Service Artifacts Info:");
428 buffer.append(System.lineSeparator());
430 buffer.append("ArtifactName:");
431 buffer.append(testNull(artifactInfo.getArtifactName()));
432 buffer.append(System.lineSeparator());
434 buffer.append("ArtifactVersion:");
435 buffer.append(testNull(artifactInfo.getArtifactVersion()));
436 buffer.append(System.lineSeparator());
438 buffer.append("ArtifactType:");
439 buffer.append(testNull(artifactInfo.getArtifactType()));
440 buffer.append(System.lineSeparator());
442 buffer.append("ArtifactDescription:");
443 buffer.append(testNull(artifactInfo.getArtifactDescription()));
444 buffer.append(System.lineSeparator());
446 buffer.append("ArtifactTimeout:");
447 buffer.append(testNull(artifactInfo.getArtifactTimeout()));
448 buffer.append(System.lineSeparator());
450 buffer.append("ArtifactURL:");
451 buffer.append(testNull(artifactInfo.getArtifactURL()));
452 buffer.append(System.lineSeparator());
454 buffer.append("ArtifactUUID:");
455 buffer.append(testNull(artifactInfo.getArtifactUUID()));
456 buffer.append(System.lineSeparator());
458 buffer.append("ArtifactChecksum:");
459 buffer.append(testNull(artifactInfo.getArtifactChecksum()));
460 buffer.append(System.lineSeparator());
462 buffer.append("GeneratedArtifact:");
464 buffer.append(testNull(dumpASDCArtifactInfo(artifactInfo.getGeneratedArtifact())));
465 buffer.append(System.lineSeparator());
467 buffer.append(System.lineSeparator());
469 buffer.append("RelatedArtifacts:");
472 if (artifactInfo.getRelatedArtifacts() != null) {
474 buffer.append(System.lineSeparator());
475 for (IArtifactInfo artifactInfoElem:artifactInfo.getRelatedArtifacts()) {
477 buffer.append(testNull(dumpASDCArtifactInfo(artifactInfoElem)));
478 buffer.append(System.lineSeparator());
482 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
484 buffer.append(System.lineSeparator());
486 buffer.append("NULL");
489 buffer.append(System.lineSeparator());
491 return buffer.toString();