Merge branch 'master' into ui-vpc-redesign

This commit is contained in:
Brian Federle 2013-05-10 13:32:41 -07:00
commit d00077ab78
1109 changed files with 14214 additions and 6301 deletions

6
.gitignore vendored
View File

@ -18,10 +18,7 @@
build/replace.properties
build/build.number
bin/
cloudstack-proprietary/
premium/
.lock-wscript
artifacts/
.waf-*
waf-*
target/
@ -37,7 +34,7 @@ cloud-*.tar.bz2
*.egg-info/
*.prefs
build.number
api.log.*.gz
*.log.*.gz
cloud.log.*.*
unittest
deps/cloud.userlibraries
@ -59,6 +56,7 @@ tools/cli/build/
*.iso
*.tar.gz
*.tgz
.*
target-eclipse
awsapi/modules/*
!.gitignore

View File

@ -50,7 +50,9 @@ public interface AsyncJob extends Identity, InternalIdentity {
AutoScaleVmProfile,
AutoScaleVmGroup,
GlobalLoadBalancerRule,
LoadBalancerRule,
AffinityGroup,
InternalLbVm,
DedicatedGuestVlanRange
}

View File

@ -16,6 +16,9 @@
// under the License.
package com.cloud.event;
import java.util.HashMap;
import java.util.Map;
import com.cloud.configuration.Configuration;
import com.cloud.dc.DataCenter;
import com.cloud.dc.Pod;
@ -23,8 +26,18 @@ import com.cloud.dc.StorageNetworkIpRange;
import com.cloud.dc.Vlan;
import com.cloud.domain.Domain;
import com.cloud.host.Host;
import com.cloud.network.*;
import com.cloud.network.as.*;
import com.cloud.network.GuestVlan;
import com.cloud.network.Network;
import com.cloud.network.PhysicalNetwork;
import com.cloud.network.PhysicalNetworkServiceProvider;
import com.cloud.network.PhysicalNetworkTrafficType;
import com.cloud.network.PublicIpAddress;
import com.cloud.network.RemoteAccessVpn;
import com.cloud.network.as.AutoScaleCounter;
import com.cloud.network.as.AutoScalePolicy;
import com.cloud.network.as.AutoScaleVmGroup;
import com.cloud.network.as.AutoScaleVmProfile;
import com.cloud.network.as.Condition;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.network.rules.StaticNat;
@ -43,9 +56,6 @@ import com.cloud.user.Account;
import com.cloud.user.User;
import com.cloud.vm.VirtualMachine;
import java.util.HashMap;
import java.util.Map;
public class EventTypes {
//map of Event and corresponding entity for which Event is applicable
@ -389,11 +399,15 @@ public class EventTypes {
public static final String EVENT_AFFINITY_GROUP_ASSIGN = "AG.ASSIGN";
public static final String EVENT_AFFINITY_GROUP_REMOVE = "AG.REMOVE";
public static final String EVENT_VM_AFFINITY_GROUP_UPDATE = "VM.AG.UPDATE";
public static final String EVENT_INTERNAL_LB_VM_START = "INTERNALLBVM.START";
public static final String EVENT_INTERNAL_LB_VM_STOP = "INTERNALLBVM.STOP";
// Dedicated guest vlan range
public static final String EVENT_GUEST_VLAN_RANGE_DEDICATE = "GUESTVLANRANGE.DEDICATE";
public static final String EVENT_DEDICATED_GUEST_VLAN_RANGE_RELEASE = "GUESTVLANRANGE.RELEASE";
static {
// TODO: need a way to force author adding event types to declare the entity details as well, with out braking

View File

@ -81,4 +81,7 @@ public interface IpAddress extends ControlledEntity, Identity, InternalIdentity
Long getVpcId();
String getVmIp();
Long getNetworkId();
}

View File

@ -16,18 +16,19 @@
// under the License.
package com.cloud.network;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.Mode;
import com.cloud.network.Networks.TrafficType;
import com.cloud.utils.fsm.StateMachine2;
import com.cloud.utils.fsm.StateObject;
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
/**
* owned by an account.
@ -50,7 +51,7 @@ public interface Network extends ControlledEntity, StateObject<Network.State>, I
Capability.MultipleIps, Capability.TrafficStatistics, Capability.SupportedTrafficDirection, Capability.SupportedEgressProtocols);
public static final Service Lb = new Service("Lb", Capability.SupportedLBAlgorithms, Capability.SupportedLBIsolation,
Capability.SupportedProtocols, Capability.TrafficStatistics, Capability.LoadBalancingSupportedIps,
Capability.SupportedStickinessMethods, Capability.ElasticLb);
Capability.SupportedStickinessMethods, Capability.ElasticLb, Capability.LbSchemes);
public static final Service UserData = new Service("UserData");
public static final Service SourceNat = new Service("SourceNat", Capability.SupportedSourceNatTypes, Capability.RedundantRouter);
public static final Service StaticNat = new Service("StaticNat", Capability.ElasticIp);
@ -124,6 +125,7 @@ public interface Network extends ControlledEntity, StateObject<Network.State>, I
public static final Provider None = new Provider("None", false);
// NiciraNvp is not an "External" provider, otherwise we get in trouble with NetworkServiceImpl.providersConfiguredForExternalNetworking
public static final Provider NiciraNvp = new Provider("NiciraNvp", false);
public static final Provider InternalLbVm = new Provider("InternalLbVm", false);
public static final Provider CiscoVnmc = new Provider("CiscoVnmc", true);
private String name;
@ -177,6 +179,7 @@ public interface Network extends ControlledEntity, StateObject<Network.State>, I
public static final Capability SupportedTrafficDirection = new Capability("SupportedTrafficDirection");
public static final Capability SupportedEgressProtocols = new Capability("SupportedEgressProtocols");
public static final Capability HealthCheckPolicy = new Capability("HealthCheckPolicy");
public static final Capability LbSchemes = new Capability("LbSchemes");
private String name;

View File

@ -33,6 +33,7 @@ import com.cloud.network.Networks.TrafficType;
import com.cloud.network.element.NetworkElement;
import com.cloud.network.element.UserDataServiceProvider;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.Detail;
import com.cloud.user.Account;
import com.cloud.vm.Nic;
import com.cloud.vm.NicProfile;
@ -264,5 +265,11 @@ public interface NetworkModel {
Nic getPlaceholderNicForRouter(Network network, Long podId);
IpAddress getPublicIpAddress(String ipAddress, long zoneId);
List<String> getUsedIpsInNetwork(Network network);
Map<Detail, String> getNtwkOffDetails(long offId);
Networks.IsolationType[] listNetworkIsolationMethods();
}

View File

@ -63,5 +63,7 @@ public interface VirtualNetworkApplianceService {
VirtualRouter startRouter(long id) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException;
VirtualRouter destroyRouter(long routerId, Account caller, Long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException;
VirtualRouter findRouter(long routerId);
}

View File

@ -23,7 +23,8 @@ public interface VirtualRouterProvider extends InternalIdentity, Identity {
public enum VirtualRouterProviderType {
VirtualRouter,
ElasticLoadBalancerVm,
VPCVirtualRouter
VPCVirtualRouter,
InternalLbVm
}
public VirtualRouterProviderType getType();

View File

@ -25,111 +25,83 @@ import com.cloud.network.as.Condition;
import com.cloud.network.as.Counter;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.utils.Pair;
import com.cloud.utils.net.Ip;
public class LoadBalancingRule implements FirewallRule, LoadBalancer {
public class LoadBalancingRule {
private LoadBalancer lb;
private Ip sourceIp;
private List<LbDestination> destinations;
private List<LbStickinessPolicy> stickinessPolicies;
private LbAutoScaleVmGroup autoScaleVmGroup;
private List<LbHealthCheckPolicy> healthCheckPolicies;
public LoadBalancingRule(LoadBalancer lb, List<LbDestination> destinations,
List<LbStickinessPolicy> stickinessPolicies, List<LbHealthCheckPolicy> healthCheckPolicies) {
List<LbStickinessPolicy> stickinessPolicies, List<LbHealthCheckPolicy> healthCheckPolicies, Ip sourceIp) {
this.lb = lb;
this.destinations = destinations;
this.stickinessPolicies = stickinessPolicies;
this.healthCheckPolicies = healthCheckPolicies;
this.sourceIp = sourceIp;
}
@Override
public long getId() {
return lb.getId();
}
@Override
public long getAccountId() {
return lb.getAccountId();
}
@Override
public long getDomainId() {
return lb.getDomainId();
}
@Override
public String getName() {
return lb.getName();
}
@Override
public String getDescription() {
return lb.getDescription();
}
@Override
public int getDefaultPortStart() {
return lb.getDefaultPortStart();
}
@Override
public int getDefaultPortEnd() {
return lb.getDefaultPortEnd();
}
@Override
public String getAlgorithm() {
return lb.getAlgorithm();
}
@Override
public String getUuid() {
return lb.getUuid();
}
@Override
public String getXid() {
return lb.getXid();
}
@Override
public Long getSourceIpAddressId() {
return lb.getSourceIpAddressId();
}
@Override
public Integer getSourcePortStart() {
return lb.getSourcePortStart();
}
@Override
public Integer getSourcePortEnd() {
return lb.getSourcePortEnd();
}
@Override
public String getProtocol() {
return lb.getProtocol();
}
@Override
public Purpose getPurpose() {
return Purpose.LoadBalancing;
public FirewallRule.Purpose getPurpose() {
return FirewallRule.Purpose.LoadBalancing;
}
@Override
public State getState() {
public FirewallRule.State getState() {
return lb.getState();
}
@Override
public long getNetworkId() {
return lb.getNetworkId();
}
public LoadBalancer getLb() {
return lb;
}
public void setDestinations(List<LbDestination> destinations) {
this.destinations = destinations;
@ -287,36 +259,6 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
}
}
@Override
public Integer getIcmpCode() {
return null;
}
@Override
public Integer getIcmpType() {
return null;
}
@Override
public List<String> getSourceCidrList() {
return null;
}
@Override
public Long getRelated() {
return null;
}
@Override
public TrafficType getTrafficType() {
return null;
}
@Override
public FirewallRuleType getType() {
return FirewallRuleType.User;
}
public LbAutoScaleVmGroup getAutoScaleVmGroup() {
return autoScaleVmGroup;
}
@ -473,4 +415,11 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
}
}
public Ip getSourceIp() {
return sourceIp;
}
public Scheme getScheme() {
return lb.getScheme();
}
}

View File

@ -17,10 +17,10 @@
package com.cloud.network.lb;
import java.util.List;
import java.util.Map;
import org.apache.cloudstack.api.command.user.loadbalancer.CreateLBHealthCheckPolicyCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.CreateLBStickinessPolicyCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.CreateLoadBalancerRuleCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.ListLBHealthCheckPoliciesCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.ListLBStickinessPoliciesCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.ListLoadBalancerRuleInstancesCmd;
@ -30,12 +30,13 @@ import org.apache.cloudstack.api.command.user.loadbalancer.UpdateLoadBalancerRul
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
import com.cloud.network.rules.HealthCheckPolicy;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.network.rules.StickinessPolicy;
import com.cloud.uservm.UserVm;
import com.cloud.utils.Pair;
import com.cloud.utils.net.Ip;
public interface LoadBalancingRulesService {
@ -49,7 +50,9 @@ public interface LoadBalancingRulesService {
* @return the newly created LoadBalancerVO if successful, null otherwise
* @throws InsufficientAddressCapacityException
*/
LoadBalancer createLoadBalancerRule(CreateLoadBalancerRuleCmd lb, boolean openFirewall) throws NetworkRuleConflictException, InsufficientAddressCapacityException;
LoadBalancer createPublicLoadBalancerRule(String xId, String name, String description,
int srcPortStart, int srcPortEnd, int defPortStart, int defPortEnd, Long ipAddrId, String protocol, String algorithm,
long networkId, long lbOwnerId, boolean openFirewall) throws NetworkRuleConflictException, InsufficientAddressCapacityException;
LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd);
@ -134,8 +137,9 @@ public interface LoadBalancingRulesService {
List<? extends HealthCheckPolicy> searchForLBHealthCheckPolicies(ListLBHealthCheckPoliciesCmd cmd);
List<LoadBalancingRule> listByNetworkId(long networkId);
LoadBalancer findById(long LoadBalancer);
public void updateLBHealthChecks() throws ResourceUnavailableException;
public void updateLBHealthChecks(Scheme scheme) throws ResourceUnavailableException;
Map<Ip, UserVm> getLbInstances(long lbId);
}

