Search in sources :

Example 36 with SR

use of com.xensource.xenapi.SR in project cloudstack by apache.

the class XenServer610MigrateVolumeCommandWrapper method execute.

@Override
public Answer execute(final MigrateVolumeCommand command, final XenServer610Resource xenServer610Resource) {
    Connection connection = xenServer610Resource.getConnection();
    String srcVolumeUuid = command.getVolumePath();
    SR destPool = null;
    Map<String, String> destDetails = command.getDestDetails();
    try {
        VDI srcVolume = xenServer610Resource.getVDIbyUuid(connection, srcVolumeUuid);
        if (destDetails != null && Boolean.parseBoolean(destDetails.get(DiskTO.MANAGED))) {
            String iScsiName = destDetails.get(DiskTO.IQN);
            String storageHost = destDetails.get(DiskTO.STORAGE_HOST);
            String chapInitiatorUsername = destDetails.get(DiskTO.CHAP_INITIATOR_USERNAME);
            String chapInitiatorSecret = destDetails.get(DiskTO.CHAP_INITIATOR_SECRET);
            destPool = xenServer610Resource.getIscsiSR(connection, iScsiName, storageHost, iScsiName, chapInitiatorUsername, chapInitiatorSecret, false);
        } else {
            final StorageFilerTO pool = command.getPool();
            destPool = xenServer610Resource.getStorageRepository(connection, CitrixHelper.getSRNameLabel(pool.getUuid(), pool.getType(), pool.getPath()));
        }
        Map<String, String> other = new HashMap<>();
        other.put("live", "true");
        // Live migrate the VDI.
        Task task = srcVolume.poolMigrateAsync(connection, destPool, other);
        long timeout = xenServer610Resource.getMigrateWait() * 1000L;
        xenServer610Resource.waitForTask(connection, task, 1000, timeout);
        xenServer610Resource.checkForSuccess(connection, task);
        VDI destVdi = Types.toVDI(task, connection);
        return new MigrateVolumeAnswer(command, true, null, destVdi.getUuid(connection));
    } catch (Exception ex) {
        if (destDetails != null && Boolean.parseBoolean(destDetails.get(DiskTO.MANAGED)) && destPool != null) {
            xenServer610Resource.removeSR(connection, destPool);
        }
        String msg = "Caught exception " + ex.getClass().getName() + " due to the following: " + ex.toString();
        LOGGER.error(msg, ex);
        return new MigrateVolumeAnswer(command, false, msg, null);
    }
}
Also used : Task(com.xensource.xenapi.Task) HashMap(java.util.HashMap) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) Connection(com.xensource.xenapi.Connection) VDI(com.xensource.xenapi.VDI) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) SR(com.xensource.xenapi.SR)

Example 37 with SR

use of com.xensource.xenapi.SR in project cloudstack by apache.

the class CitrixResourceBaseTest method createStartUpStorageCommandTest.

@Test
public void createStartUpStorageCommandTest() throws XenAPIException, XmlRpcException {
    String hostUuid = "hostUUid";
    citrixResourceBase._host.setUuid(hostUuid);
    citrixResourceBase._dcId = 1;
    Connection connectionMock = Mockito.mock(Connection.class);
    SR srMock = Mockito.mock(SR.class);
    StoragePoolInfo storagePoolInfoMock = Mockito.mock(StoragePoolInfo.class);
    Mockito.doNothing().when(citrixResourceBase).configureStorageNameAndDescription(connectionMock, srMock);
    Mockito.doReturn(storagePoolInfoMock).when(citrixResourceBase).createStoragePoolInfo(connectionMock, srMock);
    StartupStorageCommand startUpStorageCommand = citrixResourceBase.createStartUpStorageCommand(connectionMock, srMock);
    Assert.assertEquals(hostUuid, startUpStorageCommand.getGuid());
    Assert.assertEquals(storagePoolInfoMock, startUpStorageCommand.getPoolInfo());
    Assert.assertEquals(citrixResourceBase._dcId + "", startUpStorageCommand.getDataCenter());
    Assert.assertEquals(StorageResourceType.STORAGE_POOL, startUpStorageCommand.getResourceType());
}
Also used : StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) StoragePoolInfo(com.cloud.agent.api.StoragePoolInfo) Connection(com.xensource.xenapi.Connection) SR(com.xensource.xenapi.SR) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 38 with SR

