Merge branch 'master' into planner_reserve

Conflicts:
	engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
	server/src/com/cloud/server/ManagementServerImpl.java
	setup/db/db/schema-410to420.sql
This commit is contained in:
Prachi Damle 2013-05-09 17:36:59 -07:00
commit 55eabcff2c
166 changed files with 10079 additions and 894 deletions

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,12 +399,16 @@ 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";
public static final String EVENT_HOST_RESERVATION_RELEASE = "HOST.RESERVATION.RELEASE";
// 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

@ -0,0 +1,33 @@
// 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.network.rules;
public interface LoadBalancerContainer {
public enum Scheme {
Public, Internal;
}
String getName();
String getDescription();
String getAlgorithm();
Scheme getScheme();
}

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

@ -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

@ -0,0 +1,28 @@
// 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.network.rules.LoadBalancerContainer;
import com.cloud.utils.net.Ip;
public interface ApplicationLoadBalancerContainer extends LoadBalancerContainer{
public Long getSourceIpNetworkId();
public Ip getSourceIp();
}

View File

@ -0,0 +1,24 @@
// 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.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

@ -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>

View File

@ -363,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
@ -406,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
@ -780,6 +785,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

@ -579,6 +579,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
@ -596,5 +607,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

@ -18,7 +18,6 @@ package com.cloud.network.dao;
import java.util.List;
import com.cloud.host.HostVO;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.FirewallRuleVO;
import com.cloud.utils.db.GenericDao;

View File

@ -31,12 +31,8 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.apache.cloudstack.api.Identity;
import com.cloud.network.IpAddress;
import com.cloud.network.IpAddress.State;
import com.cloud.utils.net.Ip;
import org.apache.cloudstack.api.InternalIdentity;
/**
* A bean representing a public IP Address
@ -304,4 +300,9 @@ public class IPAddressVO implements IpAddress {
public void setVmIp(String vmIp) {
this.vmIp = vmIp;
}
@Override
public Long getNetworkId() {
return sourceNetworkId;
}
}

View File

@ -18,19 +18,15 @@ package com.cloud.network.dao;
import java.util.List;
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.utils.db.GenericDao;
public interface LoadBalancerDao extends GenericDao<LoadBalancerVO, Long> {
List<Long> listInstancesByLoadBalancer(long loadBalancerId);
List<LoadBalancerVO> listByIpAddress(long ipAddressId);
LoadBalancerVO findByIpAddressAndPublicPort(long ipAddressId, String publicPort);
List<LoadBalancerVO> listByNetworkIdAndScheme(long networkId, Scheme scheme);
LoadBalancerVO findByAccountAndName(Long accountId, String name);
List<LoadBalancerVO> listByNetworkId(long networkId);
List<LoadBalancerVO> listInTransitionStateByNetworkId(long networkId);
List<LoadBalancerVO> listInTransitionStateByNetworkIdAndScheme(long networkId, Scheme scheme);
}

View File

@ -16,39 +16,24 @@
// under the License.
package com.cloud.network.dao;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.network.rules.FirewallRule.State;
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.Transaction;
@Component
@Local(value = { LoadBalancerDao.class })
public class LoadBalancerDaoImpl extends GenericDaoBase<LoadBalancerVO, Long> implements LoadBalancerDao {
private static final Logger s_logger = Logger.getLogger(LoadBalancerDaoImpl.class);
private static final String LIST_INSTANCES_BY_LOAD_BALANCER = "SELECT vm.id " +
" FROM vm_instance vm, load_balancer lb, ip_forwarding fwd, user_ip_address ip " +
" WHERE lb.id = ? AND " +
" fwd.group_id = lb.id AND " +
" fwd.forwarding = 0 AND " +
" fwd.private_ip_address = vm.private_ip_address AND " +
" lb.ip_address = ip.public_ip_address AND " +
" ip.data_center_id = vm.data_center_id ";
private final SearchBuilder<LoadBalancerVO> ListByIp;
private final SearchBuilder<LoadBalancerVO> IpAndPublicPortSearch;
private final SearchBuilder<LoadBalancerVO> AccountAndNameSearch;
protected final SearchBuilder<LoadBalancerVO> TransitionStateSearch;
@Inject protected FirewallRulesCidrsDao _portForwardingRulesCidrsDao;
@ -57,45 +42,16 @@ public class LoadBalancerDaoImpl extends GenericDaoBase<LoadBalancerVO, Long> im
ListByIp = createSearchBuilder();
ListByIp.and("ipAddressId", ListByIp.entity().getSourceIpAddressId(), SearchCriteria.Op.EQ);
ListByIp.and("networkId", ListByIp.entity().getNetworkId(), SearchCriteria.Op.EQ);
ListByIp.and("scheme", ListByIp.entity().getScheme(), SearchCriteria.Op.EQ);
ListByIp.done();
IpAndPublicPortSearch = createSearchBuilder();
IpAndPublicPortSearch.and("ipAddressId", IpAndPublicPortSearch.entity().getSourceIpAddressId(), SearchCriteria.Op.EQ);
IpAndPublicPortSearch.and("publicPort", IpAndPublicPortSearch.entity().getSourcePortStart(), SearchCriteria.Op.EQ);
IpAndPublicPortSearch.done();
AccountAndNameSearch = createSearchBuilder();
AccountAndNameSearch.and("accountId", AccountAndNameSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
AccountAndNameSearch.and("name", AccountAndNameSearch.entity().getName(), SearchCriteria.Op.EQ);
AccountAndNameSearch.done();
TransitionStateSearch = createSearchBuilder();
TransitionStateSearch.and("networkId", TransitionStateSearch.entity().getNetworkId(), Op.EQ);
TransitionStateSearch.and("state", TransitionStateSearch.entity().getState(), Op.IN);
TransitionStateSearch.and("scheme", TransitionStateSearch.entity().getScheme(), Op.EQ);
TransitionStateSearch.done();
}
@Override
public List<Long> listInstancesByLoadBalancer(long loadBalancerId) {
Transaction txn = Transaction.currentTxn();
String sql = LIST_INSTANCES_BY_LOAD_BALANCER;
PreparedStatement pstmt = null;
List<Long> instanceList = new ArrayList<Long>();
try {
pstmt = txn.prepareAutoCloseStatement(sql);
pstmt.setLong(1, loadBalancerId);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
Long vmId = rs.getLong(1);
instanceList.add(vmId);
}
} catch (Exception ex) {
s_logger.error("error getting recent usage network stats", ex);
}
return instanceList;
}
@Override
public List<LoadBalancerVO> listByIpAddress(long ipAddressId) {
SearchCriteria<LoadBalancerVO> sc = ListByIp.create();
@ -104,33 +60,19 @@ public class LoadBalancerDaoImpl extends GenericDaoBase<LoadBalancerVO, Long> im
}
@Override
public List<LoadBalancerVO> listByNetworkId(long networkId) {
public List<LoadBalancerVO> listByNetworkIdAndScheme(long networkId, Scheme scheme) {
SearchCriteria<LoadBalancerVO> sc = ListByIp.create();
sc.setParameters("networkId", networkId);
sc.setParameters("scheme", scheme);
return listBy(sc);
}
@Override
public LoadBalancerVO findByIpAddressAndPublicPort(long ipAddressId, String publicPort) {
SearchCriteria<LoadBalancerVO> sc = IpAndPublicPortSearch.create();
sc.setParameters("ipAddressId", ipAddressId);
sc.setParameters("publicPort", publicPort);
return findOneBy(sc);
}
@Override
public LoadBalancerVO findByAccountAndName(Long accountId, String name) {
SearchCriteria<LoadBalancerVO> sc = AccountAndNameSearch.create();
sc.setParameters("accountId", accountId);
sc.setParameters("name", name);
return findOneBy(sc);
}
@Override
public List<LoadBalancerVO> listInTransitionStateByNetworkId(long networkId) {
public List<LoadBalancerVO> listInTransitionStateByNetworkIdAndScheme(long networkId, Scheme scheme) {
SearchCriteria<LoadBalancerVO> sc = TransitionStateSearch.create();
sc.setParameters("networkId", networkId);
sc.setParameters("state", State.Add.toString(), State.Revoke.toString());
sc.setParameters("scheme", scheme);
return listBy(sc);
}

View File

@ -19,6 +19,8 @@ package com.cloud.network.dao;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
@ -26,6 +28,12 @@ import com.cloud.network.rules.FirewallRuleVO;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.utils.net.NetUtils;
/**
* This VO represent Public Load Balancer
* It references source ip address by its Id.
* To get the VO for Internal Load Balancer rule, please refer to LoadBalancerRuleVO
*
*/
@Entity
@Table(name=("load_balancing_rules"))
@DiscriminatorValue(value="LoadBalancing")
@ -46,6 +54,10 @@ public class LoadBalancerVO extends FirewallRuleVO implements LoadBalancer {
@Column(name="default_port_end")
private int defaultPortEnd;
@Enumerated(value=EnumType.STRING)
@Column(name="scheme")
Scheme scheme = Scheme.Public;
public LoadBalancerVO() {
}
@ -57,6 +69,7 @@ public class LoadBalancerVO extends FirewallRuleVO implements LoadBalancer {
this.algorithm = algorithm;
this.defaultPortStart = dstPort;
this.defaultPortEnd = dstPort;
this.scheme = Scheme.Public;
}
@Override
@ -94,5 +107,10 @@ public class LoadBalancerVO extends FirewallRuleVO implements LoadBalancer {
public void setDescription(String description) {
this.description = description;
}
@Override
public Scheme getScheme() {
return scheme;
}
}

View File

@ -35,4 +35,5 @@ public interface NetworkServiceMapDao extends GenericDao<NetworkServiceMapVO, Lo
void deleteByNetworkId(long networkId);
List<String> getDistinctProviders(long networkId);
String isProviderForNetwork(long networkId, Provider provider);
List<String> getProvidersForServiceInNetwork(long networkId, Service service);
}

View File

@ -56,6 +56,7 @@ public class NetworkServiceMapDaoImpl extends GenericDaoBase<NetworkServiceMapVO
DistinctProvidersSearch = createSearchBuilder(String.class);
DistinctProvidersSearch.and("networkId", DistinctProvidersSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
DistinctProvidersSearch.and("provider", DistinctProvidersSearch.entity().getProvider(), SearchCriteria.Op.EQ);
DistinctProvidersSearch.and("service", DistinctProvidersSearch.entity().getService(), SearchCriteria.Op.EQ);
DistinctProvidersSearch.selectField(DistinctProvidersSearch.entity().getProvider());
DistinctProvidersSearch.done();
}
@ -163,5 +164,13 @@ public class NetworkServiceMapDaoImpl extends GenericDaoBase<NetworkServiceMapVO
return results.get(0);
}
}
@Override
public List<String> getProvidersForServiceInNetwork(long networkId, Service service) {
SearchCriteria<String> sc = DistinctProvidersSearch.create();
sc.setParameters("networkId", networkId);
sc.setParameters("service", service.getName());
return customSearch(sc, null);
}
}

View File

@ -32,9 +32,6 @@ import javax.persistence.Transient;
import org.apache.cloudstack.acl.ControlledEntity;
import com.cloud.network.Network;
import com.cloud.network.Networks;
import com.cloud.network.Network.GuestType;
import com.cloud.network.Network.State;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.Mode;
import com.cloud.network.Networks.TrafficType;

View File

@ -20,7 +20,6 @@ import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.inject.Inject;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
@ -35,7 +34,6 @@ import javax.persistence.InheritanceType;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.cloud.network.dao.FirewallRulesCidrsDao;
import com.cloud.utils.db.GenericDao;
import com.cloud.utils.net.NetUtils;

View File

@ -0,0 +1,90 @@
// 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.offerings;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.apache.cloudstack.api.InternalIdentity;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.Detail;
@Entity
@Table(name="network_offering_details")
public class NetworkOfferingDetailsVO implements InternalIdentity {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private long id;
@Column(name="network_offering_id")
private long offeringId;
@Enumerated(value=EnumType.STRING)
@Column(name="name")
private NetworkOffering.Detail name;
@Column(name="value", length=1024)
private String value;
public NetworkOfferingDetailsVO() {}
public NetworkOfferingDetailsVO(long offeringId, Detail detailName, String value) {
this.offeringId = offeringId;
this.name = detailName;
this.value = value;
}
public long getId() {
return id;
}
public long getOfferingId() {
return offeringId;
}
public NetworkOffering.Detail getName() {
return name;
}
public String getValue() {
return value;
}
public void setId(long id) {
this.id = id;
}
public void setOfferingId(long offeringId) {
this.offeringId = offeringId;
}
public void setName(NetworkOffering.Detail name) {
this.name = name;
}
public void setValue(String value) {
this.value = value;
}
}

View File

@ -16,15 +16,23 @@
// under the License.
package com.cloud.offerings;
import java.util.Date;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.cloud.network.Network;
import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.NetworkOffering;
import com.cloud.utils.db.GenericDao;
import javax.persistence.*;
import java.util.Date;
import java.util.UUID;
@Entity
@Table(name = "network_offerings")
public class NetworkOfferingVO implements NetworkOffering {
@ -126,6 +134,12 @@ public class NetworkOfferingVO implements NetworkOffering {
public String getDisplayText() {
return displayText;
}
@Column(name = "internal_lb")
boolean internalLb;
@Column(name = "public_lb")
boolean publicLb;
@Override
public long getId() {
@ -262,7 +276,7 @@ public class NetworkOfferingVO implements NetworkOffering {
}
public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, boolean isDefault,
Availability availability, String tags, Network.GuestType guestType, boolean conserveMode, boolean specifyIpRanges, boolean isPersistent) {
Availability availability, String tags, Network.GuestType guestType, boolean conserveMode, boolean specifyIpRanges, boolean isPersistent, boolean internalLb, boolean publicLb) {
this.name = name;
this.displayText = displayText;
this.rateMbps = rateMbps;
@ -286,12 +300,14 @@ public class NetworkOfferingVO implements NetworkOffering {
this.inline = false;
this.specifyIpRanges = specifyIpRanges;
this.isPersistent=isPersistent;
this.publicLb = publicLb;
this.internalLb = internalLb;
}
public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, boolean isDefault,
Availability availability, String tags, Network.GuestType guestType, boolean conserveMode, boolean dedicatedLb, boolean sharedSourceNat, boolean redundantRouter, boolean elasticIp, boolean elasticLb,
boolean specifyIpRanges, boolean inline, boolean isPersistent, boolean associatePublicIP) {
this(name, displayText, trafficType, systemOnly, specifyVlan, rateMbps, multicastRateMbps, isDefault, availability, tags, guestType, conserveMode, specifyIpRanges, isPersistent);
boolean specifyIpRanges, boolean inline, boolean isPersistent, boolean associatePublicIP, boolean publicLb, boolean internalLb) {
this(name, displayText, trafficType, systemOnly, specifyVlan, rateMbps, multicastRateMbps, isDefault, availability, tags, guestType, conserveMode, specifyIpRanges, isPersistent, internalLb, publicLb);
this.dedicatedLB = dedicatedLb;
this.sharedSourceNat = sharedSourceNat;
this.redundantRouter = redundantRouter;
@ -313,13 +329,13 @@ public class NetworkOfferingVO implements NetworkOffering {
* TODO
*/
public NetworkOfferingVO(String name, TrafficType trafficType, boolean specifyIpRanges) {
this(name, "System Offering for " + name, trafficType, true, false, 0, 0, true, Availability.Required, null, null, true, specifyIpRanges, false);
this(name, "System Offering for " + name, trafficType, true, false, 0, 0, true, Availability.Required, null, null, true, specifyIpRanges, false, false, false);
this.state = State.Enabled;
}
public NetworkOfferingVO(String name, Network.GuestType guestType) {
this(name, "System Offering for " + name, TrafficType.Guest, true, true, 0, 0, true, Availability.Optional,
null, Network.GuestType.Isolated, true, false, false);
null, Network.GuestType.Isolated, true, false, false, false, false);
this.state = State.Enabled;
}
@ -388,4 +404,14 @@ public class NetworkOfferingVO implements NetworkOffering {
return isPersistent;
}
@Override
public boolean getInternalLb() {
return internalLb;
}
@Override
public boolean getPublicLb() {
return publicLb;
}
}

View File

@ -17,11 +17,13 @@
package com.cloud.offerings.dao;
import java.util.List;
import java.util.Map;
import com.cloud.network.Network;
import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.Availability;
import com.cloud.offering.NetworkOffering.Detail;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.utils.db.GenericDao;
@ -57,4 +59,6 @@ public interface NetworkOfferingDao extends GenericDao<NetworkOfferingVO, Long>
List<NetworkOfferingVO> listByTrafficTypeGuestTypeAndState(NetworkOffering.State state, TrafficType trafficType, Network.GuestType type);
NetworkOfferingVO persist(NetworkOfferingVO off, Map<Detail, String> details);
}

View File

@ -17,8 +17,10 @@
package com.cloud.offerings.dao;
import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.persistence.EntityExistsException;
import org.springframework.stereotype.Component;
@ -27,6 +29,8 @@ import com.cloud.network.Network;
import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.Availability;
import com.cloud.offering.NetworkOffering.Detail;
import com.cloud.offerings.NetworkOfferingDetailsVO;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
@ -45,6 +49,7 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Lo
final SearchBuilder<NetworkOfferingVO> AvailabilitySearch;
final SearchBuilder<NetworkOfferingVO> AllFieldsSearch;
private final GenericSearchBuilder<NetworkOfferingVO, Long> UpgradeSearch;
@Inject NetworkOfferingDetailsDao _detailsDao;
protected NetworkOfferingDaoImpl() {
super();
@ -165,5 +170,24 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Lo
sc.setParameters("state", state);
return listBy(sc, null);
}
@Override
@DB
public NetworkOfferingVO persist(NetworkOfferingVO off, Map<Detail, String> details) {
Transaction txn = Transaction.currentTxn();
txn.start();
//1) persist the offering
NetworkOfferingVO vo = super.persist(off);
//2) persist the details
if (details != null && !details.isEmpty()) {
for (NetworkOffering.Detail detail : details.keySet()) {
_detailsDao.persist(new NetworkOfferingDetailsVO(off.getId(), detail, details.get(detail)));
}
}
txn.commit();
return vo;
}
}

View File

@ -0,0 +1,31 @@
// 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.offerings.dao;
import java.util.Map;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.Detail;
import com.cloud.offerings.NetworkOfferingDetailsVO;
import com.cloud.utils.db.GenericDao;
public interface NetworkOfferingDetailsDao extends GenericDao<NetworkOfferingDetailsVO, Long>{
Map<NetworkOffering.Detail,String> getNtwkOffDetails(long offeringId);
String getDetail(long offeringId, Detail detailName);
}

View File