View File

@ -23,7 +23,7 @@ import com.cloud.vm.VirtualMachine;
*/
public interface VirtualRouter extends VirtualMachine {
public enum Role {
VIRTUAL_ROUTER, LB
VIRTUAL_ROUTER, LB, INTERNAL_LB_VM
}
Role getRole();
boolean getIsRedundantRouter();

View File

@ -19,16 +19,10 @@ package com.cloud.network.rules;
/**
* Definition for a LoadBalancer
*/
public interface LoadBalancer extends FirewallRule {
String getName();
String getDescription();
public interface LoadBalancer extends FirewallRule, LoadBalancerContainer {
int getDefaultPortStart();
int getDefaultPortEnd();
String getAlgorithm();
}

View File

@ -14,17 +14,20 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.storage;
package com.cloud.network.rules;
public interface SecondaryStorage {
public interface LoadBalancerContainer {
String getBackupPath();
String getTemplatePath();
String getIsoPath();
public enum Scheme {
Public, Internal;
}
void createTemplate();
String getName();
String getDescription();
void destroyTemplate();
String getAlgorithm();
Scheme getScheme();
}

View File

@ -31,6 +31,8 @@ public interface SecurityGroupRules extends InternalIdentity {
Long getRuleId();
String getRuleUuid();
int getStartPort();
int getEndPort();

View File

@ -26,6 +26,7 @@ public interface VpcOffering extends InternalIdentity, Identity {
}
public static final String defaultVPCOfferingName = "Default VPC offering";
public static final String defaultVPCNSOfferingName = "Default VPC offering with Netscaler";
/**
*

View File

@ -16,6 +16,8 @@
// under the License.
package com.cloud.offering;
import java.util.Map;
import org.apache.cloudstack.acl.InfrastructureEntity;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
@ -38,6 +40,11 @@ public interface NetworkOffering extends InfrastructureEntity, InternalIdentity,
Disabled,
Enabled
}
public enum Detail {
InternalLbProvider,
PublicLbProvider
}
public final static String SystemPublicNetwork = "System-Public-Network";
public final static String SystemControlNetwork = "System-Control-Network";
@ -116,5 +123,9 @@ public interface NetworkOffering extends InfrastructureEntity, InternalIdentity,
boolean isInline();
boolean getIsPersistent();
boolean getInternalLb();
boolean getPublicLb();
}

View File

@ -30,6 +30,7 @@ public interface ServiceOffering extends InfrastructureEntity, InternalIdentity,
public static final String ssvmDefaultOffUniqueName = "Cloud.com-SecondaryStorage";
public static final String routerDefaultOffUniqueName = "Cloud.Com-SoftwareRouter";
public static final String elbVmDefaultOffUniqueName = "Cloud.Com-ElasticLBVm";
public static final String internalLbVmDefaultOffUniqueName = "Cloud.Com-InternalLBVm";
public enum StorageType {
local,

View File

@ -19,8 +19,6 @@ package com.cloud.storage;
import java.net.URI;
import java.util.Map;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import com.cloud.exception.DiscoveryException;
import com.cloud.utils.component.Adapter;
@ -29,7 +27,7 @@ import com.cloud.utils.component.Adapter;
*/
public interface StoragePoolDiscoverer extends Adapter {
Map<StoragePoolVO, Map<String, String>> find(long dcId, Long podId, URI uri, Map<String, String> details) throws DiscoveryException;
Map<StoragePoolVO, Map<String, String>> find(long dcId, Long podId, URI uri, Map<String, String> details, String username, String password) throws DiscoveryException;
Map<? extends StoragePool, Map<String, String>> find(long dcId, Long podId, URI uri, Map<String, String> details) throws DiscoveryException;
Map<? extends StoragePool, Map<String, String>> find(long dcId, Long podId, URI uri, Map<String, String> details, String username, String password) throws DiscoveryException;
}

View File

@ -16,12 +16,12 @@
// under the License.
package com.cloud.storage.snapshot;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
import java.util.Date;
public interface SnapshotSchedule {
long getId();
String getUuid();
public interface SnapshotSchedule extends InternalIdentity, Identity {
Long getVolumeId();
@ -38,10 +38,9 @@ public interface SnapshotSchedule {
Long getAsyncJobId();
void setAsyncJobId(long asyncJobId);
void setAsyncJobId(Long asyncJobId);
Long getSnapshotId();
void setSnapshotId(Long snapshotId);
}

View File

@ -186,6 +186,7 @@ public interface VirtualMachine extends RunningOn, ControlledEntity, Identity, I
SecondaryStorageVm,
ElasticIpVm,
ElasticLoadBalancerVm,
InternalLoadBalancerVm,
/*
* UserBareMetal is only used for selecting VirtualMachineGuru, there is no
@ -196,7 +197,7 @@ public interface VirtualMachine extends RunningOn, ControlledEntity, Identity, I
public static boolean isSystemVM(VirtualMachine.Type vmtype) {
if (DomainRouter.equals(vmtype)
|| ConsoleProxy.equals(vmtype)
|| SecondaryStorageVm.equals(vmtype)) {
|| SecondaryStorageVm.equals(vmtype) || InternalLoadBalancerVm.equals(vmtype)) {
return true;
}
return false;

View File

@ -480,6 +480,12 @@ public class ApiConstants {
public static final String HEALTHCHECK_HEALTHY_THRESHOLD = "healthythreshold";
public static final String HEALTHCHECK_UNHEALTHY_THRESHOLD = "unhealthythreshold";
public static final String HEALTHCHECK_PINGPATH = "pingpath";
public static final String SOURCE_PORT = "sourceport";
public static final String INSTANCE_PORT = "instanceport";
public static final String SOURCE_IP = "sourceipaddress";
public static final String SOURCE_IP_NETWORK_ID = "sourceipaddressnetworkid";
public static final String SCHEME = "scheme";
public static final String PROVIDER_TYPE = "providertype";
public static final String AFFINITY_GROUP_IDS = "affinitygroupids";
public static final String AFFINITY_GROUP_NAMES = "affinitygroupnames";
public static final String ASA_INSIDE_PORT_PROFILE = "insideportprofile";

View File

@ -28,6 +28,9 @@ import java.util.regex.Pattern;
import javax.inject.Inject;
import org.apache.cloudstack.affinity.AffinityGroupService;
import org.apache.cloudstack.network.element.InternalLoadBalancerElementService;
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerService;
import org.apache.cloudstack.network.lb.InternalLoadBalancerVMService;
import org.apache.cloudstack.query.QueryService;
import org.apache.cloudstack.usage.UsageService;
import org.apache.log4j.Logger;
@ -139,7 +142,11 @@ public abstract class BaseCmd {
@Inject public VMSnapshotService _vmSnapshotService;
@Inject public DataStoreProviderApiService dataStoreProviderApiService;
@Inject public VpcProvisioningService _vpcProvSvc;
@Inject public ApplicationLoadBalancerService _newLbSvc;
@Inject public ApplicationLoadBalancerService _appLbService;
@Inject public AffinityGroupService _affinityGroupService;
@Inject public InternalLoadBalancerElementService _internalLbElementSvc;
@Inject public InternalLoadBalancerVMService _internalLbSvc;
@Inject public NetworkModel _ntwkModel;
public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException;

View File

@ -19,14 +19,15 @@ package org.apache.cloudstack.api;
import java.text.DecimalFormat;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import com.cloud.vm.NicSecondaryIp;
import org.apache.cloudstack.affinity.AffinityGroup;
import org.apache.cloudstack.affinity.AffinityGroupResponse;
import org.apache.cloudstack.api.ApiConstants.HostDetails;
import org.apache.cloudstack.api.ApiConstants.VMDetails;
import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse;
import org.apache.cloudstack.api.response.AsyncJobResponse;
import org.apache.cloudstack.api.response.AutoScalePolicyResponse;
import org.apache.cloudstack.api.response.AutoScaleVmGroupResponse;
@ -44,11 +45,15 @@ import org.apache.cloudstack.api.response.EventResponse;
import org.apache.cloudstack.api.response.ExtractResponse;
import org.apache.cloudstack.api.response.FirewallResponse;
import org.apache.cloudstack.api.response.FirewallRuleResponse;
import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse;
import org.apache.cloudstack.api.response.GuestOSResponse;
import org.apache.cloudstack.api.response.GuestVlanRangeResponse;
import org.apache.cloudstack.api.response.HostForMigrationResponse;
import org.apache.cloudstack.api.response.HostResponse;
import org.apache.cloudstack.api.response.HypervisorCapabilitiesResponse;
import org.apache.cloudstack.api.response.IPAddressResponse;
import org.apache.cloudstack.api.response.InstanceGroupResponse;
import org.apache.cloudstack.api.response.InternalLoadBalancerElementResponse;
import org.apache.cloudstack.api.response.IpForwardingRuleResponse;
import org.apache.cloudstack.api.response.IsolationMethodResponse;
import org.apache.cloudstack.api.response.LBHealthCheckResponse;
@ -84,6 +89,7 @@ import org.apache.cloudstack.api.response.SnapshotResponse;
import org.apache.cloudstack.api.response.SnapshotScheduleResponse;
import org.apache.cloudstack.api.response.StaticRouteResponse;
import org.apache.cloudstack.api.response.StorageNetworkIpRangeResponse;
import org.apache.cloudstack.api.response.StoragePoolForMigrationResponse;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.response.SwiftResponse;
import org.apache.cloudstack.api.response.SystemVmInstanceResponse;
@ -103,6 +109,7 @@ import org.apache.cloudstack.api.response.VpcOfferingResponse;
import org.apache.cloudstack.api.response.VpcResponse;
import org.apache.cloudstack.api.response.VpnUsersResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
import org.apache.cloudstack.region.Region;
import org.apache.cloudstack.usage.Usage;
@ -119,10 +126,25 @@ import com.cloud.domain.Domain;
import com.cloud.event.Event;
import com.cloud.host.Host;
import com.cloud.hypervisor.HypervisorCapabilities;
import com.cloud.network.*;
import com.cloud.network.GuestVlan;
import com.cloud.network.IpAddress;
import com.cloud.network.Network;
import com.cloud.network.Network.Service;
import com.cloud.network.Networks.IsolationType;
import com.cloud.network.as.*;
import com.cloud.network.PhysicalNetwork;
import com.cloud.network.PhysicalNetworkServiceProvider;
import com.cloud.network.PhysicalNetworkTrafficType;
import com.cloud.network.RemoteAccessVpn;
import com.cloud.network.Site2SiteCustomerGateway;
import com.cloud.network.Site2SiteVpnConnection;
import com.cloud.network.Site2SiteVpnGateway;
import com.cloud.network.VirtualRouterProvider;
import com.cloud.network.VpnUser;
import com.cloud.network.as.AutoScalePolicy;
import com.cloud.network.as.AutoScaleVmGroup;
import com.cloud.network.as.AutoScaleVmProfile;
import com.cloud.network.as.Condition;
import com.cloud.network.as.Counter;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.HealthCheckPolicy;
@ -145,7 +167,12 @@ import com.cloud.projects.ProjectAccount;
import com.cloud.projects.ProjectInvitation;
import com.cloud.region.ha.GlobalLoadBalancerRule;
import com.cloud.server.ResourceTag;
import com.cloud.storage.*;
import com.cloud.storage.GuestOS;
import com.cloud.storage.S3;
import com.cloud.storage.Snapshot;
import com.cloud.storage.StoragePool;
import com.cloud.storage.Swift;
import com.cloud.storage.Volume;
import com.cloud.storage.snapshot.SnapshotPolicy;
import com.cloud.storage.snapshot.SnapshotSchedule;
import com.cloud.template.VirtualMachineTemplate;
@ -153,11 +180,12 @@ import com.cloud.user.Account;
import com.cloud.user.User;
import com.cloud.user.UserAccount;
import com.cloud.uservm.UserVm;
import com.cloud.utils.net.Ip;
import com.cloud.vm.InstanceGroup;
import com.cloud.vm.Nic;
import com.cloud.vm.snapshot.VMSnapshot;
import com.cloud.vm.NicSecondaryIp;
import com.cloud.vm.VirtualMachine;
import org.apache.cloudstack.api.response.*;
import com.cloud.vm.snapshot.VMSnapshot;
public interface ResponseGenerator {
UserResponse createUserResponse(UserAccount user);
@ -397,9 +425,13 @@ public interface ResponseGenerator {
NicSecondaryIpResponse createSecondaryIPToNicResponse(NicSecondaryIp result);
public NicResponse createNicResponse(Nic result);
ApplicationLoadBalancerResponse createLoadBalancerContainerReponse(ApplicationLoadBalancerRule lb, Map<Ip, UserVm> lbInstances);
AffinityGroupResponse createAffinityGroupResponse(AffinityGroup group);
Long getAffinityGroupId(String name, long entityOwnerId);
InternalLoadBalancerElementResponse createInternalLbElementResponse(VirtualRouterProvider result);
IsolationMethodResponse createIsolationMethodResponse(IsolationType method);
}

View File

@ -0,0 +1,114 @@
// 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 org.apache.cloudstack.api.command.admin.internallb;
import java.util.List;
import javax.inject.Inject;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.InternalLoadBalancerElementResponse;
import org.apache.cloudstack.network.element.InternalLoadBalancerElementService;
import org.apache.log4j.Logger;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.VirtualRouterProvider;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@APICommand(name = "configureInternalLoadBalancerElement", responseObject=InternalLoadBalancerElementResponse.class,
description="Configures an Internal Load Balancer element.", since="4.2.0")
public class ConfigureInternalLoadBalancerElementCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(ConfigureInternalLoadBalancerElementCmd.class.getName());
private static final String s_name = "configureinternalloadbalancerelementresponse";
@Inject
private List<InternalLoadBalancerElementService> _service;
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = InternalLoadBalancerElementResponse.class,
required=true, description="the ID of the internal lb provider")
private Long id;
@Parameter(name=ApiConstants.ENABLED, type=CommandType.BOOLEAN, required=true, description="Enables/Disables the Internal Load Balancer element")
private Boolean enabled;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Long getId() {
return id;
}
public Boolean getEnabled() {
return enabled;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
@Override
public String getEventType() {
return EventTypes.EVENT_NETWORK_ELEMENT_CONFIGURE;
}
@Override
public String getEventDescription() {
return "configuring internal load balancer element: " + id;
}
@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
s_logger.debug("hello alena");
UserContext.current().setEventDetails("Internal load balancer element: " + id);
s_logger.debug("hello alena");
VirtualRouterProvider result = _service.get(0).configureInternalLoadBalancerElement(getId(), getEnabled());
s_logger.debug("hello alena");
if (result != null){
InternalLoadBalancerElementResponse routerResponse = _responseGenerator.createInternalLbElementResponse(result);
routerResponse.setResponseName(getCommandName());
this.setResponseObject(routerResponse);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to configure the internal load balancer element");
}
}
}

View File

@ -0,0 +1,116 @@
// 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 org.apache.cloudstack.api.command.admin.internallb;
import java.util.List;
import javax.inject.Inject;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.InternalLoadBalancerElementResponse;
import org.apache.cloudstack.api.response.ProviderResponse;
import org.apache.cloudstack.network.element.InternalLoadBalancerElementService;
import org.apache.log4j.Logger;
import com.cloud.event.EventTypes;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.network.VirtualRouterProvider;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@APICommand(name = "createInternalLoadBalancerElement", responseObject=InternalLoadBalancerElementResponse.class, description="Create an Internal Load Balancer element.",since="4.2.0")
public class CreateInternalLoadBalancerElementCmd extends BaseAsyncCreateCmd {
public static final Logger s_logger = Logger.getLogger(CreateInternalLoadBalancerElementCmd.class.getName());
private static final String s_name = "createinternalloadbalancerelementresponse";
@Inject
private List<InternalLoadBalancerElementService> _service;
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.NETWORK_SERVICE_PROVIDER_ID, type=CommandType.UUID, entityType = ProviderResponse.class, required=true, description="the network service provider ID of the internal load balancer element")
private Long nspId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public void setNspId(Long nspId) {
this.nspId = nspId;
}
public Long getNspId() {
return nspId;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
@Override
public void execute(){
UserContext.current().setEventDetails("Virtual router element Id: "+getEntityId());
VirtualRouterProvider result = _service.get(0).getInternalLoadBalancerElement(getEntityId());
if (result != null) {
InternalLoadBalancerElementResponse response = _responseGenerator.createInternalLbElementResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Virtual Router entity to physical network");
}
}
@Override
public void create() throws ResourceAllocationException {
VirtualRouterProvider result = _service.get(0).addInternalLoadBalancerElement(getNspId());
if (result != null) {
setEntityId(result.getId());
setEntityUuid(result.getUuid());
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Internal Load Balancer entity to physical network");
}
}
@Override
public String getEventType() {
return EventTypes.EVENT_SERVICE_PROVIDER_CREATE;
}
@Override
public String getEventDescription() {
return "Adding physical network element Internal Load Balancer: " + getEntityId();
}
}

View File

@ -0,0 +1,151 @@
// 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 org.apache.cloudstack.api.command.admin.internallb;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.DomainRouterResponse;
import org.apache.cloudstack.api.response.HostResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.NetworkResponse;
import org.apache.cloudstack.api.response.PodResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.api.response.VpcResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.log4j.Logger;
import com.cloud.async.AsyncJob;
import com.cloud.network.router.VirtualRouter.Role;
@APICommand(name = "listInternalLoadBalancerVMs", description="List internal LB VMs.", responseObject=DomainRouterResponse.class)
public class ListInternalLBVMsCmd extends BaseListProjectAndAccountResourcesCmd {
public static final Logger s_logger = Logger.getLogger(ListInternalLBVMsCmd.class.getName());
private static final String s_name = "listinternallbvmssresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.HOST_ID, type=CommandType.UUID, entityType=HostResponse.class,
description="the host ID of the Internal LB VM")
private Long hostId;
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=UserVmResponse.class,
description="the ID of the Internal LB VM")
private Long id;
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name of the Internal LB VM")
private String routerName;
@Parameter(name=ApiConstants.POD_ID, type=CommandType.UUID, entityType=PodResponse.class,
description="the Pod ID of the Internal LB VM")
private Long podId;
@Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="the state of the Internal LB VM")
private String state;
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType=ZoneResponse.class,
description="the Zone ID of the Internal LB VM")
private Long zoneId;
@Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.UUID, entityType=NetworkResponse.class,
description="list by network id")
private Long networkId;
@Parameter(name=ApiConstants.VPC_ID, type=CommandType.UUID, entityType=VpcResponse.class,
description="List Internal LB VMs by VPC")
private Long vpcId;
@Parameter(name=ApiConstants.FOR_VPC, type=CommandType.BOOLEAN, description="if true is passed for this parameter, list only VPC Internal LB VMs")
private Boolean forVpc;
@Parameter(name=ApiConstants.ZONE_TYPE, type=CommandType.STRING, description="the network type of the zone that the virtual machine belongs to")
private String zoneType;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Long getHostId() {
return hostId;
}
public Long getId() {
return id;
}
public String getRouterName() {
return routerName;
}
public Long getPodId() {
return podId;
}
public String getState() {
return state;
}
public Long getZoneId() {
return zoneId;
}
public Long getNetworkId() {
return networkId;
}
public Long getVpcId() {
return vpcId;
}
public Boolean getForVpc() {
return forVpc;
}
public String getRole() {
return Role.INTERNAL_LB_VM.toString();
}
public String getZoneType() {
return zoneType;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.DomainRouter;
}
@Override
public void execute(){
ListResponse<DomainRouterResponse> response = _queryService.searchForInternalLbVms(this);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
}

View File

@ -0,0 +1,99 @@
// 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 org.apache.cloudstack.api.command.admin.internallb;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.InternalLoadBalancerElementResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.ProviderResponse;
import org.apache.cloudstack.network.element.InternalLoadBalancerElementService;
import org.apache.log4j.Logger;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.VirtualRouterProvider;
@APICommand(name = "listInternalLoadBalancerElements", description="Lists all available Internal Load Balancer elements.",
responseObject=InternalLoadBalancerElementResponse.class, since="4.2.0")
public class ListInternalLoadBalancerElementsCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListInternalLoadBalancerElementsCmd.class.getName());
private static final String _name = "listinternalloadbalancerelementsresponse";
@Inject
private InternalLoadBalancerElementService _service;
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = InternalLoadBalancerElementResponse.class,
description="list internal load balancer elements by id")
private Long id;
@Parameter(name=ApiConstants.NSP_ID, type=CommandType.UUID, entityType = ProviderResponse.class,
description="list internal load balancer elements by network service provider id")
private Long nspId;
@Parameter(name=ApiConstants.ENABLED, type=CommandType.BOOLEAN, description="list internal load balancer elements by enabled state")
private Boolean enabled;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Long getId() {
return id;
}
public Long getNspId() {
return nspId;
}
public Boolean getEnabled() {
return enabled;
}
@Override
public String getCommandName() {
return _name;
}
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
List<? extends VirtualRouterProvider> providers = _service.searchForInternalLoadBalancerElements(getId(), getNspId(), getEnabled());
ListResponse<InternalLoadBalancerElementResponse> response = new ListResponse<InternalLoadBalancerElementResponse>();
List<InternalLoadBalancerElementResponse> providerResponses = new ArrayList<InternalLoadBalancerElementResponse>();
for (VirtualRouterProvider provider : providers) {
InternalLoadBalancerElementResponse providerResponse = _responseGenerator.createInternalLbElementResponse(provider);
providerResponses.add(providerResponse);
}
response.setResponses(providerResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
}

View File

@ -0,0 +1,120 @@
// 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 org.apache.cloudstack.api.command.admin.internallb;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.DomainRouterResponse;
import org.apache.log4j.Logger;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.router.VirtualRouter.Role;
import com.cloud.user.UserContext;
@APICommand(name = "startInternalLoadBalancerVM", responseObject=DomainRouterResponse.class, description="Starts an existing internal lb vm.")
public class StartInternalLBVMCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(StartInternalLBVMCmd.class.getName());
private static final String s_name = "startinternallbvmresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=DomainRouterResponse.class,
required=true, description="the ID of the internal lb vm")
private Long id;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Long getId() {
return id;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
public static String getResultObjectName() {
return "router";
}
@Override
public long getEntityOwnerId() {
VirtualRouter router = _entityMgr.findById(VirtualRouter.class, getId());
if (router != null && router.getRole() == Role.INTERNAL_LB_VM) {
return router.getAccountId();
} else {
throw new InvalidParameterValueException("Unable to find internal lb vm by id");
}
}
@Override
public String getEventType() {
return EventTypes.EVENT_INTERNAL_LB_VM_START;
}
@Override
public String getEventDescription() {
return "starting internal lb vm: " + getId();
}
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.InternalLbVm;
}
public Long getInstanceId() {
return getId();
}
@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
UserContext.current().setEventDetails("Internal Lb Vm Id: "+getId());
VirtualRouter result = null;
VirtualRouter router = _routerService.findRouter(getId());
if (router == null || router.getRole() != Role.INTERNAL_LB_VM) {
throw new InvalidParameterValueException("Can't find internal lb vm by id");
} else {
result = _internalLbSvc.startInternalLbVm(getId(), UserContext.current().getCaller(), UserContext.current().getCallerUserId());
}
if (result != null){
DomainRouterResponse routerResponse = _responseGenerator.createDomainRouterResponse(result);
routerResponse.setResponseName(getCommandName());
this.setResponseObject(routerResponse);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to start internal lb vm");
}
}
}

View File

@ -0,0 +1,123 @@
// 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 org.apache.cloudstack.api.command.admin.internallb;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.DomainRouterResponse;
import org.apache.log4j.Logger;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.router.VirtualRouter.Role;
import com.cloud.user.UserContext;
@APICommand(name = "stopInternalLoadBalancerVM", description = "Stops an Internal LB vm.", responseObject = DomainRouterResponse.class)
public class StopInternalLBVMCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(StopInternalLBVMCmd.class.getName());
private static final String s_name = "stopinternallbvmresponse";
// ///////////////////////////////////////////////////
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = DomainRouterResponse.class,
required = true, description = "the ID of the internal lb vm")
private Long id;
@Parameter(name = ApiConstants.FORCED, type = CommandType.BOOLEAN, required = false, description = "Force stop the VM. The caller knows the VM is stopped.")
private Boolean forced;
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public Long getId() {
return id;
}
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
VirtualRouter vm = _entityMgr.findById(VirtualRouter.class, getId());
if (vm != null && vm.getRole() == Role.INTERNAL_LB_VM) {
return vm.getAccountId();
} else {
throw new InvalidParameterValueException("Unable to find internal lb vm by id");
}
}
@Override
public String getEventType() {
return EventTypes.EVENT_INTERNAL_LB_VM_STOP;
}
@Override
public String getEventDescription() {
return "stopping internal lb vm: " + getId();
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.InternalLbVm;
}
@Override
public Long getInstanceId() {
return getId();
}
public boolean isForced() {
return (forced != null) ? forced : false;
}
@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
UserContext.current().setEventDetails("Internal lb vm Id: "+getId());
VirtualRouter result = null;
VirtualRouter vm = _routerService.findRouter(getId());
if (vm == null || vm.getRole() != Role.INTERNAL_LB_VM) {
throw new InvalidParameterValueException("Can't find internal lb vm by id");
} else {
result = _internalLbSvc.stopInternalLbVm(getId(), isForced(), UserContext.current().getCaller(), UserContext.current().getCallerUserId());
}
if (result != null) {
DomainRouterResponse response = _responseGenerator.createDomainRouterResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to stop internal lb vm");
}
}
}

View File

@ -31,7 +31,6 @@ import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.NetworkOfferingResponse;
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
import org.apache.log4j.Logger;
import com.cloud.exception.InvalidParameterValueException;
@ -95,6 +94,10 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
@Parameter(name=ApiConstants.IS_PERSISTENT, type=CommandType.BOOLEAN, description="true if network offering supports persistent networks; defaulted to false if not specified")
private Boolean isPersistent;
@Parameter(name=ApiConstants.DETAILS, type=CommandType.MAP, since="4.2.0", description="Template details in key/value pairs." +
" Supported keys are internallbprovider/publiclbprovider with service provider as a value")
protected Map details;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -215,6 +218,16 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
return capabilityMap;
}
public Map<String, String> getDetails() {
if (details == null || details.isEmpty()) {
return null;
}
Collection paramsCollection = details.values();
Map<String, String> params = (Map<String, String>) (paramsCollection.toArray())[0];
return params;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////

View File

@ -31,6 +31,7 @@ import org.apache.cloudstack.api.response.VirtualRouterProviderResponse;
import org.apache.log4j.Logger;
import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.network.VirtualRouterProvider;
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
@ -52,6 +53,9 @@ public class CreateVirtualRouterElementCmd extends BaseAsyncCreateCmd {
@Parameter(name=ApiConstants.NETWORK_SERVICE_PROVIDER_ID, type=CommandType.UUID, entityType = ProviderResponse.class, required=true, description="the network service provider ID of the virtual router element")
private Long nspId;
@Parameter(name=ApiConstants.PROVIDER_TYPE, type=CommandType.UUID, entityType = ProviderResponse.class, description="The provider type. Supported types are VirtualRouter (default) and VPCVirtualRouter")
private String providerType;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -61,16 +65,27 @@ public class CreateVirtualRouterElementCmd extends BaseAsyncCreateCmd {
this.nspId = nspId;
}
public Long getNspId() {
return nspId;
}
public VirtualRouterProviderType getProviderType() {
if (providerType != null) {
if (providerType.equalsIgnoreCase(VirtualRouterProviderType.VirtualRouter.toString())) {
return VirtualRouterProviderType.VirtualRouter;
} else if (providerType.equalsIgnoreCase(VirtualRouterProviderType.VPCVirtualRouter.toString())) {
return VirtualRouterProviderType.VPCVirtualRouter;
} else throw new InvalidParameterValueException("Invalid providerType specified");
}
return VirtualRouterProviderType.VirtualRouter;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
@ -96,7 +111,7 @@ public class CreateVirtualRouterElementCmd extends BaseAsyncCreateCmd {
@Override
public void create() throws ResourceAllocationException {
VirtualRouterProvider result = _service.get(0).addElement(getNspId(), VirtualRouterProviderType.VirtualRouter);
VirtualRouterProvider result = _service.get(0).addElement(getNspId(), getProviderType());
if (result != null) {
setEntityId(result.getId());
setEntityUuid(result.getUuid());

View File

@ -31,6 +31,7 @@ import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.log4j.Logger;
import com.cloud.async.AsyncJob;
import com.cloud.network.router.VirtualRouter.Role;
@APICommand(name = "listRouters", description="List routers.", responseObject=DomainRouterResponse.class)
public class ListRoutersCmd extends BaseListProjectAndAccountResourcesCmd {
@ -77,7 +78,7 @@ public class ListRoutersCmd extends BaseListProjectAndAccountResourcesCmd {
@Parameter(name=ApiConstants.FOR_VPC, type=CommandType.BOOLEAN, description="if true is passed for this parameter, list only VPC routers")
private Boolean forVpc;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -121,6 +122,10 @@ public class ListRoutersCmd extends BaseListProjectAndAccountResourcesCmd {
public Boolean getForVpc() {
return forVpc;
}
public String getRole() {
return Role.VIRTUAL_ROUTER.toString();
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////

View File

@ -29,8 +29,10 @@ import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.router.VirtualRouter.Role;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@ -100,7 +102,13 @@ public class StartRouterCmd extends BaseAsyncCmd {
@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
UserContext.current().setEventDetails("Router Id: "+getId());
VirtualRouter result = _routerService.startRouter(id);
VirtualRouter result = null;
VirtualRouter router = _routerService.findRouter(getId());
if (router == null || router.getRole() != Role.VIRTUAL_ROUTER) {
throw new InvalidParameterValueException("Can't find router by id");
} else {
result = _routerService.startRouter(getId());
}
if (result != null){
DomainRouterResponse routerResponse = _responseGenerator.createDomainRouterResponse(result);
routerResponse.setResponseName(getCommandName());

View File

@ -28,8 +28,10 @@ import org.apache.log4j.Logger;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.router.VirtualRouter.Role;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@ -103,7 +105,14 @@ public class StopRouterCmd extends BaseAsyncCmd {
@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
UserContext.current().setEventDetails("Router Id: "+getId());
VirtualRouter result = _routerService.stopRouter(getId(), isForced());
VirtualRouter result = null;
VirtualRouter router = _routerService.findRouter(getId());
if (router == null || router.getRole() != Role.VIRTUAL_ROUTER) {
throw new InvalidParameterValueException("Can't find router by id");
} else {
result = _routerService.stopRouter(getId(), isForced());
}
if (result != null) {
DomainRouterResponse response = _responseGenerator.createDomainRouterResponse(result);
response.setResponseName(getCommandName());

View File

@ -0,0 +1,218 @@
// 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 org.apache.cloudstack.api.command.user.loadbalancer;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse;
import org.apache.cloudstack.api.response.NetworkResponse;
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
import org.apache.log4j.Logger;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.user.UserContext;
import com.cloud.utils.net.NetUtils;
@APICommand(name = "createLoadBalancer", description="Creates a Load Balancer", responseObject=ApplicationLoadBalancerResponse.class, since="4.2.0")
public class CreateApplicationLoadBalancerCmd extends BaseAsyncCreateCmd {
public static final Logger s_logger = Logger.getLogger(CreateApplicationLoadBalancerCmd.class.getName());
private static final String s_name = "createloadbalancerresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="name of the Load Balancer")
private String loadBalancerName;
@Parameter(name=ApiConstants.DESCRIPTION, type=CommandType.STRING, description="the description of the Load Balancer", length=4096)
private String description;
@Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.UUID, required=true, entityType = NetworkResponse.class,
description="The guest network the Load Balancer will be created for")
private Long networkId;
@Parameter(name=ApiConstants.SOURCE_PORT, type=CommandType.INTEGER, required=true, description="the source port the network traffic will be load balanced from")
private Integer sourcePort;
@Parameter(name=ApiConstants.ALGORITHM, type=CommandType.STRING, required=true, description="load balancer algorithm (source, roundrobin, leastconn)")
private String algorithm;
@Parameter(name=ApiConstants.INSTANCE_PORT, type=CommandType.INTEGER, required=true, description="the TCP port of the virtual machine where the network traffic will be load balanced to")
private Integer instancePort;
@Parameter(name=ApiConstants.SOURCE_IP, type=CommandType.STRING, description="the source ip address the network traffic will be load balanced from")
private String sourceIp;
@Parameter(name=ApiConstants.SOURCE_IP_NETWORK_ID, type=CommandType.UUID, entityType = NetworkResponse.class, required=true,
description="the network id of the source ip address")
private Long sourceIpNetworkId;
@Parameter(name=ApiConstants.SCHEME, type=CommandType.STRING, required=true, description="the load balancer scheme. Supported value in this release is Internal")
private String scheme;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getAlgorithm() {
return algorithm;
}
public String getDescription() {
return description;
}
public String getLoadBalancerName() {
return loadBalancerName;
}
public Integer getPrivatePort() {
return instancePort;
}
public long getNetworkId() {
return networkId;
}
public String getName() {
return loadBalancerName;
}
public Integer getSourcePort() {
return sourcePort.intValue();
}
public String getProtocol() {
return NetUtils.TCP_PROTO;
}
public long getAccountId() {
//get account info from the network object
Network ntwk = _networkService.getNetwork(networkId);
if (ntwk == null) {
throw new InvalidParameterValueException("Invalid network id specified");
}
return ntwk.getAccountId();
}
public int getInstancePort() {
return instancePort.intValue();
}
@Override
public String getEventType() {
return EventTypes.EVENT_LOAD_BALANCER_CREATE;
}
@Override
public String getEventDescription() {
return "creating load balancer: " + getName() + " account: " + getAccountId();
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.LoadBalancerRule;
}
public String getSourceIp() {
return sourceIp;
}
public long getSourceIpNetworkId() {
return sourceIpNetworkId;
}
public Scheme getScheme() {
if (scheme.equalsIgnoreCase(Scheme.Internal.toString())) {
return Scheme.Internal;
} else {
throw new InvalidParameterValueException("Invalid value for scheme. Supported value is Internal");
}
}
@Override
public long getEntityOwnerId() {
return getAccountId();
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
ApplicationLoadBalancerRule rule = null;
try {
UserContext.current().setEventDetails("Load Balancer Id: " + getEntityId());
// State might be different after the rule is applied, so get new object here
rule = _entityMgr.findById(ApplicationLoadBalancerRule.class, getEntityId());
ApplicationLoadBalancerResponse lbResponse = _responseGenerator.createLoadBalancerContainerReponse(rule, _lbService.getLbInstances(getEntityId()));
setResponseObject(lbResponse);
lbResponse.setResponseName(getCommandName());
} catch (Exception ex) {
s_logger.warn("Failed to create Load Balancer due to exception ", ex);
} finally {
if (rule == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create Load Balancer");
}
}
}
@Override
public void create() {
try {
ApplicationLoadBalancerRule result = _appLbService.createApplicationLoadBalancer(getName(), getDescription(), getScheme(),
getSourceIpNetworkId(), getSourceIp(), getSourcePort(), getInstancePort(), getAlgorithm(), getNetworkId(), getEntityOwnerId());
this.setEntityId(result.getId());
this.setEntityUuid(result.getUuid());
}catch (NetworkRuleConflictException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
} catch (InsufficientAddressCapacityException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage());
} catch (InsufficientVirtualNetworkCapcityException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage());
}
}
}

View File

@ -148,7 +148,7 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements
}
public Long getNetworkId() {
public long getNetworkId() {
if (networkId != null) {
return networkId;
}
@ -278,7 +278,9 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements
throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall rule for the specific cidr, please refer to createFirewallRule command");
}
try {
LoadBalancer result = _lbService.createLoadBalancerRule(this, getOpenFirewall());
LoadBalancer result = _lbService.createPublicLoadBalancerRule(getXid(), getName(), getDescription(),
getSourcePortStart(), getSourcePortEnd(), getDefaultPortStart(), getDefaultPortEnd(), getSourceIpAddressId(), getProtocol(), getAlgorithm(),
getNetworkId(), getEntityOwnerId(), getOpenFirewall());
this.setEntityId(result.getId());
this.setEntityUuid(result.getUuid());
} catch (NetworkRuleConflictException e) {

View File

@ -0,0 +1,116 @@
// 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 org.apache.cloudstack.api.command.user.loadbalancer;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.FirewallRuleResponse;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
import org.apache.log4j.Logger;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.user.UserContext;
@APICommand(name = "deleteLoadBalancer", description="Deletes a load balancer", responseObject=SuccessResponse.class, since="4.2.0")
public class DeleteApplicationLoadBalancerCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(DeleteApplicationLoadBalancerCmd.class.getName());
private static final String s_name = "deleteloadbalancerresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = FirewallRuleResponse.class,
required=true, description="the ID of the Load Balancer")
private Long id;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Long getId() {
return id;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
ApplicationLoadBalancerRule lb = _entityMgr.findById(ApplicationLoadBalancerRule.class, getId());
if (lb != null) {
return lb.getAccountId();
} else {
throw new InvalidParameterValueException("Can't find load balancer by id specified");
}
}
@Override
public String getEventType() {
return EventTypes.EVENT_LOAD_BALANCER_DELETE;
}
@Override
public String getEventDescription() {
return "deleting load balancer: " + getId();
}
@Override
public void execute(){
UserContext.current().setEventDetails("Load balancer Id: " + getId());
boolean result = _appLbService.deleteApplicationLoadBalancer(getId());
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete load balancer");
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
}
@Override
public Long getSyncObjId() {
ApplicationLoadBalancerRule lb = _appLbService.getApplicationLoadBalancer(id);
if(lb == null){
throw new InvalidParameterValueException("Unable to find load balancer by id ");
}
return lb.getNetworkId();
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.FirewallRule;
}
}

View File

@ -0,0 +1,131 @@
// 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 org.apache.cloudstack.api.command.user.loadbalancer;
import java.util.ArrayList;
import java.util.List;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse;
import org.apache.cloudstack.api.response.FirewallRuleResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.NetworkResponse;
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
import org.apache.log4j.Logger;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.utils.Pair;
@APICommand(name = "listLoadBalancers", description = "Lists Load Balancers", responseObject = ApplicationLoadBalancerResponse.class, since="4.2.0")
public class ListApplicationLoadBalancersCmd extends BaseListTaggedResourcesCmd {
public static final Logger s_logger = Logger.getLogger(ListApplicationLoadBalancersCmd.class.getName());
private static final String s_name = "listloadbalancerssresponse";
// ///////////////////////////////////////////////////
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = FirewallRuleResponse.class,
description = "the ID of the Load Balancer")
private Long id;
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "the name of the Load Balancer")
private String loadBalancerName;
@Parameter(name = ApiConstants.SOURCE_IP, type = CommandType.STRING, description = "the source ip address of the Load Balancer")
private String sourceIp;
@Parameter(name=ApiConstants.SOURCE_IP_NETWORK_ID, type=CommandType.UUID, entityType = NetworkResponse.class,
description="the network id of the source ip address")
private Long sourceIpNetworkId;
@Parameter(name = ApiConstants.SCHEME, type = CommandType.STRING, description = "the scheme of the Load Balancer. Supported value is Internal in the current release")
private String scheme;
@Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.UUID, entityType = NetworkResponse.class,
description="the network id of the Load Balancer")
private Long networkId;
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public Long getId() {
return id;
}
public String getLoadBalancerRuleName() {
return loadBalancerName;
}
public String getLoadBalancerName() {
return loadBalancerName;
}
public String getSourceIp() {
return sourceIp;
}
public Long getSourceIpNetworkId() {
return sourceIpNetworkId;
}
@Override
public String getCommandName() {
return s_name;
}
public Scheme getScheme() {
if (scheme != null) {
if (scheme.equalsIgnoreCase(Scheme.Internal.toString())) {
return Scheme.Internal;
} else {
throw new InvalidParameterValueException("Invalid value for scheme. Supported value is Internal");
}
}
return null;
}
public Long getNetworkId() {
return networkId;
}
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
Pair<List<? extends ApplicationLoadBalancerRule>, Integer> loadBalancers = _appLbService.listApplicationLoadBalancers(this);
ListResponse<ApplicationLoadBalancerResponse> response = new ListResponse<ApplicationLoadBalancerResponse>();
List<ApplicationLoadBalancerResponse> lbResponses = new ArrayList<ApplicationLoadBalancerResponse>();
for (ApplicationLoadBalancerRule loadBalancer : loadBalancers.first()) {
ApplicationLoadBalancerResponse lbResponse = _responseGenerator.createLoadBalancerContainerReponse(loadBalancer, _lbService.getLbInstances(loadBalancer.getId()));
lbResponse.setObjectName("loadbalancer");
lbResponses.add(lbResponse);
}
response.setResponses(lbResponses, loadBalancers.second());
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
}

View File

@ -0,0 +1,63 @@
// 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 org.apache.cloudstack.api.response;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
/**
*
* Load Balancer instance is the User Vm instance participating in the Load Balancer
*
*/
@SuppressWarnings("unused")
public class ApplicationLoadBalancerInstanceResponse extends BaseResponse{
@SerializedName(ApiConstants.ID) @Param(description = "the instance ID")
private String id;
@SerializedName(ApiConstants.NAME) @Param(description = "the name of the instance")
private String name;
@SerializedName(ApiConstants.STATE) @Param(description="the state of the instance")
private String state;
@SerializedName(ApiConstants.IP_ADDRESS)
@Param(description="the ip address of the instance")
private String ipAddress;
public void setId(String id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setState(String state) {
this.state = state;
}
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
}

View File

@ -0,0 +1,142 @@
// 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 org.apache.cloudstack.api.response;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
@SuppressWarnings("unused")
public class ApplicationLoadBalancerResponse extends BaseResponse implements ControlledEntityResponse{
@SerializedName(ApiConstants.ID) @Param(description = "the Load Balancer ID")
private String id;
@SerializedName(ApiConstants.NAME) @Param(description = "the name of the Load Balancer")
private String name;
@SerializedName(ApiConstants.DESCRIPTION) @Param(description = "the description of the Load Balancer")
private String description;
@SerializedName(ApiConstants.ALGORITHM) @Param(description = "the load balancer algorithm (source, roundrobin, leastconn)")
private String algorithm;
@SerializedName(ApiConstants.NETWORK_ID) @Param(description="Load Balancer network id")
private String networkId;
@SerializedName(ApiConstants.SOURCE_IP) @Param(description="Load Balancer source ip")
private String sourceIp;
@SerializedName(ApiConstants.SOURCE_IP_NETWORK_ID) @Param(description="Load Balancer source ip network id")
private String sourceIpNetworkId;
@SerializedName(ApiConstants.ACCOUNT)
@Param(description = "the account of the Load Balancer")
private String accountName;
@SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id of the Load Balancer")
private String projectId;
@SerializedName(ApiConstants.PROJECT) @Param(description="the project name of the Load Balancer")
private String projectName;
@SerializedName(ApiConstants.DOMAIN_ID)
@Param(description = "the domain ID of the Load Balancer")
private String domainId;
@SerializedName(ApiConstants.DOMAIN)
@Param(description = "the domain of the Load Balancer")
private String domainName;
@SerializedName("loadbalancerrule") @Param(description="the list of rules associated with the Load Balancer", responseObject = ApplicationLoadBalancerRuleResponse.class)
private List<ApplicationLoadBalancerRuleResponse> lbRules;
@SerializedName("loadbalancerinstance") @Param(description="the list of instances associated with the Load Balancer", responseObject = ApplicationLoadBalancerInstanceResponse.class)
private List<ApplicationLoadBalancerInstanceResponse> lbInstances;
@SerializedName(ApiConstants.TAGS) @Param(description="the list of resource tags associated with the Load Balancer", responseObject = ResourceTagResponse.class)
private List<ResourceTagResponse> tags;
public void setAccountName(String accountName) {
this.accountName = accountName;
}
@Override
public void setDomainId(String domainId) {
this.domainId = domainId;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
@Override
public void setProjectId(String projectId) {
this.projectId = projectId;
}
@Override
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public void setTags(List<ResourceTagResponse> tags) {
this.tags = tags;
}
public void setId(String id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setDescription(String description) {
this.description = description;
}
public void setAlgorithm(String algorithm) {
this.algorithm = algorithm;
}
public void setNetworkId(String networkId) {
this.networkId = networkId;
}
public void setSourceIp(String sourceIp) {
this.sourceIp = sourceIp;
}
public void setSourceIpNetworkId(String sourceIpNetworkId) {
this.sourceIpNetworkId = sourceIpNetworkId;
}
public void setLbRules(List<ApplicationLoadBalancerRuleResponse> lbRules) {
this.lbRules = lbRules;
}
public void setLbInstances(List<ApplicationLoadBalancerInstanceResponse> lbInstances) {
this.lbInstances = lbInstances;
}
}

View File

@ -0,0 +1,51 @@
// 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 org.apache.cloudstack.api.response;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
/**
* Subobject of the load balancer container response
*/
@SuppressWarnings("unused")
public class ApplicationLoadBalancerRuleResponse extends BaseResponse{
@SerializedName(ApiConstants.SOURCE_PORT) @Param(description = "source port of the load balancer rule")
private Integer sourcePort;
@SerializedName(ApiConstants.INSTANCE_PORT) @Param(description = "instance port of the load balancer rule")
private Integer instancePort;
@SerializedName(ApiConstants.STATE) @Param(description = "the state of the load balancer rule")
private String state;
public void setSourcePort(Integer sourcePort) {
this.sourcePort = sourcePort;
}
public void setInstancePort(Integer instancePort) {
this.instancePort = instancePort;
}
public void setState(String state) {
this.state = state;
}
}

View File

@ -153,8 +153,11 @@ public class DomainRouterResponse extends BaseResponse implements ControlledView
@SerializedName("scriptsversion") @Param(description="the version of scripts")
private String scriptsVersion;
@SerializedName(ApiConstants.VPC_ID) @Param(description="VPC the network belongs to")
@SerializedName(ApiConstants.VPC_ID) @Param(description="VPC the router belongs to")
private String vpcId;
@SerializedName(ApiConstants.ROLE) @Param(description="role of the domain router")
private String role;
@SerializedName("nic") @Param(description="the list of nics associated with the router",
responseObject = NicResponse.class, since="4.0")
@ -164,15 +167,11 @@ public class DomainRouterResponse extends BaseResponse implements ControlledView
nics = new LinkedHashSet<NicResponse>();
}
@Override
public String getObjectId() {
return this.getId();
}
public String getId() {
return id;
}
@ -372,4 +371,8 @@ public class DomainRouterResponse extends BaseResponse implements ControlledView
public void setIp6Dns2(String ip6Dns2) {
this.ip6Dns2 = ip6Dns2;
}
public void setRole(String role) {
this.role = role;
}
}

View File

@ -0,0 +1,51 @@
// 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 org.apache.cloudstack.api.response;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import org.apache.cloudstack.api.EntityReference;
import com.cloud.network.VirtualRouterProvider;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
@EntityReference(value=VirtualRouterProvider.class)
@SuppressWarnings("unused")
public class InternalLoadBalancerElementResponse extends BaseResponse {
@SerializedName(ApiConstants.ID) @Param(description="the id of the internal load balancer element")
private String id;
@SerializedName(ApiConstants.NSP_ID) @Param(description="the physical network service provider id of the element")
private String nspId;
@SerializedName(ApiConstants.ENABLED) @Param(description="Enabled/Disabled the element")
private Boolean enabled;
public void setId(String id) {
this.id = id;
}
public void setNspId(String nspId) {
this.nspId = nspId;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
}

View File

@ -18,6 +18,7 @@ package org.apache.cloudstack.api.response;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
@ -83,6 +84,10 @@ public class NetworkOfferingResponse extends BaseResponse {
@SerializedName(ApiConstants.IS_PERSISTENT) @Param(description="true if network offering supports persistent networks, false otherwise")
private Boolean isPersistent;
@SerializedName(ApiConstants.DETAILS) @Param(description="additional key/value details tied with network offering", since="4.2.0")
private Map details;
public void setId(String id) {
this.id = id;
@ -156,5 +161,9 @@ public class NetworkOfferingResponse extends BaseResponse {
public void setIsPersistent(Boolean isPersistent) {
this.isPersistent = isPersistent;
}
public void setDetails(Map details) {
this.details = details;
}
}

View File

@ -25,6 +25,7 @@ import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
@EntityReference(value=VirtualRouterProvider.class)
@SuppressWarnings("unused")
public class VirtualRouterProviderResponse extends BaseResponse implements ControlledEntityResponse {
@SerializedName(ApiConstants.ID) @Param(description="the id of the router")
private String id;

View File

@ -0,0 +1,56 @@
// 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 org.apache.cloudstack.network.element;
import java.util.List;
import com.cloud.network.VirtualRouterProvider;
import com.cloud.utils.component.PluggableService;
public interface InternalLoadBalancerElementService extends PluggableService{
/**
* Configures existing Internal Load Balancer Element (enables or disables it)
* @param id
* @param enable
* @return
*/
VirtualRouterProvider configureInternalLoadBalancerElement(long id, boolean enable);
/**
* Adds Internal Load Balancer element to the Network Service Provider
* @param ntwkSvcProviderId
* @return
*/
VirtualRouterProvider addInternalLoadBalancerElement(long ntwkSvcProviderId);
/**
* Retrieves existing Internal Load Balancer element
* @param id
* @return
*/
VirtualRouterProvider getInternalLoadBalancerElement(long id);
/**
* Searches for existing Internal Load Balancer elements based on parameters passed to the call
* @param id
* @param ntwkSvsProviderId
* @param enabled
* @return
*/
List<? extends VirtualRouterProvider> searchForInternalLoadBalancerElements(Long id, Long ntwkSvsProviderId, Boolean enabled);
}

View File

@ -14,21 +14,15 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.maint;
package org.apache.cloudstack.network.lb;
/**
* has been released.
*
*/
public class UpgradeMonitor implements Runnable {
private String _url;
private long _period;
import com.cloud.network.rules.LoadBalancerContainer;
import com.cloud.utils.net.Ip;
public interface ApplicationLoadBalancerContainer extends LoadBalancerContainer{
public UpgradeMonitor(String url, long period) {
_url = url;
}
public Long getSourceIpNetworkId();
public void run() {
}
public Ip getSourceIp();
}

View File

@ -14,10 +14,11 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.maint.dao;
import com.cloud.maint.AgentUpgradeVO;
import com.cloud.utils.db.GenericDao;
package org.apache.cloudstack.network.lb;
public interface AgentUpgradeDao extends GenericDao<AgentUpgradeVO, Long> {
import com.cloud.network.rules.LoadBalancer;
public interface ApplicationLoadBalancerRule extends ApplicationLoadBalancerContainer, LoadBalancer{
int getInstancePort();
}

View File

@ -0,0 +1,42 @@
// 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 org.apache.cloudstack.network.lb;
import java.util.List;
import org.apache.cloudstack.api.command.user.loadbalancer.ListApplicationLoadBalancersCmd;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.utils.Pair;
public interface ApplicationLoadBalancerService {
ApplicationLoadBalancerRule createApplicationLoadBalancer(String name, String description, Scheme scheme, long sourceIpNetworkId, String sourceIp,
int sourcePort, int instancePort, String algorithm, long networkId, long lbOwnerId) throws InsufficientAddressCapacityException,
NetworkRuleConflictException, InsufficientVirtualNetworkCapcityException;
boolean deleteApplicationLoadBalancer(long id);
Pair<List<? extends ApplicationLoadBalancerRule>, Integer> listApplicationLoadBalancers(ListApplicationLoadBalancersCmd cmd);
ApplicationLoadBalancerRule getApplicationLoadBalancer(long ruleId);
}

View File

@ -0,0 +1,34 @@
// 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 org.apache.cloudstack.network.lb;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.exception.StorageUnavailableException;
import com.cloud.network.router.VirtualRouter;
import com.cloud.user.Account;
public interface InternalLoadBalancerVMService {
VirtualRouter startInternalLbVm(long internalLbVmId, Account caller, long callerUserId)
throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException;
VirtualRouter stopInternalLbVm(long vmId, boolean forced, Account caller, long callerUserId)
throws ConcurrentOperationException, ResourceUnavailableException;
}

View File

@ -18,6 +18,7 @@ package org.apache.cloudstack.query;
import org.apache.cloudstack.affinity.AffinityGroupResponse;
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
import org.apache.cloudstack.api.command.admin.internallb.ListInternalLBVMsCmd;
import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd;
import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
@ -101,4 +102,6 @@ public interface QueryService {
public ListResponse<AffinityGroupResponse> listAffinityGroups(Long affinityGroupId, String affinityGroupName,
String affinityGroupType, Long vmId, Long startIndex, Long pageSize);
ListResponse<DomainRouterResponse> searchForInternalLbVms(ListInternalLBVMsCmd cmd);
}

View File

@ -286,12 +286,6 @@
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<sourceDirectory>src</sourceDirectory>
<!-- Tests still depend on hibernate,
so thats not going to work
<testSourceDirectory>test</testSourceDirectory>
-->
<resources>
<resource>
<directory>src</directory>
@ -307,6 +301,17 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>com/cloud/gate/util/UtilTestCase.java</exclude>
<exclude>com/cloud/gate/service/ServiceTestCase.java</exclude>
<exclude>com/cloud/gate/util/CloudStackClientTestCase.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
@ -364,22 +369,6 @@
</executions>
</plugin>
</plugins>
<!--
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
-->
<pluginManagement>
<plugins>
<plugin>

View File

@ -1,368 +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.gate.model;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.Assert;
import com.cloud.bridge.model.MHost;
import com.cloud.bridge.model.MHostMount;
import com.cloud.bridge.model.SBucket;
import com.cloud.bridge.model.SHost;
import com.cloud.bridge.model.SMeta;
import com.cloud.bridge.model.SObject;
import com.cloud.bridge.util.CloudSessionFactory;
import com.cloud.bridge.util.QueryHelper;
import com.cloud.gate.testcase.BaseTestCase;
public class ModelTestCase extends BaseTestCase {
protected final static Logger logger = Logger.getLogger(ModelTestCase.class);
public void testSHost() {
SHost host;
// create the record
Session session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
host = new SHost();
host.setHost("localhost");
host.setExportRoot("/");
host.setUserOnHost("root");
host.setUserPassword("password");
session.saveOrUpdate(host);
txn.commit();
} finally {
session.close();
}
Assert.assertTrue(host.getId() != 0);
// retrive the record
session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
host = (SHost)session.get(SHost.class, (long)host.getId());
txn.commit();
Assert.assertTrue(host.getHost().equals("localhost"));
Assert.assertTrue(host.getUserOnHost().equals("root"));
Assert.assertTrue(host.getUserPassword().equals("password"));
logger.info("Retrived record, host:" + host.getHost()
+ ", user: " + host.getUserOnHost()
+ ", password: " + host.getUserPassword());
} finally {
session.close();
}
// delete the record
session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
host = (SHost)session.get(SHost.class, (long)host.getId());
session.delete(host);
txn.commit();
} finally {
session.close();
}
session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
host = (SHost)session.get(SHost.class, (long)host.getId());
txn.commit();
Assert.assertTrue(host == null);
} finally {
session.close();
}
}
public void testSBucket() {
SHost host;
SBucket bucket;
Session session;
session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
host = new SHost();
host.setHost("localhost");
host.setUserOnHost("root");
host.setUserPassword("password");
host.setExportRoot("/");
bucket = new SBucket();
bucket.setName("Bucket");
bucket.setOwnerCanonicalId("OwnerId-dummy");
bucket.setCreateTime(new Date());
host.getBuckets().add(bucket);
bucket.setShost(host);
session.save(host);
session.save(bucket);
txn.commit();
} finally {
session.close();
}
long bucketId = bucket.getId();
// load bucket
session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
bucket = (SBucket)session.get(SBucket.class, bucketId);
txn.commit();
Assert.assertTrue(bucket.getShost().getHost().equals("localhost"));
Assert.assertTrue(bucket.getName().equals("Bucket"));
Assert.assertTrue(bucket.getOwnerCanonicalId().equals("OwnerId-dummy"));
} finally {
session.close();
}
// delete the bucket
session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
bucket = (SBucket)session.get(SBucket.class, bucketId);
session.delete(bucket);
host = (SHost)session.get(SHost.class, host.getId());
session.delete(host);
txn.commit();
} finally {
session.close();
}
// verify the deletion
session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
bucket = (SBucket)session.get(SBucket.class, bucketId);
txn.commit();
Assert.assertTrue(bucket == null);
} finally {
session.close();
}
}
public void testSObject() {
SHost host;
SBucket bucket;
Session session;
SObject sobject;
// setup
session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
host = new SHost();
host.setHost("localhost");
host.setUserOnHost("root");
host.setUserPassword("password");
host.setExportRoot("/");
bucket = new SBucket();
bucket.setName("Bucket");
bucket.setOwnerCanonicalId("OwnerId-dummy");
bucket.setCreateTime(new Date());
bucket.setShost(host);
host.getBuckets().add(bucket);
sobject = new SObject();
sobject.setNameKey("ObjectNameKey");
sobject.setOwnerCanonicalId("OwnerId-dummy");
sobject.setCreateTime(new Date());
sobject.setBucket(bucket);
bucket.getObjectsInBucket().add(sobject);
session.save(host);
session.save(bucket);
session.save(sobject);
txn.commit();
} finally {
session.close();
}
session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
sobject = (SObject)session.get(SObject.class, sobject.getId());
txn.commit();
Assert.assertTrue(sobject.getBucket().getName().equals("Bucket"));
Assert.assertTrue(sobject.getNameKey().equals("ObjectNameKey"));
Assert.assertTrue(sobject.getOwnerCanonicalId().equals("OwnerId-dummy"));
} finally {
session.close();
}
// test delete cascade
session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
bucket = (SBucket)session.get(SBucket.class, bucket.getId());
session.delete(bucket);
host = (SHost)session.get(SHost.class, host.getId());
session.delete(host);
txn.commit();
} finally {
session.close();
}
}
public void testMeta() {
Session session;
session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
SMeta meta = new SMeta();
meta.setTarget("SObject");
meta.setTargetId(1);
meta.setName("param1");
meta.setValue("value1");
session.save(meta);
logger.info("Meta 1: " + meta.getId());
meta = new SMeta();
meta.setTarget("SObject");
meta.setTargetId(1);
meta.setName("param2");
meta.setValue("value2");
session.save(meta);
logger.info("Meta 2: " + meta.getId());
txn.commit();
} finally {
session.close();
}
session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
Query query = session.createQuery("from SMeta where target=? and targetId=?");
QueryHelper.bindParameters(query, new Object[] {
"SObject", new Long(1)
});
List<SMeta> l = QueryHelper.executeQuery(query);
txn.commit();
for(SMeta meta: l) {
logger.info("" + meta.getName() + "=" + meta.getValue());
}
} finally {
session.close();
}
session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
Query query = session.createQuery("delete from SMeta where target=?");
QueryHelper.bindParameters(query, new Object[] {"SObject"});
query.executeUpdate();
txn.commit();
} finally {
session.close();
}
}
public void testHosts() {
Session session;
SHost shost;
MHost mhost;
MHostMount hostMount;
session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
shost = new SHost();
shost.setHost("Storage host1");
shost.setUserOnHost("root");
shost.setUserPassword("password");
shost.setExportRoot("/");
session.save(shost);
mhost = new MHost();
mhost.setHostKey("1");
mhost.setHost("management host1");
mhost.setVersion("v1");
session.save(mhost);
hostMount = new MHostMount();
hostMount.setMhost(mhost);
hostMount.setShost(shost);
hostMount.setMountPath("/mnt");
session.save(hostMount);
txn.commit();
} finally {
session.close();
}
session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
mhost = (MHost)session.createQuery("from MHost where hostKey=?").
setLong(0, new Long(1)).uniqueResult();
if(mhost != null) {
Iterator it = mhost.getMounts().iterator();
while(it.hasNext()) {
MHostMount mount = (MHostMount)it.next();
Assert.assertTrue(mount.getMountPath().equals("/mnt"));
logger.info(mount.getMountPath());
}
}
txn.commit();
} finally {
session.close();
}
session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
mhost = (MHost)session.createQuery("from MHost where hostKey=?").
setLong(0, new Long(1)).uniqueResult();
if(mhost != null)
session.delete(mhost);
shost = (SHost)session.createQuery("from SHost where host=?").
setString(0, "Storage host1").uniqueResult();
if(shost != null)
session.delete(shost);
txn.commit();
} finally {
session.close();
}
}
}