use of com.xensource.xenapi.SR in project cloudstack by apache.

the class CitrixResourceBaseTest method getAllLocalSrForTypeNoSrsFoundTest.

@Test
public void getAllLocalSrForTypeNoSrsFoundTest() throws XenAPIException, XmlRpcException {
    Connection connectionMock = Mockito.mock(Connection.class);
    List<SR> allLocalSrForType = citrixResourceBase.getAllLocalSrForType(connectionMock, SRType.EXT);
    Assert.assertTrue(allLocalSrForType.isEmpty());
}
Also used : Connection(com.xensource.xenapi.Connection) SR(com.xensource.xenapi.SR) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 39 with SR

use of com.xensource.xenapi.SR in project cloudstack by apache.

the class Xenserver625StorageProcessorTest method forgetSrTest.

@Test
public void forgetSrTest() throws XenAPIException, XmlRpcException {
    PBD pbdMock = Mockito.mock(PBD.class);
    Set<PBD> pbds = new HashSet<>();
    pbds.add(pbdMock);
    SR srMock = Mockito.mock(SR.class);
    Mockito.when(srMock.getPBDs(connectionMock)).thenReturn(pbds);
    Mockito.doNothing().when(xenserver625StorageProcessor).unplugPbd(connectionMock, pbdMock);
    xenserver625StorageProcessor.forgetSr(connectionMock, srMock);
    Mockito.verify(srMock).getPBDs(connectionMock);
    Mockito.verify(xenserver625StorageProcessor, times(1)).unplugPbd(connectionMock, pbdMock);
    Mockito.verify(srMock).forget(connectionMock);
}
Also used : PBD(com.xensource.xenapi.PBD) HashSet(java.util.HashSet) SR(com.xensource.xenapi.SR) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 40 with SR

use of com.xensource.xenapi.SR in project cloudstack by apache.

the class Xenserver625StorageProcessorTest method retrieveAlreadyConfiguredSrTestNoSrFound.

@Test
@PrepareForTest(SR.class)
public void retrieveAlreadyConfiguredSrTestNoSrFound() throws XenAPIException, XmlRpcException {
    prepareToReturnSrs(null);
    SR sr = xenserver625StorageProcessor.retrieveAlreadyConfiguredSr(connectionMock, pathMock);
    PowerMockito.verifyStatic(SR.class);
    SR.getByNameLabel(connectionMock, pathMock);
    Assert.assertNull(sr);
}
Also used : SR(com.xensource.xenapi.SR) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

SR (com.xensource.xenapi.SR)165 XenAPIException (com.xensource.xenapi.Types.XenAPIException)105 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)102 XmlRpcException (org.apache.xmlrpc.XmlRpcException)97 Connection (com.xensource.xenapi.Connection)92 VDI (com.xensource.xenapi.VDI)81 InternalErrorException (com.cloud.exception.InternalErrorException)64 HashMap (java.util.HashMap)45 Host (com.xensource.xenapi.Host)40 PBD (com.xensource.xenapi.PBD)37 URI (java.net.URI)36 NfsTO (com.cloud.agent.api.to.NfsTO)34 Test (org.junit.Test)27 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)26 Task (com.xensource.xenapi.Task)26 DataTO (com.cloud.agent.api.to.DataTO)25 Answer (com.cloud.agent.api.Answer)22 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)21 IOException (java.io.IOException)20 MalformedURLException (java.net.MalformedURLException)20