diff options
Diffstat (limited to 'common-app-api/src/main/java/org/openecomp/sdc/fe')
5 files changed, 686 insertions, 0 deletions
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/fe/config/Configuration.java b/common-app-api/src/main/java/org/openecomp/sdc/fe/config/Configuration.java new file mode 100644 index 0000000000..89953d671e --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/fe/config/Configuration.java @@ -0,0 +1,304 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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 + * + * 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========================================================= + */ + +package org.openecomp.sdc.fe.config; + +import java.util.Date; +import java.util.List; + +import org.openecomp.sdc.common.api.BasicConfiguration; + +import static java.lang.String.format; + +public class Configuration extends BasicConfiguration { + /** + * fe FQDN + */ + private String feFqdn; + /** + * backend host + */ + private String beHost; + /** + * backend http port + */ + private Integer beHttpPort; + /** + * backend http secured port + */ + private Integer beSslPort; + + private Integer healthCheckSocketTimeoutInMs; + + private Integer healthCheckIntervalInSeconds; + + private FeMonitoringConfig systemMonitoring; + + private String kibanaHost; + + private Integer kibanaPort; + + private String kibanaProtocol; + + private String onboardingForwardContext; + + public String getKibanaProtocol() { + return kibanaProtocol; + } + + public void setKibanaProtocol(String kibanaProtocol) { + this.kibanaProtocol = kibanaProtocol; + } + + public String getKibanaHost() { + return kibanaHost; + } + + public void setKibanaHost(String kibanaHost) { + this.kibanaHost = kibanaHost; + } + + public Integer getKibanaPort() { + return kibanaPort; + } + + public void setKibanaPort(Integer kibanaPort) { + this.kibanaPort = kibanaPort; + } + + public FeMonitoringConfig getSystemMonitoring() { + return systemMonitoring; + } + + public void setSystemMonitoring(FeMonitoringConfig systemMonitoring) { + this.systemMonitoring = systemMonitoring; + } + + public Integer getHealthCheckSocketTimeoutInMs() { + return healthCheckSocketTimeoutInMs; + } + + public Integer getHealthCheckSocketTimeoutInMs(int defaultVal) { + return healthCheckSocketTimeoutInMs == null ? defaultVal : healthCheckSocketTimeoutInMs; + } + + public void setHealthCheckSocketTimeoutInMs(Integer healthCheckSocketTimeout) { + this.healthCheckSocketTimeoutInMs = healthCheckSocketTimeout; + } + + public Integer getHealthCheckIntervalInSeconds() { + return healthCheckIntervalInSeconds; + } + + public Integer getHealthCheckIntervalInSeconds(int defaultVal) { + return healthCheckIntervalInSeconds == null ? defaultVal : healthCheckIntervalInSeconds; + } + + public void setHealthCheckIntervalInSeconds(Integer healthCheckInterval) { + this.healthCheckIntervalInSeconds = healthCheckInterval; + } + + /** + * be http context + */ + private String beContext; + /** + * backend protocol. http | https + */ + private String beProtocol = "http"; + + private Date released; + private String version = "1111"; + private Connection connection; + private List<String> protocols; + + private int threadpoolSize; + private int requestTimeout; + + private List<List<String>> identificationHeaderFields; + private List<List<String>> optionalHeaderFields; + + public Date getReleased() { + return released; + } + + public String getVersion() { + return version; + } + + public void setReleased(Date released) { + this.released = released; + } + + public void setVersion(String version) { + this.version = version; + } + + public Connection getConnection() { + return connection; + } + + public void setConnection(Connection connection) { + this.connection = connection; + } + + public List<String> getProtocols() { + return protocols; + } + + public void setProtocols(List<String> protocols) { + this.protocols = protocols; + } + + public String getBeHost() { + return beHost; + } + + public void setBeHost(String beHost) { + this.beHost = beHost; + } + + public Integer getBeHttpPort() { + return beHttpPort; + } + + public void setBeHttpPort(Integer beHttpPort) { + this.beHttpPort = beHttpPort; + } + + public Integer getBeSslPort() { + return beSslPort; + } + + public void setBeSslPort(Integer beSslPort) { + this.beSslPort = beSslPort; + } + + public String getBeContext() { + return beContext; + } + + public void setBeContext(String beContext) { + this.beContext = beContext; + } + + public String getBeProtocol() { + return beProtocol; + } + + public void setBeProtocol(String beProtocol) { + this.beProtocol = beProtocol; + } + + public int getThreadpoolSize() { + return threadpoolSize; + } + + public void setThreadpoolSize(int threadpoolSize) { + this.threadpoolSize = threadpoolSize; + } + + public int getRequestTimeout() { + return requestTimeout; + } + + public void setRequestTimeout(int requestTimeout) { + this.requestTimeout = requestTimeout; + } + + public List<List<String>> getIdentificationHeaderFields() { + return identificationHeaderFields; + } + + public void setIdentificationHeaderFields(List<List<String>> identificationHeaderFields) { + this.identificationHeaderFields = identificationHeaderFields; + } + + public List<List<String>> getOptionalHeaderFields() { + return optionalHeaderFields; + } + + public void setOptionalHeaderFields(List<List<String>> optionalHeaderFields) { + this.optionalHeaderFields = optionalHeaderFields; + } + + public String getFeFqdn() { + return feFqdn; + } + + public void setFeFqdn(String feFqdn) { + this.feFqdn = feFqdn; + } + + public static class FeMonitoringConfig { + + Boolean enabled; + Boolean isProxy; + Integer probeIntervalInSeconds; + + public Boolean getEnabled() { + return enabled; + } + + public void setEnabled(Boolean enabled) { + this.enabled = enabled; + } + + public Boolean getIsProxy() { + return isProxy; + } + + public void setIsProxy(Boolean isProxy) { + this.isProxy = isProxy; + } + + public Integer getProbeIntervalInSeconds() { + return probeIntervalInSeconds; + } + + public Integer getProbeIntervalInSeconds(int defaultVal) { + return probeIntervalInSeconds == null ? defaultVal : probeIntervalInSeconds; + } + + public void setProbeIntervalInSeconds(Integer probeIntervalInSeconds) { + this.probeIntervalInSeconds = probeIntervalInSeconds; + } + } + + public String getOnboardingForwardContext() { + return onboardingForwardContext; + } + + public void setOnboardingForwardContext(String onboardingForwardContext) { + this.onboardingForwardContext = onboardingForwardContext; + } + + @Override + public String toString() { + return new StringBuilder().append(format("backend host: %s%n", beHost)) + .append(format("backend http port: %s%n", beHttpPort)) + .append(format("backend ssl port: %s%n", beSslPort)).append(format("backend context: %s%n", beContext)) + .append(format("backend protocol: %s%n", beProtocol)) + .append(format("onboarding forward context: %s%n", onboardingForwardContext)) + .append(format("Version: %s%n", version)).append(format("Released: %s%n", released)) + .append(format("Connecting to database: %s%n", connection)) + .append(format("Supported protocols: %s%n", protocols)).toString(); + } +} diff --git a/common-app-api/src/main/java/org/openecomp/sdc/fe/config/ConfigurationManager.java b/common-app-api/src/main/java/org/openecomp/sdc/fe/config/ConfigurationManager.java new file mode 100644 index 0000000000..b3164fd283 --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/fe/config/ConfigurationManager.java @@ -0,0 +1,117 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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 + * + * 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========================================================= + */ + +package org.openecomp.sdc.fe.config; + +import java.util.HashMap; +import java.util.Map; + +import org.openecomp.sdc.common.api.BasicConfiguration; +import org.openecomp.sdc.common.api.ConfigurationListener; +import org.openecomp.sdc.common.api.ConfigurationSource; +import org.openecomp.sdc.common.api.FileChangeCallback; +import org.openecomp.sdc.common.config.EcompErrorConfiguration; +import org.openecomp.sdc.common.config.IEcompConfigurationManager; +import org.openecomp.sdc.common.rest.api.RestConfigurationInfo; + +public class ConfigurationManager implements FileChangeCallback, IEcompConfigurationManager { + + ConfigurationSource configurationSource = null; + private static ConfigurationManager instance; + + public ConfigurationManager(ConfigurationSource configurationSource) { + super(); + this.configurationSource = configurationSource; + loadConfigurationFiles(); + instance = this; + } + + Map<String, Object> configurations = new HashMap<String, Object>(); + + private void loadConfigurationFiles() { + + loadConfigurationClass(Configuration.class); + loadConfigurationClass(RestConfigurationInfo.class); + loadConfigurationClass(EcompErrorConfiguration.class); + + } + + private <T extends BasicConfiguration> void loadConfigurationClass(Class<T> clazz) { + ConfigurationListener configurationListener = new ConfigurationListener(clazz, this); + + T object = configurationSource.getAndWatchConfiguration(clazz, configurationListener); + + configurations.put(getKey(clazz), object); + } + + private <T> String getKey(Class<T> class1) { + + return class1.getSimpleName(); + + } + + public Configuration getConfiguration() { + + return (Configuration) configurations.get(getKey(Configuration.class)); + + } + + public RestConfigurationInfo getRestClientConfiguration() { + + return (RestConfigurationInfo) configurations.get(getKey(RestConfigurationInfo.class)); + + } + + @Override + public EcompErrorConfiguration getEcompErrorConfiguration() { + + return (EcompErrorConfiguration) configurations.get(getKey(EcompErrorConfiguration.class)); + + } + + public Configuration getConfigurationAndWatch(ConfigurationListener configurationListener) { + + if (configurationListener != null) { + + configurationSource.addWatchConfiguration(Configuration.class, configurationListener); + + } + return (Configuration) configurations.get(getKey(Configuration.class)); + + } + + public void reconfigure(BasicConfiguration obj) { + // + // if (obj != null) { + // + // if (obj instanceof Configuration) { + // configurations.put(getKey(Configuration.class), obj); + // } + // + // if (obj instanceof EcompErrorConfiguration) { + // configurations.put(getKey(EcompErrorConfiguration.class), obj); + // } + // } + } + + public static ConfigurationManager getConfigurationManager() { + return instance; + } +} diff --git a/common-app-api/src/main/java/org/openecomp/sdc/fe/config/Connection.java b/common-app-api/src/main/java/org/openecomp/sdc/fe/config/Connection.java new file mode 100644 index 0000000000..7208398525 --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/fe/config/Connection.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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 + * + * 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========================================================= + */ + +package org.openecomp.sdc.fe.config; + +public class Connection { + + private String url; + private int poolSize; + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public int getPoolSize() { + return poolSize; + } + + public void setPoolSize(int poolSize) { + this.poolSize = poolSize; + } + + @Override + public String toString() { + return String.format("'%s' with pool of %d", getUrl(), getPoolSize()); + } +} diff --git a/common-app-api/src/main/java/org/openecomp/sdc/fe/config/FeEcompErrorManager.java b/common-app-api/src/main/java/org/openecomp/sdc/fe/config/FeEcompErrorManager.java new file mode 100644 index 0000000000..6733e179ba --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/fe/config/FeEcompErrorManager.java @@ -0,0 +1,77 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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 + * + * 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========================================================= + */ + +package org.openecomp.sdc.fe.config; + +import org.openecomp.sdc.common.config.AbsEcompErrorManager; +import org.openecomp.sdc.common.config.EcompErrorEnum; +import org.openecomp.sdc.common.config.IEcompConfigurationManager; +import org.openecomp.sdc.fe.config.ConfigurationManager; + +public class FeEcompErrorManager extends AbsEcompErrorManager { + + private static volatile FeEcompErrorManager instance; + private static ConfigurationManager configurationManager; + + private FeEcompErrorManager() { + }; + + public static FeEcompErrorManager getInstance() { + if (instance == null) { + + instance = init(); + } + return instance; + } + + private static synchronized FeEcompErrorManager init() { + if (instance == null) { + instance = new FeEcompErrorManager(); + configurationManager = ConfigurationManager.getConfigurationManager(); + } + return instance; + } + + @Override + public IEcompConfigurationManager getConfigurationManager() { + return configurationManager; + } + + public void logFeHealthCheckRecovery(String context) { + processEcompError(context, EcompErrorEnum.FeHealthCheckRecovery); + } + + public void logFeHealthCheckError(String context) { + processEcompError(context, EcompErrorEnum.FeHealthCheckError); + } + + public void logFeHttpLoggingError(String context) { + processEcompError(context, EcompErrorEnum.FeHttpLoggingError); + } + + public void logFePortalServletError(String context) { + processEcompError(context, EcompErrorEnum.FePortalServletError); + } + + public void logFeHealthCheckGeneralError(String context) { + processEcompError(context, EcompErrorEnum.FeHealthCheckGeneralError); + } + +} diff --git a/common-app-api/src/main/java/org/openecomp/sdc/fe/monitoring/FeMonitoringService.java b/common-app-api/src/main/java/org/openecomp/sdc/fe/monitoring/FeMonitoringService.java new file mode 100644 index 0000000000..482be7697d --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/fe/monitoring/FeMonitoringService.java @@ -0,0 +1,140 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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 + * + * 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========================================================= + */ + +package org.openecomp.sdc.fe.monitoring; + +import java.io.IOException; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; + +import javax.servlet.ServletContext; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpStatus; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.openecomp.sdc.common.api.Constants; +import org.openecomp.sdc.common.monitoring.MonitoringEvent; +import org.openecomp.sdc.common.monitoring.MonitoringMetricsFetcher; +import org.openecomp.sdc.fe.config.Configuration; +import org.openecomp.sdc.fe.config.ConfigurationManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public class FeMonitoringService { + + private static final String URL = "%s://%s:%s/sdc2/rest/monitoring"; + private static Logger monitoringLogger = LoggerFactory.getLogger("asdc.fe.monitoring.service"); + private static Logger log = LoggerFactory.getLogger(FeMonitoringService.class.getName()); + private static Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + private class MonitoringScheduledTask implements Runnable { + @Override + public void run() { + monitoringLogger.trace("Executing FE Monitoring Task - Start"); + MonitoringEvent monitoringMetrics = MonitoringMetricsFetcher.getInstance().getMonitoringMetrics(); + processMonitoringEvent(monitoringMetrics); + monitoringLogger.trace("Executing FE Monitoring Task - Status = {}", monitoringMetrics.toString()); + } + } + + /** + * This executor will execute the Monitoring task. + */ + ScheduledExecutorService monitoringExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + return new Thread(r, "FE-Monitoring-Thread"); + } + }); + private ServletContext context; + + public FeMonitoringService(ServletContext context) { + this.context = context; + } + + public void start(int interval) { + Configuration config = ((ConfigurationManager) context.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)) + .getConfiguration(); + if (config.getSystemMonitoring().getEnabled()) { + log.info("FE monitoring service enabled, interval is {} seconds", interval); + this.monitoringExecutor.scheduleAtFixedRate(new MonitoringScheduledTask(), 0, interval, TimeUnit.SECONDS); + } else { + log.info("FE monitoring service is disabled"); + } + } + + private void processMonitoringEvent(MonitoringEvent monitoringMetrics) { + CloseableHttpClient httpClient = null; + try { + Configuration config = ((ConfigurationManager) context.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)) + .getConfiguration(); + String redirectedUrl = String.format(URL, config.getBeProtocol(), config.getBeHost(), + config.getBeHttpPort()); + httpClient = getHttpClient(config); + HttpPost httpPost = new HttpPost(redirectedUrl); + String monitoringMetricsJson = gson.toJson(monitoringMetrics); + HttpEntity myEntity = new StringEntity(monitoringMetricsJson); + httpPost.setEntity(myEntity); + httpPost.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + int beResponseStatus; + CloseableHttpResponse beResponse; + try { + beResponse = httpClient.execute(httpPost); + beResponseStatus = beResponse.getStatusLine().getStatusCode(); + if (beResponseStatus != HttpStatus.SC_OK) { + monitoringLogger.error("Unexpected HTTP response from BE : {}", beResponseStatus); + } + } catch (Exception e) { + monitoringLogger.error("Monitoring error when trying to connect to BE", e); + } + } catch (Exception e) { + monitoringLogger.error("Unexpected monitoring error", e); + } finally { + if (httpClient != null) { + try { + httpClient.close(); + } catch (IOException e) { + } + } + } + } + + private CloseableHttpClient getHttpClient(Configuration config) { + int timeout = 3000; + RequestConfig.Builder requestBuilder = RequestConfig.custom(); + requestBuilder.setConnectTimeout(timeout).setConnectionRequestTimeout(timeout).setSocketTimeout(timeout); + + HttpClientBuilder builder = HttpClientBuilder.create(); + builder.setDefaultRequestConfig(requestBuilder.build()); + return builder.build(); + } +} |