2 * ============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 * Modifications Copyright (c) 2019 Samsung
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.so.asdc.client;
27 import com.fasterxml.jackson.annotation.JsonInclude.Include;
28 import com.fasterxml.jackson.core.JsonProcessingException;
29 import com.fasterxml.jackson.databind.DeserializationFeature;
30 import com.fasterxml.jackson.databind.MapperFeature;
31 import com.fasterxml.jackson.databind.ObjectMapper;
33 import java.io.FileOutputStream;
34 import java.io.IOException;
35 import java.io.UnsupportedEncodingException;
36 import java.nio.file.Paths;
37 import java.util.List;
38 import java.util.Optional;
39 import org.onap.sdc.api.IDistributionClient;
40 import org.onap.sdc.api.consumer.IDistributionStatusMessage;
41 import org.onap.sdc.api.consumer.IFinalDistrStatusMessage;
42 import org.onap.sdc.api.notification.IArtifactInfo;
43 import org.onap.sdc.api.notification.INotificationData;
44 import org.onap.sdc.api.notification.IResourceInstance;
45 import org.onap.sdc.api.results.IDistributionClientDownloadResult;
46 import org.onap.sdc.api.results.IDistributionClientResult;
47 import org.onap.sdc.impl.DistributionClientFactory;
48 import org.onap.sdc.utils.DistributionActionResultEnum;
49 import org.onap.sdc.utils.DistributionStatusEnum;
50 import org.onap.so.asdc.client.exceptions.ASDCControllerException;
51 import org.onap.so.asdc.client.exceptions.ASDCDownloadException;
52 import org.onap.so.asdc.client.exceptions.ASDCParametersException;
53 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
54 import org.onap.so.asdc.installer.IVfResourceInstaller;
55 import org.onap.so.asdc.installer.PnfResourceStructure;
56 import org.onap.so.asdc.installer.ResourceStructure;
57 import org.onap.so.asdc.installer.ResourceType;
58 import org.onap.so.asdc.installer.ToscaResourceStructure;
59 import org.onap.so.asdc.installer.VfResourceStructure;
60 import org.onap.so.asdc.installer.bpmn.BpmnInstaller;
61 import org.onap.so.asdc.installer.heat.ToscaResourceInstaller;
62 import org.onap.so.asdc.tenantIsolation.DistributionStatus;
63 import org.onap.so.asdc.tenantIsolation.WatchdogDistribution;
64 import org.onap.so.asdc.util.ASDCNotificationLogging;
65 import org.onap.so.db.request.beans.WatchdogDistributionStatus;
66 import org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository;
67 import org.onap.so.logger.ErrorCode;
68 import org.onap.so.logger.MessageEnum;
69 import org.slf4j.Logger;
70 import org.slf4j.LoggerFactory;
71 import org.springframework.beans.factory.annotation.Autowired;
72 import org.springframework.orm.ObjectOptimisticLockingFailureException;
73 import org.springframework.stereotype.Component;
76 public class ASDCController {
78 protected static final Logger logger = LoggerFactory.getLogger(ASDCController.class);
80 protected boolean isAsdcClientAutoManaged = false;
82 protected String controllerName;
84 private ASDCControllerStatus controllerStatus = ASDCControllerStatus.STOPPED;
86 protected int nbOfNotificationsOngoing = 0;
89 private ToscaResourceInstaller toscaInstaller;
92 private BpmnInstaller bpmnInstaller;
95 private WatchdogDistributionStatusRepository wdsRepo;
98 private ASDCConfiguration asdcConfig;
101 private ASDCStatusCallBack asdcStatusCallBack;
104 private ASDCNotificationCallBack asdcNotificationCallBack;
106 private IDistributionClient distributionClient;
108 private static final String UUID_PARAM = "(UUID:";
111 private WatchdogDistribution wd;
113 public int getNbOfNotificationsOngoing() {
114 return nbOfNotificationsOngoing;
117 public IDistributionClient getDistributionClient() {
118 return distributionClient;
121 public void setDistributionClient(IDistributionClient distributionClient) {
122 this.distributionClient = distributionClient;
125 protected void changeControllerStatus(ASDCControllerStatus newControllerStatus) {
126 switch (newControllerStatus) {
129 ++this.nbOfNotificationsOngoing;
130 this.controllerStatus = newControllerStatus;
134 if (this.nbOfNotificationsOngoing > 1) {
135 --this.nbOfNotificationsOngoing;
137 this.nbOfNotificationsOngoing = 0;
138 this.controllerStatus = newControllerStatus;
143 this.controllerStatus = newControllerStatus;
149 public ASDCControllerStatus getControllerStatus() {
150 return this.controllerStatus;
153 public ASDCController() {
157 public ASDCController(String controllerConfigName) {
158 isAsdcClientAutoManaged = true;
159 this.controllerName = controllerConfigName;
162 public ASDCController(String controllerConfigName, IDistributionClient asdcClient,
163 IVfResourceInstaller resourceinstaller) {
164 distributionClient = asdcClient;
167 public ASDCController(String controllerConfigName, IDistributionClient asdcClient) {
168 distributionClient = asdcClient;
169 this.controllerName = controllerConfigName;
172 public String getControllerName() {
173 return controllerName;
176 public void setControllerName(String controllerName) {
177 this.controllerName = controllerName;
181 * This method initializes the ASDC Controller and the ASDC Client.
183 * @throws ASDCControllerException It throws an exception if the ASDC Client cannot be instantiated or if an init
184 * attempt is done when already initialized
185 * @throws ASDCParametersException If there is an issue with the parameters provided
186 * @throws IOException In case of issues when trying to load the key file
188 public void initASDC() throws ASDCControllerException {
189 String event = "Initialize the ASDC Controller";
191 if (this.getControllerStatus() != ASDCControllerStatus.STOPPED) {
192 String endEvent = "The controller is already initialized, call the closeASDC method first";
193 throw new ASDCControllerException(endEvent);
196 if (asdcConfig != null) {
197 asdcConfig.setAsdcControllerName(controllerName);
200 if (this.distributionClient == null) {
201 distributionClient = DistributionClientFactory.createDistributionClient();
204 IDistributionClientResult result =
205 this.distributionClient.init(asdcConfig, asdcNotificationCallBack, asdcStatusCallBack);
206 if (!result.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
208 "ASDC distribution client init failed with reason:" + result.getDistributionMessageResult();
209 logger.debug(endEvent);
210 this.changeControllerStatus(ASDCControllerStatus.STOPPED);
211 throw new ASDCControllerException("Initialization of the ASDC Controller failed with reason: "
212 + result.getDistributionMessageResult());
215 result = this.distributionClient.start();
216 if (!result.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
218 "ASDC distribution client start failed with reason:" + result.getDistributionMessageResult();
219 logger.debug(endEvent);
220 this.changeControllerStatus(ASDCControllerStatus.STOPPED);
221 throw new ASDCControllerException(
222 "Startup of the ASDC Controller failed with reason: " + result.getDistributionMessageResult());
225 this.changeControllerStatus(ASDCControllerStatus.IDLE);
226 logger.info("{} {} {}", MessageEnum.ASDC_INIT_ASDC_CLIENT_SUC.toString(), "ASDC", "changeControllerStatus");
230 * This method closes the ASDC Controller and the ASDC Client.
232 * @throws ASDCControllerException It throws an exception if the ASDC Client cannot be closed because it's currently
233 * BUSY in processing notifications.
235 public void closeASDC() throws ASDCControllerException {
237 if (this.getControllerStatus() == ASDCControllerStatus.BUSY) {
238 throw new ASDCControllerException("Cannot close the ASDC controller as it's currently in BUSY state");
240 if (this.distributionClient != null) {
241 this.distributionClient.stop();
242 // If auto managed we can set it to Null, ASDCController controls it.
243 // In the other case the client of this class has specified it, so we can't reset it
244 if (isAsdcClientAutoManaged) {
245 // Next init will initialize it with a new ASDC Client
246 this.distributionClient = null;
250 this.changeControllerStatus(ASDCControllerStatus.STOPPED);
253 protected boolean checkResourceAlreadyDeployed(ResourceStructure resource, boolean serviceDeployed)
254 throws ArtifactInstallerException {
257 if (toscaInstaller.isResourceAlreadyDeployed(resource, serviceDeployed)) {
258 logger.info("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_ALREADY_EXIST.toString(),
259 resource.getResourceInstance().getResourceInstanceName(),
260 resource.getResourceInstance().getResourceUUID(), resource.getResourceInstance().getResourceName());
262 this.sendDeployNotificationsForResource(resource, DistributionStatusEnum.ALREADY_DOWNLOADED, null);
263 this.sendDeployNotificationsForResource(resource, DistributionStatusEnum.ALREADY_DEPLOYED, null);
272 protected IDistributionClientDownloadResult downloadTheArtifact(IArtifactInfo artifact, String distributionId)
273 throws ASDCDownloadException {
275 logger.info("Trying to download the artifact UUID: {} from URL: {}", artifact.getArtifactUUID(),
276 artifact.getArtifactURL());
277 IDistributionClientDownloadResult downloadResult;
280 downloadResult = distributionClient.download(artifact);
281 if (null == downloadResult) {
282 logger.info("{} {}", MessageEnum.ASDC_ARTIFACT_NULL.toString(), artifact.getArtifactUUID());
283 return downloadResult;
285 } catch (RuntimeException e) {
286 logger.debug("Not able to download the artifact due to an exception: " + artifact.getArtifactURL());
287 this.sendASDCNotification(NotificationType.DOWNLOAD, artifact.getArtifactURL(), asdcConfig.getConsumerID(),
288 distributionId, DistributionStatusEnum.DOWNLOAD_ERROR, e.getMessage(), System.currentTimeMillis());
290 throw new ASDCDownloadException("Exception caught when downloading the artifact", e);
293 if (DistributionActionResultEnum.SUCCESS.equals(downloadResult.getDistributionActionResult())) {
294 logger.info("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_DOWNLOAD_SUC.toString(), artifact.getArtifactURL(),
295 artifact.getArtifactUUID(), String.valueOf(downloadResult.getArtifactPayload().length));
298 logger.error("{} {} {} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_DOWNLOAD_FAIL.toString(),
299 artifact.getArtifactName(), artifact.getArtifactURL(), artifact.getArtifactUUID(),
300 downloadResult.getDistributionMessageResult(), ErrorCode.DataError.getValue(),
301 "ASDC artifact download fail");
303 this.sendASDCNotification(NotificationType.DOWNLOAD, artifact.getArtifactURL(), asdcConfig.getConsumerID(),
304 distributionId, DistributionStatusEnum.DOWNLOAD_ERROR,
305 downloadResult.getDistributionMessageResult(), System.currentTimeMillis());
307 throw new ASDCDownloadException("Artifact " + artifact.getArtifactName()
308 + " could not be downloaded from ASDC URL " + artifact.getArtifactURL() + UUID_PARAM
309 + artifact.getArtifactUUID() + ")" + System.lineSeparator() + "Error message is "
310 + downloadResult.getDistributionMessageResult() + System.lineSeparator());
314 this.sendASDCNotification(NotificationType.DOWNLOAD, artifact.getArtifactURL(), asdcConfig.getConsumerID(),
315 distributionId, DistributionStatusEnum.DOWNLOAD_OK, null, System.currentTimeMillis());
316 return downloadResult;
320 private void writeArtifactToFile(IArtifactInfo artifact, IDistributionClientDownloadResult resultArtifact) {
323 Paths.get(getMsoConfigPath(), "ASDC", artifact.getArtifactVersion(), artifact.getArtifactName())
324 .normalize().toString();
326 logger.info("Trying to write artifact UUID: {}, URL: {} to file: {}", artifact.getArtifactUUID(),
327 artifact.getArtifactURL(), filePath);
329 // make parent directory
330 File file = new File(filePath);
331 File fileParent = file.getParentFile();
332 if (!fileParent.exists()) {
336 byte[] payloadBytes = resultArtifact.getArtifactPayload();
338 try (FileOutputStream outFile = new FileOutputStream(filePath)) {
339 logger.info("{} {} {} {}", MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF.toString(), "***WRITE FILE ARTIFACT NAME",
340 "ASDC", artifact.getArtifactName());
341 outFile.write(payloadBytes, 0, payloadBytes.length);
342 } catch (Exception e) {
343 logger.debug("Exception :", e);
344 logger.error("{} {} {} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_DOWNLOAD_FAIL.toString(),
345 artifact.getArtifactName(), artifact.getArtifactURL(), artifact.getArtifactUUID(),
346 resultArtifact.getDistributionMessageResult(), ErrorCode.DataError.getValue(),
347 "ASDC write to file failed");
353 protected void sendDeployNotificationsForResource(ResourceStructure resourceStructure,
354 DistributionStatusEnum distribStatus, String errorReason) {
356 for (IArtifactInfo artifactInfo : resourceStructure.getResourceInstance().getArtifacts()) {
358 if ((DistributionStatusEnum.DEPLOY_OK.equals(distribStatus)
359 && !artifactInfo.getArtifactType().equalsIgnoreCase("OTHER")
360 && !resourceStructure.isAlreadyDeployed())
361 // This could be NULL if the artifact is a VF module artifact, this won't be present in the MAP
362 && resourceStructure.getArtifactsMapByUUID().get(artifactInfo.getArtifactUUID()) != null
363 && resourceStructure.getArtifactsMapByUUID().get(artifactInfo.getArtifactUUID())
364 .getDeployedInDb() == 0) {
365 this.sendASDCNotification(NotificationType.DEPLOY, artifactInfo.getArtifactURL(),
366 asdcConfig.getConsumerID(), resourceStructure.getNotification().getDistributionID(),
367 DistributionStatusEnum.DEPLOY_ERROR,
368 "The artifact has not been used by the modules defined in the resource",
369 System.currentTimeMillis());
371 this.sendASDCNotification(NotificationType.DEPLOY, artifactInfo.getArtifactURL(),
372 asdcConfig.getConsumerID(), resourceStructure.getNotification().getDistributionID(),
373 distribStatus, errorReason, System.currentTimeMillis());
378 protected void sendCsarDeployNotification(INotificationData iNotif, ResourceStructure resourceStructure,
379 ToscaResourceStructure toscaResourceStructure, boolean deploySuccessful, String errorReason) {
381 IArtifactInfo csarArtifact = toscaResourceStructure.getToscaArtifact();
383 if (deploySuccessful) {
385 this.sendASDCNotification(NotificationType.DEPLOY, csarArtifact.getArtifactURL(),
386 asdcConfig.getConsumerID(), resourceStructure.getNotification().getDistributionID(),
387 DistributionStatusEnum.DEPLOY_OK, errorReason, System.currentTimeMillis());
391 this.sendASDCNotification(NotificationType.DEPLOY, csarArtifact.getArtifactURL(),
392 asdcConfig.getConsumerID(), resourceStructure.getNotification().getDistributionID(),
393 DistributionStatusEnum.DEPLOY_ERROR, errorReason, System.currentTimeMillis());
398 protected void deployResourceStructure(ResourceStructure resourceStructure,
399 ToscaResourceStructure toscaResourceStructure) throws ArtifactInstallerException {
401 logger.info("{} {} {} {}", MessageEnum.ASDC_START_DEPLOY_ARTIFACT.toString(),
402 resourceStructure.getResourceInstance().getResourceInstanceName(),
403 resourceStructure.getResourceInstance().getResourceUUID(), "ASDC");
405 resourceStructure.prepareInstall();
406 toscaInstaller.installTheResource(toscaResourceStructure, resourceStructure);
408 } catch (ArtifactInstallerException e) {
409 logger.info("{} {} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_DOWNLOAD_FAIL.toString(),
410 resourceStructure.getResourceInstance().getResourceName(),
411 resourceStructure.getResourceInstance().getResourceUUID(),
412 String.valueOf(resourceStructure.getNumberOfResources()), "ASDC", "deployResourceStructure");
413 sendDeployNotificationsForResource(resourceStructure, DistributionStatusEnum.DEPLOY_ERROR, e.getMessage());
417 if (resourceStructure.isDeployedSuccessfully() || toscaResourceStructure.isDeployedSuccessfully()) {
418 logger.info("{} {} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_DEPLOY_SUC.toString(),
419 resourceStructure.getResourceInstance().getResourceName(),
420 resourceStructure.getResourceInstance().getResourceUUID(),
421 String.valueOf(resourceStructure.getNumberOfResources()), "ASDC", "deployResourceStructure");
422 sendDeployNotificationsForResource(resourceStructure, DistributionStatusEnum.DEPLOY_OK, null);
428 private enum NotificationType {
432 protected void sendASDCNotification(NotificationType notificationType, String artifactURL, String consumerID,
433 String distributionID, DistributionStatusEnum status, String errorReason, long timestamp) {
435 String event = "Sending " + notificationType.name() + "(" + status.name() + ")"
436 + " notification to ASDC for artifact:" + artifactURL;
438 if (errorReason != null) {
439 event = event + "(" + errorReason + ")";
441 logger.info("{} {} {} {} {} {}", MessageEnum.ASDC_SEND_NOTIF_ASDC.toString(), notificationType.name(),
442 status.name(), artifactURL, "ASDC", "sendASDCNotification");
447 IDistributionStatusMessage message =
448 new DistributionStatusMessage(artifactURL, consumerID, distributionID, status, timestamp);
450 switch (notificationType) {
452 if (errorReason != null) {
453 this.distributionClient.sendDownloadStatus(message, errorReason);
455 this.distributionClient.sendDownloadStatus(message);
457 action = "sendDownloadStatus";
460 if (errorReason != null) {
461 this.distributionClient.sendDeploymentStatus(message, errorReason);
463 this.distributionClient.sendDeploymentStatus(message);
465 action = "sendDeploymentdStatus";
470 } catch (RuntimeException e) {
471 logger.warn("{} {} {} {} {}", MessageEnum.ASDC_SEND_NOTIF_ASDC_EXEC.toString(), "ASDC",
472 "sendASDCNotification", ErrorCode.SchemaError.getValue(), "RuntimeException - sendASDCNotification",
477 protected void sendFinalDistributionStatus(String distributionID, DistributionStatusEnum status,
478 String errorReason) {
480 logger.debug("Enter sendFinalDistributionStatus with DistributionID " + distributionID + " and Status of "
481 + status.name() + " and ErrorReason " + errorReason);
483 long subStarttime = System.currentTimeMillis();
486 IFinalDistrStatusMessage finalDistribution = new FinalDistributionStatusMessage(distributionID, status,
487 subStarttime, asdcConfig.getConsumerID());
489 if (errorReason == null) {
490 this.distributionClient.sendFinalDistrStatus(finalDistribution);
492 this.distributionClient.sendFinalDistrStatus(finalDistribution, errorReason);
496 } catch (RuntimeException e) {
497 logger.debug("Exception caught in sendFinalDistributionStatus {}", e.getMessage());
498 logger.warn("{} {} {} {} {}", MessageEnum.ASDC_SEND_NOTIF_ASDC_EXEC.toString(), "ASDC",
499 "sendASDCNotification", ErrorCode.SchemaError.getValue(), "RuntimeException - sendASDCNotification",
504 private Optional<String> getNotificationJson(INotificationData iNotif) {
505 ObjectMapper mapper = new ObjectMapper();
506 mapper.setSerializationInclusion(Include.NON_NULL);
507 mapper.setSerializationInclusion(Include.NON_EMPTY);
508 mapper.setSerializationInclusion(Include.NON_ABSENT);
509 mapper.enable(MapperFeature.USE_ANNOTATIONS);
510 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
511 Optional<String> returnValue = Optional.empty();
513 returnValue = Optional.of(mapper.writeValueAsString(iNotif));
514 } catch (JsonProcessingException e) {
515 logger.error("Error converting incoming ASDC notification to JSON", e);
520 public void treatNotification(INotificationData iNotif) {
522 int noOfArtifacts = 0;
524 for (IResourceInstance resource : iNotif.getResources()) {
525 noOfArtifacts += resource.getArtifacts().size();
527 logger.info("{} {} {} {}", MessageEnum.ASDC_RECEIVE_CALLBACK_NOTIF.toString(), String.valueOf(noOfArtifacts),
528 iNotif.getServiceUUID(), "ASDC");
530 logger.debug(ASDCNotificationLogging.dumpASDCNotification(iNotif));
531 logger.info("{} {} {} {}", MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF.toString(), iNotif.getServiceUUID(),
532 "ASDC", "treatNotification");
534 this.changeControllerStatus(ASDCControllerStatus.BUSY);
535 Optional<String> notificationMessage = getNotificationJson(iNotif);
536 toscaInstaller.processWatchdog(iNotif.getDistributionID(), iNotif.getServiceUUID(), notificationMessage,
537 asdcConfig.getConsumerID());
539 // Process only the Resource artifacts in MSO
540 this.processResourceNotification(iNotif);
542 // ********************************************************************************************************
543 // Start Watchdog loop and wait for all components to complete before reporting final status back.
544 // **If timer expires first then we will report a Distribution Error back to ASDC
545 // ********************************************************************************************************
546 long initialStartTime = System.currentTimeMillis();
547 boolean componentsComplete = false;
548 String distributionStatus = null;
549 String watchdogError = null;
550 String overallStatus = null;
551 int watchDogTimeout = asdcConfig.getWatchDogTimeout() * 1000;
552 boolean isDeploySuccess = false;
554 while (!componentsComplete && (System.currentTimeMillis() - initialStartTime) < watchDogTimeout) {
557 distributionStatus = wd.getOverallDistributionStatus(iNotif.getDistributionID());
558 Thread.sleep(watchDogTimeout / 10);
559 } catch (Exception e) {
560 logger.debug("Exception in Watchdog Loop {}", e.getMessage());
561 Thread.sleep(watchDogTimeout / 10);
564 if (distributionStatus != null
565 && !distributionStatus.equalsIgnoreCase(DistributionStatus.INCOMPLETE.name())) {
567 if (distributionStatus.equalsIgnoreCase(DistributionStatus.SUCCESS.name())) {
568 isDeploySuccess = true;
569 overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK.name();
571 overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name();
573 componentsComplete = true;
577 if (!componentsComplete) {
578 logger.debug("Timeout of {} seconds was reached before all components reported status",
580 watchdogError = "Timeout occurred while waiting for all components to report status";
581 overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name();
584 if (distributionStatus == null) {
585 overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name();
586 logger.debug("DistributionStatus is null for DistributionId: {}", iNotif.getDistributionID());
590 wd.executePatchAAI(iNotif.getDistributionID(), iNotif.getServiceInvariantUUID(), overallStatus);
591 logger.debug("A&AI Updated succefully with Distribution Status!");
592 } catch (Exception e) {
593 logger.debug("Exception in Watchdog executePatchAAI(): {}", e.getMessage());
594 watchdogError = "Error calling A&AI " + e.getMessage();
595 if (e.getCause() != null) {
596 logger.debug("Exception caused by: {}", e.getCause().getMessage());
600 if (isDeploySuccess && watchdogError == null) {
601 sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK,
603 WatchdogDistributionStatus wds = new WatchdogDistributionStatus(iNotif.getDistributionID());
604 wds.setDistributionIdStatus(DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK.toString());
607 sendFinalDistributionStatus(iNotif.getDistributionID(),
608 DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR, watchdogError);
609 WatchdogDistributionStatus wds = new WatchdogDistributionStatus(iNotif.getDistributionID());
610 wds.setDistributionIdStatus(DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.toString());
615 } catch (ObjectOptimisticLockingFailureException e) {
618 "OptimisticLockingFailure for DistributionId: {} Another process "
619 + "has already altered this distribution, so not going to process it on this site.",
620 iNotif.getDistributionID());
621 logger.error("{} {} {} {} {} {}", MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(),
622 "Database concurrency exception: ", "ASDC", "treatNotification",
623 ErrorCode.BusinessProcesssError.getValue(), "RuntimeException in treatNotification", e);
625 } catch (Exception e) {
626 logger.error("", MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(),
627 "Unexpected exception caught during the notification processing", "ASDC", "treatNotification",
628 ErrorCode.SchemaError.getValue(), "RuntimeException in treatNotification", e);
631 wd.executePatchAAI(iNotif.getDistributionID(), iNotif.getServiceInvariantUUID(),
632 DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name());
633 logger.debug("A&AI Updated succefully with Distribution Status of {}",
634 DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name());
635 } catch (Exception aaiException) {
636 logger.debug("Exception in executePatchAAI(): {}", aaiException);
637 if (aaiException.getCause() != null) {
638 logger.debug("Exception caused by: {}", aaiException.getCause().getMessage());
642 sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR,
645 WatchdogDistributionStatus wds = new WatchdogDistributionStatus(iNotif.getDistributionID());
646 wds.setDistributionIdStatus(DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.toString());
650 this.changeControllerStatus(ASDCControllerStatus.IDLE);
654 protected void processResourceNotification(INotificationData iNotif) {
655 // For each artifact, create a structure describing the VFModule in a ordered flat level
656 ResourceStructure resourceStructure = null;
657 String msoConfigPath = getMsoConfigPath();
658 boolean hasVFResource = false;
659 ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure(msoConfigPath);
660 boolean deploySuccessful = true;
661 String errorMessage = null;
662 boolean serviceDeployed = false;
665 this.processCsarServiceArtifacts(iNotif, toscaResourceStructure);
666 IArtifactInfo iArtifact = toscaResourceStructure.getToscaArtifact();
668 msoConfigPath + "/ASDC/" + iArtifact.getArtifactVersion() + "/" + iArtifact.getArtifactName();
669 File csarFile = new File(filePath);
670 String csarFilePath = csarFile.getAbsolutePath();
671 if (bpmnInstaller.containsWorkflows(csarFilePath)) {
672 bpmnInstaller.installBpmn(csarFilePath);
675 for (IResourceInstance resource : iNotif.getResources()) {
677 String resourceType = resource.getResourceType();
678 String category = resource.getCategory();
680 logger.info("Processing Resource Type: {}, Model UUID: {}", resourceType, resource.getResourceUUID());
682 if ("VF".equals(resourceType) && !"Allotted Resource".equalsIgnoreCase(category)) {
683 resourceStructure = new VfResourceStructure(iNotif, resource);
684 } else if ("PNF".equals(resourceType)) {
685 resourceStructure = new PnfResourceStructure(iNotif, resource);
687 // There are cases where the Service has no VF resources, those are handled here
688 logger.info("No resources found for Service: {}", iNotif.getServiceUUID());
689 resourceStructure = new VfResourceStructure(iNotif, new ResourceInstance());
690 resourceStructure.setResourceType(ResourceType.OTHER);
695 if (!this.checkResourceAlreadyDeployed(resourceStructure, serviceDeployed)) {
697 logger.debug("Processing Resource Type: " + resourceType + " and Model UUID: "
698 + resourceStructure.getResourceInstance().getResourceUUID());
700 if ("VF".equals(resourceType) && !"Allotted Resource".equalsIgnoreCase(category)) {
701 hasVFResource = true;
702 for (IArtifactInfo artifact : resource.getArtifacts()) {
703 IDistributionClientDownloadResult resultArtifact =
704 this.downloadTheArtifact(artifact, iNotif.getDistributionID());
705 if (resultArtifact != null) {
707 if (ASDCConfiguration.VF_MODULES_METADATA.equals(artifact.getArtifactType())) {
708 logger.debug("VF_MODULE_ARTIFACT: "
709 + new String(resultArtifact.getArtifactPayload(), "UTF-8"));
710 logger.debug(ASDCNotificationLogging
711 .dumpVfModuleMetaDataList(((VfResourceStructure) resourceStructure)
712 .decodeVfModuleArtifact(resultArtifact.getArtifactPayload())));
714 resourceStructure.addArtifactToStructure(distributionClient, artifact,
719 // Deploy VF resource and artifacts
720 logger.debug("Preparing to deploy Service: {}", iNotif.getServiceUUID());
723 this.deployResourceStructure(resourceStructure, toscaResourceStructure);
724 serviceDeployed = true;
728 } catch (ArtifactInstallerException e) {
729 deploySuccessful = false;
730 errorMessage = e.getMessage();
731 logger.error("Exception occurred", e);
734 if (!hasVFResource) {
736 logger.debug("No resources found for Service: " + iNotif.getServiceUUID());
738 logger.debug("Preparing to deploy Service: {}", iNotif.getServiceUUID());
740 this.deployResourceStructure(resourceStructure, toscaResourceStructure);
741 } catch (ArtifactInstallerException e) {
742 deploySuccessful = false;
743 errorMessage = e.getMessage();
744 logger.error("Exception occurred", e);
747 this.sendCsarDeployNotification(iNotif, resourceStructure, toscaResourceStructure, deploySuccessful,
752 } catch (ASDCDownloadException | UnsupportedEncodingException e) {
753 logger.error("{} {} {} {} {} {}", MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(),
754 "Exception caught during Installation of artifact", "ASDC", "processResourceNotification",
755 ErrorCode.BusinessProcesssError.getValue(), "Exception in processResourceNotification", e);
759 private String getMsoConfigPath() {
760 String msoConfigPath = System.getProperty("mso.config.path");
761 if (msoConfigPath == null) {
762 logger.info("Unable to find the system property mso.config.path, use the default configuration");
763 msoConfigPath = asdcConfig.getPropertyOrNull("mso.config.defaultpath");
765 if (msoConfigPath == null) {
766 logger.info("Unable to find the property: {} from configuration.", "mso.config.defaultpath");
769 logger.info("MSO config path is: {}", msoConfigPath);
770 return msoConfigPath;
773 protected void processCsarServiceArtifacts(INotificationData iNotif,
774 ToscaResourceStructure toscaResourceStructure) {
776 List<IArtifactInfo> serviceArtifacts = iNotif.getServiceArtifacts();
778 for (IArtifactInfo artifact : serviceArtifacts) {
780 if (artifact.getArtifactType().equals(ASDCConfiguration.TOSCA_CSAR)) {
784 toscaResourceStructure.setToscaArtifact(artifact);
786 IDistributionClientDownloadResult resultArtifact =
787 this.downloadTheArtifact(artifact, iNotif.getDistributionID());
789 writeArtifactToFile(artifact, resultArtifact);
791 toscaResourceStructure.updateResourceStructure(artifact);
793 toscaResourceStructure.setServiceVersion(iNotif.getServiceVersion());
795 logger.debug(ASDCNotificationLogging.dumpCSARNotification(iNotif, toscaResourceStructure));
798 } catch (Exception e) {
799 logger.error("{} {} {} {} {} {}", MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(),
800 "Exception caught during processCsarServiceArtifacts", "ASDC",
801 "processCsarServiceArtifacts", ErrorCode.BusinessProcesssError.getValue(),
802 "Exception in processCsarServiceArtifacts", e);
804 } else if (artifact.getArtifactType().equals(ASDCConfiguration.WORKFLOWS)) {
808 IDistributionClientDownloadResult resultArtifact =
809 this.downloadTheArtifact(artifact, iNotif.getDistributionID());
811 writeArtifactToFile(artifact, resultArtifact);
813 toscaResourceStructure.setToscaArtifact(artifact);
815 logger.debug(ASDCNotificationLogging.dumpASDCNotification(iNotif));
818 } catch (Exception e) {
819 logger.info("Whats the error {}", e.getMessage());
820 logger.error("{} {} {} {} {} {}", MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(),
821 "Exception caught during processCsarServiceArtifacts", "ASDC",
822 "processCsarServiceArtifacts", ErrorCode.BusinessProcesssError.getValue(),
823 "Exception in processCsarServiceArtifacts", e);
831 private static final String UNKNOWN = "Unknown";
834 * @return the address of the ASDC we are connected to.
836 public String getAddress() {
837 if (asdcConfig != null) {
838 return asdcConfig.getAsdcAddress();
844 * @return the environment name of the ASDC we are connected to.
846 public String getEnvironment() {
847 if (asdcConfig != null) {
848 return asdcConfig.getEnvironmentName();