@ -0,0 +1,79 @@
// 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.offerings.dao;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.Detail;
import com.cloud.offerings.NetworkOfferingDetailsVO;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Func;
import com.cloud.utils.db.SearchCriteria.Op;
public class NetworkOfferingDetailsDaoImpl extends GenericDaoBase<NetworkOfferingDetailsVO, Long> implements NetworkOfferingDetailsDao{
protected final SearchBuilder<NetworkOfferingDetailsVO> DetailSearch;
private final GenericSearchBuilder<NetworkOfferingDetailsVO, String> ValueSearch;
public NetworkOfferingDetailsDaoImpl() {
DetailSearch = createSearchBuilder();
DetailSearch.and("offeringId", DetailSearch.entity().getOfferingId(), SearchCriteria.Op.EQ);
DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ);
DetailSearch.done();
ValueSearch = createSearchBuilder(String.class);
ValueSearch.select(null, Func.DISTINCT, ValueSearch.entity().getValue());
ValueSearch.and("offeringId", ValueSearch.entity().getOfferingId(), SearchCriteria.Op.EQ);
ValueSearch.and("name", ValueSearch.entity().getName(), Op.EQ);
ValueSearch.done();
}
@Override
public Map<NetworkOffering.Detail,String> getNtwkOffDetails(long offeringId) {
SearchCriteria<NetworkOfferingDetailsVO> sc = DetailSearch.create();
sc.setParameters("offeringId", offeringId);
List<NetworkOfferingDetailsVO> results = search(sc, null);
Map<NetworkOffering.Detail, String> details = new HashMap<NetworkOffering.Detail, String>(results.size());
for (NetworkOfferingDetailsVO result : results) {
details.put(result.getName(), result.getValue());
}
return details;
}
@Override
public String getDetail(long offeringId, Detail detailName) {
SearchCriteria<String> sc = ValueSearch.create();
sc.setParameters("name", detailName);
sc.setParameters("offeringId", offeringId);
List<String> results = customSearch(sc, null);
if (results.isEmpty()) {
return null;
} else {
return results.get(0);
}
}
}

View File

@ -21,7 +21,6 @@ import com.cloud.deploy.DeploymentPlanner;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
import org.apache.log4j.Logger;
import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
@ -68,6 +67,8 @@ public class Upgrade410to420 implements DbUpgrade {
addEgressFwRulesForSRXGuestNw(conn);
upgradeEIPNetworkOfferings(conn);
updateGlobalDeploymentPlanner(conn);
upgradeDefaultVpcOffering(conn);
upgradePhysicalNtwksWithInternalLbProvider(conn);
}
private void updateSystemVmTemplates(Connection conn) {
@ -448,4 +449,87 @@ public class Upgrade410to420 implements DbUpgrade {
}
}
}
private void upgradeDefaultVpcOffering(Connection conn) {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement("select distinct map.vpc_offering_id from `cloud`.`vpc_offering_service_map` map, `cloud`.`vpc_offerings` off where off.id=map.vpc_offering_id AND service='Lb'");
rs = pstmt.executeQuery();
while (rs.next()) {
long id = rs.getLong(1);
//Add internal LB vm as a supported provider for the load balancer service
pstmt = conn.prepareStatement("INSERT INTO `cloud`.`vpc_offering_service_map` (vpc_offering_id, service, provider) VALUES (?,?,?)");
pstmt.setLong(1, id);
pstmt.setString(2, "Lb");
pstmt.setString(3, "InternalLbVm");
pstmt.executeUpdate();
}
} catch (SQLException e) {
throw new CloudRuntimeException("Unable update the default VPC offering with the internal lb service", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
}
}
private void upgradePhysicalNtwksWithInternalLbProvider(Connection conn) {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`physical_network` where removed is null");
rs = pstmt.executeQuery();
while (rs.next()) {
long pNtwkId = rs.getLong(1);
String uuid = UUID.randomUUID().toString();
//Add internal LB VM to the list of physical network service providers
pstmt = conn.prepareStatement("INSERT INTO `cloud`.`physical_network_service_providers` " +
"(uuid, physical_network_id, provider_name, state, load_balance_service_provided, destination_physical_network_id)" +
" VALUES (?, ?, 'InternalLbVm', 'Enabled', 1, 0)");
pstmt.setString(1, uuid);
pstmt.setLong(2, pNtwkId);
pstmt.executeUpdate();
//Add internal lb vm to the list of physical network elements
PreparedStatement pstmt1 = conn.prepareStatement("SELECT id FROM `cloud`.`physical_network_service_providers`" +
" WHERE physical_network_id=? AND provider_name='InternalLbVm'");
ResultSet rs1 = pstmt1.executeQuery();
while (rs1.next()) {
long providerId = rs1.getLong(1);
uuid = UUID.randomUUID().toString();
pstmt1 = conn.prepareStatement("INSERT INTO `cloud`.`virtual_router_providers` (nsp_id, uuid, type, enabled) VALUES (?, ?, 'InternalLbVm', 1)");
pstmt1.setLong(1, providerId);
pstmt1.setString(2, uuid);
pstmt1.executeUpdate();
}
}
} catch (SQLException e) {
throw new CloudRuntimeException("Unable existing physical networks with internal lb provider", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
}
}
}

View File

@ -30,7 +30,7 @@ public interface NicDao extends GenericDao<NicVO, Long> {
List<NicVO> listByNetworkId(long networkId);
NicVO findByInstanceIdAndNetworkId(long networkId, long instanceId);
NicVO findByNtwkIdAndInstanceId(long networkId, long instanceId);
NicVO findByInstanceIdAndNetworkIdIncludingRemoved(long networkId, long instanceId);

View File

@ -113,7 +113,7 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
}
@Override
public NicVO findByInstanceIdAndNetworkId(long networkId, long instanceId) {
public NicVO findByNtwkIdAndInstanceId(long networkId, long instanceId) {
SearchCriteria<NicVO> sc = AllFieldsSearch.create();
sc.setParameters("network", networkId);
sc.setParameters("instance", instanceId);

View File

@ -0,0 +1,133 @@
// 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.lb;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
import com.cloud.network.rules.FirewallRuleVO;
import com.cloud.utils.net.Ip;
import com.cloud.utils.net.NetUtils;
/**
* This VO represent Internal Load Balancer rule.
* Instead of pointing to the public ip address id directly as External Load Balancer rule does, it refers to the ip address by its value/sourceNetworkid
*
*/
@Entity
@Table(name=("load_balancing_rules"))
@DiscriminatorValue(value="LoadBalancing")
@PrimaryKeyJoinColumn(name="id")
public class ApplicationLoadBalancerRuleVO extends FirewallRuleVO implements ApplicationLoadBalancerRule{
@Column(name="name")
private String name;
@Column(name="description", length=4096)
private String description;
@Column(name="algorithm")
private String algorithm;
@Column(name="default_port_start")
private int defaultPortStart;
@Column(name="default_port_end")
private int defaultPortEnd;
@Column(name="source_ip_address_network_id")
Long sourceIpNetworkId;
@Column(name="source_ip_address")
@Enumerated(value=EnumType.STRING)
private Ip sourceIp = null;
@Enumerated(value=EnumType.STRING)
@Column(name="scheme")
Scheme scheme;
public ApplicationLoadBalancerRuleVO() {
}
public ApplicationLoadBalancerRuleVO(String name, String description, int srcPort, int instancePort, String algorithm,
long networkId, long accountId, long domainId, Ip sourceIp, long sourceIpNtwkId, Scheme scheme) {
super(null, null, srcPort, srcPort, NetUtils.TCP_PROTO, networkId, accountId, domainId, Purpose.LoadBalancing, null, null,null, null, null);
this.name = name;
this.description = description;
this.algorithm = algorithm;
this.defaultPortStart = instancePort;
this.defaultPortEnd = instancePort;
this.sourceIp = sourceIp;
this.sourceIpNetworkId = sourceIpNtwkId;
this.scheme = scheme;
}
@Override
public Long getSourceIpNetworkId() {
return sourceIpNetworkId;
}
@Override
public Ip getSourceIp() {
return sourceIp;
}
@Override
public String getName() {
return name;
}
@Override
public String getDescription() {
return description;
}
@Override
public String getAlgorithm() {
return algorithm;
}
@Override
public int getDefaultPortStart() {
return defaultPortStart;
}
@Override
public int getDefaultPortEnd() {
return defaultPortEnd;
}
@Override
public Scheme getScheme() {
return scheme;
}
@Override
public int getInstancePort() {
return defaultPortStart;
}
}

View File

@ -0,0 +1,35 @@
// 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.lb.dao;
import java.util.List;
import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.utils.db.GenericDao;
import com.cloud.utils.net.Ip;
public interface ApplicationLoadBalancerRuleDao extends GenericDao<ApplicationLoadBalancerRuleVO, Long>{
List<ApplicationLoadBalancerRuleVO> listBySrcIpSrcNtwkId(Ip sourceIp, long sourceNetworkId);
List<String> listLbIpsBySourceIpNetworkId(long sourceIpNetworkId);
long countBySourceIp(Ip sourceIp, long sourceIpNetworkId);
List<ApplicationLoadBalancerRuleVO> listBySourceIpAndNotRevoked(Ip sourceIp, long sourceNetworkId);
List<String> listLbIpsBySourceIpNetworkIdAndScheme(long sourceIpNetworkId, Scheme scheme);
}

View File

@ -0,0 +1,115 @@
// 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.lb.dao;
import java.util.List;
import javax.ejb.Local;
import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
import org.springframework.stereotype.Component;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Func;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.net.Ip;
@Component
@Local(value = { ApplicationLoadBalancerRuleDao.class })
public class ApplicationLoadBalancerRuleDaoImpl extends GenericDaoBase<ApplicationLoadBalancerRuleVO, Long> implements ApplicationLoadBalancerRuleDao{
protected final SearchBuilder<ApplicationLoadBalancerRuleVO> AllFieldsSearch;
final GenericSearchBuilder<ApplicationLoadBalancerRuleVO, String> listIps;
final GenericSearchBuilder<ApplicationLoadBalancerRuleVO, Long> CountBy;
protected final SearchBuilder<ApplicationLoadBalancerRuleVO> NotRevokedSearch;
protected ApplicationLoadBalancerRuleDaoImpl() {
AllFieldsSearch = createSearchBuilder();
AllFieldsSearch.and("sourceIp", AllFieldsSearch.entity().getSourceIp(), SearchCriteria.Op.EQ);
AllFieldsSearch.and("sourceIpNetworkId", AllFieldsSearch.entity().getSourceIpNetworkId(), SearchCriteria.Op.EQ);
AllFieldsSearch.and("networkId", AllFieldsSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
AllFieldsSearch.and("scheme", AllFieldsSearch.entity().getScheme(), SearchCriteria.Op.EQ);
AllFieldsSearch.done();
listIps = createSearchBuilder(String.class);
listIps.select(null, Func.DISTINCT, listIps.entity().getSourceIp());
listIps.and("sourceIpNetworkId", listIps.entity().getSourceIpNetworkId(), Op.EQ);
listIps.and("scheme", listIps.entity().getScheme(), Op.EQ);
listIps.done();
CountBy = createSearchBuilder(Long.class);
CountBy.select(null, Func.COUNT, CountBy.entity().getId());
CountBy.and("sourceIp", CountBy.entity().getSourceIp(), Op.EQ);
CountBy.and("sourceIpNetworkId", CountBy.entity().getSourceIpNetworkId(), Op.EQ);
CountBy.done();
NotRevokedSearch = createSearchBuilder();
NotRevokedSearch.and("sourceIp", NotRevokedSearch.entity().getSourceIp(), SearchCriteria.Op.EQ);
NotRevokedSearch.and("sourceIpNetworkId", NotRevokedSearch.entity().getSourceIpNetworkId(), SearchCriteria.Op.EQ);
NotRevokedSearch.and("state", NotRevokedSearch.entity().getState(), SearchCriteria.Op.NEQ);
NotRevokedSearch.done();
}
@Override
public List<ApplicationLoadBalancerRuleVO> listBySrcIpSrcNtwkId(Ip sourceIp, long sourceNetworkId) {
SearchCriteria<ApplicationLoadBalancerRuleVO> sc = AllFieldsSearch.create();
sc.setParameters("sourceIp", sourceIp);
sc.setParameters("sourceIpNetworkId", sourceNetworkId);
return listBy(sc);
}
@Override
public List<String> listLbIpsBySourceIpNetworkId(long sourceIpNetworkId) {
SearchCriteria<String> sc = listIps.create();
sc.setParameters("sourceIpNetworkId", sourceIpNetworkId);
return customSearch(sc, null);
}
@Override
public long countBySourceIp(Ip sourceIp, long sourceIpNetworkId) {
SearchCriteria<Long> sc = CountBy.create();
sc.setParameters("sourceIp", sourceIp);
sc.setParameters("sourceIpNetworkId", sourceIpNetworkId);
List<Long> results = customSearch(sc, null);
return results.get(0);
}
@Override
public List<ApplicationLoadBalancerRuleVO> listBySourceIpAndNotRevoked(Ip sourceIp, long sourceNetworkId) {
SearchCriteria<ApplicationLoadBalancerRuleVO> sc = NotRevokedSearch.create();
sc.setParameters("sourceIp", sourceIp);
sc.setParameters("sourceIpNetworkId", sourceNetworkId);
sc.setParameters("state", FirewallRule.State.Revoke);
return listBy(sc);
}
@Override
public List<String> listLbIpsBySourceIpNetworkIdAndScheme(long sourceIpNetworkId, Scheme scheme) {
SearchCriteria<String> sc = listIps.create();
sc.setParameters("sourceIpNetworkId", sourceIpNetworkId);
sc.setParameters("scheme", scheme);
return customSearch(sc, null);
}
}

View File

@ -901,6 +901,28 @@ setup_elbvm() {
chkconfig portmap off
}
setup_ilbvm() {
log_it "Setting up Internal Load Balancer system vm"
local hyp=$1
setup_common eth0 eth1
#eth0 = guest network, eth1=control network
sed -i /$NAME/d /etc/hosts
echo "$ETH0_IP $NAME" >> /etc/hosts
cp /etc/iptables/iptables-ilbvm /etc/iptables/rules.v4
cp /etc/iptables/iptables-ilbvm /etc/iptables/rules
setup_sshd $ETH1_IP "eth1"
enable_fwding 0
enable_svc haproxy 1
enable_svc dnsmasq 0
enable_svc cloud-passwd-srvr 0
enable_svc cloud 0
chkconfig nfs-common off
chkconfig portmap off
}
setup_default() {
cat > /etc/network/interfaces << EOF
auto lo
@ -951,6 +973,10 @@ start() {
[ "$NAME" == "" ] && NAME=elb
setup_elbvm
;;
ilbvm)
[ "$NAME" == "" ] && NAME=ilb
setup_ilbvm
;;
unknown)
[ "$NAME" == "" ] && NAME=systemvm
setup_default;

View File

@ -0,0 +1,33 @@
# 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.
*nat
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
COMMIT
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -i eth1 -p tcp -m state --state NEW --dport 3922 -j ACCEPT
COMMIT

View File

@ -0,0 +1,211 @@
#!/usr/bin/env bash
# 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.
source /root/func.sh
lock="biglock"
locked=$(getLockFile $lock)
if [ "$locked" != "1" ]
then
exit 1
fi
usage() {
printf "Usage: %s: -a <added public ip address ip:port> -d <removed ip:port> -f <load balancer config> -s <stats ip ip:port:cidr> \n" $(basename $0) >&2
}
#set -x
fw_remove_backup() {
logger -t cloud "$(basename $0): Entering fw_remove_backup"
local lb_vif_list=eth0
for vif in $lb_vif_list; do
sudo iptables -F back_load_balancer_$vif 2> /dev/null
sudo iptables -D INPUT -i $vif -p tcp -j back_load_balancer_$vif 2> /dev/null
sudo iptables -X back_load_balancer_$vif 2> /dev/null
done
sudo iptables -F back_lb_stats 2> /dev/null
sudo iptables -D INPUT -p tcp -j back_lb_stats 2> /dev/null
sudo iptables -X back_lb_stats 2> /dev/null
}
fw_restore() {
logger -t cloud "$(basename $0): Entering fw_restore"
local lb_vif_list="eth0"
for vif in $lb_vif_list; do
sudo iptables -F load_balancer_$vif 2> /dev/null
sudo iptables -D INPUT -i $vif -p tcp -j load_balancer_$vif 2> /dev/null
sudo iptables -X load_balancer_$vif 2> /dev/null
sudo iptables -E back_load_balancer_$vif load_balancer_$vif 2> /dev/null
done
sudo iptables -F lb_stats 2> /dev/null
sudo iptables -D INPUT -p tcp -j lb_stats 2> /dev/null
sudo iptables -X lb_stats 2> /dev/null
sudo iptables -E back_lb_stats lb_stats 2> /dev/null
}
# firewall entry to ensure that haproxy can receive on specified port
fw_entry() {
logger -t cloud "$(basename $0): Entering fw_entry"
local added=$1
local removed=$2
local stats=$3
if [ "$added" == "none" ]
then
added=""
fi
if [ "$removed" == "none" ]
then
removed=""
fi
local a=$(echo $added | cut -d, -f1- --output-delimiter=" ")
local r=$(echo $removed | cut -d, -f1- --output-delimiter=" ")
# back up the iptable rules by renaming before creating new.
local lb_vif_list=eth0
for vif in $lb_vif_list; do
sudo iptables -E load_balancer_$vif back_load_balancer_$vif 2> /dev/null
sudo iptables -N load_balancer_$vif 2> /dev/null
sudo iptables -A INPUT -i $vif -p tcp -j load_balancer_$vif
done
sudo iptables -E lb_stats back_lb_stats 2> /dev/null
sudo iptables -N lb_stats 2> /dev/null
sudo iptables -A INPUT -p tcp -j lb_stats
for i in $a
do
local pubIp=$(echo $i | cut -d: -f1)
local dport=$(echo $i | cut -d: -f2)
local lb_vif_list="eth0"
for vif in $lb_vif_list; do
sudo iptables -A load_balancer_$vif -p tcp -d $pubIp --dport $dport -j ACCEPT
if [ $? -gt 0 ]
then
return 1
fi
done
done
local pubIp=$(echo $stats | cut -d: -f1)
local dport=$(echo $stats | cut -d: -f2)
local cidrs=$(echo $stats | cut -d: -f3 | sed 's/-/,/')
sudo iptables -A lb_stats -s $cidrs -p tcp -m state --state NEW -d $pubIp --dport $dport -j ACCEPT
return 0
}
#Hot reconfigure HA Proxy in the routing domain
reconfig_lb() {
/root/reconfigLB.sh
return $?
}
# Restore the HA Proxy to its previous state, and revert iptables rules on loadbalancer
restore_lb() {
logger -t cloud "Restoring HA Proxy to previous state"
# Copy the old version of haproxy.cfg into the file that reconfigLB.sh uses
cp /etc/haproxy/haproxy.cfg.old /etc/haproxy/haproxy.cfg.new
if [ $? -eq 0 ]
then
# Run reconfigLB.sh again
/root/reconfigLB.sh
fi
}
logger -t cloud "$(basename $0): Entering $(dirname $0)/$(basename $0)"
iflag=
aflag=
dflag=
sflag=
while getopts 'i:a:d:s:' OPTION
do
case $OPTION in
i) iflag=1
domRIp="$OPTARG" #unused but passed in
;;
a) aflag=1
addedIps="$OPTARG"
;;
d) dflag=1
removedIps="$OPTARG"
;;
s) sflag=1
statsIp="$OPTARG"
;;
?) usage
unlock_exit 2 $lock $locked
;;
esac
done
if [[ "$aflag$dflag" != "1" && "$aflag$dflag" != "11" ]]
then
usage
unlock_exit 2 $lock $locked
fi
if [ "$addedIps" == "" ]
then
addedIps="none"
fi
if [ "$removedIps" == "" ]
then
removedIps="none"
fi
# hot reconfigure haproxy
reconfig_lb $cfgfile
if [ $? -gt 0 ]
then
logger -t cloud "Reconfiguring ilb failed"
unlock_exit 1 $lock $locked
fi
logger -t cloud "HAProxy reconfigured successfully, configuring firewall"
# iptables entry to ensure that haproxy receives traffic
fw_entry $addedIps $removedIps $statsIp
if [ $? -gt 0 ]
then
logger -t cloud "Failed to apply firewall rules for internal load balancing, reverting HA Proxy config"
# Restore the LB
restore_lb
logger -t cloud "Reverting firewall config"
fw_restore
unlock_exit 1 $lock $locked
else
# Remove backedup iptable rules
logger -t cloud "Firewall configured successfully, deleting backup firewall config"
fw_remove_backup
fi
unlock_exit 0 $lock $locked

