Search in sources :

Example 6 with EndPoint

use of org.apache.cloudstack.engine.subsystem.api.storage.EndPoint in project cloudstack by apache.

the class EndpointSelectorTest method testMixZonePrimaryStorages.

@Test
public void testMixZonePrimaryStorages() {
    Long srcStoreId = null;
    Long destStoreId = imageStore.getId();
    DataStore store = createPrimaryDataStore(ScopeType.ZONE);
    srcStoreId = store.getId();
    HostVO host = createHost(Hypervisor.HypervisorType.VMware);
    addStorageToHost(store, host);
    store = createPrimaryDataStore(ScopeType.ZONE);
    host = createHost(Hypervisor.HypervisorType.VMware);
    addStorageToHost(store, host);
    Long xenStoreId = null;
    store = createPrimaryDataStore(ScopeType.CLUSTER);
    xenStoreId = store.getId();
    host = createHost(Hypervisor.HypervisorType.XenServer);
    addStorageToHost(store, host);
    store = createPrimaryDataStore(ScopeType.CLUSTER);
    host = createHost(Hypervisor.HypervisorType.XenServer);
    addStorageToHost(store, host);
    ZoneScope srcScope = new ZoneScope(dcId);
    DataStore srcStore = mock(DataStore.class);
    DataStore destStore = mock(DataStore.class);
    when(srcStore.getScope()).thenReturn(srcScope);
    when(srcStore.getRole()).thenReturn(DataStoreRole.Primary);
    when(srcStore.getId()).thenReturn(srcStoreId);
    when(destStore.getScope()).thenReturn(srcScope);
    when(destStore.getRole()).thenReturn(DataStoreRole.Image);
    when(destStore.getId()).thenReturn(destStoreId);
    DataObject srcObj = mock(DataObject.class);
    DataObject destObj = mock(DataObject.class);
    when(srcObj.getDataStore()).thenReturn(srcStore);
    when(destObj.getDataStore()).thenReturn(destStore);
    EndPoint ep = endPointSelector.select(srcObj, destObj);
    Assert.assertTrue(ep != null);
    Long hostId = ep.getId();
    HostVO newHost = hostDao.findById(hostId);
    Assert.assertTrue(newHost.getHypervisorType() == Hypervisor.HypervisorType.VMware);
    when(srcStore.getRole()).thenReturn(DataStoreRole.Image);
    when(srcStore.getId()).thenReturn(destStoreId);
    when(destStore.getId()).thenReturn(srcStoreId);
    when(destStore.getRole()).thenReturn(DataStoreRole.Primary);
    ep = endPointSelector.select(srcObj, destObj);
    Assert.assertTrue(ep != null);
    hostId = ep.getId();
    newHost = hostDao.findById(hostId);
    Assert.assertTrue(newHost.getHypervisorType() == Hypervisor.HypervisorType.VMware);
    ClusterScope clusterScope = new ClusterScope(clusterId, podId, dcId);
    when(srcStore.getRole()).thenReturn(DataStoreRole.Primary);
    when(srcStore.getScope()).thenReturn(clusterScope);
    when(srcStore.getId()).thenReturn(xenStoreId);
    ep = endPointSelector.select(srcStore);
    Assert.assertTrue(ep != null);
    newHost = hostDao.findById(ep.getId());
    Assert.assertTrue(newHost.getHypervisorType() == Hypervisor.HypervisorType.XenServer);
}
Also used : ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) HostVO(com.cloud.host.HostVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) Test(org.junit.Test)

Example 7 with EndPoint

use of org.apache.cloudstack.engine.subsystem.api.storage.EndPoint in project cloudstack by apache.

the class AncientDataMotionStrategy method copyObject.