View File

@ -1,73 +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.gate.persist;
import org.apache.log4j.Logger;
import com.cloud.bridge.persist.PersistContext;
import com.cloud.gate.testcase.BaseTestCase;
public class PersitTestCase extends BaseTestCase {
protected final static Logger logger = Logger.getLogger(PersitTestCase.class);
public void testNamedLock() {
Thread t1 = new Thread(new Runnable() {
public void run() {
for(int i = 0; i < 10; i++) {
if(PersistContext.acquireNamedLock("TestLock", 3)) {
logger.info("Thread 1 acquired lock");
try {
Thread.currentThread().sleep(BaseTestCase.getRandomMilliseconds(5000, 10000));
} catch (InterruptedException e) {
}
logger.info("Thread 1 to release lock");
PersistContext.releaseNamedLock("TestLock");
} else {
logger.info("Thread 1 is unable to acquire lock");
}
}
}
});
Thread t2 = new Thread(new Runnable() {
public void run() {
for(int i = 0; i < 10; i++) {
if(PersistContext.acquireNamedLock("TestLock", 3)) {
logger.info("Thread 2 acquired lock");
try {
Thread.currentThread().sleep(BaseTestCase.getRandomMilliseconds(1000, 5000));
} catch (InterruptedException e) {
}
logger.info("Thread 2 to release lock");
PersistContext.releaseNamedLock("TestLock");
} else {
logger.info("Thread 2 is unable to acquire lock");
}
}
}
});
t1.start();
t2.start();
try {
t1.join();
t2.join();
} catch(InterruptedException e) {
}
}
}

