Search in sources :

Example 1 with Action

use of org.ovirt.engine.sdk4.types.Action in project ovirt-engine-sdk-java by oVirt.

the class ActionReaderTest method testFaultActionWithReason.

/**
 * Checks that having fault action with reason and detail is handled correctly
 */
@Test
public void testFaultActionWithReason() throws Exception {
    String response = "<action><fault><reason>myreason</reason><detail>mydetail</detail></fault></action>";
    try (InputStream stream = new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8));
        XmlReader reader = new XmlReader(stream)) {
        Action action = XmlActionReader.readOne(reader);
        assertTrue(action.faultPresent());
        assertTrue(action.fault().reasonPresent());
        assertEquals("myreason", action.fault().reason());
        assertTrue(action.fault().detailPresent());
        assertEquals("mydetail", action.fault().detail());
    }
}
Also used : Action(org.ovirt.engine.sdk4.types.Action) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XmlReader(org.ovirt.api.metamodel.runtime.xml.XmlReader) Test(org.junit.Test)

Example 2 with Action

use of org.ovirt.engine.sdk4.types.Action in project ovirt-engine-sdk-java by oVirt.

the class IscsiDiscover method main.

public static void main(String[] args) throws Exception {
    // Create the connection to the server:
    Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
    // Get the reference to the hosts service:
    HostsService hostsService = connection.systemService().hostsService();
    // Find the host:
    Host host = hostsService.list().search("name=myhost").send().hosts().get(0);
    // Locate the service that manages the host, as that is where the action methods are defined:
    HostService hostService = hostsService.hostService(host.id());
    // Call the "iscsiDiscover" method of the service to start it:
    HostService.IscsiDiscoverResponse response = hostService.iscsiDiscover().iscsi(iscsiDetails().address("myaddress")).send();
    // Print only targets:
    for (String target : response.iscsiTargets()) {
        System.out.println(target);
    }
    // Print only address corresponding to target:
    for (IscsiDetails detail : response.discoveredTargets()) {
        System.out.println(detail.address() + ":" + detail.target());
    }
    // Close the connection to the server:
    connection.close();
}
Also used : HostService(org.ovirt.engine.sdk4.services.HostService) IscsiDetails(org.ovirt.engine.sdk4.types.IscsiDetails) Connection(org.ovirt.engine.sdk4.Connection) HostsService(org.ovirt.engine.sdk4.services.HostsService) Host(org.ovirt.engine.sdk4.types.Host)

Example 3 with Action

use of org.ovirt.engine.sdk4.types.Action in project ovirt-engine-sdk-java by oVirt.

the class VmsServiceTest method testFaultReaderWithoutAction.

/**
 * When the server returns an action containing a fault
 * raises an error containing the information of the fault.
 */
@Test
public void testFaultReaderWithoutAction() {
    boolean raised = false;
    VmService vmService = vmsService.vmService("123");
    try {
        vmService.start().send();
    } catch (Error e) {
        assertTrue(e.getMessage().contains("myreason"));
        raised = true;
    }
    assertTrue(raised);
}
Also used : VmService(org.ovirt.engine.sdk4.services.VmService) Test(org.junit.Test)

Example 4 with Action

use of org.ovirt.engine.sdk4.types.Action in project ovirt-engine-sdk-java by oVirt.

the class IscsiDiscoverTest method testActionParameters.

/**
 * Test we don't get null vm service for existing vm id and correct object
 */
@Test
public void testActionParameters() {
    HostsService hostsService = connection.systemService().hostsService();
    HostService hostService = hostsService.hostService("123");
    HostService.IscsiDiscoverResponse response = hostService.iscsiDiscover().iscsi(iscsiDetails().address("iscsi.example.com").port(3260)).send();
    assertEquals("<action>" + "<iscsi>" + "<address>iscsi.example.com</address>" + "<port>3260</port>" + "</iscsi>" + "</action>", getLastRequestContent());
    assertEquals("192.168.121.102", response.discoveredTargets().get(0).address());
    assertEquals(BigInteger.valueOf(3260), response.discoveredTargets().get(0).port());
    assertEquals("myiqn", response.iscsiTargets().get(0));
}
Also used : HostService(org.ovirt.engine.sdk4.services.HostService) HostsService(org.ovirt.engine.sdk4.services.HostsService) Test(org.junit.Test)

Example 5 with Action

use of org.ovirt.engine.sdk4.types.Action in project ovirt-engine-sdk-java by oVirt.

the class ActionReaderTest method testFaultActionNoValue.

/**
 * Checks that having fault action empty is handled correctly
 */
@Test
public void testFaultActionNoValue() throws Exception {
    try (InputStream stream = new ByteArrayInputStream("<fault/>".getBytes(StandardCharsets.UTF_8));
        XmlReader reader = new XmlReader(stream)) {
        Action action = XmlActionReader.readOne(reader);
        assertFalse(action.statusPresent());
        assertFalse(action.faultPresent());
        assertNull(action.fault());
        assertNull(action.status());
    }
}
Also used : Action(org.ovirt.engine.sdk4.types.Action) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XmlReader(org.ovirt.api.metamodel.runtime.xml.XmlReader) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 XmlReader (org.ovirt.api.metamodel.runtime.xml.XmlReader)4 Connection (org.ovirt.engine.sdk4.Connection)4 VmService (org.ovirt.engine.sdk4.services.VmService)4 Action (org.ovirt.engine.sdk4.types.Action)4 Vm (org.ovirt.engine.sdk4.types.Vm)3 HostService (org.ovirt.engine.sdk4.services.HostService)2 HostsService (org.ovirt.engine.sdk4.services.HostsService)2 VmsService (org.ovirt.engine.sdk4.services.VmsService)2 StorageDomainService (org.ovirt.engine.sdk4.services.StorageDomainService)1 StorageDomainVmService (org.ovirt.engine.sdk4.services.StorageDomainVmService)1 StorageDomainVmsService (org.ovirt.engine.sdk4.services.StorageDomainVmsService)1 StorageDomainsService (org.ovirt.engine.sdk4.services.StorageDomainsService)1 Host (org.ovirt.engine.sdk4.types.Host)1 IscsiDetails (org.ovirt.engine.sdk4.types.IscsiDetails)1 StorageDomain (org.ovirt.engine.sdk4.types.StorageDomain)1