Search in sources :

Example 1 with CreateObjectCommand

use of org.apache.cloudstack.storage.command.CreateObjectCommand in project cloudstack by apache.

the class CloudStackPrimaryDataStoreDriverImpl method takeSnapshot.

@Override
public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CreateCmdResult> callback) {
    CreateCmdResult result = null;
    try {
        SnapshotObjectTO snapshotTO = (SnapshotObjectTO) snapshot.getTO();
        Object payload = snapshot.getPayload();
        if (payload != null && payload instanceof CreateSnapshotPayload) {
            CreateSnapshotPayload snapshotPayload = (CreateSnapshotPayload) payload;
            snapshotTO.setQuiescevm(snapshotPayload.getQuiescevm());
        }
        CreateObjectCommand cmd = new CreateObjectCommand(snapshotTO);
        EndPoint ep = epSelector.select(snapshot, StorageAction.TAKESNAPSHOT);
        Answer answer = null;
        if (ep == null) {
            String errMsg = "No remote endpoint to send createObjectCommand, check if host or ssvm is down?";
            s_logger.error(errMsg);
            answer = new Answer(cmd, false, errMsg);
        } else {
            answer = ep.sendMessage(cmd);
        }
        result = new CreateCmdResult(null, answer);
        if (answer != null && !answer.getResult()) {
            result.setResult(answer.getDetails());
        }
        callback.complete(result);
        return;
    } catch (Exception e) {
        s_logger.debug("Failed to take snapshot: " + snapshot.getId(), e);
        result = new CreateCmdResult(null, null);
        result.setResult(e.toString());
    }
    callback.complete(result);
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) CreateSnapshotPayload(com.cloud.storage.CreateSnapshotPayload) VolumeObject(org.apache.cloudstack.storage.volume.VolumeObject) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) CreateObjectCommand(org.apache.cloudstack.storage.command.CreateObjectCommand) StorageUnavailableException(com.cloud.exception.StorageUnavailableException)

Example 2 with CreateObjectCommand

use of org.apache.cloudstack.storage.command.CreateObjectCommand in project cloudstack by apache.

the class Ovm3StorageProcessorTest method createTemplateObjectCommandTest.

/*
     * unused ?
     *
     * @Test
     * public void createCommandTest() throws ConfigurationException {
     * con = prepare();
     * DiskProfile disk = diskProfile();
     * String templateUrl = null;
     * StoragePoolVO poolio = new StoragePoolVO();
     * poolio.setPath(linux.getTemplatesDir());
     * poolio.setHostAddress(linux.getRemoteHost());
     *
     * CreateCommand create = new CreateCommand(disk, templateUrl, poolio ,
     * false);
     * Answer ra = hypervisor.executeRequest(create);
     * results.basicBooleanTest(ra.getResult());
     * }
     */
@Test
public void createTemplateObjectCommandTest() throws ConfigurationException {
    con = prepare();
    String tempuuid = ovmObject.newUuid();
    TemplateObjectTO template = template(tempuuid, ovmObject.newUuid(), ovmObject.newUuid(linux.getRemote()), linux.getRemote());
    template.setSize(storageplugin.getFileSize());
    String response = storageplugin.getFileCreateXml().replace(storageplugin.getFileName(), tempuuid + ".raw");
    response = response.replace(storageplugin.getPoolUuid(), ovmObject.deDash(linux.getRepoId()));
    con.setMethodResponse("storage_plugin_create", results.simpleResponseWrapWrapper(response));
    CreateObjectCommand create = new CreateObjectCommand(template);
    Answer ra = hypervisor.executeRequest(create);
    results.basicBooleanTest(ra.getResult(), false);
}
Also used : Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) CreateObjectCommand(org.apache.cloudstack.storage.command.CreateObjectCommand) ConnectionTest(com.cloud.hypervisor.ovm3.objects.ConnectionTest) LinuxTest(com.cloud.hypervisor.ovm3.objects.LinuxTest) Test(org.junit.Test) XenTest(com.cloud.hypervisor.ovm3.objects.XenTest) StoragePluginTest(com.cloud.hypervisor.ovm3.objects.StoragePluginTest) Ovm3SupportTest(com.cloud.hypervisor.ovm3.support.Ovm3SupportTest) XmlTestResultTest(com.cloud.hypervisor.ovm3.objects.XmlTestResultTest) Ovm3ConfigurationTest(com.cloud.hypervisor.ovm3.resources.helpers.Ovm3ConfigurationTest)

