Merge branch '3.0.x' of ssh://git.cloud.com/var/lib/git/cloudstack-oss into 3.0.x

This commit is contained in:
Deepti Dohare 2012-07-06 15:13:51 +05:30
commit 009f2543ed
123 changed files with 4731 additions and 2377 deletions

View File

@ -14,6 +14,7 @@ package com.cloud.api;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@ -56,6 +57,7 @@ import com.cloud.user.Account;
import com.cloud.user.AccountService;
import com.cloud.user.DomainService;
import com.cloud.user.ResourceLimitService;
import com.cloud.utils.IdentityProxy;
import com.cloud.utils.Pair;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.vm.BareMetalVmService;
@ -196,9 +198,9 @@ public abstract class BaseCmd {
}
public ManagementService getMgmtServiceRef() {
return _mgr;
return _mgr;
}
public static String getDateString(Date date) {
if (date == null) {
return "";
@ -482,12 +484,12 @@ public abstract class BaseCmd {
public Long finalyzeAccountId(String accountName, Long domainId, Long projectId, boolean enabledOnly) {
if (accountName != null) {
if (domainId == null) {
throw new InvalidParameterValueException("Account must be specified with domainId parameter");
throw new InvalidParameterValueException("Account must be specified with domainId parameter", null);
}
Domain domain = _domainService.getDomain(domainId);
if (domain == null) {
throw new InvalidParameterValueException("Unable to find domain by id=" + domainId);
throw new InvalidParameterValueException("Unable to find domain by id", null);
}
Account account = _accountService.getActiveAccountByName(accountName, domainId);
@ -498,7 +500,9 @@ public abstract class BaseCmd {
throw new PermissionDeniedException("Can't add resources to the account id=" + account.getId() + " in state=" + account.getState() + " as it's no longer active");
}
} else {
throw new InvalidParameterValueException("Unable to find account by name " + accountName + " in domain id=" + domainId);
List<IdentityProxy> idList = new ArrayList<IdentityProxy>();
idList.add(new IdentityProxy("domain", domainId, "domainId"));
throw new InvalidParameterValueException("Unable to find account by name " + accountName + " in domain with specified id", idList);
}
}
@ -508,14 +512,12 @@ public abstract class BaseCmd {
if (!enabledOnly || project.getState() == Project.State.Active) {
return project.getProjectAccountId();
} else {
PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() + " as it's no longer active");
ex.addProxyObject(project, projectId, "projectId");
PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() + " as it's no longer active");
ex.addProxyObject(project, projectId, "projectId");
throw ex;
}
} else {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified projectId");
ex.addProxyObject(project, projectId, "projectId");
throw ex;
throw new InvalidParameterValueException("Unable to find project by id", null);
}
}
return null;

View File

