use of org.ovirt.vdsm.jsonrpc.client.JsonRpcClient in project ovirt-engine by oVirt.
the class MarshallingTestCase method testGetVMListIdsOnly.
@SuppressWarnings("unchecked")
@Test
public void testGetVMListIdsOnly() throws Exception {
// Given
String json = "{\"jsonrpc\": \"2.0\", \"id\": \"e9968b53-7450-4059-83e6-d3569f7024ec\", \"result\": [\"1397d80b-1c48-4d4a-acf9-ebd669bf3b25\"]}";
ObjectMapper mapper = new ObjectMapper();
JsonRpcResponse response = JsonRpcResponse.fromJsonNode(mapper.readTree(json));
Future<JsonRpcResponse> future = mock(Future.class);
when(future.get()).thenReturn(response);
JsonRpcClient client = mock(JsonRpcClient.class);
JsonRpcRequest request = mock(JsonRpcRequest.class);
when(client.call(request)).thenReturn(future);
// When
Map<String, Object> map = new FutureMap(client, request).withResponseKey("vmList").withResponseType(Object[].class);
// Then
VMListReturn vmList = new VMListReturn(map);
assertEquals("Done", vmList.status.message);
assertEquals(0, vmList.status.code);
assertEquals(1, vmList.vmList.length);
assertEquals("1397d80b-1c48-4d4a-acf9-ebd669bf3b25", vmList.vmList[0].get("vmId"));
}
use of org.ovirt.vdsm.jsonrpc.client.JsonRpcClient in project ovirt-engine by oVirt.
the class MarshallingTestCase method testVolumeCreate.
@SuppressWarnings("unchecked")
@Test
public void testVolumeCreate() throws Exception {
// Given
String json = "{\"jsonrpc\": \"2.0\", \"id\": \"e8ea1fa9-d819-4c41-ae9c-b103a236fb29\", \"result\": {\"uuid\": \"4f84eef5-8f8b-4732-babd-0a860cf0d1b9\"}}";
ObjectMapper mapper = new ObjectMapper();
JsonRpcResponse response = JsonRpcResponse.fromJsonNode(mapper.readTree(json));
Future<JsonRpcResponse> future = mock(Future.class);
when(future.get()).thenReturn(response);
JsonRpcClient client = mock(JsonRpcClient.class);
JsonRpcRequest request = mock(JsonRpcRequest.class);
when(client.call(request)).thenReturn(future);
// When
Map<String, Object> map = new FutureMap(client, request).withIgnoreResponseKey();
// Then
OneUuidReturn oneuuid = new OneUuidReturn(map);
assertEquals("Done", oneuuid.getStatus().message);
assertEquals(0, oneuuid.getStatus().code);
assertEquals("4f84eef5-8f8b-4732-babd-0a860cf0d1b9", UUID.fromString(oneuuid.uuid).toString());
}
use of org.ovirt.vdsm.jsonrpc.client.JsonRpcClient in project ovirt-engine by oVirt.
the class MarshallingTestCase method testShortList.
@SuppressWarnings("unchecked")
@Test
public void testShortList() throws Exception {
// Given
String json = "{\"jsonrpc\": \"2.0\", \"id\": \"ae80f5c4-0f63-4c2e-aed6-5372f07a14c1\", \"result\": [\"e4a0fc02-c5ad-4b35-b2d0-5a4b6557c06b\"]}";
ObjectMapper mapper = new ObjectMapper();
JsonRpcResponse response = JsonRpcResponse.fromJsonNode(mapper.readTree(json));
Future<JsonRpcResponse> future = mock(Future.class);
when(future.get()).thenReturn(response);
JsonRpcClient client = mock(JsonRpcClient.class);
JsonRpcRequest request = mock(JsonRpcRequest.class);
when(client.call(request)).thenReturn(future);
// When
Map<String, Object> map = new FutureMap(client, request).withResponseKey("vmList").withResponseType(Object[].class).withSubTypeClazz(HashMap.class).withSubtypeKey("vmId");
// Then
VMListReturn vmList = new VMListReturn(map);
Status status = vmList.status;
assertEquals("Done", status.message);
assertEquals(0, status.code);
assertEquals(1, vmList.vmList.length);
}
use of org.ovirt.vdsm.jsonrpc.client.JsonRpcClient in project ovirt-engine by oVirt.
the class MarshallingTestCase method testStoragePoolInfo.
@SuppressWarnings("unchecked")
@Test
public void testStoragePoolInfo() throws Exception {
// Given
String json = "{\"jsonrpc\": \"2.0\", \"id\": \"609b5787-ab3a-485b-8ed8-0bc9a27eda27\", \"result\": {\"info\": {\"spm_id\": 1, \"master_uuid\": \"05a0ad59-1259-4353-b40b-34eb80d8590a\"," + " \"name\": \"Default\", \"version\": \"0\", \"domains\": \"05a0ad59-1259-4353-b40b-34eb80d8590a:Active,6ca00a0d-3f1d-4762-b5ff-c58a6a0a0324:Active,4192b643-fae9-4c1c-8b8b-9c9c6cc10523:Active\", " + "\"pool_status\": \"connected\", \"isoprefix\": \"/rhev/data-center/mnt/192.168.1.10:_export_iso/6ca00a0d-3f1d-4762-b5ff-c58a6a0a0324/images/11111111-1111-1111-1111-111111111111\", " + "\"type\": \"NFS\", \"master_ver\": 1, \"lver\": 0}, \"dominfo\": {\"05a0ad59-1259-4353-b40b-34eb80d8590a\": {\"status\": \"Active\", \"diskfree\": \"43887099904\", \"isoprefix\": \"\"," + " \"alerts\": [], \"disktotal\": \"52710866944\", \"version\": 0}, \"6ca00a0d-3f1d-4762-b5ff-c58a6a0a0324\": {\"status\": \"Active\", \"diskfree\": \"43887099904\", \"isoprefix\": " + "\"/rhev/data-center/mnt/192.168.1.10:_export_iso/6ca00a0d-3f1d-4762-b5ff-c58a6a0a0324/images/11111111-1111-1111-1111-111111111111\", \"alerts\": [], \"disktotal\": \"52710866944\", " + "\"version\": 0}, \"4192b643-fae9-4c1c-8b8b-9c9c6cc10523\": {\"status\": \"Active\", \"isoprefix\": \"\", \"alerts\": [], \"version\": -1}}}}";
ObjectMapper mapper = new ObjectMapper();
JsonRpcResponse response = JsonRpcResponse.fromJsonNode(mapper.readTree(json));
Future<JsonRpcResponse> future = mock(Future.class);
when(future.get()).thenReturn(response);
JsonRpcClient client = mock(JsonRpcClient.class);
JsonRpcRequest request = mock(JsonRpcRequest.class);
when(client.call(request)).thenReturn(future);
// When
Map<String, Object> map = new FutureMap(client, request).withIgnoreResponseKey();
// Then
StoragePoolInfo storagePoolInfo = new StoragePoolInfo(map);
assertEquals("Done", storagePoolInfo.getStatus().message);
assertEquals(0, storagePoolInfo.getStatus().code);
Set<String> keys = storagePoolInfo.domainsList.keySet();
assertEquals(3, keys.size());
assertTrue(keys.contains("05a0ad59-1259-4353-b40b-34eb80d8590a"));
assertTrue(keys.contains("6ca00a0d-3f1d-4762-b5ff-c58a6a0a0324"));
assertTrue(keys.contains("4192b643-fae9-4c1c-8b8b-9c9c6cc10523"));
Map<String, Object> info = storagePoolInfo.storagePoolInfo;
assertEquals("/rhev/data-center/mnt/192.168.1.10:_export_iso/6ca00a0d-3f1d-4762-b5ff-c58a6a0a0324/images/11111111-1111-1111-1111-111111111111", info.get("isoprefix"));
}
use of org.ovirt.vdsm.jsonrpc.client.JsonRpcClient in project ovirt-engine by oVirt.
the class JsonRpcUtils method getJsonClient.
private static JsonRpcClient getJsonClient(Reactor reactor, String hostName, int port, ClientPolicy connectionPolicy, ClientPolicy clientPolicy, int parallelism, ScheduledExecutorService executorService) throws ClientConnectionException {
final ReactorClient client = reactor.createClient(hostName, port);
client.setClientPolicy(connectionPolicy);
ResponseWorker worker = ReactorFactory.getWorker(parallelism);
JsonRpcClient jsonClient = worker.register(client);
jsonClient.setRetryPolicy(clientPolicy);
jsonClient.setExecutorService(executorService);
return jsonClient;
}
Aggregations