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;
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;
31 public class ASDCNotificationLogging {
33 public static String dumpASDCNotification(INotificationData asdcNotification) {
35 if (asdcNotification == null) {
38 StringBuffer buffer = new StringBuffer("ASDC Notification:");
39 buffer.append(System.lineSeparator());
41 buffer.append("DistributionID:");
42 buffer.append(testNull(asdcNotification.getDistributionID()));
43 buffer.append(System.lineSeparator());
46 buffer.append("ServiceName:");
47 buffer.append(testNull(asdcNotification.getServiceName()));
48 buffer.append(System.lineSeparator());
51 buffer.append("ServiceVersion:");
52 buffer.append(testNull(asdcNotification.getServiceVersion()));
53 buffer.append(System.lineSeparator());
56 buffer.append("ServiceUUID:");
57 buffer.append(testNull(asdcNotification.getServiceUUID()));
58 buffer.append(System.lineSeparator());
61 buffer.append("ServiceInvariantUUID:");
62 buffer.append(testNull(asdcNotification.getServiceInvariantUUID()));
63 buffer.append(System.lineSeparator());
66 buffer.append("ServiceDescription:");
67 buffer.append(testNull(asdcNotification.getServiceDescription()));
68 buffer.append(System.lineSeparator());
71 buffer.append("Service Artifacts List:");
72 buffer.append(System.lineSeparator());
73 buffer.append(testNull(dumpArtifactInfoList(asdcNotification.getServiceArtifacts())));
74 buffer.append(System.lineSeparator());
76 buffer.append("Resource Instances List:");
77 buffer.append(System.lineSeparator());
78 buffer.append(testNull(dumpASDCResourcesList(asdcNotification)));
79 buffer.append(System.lineSeparator());
82 return buffer.toString();
85 public static String dumpVfModuleMetaDataList(List<IVfModuleMetadata> moduleMetaDataList) {
86 if (moduleMetaDataList == null ) {
90 StringBuffer buffer = new StringBuffer();
93 for (IVfModuleMetadata moduleMetaData:moduleMetaDataList) {
94 buffer.append(System.lineSeparator());
95 buffer.append(testNull(dumpVfModuleMetaData(moduleMetaData)));
96 buffer.append(System.lineSeparator());
100 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
102 buffer.append(System.lineSeparator());
104 return buffer.toString();
107 private static String dumpVfModuleMetaData(IVfModuleMetadata moduleMetaData) {
109 if (moduleMetaData == null ) {
113 StringBuffer buffer = new StringBuffer("VfModuleMetaData:");
114 buffer.append(System.lineSeparator());
116 buffer.append("VfModuleModelName:");
117 buffer.append(testNull(moduleMetaData.getVfModuleModelName()));
118 buffer.append(System.lineSeparator());
120 buffer.append("VfModuleModelVersion:");
121 buffer.append(testNull(moduleMetaData.getVfModuleModelVersion()));
122 buffer.append(System.lineSeparator());
124 buffer.append("VfModuleModelUUID:");
125 buffer.append(testNull(moduleMetaData.getVfModuleModelUUID()));
126 buffer.append(System.lineSeparator());
128 buffer.append("VfModuleModelInvariantUUID:");
129 buffer.append(testNull(moduleMetaData.getVfModuleModelInvariantUUID()));
130 buffer.append(System.lineSeparator());
132 buffer.append("VfModuleModelDescription:");
133 buffer.append(testNull(moduleMetaData.getVfModuleModelDescription()));
134 buffer.append(System.lineSeparator());
136 buffer.append("Artifacts UUID List:");
138 if (moduleMetaData.getArtifacts() != null) {
141 for (String artifactUUID:moduleMetaData.getArtifacts()) {
142 buffer.append(System.lineSeparator());
143 buffer.append(testNull(artifactUUID));
144 buffer.append(System.lineSeparator());
147 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
149 buffer.append(System.lineSeparator());
151 buffer.append("NULL");
155 buffer.append(System.lineSeparator());
157 buffer.append("isBase:");
158 buffer.append(moduleMetaData.isBase());
159 buffer.append(System.lineSeparator());
161 return buffer.toString();
164 private static String testNull(Object object) {
165 if (object == null) {
167 } else if (object instanceof Integer) {
168 return object.toString();
169 } else if (object instanceof String) {
170 return (String)object;
172 return "Type not recognized";
176 private static String dumpASDCResourcesList(INotificationData asdcNotification) {
177 if (asdcNotification == null || asdcNotification.getResources() == null) {
181 StringBuffer buffer = new StringBuffer();
184 for (IResourceInstance resourceInstanceElem:asdcNotification.getResources()) {
185 buffer.append(System.lineSeparator());
186 buffer.append(testNull(dumpASDCResourceInstance(resourceInstanceElem)));
187 buffer.append(System.lineSeparator());
190 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
192 buffer.append(System.lineSeparator());
194 return buffer.toString();
198 private static String dumpASDCResourceInstance(IResourceInstance resourceInstance) {
200 if (resourceInstance == null) {
204 StringBuffer buffer = new StringBuffer("Resource Instance Info:");
205 buffer.append(System.lineSeparator());
207 buffer.append("ResourceInstanceName:");
208 buffer.append(testNull(resourceInstance.getResourceInstanceName()));
209 buffer.append(System.lineSeparator());
211 buffer.append("ResourceInvariantUUID:");
212 buffer.append(testNull(resourceInstance.getResourceInvariantUUID()));
213 buffer.append(System.lineSeparator());
215 buffer.append("ResourceName:");
216 buffer.append(testNull(resourceInstance.getResourceName()));
217 buffer.append(System.lineSeparator());
219 buffer.append("ResourceType:");
220 buffer.append(testNull(resourceInstance.getResourceType()));
221 buffer.append(System.lineSeparator());
223 buffer.append("ResourceUUID:");
224 buffer.append(testNull(resourceInstance.getResourceUUID()));
225 buffer.append(System.lineSeparator());
227 buffer.append("ResourceVersion:");
228 buffer.append(testNull(resourceInstance.getResourceVersion()));
229 buffer.append(System.lineSeparator());
231 buffer.append("Resource Artifacts List:");
232 buffer.append(System.lineSeparator());
233 buffer.append(testNull(dumpArtifactInfoList(resourceInstance.getArtifacts())));
234 buffer.append(System.lineSeparator());
236 return buffer.toString();
241 private static String dumpArtifactInfoList(List<IArtifactInfo> artifactsList) {
243 if (artifactsList == null || artifactsList.isEmpty()) {
247 StringBuffer buffer = new StringBuffer();
249 for (IArtifactInfo artifactInfoElem:artifactsList) {
250 buffer.append(System.lineSeparator());
251 buffer.append(testNull(dumpASDCArtifactInfo(artifactInfoElem)));
252 buffer.append(System.lineSeparator());
256 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
258 buffer.append(System.lineSeparator());
260 return buffer.toString();
263 private static String dumpASDCArtifactInfo(IArtifactInfo artifactInfo) {
265 if (artifactInfo == null) {
269 StringBuffer buffer = new StringBuffer("Service Artifacts Info:");
270 buffer.append(System.lineSeparator());
272 buffer.append("ArtifactName:");
273 buffer.append(testNull(artifactInfo.getArtifactName()));
274 buffer.append(System.lineSeparator());
276 buffer.append("ArtifactVersion:");
277 buffer.append(testNull(artifactInfo.getArtifactVersion()));
278 buffer.append(System.lineSeparator());
280 buffer.append("ArtifactType:");
281 buffer.append(testNull(artifactInfo.getArtifactType()));
282 buffer.append(System.lineSeparator());
284 buffer.append("ArtifactDescription:");
285 buffer.append(testNull(artifactInfo.getArtifactDescription()));
286 buffer.append(System.lineSeparator());
288 buffer.append("ArtifactTimeout:");
289 buffer.append(testNull(artifactInfo.getArtifactTimeout()));
290 buffer.append(System.lineSeparator());
292 buffer.append("ArtifactURL:");
293 buffer.append(testNull(artifactInfo.getArtifactURL()));
294 buffer.append(System.lineSeparator());
296 buffer.append("ArtifactUUID:");
297 buffer.append(testNull(artifactInfo.getArtifactUUID()));
298 buffer.append(System.lineSeparator());
300 buffer.append("ArtifactChecksum:");
301 buffer.append(testNull(artifactInfo.getArtifactChecksum()));
302 buffer.append(System.lineSeparator());
304 buffer.append("GeneratedArtifact:");
306 buffer.append(testNull(dumpASDCArtifactInfo(artifactInfo.getGeneratedArtifact())));
307 buffer.append(System.lineSeparator());
309 buffer.append(System.lineSeparator());
311 buffer.append("RelatedArtifacts:");
314 if (artifactInfo.getRelatedArtifacts() != null) {
316 buffer.append(System.lineSeparator());
317 for (IArtifactInfo artifactInfoElem:artifactInfo.getRelatedArtifacts()) {
319 buffer.append(testNull(dumpASDCArtifactInfo(artifactInfoElem)));
320 buffer.append(System.lineSeparator());
324 buffer.replace(buffer.length()-1,buffer.length(), System.lineSeparator());
326 buffer.append(System.lineSeparator());
328 buffer.append("NULL");
331 buffer.append(System.lineSeparator());
333 return buffer.toString();