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);
}
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);
}
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);
}
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());
}
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);
}
Aggregations