View File

@ -135,6 +135,19 @@ elbvm_svcs() {
echo "cloud dnsmasq cloud-passwd-srvr apache2 nfs-common portmap" > /var/cache/cloud/disabled_svcs
}
ilbvm_svcs() {
chkconfig cloud off
chkconfig haproxy on ;
chkconfig ssh on
chkconfig nfs-common off
chkconfig portmap off
chkconfig keepalived off
chkconfig conntrackd off
echo "ssh haproxy" > /var/cache/cloud/enabled_svcs
echo "cloud dnsmasq cloud-passwd-srvr apache2 nfs-common portmap" > /var/cache/cloud/disabled_svcs
}
enable_pcihotplug() {
sed -i -e "/acpiphp/d" /etc/modules
sed -i -e "/pci_hotplug/d" /etc/modules
@ -253,4 +266,14 @@ then
fi
fi
if [ "$TYPE" == "ilbvm" ]
then
ilbvm_svcs
if [ $? -gt 0 ]
then
printf "Failed to execute ilbvm svcs\n" >$logfile
exit 9
fi
fi
exit $?

View File

@ -18,6 +18,29 @@
# @VERSION@
do_ilb_if_ilb () {
local typ=""
local pattern="type=(.*)"
for keyval in $(cat /var/cache/cloud/cmdline)
do
if [[ $keyval =~ $pattern ]]; then
typ=${BASH_REMATCH[1]};
fi
done
if [ "$typ" == "ilbvm" ]
then
logger -t cloud "$(basename $0): Detected that we are running in an internal load balancer vm"
$(dirname $0)/ilb.sh "$@"
exit $?
fi
}
logger -t cloud "$(basename $0): Entering $(dirname $0)/$(basename $0)"
do_ilb_if_ilb "$@"
source /root/func.sh
source /opt/cloud/bin/vpc_func.sh

View File

@ -237,6 +237,7 @@ import com.vmware.vim25.ClusterDasConfigInfo;
import com.vmware.vim25.ComputeResourceSummary;
import com.vmware.vim25.DatastoreSummary;
import com.vmware.vim25.DynamicProperty;
import com.vmware.vim25.GuestInfo;
import com.vmware.vim25.HostCapability;
import com.vmware.vim25.HostFirewallInfo;
import com.vmware.vim25.HostFirewallRuleset;
@ -1326,6 +1327,12 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
throw new Exception(msg);
}
if(!isVMWareToolsInstalled(vmMo)){
String errMsg = "vmware tools is not installed or not running, cannot add nic to vm " + vmName;
s_logger.debug(errMsg);
return new PlugNicAnswer(cmd, false, "Unable to execute PlugNicCommand due to " + errMsg);
}
// TODO need a way to specify the control of NIC device type
VirtualEthernetCardType nicDeviceType = VirtualEthernetCardType.E1000;
@ -1400,6 +1407,12 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
throw new Exception(msg);
}
if(!isVMWareToolsInstalled(vmMo)){
String errMsg = "vmware tools not installed or not running, cannot remove nic from vm " + vmName;
s_logger.debug(errMsg);
return new UnPlugNicAnswer(cmd, false, "Unable to execute unPlugNicCommand due to " + errMsg);
}
VirtualDevice nic = findVirtualNicDevice(vmMo, cmd.getNic().getMac());
if ( nic == null ) {
return new UnPlugNicAnswer(cmd, true, "success");
@ -5237,4 +5250,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
// TODO Auto-generated method stub
}
private boolean isVMWareToolsInstalled(VirtualMachineMO vmMo) throws Exception{
GuestInfo guestInfo = vmMo.getVmGuestInfo();
return (guestInfo != null && guestInfo.getGuestState() != null && guestInfo.getGuestState().equalsIgnoreCase("running"));
}
}

View File