protected Answer copyObject(DataObject srcData, DataObject destData, Host destHost) {
    String value = configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
    int _primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
    Answer answer = null;
    DataObject cacheData = null;
    DataObject srcForCopy = srcData;
    try {
        if (needCacheStorage(srcData, destData)) {
            Scope destScope = pickCacheScopeForCopy(srcData, destData);
            srcForCopy = cacheData = cacheMgr.createCacheObject(srcData, destScope);
        }
        CopyCommand cmd = new CopyCommand(srcForCopy.getTO(), addFullCloneFlagOnVMwareDest(destData.getTO()), _primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
        EndPoint ep = destHost != null ? RemoteHostEndPoint.getHypervisorHostEndPoint(destHost) : selector.select(srcForCopy, destData);
        if (ep == null) {
            String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
            s_logger.error(errMsg);
            answer = new Answer(cmd, false, errMsg);
        } else {
            answer = ep.sendMessage(cmd);
        }
        if (cacheData != null) {
            final Long cacheId = cacheData.getId();
            final String cacheType = cacheData.getType().toString();
            final String cacheUuid = cacheData.getUuid().toString();
            if (srcData.getType() == DataObjectType.VOLUME && (destData.getType() == DataObjectType.VOLUME || destData.getType() == DataObjectType.TEMPLATE)) {
                // volume transfer from primary to secondary. Volume transfer between primary pools are already handled by copyVolumeBetweenPools
                // Delete cache in order to certainly transfer a latest image.
                s_logger.debug("Delete " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")");
                cacheMgr.deleteCacheObject(srcForCopy);
            } else {
                // for template, we want to leave it on cache for performance reason
                if ((answer == null || !answer.getResult()) && srcForCopy.getRefCount() < 2) {
                    // cache object created by this copy, not already there
                    s_logger.warn("Copy may not be handled correctly by agent(id: " + (ep != null ? ep.getId() : "\"unspecified\"") + ")." + " Delete " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")");
                    cacheMgr.deleteCacheObject(srcForCopy);
                } else {
                    s_logger.debug("Decrease reference count of " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")");
                    cacheMgr.releaseCacheObject(srcForCopy);
                }
            }
        }
        return answer;
    } catch (Exception e) {
        s_logger.debug("copy object failed: ", e);
        if (cacheData != null) {
            cacheMgr.deleteCacheObject(cacheData);
        }
        throw new CloudRuntimeException(e.toString());
    }
}
Also used : Answer(com.cloud.agent.api.Answer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) Scope(org.apache.cloudstack.engine.subsystem.api.storage.Scope) HostScope(org.apache.cloudstack.engine.subsystem.api.storage.HostScope) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 8 with EndPoint

use of org.apache.cloudstack.engine.subsystem.api.storage.EndPoint in project cloudstack by apache.

the class AncientDataMotionStrategy method copyVolumeFromSnapshot.

protected Answer copyVolumeFromSnapshot(DataObject snapObj, DataObject volObj) {
    SnapshotInfo snapshot = (SnapshotInfo) snapObj;
    StoragePool pool = (StoragePool) volObj.getDataStore();
    String basicErrMsg = "Failed to create volume from " + snapshot.getName() + " on pool " + pool;
    DataStore store = snapObj.getDataStore();
    DataStoreTO storTO = store.getTO();
    DataObject srcData = snapObj;
    try {
        if (!(storTO instanceof NfsTO)) {
            // cache snapshot to zone-wide staging store for the volume to be created
            srcData = cacheSnapshotChain(snapshot, new ZoneScope(pool.getDataCenterId()));
        }
        String value = configDao.getValue(Config.CreateVolumeFromSnapshotWait.toString());
        int _createVolumeFromSnapshotWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CreateVolumeFromSnapshotWait.getDefaultValue()));
        EndPoint ep = null;
        if (srcData.getDataStore().getRole() == DataStoreRole.Primary) {
            ep = selector.select(volObj);
        } else {
            ep = selector.select(srcData, volObj);
        }
        CopyCommand cmd = new CopyCommand(srcData.getTO(), addFullCloneFlagOnVMwareDest(volObj.getTO()), _createVolumeFromSnapshotWait, VirtualMachineManager.ExecuteInSequence.value());
        Answer answer = null;
        if (ep == null) {
            String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
            s_logger.error(errMsg);
            answer = new Answer(cmd, false, errMsg);
        } else {
            answer = ep.sendMessage(cmd);
        }
        return answer;
    } catch (Exception e) {
        s_logger.error(basicErrMsg, e);
        throw new CloudRuntimeException(basicErrMsg);
    } finally {
        if (!(storTO instanceof NfsTO)) {
            // still keep snapshot on cache which may be migrated from previous secondary storage
            releaseSnapshotCacheChain((SnapshotInfo) srcData);
        }
    }
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) StoragePool(com.cloud.storage.StoragePool) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) NfsTO(com.cloud.agent.api.to.NfsTO) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) Answer(com.cloud.agent.api.Answer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore)

Example 9 with EndPoint

use of org.apache.cloudstack.engine.subsystem.api.storage.EndPoint in project cloudstack by apache.

the class TemplateServiceImpl method generateCopyUrl.

private String generateCopyUrl(TemplateInfo srcTemplate) {
    DataStore srcStore = srcTemplate.getDataStore();
    EndPoint ep = _epSelector.select(srcTemplate);
    if (ep != null) {
        if (ep.getPublicAddr() == null) {
            s_logger.warn("A running secondary storage vm has a null public ip?");
            return null;
        }
        return generateCopyUrl(ep.getPublicAddr(), ((ImageStoreEntity) srcStore).getMountPoint(), srcTemplate.getInstallPath());
    }
    VMTemplateVO tmplt = _templateDao.findById(srcTemplate.getId());
    HypervisorType hyperType = tmplt.getHypervisorType();
    /*No secondary storage vm yet*/
    if (hyperType != null && hyperType == HypervisorType.KVM) {
        return "file://" + ((ImageStoreEntity) srcStore).getMountPoint() + "/" + srcTemplate.getInstallPath();
    }
    return null;
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)

