X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fmodelloader%2Fnotification%2FNotificationPublisher.java;h=7d5b1cc5c33ea02a9977ecb7c48dd5743d28005a;hb=refs%2Fheads%2Fmaster;hp=447e817806fff7f819c69550b92ba5208a63235f;hpb=7b1f813441f94261f43ec4f5bb0944ad2570fbdf;p=aai%2Fmodel-loader.git diff --git a/src/main/java/org/onap/aai/modelloader/notification/NotificationPublisher.java b/src/main/java/org/onap/aai/modelloader/notification/NotificationPublisher.java index 447e817..7d5b1cc 100644 --- a/src/main/java/org/onap/aai/modelloader/notification/NotificationPublisher.java +++ b/src/main/java/org/onap/aai/modelloader/notification/NotificationPublisher.java @@ -1,27 +1,28 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * Copyright © 2017-2018 European Software Marketing Ltd. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * ============LICENSE_END============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.notification; -import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.Properties; @@ -31,39 +32,35 @@ import org.onap.aai.cl.mdc.MdcContext; import org.onap.aai.cl.mdc.MdcOverride; import org.onap.aai.modelloader.config.ModelLoaderConfig; import org.onap.aai.modelloader.service.ModelLoaderMsgs; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.results.IDistributionClientResult; -import org.openecomp.sdc.utils.DistributionActionResultEnum; -import org.openecomp.sdc.utils.DistributionStatusEnum; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.results.IDistributionClientResult; +import org.onap.sdc.utils.DistributionActionResultEnum; +import org.onap.sdc.utils.DistributionStatusEnum; +import org.springframework.stereotype.Component; /** * This class is responsible for publishing the status of actions performed working with artifacts. */ -class NotificationPublisher { +@Component +public class NotificationPublisher { private static Logger logger = LoggerFactory.getInstance().getLogger(NotificationPublisher.class); private static Logger metricsLogger = LoggerFactory.getInstance().getMetricsLogger(NotificationPublisher.class); - protected static final String FILESEP = - (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator"); - protected static final String CONFIG_DIR = System.getProperty("CONFIG_HOME") + FILESEP; - protected static final String CONFIG_AUTH_LOCATION = CONFIG_DIR + "auth" + FILESEP; - protected static final String CONFIG_FILE = CONFIG_DIR + "model-loader.properties"; - private boolean publishingEnabled; public NotificationPublisher() { Properties configProperties = new Properties(); - try { - configProperties.load(new FileInputStream(CONFIG_FILE)); + try (InputStream configInputStream = Files.newInputStream(ModelLoaderConfig.propertiesFile())) { + configProperties.load(configInputStream); } catch (IOException e) { String errorMsg = "Failed to load configuration: " + e.getMessage(); logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, e, errorMsg); } - ModelLoaderConfig config = new ModelLoaderConfig(configProperties, CONFIG_AUTH_LOCATION); + ModelLoaderConfig config = new ModelLoaderConfig(configProperties); publishingEnabled = !config.getASDCConnectionDisabled(); } @@ -147,28 +144,10 @@ class NotificationPublisher { * @param data data about the notification that resulted in this message being created * @param artifact the specific artifact to have its deployment status reported on */ - void publishDeployFailure(IDistributionClient client, INotificationData data, IArtifactInfo artifact) { + public void publishDeployFailure(IDistributionClient client, INotificationData data, IArtifactInfo artifact) { publishDeployStatus(client, data, artifact, DistributionStatusEnum.DEPLOY_ERROR, "failure"); } - private void publishDeployStatus(IDistributionClient client, INotificationData data, IArtifactInfo artifact, - DistributionStatusEnum distributionStatusEnum, String result) { - if (publishingEnabled) { - MdcOverride override = initMDCStartTime(); - - IDistributionClientResult sendStatus = client.sendDeploymentStatus( - DistributionStatusMessageBuilder.build(client, data, artifact, distributionStatusEnum)); - metricsLogger.info(ModelLoaderMsgs.EVENT_PUBLISHED, null, override, "deploy " + result, - artifact.getArtifactName(), sendStatus.getDistributionActionResult().toString()); - - if (sendStatus.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) { - logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, - "Failed to publish deploy " + result + " status: " + sendStatus.getDistributionMessageResult()); - } - } else { - logPublishingDisabled(distributionStatusEnum.toString(), result); - } - } /** * This method is responsible for publishing notification that the deployment of an artifact was succesful. @@ -177,11 +156,11 @@ class NotificationPublisher { * @param data data about the notification that resulted in this message being created * @param artifact the specific artifact to have its deployment status reported on */ - void publishDeploySuccess(IDistributionClient client, INotificationData data, IArtifactInfo artifact) { + public void publishDeploySuccess(IDistributionClient client, INotificationData data, IArtifactInfo artifact) { publishDeployStatus(client, data, artifact, DistributionStatusEnum.DEPLOY_OK, "success"); } - void publishComponentSuccess(IDistributionClient client, INotificationData data) { + public void publishComponentSuccess(IDistributionClient client, INotificationData data) { if (publishingEnabled) { MdcOverride override = initMDCStartTime(); @@ -200,7 +179,7 @@ class NotificationPublisher { } } - void publishComponentFailure(IDistributionClient client, INotificationData data, String errorReason) { + public void publishComponentFailure(IDistributionClient client, INotificationData data, String errorReason) { if (publishingEnabled) { MdcOverride override = initMDCStartTime(); @@ -220,6 +199,25 @@ class NotificationPublisher { } } + private void publishDeployStatus(IDistributionClient client, INotificationData data, IArtifactInfo artifact, + DistributionStatusEnum distributionStatusEnum, String result) { + if (publishingEnabled) { + MdcOverride override = initMDCStartTime(); + + IDistributionClientResult sendStatus = client.sendDeploymentStatus( + DistributionStatusMessageBuilder.build(client, data, artifact, distributionStatusEnum)); + metricsLogger.info(ModelLoaderMsgs.EVENT_PUBLISHED, null, override, "deploy " + result, + artifact.getArtifactName(), sendStatus.getDistributionActionResult().toString()); + + if (sendStatus.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) { + logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, + "Failed to publish deploy " + result + " status: " + sendStatus.getDistributionMessageResult()); + } + } else { + logPublishingDisabled(distributionStatusEnum.toString(), result); + } + } + private void logPublishingDisabled(String statusType, String message) { logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Notification publishing is disabled, skipping publishing of the following status: " + statusType