View File

@ -85,6 +85,11 @@
<artifactId>cloud-plugin-network-midonet</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-plugin-network-internallb</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-plugin-hypervisor-xen</artifactId>
@ -239,6 +244,11 @@
<artifactId>cloud-plugin-host-anti-affinity</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-console-proxy</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>

View File

@ -167,7 +167,6 @@
<bean id="accountJoinDaoImpl" class="com.cloud.api.query.dao.AccountJoinDaoImpl" />
<bean id="accountGuestVlanMapDaoImpl" class="com.cloud.network.dao.AccountGuestVlanMapDaoImpl" />
<bean id="accountVlanMapDaoImpl" class="com.cloud.dc.dao.AccountVlanMapDaoImpl" />
<bean id="agentUpgradeDaoImpl" class="com.cloud.maint.dao.AgentUpgradeDaoImpl" />
<bean id="alertDaoImpl" class="com.cloud.alert.dao.AlertDaoImpl" />
<bean id="asyncJobDaoImpl" class="com.cloud.async.dao.AsyncJobDaoImpl" />
<bean id="asyncJobJoinDaoImpl" class="com.cloud.api.query.dao.AsyncJobJoinDaoImpl" />
@ -303,7 +302,6 @@
<bean id="snapshotDaoImpl" class="com.cloud.storage.dao.SnapshotDaoImpl" />
<bean id="snapshotPolicyDaoImpl" class="com.cloud.storage.dao.SnapshotPolicyDaoImpl" />
<bean id="snapshotScheduleDaoImpl" class="com.cloud.storage.dao.SnapshotScheduleDaoImpl" />
<bean id="stackMaidDaoImpl" class="com.cloud.cluster.dao.StackMaidDaoImpl" />
<bean id="staticRouteDaoImpl" class="com.cloud.network.vpc.dao.StaticRouteDaoImpl" />
<bean id="storageNetworkIpAddressDaoImpl" class="com.cloud.dc.dao.StorageNetworkIpAddressDaoImpl" />
<bean id="storageNetworkIpRangeDaoImpl" class="com.cloud.dc.dao.StorageNetworkIpRangeDaoImpl" />
@ -365,6 +363,9 @@
<bean id="vpcOfferingServiceMapDaoImpl" class="com.cloud.network.vpc.dao.VpcOfferingServiceMapDaoImpl" />
<bean id="vpcServiceMapDaoImpl" class="com.cloud.network.vpc.dao.VpcServiceMapDaoImpl" />
<bean id="vpnUserDaoImpl" class="com.cloud.network.dao.VpnUserDaoImpl" />
<bean id="applicationLbRuleDaoImpl" class="org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDaoImpl" />
<bean id="networkOfferingDetailsDaoImpl" class="com.cloud.offerings.dao.NetworkOfferingDetailsDaoImpl" />
<!--
Checkers
@ -408,10 +409,12 @@
<bean id="VpcVirtualRouter" class="com.cloud.network.element.VpcVirtualRouterElement">
<property name="name" value="VpcVirtualRouter"/>
</bean>
<bean id="elasticLoadBalancerElement" class="com.cloud.network.element.ElasticLoadBalancerElement">
<property name="name" value="ElasticLoadBalancerElement"/>
</bean>
<bean id="InternalLbVm" class="org.apache.cloudstack.network.element.InternalLoadBalancerElement">
<property name="name" value="InternalLbVm"/>
</bean>
<!--
General allocators
@ -705,7 +708,6 @@
<bean id="syncQueueManagerImpl" class="com.cloud.async.SyncQueueManagerImpl" />
<bean id="taggedResourceManagerImpl" class="com.cloud.tags.TaggedResourceManagerImpl" />
<bean id="templateManagerImpl" class="com.cloud.template.TemplateManagerImpl" />
<bean id="upgradeManagerImpl" class="com.cloud.maint.UpgradeManagerImpl" />
<bean id="uploadMonitorImpl" class="com.cloud.storage.upload.UploadMonitorImpl" />
<bean id="usageServiceImpl" class="com.cloud.usage.UsageServiceImpl" />
<bean id="virtualNetworkApplianceManagerImpl" class="com.cloud.network.router.VirtualNetworkApplianceManagerImpl" />
@ -792,6 +794,8 @@
<bean id="vMSnapshotManagerImpl" class="com.cloud.vm.snapshot.VMSnapshotManagerImpl" />
<bean id="volumeManagerImpl" class="com.cloud.storage.VolumeManagerImpl" />
<bean id="ClassicalPrimaryDataStoreProvider" class="org.apache.cloudstack.storage.datastore.provider.CloudStackPrimaryDataStoreProviderImpl" />
<bean id="ApplicationLoadBalancerService" class="org.apache.cloudstack.network.lb.ApplicationLoadBalancerManagerImpl" />
<bean id="InternalLoadBalancerVMManager" class="org.apache.cloudstack.network.lb.InternalLoadBalancerVMManagerImpl" />
<!--=======================================================================================================-->