@ -48,11 +48,11 @@ public abstract class BaseListCmd extends BaseCmd {
public Integer getPageSize() {
if (pageSize != null && MAX_PAGESIZE != null && pageSize.longValue() > MAX_PAGESIZE.longValue()) {
throw new InvalidParameterValueException("Page size can't exceed max allowed page size value: " + MAX_PAGESIZE.longValue());
throw new InvalidParameterValueException("Page size can't exceed max allowed page size value: " + MAX_PAGESIZE.longValue(), null);
}
if (pageSize != null && pageSize.longValue() == PAGESIZE_UNLIMITED && page != null) {
throw new InvalidParameterValueException("Can't specify page parameter when pagesize is -1 (Unlimited)");
throw new InvalidParameterValueException("Can't specify page parameter when pagesize is -1 (Unlimited)", null);
}
return pageSize;

View File

@ -25,7 +25,7 @@ import com.cloud.exception.InvalidParameterValueException;
public abstract class BaseListTaggedResourcesCmd extends BaseListProjectAndAccountResourcesCmd{
@Parameter(name = ApiConstants.TAGS, type = CommandType.MAP, description = "List resources by tags (key/value pairs)")
private Map tags;
public Map<String, String> getTags() {
Map<String, String> tagsMap = null;
if (tags != null && !tags.isEmpty()) {
@ -37,7 +37,7 @@ public abstract class BaseListTaggedResourcesCmd extends BaseListProjectAndAccou
String key = services.get("key");
String value = services.get("value");
if (value == null) {
throw new InvalidParameterValueException("No value is passed in for key " + key);
throw new InvalidParameterValueException("No value is passed in for key " + key, null);
}
tagsMap.put(key, value);
}

View File

@ -109,7 +109,6 @@ import com.cloud.network.VpnUser;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.network.rules.NetworkACL;
import com.cloud.network.rules.PortForwardingRule;
import com.cloud.network.rules.StaticNatRule;
import com.cloud.network.rules.StickinessPolicy;
@ -320,7 +319,7 @@ public interface ResponseGenerator {
* @param networkACL
* @return
*/
NetworkACLResponse createNetworkACLResponse(NetworkACL networkACL);
NetworkACLResponse createNetworkACLResponse(FirewallRule networkACL);
/**
* @param result

View File

@ -18,7 +18,6 @@ import com.cloud.api.ApiConstants;
import com.cloud.api.BaseAsyncCmd;
import com.cloud.api.BaseCmd;
import com.cloud.api.IdentityMapper;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
@ -37,7 +36,7 @@ public class ActivateProjectCmd extends BaseAsyncCmd {
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@IdentityMapper(entityTableName="projects")
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="id of the project to be modified")
private Long id;
@ -54,18 +53,18 @@ public class ActivateProjectCmd extends BaseAsyncCmd {
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
Project project= _projectService.getProject(id);
//verify input parameters
if (project == null) {
throw new InvalidParameterValueException("Unable to find project by id " + id);
throw new InvalidParameterValueException("Unable to find project by id", null);
}
return _projectService.getProjectOwner(id).getId();
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
@ -83,12 +82,12 @@ public class ActivateProjectCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to activate a project");
}
}
@Override
public String getEventType() {
return EventTypes.EVENT_PROJECT_ACTIVATE;
}
@Override
public String getEventDescription() {
return "Activating project: " + id;

View File

@ -26,7 +26,6 @@ import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.projects.Project;
import com.cloud.user.UserContext;
import com.cloud.utils.AnnotationHelper;
@Implementation(description="Adds acoount to a project", responseObject=SuccessResponse.class, since="3.0.0")
@ -42,10 +41,10 @@ public class AddAccountToProjectCmd extends BaseAsyncCmd {
@IdentityMapper(entityTableName="projects")
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, required=true, description="id of the project to add the account to")
private Long projectId;
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="name of the account to be added to the project")
private String accountName;
@Parameter(name=ApiConstants.EMAIL, type=CommandType.STRING, description="email to which invitation to the project is going to be sent")
private String email;
@ -62,7 +61,7 @@ public class AddAccountToProjectCmd extends BaseAsyncCmd {
return projectId;
}
public String getEmail() {
return email;
}
@ -79,9 +78,9 @@ public class AddAccountToProjectCmd extends BaseAsyncCmd {
@Override
public void execute(){
if (accountName == null && email == null) {
throw new InvalidParameterValueException("Either accountName or email is required");
throw new InvalidParameterValueException("Either accountName or email is required", null);
}
UserContext.current().setEventDetails("Project id: "+ projectId + "; accountName " + accountName);
boolean result = _projectService.addAccountToProject(getProjectId(), getAccountName(), getEmail());
if (result) {
@ -91,25 +90,25 @@ public class AddAccountToProjectCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add account to the project");
}
}
@Override
public long getEntityOwnerId() {
Project project= _projectService.getProject(projectId);
//verify input parameters
if (project == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified id");
ex.addProxyObject(project, projectId, "projectId");
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified id", null);
ex.addProxyObject(project, projectId, "projectId");
throw ex;
}
return _projectService.getProjectOwner(projectId).getId();
}
@Override
public String getEventType() {
return EventTypes.EVENT_PROJECT_ACCOUNT_ADD;
}
@Override
public String getEventDescription() {
if (accountName != null) {

View File

@ -88,7 +88,7 @@ public class AssignToLoadBalancerRuleCmd extends BaseAsyncCmd {
public String getEventDescription() {
return "applying instances for load balancer: " + getLoadBalancerId() + " (ids: " + StringUtils.join(getVirtualMachineIds(), ",") + ")";
}
@Override
public void execute(){
UserContext.current().setEventDetails("Load balancer Id: "+getLoadBalancerId()+" VmIds: "+StringUtils.join(getVirtualMachineIds(), ","));
@ -100,7 +100,7 @@ public class AssignToLoadBalancerRuleCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to assign load balancer rule");
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
@ -108,10 +108,10 @@ public class AssignToLoadBalancerRuleCmd extends BaseAsyncCmd {
@Override
public Long getSyncObjId() {
LoadBalancer lb = _lbService.findById(id);
if(lb == null){
throw new InvalidParameterValueException("Unable to find load balancer rule: " + id);
}
LoadBalancer lb = _lbService.findById(id);
if(lb == null){
throw new InvalidParameterValueException("Unable to find load balancer rule by id", null);
}
return lb.getNetworkId();
}
}

View File

@ -56,37 +56,38 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
@IdentityMapper(entityTableName="domain")
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG,
description="the ID of the domain to associate with this IP address")
description="the ID of the domain to associate with this IP address")
private Long domainId;
@IdentityMapper(entityTableName="data_center")
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG,
description="the ID of the availability zone you want to acquire an public IP address from")
description="the ID of the availability zone you want to acquire an public IP address from")
private Long zoneId;
@IdentityMapper(entityTableName="networks")
@Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG,
description="The network this ip address should be associated to.")
description="The network this ip address should be associated to.")
private Long networkId;
@IdentityMapper(entityTableName="projects")
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG,
description="Deploy vm for the project")
description="Deploy vm for the project")
private Long projectId;
@IdentityMapper(entityTableName="vpc")
@Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="the VPC you want the ip address to " +
"be associated with")
"be associated with")
private Long vpcId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@Override
public String getEntityTable() {
return "user_ip_address";
return "user_ip_address";
}
public String getAccountName() {
if (accountName != null) {
return accountName;
@ -103,7 +104,7 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
private long getZoneId() {
if (zoneId != null) {
return zoneId;
return zoneId;
} else if (vpcId != null) {
Vpc vpc = _entityMgr.findById(Vpc.class, vpcId);
if (vpc != null) {
@ -115,28 +116,28 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
return ntwk.getDataCenterId();
}
}
throw new InvalidParameterValueException("Unable to figure out zone to assign ip to");
throw new InvalidParameterValueException("Unable to figure out zone to assign ip to", null);
}
public Long getVpcId() {
return vpcId;
}
public Long getNetworkId() {
if (vpcId != null) {
return null;
}
if (networkId != null) {
return networkId;
}
Long zoneId = getZoneId();
if (zoneId == null) {
return null;
}
DataCenter zone = _configService.getZone(zoneId);
if (zone.getNetworkType() == NetworkType.Advanced) {
List<? extends Network> networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(),
@ -144,52 +145,52 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
if (networks.size() == 0) {
String domain = _domainService.getDomain(getDomainId()).getName();
throw new InvalidParameterValueException("Account name=" + getAccountName() + " domain=" + domain +
" doesn't have virtual networks in zone=" + zone.getName());
" doesn't have virtual networks in zone=" + zone.getName(), null);
}
if (networks.size() < 1) {
throw new InvalidParameterValueException("Account doesn't have any Isolated networks in the zone");
throw new InvalidParameterValueException("Account doesn't have any Isolated networks in the zone", null);
} else if (networks.size() > 1) {
throw new InvalidParameterValueException("Account has more than one Isolated network in the zone");
throw new InvalidParameterValueException("Account has more than one Isolated network in the zone", null);
}
return networks.get(0).getId();
} else {
Network defaultGuestNetwork = _networkService.getExclusiveGuestNetwork(zoneId);
if (defaultGuestNetwork == null) {
throw new InvalidParameterValueException("Unable to find a default Guest network for account " +
getAccountName() + " in domain id=" + getDomainId());
getAccountName() + " in domain id=" + getDomainId(), null);
} else {
return defaultGuestNetwork.getId();
}
}
}
@Override
public long getEntityOwnerId() {
Account caller = UserContext.current().getCaller();
if (accountName != null && domainId != null) {
Account account = _accountService.finalizeOwner(caller, accountName, domainId, projectId);
return account.getId();
} else if (getNetworkId() != null){
Network network = _networkService.getNetwork(getNetworkId());
Account caller = UserContext.current().getCaller();
if (accountName != null && domainId != null) {
Account account = _accountService.finalizeOwner(caller, accountName, domainId, projectId);
return account.getId();
} else if (getNetworkId() != null){
Network network = _networkService.getNetwork(getNetworkId());
return network.getAccountId();
} else if (vpcId != null) {
Vpc vpc = _vpcService.getVpc(getVpcId());
if (vpc == null) {
throw new InvalidParameterValueException("Can't find Enabled vpc by id specified");
}
return vpc.getAccountId();
}
throw new InvalidParameterValueException("Failed to determine ip owner");
} else if (vpcId != null) {
Vpc vpc = _vpcService.getVpc(getVpcId());
if (vpc == null) {
throw new InvalidParameterValueException("Can't find Enabled vpc by id specified", null);
}
return vpc.getAccountId();
}
throw new InvalidParameterValueException("Failed to determine ip owner", null);
}
@Override
public String getEventType() {
return EventTypes.EVENT_NET_IP_ASSIGN;
}
@Override
public String getEventDescription() {
return "associating ip to network id: " + getNetworkId() + " in zone " + getZoneId();
@ -206,9 +207,9 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
}
public static String getResultObjectName() {
return "addressinfo";
return "addressinfo";
}
@Override
public void create() throws ResourceAllocationException{
try {
@ -227,14 +228,14 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
}
}
@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException,
ConcurrentOperationException, InsufficientCapacityException {
ConcurrentOperationException, InsufficientCapacityException {
UserContext.current().setEventDetails("Ip Id: " + getEntityId());
IpAddress result = null;
result = _networkService.associateIP(getEntityId(), getNetworkId(), getVpcId());
if (result != null) {
@ -245,8 +246,8 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to assign ip address");
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
@ -256,7 +257,7 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
public Long getSyncObjId() {
return getNetworkId();
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.IpAddress;

View File

@ -67,14 +67,14 @@ public class AttachIsoCmd extends BaseAsyncCmd {
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
UserVm vm = _entityMgr.findById(UserVm.class, getVirtualMachineId());
if (vm == null) {
throw new InvalidParameterValueException("Unable to find virtual machine by id " + getVirtualMachineId());
throw new InvalidParameterValueException("Unable to find virtual machine by id " + getVirtualMachineId(), null);
}
return vm.getAccountId();
}
@ -87,10 +87,10 @@ public class AttachIsoCmd extends BaseAsyncCmd {
public String getEventDescription() {
return "attaching ISO: " + getId() + " to vm: " + getVirtualMachineId();
}
@Override
public void execute(){
UserContext.current().setEventDetails("Vm Id: " +getVirtualMachineId()+ " ISO Id: "+getId());
UserContext.current().setEventDetails("Vm Id: " +getVirtualMachineId()+ " ISO Id: "+getId());
boolean result = _templateService.attachIso(id, virtualMachineId);
if (result) {
UserVm userVm = _responseGenerator.findUserVmById(virtualMachineId);

View File

@ -17,7 +17,9 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseAsyncCmd;
import com.cloud.api.BaseCmd;
@ -25,8 +27,8 @@ import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.SecurityGroupRuleResponse;
import com.cloud.api.response.SecurityGroupResponse;
import com.cloud.api.response.SecurityGroupRuleResponse;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
@ -65,22 +67,22 @@ public class AuthorizeSecurityGroupEgressCmd extends BaseAsyncCmd {
@Parameter(name = ApiConstants.USER_SECURITY_GROUP_LIST, type = CommandType.MAP, description = "user to security group mapping")
private Map userSecurityGroupList;
@IdentityMapper(entityTableName="domain")
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="an optional domainId for the security group. If the account parameter is used, domainId must also be used.")
private Long domainId;
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="an optional account for the security group. Must be used with domainId.")
private String accountName;
@IdentityMapper(entityTableName="projects")
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="an optional project of the security group")
private Long projectId;
@IdentityMapper(entityTableName="security_group")
@Parameter(name=ApiConstants.SECURITY_GROUP_ID, type=CommandType.LONG, description="The ID of the security group. Mutually exclusive with securityGroupName parameter")
private Long securityGroupId;
@Parameter(name=ApiConstants.SECURITY_GROUP_NAME, type=CommandType.STRING, description="The name of the security group. Mutually exclusive with securityGroupName parameter")
private String securityGroupName;
@ -110,21 +112,21 @@ public class AuthorizeSecurityGroupEgressCmd extends BaseAsyncCmd {
public Long getSecurityGroupId() {
if (securityGroupId != null && securityGroupName != null) {
throw new InvalidParameterValueException("securityGroupId and securityGroupName parameters are mutually exclusive");
throw new InvalidParameterValueException("securityGroupId and securityGroupName parameters are mutually exclusive", null);
}
if (securityGroupName != null) {
securityGroupId = _responseGenerator.getSecurityGroupId(securityGroupName, getEntityOwnerId());
if (securityGroupId == null) {
throw new InvalidParameterValueException("Unable to find security group " + securityGroupName + " for account id=" + getEntityOwnerId());
throw new InvalidParameterValueException("Unable to find security group " + securityGroupName + " for account id=" + getEntityOwnerId(), null);
}
securityGroupName = null;
}
if (securityGroupId == null) {
throw new InvalidParameterValueException("Either securityGroupId or securityGroupName is required by authorizeSecurityGroupIngress command");
throw new InvalidParameterValueException("Either securityGroupId or securityGroupName is required by authorizeSecurityGroupIngress command", null);
}
return securityGroupId;
}
@ -162,7 +164,7 @@ public class AuthorizeSecurityGroupEgressCmd extends BaseAsyncCmd {
if (accountId == null) {
return UserContext.current().getCaller().getId();
}
return accountId;
}

View File

@ -68,22 +68,22 @@ public class AuthorizeSecurityGroupIngressCmd extends BaseAsyncCmd {
@Parameter(name = ApiConstants.USER_SECURITY_GROUP_LIST, type = CommandType.MAP, description = "user to security group mapping")
private Map userSecurityGroupList;
@IdentityMapper(entityTableName="domain")
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="an optional domainId for the security group. If the account parameter is used, domainId must also be used.")
private Long domainId;
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="an optional account for the security group. Must be used with domainId.")
private String accountName;
@IdentityMapper(entityTableName="projects")
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="an optional project of the security group")
private Long projectId;
@IdentityMapper(entityTableName="security_group")
@Parameter(name=ApiConstants.SECURITY_GROUP_ID, type=CommandType.LONG, description="The ID of the security group. Mutually exclusive with securityGroupName parameter")
private Long securityGroupId;
@Parameter(name=ApiConstants.SECURITY_GROUP_NAME, type=CommandType.STRING, description="The name of the security group. Mutually exclusive with securityGroupName parameter")
private String securityGroupName;
@ -113,21 +113,21 @@ public class AuthorizeSecurityGroupIngressCmd extends BaseAsyncCmd {
public Long getSecurityGroupId() {
if (securityGroupId != null && securityGroupName != null) {
throw new InvalidParameterValueException("securityGroupId and securityGroupName parameters are mutually exclusive");
throw new InvalidParameterValueException("securityGroupId and securityGroupName parameters are mutually exclusive", null);
}
if (securityGroupName != null) {
securityGroupId = _responseGenerator.getSecurityGroupId(securityGroupName, getEntityOwnerId());
if (securityGroupId == null) {
throw new InvalidParameterValueException("Unable to find security group " + securityGroupName + " for account id=" + getEntityOwnerId());
throw new InvalidParameterValueException("Unable to find security group " + securityGroupName + " for account id=" + getEntityOwnerId(), null);
}
securityGroupName = null;
}
if (securityGroupId == null) {
throw new InvalidParameterValueException("Either securityGroupId or securityGroupName is required by authorizeSecurityGroupIngress command");
throw new InvalidParameterValueException("Either securityGroupId or securityGroupName is required by authorizeSecurityGroupIngress command", null);
}
return securityGroupId;
}
@ -165,7 +165,7 @@ public class AuthorizeSecurityGroupIngressCmd extends BaseAsyncCmd {
if (accountId == null) {
return UserContext.current().getCaller().getId();
}
return accountId;
}

View File

@ -33,7 +33,6 @@ import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.IpAddress;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.NetworkACL;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
import com.cloud.utils.net.NetUtils;
@ -60,25 +59,26 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal
@Parameter(name = ApiConstants.END_PORT, type = CommandType.INTEGER, description = "the ending port of firewall rule")
private Integer publicEndPort;
@Parameter(name = ApiConstants.CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING, description = "the cidr list to forward traffic from")
private List<String> cidrlist;
@Parameter(name = ApiConstants.ICMP_TYPE, type = CommandType.INTEGER, description = "type of the icmp message being sent")
private Integer icmpType;
@Parameter(name = ApiConstants.ICMP_CODE, type = CommandType.INTEGER, description = "error code for this icmp message")
private Integer icmpCode;
@Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, description = "type of firewallrule: system/user")
private String type;
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public String getEntityTable() {
return "firewall_rules";
return "firewall_rules";
}
public Long getIpAddressId() {
@ -90,6 +90,7 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal
return protocol.trim();
}
@Override
public List<String> getSourceCidrList() {
if (cidrlist != null) {
return cidrlist;
@ -98,7 +99,7 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal
oneCidrList.add(NetUtils.ALL_CIDRS);
return oneCidrList;
}
}
// ///////////////////////////////////////////////////
@ -109,7 +110,7 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal
public String getCommandName() {
return s_name;
}
public void setSourceCidrList(List<String> cidrs){
cidrlist = cidrs;
}
@ -118,13 +119,13 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal
public void execute() throws ResourceUnavailableException {
UserContext callerContext = UserContext.current();
boolean success = false;
FirewallRule rule = _entityMgr.findById(NetworkACL.class, getEntityId());
FirewallRule rule = _entityMgr.findById(FirewallRule.class, getEntityId());
try {
UserContext.current().setEventDetails("Rule Id: " + getEntityId());
success = _firewallService.applyFirewallRules(rule.getSourceIpAddressId(), callerContext.getCaller());
// State is different after the rule is applied, so get new object here
rule = _entityMgr.findById(NetworkACL.class, getEntityId());
rule = _entityMgr.findById(FirewallRule.class, getEntityId());
FirewallResponse fwResponse = new FirewallResponse();
if (rule != null) {
fwResponse = _responseGenerator.createFirewallResponse(rule);
@ -172,7 +173,7 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal
} else {
return publicEndPort.intValue();
}
return null;
}
@ -190,14 +191,14 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal
public long getNetworkId() {
IpAddress ip = _entityMgr.findById(IpAddress.class, getIpAddressId());
Long ntwkId = null;
if (ip.getAssociatedWithNetworkId() != null) {
ntwkId = ip.getAssociatedWithNetworkId();
}
if (ntwkId == null) {
throw new InvalidParameterValueException("Unable to create firewall rule for the ipAddress id=" + ipAddressId +
" as ip is not associated with any network and no networkId is passed in");
" as ip is not associated with any network and no networkId is passed in", null);
}
return ntwkId;
}
@ -269,11 +270,11 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal
private IpAddress getIp() {
IpAddress ip = _networkService.getIp(ipAddressId);
if (ip == null) {
throw new InvalidParameterValueException("Unable to find ip address by id " + ipAddressId);
throw new InvalidParameterValueException("Unable to find ip address by id", null);
}
return ip;
}
@Override
public Integer getIcmpCode() {
if (icmpCode != null) {
@ -283,14 +284,14 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal
}
return null;
}
@Override
public Integer getIcmpType() {
if (icmpType != null) {
return icmpType;
} else if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO)) {
return -1;
return -1;
}
return null;
}
@ -300,18 +301,23 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal
return null;
}
@Override
public FirewallRuleType getType() {
if (type != null && type.equalsIgnoreCase("system")) {
return FirewallRuleType.System;
} else {
return FirewallRuleType.User;
}
}
@Override
public FirewallRuleType getType() {
if (type != null && type.equalsIgnoreCase("system")) {
return FirewallRuleType.System;
} else {
return FirewallRuleType.User;
}
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.FirewallRule;
}
@Override
public TrafficType getTrafficType() {
return null;
}
}

View File

@ -50,19 +50,19 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta
@IdentityMapper(entityTableName="user_ip_address")
@Parameter(name=ApiConstants.IP_ADDRESS_ID, type=CommandType.LONG, required=true, description="the public IP address id of the forwarding rule, already associated via associateIp")
private Long ipAddressId;
@Parameter(name=ApiConstants.START_PORT, type=CommandType.INTEGER, required=true, description="the start port for the rule")
private Integer startPort;
@Parameter(name=ApiConstants.END_PORT, type=CommandType.INTEGER, description="the end port for the rule")
private Integer endPort;
@Parameter(name=ApiConstants.PROTOCOL, type=CommandType.STRING, required=true, description="the protocol for the rule. Valid values are TCP or UDP.")
private String protocol;
@Parameter(name = ApiConstants.OPEN_FIREWALL, type = CommandType.BOOLEAN, description = "if true, firewall rule for source/end pubic port is automatically created; if false - firewall rule has to be created explicitely. Has value true by default")
private Boolean openFirewall;
@Parameter(name = ApiConstants.CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING, description = "the cidr list to forward traffic from")
private List<String> cidrlist;
@ -70,23 +70,24 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@Override
public String getEntityTable() {
return "firewall_rules";
return "firewall_rules";
}
public Long getIpAddressId() {
return ipAddressId;
}
public int getStartPort() {
return startPort;
}
public int getEndPort() {
return endPort;
}
public Boolean getOpenFirewall() {
if (openFirewall != null) {
return openFirewall;
@ -111,11 +112,11 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta
FirewallRule rule = null;
try {
UserContext.current().setEventDetails("Rule Id: "+ getEntityId());
if (getOpenFirewall()) {
result = result && _firewallService.applyFirewallRules(ipAddressId, UserContext.current().getCaller());
}
result = result && _rulesService.applyStaticNatRules(ipAddressId, UserContext.current().getCaller());
rule = _entityMgr.findById(FirewallRule.class, getEntityId());
StaticNatRule staticNatRule = _rulesService.buildStaticNatRule(rule, false);
@ -124,26 +125,26 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta
this.setResponseObject(fwResponse);
} finally {
if (!result || rule == null) {
if (getOpenFirewall()) {
_firewallService.revokeRelatedFirewallRule(getEntityId(), true);
}
_rulesService.revokeStaticNatRule(getEntityId(), true);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Error in creating ip forwarding rule on the domr");
}
}
}
@Override
public void create() {
//cidr list parameter is deprecated
@Override
public void create() {
//cidr list parameter is deprecated
if (cidrlist != null) {
throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall rule for the specific cidr, please refer to createFirewallRule command");
throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall rule for the specific cidr, please refer to createFirewallRule command", null);
}
try {
StaticNatRule rule = _rulesService.createStaticNatRule(this, getOpenFirewall());
this.setEntityId(rule.getId());
@ -151,7 +152,7 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta
s_logger.info("Unable to create Static Nat Rule due to ", e);
throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
}
}
}
@Override
public long getEntityOwnerId() {
@ -174,16 +175,16 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta
IpAddress ip = _networkService.getIp(ipAddressId);
return ("Applying an ipforwarding 1:1 NAT rule for Ip: "+ip.getAddress()+" with virtual machine:"+ this.getVirtualMachineId());
}
private long getVirtualMachineId() {
Long vmId = _networkService.getIp(ipAddressId).getAssociatedWithVmId();
if (vmId == null) {
throw new InvalidParameterValueException("Ip address is not associated with any network, unable to create static nat rule");
throw new InvalidParameterValueException("Ip address is not associated with any network, unable to create static nat rule", null);
}
return vmId;
}
@Override
public String getDestIpAddress(){
return null;
@ -244,13 +245,13 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta
IpAddress ip = _networkService.getIp(ipAddressId);
return ip.getAccountId();
}
@Override
public String getXid() {
// FIXME: We should allow for end user to specify Xid.
return null;
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
@ -264,16 +265,16 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta
private IpAddress getIp() {
IpAddress ip = _networkService.getIp(ipAddressId);
if (ip == null) {
throw new InvalidParameterValueException("Unable to find ip address by id " + ipAddressId);
throw new InvalidParameterValueException("Unable to find ip address by id", null);
}
return ip;
}
@Override
public Integer getIcmpCode() {
return null;
}
@Override
public Integer getIcmpType() {
return null;
@ -283,20 +284,25 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta
public List<String> getSourceCidrList() {
return null;
}
@Override
public Long getRelated() {
return null;
}
@Override
public FirewallRuleType getType() {
return FirewallRuleType.User;
}
@Override
@Override
public FirewallRuleType getType() {
return FirewallRuleType.User;
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.FirewallRule;
}
@Override
public TrafficType getTrafficType() {
return null;
}
}

View File

@ -12,6 +12,7 @@
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.api.commands;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
@ -38,6 +39,7 @@ import com.cloud.network.Network;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
import com.cloud.utils.IdentityProxy;
import com.cloud.utils.net.NetUtils;
@Implementation(description="Creates a load balancer rule", responseObject=LoadBalancerResponse.class)
@ -65,7 +67,7 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements
@IdentityMapper(entityTableName="user_ip_address")
@Parameter(name=ApiConstants.PUBLIC_IP_ID, type=CommandType.LONG, description="public ip address id from where the network traffic will be load balanced from")
private Long publicIpId;
@IdentityMapper(entityTableName="data_center")
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=false, description="zone where the load balancer is going to be created. This parameter is required when LB service provider is ElasticLoadBalancerVm")
private Long zoneId;
@ -74,8 +76,8 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements
private Integer publicPort;
@Parameter(name = ApiConstants.OPEN_FIREWALL, type = CommandType.BOOLEAN, description = "if true, firewall rule for" +
" source/end pubic port is automatically created; if false - firewall rule has to be created explicitely. If not specified 1) defaulted to false when LB" +
" rule is being created for VPC guest network 2) in all other cases defaulted to true")
" source/end pubic port is automatically created; if false - firewall rule has to be created explicitely. If not specified 1) defaulted to false when LB" +
" rule is being created for VPC guest network 2) in all other cases defaulted to true")
private Boolean openFirewall;
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the load balancer. Must be used with the domainId parameter.")
@ -84,15 +86,15 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements
@IdentityMapper(entityTableName="domain")
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the domain ID associated with the load balancer")
private Long domainId;
@Parameter(name = ApiConstants.CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING, description = "the cidr list to forward traffic from")
private List<String> cidrlist;
@IdentityMapper(entityTableName="networks")
@Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, description="The guest network this " +
"rule will be created for. Required when public Ip address is not associated with any Guest network yet (VPC case)")
"rule will be created for. Required when public Ip address is not associated with any Guest network yet (VPC case)")
private Long networkId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -113,97 +115,100 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements
return privatePort;
}
@Override
public String getEntityTable() {
return "firewall_rules";
return "firewall_rules";
}
public Long getSourceIpAddressId() {
if (publicIpId != null) {
IpAddress ipAddr = _networkService.getIp(publicIpId);
if (ipAddr == null || !ipAddr.readyToUse()) {
throw new InvalidParameterValueException("Unable to create load balancer rule, invalid IP address id " + ipAddr.getId());
}
} else if (getEntityId() != null) {
LoadBalancer rule = _entityMgr.findById(LoadBalancer.class, getEntityId());
return rule.getSourceIpAddressId();
}
return publicIpId;
if (publicIpId != null) {
IpAddress ipAddr = _networkService.getIp(publicIpId);
if (ipAddr == null || !ipAddr.readyToUse()) {
throw new InvalidParameterValueException("Unable to create load balancer rule, invalid IP address id provided", null);
}
} else if (getEntityId() != null) {
LoadBalancer rule = _entityMgr.findById(LoadBalancer.class, getEntityId());
return rule.getSourceIpAddressId();
}
return publicIpId;
}
private Long getVpcId() {
if (publicIpId != null) {
IpAddress ipAddr = _networkService.getIp(publicIpId);
if (ipAddr == null || !ipAddr.readyToUse()) {
throw new InvalidParameterValueException("Unable to create load balancer rule, invalid IP address id " + ipAddr.getId());
throw new InvalidParameterValueException("Unable to create load balancer rule, invalid IP address id povided", null);
} else {
return ipAddr.getVpcId();
}
}
return null;
}
public Long getNetworkId() {
if (networkId != null) {
return networkId;
}
Long zoneId = getZoneId();
if (zoneId == null) {
Long ipId = getSourceIpAddressId();
if (ipId == null) {
throw new InvalidParameterValueException("Either networkId or zoneId or publicIpId has to be specified");
}
Long ipId = getSourceIpAddressId();
if (ipId == null) {
throw new InvalidParameterValueException("Either networkId or zoneId or publicIpId has to be specified", null);
}
}
if (zoneId != null) {
DataCenter zone = _configService.getZone(zoneId);
if (zone.getNetworkType() == NetworkType.Advanced) {
DataCenter zone = _configService.getZone(zoneId);
if (zone.getNetworkType() == NetworkType.Advanced) {
List<? extends Network> networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(), _accountService.getAccount(getEntityOwnerId()));
if (networks.size() == 0) {
String domain = _domainService.getDomain(getDomainId()).getName();
throw new InvalidParameterValueException("Account name=" + getAccountName() + " domain=" + domain + " doesn't have virtual networks in zone=" + zone.getName());
throw new InvalidParameterValueException("Account name=" + getAccountName() + " domain=" + domain + " doesn't have virtual networks in zone=" + zone.getName(), null);
}
if (networks.size() < 1) {
throw new InvalidParameterValueException("Account doesn't have any Isolated networks in the zone");
throw new InvalidParameterValueException("Account doesn't have any Isolated networks in the zone", null);
} else if (networks.size() > 1) {
throw new InvalidParameterValueException("Account has more than one Isolated network in the zone");
throw new InvalidParameterValueException("Account has more than one Isolated network in the zone", null);
}
return networks.get(0).getId();
} else {
Network defaultGuestNetwork = _networkService.getExclusiveGuestNetwork(zoneId);
if (defaultGuestNetwork == null) {
throw new InvalidParameterValueException("Unable to find a default Guest network for account " + getAccountName() + " in domain id=" + getDomainId());
List<IdentityProxy> idList = new ArrayList<IdentityProxy>();
idList.add(new IdentityProxy("domain", getDomainId(), "domainId"));
throw new InvalidParameterValueException("Unable to find a default Guest network for account " + getAccountName() + " in domain with specified id", idList);
} else {
return defaultGuestNetwork.getId();
}
}
} else {
IpAddress ipAddr = _networkService.getIp(publicIpId);
if (ipAddr.getAssociatedWithNetworkId() != null) {
IpAddress ipAddr = _networkService.getIp(publicIpId);
if (ipAddr.getAssociatedWithNetworkId() != null) {
return ipAddr.getAssociatedWithNetworkId();
} else {
throw new InvalidParameterValueException("Ip address id=" + publicIpId + " is not associated with any network");
}
} else {
throw new InvalidParameterValueException("Ip address id=" + publicIpId + " is not associated with any network", null);
}
}
}
public Integer getPublicPort() {
return publicPort;
}
public String getName() {
return loadBalancerRuleName;
}
public Boolean getOpenFirewall() {
boolean isVpc = getVpcId() == null ? false : true;
if (openFirewall != null) {
if (isVpc && openFirewall) {
throw new InvalidParameterValueException("Can't have openFirewall=true when IP address belongs to VPC");
throw new InvalidParameterValueException("Can't have openFirewall=true when IP address belongs to VPC", null);
}
return openFirewall;
} else {
@ -213,10 +218,10 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements
return true;
}
}
public List<String> getSourceCidrList() {
if (cidrlist != null) {
throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall rule for the specific cidr, please refer to createFirewallRule command");
throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall rule for the specific cidr, please refer to createFirewallRule command", null);
}
return null;
}
@ -229,16 +234,16 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements
public String getCommandName() {
return s_name;
}
@Override
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
UserContext callerContext = UserContext.current();
boolean success = true;
LoadBalancer rule = null;
try {
UserContext.current().setEventDetails("Rule Id: " + getEntityId());
if (getOpenFirewall()) {
success = success && _firewallService.applyFirewallRules(getSourceIpAddressId(), callerContext.getCaller());
}
@ -252,10 +257,10 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements
}
lbResponse.setResponseName(getCommandName());
} catch (Exception ex) {
s_logger.warn("Failed to create LB rule due to exception ", ex);
s_logger.warn("Failed to create LB rule due to exception ", ex);
}finally {
if (!success || rule == null) {
if (getOpenFirewall()) {
_firewallService.revokeRelatedFirewallRule(getEntityId(), true);
}
@ -266,12 +271,12 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements
}
}
}
@Override
public void create() {
//cidr list parameter is deprecated
if (cidrlist != null) {
throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall rule for the specific cidr, please refer to createFirewallRule command");
throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall rule for the specific cidr, please refer to createFirewallRule command", null);
}
try {
LoadBalancer result = _lbService.createLoadBalancerRule(this, getOpenFirewall());
@ -296,21 +301,23 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements
public String getProtocol() {
return NetUtils.TCP_PROTO;
}
public long getAccountId() {
if (publicIpId != null)
return _networkService.getIp(getSourceIpAddressId()).getAccountId();
Account account = null;
if ((domainId != null) && (accountName != null)) {
account = _responseGenerator.findAccountByNameDomain(accountName, domainId);
if (account != null) {
return account.getId();
} else {
throw new InvalidParameterValueException("Unable to find account " + account + " in domain id=" + domainId);
List<IdentityProxy> idList = new ArrayList<IdentityProxy>();
idList.add(new IdentityProxy("domain", getDomainId(), "domainId"));
throw new InvalidParameterValueException("Unable to find account " + account + " in domain with specified id", idList);
}
} else {
throw new InvalidParameterValueException("Can't define IP owner. Either specify account/domainId or ipAddressId");
throw new InvalidParameterValueException("Can't define IP owner. Either specify account/domainId or ipAddressId", null);
}
}
@ -330,16 +337,16 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements
public int getDefaultPortEnd() {
return privatePort.intValue();
}
@Override
public long getEntityOwnerId() {
return getAccountId();
return getAccountId();
}
public String getAccountName() {
return accountName;
}
public Long getZoneId() {
return zoneId;
}
@ -367,7 +374,7 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements
public void setSourceIpAddressId(Long ipId) {
this.publicIpId = ipId;
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.FirewallRule;

View File

@ -22,7 +22,6 @@ import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.NetworkACL;
import com.cloud.network.vpc.Vpc;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@ -30,7 +29,7 @@ import com.cloud.utils.net.NetUtils;
@Implementation(description = "Creates a ACL rule the given network (the network has to belong to VPC)",
responseObject = NetworkACLResponse.class)
public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements NetworkACL {
public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements FirewallRule {
public static final Logger s_logger = Logger.getLogger(CreateNetworkACLCmd.class.getName());
private static final String s_name = "createnetworkaclresponse";
@ -48,30 +47,31 @@ public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements NetworkAC
@Parameter(name = ApiConstants.END_PORT, type = CommandType.INTEGER, description = "the ending port of ACL")
private Integer publicEndPort;
@Parameter(name = ApiConstants.CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING,
description = "the cidr list to allow traffic from/to")
private List<String> cidrlist;
@Parameter(name = ApiConstants.ICMP_TYPE, type = CommandType.INTEGER, description = "type of the icmp message being sent")
private Integer icmpType;
@Parameter(name = ApiConstants.ICMP_CODE, type = CommandType.INTEGER, description = "error code for this icmp message")
private Integer icmpCode;
@IdentityMapper(entityTableName="networks")
@Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, required=true,
description="The network of the vm the ACL will be created for")
description="The network of the vm the ACL will be created for")
private Long networkId;
@Parameter(name=ApiConstants.TRAFFIC_TYPE, type=CommandType.STRING, description="the traffic type for the ACL," +
"can be Ingress or Egress, defaulted to Ingress if not specified")
"can be Ingress or Egress, defaulted to Ingress if not specified")
private String trafficType;
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public String getEntityTable() {
return "firewall_rules";
}
@ -85,6 +85,7 @@ public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements NetworkAC
return protocol.trim();
}
@Override
public List<String> getSourceCidrList() {
if (cidrlist != null) {
return cidrlist;
@ -94,21 +95,21 @@ public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements NetworkAC
return oneCidrList;
}
}
public long getVpcId() {
Network network = _networkService.getNetwork(getNetworkId());
if (network == null) {
throw new InvalidParameterValueException("Invalid networkId is given");
throw new InvalidParameterValueException("Invalid networkId is given", null);
}
Long vpcId = network.getVpcId();
if (vpcId == null) {
throw new InvalidParameterValueException("Can create network ACL only for the network belonging to the VPC");
throw new InvalidParameterValueException("Can create network ACL only for the network belonging to the VPC", null);
}
return vpcId;
}
@Override
public FirewallRule.TrafficType getTrafficType() {
if (trafficType == null) {
@ -119,7 +120,7 @@ public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements NetworkAC
return type;
}
}
throw new InvalidParameterValueException("Invalid traffic type " + trafficType);
throw new InvalidParameterValueException("Invalid traffic type " + trafficType, null);
}
// ///////////////////////////////////////////////////
@ -130,7 +131,7 @@ public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements NetworkAC
public String getCommandName() {
return s_name;
}
public void setSourceCidrList(List<String> cidrs){
cidrlist = cidrs;
}
@ -139,7 +140,7 @@ public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements NetworkAC
public void execute() throws ResourceUnavailableException {
UserContext callerContext = UserContext.current();
boolean success = false;
NetworkACL rule = _networkACLService.getNetworkACL(getEntityId());
FirewallRule rule = _networkACLService.getNetworkACL(getEntityId());
try {
UserContext.current().setEventDetails("Rule Id: " + getEntityId());
success = _networkACLService.applyNetworkACLs(rule.getNetworkId(), callerContext.getCaller());
@ -192,7 +193,7 @@ public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements NetworkAC
} else {
return publicEndPort.intValue();
}
return null;
}
@ -215,7 +216,7 @@ public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements NetworkAC
public long getEntityOwnerId() {
Vpc vpc = _vpcService.getVpc(getVpcId());
if (vpc == null) {
throw new InvalidParameterValueException("Invalid vpcId is given");
throw new InvalidParameterValueException("Invalid vpcId is given", null);
}
Account account = _accountService.getAccount(vpc.getAccountId());
@ -239,7 +240,7 @@ public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements NetworkAC
}
try {
NetworkACL result = _networkACLService.createNetworkACL(this);
FirewallRule result = _networkACLService.createNetworkACL(this);
setEntityId(result.getId());
} catch (NetworkRuleConflictException ex) {
s_logger.info("Network rule conflict: " + ex.getMessage());
@ -274,7 +275,7 @@ public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements NetworkAC
public Long getSyncObjId() {
return getNetworkId();
}
@Override
public Integer getIcmpCode() {
if (icmpCode != null) {
@ -284,14 +285,14 @@ public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements NetworkAC
}
return null;
}
@Override
public Integer getIcmpType() {
if (icmpType != null) {
return icmpType;
} else if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO)) {
return -1;
return -1;
}
return null;
}
@ -305,7 +306,7 @@ public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements NetworkAC
public FirewallRuleType getType() {
return FirewallRuleType.User;
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.FirewallRule;

View File

@ -39,54 +39,54 @@ public class CreateNetworkCmd extends BaseCmd {
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the network")
private String name;
@Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="the display text of the network")
private String displayText;
@IdentityMapper(entityTableName="network_offerings")
@Parameter(name=ApiConstants.NETWORK_OFFERING_ID, type=CommandType.LONG, required=true, description="the network offering id")
private Long networkOfferingId;
@IdentityMapper(entityTableName="data_center")
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the Zone ID for the network")
private Long zoneId;
@IdentityMapper(entityTableName="physical_network")
@Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="the Physical Network ID the network belongs to")
private Long physicalNetworkId;
@Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, description="the gateway of the network. Required " +
"for Shared networks and Isolated networks when it belongs to VPC")
"for Shared networks and Isolated networks when it belongs to VPC")
private String gateway;
@Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, description="the netmask of the network. Required " +
"for Shared networks and Isolated networks when it belongs to VPC")
private String netmask;
@Parameter(name=ApiConstants.START_IP, type=CommandType.STRING, description="the beginning IP address in the network IP range")
private String startIp;
@Parameter(name=ApiConstants.END_IP, type=CommandType.STRING, description="the ending IP address in the network IP" +
" range. If not specified, will be defaulted to startIP")
" range. If not specified, will be defaulted to startIP")
private String endIp;
@Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the ID or VID of the network")
private String vlan;
@Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="network domain")
private String networkDomain;
@Parameter(name=ApiConstants.ACL_TYPE, type=CommandType.STRING, description="Access control type; supported values" +
" are account and domain. In 3.0 all shared networks should have aclType=Domain, and all Isolated networks" +
" - Account. Account means that only the account owner can use the network, domain - all accouns in the domain can use the network")
" are account and domain. In 3.0 all shared networks should have aclType=Domain, and all Isolated networks" +
" - Account. Account means that only the account owner can use the network, domain - all accouns in the domain can use the network")
private String aclType;
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="account who will own the network")
private String accountName;
@IdentityMapper(entityTableName="projects")
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="an optional project for the ssh key")
private Long projectId;
@ -94,11 +94,11 @@ public class CreateNetworkCmd extends BaseCmd {
@IdentityMapper(entityTableName="domain")
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a network")
private Long domainId;
@Parameter(name=ApiConstants.SUBDOMAIN_ACCESS, type=CommandType.BOOLEAN, description="Defines whether to allow" +
" subdomains to use networks dedicated to their parent domain(s). Should be used with aclType=Domain, defaulted to allow.subdomain.network.access global config if not specified")
" subdomains to use networks dedicated to their parent domain(s). Should be used with aclType=Domain, defaulted to allow.subdomain.network.access global config if not specified")
private Boolean subdomainAccess;
@IdentityMapper(entityTableName="vpc")
@Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="the VPC network belongs to")
private Long vpcId;
@ -126,7 +126,7 @@ public class CreateNetworkCmd extends BaseCmd {
public Long getDomainId() {
return domainId;
}
public String getNetmask() {
return netmask;
}
@ -138,11 +138,11 @@ public class CreateNetworkCmd extends BaseCmd {
public String getEndIp() {
return endIp;
}
public String getNetworkName() {
return name;
}
public String getDisplayText() {
return displayText;
}
@ -150,48 +150,48 @@ public class CreateNetworkCmd extends BaseCmd {
public String getNetworkDomain() {
return networkDomain;
}
public Long getProjectId() {
return projectId;
}
public String getAclType() {
return aclType;
}
return aclType;
}
public Boolean getSubdomainAccess() {
return subdomainAccess;
}
public Boolean getSubdomainAccess() {
return subdomainAccess;
}
public Long getVpcId() {
public Long getVpcId() {
return vpcId;
}
public Long getZoneId() {
Long physicalNetworkId = getPhysicalNetworkId();
if (physicalNetworkId == null && zoneId == null) {
throw new InvalidParameterValueException("Zone id is required");
throw new InvalidParameterValueException("Zone id is required", null);
}
return zoneId;
}
public Long getPhysicalNetworkId() {
NetworkOffering offering = _configService.getNetworkOffering(networkOfferingId);
if (offering == null) {
throw new InvalidParameterValueException("Unable to find network offering by id " + networkOfferingId);
throw new InvalidParameterValueException("Unable to find network offering by id", null);
}
if (physicalNetworkId != null) {
if (offering.getGuestType() == GuestType.Shared) {
return physicalNetworkId;
} else {
throw new InvalidParameterValueException("Physical network id can be specified for networks of guest ip type " + GuestType.Shared + " only.");
throw new InvalidParameterValueException("Physical network id can be specified for networks of guest ip type " + GuestType.Shared + " only.", null);
}
} else {
if (zoneId == null) {
throw new InvalidParameterValueException("ZoneId is required as physicalNetworkId is null");
throw new InvalidParameterValueException("ZoneId is required as physicalNetworkId is null", null);
}
return _networkService.findPhysicalNetworkId(zoneId, offering.getTags(), offering.getTrafficType());
}
@ -204,17 +204,17 @@ public class CreateNetworkCmd extends BaseCmd {
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
if (accountId == null) {
return UserContext.current().getCaller().getId();
}
return accountId;
}
@Override
public void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException{
Network result = _networkService.createGuestNetwork(this);

View File

@ -46,55 +46,55 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the network offering")
private String networkOfferingName;
@Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="the display text of the network offering")
private String displayText;
@Parameter(name=ApiConstants.TRAFFIC_TYPE, type=CommandType.STRING, required=true, description="the traffic type for the network offering. Supported type in current release is GUEST only")
private String traffictype;
@Parameter(name=ApiConstants.TAGS, type=CommandType.STRING, description="the tags for the network offering.", length=4096)
private String tags;
@Parameter(name=ApiConstants.SPECIFY_VLAN, type=CommandType.BOOLEAN, description="true if network offering supports vlans")
private Boolean specifyVlan;
@Parameter(name=ApiConstants.AVAILABILITY, type=CommandType.STRING, description="the availability of network offering. Default value is Optional")
private String availability;
@Parameter(name=ApiConstants.NETWORKRATE, type=CommandType.INTEGER, description="data transfer rate in megabits per second allowed")
private Integer networkRate;
@Parameter(name=ApiConstants.CONSERVE_MODE, type=CommandType.BOOLEAN, description="true if the network offering is IP conserve mode enabled")
private Boolean conserveMode;
@IdentityMapper(entityTableName="disk_offering")
@Parameter(name=ApiConstants.SERVICE_OFFERING_ID, type=CommandType.LONG, description="the service offering ID used by virtual router provider")
private Long serviceOfferingId;
@Parameter(name=ApiConstants.GUEST_IP_TYPE, type=CommandType.STRING, required=true, description="guest type of the network offering: Shared or Isolated")
private String guestIptype;
@Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, required=true, collectionType=CommandType.STRING, description="services supported by the network offering")
private List<String> supportedServices;
@Parameter(name = ApiConstants.SERVICE_PROVIDER_LIST, type = CommandType.MAP, description = "provider to service mapping. If not specified, the provider for the service will be mapped to the default provider on the physical network")
private Map serviceProviderList;
@Parameter(name = ApiConstants.SERVICE_CAPABILITY_LIST, type = CommandType.MAP, description = "desired service capabilities as part of network offering")
private Map serviceCapabilitystList;
@Parameter(name=ApiConstants.SPECIFY_IP_RANGES, type=CommandType.BOOLEAN, description="true if network offering supports specifying ip ranges; defaulted to false if not specified")
private Boolean specifyIpRanges;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getNetworkOfferingName() {
return networkOfferingName;
}
public String getDisplayText() {
return displayText;
}
@ -106,7 +106,7 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
public String getTraffictype() {
return traffictype;
}
public Boolean getSpecifyVlan() {
return specifyVlan == null ? false : specifyVlan;
}
@ -114,7 +114,7 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
public String getAvailability() {
return availability == null ? Availability.Optional.toString() : availability;
}
public Integer getNetworkRate() {
return networkRate;
}
@ -126,18 +126,18 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
public Long getServiceOfferingId() {
return serviceOfferingId;
}
public List<String> getSupportedServices() {
return supportedServices;
}
public String getGuestIpType() {
public List<String> getSupportedServices() {
return supportedServices;
}
public String getGuestIpType() {
return guestIptype;
}
public Boolean getSpecifyIpRanges() {
return specifyIpRanges == null ? false : specifyIpRanges;
}
public Boolean getSpecifyIpRanges() {
return specifyIpRanges == null ? false : specifyIpRanges;
}
public Boolean getConserveMode() {
if (conserveMode == null) {
@ -166,7 +166,7 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
serviceProviderMap.put(service, providerList);
}
}
return serviceProviderMap;
}
@ -180,22 +180,22 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
while (iter.hasNext()) {
HashMap<String, String> svcCapabilityMap = (HashMap<String, String>) iter.next();
Capability capability = null;
String svc = (String) svcCapabilityMap.get("service");
String capabilityName = (String) svcCapabilityMap.get("capabilitytype");
String capabilityValue = (String) svcCapabilityMap.get("capabilityvalue");
String svc = svcCapabilityMap.get("service");
String capabilityName = svcCapabilityMap.get("capabilitytype");
String capabilityValue = svcCapabilityMap.get("capabilityvalue");
if (capabilityName != null) {
capability = Capability.getCapability(capabilityName);
}
if ((capability == null) || (capabilityName == null) || (capabilityValue == null) ) {
throw new InvalidParameterValueException("Invalid capability:" + capabilityName + " capability value:" + capabilityValue);
throw new InvalidParameterValueException("Invalid capability:" + capabilityName + " capability value:" + capabilityValue, null);
}
if (svc.equalsIgnoreCase(service.getName())) {
capabilityMap.put(capability, capabilityValue);
} else {
//throw new InvalidParameterValueException("Service is not equal ")
//throw new InvalidParameterValueException("Service is not equal ")
}
}
}
@ -210,7 +210,7 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
public String getCommandName() {
return _name;
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;

View File

@ -65,7 +65,7 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
@IdentityMapper(entityTableName = "vm_instance")
@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type = CommandType.LONG, required = true,
description = "the ID of the virtual machine for the port forwarding rule")
description = "the ID of the virtual machine for the port forwarding rule")
private Long virtualMachineId;
@Parameter(name = ApiConstants.CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING,
@ -74,20 +74,21 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
@Parameter(name = ApiConstants.OPEN_FIREWALL, type = CommandType.BOOLEAN,
description = "if true, firewall rule for source/end pubic port is automatically created; " +
"if false - firewall rule has to be created explicitely. If not specified 1) defaulted to false when PF" +
" rule is being created for VPC guest network 2) in all other cases defaulted to true")
"if false - firewall rule has to be created explicitely. If not specified 1) defaulted to false when PF" +
" rule is being created for VPC guest network 2) in all other cases defaulted to true")
private Boolean openFirewall;
@IdentityMapper(entityTableName="networks")
@Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG,
description="The network of the vm the Port Forwarding rule will be created for. " +
"Required when public Ip address is not associated with any Guest network yet (VPC case)")
description="The network of the vm the Port Forwarding rule will be created for. " +
"Required when public Ip address is not associated with any Guest network yet (VPC case)")
private Long networkId;
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public String getEntityTable() {
return "firewall_rules";
}
@ -106,10 +107,11 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
return virtualMachineId;
}
@Override
public List<String> getSourceCidrList() {
if (cidrlist != null) {
throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall " +
"rule for the specific cidr, please refer to createFirewallRule command");
"rule for the specific cidr, please refer to createFirewallRule command", null);
}
return null;
}
@ -118,7 +120,7 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
boolean isVpc = getVpcId() == null ? false : true;
if (openFirewall != null) {
if (isVpc && openFirewall) {
throw new InvalidParameterValueException("Can't have openFirewall=true when IP address belongs to VPC");
throw new InvalidParameterValueException("Can't have openFirewall=true when IP address belongs to VPC", null);
}
return openFirewall;
} else {
@ -128,12 +130,12 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
return true;
}
}
private Long getVpcId() {
if (ipAddressId != null) {
IpAddress ipAddr = _networkService.getIp(ipAddressId);
if (ipAddr == null || !ipAddr.readyToUse()) {
throw new InvalidParameterValueException("Unable to create PF rule, invalid IP address id " + ipAddr.getId());
throw new InvalidParameterValueException("Unable to create PF rule, invalid IP address id " + ipAddr.getId(), null);
} else {
return ipAddr.getVpcId();
}
@ -226,7 +228,7 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
public long getNetworkId() {
IpAddress ip = _entityMgr.findById(IpAddress.class, getIpAddressId());
Long ntwkId = null;
if (ip.getAssociatedWithNetworkId() != null) {
ntwkId = ip.getAssociatedWithNetworkId();
} else {
@ -234,7 +236,7 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
}
if (ntwkId == null) {
throw new InvalidParameterValueException("Unable to create port forwarding rule for the ipAddress id=" + ipAddressId +
" as ip is not associated with any network and no networkId is passed in");
" as ip is not associated with any network and no networkId is passed in", null);
}
return ntwkId;
}
@ -281,7 +283,7 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
public void create() {
// cidr list parameter is deprecated
if (cidrlist != null) {
throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall rule for the specific cidr, please refer to createFirewallRule command");
throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall rule for the specific cidr, please refer to createFirewallRule command", null);
}
try {
@ -324,7 +326,7 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
private IpAddress getIp() {
IpAddress ip = _networkService.getIp(ipAddressId);
if (ip == null) {
throw new InvalidParameterValueException("Unable to find ip address by id " + ipAddressId);
throw new InvalidParameterValueException("Unable to find ip address by id", null);
}
return ip;
}
@ -348,10 +350,15 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
public FirewallRuleType getType() {
return FirewallRuleType.User;
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.FirewallRule;
}
@Override
public TrafficType getTrafficType() {
return null;
}
}

View File

@ -46,27 +46,27 @@ public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd {
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@IdentityMapper(entityTableName="physical_network")
@Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="the Physical Network ID the network belongs to")
private Long physicalNetworkId;
@Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, required=true, description="the gateway of the Private gateway")
private String gateway;
@Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, required=true, description="the netmask of the Private gateway")
private String netmask;
@Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, required=true, description="the IP address of the Private gateaway")
private String ipAddress;
@Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, required=true, description="the Vlan for the private gateway")
private String vlan;
@IdentityMapper(entityTableName="vpc")
@Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, required=true, description="the VPC network belongs to")
private Long vpcId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -78,7 +78,7 @@ public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd {
public String getVlan() {
return vlan;
}
public String getNetmask() {
return netmask;
}
@ -86,11 +86,11 @@ public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd {
public String getStartIp() {
return ipAddress;
}
public Long getPhysicalNetworkId() {
return physicalNetworkId;
}
public Long getVpcId() {
return vpcId;
}
@ -102,8 +102,8 @@ public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd {
public String getCommandName() {
return s_name;
}
@Override
public void create() throws ResourceAllocationException {
PrivateGateway result = null;
@ -118,17 +118,17 @@ public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
}
if (result != null) {
this.setEntityId(result.getId());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create private gateway");
}
}
@Override
public void execute() throws InsufficientCapacityException, ConcurrentOperationException,
ResourceAllocationException, ResourceUnavailableException {
ResourceAllocationException, ResourceUnavailableException {
PrivateGateway result = _vpcService.applyVpcPrivateGateway(getEntityId());
if (result != null) {
PrivateGatewayResponse response = _responseGenerator.createPrivateGatewayResponse(result);
@ -138,7 +138,7 @@ public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create private gateway");
}
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
@ -153,13 +153,13 @@ public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd {
public String getEventDescription() {
return "creating private gateway";
}
@Override
public String getEntityTable() {
return "vpc_gateways";
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.vpcSyncObject;
@ -169,11 +169,11 @@ public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd {
public Long getSyncObjId() {
Vpc vpc = _vpcService.getVpc(vpcId);
if (vpc == null) {
throw new InvalidParameterValueException("Invalid id is specified for the vpc");
throw new InvalidParameterValueException("Invalid id is specified for the vpc", null);
}
return vpc.getId();
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.PrivateGateway;

View File

@ -56,6 +56,7 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd {
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public String getEntityTable() {
return "projects";
}
@ -95,7 +96,7 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd {
Account caller = UserContext.current().getCaller();
if ((accountName != null && domainId == null) || (domainId != null && accountName == null)) {
throw new InvalidParameterValueException("Account name and domain id must be specified together");
throw new InvalidParameterValueException("Account name and domain id must be specified together", null);
}
if (accountName != null) {

View File

@ -45,7 +45,7 @@ public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd {
@Parameter(name="iprange", type=CommandType.STRING, required=false, description="the range of ip addresses to allocate to vpn clients. The first ip in the range will be taken by the vpn server")
private String ipRange;
@Deprecated
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="an optional account for the VPN. Must be used with domainId.")
private String accountName;
@ -54,46 +54,47 @@ public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd {
@IdentityMapper(entityTableName="domain")
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="an optional domainId for the VPN. If the account parameter is used, domainId must also be used.")
private Long domainId;
@Parameter(name = ApiConstants.OPEN_FIREWALL, type = CommandType.BOOLEAN, description = "if true, firewall rule for source/end pubic port is automatically created; if false - firewall rule has to be created explicitely. Has value true by default")
private Boolean openFirewall;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@Override
public String getEntityTable() {
return "user_ip_address";
return "user_ip_address";
}
public Long getPublicIpId() {
return publicIpId;
}
public String getAccountName() {
return accountName;
}
public Long getDomainId() {
return domainId;
}
public String getIpRange() {
return ipRange;
}
public void setIpRange(String ipRange) {
this.ipRange = ipRange;
}
public Boolean getOpenFirewall() {
if (openFirewall != null) {
return openFirewall;
} else {
return true;
}
return publicIpId;
}
public String getAccountName() {
return accountName;
}
public Long getDomainId() {
return domainId;
}
public String getIpRange() {
return ipRange;
}
public void setIpRange(String ipRange) {
this.ipRange = ipRange;
}
public Boolean getOpenFirewall() {
if (openFirewall != null) {
return openFirewall;
} else {
return true;
}
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@ -104,42 +105,42 @@ public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd {
return s_name;
}
@Override
public long getEntityOwnerId() {
IpAddress ip = _networkService.getIp(publicIpId);
if (ip == null) {
throw new InvalidParameterValueException("Unable to find ip address by id=" + publicIpId);
}
return ip.getAccountId();
@Override
public long getEntityOwnerId() {
IpAddress ip = _networkService.getIp(publicIpId);
if (ip == null) {
throw new InvalidParameterValueException("Unable to find ip address by id", null);
}
return ip.getAccountId();
}
@Override
public String getEventDescription() {
return "Create Remote Access VPN for account " + getEntityOwnerId() + " using public ip id=" + publicIpId;
}
@Override
public String getEventDescription() {
return "Create Remote Access VPN for account " + getEntityOwnerId() + " using public ip id=" + publicIpId;
}
@Override
public String getEventType() {
return EventTypes.EVENT_REMOTE_ACCESS_VPN_CREATE;
}
@Override
public String getEventType() {
return EventTypes.EVENT_REMOTE_ACCESS_VPN_CREATE;
}
public long getNetworkId() {
IpAddress ip = _entityMgr.findById(IpAddress.class, getPublicIpId());
Long ntwkId = null;
if (ip.getAssociatedWithNetworkId() != null) {
ntwkId = ip.getAssociatedWithNetworkId();
}
if (ntwkId == null) {
throw new InvalidParameterValueException("Unable to create remote access vpn for the ipAddress id=" + getPublicIpId() +
" as ip is not associated with any network and no networkId is passed in");
" as ip is not associated with any network and no networkId is passed in", null);
}
return ntwkId;
}
@Override
public void create() {
try {
@ -172,8 +173,8 @@ public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd {
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
@ -187,7 +188,7 @@ public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd {
private IpAddress getIp() {
IpAddress ip = _networkService.getIp(publicIpId);
if (ip == null) {
throw new InvalidParameterValueException("Unable to find ip address by id " + publicIpId);
throw new InvalidParameterValueException("Unable to find ip address by id", null);
}
return ip;
}

View File

@ -60,9 +60,10 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public String getEntityTable() {
return "snapshots";
return "snapshots";
}
public String getAccountName() {
@ -100,23 +101,23 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
@Override
public long getEntityOwnerId() {
Volume volume = _entityMgr.findById(Volume.class, getVolumeId());
if (volume == null) {
throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId);
throw new InvalidParameterValueException("Unable to find volume by id", null);
}
Account account = _accountService.getAccount(volume.getAccountId());
//Can create templates for enabled projects/accounts only
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
Project project = _projectService.findByProjectAccountId(volume.getAccountId());
Project project = _projectService.findByProjectAccountId(volume.getAccountId());
if (project.getState() != Project.State.Active) {
throw new PermissionDeniedException("Can't add resources to the project id=" + project.getId() + " in state=" + project.getState() + " as it's no longer active");
}
} else if (account.getState() == Account.State.disabled) {
throw new PermissionDeniedException("The owner of template is disabled: " + account);
}
return volume.getAccountId();
}

View File

@ -45,11 +45,11 @@ public class CreateSnapshotPolicyCmd extends BaseCmd {
private Integer maxSnaps;
@Parameter(name=ApiConstants.SCHEDULE, type=CommandType.STRING, required=true, description="time the snapshot is scheduled to be taken. " +
"Format is:" +
"* if HOURLY, MM" +
"* if DAILY, MM:HH" +
"* if WEEKLY, MM:HH:DD (1-7)" +
"* if MONTHLY, MM:HH:DD (1-28)")
"Format is:" +
"* if HOURLY, MM" +
"* if DAILY, MM:HH" +
"* if WEEKLY, MM:HH:DD (1-7)" +
"* if MONTHLY, MM:HH:DD (1-28)")
private String schedule;
@Parameter(name=ApiConstants.TIMEZONE, type=CommandType.STRING, required=true, description="Specifies a timezone for this command. For more information on the timezone parameter, see Time Zone Format.")
@ -93,30 +93,30 @@ public class CreateSnapshotPolicyCmd extends BaseCmd {
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
Volume volume = _entityMgr.findById(Volume.class, getVolumeId());
if (volume == null) {
throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId);
throw new InvalidParameterValueException("Unable to find volume by id", null);
}
Account account = _accountService.getAccount(volume.getAccountId());
//Can create templates for enabled projects/accounts only
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
Project project = _projectService.findByProjectAccountId(volume.getAccountId());
Project project = _projectService.findByProjectAccountId(volume.getAccountId());
if (project.getState() != Project.State.Active) {
PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the specified project id in state=" + project.getState() + " as it's no longer active");
PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the specified project id in state=" + project.getState() + " as it's no longer active");
ex.addProxyObject(project, project.getId(), "projectId");
throw ex;
}
} else if (account.getState() == Account.State.disabled) {
throw new PermissionDeniedException("The owner of template is disabled: " + account);
}
return volume.getAccountId();
}
@Override
public void execute(){
SnapshotPolicy result = _snapshotService.createPolicy(this, _accountService.getAccount(getEntityOwnerId()));

View File

@ -29,7 +29,6 @@ import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.vpc.PrivateGateway;
import com.cloud.network.vpc.StaticRoute;
import com.cloud.network.vpc.VpcGateway;
import com.cloud.user.UserContext;
@ -42,12 +41,12 @@ import com.cloud.user.UserContext;
public class CreateStaticRouteCmd extends BaseAsyncCreateCmd{
private static final String s_name = "createstaticrouteresponse";
public static final Logger s_logger = Logger.getLogger(CreateStaticRouteCmd.class.getName());
@IdentityMapper(entityTableName="vpc_gateways")
@Parameter(name=ApiConstants.GATEWAY_ID, type=CommandType.LONG, required=true,
description="the gateway id we are creating static route for")
description="the gateway id we are creating static route for")
private Long gatewayId;
@Parameter(name = ApiConstants.CIDR, required = true, type = CommandType.STRING, description = "static route cidr")
private String cidr;
@ -115,7 +114,7 @@ public class CreateStaticRouteCmd extends BaseAsyncCreateCmd{
}
}
}
@Override
public String getCommandName() {
return s_name;
@ -123,13 +122,13 @@ public class CreateStaticRouteCmd extends BaseAsyncCreateCmd{
@Override
public long getEntityOwnerId() {
VpcGateway gateway = _vpcService.getVpcGateway(gatewayId);
if (gateway == null) {
throw new InvalidParameterValueException("Invalid gateway id is specified");
}
return _vpcService.getVpc(gateway.getVpcId()).getAccountId();
VpcGateway gateway = _vpcService.getVpcGateway(gatewayId);
if (gateway == null) {
throw new InvalidParameterValueException("Invalid gateway id is specified", null);
}
return _vpcService.getVpc(gateway.getVpcId()).getAccountId();
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.vpcSyncObject;
@ -139,11 +138,11 @@ public class CreateStaticRouteCmd extends BaseAsyncCreateCmd{
public Long getSyncObjId() {
VpcGateway gateway = _vpcService.getVpcGateway(gatewayId);
if (gateway == null) {
throw new InvalidParameterValueException("Invalid id is specified for the gateway");
throw new InvalidParameterValueException("Invalid id is specified for the gateway", null);
}
return gateway.getVpcId();
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.StaticRoute;

View File

@ -41,7 +41,7 @@ import com.cloud.user.UserContext;
@Implementation(responseObject = StoragePoolResponse.class, description = "Creates a template of a virtual machine. " + "The virtual machine must be in a STOPPED state. "
+ "A template created from this command is automatically designated as a private template visible to the account that created it.")
public class CreateTemplateCmd extends BaseAsyncCreateCmd {
public class CreateTemplateCmd extends BaseAsyncCreateCmd {
public static final Logger s_logger = Logger.getLogger(CreateTemplateCmd.class.getName());
private static final String s_name = "createtemplateresponse";
@ -91,16 +91,17 @@ import com.cloud.user.UserContext;
@Parameter(name=ApiConstants.TEMPLATE_TAG, type=CommandType.STRING, description="the tag for this template.")
private String templateTag;
@Parameter(name=ApiConstants.DETAILS, type=CommandType.MAP, description="Template details in key/value pairs.")
protected Map details;
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public String getEntityTable() {
return "vm_template";
return "vm_template";
}
public Integer getBits() {
@ -154,17 +155,17 @@ import com.cloud.user.UserContext;
public String getTemplateTag() {
return templateTag;
}
public Map getDetails() {
if (details == null || details.isEmpty()) {
return null;
}
Collection paramsCollection = details.values();
Map params = (Map) (paramsCollection.toArray())[0];
return params;
if (details == null || details.isEmpty()) {
return null;
}
Collection paramsCollection = details.values();
Map params = (Map) (paramsCollection.toArray())[0];
return params;
}
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@ -188,29 +189,29 @@ import com.cloud.user.UserContext;
if (volume != null) {
accountId = volume.getAccountId();
} else {
throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId);
throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId, null);
}
} else {
Snapshot snapshot = _entityMgr.findById(Snapshot.class, snapshotId);
if (snapshot != null) {
accountId = snapshot.getAccountId();
} else {
throw new InvalidParameterValueException("Unable to find snapshot by id=" + snapshotId);
throw new InvalidParameterValueException("Unable to find snapshot by id=" + snapshotId, null);
}
}
Account account = _accountService.getAccount(accountId);
//Can create templates for enabled projects/accounts only
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
Project project = _projectService.findByProjectAccountId(accountId);
Project project = _projectService.findByProjectAccountId(accountId);
if (project.getState() != Project.State.Active) {
PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the specified project id in state=" + project.getState() + " as it's no longer active");
PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the specified project id in state=" + project.getState() + " as it's no longer active");
ex.addProxyObject(project, project.getId(), "projectId");
}
} else if (account.getState() == Account.State.disabled) {
throw new PermissionDeniedException("The owner of template is disabled: " + account);
}
return accountId;
}
@ -246,7 +247,7 @@ import com.cloud.user.UserContext;
this.setEntityId(template.getId());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR,
"Failed to create a template");
"Failed to create a template");
}
}
}

View File

@ -30,7 +30,6 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.IpAddress;
import com.cloud.network.Site2SiteVpnConnection;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@Implementation(description="Create site to site vpn connection", responseObject=Site2SiteVpnConnectionResponse.class)
public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd {
@ -53,18 +52,19 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd {
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@Override
public String getEntityTable() {
return "s2s_vpn_connection";
return "s2s_vpn_connection";
}
public Long getVpnGatewayId() {
return vpnGatewayId;
}
public Long getCustomerGatewayId() {
return customerGatewayId;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@ -75,21 +75,21 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd {
return s_name;
}
@Override
public long getEntityOwnerId() {
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
@Override
public String getEventDescription() {
return "Create site-to-site VPN connection";
}
@Override
public String getEventDescription() {
return "Create site-to-site VPN connection";
}
@Override
public String getEventType() {
return EventTypes.EVENT_S2S_CONNECTION_CREATE;
}
@Override
public String getEventType() {
return EventTypes.EVENT_S2S_CONNECTION_CREATE;
}
@Override
public void create() {
try {
@ -122,8 +122,8 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd {
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.vpcSyncObject;
@ -137,7 +137,7 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd {
private IpAddress getIp() {
IpAddress ip = _s2sVpnService.getVpnGatewayIp(vpnGatewayId);
if (ip == null) {
throw new InvalidParameterValueException("Unable to find ip address by vpn gateway id " + vpnGatewayId);
throw new InvalidParameterValueException("Unable to find ip address by vpn gateway id " + vpnGatewayId, null);
}
return ip;
}

View File

@ -45,9 +45,9 @@ public class CreateVpnGatewayCmd extends BaseAsyncCmd {
/////////////////////////////////////////////////////
public String getEntityTable() {
return "user_ip_address";
return "user_ip_address";
}
public Long getPublicIpId() {
return publicIpId;
}
@ -62,27 +62,27 @@ public class CreateVpnGatewayCmd extends BaseAsyncCmd {
return s_name;
}
@Override
public long getEntityOwnerId() {
IpAddress ip = _networkService.getIp(publicIpId);
if (ip == null) {
throw new InvalidParameterValueException("Unable to find ip address by id=" + publicIpId);
}
return ip.getAccountId();
@Override
public long getEntityOwnerId() {
IpAddress ip = _networkService.getIp(publicIpId);
if (ip == null) {
throw new InvalidParameterValueException("Unable to find ip address by id", null);
}
return ip.getAccountId();
}
@Override
public String getEventDescription() {
return "Create site-to-site VPN gateway for account " + getEntityOwnerId() + " using public ip id=" + publicIpId;
}
@Override
public String getEventDescription() {
return "Create site-to-site VPN gateway for account " + getEntityOwnerId() + " using public ip id=" + publicIpId;
}
@Override
public String getEventType() {
return EventTypes.EVENT_S2S_VPN_GATEWAY_CREATE;
}
@Override
public String getEventType() {
return EventTypes.EVENT_S2S_VPN_GATEWAY_CREATE;
}
@Override
public void execute(){
Site2SiteVpnGateway result = _s2sVpnService.createVpnGateway(this);
@ -94,7 +94,7 @@ public class CreateVpnGatewayCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create VPN gateway");
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.vpcSyncObject;
@ -108,7 +108,7 @@ public class CreateVpnGatewayCmd extends BaseAsyncCmd {
private IpAddress getIp() {
IpAddress ip = _networkService.getIp(publicIpId);
if (ip == null) {
throw new InvalidParameterValueException("Unable to find ip address by id " + publicIpId);
throw new InvalidParameterValueException("Unable to find ip address by id", null);
}
return ip;
}

View File

@ -39,7 +39,7 @@ public class DeleteAccountFromProjectCmd extends BaseAsyncCmd {
@IdentityMapper(entityTableName="projects")
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, required=true, description="id of the project to remove the account from")
private Long projectId;
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, required=true, description="name of the account to be removed from the project")
private String accountName;
@ -48,7 +48,7 @@ public class DeleteAccountFromProjectCmd extends BaseAsyncCmd {
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
@ -78,24 +78,24 @@ public class DeleteAccountFromProjectCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete account from the project");
}
}
@Override
public long getEntityOwnerId() {
Project project= _projectService.getProject(projectId);
//verify input parameters
if (project == null) {
throw new InvalidParameterValueException("Unable to find project by id " + projectId);
throw new InvalidParameterValueException("Unable to find project by id", null);
}
return _projectService.getProjectOwner(projectId).getId();
}
@Override
public String getEventType() {
return EventTypes.EVENT_PROJECT_ACCOUNT_REMOVE;
}
@Override
public String getEventDescription() {
return "Removing account " + accountName + " from project: " + projectId;

View File

@ -27,7 +27,6 @@ import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.NetworkACL;
import com.cloud.user.UserContext;
@Implementation(description="Deletes a firewall rule", responseObject=SuccessResponse.class)
@ -54,7 +53,7 @@ public class DeleteFirewallRuleCmd extends BaseAsyncCmd {
public Long getId() {
return id;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@ -62,7 +61,7 @@ public class DeleteFirewallRuleCmd extends BaseAsyncCmd {
public String getCommandName() {
return s_name;
}
@Override
public String getEventType() {
return EventTypes.EVENT_FIREWALL_CLOSE;
@ -72,25 +71,25 @@ public class DeleteFirewallRuleCmd extends BaseAsyncCmd {
public String getEventDescription() {
return ("Deleting firewall rule id=" + id);
}
@Override
public long getEntityOwnerId() {
if (ownerId == null) {
FirewallRule rule = _entityMgr.findById(NetworkACL.class, id);
FirewallRule rule = _entityMgr.findById(FirewallRule.class, id);
if (rule == null) {
throw new InvalidParameterValueException("Unable to find firewall rule by id=" + id);
throw new InvalidParameterValueException("Unable to find firewall rule by id", null);
} else {
ownerId = _entityMgr.findById(NetworkACL.class, id).getAccountId();
ownerId = _entityMgr.findById(FirewallRule.class, id).getAccountId();
}
}
return ownerId;
}
@Override
public void execute() throws ResourceUnavailableException {
UserContext.current().setEventDetails("Rule Id: " + id);
boolean result = _firewallService.revokeFirewallRule(id, true);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);
@ -98,8 +97,8 @@ public class DeleteFirewallRuleCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete firewall rule");
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
@ -109,7 +108,7 @@ public class DeleteFirewallRuleCmd extends BaseAsyncCmd {
public Long getSyncObjId() {
return _firewallService.getFirewallRule(id).getNetworkId();
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.FirewallRule;

View File

@ -42,7 +42,7 @@ public class DeleteIpForwardingRuleCmd extends BaseAsyncCmd {
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the id of the forwarding rule")
private Long id;
// unexposed parameter needed for events logging
@IdentityMapper(entityTableName="account")
@Parameter(name=ApiConstants.ACCOUNT_ID, type=CommandType.LONG, expose=false)
@ -67,8 +67,8 @@ public class DeleteIpForwardingRuleCmd extends BaseAsyncCmd {
@Override
public void execute(){
UserContext.current().setEventDetails("Rule Id: "+id);
boolean result = _firewallService.revokeRelatedFirewallRule(id, true);
result = result && _rulesService.revokeStaticNatRule(id, true);
boolean result = _firewallService.revokeRelatedFirewallRule(id, true);
result = result && _rulesService.revokeStaticNatRule(id, true);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
@ -83,7 +83,7 @@ public class DeleteIpForwardingRuleCmd extends BaseAsyncCmd {
if (ownerId == null) {
FirewallRule rule = _entityMgr.findById(FirewallRule.class, id);
if (rule == null) {
throw new InvalidParameterValueException("Unable to find static nat rule by id: " + id);
throw new InvalidParameterValueException("Unable to find static nat rule by id", null);
} else {
ownerId = rule.getAccountId();
}
@ -100,7 +100,7 @@ public class DeleteIpForwardingRuleCmd extends BaseAsyncCmd {
public String getEventDescription() {
return ("Deleting an ipforwarding 1:1 NAT rule id:"+id);
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
@ -110,7 +110,7 @@ public class DeleteIpForwardingRuleCmd extends BaseAsyncCmd {
public Long getSyncObjId() {
return _rulesService.getFirewallRule(id).getNetworkId();
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.FirewallRule;

View File

@ -24,8 +24,8 @@ import com.cloud.api.ServerApiException;
import com.cloud.api.response.SuccessResponse;
import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.network.rules.StickinessPolicy;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.network.rules.StickinessPolicy;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@ -101,11 +101,11 @@ public class DeleteLBStickinessPolicyCmd extends BaseAsyncCmd {
StickinessPolicy policy = _entityMgr.findById(StickinessPolicy.class,
getId());
if (policy == null) {
throw new InvalidParameterValueException("Unable to find LB stickiness rule: " + id);
throw new InvalidParameterValueException("Unable to find LB stickiness rule by id", null);
}
LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
if (lb == null) {
throw new InvalidParameterValueException("Unable to find load balancer rule for stickiness rule: " + id);
throw new InvalidParameterValueException("Unable to find load balancer rule for stickiness rule by id", null);
}
return lb.getNetworkId();
}

View File

@ -78,13 +78,13 @@ public class DeleteLoadBalancerRuleCmd extends BaseAsyncCmd {
public String getEventDescription() {
return "deleting load balancer: " + getId();
}
@Override
public void execute(){
UserContext.current().setEventDetails("Load balancer Id: "+getId());
boolean result = _firewallService.revokeRelatedFirewallRule(id, true);
result = result && _lbService.deleteLoadBalancerRule(id, true);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);
@ -92,7 +92,7 @@ public class DeleteLoadBalancerRuleCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete load balancer");
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
@ -100,13 +100,13 @@ public class DeleteLoadBalancerRuleCmd extends BaseAsyncCmd {
@Override
public Long getSyncObjId() {
LoadBalancer lb = _lbService.findById(id);
if(lb == null){
throw new InvalidParameterValueException("Unable to find load balancer rule: " + id);
}
LoadBalancer lb = _lbService.findById(id);
if(lb == null){
throw new InvalidParameterValueException("Unable to find load balancer rule by id", null);
}
return lb.getNetworkId();
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.FirewallRule;

View File

@ -29,7 +29,7 @@ import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.rules.NetworkACL;
import com.cloud.network.rules.FirewallRule;
import com.cloud.user.UserContext;
@Implementation(description="Deletes a Network ACL", responseObject=SuccessResponse.class)
@ -56,7 +56,7 @@ public class DeleteNetworkACLCmd extends BaseAsyncCmd {
public Long getId() {
return id;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@ -64,7 +64,7 @@ public class DeleteNetworkACLCmd extends BaseAsyncCmd {
public String getCommandName() {
return s_name;
}
@Override
public String getEventType() {
return EventTypes.EVENT_FIREWALL_CLOSE;
@ -74,25 +74,25 @@ public class DeleteNetworkACLCmd extends BaseAsyncCmd {
public String getEventDescription() {
return ("Deleting Network ACL id=" + id);
}
@Override
public long getEntityOwnerId() {
if (ownerId == null) {
NetworkACL rule = _networkACLService.getNetworkACL(id);
FirewallRule rule = _networkACLService.getNetworkACL(id);
if (rule == null) {
throw new InvalidParameterValueException("Unable to find network ACL by id=" + id);
throw new InvalidParameterValueException("Unable to find network ACL by id", null);
} else {
ownerId = rule.getAccountId();
}
}
return ownerId;
}
@Override
public void execute() throws ResourceUnavailableException {
UserContext.current().setEventDetails("Network ACL Id: " + id);
boolean result = _networkACLService.revokeNetworkACL(id, true);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);
@ -100,8 +100,8 @@ public class DeleteNetworkACLCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete network ACL");
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
@ -111,7 +111,7 @@ public class DeleteNetworkACLCmd extends BaseAsyncCmd {
public Long getSyncObjId() {
return _firewallService.getFirewallRule(id).getNetworkId();
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.FirewallRule;

View File

@ -58,7 +58,7 @@ public class DeleteNetworkCmd extends BaseAsyncCmd{
public String getCommandName() {
return s_name;
}
@Override
public void execute(){
UserContext.current().setEventDetails("Network Id: " + id);
@ -70,8 +70,8 @@ public class DeleteNetworkCmd extends BaseAsyncCmd{
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete network");
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
@ -81,22 +81,22 @@ public class DeleteNetworkCmd extends BaseAsyncCmd{
public Long getSyncObjId() {
return id;
}
@Override
public String getEventType() {
return EventTypes.EVENT_NETWORK_DELETE;
}
@Override
public String getEventDescription() {
return "Deleting network: " + id;
}
@Override
public long getEntityOwnerId() {
Network network = _networkService.getNetwork(id);
if (network == null) {
throw new InvalidParameterValueException("Networkd id=" + id + " doesn't exist");
throw new InvalidParameterValueException("Couldn't find network by id", null);
} else {
return _networkService.getNetwork(id).getAccountId();
}

View File

@ -52,7 +52,7 @@ public class DeletePortForwardingRuleCmd extends BaseAsyncCmd {
public Long getId() {
return id;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@ -60,7 +60,7 @@ public class DeletePortForwardingRuleCmd extends BaseAsyncCmd {
public String getCommandName() {
return s_name;
}
@Override
public String getEventType() {
return EventTypes.EVENT_NET_RULE_DELETE;
@ -70,28 +70,28 @@ public class DeletePortForwardingRuleCmd extends BaseAsyncCmd {
public String getEventDescription() {
return ("Deleting port forwarding rule for id=" + id);
}
@Override
public long getEntityOwnerId() {
if (ownerId == null) {
PortForwardingRule rule = _entityMgr.findById(PortForwardingRule.class, id);
if (rule == null) {
throw new InvalidParameterValueException("Unable to find port forwarding rule by id=" + id);
throw new InvalidParameterValueException("Unable to find port forwarding rule by id", null);
} else {
ownerId = _entityMgr.findById(PortForwardingRule.class, id).getAccountId();
}
}
return ownerId;
}
@Override
public void execute(){
UserContext.current().setEventDetails("Rule Id: "+id);
//revoke corresponding firewall rule first
boolean result = _firewallService.revokeRelatedFirewallRule(id, true);
result = result && _rulesService.revokePortForwardingRule(id, true);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);
@ -99,8 +99,8 @@ public class DeletePortForwardingRuleCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete port forwarding rule");
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
@ -110,7 +110,7 @@ public class DeletePortForwardingRuleCmd extends BaseAsyncCmd {
public Long getSyncObjId() {
return _rulesService.getPortForwardigRule(id).getNetworkId();
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.FirewallRule;

View File

@ -54,7 +54,7 @@ public class DeletePrivateGatewayCmd extends BaseAsyncCmd {
public Long getId() {
return id;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@ -62,7 +62,7 @@ public class DeletePrivateGatewayCmd extends BaseAsyncCmd {
public String getCommandName() {
return s_name;
}
@Override
public String getEventType() {
return EventTypes.EVENT_PRIVATE_GATEWAY_DELETE;
@ -72,12 +72,12 @@ public class DeletePrivateGatewayCmd extends BaseAsyncCmd {
public String getEventDescription() {
return ("Deleting private gateway id=" + id);
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
@Override
public void execute() throws ResourceUnavailableException, ConcurrentOperationException {
UserContext.current().setEventDetails("Network ACL Id: " + id);
@ -89,8 +89,8 @@ public class DeletePrivateGatewayCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete private gateway");
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.vpcSyncObject;
@ -100,14 +100,14 @@ public class DeletePrivateGatewayCmd extends BaseAsyncCmd {
public Long getSyncObjId() {
VpcGateway gateway = _vpcService.getVpcPrivateGateway(getId());
if (gateway == null) {
throw new InvalidParameterValueException("Invalid private gateway id");
throw new InvalidParameterValueException("Invalid private gateway id", null);
}
return gateway.getVpcId();
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.PrivateGateway;
}
}

View File

@ -70,26 +70,26 @@ public class DeleteProjectCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete project");
}
}
@Override
public String getEventType() {
return EventTypes.EVENT_PROJECT_DELETE;
}
@Override
public String getEventDescription() {
return "Deleting project: " + id;
}
@Override
public long getEntityOwnerId() {
Project project= _projectService.getProject(id);
//verify input parameters
if (project == null) {
throw new InvalidParameterValueException("Unable to find project by id " + id);
throw new InvalidParameterValueException("Unable to find project by id", null);
}
return _projectService.getProjectOwner(id).getId();
}
}

View File

@ -37,7 +37,7 @@ public class DeleteRemoteAccessVpnCmd extends BaseAsyncCmd {
@IdentityMapper(entityTableName="user_ip_address")
@Parameter(name=ApiConstants.PUBLIC_IP_ID, type=CommandType.LONG, required=true, description="public ip address id of the vpn server")
private Long publicIpId;
// unexposed parameter needed for events logging
@IdentityMapper(entityTableName="account")
@Parameter(name=ApiConstants.ACCOUNT_ID, type=CommandType.LONG, expose=false)
@ -45,43 +45,43 @@ public class DeleteRemoteAccessVpnCmd extends BaseAsyncCmd {
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
if (ownerId == null) {
RemoteAccessVpn vpnEntity = _entityMgr.findById(RemoteAccessVpn.class, publicIpId);
if(vpnEntity != null)
return vpnEntity.getAccountId();
throw new InvalidParameterValueException("The specified public ip is not allocated to any account");
}
return ownerId;
@Override
public long getEntityOwnerId() {
if (ownerId == null) {
RemoteAccessVpn vpnEntity = _entityMgr.findById(RemoteAccessVpn.class, publicIpId);
if(vpnEntity != null)
return vpnEntity.getAccountId();
throw new InvalidParameterValueException("The specified public ip is not allocated to any account", null);
}
return ownerId;
}
@Override
public String getEventDescription() {
return "Delete Remote Access VPN for account " + getEntityOwnerId() + " for ip id=" + publicIpId;
}
@Override
public String getEventDescription() {
return "Delete Remote Access VPN for account " + getEntityOwnerId() + " for ip id=" + publicIpId;
}
@Override
public String getEventType() {
return EventTypes.EVENT_REMOTE_ACCESS_VPN_DESTROY;
}
@Override
public String getEventType() {
return EventTypes.EVENT_REMOTE_ACCESS_VPN_DESTROY;
}
@Override
public void execute() throws ResourceUnavailableException {
_ravService.destroyRemoteAccessVpn(publicIpId);
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
@ -91,5 +91,5 @@ public class DeleteRemoteAccessVpnCmd extends BaseAsyncCmd {
public Long getSyncObjId() {
return _ravService.getRemoteAccessVpn(publicIpId).getNetworkId();
}
}

View File

@ -12,18 +12,18 @@
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.api.commands;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseCmd;
import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.SuccessResponse;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceInUseException;
import com.cloud.user.UserContext;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseCmd;
import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.SuccessResponse;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceInUseException;
import com.cloud.user.UserContext;
@Implementation(description="Deletes security group", responseObject=SuccessResponse.class)
public class DeleteSecurityGroupCmd extends BaseCmd {
@ -40,7 +40,7 @@ public class DeleteSecurityGroupCmd extends BaseCmd {
@IdentityMapper(entityTableName="domain")
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the domain ID of account owning the security group")
private Long domainId;
@IdentityMapper(entityTableName="projects")
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="the project of the security group")
private Long projectId;
@ -48,7 +48,7 @@ public class DeleteSecurityGroupCmd extends BaseCmd {
@IdentityMapper(entityTableName="security_group")
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="The ID of the security group. Mutually exclusive with name parameter")
private Long id;
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="The ID of the security group. Mutually exclusive with id parameter")
private String name;
@ -64,27 +64,27 @@ public class DeleteSecurityGroupCmd extends BaseCmd {
public Long getDomainId() {
return domainId;
}
public Long getProjectId() {
return projectId;
}
public Long getId() {
if (id != null && name != null) {
throw new InvalidParameterValueException("name and id parameters are mutually exclusive");
throw new InvalidParameterValueException("name and id parameters are mutually exclusive", null);
}
if (name != null) {
id = _responseGenerator.getSecurityGroupId(name, getEntityOwnerId());
if (id == null) {
throw new InvalidParameterValueException("Unable to find security group by name " + name + " for the account id=" + getEntityOwnerId());
throw new InvalidParameterValueException("Unable to find security group by name " + name + " for the account id=" + getEntityOwnerId(), null);
}
}
if (id == null) {
throw new InvalidParameterValueException("Either id or name parameter is requred by deleteSecurityGroup command");
throw new InvalidParameterValueException("Either id or name parameter is requred by deleteSecurityGroup command", null);
}
return id;
}
@ -98,17 +98,17 @@ public class DeleteSecurityGroupCmd extends BaseCmd {
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
if (accountId == null) {
return UserContext.current().getCaller().getId();
}
return accountId;
}
@Override
public void execute(){
try{

View File

@ -57,7 +57,7 @@ public class DeleteStaticRouteCmd extends BaseAsyncCmd{
public Long getId() {
return id;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@ -65,7 +65,7 @@ public class DeleteStaticRouteCmd extends BaseAsyncCmd{
public String getCommandName() {
return s_name;
}
@Override
public String getEventType() {
return EventTypes.EVENT_STATIC_ROUTE_DELETE;
@ -75,25 +75,25 @@ public class DeleteStaticRouteCmd extends BaseAsyncCmd{
public String getEventDescription() {
return ("Deleting static route id=" + id);
}
@Override
public long getEntityOwnerId() {
if (ownerId == null) {
StaticRoute route = _entityMgr.findById(StaticRoute.class, id);
if (route == null) {
throw new InvalidParameterValueException("Unable to find static route by id=" + id);
throw new InvalidParameterValueException("Unable to find static route by id", null);
} else {
ownerId = route.getAccountId();
}
}
return ownerId;
}
@Override
public void execute() throws ResourceUnavailableException {
UserContext.current().setEventDetails("Route Id: " + id);
boolean result = _vpcService.revokeStaticRoute(id);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);
@ -101,8 +101,8 @@ public class DeleteStaticRouteCmd extends BaseAsyncCmd{
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete static route");
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.vpcSyncObject;
@ -112,11 +112,11 @@ public class DeleteStaticRouteCmd extends BaseAsyncCmd{
public Long getSyncObjId() {
StaticRoute route = _vpcService.getStaticRoute(id);
if (route == null) {
throw new InvalidParameterValueException("Invalid id is specified for the static route");
throw new InvalidParameterValueException("Invalid id is specified for the static route", null);
}
return route.getVpcId();
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.StaticRoute;

View File

@ -111,39 +111,40 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
@IdentityMapper(entityTableName="host")
@Parameter(name=ApiConstants.HOST_ID, type=CommandType.LONG, description="destination Host ID to deploy the VM to - parameter available for root admin only")
private Long hostId;
@IdentityMapper(entityTableName="security_group")
@Parameter(name=ApiConstants.SECURITY_GROUP_IDS, type=CommandType.LIST, collectionType=CommandType.LONG, description="comma separated list of security groups id that going to be applied to the virtual machine. Should be passed only when vm is created from a zone with Basic Network support. Mutually exclusive with securitygroupnames parameter")
private List<Long> securityGroupIdList;
@Parameter(name=ApiConstants.SECURITY_GROUP_NAMES, type=CommandType.LIST, collectionType=CommandType.STRING, description="comma separated list of security groups names that going to be applied to the virtual machine. Should be passed only when vm is created from a zone with Basic Network support. Mutually exclusive with securitygroupids parameter")
private List<String> securityGroupNameList;
@Parameter(name = ApiConstants.IP_NETWORK_LIST, type = CommandType.MAP, description = "ip to network mapping. Can't be specified with networkIds parameter. Example: iptonetworklist[0].ip=10.10.10.11&iptonetworklist[0].networkid=204 - requests to use ip 10.10.10.11 in network id=204")
private Map ipToNetworkList;
@Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, description="the ip address for default vm's network")
private String ipAddress;
@Parameter(name=ApiConstants.KEYBOARD, type=CommandType.STRING, description="an optional keyboard device type for the virtual machine. valid value can be one of de,de-ch,es,fi,fr,fr-be,fr-ch,is,it,jp,nl-be,no,pt,uk,us")
private String keyboard;
@IdentityMapper(entityTableName="projects")
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="Deploy vm for the project")
private Long projectId;
@Parameter(name=ApiConstants.START_VM, type=CommandType.BOOLEAN, description="true if network offering supports specifying ip ranges; defaulted to true if not specified")
private Boolean startVm;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@Override
public String getEntityTable() {
return "vm_instance";
return "vm_instance";
}
public String getAccountName() {
if (accountName == null) {
return UserContext.current().getCaller().getAccountName();
@ -176,16 +177,16 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
public List<Long> getSecurityGroupIdList() {
if (securityGroupNameList != null && securityGroupIdList != null) {
throw new InvalidParameterValueException("securitygroupids parameter is mutually exclusive with securitygroupnames parameter");
throw new InvalidParameterValueException("securitygroupids parameter is mutually exclusive with securitygroupnames parameter", null);
}
//transform group names to ids here
if (securityGroupNameList != null) {
//transform group names to ids here
if (securityGroupNameList != null) {
List<Long> securityGroupIds = new ArrayList<Long>();
for (String groupName : securityGroupNameList) {
Long groupId = _responseGenerator.getSecurityGroupId(groupName, getEntityOwnerId());
if (groupId == null) {
throw new InvalidParameterValueException("Unable to find group by name " + groupName + " for account " + getEntityOwnerId());
throw new InvalidParameterValueException("Unable to find group by name " + groupName + " for account " + getEntityOwnerId(), null);
} else {
securityGroupIds.add(groupId);
}
@ -217,15 +218,15 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
}
public List<Long> getNetworkIds() {
if (ipToNetworkList != null) {
if (networkIds != null || ipAddress != null) {
throw new InvalidParameterValueException("ipToNetworkMap can't be specified along with networkIds or ipAddress");
} else {
List<Long> networks = new ArrayList<Long>();
networks.addAll(getIpToNetworkMap().keySet());
return networks;
}
}
if (ipToNetworkList != null) {
if (networkIds != null || ipAddress != null) {
throw new InvalidParameterValueException("ipToNetworkMap can't be specified along with networkIds or ipAddress", null);
} else {
List<Long> networks = new ArrayList<Long>();
networks.addAll(getIpToNetworkMap().keySet());
return networks;
}
}
return networkIds;
}
@ -240,14 +241,14 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
public Long getHostId() {
return hostId;
}
public boolean getStartVm() {
return startVm == null ? true : startVm;
}
private Map<Long, String> getIpToNetworkMap() {
if ((networkIds != null || ipAddress != null) && ipToNetworkList != null) {
throw new InvalidParameterValueException("NetworkIds and ipAddress can't be specified along with ipToNetworkMap parameter");
throw new InvalidParameterValueException("NetworkIds and ipAddress can't be specified along with ipToNetworkMap parameter", null);
}
Map<Long, String> ipToNetworkMap = null;
if (ipToNetworkList != null && !ipToNetworkList.isEmpty()) {
@ -257,11 +258,11 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
while (iter.hasNext()) {
HashMap<String, String> ips = (HashMap<String, String>) iter.next();
Long networkId = Long.valueOf(_responseGenerator.getIdentiyId("networks", ips.get("networkid")));
String requestedIp = (String) ips.get("ip");
String requestedIp = ips.get("ip");
ipToNetworkMap.put(networkId, requestedIp);
}
}
return ipToNetworkMap;
}
@ -284,7 +285,7 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
if (accountId == null) {
return UserContext.current().getCaller().getId();
}
return accountId;
}
@ -316,7 +317,7 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
@Override
public void execute(){
UserVm result;
if (getStartVm()) {
try {
UserContext.current().setEventDetails("Vm Id: "+getEntityId());
@ -339,7 +340,7 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
} else {
result = _userVmService.getUserVm(getEntityId());
}
if (result != null) {
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
response.setResponseName(getCommandName());
@ -357,24 +358,24 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
DataCenter zone = _configService.getZone(zoneId);
if (zone == null) {
throw new InvalidParameterValueException("Unable to find zone by id=" + zoneId);
throw new InvalidParameterValueException("Unable to find zone by id", null);
}
ServiceOffering serviceOffering = _configService.getServiceOffering(serviceOfferingId);
if (serviceOffering == null) {
throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
throw new InvalidParameterValueException("Unable to find service offering by id", null);
}
VirtualMachineTemplate template = _templateService.getTemplate(templateId);
// Make sure a valid template ID was specified
if (template == null) {
throw new InvalidParameterValueException("Unable to use template " + templateId);
throw new InvalidParameterValueException("Unable to use template " + templateId, null);
}
if (diskOfferingId != null) {
DiskOffering diskOffering = _configService.getDiskOffering(diskOfferingId);
if (diskOffering == null) {
throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
throw new InvalidParameterValueException("Unable to find disk offering by id", null);
}
}
@ -384,7 +385,7 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
} else {
if (zone.getNetworkType() == NetworkType.Basic) {
if (getNetworkIds() != null) {
throw new InvalidParameterValueException("Can't specify network Ids in Basic zone");
throw new InvalidParameterValueException("Can't specify network Ids in Basic zone", null);
} else {
vm = _userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, getSecurityGroupIdList(), owner, name,
displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), ipAddress, keyboard);
@ -395,7 +396,7 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
owner, name, displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), ipAddress, keyboard);
} else {
if (getSecurityGroupIdList() != null && !getSecurityGroupIdList().isEmpty()) {
throw new InvalidParameterValueException("Can't create vm with security groups; security group feature is not enabled per zone");
throw new InvalidParameterValueException("Can't create vm with security groups; security group feature is not enabled per zone", null);
}
vm = _userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, getNetworkIds(), owner, name, displayName,
diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), ipAddress, keyboard);

View File

@ -63,7 +63,7 @@ public class DetachIsoCmd extends BaseAsyncCmd {
if (vm != null) {
return vm.getAccountId();
} else {
throw new InvalidParameterValueException("Unable to find vm by id " + getVirtualMachineId());
throw new InvalidParameterValueException("Unable to find vm by id", null);
}
}
@ -76,7 +76,7 @@ public class DetachIsoCmd extends BaseAsyncCmd {
public String getEventDescription() {
return "detaching ISO from vm: " + getVirtualMachineId();
}
@Override
public void execute(){
boolean result = _templateService.detachIso(virtualMachineId);

View File

@ -41,7 +41,7 @@ public class DisableStaticNatCmd extends BaseAsyncCmd {
@IdentityMapper(entityTableName="user_ip_address")
@Parameter(name=ApiConstants.IP_ADDRESS_ID, type=CommandType.LONG, required=true, description="the public IP address id for which static nat feature is being disableed")
private Long ipAddressId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -49,7 +49,7 @@ public class DisableStaticNatCmd extends BaseAsyncCmd {
public Long getIpAddress() {
return ipAddressId;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@ -57,7 +57,7 @@ public class DisableStaticNatCmd extends BaseAsyncCmd {
public String getCommandName() {
return s_name;
}
@Override
public String getEventType() {
return EventTypes.EVENT_DISABLE_STATIC_NAT;
@ -67,16 +67,16 @@ public class DisableStaticNatCmd extends BaseAsyncCmd {
public String getEventDescription() {
return ("Disabling static nat for ip id=" + ipAddressId);
}
@Override
public long getEntityOwnerId() {
return _entityMgr.findById(IpAddress.class, ipAddressId).getAccountId();
}
@Override
public void execute() throws ResourceUnavailableException, NetworkRuleConflictException, InsufficientAddressCapacityException {
boolean result = _rulesService.disableStaticNat(ipAddressId);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);
@ -84,8 +84,8 @@ public class DisableStaticNatCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to disable static nat");
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
@ -99,7 +99,7 @@ public class DisableStaticNatCmd extends BaseAsyncCmd {
private IpAddress getIp() {
IpAddress ip = _networkService.getIp(ipAddressId);
if (ip == null) {
throw new InvalidParameterValueException("Unable to find ip address by id " + ipAddressId);
throw new InvalidParameterValueException("Unable to find ip address by id", null);
}
return ip;
}

View File

@ -42,7 +42,7 @@ public class DisassociateIPAddrCmd extends BaseAsyncCmd {
@IdentityMapper(entityTableName="user_ip_address")
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the id of the public ip address" +
" to disassociate")
" to disassociate")
private Long id;
// unexposed parameter needed for events logging
@ -77,7 +77,7 @@ public class DisassociateIPAddrCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to disassociate ip address");
}
}
@Override
public String getEventType() {
return EventTypes.EVENT_NET_IP_RELEASE;
@ -87,23 +87,23 @@ public class DisassociateIPAddrCmd extends BaseAsyncCmd {
public String getEventDescription() {
return ("Disassociating ip address with id=" + id);
}
@Override
public long getEntityOwnerId() {
if (ownerId == null) {
IpAddress ip = getIpAddress(id);
if (ip == null) {
throw new InvalidParameterValueException("Unable to find ip address by id=" + id);
throw new InvalidParameterValueException("Unable to find ip address by id", null);
}
ownerId = ip.getAccountId();
}
if (ownerId == null) {
return Account.ACCOUNT_ID_SYSTEM;
}
return ownerId;
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
@ -114,22 +114,22 @@ public class DisassociateIPAddrCmd extends BaseAsyncCmd {
IpAddress ip = getIpAddress(id);
return ip.getAssociatedWithNetworkId();
}
private IpAddress getIpAddress(long id) {
IpAddress ip = _entityMgr.findById(IpAddress.class, id);
if (ip == null) {
throw new InvalidParameterValueException("Unable to find ip address by id=" + id);
throw new InvalidParameterValueException("Unable to find ip address by id", null);
} else {
return ip;
}
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.IpAddress;
}
@Override
public Long getInstanceId() {
return getIpAddressId();

View File

@ -40,18 +40,18 @@ public class EnableStaticNatCmd extends BaseCmd{
@IdentityMapper(entityTableName="user_ip_address")
@Parameter(name=ApiConstants.IP_ADDRESS_ID, type=CommandType.LONG, required=true, description="the public IP " +
"address id for which static nat feature is being enabled")
"address id for which static nat feature is being enabled")
private Long ipAddressId;
@IdentityMapper(entityTableName="vm_instance")
@Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.LONG, required=true, description="the ID of " +
"the virtual machine for enabling static nat feature")
"the virtual machine for enabling static nat feature")
private Long virtualMachineId;
@IdentityMapper(entityTableName="networks")
@Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG,
description="The network of the vm the static nat will be enabled for." +
" Required when public Ip address is not associated with any Guest network yet (VPC case)")
description="The network of the vm the static nat will be enabled for." +
" Required when public Ip address is not associated with any Guest network yet (VPC case)")
private Long networkId;
/////////////////////////////////////////////////////
@ -69,7 +69,7 @@ public class EnableStaticNatCmd extends BaseCmd{
public long getNetworkId() {
IpAddress ip = _entityMgr.findById(IpAddress.class, getIpAddressId());
Long ntwkId = null;
if (ip.getAssociatedWithNetworkId() != null) {
ntwkId = ip.getAssociatedWithNetworkId();
} else {
@ -77,7 +77,7 @@ public class EnableStaticNatCmd extends BaseCmd{
}
if (ntwkId == null) {
throw new InvalidParameterValueException("Unable to enable static nat for the ipAddress id=" + ipAddressId +
" as ip is not associated with any network and no networkId is passed in");
" as ip is not associated with any network and no networkId is passed in", null);
}
return ntwkId;
}
@ -90,7 +90,7 @@ public class EnableStaticNatCmd extends BaseCmd{
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
UserVm userVm = _entityMgr.findById(UserVm.class, getVirtualMachineId());

View File

@ -38,7 +38,7 @@ public class ListCapacityCmd extends BaseListCmd {
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@IdentityMapper(entityTableName="data_center")
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="lists capacity by the Zone ID")
private Long zoneId;
@ -46,28 +46,28 @@ public class ListCapacityCmd extends BaseListCmd {
@IdentityMapper(entityTableName="host_pod_ref")
@Parameter(name=ApiConstants.POD_ID, type=CommandType.LONG, description="lists capacity by the Pod ID")
private Long podId;
@IdentityMapper(entityTableName="cluster")
@Parameter(name=ApiConstants.CLUSTER_ID, type=CommandType.LONG, since="3.0.0", description="lists capacity by the Cluster ID")
private Long clusterId;
@Parameter(name=ApiConstants.FETCH_LATEST, type=CommandType.BOOLEAN, since="3.0.0", description="recalculate capacities and fetch the latest")
private Boolean fetchLatest;
@Parameter(name=ApiConstants.TYPE, type=CommandType.INTEGER, description="lists capacity by type" +
"* CAPACITY_TYPE_MEMORY = 0" +
"* CAPACITY_TYPE_CPU = 1" +
"* CAPACITY_TYPE_STORAGE = 2" +
"* CAPACITY_TYPE_STORAGE_ALLOCATED = 3" +
"* CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP = 4" +
"* CAPACITY_TYPE_PRIVATE_IP = 5" +
"* CAPACITY_TYPE_SECONDARY_STORAGE = 6" +
"* CAPACITY_TYPE_VLAN = 7" +
"* CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP = 8" +
"* CAPACITY_TYPE_LOCAL_STORAGE = 9.")
"* CAPACITY_TYPE_MEMORY = 0" +
"* CAPACITY_TYPE_CPU = 1" +
"* CAPACITY_TYPE_STORAGE = 2" +
"* CAPACITY_TYPE_STORAGE_ALLOCATED = 3" +
"* CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP = 4" +
"* CAPACITY_TYPE_PRIVATE_IP = 5" +
"* CAPACITY_TYPE_SECONDARY_STORAGE = 6" +
"* CAPACITY_TYPE_VLAN = 7" +
"* CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP = 8" +
"* CAPACITY_TYPE_LOCAL_STORAGE = 9.")
private Integer type;
@Parameter(name=ApiConstants.SORT_BY, type=CommandType.STRING, since="3.0.0", description="Sort the results. Available values: Usage")
private String sortBy;
@ -78,32 +78,32 @@ public class ListCapacityCmd extends BaseListCmd {
public Long getZoneId() {
return zoneId;
}
public Long getPodId() {
return podId;
}
public Long getClusterId() {
return clusterId;
}
return clusterId;
}
public Boolean getFetchLatest() {
return fetchLatest;
}
public Boolean getFetchLatest() {
return fetchLatest;
}
public Integer getType() {
public Integer getType() {
return type;
}
public String getSortBy() {
if (sortBy != null) {
if (sortBy.equalsIgnoreCase("usage")) {
return sortBy;
} else {
throw new InvalidParameterValueException("Only value supported for sortBy parameter is : usage");
throw new InvalidParameterValueException("Only value supported for sortBy parameter is : usage", null);
}
}
return null;
}
@ -115,7 +115,7 @@ public class ListCapacityCmd extends BaseListCmd {
public String getCommandName() {
return s_name;
}
@Override
public void execute(){
List<? extends Capacity> result = null;
@ -124,7 +124,7 @@ public class ListCapacityCmd extends BaseListCmd {
} else {
result = _mgr.listCapacities(this);
}
ListResponse<CapacityResponse> response = new ListResponse<CapacityResponse>();
List<CapacityResponse> capacityResponses = _responseGenerator.createCapacityResponse(result, s_percentFormat);
response.setResponses(capacityResponses);

View File

@ -69,16 +69,16 @@ public class ListHostsCmd extends BaseListCmd {
@IdentityMapper(entityTableName="vm_instance")
@Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.LONG, required=false, description="lists hosts in the same cluster as this VM and flag hosts with enough CPU/RAm to host this VM")
private Long virtualMachineId;
@Parameter(name=ApiConstants.RESOURCE_STATE, type=CommandType.STRING, description="list hosts by resource state. Resource state represents current state determined by admin of host, valule can be one of [Enabled, Disabled, Unmanaged, PrepareForMaintenance, ErrorInMaintenance, Maintenance, Error]")
private String resourceState;
@Parameter(name=ApiConstants.DETAILS, type=CommandType.LIST, collectionType=CommandType.STRING, description="comma separated list of host details requested, value can be a list of [ min, all, capacity, events, stats]" )
private List<String> viewDetails;
@Parameter(name=ApiConstants.HA_HOST, type=CommandType.BOOLEAN, description="if true, list only hosts dedicated to HA")
private Boolean haHost;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -106,7 +106,7 @@ public class ListHostsCmd extends BaseListCmd {
public String getType() {
return type;
}
public Boolean getHaHost() {
return haHost;
}
@ -118,7 +118,7 @@ public class ListHostsCmd extends BaseListCmd {
public Long getVirtualMachineId() {
return virtualMachineId;
}
public EnumSet<HostDetails> getDetails() throws InvalidParameterValueException {
EnumSet<HostDetails> dv;
if (viewDetails==null || viewDetails.size() <=0){
@ -133,14 +133,14 @@ public class ListHostsCmd extends BaseListCmd {
dv = EnumSet.copyOf(dc);
}
catch (IllegalArgumentException e){
throw new InvalidParameterValueException("The details parameter contains a non permitted value. The allowed values are " + EnumSet.allOf(HostDetails.class));
throw new InvalidParameterValueException("The details parameter contains a non permitted value. The allowed values are " + EnumSet.allOf(HostDetails.class), null);
}
}
return dv;
}
public String getResourceState() {
return resourceState;
return resourceState;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
@ -150,23 +150,24 @@ public class ListHostsCmd extends BaseListCmd {
public String getCommandName() {
return s_name;
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.Host;
return AsyncJob.Type.Host;
}
@Override
public void execute(){
List<? extends Host> result = new ArrayList<Host>();
List<? extends Host> hostsWithCapacity = new ArrayList<Host>();
if(getVirtualMachineId() != null){
List<? extends Host> result = new ArrayList<Host>();
List<? extends Host> hostsWithCapacity = new ArrayList<Host>();
if(getVirtualMachineId() != null){
Pair<List<? extends Host>, List<? extends Host>> hostsForMigration = _mgr.listHostsForMigrationOfVM(getVirtualMachineId(), this.getStartIndex(), this.getPageSizeVal());
result = hostsForMigration.first();
hostsWithCapacity = hostsForMigration.second();
}else{
result = _mgr.searchForServers(this);
}
}else{
result = _mgr.searchForServers(this);
}
ListResponse<HostResponse> response = new ListResponse<HostResponse>();
List<HostResponse> hostResponses = new ArrayList<HostResponse>();

View File

@ -22,17 +22,17 @@ import java.util.List;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseListProjectAndAccountResourcesCmd;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.BaseListTaggedResourcesCmd;
import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.response.FirewallResponse;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.NetworkACLResponse;
import com.cloud.network.rules.NetworkACL;
import com.cloud.network.rules.FirewallRule;
@Implementation(description="Lists all network ACLs", responseObject=NetworkACLResponse.class)
public class ListNetworkACLsCmd extends BaseListProjectAndAccountResourcesCmd {
public class ListNetworkACLsCmd extends BaseListTaggedResourcesCmd {
public static final Logger s_logger = Logger.getLogger(ListNetworkACLsCmd.class.getName());
private static final String s_name = "listnetworkaclsresponse";
@ -78,11 +78,11 @@ public class ListNetworkACLsCmd extends BaseListProjectAndAccountResourcesCmd {
@Override
public void execute(){
List<? extends NetworkACL> result = _networkACLService.listNetworkACLs(this);
List<? extends FirewallRule> result = _networkACLService.listNetworkACLs(this);
ListResponse<NetworkACLResponse> response = new ListResponse<NetworkACLResponse>();
List<NetworkACLResponse> aclResponses = new ArrayList<NetworkACLResponse>();
for (NetworkACL acl : result) {
for (FirewallRule acl : result) {
NetworkACLResponse ruleData = _responseGenerator.createNetworkACLResponse(acl);
aclResponses.add(ruleData);
}

View File

@ -13,7 +13,11 @@
package com.cloud.api.commands;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
@ -24,6 +28,7 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.ProjectResponse;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.projects.Project;
@Implementation(description="Lists projects and provides detailed information for listed projects", responseObject=ProjectResponse.class, since="3.0.0")
@ -48,6 +53,9 @@ public class ListProjectsCmd extends BaseListAccountResourcesCmd {
@Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="list projects by state")
private String state;
@Parameter(name = ApiConstants.TAGS, type = CommandType.MAP, description = "List projects by tags (key/value pairs)")
private Map tags;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -68,6 +76,25 @@ public class ListProjectsCmd extends BaseListAccountResourcesCmd {
public String getCommandName() {
return s_name;
}
public Map<String, String> getTags() {
Map<String, String> tagsMap = null;
if (tags != null && !tags.isEmpty()) {
tagsMap = new HashMap<String, String>();
Collection<?> servicesCollection = tags.values();
Iterator<?> iter = servicesCollection.iterator();
while (iter.hasNext()) {
HashMap<String, String> services = (HashMap<String, String>) iter.next();
String key = services.get("key");
String value = services.get("value");
if (value == null) {
throw new InvalidParameterValueException("No value is passed in for key " + key);
}
tagsMap.put(key, value);
}
}
return tagsMap;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
@ -75,7 +102,9 @@ public class ListProjectsCmd extends BaseListAccountResourcesCmd {
@Override
public void execute(){
List<? extends Project> projects = _projectService.listProjects(id, name, displayText, state, this.getAccountName(), this.getDomainId(), this.getKeyword(), this.getStartIndex(), this.getPageSizeVal(), this.listAll(), this.isRecursive());
List<? extends Project> projects = _projectService.listProjects(id, name, displayText, state,
this.getAccountName(), this.getDomainId(), this.getKeyword(), this.getStartIndex(), this.getPageSizeVal(),
this.listAll(), this.isRecursive(), getTags());
ListResponse<ProjectResponse> response = new ListResponse<ProjectResponse>();
List<ProjectResponse> projectResponses = new ArrayList<ProjectResponse>();
for (Project project : projects) {

View File

@ -66,6 +66,9 @@ public class ListRoutersCmd extends BaseListProjectAndAccountResourcesCmd {
@IdentityMapper(entityTableName="vpc")
@Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="List networks by VPC")
private Long vpcId;
@Parameter(name=ApiConstants.FOR_VPC, type=CommandType.BOOLEAN, description="if true is passed for this parameter, list only VPC routers")
private Boolean forVpc;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -102,6 +105,10 @@ public class ListRoutersCmd extends BaseListProjectAndAccountResourcesCmd {
public Long getVpcId() {
return vpcId;
}
public Boolean getForVpc() {
return forVpc;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////

View File

@ -16,7 +16,7 @@ import java.util.ArrayList;
import java.util.List;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseListProjectAndAccountResourcesCmd;
import com.cloud.api.BaseListTaggedResourcesCmd;
import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
@ -29,7 +29,7 @@ import com.cloud.network.vpc.StaticRoute;
*/
@Implementation(description="Lists all static routes", responseObject=StaticRouteResponse.class)
public class ListStaticRoutesCmd extends BaseListProjectAndAccountResourcesCmd {
public class ListStaticRoutesCmd extends BaseListTaggedResourcesCmd {
private static final String s_name = "liststaticroutesresponse";
/////////////////////////////////////////////////////

View File

@ -33,21 +33,21 @@ import com.cloud.user.Account;
public class ListSupportedNetworkServicesCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListSupportedNetworkServicesCmd.class.getName());
private static final String _name = "listsupportednetworkservicesresponse";
@Parameter(name=ApiConstants.PROVIDER, type=CommandType.STRING, description="network service provider name")
private String providerName;
@Parameter(name=ApiConstants.SERVICE, type=CommandType.STRING, description="network service name to list providers and capabilities of")
private String serviceName;
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public void setProviderName(String providerName) {
this.providerName = providerName;
@ -74,7 +74,7 @@ public class ListSupportedNetworkServicesCmd extends BaseListCmd {
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
@Override
public void execute(){
List<? extends Network.Service> services;
@ -83,7 +83,7 @@ public class ListSupportedNetworkServicesCmd extends BaseListCmd {
if(serviceName != null){
service = Network.Service.getService(serviceName);
if(service == null){
throw new InvalidParameterValueException("Invalid Network Service=" + serviceName);
throw new InvalidParameterValueException("Invalid Network Service=" + serviceName, null);
}
}
List<Network.Service> serviceList = new ArrayList<Network.Service>();
@ -92,14 +92,14 @@ public class ListSupportedNetworkServicesCmd extends BaseListCmd {
}else{
services = _networkService.listNetworkServices(getProviderName());
}
ListResponse<ServiceResponse> response = new ListResponse<ServiceResponse>();
List<ServiceResponse> servicesResponses = new ArrayList<ServiceResponse>();
for (Network.Service service : services) {
//skip gateway service
if (service == Service.Gateway) {
continue;
}
//skip gateway service
if (service == Service.Gateway) {
continue;
}
ServiceResponse serviceResponse = _responseGenerator.createNetworkServiceResponse(service);
servicesResponses.add(serviceResponse);
}

View File

@ -65,25 +65,25 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd {
@IdentityMapper(entityTableName="data_center")
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="the availability zone ID")
private Long zoneId;
@Parameter(name=ApiConstants.FOR_VIRTUAL_NETWORK, type=CommandType.BOOLEAN, description="list by network type; true if need to list vms using Virtual Network, false otherwise")
private Boolean forVirtualNetwork;
@IdentityMapper(entityTableName="networks")
@Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, description="list by network id")
private Long networkId;
@Parameter(name=ApiConstants.HYPERVISOR, type=CommandType.STRING, description="the target hypervisor for the template")
private String hypervisor;
@IdentityMapper(entityTableName="storage_pool")
@Parameter(name=ApiConstants.STORAGE_ID, type=CommandType.LONG, description="the storage ID where vm's volumes belong to")
private Long storageId;
@Parameter(name=ApiConstants.DETAILS, type=CommandType.LIST, collectionType=CommandType.STRING, description="comma separated list of host details requested, " +
"value can be a list of [all, group, nics, stats, secgrp, tmpl, servoff, iso, volume, min]. If no parameter is passed in, the details will be defaulted to all" )
"value can be a list of [all, group, nics, stats, secgrp, tmpl, servoff, iso, volume, min]. If no parameter is passed in, the details will be defaulted to all" )
private List<String> viewDetails;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -116,7 +116,7 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd {
public Long getZoneId() {
return zoneId;
}
public Boolean getForVirtualNetwork() {
return forVirtualNetwork;
}
@ -124,19 +124,19 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd {
public void setForVirtualNetwork(Boolean forVirtualNetwork) {
this.forVirtualNetwork = forVirtualNetwork;
}
public Long getNetworkId() {
return networkId;
}
public String getHypervisor() {
return hypervisor;
}
return hypervisor;
}
public Long getStorageId() {
return storageId;
}
public EnumSet<VMDetails> getDetails() throws InvalidParameterValueException {
EnumSet<VMDetails> dv;
if (viewDetails==null || viewDetails.size() <=0){
@ -151,39 +151,40 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd {
dv = EnumSet.copyOf(dc);
}
catch (IllegalArgumentException e){
throw new InvalidParameterValueException("The details parameter contains a non permitted value. The allowed values are " + EnumSet.allOf(VMDetails.class));
throw new InvalidParameterValueException("The details parameter contains a non permitted value. The allowed values are " + EnumSet.allOf(VMDetails.class), null);
}
}
return dv;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
public String getCommandName() {
return s_name;
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.VirtualMachine;
return AsyncJob.Type.VirtualMachine;
}
@Override
@Override
public void execute(){
List<? extends UserVm> result = _userVmService.searchForUserVMs(this);
ListResponse<UserVmResponse> response = new ListResponse<UserVmResponse>();
EnumSet<VMDetails> details = getDetails();
List<UserVmResponse> vmResponses;
if (details.contains(VMDetails.all)){ // for all use optimized version
vmResponses = _responseGenerator.createUserVmResponse("virtualmachine", result.toArray(new UserVm[result.size()]));
vmResponses = _responseGenerator.createUserVmResponse("virtualmachine", result.toArray(new UserVm[result.size()]));
}
else {
vmResponses = _responseGenerator.createUserVmResponse("virtualmachine", getDetails(), result.toArray(new UserVm[result.size()]));
vmResponses = _responseGenerator.createUserVmResponse("virtualmachine", getDetails(), result.toArray(new UserVm[result.size()]));
}
response.setResponses(vmResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
}

View File

@ -18,7 +18,7 @@ import java.util.List;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseListAccountResourcesCmd;
import com.cloud.api.BaseListTaggedResourcesCmd;
import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
@ -31,7 +31,7 @@ import com.cloud.network.vpc.Vpc;
*/
@Implementation(description="Lists VPCs", responseObject=VpcResponse.class)
public class ListVPCsCmd extends BaseListAccountResourcesCmd{
public class ListVPCsCmd extends BaseListTaggedResourcesCmd{
public static final Logger s_logger = Logger.getLogger(ListVPCsCmd.class.getName());
private static final String s_name = "listvpcsresponse";
@ -137,7 +137,7 @@ public class ListVPCsCmd extends BaseListAccountResourcesCmd{
List<? extends Vpc> vpcs = _vpcService.listVpcs(getId(), getVpcName(), getDisplayText(),
getSupportedServices(), getCidr(), getVpcOffId(), getState(), getAccountName(), getDomainId(),
this.getKeyword(), this.getStartIndex(), this.getPageSizeVal(), getZoneId(), this.isRecursive(),
this.listAll(), getRestartRequired());
this.listAll(), getRestartRequired(), getTags());
ListResponse<VpcResponse> response = new ListResponse<VpcResponse>();
List<VpcResponse> offeringResponses = new ArrayList<VpcResponse>();
for (Vpc vpc : vpcs) {

View File

@ -73,7 +73,7 @@ public class MigrateSystemVMCmd extends BaseAsyncCmd {
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
Account account = UserContext.current().getCaller();
@ -93,38 +93,38 @@ public class MigrateSystemVMCmd extends BaseAsyncCmd {
public String getEventDescription() {
return "Attempting to migrate VM Id: " + getVirtualMachineId() + " to host Id: "+ getHostId();
}
@Override
public void execute(){
Host destinationHost = _resourceService.getHost(getHostId());
if (destinationHost == null) {
throw new InvalidParameterValueException("Unable to find the host to migrate the VM, host id=" + getHostId());
throw new InvalidParameterValueException("Unable to find the host to migrate the VM, host id=" + getHostId(), null);
}
try{
UserContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to host Id: "+ getHostId());
//FIXME : Should not be calling UserVmService to migrate all types of VMs - need a generic VM layer
VirtualMachine migratedVm = _userVmService.migrateVirtualMachine(getVirtualMachineId(), destinationHost);
if (migratedVm != null) {
// return the generic system VM instance response
SystemVmInstanceResponse response = _responseGenerator.createSystemVmInstanceResponse(migratedVm);
UserContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to host Id: "+ getHostId());
//FIXME : Should not be calling UserVmService to migrate all types of VMs - need a generic VM layer
VirtualMachine migratedVm = _userVmService.migrateVirtualMachine(getVirtualMachineId(), destinationHost);
if (migratedVm != null) {
// return the generic system VM instance response
SystemVmInstanceResponse response = _responseGenerator.createSystemVmInstanceResponse(migratedVm);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to migrate the system vm");
}
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to migrate the system vm");
}
} catch (ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (ConcurrentOperationException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
} catch (ManagementServerException e) {
} catch (ManagementServerException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
} catch (VirtualMachineMigrationException e) {
} catch (VirtualMachineMigrationException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
}
}
}
}

View File

@ -68,9 +68,9 @@ public class MigrateVMCmd extends BaseAsyncCmd {
public Long getVirtualMachineId() {
return virtualMachineId;
}
public Long getStoragePoolId() {
return storageId;
return storageId;
}
@ -82,7 +82,7 @@ public class MigrateVMCmd extends BaseAsyncCmd {
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
UserVm userVm = _entityMgr.findById(UserVm.class, getVirtualMachineId());
@ -102,66 +102,66 @@ public class MigrateVMCmd extends BaseAsyncCmd {
public String getEventDescription() {
return "Attempting to migrate VM Id: " + getVirtualMachineId() + " to host Id: "+ getHostId();
}
@Override
public void execute(){
if (getHostId() == null && getStoragePoolId() == null) {
throw new InvalidParameterValueException("either hostId or storageId must be specified");
}
if (getHostId() != null && getStoragePoolId() != null) {
throw new InvalidParameterValueException("only one of hostId and storageId can be specified");
}
if (getHostId() == null && getStoragePoolId() == null) {
throw new InvalidParameterValueException("either hostId or storageId must be specified", null);
}
if (getHostId() != null && getStoragePoolId() != null) {
throw new InvalidParameterValueException("only one of hostId and storageId can be specified", null);
}
UserVm userVm = _userVmService.getUserVm(getVirtualMachineId());
if (userVm == null) {
throw new InvalidParameterValueException("Unable to find the VM by id=" + getVirtualMachineId());
throw new InvalidParameterValueException("Unable to find the VM by id=" + getVirtualMachineId(), null);
}
Host destinationHost = null;
if (getHostId() != null) {
destinationHost = _resourceService.getHost(getHostId());
if (destinationHost == null) {
throw new InvalidParameterValueException("Unable to find the host to migrate the VM, host id=" + getHostId());
}
UserContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to host Id: "+ getHostId());
destinationHost = _resourceService.getHost(getHostId());
if (destinationHost == null) {
throw new InvalidParameterValueException("Unable to find the host to migrate the VM, host id=" + getHostId(), null);
}
UserContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to host Id: "+ getHostId());
}
StoragePool destStoragePool = null;
if (getStoragePoolId() != null) {
destStoragePool = _storageService.getStoragePool(getStoragePoolId());
if (destStoragePool == null) {
throw new InvalidParameterValueException("Unable to find the storage pool to migrate the VM");
}
UserContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to storage pool Id: "+ getStoragePoolId());
destStoragePool = _storageService.getStoragePool(getStoragePoolId());
if (destStoragePool == null) {
throw new InvalidParameterValueException("Unable to find the storage pool to migrate the VM", null);
}
UserContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to storage pool Id: "+ getStoragePoolId());
}
try{
VirtualMachine migratedVm = null;
if (getHostId() != null) {
migratedVm = _userVmService.migrateVirtualMachine(getVirtualMachineId(), destinationHost);
} else if (getStoragePoolId() != null) {
migratedVm = _userVmService.vmStorageMigration(getVirtualMachineId(), destStoragePool);
}
if (migratedVm != null) {
VirtualMachine migratedVm = null;
if (getHostId() != null) {
migratedVm = _userVmService.migrateVirtualMachine(getVirtualMachineId(), destinationHost);
} else if (getStoragePoolId() != null) {
migratedVm = _userVmService.vmStorageMigration(getVirtualMachineId(), destStoragePool);
}
if (migratedVm != null) {
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", (UserVm)migratedVm).get(0);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to migrate vm");
}
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to migrate vm");
}
} catch (ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (ConcurrentOperationException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
} catch (ManagementServerException e) {
} catch (ManagementServerException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
} catch (VirtualMachineMigrationException e) {
} catch (VirtualMachineMigrationException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
}
}
}
}

View File

@ -36,7 +36,7 @@ public class RemoveFromLoadBalancerRuleCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(RemoveFromLoadBalancerRuleCmd.class.getName());
private static final String s_name = "removefromloadbalancerruleresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@ -100,7 +100,7 @@ public class RemoveFromLoadBalancerRuleCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to remove instance from load balancer rule");
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
@ -108,10 +108,10 @@ public class RemoveFromLoadBalancerRuleCmd extends BaseAsyncCmd {
@Override
public Long getSyncObjId() {
LoadBalancer lb = _lbService.findById(id);
if(lb == null){
throw new InvalidParameterValueException("Unable to find load balancer rule: " + id);
}
LoadBalancer lb = _lbService.findById(id);
if(lb == null){
throw new InvalidParameterValueException("Unable to find load balancer rule by id", null);
}
return lb.getNetworkId();
}
}

View File

@ -40,7 +40,7 @@ public class RestartNetworkCmd extends BaseAsyncCmd {
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@IdentityMapper(entityTableName="networks")
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The id of the network to restart.")
private Long id;
@ -52,16 +52,16 @@ public class RestartNetworkCmd extends BaseAsyncCmd {
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Long getNetworkId() {
Network network = _networkService.getNetwork(id);
if (network == null) {
throw new InvalidParameterValueException("Unable to find network by id " + id);
throw new InvalidParameterValueException("Unable to find network by id", null);
} else {
return network.getId();
}
}
public Boolean getCleanup() {
if (cleanup != null) {
return cleanup;
@ -83,7 +83,7 @@ public class RestartNetworkCmd extends BaseAsyncCmd {
public static String getResultObjectName() {
return "addressinfo";
}
@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
boolean result = _networkService.restartNetwork(this, getCleanup());
@ -94,7 +94,7 @@ public class RestartNetworkCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to restart network");
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
@ -104,21 +104,22 @@ public class RestartNetworkCmd extends BaseAsyncCmd {
public Long getSyncObjId() {
return id;
}
@Override
public String getEventDescription() {
return "Restarting network: " + getNetworkId();
}
@Override
public String getEventType() {
return EventTypes.EVENT_NETWORK_RESTART;
}
@Override
public long getEntityOwnerId() {
Network network = _networkService.getNetwork(id);
if (network == null) {
throw new InvalidParameterValueException("Networkd id=" + id + " doesn't exist");
throw new InvalidParameterValueException("Couldn't find network by id", null);
} else {
return _networkService.getNetwork(id).getAccountId();
}

View File

@ -73,26 +73,26 @@ public class SuspendProjectCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to suspend a project");
}
}
@Override
public String getEventType() {
return EventTypes.EVENT_PROJECT_SUSPEND;
}
@Override
public String getEventDescription() {
return "Suspending project: " + id;
}
@Override
public long getEntityOwnerId() {
Project project= _projectService.getProject(id);
//verify input parameters
if (project == null) {
throw new InvalidParameterValueException("Unable to find project by id " + id);
throw new InvalidParameterValueException("Unable to find project by id", null);
}
return _projectService.getProjectOwner(id).getId();
}
}

View File

@ -12,18 +12,18 @@
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.api.commands;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseCmd;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseCmd;
import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.ClusterResponse;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.org.Cluster;
import com.cloud.user.Account;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.ClusterResponse;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.org.Cluster;
import com.cloud.user.Account;
@Implementation(description="Updates an existing cluster", responseObject=ClusterResponse.class)
public class UpdateClusterCmd extends BaseCmd {
@ -34,22 +34,22 @@ public class UpdateClusterCmd extends BaseCmd {
@IdentityMapper(entityTableName="cluster")
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the Cluster")
private Long id;
@Parameter(name=ApiConstants.CLUSTER_NAME, type=CommandType.STRING, description="the cluster name")
private String clusterName;
@Parameter(name=ApiConstants.HYPERVISOR, type=CommandType.STRING, description="hypervisor type of the cluster")
private String hypervisor;
@Parameter(name=ApiConstants.CLUSTER_TYPE, type=CommandType.STRING, description="hypervisor type of the cluster")
private String clusterType;
@Parameter(name=ApiConstants.ALLOCATION_STATE, type=CommandType.STRING, description="Allocation state of this cluster for allocation of new resources")
private String allocationState;
@Parameter(name=ApiConstants.MANAGED_STATE, type=CommandType.STRING, description="whether this cluster is managed by cloudstack")
private String managedState;
public String getClusterName() {
return clusterName;
}
@ -59,33 +59,33 @@ public class UpdateClusterCmd extends BaseCmd {
}
public String getHypervisor() {
return hypervisor;
return hypervisor;
}
@Override
public String getCommandName() {
return s_name;
return s_name;
}
public String getClusterType() {
return clusterType;
return clusterType;
}
public void setClusterType(String type) {
this.clusterType = type;
this.clusterType = type;
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
public String getAllocationState() {
return allocationState;
return allocationState;
}
public void setAllocationState(String allocationState) {
this.allocationState = allocationState;
this.allocationState = allocationState;
}
public String getManagedstate() {
@ -98,16 +98,16 @@ public class UpdateClusterCmd extends BaseCmd {
@Override
public void execute(){
Cluster cluster = _resourceService.getCluster(getId());
Cluster cluster = _resourceService.getCluster(getId());
if (cluster == null) {
throw new InvalidParameterValueException("Unable to find the cluster by id=" + getId());
throw new InvalidParameterValueException("Unable to find the cluster by id", null);
}
Cluster result = _resourceService.updateCluster(cluster, getClusterType(), getHypervisor(), getAllocationState(), getManagedstate());
if (result != null) {
ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false);
clusterResponse.setResponseName(getCommandName());
this.setResponseObject(clusterResponse);
ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false);
clusterResponse.setResponseName(getCommandName());
this.setResponseObject(clusterResponse);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update cluster");
}

View File

@ -43,43 +43,43 @@ public class UpdateNetworkCmd extends BaseAsyncCmd {
@IdentityMapper(entityTableName="networks")
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the network")
private Long id;
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the new name for the network")
private String name;
@Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="the new display text for the network")
private String displayText;
@Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="network domain")
private String networkDomain;
@Parameter(name=ApiConstants.CHANGE_CIDR, type=CommandType.BOOLEAN, description="Force update even if cidr type is different")
private Boolean changeCidr;
@IdentityMapper(entityTableName="network_offerings")
@Parameter(name=ApiConstants.NETWORK_OFFERING_ID, type=CommandType.LONG, description="network offering ID")
private Long networkOfferingId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Long getId() {
return id;
}
public String getNetworkName() {
return name;
}
public String getDisplayText() {
return displayText;
}
private String getNetworkDomain() {
return networkDomain;
}
private Long getNetworkOfferingId() {
return networkOfferingId;
}
@ -98,17 +98,17 @@ public class UpdateNetworkCmd extends BaseAsyncCmd {
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
Network network = _networkService.getNetwork(id);
if (network == null) {
throw new InvalidParameterValueException("Networkd id=" + id + " doesn't exist");
throw new InvalidParameterValueException("Couldn't find network by id", null);
} else {
return _networkService.getNetwork(id).getAccountId();
}
}
@Override
public void execute() throws InsufficientCapacityException, ConcurrentOperationException{
User callerUser = _accountService.getActiveUser(UserContext.current().getCallerUserId());
@ -123,12 +123,12 @@ public class UpdateNetworkCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update network");
}
}
@Override
public String getEventDescription() {
return "Updating network: " + getId();
}
@Override
public String getEventType() {
return EventTypes.EVENT_NETWORK_UPDATE;

View File

@ -37,14 +37,14 @@ public class UpdateProjectCmd extends BaseAsyncCmd {
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@IdentityMapper(entityTableName="projects")
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="id of the project to be modified")
private Long id;
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="new Admin account for the project")
private String accountName;
@Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="display text of the project")
private String displayText;
@ -68,18 +68,18 @@ public class UpdateProjectCmd extends BaseAsyncCmd {
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
Project project= _projectService.getProject(id);
//verify input parameters
if (project == null) {
throw new InvalidParameterValueException("Unable to find project by id " + id);
throw new InvalidParameterValueException("Unable to find project by id ", null);
}
return _projectService.getProjectOwner(id).getId();
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
@ -97,12 +97,12 @@ public class UpdateProjectCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update a project");
}
}
@Override
public String getEventType() {
return EventTypes.EVENT_PROJECT_UPDATE;
}
@Override
public String getEventDescription() {
return "Updating project: " + id;

View File

@ -44,13 +44,13 @@ public abstract class UpdateTemplateOrIsoPermissionsCmd extends BaseCmd {
@Parameter(name = ApiConstants.IS_PUBLIC, type = CommandType.BOOLEAN, description = "true for public template/iso, false for private templates/isos")
private Boolean isPublic;
@Parameter(name = ApiConstants.IS_EXTRACTABLE, type = CommandType.BOOLEAN, description = "true if the template/iso is extractable, false other wise. Can be set only by root admin")
private Boolean isExtractable;
@Parameter(name = ApiConstants.OP, type = CommandType.STRING, description = "permission operator (add, remove, reset)")
private String operation;
@IdentityMapper(entityTableName="projects")
@Parameter(name = ApiConstants.PROJECT_IDS, type = CommandType.LIST, collectionType = CommandType.LONG, description = "a comma delimited list of projects. If specified, \"op\" parameter has to be passed in.")
private List<Long> projectIds;
@ -61,9 +61,9 @@ public abstract class UpdateTemplateOrIsoPermissionsCmd extends BaseCmd {
public List<String> getAccountNames() {
if (accountNames != null && projectIds != null) {
throw new InvalidParameterValueException("Accounts and projectIds can't be specified together");
throw new InvalidParameterValueException("Accounts and projectIds can't be specified together", null);
}
return accountNames;
}
@ -78,18 +78,18 @@ public abstract class UpdateTemplateOrIsoPermissionsCmd extends BaseCmd {
public Boolean isPublic() {
return isPublic;
}
public Boolean isExtractable() {
return isExtractable;
}
public String getOperation() {
return operation;
}
public List<Long> getProjectIds() {
if (accountNames != null && projectIds != null) {
throw new InvalidParameterValueException("Accounts and projectIds can't be specified together");
throw new InvalidParameterValueException("Accounts and projectIds can't be specified together", null);
}
return projectIds;
}

View File

@ -33,8 +33,8 @@ import com.cloud.user.UserContext;
import com.cloud.vm.VirtualMachine;
@Implementation(responseObject=SystemVmResponse.class, description="Changes the service offering for a system vm (console proxy or secondary storage). " +
"The system vm must be in a \"Stopped\" state for " +
"this command to take effect.")
"The system vm must be in a \"Stopped\" state for " +
"this command to take effect.")
public class UpgradeSystemVMCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(UpgradeVMCmd.class.getName());
private static final String s_name = "changeserviceforsystemvmresponse";
@ -49,7 +49,7 @@ public class UpgradeSystemVMCmd extends BaseCmd {
@IdentityMapper(entityTableName="disk_offering")
@Parameter(name=ApiConstants.SERVICE_OFFERING_ID, type=CommandType.LONG, required=true,
description="the service offering ID to apply to the system vm")
description="the service offering ID to apply to the system vm")
private Long serviceOfferingId;
/////////////////////////////////////////////////////
@ -72,7 +72,7 @@ public class UpgradeSystemVMCmd extends BaseCmd {
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
Account account = UserContext.current().getCaller();
@ -82,16 +82,16 @@ public class UpgradeSystemVMCmd extends BaseCmd {
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
}
@Override
public void execute(){
UserContext.current().setEventDetails("Vm Id: "+getId());
ServiceOffering serviceOffering = _configService.getServiceOffering(serviceOfferingId);
if (serviceOffering == null) {
throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
throw new InvalidParameterValueException("Unable to find service offering by id", null);
}
VirtualMachine result = _mgr.upgradeSystemVM(this);
if (result != null) {
SystemVmResponse response = _responseGenerator.createSystemVmResponse(result);

View File

@ -28,8 +28,8 @@ import com.cloud.user.UserContext;
import com.cloud.uservm.UserVm;
@Implementation(responseObject=UserVmResponse.class, description="Changes the service offering for a virtual machine. " +
"The virtual machine must be in a \"Stopped\" state for " +
"this command to take effect.")
"The virtual machine must be in a \"Stopped\" state for " +
"this command to take effect.")
public class UpgradeVMCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(UpgradeVMCmd.class.getName());
private static final String s_name = "changeserviceforvirtualmachineresponse";
@ -68,9 +68,9 @@ public class UpgradeVMCmd extends BaseCmd {
}
public static String getResultObjectName() {
return "virtualmachine";
return "virtualmachine";
}
@Override
public long getEntityOwnerId() {
UserVm userVm = _entityMgr.findById(UserVm.class, getId());
@ -80,16 +80,16 @@ public class UpgradeVMCmd extends BaseCmd {
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
}
@Override
public void execute(){
UserContext.current().setEventDetails("Vm Id: "+getId());
ServiceOffering serviceOffering = _configService.getServiceOffering(serviceOfferingId);
if (serviceOffering == null) {
throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
throw new InvalidParameterValueException("Unable to find service offering by id", null);
}
UserVm result = _userVmService.upgradeVirtualMachine(this);
if (result != null){
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);

View File

@ -12,6 +12,8 @@
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.api.response;
import java.util.List;
import com.cloud.api.ApiConstants;
import com.cloud.serializer.Param;
import com.cloud.utils.IdentityProxy;
@ -45,6 +47,10 @@ public class NetworkACLResponse extends BaseResponse {
@SerializedName(ApiConstants.ICMP_CODE) @Param(description = "error code for this icmp message")
private Integer icmpCode;
@SerializedName(ApiConstants.TAGS) @Param(description="the list of resource tags associated with the network ACLs",
responseObject = ResourceTagResponse.class)
private List<ResourceTagResponse> tags;
public void setId(Long id) {
this.id.setValue(id);
@ -81,4 +87,8 @@ public class NetworkACLResponse extends BaseResponse {
public void setTrafficType(String trafficType) {
this.trafficType = trafficType;
}
public void setTags(List<ResourceTagResponse> tags) {
this.tags = tags;
}
}

View File

@ -12,9 +12,11 @@
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.api.response;
import java.util.List;
import com.cloud.api.ApiConstants;
import com.cloud.utils.IdentityProxy;
import com.cloud.serializer.Param;
import com.cloud.utils.IdentityProxy;
import com.google.gson.annotations.SerializedName;
@SuppressWarnings("unused")
@ -40,6 +42,9 @@ public class ProjectResponse extends BaseResponse{
@SerializedName(ApiConstants.STATE) @Param(description="the state of the project")
private String state;
@SerializedName(ApiConstants.TAGS) @Param(description="the list of resource tags associated with vm", responseObject = ResourceTagResponse.class)
private List<ResourceTagResponse> tags;
public void setId(Long id) {
@ -69,4 +74,8 @@ public class ProjectResponse extends BaseResponse{
public void setState(String state) {
this.state = state;
}
public void setTags(List<ResourceTagResponse> tags) {
this.tags = tags;
}
}

View File

@ -12,6 +12,8 @@
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.api.response;
import java.util.List;
import com.cloud.api.ApiConstants;
import com.cloud.serializer.Param;
import com.cloud.utils.IdentityProxy;
@ -54,6 +56,10 @@ public class StaticRouteResponse extends BaseResponse implements ControlledEntit
@SerializedName(ApiConstants.DOMAIN)
@Param(description = "the domain associated with the static route")
private String domainName;
@SerializedName(ApiConstants.TAGS) @Param(description="the list of resource tags associated with static route",
responseObject = ResourceTagResponse.class)
private List<ResourceTagResponse> tags;
public void setId(Long id) {
this.id.setValue(id);
@ -99,4 +105,8 @@ public class StaticRouteResponse extends BaseResponse implements ControlledEntit
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public void setTags(List<ResourceTagResponse> tags) {
this.tags = tags;
}
}

View File

@ -79,6 +79,9 @@ public class VpcResponse extends BaseResponse implements ControlledEntityRespons
@SerializedName(ApiConstants.NETWORK_DOMAIN) @Param(description="the network domain")
private String networkDomain;
@SerializedName(ApiConstants.TAGS) @Param(description="the list of resource tags associated with the project", responseObject = ResourceTagResponse.class)
private List<ResourceTagResponse> tags;
public void setId(Long id) {
this.id.setValue(id);
@ -160,4 +163,8 @@ public class VpcResponse extends BaseResponse implements ControlledEntityRespons
public void setZoneName(String zoneName) {
this.zoneName = zoneName;
}
public void setTags(List<ResourceTagResponse> tags) {
this.tags = tags;
}
}

View File

@ -12,6 +12,9 @@
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.exception;
import java.util.List;
import com.cloud.utils.IdentityProxy;
import com.cloud.utils.exception.CloudRuntimeException;
/**
@ -26,4 +29,13 @@ public class InvalidParameterValueException extends CloudRuntimeException {
super(message);
}
public InvalidParameterValueException(String message, List<IdentityProxy> idProxyList) {
super(message);
if (idProxyList != null) {
for (IdentityProxy id : idProxyList) {
this.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
}
}
}
}

View File

@ -60,4 +60,6 @@ public interface PhysicalNetworkServiceProvider {
List<Service> getEnabledServices();
String getUuid();
boolean isNetworkAclServiceProvided();
}

View File

@ -17,21 +17,21 @@ import java.util.List;
import com.cloud.api.commands.ListNetworkACLsCmd;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.rules.NetworkACL;
import com.cloud.network.rules.FirewallRule;
import com.cloud.user.Account;
/**
* @author Alena Prokharchyk
*/
public interface NetworkACLService {
NetworkACL getNetworkACL(long ruleId);
FirewallRule getNetworkACL(long ruleId);
boolean applyNetworkACLs(long networkId, Account caller) throws ResourceUnavailableException;
/**
* @param createNetworkACLCmd
* @return
*/
NetworkACL createNetworkACL(NetworkACL acl) throws NetworkRuleConflictException;
FirewallRule createNetworkACL(FirewallRule acl) throws NetworkRuleConflictException;
/**
* @param ruleId
* @param apply
@ -42,6 +42,6 @@ public interface NetworkACLService {
* @param listNetworkACLsCmd
* @return
*/
List<? extends NetworkACL> listNetworkACLs(ListNetworkACLsCmd cmd);
List<? extends FirewallRule> listNetworkACLs(ListNetworkACLsCmd cmd);
}

View File

@ -214,4 +214,9 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer{
public FirewallRuleType getType() {
return FirewallRuleType.User;
}
@Override
public TrafficType getTrafficType() {
return null;
}
}

View File

@ -15,6 +15,7 @@ package com.cloud.network.rules;
import java.util.List;
import com.cloud.acl.ControlledEntity;
import com.cloud.network.rules.FirewallRule.TrafficType;
public interface FirewallRule extends ControlledEntity {
enum Purpose {
@ -86,4 +87,9 @@ public interface FirewallRule extends ControlledEntity {
FirewallRuleType getType();
/**
* @return
*/
TrafficType getTrafficType();
}

View File

@ -1,26 +0,0 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.rules;
/**
* @author Alena Prokharchyk
*/
public interface NetworkACL extends FirewallRule{
/**
* @return
*/
TrafficType getTrafficType();
}

View File

@ -107,13 +107,14 @@ public interface VpcService {
* @param isRecursive TODO
* @param listAll TODO
* @param restartRequired TODO
* @param tags TODO
* @param vpc
* @return
*/
public List<? extends Vpc> listVpcs(Long id, String vpcName, String displayText,
List<String> supportedServicesStr, String cidr, Long vpcOffId, String state, String accountName, Long domainId,
String keyword, Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll,
Boolean restartRequired);
Boolean restartRequired, Map<String, String> tags);
/**
* @param vpcId

View File

@ -13,6 +13,7 @@
package com.cloud.projects;
import java.util.List;
import java.util.Map;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.ResourceAllocationException;
@ -55,7 +56,8 @@ public interface ProjectService {
*/
Project getProject(long id);
List<? extends Project> listProjects(Long id, String name, String displayText, String state, String accountName, Long domainId, String keyword, Long startIndex, Long pageSize, boolean listAll, boolean isRecursive);
List<? extends Project> listProjects(Long id, String name, String displayText, String state, String accountName,
Long domainId, String keyword, Long startIndex, Long pageSize, boolean listAll, boolean isRecursive, Map<String, String> tags);
ProjectAccount assignAccountToProject(Project project, long accountId, Role accountRole);

View File

@ -30,7 +30,11 @@ public interface ResourceTag extends ControlledEntity{
PortForwardingRule,
FirewallRule,
SecurityGroup,
PublicIpAddress
PublicIpAddress,
Project,
Vpc,
NetworkACL,
StaticRoute
}
/**

View File

@ -30,15 +30,10 @@ import org.apache.log4j.Logger;
import com.cloud.bridge.util.ConfigurationHelper;
public class BucketPolicyDao {
public class BucketPolicyDao extends BaseDao {
public static final Logger logger = Logger.getLogger(BucketPolicyDao.class);
private Connection conn = null;
private String dbName = null;
private String dbUser = null;
private String dbPassword = null;
private String dbHost = null;
private String dbPort = null;
public BucketPolicyDao()
{
@ -54,11 +49,14 @@ public class BucketPolicyDao {
} catch (IOException e) {
logger.warn("Unable to read properties file: " + propertiesFile.getAbsolutePath(), e);
}
/* using the values from base class
dbHost = EC2Prop.getProperty( "db.cloud.host" );
dbName = EC2Prop.getProperty( "db.awsapi.name" );
dbUser = EC2Prop.getProperty( "db.cloud.username" );
dbPassword = EC2Prop.getProperty( "db.cloud.password" );
dbPort = EC2Prop.getProperty( "db.cloud.port" );
*/
}
}
@ -147,7 +145,7 @@ public class BucketPolicyDao {
{
if (null == conn) {
Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
conn = DriverManager.getConnection( "jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName, dbUser, dbPassword );
conn = DriverManager.getConnection( "jdbc:mysql://" + dbHost + ":" + dbPort + "/" + awsapi_dbName, dbUser, dbPassword );
}
}

View File

@ -633,7 +633,7 @@ fi
%config(noreplace) %attr(0640,root,%{name}) %{_sysconfdir}/%{name}/usage/db.properties
%files aws-api
%defattr(0644,cloud,cloud,0755)
%defattr(0666,cloud,cloud,0755)
%{_datadir}/cloud/bridge/conf/*
%{_datadir}/cloud/bridge/lib/*
%{_datadir}/cloud/bridge/webapps/*

View File

@ -560,7 +560,7 @@ setup_vpcrouter() {
fi
cat > /etc/network/interfaces << EOF
auto lo $1
auto lo
iface lo inet loopback
EOF
setup_interface "0" $ETH0_IP $ETH0_MASK $GW
@ -596,7 +596,10 @@ EOF
fi
if [ -n "$MGMTNET" -a -n "$LOCAL_GW" ]
then
ip route add $MGMTNET via $LOCAL_GW dev eth1
if [ "$hyp" == "vmware" ]
then
ip route add $MGMTNET via $LOCAL_GW dev eth0
fi
fi
ip route delete default

View File

@ -11,7 +11,8 @@ COMMIT
-A INPUT -d 225.0.0.50/32 -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -i eth0 -p tcp --dport 3922 -j ACCEPT
-A INPUT -i eth0 -p tcp -m state --state NEW --dport 3922 -j ACCEPT
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
COMMIT
*mangle

View File

@ -699,7 +699,7 @@ class firewallConfigServer(firewallConfigBase):
if self.syscfg.env.svrMode == "myCloud":
self.ports = "443 8080 8250 8443 9090".split()
else:
self.ports = "8080 8250 9090".split()
self.ports = "8080 7080 8250 9090".split()
class ubuntuFirewallConfigServer(firewallConfigServer):
def allowPort(self, port):

View File

@ -149,7 +149,6 @@ import com.cloud.network.VpnUser;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.network.rules.NetworkACL;
import com.cloud.network.rules.PortForwardingRule;
import com.cloud.network.rules.StaticNatRule;
import com.cloud.network.rules.StickinessPolicy;
@ -3045,6 +3044,15 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setDomain(domain.getName());
response.setOwner(ApiDBUtils.getProjectOwner(project.getId()).getAccountName());
//set tag information
List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.Project, project.getId());
List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
for (ResourceTag tag : tags) {
ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
tagResponses.add(tagResponse);
}
response.setTags(tagResponses);
response.setObjectName("project");
return response;
@ -3095,7 +3103,7 @@ public class ApiResponseHelper implements ResponseGenerator {
}
@Override
public NetworkACLResponse createNetworkACLResponse(NetworkACL networkACL) {
public NetworkACLResponse createNetworkACLResponse(FirewallRule networkACL) {
NetworkACLResponse response = new NetworkACLResponse();
response.setId(networkACL.getId());
@ -3123,6 +3131,16 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setIcmpType(networkACL.getIcmpType());
response.setState(stateToSet);
//set tag information
List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.NetworkACL, networkACL.getId());
List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
for (ResourceTag tag : tags) {
ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
tagResponses.add(tagResponse);
}
response.setTags(tagResponses);
response.setObjectName("networkacl");
return response;
}
@ -3703,6 +3721,16 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setNetworks(networkResponses);
response.setServices(serviceResponses);
//set tag information
List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.Vpc, vpc.getId());
List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
for (ResourceTag tag : tags) {
ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
tagResponses.add(tagResponse);
}
response.setTags(tagResponses);
response.setObjectName("vpc");
return response;
}
@ -3744,6 +3772,15 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setState(stateToSet);
populateAccount(response, result.getAccountId());
populateDomain(response, result.getDomainId());
//set tag information
List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.StaticRoute, result.getId());
List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
for (ResourceTag tag : tags) {
ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
tagResponses.add(tagResponse);
}
response.setTags(tagResponses);
response.setObjectName("staticroute");
return response;

File diff suppressed because it is too large Load Diff

View File

@ -298,6 +298,8 @@ public class FirewallRulesDaoImpl extends GenericDaoBase<FirewallRuleVO, Long> i
_tagsDao.removeBy(id, TaggedResourceType.PortForwardingRule);
} else if (entry.getPurpose() == Purpose.Firewall) {
_tagsDao.removeBy(id, TaggedResourceType.FirewallRule);
} else if (entry.getPurpose() == Purpose.NetworkACL) {
_tagsDao.removeBy(id, TaggedResourceType.NetworkACL);
}
}
boolean result = super.remove(id);

View File

@ -87,6 +87,9 @@ public class PhysicalNetworkServiceProviderVO implements PhysicalNetworkServiceP
@Column(name = "security_group_service_provided")
boolean securitygroupServiceProvided;
@Column(name = "networkacl_service_provided")
boolean networkAclServiceProvided;
@Column(name=GenericDao.REMOVED_COLUMN)
Date removed;
@ -261,6 +264,7 @@ public class PhysicalNetworkServiceProviderVO implements PhysicalNetworkServiceP
this.setPortForwardingServiceProvided(services.contains(Service.PortForwarding));
this.setUserdataServiceProvided(services.contains(Service.UserData));
this.setSecuritygroupServiceProvided(services.contains(Service.SecurityGroup));
this.setNetworkAclServiceProvided(services.contains(Service.NetworkACL));
}
@Override
@ -301,4 +305,13 @@ public class PhysicalNetworkServiceProviderVO implements PhysicalNetworkServiceP
}
return services;
}
@Override
public boolean isNetworkAclServiceProvided() {
return networkAclServiceProvided;
}
public void setNetworkAclServiceProvided(boolean networkAclServiceProvided) {
this.networkAclServiceProvided = networkAclServiceProvided;
}
}

View File

@ -7,4 +7,5 @@ import com.cloud.utils.db.GenericDao;
public interface Site2SiteVpnGatewayDao extends GenericDao<Site2SiteVpnGatewayVO, Long> {
Site2SiteVpnGatewayVO findByIpAddrId(long id);
List<Site2SiteVpnGatewayVO> listByVpcId(long vpcId);
}

View File

@ -6,21 +6,35 @@ import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.network.IPAddressVO;
import com.cloud.network.Site2SiteVpnGatewayVO;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.JoinBuilder.JoinType;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
@Local(value={Site2SiteVpnGatewayDao.class})
public class Site2SiteVpnGatewayDaoImpl extends GenericDaoBase<Site2SiteVpnGatewayVO, Long> implements Site2SiteVpnGatewayDao {
protected final IPAddressDaoImpl _addrDao = ComponentLocator.inject(IPAddressDaoImpl.class);
private static final Logger s_logger = Logger.getLogger(Site2SiteVpnGatewayDaoImpl.class);
private final SearchBuilder<Site2SiteVpnGatewayVO> AllFieldsSearch;
private final SearchBuilder<Site2SiteVpnGatewayVO> VpcSearch;
private final SearchBuilder<IPAddressVO> AddrSearch;
protected Site2SiteVpnGatewayDaoImpl() {
AllFieldsSearch = createSearchBuilder();
AllFieldsSearch.and("addrId", AllFieldsSearch.entity().getAddrId(), SearchCriteria.Op.EQ);
AllFieldsSearch.done();
VpcSearch = createSearchBuilder();
AddrSearch = _addrDao.createSearchBuilder();
AddrSearch.and("vpcId", AddrSearch.entity().getVpcId(), SearchCriteria.Op.EQ);
VpcSearch.join("addrSearch", AddrSearch, AddrSearch.entity().getId(), VpcSearch.entity().getAddrId(), JoinType.INNER);
VpcSearch.done();
}
@Override
@ -29,4 +43,11 @@ public class Site2SiteVpnGatewayDaoImpl extends GenericDaoBase<Site2SiteVpnGatew
sc.setParameters("addrId", id);
return findOneBy(sc);
}
@Override
public List<Site2SiteVpnGatewayVO> listByVpcId(long vpcId) {
SearchCriteria<Site2SiteVpnGatewayVO> sc = VpcSearch.create();
sc.setJoinParameters("addrSearch", "vpcId", vpcId);
return listBy(sc);
}
}

View File

@ -46,7 +46,6 @@ import com.cloud.network.router.VirtualRouter;
import com.cloud.network.router.VirtualRouter.Role;
import com.cloud.network.router.VpcVirtualNetworkApplianceManager;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.NetworkACL;
import com.cloud.network.vpc.PrivateGateway;
import com.cloud.network.vpc.StaticRouteProfile;
import com.cloud.network.vpc.Vpc;
@ -406,7 +405,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
return true;
}
if (!_vpcRouterMgr.applyNetworkACLs(config, (List<NetworkACL>)rules, routers)) {
if (!_vpcRouterMgr.applyNetworkACLs(config, rules, routers)) {
throw new CloudRuntimeException("Failed to apply firewall rules in network " + config.getId());
} else {
return true;

View File

@ -711,42 +711,42 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
}
Long ipAddrId = lb.getSourceIpAddressId();
IPAddressVO ipAddressVO = null;
IPAddressVO ipVO = null;
if (ipAddrId != null) {
ipAddressVO = _ipAddressDao.findById(ipAddrId);
ipVO = _ipAddressDao.findById(ipAddrId);
// Validate ip address
if (ipAddressVO == null) {
if (ipVO == null) {
throw new InvalidParameterValueException("Unable to create load balance rule; ip id=" + ipAddrId + "" +
" doesn't exist in the system");
} else if (ipAddressVO.isOneToOneNat()) {
throw new NetworkRuleConflictException("Can't do load balance on ip address: " + ipAddressVO.getAddress());
} else if (ipVO.isOneToOneNat()) {
throw new NetworkRuleConflictException("Can't do load balance on ip address: " + ipVO.getAddress());
}
}
LoadBalancer result = _elbMgr.handleCreateLoadBalancerRule(lb, lbOwner, lb.getNetworkId());
boolean performedIpAssoc = false;
if (result == null) {
IpAddress ip = null;
IpAddress systemIp = null;
Network guestNetwork = _networkMgr.getNetwork(lb.getNetworkId());
NetworkOffering off = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId());
if (off.getElasticLb() && ipAddressVO == null) {
ip = _networkMgr.assignSystemIp(lb.getNetworkId(), lbOwner, true, false);
lb.setSourceIpAddressId(ip.getId());
if (off.getElasticLb() && ipVO == null) {
systemIp = _networkMgr.assignSystemIp(lb.getNetworkId(), lbOwner, true, false);
lb.setSourceIpAddressId(systemIp.getId());
}
try {
if (ipAddressVO != null) {
if (ipAddressVO.getAssociatedWithNetworkId() == null) {
if (ipVO != null) {
if (ipVO.getAssociatedWithNetworkId() == null) {
//set networkId just for verification purposes
ipAddressVO.setAssociatedWithNetworkId(lb.getNetworkId());
_networkMgr.checkIpForService(ipAddressVO, Service.Lb);
ipVO.setAssociatedWithNetworkId(lb.getNetworkId());
_networkMgr.checkIpForService(ipVO, Service.Lb);
s_logger.debug("The ip is not associated with the network id="+ lb.getNetworkId() + " so assigning");
ipAddressVO = _networkMgr.associateIPToGuestNetwork(ipAddrId, lb.getNetworkId());
ipVO = _networkMgr.associateIPToGuestNetwork(ipAddrId, lb.getNetworkId());
performedIpAssoc = true;
} else {
_networkMgr.checkIpForService(ipAddressVO, Service.Lb);
_networkMgr.checkIpForService(ipVO, Service.Lb);
}
}
@ -760,17 +760,17 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
throw (NetworkRuleConflictException) ex;
}
} finally {
if (result == null && ip != null) {
s_logger.debug("Releasing system IP address " + ip + " as corresponding lb rule failed to create");
_networkMgr.handleSystemIpRelease(ip);
if (result == null && systemIp != null) {
s_logger.debug("Releasing system IP address " + systemIp + " as corresponding lb rule failed to create");
_networkMgr.handleSystemIpRelease(systemIp);
}
// release ip address if ipassoc was perfored
if (performedIpAssoc) {
//if the rule is the last one for the ip address assigned to VPC, unassign it from the network
ip = _ipAddressDao.findById(ip.getId());
if (ip != null && ip.getVpcId() != null && _firewallDao.listByIp(ip.getId()).isEmpty()) {
s_logger.debug("Releasing VPC ip address " + ip + " as LB rule failed to create");
_networkMgr.unassignIPFromVpcNetwork(ip.getId());
ipVO = _ipAddressDao.findById(ipVO.getId());
if (ipVO != null && ipVO.getVpcId() != null && _firewallDao.listByIp(ipVO.getId()).isEmpty()) {
s_logger.debug("Releasing VPC ip address " + ipVO + " as LB rule failed to create");
_networkMgr.unassignIPFromVpcNetwork(ipVO.getId());
}
}
}

View File

@ -48,7 +48,6 @@ import com.cloud.agent.api.GetDomRVersionCmd;
import com.cloud.agent.api.ModifySshKeysCommand;
import com.cloud.agent.api.NetworkUsageAnswer;
import com.cloud.agent.api.NetworkUsageCommand;
import com.cloud.agent.api.RebootAnswer;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.check.CheckSshAnswer;
@ -63,7 +62,6 @@ import com.cloud.agent.api.routing.SetFirewallRulesCommand;
import com.cloud.agent.api.routing.SetPortForwardingRulesCommand;
import com.cloud.agent.api.routing.SetPortForwardingRulesVpcCommand;
import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
import com.cloud.agent.api.routing.Site2SiteVpnCfgCommand;
import com.cloud.agent.api.routing.VmDataCommand;
import com.cloud.agent.api.routing.VpnUsersCfgCommand;
import com.cloud.agent.api.to.FirewallRuleTO;
@ -129,9 +127,6 @@ import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetworkServiceProvider;
import com.cloud.network.PublicIpAddress;
import com.cloud.network.RemoteAccessVpn;
import com.cloud.network.Site2SiteCustomerGatewayVO;
import com.cloud.network.Site2SiteVpnConnection;
import com.cloud.network.Site2SiteVpnGatewayVO;
import com.cloud.network.SshKeysDistriMonitor;
import com.cloud.network.VirtualNetworkApplianceService;
import com.cloud.network.VirtualRouterProvider;
@ -1722,7 +1717,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
* to return DNS server rather than
* virtual router itself. */
if (dnsProvided || dhcpProvided) {
buf.append(" dns1=").append(defaultDns1);
if (defaultDns1 != null) {
buf.append(" dns1=").append(defaultDns1);
}
if (defaultDns2 != null) {
buf.append(" dns2=").append(defaultDns2);
}

View File

@ -22,10 +22,10 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.Site2SiteVpnConnection;
import com.cloud.network.VpcVirtualNetworkApplianceService;
import com.cloud.network.rules.NetworkACL;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.vpc.PrivateGateway;
import com.cloud.network.vpc.StaticRouteProfile;
import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.PrivateGateway;
import com.cloud.user.Account;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.VirtualMachineProfile.Param;
@ -56,7 +56,7 @@ public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplian
* @return
* @throws ResourceUnavailableException
*/
boolean applyNetworkACLs(Network network, List<? extends NetworkACL> rules, List<? extends VirtualRouter> routers)
boolean applyNetworkACLs(Network network, List<? extends FirewallRule> rules, List<? extends VirtualRouter> routers)
throws ResourceUnavailableException;
/**

View File

@ -43,6 +43,7 @@ import com.cloud.agent.api.to.NetworkACLTO;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.manager.Commands;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenterVO;
import com.cloud.deploy.DataCenterDeployment;
import com.cloud.deploy.DeployDestination;
@ -75,7 +76,7 @@ import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
import com.cloud.network.VpcVirtualNetworkApplianceService;
import com.cloud.network.addr.PublicIp;
import com.cloud.network.dao.PhysicalNetworkDao;
import com.cloud.network.rules.NetworkACL;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.vpc.NetworkACLManager;
import com.cloud.network.vpc.PrivateGateway;
import com.cloud.network.vpc.PrivateIpAddress;
@ -100,6 +101,7 @@ import com.cloud.vm.Nic;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachineProfile.Param;
import com.cloud.vm.dao.VMInstanceDao;
@ -666,28 +668,40 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
ReservationContext context) {
if (profile.getVirtualMachine().getVpcId() != null) {
//remove public and guest nics as we will plug them later
String defaultDns1 = null;
String defaultDns2 = null;
//remove public and guest nics as we will plug them later
Iterator<NicProfile> it = profile.getNics().iterator();
while (it.hasNext()) {
NicProfile nic = it.next();
if (nic.getTrafficType() == TrafficType.Public || nic.getTrafficType() == TrafficType.Guest) {
//save dns information
if(nic.getTrafficType() == TrafficType.Public) {
defaultDns1 = nic.getDns1();
defaultDns2 = nic.getDns2();
}
s_logger.debug("Removing nic of type " + nic.getTrafficType() + " from the nics passed on vm start. " +
"The nic will be plugged later");
it.remove();
}
}
//add vpc cidr to the boot load args
//add vpc cidr/dns/networkdomain to the boot load args
StringBuilder buf = profile.getBootArgsBuilder();
Vpc vpc = _vpcMgr.getVpc(profile.getVirtualMachine().getVpcId());
buf.append(" vpccidr=" + vpc.getCidr());
buf.append(" vpccidr=" + vpc.getCidr() + " domain=" + vpc.getNetworkDomain());
buf.append(" dns1=").append(defaultDns1);
if (defaultDns2 != null) {
buf.append(" dns2=").append(defaultDns2);
}
}
return super.finalizeVirtualMachineProfile(profile, dest, context);
}
@Override
public boolean applyNetworkACLs(Network network, final List<? extends NetworkACL> rules, List<? extends VirtualRouter> routers)
public boolean applyNetworkACLs(Network network, final List<? extends FirewallRule> rules, List<? extends VirtualRouter> routers)
throws ResourceUnavailableException {
if (rules == null || rules.isEmpty()) {
s_logger.debug("No network ACLs to be applied for network " + network.getId());
@ -696,20 +710,20 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
return applyRules(network, routers, "network acls", false, null, false, new RuleApplier() {
@Override
public boolean execute(Network network, VirtualRouter router) throws ResourceUnavailableException {
return sendNetworkACLs(router, (List<NetworkACL>)rules, network.getId());
return sendNetworkACLs(router, rules, network.getId());
}
});
}
protected boolean sendNetworkACLs(VirtualRouter router, List<NetworkACL> rules, long guestNetworkId)
protected boolean sendNetworkACLs(VirtualRouter router, List<? extends FirewallRule> rules, long guestNetworkId)
throws ResourceUnavailableException {
Commands cmds = new Commands(OnError.Continue);
createNetworkACLsCommands(rules, router, cmds, guestNetworkId);
return sendCommandsToRouter(router, cmds);
}
private void createNetworkACLsCommands(List<NetworkACL> rules, VirtualRouter router, Commands cmds, long guestNetworkId) {
private void createNetworkACLsCommands(List<? extends FirewallRule> rules, VirtualRouter router, Commands cmds, long guestNetworkId) {
List<NetworkACLTO> rulesTO = null;
String guestVlan = null;
Network guestNtwk = _networkDao.findById(guestNetworkId);
@ -721,7 +735,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
if (rules != null) {
rulesTO = new ArrayList<NetworkACLTO>();
for (NetworkACL rule : rules) {
for (FirewallRule rule : rules) {
NetworkACLTO ruleTO = new NetworkACLTO(rule, guestVlan, rule.getTrafficType());
rulesTO.add(ruleTO);
}
@ -898,11 +912,11 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
super.finalizeNetworkRulesForNetwork(cmds, router, provider, guestNetworkId);
if (_networkMgr.isProviderSupportServiceInNetwork(guestNetworkId, Service.NetworkACL, Provider.VPCVirtualRouter)) {
List<? extends NetworkACL> networkACLs = _networkACLMgr.listNetworkACLs(guestNetworkId);
List<? extends FirewallRule> networkACLs = _networkACLMgr.listNetworkACLs(guestNetworkId);
s_logger.debug("Found " + networkACLs.size() + " network ACLs to apply as a part of VPC VR " + router
+ " start for guest network id=" + guestNetworkId);
if (!networkACLs.isEmpty()) {
createNetworkACLsCommands((List<NetworkACL>)networkACLs, router, cmds, guestNetworkId);
createNetworkACLsCommands(networkACLs, router, cmds, guestNetworkId);
}
}
}
@ -1013,9 +1027,22 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
return true;
}
//send commands to only one router as there is only one in the VPC
return sendStaticRoutes(staticRoutes, routers.get(0));
boolean result = true;
for (VirtualRouter router : routers) {
if (router.getState() == State.Running) {
result = result && sendStaticRoutes(staticRoutes, routers.get(0));
} else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() +
", so not sending StaticRoute command to the backend");
} else {
s_logger.warn("Unable to apply StaticRoute, virtual router is not in the right state " + router.getState());
throw new ResourceUnavailableException("Unable to apply StaticRoute on the backend," +
" virtual router is not in the right state", DataCenter.class, router.getDataCenterIdToDeployIn());
}
}
return result;
}
protected boolean sendStaticRoutes(List<StaticRouteProfile> staticRoutes, DomainRouterVO router)

View File

@ -40,7 +40,7 @@ import com.cloud.utils.net.NetUtils;
@Table(name="firewall_rules")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="purpose", discriminatorType=DiscriminatorType.STRING, length=32)
public class FirewallRuleVO implements Identity, NetworkACL {
public class FirewallRuleVO implements Identity, FirewallRule {
protected final FirewallRulesCidrsDaoImpl _firewallRulesCidrsDao = ComponentLocator.inject(FirewallRulesCidrsDaoImpl.class);
@Id

View File

@ -14,8 +14,6 @@ package com.cloud.network.rules;
import java.util.List;
import com.cloud.network.rules.FirewallRule.FirewallRuleType;
public class StaticNatRuleImpl implements StaticNatRule{
long id;
@ -128,5 +126,10 @@ public class StaticNatRuleImpl implements StaticNatRule{
public FirewallRuleType getType() {
return FirewallRuleType.User;
}
@Override
public TrafficType getTrafficType() {
return null;
}
}

View File

@ -18,6 +18,9 @@ import javax.ejb.Local;
import com.cloud.network.vpc.StaticRoute;
import com.cloud.network.vpc.StaticRouteVO;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;
@ -25,6 +28,7 @@ import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Func;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.Transaction;
/**
* @author Alena Prokharchyk
@ -36,6 +40,7 @@ public class StaticRouteDaoImpl extends GenericDaoBase<StaticRouteVO, Long> impl
protected final SearchBuilder<StaticRouteVO> AllFieldsSearch;
protected final SearchBuilder<StaticRouteVO> NotRevokedSearch;
protected final GenericSearchBuilder<StaticRouteVO, Long> RoutesByGatewayCount;
ResourceTagsDaoImpl _tagsDao = ComponentLocator.inject(ResourceTagsDaoImpl.class);
protected StaticRouteDaoImpl() {
super();
@ -92,4 +97,18 @@ public class StaticRouteDaoImpl extends GenericDaoBase<StaticRouteVO, Long> impl
sc.setParameters("gatewayId", gatewayId);
return customSearch(sc, null).get(0);
}
@Override
@DB
public boolean remove(Long id) {
Transaction txn = Transaction.currentTxn();
txn.start();
StaticRouteVO entry = findById(id);
if (entry != null) {
_tagsDao.removeBy(id, TaggedResourceType.StaticRoute);
}
boolean result = super.remove(id);
txn.commit();
return result;
}
}

View File

@ -18,6 +18,9 @@ import javax.ejb.Local;
import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.VpcVO;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;
@ -25,6 +28,7 @@ import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Func;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.Transaction;
/**
* @author Alena Prokharchyk
@ -35,6 +39,7 @@ import com.cloud.utils.db.SearchCriteria.Op;
public class VpcDaoImpl extends GenericDaoBase<VpcVO, Long> implements VpcDao{
final GenericSearchBuilder<VpcVO, Integer> CountByOfferingId;
final SearchBuilder<VpcVO> AllFieldsSearch;
ResourceTagsDaoImpl _tagsDao = ComponentLocator.inject(ResourceTagsDaoImpl.class);
protected VpcDaoImpl() {
super();
@ -82,5 +87,19 @@ public class VpcDaoImpl extends GenericDaoBase<VpcVO, Long> implements VpcDao{
sc.setParameters("state", Vpc.State.Inactive);
return listBy(sc, null);
}
@Override
@DB
public boolean remove(Long id) {
Transaction txn = Transaction.currentTxn();
txn.start();
VpcVO entry = findById(id);
if (entry != null) {
_tagsDao.removeBy(id, TaggedResourceType.Vpc);
}
boolean result = super.remove(id);
txn.commit();
return result;
}
}

View File

@ -16,7 +16,7 @@ import java.util.List;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.firewall.NetworkACLService;
import com.cloud.network.rules.NetworkACL;
import com.cloud.network.rules.FirewallRule;
import com.cloud.user.Account;
/**
@ -33,6 +33,6 @@ public interface NetworkACLManager extends NetworkACLService{
*/
boolean revokeAllNetworkACLsForNetwork(long networkId, long userId, Account caller) throws ResourceUnavailableException;
List<? extends NetworkACL> listNetworkACLs(long guestNtwkId);
List<? extends FirewallRule> listNetworkACLs(long guestNtwkId);
}

View File

@ -42,8 +42,10 @@ import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.FirewallRule.Purpose;
import com.cloud.network.rules.FirewallRule.TrafficType;
import com.cloud.network.rules.FirewallRuleVO;
import com.cloud.network.rules.NetworkACL;
import com.cloud.projects.Project.ListProjectResourcesCriteria;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.tags.ResourceTagVO;
import com.cloud.tags.dao.ResourceTagDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.UserContext;
@ -52,6 +54,7 @@ import com.cloud.utils.component.Inject;
import com.cloud.utils.component.Manager;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Filter;
import com.cloud.utils.db.JoinBuilder;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op;
@ -68,7 +71,6 @@ public class NetworkACLManagerImpl implements Manager,NetworkACLManager{
String _name;
private static final Logger s_logger = Logger.getLogger(NetworkACLManagerImpl.class);
@Inject
AccountManager _accountMgr;
@Inject
@ -79,7 +81,8 @@ public class NetworkACLManagerImpl implements Manager,NetworkACLManager{
NetworkManager _networkMgr;
@Inject
VpcManager _vpcMgr;
@Inject
ResourceTagDao _resourceTagDao;
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
@ -111,7 +114,7 @@ public class NetworkACLManagerImpl implements Manager,NetworkACLManager{
}
@Override
public NetworkACL createNetworkACL(NetworkACL acl) throws NetworkRuleConflictException {
public FirewallRule createNetworkACL(FirewallRule acl) throws NetworkRuleConflictException {
return createNetworkACL(UserContext.current().getCaller(), acl.getXid(), acl.getSourcePortStart(),
acl.getSourcePortEnd(), acl.getProtocol(), acl.getSourceCidrList(), acl.getIcmpCode(),
acl.getIcmpType(), null, acl.getType(), acl.getNetworkId(), acl.getTrafficType());
@ -119,7 +122,7 @@ public class NetworkACLManagerImpl implements Manager,NetworkACLManager{
@DB
@ActionEvent(eventType = EventTypes.EVENT_FIREWALL_OPEN, eventDescription = "creating firewall rule", create = true)
protected NetworkACL createNetworkACL(Account caller, String xId, Integer portStart,
protected FirewallRule createNetworkACL(Account caller, String xId, Integer portStart,
Integer portEnd, String protocol, List<String> sourceCidrList, Integer icmpCode, Integer icmpType,
Long relatedRuleId, FirewallRule.FirewallRuleType type, long networkId, TrafficType trafficType) throws NetworkRuleConflictException {
@ -173,7 +176,7 @@ public class NetworkACLManagerImpl implements Manager,NetworkACLManager{
txn.commit();
return newRule;
return getNetworkACL(newRule.getId());
}
@ -210,9 +213,13 @@ public class NetworkACLManagerImpl implements Manager,NetworkACLManager{
}
}
protected void detectNetworkACLConflict(NetworkACL newRule) throws NetworkRuleConflictException {
List<FirewallRuleVO> rules = _firewallDao.listByNetworkPurposeTrafficTypeAndNotRevoked(newRule.getNetworkId(), Purpose.NetworkACL, newRule.getTrafficType());
protected void detectNetworkACLConflict(FirewallRuleVO newRule) throws NetworkRuleConflictException {
if (newRule.getPurpose() != Purpose.NetworkACL) {
return;
}
List<FirewallRuleVO> rules = _firewallDao.listByNetworkPurposeTrafficTypeAndNotRevoked(newRule.getNetworkId(),
Purpose.NetworkACL, newRule.getTrafficType());
assert (rules.size() >= 1) : "For network ACLs, we now always first persist the rule and then check for " +
"network conflicts so we should at least have one rule at this point.";
@ -301,8 +308,8 @@ public class NetworkACLManagerImpl implements Manager,NetworkACLManager{
}
@Override
public NetworkACL getNetworkACL(long ACLId) {
FirewallRuleVO rule = _firewallDao.findById(ACLId);
public FirewallRule getNetworkACL(long ACLId) {
FirewallRule rule = _firewallDao.findById(ACLId);
if (rule != null && rule.getPurpose() == Purpose.NetworkACL) {
return rule;
}
@ -310,10 +317,11 @@ public class NetworkACLManagerImpl implements Manager,NetworkACLManager{
}
@Override
public List<? extends NetworkACL> listNetworkACLs(ListNetworkACLsCmd cmd) {
public List<? extends FirewallRule> listNetworkACLs(ListNetworkACLsCmd cmd) {
Long networkId = cmd.getNetworkId();
Long id = cmd.getId();
String trafficType = cmd.getTrafficType();
Map<String, String> tags = cmd.getTags();
Account caller = UserContext.current().getCaller();
List<Long> permittedAccounts = new ArrayList<Long>();
@ -334,6 +342,18 @@ public class NetworkACLManagerImpl implements Manager,NetworkACLManager{
sb.and("network", sb.entity().getNetworkId(), Op.EQ);
sb.and("purpose", sb.entity().getPurpose(), Op.EQ);
sb.and("trafficType", sb.entity().getTrafficType(), Op.EQ);
if (tags != null && !tags.isEmpty()) {
SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
for (int count=0; count < tags.size(); count++) {
tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
tagSearch.cp();
}
tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
sb.groupBy(sb.entity().getId());
sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
}
SearchCriteria<FirewallRuleVO> sc = sb.create();
_accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
@ -349,6 +369,16 @@ public class NetworkACLManagerImpl implements Manager,NetworkACLManager{
if (trafficType != null) {
sc.setParameters("trafficType", trafficType);
}
if (tags != null && !tags.isEmpty()) {
int count = 0;
sc.setJoinParameters("tagSearch", "resourceType", TaggedResourceType.NetworkACL.toString());
for (String key : tags.keySet()) {
sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key);
sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), tags.get(key));
count++;
}
}
sc.setParameters("purpose", Purpose.NetworkACL);
@ -357,7 +387,7 @@ public class NetworkACLManagerImpl implements Manager,NetworkACLManager{
@Override
public List<? extends NetworkACL> listNetworkACLs(long guestNtwkId) {
public List<? extends FirewallRule> listNetworkACLs(long guestNtwkId) {
return _firewallDao.listByNetworkAndPurpose(guestNtwkId, Purpose.NetworkACL);
}

Some files were not shown because too many files have changed in this diff Show More