Example 10 with EndPoint

use of org.apache.cloudstack.engine.subsystem.api.storage.EndPoint in project cloudstack by apache.

the class AncientDataMotionStrategy method copyVolumeBetweenPools.

protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData) {
    String value = configDao.getValue(Config.CopyVolumeWait.key());
    int _copyvolumewait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CopyVolumeWait.getDefaultValue()));
    Scope destScope = getZoneScope(destData.getDataStore().getScope());
    DataStore cacheStore = cacheMgr.getCacheStorage(destScope);
    if (cacheStore == null) {
        // need to find a nfs or cifs image store, assuming that can't copy volume
        // directly to s3
        ImageStoreEntity imageStore = (ImageStoreEntity) dataStoreMgr.getImageStore(destScope.getScopeId());
        if (!imageStore.getProtocol().equalsIgnoreCase("nfs") && !imageStore.getProtocol().equalsIgnoreCase("cifs")) {
            s_logger.debug("can't find a nfs (or cifs) image store to satisfy the need for a staging store");
            return null;
        }
        DataObject objOnImageStore = imageStore.create(srcData);
        objOnImageStore.processEvent(Event.CreateOnlyRequested);
        Answer answer = copyObject(srcData, objOnImageStore);
        if (answer == null || !answer.getResult()) {
            if (answer != null) {
                s_logger.debug("copy to image store failed: " + answer.getDetails());
            }
            objOnImageStore.processEvent(Event.OperationFailed);
            imageStore.delete(objOnImageStore);
            return answer;
        }
        objOnImageStore.processEvent(Event.OperationSuccessed, answer);
        objOnImageStore.processEvent(Event.CopyingRequested);
        CopyCommand cmd = new CopyCommand(objOnImageStore.getTO(), addFullCloneFlagOnVMwareDest(destData.getTO()), _copyvolumewait, VirtualMachineManager.ExecuteInSequence.value());
        EndPoint ep = selector.select(objOnImageStore, destData);
        if (ep == null) {
            String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
            s_logger.error(errMsg);
            answer = new Answer(cmd, false, errMsg);
        } else {
            answer = ep.sendMessage(cmd);
        }
        if (answer == null || !answer.getResult()) {
            if (answer != null) {
                s_logger.debug("copy to primary store failed: " + answer.getDetails());
            }
            objOnImageStore.processEvent(Event.OperationFailed);
            imageStore.delete(objOnImageStore);
            return answer;
        }
        objOnImageStore.processEvent(Event.OperationSuccessed);
        imageStore.delete(objOnImageStore);
        return answer;
    } else {
        DataObject cacheData = cacheMgr.createCacheObject(srcData, destScope);
        CopyCommand cmd = new CopyCommand(cacheData.getTO(), destData.getTO(), _copyvolumewait, VirtualMachineManager.ExecuteInSequence.value());
        EndPoint ep = selector.select(cacheData, destData);
        Answer answer = null;
        if (ep == null) {
            String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
            s_logger.error(errMsg);
            answer = new Answer(cmd, false, errMsg);
        } else {
            answer = ep.sendMessage(cmd);
        }
        // delete volume on cache store
        if (cacheData != null) {
            cacheMgr.deleteCacheObject(cacheData);
        }
        return answer;
    }
}
Also used : Answer(com.cloud.agent.api.Answer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) Scope(org.apache.cloudstack.engine.subsystem.api.storage.Scope) HostScope(org.apache.cloudstack.engine.subsystem.api.storage.HostScope) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ImageStoreEntity(org.apache.cloudstack.storage.image.datastore.ImageStoreEntity) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint)

Aggregations

EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)44 Answer (com.cloud.agent.api.Answer)28 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)22 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)17 RemoteHostEndPoint (org.apache.cloudstack.storage.RemoteHostEndPoint)13 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)10 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)9 Date (java.util.Date)8 CopyCommand (org.apache.cloudstack.storage.command.CopyCommand)8 MigrateVolumeAnswer (com.cloud.agent.api.storage.MigrateVolumeAnswer)7 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)6 ResizeVolumeAnswer (com.cloud.agent.api.storage.ResizeVolumeAnswer)5 HostVO (com.cloud.host.HostVO)5 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)5 UploadVO (com.cloud.storage.UploadVO)4 URISyntaxException (java.net.URISyntaxException)4 ClusterScope (org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope)4 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)4 VolumeDataStoreVO (org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)4 CreateEntityDownloadURLCommand (com.cloud.agent.api.storage.CreateEntityDownloadURLCommand)3