From 781b1a6df324419c846c84ea983c18fc8362bfd3 Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 13 Dec 2017 11:19:06 -0800 Subject: Third part of onap rename This part of the commit changes the folder structure on all other folders of appc. Change-Id: I8acfa11cdfcdcd36be0e137245d1dd7324f1abd3 Signed-off-by: Patrick Brady Issue-ID: APPC-13 --- .../main/java/org/onap/appc/MetricActivator.java | 56 ++++++ .../onap/appc/metricservice/MetricRegistry.java | 49 +++++ .../org/onap/appc/metricservice/MetricService.java | 41 ++++ .../org/onap/appc/metricservice/Publisher.java | 37 ++++ .../metricservice/impl/MetricRegistryImpl.java | 101 ++++++++++ .../appc/metricservice/impl/MetricServiceImpl.java | 59 ++++++ .../onap/appc/metricservice/metric/Counter.java | 30 +++ .../metric/DispatchingFunctionCounterBuilder.java | 34 ++++ .../metric/DispatchingFuntionMetric.java | 32 +++ .../metric/DmaapRequestCounterBuilder.java | 34 ++++ .../metric/DmaapRequestCounterMetric.java | 32 +++ .../org/onap/appc/metricservice/metric/Metric.java | 55 +++++ .../metricservice/metric/MetricBuilderFactory.java | 33 +++ .../onap/appc/metricservice/metric/MetricType.java | 35 ++++ .../metricservice/metric/PrimitiveCounter.java | 36 ++++ .../metric/PrimitiveCounterBuilder.java | 36 ++++ .../metric/impl/DefaultPrimitiveCounter.java | 113 +++++++++++ .../DispatchingFunctionCounterBuilderImpl.java | 64 ++++++ .../metric/impl/DispatchingFuntionMetricImpl.java | 124 ++++++++++++ .../impl/DmaapRequestCounterBuilderImpl.java | 67 ++++++ .../metric/impl/DmaapRequestCounterMetricImpl.java | 121 +++++++++++ .../metric/impl/MetricBuilderFactoryImpl.java | 48 +++++ .../metric/impl/PrimitiveCounterBuilderImpl.java | 59 ++++++ .../metricservice/policy/PolicyBuilderFactory.java | 30 +++ .../metricservice/policy/PublishingPolicy.java | 43 ++++ .../policy/ScheduledPolicyBuilder.java | 41 ++++ .../policy/ScheduledPublishingPolicy.java | 36 ++++ .../policy/impl/PolicyBuilderFactoryImpl.java | 36 ++++ .../policy/impl/ScheduledPolicyBuilderImpl.java | 68 +++++++ .../policy/impl/ScheduledPublishingPolicyImpl.java | 224 +++++++++++++++++++++ .../appc/metricservice/publisher/LogPublisher.java | 52 +++++ .../java/org/openecomp/appc/MetricActivator.java | 56 ------ .../appc/metricservice/MetricRegistry.java | 49 ----- .../appc/metricservice/MetricService.java | 41 ---- .../openecomp/appc/metricservice/Publisher.java | 37 ---- .../metricservice/impl/MetricRegistryImpl.java | 101 ---------- .../appc/metricservice/impl/MetricServiceImpl.java | 59 ------ .../appc/metricservice/metric/Counter.java | 30 --- .../metric/DispatchingFunctionCounterBuilder.java | 34 ---- .../metric/DispatchingFuntionMetric.java | 32 --- .../metric/DmaapRequestCounterBuilder.java | 34 ---- .../metric/DmaapRequestCounterMetric.java | 32 --- .../appc/metricservice/metric/Metric.java | 55 ----- .../metricservice/metric/MetricBuilderFactory.java | 33 --- .../appc/metricservice/metric/MetricType.java | 35 ---- .../metricservice/metric/PrimitiveCounter.java | 36 ---- .../metric/PrimitiveCounterBuilder.java | 36 ---- .../metric/impl/DefaultPrimitiveCounter.java | 113 ----------- .../DispatchingFunctionCounterBuilderImpl.java | 64 ------ .../metric/impl/DispatchingFuntionMetricImpl.java | 124 ------------ .../impl/DmaapRequestCounterBuilderImpl.java | 67 ------ .../metric/impl/DmaapRequestCounterMetricImpl.java | 121 ----------- .../metric/impl/MetricBuilderFactoryImpl.java | 48 ----- .../metric/impl/PrimitiveCounterBuilderImpl.java | 59 ------ .../metricservice/policy/PolicyBuilderFactory.java | 30 --- .../metricservice/policy/PublishingPolicy.java | 43 ---- .../policy/ScheduledPolicyBuilder.java | 41 ---- .../policy/ScheduledPublishingPolicy.java | 36 ---- .../policy/impl/PolicyBuilderFactoryImpl.java | 36 ---- .../policy/impl/ScheduledPolicyBuilderImpl.java | 68 ------- .../policy/impl/ScheduledPublishingPolicyImpl.java | 224 --------------------- .../appc/metricservice/publisher/LogPublisher.java | 52 ----- .../resources/org/onap/appc/default.properties | 31 +++ .../org/openecomp/appc/default.properties | 31 --- .../appc/metricservice/TestMetricServiceImpl.java | 169 ++++++++++++++++ .../appc/metricservice/TestMetricServiceImpl.java | 169 ---------------- .../resources/org/onap/appc/default.properties | 29 +++ .../org/openecomp/appc/default.properties | 29 --- 68 files changed, 2055 insertions(+), 2055 deletions(-) create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/MetricActivator.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/MetricRegistry.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/MetricService.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/Publisher.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/impl/MetricRegistryImpl.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/impl/MetricServiceImpl.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/Counter.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/DispatchingFunctionCounterBuilder.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/DispatchingFuntionMetric.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/DmaapRequestCounterBuilder.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/DmaapRequestCounterMetric.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/Metric.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/MetricBuilderFactory.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/MetricType.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/PrimitiveCounter.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/PrimitiveCounterBuilder.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DefaultPrimitiveCounter.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DispatchingFunctionCounterBuilderImpl.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DispatchingFuntionMetricImpl.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DmaapRequestCounterBuilderImpl.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DmaapRequestCounterMetricImpl.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/MetricBuilderFactoryImpl.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/PrimitiveCounterBuilderImpl.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/PolicyBuilderFactory.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/PublishingPolicy.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/ScheduledPolicyBuilder.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/ScheduledPublishingPolicy.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/impl/PolicyBuilderFactoryImpl.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/impl/ScheduledPolicyBuilderImpl.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/impl/ScheduledPublishingPolicyImpl.java create mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/publisher/LogPublisher.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/MetricActivator.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/MetricRegistry.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/MetricService.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/Publisher.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/impl/MetricRegistryImpl.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/impl/MetricServiceImpl.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/Counter.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/DispatchingFunctionCounterBuilder.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/DispatchingFuntionMetric.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/DmaapRequestCounterBuilder.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/DmaapRequestCounterMetric.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/Metric.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/MetricBuilderFactory.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/MetricType.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/PrimitiveCounter.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/PrimitiveCounterBuilder.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DefaultPrimitiveCounter.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DispatchingFunctionCounterBuilderImpl.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DispatchingFuntionMetricImpl.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DmaapRequestCounterBuilderImpl.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DmaapRequestCounterMetricImpl.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/MetricBuilderFactoryImpl.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/PrimitiveCounterBuilderImpl.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/PolicyBuilderFactory.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/PublishingPolicy.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/ScheduledPolicyBuilder.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/ScheduledPublishingPolicy.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/impl/PolicyBuilderFactoryImpl.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/impl/ScheduledPolicyBuilderImpl.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/impl/ScheduledPublishingPolicyImpl.java delete mode 100644 appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/publisher/LogPublisher.java create mode 100644 appc-metric/appc-metric-bundle/src/main/resources/org/onap/appc/default.properties delete mode 100644 appc-metric/appc-metric-bundle/src/main/resources/org/openecomp/appc/default.properties create mode 100644 appc-metric/appc-metric-bundle/src/test/java/org/onap/appc/metricservice/TestMetricServiceImpl.java delete mode 100644 appc-metric/appc-metric-bundle/src/test/java/org/openecomp/appc/metricservice/TestMetricServiceImpl.java create mode 100644 appc-metric/appc-metric-bundle/src/test/resources/org/onap/appc/default.properties delete mode 100644 appc-metric/appc-metric-bundle/src/test/resources/org/openecomp/appc/default.properties (limited to 'appc-metric/appc-metric-bundle') diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/MetricActivator.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/MetricActivator.java new file mode 100644 index 000000000..40ff14827 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/MetricActivator.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc; + +import org.onap.appc.metricservice.MetricService; +import org.onap.appc.metricservice.impl.MetricServiceImpl; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + + +public class MetricActivator implements BundleActivator { + + private ServiceRegistration registration = null; + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(MetricActivator.class); + + @Override + public void start(BundleContext bundleContext) throws Exception { + logger.debug("Starting Metric service " ); + MetricService impl = new MetricServiceImpl(); + String regName = MetricService.class.getName(); + logger.debug("Registering Metric service " + regName); + registration = bundleContext.registerService(regName, impl, null); + logger.debug("Registered Metric service " + regName); + } + + @Override + public void stop(BundleContext bundleContext) throws Exception { + + } +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/MetricRegistry.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/MetricRegistry.java new file mode 100644 index 000000000..6e658ae47 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/MetricRegistry.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice; + +import org.onap.appc.metricservice.metric.Counter; +import org.onap.appc.metricservice.metric.Metric; +import org.onap.appc.metricservice.metric.MetricBuilderFactory; +import org.onap.appc.metricservice.policy.PolicyBuilderFactory; +import org.onap.appc.metricservice.policy.PublishingPolicy; + +/** + * + * A named group of metrics which might be related to a specific domain. The service doesn't limit number of metric registries per instance. + * It's up to application to decide on domain scope. The registry instances are independent. + * + */ +public interface MetricRegistry { + boolean register(Metric metric); + void attach (PublishingPolicy publishPolicy); + MetricBuilderFactory metricBuilderFactory(); + PolicyBuilderFactory policyBuilderFactory(); + Counter counter(String value); + Counter[] counters(); + Metric[] metrics(); + Metric metric(String metricName); + void dispose(); +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/MetricService.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/MetricService.java new file mode 100644 index 000000000..65ff72d97 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/MetricService.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice; + + +import java.util.Map; + +public interface MetricService { + MetricRegistry registry(String name); + MetricRegistry createRegistry(String name); + void dispose(); + + /** + * This API will be used to get the Map of all the registered Registry for the Metric Service + * @return Map where String will be the name of the Metric Registry + * and MetricRegistry will be the actual object for that Registry + */ + Map getAllRegistry(); +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/Publisher.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/Publisher.java new file mode 100644 index 000000000..1d38e44c3 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/Publisher.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice; + +import org.onap.appc.metricservice.metric.Metric; + +/** + * Low-level logic of exposing metric values in certain way. There might be plenty of options such as logging, JMX, etc. + * API to be supported by any logic that is going to be plugged into metric service. + * The publisher is considered as low-level technical unit which, potentially, can be reused to expose metrics from different registries + * + */ +public interface Publisher { + void publish(MetricRegistry metricRegistry,Metric[] metrics); +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/impl/MetricRegistryImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/impl/MetricRegistryImpl.java new file mode 100644 index 000000000..ac2054151 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/impl/MetricRegistryImpl.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.impl; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.onap.appc.metricservice.MetricRegistry; +import org.onap.appc.metricservice.metric.Counter; +import org.onap.appc.metricservice.metric.Metric; +import org.onap.appc.metricservice.metric.MetricBuilderFactory; +import org.onap.appc.metricservice.metric.impl.MetricBuilderFactoryImpl; +import org.onap.appc.metricservice.policy.PolicyBuilderFactory; +import org.onap.appc.metricservice.policy.PublishingPolicy; +import org.onap.appc.metricservice.policy.impl.PolicyBuilderFactoryImpl; + + +public class MetricRegistryImpl implements MetricRegistry { + private String name; + private Map concurrentMetricMap=new ConcurrentHashMap(); + + public MetricRegistryImpl(String name) { + this.name = name; + } + + @Override + public boolean register(Metric metric) { + if(concurrentMetricMap.get(metric.name())==null){ + concurrentMetricMap.put(metric.name(),metric); + return true; + } + return false; + } + + @Override + public void attach(PublishingPolicy publishPolicy) { +//TODO + } + + @Override + public MetricBuilderFactory metricBuilderFactory() { + return new MetricBuilderFactoryImpl(); + } + + @Override + public PolicyBuilderFactory policyBuilderFactory() { + return new PolicyBuilderFactoryImpl() ; + } + + @Override + public Counter counter(String value) { + if(concurrentMetricMap.get(value)!=null ) + return (Counter)concurrentMetricMap.get(value) ; + else + return null; + + } + + @Override + public Counter[] counters() { + return (Counter[])concurrentMetricMap.values().toArray(); + } + + @Override + public Metric[] metrics() { + java.util.Collection var = concurrentMetricMap.values(); + return var.toArray(new Metric[var.size()]); + } + + @Override + public Metric metric(String metricName) { + return concurrentMetricMap.get(metricName); + } + + @Override + public void dispose() { + concurrentMetricMap.clear(); + } +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/impl/MetricServiceImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/impl/MetricServiceImpl.java new file mode 100644 index 000000000..20f2d8d2e --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/impl/MetricServiceImpl.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.impl; + +import java.util.Collections; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.onap.appc.metricservice.MetricRegistry; +import org.onap.appc.metricservice.MetricService; + + +public class MetricServiceImpl implements MetricService { + private Map concurrentRegistryMap=new ConcurrentHashMap<>(); + @Override + public MetricRegistry registry(String name) { + return concurrentRegistryMap.get(name); + } + + @Override + public MetricRegistry createRegistry(String name) { + if(concurrentRegistryMap.get(name)==null) + concurrentRegistryMap.put(name,new MetricRegistryImpl(name)); + return concurrentRegistryMap.get(name); + } + + @Override + public Map getAllRegistry(){ + return Collections.unmodifiableMap(concurrentRegistryMap); + + } + + @Override + public void dispose() { +//TODO + } +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/Counter.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/Counter.java new file mode 100644 index 000000000..0b4d3e2d3 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/Counter.java @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.metric; + + +public interface Counter extends Metric { + long value(); +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/DispatchingFunctionCounterBuilder.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/DispatchingFunctionCounterBuilder.java new file mode 100644 index 000000000..bff07f627 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/DispatchingFunctionCounterBuilder.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.metric; + + +public interface DispatchingFunctionCounterBuilder { + DispatchingFunctionCounterBuilder withName(String name); + DispatchingFunctionCounterBuilder withAcceptRequestValue(long value); + DispatchingFunctionCounterBuilder withRejectRequestValue(long value); + DispatchingFunctionCounterBuilder withType(MetricType type); + DispatchingFuntionMetric build(); +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/DispatchingFuntionMetric.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/DispatchingFuntionMetric.java new file mode 100644 index 000000000..384875e9b --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/DispatchingFuntionMetric.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.metric; + + +public interface DispatchingFuntionMetric extends Metric { + void incrementAcceptedRequest(); + void incrementRejectedRequest(); + String value(); +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/DmaapRequestCounterBuilder.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/DmaapRequestCounterBuilder.java new file mode 100644 index 000000000..efb23963f --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/DmaapRequestCounterBuilder.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.metric; + + +public interface DmaapRequestCounterBuilder { + DmaapRequestCounterBuilder withName(String name); + DmaapRequestCounterBuilder withRecievedMessage(long value); + DmaapRequestCounterBuilder withPublishedMessage(long value); + DmaapRequestCounterBuilder withType(MetricType type); + DmaapRequestCounterMetric build(); +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/DmaapRequestCounterMetric.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/DmaapRequestCounterMetric.java new file mode 100644 index 000000000..522432631 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/DmaapRequestCounterMetric.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.metric; + + +public interface DmaapRequestCounterMetric extends Metric { + void incrementRecievedMessage(); + void incrementPublishedMessage(); + String value(); +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/Metric.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/Metric.java new file mode 100644 index 000000000..ce4297c88 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/Metric.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.metric; + +import java.util.HashMap; + +/** + * + * a measure of system parameter at the current moment. Each metric is identified by name. + * In general case, a metric just reflects its (almost) real-time value and is not responsible for maintaining its historical data. + * One that needs to build series of a metric values for statistical/analytic purposes should query the value and store it for further processing. + * Metrics can be of different types - counters, timers etc. + * The initial service implementation supports simple (flat) counters only. + * + */ +public interface Metric { + String name(); + void reset(); + MetricType type(); + /** + * This API will be used to get all the running Metrics Output. + * @return HashMap in which + * the First String(Key) will be the name of the KPI property + * and another String(Value of the Key) will be the Value of + * that property for that KPI + */ + HashMap getMetricsOutput(); + /** + * Return last modified date for KPI in string format + * @return - last modified date for KPI + */ + String getLastModified(); +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/MetricBuilderFactory.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/MetricBuilderFactory.java new file mode 100644 index 000000000..5a35247d3 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/MetricBuilderFactory.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.metric; + + +public interface MetricBuilderFactory { + + PrimitiveCounterBuilder primitiveCounterBuilder(); + DispatchingFunctionCounterBuilder dispatchingFunctionCounterBuilder(); + DmaapRequestCounterBuilder dmaapRequestCounterBuilder(); +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/MetricType.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/MetricType.java new file mode 100644 index 000000000..3f8ec30a8 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/MetricType.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.metric; + +/** + * + * Auxiliary enumeration that lists all the supported metric types. + * Can be used for generic processing of metrics rather than using Java reflection mechanisms to determine metric kind. + * + */ +public enum MetricType { +COUNTER +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/PrimitiveCounter.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/PrimitiveCounter.java new file mode 100644 index 000000000..a3fc2191f --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/PrimitiveCounter.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.metric; + +/** + * + * The simplest metric of type counter which mutable value. + */ +public interface PrimitiveCounter extends Counter{ + void increment(); + void increment(long value); + void decrement(); + void decrement(long value); +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/PrimitiveCounterBuilder.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/PrimitiveCounterBuilder.java new file mode 100644 index 000000000..ded5ecf47 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/PrimitiveCounterBuilder.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.metric; + +/** + * + * Builder interface which can be used to instantiate and initialize a new primitive counter instance. + */ +public interface PrimitiveCounterBuilder { + PrimitiveCounterBuilder withName(String name); + PrimitiveCounterBuilder withValue(long value); + PrimitiveCounterBuilder withType(MetricType type); + PrimitiveCounter build(); +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DefaultPrimitiveCounter.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DefaultPrimitiveCounter.java new file mode 100644 index 000000000..4b1992986 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DefaultPrimitiveCounter.java @@ -0,0 +1,113 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.metric.impl; + +import org.onap.appc.metricservice.metric.MetricType; +import org.onap.appc.metricservice.metric.PrimitiveCounter; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.HashMap; +import java.util.concurrent.atomic.AtomicLong; + + +public class DefaultPrimitiveCounter implements PrimitiveCounter { + private String name; + private MetricType metricType; + private AtomicLong counter = new AtomicLong(); + + private final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("YYYY-MM-dd:HH:mm:ss"); + private String lastResetTime = dateTimeFormat.format(Calendar.getInstance().getTime()); + + public DefaultPrimitiveCounter(String name, MetricType metricType, long counter) { + this.name = name; + this.metricType = metricType; + this.counter.set(counter); + } + + public DefaultPrimitiveCounter(String name, MetricType metricType) { + this.counter.set(0); + this.name = name; + this.metricType = metricType; + } + + @Override + public void increment() { + increment(1); + } + + @Override + public void increment(long value) { + this.counter.incrementAndGet(); + } + + @Override + public void decrement() { + decrement(1); + } + + @Override + public void decrement(long value) { + this.counter.decrementAndGet(); + } + + @Override + public long value() { + return this.counter.get(); + } + + @Override + public String name() { + return this.name; + } + + @Override + public void reset() { + this.counter.set(0); + Calendar cal = Calendar.getInstance(); + lastResetTime = dateTimeFormat.format(cal.getTime()); + } + + @Override + public String toString() { + return "DefaultPrimitiveCounter{" + "name='" + name + '\'' + ", metricType=" + metricType + ", counter=" + + counter.get() + '}'; + } + + @Override + public MetricType type() { + return this.metricType; + } + + @Override + public HashMap getMetricsOutput() { + return new HashMap<>(); + } + + @Override + public String getLastModified() { + return lastResetTime; + } +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DispatchingFunctionCounterBuilderImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DispatchingFunctionCounterBuilderImpl.java new file mode 100644 index 000000000..fd3b05ef7 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DispatchingFunctionCounterBuilderImpl.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.metric.impl; + +import org.onap.appc.metricservice.metric.DispatchingFunctionCounterBuilder; +import org.onap.appc.metricservice.metric.DispatchingFuntionMetric; +import org.onap.appc.metricservice.metric.MetricType; + + +public class DispatchingFunctionCounterBuilderImpl implements DispatchingFunctionCounterBuilder { + private String name; + private MetricType metricType; + private long acceptedRequested; + private long rejectedRequest; + + @Override + public DispatchingFunctionCounterBuilder withName(String name) { + this.name=name; + return this; + } + + @Override + public DispatchingFunctionCounterBuilder withAcceptRequestValue(long value) { + this.acceptedRequested=value; + return this; + } + @Override + public DispatchingFunctionCounterBuilder withRejectRequestValue(long value) { + this.rejectedRequest=value; + return this; + } + @Override + public DispatchingFunctionCounterBuilder withType(MetricType type) { + this.metricType=type; + return this; + } + + @Override + public DispatchingFuntionMetric build() { + return new DispatchingFuntionMetricImpl(this.name,this.metricType,this.acceptedRequested,this.rejectedRequest); + } +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DispatchingFuntionMetricImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DispatchingFuntionMetricImpl.java new file mode 100644 index 000000000..a6487957f --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DispatchingFuntionMetricImpl.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.metric.impl; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.HashMap; +import java.util.TimeZone; +import java.util.concurrent.atomic.AtomicLong; + +import org.onap.appc.metricservice.metric.DispatchingFuntionMetric; +import org.onap.appc.metricservice.metric.MetricType; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + + +public class DispatchingFuntionMetricImpl implements DispatchingFuntionMetric { + private String name; + private MetricType metricType; + private AtomicLong acceptedRequested = new AtomicLong(); + private AtomicLong rejectedRequest = new AtomicLong(); + + private final SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd"); + private final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("YYYY-MM-dd:HH:mm:ss"); + + private String lastResetTime = dateTimeFormat.format(Calendar.getInstance().getTime()); + private static final EELFLogger logger = EELFManager.getInstance().getLogger(DispatchingFuntionMetricImpl.class); + + public DispatchingFuntionMetricImpl(String name, MetricType metricType, long acceptedRequested, + long rejectedRequest) { + this.name = name; + this.metricType = metricType; + this.acceptedRequested.set(acceptedRequested); + this.rejectedRequest.set(rejectedRequest); + } + + @Override + public void incrementAcceptedRequest() { + this.acceptedRequested.incrementAndGet(); + } + + @Override + public void incrementRejectedRequest() { + this.rejectedRequest.incrementAndGet(); + } + + @Override + public String value() { + logger.debug("Value is getting calculated for metric :" + this.name); + try { + Calendar cal = Calendar.getInstance(); + cal.setTimeZone(TimeZone.getTimeZone("UTC")); + String date = dateFormat.format(cal.getTime()); + String value = date + "[" + acceptedRequested.get() + "," + rejectedRequest.get() + "]" + "@" + + (acceptedRequested.get() + rejectedRequest.get()); + logger.debug("Current value of the metric " + this.name + " :" + value); + return value; + + } catch (Exception e) { + logger.debug("Cant format the date.",e); + } + return null; + + } + + @Override + public String name() { + return this.name; + } + + @Override + public void reset() { + this.acceptedRequested.set(0); + this.rejectedRequest.set(0); + Calendar cal = Calendar.getInstance(); + lastResetTime = dateTimeFormat.format(cal.getTime()); + } + + @Override + public MetricType type() { + return this.metricType; + } + + @Override + public HashMap getMetricsOutput() { + HashMap dispatcherMetricResult = new HashMap<>(); + dispatcherMetricResult.put("Total Received messages", + Long.toString(acceptedRequested.get() + rejectedRequest.get())); + dispatcherMetricResult.put("Total Rejected messages", Long.toString(rejectedRequest.get())); + return dispatcherMetricResult; + } + + @Override + public String toString() { + return this.value(); + } + + @Override + public String getLastModified() { + return lastResetTime; + } +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DmaapRequestCounterBuilderImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DmaapRequestCounterBuilderImpl.java new file mode 100644 index 000000000..b5b53a810 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DmaapRequestCounterBuilderImpl.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.metric.impl; + +import org.onap.appc.metricservice.metric.MetricType; +import org.onap.appc.metricservice.metric.DmaapRequestCounterBuilder; +import org.onap.appc.metricservice.metric.DmaapRequestCounterMetric; + + +public class DmaapRequestCounterBuilderImpl implements DmaapRequestCounterBuilder { + private String name; + private MetricType metricType; + private long recievedMessage; + private long publishedMessage; + + @Override + public DmaapRequestCounterBuilder withName(String name) { + this.name=name; + return this; + } + + @Override + public DmaapRequestCounterBuilder withRecievedMessage(long value) { + + this.recievedMessage=value; + return this; + } + + @Override + public DmaapRequestCounterBuilder withPublishedMessage(long value) { + this.publishedMessage=value; + return this; + } + + @Override + public DmaapRequestCounterBuilder withType(MetricType type) { + this.metricType=type; + return this; + } + + @Override + public DmaapRequestCounterMetric build() { + return new DmaapRequestCounterMetricImpl(this.name,this.metricType,this.recievedMessage,this.publishedMessage); + } +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DmaapRequestCounterMetricImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DmaapRequestCounterMetricImpl.java new file mode 100644 index 000000000..dd1a6fc08 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/DmaapRequestCounterMetricImpl.java @@ -0,0 +1,121 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.metric.impl; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.HashMap; +import java.util.TimeZone; +import java.util.concurrent.atomic.AtomicLong; + +import org.onap.appc.metricservice.metric.MetricType; +import org.onap.appc.metricservice.metric.DmaapRequestCounterMetric; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + + +public class DmaapRequestCounterMetricImpl implements DmaapRequestCounterMetric { + + private String name; + private MetricType metricType; + private AtomicLong recievedMessage = new AtomicLong(); + private AtomicLong publishedMessage = new AtomicLong(); + + private final SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd"); + private final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("YYYY-MM-dd:HH:mm:ss"); + + private String lastResetTime = dateTimeFormat.format(Calendar.getInstance().getTime()); + private static final EELFLogger logger = EELFManager.getInstance().getLogger(DmaapRequestCounterMetricImpl.class); + + public DmaapRequestCounterMetricImpl(String name, MetricType metricType, long recievedMessage, + long publishedMessage) { + this.name = name; + this.metricType = metricType; + this.recievedMessage.set(recievedMessage); + this.publishedMessage.set(publishedMessage); + } + + @Override + public void incrementRecievedMessage() { + this.recievedMessage.incrementAndGet(); + } + + @Override + public void incrementPublishedMessage() { + this.publishedMessage.incrementAndGet(); + } + + @Override + public String value() { + logger.debug("Value is getting calculated for metric :" + this.name); + try { + Calendar cal = Calendar.getInstance(); + cal.setTimeZone(TimeZone.getTimeZone("UTC")); + String date = dateFormat.format(cal.getTime()); + String value = date + "[" + recievedMessage.get() + "],[" + publishedMessage.get() + "]"; + logger.debug("Current value of the metric " + this.name + " :" + value); + return value; + } catch (Exception e) { + logger.debug("Cant format the date.",e); + } + return null; + } + + @Override + public String name() { + return this.name; + } + + @Override + public void reset() { + this.recievedMessage.set(0); + this.publishedMessage.set(0); + Calendar cal = Calendar.getInstance(); + lastResetTime = dateTimeFormat.format(cal.getTime()); + } + + @Override + public MetricType type() { + return this.metricType; + } + + @Override + public HashMap getMetricsOutput() { + HashMap dmaapMetricResult = new HashMap<>(); + dmaapMetricResult.put("Total Received messages", Long.toString(recievedMessage.get())); + dmaapMetricResult.put("Total Published messages", Long.toString(publishedMessage.get())); + return dmaapMetricResult; + } + + @Override + public String toString() { + return this.value(); + } + + @Override + public String getLastModified() { + return lastResetTime; + } +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/MetricBuilderFactoryImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/MetricBuilderFactoryImpl.java new file mode 100644 index 000000000..0a45941d1 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/MetricBuilderFactoryImpl.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.metric.impl; + +import org.onap.appc.metricservice.metric.DispatchingFunctionCounterBuilder; +import org.onap.appc.metricservice.metric.MetricBuilderFactory; +import org.onap.appc.metricservice.metric.PrimitiveCounterBuilder; +import org.onap.appc.metricservice.metric.DmaapRequestCounterBuilder; + + +public class MetricBuilderFactoryImpl implements MetricBuilderFactory { + @Override + public PrimitiveCounterBuilder primitiveCounterBuilder() { + return new PrimitiveCounterBuilderImpl(); + } + + @Override + public DispatchingFunctionCounterBuilder dispatchingFunctionCounterBuilder() { + return new DispatchingFunctionCounterBuilderImpl() ; + } + + @Override + public DmaapRequestCounterBuilder dmaapRequestCounterBuilder() { + return new DmaapRequestCounterBuilderImpl(); + } +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/PrimitiveCounterBuilderImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/PrimitiveCounterBuilderImpl.java new file mode 100644 index 000000000..c95f89e75 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric/impl/PrimitiveCounterBuilderImpl.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.metric.impl; + +import org.onap.appc.metricservice.metric.MetricType; +import org.onap.appc.metricservice.metric.PrimitiveCounter; +import org.onap.appc.metricservice.metric.PrimitiveCounterBuilder; + + +public class PrimitiveCounterBuilderImpl implements PrimitiveCounterBuilder { + private String name; + private MetricType metricType; + private long counter; + + @Override + public PrimitiveCounterBuilder withName(String name) { + this.name=name; + return this; + } + + @Override + public PrimitiveCounterBuilder withValue(long value) { + this.counter=value; + return this; + } + + @Override + public PrimitiveCounterBuilder withType(MetricType type) { + this.metricType=type; + return this; + } + + @Override + public PrimitiveCounter build() { + return new DefaultPrimitiveCounter(this.name,this.metricType,this.counter); + } +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/PolicyBuilderFactory.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/PolicyBuilderFactory.java new file mode 100644 index 000000000..fbdd04979 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/PolicyBuilderFactory.java @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.policy; + + +public interface PolicyBuilderFactory { + ScheduledPolicyBuilder scheduledPolicyBuilder(); +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/PublishingPolicy.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/PublishingPolicy.java new file mode 100644 index 000000000..44a05f994 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/PublishingPolicy.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.policy; + +import org.onap.appc.exceptions.APPCException; +import org.onap.appc.metricservice.metric.Metric; + +/** + * + * A custom logic that determines strategy of exposing metric values. + * Policy is associated with a specific registry and its implementation can very from the simplest options, such as 'real-time' behavior (upon each value change) to more sophisticated approaches such as thresholds or recurrent scheduling rules. + * The policy can also decide whether or not to publish the entire metric registry or just a subset of the it (e.g. changed ones). + * Policy supports execution of one or more Publishers. + * + */ +public interface PublishingPolicy { + void onMetricChange(Metric meric) throws APPCException; + Metric[] metrics(); + + void init(); +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/ScheduledPolicyBuilder.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/ScheduledPolicyBuilder.java new file mode 100644 index 000000000..d67031d03 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/ScheduledPolicyBuilder.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.policy; + +import org.onap.appc.metricservice.Publisher; +import org.onap.appc.metricservice.metric.Metric; + +/** + * + * An auxiliary class to instantiate scheduler-based policy delivered along with the initial release of the service. + * + */ +public interface ScheduledPolicyBuilder { + ScheduledPolicyBuilder withStartTime(long time); + ScheduledPolicyBuilder withPeriod(long period); + ScheduledPolicyBuilder withPublishers(Publisher[] publishers); + ScheduledPolicyBuilder withMetrics(Metric[] metrics); + PublishingPolicy build(); +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/ScheduledPublishingPolicy.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/ScheduledPublishingPolicy.java new file mode 100644 index 000000000..697ef3ff7 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/ScheduledPublishingPolicy.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.policy; + +import org.onap.appc.metricservice.Publisher; + + +public interface ScheduledPublishingPolicy extends PublishingPolicy{ + + long getStartTime(); + long getPeriod(); + Publisher[] getPublishers(); + void reset(); +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/impl/PolicyBuilderFactoryImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/impl/PolicyBuilderFactoryImpl.java new file mode 100644 index 000000000..d9c4cf024 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/impl/PolicyBuilderFactoryImpl.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.policy.impl; + +import org.onap.appc.metricservice.policy.PolicyBuilderFactory; +import org.onap.appc.metricservice.policy.ScheduledPolicyBuilder; + + +public class PolicyBuilderFactoryImpl implements PolicyBuilderFactory { + @Override + public ScheduledPolicyBuilder scheduledPolicyBuilder() { + return new ScheduledPolicyBuilderImpl(); + } +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/impl/ScheduledPolicyBuilderImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/impl/ScheduledPolicyBuilderImpl.java new file mode 100644 index 000000000..65ce62435 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/impl/ScheduledPolicyBuilderImpl.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.policy.impl; + +import org.onap.appc.metricservice.Publisher; +import org.onap.appc.metricservice.metric.Metric; +import org.onap.appc.metricservice.policy.PublishingPolicy; +import org.onap.appc.metricservice.policy.ScheduledPolicyBuilder; + + +public class ScheduledPolicyBuilderImpl implements ScheduledPolicyBuilder { + + private long startTime; + private long period; + private Publisher[] publishers; + private Metric[] metrics; + + @Override + public ScheduledPolicyBuilder withStartTime(long time) { + this.startTime=time; + return this; + } + + @Override + public ScheduledPolicyBuilder withPeriod(long period) { + this.period=period; + return this; + } + + @Override + public ScheduledPolicyBuilder withPublishers(Publisher[] publishers) { + this.publishers=publishers; + return this; + } + + @Override + public ScheduledPolicyBuilder withMetrics(Metric[] metrics) { + this.metrics=metrics; + return this; + } + + @Override + public PublishingPolicy build() { + return new ScheduledPublishingPolicyImpl(this.publishers,this.metrics); + } +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/impl/ScheduledPublishingPolicyImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/impl/ScheduledPublishingPolicyImpl.java new file mode 100644 index 000000000..8933150f3 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/policy/impl/ScheduledPublishingPolicyImpl.java @@ -0,0 +1,224 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.policy.impl; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Properties; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; + +import org.onap.appc.configuration.Configuration; +import org.onap.appc.configuration.ConfigurationFactory; +import org.onap.appc.exceptions.APPCException; +import org.onap.appc.metricservice.MetricRegistry; +import org.onap.appc.metricservice.MetricService; +import org.onap.appc.metricservice.Publisher; +import org.onap.appc.metricservice.metric.Metric; +import org.onap.appc.metricservice.policy.ScheduledPublishingPolicy; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + + +public class ScheduledPublishingPolicyImpl implements ScheduledPublishingPolicy { + private long startTime; + private long period; + private Publisher[] publishers; + private Metric[] metrics; + private MetricRegistry metricRegistry; + private static final EELFLogger logger = EELFManager.getInstance().getLogger(ScheduledPublishingPolicyImpl.class); + private ScheduledExecutorService scheduleExecutor; + private Configuration configuration; + + public ScheduledPublishingPolicyImpl(long startTime, long period, Publisher[] publishers, Metric[] metrics) { + this.startTime = startTime; + this.period = period; + this.publishers = publishers; + this.metrics = metrics; + this.scheduleExecutor= Executors.newSingleThreadScheduledExecutor(getThreadFactory(true)); + } + + public ScheduledPublishingPolicyImpl( Publisher[] publishers, Metric[] metrics) { + configuration = ConfigurationFactory.getConfiguration(); + Properties properties=configuration.getProperties(); + if(properties!=null){ + if(properties.getProperty("schedule.policy.metric.period")!=null && properties.getProperty("schedule.policy.metric.start.time")!=null){ + this.startTime = getConfigStartTime(properties); + this.period = getConfigPeriod(properties); + logger.info("Metric Properties read from configuration Start Time :"+this.startTime+", Period :"+this.period); + }else if(properties.getProperty("schedule.policy.metric.period")!=null){ + this.startTime=1; + this.period=getConfigPeriod(properties); + logger.info("Metric Properties read from configuration Start Time :"+this.startTime+", Period :"+this.period); + + }else if(properties.getProperty("schedule.policy.metric.period")==null && properties.getProperty("schedule.policy.metric.start.time")!=null){ + this.startTime=getConfigStartTime("00:00:00",properties); + this.period=(24*60*60*1000)-1; + logger.info("Metric Properties read from configuration Start Time :"+this.startTime+", Period :"+this.period); + + }else{ + logger.info("Metric Properties coming as null,setting to default Start Time :1 ms,Period : 100000 ms"); + this.startTime = 1; + this.period = 100000; + logger.info("Metric Properties read from configuration Start Time :"+this.startTime+", Period :"+this.period); + + } + } else { + logger.info("Metric Properties coming as null,setting to default Start Time :1 ms,Period : 100000 ms"); + this.startTime = 1; + this.period = 100000; + logger.info("Metric Properties read from configuration Start Time :"+this.startTime+", Period :"+this.period); + } + this.publishers = publishers; + this.metrics = metrics; + this.scheduleExecutor= Executors.newSingleThreadScheduledExecutor(getThreadFactory(true)); + } + + private long getConfigPeriod(Properties properties) { + String period=properties.getProperty("schedule.policy.metric.period"); + logger.info("Metric period : " +period); + long periodInMs=Integer.parseInt(period)*1000; + logger.info("Metric period in long : " +periodInMs); + return periodInMs; + } + + private long getTimeInMs(String time) { + String[] strings=time.split(":"); + if(strings.length==3) { + long hour = Integer.parseInt(strings[0]) * 60 * 60 * 1000; + long min = Integer.parseInt(strings[1]) * 60 * 1000; + long sec = Integer.parseInt(strings[2]) * 1000; + return hour+min+sec; + }else{ + return 0; + } + + } + + + + private long getConfigStartTime(Properties properties) { + String startTime=properties.getProperty("schedule.policy.metric.start.time"); + if(startTime!=null){ + long timeDiff=(getTimeInMs(startTime))-(getTimeInMs((new SimpleDateFormat("HH:mm:ss")).format(new Date()))); + long period=getConfigPeriod(properties); + if(timeDiff>=0){ + return timeDiff; + }else{ + return period-((timeDiff*-1)%period); + } + } + return 0; + } + + private long getConfigStartTime(String startTime,Properties properties) { + if(startTime!=null){ + long timeDiff=(getTimeInMs(startTime))-(getTimeInMs((new SimpleDateFormat("HH:mm:ss")).format(new Date()))); + long period=getConfigPeriod(properties); + if(timeDiff>=0){ + return timeDiff%period; + }else{ + return period-((timeDiff*-1)%period); + } + } + return 0; + } + @Override + public void onMetricChange(Metric metric) throws APPCException { + //TODO + } + + @Override + public Metric[] metrics() { + return metrics; + } + + @Override + public void init() { + Properties properties=configuration.getProperties(); + boolean isMetricEnabled=false; + if(properties!=null){ + String metricProperty=properties.getProperty("metric.enabled"); + if(metricProperty!=null){ + isMetricEnabled=Boolean.valueOf(metricProperty); + } + } + if(isMetricEnabled){ + logger.info("Metric Service is enabled, hence policies getting scheduled"); + for(final Publisher publisher:this.getPublishers()){ + scheduleExecutor.scheduleWithFixedDelay(new Runnable() + { + public void run() { + try { + publisher.publish(metricRegistry, metrics); + reset(); + } catch (RuntimeException ex) { + logger.error("RuntimeException thrown from {}#report. Exception was suppressed.", publisher.getClass().getSimpleName(), ex); + } + } + } + , startTime, period, TimeUnit.MILLISECONDS); + } + }else{ + logger.info("Metric Service is not enabled, hence policies not getting scheduled"); + + } + } + + @Override + public long getStartTime() { + return this.startTime; + } + + @Override + public long getPeriod() { + return this.period; + } + + @Override + public Publisher[] getPublishers() { + return this.publishers; + } + + @Override + public void reset() { + for(Metric metric:this.metrics){ + metric.reset();} + } + + + private ThreadFactory getThreadFactory(final boolean isDaemon){ + return new ThreadFactory() { + public Thread newThread(Runnable r) { + Thread t = Executors.defaultThreadFactory().newThread(r); + t.setDaemon(isDaemon); + return t; + } + }; + } + +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/publisher/LogPublisher.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/publisher/LogPublisher.java new file mode 100644 index 000000000..e4f160d40 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/publisher/LogPublisher.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice.publisher; + +import org.onap.appc.metricservice.MetricRegistry; +import org.onap.appc.metricservice.Publisher; +import org.onap.appc.metricservice.metric.Metric; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + + +public class LogPublisher implements Publisher { + private static final EELFLogger logger = EELFManager.getInstance().getLogger(LogPublisher.class); + private MetricRegistry metricRegistry; + private Metric[] metrics; + + public LogPublisher(MetricRegistry metricRegistry, Metric[] metrics) { + this.metricRegistry = metricRegistry; + this.metrics = metrics; + } + + @Override + public void publish(MetricRegistry metricRegistry, Metric[] metrics) { + for(Metric metric:metrics){ + logger.debug("LOG PUBLISHER:"+metric.name()+":"+metric.toString()); + } + } + + +} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/MetricActivator.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/MetricActivator.java deleted file mode 100644 index 40ff14827..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/MetricActivator.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc; - -import org.onap.appc.metricservice.MetricService; -import org.onap.appc.metricservice.impl.MetricServiceImpl; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; - - -public class MetricActivator implements BundleActivator { - - private ServiceRegistration registration = null; - - private static final EELFLogger logger = EELFManager.getInstance().getLogger(MetricActivator.class); - - @Override - public void start(BundleContext bundleContext) throws Exception { - logger.debug("Starting Metric service " ); - MetricService impl = new MetricServiceImpl(); - String regName = MetricService.class.getName(); - logger.debug("Registering Metric service " + regName); - registration = bundleContext.registerService(regName, impl, null); - logger.debug("Registered Metric service " + regName); - } - - @Override - public void stop(BundleContext bundleContext) throws Exception { - - } -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/MetricRegistry.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/MetricRegistry.java deleted file mode 100644 index 6e658ae47..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/MetricRegistry.java +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice; - -import org.onap.appc.metricservice.metric.Counter; -import org.onap.appc.metricservice.metric.Metric; -import org.onap.appc.metricservice.metric.MetricBuilderFactory; -import org.onap.appc.metricservice.policy.PolicyBuilderFactory; -import org.onap.appc.metricservice.policy.PublishingPolicy; - -/** - * - * A named group of metrics which might be related to a specific domain. The service doesn't limit number of metric registries per instance. - * It's up to application to decide on domain scope. The registry instances are independent. - * - */ -public interface MetricRegistry { - boolean register(Metric metric); - void attach (PublishingPolicy publishPolicy); - MetricBuilderFactory metricBuilderFactory(); - PolicyBuilderFactory policyBuilderFactory(); - Counter counter(String value); - Counter[] counters(); - Metric[] metrics(); - Metric metric(String metricName); - void dispose(); -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/MetricService.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/MetricService.java deleted file mode 100644 index 65ff72d97..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/MetricService.java +++ /dev/null @@ -1,41 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice; - - -import java.util.Map; - -public interface MetricService { - MetricRegistry registry(String name); - MetricRegistry createRegistry(String name); - void dispose(); - - /** - * This API will be used to get the Map of all the registered Registry for the Metric Service - * @return Map where String will be the name of the Metric Registry - * and MetricRegistry will be the actual object for that Registry - */ - Map getAllRegistry(); -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/Publisher.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/Publisher.java deleted file mode 100644 index 1d38e44c3..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/Publisher.java +++ /dev/null @@ -1,37 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice; - -import org.onap.appc.metricservice.metric.Metric; - -/** - * Low-level logic of exposing metric values in certain way. There might be plenty of options such as logging, JMX, etc. - * API to be supported by any logic that is going to be plugged into metric service. - * The publisher is considered as low-level technical unit which, potentially, can be reused to expose metrics from different registries - * - */ -public interface Publisher { - void publish(MetricRegistry metricRegistry,Metric[] metrics); -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/impl/MetricRegistryImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/impl/MetricRegistryImpl.java deleted file mode 100644 index ac2054151..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/impl/MetricRegistryImpl.java +++ /dev/null @@ -1,101 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.impl; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.onap.appc.metricservice.MetricRegistry; -import org.onap.appc.metricservice.metric.Counter; -import org.onap.appc.metricservice.metric.Metric; -import org.onap.appc.metricservice.metric.MetricBuilderFactory; -import org.onap.appc.metricservice.metric.impl.MetricBuilderFactoryImpl; -import org.onap.appc.metricservice.policy.PolicyBuilderFactory; -import org.onap.appc.metricservice.policy.PublishingPolicy; -import org.onap.appc.metricservice.policy.impl.PolicyBuilderFactoryImpl; - - -public class MetricRegistryImpl implements MetricRegistry { - private String name; - private Map concurrentMetricMap=new ConcurrentHashMap(); - - public MetricRegistryImpl(String name) { - this.name = name; - } - - @Override - public boolean register(Metric metric) { - if(concurrentMetricMap.get(metric.name())==null){ - concurrentMetricMap.put(metric.name(),metric); - return true; - } - return false; - } - - @Override - public void attach(PublishingPolicy publishPolicy) { -//TODO - } - - @Override - public MetricBuilderFactory metricBuilderFactory() { - return new MetricBuilderFactoryImpl(); - } - - @Override - public PolicyBuilderFactory policyBuilderFactory() { - return new PolicyBuilderFactoryImpl() ; - } - - @Override - public Counter counter(String value) { - if(concurrentMetricMap.get(value)!=null ) - return (Counter)concurrentMetricMap.get(value) ; - else - return null; - - } - - @Override - public Counter[] counters() { - return (Counter[])concurrentMetricMap.values().toArray(); - } - - @Override - public Metric[] metrics() { - java.util.Collection var = concurrentMetricMap.values(); - return var.toArray(new Metric[var.size()]); - } - - @Override - public Metric metric(String metricName) { - return concurrentMetricMap.get(metricName); - } - - @Override - public void dispose() { - concurrentMetricMap.clear(); - } -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/impl/MetricServiceImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/impl/MetricServiceImpl.java deleted file mode 100644 index 20f2d8d2e..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/impl/MetricServiceImpl.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.impl; - -import java.util.Collections; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.onap.appc.metricservice.MetricRegistry; -import org.onap.appc.metricservice.MetricService; - - -public class MetricServiceImpl implements MetricService { - private Map concurrentRegistryMap=new ConcurrentHashMap<>(); - @Override - public MetricRegistry registry(String name) { - return concurrentRegistryMap.get(name); - } - - @Override - public MetricRegistry createRegistry(String name) { - if(concurrentRegistryMap.get(name)==null) - concurrentRegistryMap.put(name,new MetricRegistryImpl(name)); - return concurrentRegistryMap.get(name); - } - - @Override - public Map getAllRegistry(){ - return Collections.unmodifiableMap(concurrentRegistryMap); - - } - - @Override - public void dispose() { -//TODO - } -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/Counter.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/Counter.java deleted file mode 100644 index 0b4d3e2d3..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/Counter.java +++ /dev/null @@ -1,30 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.metric; - - -public interface Counter extends Metric { - long value(); -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/DispatchingFunctionCounterBuilder.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/DispatchingFunctionCounterBuilder.java deleted file mode 100644 index bff07f627..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/DispatchingFunctionCounterBuilder.java +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.metric; - - -public interface DispatchingFunctionCounterBuilder { - DispatchingFunctionCounterBuilder withName(String name); - DispatchingFunctionCounterBuilder withAcceptRequestValue(long value); - DispatchingFunctionCounterBuilder withRejectRequestValue(long value); - DispatchingFunctionCounterBuilder withType(MetricType type); - DispatchingFuntionMetric build(); -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/DispatchingFuntionMetric.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/DispatchingFuntionMetric.java deleted file mode 100644 index 384875e9b..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/DispatchingFuntionMetric.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.metric; - - -public interface DispatchingFuntionMetric extends Metric { - void incrementAcceptedRequest(); - void incrementRejectedRequest(); - String value(); -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/DmaapRequestCounterBuilder.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/DmaapRequestCounterBuilder.java deleted file mode 100644 index efb23963f..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/DmaapRequestCounterBuilder.java +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.metric; - - -public interface DmaapRequestCounterBuilder { - DmaapRequestCounterBuilder withName(String name); - DmaapRequestCounterBuilder withRecievedMessage(long value); - DmaapRequestCounterBuilder withPublishedMessage(long value); - DmaapRequestCounterBuilder withType(MetricType type); - DmaapRequestCounterMetric build(); -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/DmaapRequestCounterMetric.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/DmaapRequestCounterMetric.java deleted file mode 100644 index 522432631..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/DmaapRequestCounterMetric.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.metric; - - -public interface DmaapRequestCounterMetric extends Metric { - void incrementRecievedMessage(); - void incrementPublishedMessage(); - String value(); -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/Metric.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/Metric.java deleted file mode 100644 index ce4297c88..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/Metric.java +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.metric; - -import java.util.HashMap; - -/** - * - * a measure of system parameter at the current moment. Each metric is identified by name. - * In general case, a metric just reflects its (almost) real-time value and is not responsible for maintaining its historical data. - * One that needs to build series of a metric values for statistical/analytic purposes should query the value and store it for further processing. - * Metrics can be of different types - counters, timers etc. - * The initial service implementation supports simple (flat) counters only. - * - */ -public interface Metric { - String name(); - void reset(); - MetricType type(); - /** - * This API will be used to get all the running Metrics Output. - * @return HashMap in which - * the First String(Key) will be the name of the KPI property - * and another String(Value of the Key) will be the Value of - * that property for that KPI - */ - HashMap getMetricsOutput(); - /** - * Return last modified date for KPI in string format - * @return - last modified date for KPI - */ - String getLastModified(); -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/MetricBuilderFactory.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/MetricBuilderFactory.java deleted file mode 100644 index 5a35247d3..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/MetricBuilderFactory.java +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.metric; - - -public interface MetricBuilderFactory { - - PrimitiveCounterBuilder primitiveCounterBuilder(); - DispatchingFunctionCounterBuilder dispatchingFunctionCounterBuilder(); - DmaapRequestCounterBuilder dmaapRequestCounterBuilder(); -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/MetricType.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/MetricType.java deleted file mode 100644 index 3f8ec30a8..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/MetricType.java +++ /dev/null @@ -1,35 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.metric; - -/** - * - * Auxiliary enumeration that lists all the supported metric types. - * Can be used for generic processing of metrics rather than using Java reflection mechanisms to determine metric kind. - * - */ -public enum MetricType { -COUNTER -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/PrimitiveCounter.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/PrimitiveCounter.java deleted file mode 100644 index a3fc2191f..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/PrimitiveCounter.java +++ /dev/null @@ -1,36 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.metric; - -/** - * - * The simplest metric of type counter which mutable value. - */ -public interface PrimitiveCounter extends Counter{ - void increment(); - void increment(long value); - void decrement(); - void decrement(long value); -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/PrimitiveCounterBuilder.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/PrimitiveCounterBuilder.java deleted file mode 100644 index ded5ecf47..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/PrimitiveCounterBuilder.java +++ /dev/null @@ -1,36 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.metric; - -/** - * - * Builder interface which can be used to instantiate and initialize a new primitive counter instance. - */ -public interface PrimitiveCounterBuilder { - PrimitiveCounterBuilder withName(String name); - PrimitiveCounterBuilder withValue(long value); - PrimitiveCounterBuilder withType(MetricType type); - PrimitiveCounter build(); -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DefaultPrimitiveCounter.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DefaultPrimitiveCounter.java deleted file mode 100644 index 4b1992986..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DefaultPrimitiveCounter.java +++ /dev/null @@ -1,113 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.metric.impl; - -import org.onap.appc.metricservice.metric.MetricType; -import org.onap.appc.metricservice.metric.PrimitiveCounter; - -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.HashMap; -import java.util.concurrent.atomic.AtomicLong; - - -public class DefaultPrimitiveCounter implements PrimitiveCounter { - private String name; - private MetricType metricType; - private AtomicLong counter = new AtomicLong(); - - private final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("YYYY-MM-dd:HH:mm:ss"); - private String lastResetTime = dateTimeFormat.format(Calendar.getInstance().getTime()); - - public DefaultPrimitiveCounter(String name, MetricType metricType, long counter) { - this.name = name; - this.metricType = metricType; - this.counter.set(counter); - } - - public DefaultPrimitiveCounter(String name, MetricType metricType) { - this.counter.set(0); - this.name = name; - this.metricType = metricType; - } - - @Override - public void increment() { - increment(1); - } - - @Override - public void increment(long value) { - this.counter.incrementAndGet(); - } - - @Override - public void decrement() { - decrement(1); - } - - @Override - public void decrement(long value) { - this.counter.decrementAndGet(); - } - - @Override - public long value() { - return this.counter.get(); - } - - @Override - public String name() { - return this.name; - } - - @Override - public void reset() { - this.counter.set(0); - Calendar cal = Calendar.getInstance(); - lastResetTime = dateTimeFormat.format(cal.getTime()); - } - - @Override - public String toString() { - return "DefaultPrimitiveCounter{" + "name='" + name + '\'' + ", metricType=" + metricType + ", counter=" - + counter.get() + '}'; - } - - @Override - public MetricType type() { - return this.metricType; - } - - @Override - public HashMap getMetricsOutput() { - return new HashMap<>(); - } - - @Override - public String getLastModified() { - return lastResetTime; - } -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DispatchingFunctionCounterBuilderImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DispatchingFunctionCounterBuilderImpl.java deleted file mode 100644 index fd3b05ef7..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DispatchingFunctionCounterBuilderImpl.java +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.metric.impl; - -import org.onap.appc.metricservice.metric.DispatchingFunctionCounterBuilder; -import org.onap.appc.metricservice.metric.DispatchingFuntionMetric; -import org.onap.appc.metricservice.metric.MetricType; - - -public class DispatchingFunctionCounterBuilderImpl implements DispatchingFunctionCounterBuilder { - private String name; - private MetricType metricType; - private long acceptedRequested; - private long rejectedRequest; - - @Override - public DispatchingFunctionCounterBuilder withName(String name) { - this.name=name; - return this; - } - - @Override - public DispatchingFunctionCounterBuilder withAcceptRequestValue(long value) { - this.acceptedRequested=value; - return this; - } - @Override - public DispatchingFunctionCounterBuilder withRejectRequestValue(long value) { - this.rejectedRequest=value; - return this; - } - @Override - public DispatchingFunctionCounterBuilder withType(MetricType type) { - this.metricType=type; - return this; - } - - @Override - public DispatchingFuntionMetric build() { - return new DispatchingFuntionMetricImpl(this.name,this.metricType,this.acceptedRequested,this.rejectedRequest); - } -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DispatchingFuntionMetricImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DispatchingFuntionMetricImpl.java deleted file mode 100644 index a6487957f..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DispatchingFuntionMetricImpl.java +++ /dev/null @@ -1,124 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.metric.impl; - -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.HashMap; -import java.util.TimeZone; -import java.util.concurrent.atomic.AtomicLong; - -import org.onap.appc.metricservice.metric.DispatchingFuntionMetric; -import org.onap.appc.metricservice.metric.MetricType; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - - -public class DispatchingFuntionMetricImpl implements DispatchingFuntionMetric { - private String name; - private MetricType metricType; - private AtomicLong acceptedRequested = new AtomicLong(); - private AtomicLong rejectedRequest = new AtomicLong(); - - private final SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd"); - private final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("YYYY-MM-dd:HH:mm:ss"); - - private String lastResetTime = dateTimeFormat.format(Calendar.getInstance().getTime()); - private static final EELFLogger logger = EELFManager.getInstance().getLogger(DispatchingFuntionMetricImpl.class); - - public DispatchingFuntionMetricImpl(String name, MetricType metricType, long acceptedRequested, - long rejectedRequest) { - this.name = name; - this.metricType = metricType; - this.acceptedRequested.set(acceptedRequested); - this.rejectedRequest.set(rejectedRequest); - } - - @Override - public void incrementAcceptedRequest() { - this.acceptedRequested.incrementAndGet(); - } - - @Override - public void incrementRejectedRequest() { - this.rejectedRequest.incrementAndGet(); - } - - @Override - public String value() { - logger.debug("Value is getting calculated for metric :" + this.name); - try { - Calendar cal = Calendar.getInstance(); - cal.setTimeZone(TimeZone.getTimeZone("UTC")); - String date = dateFormat.format(cal.getTime()); - String value = date + "[" + acceptedRequested.get() + "," + rejectedRequest.get() + "]" + "@" - + (acceptedRequested.get() + rejectedRequest.get()); - logger.debug("Current value of the metric " + this.name + " :" + value); - return value; - - } catch (Exception e) { - logger.debug("Cant format the date.",e); - } - return null; - - } - - @Override - public String name() { - return this.name; - } - - @Override - public void reset() { - this.acceptedRequested.set(0); - this.rejectedRequest.set(0); - Calendar cal = Calendar.getInstance(); - lastResetTime = dateTimeFormat.format(cal.getTime()); - } - - @Override - public MetricType type() { - return this.metricType; - } - - @Override - public HashMap getMetricsOutput() { - HashMap dispatcherMetricResult = new HashMap<>(); - dispatcherMetricResult.put("Total Received messages", - Long.toString(acceptedRequested.get() + rejectedRequest.get())); - dispatcherMetricResult.put("Total Rejected messages", Long.toString(rejectedRequest.get())); - return dispatcherMetricResult; - } - - @Override - public String toString() { - return this.value(); - } - - @Override - public String getLastModified() { - return lastResetTime; - } -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DmaapRequestCounterBuilderImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DmaapRequestCounterBuilderImpl.java deleted file mode 100644 index b5b53a810..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DmaapRequestCounterBuilderImpl.java +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.metric.impl; - -import org.onap.appc.metricservice.metric.MetricType; -import org.onap.appc.metricservice.metric.DmaapRequestCounterBuilder; -import org.onap.appc.metricservice.metric.DmaapRequestCounterMetric; - - -public class DmaapRequestCounterBuilderImpl implements DmaapRequestCounterBuilder { - private String name; - private MetricType metricType; - private long recievedMessage; - private long publishedMessage; - - @Override - public DmaapRequestCounterBuilder withName(String name) { - this.name=name; - return this; - } - - @Override - public DmaapRequestCounterBuilder withRecievedMessage(long value) { - - this.recievedMessage=value; - return this; - } - - @Override - public DmaapRequestCounterBuilder withPublishedMessage(long value) { - this.publishedMessage=value; - return this; - } - - @Override - public DmaapRequestCounterBuilder withType(MetricType type) { - this.metricType=type; - return this; - } - - @Override - public DmaapRequestCounterMetric build() { - return new DmaapRequestCounterMetricImpl(this.name,this.metricType,this.recievedMessage,this.publishedMessage); - } -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DmaapRequestCounterMetricImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DmaapRequestCounterMetricImpl.java deleted file mode 100644 index dd1a6fc08..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DmaapRequestCounterMetricImpl.java +++ /dev/null @@ -1,121 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.metric.impl; - -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.HashMap; -import java.util.TimeZone; -import java.util.concurrent.atomic.AtomicLong; - -import org.onap.appc.metricservice.metric.MetricType; -import org.onap.appc.metricservice.metric.DmaapRequestCounterMetric; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - - -public class DmaapRequestCounterMetricImpl implements DmaapRequestCounterMetric { - - private String name; - private MetricType metricType; - private AtomicLong recievedMessage = new AtomicLong(); - private AtomicLong publishedMessage = new AtomicLong(); - - private final SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd"); - private final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("YYYY-MM-dd:HH:mm:ss"); - - private String lastResetTime = dateTimeFormat.format(Calendar.getInstance().getTime()); - private static final EELFLogger logger = EELFManager.getInstance().getLogger(DmaapRequestCounterMetricImpl.class); - - public DmaapRequestCounterMetricImpl(String name, MetricType metricType, long recievedMessage, - long publishedMessage) { - this.name = name; - this.metricType = metricType; - this.recievedMessage.set(recievedMessage); - this.publishedMessage.set(publishedMessage); - } - - @Override - public void incrementRecievedMessage() { - this.recievedMessage.incrementAndGet(); - } - - @Override - public void incrementPublishedMessage() { - this.publishedMessage.incrementAndGet(); - } - - @Override - public String value() { - logger.debug("Value is getting calculated for metric :" + this.name); - try { - Calendar cal = Calendar.getInstance(); - cal.setTimeZone(TimeZone.getTimeZone("UTC")); - String date = dateFormat.format(cal.getTime()); - String value = date + "[" + recievedMessage.get() + "],[" + publishedMessage.get() + "]"; - logger.debug("Current value of the metric " + this.name + " :" + value); - return value; - } catch (Exception e) { - logger.debug("Cant format the date.",e); - } - return null; - } - - @Override - public String name() { - return this.name; - } - - @Override - public void reset() { - this.recievedMessage.set(0); - this.publishedMessage.set(0); - Calendar cal = Calendar.getInstance(); - lastResetTime = dateTimeFormat.format(cal.getTime()); - } - - @Override - public MetricType type() { - return this.metricType; - } - - @Override - public HashMap getMetricsOutput() { - HashMap dmaapMetricResult = new HashMap<>(); - dmaapMetricResult.put("Total Received messages", Long.toString(recievedMessage.get())); - dmaapMetricResult.put("Total Published messages", Long.toString(publishedMessage.get())); - return dmaapMetricResult; - } - - @Override - public String toString() { - return this.value(); - } - - @Override - public String getLastModified() { - return lastResetTime; - } -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/MetricBuilderFactoryImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/MetricBuilderFactoryImpl.java deleted file mode 100644 index 0a45941d1..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/MetricBuilderFactoryImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.metric.impl; - -import org.onap.appc.metricservice.metric.DispatchingFunctionCounterBuilder; -import org.onap.appc.metricservice.metric.MetricBuilderFactory; -import org.onap.appc.metricservice.metric.PrimitiveCounterBuilder; -import org.onap.appc.metricservice.metric.DmaapRequestCounterBuilder; - - -public class MetricBuilderFactoryImpl implements MetricBuilderFactory { - @Override - public PrimitiveCounterBuilder primitiveCounterBuilder() { - return new PrimitiveCounterBuilderImpl(); - } - - @Override - public DispatchingFunctionCounterBuilder dispatchingFunctionCounterBuilder() { - return new DispatchingFunctionCounterBuilderImpl() ; - } - - @Override - public DmaapRequestCounterBuilder dmaapRequestCounterBuilder() { - return new DmaapRequestCounterBuilderImpl(); - } -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/PrimitiveCounterBuilderImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/PrimitiveCounterBuilderImpl.java deleted file mode 100644 index c95f89e75..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/PrimitiveCounterBuilderImpl.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.metric.impl; - -import org.onap.appc.metricservice.metric.MetricType; -import org.onap.appc.metricservice.metric.PrimitiveCounter; -import org.onap.appc.metricservice.metric.PrimitiveCounterBuilder; - - -public class PrimitiveCounterBuilderImpl implements PrimitiveCounterBuilder { - private String name; - private MetricType metricType; - private long counter; - - @Override - public PrimitiveCounterBuilder withName(String name) { - this.name=name; - return this; - } - - @Override - public PrimitiveCounterBuilder withValue(long value) { - this.counter=value; - return this; - } - - @Override - public PrimitiveCounterBuilder withType(MetricType type) { - this.metricType=type; - return this; - } - - @Override - public PrimitiveCounter build() { - return new DefaultPrimitiveCounter(this.name,this.metricType,this.counter); - } -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/PolicyBuilderFactory.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/PolicyBuilderFactory.java deleted file mode 100644 index fbdd04979..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/PolicyBuilderFactory.java +++ /dev/null @@ -1,30 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.policy; - - -public interface PolicyBuilderFactory { - ScheduledPolicyBuilder scheduledPolicyBuilder(); -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/PublishingPolicy.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/PublishingPolicy.java deleted file mode 100644 index 44a05f994..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/PublishingPolicy.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.policy; - -import org.onap.appc.exceptions.APPCException; -import org.onap.appc.metricservice.metric.Metric; - -/** - * - * A custom logic that determines strategy of exposing metric values. - * Policy is associated with a specific registry and its implementation can very from the simplest options, such as 'real-time' behavior (upon each value change) to more sophisticated approaches such as thresholds or recurrent scheduling rules. - * The policy can also decide whether or not to publish the entire metric registry or just a subset of the it (e.g. changed ones). - * Policy supports execution of one or more Publishers. - * - */ -public interface PublishingPolicy { - void onMetricChange(Metric meric) throws APPCException; - Metric[] metrics(); - - void init(); -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/ScheduledPolicyBuilder.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/ScheduledPolicyBuilder.java deleted file mode 100644 index d67031d03..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/ScheduledPolicyBuilder.java +++ /dev/null @@ -1,41 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.policy; - -import org.onap.appc.metricservice.Publisher; -import org.onap.appc.metricservice.metric.Metric; - -/** - * - * An auxiliary class to instantiate scheduler-based policy delivered along with the initial release of the service. - * - */ -public interface ScheduledPolicyBuilder { - ScheduledPolicyBuilder withStartTime(long time); - ScheduledPolicyBuilder withPeriod(long period); - ScheduledPolicyBuilder withPublishers(Publisher[] publishers); - ScheduledPolicyBuilder withMetrics(Metric[] metrics); - PublishingPolicy build(); -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/ScheduledPublishingPolicy.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/ScheduledPublishingPolicy.java deleted file mode 100644 index 697ef3ff7..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/ScheduledPublishingPolicy.java +++ /dev/null @@ -1,36 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.policy; - -import org.onap.appc.metricservice.Publisher; - - -public interface ScheduledPublishingPolicy extends PublishingPolicy{ - - long getStartTime(); - long getPeriod(); - Publisher[] getPublishers(); - void reset(); -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/impl/PolicyBuilderFactoryImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/impl/PolicyBuilderFactoryImpl.java deleted file mode 100644 index d9c4cf024..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/impl/PolicyBuilderFactoryImpl.java +++ /dev/null @@ -1,36 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.policy.impl; - -import org.onap.appc.metricservice.policy.PolicyBuilderFactory; -import org.onap.appc.metricservice.policy.ScheduledPolicyBuilder; - - -public class PolicyBuilderFactoryImpl implements PolicyBuilderFactory { - @Override - public ScheduledPolicyBuilder scheduledPolicyBuilder() { - return new ScheduledPolicyBuilderImpl(); - } -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/impl/ScheduledPolicyBuilderImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/impl/ScheduledPolicyBuilderImpl.java deleted file mode 100644 index 65ce62435..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/impl/ScheduledPolicyBuilderImpl.java +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.policy.impl; - -import org.onap.appc.metricservice.Publisher; -import org.onap.appc.metricservice.metric.Metric; -import org.onap.appc.metricservice.policy.PublishingPolicy; -import org.onap.appc.metricservice.policy.ScheduledPolicyBuilder; - - -public class ScheduledPolicyBuilderImpl implements ScheduledPolicyBuilder { - - private long startTime; - private long period; - private Publisher[] publishers; - private Metric[] metrics; - - @Override - public ScheduledPolicyBuilder withStartTime(long time) { - this.startTime=time; - return this; - } - - @Override - public ScheduledPolicyBuilder withPeriod(long period) { - this.period=period; - return this; - } - - @Override - public ScheduledPolicyBuilder withPublishers(Publisher[] publishers) { - this.publishers=publishers; - return this; - } - - @Override - public ScheduledPolicyBuilder withMetrics(Metric[] metrics) { - this.metrics=metrics; - return this; - } - - @Override - public PublishingPolicy build() { - return new ScheduledPublishingPolicyImpl(this.publishers,this.metrics); - } -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/impl/ScheduledPublishingPolicyImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/impl/ScheduledPublishingPolicyImpl.java deleted file mode 100644 index 8933150f3..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/policy/impl/ScheduledPublishingPolicyImpl.java +++ /dev/null @@ -1,224 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.policy.impl; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Properties; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; - -import org.onap.appc.configuration.Configuration; -import org.onap.appc.configuration.ConfigurationFactory; -import org.onap.appc.exceptions.APPCException; -import org.onap.appc.metricservice.MetricRegistry; -import org.onap.appc.metricservice.MetricService; -import org.onap.appc.metricservice.Publisher; -import org.onap.appc.metricservice.metric.Metric; -import org.onap.appc.metricservice.policy.ScheduledPublishingPolicy; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - - -public class ScheduledPublishingPolicyImpl implements ScheduledPublishingPolicy { - private long startTime; - private long period; - private Publisher[] publishers; - private Metric[] metrics; - private MetricRegistry metricRegistry; - private static final EELFLogger logger = EELFManager.getInstance().getLogger(ScheduledPublishingPolicyImpl.class); - private ScheduledExecutorService scheduleExecutor; - private Configuration configuration; - - public ScheduledPublishingPolicyImpl(long startTime, long period, Publisher[] publishers, Metric[] metrics) { - this.startTime = startTime; - this.period = period; - this.publishers = publishers; - this.metrics = metrics; - this.scheduleExecutor= Executors.newSingleThreadScheduledExecutor(getThreadFactory(true)); - } - - public ScheduledPublishingPolicyImpl( Publisher[] publishers, Metric[] metrics) { - configuration = ConfigurationFactory.getConfiguration(); - Properties properties=configuration.getProperties(); - if(properties!=null){ - if(properties.getProperty("schedule.policy.metric.period")!=null && properties.getProperty("schedule.policy.metric.start.time")!=null){ - this.startTime = getConfigStartTime(properties); - this.period = getConfigPeriod(properties); - logger.info("Metric Properties read from configuration Start Time :"+this.startTime+", Period :"+this.period); - }else if(properties.getProperty("schedule.policy.metric.period")!=null){ - this.startTime=1; - this.period=getConfigPeriod(properties); - logger.info("Metric Properties read from configuration Start Time :"+this.startTime+", Period :"+this.period); - - }else if(properties.getProperty("schedule.policy.metric.period")==null && properties.getProperty("schedule.policy.metric.start.time")!=null){ - this.startTime=getConfigStartTime("00:00:00",properties); - this.period=(24*60*60*1000)-1; - logger.info("Metric Properties read from configuration Start Time :"+this.startTime+", Period :"+this.period); - - }else{ - logger.info("Metric Properties coming as null,setting to default Start Time :1 ms,Period : 100000 ms"); - this.startTime = 1; - this.period = 100000; - logger.info("Metric Properties read from configuration Start Time :"+this.startTime+", Period :"+this.period); - - } - } else { - logger.info("Metric Properties coming as null,setting to default Start Time :1 ms,Period : 100000 ms"); - this.startTime = 1; - this.period = 100000; - logger.info("Metric Properties read from configuration Start Time :"+this.startTime+", Period :"+this.period); - } - this.publishers = publishers; - this.metrics = metrics; - this.scheduleExecutor= Executors.newSingleThreadScheduledExecutor(getThreadFactory(true)); - } - - private long getConfigPeriod(Properties properties) { - String period=properties.getProperty("schedule.policy.metric.period"); - logger.info("Metric period : " +period); - long periodInMs=Integer.parseInt(period)*1000; - logger.info("Metric period in long : " +periodInMs); - return periodInMs; - } - - private long getTimeInMs(String time) { - String[] strings=time.split(":"); - if(strings.length==3) { - long hour = Integer.parseInt(strings[0]) * 60 * 60 * 1000; - long min = Integer.parseInt(strings[1]) * 60 * 1000; - long sec = Integer.parseInt(strings[2]) * 1000; - return hour+min+sec; - }else{ - return 0; - } - - } - - - - private long getConfigStartTime(Properties properties) { - String startTime=properties.getProperty("schedule.policy.metric.start.time"); - if(startTime!=null){ - long timeDiff=(getTimeInMs(startTime))-(getTimeInMs((new SimpleDateFormat("HH:mm:ss")).format(new Date()))); - long period=getConfigPeriod(properties); - if(timeDiff>=0){ - return timeDiff; - }else{ - return period-((timeDiff*-1)%period); - } - } - return 0; - } - - private long getConfigStartTime(String startTime,Properties properties) { - if(startTime!=null){ - long timeDiff=(getTimeInMs(startTime))-(getTimeInMs((new SimpleDateFormat("HH:mm:ss")).format(new Date()))); - long period=getConfigPeriod(properties); - if(timeDiff>=0){ - return timeDiff%period; - }else{ - return period-((timeDiff*-1)%period); - } - } - return 0; - } - @Override - public void onMetricChange(Metric metric) throws APPCException { - //TODO - } - - @Override - public Metric[] metrics() { - return metrics; - } - - @Override - public void init() { - Properties properties=configuration.getProperties(); - boolean isMetricEnabled=false; - if(properties!=null){ - String metricProperty=properties.getProperty("metric.enabled"); - if(metricProperty!=null){ - isMetricEnabled=Boolean.valueOf(metricProperty); - } - } - if(isMetricEnabled){ - logger.info("Metric Service is enabled, hence policies getting scheduled"); - for(final Publisher publisher:this.getPublishers()){ - scheduleExecutor.scheduleWithFixedDelay(new Runnable() - { - public void run() { - try { - publisher.publish(metricRegistry, metrics); - reset(); - } catch (RuntimeException ex) { - logger.error("RuntimeException thrown from {}#report. Exception was suppressed.", publisher.getClass().getSimpleName(), ex); - } - } - } - , startTime, period, TimeUnit.MILLISECONDS); - } - }else{ - logger.info("Metric Service is not enabled, hence policies not getting scheduled"); - - } - } - - @Override - public long getStartTime() { - return this.startTime; - } - - @Override - public long getPeriod() { - return this.period; - } - - @Override - public Publisher[] getPublishers() { - return this.publishers; - } - - @Override - public void reset() { - for(Metric metric:this.metrics){ - metric.reset();} - } - - - private ThreadFactory getThreadFactory(final boolean isDaemon){ - return new ThreadFactory() { - public Thread newThread(Runnable r) { - Thread t = Executors.defaultThreadFactory().newThread(r); - t.setDaemon(isDaemon); - return t; - } - }; - } - -} diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/publisher/LogPublisher.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/publisher/LogPublisher.java deleted file mode 100644 index e4f160d40..000000000 --- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/publisher/LogPublisher.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice.publisher; - -import org.onap.appc.metricservice.MetricRegistry; -import org.onap.appc.metricservice.Publisher; -import org.onap.appc.metricservice.metric.Metric; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - - -public class LogPublisher implements Publisher { - private static final EELFLogger logger = EELFManager.getInstance().getLogger(LogPublisher.class); - private MetricRegistry metricRegistry; - private Metric[] metrics; - - public LogPublisher(MetricRegistry metricRegistry, Metric[] metrics) { - this.metricRegistry = metricRegistry; - this.metrics = metrics; - } - - @Override - public void publish(MetricRegistry metricRegistry, Metric[] metrics) { - for(Metric metric:metrics){ - logger.debug("LOG PUBLISHER:"+metric.name()+":"+metric.toString()); - } - } - - -} diff --git a/appc-metric/appc-metric-bundle/src/main/resources/org/onap/appc/default.properties b/appc-metric/appc-metric-bundle/src/main/resources/org/onap/appc/default.properties new file mode 100644 index 000000000..f7eae381e --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/main/resources/org/onap/appc/default.properties @@ -0,0 +1,31 @@ +### +# ============LICENSE_START======================================================= +# ONAP : APPC +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Copyright (C) 2017 Amdocs +# ============================================================================= +# 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. +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# ============LICENSE_END========================================================= +### + +# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded +# to supply configuration options +org.onap.appc.bootstrap.file=appc.properties +org.onap.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. + + + diff --git a/appc-metric/appc-metric-bundle/src/main/resources/org/openecomp/appc/default.properties b/appc-metric/appc-metric-bundle/src/main/resources/org/openecomp/appc/default.properties deleted file mode 100644 index f7eae381e..000000000 --- a/appc-metric/appc-metric-bundle/src/main/resources/org/openecomp/appc/default.properties +++ /dev/null @@ -1,31 +0,0 @@ -### -# ============LICENSE_START======================================================= -# ONAP : APPC -# ================================================================================ -# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. -# ================================================================================ -# Copyright (C) 2017 Amdocs -# ============================================================================= -# 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. -# -# ECOMP is a trademark and service mark of AT&T Intellectual Property. -# ============LICENSE_END========================================================= -### - -# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded -# to supply configuration options -org.onap.appc.bootstrap.file=appc.properties -org.onap.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. - - - diff --git a/appc-metric/appc-metric-bundle/src/test/java/org/onap/appc/metricservice/TestMetricServiceImpl.java b/appc-metric/appc-metric-bundle/src/test/java/org/onap/appc/metricservice/TestMetricServiceImpl.java new file mode 100644 index 000000000..7c8011e81 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/test/java/org/onap/appc/metricservice/TestMetricServiceImpl.java @@ -0,0 +1,169 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.metricservice; +import org.junit.Assert; +import org.junit.Test; +import org.onap.appc.metricservice.impl.MetricServiceImpl; +import org.onap.appc.metricservice.metric.MetricType; +import org.onap.appc.metricservice.metric.PrimitiveCounter; +import org.onap.appc.metricservice.metric.DmaapRequestCounterMetric; +import org.onap.appc.metricservice.metric.DispatchingFuntionMetric; +import org.onap.appc.metricservice.metric.impl.DefaultPrimitiveCounter; +import org.onap.appc.metricservice.metric.impl.DmaapRequestCounterMetricImpl; +import org.onap.appc.metricservice.metric.impl.DispatchingFuntionMetricImpl; +import org.onap.appc.metricservice.metric.impl.DispatchingFunctionCounterBuilderImpl; +import org.onap.appc.metricservice.metric.impl.DmaapRequestCounterBuilderImpl; +import org.onap.appc.metricservice.metric.impl.PrimitiveCounterBuilderImpl; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.TimeZone; + + +public class TestMetricServiceImpl { + @Test + public void createRegistryTest() { + MetricServiceImpl metricServiceImpl = new MetricServiceImpl(); + metricServiceImpl.createRegistry("anyName"); + MetricRegistry metricRegistry = metricServiceImpl.registry("anyName"); + Assert.assertNotNull(metricRegistry); + Assert.assertTrue(metricServiceImpl.getAllRegistry().keySet().contains("anyName")); + } + + @Test + public void testDefaultPrimitiveCounter(){ + DefaultPrimitiveCounter df= new DefaultPrimitiveCounter("TEST", MetricType.COUNTER); + df.increment(); + Assert.assertEquals(1, df.value()); + df.increment(25); + Assert.assertEquals(2, df.value()); + df.decrement(); + Assert.assertEquals(1, df.value()); + Assert.assertNotNull(df.getLastModified()); + Assert.assertEquals("TEST",df.name()); + Assert.assertEquals(MetricType.COUNTER,df.type()); + df.reset(); + Assert.assertEquals(0,df.value()); + Assert.assertNotNull(df.getMetricsOutput()); + + } + + @Test + public void testDefaultPrimitiveCounterWithThreeArgsConstructor(){ + DefaultPrimitiveCounter obj= new DefaultPrimitiveCounter("TEST", MetricType.COUNTER,3); + obj.increment(); + Assert.assertEquals(4, obj.value()); + obj.increment(25); + Assert.assertEquals(5, obj.value()); + obj.decrement(); + Assert.assertEquals(4, obj.value()); + Assert.assertNotNull(obj.getLastModified()); + Assert.assertEquals("TEST",obj.name()); + Assert.assertEquals(MetricType.COUNTER,obj.type()); + obj.reset(); + Assert.assertEquals(0,obj.value()); + Assert.assertNotNull(obj.getMetricsOutput()); + } + + @Test + public void testDmaapRequestCounterMetricImpl() { + + DmaapRequestCounterMetricImpl obj =new DmaapRequestCounterMetricImpl("TEST",MetricType.COUNTER,7,1); + String date = getCurrentDate(); + + obj.incrementPublishedMessage(); + obj.incrementRecievedMessage(); + Assert.assertEquals(2,Integer.parseInt(obj.getMetricsOutput().get("Total Published messages"))); + Assert.assertEquals(8,Integer.parseInt(obj.getMetricsOutput().get("Total Received messages"))); + Assert.assertEquals(date+"[8],[2]",obj.value()); + Assert.assertNotNull(obj.getLastModified()); + Assert.assertEquals("TEST",obj.name()); + Assert.assertEquals(MetricType.COUNTER,obj.type()); + obj.reset(); + Assert.assertEquals(0,Integer.parseInt(obj.getMetricsOutput().get("Total Published messages"))); + Assert.assertEquals(0,Integer.parseInt(obj.getMetricsOutput().get("Total Received messages"))); + + } + + @Test + public void testDispatchingFuntionMetricImpl() { + + DispatchingFuntionMetricImpl obj= new DispatchingFuntionMetricImpl("TEST",MetricType.COUNTER,7,1); + String date = getCurrentDate(); + + obj.incrementAcceptedRequest(); + obj.incrementRejectedRequest(); + Assert.assertEquals(10,Integer.parseInt(obj.getMetricsOutput().get("Total Received messages"))); + Assert.assertEquals(2,Integer.parseInt(obj.getMetricsOutput().get("Total Rejected messages"))); + Assert.assertEquals(date+"[8,2]@10",obj.value()); + Assert.assertNotNull(obj.getLastModified()); + Assert.assertEquals("TEST",obj.name()); + Assert.assertEquals(MetricType.COUNTER,obj.type()); + obj.reset(); + Assert.assertEquals(0,Integer.parseInt(obj.getMetricsOutput().get("Total Received messages"))); + Assert.assertEquals(0,Integer.parseInt(obj.getMetricsOutput().get("Total Rejected messages"))); + + + } + + @Test + public void testDispatchingFunctionCounterBuilderImpl(){ + DispatchingFunctionCounterBuilderImpl obj=new DispatchingFunctionCounterBuilderImpl(); + String date = getCurrentDate(); + DispatchingFuntionMetric metric=obj.withName("TEST").withType(MetricType.COUNTER).withAcceptRequestValue(7).withRejectRequestValue(2).build(); + metric.incrementAcceptedRequest(); + metric.incrementRejectedRequest(); + Assert.assertEquals(date+"[8,3]@11",metric.value()); + } + + @Test + public void testDmaapRequestCounterBuilderImpl(){ + DmaapRequestCounterBuilderImpl obj=new DmaapRequestCounterBuilderImpl(); + DmaapRequestCounterMetric metric =obj.withName("TEST").withPublishedMessage(1).withRecievedMessage(21).withType(MetricType.COUNTER).build(); + metric.incrementPublishedMessage(); + metric.incrementRecievedMessage(); + Assert.assertEquals(2,Integer.parseInt(metric.getMetricsOutput().get("Total Published messages"))); + Assert.assertEquals(22,Integer.parseInt(metric.getMetricsOutput().get("Total Received messages"))); + } + + @Test + public void testPrimitiveCounterBuilderImpl(){ + PrimitiveCounterBuilderImpl obj=new PrimitiveCounterBuilderImpl(); + PrimitiveCounter counter=obj.withName("TEST").withType(MetricType.COUNTER).withValue(1).build(); + counter.increment(); + Assert.assertEquals(2, counter.value()); + counter.decrement(); + Assert.assertEquals(1, counter.value()); + } + + private String getCurrentDate() { + Calendar cal = Calendar.getInstance(); + cal.setTimeZone(TimeZone.getTimeZone("UTC")); + SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd"); + return dateFormat.format(cal.getTime()); + + } + +} diff --git a/appc-metric/appc-metric-bundle/src/test/java/org/openecomp/appc/metricservice/TestMetricServiceImpl.java b/appc-metric/appc-metric-bundle/src/test/java/org/openecomp/appc/metricservice/TestMetricServiceImpl.java deleted file mode 100644 index 7c8011e81..000000000 --- a/appc-metric/appc-metric-bundle/src/test/java/org/openecomp/appc/metricservice/TestMetricServiceImpl.java +++ /dev/null @@ -1,169 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.metricservice; -import org.junit.Assert; -import org.junit.Test; -import org.onap.appc.metricservice.impl.MetricServiceImpl; -import org.onap.appc.metricservice.metric.MetricType; -import org.onap.appc.metricservice.metric.PrimitiveCounter; -import org.onap.appc.metricservice.metric.DmaapRequestCounterMetric; -import org.onap.appc.metricservice.metric.DispatchingFuntionMetric; -import org.onap.appc.metricservice.metric.impl.DefaultPrimitiveCounter; -import org.onap.appc.metricservice.metric.impl.DmaapRequestCounterMetricImpl; -import org.onap.appc.metricservice.metric.impl.DispatchingFuntionMetricImpl; -import org.onap.appc.metricservice.metric.impl.DispatchingFunctionCounterBuilderImpl; -import org.onap.appc.metricservice.metric.impl.DmaapRequestCounterBuilderImpl; -import org.onap.appc.metricservice.metric.impl.PrimitiveCounterBuilderImpl; - -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.TimeZone; - - -public class TestMetricServiceImpl { - @Test - public void createRegistryTest() { - MetricServiceImpl metricServiceImpl = new MetricServiceImpl(); - metricServiceImpl.createRegistry("anyName"); - MetricRegistry metricRegistry = metricServiceImpl.registry("anyName"); - Assert.assertNotNull(metricRegistry); - Assert.assertTrue(metricServiceImpl.getAllRegistry().keySet().contains("anyName")); - } - - @Test - public void testDefaultPrimitiveCounter(){ - DefaultPrimitiveCounter df= new DefaultPrimitiveCounter("TEST", MetricType.COUNTER); - df.increment(); - Assert.assertEquals(1, df.value()); - df.increment(25); - Assert.assertEquals(2, df.value()); - df.decrement(); - Assert.assertEquals(1, df.value()); - Assert.assertNotNull(df.getLastModified()); - Assert.assertEquals("TEST",df.name()); - Assert.assertEquals(MetricType.COUNTER,df.type()); - df.reset(); - Assert.assertEquals(0,df.value()); - Assert.assertNotNull(df.getMetricsOutput()); - - } - - @Test - public void testDefaultPrimitiveCounterWithThreeArgsConstructor(){ - DefaultPrimitiveCounter obj= new DefaultPrimitiveCounter("TEST", MetricType.COUNTER,3); - obj.increment(); - Assert.assertEquals(4, obj.value()); - obj.increment(25); - Assert.assertEquals(5, obj.value()); - obj.decrement(); - Assert.assertEquals(4, obj.value()); - Assert.assertNotNull(obj.getLastModified()); - Assert.assertEquals("TEST",obj.name()); - Assert.assertEquals(MetricType.COUNTER,obj.type()); - obj.reset(); - Assert.assertEquals(0,obj.value()); - Assert.assertNotNull(obj.getMetricsOutput()); - } - - @Test - public void testDmaapRequestCounterMetricImpl() { - - DmaapRequestCounterMetricImpl obj =new DmaapRequestCounterMetricImpl("TEST",MetricType.COUNTER,7,1); - String date = getCurrentDate(); - - obj.incrementPublishedMessage(); - obj.incrementRecievedMessage(); - Assert.assertEquals(2,Integer.parseInt(obj.getMetricsOutput().get("Total Published messages"))); - Assert.assertEquals(8,Integer.parseInt(obj.getMetricsOutput().get("Total Received messages"))); - Assert.assertEquals(date+"[8],[2]",obj.value()); - Assert.assertNotNull(obj.getLastModified()); - Assert.assertEquals("TEST",obj.name()); - Assert.assertEquals(MetricType.COUNTER,obj.type()); - obj.reset(); - Assert.assertEquals(0,Integer.parseInt(obj.getMetricsOutput().get("Total Published messages"))); - Assert.assertEquals(0,Integer.parseInt(obj.getMetricsOutput().get("Total Received messages"))); - - } - - @Test - public void testDispatchingFuntionMetricImpl() { - - DispatchingFuntionMetricImpl obj= new DispatchingFuntionMetricImpl("TEST",MetricType.COUNTER,7,1); - String date = getCurrentDate(); - - obj.incrementAcceptedRequest(); - obj.incrementRejectedRequest(); - Assert.assertEquals(10,Integer.parseInt(obj.getMetricsOutput().get("Total Received messages"))); - Assert.assertEquals(2,Integer.parseInt(obj.getMetricsOutput().get("Total Rejected messages"))); - Assert.assertEquals(date+"[8,2]@10",obj.value()); - Assert.assertNotNull(obj.getLastModified()); - Assert.assertEquals("TEST",obj.name()); - Assert.assertEquals(MetricType.COUNTER,obj.type()); - obj.reset(); - Assert.assertEquals(0,Integer.parseInt(obj.getMetricsOutput().get("Total Received messages"))); - Assert.assertEquals(0,Integer.parseInt(obj.getMetricsOutput().get("Total Rejected messages"))); - - - } - - @Test - public void testDispatchingFunctionCounterBuilderImpl(){ - DispatchingFunctionCounterBuilderImpl obj=new DispatchingFunctionCounterBuilderImpl(); - String date = getCurrentDate(); - DispatchingFuntionMetric metric=obj.withName("TEST").withType(MetricType.COUNTER).withAcceptRequestValue(7).withRejectRequestValue(2).build(); - metric.incrementAcceptedRequest(); - metric.incrementRejectedRequest(); - Assert.assertEquals(date+"[8,3]@11",metric.value()); - } - - @Test - public void testDmaapRequestCounterBuilderImpl(){ - DmaapRequestCounterBuilderImpl obj=new DmaapRequestCounterBuilderImpl(); - DmaapRequestCounterMetric metric =obj.withName("TEST").withPublishedMessage(1).withRecievedMessage(21).withType(MetricType.COUNTER).build(); - metric.incrementPublishedMessage(); - metric.incrementRecievedMessage(); - Assert.assertEquals(2,Integer.parseInt(metric.getMetricsOutput().get("Total Published messages"))); - Assert.assertEquals(22,Integer.parseInt(metric.getMetricsOutput().get("Total Received messages"))); - } - - @Test - public void testPrimitiveCounterBuilderImpl(){ - PrimitiveCounterBuilderImpl obj=new PrimitiveCounterBuilderImpl(); - PrimitiveCounter counter=obj.withName("TEST").withType(MetricType.COUNTER).withValue(1).build(); - counter.increment(); - Assert.assertEquals(2, counter.value()); - counter.decrement(); - Assert.assertEquals(1, counter.value()); - } - - private String getCurrentDate() { - Calendar cal = Calendar.getInstance(); - cal.setTimeZone(TimeZone.getTimeZone("UTC")); - SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd"); - return dateFormat.format(cal.getTime()); - - } - -} diff --git a/appc-metric/appc-metric-bundle/src/test/resources/org/onap/appc/default.properties b/appc-metric/appc-metric-bundle/src/test/resources/org/onap/appc/default.properties new file mode 100644 index 000000000..596705820 --- /dev/null +++ b/appc-metric/appc-metric-bundle/src/test/resources/org/onap/appc/default.properties @@ -0,0 +1,29 @@ +### +# ============LICENSE_START======================================================= +# ONAP : APPC +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Copyright (C) 2017 Amdocs +# ============================================================================= +# 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. +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# ============LICENSE_END========================================================= +### + +# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded to supply configuration options +#org.onap.appc.bootstrap.file=executor-test.properties +org.onap.appc.bootstrap.file=appc.properties +org.onap.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. + diff --git a/appc-metric/appc-metric-bundle/src/test/resources/org/openecomp/appc/default.properties b/appc-metric/appc-metric-bundle/src/test/resources/org/openecomp/appc/default.properties deleted file mode 100644 index 596705820..000000000 --- a/appc-metric/appc-metric-bundle/src/test/resources/org/openecomp/appc/default.properties +++ /dev/null @@ -1,29 +0,0 @@ -### -# ============LICENSE_START======================================================= -# ONAP : APPC -# ================================================================================ -# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. -# ================================================================================ -# Copyright (C) 2017 Amdocs -# ============================================================================= -# 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. -# -# ECOMP is a trademark and service mark of AT&T Intellectual Property. -# ============LICENSE_END========================================================= -### - -# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded to supply configuration options -#org.onap.appc.bootstrap.file=executor-test.properties -org.onap.appc.bootstrap.file=appc.properties -org.onap.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. - -- cgit 1.2.3-korg