Skip to content

Commit

Permalink
Merge pull request #508 from iviireczech/volume-metadata
Browse files Browse the repository at this point in the history
Add Sample metadata init
  • Loading branch information
gondor committed Nov 15, 2015
2 parents 8afc135 + f896ebf commit 6e6cbf1
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<? extends Sample> 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);

}

}
121 changes: 121 additions & 0 deletions core-test/src/main/resources/telemetry/samples.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,6 @@ public void setMessageId(String messageId) {

@Override
public void setMetadata(Map<String, Object> metadata) {
// TODO Auto-generated method stub
this.metadata = metadata;
}
}

0 comments on commit 6e6cbf1

Please sign in to comment.