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 org.openecomp.sdc.be.config.ConfigurationManager;
24 import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
25 import org.openecomp.sdc.be.dao.api.ActionStatus;
26 import org.openecomp.sdc.be.distribution.api.client.CambriaOperationStatus;
27 import org.openecomp.sdc.be.impl.ComponentsUtils;
28 import org.openecomp.sdc.be.model.Service;
29 import org.openecomp.sdc.be.model.User;
30 import org.openecomp.sdc.common.log.wrappers.Logger;
31 import org.springframework.stereotype.Component;
33 @Component("distributionNotificationSender")
34 public class DistributionNotificationSender {
36 protected static final String DISTRIBUTION_NOTIFICATION_SENDING = "distributionNotificationSending";
38 private static final Logger logger = Logger.getLogger(DistributionNotificationSender.class.getName());
40 @javax.annotation.Resource
41 protected ComponentsUtils componentUtils;
42 private CambriaHandler cambriaHandler = new CambriaHandler();
43 private DistributionEngineConfiguration deConfiguration =
44 ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration();
46 public ActionStatus sendNotification(String topicName, String distributionId,
47 EnvironmentMessageBusData messageBusData, INotificationData notificationData, Service service,
49 long startTime = System.currentTimeMillis();
50 CambriaErrorResponse status =
51 cambriaHandler.sendNotificationAndClose(topicName, messageBusData.getUebPublicKey(),
52 messageBusData.getUebPrivateKey(), messageBusData.getDmaaPuebEndpoints(), notificationData,
53 deConfiguration.getDistributionNotificationTopic().getMaxWaitingAfterSendingSeconds());
55 logger.info("After publishing service {} of version {}. Status is {}", service.getName(), service.getVersion(),
56 status.getHttpCode());
58 auditDistributionNotification(new AuditDistributionNotificationBuilder().setTopicName(topicName)
59 .setDistributionId(distributionId).setStatus(status).setService(service)
60 .setEnvId(messageBusData.getEnvId()).setModifier(modifier)
61 .setWorkloadContext(notificationData.getWorkloadContext()).setTenant(messageBusData.getTenant()));
63 long endTime = System.currentTimeMillis();
65 if (logger.isDebugEnabled()) {
66 logger.debug("After building and publishing artifacts object. Total took {} milliseconds",
70 return convertCambriaResponse(status);
73 private void auditDistributionNotification(AuditDistributionNotificationBuilder builder) {
74 if (this.componentUtils != null) {
75 Integer httpCode = builder.getStatus().getHttpCode();
76 String httpCodeStr = String.valueOf(httpCode);
78 String desc = getDescriptionFromErrorResponse(builder.getStatus());
80 this.componentUtils.auditDistributionNotification(builder.getService().getUUID(),
81 builder.getService().getName(), "Service", builder.getService().getVersion(), builder.getModifier(),
82 builder.getEnvId(), builder.getService().getLifecycleState().name(), builder.getTopicName(),
83 builder.getDistributionId(), desc, httpCodeStr, builder.getWorkloadContext(), builder.getTenant());
87 private String getDescriptionFromErrorResponse(CambriaErrorResponse status) {
89 CambriaOperationStatus operationStatus = status.getOperationStatus();
91 switch (operationStatus) {
94 case AUTHENTICATION_ERROR:
95 return "Error: Authentication problem towards U-EB server";
96 case INTERNAL_SERVER_ERROR:
97 return "Error: Internal U-EB server error";
98 case UNKNOWN_HOST_ERROR:
99 return "Error: Cannot reach U-EB server host";
100 case CONNNECTION_ERROR:
101 return "Error: Cannot connect to U-EB server";
102 case OBJECT_NOT_FOUND:
103 return "Error: object not found in U-EB server";
105 return "Error: Internal Cambria server problem";
111 private ActionStatus convertCambriaResponse(CambriaErrorResponse status) {
112 CambriaOperationStatus operationStatus = status.getOperationStatus();
114 switch (operationStatus) {
116 return ActionStatus.OK;
117 case AUTHENTICATION_ERROR:
118 return ActionStatus.AUTHENTICATION_ERROR;
119 case INTERNAL_SERVER_ERROR:
120 return ActionStatus.GENERAL_ERROR;
121 case UNKNOWN_HOST_ERROR:
122 return ActionStatus.UNKNOWN_HOST;
123 case CONNNECTION_ERROR:
124 return ActionStatus.CONNNECTION_ERROR;
125 case OBJECT_NOT_FOUND:
126 return ActionStatus.OBJECT_NOT_FOUND;
128 return ActionStatus.GENERAL_ERROR;