diff options
Diffstat (limited to 'appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/metric')
17 files changed, 953 insertions, 0 deletions
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 <String,String> 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<String,String> 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<String, String> 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<String, String> getMetricsOutput() { + HashMap<String, String> 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<String, String> getMetricsOutput() { + HashMap<String, String> 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); + } +} |