@ -89,6 +89,7 @@ public class ListCiscoAsa1000vResourcesCmd extends BaseListCmd {
if (ciscoAsa1000vDevices != null && !ciscoAsa1000vDevices.isEmpty()) {
for (CiscoAsa1000vDevice ciscoAsa1000vDeviceVO : ciscoAsa1000vDevices) {
CiscoAsa1000vResourceResponse ciscoAsa1000vResourceResponse = _ciscoAsa1000vService.createCiscoAsa1000vResourceResponse(ciscoAsa1000vDeviceVO);
ciscoAsa1000vResourceResponse.setObjectName("CiscoAsa1000vResource");
ciscoAsa1000vResourcesResponse.add(ciscoAsa1000vResourceResponse);
}
}

View File

@ -77,18 +77,19 @@ public class ListCiscoVnmcResourcesCmd extends BaseListCmd {
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try {
List<CiscoVnmcControllerVO> CiscoVnmcResources = _ciscoVnmcElementService.listCiscoVnmcResources(this);
List<CiscoVnmcControllerVO> ciscoVnmcResources = _ciscoVnmcElementService.listCiscoVnmcResources(this);
ListResponse<CiscoVnmcResourceResponse> response = new ListResponse<CiscoVnmcResourceResponse>();
List<CiscoVnmcResourceResponse> CiscoVnmcResourcesResponse = new ArrayList<CiscoVnmcResourceResponse>();
List<CiscoVnmcResourceResponse> ciscoVnmcResourcesResponse = new ArrayList<CiscoVnmcResourceResponse>();
if (CiscoVnmcResources != null && !CiscoVnmcResources.isEmpty()) {
for (CiscoVnmcController CiscoVnmcResourceVO : CiscoVnmcResources) {
CiscoVnmcResourceResponse CiscoVnmcResourceResponse = _ciscoVnmcElementService.createCiscoVnmcResourceResponse(CiscoVnmcResourceVO);
CiscoVnmcResourcesResponse.add(CiscoVnmcResourceResponse);
if (ciscoVnmcResources != null && !ciscoVnmcResources.isEmpty()) {
for (CiscoVnmcController ciscoVnmcResourceVO : ciscoVnmcResources) {
CiscoVnmcResourceResponse ciscoVnmcResourceResponse = _ciscoVnmcElementService.createCiscoVnmcResourceResponse(ciscoVnmcResourceVO);
ciscoVnmcResourceResponse.setObjectName("CiscoVnmcResource");
ciscoVnmcResourcesResponse.add(ciscoVnmcResourceResponse);
}
}
response.setResponses(CiscoVnmcResourcesResponse);
response.setResponses(ciscoVnmcResourcesResponse);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (InvalidParameterValueException invalidParamExcp) {

View File

@ -29,60 +29,69 @@ import com.google.gson.annotations.SerializedName;
@EntityReference(value = CiscoAsa1000vDevice.class)
public class CiscoAsa1000vResourceResponse extends BaseResponse {
public static final String RESOURCE_NAME = "resourcename";
@SerializedName(ApiConstants.RESOURCE_ID) @Parameter(description="resource id of the Cisco ASA 1000v appliance")
@SerializedName(ApiConstants.RESOURCE_ID)
@Parameter(description="resource id of the Cisco ASA 1000v appliance")
private String id;
@SerializedName(ApiConstants.PHYSICAL_NETWORK_ID)
@Parameter(description="the physical network to which this ASA 1000v belongs to", entityType = PhysicalNetworkResponse.class)
private Long physicalNetworkId ;
public Long getPhysicalNetworkId() {
return physicalNetworkId;
}
private Long physicalNetworkId;
@SerializedName(ApiConstants.HOST_NAME)
@Parameter(description="management ip address of ASA 1000v")
private String managementIp;
public String getManagementIp() {
return managementIp;
}
@SerializedName(ApiConstants.ASA_INSIDE_PORT_PROFILE)
@Parameter(description="management ip address of ASA 1000v")
@Parameter(description="port profile associated with inside interface of ASA 1000v")
private String inPortProfile;
public String getInPortProfile() {
return inPortProfile;
}
@SerializedName(ApiConstants.NETWORK_ID)
@Parameter(description="the guest network to which ASA 1000v is associated", entityType = NetworkResponse.class)
private Long guestNetworkId;
public Long getGuestNetworkId() {
return guestNetworkId;
public String getId() {
return id;
}
public void setId(String ciscoAsa1000vResourceId) {
this.id = ciscoAsa1000vResourceId;
}
public Long getPhysicalNetworkId() {
return physicalNetworkId;
}
public void setPhysicalNetworkId(Long physicalNetworkId) {
this.physicalNetworkId = physicalNetworkId;
}
public String getManagementIp() {
return managementIp;
}
public void setManagementIp(String managementIp) {
this.managementIp = managementIp;
}
public String getInPortProfile() {
return inPortProfile;
}
public void setInPortProfile(String inPortProfile) {
this.inPortProfile = inPortProfile;
}
public Long getGuestNetworkId() {
return guestNetworkId;
}
public void setGuestNetworkId(Long guestNetworkId) {
this.guestNetworkId = guestNetworkId;
}
@Override
public String getObjectId() {
return this.getId();
}
}

View File

@ -25,6 +25,7 @@ import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
import com.cloud.network.cisco.CiscoVnmcController;
import com.google.gson.annotations.SerializedName;
@EntityReference(value = CiscoVnmcController.class)
public class CiscoVnmcResourceResponse extends BaseResponse {
public static final String RESOURCE_NAME = "resourcename";
@ -33,43 +34,52 @@ public class CiscoVnmcResourceResponse extends BaseResponse {
@Parameter(description="resource id of the Cisco VNMC controller")
private String id;
@SerializedName(ApiConstants.PHYSICAL_NETWORK_ID)
@SerializedName(ApiConstants.PHYSICAL_NETWORK_ID)
@Parameter(description="the physical network to which this VNMC belongs to", entityType = PhysicalNetworkResponse.class)
private Long physicalNetworkId;
public Long getPhysicalNetworkId() {
return physicalNetworkId;
}
public String getProviderName() {
return providerName;
}
public String getResourceName() {
return resourceName;
}
@SerializedName(ApiConstants.PROVIDER) @Parameter(description="name of the provider")
@SerializedName(ApiConstants.PROVIDER)
@Parameter(description="name of the provider")
private String providerName;
@SerializedName(RESOURCE_NAME)
@SerializedName(RESOURCE_NAME)
@Parameter(description="Cisco VNMC resource name")
private String resourceName;
public String getId() {
return id;
}
public void setId(String ciscoVnmcResourceId) {
this.id = ciscoVnmcResourceId;
}
public Long getPhysicalNetworkId() {
return physicalNetworkId;
}
public void setPhysicalNetworkId(Long physicalNetworkId) {
this.physicalNetworkId = physicalNetworkId;
}
public String getProviderName() {
return providerName;
}
public void setProviderName(String providerName) {
this.providerName = providerName;
}
public String getResourceName() {
return resourceName;
}
public void setResourceName(String resourceName) {
this.resourceName = resourceName;
}
}
@Override
public String getObjectId() {
return this.getId();
}
}

View File

@ -35,6 +35,7 @@ import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.exception.UnsupportedServiceException;
import com.cloud.network.Network;
import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Provider;
@ -46,6 +47,7 @@ import com.cloud.network.PublicIpAddress;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.lb.ElasticLoadBalancerManager;
import com.cloud.network.lb.LoadBalancingRule;
import com.cloud.network.rules.LoadBalancerContainer;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.utils.component.AdapterBase;
@ -68,12 +70,25 @@ public class ElasticLoadBalancerElement extends AdapterBase implements LoadBalan
boolean _enabled;
TrafficType _frontEndTrafficType = TrafficType.Guest;
private boolean canHandle(Network network) {
private boolean canHandle(Network network, List<LoadBalancingRule> rules) {
if (network.getGuestType() != Network.GuestType.Shared|| network.getTrafficType() != TrafficType.Guest) {
s_logger.debug("Not handling network with type " + network.getGuestType() + " and traffic type " + network.getTrafficType());
return false;
}
Map<Capability, String> lbCaps = this.getCapabilities().get(Service.Lb);
if (!lbCaps.isEmpty()) {
String schemeCaps = lbCaps.get(Capability.LbSchemes);
if (schemeCaps != null) {
for (LoadBalancingRule rule : rules) {
if (!schemeCaps.contains(rule.getScheme().toString())) {
s_logger.debug("Scheme " + rules.get(0).getScheme() + " is not supported by the provider " + this.getName());
return false;
}
}
}
}
return true;
}
@ -94,6 +109,7 @@ public class ElasticLoadBalancerElement extends AdapterBase implements LoadBalan
lbCapabilities.put(Capability.SupportedLBAlgorithms, "roundrobin,leastconn,source");
lbCapabilities.put(Capability.SupportedLBIsolation, "shared");
lbCapabilities.put(Capability.SupportedProtocols, "tcp, udp");
lbCapabilities.put(Capability.LbSchemes, LoadBalancerContainer.Scheme.Public.toString());
capabilities.put(Service.Lb, lbCapabilities);
return capabilities;
@ -139,10 +155,10 @@ public class ElasticLoadBalancerElement extends AdapterBase implements LoadBalan
@Override
public boolean applyLBRules(Network network, List<LoadBalancingRule> rules) throws ResourceUnavailableException {
if (!canHandle(network)) {
if (!canHandle(network, rules)) {
return false;
}
return _lbMgr.applyLoadBalancerRules(network, rules);
}

View File

@ -19,11 +19,11 @@ package com.cloud.network.lb;
import java.util.List;
import org.apache.cloudstack.api.command.user.loadbalancer.CreateLoadBalancerRuleCmd;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.user.Account;
@ -32,7 +32,7 @@ public interface ElasticLoadBalancerManager {
public static final int DEFAULT_ELB_VM_CPU_MHZ = 256; // 500 MHz
public boolean applyLoadBalancerRules(Network network,
List<? extends FirewallRule> rules)
List<LoadBalancingRule> rules)
throws ResourceUnavailableException;
public LoadBalancer handleCreateLoadBalancerRule(CreateLoadBalancerRuleCmd lb, Account caller, long networkId) throws InsufficientAddressCapacityException, NetworkRuleConflictException;

View File

@ -102,7 +102,6 @@ import com.cloud.network.router.VirtualRouter.RedundantState;
import com.cloud.network.router.VirtualRouter.Role;
import com.cloud.network.router.VpcVirtualNetworkApplianceManager;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.FirewallRule.Purpose;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.ServiceOffering;
@ -118,7 +117,6 @@ import com.cloud.user.UserContext;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.component.Manager;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;
@ -126,6 +124,7 @@ import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.Ip;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
@ -297,8 +296,7 @@ ElasticLoadBalancerManager, VirtualMachineGuru<DomainRouterVO> {
String protocol = rule.getProtocol();
String algorithm = rule.getAlgorithm();
String elbIp = _networkModel.getIp(rule.getSourceIpAddressId()).getAddress()
.addr();
String elbIp = rule.getSourceIp().addr();
int srcPort = rule.getSourcePortStart();
String uuid = rule.getUuid();
List<LbDestination> destinations = rule.getDestinations();
@ -331,8 +329,10 @@ ElasticLoadBalancerManager, VirtualMachineGuru<DomainRouterVO> {
return sendCommandsToRouter(elbVm, cmds);
}
protected DomainRouterVO findElbVmForLb(FirewallRule lb) {//TODO: use a table to lookup
ElasticLbVmMapVO map = _elbVmMapDao.findOneByIp(lb.getSourceIpAddressId());
protected DomainRouterVO findElbVmForLb(LoadBalancingRule lb) {//TODO: use a table to lookup
Network ntwk = _networkModel.getNetwork(lb.getNetworkId());
long sourceIpId = _networkModel.getPublicIpAddress(lb.getSourceIp().addr(), ntwk.getDataCenterId()).getId();
ElasticLbVmMapVO map = _elbVmMapDao.findOneByIp(sourceIpId);
if (map == null) {
return null;
}
@ -342,15 +342,11 @@ ElasticLoadBalancerManager, VirtualMachineGuru<DomainRouterVO> {
@Override
public boolean applyLoadBalancerRules(Network network,
List<? extends FirewallRule> rules)
List<LoadBalancingRule> rules)
throws ResourceUnavailableException {
if (rules == null || rules.isEmpty()) {
return true;
}
if (rules.get(0).getPurpose() != Purpose.LoadBalancing) {
s_logger.warn("ELB: Not handling non-LB firewall rules");
return false;
}
DomainRouterVO elbVm = findElbVmForLb(rules.get(0));
@ -363,14 +359,16 @@ ElasticLoadBalancerManager, VirtualMachineGuru<DomainRouterVO> {
if (elbVm.getState() == State.Running) {
//resend all rules for the public ip
List<LoadBalancerVO> lbs = _lbDao.listByIpAddress(rules.get(0).getSourceIpAddressId());
long sourceIpId = _networkModel.getPublicIpAddress(rules.get(0).getSourceIp().addr(), network.getDataCenterId()).getId();
List<LoadBalancerVO> lbs = _lbDao.listByIpAddress(sourceIpId);
List<LoadBalancingRule> lbRules = new ArrayList<LoadBalancingRule>();
for (LoadBalancerVO lb : lbs) {
List<LbDestination> dstList = _lbMgr.getExistingDestinations(lb.getId());
List<LbStickinessPolicy> policyList = _lbMgr.getStickinessPolicies(lb.getId());
List<LbHealthCheckPolicy> hcPolicyList = _lbMgr.getHealthCheckPolicies(lb.getId());
Ip sourceIp = _networkModel.getPublicIpAddress(lb.getSourceIpAddressId()).getAddress();
LoadBalancingRule loadBalancing = new LoadBalancingRule(
lb, dstList, policyList, hcPolicyList);
lb, dstList, policyList, hcPolicyList, sourceIp);
lbRules.add(loadBalancing);
}
return applyLBRules(elbVm, lbRules, network.getId());
@ -656,7 +654,10 @@ ElasticLoadBalancerManager, VirtualMachineGuru<DomainRouterVO> {
LoadBalancer result = null;
try {
lb.setSourceIpAddressId(ipId);
result = _lbMgr.createLoadBalancer(lb, false);
result = _lbMgr.createPublicLoadBalancer(lb.getXid(), lb.getName(), lb.getDescription(),
lb.getSourcePortStart(), lb.getDefaultPortStart(), ipId.longValue(), lb.getProtocol(),
lb.getAlgorithm(), false, UserContext.current());
} catch (NetworkRuleConflictException e) {
s_logger.warn("Failed to create LB rule, not continuing with ELB deployment");
if (newIp) {
@ -943,7 +944,8 @@ ElasticLoadBalancerManager, VirtualMachineGuru<DomainRouterVO> {
List<LbDestination> dstList = _lbMgr.getExistingDestinations(lb.getId());
List<LbStickinessPolicy> policyList = _lbMgr.getStickinessPolicies(lb.getId());
List<LbHealthCheckPolicy> hcPolicyList = _lbMgr.getHealthCheckPolicies(lb.getId());
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList);
Ip sourceIp = _networkModel.getPublicIpAddress(lb.getSourceIpAddressId()).getAddress();
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList, sourceIp);
lbRules.add(loadBalancing);
}

View File

@ -16,9 +16,30 @@
// under the License.
package com.cloud.network.element;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.cloudstack.api.response.ExternalLoadBalancerResponse;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
import org.apache.log4j.Logger;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.commands.*;
import com.cloud.api.commands.AddExternalLoadBalancerCmd;
import com.cloud.api.commands.AddF5LoadBalancerCmd;
import com.cloud.api.commands.ConfigureF5LoadBalancerCmd;
import com.cloud.api.commands.DeleteExternalLoadBalancerCmd;
import com.cloud.api.commands.DeleteF5LoadBalancerCmd;
import com.cloud.api.commands.ListExternalLoadBalancersCmd;
import com.cloud.api.commands.ListF5LoadBalancerNetworksCmd;
import com.cloud.api.commands.ListF5LoadBalancersCmd;
import com.cloud.api.response.F5LoadBalancerResponse;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
@ -27,22 +48,41 @@ import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.*;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InsufficientNetworkCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.host.dao.HostDetailsDao;
import com.cloud.network.*;
import com.cloud.network.ExternalLoadBalancerDeviceManager;
import com.cloud.network.ExternalLoadBalancerDeviceManagerImpl;
import com.cloud.network.Network;
import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.NetworkModel;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.dao.*;
import com.cloud.network.PhysicalNetwork;
import com.cloud.network.PhysicalNetworkServiceProvider;
import com.cloud.network.PublicIpAddress;
import com.cloud.network.dao.ExternalLoadBalancerDeviceDao;
import com.cloud.network.dao.ExternalLoadBalancerDeviceVO;
import com.cloud.network.dao.ExternalLoadBalancerDeviceVO.LBDeviceState;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.NetworkExternalLoadBalancerDao;
import com.cloud.network.dao.NetworkExternalLoadBalancerVO;
import com.cloud.network.dao.NetworkServiceMapDao;
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.dao.PhysicalNetworkDao;
import com.cloud.network.dao.PhysicalNetworkVO;
import com.cloud.network.lb.LoadBalancingRule;
import com.cloud.network.resource.F5BigIpResource;
import com.cloud.network.rules.LbStickinessMethod;
import com.cloud.network.rules.LbStickinessMethod.StickinessMethodType;
import com.cloud.network.rules.LoadBalancerContainer;
import com.cloud.offering.NetworkOffering;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.exception.CloudRuntimeException;
@ -51,13 +91,6 @@ import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.google.gson.Gson;
import org.apache.cloudstack.api.response.ExternalLoadBalancerResponse;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
import org.apache.log4j.Logger;
import javax.ejb.Local;
import javax.inject.Inject;
import java.util.*;
@Local(value = {NetworkElement.class, LoadBalancingServiceProvider.class, IpDeployer.class})
public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceManagerImpl implements LoadBalancingServiceProvider, IpDeployer, F5ExternalLoadBalancerElementService, ExternalLoadBalancerDeviceManager {
@ -87,11 +120,25 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan
@Inject
ConfigurationDao _configDao;
private boolean canHandle(Network config) {
private boolean canHandle(Network config, List<LoadBalancingRule> rules) {
if ((config.getGuestType() != Network.GuestType.Isolated && config.getGuestType() != Network.GuestType.Shared) || config.getTrafficType() != TrafficType.Guest) {
s_logger.trace("Not handling network with Type " + config.getGuestType() + " and traffic type " + config.getTrafficType());
return false;
}
Map<Capability, String> lbCaps = this.getCapabilities().get(Service.Lb);
if (!lbCaps.isEmpty()) {
String schemeCaps = lbCaps.get(Capability.LbSchemes);
if (schemeCaps != null && rules != null && !rules.isEmpty()) {
for (LoadBalancingRule rule : rules) {
if (!schemeCaps.contains(rule.getScheme().toString())) {
s_logger.debug("Scheme " + rules.get(0).getScheme() + " is not supported by the provider " + this.getName());
return false;
}
}
}
}
return (_networkManager.isProviderForNetwork(getProvider(), config.getId()) && _ntwkSrvcDao.canProviderSupportServiceInNetwork(config.getId(), Service.Lb, Network.Provider.F5BigIp));
}
@ -100,7 +147,7 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan
public boolean implement(Network guestConfig, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException,
InsufficientNetworkCapacityException {
if (!canHandle(guestConfig)) {
if (!canHandle(guestConfig, null)) {
return false;
}
@ -124,7 +171,7 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan
@Override
public boolean shutdown(Network guestConfig, ReservationContext context, boolean cleanup) throws ResourceUnavailableException, ConcurrentOperationException {
if (!canHandle(guestConfig)) {
if (!canHandle(guestConfig, null)) {
return false;
}
@ -143,13 +190,16 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan
@Override
public boolean validateLBRule(Network network, LoadBalancingRule rule) {
String algo = rule.getAlgorithm();
return (algo.equals("roundrobin") || algo.equals("leastconn"));
if (canHandle(network, new ArrayList<LoadBalancingRule>(Arrays.asList(rule)))) {
String algo = rule.getAlgorithm();
return (algo.equals("roundrobin") || algo.equals("leastconn"));
}
return true;
}
@Override
public boolean applyLBRules(Network config, List<LoadBalancingRule> rules) throws ResourceUnavailableException {
if (!canHandle(config)) {
if (!canHandle(config, rules)) {
return false;
}
@ -180,6 +230,9 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan
// Support inline mode with firewall
lbCapabilities.put(Capability.InlineMode, "true");
//support only for public lb
lbCapabilities.put(Capability.LbSchemes, LoadBalancerContainer.Scheme.Public.toString());
LbStickinessMethod method;
List<LbStickinessMethod> methodList = new ArrayList<LbStickinessMethod>();

View File

@ -0,0 +1,50 @@
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-plugin-network-internallb</artifactId>
<name>Apache CloudStack Plugin - Network Internal Load Balancer</name>
<parent>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloudstack-plugins</artifactId>
<version>4.2.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<build>
<defaultGoal>install</defaultGoal>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<resources>
<resource>
<directory>resources</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>test/resources</directory>
<excludes>
<exclude>%regex[.*[0-9]*To[0-9]*.*Test.*]</exclude>
</excludes>
</testResource>
</testResources>
</build>
</project>

View File

@ -0,0 +1,548 @@
// 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.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.cloudstack.api.command.admin.internallb.ConfigureInternalLoadBalancerElementCmd;
import org.apache.cloudstack.api.command.admin.internallb.CreateInternalLoadBalancerElementCmd;
import org.apache.cloudstack.api.command.admin.internallb.ListInternalLoadBalancerElementsCmd;
import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao;
import org.apache.cloudstack.network.lb.InternalLoadBalancerVMManager;
import org.apache.log4j.Logger;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.NetworkModel;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetworkServiceProvider;
import com.cloud.network.PublicIpAddress;
import com.cloud.network.VirtualRouterProvider;
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
import com.cloud.network.dao.NetworkServiceMapDao;
import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
import com.cloud.network.dao.VirtualRouterProviderDao;
import com.cloud.network.element.IpDeployer;
import com.cloud.network.element.LoadBalancingServiceProvider;
import com.cloud.network.element.NetworkElement;
import com.cloud.network.element.VirtualRouterElement;
import com.cloud.network.element.VirtualRouterProviderVO;
import com.cloud.network.lb.LoadBalancingRule;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.router.VirtualRouter.Role;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.LoadBalancerContainer;
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.User;
import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.SearchCriteria2;
import com.cloud.utils.db.SearchCriteriaService;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.Ip;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.DomainRouterDao;
@Local(value = {NetworkElement.class})
public class InternalLoadBalancerElement extends AdapterBase implements LoadBalancingServiceProvider, InternalLoadBalancerElementService, IpDeployer{
private static final Logger s_logger = Logger.getLogger(InternalLoadBalancerElement.class);
protected static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
private static InternalLoadBalancerElement internalLbElement = null;
@Inject NetworkModel _ntwkModel;
@Inject NetworkServiceMapDao _ntwkSrvcDao;
@Inject DomainRouterDao _routerDao;
@Inject VirtualRouterProviderDao _vrProviderDao;
@Inject PhysicalNetworkServiceProviderDao _pNtwkSvcProviderDao;
@Inject InternalLoadBalancerVMManager _internalLbMgr;
@Inject ConfigurationManager _configMgr;
@Inject AccountManager _accountMgr;
@Inject ApplicationLoadBalancerRuleDao _appLbDao;
protected InternalLoadBalancerElement() {
}
public static InternalLoadBalancerElement getInstance() {
if ( internalLbElement == null) {
internalLbElement = new InternalLoadBalancerElement();
}
return internalLbElement;
}
private boolean canHandle(Network config, Scheme lbScheme) {
//works in Advance zone only
DataCenter dc = _configMgr.getZone(config.getDataCenterId());
if (dc.getNetworkType() != NetworkType.Advanced) {
s_logger.trace("Not hanling zone of network type " + dc.getNetworkType());
return false;
}
if (config.getGuestType() != Network.GuestType.Isolated || config.getTrafficType() != TrafficType.Guest) {
s_logger.trace("Not handling network with Type " + config.getGuestType() + " and traffic type " + config.getTrafficType());
return false;
}
Map<Capability, String> lbCaps = this.getCapabilities().get(Service.Lb);
if (!lbCaps.isEmpty()) {
String schemeCaps = lbCaps.get(Capability.LbSchemes);
if (schemeCaps != null && lbScheme != null) {
if (!schemeCaps.contains(lbScheme.toString())) {
s_logger.debug("Scheme " + lbScheme.toString() + " is not supported by the provider " + this.getName());
return false;
}
}
}
if (!_ntwkModel.isProviderSupportServiceInNetwork(config.getId(), Service.Lb, getProvider())) {
s_logger.trace("Element " + getProvider().getName() + " doesn't support service " + Service.Lb
+ " in the network " + config);
return false;
}
return true;
}
@Override
public Map<Service, Map<Capability, String>> getCapabilities() {
return capabilities;
}
@Override
public Provider getProvider() {
return Provider.InternalLbVm;
}
@Override
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context)
throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
if (!canHandle(network, null)) {
s_logger.trace("No need to implement " + this.getName());
return true;
}
//1) Get all the Ips from the network having LB rules assigned
List<String> ips = _appLbDao.listLbIpsBySourceIpNetworkIdAndScheme(network.getId(), Scheme.Internal);
//2) Start those vms
for (String ip : ips) {
Ip sourceIp = new Ip(ip);
List<? extends VirtualRouter> internalLbVms;
try {
internalLbVms = _internalLbMgr.deployInternalLbVm(network, sourceIp, dest, _accountMgr.getAccount(network.getAccountId()), null);
} catch (InsufficientCapacityException e) {
s_logger.warn("Failed to deploy element " + this.getName() + " for ip " + sourceIp + " due to:", e);
return false;
} catch (ConcurrentOperationException e) {
s_logger.warn("Failed to deploy element " + this.getName() + " for ip " + sourceIp + " due to:", e);
return false;
}
if (internalLbVms == null || internalLbVms.isEmpty()) {
throw new ResourceUnavailableException("Can't deploy " + this.getName() + " to handle LB rules",
DataCenter.class, network.getDataCenterId());
}
}
return true;
}
@Override
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException {
if (!canHandle(network, null)) {
s_logger.trace("No need to prepare " + this.getName());
return true;
}
if (vm.getType() == VirtualMachine.Type.User) {
//1) Get all the Ips from the network having LB rules assigned
List<String> ips = _appLbDao.listLbIpsBySourceIpNetworkIdAndScheme(network.getId(), Scheme.Internal);
//2) Start those vms
for (String ip : ips) {
Ip sourceIp = new Ip(ip);
List<? extends VirtualRouter> internalLbVms;
try {
internalLbVms = _internalLbMgr.deployInternalLbVm(network, sourceIp, dest, _accountMgr.getAccount(network.getAccountId()), null);
} catch (InsufficientCapacityException e) {
s_logger.warn("Failed to deploy element " + this.getName() + " for ip " + sourceIp + " due to:", e);
return false;
} catch (ConcurrentOperationException e) {
s_logger.warn("Failed to deploy element " + this.getName() + " for ip " + sourceIp + " due to:", e);
return false;
}
if (internalLbVms == null || internalLbVms.isEmpty()) {
throw new ResourceUnavailableException("Can't deploy " + this.getName() + " to handle LB rules",
DataCenter.class, network.getDataCenterId());
}
}
}
return true;
}
@Override
public boolean release(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
return true;
}
@Override
public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException {
List<? extends VirtualRouter> internalLbVms = _routerDao.listByNetworkAndRole(network.getId(), Role.INTERNAL_LB_VM);
if (internalLbVms == null || internalLbVms.isEmpty()) {
return true;
}
boolean result = true;
for (VirtualRouter internalLbVm : internalLbVms) {
result = result && _internalLbMgr.destroyInternalLbVm(internalLbVm.getId(),
context.getAccount(), context.getCaller().getId());
if (cleanup) {
if (!result) {
s_logger.warn("Failed to stop internal lb element " + internalLbVm + ", but would try to process clean up anyway.");
}
result = (_internalLbMgr.destroyInternalLbVm(internalLbVm.getId(),
context.getAccount(), context.getCaller().getId()));
if (!result) {
s_logger.warn("Failed to clean up internal lb element " + internalLbVm);
}
}
}
return result;
}
@Override
public boolean destroy(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
List<? extends VirtualRouter> internalLbVms = _routerDao.listByNetworkAndRole(network.getId(), Role.INTERNAL_LB_VM);
if (internalLbVms == null || internalLbVms.isEmpty()) {
return true;
}
boolean result = true;
for (VirtualRouter internalLbVm : internalLbVms) {
result = result && (_internalLbMgr.destroyInternalLbVm(internalLbVm.getId(),
context.getAccount(), context.getCaller().getId()));
}
return result;
}
@Override
public boolean isReady(PhysicalNetworkServiceProvider provider) {
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(),
VirtualRouterProviderType.InternalLbVm);
if (element == null) {
return false;
}
return element.isEnabled();
}
@Override
public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context)
throws ConcurrentOperationException, ResourceUnavailableException {
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(),
VirtualRouterProviderType.InternalLbVm);
if (element == null) {
return true;
}
long elementId = element.getId();
List<DomainRouterVO> internalLbVms = _routerDao.listByElementId(elementId);
boolean result = true;
for (DomainRouterVO internalLbVm : internalLbVms) {
result = result && (_internalLbMgr.destroyInternalLbVm(internalLbVm.getId(),
context.getAccount(), context.getCaller().getId()));
}
_vrProviderDao.remove(elementId);
return result;
}
@Override
public boolean canEnableIndividualServices() {
return true;
}
@Override
public boolean verifyServicesCombination(Set<Service> services) {
return true;
}
@Override
public IpDeployer getIpDeployer(Network network) {
return this;
}
@Override
public boolean applyLBRules(Network network, List<LoadBalancingRule> rules) throws ResourceUnavailableException {
//1) Get Internal LB VMs to destroy
Set<Ip> vmsToDestroy = getVmsToDestroy(rules);
//2) Get rules to apply
Map<Ip, List<LoadBalancingRule>> rulesToApply = getLbRulesToApply(rules);
s_logger.debug("Applying " + rulesToApply.size() + " on element " + this.getName());
for (Ip sourceIp : rulesToApply.keySet()) {
if (vmsToDestroy.contains(sourceIp)) {
//2.1 Destroy internal lb vm
List<? extends VirtualRouter> vms = _internalLbMgr.findInternalLbVms(network.getId(), sourceIp);
if (vms.size() > 0) {
//only one internal lb per IP exists
try {
s_logger.debug("Destroying internal lb vm for ip " + sourceIp.addr() + " as all the rules for this vm are in Revoke state");
return _internalLbMgr.destroyInternalLbVm(vms.get(0).getId(), _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM),
_accountMgr.getUserIncludingRemoved(User.UID_SYSTEM).getId());
} catch (ConcurrentOperationException e) {
s_logger.warn("Failed to apply lb rule(s) for ip " + sourceIp.addr() + " on the element " + this.getName() + " due to:", e);
return false;
}
}
} else {
//2.2 Start Internal LB vm per IP address
List<? extends VirtualRouter> internalLbVms;
try {
DeployDestination dest = new DeployDestination(_configMgr.getZone(network.getDataCenterId()), null, null, null);
internalLbVms = _internalLbMgr.deployInternalLbVm(network, sourceIp, dest, _accountMgr.getAccount(network.getAccountId()), null);
} catch (InsufficientCapacityException e) {
s_logger.warn("Failed to apply lb rule(s) for ip " + sourceIp.addr() + "on the element " + this.getName() + " due to:", e);
return false;
} catch (ConcurrentOperationException e) {
s_logger.warn("Failed to apply lb rule(s) for ip " + sourceIp.addr() + "on the element " + this.getName() + " due to:", e);
return false;
}
if (internalLbVms == null || internalLbVms.isEmpty()) {
throw new ResourceUnavailableException("Can't find/deploy internal lb vm to handle LB rules",
DataCenter.class, network.getDataCenterId());
}
//2.3 Apply Internal LB rules on the VM
if (!_internalLbMgr.applyLoadBalancingRules(network, rulesToApply.get(sourceIp), internalLbVms)) {
throw new CloudRuntimeException("Failed to apply load balancing rules for ip " + sourceIp.addr() +
" in network " + network.getId() + " on element " + this.getName());
}
}
}
return true;
}
protected Map<Ip, List<LoadBalancingRule>> getLbRulesToApply(List<LoadBalancingRule> rules) {
//Group rules by the source ip address as NetworkManager always passes the entire network lb config to the element
Map<Ip, List<LoadBalancingRule>> rulesToApply = groupBySourceIp(rules);
return rulesToApply;
}
protected Set<Ip> getVmsToDestroy(List<LoadBalancingRule> rules) {
//1) Group rules by the source ip address as NetworkManager always passes the entire network lb config to the element
Map<Ip, List<LoadBalancingRule>> groupedRules = groupBySourceIp(rules);
//2) Count rules in revoke state
Set<Ip> vmsToDestroy = new HashSet<Ip>();
for (Ip sourceIp : groupedRules.keySet()) {
List<LoadBalancingRule> rulesToCheck = groupedRules.get(sourceIp);
int revoke = 0;
for (LoadBalancingRule ruleToCheck : rulesToCheck) {
if (ruleToCheck.getState() == FirewallRule.State.Revoke){
revoke++;
}
}
if (revoke == rulesToCheck.size()) {
s_logger.debug("Have to destroy internal lb vm for source ip " + sourceIp);
vmsToDestroy.add(sourceIp);
}
}
return vmsToDestroy;
}
protected Map<Ip, List<LoadBalancingRule>> groupBySourceIp(List<LoadBalancingRule> rules) {
Map<Ip, List<LoadBalancingRule>> groupedRules = new HashMap<Ip, List<LoadBalancingRule>>();
for (LoadBalancingRule rule : rules) {
Ip sourceIp = rule.getSourceIp();
if (!groupedRules.containsKey(sourceIp)) {
groupedRules.put(sourceIp, null);
}
List<LoadBalancingRule> rulesToApply = groupedRules.get(sourceIp);
if (rulesToApply == null) {
rulesToApply = new ArrayList<LoadBalancingRule>();
}
rulesToApply.add(rule);
groupedRules.put(sourceIp, rulesToApply);
}
return groupedRules;
}
@Override
public boolean validateLBRule(Network network, LoadBalancingRule rule) {
List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
rules.add(rule);
if (canHandle(network, rule.getScheme())) {
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.INTERNAL_LB_VM);
if (routers == null || routers.isEmpty()) {
return true;
}
return VirtualRouterElement.validateHAProxyLBRule(rule);
}
return true;
}
@Override
public List<LoadBalancerTO> updateHealthChecks(Network network, List<LoadBalancingRule> lbrules) {
return null;
}
private static Map<Service, Map<Capability, String>> setCapabilities() {
Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
// Set capabilities for LB service
Map<Capability, String> lbCapabilities = new HashMap<Capability, String>();
lbCapabilities.put(Capability.SupportedLBAlgorithms, "roundrobin,leastconn,source");
lbCapabilities.put(Capability.SupportedLBIsolation, "dedicated");
lbCapabilities.put(Capability.SupportedProtocols, "tcp, udp");
lbCapabilities.put(Capability.SupportedStickinessMethods, VirtualRouterElement.getHAProxyStickinessCapability());
lbCapabilities.put(Capability.LbSchemes, LoadBalancerContainer.Scheme.Internal.toString());
capabilities.put(Service.Lb, lbCapabilities);
return capabilities;
}
@Override
public List<Class<?>> getCommands() {
List<Class<?>> cmdList = new ArrayList<Class<?>>();
cmdList.add(CreateInternalLoadBalancerElementCmd.class);
cmdList.add(ConfigureInternalLoadBalancerElementCmd.class);
cmdList.add(ListInternalLoadBalancerElementsCmd.class);
return cmdList;
}
@Override
public VirtualRouterProvider configureInternalLoadBalancerElement(long id, boolean enable) {
VirtualRouterProviderVO element = _vrProviderDao.findById(id);
if (element == null || element.getType() != VirtualRouterProviderType.InternalLbVm) {
throw new InvalidParameterValueException("Can't find " + this.getName() + " element with network service provider id " + id +
" to be used as a provider for " + this.getName());
}
element.setEnabled(enable);
element = _vrProviderDao.persist(element);
return element;
}
@Override
public VirtualRouterProvider addInternalLoadBalancerElement(long ntwkSvcProviderId) {
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(ntwkSvcProviderId, VirtualRouterProviderType.InternalLbVm);
if (element != null) {
s_logger.debug("There is already an " + this.getName() + " with service provider id " + ntwkSvcProviderId);
return null;
}
PhysicalNetworkServiceProvider provider = _pNtwkSvcProviderDao.findById(ntwkSvcProviderId);
if (provider == null || !provider.getProviderName().equalsIgnoreCase(this.getName())) {
throw new InvalidParameterValueException("Invalid network service provider is specified");
}
element = new VirtualRouterProviderVO(ntwkSvcProviderId, VirtualRouterProviderType.InternalLbVm);
element = _vrProviderDao.persist(element);
return element;
}
@Override
public VirtualRouterProvider getInternalLoadBalancerElement(long id) {
VirtualRouterProvider provider = _vrProviderDao.findById(id);
if (provider == null || provider.getType() != VirtualRouterProviderType.InternalLbVm) {
throw new InvalidParameterValueException("Unable to find " + this.getName() + " by id");
}
return provider;
}
@Override
public List<? extends VirtualRouterProvider> searchForInternalLoadBalancerElements(Long id, Long ntwkSvsProviderId, Boolean enabled) {
SearchCriteriaService<VirtualRouterProviderVO, VirtualRouterProviderVO> sc = SearchCriteria2.create(VirtualRouterProviderVO.class);
if (id != null) {
sc.addAnd(sc.getEntity().getId(), Op.EQ, id);
}
if (ntwkSvsProviderId != null) {
sc.addAnd(sc.getEntity().getNspId(), Op.EQ, ntwkSvsProviderId);
}
if (enabled != null) {
sc.addAnd(sc.getEntity().isEnabled(), Op.EQ, enabled);
}
//return only Internal LB elements
sc.addAnd(sc.getEntity().getType(), Op.EQ, VirtualRouterProvider.VirtualRouterProviderType.InternalLbVm);
return sc.list();
}
@Override
public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress, Set<Service> services) throws ResourceUnavailableException {
//do nothing here; this element just has to extend the ip deployer
//as the LB service implements IPDeployerRequester
return true;
}
}

View File

@ -0,0 +1,90 @@
// 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 java.util.Map;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.lb.LoadBalancingRule;
import com.cloud.network.router.VirtualRouter;
import com.cloud.user.Account;
import com.cloud.utils.component.Manager;
import com.cloud.utils.net.Ip;
import com.cloud.vm.VirtualMachineProfile.Param;
public interface InternalLoadBalancerVMManager extends Manager, InternalLoadBalancerVMService{
//RAM/CPU for the system offering used by Internal LB VMs
public static final int DEFAULT_INTERNALLB_VM_RAMSIZE = 128; // 128 MB
public static final int DEFAULT_INTERNALLB_VM_CPU_MHZ = 256; // 256 MHz
/**
* Destroys Internal LB vm instance
* @param vmId
* @param caller
* @param callerUserId
* @return
* @throws ResourceUnavailableException
* @throws ConcurrentOperationException
*/
boolean destroyInternalLbVm(long vmId, Account caller, Long callerUserId)
throws ResourceUnavailableException, ConcurrentOperationException;
/**
* Deploys internal lb vm
* @param guestNetwork
* @param requestedGuestIp
* @param dest
* @param owner
* @param params
* @return
* @throws InsufficientCapacityException
* @throws ConcurrentOperationException
* @throws ResourceUnavailableException
*/
List<? extends VirtualRouter> deployInternalLbVm(Network guestNetwork, Ip requestedGuestIp, DeployDestination dest, Account owner,
Map<Param, Object> params) throws InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException;
/**
*
* @param network
* @param rules
* @param internalLbVms
* @return
* @throws ResourceUnavailableException
*/
boolean applyLoadBalancingRules(Network network, List<LoadBalancingRule> rules, List<? extends VirtualRouter> internalLbVms)
throws ResourceUnavailableException;
/**
* Returns existing Internal Load Balancer elements based on guestNetworkId (required) and requestedIp (optional)
* @param guestNetworkId
* @param requestedGuestIp
* @return
*/
List<? extends VirtualRouter> findInternalLbVms(long guestNetworkId, Ip requestedGuestIp);
}

View File

@ -0,0 +1,951 @@
// 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.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.agent.AgentManager;
import com.cloud.agent.AgentManager.OnError;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.GetDomRVersionAnswer;
import com.cloud.agent.api.GetDomRVersionCmd;
import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.check.CheckSshAnswer;
import com.cloud.agent.api.check.CheckSshCommand;
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
import com.cloud.agent.api.routing.NetworkElementCommand;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.manager.Commands;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.deploy.DataCenterDeployment;
import com.cloud.deploy.DeployDestination;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InsufficientServerCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.exception.StorageUnavailableException;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.Network;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkModel;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetworkServiceProvider;
import com.cloud.network.VirtualRouterProvider;
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
import com.cloud.network.dao.VirtualRouterProviderDao;
import com.cloud.network.lb.LoadBalancingRule;
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy;
import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
import com.cloud.network.lb.LoadBalancingRulesManager;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.router.VirtualRouter.RedundantState;
import com.cloud.network.router.VirtualRouter.Role;
import com.cloud.network.rules.FirewallRule;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.ServiceOffering;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.resource.ResourceManager;
import com.cloud.server.ConfigurationServer;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.User;
import com.cloud.utils.Pair;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.db.DB;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.Ip;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.Nic;
import com.cloud.vm.NicProfile;
import com.cloud.vm.NicVO;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.VirtualMachineGuru;
import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.VirtualMachineName;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachineProfile.Param;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.NicDao;
@Component
@Local(value = { InternalLoadBalancerVMManager.class, InternalLoadBalancerVMService.class})
public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
private static final Logger s_logger = Logger
.getLogger(InternalLoadBalancerVMManagerImpl.class);
static final private String _internalLbVmNamePrefix = "b";
private String _instance;
private String _mgmtHost;
private String _mgmtCidr;
private long _internalLbVmOfferingId;
@Inject VirtualMachineManager _itMgr;
@Inject DomainRouterDao _internalLbVmDao;
@Inject ConfigurationDao _configDao;
@Inject AgentManager _agentMgr;
@Inject DataCenterDao _dcDao;
@Inject VirtualRouterProviderDao _vrProviderDao;
@Inject ApplicationLoadBalancerRuleDao _lbDao;
@Inject NetworkModel _ntwkModel;
@Inject LoadBalancingRulesManager _lbMgr;
@Inject NicDao _nicDao;
@Inject AccountManager _accountMgr;
@Inject NetworkDao _networkDao;
@Inject NetworkManager _ntwkMgr;
@Inject ServiceOfferingDao _serviceOfferingDao;
@Inject PhysicalNetworkServiceProviderDao _physicalProviderDao;
@Inject NetworkOfferingDao _networkOfferingDao;
@Inject VMTemplateDao _templateDao;
@Inject ResourceManager _resourceMgr;
@Inject ConfigurationServer _configServer;
@Override
public DomainRouterVO findByName(String name) {
if (!VirtualMachineName.isValidSystemVmName(name, _instance, _internalLbVmNamePrefix)) {
return null;
}
return _internalLbVmDao.findById(VirtualMachineName.getRouterId(name));
}
@Override
public DomainRouterVO findById(long id) {
return _internalLbVmDao.findById(id);
}
@Override
public DomainRouterVO persist(DomainRouterVO vm) {
DomainRouterVO virtualRouter = _internalLbVmDao.persist(vm);
return virtualRouter;
}
@Override
public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<DomainRouterVO> profile,
DeployDestination dest, ReservationContext context) {
//Internal LB vm starts up with 2 Nics
//Nic #1 - Guest Nic with IP address that would act as the LB entry point
//Nic #2 - Control/Management Nic
StringBuilder buf = profile.getBootArgsBuilder();
buf.append(" template=domP");
buf.append(" name=").append(profile.getHostName());
if (Boolean.valueOf(_configDao.getValue("system.vm.random.password"))) {
buf.append(" vmpassword=").append(_configDao.getValue("system.vm.password"));
}
NicProfile controlNic = null;
Network guestNetwork = null;
for (NicProfile nic : profile.getNics()) {
int deviceId = nic.getDeviceId();
buf.append(" eth").append(deviceId).append("ip=").append(nic.getIp4Address());
buf.append(" eth").append(deviceId).append("mask=").append(nic.getNetmask());
if (nic.isDefaultNic()) {
buf.append(" gateway=").append(nic.getGateway());
buf.append(" dns1=").append(nic.getGateway());
}
if (nic.getTrafficType() == TrafficType.Guest) {
guestNetwork = _ntwkModel.getNetwork(nic.getNetworkId());
} else if (nic.getTrafficType() == TrafficType.Management) {
buf.append(" localgw=").append(dest.getPod().getGateway());
} else if (nic.getTrafficType() == TrafficType.Control) {
controlNic = nic;
// Internal LB control command is sent over management server in VMware
if (dest.getHost().getHypervisorType() == HypervisorType.VMware) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Check if we need to add management server explicit route to Internal LB. pod cidr: "
+ dest.getPod().getCidrAddress() + "/" + dest.getPod().getCidrSize()
+ ", pod gateway: " + dest.getPod().getGateway() + ", management host: " + _mgmtHost);
}
if (s_logger.isInfoEnabled()) {
s_logger.info("Add management server explicit route to Internal LB.");
}
buf.append(" mgmtcidr=").append(_mgmtCidr);
buf.append(" localgw=").append(dest.getPod().getGateway());
}
}
}
if (controlNic == null) {
throw new CloudRuntimeException("Didn't start a control port");
}
if (guestNetwork != null) {
String domain = guestNetwork.getNetworkDomain();
if (domain != null) {
buf.append(" domain=" + domain);
}
}
String type = "ilbvm";
buf.append(" type=" + type);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Boot Args for " + profile + ": " + buf.toString());
}
return true;
}
@Override
public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile<DomainRouterVO> profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException {
DomainRouterVO internalLbVm = profile.getVirtualMachine();
List<NicProfile> nics = profile.getNics();
for (NicProfile nic : nics) {
if (nic.getTrafficType() == TrafficType.Control) {
internalLbVm.setPrivateIpAddress(nic.getIp4Address());
internalLbVm.setPrivateMacAddress(nic.getMacAddress());
}
}
_internalLbVmDao.update(internalLbVm.getId(), internalLbVm);
finalizeCommandsOnStart(cmds, profile);
return true;
}
@Override
public boolean finalizeStart(VirtualMachineProfile<DomainRouterVO> profile, long hostId, Commands cmds, ReservationContext context) {
DomainRouterVO internalLbVm = profile.getVirtualMachine();
boolean result = true;
Answer answer = cmds.getAnswer("checkSsh");
if (answer != null && answer instanceof CheckSshAnswer) {
CheckSshAnswer sshAnswer = (CheckSshAnswer) answer;
if (sshAnswer == null || !sshAnswer.getResult()) {
s_logger.warn("Unable to ssh to the internal LB VM: " + sshAnswer.getDetails());
result = false;
}
} else {
result = false;
}
if (result == false) {
return result;
}
//Get guest network info
List<Network> guestNetworks = new ArrayList<Network>();
List<? extends Nic> internalLbVmNics = _nicDao.listByVmId(profile.getId());
for (Nic internalLbVmNic : internalLbVmNics) {
Network network = _ntwkModel.getNetwork(internalLbVmNic.getNetworkId());
if (network.getTrafficType() == TrafficType.Guest) {
guestNetworks.add(network);
}
}
answer = cmds.getAnswer("getDomRVersion");
if (answer != null && answer instanceof GetDomRVersionAnswer) {
GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer)answer;
if (answer == null || !answer.getResult()) {
s_logger.warn("Unable to get the template/scripts version of internal LB VM " + internalLbVm.getInstanceName() +
" due to: " + versionAnswer.getDetails());
result = false;
} else {
internalLbVm.setTemplateVersion(versionAnswer.getTemplateVersion());
internalLbVm.setScriptsVersion(versionAnswer.getScriptsVersion());
internalLbVm = _internalLbVmDao.persist(internalLbVm, guestNetworks);
}
} else {
result = false;
}
return result;
}
@Override
public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile<DomainRouterVO> profile) {
DomainRouterVO internalLbVm = profile.getVirtualMachine();
NicProfile controlNic = getNicProfileByTrafficType(profile, TrafficType.Control);
if (controlNic == null) {
s_logger.error("Control network doesn't exist for the internal LB vm " + internalLbVm);
return false;
}
finalizeSshAndVersionOnStart(cmds, profile, internalLbVm, controlNic);
// restart network if restartNetwork = false is not specified in profile parameters
boolean reprogramGuestNtwk = true;
if (profile.getParameter(Param.ReProgramGuestNetworks) != null
&& (Boolean) profile.getParameter(Param.ReProgramGuestNetworks) == false) {
reprogramGuestNtwk = false;
}
VirtualRouterProvider lbProvider = _vrProviderDao.findById(internalLbVm.getElementId());
if (lbProvider == null) {
throw new CloudRuntimeException("Cannot find related element " + VirtualRouterProviderType.InternalLbVm + " of vm: " + internalLbVm.getHostName());
}
Provider provider = Network.Provider.getProvider(lbProvider.getType().toString());
if (provider == null) {
throw new CloudRuntimeException("Cannot find related provider of provider: " + lbProvider.getType().toString());
}
if (reprogramGuestNtwk) {
NicProfile guestNic = getNicProfileByTrafficType(profile, TrafficType.Guest);
finalizeLbRulesForIp(cmds, internalLbVm, provider, new Ip(guestNic.getIp4Address()), guestNic.getNetworkId());
}
return true;
}
@Override
public void finalizeStop(VirtualMachineProfile<DomainRouterVO> profile, StopAnswer answer) {
}
@Override
public void finalizeExpunge(DomainRouterVO vm) {
}
@Override
public Long convertToId(String vmName) {
if (!VirtualMachineName.isValidSystemVmName(vmName, _instance, _internalLbVmNamePrefix)) {
return null;
}
return VirtualMachineName.getRouterId(vmName);
}
@Override
public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
//not supported
throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType());
}
@Override
public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException {
//not supported
throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType());
}
@Override
public void prepareStop(VirtualMachineProfile<DomainRouterVO> profile) {
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params);
_instance = configs.get("instance.name");
if (_instance == null) {
_instance = "DEFAULT";
}
_mgmtHost = configs.get("host");
_mgmtCidr = _configDao.getValue(Config.ManagementNetwork.key());
String offIdStr = configs.get(Config.InternalLbVmServiceOfferingId.key());
if (offIdStr != null && !offIdStr.isEmpty()) {
_internalLbVmOfferingId = Long.parseLong(offIdStr);
} else {
boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key()));
ServiceOfferingVO newOff = new ServiceOfferingVO("System Offering For Internal LB VM", 1, InternalLoadBalancerVMManager.DEFAULT_INTERNALLB_VM_RAMSIZE, InternalLoadBalancerVMManager.DEFAULT_INTERNALLB_VM_CPU_MHZ, null,
null, true, null, useLocalStorage, true, null, true, VirtualMachine.Type.InternalLoadBalancerVm, true);
newOff.setUniqueName(ServiceOffering.internalLbVmDefaultOffUniqueName);
newOff = _serviceOfferingDao.persistSystemServiceOffering(newOff);
_internalLbVmOfferingId = newOff.getId();
}
_itMgr.registerGuru(VirtualMachine.Type.InternalLoadBalancerVm, this);
if (s_logger.isInfoEnabled()) {
s_logger.info(getName() + " has been configured");
}
return true;
}
@Override
public String getName() {
return _name;
}
protected NicProfile getNicProfileByTrafficType(VirtualMachineProfile<DomainRouterVO> profile, TrafficType trafficType) {
for (NicProfile nic : profile.getNics()) {
if (nic.getTrafficType() == trafficType && nic.getIp4Address() != null) {
return nic;
}
}
return null;
}
protected void finalizeSshAndVersionOnStart(Commands cmds, VirtualMachineProfile<DomainRouterVO> profile, DomainRouterVO router, NicProfile controlNic) {
cmds.addCommand("checkSsh", new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922));
// Update internal lb vm template/scripts version
final GetDomRVersionCmd command = new GetDomRVersionCmd();
command.setAccessDetail(NetworkElementCommand.ROUTER_IP, controlNic.getIp4Address());
command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
cmds.addCommand("getDomRVersion", command);
}
protected void finalizeLbRulesForIp(Commands cmds, DomainRouterVO internalLbVm, Provider provider, Ip sourceIp, long guestNtwkId) {
s_logger.debug("Resending load balancing rules as a part of start for " + internalLbVm);
List<ApplicationLoadBalancerRuleVO> lbs = _lbDao.listBySrcIpSrcNtwkId(sourceIp, guestNtwkId);
List<LoadBalancingRule> lbRules = new ArrayList<LoadBalancingRule>();
if (_ntwkModel.isProviderSupportServiceInNetwork(guestNtwkId, Service.Lb, provider)) {
// Re-apply load balancing rules
for (ApplicationLoadBalancerRuleVO lb : lbs) {
List<LbDestination> dstList = _lbMgr.getExistingDestinations(lb.getId());
List<LbStickinessPolicy> policyList = _lbMgr.getStickinessPolicies(lb.getId());
List<LbHealthCheckPolicy> hcPolicyList = _lbMgr.getHealthCheckPolicies(lb.getId());
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList, sourceIp);
lbRules.add(loadBalancing);
}
}
s_logger.debug("Found " + lbRules.size() + " load balancing rule(s) to apply as a part of Intenrnal LB vm" + internalLbVm + " start.");
if (!lbRules.isEmpty()) {
createApplyLoadBalancingRulesCommands(lbRules, internalLbVm, cmds, guestNtwkId);
}
}
private void createApplyLoadBalancingRulesCommands(List<LoadBalancingRule> rules, VirtualRouter internalLbVm, Commands cmds, long guestNetworkId) {
LoadBalancerTO[] lbs = new LoadBalancerTO[rules.size()];
int i = 0;
boolean inline = false;
for (LoadBalancingRule rule : rules) {
boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke));
String protocol = rule.getProtocol();
String algorithm = rule.getAlgorithm();
String uuid = rule.getUuid();
String srcIp = rule.getSourceIp().addr();
int srcPort = rule.getSourcePortStart();
List<LbDestination> destinations = rule.getDestinations();
List<LbStickinessPolicy> stickinessPolicies = rule.getStickinessPolicies();
LoadBalancerTO lb = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked, false, inline, destinations, stickinessPolicies);
lbs[i++] = lb;
}
Network guestNetwork = _ntwkModel.getNetwork(guestNetworkId);
Nic guestNic = _nicDao.findByNtwkIdAndInstanceId(guestNetwork.getId(), internalLbVm.getId());
NicProfile guestNicProfile = new NicProfile(guestNic, guestNetwork, guestNic.getBroadcastUri(), guestNic.getIsolationUri(),
_ntwkModel.getNetworkRate(guestNetwork.getId(), internalLbVm.getId()),
_ntwkModel.isSecurityGroupSupportedInNetwork(guestNetwork),
_ntwkModel.getNetworkTag(internalLbVm.getHypervisorType(), guestNetwork));
LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs, guestNic.getIp4Address(),
guestNic.getIp4Address(), internalLbVm.getPrivateIpAddress(),
_itMgr.toNicTO(guestNicProfile, internalLbVm.getHypervisorType()), internalLbVm.getVpcId());
cmd.lbStatsVisibility = _configDao.getValue(Config.NetworkLBHaproxyStatsVisbility.key());
cmd.lbStatsUri = _configDao.getValue(Config.NetworkLBHaproxyStatsUri.key());
cmd.lbStatsAuth = _configDao.getValue(Config.NetworkLBHaproxyStatsAuth.key());
cmd.lbStatsPort = _configDao.getValue(Config.NetworkLBHaproxyStatsPort.key());
cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getInternalLbControlIp(internalLbVm.getId()));
cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, guestNic.getIp4Address());
cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, internalLbVm.getInstanceName());
DataCenterVO dcVo = _dcDao.findById(internalLbVm.getDataCenterId());
cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
cmds.addCommand(cmd);
}
protected String getInternalLbControlIp(long internalLbVmId) {
String controlIpAddress = null;
List<NicVO> nics = _nicDao.listByVmId(internalLbVmId);
for (NicVO nic : nics) {
Network ntwk = _ntwkModel.getNetwork(nic.getNetworkId());
if (ntwk.getTrafficType() == TrafficType.Control) {
controlIpAddress = nic.getIp4Address();
}
}
if(controlIpAddress == null) {
s_logger.warn("Unable to find Internal LB control ip in its attached NICs!. Internal LB vm: " + internalLbVmId);
DomainRouterVO internalLbVm = _internalLbVmDao.findById(internalLbVmId);
return internalLbVm.getPrivateIpAddress();
}
return controlIpAddress;
}
@Override
public boolean destroyInternalLbVm(long vmId, Account caller, Long callerUserId)
throws ResourceUnavailableException, ConcurrentOperationException {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Attempting to destroy Internal LB vm " + vmId);
}
DomainRouterVO internalLbVm = _internalLbVmDao.findById(vmId);
if (internalLbVm == null) {
return true;
}
_accountMgr.checkAccess(caller, null, true, internalLbVm);
return _itMgr.expunge(internalLbVm, _accountMgr.getActiveUser(callerUserId), caller);
}
@Override
public VirtualRouter stopInternalLbVm(long vmId, boolean forced, Account caller, long callerUserId) throws ConcurrentOperationException,
ResourceUnavailableException {
DomainRouterVO internalLbVm = _internalLbVmDao.findById(vmId);
if (internalLbVm == null || internalLbVm.getRole() != Role.INTERNAL_LB_VM) {
throw new InvalidParameterValueException("Can't find internal lb vm by id specified");
}
return stopInternalLbVm(internalLbVm, forced, caller, callerUserId);
}
protected VirtualRouter stopInternalLbVm(DomainRouterVO internalLbVm, boolean forced, Account caller, long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException {
s_logger.debug("Stopping internal lb vm " + internalLbVm);
try {
if (_itMgr.advanceStop((DomainRouterVO) internalLbVm, forced, _accountMgr.getActiveUser(callerUserId), caller)) {
return _internalLbVmDao.findById(internalLbVm.getId());
} else {
return null;
}
} catch (OperationTimedoutException e) {
throw new CloudRuntimeException("Unable to stop " + internalLbVm, e);
}
}
@Override
public List<DomainRouterVO> deployInternalLbVm(Network guestNetwork, Ip requestedGuestIp, DeployDestination dest,
Account owner, Map<Param, Object> params) throws InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException {
List<DomainRouterVO> internalLbVms = findOrDeployInternalLbVm(guestNetwork, requestedGuestIp, dest, owner, params);
return startInternalLbVms(params, internalLbVms);
}
protected List<DomainRouterVO> startInternalLbVms(Map<Param, Object> params, List<DomainRouterVO> internalLbVms)
throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
List<DomainRouterVO> runningInternalLbVms = null;
if (internalLbVms != null) {
runningInternalLbVms = new ArrayList<DomainRouterVO>();
} else {
s_logger.debug("Have no internal lb vms to start");
return null;
}
for (DomainRouterVO internalLbVm : internalLbVms) {
if (internalLbVm.getState() != VirtualMachine.State.Running) {
internalLbVm = startInternalLbVm(internalLbVm, _accountMgr.getSystemAccount(), User.UID_SYSTEM, params);
}
if (internalLbVm != null) {
runningInternalLbVms.add(internalLbVm);
}
}
return runningInternalLbVms;
}
@DB
protected List<DomainRouterVO> findOrDeployInternalLbVm(Network guestNetwork, Ip requestedGuestIp, DeployDestination dest,
Account owner, Map<Param, Object> params) throws ConcurrentOperationException,
InsufficientCapacityException, ResourceUnavailableException {
List<DomainRouterVO> internalLbVms = new ArrayList<DomainRouterVO>();
Network lock = _networkDao.acquireInLockTable(guestNetwork.getId(), _ntwkMgr.getNetworkLockTimeout());
if (lock == null) {
throw new ConcurrentOperationException("Unable to lock network " + guestNetwork.getId());
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Lock is acquired for network id " + lock.getId() + " as a part of internal lb startup in " + dest);
}
long internalLbProviderId = getInternalLbProviderId(guestNetwork);
try {
assert guestNetwork.getState() == Network.State.Implemented || guestNetwork.getState() == Network.State.Setup ||
guestNetwork.getState() == Network.State.Implementing : "Network is not yet fully implemented: "
+ guestNetwork;
assert guestNetwork.getTrafficType() == TrafficType.Guest;
//deploy internal lb vm
Pair<DeploymentPlan, List<DomainRouterVO>> planAndInternalLbVms = getDeploymentPlanAndInternalLbVms(dest, guestNetwork.getId(), requestedGuestIp);
internalLbVms = planAndInternalLbVms.second();
DeploymentPlan plan = planAndInternalLbVms.first();
if (internalLbVms.size() > 0) {
s_logger.debug("Found " + internalLbVms.size() + " internal lb vms for the requested IP " + requestedGuestIp.addr());
return internalLbVms;
}
List<Pair<NetworkVO, NicProfile>> networks = createInternalLbVmNetworks(guestNetwork, plan, requestedGuestIp);
//Pass startVm=false as we are holding the network lock that needs to be released at the end of vm allocation
DomainRouterVO internalLbVm = deployInternalLbVm(owner, dest, plan, params, internalLbProviderId, _internalLbVmOfferingId, guestNetwork.getVpcId(),
networks, false);
if (internalLbVm != null) {
_internalLbVmDao.addRouterToGuestNetwork(internalLbVm, guestNetwork);
internalLbVms.add(internalLbVm);
}
} finally {
if (lock != null) {
_networkDao.releaseFromLockTable(lock.getId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Lock is released for network id " + lock.getId() + " as a part of internal lb vm startup in " + dest);
}
}
}
return internalLbVms;
}
protected long getInternalLbProviderId(Network guestNetwork) {
VirtualRouterProviderType type = VirtualRouterProviderType.InternalLbVm;
long physicalNetworkId = _ntwkModel.getPhysicalNetworkId(guestNetwork);
PhysicalNetworkServiceProvider provider = _physicalProviderDao.findByServiceProvider(physicalNetworkId, type.toString());
if (provider == null) {
throw new CloudRuntimeException("Cannot find service provider " + type.toString() + " in physical network " + physicalNetworkId);
}
VirtualRouterProvider internalLbProvider = _vrProviderDao.findByNspIdAndType(provider.getId(), type);
if (internalLbProvider == null) {
throw new CloudRuntimeException("Cannot find provider " + type.toString() + " as service provider " + provider.getId());
}
return internalLbProvider.getId();
}
protected List<Pair<NetworkVO, NicProfile>> createInternalLbVmNetworks(Network guestNetwork, DeploymentPlan plan, Ip guestIp) throws ConcurrentOperationException,
InsufficientAddressCapacityException {
//Form networks
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(3);
//1) Guest network - default
if (guestNetwork != null) {
s_logger.debug("Adding nic for Internal LB in Guest network " + guestNetwork);
NicProfile guestNic = new NicProfile();
if (guestIp != null) {
guestNic.setIp4Address(guestIp.addr());
} else {
guestNic.setIp4Address(_ntwkMgr.acquireGuestIpAddress(guestNetwork, null));
}
guestNic.setGateway(guestNetwork.getGateway());
guestNic.setBroadcastUri(guestNetwork.getBroadcastUri());
guestNic.setBroadcastType(guestNetwork.getBroadcastDomainType());
guestNic.setIsolationUri(guestNetwork.getBroadcastUri());
guestNic.setMode(guestNetwork.getMode());
String gatewayCidr = guestNetwork.getCidr();
guestNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr));
guestNic.setDefaultNic(true);
networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) guestNetwork, guestNic));
}
//2) Control network
s_logger.debug("Adding nic for Internal LB vm in Control network ");
List<? extends NetworkOffering> offerings = _ntwkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
NetworkOffering controlOffering = offerings.get(0);
NetworkVO controlConfig = _ntwkMgr.setupNetwork(_accountMgr.getSystemAccount(), controlOffering, plan, null, null, false).get(0);
networks.add(new Pair<NetworkVO, NicProfile>(controlConfig, null));
return networks;
}
protected Pair<DeploymentPlan, List<DomainRouterVO>> getDeploymentPlanAndInternalLbVms(DeployDestination dest, long guestNetworkId, Ip requestedGuestIp) {
long dcId = dest.getDataCenter().getId();
DeploymentPlan plan = new DataCenterDeployment(dcId);
List<DomainRouterVO> internalLbVms = findInternalLbVms(guestNetworkId, requestedGuestIp);
return new Pair<DeploymentPlan, List<DomainRouterVO>>(plan, internalLbVms);
}
@Override
public List<DomainRouterVO> findInternalLbVms(long guestNetworkId, Ip requestedGuestIp) {
List<DomainRouterVO> internalLbVms = _internalLbVmDao.listByNetworkAndRole(guestNetworkId, Role.INTERNAL_LB_VM);
if (requestedGuestIp != null && !internalLbVms.isEmpty()) {
Iterator<DomainRouterVO> it = internalLbVms.iterator();
while (it.hasNext()) {
DomainRouterVO vm = it.next();
Nic nic = _nicDao.findByNtwkIdAndInstanceId(guestNetworkId, vm.getId());
if (!nic.getIp4Address().equalsIgnoreCase(requestedGuestIp.addr())) {
it.remove();
}
}
}
return internalLbVms;
}
protected DomainRouterVO deployInternalLbVm(Account owner, DeployDestination dest, DeploymentPlan plan, Map<Param, Object> params,
long internalLbProviderId, long svcOffId, Long vpcId,
List<Pair<NetworkVO, NicProfile>> networks, boolean startVm) throws ConcurrentOperationException,
InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException,
StorageUnavailableException, ResourceUnavailableException {
long id = _internalLbVmDao.getNextInSequence(Long.class, "id");
if (s_logger.isDebugEnabled()) {
s_logger.debug("Creating the internal lb vm " + id + " in datacenter " + dest.getDataCenter());
}
ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(svcOffId);
// Internal lb is the network element, we don't know the hypervisor type yet.
// Try to allocate the internal lb twice using diff hypervisors, and when failed both times, throw the exception up
List<HypervisorType> hypervisors = getHypervisors(dest, plan, null);
int allocateRetry = 0;
int startRetry = 0;
DomainRouterVO internalLbVm = null;
for (Iterator<HypervisorType> iter = hypervisors.iterator(); iter.hasNext();) {
HypervisorType hType = iter.next();
try {
s_logger.debug("Allocating the Internal lb with the hypervisor type " + hType);
String templateName = null;
switch (hType) {
case XenServer:
templateName = _configServer.getConfigValue(Config.RouterTemplateXen.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
break;
case KVM:
templateName = _configServer.getConfigValue(Config.RouterTemplateKVM.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
break;
case VMware:
templateName = _configServer.getConfigValue(Config.RouterTemplateVmware.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
break;
case Hyperv:
templateName = _configServer.getConfigValue(Config.RouterTemplateHyperv.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
break;
case LXC:
templateName = _configServer.getConfigValue(Config.RouterTemplateLXC.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId());
break;
default: break;
}
VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName);
if (template == null) {
s_logger.debug(hType + " won't support system vm, skip it");
continue;
}
internalLbVm = new DomainRouterVO(id, routerOffering.getId(), internalLbProviderId,
VirtualMachineName.getSystemVmName(id, _instance, _internalLbVmNamePrefix), template.getId(), template.getHypervisorType(),
template.getGuestOSId(), owner.getDomainId(), owner.getId(), false, 0, false,
RedundantState.UNKNOWN, false, false, VirtualMachine.Type.InternalLoadBalancerVm, vpcId);
internalLbVm.setRole(Role.INTERNAL_LB_VM);
internalLbVm = _itMgr.allocate(internalLbVm, template, routerOffering, networks, plan, null, owner);
} catch (InsufficientCapacityException ex) {
if (allocateRetry < 2 && iter.hasNext()) {
s_logger.debug("Failed to allocate the Internal lb vm with hypervisor type " + hType + ", retrying one more time");
continue;
} else {
throw ex;
}
} finally {
allocateRetry++;
}
if (startVm) {
try {
internalLbVm = startInternalLbVm(internalLbVm, _accountMgr.getSystemAccount(), User.UID_SYSTEM, params);
break;
} catch (InsufficientCapacityException ex) {
if (startRetry < 2 && iter.hasNext()) {
s_logger.debug("Failed to start the Internal lb vm " + internalLbVm + " with hypervisor type " + hType + ", " +
"destroying it and recreating one more time");
// destroy the internal lb vm
destroyInternalLbVm(internalLbVm.getId(), _accountMgr.getSystemAccount(), User.UID_SYSTEM);
continue;
} else {
throw ex;
}
} finally {
startRetry++;
}
} else {
//return stopped internal lb vm
return internalLbVm;
}
}
return internalLbVm;
}
protected DomainRouterVO startInternalLbVm(DomainRouterVO internalLbVm, Account caller, long callerUserId, Map<Param, Object> params)
throws StorageUnavailableException, InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException {
s_logger.debug("Starting Internal LB VM " + internalLbVm);
if (_itMgr.start(internalLbVm, params, _accountMgr.getUserIncludingRemoved(callerUserId), caller, null) != null) {
if (internalLbVm.isStopPending()) {
s_logger.info("Clear the stop pending flag of Internal LB VM " + internalLbVm.getHostName() + " after start router successfully!");
internalLbVm.setStopPending(false);
internalLbVm = _internalLbVmDao.persist(internalLbVm);
}
return _internalLbVmDao.findById(internalLbVm.getId());
} else {
return null;
}
}
protected List<HypervisorType> getHypervisors(DeployDestination dest, DeploymentPlan plan,
List<HypervisorType> supportedHypervisors) throws InsufficientServerCapacityException {
List<HypervisorType> hypervisors = new ArrayList<HypervisorType>();
HypervisorType defaults = _resourceMgr.getDefaultHypervisor(dest.getDataCenter().getId());
if (defaults != HypervisorType.None) {
hypervisors.add(defaults);
} else {
//if there is no default hypervisor, get it from the cluster
hypervisors = _resourceMgr.getSupportedHypervisorTypes(dest.getDataCenter().getId(), true,
plan.getPodId());
}
//keep only elements defined in supported hypervisors
StringBuilder hTypesStr = new StringBuilder();
if (supportedHypervisors != null && !supportedHypervisors.isEmpty()) {
hypervisors.retainAll(supportedHypervisors);
for (HypervisorType hType : supportedHypervisors) {
hTypesStr.append(hType).append(" ");
}
}
if (hypervisors.isEmpty()) {
throw new InsufficientServerCapacityException("Unable to create internal lb vm, " +
"there are no clusters in the zone ", DataCenter.class, dest.getDataCenter().getId());
}
return hypervisors;
}
@Override
public boolean applyLoadBalancingRules(Network network, final List<LoadBalancingRule> rules, List<? extends VirtualRouter> internalLbVms)
throws ResourceUnavailableException {
if (rules == null || rules.isEmpty()) {
s_logger.debug("No lb rules to be applied for network " + network);
return true;
}
//only one internal lb vm is supported per ip address at this time
if (internalLbVms == null || internalLbVms.isEmpty()) {
throw new CloudRuntimeException("Can't apply the lb rules on network " + network + " as the list of internal lb vms is empty");
}
VirtualRouter lbVm = internalLbVms.get(0);
if (lbVm.getState() == State.Running) {
return sendLBRules(lbVm, rules, network.getId());
} else if (lbVm.getState() == State.Stopped || lbVm.getState() == State.Stopping) {
s_logger.debug("Internal LB VM " + lbVm.getInstanceName() + " is in " + lbVm.getState() +
", so not sending apply lb rules commands to the backend");
return true;
} else {
s_logger.warn("Unable to apply lb rules, Internal LB VM is not in the right state " + lbVm.getState());
throw new ResourceUnavailableException("Unable to apply lb rules; Internal LB VM is not in the right state", DataCenter.class, lbVm.getDataCenterId());
}
}
protected boolean sendLBRules(VirtualRouter internalLbVm, List<LoadBalancingRule> rules, long guestNetworkId) throws ResourceUnavailableException {
Commands cmds = new Commands(OnError.Continue);
createApplyLoadBalancingRulesCommands(rules, internalLbVm, cmds, guestNetworkId);
return sendCommandsToInternalLbVm(internalLbVm, cmds);
}
protected boolean sendCommandsToInternalLbVm(final VirtualRouter internalLbVm, Commands cmds) throws AgentUnavailableException {
Answer[] answers = null;
try {
answers = _agentMgr.send(internalLbVm.getHostId(), cmds);
} catch (OperationTimedoutException e) {
s_logger.warn("Timed Out", e);
throw new AgentUnavailableException("Unable to send commands to virtual router ", internalLbVm.getHostId(), e);
}
if (answers == null) {
return false;
}
if (answers.length != cmds.size()) {
return false;
}
boolean result = true;
if (answers.length > 0) {
for (Answer answer : answers) {
if (!answer.getResult()) {
result = false;
break;
}
}
}
return result;
}
@Override
public VirtualRouter startInternalLbVm(long internalLbVmId, Account caller, long callerUserId)
throws StorageUnavailableException, InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException {
DomainRouterVO internalLbVm = _internalLbVmDao.findById(internalLbVmId);
if (internalLbVm == null || internalLbVm.getRole() != Role.INTERNAL_LB_VM) {
throw new InvalidParameterValueException("Can't find internal lb vm by id specified");
}
return startInternalLbVm(internalLbVm, caller, callerUserId, null);
}
}

View File

@ -0,0 +1,124 @@
// 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.internallbelement;
import java.io.IOException;
import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao;
import org.apache.cloudstack.network.lb.InternalLoadBalancerVMManager;
import org.apache.cloudstack.test.utils.SpringUtils;
import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.dc.dao.AccountVlanMapDaoImpl;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkModel;
import com.cloud.network.dao.NetworkServiceMapDao;
import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
import com.cloud.network.dao.VirtualRouterProviderDao;
import com.cloud.user.AccountManager;
import com.cloud.vm.dao.DomainRouterDao;
@Configuration
@ComponentScan(
basePackageClasses={
AccountVlanMapDaoImpl.class
},
includeFilters={@Filter(value=ElementChildTestConfiguration.Library.class, type=FilterType.CUSTOM)},
useDefaultFilters=false
)
public class ElementChildTestConfiguration {
public static class Library implements TypeFilter {
@Bean
public AccountManager accountManager() {
return Mockito.mock(AccountManager.class);
}
@Bean
public DomainRouterDao domainRouterDao() {
return Mockito.mock(DomainRouterDao.class);
}
@Bean
public VirtualRouterProviderDao virtualRouterProviderDao() {
return Mockito.mock(VirtualRouterProviderDao.class);
}
@Bean
public NetworkModel networkModel() {
return Mockito.mock(NetworkModel.class);
}
@Bean
public NetworkManager networkManager() {
return Mockito.mock(NetworkManager.class);
}
@Bean
public PhysicalNetworkServiceProviderDao physicalNetworkServiceProviderDao() {
return Mockito.mock(PhysicalNetworkServiceProviderDao.class);
}
@Bean
public NetworkServiceMapDao networkServiceMapDao() {
return Mockito.mock(NetworkServiceMapDao.class);
}
@Bean
public InternalLoadBalancerVMManager internalLoadBalancerVMManager() {
return Mockito.mock(InternalLoadBalancerVMManager.class);
}
@Bean
public ConfigurationManager confugurationManager() {
return Mockito.mock(ConfigurationManager.class);
}
@Bean
public ApplicationLoadBalancerRuleDao applicationLoadBalancerRuleDao() {
return Mockito.mock(ApplicationLoadBalancerRuleDao.class);
}
@Bean
public DataCenterDao dataCenterDao() {
return Mockito.mock(DataCenterDao.class);
}
@Override
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
mdr.getClassMetadata().getClassName();
ComponentScan cs = ElementChildTestConfiguration.class.getAnnotation(ComponentScan.class);
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
}
}
}

View File

@ -0,0 +1,190 @@
// 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.internallbelement;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import javax.inject.Inject;
import org.apache.cloudstack.network.element.InternalLoadBalancerElementService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.network.VirtualRouterProvider;
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
import com.cloud.network.dao.PhysicalNetworkServiceProviderVO;
import com.cloud.network.dao.VirtualRouterProviderDao;
import com.cloud.network.element.VirtualRouterProviderVO;
import com.cloud.user.AccountManager;
import com.cloud.utils.component.ComponentContext;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:/lb_element.xml")
public class InternalLbElementServiceTest {
//The interface to test
@Inject InternalLoadBalancerElementService _lbElSvc;
//Mocked interfaces
@Inject AccountManager _accountMgr;
@Inject VirtualRouterProviderDao _vrProviderDao;
@Inject PhysicalNetworkServiceProviderDao _pNtwkProviderDao;
long validElId = 1L;
long nonExistingElId = 2L;
long invalidElId = 3L; //not of VirtualRouterProviderType
long validProviderId = 1L;
long nonExistingProviderId = 2L;
long invalidProviderId = 3L;
@Before
public void setUp() {
ComponentContext.initComponentsLifeCycle();
VirtualRouterProviderVO validElement = new VirtualRouterProviderVO(1, VirtualRouterProviderType.InternalLbVm);
VirtualRouterProviderVO invalidElement = new VirtualRouterProviderVO(1, VirtualRouterProviderType.VirtualRouter);
Mockito.when(_vrProviderDao.findById(validElId)).thenReturn(validElement);
Mockito.when(_vrProviderDao.findById(invalidElId)).thenReturn(invalidElement);
Mockito.when(_vrProviderDao.persist(validElement)).thenReturn(validElement);
Mockito.when(_vrProviderDao.findByNspIdAndType(validProviderId, VirtualRouterProviderType.InternalLbVm)).thenReturn(validElement);
PhysicalNetworkServiceProviderVO validProvider = new PhysicalNetworkServiceProviderVO(1, "InternalLoadBalancerElement");
PhysicalNetworkServiceProviderVO invalidProvider = new PhysicalNetworkServiceProviderVO(1, "Invalid name!");
Mockito.when(_pNtwkProviderDao.findById(validProviderId)).thenReturn(validProvider);
Mockito.when(_pNtwkProviderDao.findById(invalidProviderId)).thenReturn(invalidProvider);
Mockito.when(_vrProviderDao.persist(Mockito.any(VirtualRouterProviderVO.class))).thenReturn(validElement);
}
//TESTS FOR getInternalLoadBalancerElement METHOD
@Test (expected = InvalidParameterValueException.class)
public void findNonExistingVm() {
String expectedExcText = null;
try {
_lbElSvc.getInternalLoadBalancerElement(nonExistingElId);
} catch (InvalidParameterValueException e) {
expectedExcText = e.getMessage();
throw e;
} finally {
assertEquals("Test failed. The non-existing intenral lb provider was found"
+ expectedExcText, expectedExcText, "Unable to find InternalLoadBalancerElementService by id");
}
}
@Test (expected = InvalidParameterValueException.class)
public void findInvalidVm() {
String expectedExcText = null;
try {
_lbElSvc.getInternalLoadBalancerElement(invalidElId);
} catch (InvalidParameterValueException e) {
expectedExcText = e.getMessage();
throw e;
} finally {
assertEquals("Test failed. The non-existing intenral lb provider was found"
+ expectedExcText, expectedExcText, "Unable to find InternalLoadBalancerElementService by id");
}
}
@Test
public void findValidVm() {
VirtualRouterProvider provider = null;
try {
provider = _lbElSvc.getInternalLoadBalancerElement(validElId);
} finally {
assertNotNull("Test failed. Couldn't find the VR provider by the valid id",provider);
}
}
//TESTS FOR configureInternalLoadBalancerElement METHOD
@Test (expected = InvalidParameterValueException.class)
public void configureNonExistingVm() {
_lbElSvc.configureInternalLoadBalancerElement(nonExistingElId, true);
}
@Test (expected = InvalidParameterValueException.class)
public void ConfigureInvalidVm() {
_lbElSvc.configureInternalLoadBalancerElement(invalidElId, true);
}
@Test
public void enableProvider() {
VirtualRouterProvider provider = null;
try {
provider = _lbElSvc.configureInternalLoadBalancerElement(validElId, true);
} finally {
assertNotNull("Test failed. Couldn't find the VR provider by the valid id ",provider);
assertTrue("Test failed. The provider wasn't eanbled ", provider.isEnabled());
}
}
@Test
public void disableProvider() {
VirtualRouterProvider provider = null;
try {
provider = _lbElSvc.configureInternalLoadBalancerElement(validElId, false);
} finally {
assertNotNull("Test failed. Couldn't find the VR provider by the valid id ",provider);
assertFalse("Test failed. The provider wasn't disabled ", provider.isEnabled());
}
}
//TESTS FOR addInternalLoadBalancerElement METHOD
@Test (expected = InvalidParameterValueException.class)
public void addToNonExistingProvider() {
_lbElSvc.addInternalLoadBalancerElement(nonExistingProviderId);
}
@Test (expected = InvalidParameterValueException.class)
public void addToInvalidProvider() {
_lbElSvc.addInternalLoadBalancerElement(invalidProviderId);
}
@Test
public void addToExistingProvider() {
_lbElSvc.addInternalLoadBalancerElement(validProviderId);
}
}

View File

@ -0,0 +1,226 @@
// 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.internallbelement;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import javax.inject.Inject;
import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
import org.apache.cloudstack.network.element.InternalLoadBalancerElement;
import org.apache.cloudstack.network.lb.InternalLoadBalancerVMManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.DataCenterVO;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
import com.cloud.network.addr.PublicIp;
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
import com.cloud.network.dao.PhysicalNetworkServiceProviderVO;
import com.cloud.network.dao.VirtualRouterProviderDao;
import com.cloud.network.element.VirtualRouterProviderVO;
import com.cloud.network.lb.LoadBalancingRule;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.user.AccountManager;
import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.net.Ip;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:/lb_element.xml")
public class InternalLbElementTest {
//The class to test
@Inject InternalLoadBalancerElement _lbEl;
//Mocked interfaces
@Inject AccountManager _accountMgr;
@Inject VirtualRouterProviderDao _vrProviderDao;
@Inject PhysicalNetworkServiceProviderDao _pNtwkProviderDao;
@Inject InternalLoadBalancerVMManager _internalLbMgr;
@Inject ConfigurationManager _configMgr;
long validElId = 1L;
long nonExistingElId = 2L;
long invalidElId = 3L; //not of VirtualRouterProviderType
long notEnabledElId = 4L;
long validProviderId = 1L;
long nonExistingProviderId = 2L;
long invalidProviderId = 3L;
@Before
public void setUp() {
ComponentContext.initComponentsLifeCycle();
VirtualRouterProviderVO validElement = new VirtualRouterProviderVO(1, VirtualRouterProviderType.InternalLbVm);
validElement.setEnabled(true);
VirtualRouterProviderVO invalidElement = new VirtualRouterProviderVO(1, VirtualRouterProviderType.VirtualRouter);
VirtualRouterProviderVO notEnabledElement = new VirtualRouterProviderVO(1, VirtualRouterProviderType.InternalLbVm);
Mockito.when(_vrProviderDao.findByNspIdAndType(validElId, VirtualRouterProviderType.InternalLbVm)).thenReturn(validElement);
Mockito.when(_vrProviderDao.findByNspIdAndType(invalidElId, VirtualRouterProviderType.InternalLbVm)).thenReturn(invalidElement);
Mockito.when(_vrProviderDao.findByNspIdAndType(notEnabledElId, VirtualRouterProviderType.InternalLbVm)).thenReturn(notEnabledElement);
Mockito.when(_vrProviderDao.persist(validElement)).thenReturn(validElement);
Mockito.when(_vrProviderDao.findByNspIdAndType(validProviderId, VirtualRouterProviderType.InternalLbVm)).thenReturn(validElement);
PhysicalNetworkServiceProviderVO validProvider = new PhysicalNetworkServiceProviderVO(1, "InternalLoadBalancerElement");
PhysicalNetworkServiceProviderVO invalidProvider = new PhysicalNetworkServiceProviderVO(1, "Invalid name!");
Mockito.when(_pNtwkProviderDao.findById(validProviderId)).thenReturn(validProvider);
Mockito.when(_pNtwkProviderDao.findById(invalidProviderId)).thenReturn(invalidProvider);
Mockito.when(_vrProviderDao.persist(Mockito.any(VirtualRouterProviderVO.class))).thenReturn(validElement);
DataCenterVO dc = new DataCenterVO
(1L, null, null, null, null, null, null, null, null, null, NetworkType.Advanced, null, null);
Mockito.when(_configMgr.getZone(Mockito.anyLong())).thenReturn(dc);
}
//TEST FOR getProvider() method
@Test
public void verifyProviderName() {
Provider pr = _lbEl.getProvider();
assertEquals("Wrong provider is returned", pr.getName(), Provider.InternalLbVm.getName());
}
//TEST FOR isReady() METHOD
@Test
public void verifyValidProviderState() {
PhysicalNetworkServiceProviderVO provider = new PhysicalNetworkServiceProviderVO();
provider = setId(provider, validElId);
boolean isReady = _lbEl.isReady(provider);
assertTrue("Valid provider is returned as not ready", isReady);
}
@Test
public void verifyNonExistingProviderState() {
PhysicalNetworkServiceProviderVO provider = new PhysicalNetworkServiceProviderVO();
provider = setId(provider, nonExistingElId);
boolean isReady = _lbEl.isReady(provider);
assertFalse("Non existing provider is returned as ready", isReady);
}
@Test
public void verifyInvalidProviderState() {
PhysicalNetworkServiceProviderVO provider = new PhysicalNetworkServiceProviderVO();
provider = setId(provider, invalidElId);
boolean isReady = _lbEl.isReady(provider);
assertFalse("Not valid provider is returned as ready", isReady);
}
@Test
public void verifyNotEnabledProviderState() {
PhysicalNetworkServiceProviderVO provider = new PhysicalNetworkServiceProviderVO();
provider = setId(provider, notEnabledElId);
boolean isReady = _lbEl.isReady(provider);
assertFalse("Not enabled provider is returned as ready", isReady);
}
//TEST FOR canEnableIndividualServices METHOD
@Test
public void verifyCanEnableIndividualSvc() {
boolean result = _lbEl.canEnableIndividualServices();
assertTrue("Wrong value is returned by canEnableIndividualSvc", result);
}
//TEST FOR verifyServicesCombination METHOD
@Test
public void verifyServicesCombination() {
boolean result = _lbEl.verifyServicesCombination(new HashSet<Service>());
assertTrue("Wrong value is returned by verifyServicesCombination", result);
}
//TEST FOR applyIps METHOD
@Test
public void verifyApplyIps() throws ResourceUnavailableException {
List<PublicIp> ips = new ArrayList<PublicIp>();
boolean result = _lbEl.applyIps(new NetworkVO(), ips, new HashSet<Service>());
assertTrue("Wrong value is returned by applyIps method", result);
}
//TEST FOR updateHealthChecks METHOD
@Test
public void verifyUpdateHealthChecks() throws ResourceUnavailableException {
List<LoadBalancerTO> check = _lbEl.updateHealthChecks(new NetworkVO(), new ArrayList<LoadBalancingRule>());
assertNull("Wrong value is returned by updateHealthChecks method", check);
}
//TEST FOR validateLBRule METHOD
@Test
public void verifyValidateLBRule() throws ResourceUnavailableException {
ApplicationLoadBalancerRuleVO lb = new ApplicationLoadBalancerRuleVO(null, null, 22, 22, "roundrobin",
1L, 1L, 1L, new Ip("10.10.10.1"), 1L, Scheme.Internal);
lb.setState(FirewallRule.State.Add);
LoadBalancingRule rule = new LoadBalancingRule(lb, null,
null, null, new Ip("10.10.10.1"));
boolean result = _lbEl.validateLBRule(new NetworkVO(), rule);
assertTrue("Wrong value is returned by validateLBRule method", result);
}
private static PhysicalNetworkServiceProviderVO setId(PhysicalNetworkServiceProviderVO vo, long id) {
PhysicalNetworkServiceProviderVO voToReturn = vo;
Class<?> c = voToReturn.getClass();
try {
Field f = c.getDeclaredField("id");
f.setAccessible(true);
f.setLong(voToReturn, id);
} catch (NoSuchFieldException ex) {
return null;
} catch (IllegalAccessException ex) {
return null;
}
return voToReturn;
}
}

View File

@ -0,0 +1,388 @@
// 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.internallbvmmgr;
import java.lang.reflect.Field;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import junit.framework.TestCase;
import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
import org.apache.cloudstack.network.lb.InternalLoadBalancerVMManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.manager.Commands;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.NetworkModel;
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.lb.LoadBalancingRule;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.router.VirtualRouter.Role;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.AccountVO;
import com.cloud.user.User;
import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.Ip;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.NicProfile;
import com.cloud.vm.NicVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.NicDao;
/**
* Set of unittests for InternalLoadBalancerVMManager
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:/lb_mgr.xml")
public class InternalLBVMManagerTest extends TestCase {
//The interface to test
@Inject InternalLoadBalancerVMManager _lbVmMgr;
//Mocked interfaces
@Inject AccountManager _accountMgr;
@Inject ServiceOfferingDao _svcOffDao;
@Inject DomainRouterDao _domainRouterDao;
@Inject NicDao _nicDao;
@Inject AgentManager _agentMgr;
@Inject NetworkModel _ntwkModel;
@Inject VirtualMachineManager _itMgr;
@Inject DataCenterDao _dcDao;
long validNtwkId = 1L;
long invalidNtwkId = 2L;
String requestedIp = "10.1.1.1";
DomainRouterVO vm = null;
NetworkVO ntwk = createNetwork();
long validVmId = 1L;
long invalidVmId = 2L;
@Before
public void setUp() {
//mock system offering creation as it's used by configure() method called by initComponentsLifeCycle
Mockito.when(_accountMgr.getAccount(1L)).thenReturn(new AccountVO());
ServiceOfferingVO off = new ServiceOfferingVO("alena", 1, 1,
1, 1, 1, false, "alena", false, false, null, false, VirtualMachine.Type.InternalLoadBalancerVm, false);
off = setId(off, 1);
Mockito.when(_svcOffDao.persistSystemServiceOffering(Mockito.any(ServiceOfferingVO.class))).thenReturn(off);
ComponentContext.initComponentsLifeCycle();
vm = new DomainRouterVO(1L,off.getId(),1,"alena",1,HypervisorType.XenServer,1,1,1,
false, 0,false,null,false,false,
VirtualMachine.Type.InternalLoadBalancerVm, null);
vm.setRole(Role.INTERNAL_LB_VM);
vm = setId(vm, 1);
vm.setPrivateIpAddress("10.2.2.2");
NicVO nic = new NicVO("somereserver", 1L, 1L, VirtualMachine.Type.InternalLoadBalancerVm);
nic.setIp4Address(requestedIp);
List<DomainRouterVO> emptyList = new ArrayList<DomainRouterVO>();
List<DomainRouterVO> nonEmptyList = new ArrayList<DomainRouterVO>();
nonEmptyList.add(vm);
Mockito.when(_domainRouterDao.listByNetworkAndRole(invalidNtwkId, Role.INTERNAL_LB_VM)).thenReturn(emptyList);
Mockito.when(_domainRouterDao.listByNetworkAndRole(validNtwkId, Role.INTERNAL_LB_VM)).thenReturn(nonEmptyList);
Mockito.when(_nicDao.findByNtwkIdAndInstanceId(validNtwkId, 1)).thenReturn(nic);
Mockito.when(_nicDao.findByNtwkIdAndInstanceId(invalidNtwkId, 1)).thenReturn(nic);
Answer answer= new Answer(null, true, null);
Answer[] answers = new Answer[1];
answers[0] = answer;
try {
Mockito.when(_agentMgr.send(Mockito.anyLong(), Mockito.any(Commands.class))).thenReturn(answers);
} catch (AgentUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OperationTimedoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
createNetwork();
Mockito.when(_ntwkModel.getNetwork(Mockito.anyLong())).thenReturn(ntwk);
Mockito.when(_itMgr.toNicTO(Mockito.any(NicProfile.class), Mockito.any(HypervisorType.class))).thenReturn(null);
Mockito.when(_domainRouterDao.findById(Mockito.anyLong())).thenReturn(vm);
DataCenterVO dc = new DataCenterVO
(1L, null, null, null, null, null, null, null, null, null, NetworkType.Advanced, null, null);
Mockito.when(_dcDao.findById(Mockito.anyLong())).thenReturn(dc);
try {
Mockito.when(_itMgr.expunge(Mockito.any(DomainRouterVO.class), Mockito.any(User.class), Mockito.any(Account.class))).thenReturn(true);
} catch (ResourceUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(vm);
Mockito.when(_domainRouterDao.findById(invalidVmId)).thenReturn(null);
}
protected NetworkVO createNetwork() {
ntwk = new NetworkVO();
try {
ntwk.setBroadcastUri(new URI("somevlan"));
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ntwk = setId(ntwk, 1L);
return ntwk;
}
//TESTS FOR findInternalLbVms METHOD
@Test
public void findInternalLbVmsForInvalidNetwork() {
List<? extends VirtualRouter> vms = _lbVmMgr.findInternalLbVms(invalidNtwkId, new Ip(requestedIp));
assertTrue("Non empty vm list was returned for invalid network id", vms.isEmpty());
}
@Test
public void findInternalLbVmsForValidNetwork() {
List<? extends VirtualRouter> vms = _lbVmMgr.findInternalLbVms(validNtwkId, new Ip(requestedIp));
assertTrue("Empty vm list was returned for valid network id", !vms.isEmpty());
}
//TESTS FOR applyLoadBalancingRules METHOD
@Test
public void applyEmptyRulesSet() {
boolean result = false;
List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
try {
result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), new ArrayList<LoadBalancingRule>(), vms);
} catch (ResourceUnavailableException e) {
} finally {
assertTrue("Got failure when tried to apply empty list of rules", result);
}
}
@Test (expected = CloudRuntimeException.class)
public void applyWithEmptyVmsSet() {
boolean result = false;
List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
LoadBalancingRule rule = new LoadBalancingRule(null, null,
null, null, null);
rules.add(rule);
try {
result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), rules, vms);
} catch (ResourceUnavailableException e) {
} finally {
assertFalse("Got success when tried to apply with the empty internal lb vm list", result);
}
}
@Test (expected = ResourceUnavailableException.class)
public void applyToVmInStartingState() throws ResourceUnavailableException {
boolean result = false;
List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
vm.setState(State.Starting);
vms.add(vm);
List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
LoadBalancingRule rule = new LoadBalancingRule(null, null,
null, null, null);
rules.add(rule);
try {
result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), rules, vms);
} finally {
assertFalse("Rules were applied to vm in Starting state", result);
}
}
@Test
public void applyToVmInStoppedState() throws ResourceUnavailableException {
boolean result = false;
List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
vm.setState(State.Stopped);
vms.add(vm);
List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
LoadBalancingRule rule = new LoadBalancingRule(null, null,
null, null, null);
rules.add(rule);
try {
result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), rules, vms);
} finally {
assertTrue("Rules failed to apply to vm in Stopped state", result);
}
}
@Test
public void applyToVmInStoppingState() throws ResourceUnavailableException {
boolean result = false;
List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
vm.setState(State.Stopping);
vms.add(vm);
List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
LoadBalancingRule rule = new LoadBalancingRule(null, null,
null, null, null);
rules.add(rule);
try {
result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), rules, vms);
} finally {
assertTrue("Rules failed to apply to vm in Stopping state", result);
}
}
@Test
public void applyToVmInRunningState() throws ResourceUnavailableException {
boolean result = false;
List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
vm.setState(State.Running);
vms.add(vm);
List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
ApplicationLoadBalancerRuleVO lb = new ApplicationLoadBalancerRuleVO(null, null, 22, 22, "roundrobin",
1L, 1L, 1L, new Ip(requestedIp), 1L, Scheme.Internal);
lb.setState(FirewallRule.State.Add);
LoadBalancingRule rule = new LoadBalancingRule(lb, null,
null, null, new Ip(requestedIp));
rules.add(rule);
ntwk.getId();
try {
result = _lbVmMgr.applyLoadBalancingRules(ntwk, rules, vms);
} finally {
assertTrue("Rules failed to apply to vm in Running state", result);
}
}
//TESTS FOR destroyInternalLbVm METHOD
@Test
public void destroyNonExistingVM() throws ResourceUnavailableException, ConcurrentOperationException {
boolean result = false;
try {
result = _lbVmMgr.destroyInternalLbVm(invalidVmId, new AccountVO(), 1L);
} finally {
assertTrue("Failed to destroy non-existing vm", result);
}
}
@Test
public void destroyExistingVM() throws ResourceUnavailableException, ConcurrentOperationException {
boolean result = false;
try {
result = _lbVmMgr.destroyInternalLbVm(validVmId, new AccountVO(), 1L);
} finally {
assertTrue("Failed to destroy valid vm", result);
}
}
private static ServiceOfferingVO setId(ServiceOfferingVO vo, long id) {
ServiceOfferingVO voToReturn = vo;
Class<?> c = voToReturn.getClass();
try {
Field f = c.getSuperclass().getDeclaredField("id");
f.setAccessible(true);
f.setLong(voToReturn, id);
} catch (NoSuchFieldException ex) {
return null;
} catch (IllegalAccessException ex) {
return null;
}
return voToReturn;
}
private static NetworkVO setId(NetworkVO vo, long id) {
NetworkVO voToReturn = vo;
Class<?> c = voToReturn.getClass();
try {
Field f = c.getDeclaredField("id");
f.setAccessible(true);
f.setLong(voToReturn, id);
} catch (NoSuchFieldException ex) {
return null;
} catch (IllegalAccessException ex) {
return null;
}
return voToReturn;
}
private static DomainRouterVO setId(DomainRouterVO vo, long id) {
DomainRouterVO voToReturn = vo;
Class<?> c = voToReturn.getClass();
try {
Field f = c.getSuperclass().getDeclaredField("id");
f.setAccessible(true);
f.setLong(voToReturn, id);
} catch (NoSuchFieldException ex) {
return null;
} catch (IllegalAccessException ex) {
return null;
}
return voToReturn;
}
}

View File

@ -0,0 +1,291 @@
// 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.internallbvmmgr;
import java.lang.reflect.Field;
import java.util.Map;
import javax.inject.Inject;
import junit.framework.TestCase;
import org.apache.cloudstack.network.lb.InternalLoadBalancerVMService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.exception.StorageUnavailableException;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.router.VirtualRouter.Role;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.AccountVO;
import com.cloud.user.User;
import com.cloud.utils.component.ComponentContext;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.dao.DomainRouterDao;
/**
* Set of unittests for InternalLoadBalancerVMService
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:/lb_svc.xml")
@SuppressWarnings("unchecked")
public class InternalLBVMServiceTest extends TestCase {
//The interface to test
@Inject InternalLoadBalancerVMService _lbVmSvc;
//Mocked interfaces
@Inject AccountManager _accountMgr;
@Inject ServiceOfferingDao _svcOffDao;
@Inject DomainRouterDao _domainRouterDao;
@Inject VirtualMachineManager _itMgr;
long validVmId = 1L;
long nonExistingVmId = 2L;
long nonInternalLbVmId = 3L;
@Before
public void setUp() {
//mock system offering creation as it's used by configure() method called by initComponentsLifeCycle
Mockito.when(_accountMgr.getAccount(1L)).thenReturn(new AccountVO());
ServiceOfferingVO off = new ServiceOfferingVO("alena", 1, 1,
1, 1, 1, false, "alena", false, false, null, false, VirtualMachine.Type.InternalLoadBalancerVm, false);
off = setId(off, 1);
Mockito.when(_svcOffDao.persistSystemServiceOffering(Mockito.any(ServiceOfferingVO.class))).thenReturn(off);
ComponentContext.initComponentsLifeCycle();
DomainRouterVO validVm = new DomainRouterVO(validVmId,off.getId(),1,"alena",1,HypervisorType.XenServer,1,1,1,
false, 0,false,null,false,false,
VirtualMachine.Type.InternalLoadBalancerVm, null);
validVm.setRole(Role.INTERNAL_LB_VM);
DomainRouterVO nonInternalLbVm = new DomainRouterVO(validVmId,off.getId(),1,"alena",1,HypervisorType.XenServer,1,1,1,
false, 0,false,null,false,false,
VirtualMachine.Type.DomainRouter, null);
nonInternalLbVm.setRole(Role.VIRTUAL_ROUTER);
Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(validVm);
Mockito.when(_domainRouterDao.findById(nonExistingVmId)).thenReturn(null);
Mockito.when(_domainRouterDao.findById(nonInternalLbVmId)).thenReturn(nonInternalLbVm);
try {
Mockito.when(_itMgr.start(Mockito.any(DomainRouterVO.class),
Mockito.any(Map.class), Mockito.any(User.class), Mockito.any(Account.class), Mockito.any(DeploymentPlan.class))).thenReturn(validVm);
} catch (InsufficientCapacityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ResourceUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Mockito.when(_itMgr.advanceStop(Mockito.any(DomainRouterVO.class), Mockito.any(Boolean.class), Mockito.any(User.class), Mockito.any(Account.class))).thenReturn(true);
} catch (ResourceUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OperationTimedoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ConcurrentOperationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//TESTS FOR START COMMAND
@Test (expected = InvalidParameterValueException.class)
public void startNonExistingVm() {
String expectedExcText = null;
try {
_lbVmSvc.startInternalLbVm(nonExistingVmId, _accountMgr.getAccount(1L), 1L);
} catch (StorageUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InsufficientCapacityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ConcurrentOperationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ResourceUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidParameterValueException e) {
expectedExcText = e.getMessage();
throw e;
} finally {
assertEquals("Test failed. The non-existing internal lb vm was attempted to start"
+ expectedExcText, expectedExcText, "Can't find internal lb vm by id specified");
}
}
@Test (expected = InvalidParameterValueException.class)
public void startNonInternalLbVmVm() {
String expectedExcText = null;
try {
_lbVmSvc.startInternalLbVm(nonInternalLbVmId, _accountMgr.getAccount(1L), 1L);
} catch (StorageUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InsufficientCapacityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ConcurrentOperationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ResourceUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (InvalidParameterValueException e) {
expectedExcText = e.getMessage();
throw e;
} finally {
assertEquals("Test failed. The existing vm of not Internal lb vm type was attempted to start"
+ expectedExcText, expectedExcText, "Can't find internal lb vm by id specified");
}
}
@Test
public void startValidLbVmVm() {
VirtualRouter vr = null;
try {
vr = _lbVmSvc.startInternalLbVm(validVmId, _accountMgr.getAccount(1L), 1L);
} catch (StorageUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InsufficientCapacityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ConcurrentOperationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ResourceUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
assertNotNull("Internal LB vm is null which means it failed to start " + vr, vr);
}
}
//TEST FOR STOP COMMAND
@Test (expected = InvalidParameterValueException.class)
public void stopNonExistingVm() {
String expectedExcText = null;
try {
_lbVmSvc.stopInternalLbVm(nonExistingVmId, false,_accountMgr.getAccount(1L), 1L);
} catch (StorageUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ConcurrentOperationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ResourceUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidParameterValueException e) {
expectedExcText = e.getMessage();
throw e;
} finally {
assertEquals("Test failed. The non-existing internal lb vm was attempted to stop"
+ expectedExcText, expectedExcText, "Can't find internal lb vm by id specified");
}
}
@Test (expected = InvalidParameterValueException.class)
public void stopNonInternalLbVmVm() {
String expectedExcText = null;
try {
_lbVmSvc.stopInternalLbVm(nonInternalLbVmId, false, _accountMgr.getAccount(1L), 1L);
} catch (StorageUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ConcurrentOperationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ResourceUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (InvalidParameterValueException e) {
expectedExcText = e.getMessage();
throw e;
} finally {
assertEquals("Test failed. The existing vm of not Internal lb vm type was attempted to stop"
+ expectedExcText, expectedExcText, "Can't find internal lb vm by id specified");
}
}
@Test
public void stopValidLbVmVm() {
VirtualRouter vr = null;
try {
vr = _lbVmSvc.stopInternalLbVm(validVmId, false, _accountMgr.getAccount(1L), 1L);
} catch (StorageUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ConcurrentOperationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ResourceUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
assertNotNull("Internal LB vm is null which means it failed to stop " + vr, vr);
}
}
private static ServiceOfferingVO setId(ServiceOfferingVO vo, long id) {
ServiceOfferingVO voToReturn = vo;
Class<?> c = voToReturn.getClass();
try {
Field f = c.getSuperclass().getDeclaredField("id");
f.setAccessible(true);
f.setLong(voToReturn, id);
} catch (NoSuchFieldException ex) {
return null;
} catch (IllegalAccessException ex) {
return null;
}
return voToReturn;
}
}

View File

@ -0,0 +1,170 @@
// 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.internallbvmmgr;
import java.io.IOException;
import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao;
import org.apache.cloudstack.test.utils.SpringUtils;
import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
import com.cloud.agent.AgentManager;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.dao.AccountVlanMapDaoImpl;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkModel;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
import com.cloud.network.dao.VirtualRouterProviderDao;
import com.cloud.network.lb.LoadBalancingRulesManager;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.resource.ResourceManager;
import com.cloud.server.ConfigurationServer;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.user.AccountManager;
import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.NicDao;
@Configuration
@ComponentScan(
basePackageClasses={
AccountVlanMapDaoImpl.class
},
includeFilters={@Filter(value=LbChildTestConfiguration.Library.class, type=FilterType.CUSTOM)},
useDefaultFilters=false
)
public class LbChildTestConfiguration {
public static class Library implements TypeFilter {
@Bean
public AccountManager accountManager() {
return Mockito.mock(AccountManager.class);
}
@Bean
public VirtualMachineManager virtualMachineManager() {
return Mockito.mock(VirtualMachineManager.class);
}
@Bean
public DomainRouterDao domainRouterDao() {
return Mockito.mock(DomainRouterDao.class);
}
@Bean
public ConfigurationDao configurationDao() {
return Mockito.mock(ConfigurationDao.class);
}
@Bean
public VirtualRouterProviderDao virtualRouterProviderDao() {
return Mockito.mock(VirtualRouterProviderDao.class);
}
@Bean
public ApplicationLoadBalancerRuleDao applicationLoadBalancerRuleDao() {
return Mockito.mock(ApplicationLoadBalancerRuleDao.class);
}
@Bean
public NetworkModel networkModel() {
return Mockito.mock(NetworkModel.class);
}
@Bean
public LoadBalancingRulesManager loadBalancingRulesManager() {
return Mockito.mock(LoadBalancingRulesManager.class);
}
@Bean
public NicDao nicDao() {
return Mockito.mock(NicDao.class);
}
@Bean
public NetworkDao networkDao() {
return Mockito.mock(NetworkDao.class);
}
@Bean
public NetworkManager networkManager() {
return Mockito.mock(NetworkManager.class);
}
@Bean
public ServiceOfferingDao serviceOfferingDao() {
return Mockito.mock(ServiceOfferingDao.class);
}
@Bean
public PhysicalNetworkServiceProviderDao physicalNetworkServiceProviderDao() {
return Mockito.mock(PhysicalNetworkServiceProviderDao.class);
}
@Bean
public NetworkOfferingDao networkOfferingDao() {
return Mockito.mock(NetworkOfferingDao.class);
}
@Bean
public VMTemplateDao vmTemplateDao() {
return Mockito.mock(VMTemplateDao.class);
}
@Bean
public ResourceManager resourceManager() {
return Mockito.mock(ResourceManager.class);
}
@Bean
public AgentManager agentManager() {
return Mockito.mock(AgentManager.class);
}
@Bean
public DataCenterDao dataCenterDao() {
return Mockito.mock(DataCenterDao.class);
}
@Bean
public ConfigurationServer configurationServer() {
return Mockito.mock(ConfigurationServer.class);
}
@Override
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
mdr.getClassMetadata().getClassName();
ComponentScan cs = LbChildTestConfiguration.class.getAnnotation(ComponentScan.class);
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
}
}
}

View File

@ -0,0 +1,46 @@
<!-- 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. -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config />
<!-- @DB support -->
<bean id="componentContext" class="com.cloud.utils.component.ComponentContext" />
<bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" />
<bean id="actionEventInterceptor" class="com.cloud.event.ActionEventInterceptor" />
<bean id="instantiatePostProcessor" class="com.cloud.utils.component.ComponentInstantiationPostProcessor">
<property name="Interceptors">
<list>
<ref bean="transactionContextBuilder" />
<ref bean="actionEventInterceptor" />
</list>
</property>
</bean>
<bean id="InternalLoadBalancerElementService" class="org.apache.cloudstack.network.element.InternalLoadBalancerElement">
<property name="name" value="InternalLoadBalancerElementService"/>
</bean>
<bean class="org.apache.cloudstack.internallbelement.ElementChildTestConfiguration" />
</beans>

View File

@ -0,0 +1,46 @@
<!-- 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. -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config />
<!-- @DB support -->
<bean id="componentContext" class="com.cloud.utils.component.ComponentContext" />
<bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" />
<bean id="actionEventInterceptor" class="com.cloud.event.ActionEventInterceptor" />
<bean id="instantiatePostProcessor" class="com.cloud.utils.component.ComponentInstantiationPostProcessor">
<property name="Interceptors">
<list>
<ref bean="transactionContextBuilder" />
<ref bean="actionEventInterceptor" />
</list>
</property>
</bean>
<bean id="InternalLoadBalancerVMManager" class="org.apache.cloudstack.network.lb.InternalLoadBalancerVMManagerImpl">
<property name="name" value="InternalLoadBalancerVMManager"/>
</bean>
<bean class="org.apache.cloudstack.internallbvmmgr.LbChildTestConfiguration" />
</beans>

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