2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
\r
7 * ================================================================================
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
19 * ============LICENSE_END=========================================================
\r
22 package org.openecomp.mso.asdc.client;
\r
25 import java.io.File;
\r
26 import java.io.FileOutputStream;
\r
27 import java.io.IOException;
\r
28 import java.io.UnsupportedEncodingException;
\r
29 import java.util.List;
\r
31 import org.openecomp.sdc.api.IDistributionClient;
\r
32 import org.openecomp.sdc.api.consumer.IDistributionStatusMessage;
\r
33 import org.openecomp.sdc.api.consumer.INotificationCallback;
\r
34 import org.openecomp.sdc.api.notification.IArtifactInfo;
\r
35 import org.openecomp.sdc.api.notification.INotificationData;
\r
36 import org.openecomp.sdc.api.notification.IResourceInstance;
\r
37 import org.openecomp.sdc.api.results.IDistributionClientDownloadResult;
\r
38 import org.openecomp.sdc.api.results.IDistributionClientResult;
\r
39 import org.openecomp.sdc.impl.DistributionClientFactory;
\r
40 import org.openecomp.sdc.utils.DistributionActionResultEnum;
\r
41 import org.openecomp.sdc.utils.DistributionStatusEnum;
\r
42 import org.openecomp.mso.asdc.client.exceptions.ASDCControllerException;
\r
43 import org.openecomp.mso.asdc.client.exceptions.ASDCDownloadException;
\r
44 import org.openecomp.mso.asdc.client.exceptions.ASDCParametersException;
\r
45 import org.openecomp.mso.asdc.client.exceptions.ArtifactInstallerException;
\r
46 import org.openecomp.mso.asdc.installer.IVfResourceInstaller;
\r
47 import org.openecomp.mso.asdc.installer.ToscaResourceStructure;
\r
48 import org.openecomp.mso.asdc.installer.VfResourceStructure;
\r
49 import org.openecomp.mso.asdc.installer.heat.ToscaResourceInstaller;
\r
50 import org.openecomp.mso.asdc.installer.heat.VfResourceInstaller;
\r
51 import org.openecomp.mso.asdc.util.ASDCNotificationLogging;
\r
52 import org.openecomp.mso.logger.MessageEnum;
\r
53 import org.openecomp.mso.logger.MsoAlarmLogger;
\r
54 import org.openecomp.mso.logger.MsoLogger;
\r
55 import org.openecomp.mso.utils.UUIDChecker;
\r
57 public class ASDCController {
\r
59 protected static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.ASDC);
\r
61 protected static MsoAlarmLogger alarmLogger = new MsoAlarmLogger ();
\r
63 protected boolean isAsdcClientAutoManaged = false;
\r
65 protected String controllerName;
\r
67 protected ToscaResourceInstaller toscaInstaller;
\r
71 * Inner class for Notification callback
\r
75 private final class ASDCNotificationCallBack implements INotificationCallback {
\r
77 private ASDCController asdcController;
\r
79 ASDCNotificationCallBack (ASDCController controller) {
\r
80 asdcController = controller;
\r
84 * This method can be called multiple times at the same moment.
\r
85 * The controller must be thread safe !
\r
88 public void activateCallback (INotificationData iNotif) {
\r
89 long startTime = System.currentTimeMillis ();
\r
90 UUIDChecker.generateUUID (LOGGER);
\r
91 MsoLogger.setServiceName ("NotificationHandler");
\r
92 MsoLogger.setLogContext (iNotif.getDistributionID (), iNotif.getServiceUUID ());
\r
93 String event = "Receive a callback notification in ASDC, nb of resources: " + iNotif.getResources ().size ();
\r
94 LOGGER.debug(event);
\r
95 asdcController.treatNotification (iNotif);
\r
96 LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Completed the treatment of the notification");
\r
100 // ***** Controller STATUS code
\r
102 protected int nbOfNotificationsOngoing = 0;
\r
104 public int getNbOfNotificationsOngoing () {
\r
105 return nbOfNotificationsOngoing;
\r
108 private ASDCControllerStatus controllerStatus = ASDCControllerStatus.STOPPED;
\r
110 protected synchronized final void changeControllerStatus (ASDCControllerStatus newControllerStatus) {
\r
111 switch (newControllerStatus) {
\r
114 ++this.nbOfNotificationsOngoing;
\r
115 this.controllerStatus = newControllerStatus;
\r
119 if (this.nbOfNotificationsOngoing > 1) {
\r
120 --this.nbOfNotificationsOngoing;
\r
122 this.nbOfNotificationsOngoing = 0;
\r
123 this.controllerStatus = newControllerStatus;
\r
128 this.controllerStatus = newControllerStatus;
\r
134 public synchronized final ASDCControllerStatus getControllerStatus () {
\r
135 return this.controllerStatus;
\r
138 // ***** END of Controller STATUS code
\r
140 protected ASDCConfiguration asdcConfig;
\r
141 private IDistributionClient distributionClient;
\r
142 private IVfResourceInstaller resourceInstaller;
\r
144 public ASDCController (String controllerConfigName) {
\r
145 isAsdcClientAutoManaged = true;
\r
146 this.controllerName = controllerConfigName;
\r
147 this.resourceInstaller = new VfResourceInstaller();
\r
148 toscaInstaller = new ToscaResourceInstaller();
\r
151 public ASDCController (String controllerConfigName, IDistributionClient asdcClient, IVfResourceInstaller resourceinstaller) {
\r
153 distributionClient = asdcClient;
\r
154 this.resourceInstaller = resourceinstaller;
\r
155 this.controllerName = controllerConfigName;
\r
158 public ASDCController (String controllerConfigName,IDistributionClient asdcClient) {
\r
159 distributionClient = asdcClient;
\r
160 this.controllerName = controllerConfigName;
\r
161 this.resourceInstaller = new VfResourceInstaller();
\r
162 toscaInstaller = new ToscaResourceInstaller();
\r
166 * This method refresh the ASDC Controller config and restart the client.
\r
168 * @return true if config has been reloaded, false otherwise
\r
169 * @throws ASDCControllerException If case of issue with the init or close called during the config reload
\r
170 * @throws ASDCParametersException If there is an issue with the parameters
\r
171 * @throws IOException In case of the key file could not be loaded properly
\r
173 public boolean updateConfigIfNeeded () throws ASDCParametersException, ASDCControllerException, IOException {
\r
174 LOGGER.debug ("Checking whether ASDC config must be reloaded");
\r
177 if (this.asdcConfig != null && this.asdcConfig.hasASDCConfigChanged ()) {
\r
178 LOGGER.debug ("ASDC Config must be reloaded");
\r
180 this.asdcConfig.refreshASDCConfig ();
\r
184 LOGGER.debug ("ASDC Config must NOT be reloaded");
\r
187 } catch (ASDCParametersException ep) {
\r
188 // Try to close it at least to make it consistent with the file specified
\r
189 // We cannot let it run with a different config file, even if it's bad.
\r
190 // This call could potentially throw a ASDCController exception if the controller is currently BUSY.
\r
198 * This method initializes the ASDC Controller and the ASDC Client.
\r
200 * @throws ASDCControllerException It throws an exception if the ASDC Client cannot be instantiated or if an init
\r
201 * attempt is done when already initialized
\r
202 * @throws ASDCParametersException If there is an issue with the parameters provided
\r
203 * @throws IOException In case of issues when trying to load the key file
\r
205 public void initASDC () throws ASDCControllerException, ASDCParametersException, IOException {
\r
206 String event = "Initialize the ASDC Controller";
\r
207 MsoLogger.setServiceName ("InitASDC");
\r
208 LOGGER.debug (event);
\r
209 if (this.getControllerStatus () != ASDCControllerStatus.STOPPED) {
\r
210 String endEvent = "The controller is already initialized, call the closeASDC method first";
\r
211 throw new ASDCControllerException (endEvent);
\r
214 if (asdcConfig == null) {
\r
215 asdcConfig = new ASDCConfiguration (this.controllerName);
\r
218 // attempt to refresh during init as MsoProperties is may be pointing to an old file
\r
219 // Be careful this is static in MsoProperties
\r
220 asdcConfig.refreshASDCConfig ();
\r
222 if (this.distributionClient == null) {
\r
223 distributionClient = DistributionClientFactory.createDistributionClient ();
\r
225 long initStartTime = System.currentTimeMillis ();
\r
226 IDistributionClientResult result = this.distributionClient.init (asdcConfig,
\r
227 new ASDCNotificationCallBack (this));
\r
228 if (!result.getDistributionActionResult ().equals (DistributionActionResultEnum.SUCCESS)) {
\r
229 String endEvent = "ASDC distribution client init failed with reason:"
\r
230 + result.getDistributionMessageResult ();
\r
231 LOGGER.recordMetricEvent (initStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.UnknownError, "Initialization of the ASDC Controller failed with reason:" + result.getDistributionMessageResult (), "ASDC", "init", null);
\r
232 LOGGER.debug (endEvent);
\r
235 this.changeControllerStatus (ASDCControllerStatus.STOPPED);
\r
236 throw new ASDCControllerException ("Initialization of the ASDC Controller failed with reason: "
\r
237 + result.getDistributionMessageResult ());
\r
239 LOGGER.recordMetricEvent (initStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully initialize ASDC Controller", "ASDC", "init", null);
\r
241 long clientstartStartTime = System.currentTimeMillis ();
\r
242 result = this.distributionClient.start ();
\r
243 if (!result.getDistributionActionResult ().equals (DistributionActionResultEnum.SUCCESS)) {
\r
244 String endEvent = "ASDC distribution client start failed with reason:"
\r
245 + result.getDistributionMessageResult ();
\r
246 LOGGER.recordMetricEvent (clientstartStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.UnknownError, endEvent, "ASDC", "start", null);
\r
247 LOGGER.debug (endEvent);
\r
249 this.changeControllerStatus (ASDCControllerStatus.STOPPED);
\r
250 throw new ASDCControllerException ("Startup of the ASDC Controller failed with reason: "
\r
251 + result.getDistributionMessageResult ());
\r
253 LOGGER.recordMetricEvent (clientstartStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully start ASDC distribution client", "ASDC", "start", null);
\r
256 this.changeControllerStatus (ASDCControllerStatus.IDLE);
\r
257 LOGGER.info (MessageEnum.ASDC_INIT_ASDC_CLIENT_SUC, "ASDC", "changeControllerStatus");
\r
261 * This method closes the ASDC Controller and the ASDC Client.
\r
263 * @throws ASDCControllerException It throws an exception if the ASDC Client cannot be closed because
\r
264 * it's currently BUSY in processing notifications.
\r
266 public void closeASDC () throws ASDCControllerException {
\r
268 MsoLogger.setServiceName ("CloseController");
\r
269 if (this.getControllerStatus () == ASDCControllerStatus.BUSY) {
\r
270 throw new ASDCControllerException ("Cannot close the ASDC controller as it's currently in BUSY state");
\r
272 if (this.distributionClient != null) {
\r
273 this.distributionClient.stop ();
\r
274 // If auto managed we can set it to Null, ASDCController controls it.
\r
275 // In the other case the client of this class has specified it, so we can't reset it
\r
276 if (isAsdcClientAutoManaged) {
\r
277 // Next init will initialize it with a new ASDC Client
\r
278 this.distributionClient = null;
\r
282 this.changeControllerStatus (ASDCControllerStatus.STOPPED);
\r
285 private boolean checkResourceAlreadyDeployed (VfResourceStructure resource) throws ArtifactInstallerException {
\r
287 if (toscaInstaller.isResourceAlreadyDeployed (resource)) {
\r
288 LOGGER.info (MessageEnum.ASDC_ARTIFACT_ALREADY_EXIST,
\r
289 resource.getResourceInstance().getResourceInstanceName(),
\r
290 resource.getResourceInstance().getResourceUUID(),
\r
291 resource.getResourceInstance().getResourceName(), "", "");
\r
293 this.sendDeployNotificationsForResource(resource,DistributionStatusEnum.ALREADY_DOWNLOADED,null);
\r
294 this.sendDeployNotificationsForResource(resource,DistributionStatusEnum.ALREADY_DEPLOYED,null);
\r
303 private final static String UUID_PARAM = "(UUID:";
\r
305 private IDistributionClientDownloadResult downloadTheArtifact (IArtifactInfo artifact,
\r
306 String distributionId) throws ASDCDownloadException {
\r
308 LOGGER.debug ("Trying to download the artifact : " + artifact.getArtifactURL ()
\r
310 + artifact.getArtifactUUID ()
\r
312 IDistributionClientDownloadResult downloadResult;
\r
316 downloadResult = distributionClient.download (artifact);
\r
317 if (null == downloadResult) {
\r
318 LOGGER.info (MessageEnum.ASDC_ARTIFACT_NULL, artifact.getArtifactUUID (), "", "");
\r
319 return downloadResult;
\r
321 } catch (RuntimeException e) {
\r
322 LOGGER.debug ("Not able to download the artifact due to an exception: " + artifact.getArtifactURL ());
\r
323 this.sendASDCNotification (NotificationType.DOWNLOAD,
\r
324 artifact.getArtifactURL (),
\r
325 asdcConfig.getConsumerID (),
\r
327 DistributionStatusEnum.DOWNLOAD_ERROR,
\r
329 System.currentTimeMillis ());
\r
331 throw new ASDCDownloadException ("Exception caught when downloading the artifact", e);
\r
334 if (DistributionActionResultEnum.SUCCESS.equals(downloadResult.getDistributionActionResult ())) {
\r
336 LOGGER.info (MessageEnum.ASDC_ARTIFACT_DOWNLOAD_SUC,
\r
337 artifact.getArtifactURL (),
\r
338 artifact.getArtifactUUID (),
\r
339 String.valueOf (downloadResult.getArtifactPayload ().length), "", "");
\r
343 LOGGER.error (MessageEnum.ASDC_ARTIFACT_DOWNLOAD_FAIL,
\r
344 artifact.getArtifactName (),
\r
345 artifact.getArtifactURL (),
\r
346 artifact.getArtifactUUID (),
\r
347 downloadResult.getDistributionMessageResult (), "", "", MsoLogger.ErrorCode.DataError, "ASDC artifact download fail");
\r
349 this.sendASDCNotification (NotificationType.DOWNLOAD,
\r
350 artifact.getArtifactURL (),
\r
351 asdcConfig.getConsumerID (),
\r
353 DistributionStatusEnum.DOWNLOAD_ERROR,
\r
354 downloadResult.getDistributionMessageResult (),
\r
355 System.currentTimeMillis ());
\r
357 throw new ASDCDownloadException ("Artifact " + artifact.getArtifactName ()
\r
358 + " could not be downloaded from ASDC URL "
\r
359 + artifact.getArtifactURL ()
\r
361 + artifact.getArtifactUUID ()
\r
363 + System.lineSeparator ()
\r
364 + "Error message is "
\r
365 + downloadResult.getDistributionMessageResult ()
\r
366 + System.lineSeparator ());
\r
370 this.sendASDCNotification (NotificationType.DOWNLOAD,
\r
371 artifact.getArtifactURL (),
\r
372 asdcConfig.getConsumerID (),
\r
374 DistributionStatusEnum.DOWNLOAD_OK,
\r
376 System.currentTimeMillis ());
\r
377 return downloadResult;
\r
381 private void writeArtifactToFile (IArtifactInfo artifact,
\r
382 IDistributionClientDownloadResult resultArtifact) throws ASDCDownloadException {
\r
384 LOGGER.debug ("Trying to download the artifact : " + artifact.getArtifactURL ()
\r
386 + artifact.getArtifactUUID ()
\r
389 File spoolFile = new File(System.getProperty("mso.config.path") + "/ASDC" + "/" + artifact.getArtifactName());
\r
392 byte[] payloadBytes = resultArtifact.getArtifactPayload();
\r
395 LOGGER.info(MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF, "***WRITE FILE ARTIFACT NAME", "ASDC", artifact.getArtifactName());
\r
397 FileOutputStream outFile = new FileOutputStream(System.getProperty("mso.config.path") + "/ASDC" + "/" + artifact.getArtifactName());
\r
398 outFile.write(payloadBytes, 0, payloadBytes.length);
\r
400 } catch (Exception e) {
\r
401 LOGGER.debug("Exception :",e);
\r
402 LOGGER.error(MessageEnum.ASDC_ARTIFACT_DOWNLOAD_FAIL,
\r
403 artifact.getArtifactName (),
\r
404 artifact.getArtifactURL (),
\r
405 artifact.getArtifactUUID (),
\r
406 resultArtifact.getDistributionMessageResult (), "", "", MsoLogger.ErrorCode.DataError, "ASDC write to file failed");
\r
412 private void sendDeployNotificationsForResource(VfResourceStructure vfResourceStructure,DistributionStatusEnum distribStatus, String errorReason) {
\r
414 for (IArtifactInfo artifactInfo : vfResourceStructure.getResourceInstance().getArtifacts()) {
\r
416 if (DistributionStatusEnum.DEPLOY_OK.equals(distribStatus)
\r
417 // This could be NULL if the artifact is a VF module artifact, this won't be present in the MAP
\r
418 && vfResourceStructure.getArtifactsMapByUUID().get(artifactInfo.getArtifactUUID()) != null
\r
419 && vfResourceStructure.getArtifactsMapByUUID().get(artifactInfo.getArtifactUUID()).getDeployedInDb() == 0) {
\r
420 this.sendASDCNotification (NotificationType.DEPLOY,
\r
421 artifactInfo.getArtifactURL (),
\r
422 asdcConfig.getConsumerID (),
\r
423 vfResourceStructure.getNotification().getDistributionID(),
\r
424 DistributionStatusEnum.DEPLOY_ERROR,
\r
425 "The artifact has not been used by the modules defined in the resource",
\r
426 System.currentTimeMillis ());
\r
428 this.sendASDCNotification (NotificationType.DEPLOY,
\r
429 artifactInfo.getArtifactURL (),
\r
430 asdcConfig.getConsumerID (),
\r
431 vfResourceStructure.getNotification().getDistributionID(),
\r
434 System.currentTimeMillis ());
\r
439 private void deployResourceStructure (VfResourceStructure resourceStructure, ToscaResourceStructure toscaResourceStructure) throws ArtifactInstallerException {
\r
441 LOGGER.info (MessageEnum.ASDC_START_DEPLOY_ARTIFACT, resourceStructure.getResourceInstance().getResourceInstanceName(), resourceStructure.getResourceInstance().getResourceUUID(), "ASDC", "deployResourceStructure");
\r
443 String resourceType = resourceStructure.getResourceInstance().getResourceType();
\r
444 String category = resourceStructure.getResourceInstance().getCategory();
\r
445 if("VF".equals(resourceType) && !"Allotted Resource".equalsIgnoreCase(category)){
\r
446 resourceStructure.createVfModuleStructures();
\r
448 //resourceInstaller.installTheResource (resourceStructure);
\r
450 //ToscaResourceInstaller tri = new ToscaResourceInstaller();
\r
451 toscaInstaller.installTheResource(toscaResourceStructure, resourceStructure);
\r
453 /* if(toscaResourceStructure.isVnfAlreadyInstalled()){
\r
454 LOGGER.info (MessageEnum.ASDC_ARTIFACT_ALREADY_EXIST,
\r
455 toscaResourceStructure.getCatalogVnfResource().getModelName(),
\r
456 toscaResourceStructure.getCatalogVnfResource().getModelUuid(),
\r
457 toscaResourceStructure.getCatalogVnfResource().getModelUuid(),"","");
\r
460 this.sendDeployNotificationsForResource(resourceStructure,DistributionStatusEnum.ALREADY_DOWNLOADED,null);
\r
461 this.sendDeployNotificationsForResource(resourceStructure,DistributionStatusEnum.ALREADY_DEPLOYED,null);
\r
464 } catch (ArtifactInstallerException e) {
\r
465 LOGGER.info (MessageEnum.ASDC_ARTIFACT_DOWNLOAD_FAIL,
\r
466 resourceStructure.getResourceInstance().getResourceName(),
\r
467 resourceStructure.getResourceInstance().getResourceUUID(),
\r
468 String.valueOf (resourceStructure.getVfModuleStructure().size()), "ASDC", "deployResourceStructure");
\r
469 sendDeployNotificationsForResource(resourceStructure,DistributionStatusEnum.DEPLOY_ERROR,e.getMessage());
\r
473 if (resourceStructure.isDeployedSuccessfully()) {
\r
474 LOGGER.info (MessageEnum.ASDC_ARTIFACT_DEPLOY_SUC,
\r
475 resourceStructure.getResourceInstance().getResourceName(),
\r
476 resourceStructure.getResourceInstance().getResourceUUID(),
\r
477 String.valueOf (resourceStructure.getVfModuleStructure().size()), "ASDC", "deployResourceStructure");
\r
478 sendDeployNotificationsForResource(resourceStructure,DistributionStatusEnum.DEPLOY_OK ,null);
\r
483 private enum NotificationType {
\r
487 private void sendASDCNotification (NotificationType notificationType,
\r
488 String artifactURL,
\r
490 String distributionID,
\r
491 DistributionStatusEnum status,
\r
492 String errorReason,
\r
495 String event = "Sending " + notificationType.name ()
\r
499 + " notification to ASDC for artifact:"
\r
502 if (errorReason != null) {
\r
503 event=event+"("+errorReason+")";
\r
505 LOGGER.info (MessageEnum.ASDC_SEND_NOTIF_ASDC, notificationType.name (), status.name (), artifactURL, "ASDC", "sendASDCNotification");
\r
506 LOGGER.debug (event);
\r
508 long subStarttime = System.currentTimeMillis ();
\r
509 String action = "";
\r
511 IDistributionStatusMessage message = new DistributionStatusMessage (artifactURL,
\r
517 switch (notificationType) {
\r
519 if (errorReason != null) {
\r
520 this.distributionClient.sendDownloadStatus (message, errorReason);
\r
522 this.distributionClient.sendDownloadStatus (message);
\r
524 action = "sendDownloadStatus";
\r
527 if (errorReason != null) {
\r
528 this.distributionClient.sendDeploymentStatus (message, errorReason);
\r
530 this.distributionClient.sendDeploymentStatus (message);
\r
532 action = "sendDeploymentdStatus";
\r
537 } catch (RuntimeException e) {
\r
538 // TODO: May be a list containing the unsent notification should be
\r
540 LOGGER.warn (MessageEnum.ASDC_SEND_NOTIF_ASDC_EXEC, "ASDC", "sendASDCNotification", MsoLogger.ErrorCode.SchemaError, "RuntimeException - sendASDCNotification", e);
\r
542 LOGGER.recordMetricEvent (subStarttime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully sent notification to ASDC", "ASDC", action, null);
\r
545 public void treatNotification (INotificationData iNotif) {
\r
547 int noOfArtifacts = 0;
\r
548 for (IResourceInstance resource : iNotif.getResources ()) {
\r
549 noOfArtifacts += resource.getArtifacts ().size ();
\r
551 LOGGER.info (MessageEnum.ASDC_RECEIVE_CALLBACK_NOTIF,
\r
552 String.valueOf (noOfArtifacts),
\r
553 iNotif.getServiceUUID (), "ASDC", "treatNotification");
\r
556 LOGGER.debug(ASDCNotificationLogging.dumpASDCNotification(iNotif));
\r
557 LOGGER.info(MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF, iNotif.getServiceUUID(), "ASDC", "treatNotification");
\r
558 this.changeControllerStatus(ASDCControllerStatus.BUSY);
\r
562 // Process only the Resource artifacts in MSO
\r
563 for (IResourceInstance resource : iNotif.getResources()) {
\r
565 // We process only VNF(VF) and Network(VL) resources on MSO Side
\r
566 // We process only VNF resource on MSO Side
\r
567 if ("VF".equals(resource.getResourceType()) || "VL".equals(resource.getResourceType())) {
\r
568 this.processResourceNotification(iNotif,resource);
\r
575 } catch (RuntimeException e) {
\r
576 LOGGER.error (MessageEnum.ASDC_GENERAL_EXCEPTION_ARG,
\r
577 "Unexpected exception caught during the notification processing", "ASDC", "treatNotification", MsoLogger.ErrorCode.SchemaError, "RuntimeException in treatNotification",
\r
580 this.changeControllerStatus (ASDCControllerStatus.IDLE);
\r
585 private void processResourceNotification (INotificationData iNotif,IResourceInstance resource) {
\r
586 // For each artifact, create a structure describing the VFModule in a ordered flat level
\r
587 VfResourceStructure resourceStructure = new VfResourceStructure(iNotif,resource);
\r
588 ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
\r
592 if (!this.checkResourceAlreadyDeployed(resourceStructure)) {
\r
593 for (IArtifactInfo artifact : resource.getArtifacts()) {
\r
595 IDistributionClientDownloadResult resultArtifact = this.downloadTheArtifact(artifact,
\r
596 iNotif.getDistributionID());
\r
598 if (resultArtifact != null) {
\r
599 if (ASDCConfiguration.VF_MODULES_METADATA.equals(artifact.getArtifactType())) {
\r
600 LOGGER.debug("VF_MODULE_ARTIFACT: "+new String(resultArtifact.getArtifactPayload(),"UTF-8"));
\r
601 LOGGER.debug(ASDCNotificationLogging.dumpVfModuleMetaDataList(resourceStructure.decodeVfModuleArtifact(resultArtifact.getArtifactPayload())));
\r
603 resourceStructure.addArtifactToStructure(distributionClient,artifact, resultArtifact);
\r
609 this.processCsarServiceArtifacts(iNotif, toscaResourceStructure);
\r
611 this.deployResourceStructure(resourceStructure, toscaResourceStructure);
\r
614 } catch (ArtifactInstallerException | ASDCDownloadException | UnsupportedEncodingException e) {
\r
615 LOGGER.error(MessageEnum.ASDC_GENERAL_EXCEPTION_ARG,
\r
616 "Exception caught during Installation of artifact", "ASDC", "processResourceNotification", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in processResourceNotification", e);
\r
620 private void processCsarServiceArtifacts (INotificationData iNotif, ToscaResourceStructure toscaResourceStructure) {
\r
622 List<IArtifactInfo> serviceArtifacts = iNotif.getServiceArtifacts();
\r
624 for(IArtifactInfo artifact : serviceArtifacts){
\r
626 if(artifact.getArtifactType().equals(ASDCConfiguration.TOSCA_CSAR)){
\r
630 toscaResourceStructure.setToscaArtifact(artifact);
\r
632 IDistributionClientDownloadResult resultArtifact = this.downloadTheArtifact(artifact,iNotif.getDistributionID());
\r
634 writeArtifactToFile(artifact, resultArtifact);
\r
636 toscaResourceStructure.updateResourceStructure(artifact);
\r
638 toscaResourceStructure.setServiceVersion(iNotif.getServiceVersion());
\r
640 LOGGER.debug(ASDCNotificationLogging.dumpCSARNotification(iNotif, toscaResourceStructure));
\r
643 } catch(Exception e){
\r
644 System.out.println("Whats the error " + e.getMessage());
\r
645 LOGGER.error(MessageEnum.ASDC_GENERAL_EXCEPTION_ARG,
\r
646 "Exception caught during processCsarServiceArtifacts", "ASDC", "processCsarServiceArtifacts", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in processCsarServiceArtifacts", e);
\r
653 private static final String UNKNOWN="Unknown";
\r
656 * @return the address of the ASDC we are connected to.
\r
658 public String getAddress () {
\r
659 if (asdcConfig != null) {
\r
660 return asdcConfig.getAsdcAddress ();
\r
666 * @return the environment name of the ASDC we are connected to.
\r
668 public String getEnvironment () {
\r
669 if (asdcConfig != null) {
\r
670 return asdcConfig.getEnvironmentName ();
\r