From f896ebfd3cfd2706dbb6e52cce669872f4edad90 Mon Sep 17 00:00:00 2001 From: Miroslav Lacina Date: Sat, 14 Nov 2015 20:42:37 +0100 Subject: [PATCH] Add Sample metadata init --- .../api/telemetry/SampleTests.java | 39 ++++++ .../src/main/resources/telemetry/samples.json | 121 ++++++++++++++++++ .../telemetry/domain/CeilometerSample.java | 2 +- 3 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 core-test/src/main/java/org/openstack4j/api/telemetry/SampleTests.java create mode 100644 core-test/src/main/resources/telemetry/samples.json diff --git a/core-test/src/main/java/org/openstack4j/api/telemetry/SampleTests.java b/core-test/src/main/java/org/openstack4j/api/telemetry/SampleTests.java new file mode 100644 index 000000000..f691702e0 --- /dev/null +++ b/core-test/src/main/java/org/openstack4j/api/telemetry/SampleTests.java @@ -0,0 +1,39 @@ +package org.openstack4j.api.telemetry; + +import org.openstack4j.api.AbstractTest; +import org.openstack4j.model.telemetry.Event; +import org.openstack4j.model.telemetry.Sample; +import org.openstack4j.model.telemetry.Trait; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.util.List; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +@Test(suiteName="Sample Tests") +public class SampleTests extends AbstractTest { + + private static final String JSON_SAMPLES = "/telemetry/samples.json"; + + @Override + protected Service service() { + return Service.TELEMETRY; + } + + @Test + public void listTest() throws IOException { + respondWith(JSON_SAMPLES); + + List samples = os().telemetry().meters().samples("cpu"); + assertEquals(samples.size(), 3); + + Sample sample = samples.get(0); + assertEquals(sample.getCounterName(), "cpu"); + assertNotNull(sample.getMetadata()); + assertEquals(sample.getMetadata().size(), 26); + + } + +} diff --git a/core-test/src/main/resources/telemetry/samples.json b/core-test/src/main/resources/telemetry/samples.json new file mode 100644 index 000000000..84eca9ff4 --- /dev/null +++ b/core-test/src/main/resources/telemetry/samples.json @@ -0,0 +1,121 @@ +[ + { + "counter_name": "cpu", + "user_id": "c9ecb6ecf09045e5bbf5f223492e63a0", + "resource_id": "95f30eea-0d6b-4de5-a71f-bf27ab74d1eb", + "timestamp": "2015-11-13T00:56:08", + "recorded_at": "2015-11-13T00:56:08.394081", + "message_id": "531e2408-89a1-11e5-9d10-080027fe75d2", + "source": "openstack", + "counter_unit": "ns", + "counter_volume": 107830000000.0, + "project_id": "78d58a27e48e46678b70cd2448141de2", + "resource_metadata": { + "ephemeral_gb": "0", + "flavor.vcpus": "1", + "OS-EXT-AZ.availability_zone": "nova", + "display_name": "test", + "flavor.ram": "64", + "status": "active", + "ramdisk_id": "59b8ec22-26b9-4111-aab6-a51a094ea6c1", + "flavor.name": "m1.nano", + "disk_gb": "0", + "kernel_id": "db41e262-294f-41bc-bcef-e37cc8bcaafa", + "image.id": "150be85f-6dd3-4c91-af18-197735fa498c", + "flavor.id": "42", + "host": "ba714ffcdd167996d70f4dbfdd81e714c251d9baa486a028229d763e", + "flavor.ephemeral": "0", + "image.name": "cirros-0.3.4-x86_64-uec", + "image_ref_url": "http://192.168.56.101:8774/8d1885c3cc7c41e98816b98d3240388f/images/150be85f-6dd3-4c91-af18-197735fa498c", + "name": "instance-00000009", + "cpu_number": "1", + "flavor.disk": "0", + "root_gb": "0", + "image.links": "[{'href': 'http://192.168.56.101:8774/8d1885c3cc7c41e98816b98d3240388f/images/150be85f-6dd3-4c91-af18-197735fa498c', 'rel': 'bookmark'}]", + "memory_mb": "64", + "instance_type": "m1.nano", + "vcpus": "1", + "image_ref": "150be85f-6dd3-4c91-af18-197735fa498c", + "flavor.links": "[{'href': 'http://192.168.56.101:8774/8d1885c3cc7c41e98816b98d3240388f/flavors/42', 'rel': 'bookmark'}]" + }, + "counter_type": "cumulative" + }, + { + "counter_name": "cpu", + "user_id": "a214ef1246a044ab876100fc0b5d9f25", + "resource_id": "ad5a3906-4ac3-4b32-abb0-237171d11048", + "timestamp": "2015-11-13T00:56:08", + "recorded_at": "2015-11-13T00:56:08.498232", + "message_id": "53215628-89a1-11e5-9d10-080027fe75d2", + "source": "openstack", + "counter_unit": "ns", + "counter_volume": 0.0, + "project_id": "9e25eb031b8d43e5aac3686b8e7696c6", + "resource_metadata": { + "image": "None", + "ramdisk_id": "None", + "flavor.vcpus": "1", + "OS-EXT-AZ.availability_zone": "nova", + "display_name": "boot_from_volume_snapshot", + "flavor.ram": "64", + "status": "shutoff", + "ephemeral_gb": "0", + "flavor.name": "m1.nano", + "disk_gb": "0", + "kernel_id": "None", + "flavor.id": "42", + "host": "205abadfcd65817185f9fb0f7123c58541ffae645b2221df08c32ebe", + "flavor.ephemeral": "0", + "image_ref_url": "None", + "cpu_number": "1", + "flavor.disk": "0", + "root_gb": "0", + "name": "instance-00000007", + "memory_mb": "64", + "instance_type": "m1.nano", + "vcpus": "1", + "image_ref": "None", + "flavor.links": "[{'href': 'http://192.168.56.101:8774/8d1885c3cc7c41e98816b98d3240388f/flavors/42', 'rel': 'bookmark'}]" + }, + "counter_type": "cumulative" + }, + { + "counter_name": "cpu", + "user_id": "a214ef1246a044ab876100fc0b5d9f25", + "resource_id": "16922c74-0b2d-437b-ac54-7f1d5582d078", + "timestamp": "2015-11-13T00:56:08", + "recorded_at": "2015-11-13T00:56:08.578034", + "message_id": "5323838a-89a1-11e5-9d10-080027fe75d2", + "source": "openstack", + "counter_unit": "ns", + "counter_volume": 206270000000.0, + "project_id": "9e25eb031b8d43e5aac3686b8e7696c6", + "resource_metadata": { + "image": "None", + "ramdisk_id": "None", + "flavor.vcpus": "1", + "OS-EXT-AZ.availability_zone": "nova", + "display_name": "boot_from_volume", + "flavor.ram": "64", + "status": "active", + "ephemeral_gb": "0", + "flavor.name": "m1.nano", + "disk_gb": "0", + "kernel_id": "None", + "flavor.id": "42", + "host": "205abadfcd65817185f9fb0f7123c58541ffae645b2221df08c32ebe", + "flavor.ephemeral": "0", + "image_ref_url": "None", + "cpu_number": "1", + "flavor.disk": "0", + "root_gb": "0", + "name": "instance-00000006", + "memory_mb": "64", + "instance_type": "m1.nano", + "vcpus": "1", + "image_ref": "None", + "flavor.links": "[{'href': 'http://192.168.56.101:8774/8d1885c3cc7c41e98816b98d3240388f/flavors/42', 'rel': 'bookmark'}]" + }, + "counter_type": "cumulative" + } +] \ No newline at end of file diff --git a/core/src/main/java/org/openstack4j/openstack/telemetry/domain/CeilometerSample.java b/core/src/main/java/org/openstack4j/openstack/telemetry/domain/CeilometerSample.java index 63209a49e..aed2ea943 100644 --- a/core/src/main/java/org/openstack4j/openstack/telemetry/domain/CeilometerSample.java +++ b/core/src/main/java/org/openstack4j/openstack/telemetry/domain/CeilometerSample.java @@ -221,6 +221,6 @@ public void setMessageId(String messageId) { @Override public void setMetadata(Map metadata) { - // TODO Auto-generated method stub + this.metadata = metadata; } }