mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
bug 10281: Template/ISO APIs should throw an exception in failure case for the events to be registered as failure.
Reviewed by : Kishan. status 10281: resolved fixed
This commit is contained in:
parent
57aa7dec91
commit
ec3a00a230
@ -32,6 +32,7 @@ import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.InternalErrorException;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
|
||||
@Implementation(description="Extracts an ISO", responseObject=ExtractResponse.class)
|
||||
public class ExtractIsoCmd extends BaseAsyncCmd {
|
||||
@ -103,7 +104,7 @@ public class ExtractIsoCmd extends BaseAsyncCmd {
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "Extraction job";
|
||||
return "extracting iso: " + getId() + " from zone: " + getZoneId();
|
||||
}
|
||||
|
||||
public static String getStaticName() {
|
||||
@ -121,6 +122,7 @@ public class ExtractIsoCmd extends BaseAsyncCmd {
|
||||
@Override
|
||||
public void execute(){
|
||||
try {
|
||||
UserContext.current().setEventDetails(getEventDescription());
|
||||
Long uploadId = _templateService.extract(this);
|
||||
if (uploadId != null){
|
||||
ExtractResponse response = _responseGenerator.createExtractResponse(uploadId, id, zoneId, getEntityOwnerId(), mode);
|
||||
|
||||
@ -32,6 +32,7 @@ import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.InternalErrorException;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
|
||||
@Implementation(description="Extracts a template", responseObject=ExtractResponse.class)
|
||||
public class ExtractTemplateCmd extends BaseAsyncCmd {
|
||||
@ -108,7 +109,7 @@ public class ExtractTemplateCmd extends BaseAsyncCmd {
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "Extraction job";
|
||||
return "extracting template: " + getId() + " from zone: " + getZoneId();
|
||||
}
|
||||
|
||||
public AsyncJob.Type getInstanceType() {
|
||||
@ -122,6 +123,7 @@ public class ExtractTemplateCmd extends BaseAsyncCmd {
|
||||
@Override
|
||||
public void execute(){
|
||||
try {
|
||||
UserContext.current().setEventDetails(getEventDescription());
|
||||
Long uploadId = _templateService.extract(this);
|
||||
if (uploadId != null){
|
||||
ExtractResponse response = _responseGenerator.createExtractResponse(uploadId, id, zoneId, getEntityOwnerId(), mode);
|
||||
|
||||
@ -215,8 +215,14 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
@ActionEvent(eventType = EventTypes.EVENT_ISO_CREATE, eventDescription = "creating iso")
|
||||
public VirtualMachineTemplate registerIso(RegisterIsoCmd cmd) throws ResourceAllocationException{
|
||||
TemplateAdapter adapter = getAdapter(HypervisorType.None);
|
||||
TemplateProfile profile = adapter.prepare(cmd);
|
||||
return adapter.create(profile);
|
||||
TemplateProfile profile = adapter.prepare(cmd);
|
||||
VMTemplateVO template = adapter.create(profile);
|
||||
|
||||
if (template != null){
|
||||
return template;
|
||||
}else {
|
||||
throw new CloudRuntimeException("Failed to create ISO");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -230,10 +236,17 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
}
|
||||
TemplateAdapter adapter = getAdapter(HypervisorType.getType(cmd.getHypervisor()));
|
||||
TemplateProfile profile = adapter.prepare(cmd);
|
||||
return adapter.create(profile);
|
||||
VMTemplateVO template = adapter.create(profile);
|
||||
|
||||
if (template != null){
|
||||
return template;
|
||||
}else {
|
||||
throw new CloudRuntimeException("Failed to create a template");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_ISO_EXTRACT, eventDescription = "extracting ISO", async = true)
|
||||
public Long extract(ExtractIsoCmd cmd) {
|
||||
Account account = UserContext.current().getCaller();
|
||||
Long templateId = cmd.getId();
|
||||
@ -243,10 +256,16 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
Long eventId = cmd.getStartEventId();
|
||||
|
||||
// FIXME: async job needs fixing
|
||||
return extract(account, templateId, url, zoneId, mode, eventId, true, null, _asyncMgr);
|
||||
Long uploadId = extract(account, templateId, url, zoneId, mode, eventId, true, null, _asyncMgr);
|
||||
if (uploadId != null){
|
||||
return uploadId;
|
||||
}else {
|
||||
throw new CloudRuntimeException("Failed to extract the iso");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_EXTRACT, eventDescription = "extracting template", async = true)
|
||||
public Long extract(ExtractTemplateCmd cmd) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
Long templateId = cmd.getId();
|
||||
@ -256,7 +275,12 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
Long eventId = cmd.getStartEventId();
|
||||
|
||||
// FIXME: async job needs fixing
|
||||
return extract(caller, templateId, url, zoneId, mode, eventId, false, null, _asyncMgr);
|
||||
Long uploadId = extract(caller, templateId, url, zoneId, mode, eventId, false, null, _asyncMgr);
|
||||
if (uploadId != null){
|
||||
return uploadId;
|
||||
}else {
|
||||
throw new CloudRuntimeException("Failed to extract the teamplate");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -747,11 +771,11 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
|
||||
boolean success = copy(userId, template, srcSecHost, sourceZone, dstZone);
|
||||
|
||||
if (success) {
|
||||
return template;
|
||||
if (success){
|
||||
return template;
|
||||
}else {
|
||||
throw new CloudRuntimeException("Failed to copy template");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -988,7 +1012,12 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
throw new InvalidParameterValueException("Please specify a VM that is either Stopped or Running.");
|
||||
}
|
||||
|
||||
return attachISOToVM(vmId, userId, isoId, false); //attach=false => detach
|
||||
boolean result = attachISOToVM(vmId, userId, isoId, false); //attach=false => detach
|
||||
if (result){
|
||||
return result;
|
||||
}else {
|
||||
throw new CloudRuntimeException("Failed to detach iso");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1023,7 +1052,12 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
if("vmware-tools.iso".equals(iso.getName()) && vm.getHypervisorType() != Hypervisor.HypervisorType.VMware) {
|
||||
throw new InvalidParameterValueException("Cannot attach VMware tools drivers to incompatible hypervisor " + vm.getHypervisorType());
|
||||
}
|
||||
return attachISOToVM(vmId, userId, isoId, true);
|
||||
boolean result = attachISOToVM(vmId, userId, isoId, true);
|
||||
if (result){
|
||||
return result;
|
||||
}else {
|
||||
throw new CloudRuntimeException("Failed to attach iso");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean attachISOToVM(long vmId, long userId, long isoId, boolean attach) {
|
||||
@ -1060,7 +1094,13 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
}
|
||||
TemplateAdapter adapter = getAdapter(template.getHypervisorType());
|
||||
TemplateProfile profile = adapter.prepareDelete(cmd);
|
||||
return adapter.delete(profile);
|
||||
boolean result = adapter.delete(profile);
|
||||
|
||||
if (result){
|
||||
return true;
|
||||
}else{
|
||||
throw new CloudRuntimeException("Failed to delete template");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1086,7 +1126,12 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
}
|
||||
TemplateAdapter adapter = getAdapter(template.getHypervisorType());
|
||||
TemplateProfile profile = adapter.prepareDelete(cmd);
|
||||
return adapter.delete(profile);
|
||||
boolean result = adapter.delete(profile);
|
||||
if (result){
|
||||
return true;
|
||||
}else{
|
||||
throw new CloudRuntimeException("Failed to delete ISO");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1444,7 +1444,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
_resourceLimitMgr.incrementResourceCount(accountId, ResourceType.template);
|
||||
}
|
||||
|
||||
return template;
|
||||
if (template != null){
|
||||
return template;
|
||||
}else {
|
||||
throw new CloudRuntimeException("Failed to create a template");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1644,8 +1649,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
txn.commit();
|
||||
}
|
||||
}
|
||||
|
||||
return privateTemplate;
|
||||
|
||||
if (privateTemplate != null){
|
||||
return privateTemplate;
|
||||
}else {
|
||||
throw new CloudRuntimeException("Failed to create a template");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user