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.DistributionEngineConfiguration;
24 import org.openecomp.sdc.be.distribution.api.client.CambriaOperationStatus;
25 import org.openecomp.sdc.be.impl.ComponentsUtils;
26 import org.openecomp.sdc.be.model.Service;
27 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
28 import org.openecomp.sdc.common.util.ThreadLocalsHolder;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class PublishNotificationRunnable implements Runnable {
34 private String envName;
35 private String distributionId;
36 private Service service;
37 private INotificationData data;
38 private DistributionEngineConfiguration deConfiguration;
39 private String topicName;
40 private CambriaHandler cambriaHandler;
41 private ComponentsUtils componentUtils;
42 private String userId;
43 private String modifierName;
44 private String requestId;
46 private static Logger logger = LoggerFactory.getLogger(PublishNotificationRunnable.class.getName());
48 public PublishNotificationRunnable(String envName, String distributionId, Service service, INotificationData data, DistributionEngineConfiguration deConfiguration, String topicName, String userId, String modifierName,
49 CambriaHandler cambriaHandler, ComponentsUtils componentUtils, String requestId) {
51 this.envName = envName;
52 this.distributionId = distributionId;
53 this.service = service;
55 this.deConfiguration = deConfiguration;
56 this.topicName = topicName;
57 this.cambriaHandler = cambriaHandler;
58 this.componentUtils = componentUtils;
60 this.modifierName = modifierName;
61 this.requestId = requestId;
64 public INotificationData getData() {
68 public void setData(INotificationData data) {
72 public DistributionEngineConfiguration getDeConfiguration() {
73 return deConfiguration;
76 public void setDeConfiguration(DistributionEngineConfiguration deConfiguration) {
77 this.deConfiguration = deConfiguration;
80 public String getTopicName() {
84 public void setTopicName(String topicName) {
85 this.topicName = topicName;
88 public String getUserId() {
92 public void setUserId(String userId) {
96 public String getModifierName() {
100 public void setModifierName(String modifierName) {
101 this.modifierName = modifierName;
107 long startTime = System.currentTimeMillis();
108 ThreadLocalsHolder.setUuid(this.requestId);
110 CambriaErrorResponse status = cambriaHandler.sendNotificationAndClose(topicName, deConfiguration.getUebPublicKey(), deConfiguration.getUebSecretKey(), deConfiguration.getUebServers(), data,
111 deConfiguration.getDistributionNotificationTopic().getMaxWaitingAfterSendingSeconds());
113 logger.info("After publishing service {} of version {}. Status is {}", service.getName(), service.getVersion(), status.getHttpCode());
114 auditDistributionNotification(topicName, status, service, distributionId, envName, userId, modifierName);
116 long endTime = System.currentTimeMillis();
117 logger.debug("After building and publishing artifacts object. Total took {} milliseconds", (endTime - startTime));
121 private void auditDistributionNotification(String topicName, CambriaErrorResponse status, Service service, String distributionId, String envName, String userId, String modifierName) {
122 if (this.componentUtils != null) {
123 Integer httpCode = status.getHttpCode();
124 String httpCodeStr = String.valueOf(httpCode);
126 String desc = getDescriptionFromErrorResponse(status);
128 this.componentUtils.auditDistributionNotification(AuditingActionEnum.DISTRIBUTION_NOTIFY, service.getUUID(), service.getName(), "Service", service.getVersion(), userId, modifierName, envName, service.getLifecycleState().name(), topicName,
129 distributionId, desc, httpCodeStr);
133 private String getDescriptionFromErrorResponse(CambriaErrorResponse status) {
135 CambriaOperationStatus operationStatus = status.getOperationStatus();
137 switch (operationStatus) {
140 case AUTHENTICATION_ERROR:
141 return "Error: Authentication problem towards U-EB server";
142 case INTERNAL_SERVER_ERROR:
143 return "Error: Internal U-EB server error";
144 case UNKNOWN_HOST_ERROR:
145 return "Error: Cannot reach U-EB server host";
146 case CONNNECTION_ERROR:
147 return "Error: Cannot connect to U-EB server";
148 case OBJECT_NOT_FOUND:
149 return "Error: object not found in U-EB server";
151 return "Error: Internal Cambria server problem";