2 d * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.so.asdc.client;
26 import java.io.FileOutputStream;
27 import java.io.IOException;
28 import java.io.UnsupportedEncodingException;
29 import java.util.ArrayList;
30 import java.util.List;
32 import org.onap.sdc.api.IDistributionClient;
33 import org.onap.sdc.api.consumer.IDistributionStatusMessage;
34 import org.onap.sdc.api.consumer.IFinalDistrStatusMessage;
35 import org.onap.sdc.api.notification.IArtifactInfo;
36 import org.onap.sdc.api.notification.INotificationData;
37 import org.onap.sdc.api.notification.IResourceInstance;
38 import org.onap.sdc.api.results.IDistributionClientDownloadResult;
39 import org.onap.sdc.api.results.IDistributionClientResult;
40 import org.onap.sdc.impl.DistributionClientFactory;
41 import org.onap.sdc.utils.DistributionActionResultEnum;
42 import org.onap.sdc.utils.DistributionStatusEnum;
43 import org.onap.so.asdc.client.exceptions.ASDCControllerException;
44 import org.onap.so.asdc.client.exceptions.ASDCDownloadException;
45 import org.onap.so.asdc.client.exceptions.ASDCParametersException;
46 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
47 import org.onap.so.asdc.installer.IVfResourceInstaller;
48 import org.onap.so.asdc.installer.ToscaResourceStructure;
49 import org.onap.so.asdc.installer.VfModuleStructure;
50 import org.onap.so.asdc.installer.VfResourceStructure;
51 import org.onap.so.asdc.installer.heat.ToscaResourceInstaller;
52 import org.onap.so.asdc.tenantIsolation.DistributionStatus;
53 import org.onap.so.asdc.tenantIsolation.WatchdogDistribution;
54 import org.onap.so.asdc.util.ASDCNotificationLogging;
55 import org.onap.so.db.request.beans.WatchdogDistributionStatus;
56 import org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository;
57 import org.onap.so.logger.MessageEnum;
58 import org.onap.so.logger.MsoAlarmLogger;
59 import org.onap.so.logger.MsoLogger;
60 import org.springframework.beans.factory.annotation.Autowired;
61 import org.springframework.stereotype.Component;
64 public class ASDCController {
66 protected static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.ASDC,ASDCController.class);
68 protected static MsoAlarmLogger alarmLogger = new MsoAlarmLogger ();
70 protected boolean isAsdcClientAutoManaged = false;
72 protected String controllerName;
74 private ASDCControllerStatus controllerStatus = ASDCControllerStatus.STOPPED;
76 protected int nbOfNotificationsOngoing = 0;
79 private ToscaResourceInstaller toscaInstaller;
82 private WatchdogDistributionStatusRepository wdsRepo;
85 private ASDCConfiguration asdcConfig;
88 private ASDCStatusCallBack asdcStatusCallBack;
91 private ASDCNotificationCallBack asdcNotificationCallBack;
93 private IDistributionClient distributionClient;
95 private static final String UUID_PARAM = "(UUID:";
98 private WatchdogDistribution wd;
101 public int getNbOfNotificationsOngoing () {
102 return nbOfNotificationsOngoing;
105 public IDistributionClient getDistributionClient() {
106 return distributionClient;
111 public void setDistributionClient(IDistributionClient distributionClient) {
112 this.distributionClient = distributionClient;
117 protected void changeControllerStatus (ASDCControllerStatus newControllerStatus) {
118 switch (newControllerStatus) {
121 ++this.nbOfNotificationsOngoing;
122 this.controllerStatus = newControllerStatus;
126 if (this.nbOfNotificationsOngoing > 1) {
127 --this.nbOfNotificationsOngoing;
129 this.nbOfNotificationsOngoing = 0;
130 this.controllerStatus = newControllerStatus;
135 this.controllerStatus = newControllerStatus;
141 public ASDCControllerStatus getControllerStatus () {
142 return this.controllerStatus;
145 public ASDCController () {
146 isAsdcClientAutoManaged = true;
149 public ASDCController (String controllerConfigName) {
150 isAsdcClientAutoManaged = true;
151 this.controllerName = controllerConfigName;
154 public ASDCController (String controllerConfigName, IDistributionClient asdcClient, IVfResourceInstaller resourceinstaller) {
155 distributionClient = asdcClient;
158 public ASDCController (String controllerConfigName,IDistributionClient asdcClient) {
159 distributionClient = asdcClient;
160 this.controllerName = controllerConfigName;
162 public String getControllerName() {
163 return controllerName;
166 public void setControllerName(String controllerName) {
167 this.controllerName = controllerName;
171 * This method initializes the ASDC Controller and the ASDC Client.
173 * @throws ASDCControllerException It throws an exception if the ASDC Client cannot be instantiated or if an init
174 * attempt is done when already initialized
175 * @throws ASDCParametersException If there is an issue with the parameters provided
176 * @throws IOException In case of issues when trying to load the key file
178 public void initASDC () throws ASDCControllerException {
179 String event = "Initialize the ASDC Controller";
180 MsoLogger.setServiceName ("InitASDC");
181 LOGGER.debug (event);
182 if (this.getControllerStatus () != ASDCControllerStatus.STOPPED) {
183 String endEvent = "The controller is already initialized, call the closeASDC method first";
184 throw new ASDCControllerException (endEvent);
187 if (asdcConfig != null) {
188 asdcConfig.setAsdcControllerName(controllerName);
191 if (this.distributionClient == null) {
192 distributionClient = DistributionClientFactory.createDistributionClient ();
195 long initStartTime = System.currentTimeMillis ();
196 IDistributionClientResult result = this.distributionClient.init (asdcConfig,
197 asdcNotificationCallBack, asdcStatusCallBack);
198 if (!result.getDistributionActionResult ().equals (DistributionActionResultEnum.SUCCESS)) {
199 String endEvent = "ASDC distribution client init failed with reason:"
200 + result.getDistributionMessageResult ();
201 LOGGER.recordMetricEvent (initStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.UnknownError, "Initialization of the ASDC Controller failed with reason:" + result.getDistributionMessageResult (), "ASDC", "init", null);
202 LOGGER.debug (endEvent);
203 this.changeControllerStatus (ASDCControllerStatus.STOPPED);
204 throw new ASDCControllerException ("Initialization of the ASDC Controller failed with reason: "
205 + result.getDistributionMessageResult ());
207 LOGGER.recordMetricEvent (initStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully initialize ASDC Controller", "ASDC", "init", null);
209 long clientstartStartTime = System.currentTimeMillis ();
210 result = this.distributionClient.start ();
211 if (!result.getDistributionActionResult ().equals (DistributionActionResultEnum.SUCCESS)) {
212 String endEvent = "ASDC distribution client start failed with reason:"
213 + result.getDistributionMessageResult ();
214 LOGGER.recordMetricEvent (clientstartStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.UnknownError, endEvent, "ASDC", "start", null);
215 LOGGER.debug (endEvent);
216 this.changeControllerStatus (ASDCControllerStatus.STOPPED);
217 throw new ASDCControllerException ("Startup of the ASDC Controller failed with reason: "
218 + result.getDistributionMessageResult ());
220 LOGGER.recordMetricEvent (clientstartStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully start ASDC distribution client", "ASDC", "start", null);
223 this.changeControllerStatus (ASDCControllerStatus.IDLE);
224 LOGGER.info (MessageEnum.ASDC_INIT_ASDC_CLIENT_SUC, "ASDC", "changeControllerStatus","");
228 * This method closes the ASDC Controller and the ASDC Client.
230 * @throws ASDCControllerException It throws an exception if the ASDC Client cannot be closed because
231 * it's currently BUSY in processing notifications.
233 public void closeASDC () throws ASDCControllerException {
235 MsoLogger.setServiceName ("CloseController");
236 if (this.getControllerStatus () == ASDCControllerStatus.BUSY) {
237 throw new ASDCControllerException ("Cannot close the ASDC controller as it's currently in BUSY state");
239 if (this.distributionClient != null) {
240 this.distributionClient.stop ();
241 // If auto managed we can set it to Null, ASDCController controls it.
242 // In the other case the client of this class has specified it, so we can't reset it
243 if (isAsdcClientAutoManaged) {
244 // Next init will initialize it with a new ASDC Client
245 this.distributionClient = null;
249 this.changeControllerStatus (ASDCControllerStatus.STOPPED);
252 private boolean checkResourceAlreadyDeployed (VfResourceStructure resource) throws ArtifactInstallerException {
255 if (toscaInstaller.isResourceAlreadyDeployed (resource)) {
256 LOGGER.info (MessageEnum.ASDC_ARTIFACT_ALREADY_EXIST,
257 resource.getResourceInstance().getResourceInstanceName(),
258 resource.getResourceInstance().getResourceUUID(),
259 resource.getResourceInstance().getResourceName(), "", "");
261 this.sendDeployNotificationsForResource(resource,DistributionStatusEnum.ALREADY_DOWNLOADED,null);
262 this.sendDeployNotificationsForResource(resource,DistributionStatusEnum.ALREADY_DEPLOYED,null);
272 protected IDistributionClientDownloadResult downloadTheArtifact (IArtifactInfo artifact,
273 String distributionId) throws ASDCDownloadException {
275 LOGGER.debug ("Trying to download the artifact : " + artifact.getArtifactURL ()
277 + artifact.getArtifactUUID ()
279 IDistributionClientDownloadResult downloadResult;
283 downloadResult = distributionClient.download (artifact);
284 if (null == downloadResult) {
285 LOGGER.info (MessageEnum.ASDC_ARTIFACT_NULL, artifact.getArtifactUUID (), "", "");
286 return downloadResult;
288 } catch (RuntimeException e) {
289 LOGGER.debug ("Not able to download the artifact due to an exception: " + artifact.getArtifactURL ());
290 this.sendASDCNotification (NotificationType.DOWNLOAD,
291 artifact.getArtifactURL (),
292 asdcConfig.getConsumerID (),
294 DistributionStatusEnum.DOWNLOAD_ERROR,
296 System.currentTimeMillis ());
298 throw new ASDCDownloadException ("Exception caught when downloading the artifact", e);
301 if (DistributionActionResultEnum.SUCCESS.equals(downloadResult.getDistributionActionResult ())) {
303 LOGGER.info (MessageEnum.ASDC_ARTIFACT_DOWNLOAD_SUC,
304 artifact.getArtifactURL (),
305 artifact.getArtifactUUID (),
306 String.valueOf (downloadResult.getArtifactPayload ().length), "", "");
310 LOGGER.error (MessageEnum.ASDC_ARTIFACT_DOWNLOAD_FAIL,
311 artifact.getArtifactName (),
312 artifact.getArtifactURL (),
313 artifact.getArtifactUUID (),
314 downloadResult.getDistributionMessageResult (), "", "", MsoLogger.ErrorCode.DataError, "ASDC artifact download fail");
316 this.sendASDCNotification (NotificationType.DOWNLOAD,
317 artifact.getArtifactURL (),
318 asdcConfig.getConsumerID (),
320 DistributionStatusEnum.DOWNLOAD_ERROR,
321 downloadResult.getDistributionMessageResult (),
322 System.currentTimeMillis ());
324 throw new ASDCDownloadException ("Artifact " + artifact.getArtifactName ()
325 + " could not be downloaded from ASDC URL "
326 + artifact.getArtifactURL ()
328 + artifact.getArtifactUUID ()
330 + System.lineSeparator ()
331 + "Error message is "
332 + downloadResult.getDistributionMessageResult ()
333 + System.lineSeparator ());
337 this.sendASDCNotification (NotificationType.DOWNLOAD,
338 artifact.getArtifactURL (),
339 asdcConfig.getConsumerID (),
341 DistributionStatusEnum.DOWNLOAD_OK,
343 System.currentTimeMillis ());
344 return downloadResult;
348 private void writeArtifactToFile (IArtifactInfo artifact,
349 IDistributionClientDownloadResult resultArtifact) {
351 LOGGER.debug ("Trying to write artifact to file : " + artifact.getArtifactURL ()
353 + artifact.getArtifactUUID ()
356 String filePath = System.getProperty("mso.config.path") + "/ASDC" + "/" + artifact.getArtifactVersion() + "/" + artifact.getArtifactName();
357 // make parent directory
358 File file = new File(filePath);
359 File fileParent = file.getParentFile();
360 if (!fileParent.exists()) {
364 byte[] payloadBytes = resultArtifact.getArtifactPayload();
366 try (FileOutputStream outFile = new FileOutputStream(filePath)) {
367 LOGGER.info(MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF, "***WRITE FILE ARTIFACT NAME", "ASDC", artifact.getArtifactName());
368 outFile.write(payloadBytes, 0, payloadBytes.length);
370 } catch (Exception e) {
371 LOGGER.debug("Exception :",e);
372 LOGGER.error(MessageEnum.ASDC_ARTIFACT_DOWNLOAD_FAIL,
373 artifact.getArtifactName (),
374 artifact.getArtifactURL (),
375 artifact.getArtifactUUID (),
376 resultArtifact.getDistributionMessageResult (), "", "", MsoLogger.ErrorCode.DataError, "ASDC write to file failed");
382 protected void sendDeployNotificationsForResource(VfResourceStructure vfResourceStructure,DistributionStatusEnum distribStatus, String errorReason) {
384 for (IArtifactInfo artifactInfo : vfResourceStructure.getResourceInstance().getArtifacts()) {
386 if ((DistributionStatusEnum.DEPLOY_OK.equals(distribStatus) && !artifactInfo.getArtifactType().equalsIgnoreCase("OTHER") && !vfResourceStructure.isAlreadyDeployed())
387 // This could be NULL if the artifact is a VF module artifact, this won't be present in the MAP
388 && vfResourceStructure.getArtifactsMapByUUID().get(artifactInfo.getArtifactUUID()) != null
389 && vfResourceStructure.getArtifactsMapByUUID().get(artifactInfo.getArtifactUUID()).getDeployedInDb() == 0) {
390 this.sendASDCNotification (NotificationType.DEPLOY,
391 artifactInfo.getArtifactURL (),
392 asdcConfig.getConsumerID (),
393 vfResourceStructure.getNotification().getDistributionID(),
394 DistributionStatusEnum.DEPLOY_ERROR,
395 "The artifact has not been used by the modules defined in the resource",
396 System.currentTimeMillis ());
398 this.sendASDCNotification (NotificationType.DEPLOY,
399 artifactInfo.getArtifactURL (),
400 asdcConfig.getConsumerID (),
401 vfResourceStructure.getNotification().getDistributionID(),
404 System.currentTimeMillis ());
409 protected void sendCsarDeployNotification(INotificationData iNotif, VfResourceStructure resourceStructure, ToscaResourceStructure toscaResourceStructure, boolean deploySuccessful, String errorReason) {
411 IArtifactInfo csarArtifact = toscaResourceStructure.getToscaArtifact();
413 if(deploySuccessful){
415 this.sendASDCNotification (NotificationType.DEPLOY,
416 csarArtifact.getArtifactURL (),
417 asdcConfig.getConsumerID (),
418 resourceStructure.getNotification().getDistributionID(),
419 DistributionStatusEnum.DEPLOY_OK,
421 System.currentTimeMillis ());
425 this.sendASDCNotification (NotificationType.DEPLOY,
426 csarArtifact.getArtifactURL (),
427 asdcConfig.getConsumerID (),
428 resourceStructure.getNotification().getDistributionID(),
429 DistributionStatusEnum.DEPLOY_ERROR,
431 System.currentTimeMillis ());
436 protected void deployResourceStructure (VfResourceStructure resourceStructure, ToscaResourceStructure toscaResourceStructure) throws ArtifactInstallerException {
438 LOGGER.info (MessageEnum.ASDC_START_DEPLOY_ARTIFACT, resourceStructure.getResourceInstance().getResourceInstanceName(), resourceStructure.getResourceInstance().getResourceUUID(), "ASDC");
440 String resourceType = resourceStructure.getResourceInstance().getResourceType();
441 String category = resourceStructure.getResourceInstance().getCategory();
442 if("VF".equals(resourceType) && !"Allotted Resource".equalsIgnoreCase(category)){
443 resourceStructure.createVfModuleStructures();
445 toscaInstaller.installTheResource(toscaResourceStructure, resourceStructure);
447 } catch (ArtifactInstallerException e) {
448 LOGGER.info (MessageEnum.ASDC_ARTIFACT_DOWNLOAD_FAIL,
449 resourceStructure.getResourceInstance().getResourceName(),
450 resourceStructure.getResourceInstance().getResourceUUID(),
451 String.valueOf (resourceStructure.getVfModuleStructure().size()), "ASDC", "deployResourceStructure");
452 sendDeployNotificationsForResource(resourceStructure,DistributionStatusEnum.DEPLOY_ERROR,e.getMessage());
456 if (resourceStructure.isDeployedSuccessfully() || toscaResourceStructure.isDeployedSuccessfully()) {
457 LOGGER.info (MessageEnum.ASDC_ARTIFACT_DEPLOY_SUC,
458 resourceStructure.getResourceInstance().getResourceName(),
459 resourceStructure.getResourceInstance().getResourceUUID(),
460 String.valueOf (resourceStructure.getVfModuleStructure().size()), "ASDC", "deployResourceStructure");
461 sendDeployNotificationsForResource(resourceStructure,DistributionStatusEnum.DEPLOY_OK ,null);
467 private enum NotificationType {
471 protected void sendASDCNotification (NotificationType notificationType,
474 String distributionID,
475 DistributionStatusEnum status,
479 String event = "Sending " + notificationType.name ()
483 + " notification to ASDC for artifact:"
486 if (errorReason != null) {
487 event=event+"("+errorReason+")";
489 LOGGER.info (MessageEnum.ASDC_SEND_NOTIF_ASDC, notificationType.name (), status.name (), artifactURL, "ASDC", "sendASDCNotification");
490 LOGGER.debug (event);
492 long subStarttime = System.currentTimeMillis ();
495 IDistributionStatusMessage message = new DistributionStatusMessage (artifactURL,
501 switch (notificationType) {
503 if (errorReason != null) {
504 this.distributionClient.sendDownloadStatus (message, errorReason);
506 this.distributionClient.sendDownloadStatus (message);
508 action = "sendDownloadStatus";
511 if (errorReason != null) {
512 this.distributionClient.sendDeploymentStatus (message, errorReason);
514 this.distributionClient.sendDeploymentStatus (message);
516 action = "sendDeploymentdStatus";
521 } catch (RuntimeException e) {
522 LOGGER.warn (MessageEnum.ASDC_SEND_NOTIF_ASDC_EXEC, "ASDC", "sendASDCNotification", MsoLogger.ErrorCode.SchemaError, "RuntimeException - sendASDCNotification", e);
524 LOGGER.recordMetricEvent (subStarttime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully sent notification to ASDC", "ASDC", action, null);
527 protected void sendFinalDistributionStatus (
528 String distributionID,
529 DistributionStatusEnum status,
530 String errorReason) {
533 LOGGER.debug ("Enter sendFinalDistributionStatus with DistributionID " + distributionID + " and Status of " + status.name() + " and ErrorReason " + errorReason);
535 long subStarttime = System.currentTimeMillis ();
539 IFinalDistrStatusMessage finalDistribution = new FinalDistributionStatusMessage(distributionID,status,subStarttime, asdcConfig.getConsumerID());
541 if(errorReason == null){
542 this.distributionClient.sendFinalDistrStatus(finalDistribution);
544 this.distributionClient.sendFinalDistrStatus(finalDistribution, errorReason);
548 } catch (RuntimeException e) {
549 LOGGER.debug ("Exception caught in sendFinalDistributionStatus " + e.getMessage());
550 LOGGER.warn (MessageEnum.ASDC_SEND_NOTIF_ASDC_EXEC, "ASDC", "sendASDCNotification", MsoLogger.ErrorCode.SchemaError, "RuntimeException - sendASDCNotification", e);
552 LOGGER.recordMetricEvent (subStarttime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully sent Final notification to ASDC", "ASDC", null, null);
555 public void treatNotification (INotificationData iNotif) {
557 int noOfArtifacts = 0;
560 for (IResourceInstance resource : iNotif.getResources ()) {
561 noOfArtifacts += resource.getArtifacts ().size ();
563 LOGGER.info (MessageEnum.ASDC_RECEIVE_CALLBACK_NOTIF,
564 String.valueOf (noOfArtifacts),
565 iNotif.getServiceUUID (), "ASDC");
568 LOGGER.debug(ASDCNotificationLogging.dumpASDCNotification(iNotif));
569 LOGGER.info(MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF, iNotif.getServiceUUID(), "ASDC", "treatNotification");
570 this.changeControllerStatus(ASDCControllerStatus.BUSY);
571 toscaInstaller.processWatchdog(iNotif.getDistributionID(),iNotif.getServiceUUID());
573 // Process only the Resource artifacts in MSO
574 this.processResourceNotification(iNotif);
576 //********************************************************************************************************
577 //Start Watchdog loop and wait for all components to complete before reporting final status back.
578 // **If timer expires first then we will report a Distribution Error back to ASDC
579 //********************************************************************************************************
580 long initialStartTime = System.currentTimeMillis();
581 boolean componentsComplete = false;
582 String distributionStatus = null;
583 String watchdogError = null;
584 String overallStatus = null;
585 int watchDogTimeout = asdcConfig.getWatchDogTimeout() * 1000;
586 boolean isDeploySuccess = false;
588 while(!componentsComplete && (System.currentTimeMillis() - initialStartTime) < watchDogTimeout)
592 distributionStatus = wd.getOverallDistributionStatus(iNotif.getDistributionID());
593 Thread.sleep(watchDogTimeout / 10);
595 LOGGER.debug ("Exception in Watchdog Loop " + e.getMessage());
596 Thread.sleep(watchDogTimeout / 10);
599 if(distributionStatus != null && !distributionStatus.equalsIgnoreCase(DistributionStatus.INCOMPLETE.name())){
601 if(distributionStatus.equalsIgnoreCase(DistributionStatus.SUCCESS.name())){
602 isDeploySuccess = true;
603 overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK.name();
605 overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name();
607 componentsComplete = true;
611 if(!componentsComplete){
612 LOGGER.debug("Timeout of " + watchDogTimeout + " seconds was reached before all components reported status");
613 watchdogError = "Timeout occurred while waiting for all components to report status";
614 overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name();
617 if(distributionStatus == null){
618 overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name();
619 LOGGER.debug("DistributionStatus is null for DistributionId: " + iNotif.getDistributionID());
623 wd.executePatchAAI(iNotif.getDistributionID(), iNotif.getServiceInvariantUUID(), overallStatus);
624 LOGGER.debug ("A&AI Updated succefully with Distribution Status!");
627 LOGGER.debug ("Exception in Watchdog executePatchAAI(): " + e.getMessage());
628 watchdogError = "Error calling A&AI " + e.getMessage();
629 if(e.getCause() != null) {
630 LOGGER.debug ("Exception caused by: " + e.getCause().getMessage());
635 if(isDeploySuccess && watchdogError == null){
636 sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK, null);
637 WatchdogDistributionStatus wds = new WatchdogDistributionStatus(iNotif.getDistributionID());
638 wds.setDistributionIdStatus(DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK.toString());
641 sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR, watchdogError);
642 WatchdogDistributionStatus wds = new WatchdogDistributionStatus(iNotif.getDistributionID());
643 wds.setDistributionIdStatus(DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.toString());
649 } catch (Exception e) {
650 LOGGER.error (MessageEnum.ASDC_GENERAL_EXCEPTION_ARG,
651 "Unexpected exception caught during the notification processing", "ASDC", "treatNotification", MsoLogger.ErrorCode.SchemaError, "RuntimeException in treatNotification",
655 wd.executePatchAAI(iNotif.getDistributionID(), iNotif.getServiceInvariantUUID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name());
656 LOGGER.debug ("A&AI Updated succefully with Distribution Status of " + DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name());
658 catch(Exception aaiException) {
659 LOGGER.debug ("Exception in executePatchAAI(): " + aaiException.getMessage());
660 if(aaiException.getCause() != null) {
661 LOGGER.debug ("Exception caused by: " + aaiException.getCause().getMessage());
665 sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR, e.getMessage());
667 WatchdogDistributionStatus wds = new WatchdogDistributionStatus(iNotif.getDistributionID());
668 wds.setDistributionIdStatus(DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.toString());
672 this.changeControllerStatus (ASDCControllerStatus.IDLE);
676 protected void processResourceNotification (INotificationData iNotif) {
677 // For each artifact, create a structure describing the VFModule in a ordered flat level
678 VfResourceStructure resourceStructure = null;
679 ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
680 boolean deploySuccessful = true;
681 String errorMessage = null;
685 this.processCsarServiceArtifacts(iNotif, toscaResourceStructure);
687 // Install a service with no resources, only the service itself
688 if (iNotif.getResources() == null || iNotif.getResources().size() < 1) {
690 LOGGER.debug("No resources found for Service: " + iNotif.getServiceUUID());
693 resourceStructure = new VfResourceStructure(iNotif,new ResourceInstance());
695 this.deployResourceStructure(resourceStructure, toscaResourceStructure);
697 } catch(ArtifactInstallerException e){
698 deploySuccessful = false;
699 errorMessage = e.getMessage();
701 } else { // Services with resources
703 for (IResourceInstance resource : iNotif.getResources()){
705 resourceStructure = new VfResourceStructure(iNotif,resource);
707 String resourceType = resourceStructure.getResourceInstance().getResourceType();
708 String category = resourceStructure.getResourceInstance().getCategory();
710 LOGGER.debug("Processing Resource Type: " + resourceType + " and Model UUID: " + resourceStructure.getResourceInstance().getResourceUUID());
712 if("VF".equals(resourceType) && !"Allotted Resource".equalsIgnoreCase(category)){
714 for (IArtifactInfo artifact : resource.getArtifacts()) {
715 IDistributionClientDownloadResult resultArtifact = this.downloadTheArtifact(artifact,
716 iNotif.getDistributionID());
717 if (resultArtifact != null) {
718 if (ASDCConfiguration.VF_MODULES_METADATA.equals(artifact.getArtifactType())) {
719 LOGGER.debug("VF_MODULE_ARTIFACT: "+new String(resultArtifact.getArtifactPayload(),"UTF-8"));
720 LOGGER.debug(ASDCNotificationLogging.dumpVfModuleMetaDataList(resourceStructure.decodeVfModuleArtifact(resultArtifact.getArtifactPayload())));
722 resourceStructure.addArtifactToStructure(distributionClient,artifact, resultArtifact);
727 //Deploy All resources and artifacts
728 LOGGER.debug("Preparing to deploy Service: " + iNotif.getServiceUUID());
731 this.deployResourceStructure(resourceStructure, toscaResourceStructure);
733 } catch(ArtifactInstallerException e){
734 deploySuccessful = false;
735 errorMessage = e.getMessage();
740 this.sendCsarDeployNotification(iNotif, resourceStructure, toscaResourceStructure, deploySuccessful, errorMessage);
742 } catch (ASDCDownloadException | UnsupportedEncodingException e) {
743 LOGGER.error(MessageEnum.ASDC_GENERAL_EXCEPTION_ARG,
744 "Exception caught during Installation of artifact", "ASDC", "processResourceNotification", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in processResourceNotification", e);
747 protected void processCsarServiceArtifacts (INotificationData iNotif, ToscaResourceStructure toscaResourceStructure) {
749 List<IArtifactInfo> serviceArtifacts = iNotif.getServiceArtifacts();
751 for(IArtifactInfo artifact : serviceArtifacts){
753 if(artifact.getArtifactType().equals(ASDCConfiguration.TOSCA_CSAR)){
757 toscaResourceStructure.setToscaArtifact(artifact);
759 IDistributionClientDownloadResult resultArtifact = this.downloadTheArtifact(artifact,iNotif.getDistributionID());
761 writeArtifactToFile(artifact, resultArtifact);
763 toscaResourceStructure.updateResourceStructure(artifact);
765 toscaResourceStructure.setServiceVersion(iNotif.getServiceVersion());
767 LOGGER.debug(ASDCNotificationLogging.dumpCSARNotification(iNotif, toscaResourceStructure));
770 } catch(Exception e){
771 LOGGER.error(MessageEnum.ASDC_GENERAL_EXCEPTION_ARG,
772 "Exception caught during processCsarServiceArtifacts", "ASDC", "processCsarServiceArtifacts", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in processCsarServiceArtifacts", e);
779 private static final String UNKNOWN="Unknown";
782 * @return the address of the ASDC we are connected to.
784 public String getAddress () {
785 if (asdcConfig != null) {
786 return asdcConfig.getAsdcAddress ();
792 * @return the environment name of the ASDC we are connected to.
794 public String getEnvironment () {
795 if (asdcConfig != null) {
796 return asdcConfig.getEnvironmentName ();