Search in sources :

Example 1 with VMListReturn

use of org.ovirt.engine.core.vdsbroker.vdsbroker.VMListReturn in project ovirt-engine by oVirt.

the class JsonRpcVdsServer method list.

@Override
public VMListReturn list() {
    JsonRpcRequest request = new RequestBuilder("Host.getVMList").withOptionalParameterAsList("vmList", new ArrayList<>(Arrays.asList(new String[] {}))).withParameter("onlyUUID", false).build();
    Map<String, Object> response = new FutureMap(this.client, request).withResponseKey("vmList").withResponseType(Object[].class);
    return new VMListReturn(response);
}
Also used : JsonRpcRequest(org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest) RequestBuilder(org.ovirt.vdsm.jsonrpc.client.RequestBuilder) VMListReturn(org.ovirt.engine.core.vdsbroker.vdsbroker.VMListReturn)

Example 2 with VMListReturn

use of org.ovirt.engine.core.vdsbroker.vdsbroker.VMListReturn in project ovirt-engine by oVirt.

the class JsonRpcVdsServer method fullList.

@Override
public VMListReturn fullList(List<String> vmIds) {
    JsonRpcRequest request = new RequestBuilder("Host.getVMFullList").withOptionalParameterAsList("vmList", vmIds).build();
    Map<String, Object> response = new FutureMap(this.client, request).withResponseKey("vmList").withResponseType(Object[].class);
    return new VMListReturn(response);
}
Also used : JsonRpcRequest(org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest) RequestBuilder(org.ovirt.vdsm.jsonrpc.client.RequestBuilder) VMListReturn(org.ovirt.engine.core.vdsbroker.vdsbroker.VMListReturn)

Example 3 with VMListReturn

use of org.ovirt.engine.core.vdsbroker.vdsbroker.VMListReturn in project ovirt-engine by oVirt.

the class MarshallingTestCase method testGetVMList.

@SuppressWarnings("unchecked")
@Test
public void testGetVMList() throws Exception {
    // Given
    String json = "{\"jsonrpc\": \"2.0\", \"id\": \"e32621e5-753f-45b8-b071-2eb929408efd\", \"result\": [{\"status\": \"Up\", \"vmId\": \"dd4d61c3-5128-4c26-ae71-0dbe5081ea93\"}]}";
    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("dd4d61c3-5128-4c26-ae71-0dbe5081ea93", vmList.vmList[0].get("vmId"));
    assertEquals("Up", vmList.vmList[0].get("status"));
}
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 4 with VMListReturn

use of org.ovirt.engine.core.vdsbroker.vdsbroker.VMListReturn in project ovirt-engine by oVirt.

the class MarshallingTestCase method testEmptyListVDS.

@SuppressWarnings("unchecked")
@Test
public void testEmptyListVDS() throws Exception {
    // Given
    String json = "{\"jsonrpc\": \"2.0\", \"id\": \"3a0a4c64-1b67-4b48-bc31-e4e0cb7538b1\", \"result\": []}";
    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);
    Status status = vmList.status;
    assertEquals("Done", status.message);
    assertEquals(0, status.code);
    assertEquals(0, 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) 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 5 with VMListReturn

use of org.ovirt.engine.core.vdsbroker.vdsbroker.VMListReturn 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)

Aggregations

VMListReturn (org.ovirt.engine.core.vdsbroker.vdsbroker.VMListReturn)7 JsonRpcRequest (org.ovirt.vdsm.jsonrpc.client.JsonRpcRequest)7 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 Test (org.junit.Test)4 JsonRpcClient (org.ovirt.vdsm.jsonrpc.client.JsonRpcClient)4 JsonRpcResponse (org.ovirt.vdsm.jsonrpc.client.JsonRpcResponse)4 RequestBuilder (org.ovirt.vdsm.jsonrpc.client.RequestBuilder)3 Status (org.ovirt.engine.core.vdsbroker.vdsbroker.Status)2 HashMap (java.util.HashMap)1