Example 3 with CreateObjectCommand

use of org.apache.cloudstack.storage.command.CreateObjectCommand in project cloudstack by apache.

the class Ovm3StorageProcessorTest method createSnapshotObjectCommandTest.

@Test
public void createSnapshotObjectCommandTest() throws ConfigurationException {
    con = prepare();
    String snapuuid = ovmObject.newUuid();
    SnapshotObjectTO snap = snapshot(snapuuid, linux.getRepoId(), "", linux.getVirtualDisksDir());
    String response = storageplugin.getFileCreateXml().replace(storageplugin.getFileName(), snapuuid + ".raw");
    response = response.replace(storageplugin.getPoolUuid(), ovmObject.deDash(linux.getRepoId()));
    con.setMethodResponse("storage_plugin_create", results.simpleResponseWrapWrapper(response));
    CreateObjectCommand create = new CreateObjectCommand(snap);
    Answer ra = hypervisor.executeRequest(create);
    results.basicBooleanTest(ra.getResult(), false);
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) CreateObjectCommand(org.apache.cloudstack.storage.command.CreateObjectCommand) ConnectionTest(com.cloud.hypervisor.ovm3.objects.ConnectionTest) LinuxTest(com.cloud.hypervisor.ovm3.objects.LinuxTest) Test(org.junit.Test) XenTest(com.cloud.hypervisor.ovm3.objects.XenTest) StoragePluginTest(com.cloud.hypervisor.ovm3.objects.StoragePluginTest) Ovm3SupportTest(com.cloud.hypervisor.ovm3.support.Ovm3SupportTest) XmlTestResultTest(com.cloud.hypervisor.ovm3.objects.XmlTestResultTest) Ovm3ConfigurationTest(com.cloud.hypervisor.ovm3.resources.helpers.Ovm3ConfigurationTest)

Example 4 with CreateObjectCommand

use of org.apache.cloudstack.storage.command.CreateObjectCommand in project cloudstack by apache.

the class Ovm3StorageProcessorTest method createVolumeObjectCommandTest.

@Test
public void createVolumeObjectCommandTest() throws ConfigurationException {
    con = prepare();
    String voluuid = ovmObject.newUuid();
    VolumeObjectTO vol = volume(voluuid, linux.getRepoId(), "", linux.getVirtualDisksDir());
    vol.setSize(storageplugin.getFileSize());
    String response = storageplugin.getFileCreateXml().replace(storageplugin.getFileName(), voluuid + ".raw");
    response = response.replace(storageplugin.getPoolUuid(), ovmObject.deDash(linux.getRepoId()));
    con.setMethodResponse("storage_plugin_create", results.simpleResponseWrapWrapper(response));
    CreateObjectCommand create = new CreateObjectCommand(vol);
    Answer ra = hypervisor.executeRequest(create);
    results.basicBooleanTest(ra.getResult());
}
Also used : Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) CreateObjectCommand(org.apache.cloudstack.storage.command.CreateObjectCommand) ConnectionTest(com.cloud.hypervisor.ovm3.objects.ConnectionTest) LinuxTest(com.cloud.hypervisor.ovm3.objects.LinuxTest) Test(org.junit.Test) XenTest(com.cloud.hypervisor.ovm3.objects.XenTest) StoragePluginTest(com.cloud.hypervisor.ovm3.objects.StoragePluginTest) Ovm3SupportTest(com.cloud.hypervisor.ovm3.support.Ovm3SupportTest) XmlTestResultTest(com.cloud.hypervisor.ovm3.objects.XmlTestResultTest) Ovm3ConfigurationTest(com.cloud.hypervisor.ovm3.resources.helpers.Ovm3ConfigurationTest)

Example 5 with CreateObjectCommand

use of org.apache.cloudstack.storage.command.CreateObjectCommand in project cloudstack by apache.

the class SamplePrimaryDataStoreDriverImpl method createAsync.

