Search in sources :

Example 71 with NfsTO

use of com.cloud.agent.api.to.NfsTO in project cosmic by MissionCriticalCloud.

the class CloudStackImageStoreDriverImpl method getStoreTO.

@Override
public DataStoreTO getStoreTO(final DataStore store) {
    final ImageStoreImpl nfsStore = (ImageStoreImpl) store;
    final NfsTO nfsTO = new NfsTO();
    nfsTO.setRole(store.getRole());
    nfsTO.setUrl(nfsStore.getUri());
    return nfsTO;
}
Also used : ImageStoreImpl(com.cloud.storage.image.store.ImageStoreImpl) NfsTO(com.cloud.agent.api.to.NfsTO)

Example 72 with NfsTO

use of com.cloud.agent.api.to.NfsTO in project cloudstack by apache.

the class RequestTest method testSerDeserTO.

public void testSerDeserTO() {
    s_logger.info("Testing serializing and deserializing interface TO works as expected");
    NfsTO nfs = new NfsTO("nfs://192.168.56.10/opt/storage/secondary", DataStoreRole.Image);
    // SecStorageSetupCommand cmd = new SecStorageSetupCommand(nfs, "nfs://192.168.56.10/opt/storage/secondary", null);
    ListTemplateCommand cmd = new ListTemplateCommand(nfs);
    Request sreq = new Request(2, 3, cmd, true);
    sreq.setSequence(892403718);
    byte[] bytes = sreq.getBytes();
    assert Request.getSequence(bytes) == 892403718;
    assert Request.getManagementServerId(bytes) == 3;
    assert Request.getAgentId(bytes) == 2;
    assert Request.getViaAgentId(bytes) == 2;
    Request creq = null;
    try {
        creq = Request.parse(bytes);
    } catch (ClassNotFoundException e) {
        s_logger.error("Unable to parse bytes: ", e);
    } catch (UnsupportedVersionException e) {
        s_logger.error("Unable to parse bytes: ", e);
    }
    assert creq != null : "Couldn't get the request back";
    compareRequest(creq, sreq);
    assertEquals("nfs://192.168.56.10/opt/storage/secondary", ((NfsTO) ((ListTemplateCommand) creq.getCommand()).getDataStore()).getUrl());
}
Also used : ListTemplateCommand(com.cloud.agent.api.storage.ListTemplateCommand) NfsTO(com.cloud.agent.api.to.NfsTO) UnsupportedVersionException(com.cloud.exception.UnsupportedVersionException)

Example 73 with NfsTO

use of com.cloud.agent.api.to.NfsTO in project cloudstack by apache.

the class RequestTest method testDownload.

public void testDownload() {
    s_logger.info("Testing Download answer");
    VirtualMachineTemplate template = Mockito.mock(VirtualMachineTemplate.class);
    Mockito.when(template.getId()).thenReturn(1L);
    Mockito.when(template.getFormat()).thenReturn(ImageFormat.QCOW2);
    Mockito.when(template.getName()).thenReturn("templatename");
    Mockito.when(template.getTemplateType()).thenReturn(TemplateType.USER);
    Mockito.when(template.getDisplayText()).thenReturn("displayText");
    Mockito.when(template.getHypervisorType()).thenReturn(HypervisorType.KVM);
    Mockito.when(template.getUrl()).thenReturn("url");
    NfsTO nfs = new NfsTO("secUrl", DataStoreRole.Image);
    TemplateObjectTO to = new TemplateObjectTO(template);
    to.setImageDataStore(nfs);
    DownloadCommand cmd = new DownloadCommand(to, 30000000l);
    Request req = new Request(1, 1, cmd, true);
    req.logD("Debug for Download");
    DownloadAnswer answer = new DownloadAnswer("jobId", 50, "errorString", Status.ABANDONED, "filesystempath", "installpath", 10000000, 20000000, "chksum");
    Response resp = new Response(req, answer);
    resp.logD("Debug for Download");
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) DownloadCommand(org.apache.cloudstack.storage.command.DownloadCommand) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) NfsTO(com.cloud.agent.api.to.NfsTO)

Example 74 with NfsTO

use of com.cloud.agent.api.to.NfsTO in project cloudstack by apache.

the class VmwareStorageManagerImpl method createOvaForVolume.