View File

@ -67,7 +67,7 @@ getVMPassword=15
restoreVirtualMachine=15
changeServiceForVirtualMachine=15
scaleVirtualMachine=15
assignVirtualMachine=1
assignVirtualMachine=7
migrateVirtualMachine=1
migrateVirtualMachineWithVolume=1
recoverVirtualMachine=7
@ -127,6 +127,9 @@ deleteVlanIpRange=1
listVlanIpRanges=1
dedicatePublicIpRange=1
releasePublicIpRange=1
dedicateGuestVlanRange=1
releaseDedicatedGuestVlanRange=1
listDedicatedGuestVlanRanges=1
#### address commands
associateIpAddress=15
@ -574,6 +577,17 @@ revertToVMSnapshot=15
#### Baremetal commands
addBaremetalHost=1
#### New Load Balancer commands
createLoadBalancer=15
listLoadBalancers=15
deleteLoadBalancer=15
#Internal Load Balancer Element commands
configureInternalLoadBalancerElement=1
createInternalLoadBalancerElement=1
listInternalLoadBalancerElements=1
#### Affinity group commands
createAffinityGroup=15
deleteAffinityGroup=15
@ -591,5 +605,10 @@ addCiscoAsa1000vResource=1
deleteCiscoAsa1000vResource=1
listCiscoAsa1000vResources=1
#### Internal LB VM commands
stopInternalLoadBalancerVM=1
startInternalLoadBalancerVM=1
listInternalLoadBalancerVMs=1
### Network Isolation methods listing
listNetworkIsolationMethods=1

