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.sdc.be.components.distribution.engine;
23 import java.util.concurrent.ExecutorService;
24 import java.util.concurrent.RejectedExecutionException;
26 import javax.annotation.PreDestroy;
28 import org.openecomp.sdc.be.config.ConfigurationManager;
29 import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
30 import org.openecomp.sdc.be.config.DistributionEngineConfiguration.DistributionNotificationTopicConfig;
31 import org.openecomp.sdc.be.impl.ComponentsUtils;
32 import org.openecomp.sdc.be.model.Service;
33 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
34 import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
35 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
36 import org.openecomp.sdc.common.util.ThreadLocalsHolder;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.stereotype.Component;
41 @Component("distributionNotificationSender")
42 public class DistributionNotificationSender {
44 protected static final String DISTRIBUTION_NOTIFICATION_SENDING = "distributionNotificationSending";
46 private static Logger logger = LoggerFactory.getLogger(DistributionNotificationSender.class.getName());
48 // final String BASE_ARTIFACT_URL = "/sdc/v1/catalog/services/%s/%s/";
49 // final String RESOURCE_ARTIFACT_URL = BASE_ARTIFACT_URL
50 // + "resources/%s/%s/artifacts/%s";
51 // final String SERVICE_ARTIFACT_URL = BASE_ARTIFACT_URL + "artifacts/%s";
53 @javax.annotation.Resource
54 InterfaceLifecycleOperation interfaceLifecycleOperation;
56 @javax.annotation.Resource
57 protected ComponentsUtils componentUtils;
59 ExecutorService executorService = null;
61 CambriaHandler cambriaHandler = new CambriaHandler();
63 NotificationExecutorService notificationExecutorService = new NotificationExecutorService();
65 public DistributionNotificationSender() {
68 DistributionNotificationTopicConfig distributionNotificationTopic = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration().getDistributionNotificationTopic();
70 executorService = notificationExecutorService.createExcecutorService(distributionNotificationTopic);
74 public void shutdown() {
75 logger.debug("Going to close notificationExecutorService");
76 if (executorService != null) {
78 long maxWaitingTime = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration().getDistributionNotificationTopic().getMaxWaitingAfterSendingSeconds();
80 notificationExecutorService.shutdownAndAwaitTermination(executorService, maxWaitingTime + 1);
84 public StorageOperationStatus sendNotification(String topicName, String distributionId, DistributionEngineConfiguration deConfiguration, String envName, INotificationData notificationData, Service service, String userId, String modifierName) {
86 Runnable task = new PublishNotificationRunnable(envName, distributionId, service, notificationData, deConfiguration, topicName, userId, modifierName, cambriaHandler, componentUtils, ThreadLocalsHolder.getUuid());
88 executorService.submit(task);
89 } catch (RejectedExecutionException e) {
90 logger.warn("Failed to submit task. Number of threads exceeeds", e);
91 return StorageOperationStatus.OVERLOAD;
94 return StorageOperationStatus.OK;
98 * Audit the publishing notification in case of internal server error.
102 * @param distributionId
105 private void auditDistributionNotificationInternalServerError(String topicName, StorageOperationStatus status, String distributionId, String envName) {
107 if (this.componentUtils != null) {
108 this.componentUtils.auditDistributionNotification(AuditingActionEnum.DISTRIBUTION_NOTIFY, "", " ", "Service", " ", " ", " ", envName, " ", topicName, distributionId, "Error: Internal Server Error. " + status, " ");
112 protected CambriaErrorResponse publishNotification(INotificationData data, DistributionEngineConfiguration deConfiguration, String topicName) {
114 CambriaErrorResponse status = cambriaHandler.sendNotification(topicName, deConfiguration.getUebPublicKey(), deConfiguration.getUebSecretKey(), deConfiguration.getUebServers(), data);