-/*-\r
- * ================================================================================\r
- * ECOMP Portal\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ================================================================================\r
- */\r
-package org.openecomp.portalapp.portal.ueb;\r
-\r
-import java.net.HttpURLConnection;\r
-import java.net.URL;\r
-import java.util.LinkedList;\r
-import java.util.List;\r
-\r
-import javax.annotation.PostConstruct;\r
-\r
-import org.hibernate.Session;\r
-import org.hibernate.SessionFactory;\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.context.annotation.EnableAspectJAutoProxy;\r
-import org.springframework.stereotype.Component;\r
-import org.springframework.transaction.annotation.Transactional;\r
-\r
-import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;\r
-import org.openecomp.portalsdk.core.onboarding.util.PortalApiConstants;\r
-import org.openecomp.portalsdk.core.onboarding.util.PortalApiProperties;\r
-import org.openecomp.portalsdk.core.onboarding.ueb.Helper;\r
-import org.openecomp.portalsdk.core.onboarding.ueb.Publisher;\r
-import org.openecomp.portalsdk.core.onboarding.ueb.UebException;\r
-import org.openecomp.portalsdk.core.onboarding.ueb.UebManager;\r
-import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg;\r
-import org.openecomp.portalapp.portal.domain.EPApp;\r
-import org.openecomp.portalapp.portal.domain.EcompApp;\r
-import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;\r
-import org.openecomp.portalapp.portal.logging.format.EPAppMessagesEnum;\r
-import org.openecomp.portalapp.portal.logging.logic.EPLogUtil;\r
-import org.openecomp.portalapp.portal.service.EPAppService;\r
-import org.openecomp.portalapp.portal.utils.EcompPortalUtils;\r
-\r
-@Component\r
-@Transactional\r
-@org.springframework.context.annotation.Configuration\r
-@EnableAspectJAutoProxy\r
-public class EPUebHelper {\r
- EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPUebHelper.class);\r
- \r
- @Autowired\r
- EPAppService appsService;\r
- \r
- \r
- @Autowired\r
- private SessionFactory sessionFactory;\r
- \r
- @SuppressWarnings("unused")\r
- private Publisher epPublisher;\r
- \r
- public EPUebHelper() {\r
- \r
- }\r
- //\r
- // This should only be called by the ECOMP Portal App, other Apps have just one publisher and use appPublisher\r
- //\r
- @SuppressWarnings("unused")\r
- @EPMetricsLog\r
- public void refreshPublisherList()\r
- {\r
- Session localSession = null;\r
- boolean addedPublisher = false;\r
- \r
- try {\r
- localSession = sessionFactory.openSession();\r
- \r
- List<EcompApp> apps = appsService.getEcompAppAppsFullList();\r
- for (int i = 0; i < apps.size(); i++) \r
- {\r
- if ((apps.get(i).isEnabled()) &&\r
- (apps.get(i).getUebTopicName() != null) &&\r
- !(apps.get(i).getUebTopicName().toUpperCase().contains("ECOMP-PORTAL-INBOX")))\r
- {\r
- logger.debug(EELFLoggerDelegate.debugLogger, "UEBManager adding publisher for " + apps.get(i).getUebTopicName());\r
- UebManager.getInstance().addPublisher(apps.get(i).getUebTopicName());\r
- addedPublisher = true;\r
- }\r
- else if ((apps.get(i).getId() != 1) && // App may have been disabled, remove the publisher\r
- !(apps.get(i).isEnabled()))\r
- {\r
- if(apps.get(i).getUebTopicName()!=null){\r
- UebManager.getInstance().removePublisher(apps.get(i).getUebTopicName());\r
- }\r
- }\r
- }\r
- }\r
- catch (Exception e)\r
- {\r
- EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeUebSystemError, e, "add/remove Publisher");\r
- logger.error(EELFLoggerDelegate.errorLogger, "Exception occurred while refreshing the publisher list", e);\r
- }\r
- \r
- //publisherList.print();\r
- \r
- if (addedPublisher == true) // Give publishers time to initialize\r
- {\r
- Helper.sleep(400);\r
- }\r
- }\r
- \r
- @PostConstruct\r
- @EPMetricsLog\r
- public void initUeb() {\r
- try {\r
- epPublisher = new Publisher(PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY), \r
- PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_SECRET), \r
- PortalApiProperties.getProperty(PortalApiConstants.ECOMP_PORTAL_INBOX_NAME));\r
- } catch (Exception e) {\r
- EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeUebConnectionError, e);\r
- String stackTrace = EcompPortalUtils.getStackTrace(e);\r
- logger.error(EELFLoggerDelegate.errorLogger, "Exception occurred while initializing the publisher. Details: " + stackTrace);\r
- }\r
- \r
- Thread thread = new Thread("EPUebManager: postConstructMethod - refreshPublisherList") {\r
- public void run(){\r
- refreshPublisherList();\r
- }\r
- };\r
- if (thread != null) {\r
- thread.start();\r
- }\r
- }\r
-\r
- @EPMetricsLog\r
- public void addPublisher(EPApp app) {\r
- // TODO Auto-generated method stub\r
- try {\r
- UebManager.getInstance().addPublisher(app.getUebTopicName());\r
- } catch (UebException e) {\r
- String stackTrace = EcompPortalUtils.getStackTrace(e);\r
- logger.error(EELFLoggerDelegate.errorLogger, "Exception while adding a publisher. Details: " + stackTrace);\r
- }\r
- }\r
- \r
- public boolean checkAvailability() {\r
- \r
- //\r
- // Test existence of topic at UEB url\r
- //\r
- // (ie http://uebsb91kcdc.it.att.com:3904/topics/ECOMP-PORTAL-INBOX)\r
- //\r
- boolean available = true;\r
- LinkedList<String> urlList = Helper.uebUrlList();\r
- if (!urlList.isEmpty()) {\r
- String url = "http://" + urlList.getFirst() + ":3904/topics/" + PortalApiProperties.getProperty(PortalApiConstants.ECOMP_PORTAL_INBOX_NAME);\r
- if (!url.isEmpty()) {\r
- try {\r
- URL siteURL = new URL(url);\r
- HttpURLConnection connection = (HttpURLConnection) siteURL.openConnection();\r
- connection.setRequestMethod("GET");\r
- connection.connect();\r
- \r
- int code = connection.getResponseCode();\r
- if (code == 200) {\r
- available = true;\r
- }\r
- else {\r
- EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeUebConnectionError, url);\r
- available = false;\r
- logger.warn(EELFLoggerDelegate.errorLogger, "Warning! UEB topic existence check failed, topic = " + url );\r
- logger.debug(EELFLoggerDelegate.debugLogger, "Warning! UEB topic existence check failed, topic = " + url );\r
- }\r
- }\r
- catch (Exception e) {\r
- available = false;\r
- String stackTrace = EcompPortalUtils.getStackTrace(e);\r
- logger.error(EELFLoggerDelegate.errorLogger, "Exception occurred while performing the UEB Healthcheck. Details: " + stackTrace);\r
- }\r
- }\r
- }\r
- return available;\r
- }\r
- \r
- public boolean MessageCanBeSentToTopic() {\r
- \r
- boolean sentMsgSuccessfully = false;\r
- \r
- UebMsg msg = new UebMsg();\r
- msg.putSourceTopicName(PortalApiProperties.getProperty(PortalApiConstants.ECOMP_PORTAL_INBOX_NAME));\r
- msg.putPayload("Pinging topic for health check");\r
- msg.putMsgType(EPUebMsgTypes.UEB_MSG_TYPE_HEALTH_CHECK);\r
- \r
- try {\r
- // epPublisher.send(msg);\r
- sentMsgSuccessfully = true;\r
- } \r
- catch (Exception e) {\r
- EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeHealthCheckUebClusterError, e);\r
- sentMsgSuccessfully = false;\r
- logger.warn(EELFLoggerDelegate.errorLogger, "Warning! could not successfully publish a UEB msg to " \r
- + PortalApiProperties.getProperty(PortalApiConstants.ECOMP_PORTAL_INBOX_NAME), e); \r
- } \r
- \r
- return sentMsgSuccessfully;\r
- }\r
- \r
-}\r
-\r
-\r
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the “License”);
+ * you may not use this software except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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============================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.openecomp.portalapp.portal.ueb;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.openecomp.portalapp.portal.domain.EPApp;
+import org.openecomp.portalapp.portal.domain.EcompApp;
+import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
+import org.openecomp.portalapp.portal.logging.format.EPAppMessagesEnum;
+import org.openecomp.portalapp.portal.logging.logic.EPLogUtil;
+import org.openecomp.portalapp.portal.service.EPAppService;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.portalsdk.core.onboarding.ueb.Helper;
+import org.openecomp.portalsdk.core.onboarding.ueb.Publisher;
+import org.openecomp.portalsdk.core.onboarding.ueb.UebException;
+import org.openecomp.portalsdk.core.onboarding.ueb.UebManager;
+import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg;
+import org.openecomp.portalsdk.core.onboarding.util.PortalApiConstants;
+import org.openecomp.portalsdk.core.onboarding.util.PortalApiProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+@Component
+@Transactional
+@org.springframework.context.annotation.Configuration
+@EnableAspectJAutoProxy
+public class EPUebHelper {
+ private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPUebHelper.class);
+
+ @Autowired
+ private EPAppService appsService;
+
+ @Autowired
+ private SessionFactory sessionFactory;
+
+ @SuppressWarnings("unused")
+ private Publisher epPublisher;
+
+ public EPUebHelper() {
+
+ }
+ //
+ // This should only be called by the ECOMP Portal App, other Apps have just one publisher and use appPublisher
+ //
+ @SuppressWarnings("unused")
+ @EPMetricsLog
+ public void refreshPublisherList()
+ {
+ Session localSession = null;
+ boolean addedPublisher = false;
+
+ try {
+ localSession = sessionFactory.openSession();
+
+ List<EcompApp> apps = appsService.getEcompAppAppsFullList();
+ for (int i = 0; i < apps.size(); i++)
+ {
+ if ((apps.get(i).isEnabled()) &&
+ (apps.get(i).getUebTopicName() != null) &&
+ !(apps.get(i).getUebTopicName().toUpperCase().contains("ECOMP-PORTAL-INBOX")))
+ {
+ logger.debug(EELFLoggerDelegate.debugLogger, "UEBManager adding publisher for " + apps.get(i).getUebTopicName());
+ UebManager.getInstance().addPublisher(apps.get(i).getUebTopicName());
+ addedPublisher = true;
+ }
+ else if ((apps.get(i).getId() != 1) && // App may have been disabled, remove the publisher
+ !(apps.get(i).isEnabled()))
+ {
+ if(apps.get(i).getUebTopicName()!=null){
+ UebManager.getInstance().removePublisher(apps.get(i).getUebTopicName());
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeUebSystemError, e, "add/remove Publisher");
+ logger.error(EELFLoggerDelegate.errorLogger, "Exception occurred while refreshing the publisher list", e);
+ }
+
+ //publisherList.print();
+
+ if (addedPublisher == true) // Give publishers time to initialize
+ {
+ Helper.sleep(400);
+ }
+ }
+
+ @PostConstruct
+ @EPMetricsLog
+ public void initUeb() {
+ try {
+ epPublisher = new Publisher(PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY),
+ PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_SECRET),
+ PortalApiProperties.getProperty(PortalApiConstants.ECOMP_PORTAL_INBOX_NAME));
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "initUeb failed", e);
+ EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeUebConnectionError, e);
+ }
+
+ Thread thread = new Thread("EPUebManager: postConstructMethod - refreshPublisherList") {
+ public void run(){
+ refreshPublisherList();
+ }
+ };
+ thread.start();
+
+ }
+
+ @EPMetricsLog
+ public void addPublisher(EPApp app) {
+ // TODO Auto-generated method stub
+ try {
+ UebManager.getInstance().addPublisher(app.getUebTopicName());
+ } catch (UebException e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "addPublisher failed", e);
+ }
+ }
+
+ public boolean checkAvailability() {
+ //
+ // Test existence of topic at UEB url
+ //
+ // (ie http://uebsb91kcdc.it.com:3904/topics/ECOMP-PORTAL-INBOX)
+ //
+ boolean available = true;
+ LinkedList<String> urlList = Helper.uebUrlList();
+ if (!urlList.isEmpty()) {
+ String url = "http://" + urlList.getFirst() + ":3904/topics/" + PortalApiProperties.getProperty(PortalApiConstants.ECOMP_PORTAL_INBOX_NAME);
+ if (!url.isEmpty()) {
+ try {
+ URL siteURL = new URL(url);
+ HttpURLConnection connection = (HttpURLConnection) siteURL.openConnection();
+ connection.setRequestMethod("GET");
+ connection.connect();
+
+ int code = connection.getResponseCode();
+ if (code == 200) {
+ available = true;
+ }
+ else {
+ EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeUebConnectionError, url);
+ available = false;
+ logger.warn(EELFLoggerDelegate.errorLogger, "Warning! UEB topic existence check failed, topic = " + url );
+ logger.debug(EELFLoggerDelegate.debugLogger, "Warning! UEB topic existence check failed, topic = " + url );
+ }
+ }
+ catch (Exception e) {
+ available = false;
+ logger.error(EELFLoggerDelegate.errorLogger, "checkAvailability failed", e);
+ }
+ }
+ }
+ return available;
+ }
+
+ public boolean MessageCanBeSentToTopic() {
+
+ boolean sentMsgSuccessfully = false;
+
+ UebMsg msg = new UebMsg();
+ msg.putSourceTopicName(PortalApiProperties.getProperty(PortalApiConstants.ECOMP_PORTAL_INBOX_NAME));
+ msg.putPayload("Pinging topic for health check");
+ msg.putMsgType(EPUebMsgTypes.UEB_MSG_TYPE_HEALTH_CHECK);
+
+ try {
+ // epPublisher.send(msg);
+ sentMsgSuccessfully = true;
+ }
+ catch (Exception e) {
+ EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeHealthCheckUebClusterError, e);
+ sentMsgSuccessfully = false;
+ logger.warn(EELFLoggerDelegate.errorLogger, "Warning! could not successfully publish a UEB msg to "
+ + PortalApiProperties.getProperty(PortalApiConstants.ECOMP_PORTAL_INBOX_NAME), e);
+ }
+
+ return sentMsgSuccessfully;
+ }
+
+}
+
+