View File

@ -198,6 +198,7 @@
<ref bean="VirtualRouter"/>
<ref bean="VpcVirtualRouter"/>
<ref bean="NiciraNvp"/>
<ref bean="InternalLbVm"/>
</list>
</property>
</bean>
@ -241,6 +242,7 @@
<ref bean="VpcVirtualRouter"/>
<ref bean="NiciraNvp" />
<ref bean="MidoNetElement"/>
<ref bean="InternalLbVm"/>
<!--
<ref bean="BareMetalDhcp"/>
<ref bean="BareMetalPxe"/>

View File

@ -294,6 +294,7 @@
<ref bean="VirtualRouter"/>
<ref bean="VpcVirtualRouter"/>
<ref bean="NiciraNvp"/>
<ref bean="InternalLbVm"/>
</list>
</property>
</bean>
@ -343,6 +344,7 @@
<ref bean="Ovs"/>
<ref bean="SecurityGroupProvider"/>
<ref bean="VpcVirtualRouter"/>
<ref bean="InternalLbVm"/>
<!--
<ref bean="BareMetalDhcp"/>
<ref bean="BareMetalPxe"/>

View File

@ -205,6 +205,7 @@
<ref bean="Ovs"/>
<ref bean="SecurityGroupProvider"/>
<ref bean="VpcVirtualRouter"/>
<ref bean="InternalLbVm"/>
<!--
<ref bean="BareMetalDhcp"/>
<ref bean="BareMetalPxe"/>

View File

@ -36,6 +36,11 @@
<artifactId>cloud-engine-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-engine-schema</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
@ -55,7 +60,5 @@
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
</build>
</project>

View File

@ -1,31 +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.agent;
import com.cloud.agent.api.Command;
public interface RecoveryHandler {
/**
* Perform the necessary recovery because the success of this command
* is not known.
*
* @param agentId agent the commands were sent to.
* @param seq sequence number.
* @param cmds commands that failed.
*/
public void handle(long agentId, long seq, Command[] cmds);
}

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