Updated Branches: refs/heads/4.1 27479d569 -> f900d0bc7
CLOUDSTACK-1330: ec2-run-instances - When -n option is used to deploy multiple Vms API returns error even though few of the Vms have been deployed successfully. Changes: - Instead of throwing out error, return the response containing the info about the instances that were launched. Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/f900d0bc Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/f900d0bc Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/f900d0bc Branch: refs/heads/4.1 Commit: f900d0bc71e8edded33f4e18f22153bfd258fbcd Parents: 378827e Author: Prachi Damle <[email protected]> Authored: Tue Feb 19 15:12:06 2013 -0800 Committer: Prachi Damle <[email protected]> Committed: Tue Feb 19 15:15:27 2013 -0800 ---------------------------------------------------------------------- .../cloud/bridge/service/core/ec2/EC2Engine.java | 72 ++++++++------- 1 files changed, 39 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/f900d0bc/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java ---------------------------------------------------------------------- diff --git a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java index 281ecbd..e92f845 100644 --- a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java +++ b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java @@ -1423,47 +1423,53 @@ public class EC2Engine extends ManagerBase { // now actually deploy the vms for( int i=0; i < createInstances; i++ ) { - CloudStackUserVm resp = getApi().deployVirtualMachine(svcOffering.getId(), - request.getTemplateId(), zoneId, null, null, null, null, - null, null, null, request.getKeyName(), null, (network != null ? network.getId() : null), - null, constructList(request.getGroupSet()), request.getSize().longValue(), request.getUserData()); - EC2Instance vm = new EC2Instance(); - vm.setId(resp.getId().toString()); - vm.setName(resp.getName()); - vm.setZoneName(resp.getZoneName()); - vm.setTemplateId(resp.getTemplateId().toString()); - if (resp.getSecurityGroupList() != null && resp.getSecurityGroupList().size() > 0) { - List<CloudStackSecurityGroup> securityGroupList = resp.getSecurityGroupList(); - for (CloudStackSecurityGroup securityGroup : securityGroupList) { - EC2SecurityGroup param = new EC2SecurityGroup(); - param.setId(securityGroup.getId()); - param.setName(securityGroup.getName()); - vm.addGroupName(param); + try{ + CloudStackUserVm resp = getApi().deployVirtualMachine(svcOffering.getId(), + request.getTemplateId(), zoneId, null, null, null, null, + null, null, null, request.getKeyName(), null, (network != null ? network.getId() : null), + null, constructList(request.getGroupSet()), request.getSize().longValue(), request.getUserData()); + EC2Instance vm = new EC2Instance(); + vm.setId(resp.getId().toString()); + vm.setName(resp.getName()); + vm.setZoneName(resp.getZoneName()); + vm.setTemplateId(resp.getTemplateId().toString()); + if (resp.getSecurityGroupList() != null && resp.getSecurityGroupList().size() > 0) { + List<CloudStackSecurityGroup> securityGroupList = resp.getSecurityGroupList(); + for (CloudStackSecurityGroup securityGroup : securityGroupList) { + EC2SecurityGroup param = new EC2SecurityGroup(); + param.setId(securityGroup.getId()); + param.setName(securityGroup.getName()); + vm.addGroupName(param); + } } - } - vm.setState(resp.getState()); - vm.setCreated(resp.getCreated()); - List <CloudStackNic> nicList = resp.getNics(); - for (CloudStackNic nic : nicList) { - if (nic.getIsDefault()) { - vm.setPrivateIpAddress(nic.getIpaddress()); - break; + vm.setState(resp.getState()); + vm.setCreated(resp.getCreated()); + List <CloudStackNic> nicList = resp.getNics(); + for (CloudStackNic nic : nicList) { + if (nic.getIsDefault()) { + vm.setPrivateIpAddress(nic.getIpaddress()); + break; + } } + vm.setIpAddress(resp.getIpAddress()); + vm.setAccountName(resp.getAccountName()); + vm.setDomainId(resp.getDomainId()); + vm.setHypervisor(resp.getHypervisor()); + vm.setServiceOffering( svcOffering.getName()); + vm.setKeyPairName(resp.getKeyPairName()); + instances.addInstance(vm); + countCreated++; + }catch(Exception e){ + logger.error("Failed to deploy VM number: "+ (i+1) +" due to error: "+e.getMessage()); + break; } - vm.setIpAddress(resp.getIpAddress()); - vm.setAccountName(resp.getAccountName()); - vm.setDomainId(resp.getDomainId()); - vm.setHypervisor(resp.getHypervisor()); - vm.setServiceOffering( svcOffering.getName()); - vm.setKeyPairName(resp.getKeyPairName()); - instances.addInstance(vm); - countCreated++; } if (0 == countCreated) { // TODO, we actually need to destroy left-over VMs when the exception is thrown - throw new EC2ServiceException(ServerError.InsufficientInstanceCapacity, "Insufficient Instance Capacity" ); + throw new EC2ServiceException(ServerError.InternalError, "Failed to deploy instances" ); } + logger.debug("Could deploy "+ countCreated + " VM's successfully"); return instances; } catch( Exception e ) {
