Merge branch 'master' into api_limit

This commit is contained in:
Min Chen 2013-01-10 09:51:41 -08:00
commit 0b69d9449a
61 changed files with 140 additions and 434 deletions

View File

@ -31,7 +31,7 @@ import com.cloud.exception.ResourceAllocationException;
import com.cloud.network.Network;
import com.cloud.user.UserContext;
@APICommand(description="Creates a private network", responseObject=NetworkResponse.class)
//@APICommand(description="Creates a private network", responseObject=NetworkResponse.class)
public class CreatePrivateNetworkCmd extends BaseAsyncCreateCmd {
public static final Logger s_logger = Logger.getLogger(CreatePrivateNetworkCmd.class.getName());
@ -153,6 +153,7 @@ public class CreatePrivateNetworkCmd extends BaseAsyncCreateCmd {
if (result != null) {
this.setEntityId(result.getId());
this.setEntityUuid(result.getUuid());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a Private network");
}
@ -190,8 +191,4 @@ public class CreatePrivateNetworkCmd extends BaseAsyncCreateCmd {
}
@Override
public String getEntityTable() {
return "networks";
}
}

View File

@ -25,7 +25,7 @@ import com.cloud.event.EventTypes;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@APICommand(description="Destroys console proxy", responseObject=SuccessResponse.class)
//@APICommand(description="Destroys console proxy", responseObject=SuccessResponse.class)
public class DestroyConsoleProxyCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(DestroyConsoleProxyCmd.class.getName());

View File

@ -27,7 +27,7 @@ import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.SnapshotScheduleResponse;
import com.cloud.storage.snapshot.SnapshotSchedule;
@APICommand(description="Lists recurring snapshot schedule", responseObject=SnapshotScheduleResponse.class)
//@APICommand(description="Lists recurring snapshot schedule", responseObject=SnapshotScheduleResponse.class)
public class ListRecurringSnapshotScheduleCmd extends BaseListCmd {
private static final String s_name = "listrecurringsnapshotscheduleresponse";

View File

@ -16,10 +16,8 @@
// under the License.
package com.cloud.exception;
import com.cloud.utils.IdentityProxy;
import java.util.ArrayList;
import com.cloud.utils.exception.CSExceptionErrorCode;
import com.cloud.utils.AnnotationHelper;
/**
* by the API response serializer. Any exceptions that are thrown by

View File

@ -25,6 +25,8 @@ public abstract class BaseAsyncCreateCmd extends BaseAsyncCmd {
@Parameter(name = "id", type = CommandType.LONG)
private Long id;
private String uuid;
public abstract void create() throws ResourceAllocationException;
public Long getEntityId() {
@ -35,14 +37,19 @@ public abstract class BaseAsyncCreateCmd extends BaseAsyncCmd {
this.id = id;
}
public abstract String getEntityTable();
public String getEntityUuid() {
return uuid;
}
public String getResponse(long jobId, long objectId, String objectEntityTable) {
public void setEntityUuid(String uuid) {
this.uuid = uuid;
}
public String getResponse(long jobId, String objectUuid) {
CreateCmdResponse response = new CreateCmdResponse();
AsyncJob job = _entityMgr.findById(AsyncJob.class, jobId);
response.setJobId(job.getUuid());
response.setId(objectId);
response.setIdEntityTable(objectEntityTable);
response.setId(objectUuid);
response.setResponseName(getCommandName());
return _responseGenerator.toSerializedString(response, getResponseType());
}

View File

@ -19,7 +19,6 @@ package org.apache.cloudstack.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;
@ -64,7 +63,6 @@ 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;

View File

@ -17,7 +17,6 @@
package org.apache.cloudstack.api;
import org.apache.cloudstack.api.ApiConstants;
import com.cloud.utils.IdentityProxy;
import org.apache.cloudstack.api.ResponseObject;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
@ -46,6 +45,7 @@ public abstract class BaseResponse implements ResponseObject {
this.objectName = objectName;
}
@Override
public String getObjectId() {
return null;
}
@ -56,18 +56,22 @@ public abstract class BaseResponse implements ResponseObject {
@SerializedName(ApiConstants.JOB_STATUS) @Param(description="the current status of the latest async job acting on this object")
private Integer jobStatus;
@Override
public String getJobId() {
return jobId;
}
@Override
public void setJobId(String jobId) {
this.jobId = jobId;
}
@Override
public Integer getJobStatus() {
return jobStatus;
}
@Override
public void setJobStatus(Integer jobStatus) {
this.jobStatus = jobStatus;
}

View File

@ -81,6 +81,7 @@ public class CreateCounterCmd extends BaseAsyncCreateCmd {
if (ctr != null) {
this.setEntityId(ctr.getId());
this.setEntityUuid(ctr.getUuid());
CounterResponse response = _responseGenerator.createCounterResponse(ctr);
response.setResponseName(getCommandName());
this.setResponseObject(response);
@ -113,8 +114,5 @@ public class CreateCounterCmd extends BaseAsyncCreateCmd {
return Account.ACCOUNT_ID_SYSTEM;
}
@Override
public String getEntityTable() {
return "counter";
}
}

View File

@ -59,10 +59,6 @@ public class AddNetworkServiceProviderCmd extends BaseAsyncCreateCmd {
@Parameter(name=ApiConstants.SERVICE_LIST, type=CommandType.LIST, collectionType = CommandType.STRING, description="the list of services to be enabled for this physical network service provider")
private List<String> enabledServices;
@Override
public String getEntityTable() {
return "physical_network_service_providers";
}
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -116,6 +112,7 @@ public class AddNetworkServiceProviderCmd extends BaseAsyncCreateCmd {
PhysicalNetworkServiceProvider result = _networkService.addProviderToPhysicalNetwork(getPhysicalNetworkId(), getProviderName(), getDestinationPhysicalNetworkId(), getEnabledServices());
if (result != null) {
setEntityId(result.getId());
setEntityUuid(result.getUuid());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add service provider entity to physical network");
}

View File

@ -79,10 +79,6 @@ public class CreatePhysicalNetworkCmd extends BaseAsyncCreateCmd {
return tags;
}
@Override
public String getEntityTable() {
return "physical_network";
}
public Long getZoneId() {
return zoneId;
@ -164,6 +160,7 @@ public class CreatePhysicalNetworkCmd extends BaseAsyncCreateCmd {
PhysicalNetwork result = _networkService.createPhysicalNetwork(getZoneId(),getVlan(),getNetworkSpeed(), getIsolationMethods(),getBroadcastDomainRange(),getDomainId(), getTags(), getNetworkName());
if (result != null) {
setEntityId(result.getId());
setEntityUuid(result.getUuid());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create physical network entity");
}

View File

@ -53,10 +53,7 @@ public class CreateVirtualRouterElementCmd extends BaseAsyncCreateCmd {
this.nspId = nspId;
}
@Override
public String getEntityTable() {
return "virtual_router_providers";
}
public Long getNspId() {
return nspId;
@ -94,6 +91,7 @@ public class CreateVirtualRouterElementCmd extends BaseAsyncCreateCmd {
VirtualRouterProvider result = _service.addElement(getNspId(), VirtualRouterProviderType.VirtualRouter);
if (result != null) {
setEntityId(result.getId());
setEntityUuid(result.getUuid());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add Virtual Router entity to physical network");
}

View File

@ -66,10 +66,6 @@ public class AddTrafficTypeCmd extends BaseAsyncCreateCmd {
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@Override
public String getEntityTable() {
return "physical_network_traffic_types";
}
public Long getPhysicalNetworkId() {
return physicalNetworkId;
@ -136,6 +132,7 @@ public class AddTrafficTypeCmd extends BaseAsyncCreateCmd {
PhysicalNetworkTrafficType result = _networkService.addTrafficTypeToPhysicalNetwork(getPhysicalNetworkId(), getTrafficType(), getXenLabel(), getKvmLabel(), getVmwareLabel(), getSimulatorLabel(), getVlan());
if (result != null) {
setEntityId(result.getId());
setEntityUuid(result.getUuid());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add traffic type to physical network");
}

View File

@ -123,6 +123,7 @@ public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd {
if (result != null) {
this.setEntityId(result.getId());
this.setEntityUuid(result.getUuid());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create private gateway");
}
@ -156,10 +157,6 @@ public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd {
return "creating private gateway";
}
@Override
public String getEntityTable() {
return "vpc_gateways";
}
@Override

View File

@ -70,6 +70,7 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd{
VpcOffering vpcOff = _vpcService.createVpcOffering(getVpcOfferingName(), getDisplayText(), getSupportedServices());
if (vpcOff != null) {
this.setEntityId(vpcOff.getId());
this.setEntityUuid(vpcOff.getUuid());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a VPC offering");
}
@ -87,10 +88,6 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd{
}
}
@Override
public String getEntityTable() {
return "vpc_offerings";
}
@Override
public String getEventType() {

View File

@ -87,9 +87,6 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getEntityTable() {
return "user_ip_address";
}
public String getAccountName() {
if (accountName != null) {
@ -220,6 +217,7 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
if (ip != null) {
this.setEntityId(ip.getId());
this.setEntityUuid(ip.getUuid());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to allocate ip address");
}

View File

@ -62,10 +62,6 @@ public class CreateAutoScalePolicyCmd extends BaseAsyncCreateCmd {
private Long conditionDomainId;
private Long conditionAccountId;
@Override
public String getEntityTable() {
return "autoscale_policies";
}
public int getDuration() {
return duration;
@ -159,6 +155,7 @@ public class CreateAutoScalePolicyCmd extends BaseAsyncCreateCmd {
AutoScalePolicy result = _autoScaleService.createAutoScalePolicy(this);
if (result != null) {
this.setEntityId(result.getId());
this.setEntityUuid(result.getUuid());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create AutoScale Policy");
}

View File

@ -72,10 +72,6 @@ public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd {
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public String getEntityTable() {
return "autoscale_vmgroups";
}
public int getMinMembers() {
return minMembers;
@ -161,6 +157,7 @@ public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd {
AutoScaleVmGroup result = _autoScaleService.createAutoScaleVmGroup(this);
if (result != null) {
this.setEntityId(result.getId());
this.setEntityUuid(result.getUuid());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create Autoscale Vm Group");
}

View File

@ -86,10 +86,7 @@ public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd {
private Long domainId;
private Long accountId;
@Override
public String getEntityTable() {
return "autoscale_vmprofiles";
}
public Long getDomainId() {
if (domainId == null) {
@ -232,6 +229,7 @@ public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd {
AutoScaleVmProfile result = _autoScaleService.createAutoScaleVmProfile(this);
if (result != null) {
this.setEntityId(result.getId());
this.setEntityUuid(result.getUuid());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create Autoscale Vm Profile");
}

View File

@ -72,6 +72,7 @@ public class CreateConditionCmd extends BaseAsyncCreateCmd {
if (condition != null) {
this.setEntityId(condition.getId());
this.setEntityUuid(condition.getUuid());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create condition.");
}
@ -146,8 +147,5 @@ public class CreateConditionCmd extends BaseAsyncCreateCmd {
return accountId;
}
@Override
public String getEntityTable() {
return "conditions";
}
}

View File

@ -80,9 +80,6 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public String getEntityTable() {
return "firewall_rules";
}
public Long getIpAddressId() {
return ipAddressId;
@ -242,6 +239,7 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal
try {
FirewallRule result = _firewallService.createFirewallRule(this);
setEntityId(result.getId());
setEntityUuid(result.getUuid());
} catch (NetworkRuleConflictException ex) {
s_logger.info("Network rule conflict: " + ex.getMessage());
s_logger.trace("Network Rule Conflict: ", ex);

View File

@ -94,9 +94,6 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public String getEntityTable() {
return "firewall_rules";
}
public Long getIpAddressId() {
return ipAddressId;
@ -301,6 +298,7 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
try {
PortForwardingRule result = _rulesService.createPortForwardingRule(this, virtualMachineId, getOpenFirewall());
setEntityId(result.getId());
setEntityUuid(result.getUuid());
} catch (NetworkRuleConflictException ex) {
s_logger.info("Network rule conflict: " , ex);
s_logger.trace("Network Rule Conflict: ", ex);

View File

@ -91,9 +91,7 @@ public class CreateLBStickinessPolicyCmd extends BaseAsyncCreateCmd {
return paramList;
}
public String getEntityTable() {
return "firewall_rules";
}
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@ -141,6 +139,7 @@ public class CreateLBStickinessPolicyCmd extends BaseAsyncCreateCmd {
try {
StickinessPolicy result = _lbService.createLBStickinessPolicy(this);
this.setEntityId(result.getId());
this.setEntityUuid(result.getUuid());
} catch (NetworkRuleConflictException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());

View File

@ -120,9 +120,6 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements
return privatePort;
}
public String getEntityTable() {
return "firewall_rules";
}
public Long getSourceIpAddressId() {
if (publicIpId != null) {
@ -283,6 +280,7 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements
try {
LoadBalancer result = _lbService.createLoadBalancerRule(this, getOpenFirewall());
this.setEntityId(result.getId());
this.setEntityUuid(result.getUuid());
} catch (NetworkRuleConflictException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());

View File

@ -75,9 +75,6 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getEntityTable() {
return "firewall_rules";
}
public Long getIpAddressId() {
return ipAddressId;
@ -151,6 +148,7 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta
try {
StaticNatRule rule = _rulesService.createStaticNatRule(this, getOpenFirewall());
this.setEntityId(rule.getId());
this.setEntityUuid(rule.getUuid());
} catch (NetworkRuleConflictException e) {
s_logger.info("Unable to create Static Nat Rule due to ", e);
throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());

View File

@ -86,10 +86,6 @@ public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements FirewallR
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public String getEntityTable() {
return "firewall_rules";
}
public Long getIpAddressId() {
return null;
}
@ -262,6 +258,7 @@ public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements FirewallR
try {
FirewallRule result = _networkACLService.createNetworkACL(this);
setEntityId(result.getId());
setEntityUuid(result.getUuid());
} catch (NetworkRuleConflictException ex) {
s_logger.info("Network rule conflict: " + ex.getMessage());
s_logger.trace("Network Rule Conflict: ", ex);

View File

@ -56,9 +56,6 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd {
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public String getEntityTable() {
return "projects";
}
public String getAccountName() {
if (accountName != null) {
@ -127,6 +124,7 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd {
Project project = _projectService.createProject(getName(), getDisplayText(), getAccountName(), getDomainId());
if (project != null) {
this.setEntityId(project.getId());
this.setEntityUuid(project.getUuid());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a project");
}

View File

@ -65,9 +65,6 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public String getEntityTable() {
return "snapshots";
}
public String getAccountName() {
return accountName;
@ -153,6 +150,7 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
Snapshot snapshot = _snapshotService.allocSnapshot(getVolumeId(), getPolicyId());
if (snapshot != null) {
this.setEntityId(snapshot.getId());
this.setEntityUuid(snapshot.getUuid());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create snapshot");
}

View File

@ -102,9 +102,6 @@ import com.cloud.user.UserContext;
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public String getEntityTable() {
return "vm_template";
}
public Integer getBits() {
return bits;
@ -240,13 +237,15 @@ import com.cloud.user.UserContext;
public void create() throws ResourceAllocationException {
if (isBareMetal()) {
_bareMetalVmService.createPrivateTemplateRecord(this, _accountService.getAccount(getEntityOwnerId()));
/*Baremetal creates template record after taking image proceeded, use vmId as entity id here*/
/*Baremetal creates template record after taking image proceeded, use vmId as entity id and uuid here*/
this.setEntityId(vmId);
this.setEntityUuid(vmId.toString());
} else {
VirtualMachineTemplate template = null;
template = _userVmService.createPrivateTemplateRecord(this, _accountService.getAccount(getEntityOwnerId()));
if (template != null) {
this.setEntityId(template.getId());
this.setEntityUuid(template.getUuid());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR,
"Failed to create a template");

View File

@ -171,9 +171,6 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getEntityTable() {
return "vm_instance";
}
public String getAccountName() {
if (accountName == null) {
@ -446,6 +443,7 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
if (vm != null) {
setEntityId(vm.getId());
setEntityUuid(vm.getUuid());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to deploy vm");
}

View File

@ -76,9 +76,6 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd {
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getEntityTable() {
return "volumes";
}
public String getAccountName() {
return accountName;
@ -154,6 +151,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd {
Volume volume = _storageService.allocVolume(this);
if (volume != null) {
this.setEntityId(volume.getId());
this.setEntityUuid(volume.getUuid());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create volume");
}

View File

@ -67,6 +67,7 @@ public class CreateStaticRouteCmd extends BaseAsyncCreateCmd{
try {
StaticRoute result = _vpcService.createStaticRoute(getGatewayId(), getCidr());
setEntityId(result.getId());
setEntityUuid(result.getUuid());
} catch (NetworkRuleConflictException ex) {
s_logger.info("Network rule conflict: " + ex.getMessage());
s_logger.trace("Network rule conflict: ", ex);
@ -74,10 +75,6 @@ public class CreateStaticRouteCmd extends BaseAsyncCreateCmd{
}
}
@Override
public String getEntityTable() {
return "static_routes";
}
@Override
public String getEventType() {

View File

@ -124,6 +124,7 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{
getCidr(), getNetworkDomain());
if (vpc != null) {
this.setEntityId(vpc.getId());
this.setEntityUuid(vpc.getUuid());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a VPC");
}
@ -157,11 +158,6 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{
}
}
@Override
public String getEntityTable() {
return "vpc";
}
@Override
public String getEventType() {

View File

@ -103,9 +103,6 @@ public class AddVpnUserCmd extends BaseAsyncCreateCmd {
return accountId;
}
public String getEntityTable() {
return "vpn_users";
}
@Override
public String getEventDescription() {
@ -150,5 +147,6 @@ public class AddVpnUserCmd extends BaseAsyncCreateCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add vpn user");
}
setEntityId(vpnUser.getId());
setEntityUuid(vpnUser.getUuid());
}
}

View File

@ -62,10 +62,6 @@ public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd {
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getEntityTable() {
return "user_ip_address";
}
public Long getPublicIpId() {
return publicIpId;
}
@ -146,6 +142,11 @@ public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd {
RemoteAccessVpn vpn = _ravService.createRemoteAccessVpn(publicIpId, ipRange, getOpenFirewall(), getNetworkId());
if (vpn != null) {
this.setEntityId(vpn.getServerAddressId());
// find uuid for server ip address
IpAddress ipAddr = _entityMgr.findById(IpAddress.class, vpn.getServerAddressId());
if (ipAddr != null) {
this.setEntityUuid(ipAddr.getUuid());
}
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create remote access vpn");
}

View File

@ -51,9 +51,6 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd {
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getEntityTable() {
return "s2s_vpn_connection";
}
public Long getVpnGatewayId() {
return vpnGatewayId;
@ -95,6 +92,7 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd {
Site2SiteVpnConnection conn = _s2sVpnService.createVpnConnection(this);
if (conn != null) {
this.setEntityId(conn.getId());
this.setEntityUuid(conn.getUuid());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create site to site vpn connection");
}

View File

@ -78,9 +78,6 @@ public class CreateVpnCustomerGatewayCmd extends BaseAsyncCmd {
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getEntityTable() {
return "s2s_customer_gateway";
}
public String getName() {
return name;

View File

@ -47,10 +47,6 @@ public class CreateVpnGatewayCmd extends BaseAsyncCmd {
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getEntityTable() {
return "s2s_vpn_gateway";
}
public Long getVpcId() {
return vpcId;
}

View File

@ -44,9 +44,6 @@ public class DeleteVpnConnectionCmd extends BaseAsyncCmd {
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getEntityTable() {
return "s2s_vpn_connection";
}
public Long getId() {
return id;

View File

@ -43,9 +43,6 @@ public class DeleteVpnCustomerGatewayCmd extends BaseAsyncCmd {
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getEntityTable() {
return "s2s_customer_gateway";
}
public Long getId() {
return id;

View File

@ -43,9 +43,6 @@ public class DeleteVpnGatewayCmd extends BaseAsyncCmd {
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getEntityTable() {
return "s2s_vpn_gateway";
}
public Long getId() {
return id;

View File

@ -53,9 +53,6 @@ public class ResetVpnConnectionCmd extends BaseAsyncCmd {
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getEntityTable() {
return "s2s_vpn_connection";
}
public Long getDomainId() {
return domainId;

View File

@ -78,11 +78,7 @@ public class UpdateVpnCustomerGatewayCmd extends BaseAsyncCmd {
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getEntityTable() {
return "s2s_customer_gateway";
}
public Long getId() {
public Long getId() {
return id;
}

View File

@ -17,7 +17,6 @@
package org.apache.cloudstack.api.response;
import org.apache.cloudstack.api.ApiConstants;
import com.cloud.utils.IdentityProxy;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.BaseResponse;

View File

@ -16,24 +16,16 @@
// under the License.
package org.apache.cloudstack.api.response;
import org.apache.cloudstack.api.ApiConstants;
import com.cloud.utils.IdentityProxy;
import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.BaseResponse;
public class CreateCmdResponse extends BaseResponse {
@SerializedName(ApiConstants.ID)
private IdentityProxy id = new IdentityProxy();
private String id;
public Long getId() {
return id.getValue();
public String getId() {
return id;
}
public void setId(Long id) {
this.id.setValue(id);
}
public void setIdEntityTable(String entityTable) {
this.id.setTableName(entityTable);
public void setId(String id) {
this.id = id;
}
}

View File

@ -17,7 +17,6 @@
package org.apache.cloudstack.api.response;
import org.apache.cloudstack.api.ApiConstants;
import com.cloud.utils.IdentityProxy;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.BaseResponse;

View File

@ -19,7 +19,6 @@
package org.apache.cloudstack.api.response;
import com.cloud.serializer.Param;
import com.cloud.utils.IdentityProxy;
import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.BaseResponse;
@ -29,7 +28,7 @@ public class S3Response extends BaseResponse {
@SerializedName(ID)
@Param(description = "The ID of the S3 configuration")
private IdentityProxy id = new IdentityProxy("s3");
private String id;
@SerializedName(S3_ACCESS_KEY)
@Param(description = "The S3 access key")
@ -135,11 +134,11 @@ public class S3Response extends BaseResponse {
@Override
public String getObjectId() {
return this.id.getValue().toString();
return this.id;
}
public void setObjectId(Long id) {
this.id.setValue(id);
public void setObjectId(String id) {
this.id = id;
}
public String getAccessKey() {

View File

@ -16,14 +16,10 @@
// under the License.
package org.apache.cloudstack.discovery;
import com.cloud.utils.component.Adapter;
import com.cloud.utils.component.PluggableService;
import org.apache.cloudstack.api.BaseResponse;
import org.apache.cloudstack.api.response.ListResponse;
import java.util.Map;
public interface ApiDiscoveryService extends Adapter, PluggableService {
public interface ApiDiscoveryService extends PluggableService {
ListResponse<? extends BaseResponse> listApis();
Map<String, Class<?>> getApiNameCmdClassMapping();
}

View File

@ -56,9 +56,6 @@ under the License.
<adapters key="org.apache.cloudstack.acl.APIAccessChecker">
<adapter name="StaticRoleBasedAPIAccessChecker" class="org.apache.cloudstack.acl.StaticRoleBasedAPIAccessChecker"/>
</adapters>
<adapters key="org.apache.cloudstack.discovery.ApiDiscoveryService">
<adapter name="ApiDiscoveryService" class="org.apache.cloudstack.discovery.ApiDiscoveryServiceImpl"/>
</adapters>
<adapters key="com.cloud.agent.manager.allocator.HostAllocator">
<adapter name="FirstFitRouting" class="com.cloud.agent.manager.allocator.impl.FirstFitRoutingAllocator"/>
<!--adapter name="FirstFitRouting" class="com.cloud.agent.manager.allocator.impl.RecreateHostAllocator"/-->

View File

@ -17,7 +17,6 @@
package org.apache.cloudstack.discovery;
import com.cloud.utils.ReflectUtil;
import com.cloud.utils.component.AdapterBase;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.BaseAsyncCmd;
@ -30,7 +29,6 @@ import org.apache.cloudstack.api.response.ListResponse;
import org.apache.log4j.Logger;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
@ -39,36 +37,28 @@ import java.util.Map;
import java.util.Set;
@Local(value = ApiDiscoveryService.class)
public class ApiDiscoveryServiceImpl extends AdapterBase implements ApiDiscoveryService {
public class ApiDiscoveryServiceImpl implements ApiDiscoveryService {
private static final Logger s_logger = Logger.getLogger(ApiDiscoveryServiceImpl.class);
private Map<String, Class<?>> _apiNameCmdClassMap;
private ListResponse<ApiDiscoveryResponse> _discoveryResponse;
private ListResponse<ApiDiscoveryResponse> _discoveryResponse = new ListResponse<ApiDiscoveryResponse>();
private Map<String, Class<?>> _apiNameCmdClassMap = new HashMap<String, Class<?>>();
protected ApiDiscoveryServiceImpl() {
super();
generateApiNameCmdClassMap();
cacheListApiResponse();
}
private void generateApiNameCmdClassMapping() {
_apiNameCmdClassMap = new HashMap<String, Class<?>>();
Set<Class<?>> cmdClasses = ReflectUtil.getClassesWithAnnotation(APICommand.class, new String[]{"org.apache.cloudstack.api", "com.cloud.api"});
private void generateApiNameCmdClassMap() {
Set<Class<?>> cmdClasses = ReflectUtil.getClassesWithAnnotation(APICommand.class,
new String[]{"org.apache.cloudstack.api", "com.cloud.api"});
for(Class<?> cmdClass: cmdClasses) {
String apiName = cmdClass.getAnnotation(APICommand.class).name();
if (_apiNameCmdClassMap.containsKey(apiName)) {
s_logger.error("API Cmd class " + cmdClass.getName() + " has non-unique apiname" + apiName);
continue;
}
_apiNameCmdClassMap.put(apiName, cmdClass);
}
for(Class<?> cmdClass: cmdClasses)
_apiNameCmdClassMap.put(cmdClass.getAnnotation(APICommand.class).name(), cmdClass);
}
private void precacheListApiResponse() {
if(_apiNameCmdClassMap == null)
return;
_discoveryResponse = new ListResponse<ApiDiscoveryResponse>();
private void cacheListApiResponse() {
List<ApiDiscoveryResponse> apiDiscoveryResponses = new ArrayList<ApiDiscoveryResponse>();
@ -117,21 +107,6 @@ public class ApiDiscoveryServiceImpl extends AdapterBase implements ApiDiscovery
_discoveryResponse.setResponses(apiDiscoveryResponses);
}
@Override
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
super.configure(name, params);
generateApiNameCmdClassMapping();
precacheListApiResponse();
return true;
}
public Map<String, Class<?>> getApiNameCmdClassMapping() {
return _apiNameCmdClassMap;
}
@Override
public ListResponse<? extends BaseResponse> listApis() {
return _discoveryResponse;

View File

@ -17,7 +17,6 @@
package com.cloud.api;
import com.google.gson.GsonBuilder;
import com.cloud.utils.IdentityProxy;
import org.apache.cloudstack.api.ResponseObject;
import java.util.Map;
@ -28,7 +27,6 @@ public class ApiGsonHelper {
s_gBuilder = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
s_gBuilder.setVersion(1.3);
s_gBuilder.registerTypeAdapter(ResponseObject.class, new ResponseObjectTypeAdapter());
s_gBuilder.registerTypeAdapter(IdentityProxy.class, new IdentityTypeAdapter());
s_gBuilder.registerTypeAdapter(Map.class, new StringMapTypeAdapter());
}

View File

@ -17,7 +17,6 @@
package com.cloud.api;
import com.google.gson.GsonBuilder;
import com.cloud.utils.IdentityProxy;
import org.apache.cloudstack.api.ResponseObject;
/**
@ -25,13 +24,12 @@ import org.apache.cloudstack.api.ResponseObject;
*/
public class ApiResponseGsonHelper {
private static final GsonBuilder s_gBuilder;
static {
s_gBuilder = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
s_gBuilder.setVersion(1.3);
s_gBuilder.registerTypeAdapter(ResponseObject.class, new ResponseObjectTypeAdapter());
s_gBuilder.registerTypeAdapter(String.class, new EncodedStringTypeAdapter());
s_gBuilder.registerTypeAdapter(IdentityProxy.class, new IdentityTypeAdapter());
}
public static GsonBuilder getBuilder() {

View File

@ -482,7 +482,7 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setEndPoint(result.getEndPoint());
response.setHttpsFlag(result.getHttpsFlag());
response.setMaxErrorRetry(result.getMaxErrorRetry());
response.setObjectId(result.getId());
response.setObjectId(result.getUuid());
response.setSecretKey(result.getSecretKey());
response.setSocketTimeout(result.getSocketTimeout());
response.setTemplateBucketName(result.getBucketName());

View File

@ -61,7 +61,6 @@ import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd;
import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd;
import org.apache.cloudstack.discovery.ApiDiscoveryService;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.ConnectionClosedException;
@ -135,8 +134,6 @@ import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CSExceptionErrorCode;
import com.cloud.uuididentity.dao.IdentityDao;
import org.reflections.Reflections;
public class ApiServer implements HttpRequestHandler {
private static final Logger s_logger = Logger.getLogger(ApiServer.class.getName());
private static final Logger s_accessLogger = Logger.getLogger("apiserver." + ApiServer.class.getName());
@ -154,15 +151,13 @@ public class ApiServer implements HttpRequestHandler {
protected Adapters<APILimitChecker> _apiLimitCheckers;
@Inject(adapter = APIAccessChecker.class)
protected Adapters<APIAccessChecker> _apiAccessCheckers;
@Inject(adapter = ApiDiscoveryService.class)
protected Adapters<ApiDiscoveryService> _apiDiscoveryServices;
private Account _systemAccount = null;
private User _systemUser = null;
private static int _workerCount = 0;
private static ApiServer s_instance = null;
private static final DateFormat _dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
private Map<String, Class<?>> _apiNameCmdClassMap = new HashMap<String, Class<?>>();
private static Map<String, Class<?>> _apiNameCmdClassMap = new HashMap<String, Class<?>>();
private static ExecutorService _executor = new ThreadPoolExecutor(10, 150, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("ApiServer"));
@ -170,23 +165,22 @@ public class ApiServer implements HttpRequestHandler {
super();
}
public static void initApiServer(String[] apiConfig) {
public static void initApiServer() {
if (s_instance == null) {
//Injection will create ApiServer and all its fields which have @Inject
s_instance = ComponentLocator.inject(ApiServer.class);
s_instance.init(apiConfig);
s_instance.init();
}
}
public static ApiServer getInstance() {
// Assumption: CloudStartupServlet would initialize ApiServer
if (s_instance == null) {
s_logger.fatal("ApiServer instance failed to initialize");
ApiServer.initApiServer();
}
return s_instance;
}
public void init(String[] apiConfig) {
public void init() {
BaseCmd.setComponents(new ApiResponseHelper());
BaseListCmd.configure();
@ -207,13 +201,16 @@ public class ApiServer implements HttpRequestHandler {
}
}
for (ApiDiscoveryService discoveryService: _apiDiscoveryServices) {
_apiNameCmdClassMap.putAll(discoveryService.getApiNameCmdClassMapping());
}
Set<Class<?>> cmdClasses = ReflectUtil.getClassesWithAnnotation(APICommand.class,
new String[]{"org.apache.cloudstack.api", "com.cloud.api"});
if (_apiNameCmdClassMap.size() == 0) {
s_logger.fatal("ApiServer failed to generate apiname, cmd class mappings."
+ "Please check and enable at least one ApiDiscovery adapter.");
for(Class<?> cmdClass: cmdClasses) {
String apiName = cmdClass.getAnnotation(APICommand.class).name();
if (_apiNameCmdClassMap.containsKey(apiName)) {
s_logger.error("API Cmd class " + cmdClass.getName() + " has non-unique apiname" + apiName);
continue;
}
_apiNameCmdClassMap.put(apiName, cmdClass);
}
encodeApiResponse = Boolean.valueOf(configDao.getValue(Config.EncodeApiResponse.key()));
@ -408,12 +405,12 @@ public class ApiServer implements HttpRequestHandler {
// BaseAsyncCmd: cmd is processed and submitted as an AsyncJob, job related info is serialized and returned.
if (cmdObj instanceof BaseAsyncCmd) {
Long objectId = null;
String objectEntityTable = null;
String objectUuid = null;
if (cmdObj instanceof BaseAsyncCreateCmd) {
BaseAsyncCreateCmd createCmd = (BaseAsyncCreateCmd) cmdObj;
_dispatcher.dispatchCreateCmd(createCmd, params);
objectId = createCmd.getEntityId();
objectEntityTable = createCmd.getEntityTable();
objectUuid = createCmd.getEntityUuid();
params.put("id", objectId.toString());
} else {
ApiDispatcher.processParameters(cmdObj, params);
@ -457,8 +454,8 @@ public class ApiServer implements HttpRequestHandler {
}
if (objectId != null) {
SerializationContext.current().setUuidTranslation(true);
return ((BaseAsyncCreateCmd) asyncCmd).getResponse(jobId, objectId, objectEntityTable);
String objUuid = (objectUuid == null) ? objectId.toString() : objectUuid;
return ((BaseAsyncCreateCmd) asyncCmd).getResponse(jobId, objUuid);
}
SerializationContext.current().setUuidTranslation(true);
@ -468,6 +465,7 @@ public class ApiServer implements HttpRequestHandler {
// if the command is of the listXXXCommand, we will need to also return the
// the job id and status if possible
// For those listXXXCommand which we have already created DB views, this step is not needed since async job is joined in their db views.
if (cmdObj instanceof BaseListCmd && !(cmdObj instanceof ListVMsCmd) && !(cmdObj instanceof ListRoutersCmd)
&& !(cmdObj instanceof ListSecurityGroupsCmd)
&& !(cmdObj instanceof ListTagsCmd)

View File

@ -1,80 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with 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.
package com.cloud.api;
import java.lang.reflect.Type;
import com.cloud.uuididentity.dao.IdentityDao;
import com.cloud.uuididentity.dao.IdentityDaoImpl;
import com.google.gson.Gson;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.cloud.utils.IdentityProxy;
public class IdentityTypeAdapter implements JsonSerializer<IdentityProxy>, JsonDeserializer<IdentityProxy> {
@Override
public JsonElement serialize(IdentityProxy src, Type srcType, JsonSerializationContext context) {
if(SerializationContext.current().getUuidTranslation()) {
assert(src != null);
if(src.getValue() == null)
return context.serialize(null);
IdentityDao identityDao = new IdentityDaoImpl();
if(src.getTableName() != null) {
String uuid = identityDao.getIdentityUuid(src.getTableName(), String.valueOf(src.getValue()));
if(uuid == null)
return context.serialize(null);
// Exceptions set the _idFieldName in the IdentityProxy structure. So if this field is not
// null, prepare a structure of uuid and idFieldName and return the json representation of that.
String idName = src.getidFieldName();
if (idName != null) {
// Prepare a structure.
JsonObject jsonObj = new JsonObject();
jsonObj.add("uuid", new JsonPrimitive(uuid));
jsonObj.add("uuidProperty", new JsonPrimitive(idName));
return jsonObj;
}
return new JsonPrimitive(uuid);
} else {
return new JsonPrimitive(String.valueOf(src.getValue()));
}
} else {
return new Gson().toJsonTree(src);
}
}
@Override
public IdentityProxy deserialize(JsonElement src, Type srcType,
JsonDeserializationContext context) throws JsonParseException {
IdentityProxy obj = new IdentityProxy();
JsonObject json = src.getAsJsonObject();
obj.setTableName(json.get("_tableName").getAsString());
if(json.get("_value") != null)
obj.setValue(json.get("_value").getAsLong());
return obj;
}
}

View File

@ -37,7 +37,6 @@ import com.cloud.api.ApiResponseGsonHelper;
import com.cloud.api.ApiServer;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.ResponseObject;
import com.cloud.utils.IdentityProxy;
import com.cloud.utils.encoding.URLEncoder;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.uuididentity.dao.IdentityDao;
@ -226,27 +225,17 @@ public class ApiResponseSerializer {
subObj.setObjectName(serializedName.value());
}
serializeResponseObjXML(sb, subObj);
} else if (value instanceof IdentityProxy) {
// Only exception reponses carry a list of IdentityProxy objects.
IdentityProxy idProxy = (IdentityProxy)value;
String id = (idProxy.getValue() != null ? String.valueOf(idProxy.getValue()) : "");
if(!id.isEmpty()) {
IdentityDao identityDao = new IdentityDaoImpl();
id = identityDao.getIdentityUuid(idProxy.getTableName(), id);
}
if(id != null && !id.isEmpty()) {
// If this is the first IdentityProxy field encountered, put in a uuidList tag.
if (!usedUuidList) {
sb.append("<").append(serializedName.value()).append(">");
usedUuidList = true;
}
sb.append("<uuid>").append(id).append("</uuid>");
}
// Append the new idFieldName property also.
String idFieldName = idProxy.getidFieldName();
if (idFieldName != null) {
sb.append("<uuidProperty>").append(idFieldName).append("</uuidProperty>");
}
} else {
// Only exception reponses carry a list of uuid
// strings.
// If this is the first IdentityProxy field
// encountered, put in a uuidList tag.
if (!usedUuidList) {
sb.append("<").append(serializedName.value()).append(">");
usedUuidList = true;
}
sb.append("<uuid>").append(value).append("</uuid>");
// We have removed uuid property field due to removal of IdentityProxy class.
}
}
if (usedUuidList) {
@ -256,19 +245,6 @@ public class ApiResponseSerializer {
} else if (fieldValue instanceof Date) {
sb.append("<").append(serializedName.value()).append(">").append(BaseCmd.getDateString((Date) fieldValue)).
append("</").append(serializedName.value()).append(">");
} else if (fieldValue instanceof IdentityProxy) {
IdentityProxy idProxy = (IdentityProxy)fieldValue;
String id = (idProxy.getValue() != null ? String.valueOf(idProxy.getValue()) : "");
if(!id.isEmpty()) {
IdentityDao identityDao = new IdentityDaoImpl();
if(idProxy.getTableName() != null) {
id = identityDao.getIdentityUuid(idProxy.getTableName(), id);
} else {
s_logger.warn("IdentityProxy sanity check issue, invalid IdentityProxy table name found in class: " + obj.getClass().getName());
}
}
if(id != null && !id.isEmpty())
sb.append("<").append(serializedName.value()).append(">").append(id).append("</").append(serializedName.value()).append(">");
} else {
String resultString = escapeSpecialXmlChars(fieldValue.toString());
if (!(obj instanceof ExceptionResponse)) {

View File

@ -823,26 +823,29 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
String privateIP = router.getPrivateIpAddress();
if (privateIP != null) {
boolean forVpc = router.getVpcId() != null;
List<? extends Nic> routerNics = _nicDao.listByVmId(router.getId());
for (Nic routerNic : routerNics) {
Network network = _networkMgr.getNetwork(routerNic.getNetworkId());
if (network.getTrafficType() == TrafficType.Public) {
boolean forVpc = router.getVpcId() != null;
//Send network usage command for public nic in VPC VR
//Send network usage command for isolated guest nic of non VPC VR
if ((forVpc && network.getTrafficType() == TrafficType.Public) || (!forVpc && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Isolated)) {
final NetworkUsageCommand usageCmd = new NetworkUsageCommand(privateIP, router.getHostName(),
forVpc, routerNic.getIp4Address());
UserStatisticsVO previousStats = _statsDao.findBy(router.getAccountId(),
router.getDataCenterIdToDeployIn(), network.getId(), null, router.getId(), router.getType().toString());
String routerType = router.getType().toString();
UserStatisticsVO previousStats = _statsDao.findBy(router.getAccountId(),
router.getDataCenterIdToDeployIn(), network.getId(), (forVpc ? routerNic.getIp4Address() : null), router.getId(), routerType);
NetworkUsageAnswer answer = null;
try {
answer = (NetworkUsageAnswer) _agentMgr.easySend(router.getHostId(), usageCmd);
} catch (Exception e) {
s_logger.warn("Error while collecting network stats from router: "+router.getInstanceName()+" from host: "+router.getHostId(), e);
s_logger.warn("Error while collecting network stats from router: " + router.getInstanceName() + " from host: " + router.getHostId(), e);
continue;
}
if (answer != null) {
if (!answer.getResult()) {
s_logger.warn("Error while collecting network stats from router: "+router.getInstanceName()+" from host: "+router.getHostId() + "; details: " + answer.getDetails());
s_logger.warn("Error while collecting network stats from router: " + router.getInstanceName() + " from host: " + router.getHostId() + "; details: " + answer.getDetails());
continue;
}
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
@ -852,27 +855,27 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
continue;
}
txn.start();
UserStatisticsVO stats = _statsDao.lock(router.getAccountId(),
router.getDataCenterIdToDeployIn(), network.getId(), routerNic.getIp4Address(), router.getId(), router.getType().toString());
UserStatisticsVO stats = _statsDao.lock(router.getAccountId(),
router.getDataCenterIdToDeployIn(), network.getId(), (forVpc ? routerNic.getIp4Address() : null), router.getId(), routerType);
if (stats == null) {
s_logger.warn("unable to find stats for account: " + router.getAccountId());
continue;
}
if(previousStats != null
&& ((previousStats.getCurrentBytesReceived() != stats.getCurrentBytesReceived())
|| (previousStats.getCurrentBytesSent() != stats.getCurrentBytesSent()))){
if (previousStats != null
&& ((previousStats.getCurrentBytesReceived() != stats.getCurrentBytesReceived())
|| (previousStats.getCurrentBytesSent() != stats.getCurrentBytesSent()))) {
s_logger.debug("Router stats changed from the time NetworkUsageCommand was sent. " +
"Ignoring current answer. Router: "+answer.getRouterName()+" Rcvd: " +
answer.getBytesReceived()+ "Sent: " +answer.getBytesSent());
"Ignoring current answer. Router: " + answer.getRouterName() + " Rcvd: " +
answer.getBytesReceived() + "Sent: " + answer.getBytesSent());
continue;
}
if (stats.getCurrentBytesReceived() > answer.getBytesReceived()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Received # of bytes that's less than the last one. " +
"Assuming something went wrong and persisting it. Router: " +
answer.getRouterName()+" Reported: " + answer.getBytesReceived()
"Assuming something went wrong and persisting it. Router: " +
answer.getRouterName() + " Reported: " + answer.getBytesReceived()
+ " Stored: " + stats.getCurrentBytesReceived());
}
stats.setNetBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived());
@ -881,8 +884,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
if (stats.getCurrentBytesSent() > answer.getBytesSent()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Received # of bytes that's less than the last one. " +
"Assuming something went wrong and persisting it. Router: " +
answer.getRouterName()+" Reported: " + answer.getBytesSent()
"Assuming something went wrong and persisting it. Router: " +
answer.getRouterName() + " Reported: " + answer.getBytesSent()
+ " Stored: " + stats.getCurrentBytesSent());
}
stats.setNetBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent());

View File

@ -103,7 +103,6 @@ public class ConfigurationServerImpl implements ConfigurationServer {
private final AccountDao _accountDao;
private final ResourceCountDao _resourceCountDao;
private final NetworkOfferingServiceMapDao _ntwkOfferingServiceMapDao;
private final IdentityDao _identityDao;
public ConfigurationServerImpl() {
ComponentLocator locator = ComponentLocator.getLocator(Name);
@ -120,7 +119,6 @@ public class ConfigurationServerImpl implements ConfigurationServer {
_accountDao = locator.getDao(AccountDao.class);
_resourceCountDao = locator.getDao(ResourceCountDao.class);
_ntwkOfferingServiceMapDao = locator.getDao(NetworkOfferingServiceMapDao.class);
_identityDao = locator.getDao(IdentityDao.class);
}
@Override

View File

@ -48,7 +48,7 @@ public class CloudStartupServlet extends HttpServlet implements ServletContextLi
s_locator = ComponentLocator.getLocator(ManagementServer.Name);
ManagementServer ms = (ManagementServer)ComponentLocator.getComponent(ManagementServer.Name);
ms.enableAdminUser("password");
ApiServer.initApiServer(ms.getPropertiesFiles());
ApiServer.initApiServer();
} catch (InvalidParameterValueException ipve) {
s_logger.error("Exception starting management server ", ipve);
throw new ServletException (ipve.getMessage());

View File

@ -219,14 +219,14 @@ class TestISO(cloudstackTestCase):
# Finding the OsTypeId from Ostype
ostypes = list_os_types(
cls.api_client,
description=self.services["ostype"]
description=cls.services["ostype"]
)
if not isinstance(ostypes, list):
raise unittest.SkipTest("OSTypeId for given description not found")
self.services["iso_1"]["ostypeid"] = ostypes[0].id
self.services["iso_2"]["ostypeid"] = ostypes[0].id
self.services["ostypeid"] = ostypes[0].id
cls.services["iso_1"]["ostypeid"] = ostypes[0].id
cls.services["iso_2"]["ostypeid"] = ostypes[0].id
cls.services["ostypeid"] = ostypes[0].id
cls.iso_1 = Iso.create(
cls.api_client,

View File

@ -1,60 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// 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.
package com.cloud.utils;
public class IdentityProxy {
private String _tableName;
private Long _value;
private String _idFieldName;
public IdentityProxy() {
}
public IdentityProxy(String tableName) {
_tableName = tableName;
}
public IdentityProxy(String tableName, Long id, String fieldName) {
_tableName = tableName;
_value = id;
_idFieldName = fieldName;
}
public String getTableName() {
return _tableName;
}
public void setTableName(String tableName) {
_tableName = tableName;
}
public Long getValue() {
return _value;
}
public void setValue(Long value) {
_value = value;
}
public void setidFieldName(String value) {
_idFieldName = value;
}
public String getidFieldName() {
return _idFieldName;
}
}

View File

@ -17,7 +17,6 @@
package com.cloud.utils.exception;
import com.cloud.utils.AnnotationHelper;
import com.cloud.utils.IdentityProxy;
import java.util.ArrayList;
/**