/*
     * private class CreateVolumeFromBaseImageContext<T> extends
     * AsyncRpcContext<T> { private final VolumeObject volume;
     *
     * public CreateVolumeFromBaseImageContext(AsyncCompletionCallback<T>
     * callback, VolumeObject volume) { super(callback); this.volume = volume; }
     *
     * public VolumeObject getVolume() { return this.volume; }
     *
     * }
     *
     * @Override public void createVolumeFromBaseImageAsync(VolumeObject volume,
     * TemplateInfo template, AsyncCompletionCallback<CommandResult> callback) {
     * VolumeTO vol = this.dataStore.getVolumeTO(volume); List<EndPoint>
     * endPoints = this.dataStore.getEndPoints(); EndPoint ep =
     * endPoints.get(0); String templateUri =
     * template.getDataStore().grantAccess(template, ep);
     * CreateVolumeFromBaseImageCommand cmd = new
     * CreateVolumeFromBaseImageCommand(vol, templateUri);
     *
     * CreateVolumeFromBaseImageContext<CommandResult> context = new
     * CreateVolumeFromBaseImageContext<CommandResult>(callback, volume);
     * AsyncCallbackDispatcher<DefaultPrimaryDataStoreDriverImpl, Answer> caller
     * = AsyncCallbackDispatcher.create(this); caller.setContext(context)
     * .setCallback
     * (caller.getTarget().createVolumeFromBaseImageAsyncCallback(null, null));
     *
     * ep.sendMessageAsync(cmd, caller); }
     */
/*
     * public Object
     * createVolumeFromBaseImageAsyncCallback(AsyncCallbackDispatcher
     * <DefaultPrimaryDataStoreDriverImpl, Answer> callback,
     * CreateVolumeFromBaseImageContext<CommandResult> context) {
     * CreateVolumeAnswer answer = (CreateVolumeAnswer)callback.getResult();
     * CommandResult result = new CommandResult(); if (answer == null ||
     * answer.getDetails() != null) { result.setSuccess(false); if (answer !=
     * null) { result.setResult(answer.getDetails()); } } else {
     * result.setSuccess(true); VolumeObject volume = context.getVolume();
     * volume.setPath(answer.getVolumeUuid()); }
     * AsyncCompletionCallback<CommandResult> parentCall =
     * context.getParentCallback(); parentCall.complete(result); return null; }
     */
@Override
public void createAsync(DataStore dataStore, DataObject vol, AsyncCompletionCallback<CreateCmdResult> callback) {
    EndPoint ep = selector.select(vol);
    if (ep == null) {
        String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
        s_logger.error(errMsg);
        throw new CloudRuntimeException(errMsg);
    }
    CreateObjectCommand createCmd = new CreateObjectCommand(null);
    CreateVolumeContext<CreateCmdResult> context = new CreateVolumeContext<CreateCmdResult>(callback, vol);
    AsyncCallbackDispatcher<SamplePrimaryDataStoreDriverImpl, Answer> caller = AsyncCallbackDispatcher.create(this);
    caller.setContext(context).setCallback(caller.getTarget().createAsyncCallback(null, null));
    ep.sendMessageAsync(createCmd, caller);
}
Also used : Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) CreateObjectCommand(org.apache.cloudstack.storage.command.CreateObjectCommand)

Aggregations

Answer (com.cloud.agent.api.Answer)6 CreateObjectCommand (org.apache.cloudstack.storage.command.CreateObjectCommand)6 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)5 ConnectionTest (com.cloud.hypervisor.ovm3.objects.ConnectionTest)3 LinuxTest (com.cloud.hypervisor.ovm3.objects.LinuxTest)3 StoragePluginTest (com.cloud.hypervisor.ovm3.objects.StoragePluginTest)3 XenTest (com.cloud.hypervisor.ovm3.objects.XenTest)3 XmlTestResultTest (com.cloud.hypervisor.ovm3.objects.XmlTestResultTest)3 Ovm3ConfigurationTest (com.cloud.hypervisor.ovm3.resources.helpers.Ovm3ConfigurationTest)3 Ovm3SupportTest (com.cloud.hypervisor.ovm3.support.Ovm3SupportTest)3 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)3 Test (org.junit.Test)3 ResizeVolumeAnswer (com.cloud.agent.api.storage.ResizeVolumeAnswer)2 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)2 SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)2 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)1 CreateSnapshotPayload (com.cloud.storage.CreateSnapshotPayload)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)1 TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)1