//Fang: new command added;
// Important! we need to sync file system before we can safely use tar to work around a linux kernal bug(or feature)
public String createOvaForVolume(VolumeObjectTO volume) {
    DataStoreTO storeTO = volume.getDataStore();
    if (!(storeTO instanceof NfsTO)) {
        s_logger.debug("can only handle nfs storage, when create ova from volume");
        return null;
    }
    NfsTO nfsStore = (NfsTO) storeTO;
    String secStorageUrl = nfsStore.getUrl();
    assert (secStorageUrl != null);
    //Note the volume path is volumes/accountId/volumeId/uuid/, the actual volume is uuid/uuid.vmdk
    String installPath = volume.getPath();
    int index = installPath.lastIndexOf(File.separator);
    String volumeUuid = installPath.substring(index + 1);
    String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, _nfsVersion);
    //The real volume path
    String volumePath = installPath + File.separator + volumeUuid + ".ova";
    String installFullPath = secondaryMountPoint + "/" + installPath;
    try {
        if (new File(secondaryMountPoint + File.separator + volumePath).exists()) {
            s_logger.debug("ova already exists:" + volumePath);
            return volumePath;
        } else {
            Script commandSync = new Script(true, "sync", 0, s_logger);
            commandSync.execute();
            Script command = new Script(false, "tar", 0, s_logger);
            command.setWorkDir(installFullPath);
            command.add("-cf", volumeUuid + ".ova");
            // OVF file should be the first file in OVA archive
            command.add(volumeUuid + ".ovf");
            command.add(volumeUuid + "-disk0.vmdk");
            command.execute();
            return volumePath;
        }
    } catch (Throwable e) {
        s_logger.info("Exception for createVolumeOVA");
    }
    return null;
}
Also used : Script(com.cloud.utils.script.Script) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) NfsTO(com.cloud.agent.api.to.NfsTO) File(java.io.File)

Example 75 with NfsTO

use of com.cloud.agent.api.to.NfsTO in project cloudstack by apache.

the class TemplateManagerImpl method prepareIso.

// for ISO, we need to consider whether to copy to cache storage or not if it is not on NFS, since our hypervisor resource always assumes that they are in NFS
@Override
public TemplateInfo prepareIso(long isoId, long dcId) {
    TemplateInfo tmplt = _tmplFactory.getTemplate(isoId, DataStoreRole.Image, dcId);
    if (tmplt == null || tmplt.getFormat() != ImageFormat.ISO) {
        s_logger.warn("ISO: " + isoId + " does not exist in vm_template table");
        return null;
    }
    if (tmplt.getDataStore() != null && !(tmplt.getDataStore().getTO() instanceof NfsTO)) {
        // if it is s3, need to download into cache storage first
        Scope destScope = new ZoneScope(dcId);
        TemplateInfo cacheData = (TemplateInfo) cacheMgr.createCacheObject(tmplt, destScope);
        if (cacheData == null) {
            s_logger.error("Failed in copy iso from S3 to cache storage");
            return null;
        }
        return cacheData;
    } else {
        return tmplt;
    }
}
Also used : ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) Scope(org.apache.cloudstack.engine.subsystem.api.storage.Scope) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) PublishScope(org.apache.cloudstack.framework.messagebus.PublishScope) NfsTO(com.cloud.agent.api.to.NfsTO)

Aggregations

NfsTO (com.cloud.agent.api.to.NfsTO)142 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)110 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)79 DataTO (com.cloud.agent.api.to.DataTO)71 InternalErrorException (com.cloud.exception.InternalErrorException)58 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)52 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)39 TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)38 XmlRpcException (org.apache.xmlrpc.XmlRpcException)37 XenAPIException (com.xensource.xenapi.Types.XenAPIException)36 URI (java.net.URI)36 Connection (com.xensource.xenapi.Connection)34 SR (com.xensource.xenapi.SR)34 VDI (com.xensource.xenapi.VDI)34 CopyCmdAnswer (com.cloud.storage.command.CopyCmdAnswer)32 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)32 Answer (com.cloud.agent.api.Answer)29 IOException (java.io.IOException)28 File (java.io.File)27 PrimaryDataStoreTO (com.cloud.storage.to.PrimaryDataStoreTO)26