Search in sources :

Example 11 with JsonRpcClient

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"));
}
Also used : JsonRpcResponse(org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse) JsonRpcRequest(org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest) VMListReturn(org.ovirt.engine.core.vdsbroker.vdsbroker.VMListReturn) JsonRpcClient(org.ovirt.vdsm.jsonrpc.client.JsonRpcClient) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 12 with JsonRpcClient

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());
}
Also used : JsonRpcResponse(org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse) JsonRpcRequest(org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest) OneUuidReturn(org.ovirt.engine.core.vdsbroker.irsbroker.OneUuidReturn) JsonRpcClient(org.ovirt.vdsm.jsonrpc.client.JsonRpcClient) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 13 with JsonRpcClient

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);
}
Also used : JsonRpcResponse(org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse) Status(org.ovirt.engine.core.vdsbroker.vdsbroker.Status) JsonRpcRequest(org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest) HashMap(java.util.HashMap) VMListReturn(org.ovirt.engine.core.vdsbroker.vdsbroker.VMListReturn) JsonRpcClient(org.ovirt.vdsm.jsonrpc.client.JsonRpcClient) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 14 with JsonRpcClient

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"));
}
Also used : JsonRpcResponse(org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse) JsonRpcRequest(org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest) StoragePoolInfo(org.ovirt.engine.core.vdsbroker.irsbroker.StoragePoolInfo) JsonRpcClient(org.ovirt.vdsm.jsonrpc.client.JsonRpcClient) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 15 with JsonRpcClient

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;
}
Also used : ReactorClient(org.ovirt.vdsm.jsonrpc.client.reactors.ReactorClient) ResponseWorker(org.ovirt.vdsm.jsonrpc.client.internal.ResponseWorker) JsonRpcClient(org.ovirt.vdsm.jsonrpc.client.JsonRpcClient)

Aggregations

JsonRpcClient (org.ovirt.vdsm.jsonrpc.client.JsonRpcClient)15 Test (org.junit.Test)14 JsonRpcRequest (org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest)14 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)13 JsonRpcResponse (org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse)13 VMListReturn (org.ovirt.engine.core.vdsbroker.vdsbroker.VMListReturn)4 HashMap (java.util.HashMap)3 Status (org.ovirt.engine.core.vdsbroker.vdsbroker.Status)3 Map (java.util.Map)2 FileStatsReturn (org.ovirt.engine.core.vdsbroker.irsbroker.FileStatsReturn)2 OneUuidReturn (org.ovirt.engine.core.vdsbroker.irsbroker.OneUuidReturn)1 StoragePoolInfo (org.ovirt.engine.core.vdsbroker.irsbroker.StoragePoolInfo)1 StorageStatusReturn (org.ovirt.engine.core.vdsbroker.irsbroker.StorageStatusReturn)1 IQNListReturn (org.ovirt.engine.core.vdsbroker.vdsbroker.IQNListReturn)1 ServerConnectionStatusReturn (org.ovirt.engine.core.vdsbroker.vdsbroker.ServerConnectionStatusReturn)1 VDSInfoReturn (org.ovirt.engine.core.vdsbroker.vdsbroker.VDSInfoReturn)1 RequestBuilder (org.ovirt.vdsm.jsonrpc.client.RequestBuilder)1 ResponseWorker (org.ovirt.vdsm.jsonrpc.client.internal.ResponseWorker)1 ReactorClient (org.ovirt.vdsm.jsonrpc.client.reactors.ReactorClient)1