merge to master

This commit is contained in:
Edison Su 2013-05-16 23:56:20 -07:00
commit f7c1b711ad
130 changed files with 4768 additions and 1574 deletions

View File

@ -0,0 +1,121 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.agent.api;
import java.net.URI;
import com.cloud.utils.net.NetUtils;
public class PvlanSetupCommand extends Command {
public enum Type {
DHCP,
VM
}
private String op;
private String primary;
private String isolated;
private String vmMac;
private String dhcpName;
private String dhcpMac;
private String dhcpIp;
private Type type;
private String networkTag;
protected PvlanSetupCommand() {}
protected PvlanSetupCommand(Type type, String op, URI uri, String networkTag)
{
this.type = type;
this.op = op;
this.primary = NetUtils.getPrimaryPvlanFromUri(uri);
this.isolated = NetUtils.getIsolatedPvlanFromUri(uri);
this.networkTag = networkTag;
}
static public PvlanSetupCommand createDhcpSetup(String op, URI uri, String networkTag, String dhcpName, String dhcpMac, String dhcpIp)
{
PvlanSetupCommand cmd = new PvlanSetupCommand(Type.DHCP, op, uri, networkTag);
cmd.setDhcpName(dhcpName);
cmd.setDhcpMac(dhcpMac);
cmd.setDhcpIp(dhcpIp);
return cmd;
}
static public PvlanSetupCommand createVmSetup(String op, URI uri, String networkTag, String vmMac)
{
PvlanSetupCommand cmd = new PvlanSetupCommand(Type.VM, op, uri, networkTag);
cmd.setVmMac(vmMac);
return cmd;
}
@Override
public boolean executeInSequence() {
return true;
}
public String getOp() {
return op;
}
public String getPrimary() {
return primary;
}
public String getIsolated() {
return isolated;
}
public String getVmMac() {
return vmMac;
}
protected void setVmMac(String vmMac) {
this.vmMac = vmMac;
}
public String getDhcpMac() {
return dhcpMac;
}
protected void setDhcpMac(String dhcpMac) {
this.dhcpMac = dhcpMac;
}
public String getDhcpIp() {
return dhcpIp;
}
protected void setDhcpIp(String dhcpIp) {
this.dhcpIp = dhcpIp;
}
public Type getType() {
return type;
}
public String getDhcpName() {
return dhcpName;
}
public void setDhcpName(String dhcpName) {
this.dhcpName = dhcpName;
}
public String getNetworkTag() {
return networkTag;
}
}

View File

@ -0,0 +1,45 @@
// 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.deploy;
import java.util.List;
import com.cloud.exception.InsufficientServerCapacityException;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
/**
*/
public interface DeploymentClusterPlanner extends DeploymentPlanner {
/**
* This is called to determine list of possible clusters where a virtual
* machine can be deployed.
*
* @param vm
* virtual machine.
* @param plan
* deployment plan that tells you where it's being deployed to.
* @param avoid
* avoid these data centers, pods, clusters, or hosts.
* @return DeployDestination for that virtual machine.
*/
List<Long> orderClusters(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, ExcludeList avoid)
throws InsufficientServerCapacityException;
PlannerResourceUsage getResourceUsage();
}

View File

@ -35,6 +35,7 @@ import com.cloud.vm.VirtualMachineProfile;
/** /**
*/ */
public interface DeploymentPlanner extends Adapter { public interface DeploymentPlanner extends Adapter {
/** /**
* plan is called to determine where a virtual machine should be running. * plan is called to determine where a virtual machine should be running.
* *
@ -46,6 +47,7 @@ public interface DeploymentPlanner extends Adapter {
* avoid these data centers, pods, clusters, or hosts. * avoid these data centers, pods, clusters, or hosts.
* @return DeployDestination for that virtual machine. * @return DeployDestination for that virtual machine.
*/ */
@Deprecated
DeployDestination plan(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException; DeployDestination plan(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException;
/** /**
@ -88,6 +90,10 @@ public interface DeploymentPlanner extends Adapter {
userconcentratedpod_firstfit; userconcentratedpod_firstfit;
} }
public enum PlannerResourceUsage {
Shared, Dedicated;
}
public static class ExcludeList { public static class ExcludeList {
private Set<Long> _dcIds; private Set<Long> _dcIds;
private Set<Long> _podIds; private Set<Long> _podIds;
@ -99,10 +105,22 @@ public interface DeploymentPlanner extends Adapter {
} }
public ExcludeList(Set<Long> _dcIds, Set<Long> _podIds, Set<Long> _clusterIds, Set<Long> _hostIds, Set<Long> _poolIds) { public ExcludeList(Set<Long> _dcIds, Set<Long> _podIds, Set<Long> _clusterIds, Set<Long> _hostIds, Set<Long> _poolIds) {
this._dcIds = _dcIds; if (_dcIds != null) {
this._podIds = _podIds; this._dcIds = new HashSet<Long>(_dcIds);
this._clusterIds = _clusterIds; }
this._poolIds = _poolIds; if (_podIds != null) {
this._podIds = new HashSet<Long>(_podIds);
}
if (_clusterIds != null) {
this._clusterIds = new HashSet<Long>(_clusterIds);
}
if (_hostIds != null) {
this._hostIds = new HashSet<Long>(_hostIds);
}
if (_poolIds != null) {
this._poolIds = new HashSet<Long>(_poolIds);
}
} }
public boolean add(InsufficientCapacityException e) { public boolean add(InsufficientCapacityException e) {

View File

@ -134,6 +134,7 @@ public class EventTypes {
public static final String EVENT_REMOVE_FROM_GLOBAL_LOAD_BALANCER_RULE = "GLOBAL.LB.REMOVE"; public static final String EVENT_REMOVE_FROM_GLOBAL_LOAD_BALANCER_RULE = "GLOBAL.LB.REMOVE";
public static final String EVENT_GLOBAL_LOAD_BALANCER_CREATE = "GLOBAL.LB.CREATE"; public static final String EVENT_GLOBAL_LOAD_BALANCER_CREATE = "GLOBAL.LB.CREATE";
public static final String EVENT_GLOBAL_LOAD_BALANCER_DELETE = "GLOBAL.LB.DELETE"; public static final String EVENT_GLOBAL_LOAD_BALANCER_DELETE = "GLOBAL.LB.DELETE";
public static final String EVENT_GLOBAL_LOAD_BALANCER_UPDATE = "GLOBAL.LB.UPDATE";
// Account events // Account events
public static final String EVENT_ACCOUNT_ENABLE = "ACCOUNT.ENABLE"; public static final String EVENT_ACCOUNT_ENABLE = "ACCOUNT.ENABLE";
@ -422,6 +423,7 @@ public class EventTypes {
public static final String EVENT_INTERNAL_LB_VM_START = "INTERNALLBVM.START"; 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_INTERNAL_LB_VM_STOP = "INTERNALLBVM.STOP";
public static final String EVENT_HOST_RESERVATION_RELEASE = "HOST.RESERVATION.RELEASE";
// Dedicated guest vlan range // Dedicated guest vlan range
public static final String EVENT_GUEST_VLAN_RANGE_DEDICATE = "GUESTVLANRANGE.DEDICATE"; public static final String EVENT_GUEST_VLAN_RANGE_DEDICATE = "GUESTVLANRANGE.DEDICATE";
public static final String EVENT_DEDICATED_GUEST_VLAN_RANGE_RELEASE = "GUESTVLANRANGE.RELEASE"; public static final String EVENT_DEDICATED_GUEST_VLAN_RANGE_RELEASE = "GUESTVLANRANGE.RELEASE";
@ -727,7 +729,6 @@ public class EventTypes {
entityEventDetails.put(EVENT_AUTOSCALEVMGROUP_UPDATE, AutoScaleVmGroup.class.getName()); entityEventDetails.put(EVENT_AUTOSCALEVMGROUP_UPDATE, AutoScaleVmGroup.class.getName());
entityEventDetails.put(EVENT_AUTOSCALEVMGROUP_ENABLE, AutoScaleVmGroup.class.getName()); entityEventDetails.put(EVENT_AUTOSCALEVMGROUP_ENABLE, AutoScaleVmGroup.class.getName());
entityEventDetails.put(EVENT_AUTOSCALEVMGROUP_DISABLE, AutoScaleVmGroup.class.getName()); entityEventDetails.put(EVENT_AUTOSCALEVMGROUP_DISABLE, AutoScaleVmGroup.class.getName());
entityEventDetails.put(EVENT_GUEST_VLAN_RANGE_DEDICATE, GuestVlan.class.getName()); entityEventDetails.put(EVENT_GUEST_VLAN_RANGE_DEDICATE, GuestVlan.class.getName());
entityEventDetails.put(EVENT_DEDICATED_GUEST_VLAN_RANGE_RELEASE, GuestVlan.class.getName()); entityEventDetails.put(EVENT_DEDICATED_GUEST_VLAN_RANGE_RELEASE, GuestVlan.class.getName());
} }

View File

@ -147,6 +147,7 @@ public enum Status {
s_fsm.addTransition(Status.Down, Event.Remove, Status.Removed); s_fsm.addTransition(Status.Down, Event.Remove, Status.Removed);
s_fsm.addTransition(Status.Down, Event.ManagementServerDown, Status.Down); s_fsm.addTransition(Status.Down, Event.ManagementServerDown, Status.Down);
s_fsm.addTransition(Status.Down, Event.AgentDisconnected, Status.Down); s_fsm.addTransition(Status.Down, Event.AgentDisconnected, Status.Down);
s_fsm.addTransition(Status.Down, Event.PingTimeout, Status.Down);
s_fsm.addTransition(Status.Alert, Event.AgentConnected, Status.Connecting); s_fsm.addTransition(Status.Alert, Event.AgentConnected, Status.Connecting);
s_fsm.addTransition(Status.Alert, Event.Ping, Status.Up); s_fsm.addTransition(Status.Alert, Event.Ping, Status.Up);
s_fsm.addTransition(Status.Alert, Event.Remove, Status.Removed); s_fsm.addTransition(Status.Alert, Event.Remove, Status.Removed);

View File

@ -63,6 +63,7 @@ public class Networks {
Storage("storage", Integer.class), Storage("storage", Integer.class),
Lswitch("lswitch", String.class), Lswitch("lswitch", String.class),
Mido("mido", String.class), Mido("mido", String.class),
Pvlan("pvlan", String.class),
UnDecided(null, null); UnDecided(null, null);
private String scheme; private String scheme;

View File

@ -108,4 +108,6 @@ public interface ServiceOffering extends InfrastructureEntity, InternalIdentity,
boolean getDefaultUse(); boolean getDefaultUse();
String getSystemVmType(); String getSystemVmType();
String getDeploymentPlanner();
} }

View File

@ -101,12 +101,12 @@ public interface ResourceService {
S3 discoverS3(AddS3Cmd cmd) throws DiscoveryException; S3 discoverS3(AddS3Cmd cmd) throws DiscoveryException;
List<HypervisorType> getSupportedHypervisorTypes(long zoneId, boolean forVirtualRouter, Long podId); List<HypervisorType> getSupportedHypervisorTypes(long zoneId, boolean forVirtualRouter, Long podId);
Pair<List<? extends Swift>, Integer> listSwifts(ListSwiftsCmd cmd); Pair<List<? extends Swift>, Integer> listSwifts(ListSwiftsCmd cmd);
List<? extends S3> listS3s(ListS3sCmd cmd); List<? extends S3> listS3s(ListS3sCmd cmd);
boolean releaseHostReservation(Long hostId);
} }

View File

@ -388,5 +388,7 @@ public interface ManagementService {
* @return List of capacities * @return List of capacities
*/ */
List<? extends Capacity> listTopConsumedResources(ListCapacityCmd cmd); List<? extends Capacity> listTopConsumedResources(ListCapacityCmd cmd);
List<String> listDeploymentPlanners();
} }

View File

@ -230,6 +230,7 @@ public class ApiConstants {
public static final String VLAN_RANGE = "vlanrange"; public static final String VLAN_RANGE = "vlanrange";
public static final String REMOVE_VLAN="removevlan"; public static final String REMOVE_VLAN="removevlan";
public static final String VLAN_ID = "vlanid"; public static final String VLAN_ID = "vlanid";
public static final String ISOLATED_PVLAN = "isolatedpvlan";
public static final String VM_AVAILABLE = "vmavailable"; public static final String VM_AVAILABLE = "vmavailable";
public static final String VM_LIMIT = "vmlimit"; public static final String VM_LIMIT = "vmlimit";
public static final String VM_TOTAL = "vmtotal"; public static final String VM_TOTAL = "vmtotal";
@ -495,6 +496,7 @@ public class ApiConstants {
public static final String AFFINITY_GROUP_NAMES = "affinitygroupnames"; public static final String AFFINITY_GROUP_NAMES = "affinitygroupnames";
public static final String ASA_INSIDE_PORT_PROFILE = "insideportprofile"; public static final String ASA_INSIDE_PORT_PROFILE = "insideportprofile";
public static final String AFFINITY_GROUP_ID = "affinitygroupid"; public static final String AFFINITY_GROUP_ID = "affinitygroupid";
public static final String DEPLOYMENT_PLANNER = "deploymentplanner";
public static final String ACL_ID = "aclid"; public static final String ACL_ID = "aclid";
public static final String NUMBER = "number"; public static final String NUMBER = "number";

View File

@ -0,0 +1,71 @@
// 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.config;
import java.util.ArrayList;
import java.util.List;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.response.DeploymentPlannersResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.log4j.Logger;
@APICommand(name = "listDeploymentPlanners", description = "Lists all DeploymentPlanners available.", responseObject = DeploymentPlannersResponse.class)
public class ListDeploymentPlannersCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListDeploymentPlannersCmd.class.getName());
private static final String s_name = "listdeploymentplannersresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public void execute(){
List<String> planners = _mgr.listDeploymentPlanners();
ListResponse<DeploymentPlannersResponse> response = new ListResponse<DeploymentPlannersResponse>();
List<DeploymentPlannersResponse> plannerResponses = new ArrayList<DeploymentPlannersResponse>();
for (String planner : planners) {
DeploymentPlannersResponse plannerResponse = new DeploymentPlannersResponse();
plannerResponse.setName(planner);
plannerResponse.setObjectName("deploymentPlanner");
plannerResponses.add(plannerResponse);
}
response.setResponses(plannerResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
}

View File

@ -0,0 +1,105 @@
// 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.host;
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.HostResponse;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.log4j.Logger;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@APICommand(name = "releaseHostReservation", description = "Releases host reservation.", responseObject = SuccessResponse.class)
public class ReleaseHostReservationCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(ReleaseHostReservationCmd.class.getName());
private static final String s_name = "releasehostreservationresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=HostResponse.class,
required=true, description="the host ID")
private Long id;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Long getId() {
return id;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
Account account = UserContext.current().getCaller();
if (account != null) {
return account.getId();
}
return Account.ACCOUNT_ID_SYSTEM;
}
@Override
public String getEventType() {
return EventTypes.EVENT_HOST_RESERVATION_RELEASE;
}
@Override
public String getEventDescription() {
return "releasing reservation for host: " + getId();
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.Host;
}
@Override
public Long getInstanceId() {
return getId();
}
@Override
public void execute(){
boolean result = _resourceService.releaseHostReservation(getId());
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to release host reservation");
}
}
}

View File

@ -44,7 +44,7 @@ public class ListNetworkIsolationMethodsCmd extends BaseListCmd{
isolationResponses.add(isolationMethod); isolationResponses.add(isolationMethod);
} }
} }
response.setResponses(isolationResponses, methods.length); response.setResponses(isolationResponses, isolationResponses.size());
response.setResponseName(getCommandName()); response.setResponseName(getCommandName());
this.setResponseObject(response); this.setResponseObject(response);

View File

@ -84,6 +84,9 @@ public class CreateServiceOfferingCmd extends BaseCmd {
@Parameter(name=ApiConstants.NETWORKRATE, type=CommandType.INTEGER, description="data transfer rate in megabits per second allowed. Supported only for non-System offering and system offerings having \"domainrouter\" systemvmtype") @Parameter(name=ApiConstants.NETWORKRATE, type=CommandType.INTEGER, description="data transfer rate in megabits per second allowed. Supported only for non-System offering and system offerings having \"domainrouter\" systemvmtype")
private Integer networkRate; private Integer networkRate;
@Parameter(name = ApiConstants.DEPLOYMENT_PLANNER, type = CommandType.STRING, description = "The deployment planner heuristics used to deploy a VM of this offering. If null, value of global config vm.deployment.planner is used")
private String deploymentPlanner;
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
/////////////////// Accessors /////////////////////// /////////////////// Accessors ///////////////////////
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
@ -148,6 +151,9 @@ public class CreateServiceOfferingCmd extends BaseCmd {
return networkRate; return networkRate;
} }
public String getDeploymentPlanner() {
return deploymentPlanner;
}
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
/////////////// API Implementation/////////////////// /////////////// API Implementation///////////////////

View File

@ -80,6 +80,9 @@ public class CreateNetworkCmd extends BaseCmd {
@Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the ID or VID of the network") @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the ID or VID of the network")
private String vlan; private String vlan;
@Parameter(name=ApiConstants.ISOLATED_PVLAN, type=CommandType.STRING, description="the isolated private vlan for this network")
private String isolatedPvlan;
@Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="network domain") @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="network domain")
private String networkDomain; private String networkDomain;
@ -141,6 +144,10 @@ public class CreateNetworkCmd extends BaseCmd {
return vlan; return vlan;
} }
public String getIsolatedPvlan() {
return isolatedPvlan;
}
public String getAccountName() { public String getAccountName() {
return accountName; return accountName;
} }

View File

@ -95,7 +95,7 @@ public class AssignToGlobalLoadBalancerRuleCmd extends BaseAsyncCmd {
@Override @Override
public String getEventDescription() { public String getEventDescription() {
return "applying load balancer rules " + StringUtils.join(getLoadBalancerRulesIds(), ",") + return "assign load balancer rules " + StringUtils.join(getLoadBalancerRulesIds(), ",") +
" to global load balancer rule " + getGlobalLoadBalancerRuleId(); " to global load balancer rule " + getGlobalLoadBalancerRuleId();
} }

View File

@ -85,7 +85,11 @@ public class CreateGlobalLoadBalancerRuleCmd extends BaseAsyncCreateCmd {
} }
public String getAlgorithm() { public String getAlgorithm() {
return algorithm; if (algorithm != null) {
return algorithm;
} else {
return GlobalLoadBalancerRule.Algorithm.RoundRobin.name();
}
} }
public String getGslbMethod() { public String getGslbMethod() {
@ -158,7 +162,7 @@ public class CreateGlobalLoadBalancerRuleCmd extends BaseAsyncCreateCmd {
@Override @Override
public String getEventDescription() { public String getEventDescription() {
return "creating a global load balancer: " + getName() + " for account: " + getAccountName(); return "creating a global load balancer rule Id: " + getEntityId();
} }

View File

@ -77,12 +77,12 @@ public class DeleteGlobalLoadBalancerRuleCmd extends BaseAsyncCmd {
@Override @Override
public String getEventType() { public String getEventType() {
return EventTypes.EVENT_LOAD_BALANCER_DELETE; return EventTypes.EVENT_GLOBAL_LOAD_BALANCER_DELETE;
} }
@Override @Override
public String getEventDescription() { public String getEventDescription() {
return "deleting global load balancer: " + getGlobalLoadBalancerId(); return "deleting global load balancer rule: " + getGlobalLoadBalancerId();
} }
@Override @Override

View File

@ -17,11 +17,11 @@
package org.apache.cloudstack.api.command.user.region.ha.gslb; package org.apache.cloudstack.api.command.user.region.ha.gslb;
import com.cloud.event.EventTypes;
import com.cloud.region.ha.GlobalLoadBalancerRule;
import com.cloud.region.ha.GlobalLoadBalancingRulesService; import com.cloud.region.ha.GlobalLoadBalancingRulesService;
import org.apache.cloudstack.api.APICommand; import com.cloud.user.Account;
import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.*;
import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse; import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse;
import org.apache.cloudstack.api.response.LoadBalancerResponse; import org.apache.cloudstack.api.response.LoadBalancerResponse;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -29,7 +29,7 @@ import org.apache.log4j.Logger;
import javax.inject.Inject; import javax.inject.Inject;
@APICommand(name = "updateGlobalLoadBalancerRule", description = "update global load balancer rules.", responseObject = LoadBalancerResponse.class) @APICommand(name = "updateGlobalLoadBalancerRule", description = "update global load balancer rules.", responseObject = LoadBalancerResponse.class)
public class UpdateGlobalLoadBalancerRuleCmd extends BaseListTaggedResourcesCmd { public class UpdateGlobalLoadBalancerRuleCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(GlobalLoadBalancerResponse.class.getName()); public static final Logger s_logger = Logger.getLogger(GlobalLoadBalancerResponse.class.getName());
private static final String s_name = "updategloballoadbalancerruleresponse"; private static final String s_name = "updategloballoadbalancerruleresponse";
@ -88,9 +88,27 @@ public class UpdateGlobalLoadBalancerRuleCmd extends BaseListTaggedResourcesCmd
return s_name; return s_name;
} }
@Override
public long getEntityOwnerId() {
GlobalLoadBalancerRule lb = _entityMgr.findById(GlobalLoadBalancerRule.class, getId());
if (lb != null) {
return lb.getAccountId();
}
return Account.ACCOUNT_ID_SYSTEM;
}
@Override @Override
public void execute() { public void execute() {
_gslbService.updateGlobalLoadBalancerRule(this); _gslbService.updateGlobalLoadBalancerRule(this);
} }
@Override
public String getEventType() {
return EventTypes.EVENT_GLOBAL_LOAD_BALANCER_UPDATE;
}
@Override
public String getEventDescription() {
return null;
}
} }

View File

@ -18,6 +18,8 @@ package org.apache.cloudstack.api.response;
import java.util.Date; import java.util.Date;
import javax.persistence.Column;
import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse; import org.apache.cloudstack.api.BaseResponse;
import org.apache.cloudstack.api.EntityReference; import org.apache.cloudstack.api.EntityReference;
@ -82,6 +84,8 @@ public class ServiceOfferingResponse extends BaseResponse {
@SerializedName(ApiConstants.NETWORKRATE) @Param(description="data transfer rate in megabits per second allowed.") @SerializedName(ApiConstants.NETWORKRATE) @Param(description="data transfer rate in megabits per second allowed.")
private Integer networkRate; private Integer networkRate;
@SerializedName(ApiConstants.DEPLOYMENT_PLANNER) @Param(description="deployment strategy used to deploy VM.")
private String deploymentPlanner;
public String getId() { public String getId() {
return id; return id;
@ -225,4 +229,12 @@ public class ServiceOfferingResponse extends BaseResponse {
public void setNetworkRate(Integer networkRate) { public void setNetworkRate(Integer networkRate) {
this.networkRate = networkRate; this.networkRate = networkRate;
} }
public String getDeploymentPlanner() {
return deploymentPlanner;
}
public void setDeploymentPlanner(String deploymentPlanner) {
this.deploymentPlanner = deploymentPlanner;
}
} }

View File

@ -545,15 +545,11 @@
Deployment planners Deployment planners
--> -->
<bean id="UserDispersingPlanner" class="com.cloud.deploy.UserDispersingPlanner"> <bean id="UserDispersingPlanner" class="com.cloud.deploy.UserDispersingPlanner">
<property name="name" value="UserDispersing"/> <property name="name" value="UserDispersingPlanner"/>
<property name="StoragePoolAllocators" value="#{storagePoolAllocators.Adapters}" />
<property name="HostAllocators" value="#{hostAllocators.Adapters}" />
</bean> </bean>
<bean id="UserConcentratedPodPlanner" class="com.cloud.deploy.UserConcentratedPodPlanner"> <bean id="UserConcentratedPodPlanner" class="com.cloud.deploy.UserConcentratedPodPlanner">
<property name="name" value="UserConcentratedPod"/> <property name="name" value="UserConcentratedPodPlanner"/>
<property name="StoragePoolAllocators" value="#{storagePoolAllocators.Adapters}" />
<property name="HostAllocators" value="#{hostAllocators.Adapters}" />
</bean> </bean>
<bean id="clusterBasedAgentLoadBalancerPlanner" class="com.cloud.cluster.agentlb.ClusterBasedAgentLoadBalancerPlanner"> <bean id="clusterBasedAgentLoadBalancerPlanner" class="com.cloud.cluster.agentlb.ClusterBasedAgentLoadBalancerPlanner">
@ -610,10 +606,6 @@
<property name="name" value="OvmGuru"/> <property name="name" value="OvmGuru"/>
</bean> </bean>
<bean id="HypervisorPlannerSelector" class="com.cloud.deploy.HypervisorVmPlannerSelector">
<property name="name" value="HypervisorPlannerSelector"/>
</bean>
<!-- <!--
Managers Managers
--> -->
@ -628,6 +620,7 @@
<property name="UserPasswordEncoders" value="#{userPasswordEncoders.Adapters}" /> <property name="UserPasswordEncoders" value="#{userPasswordEncoders.Adapters}" />
<property name="HostAllocators" value="#{hostAllocators.Adapters}" /> <property name="HostAllocators" value="#{hostAllocators.Adapters}" />
<property name="AffinityGroupProcessors" value="#{affinityProcessors.Adapters}" /> <property name="AffinityGroupProcessors" value="#{affinityProcessors.Adapters}" />
<property name="Planners" value="#{deploymentPlanners.Adapters}" />
</bean> </bean>
<bean id="storageManagerImpl" class="com.cloud.storage.StorageManagerImpl"> <bean id="storageManagerImpl" class="com.cloud.storage.StorageManagerImpl">
@ -635,9 +628,7 @@
</bean> </bean>
<bean id="FirstFitPlanner" class="com.cloud.deploy.FirstFitPlanner"> <bean id="FirstFitPlanner" class="com.cloud.deploy.FirstFitPlanner">
<property name="name" value="First Fit"/> <property name="name" value="FirstFitPlanner"/>
<property name="StoragePoolAllocators" value="#{storagePoolAllocators.Adapters}" />
<property name="HostAllocators" value="#{hostAllocators.Adapters}" />
</bean> </bean>
<bean id="resourceManagerImpl" class="com.cloud.resource.ResourceManagerImpl" > <bean id="resourceManagerImpl" class="com.cloud.resource.ResourceManagerImpl" >
@ -842,17 +833,13 @@
</bean> </bean>
<bean id="BareMetalPlanner" class="com.cloud.baremetal.manager.BareMetalPlanner"> <bean id="BareMetalPlanner" class="com.cloud.baremetal.manager.BareMetalPlanner">
<property name="name" value="BareMetal Fit"/> <property name="name" value="BareMetalPlanner"/>
</bean> </bean>
<bean id="BaremetalGuru" class="com.cloud.baremetal.manager.BareMetalGuru"> <bean id="BaremetalGuru" class="com.cloud.baremetal.manager.BareMetalGuru">
<property name="name" value="BaremetalGuru"/> <property name="name" value="BaremetalGuru"/>
</bean> </bean>
<bean id="BaremetalPlannerSelector" class="com.cloud.baremetal.manager.BaremetalPlannerSelector">
<property name="name" value="BaremetalPlannerSelector"/>
</bean>
<bean id="BaremetalManager" class="com.cloud.baremetal.manager.BaremetalManagerImpl"/> <bean id="BaremetalManager" class="com.cloud.baremetal.manager.BaremetalManagerImpl"/>
<bean id="BaremetalDhcpManager" class="com.cloud.baremetal.networkservice.BaremetalDhcpManagerImpl"/> <bean id="BaremetalDhcpManager" class="com.cloud.baremetal.networkservice.BaremetalDhcpManagerImpl"/>
<bean id="BaremetalKickStartPxeService" class="com.cloud.baremetal.networkservice.BaremetalKickStartServiceImpl"/> <bean id="BaremetalKickStartPxeService" class="com.cloud.baremetal.networkservice.BaremetalKickStartServiceImpl"/>
@ -868,6 +855,8 @@
<bean id="DeploymentPlanningManager" class="com.cloud.deploy.DeploymentPlanningManagerImpl"> <bean id="DeploymentPlanningManager" class="com.cloud.deploy.DeploymentPlanningManagerImpl">
<property name="Planners" value="#{deploymentPlanners.Adapters}" /> <property name="Planners" value="#{deploymentPlanners.Adapters}" />
<property name="AffinityGroupProcessors" value="#{affinityProcessors.Adapters}" /> <property name="AffinityGroupProcessors" value="#{affinityProcessors.Adapters}" />
<property name="StoragePoolAllocators" value="#{storagePoolAllocators.Adapters}" />
<property name="HostAllocators" value="#{hostAllocators.Adapters}" />
</bean> </bean>
<bean id="AffinityGroupJoinDaoImpl" class="com.cloud.api.query.dao.AffinityGroupJoinDaoImpl"> <bean id="AffinityGroupJoinDaoImpl" class="com.cloud.api.query.dao.AffinityGroupJoinDaoImpl">
@ -877,4 +866,7 @@
<bean id="AffinityGroupVMMapDaoImpl" class="org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDaoImpl"> <bean id="AffinityGroupVMMapDaoImpl" class="org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDaoImpl">
</bean> </bean>
<bean id="PlannerHostReservationDaoImpl" class="com.cloud.deploy.dao.PlannerHostReservationDaoImpl">
</bean>
</beans> </beans>

View File

@ -212,6 +212,7 @@ listConfigurations=1
ldapConfig=1 ldapConfig=1
ldapRemove=1 ldapRemove=1
listCapabilities=15 listCapabilities=15
listDeploymentPlanners=1
#### pod commands #### pod commands
createPod=1 createPod=1
@ -267,6 +268,7 @@ listHosts=3
findHostsForMigration=1 findHostsForMigration=1
addSecondaryStorage=1 addSecondaryStorage=1
updateHostPassword=1 updateHostPassword=1
releaseHostReservation=1
#### volume commands #### volume commands
attachVolume=15 attachVolume=15

View File

@ -17,11 +17,13 @@
package com.cloud.agent.api; package com.cloud.agent.api;
import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.NicTO;
import com.cloud.vm.VirtualMachine;
public class PlugNicCommand extends Command { public class PlugNicCommand extends Command {
NicTO nic; NicTO nic;
String instanceName; String instanceName;
VirtualMachine.Type vmType;
public NicTO getNic() { public NicTO getNic() {
return nic; return nic;
@ -35,12 +37,17 @@ public class PlugNicCommand extends Command {
protected PlugNicCommand() { protected PlugNicCommand() {
} }
public PlugNicCommand(NicTO nic, String instanceName) { public PlugNicCommand(NicTO nic, String instanceName, VirtualMachine.Type vmtype) {
this.nic = nic; this.nic = nic;
this.instanceName = instanceName; this.instanceName = instanceName;
this.vmType = vmtype;
} }
public String getVmName() { public String getVmName() {
return instanceName; return instanceName;
} }
public VirtualMachine.Type getVMType() {
return vmType;
}
} }

View File

@ -41,9 +41,9 @@ under the License.
<para>You probably want to ensure that your environment variables will survive a logout/reboot. <para>You probably want to ensure that your environment variables will survive a logout/reboot.
Be sure to update <filename>~/.bashrc</filename> with the PATH and JAVA_HOME variables.</para> Be sure to update <filename>~/.bashrc</filename> with the PATH and JAVA_HOME variables.</para>
<para>Building RPMs for $PRODUCT; is fairly simple. Assuming you already have the source downloaded and have uncompressed the tarball into a local directory, you're going to be able to generate packages in just a few minutes.</para> <para>Building RPMs for &PRODUCT; is fairly simple. Assuming you already have the source downloaded and have uncompressed the tarball into a local directory, you're going to be able to generate packages in just a few minutes.</para>
<note><title>Packaging has Changed</title> <note><title>Packaging has Changed</title>
<para>If you've created packages for $PRODUCT; previously, you should be aware that the process has changed considerably since the project has moved to using Apache Maven. Please be sure to follow the steps in this section closely.</para> <para>If you've created packages for &PRODUCT; previously, you should be aware that the process has changed considerably since the project has moved to using Apache Maven. Please be sure to follow the steps in this section closely.</para>
</note> </note>
<section id="generating-rpms"> <section id="generating-rpms">
<title>Generating RPMS</title> <title>Generating RPMS</title>
@ -69,7 +69,7 @@ under the License.
<title>Configuring your systems to use your new yum repository</title> <title>Configuring your systems to use your new yum repository</title>
<para> <para>
Now that your yum repository is populated with RPMs and metadata Now that your yum repository is populated with RPMs and metadata
we need to configure the machines that need to install $PRODUCT;. we need to configure the machines that need to install &PRODUCT;.
Create a file named <filename>/etc/yum.repos.d/cloudstack.repo</filename> with this information: Create a file named <filename>/etc/yum.repos.d/cloudstack.repo</filename> with this information:
<programlisting> <programlisting>
[apache-cloudstack] [apache-cloudstack]
@ -79,7 +79,7 @@ under the License.
gpgcheck=0 gpgcheck=0
</programlisting> </programlisting>
</para> </para>
<para> Completing this step will allow you to easily install $PRODUCT; on a number of machines across the network. <para> Completing this step will allow you to easily install &PRODUCT; on a number of machines across the network.
</para> </para>
</section> </section>
</section> </section>

View File

@ -49,7 +49,7 @@
multi-node Management Server installation and up to tens of thousands of multi-node Management Server installation and up to tens of thousands of
hosts using any of several advanced networking setups. For hosts using any of several advanced networking setups. For
information about deployment options, see the "Choosing a Deployment Architecture" information about deployment options, see the "Choosing a Deployment Architecture"
section of the $PRODUCT; Installation Guide. section of the &PRODUCT; Installation Guide.
</para> </para>
<xi:include href="management-server-overview.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /> <xi:include href="management-server-overview.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="cloud-infrastructure-overview.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /> <xi:include href="cloud-infrastructure-overview.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />

View File

@ -24,7 +24,7 @@
<para>Event notification framework provides a means for the Management Server components to <para>Event notification framework provides a means for the Management Server components to
publish and subscribe to &PRODUCT; events. Event notification is achieved by implementing the publish and subscribe to &PRODUCT; events. Event notification is achieved by implementing the
concept of event bus abstraction in the Management Server. An event bus is introduced in the concept of event bus abstraction in the Management Server. An event bus is introduced in the
Management Server that allows the &PRODUCT;components and extension plug-ins to subscribe to the Management Server that allows the &PRODUCT; components and extension plug-ins to subscribe to the
events by using the Advanced Message Queuing Protocol (AMQP) client. In &PRODUCT;, a default events by using the Advanced Message Queuing Protocol (AMQP) client. In &PRODUCT;, a default
implementation of event bus is provided as a plug-in that uses the RabbitMQ AMQP client. The implementation of event bus is provided as a plug-in that uses the RabbitMQ AMQP client. The
AMQP client pushes the published events to a compatible AMQP server. Therefore all the &PRODUCT; AMQP client pushes the published events to a compatible AMQP server. Therefore all the &PRODUCT;

View File

@ -45,7 +45,7 @@
<para>A typical GSLB environment is comprised of the following components:</para> <para>A typical GSLB environment is comprised of the following components:</para>
<itemizedlist> <itemizedlist>
<listitem> <listitem>
<para><emphasis role="bold">GSLB Site</emphasis>: In &PRODUCT;terminology, GSLB sites are <para><emphasis role="bold">GSLB Site</emphasis>: In &PRODUCT; terminology, GSLB sites are
represented by zones that are mapped to data centers, each of which has various network represented by zones that are mapped to data centers, each of which has various network
appliances. Each GSLB site is managed by a NetScaler appliance that is local to that appliances. Each GSLB site is managed by a NetScaler appliance that is local to that
site. Each of these appliances treats its own site as the local site and all other site. Each of these appliances treats its own site as the local site and all other

View File

@ -21,7 +21,7 @@
--> -->
<section id="ipv6-support"> <section id="ipv6-support">
<title>IPv6 Support in &PRODUCT;</title> <title>IPv6 Support in &PRODUCT;</title>
<para>&PRODUCT;supports Internet Protocol version 6 (IPv6), the recent version of the Internet <para>&PRODUCT; supports Internet Protocol version 6 (IPv6), the recent version of the Internet
Protocol (IP) that defines routing the network traffic. IPv6 uses a 128-bit address that Protocol (IP) that defines routing the network traffic. IPv6 uses a 128-bit address that
exponentially expands the current address space that is available to the users. IPv6 addresses exponentially expands the current address space that is available to the users. IPv6 addresses
consist of eight groups of four hexadecimal digits separated by colons, for example, consist of eight groups of four hexadecimal digits separated by colons, for example,

View File

@ -21,7 +21,7 @@
--> -->
<section id="vmware-cluster-config-dvswitch"> <section id="vmware-cluster-config-dvswitch">
<title>Configuring a vSphere Cluster with VMware Distributed Virtual Switch</title> <title>Configuring a vSphere Cluster with VMware Distributed Virtual Switch</title>
<para>&PRODUCT;supports VMware vNetwork Distributed Switch (VDS) for virtual network configuration <para>&PRODUCT; supports VMware vNetwork Distributed Switch (VDS) for virtual network configuration
in a VMware vSphere environment. This section helps you configure VMware VDS in a &PRODUCT; in a VMware vSphere environment. This section helps you configure VMware VDS in a &PRODUCT;
deployment. Each vCenter server instance can support up to 128 VDS instances and each VDS deployment. Each vCenter server instance can support up to 128 VDS instances and each VDS
instance can manage up to 500 VMware hosts.</para> instance can manage up to 500 VMware hosts.</para>

View File

@ -16,6 +16,8 @@
// under the License. // under the License.
package org.apache.cloudstack.engine.datacenter.entity.api.db.dao; package org.apache.cloudstack.engine.datacenter.entity.api.db.dao;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -30,18 +32,19 @@ import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction; import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
@Component(value="EngineHostDetailsDao") @Component(value="EngineHostDetailsDao")
@Local(value=HostDetailsDao.class) @Local(value=HostDetailsDao.class)
public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implements HostDetailsDao { public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implements HostDetailsDao {
protected final SearchBuilder<DetailVO> HostSearch; protected final SearchBuilder<DetailVO> HostSearch;
protected final SearchBuilder<DetailVO> DetailSearch; protected final SearchBuilder<DetailVO> DetailSearch;
public HostDetailsDaoImpl() { public HostDetailsDaoImpl() {
HostSearch = createSearchBuilder(); HostSearch = createSearchBuilder();
HostSearch.and("hostId", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ); HostSearch.and("hostId", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ);
HostSearch.done(); HostSearch.done();
DetailSearch = createSearchBuilder(); DetailSearch = createSearchBuilder();
DetailSearch.and("hostId", DetailSearch.entity().getHostId(), SearchCriteria.Op.EQ); DetailSearch.and("hostId", DetailSearch.entity().getHostId(), SearchCriteria.Op.EQ);
DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ); DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ);
@ -53,7 +56,7 @@ public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implement
SearchCriteria<DetailVO> sc = DetailSearch.create(); SearchCriteria<DetailVO> sc = DetailSearch.create();
sc.setParameters("hostId", hostId); sc.setParameters("hostId", hostId);
sc.setParameters("name", name); sc.setParameters("name", name);
DetailVO detail = findOneIncludingRemovedBy(sc); DetailVO detail = findOneIncludingRemovedBy(sc);
if("password".equals(name) && detail != null){ if("password".equals(name) && detail != null){
detail.setValue(DBEncryptionUtil.decrypt(detail.getValue())); detail.setValue(DBEncryptionUtil.decrypt(detail.getValue()));
@ -65,7 +68,7 @@ public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implement
public Map<String, String> findDetails(long hostId) { public Map<String, String> findDetails(long hostId) {
SearchCriteria<DetailVO> sc = HostSearch.create(); SearchCriteria<DetailVO> sc = HostSearch.create();
sc.setParameters("hostId", hostId); sc.setParameters("hostId", hostId);
List<DetailVO> results = search(sc, null); List<DetailVO> results = search(sc, null);
Map<String, String> details = new HashMap<String, String>(results.size()); Map<String, String> details = new HashMap<String, String>(results.size());
for (DetailVO result : results) { for (DetailVO result : results) {
@ -77,12 +80,12 @@ public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implement
} }
return details; return details;
} }
@Override @Override
public void deleteDetails(long hostId) { public void deleteDetails(long hostId) {
SearchCriteria sc = HostSearch.create(); SearchCriteria sc = HostSearch.create();
sc.setParameters("hostId", hostId); sc.setParameters("hostId", hostId);
List<DetailVO> results = search(sc, null); List<DetailVO> results = search(sc, null);
for (DetailVO result : results) { for (DetailVO result : results) {
remove(result.getId()); remove(result.getId());
@ -91,19 +94,27 @@ public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implement
@Override @Override
public void persist(long hostId, Map<String, String> details) { public void persist(long hostId, Map<String, String> details) {
final String InsertOrUpdateSql = "INSERT INTO `cloud`.`host_details` (host_id, name, value) VALUES (?,?,?) ON DUPLICATE KEY UPDATE value=?";
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
txn.start(); txn.start();
SearchCriteria<DetailVO> sc = HostSearch.create();
sc.setParameters("hostId", hostId);
expunge(sc);
for (Map.Entry<String, String> detail : details.entrySet()) { for (Map.Entry<String, String> detail : details.entrySet()) {
String value = detail.getValue(); String value = detail.getValue();
if("password".equals(detail.getKey())){ if ("password".equals(detail.getKey())) {
value = DBEncryptionUtil.encrypt(value); value = DBEncryptionUtil.encrypt(value);
} }
DetailVO vo = new DetailVO(hostId, detail.getKey(), value); try {
persist(vo); PreparedStatement pstmt = txn.prepareAutoCloseStatement(InsertOrUpdateSql);
pstmt.setLong(1, hostId);
pstmt.setString(2, detail.getKey());
pstmt.setString(3, value);
pstmt.setString(4, value);
pstmt.executeUpdate();
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to persist the host_details key: " + detail.getKey()
+ " for host id: " + hostId, e);
}
} }
txn.commit(); txn.commit();
} }

View File

@ -16,6 +16,8 @@
// under the License. // under the License.
package com.cloud.host.dao; package com.cloud.host.dao;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -30,18 +32,19 @@ import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction; import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
@Component @Component
@Local(value=HostDetailsDao.class) @Local(value=HostDetailsDao.class)
public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implements HostDetailsDao { public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implements HostDetailsDao {
protected final SearchBuilder<DetailVO> HostSearch; protected final SearchBuilder<DetailVO> HostSearch;
protected final SearchBuilder<DetailVO> DetailSearch; protected final SearchBuilder<DetailVO> DetailSearch;
public HostDetailsDaoImpl() { public HostDetailsDaoImpl() {
HostSearch = createSearchBuilder(); HostSearch = createSearchBuilder();
HostSearch.and("hostId", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ); HostSearch.and("hostId", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ);
HostSearch.done(); HostSearch.done();
DetailSearch = createSearchBuilder(); DetailSearch = createSearchBuilder();
DetailSearch.and("hostId", DetailSearch.entity().getHostId(), SearchCriteria.Op.EQ); DetailSearch.and("hostId", DetailSearch.entity().getHostId(), SearchCriteria.Op.EQ);
DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ); DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ);
@ -53,7 +56,7 @@ public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implement
SearchCriteria<DetailVO> sc = DetailSearch.create(); SearchCriteria<DetailVO> sc = DetailSearch.create();
sc.setParameters("hostId", hostId); sc.setParameters("hostId", hostId);
sc.setParameters("name", name); sc.setParameters("name", name);
DetailVO detail = findOneIncludingRemovedBy(sc); DetailVO detail = findOneIncludingRemovedBy(sc);
if("password".equals(name) && detail != null){ if("password".equals(name) && detail != null){
detail.setValue(DBEncryptionUtil.decrypt(detail.getValue())); detail.setValue(DBEncryptionUtil.decrypt(detail.getValue()));
@ -65,7 +68,7 @@ public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implement
public Map<String, String> findDetails(long hostId) { public Map<String, String> findDetails(long hostId) {
SearchCriteria<DetailVO> sc = HostSearch.create(); SearchCriteria<DetailVO> sc = HostSearch.create();
sc.setParameters("hostId", hostId); sc.setParameters("hostId", hostId);
List<DetailVO> results = search(sc, null); List<DetailVO> results = search(sc, null);
Map<String, String> details = new HashMap<String, String>(results.size()); Map<String, String> details = new HashMap<String, String>(results.size());
for (DetailVO result : results) { for (DetailVO result : results) {
@ -77,12 +80,12 @@ public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implement
} }
return details; return details;
} }
@Override @Override
public void deleteDetails(long hostId) { public void deleteDetails(long hostId) {
SearchCriteria sc = HostSearch.create(); SearchCriteria sc = HostSearch.create();
sc.setParameters("hostId", hostId); sc.setParameters("hostId", hostId);
List<DetailVO> results = search(sc, null); List<DetailVO> results = search(sc, null);
for (DetailVO result : results) { for (DetailVO result : results) {
remove(result.getId()); remove(result.getId());
@ -91,19 +94,27 @@ public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implement
@Override @Override
public void persist(long hostId, Map<String, String> details) { public void persist(long hostId, Map<String, String> details) {
final String InsertOrUpdateSql = "INSERT INTO `cloud`.`host_details` (host_id, name, value) VALUES (?,?,?) ON DUPLICATE KEY UPDATE value=?";
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
txn.start(); txn.start();
SearchCriteria<DetailVO> sc = HostSearch.create();
sc.setParameters("hostId", hostId);
expunge(sc);
for (Map.Entry<String, String> detail : details.entrySet()) { for (Map.Entry<String, String> detail : details.entrySet()) {
String value = detail.getValue(); String value = detail.getValue();
if("password".equals(detail.getKey())){ if ("password".equals(detail.getKey())) {
value = DBEncryptionUtil.encrypt(value); value = DBEncryptionUtil.encrypt(value);
} }
DetailVO vo = new DetailVO(hostId, detail.getKey(), value); try {
persist(vo); PreparedStatement pstmt = txn.prepareAutoCloseStatement(InsertOrUpdateSql);
pstmt.setLong(1, hostId);
pstmt.setString(2, detail.getKey());
pstmt.setString(3, value);
pstmt.setString(4, value);
pstmt.executeUpdate();
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to persist the host_details key: " + detail.getKey()
+ " for host id: " + hostId, e);
}
} }
txn.commit(); txn.commit();
} }

View File

@ -174,5 +174,10 @@ public class ServiceOffering21VO extends DiskOffering21VO implements ServiceOffe
return false; return false;
} }
@Override
public String getDeploymentPlanner() {
// TODO Auto-generated method stub
return null;
}
} }

View File

@ -113,4 +113,6 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long> , StateDao<State
List<NetworkVO> listRedundantNetworks(); List<NetworkVO> listRedundantNetworks();
List<NetworkVO> listByAclId(long aclId); List<NetworkVO> listByAclId(long aclId);
int getNonSystemNetworkCountByVpcId(long vpcId);
} }

View File

@ -162,6 +162,9 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
CountBy.and("offeringId", CountBy.entity().getNetworkOfferingId(), Op.EQ); CountBy.and("offeringId", CountBy.entity().getNetworkOfferingId(), Op.EQ);
CountBy.and("vpcId", CountBy.entity().getVpcId(), Op.EQ); CountBy.and("vpcId", CountBy.entity().getVpcId(), Op.EQ);
CountBy.and("removed", CountBy.entity().getRemoved(), Op.NULL); CountBy.and("removed", CountBy.entity().getRemoved(), Op.NULL);
SearchBuilder<NetworkOfferingVO> ntwkOffJoin = _ntwkOffDao.createSearchBuilder();
ntwkOffJoin.and("isSystem", ntwkOffJoin.entity().isSystemOnly(), Op.EQ);
CountBy.join("offerings", ntwkOffJoin, CountBy.entity().getNetworkOfferingId(), ntwkOffJoin.entity().getId(), JoinBuilder.JoinType.INNER);
CountBy.done(); CountBy.done();
PhysicalNetworkSearch = createSearchBuilder(); PhysicalNetworkSearch = createSearchBuilder();
@ -627,4 +630,14 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
return listBy(sc, null); return listBy(sc, null);
} }
@Override
public int getNonSystemNetworkCountByVpcId(long vpcId) {
SearchCriteria<Integer> sc = CountBy.create();
sc.setParameters("vpcId", vpcId);
sc.setJoinParameters("offerings", "isSystem", false);
List<Integer> results = customSearch(sc, null);
return results.get(0);
}
} }

View File

@ -68,6 +68,9 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
@Column(name="sort_key") @Column(name="sort_key")
int sortKey; int sortKey;
@Column(name = "deployment_planner")
private String deploymentPlanner = null;
protected ServiceOfferingVO() { protected ServiceOfferingVO() {
super(); super();
} }
@ -104,6 +107,15 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
this.hostTag = hostTag; this.hostTag = hostTag;
} }
public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, Integer rateMbps, Integer multicastRateMbps,
boolean offerHA, boolean limitResourceUse, boolean volatileVm, String displayText, boolean useLocalStorage,
boolean recreatable, String tags, boolean systemUse, VirtualMachine.Type vm_type, Long domainId,
String hostTag, String deploymentPlanner) {
this(name, cpu, ramSize, speed, rateMbps, multicastRateMbps, offerHA, limitResourceUse, volatileVm,
displayText, useLocalStorage, recreatable, tags, systemUse, vm_type, domainId, hostTag);
this.deploymentPlanner = deploymentPlanner;
}
@Override @Override
public boolean getOfferHA() { public boolean getOfferHA() {
return offerHA; return offerHA;
@ -208,4 +220,9 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
return volatileVm; return volatileVm;
} }
@Override
public String getDeploymentPlanner() {
return deploymentPlanner;
}
} }

View File

@ -17,6 +17,10 @@
package com.cloud.upgrade.dao; package com.cloud.upgrade.dao;
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.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.Date; import java.sql.Date;
@ -25,12 +29,7 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import java.util.UUID; import java.util.UUID;
import com.cloud.network.vpc.NetworkACL; import com.cloud.network.vpc.NetworkACL;
import org.apache.log4j.Logger;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
public class Upgrade410to420 implements DbUpgrade { public class Upgrade410to420 implements DbUpgrade {
final static Logger s_logger = Logger.getLogger(Upgrade410to420.class); final static Logger s_logger = Logger.getLogger(Upgrade410to420.class);
@ -70,9 +69,12 @@ public class Upgrade410to420 implements DbUpgrade {
updatePrimaryStore(conn); updatePrimaryStore(conn);
addEgressFwRulesForSRXGuestNw(conn); addEgressFwRulesForSRXGuestNw(conn);
upgradeEIPNetworkOfferings(conn); upgradeEIPNetworkOfferings(conn);
updateGlobalDeploymentPlanner(conn);
upgradeDefaultVpcOffering(conn); upgradeDefaultVpcOffering(conn);
upgradePhysicalNtwksWithInternalLbProvider(conn); upgradePhysicalNtwksWithInternalLbProvider(conn);
updateNetworkACLs(conn); updateNetworkACLs(conn);
addHostDetailsIndex(conn);
updateNetworksForPrivateGateways(conn);
} }
private void updateSystemVmTemplates(Connection conn) { private void updateSystemVmTemplates(Connection conn) {
@ -562,10 +564,56 @@ public class Upgrade410to420 implements DbUpgrade {
} }
} }
} }
private void upgradeDefaultVpcOffering(Connection conn) {
private void updateGlobalDeploymentPlanner(Connection conn) {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn
.prepareStatement("select value from `cloud`.`configuration` where name = 'vm.allocation.algorithm'");
rs = pstmt.executeQuery();
while (rs.next()) {
String globalValue = rs.getString(1);
String plannerName = "FirstFitPlanner";
if (globalValue != null) {
if (globalValue.equals(DeploymentPlanner.AllocationAlgorithm.random.toString())) {
plannerName = "FirstFitPlanner";
} else if (globalValue.equals(DeploymentPlanner.AllocationAlgorithm.firstfit.toString())) {
plannerName = "FirstFitPlanner";
} else if (globalValue.equals(DeploymentPlanner.AllocationAlgorithm.userconcentratedpod_firstfit
.toString())) {
plannerName = "UserConcentratedPodPlanner";
} else if (globalValue.equals(DeploymentPlanner.AllocationAlgorithm.userconcentratedpod_random
.toString())) {
plannerName = "UserConcentratedPodPlanner";
} else if (globalValue.equals(DeploymentPlanner.AllocationAlgorithm.userdispersing.toString())) {
plannerName = "UserDispersingPlanner";
}
}
// update vm.deployment.planner global config
pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` set value=? where name = 'vm.deployment.planner'");
pstmt.setString(1, plannerName);
pstmt.executeUpdate();
}
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to set vm.deployment.planner global config", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
}
}
private void upgradeDefaultVpcOffering(Connection conn) {
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -581,7 +629,7 @@ public class Upgrade410to420 implements DbUpgrade {
pstmt.setString(3, "InternalLbVm"); pstmt.setString(3, "InternalLbVm");
pstmt.executeUpdate(); pstmt.executeUpdate();
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new CloudRuntimeException("Unable update the default VPC offering with the internal lb service", e); throw new CloudRuntimeException("Unable update the default VPC offering with the internal lb service", e);
} finally { } finally {
@ -596,9 +644,7 @@ public class Upgrade410to420 implements DbUpgrade {
} }
} }
} }
private void upgradePhysicalNtwksWithInternalLbProvider(Connection conn) { private void upgradePhysicalNtwksWithInternalLbProvider(Connection conn) {
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
@ -617,7 +663,7 @@ public class Upgrade410to420 implements DbUpgrade {
pstmt.setString(1, uuid); pstmt.setString(1, uuid);
pstmt.setLong(2, pNtwkId); pstmt.setLong(2, pNtwkId);
pstmt.executeUpdate(); pstmt.executeUpdate();
//Add internal lb vm to the list of physical network elements //Add internal lb vm to the list of physical network elements
PreparedStatement pstmt1 = conn.prepareStatement("SELECT id FROM `cloud`.`physical_network_service_providers`" + PreparedStatement pstmt1 = conn.prepareStatement("SELECT id FROM `cloud`.`physical_network_service_providers`" +
" WHERE physical_network_id=? AND provider_name='InternalLbVm'"); " WHERE physical_network_id=? AND provider_name='InternalLbVm'");
@ -631,7 +677,7 @@ public class Upgrade410to420 implements DbUpgrade {
pstmt1.executeUpdate(); pstmt1.executeUpdate();
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new CloudRuntimeException("Unable existing physical networks with internal lb provider", e); throw new CloudRuntimeException("Unable existing physical networks with internal lb provider", e);
} finally { } finally {
@ -645,6 +691,62 @@ public class Upgrade410to420 implements DbUpgrade {
} catch (SQLException e) { } catch (SQLException e) {
} }
} }
}
private void addHostDetailsIndex(Connection conn) {
s_logger.debug("Checking if host_details index exists, if not we will add it");
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement("SHOW INDEX FROM `cloud`.`host_details` where KEY_NAME = 'fk_host_details__host_id'");
rs = pstmt.executeQuery();
if (rs.next()) {
s_logger.debug("Index already exists on host_details - not adding new one");
} else {
// add the index
PreparedStatement pstmtUpdate = conn.prepareStatement("ALTER IGNORE TABLE `cloud`.`host_details` ADD INDEX `fk_host_details__host_id` (`host_id`)");
pstmtUpdate.executeUpdate();
s_logger.debug("Index did not exist on host_details - added new one");
pstmtUpdate.close();
}
} catch (SQLException e) {
throw new CloudRuntimeException("Failed to check/update the host_details index ", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
}
}
private void updateNetworksForPrivateGateways(Connection conn) {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
//1) get all non removed gateways
pstmt = conn.prepareStatement("SELECT network_id, vpc_id FROM `cloud`.`vpc_gateways` WHERE type='Private' AND removed IS null");
rs = pstmt.executeQuery();
while (rs.next()) {
Long networkId = rs.getLong(1);
Long vpcId = rs.getLong(2);
//2) Update networks with vpc_id if its set to NULL
pstmt = conn.prepareStatement("UPDATE `cloud`.`networks` set vpc_id=? where id=? and vpc_id is NULL and removed is NULL");
pstmt.setLong(1, vpcId);
pstmt.setLong(2, networkId);
pstmt.executeUpdate();
}
} catch (SQLException e) {
throw new CloudRuntimeException("Failed to update private networks with VPC id.", e);
}
} }
} }

View File

@ -118,18 +118,18 @@ public class UsageNetworkOfferingDaoImpl extends GenericDaoBase<UsageNetworkOffe
ResultSet rs = pstmt.executeQuery(); ResultSet rs = pstmt.executeQuery();
while (rs.next()) { while (rs.next()) {
//zoneId, account_id, domain_id, vm_instance_id, network_offering_id, is_default, created, deleted //zoneId, account_id, domain_id, vm_instance_id, network_offering_id, nic_id, is_default, created, deleted
Long zoneId = Long.valueOf(rs.getLong(1)); Long zoneId = Long.valueOf(rs.getLong(1));
Long acctId = Long.valueOf(rs.getLong(2)); Long acctId = Long.valueOf(rs.getLong(2));
Long dId = Long.valueOf(rs.getLong(3)); Long dId = Long.valueOf(rs.getLong(3));
long vmId = Long.valueOf(rs.getLong(4)); long vmId = Long.valueOf(rs.getLong(4));
long noId = Long.valueOf(rs.getLong(5)); long noId = Long.valueOf(rs.getLong(5));
long nicId = Long.valueOf(rs.getLong(6)); long nicId = Long.valueOf(rs.getLong(6));
boolean isDefault = Boolean.valueOf(rs.getBoolean(6)); boolean isDefault = Boolean.valueOf(rs.getBoolean(7));
Date createdDate = null; Date createdDate = null;
Date deletedDate = null; Date deletedDate = null;
String createdTS = rs.getString(7); String createdTS = rs.getString(8);
String deletedTS = rs.getString(8); String deletedTS = rs.getString(9);
if (createdTS != null) { if (createdTS != null) {

View File

@ -38,14 +38,14 @@ public interface VMInstanceDao extends GenericDao<VMInstanceVO, Long>, StateDao<
* @return list of VMInstanceVO running on that host. * @return list of VMInstanceVO running on that host.
*/ */
List<VMInstanceVO> listByHostId(long hostId); List<VMInstanceVO> listByHostId(long hostId);
/** /**
* List VMs by zone ID * List VMs by zone ID
* @param zoneId * @param zoneId
* @return list of VMInstanceVO in the specified zone * @return list of VMInstanceVO in the specified zone
*/ */
List<VMInstanceVO> listByZoneId(long zoneId); List<VMInstanceVO> listByZoneId(long zoneId);
/** /**
* List VMs by pod ID * List VMs by pod ID
* @param podId * @param podId
@ -59,32 +59,32 @@ public interface VMInstanceDao extends GenericDao<VMInstanceVO, Long>, StateDao<
* @return list of VMInstanceVO in the specified zone, deployed from the specified template, that are not expunged * @return list of VMInstanceVO in the specified zone, deployed from the specified template, that are not expunged
*/ */
public List<VMInstanceVO> listNonExpungedByZoneAndTemplate(long zoneId, long templateId); public List<VMInstanceVO> listNonExpungedByZoneAndTemplate(long zoneId, long templateId);
/** /**
* Find vm instance with names like. * Find vm instance with names like.
* *
* @param name name that fits SQL like. * @param name name that fits SQL like.
* @return list of VMInstanceVO * @return list of VMInstanceVO
*/ */
List<VMInstanceVO> findVMInstancesLike(String name); List<VMInstanceVO> findVMInstancesLike(String name);
List<VMInstanceVO> findVMInTransition(Date time, State... states); List<VMInstanceVO> findVMInTransition(Date time, State... states);
List<VMInstanceVO> listByTypes(VirtualMachine.Type... types); List<VMInstanceVO> listByTypes(VirtualMachine.Type... types);
VMInstanceVO findByIdTypes(long id, VirtualMachine.Type... types); VMInstanceVO findByIdTypes(long id, VirtualMachine.Type... types);
VMInstanceVO findVMByInstanceName(String name); VMInstanceVO findVMByInstanceName(String name);
void updateProxyId(long id, Long proxyId, Date time); void updateProxyId(long id, Long proxyId, Date time);
List<VMInstanceVO> listByHostIdTypes(long hostid, VirtualMachine.Type... types); List<VMInstanceVO> listByHostIdTypes(long hostid, VirtualMachine.Type... types);
List<VMInstanceVO> listUpByHostIdTypes(long hostid, VirtualMachine.Type... types); List<VMInstanceVO> listUpByHostIdTypes(long hostid, VirtualMachine.Type... types);
List<VMInstanceVO> listByZoneIdAndType(long zoneId, VirtualMachine.Type type); List<VMInstanceVO> listByZoneIdAndType(long zoneId, VirtualMachine.Type type);
List<VMInstanceVO> listUpByHostId(Long hostId); List<VMInstanceVO> listUpByHostId(Long hostId);
List<VMInstanceVO> listByLastHostId(Long hostId); List<VMInstanceVO> listByLastHostId(Long hostId);
List<VMInstanceVO> listByTypeAndState(VirtualMachine.Type type, State state); List<VMInstanceVO> listByTypeAndState(VirtualMachine.Type type, State state);
List<VMInstanceVO> listByAccountId(long accountId); List<VMInstanceVO> listByAccountId(long accountId);
@ -92,9 +92,9 @@ public interface VMInstanceDao extends GenericDao<VMInstanceVO, Long>, StateDao<
List<VMInstanceVO> listByClusterId(long clusterId); // this does not pull up VMs which are starting List<VMInstanceVO> listByClusterId(long clusterId); // this does not pull up VMs which are starting
List<VMInstanceVO> listLHByClusterId(long clusterId); // get all the VMs even starting one on this cluster List<VMInstanceVO> listLHByClusterId(long clusterId); // get all the VMs even starting one on this cluster
List<VMInstanceVO> listVmsMigratingFromHost(Long hostId); List<VMInstanceVO> listVmsMigratingFromHost(Long hostId);
public Long countRunningByHostId(long hostId); public Long countRunningByHostId(long hostId);
Pair<List<Long>, Map<Long, Double>> listClusterIdsInZoneByVmCount(long zoneId, long accountId); Pair<List<Long>, Map<Long, Double>> listClusterIdsInZoneByVmCount(long zoneId, long accountId);
@ -106,7 +106,7 @@ public interface VMInstanceDao extends GenericDao<VMInstanceVO, Long>, StateDao<
List<Long> listHostIdsByVmCount(long dcId, Long podId, Long clusterId, long accountId); List<Long> listHostIdsByVmCount(long dcId, Long podId, Long clusterId, long accountId);
Long countRunningByAccount(long accountId); Long countRunningByAccount(long accountId);
List<VMInstanceVO> listNonRemovedVmsByTypeAndNetwork(long networkId, VirtualMachine.Type... types); List<VMInstanceVO> listNonRemovedVmsByTypeAndNetwork(long networkId, VirtualMachine.Type... types);
/** /**
@ -116,4 +116,8 @@ public interface VMInstanceDao extends GenericDao<VMInstanceVO, Long>, StateDao<
*/ */
List<String> listDistinctHostNames(long networkId, VirtualMachine.Type... types); List<String> listDistinctHostNames(long networkId, VirtualMachine.Type... types);
List<VMInstanceVO> findByHostInStates(Long hostId, State... states);
List<VMInstanceVO> listStartingWithNoHostId();
} }

View File

@ -5,7 +5,7 @@
// to you under the Apache License, Version 2.0 (the // to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance // "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at // with the License. You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, // Unless required by applicable law or agreed to in writing,
@ -83,30 +83,32 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
protected GenericSearchBuilder<VMInstanceVO, Long> CountRunningByAccount; protected GenericSearchBuilder<VMInstanceVO, Long> CountRunningByAccount;
protected SearchBuilder<VMInstanceVO> NetworkTypeSearch; protected SearchBuilder<VMInstanceVO> NetworkTypeSearch;
protected GenericSearchBuilder<VMInstanceVO, String> DistinctHostNameSearch; protected GenericSearchBuilder<VMInstanceVO, String> DistinctHostNameSearch;
protected SearchBuilder<VMInstanceVO> HostAndStateSearch;
protected SearchBuilder<VMInstanceVO> StartingWithNoHostSearch;
@Inject ResourceTagDao _tagsDao; @Inject ResourceTagDao _tagsDao;
@Inject NicDao _nicDao; @Inject NicDao _nicDao;
protected Attribute _updateTimeAttr; protected Attribute _updateTimeAttr;
private static final String ORDER_CLUSTERS_NUMBER_OF_VMS_FOR_ACCOUNT_PART1 = private static final String ORDER_CLUSTERS_NUMBER_OF_VMS_FOR_ACCOUNT_PART1 =
"SELECT host.cluster_id, SUM(IF(vm.state='Running' AND vm.account_id = ?, 1, 0)) FROM `cloud`.`host` host LEFT JOIN `cloud`.`vm_instance` vm ON host.id = vm.host_id WHERE "; "SELECT host.cluster_id, SUM(IF(vm.state='Running' AND vm.account_id = ?, 1, 0)) FROM `cloud`.`host` host LEFT JOIN `cloud`.`vm_instance` vm ON host.id = vm.host_id WHERE ";
private static final String ORDER_CLUSTERS_NUMBER_OF_VMS_FOR_ACCOUNT_PART2 = private static final String ORDER_CLUSTERS_NUMBER_OF_VMS_FOR_ACCOUNT_PART2 =
" AND host.type = 'Routing' GROUP BY host.cluster_id ORDER BY 2 ASC "; " AND host.type = 'Routing' GROUP BY host.cluster_id ORDER BY 2 ASC ";
private static final String ORDER_PODS_NUMBER_OF_VMS_FOR_ACCOUNT = "SELECT pod.id, SUM(IF(vm.state='Running' AND vm.account_id = ?, 1, 0)) FROM `cloud`.`host_pod_ref` pod LEFT JOIN `cloud`.`vm_instance` vm ON pod.id = vm.pod_id WHERE pod.data_center_id = ? " + private static final String ORDER_PODS_NUMBER_OF_VMS_FOR_ACCOUNT = "SELECT pod.id, SUM(IF(vm.state='Running' AND vm.account_id = ?, 1, 0)) FROM `cloud`.`host_pod_ref` pod LEFT JOIN `cloud`.`vm_instance` vm ON pod.id = vm.pod_id WHERE pod.data_center_id = ? " +
" GROUP BY pod.id ORDER BY 2 ASC "; " GROUP BY pod.id ORDER BY 2 ASC ";
private static final String ORDER_HOSTS_NUMBER_OF_VMS_FOR_ACCOUNT = private static final String ORDER_HOSTS_NUMBER_OF_VMS_FOR_ACCOUNT =
"SELECT host.id, SUM(IF(vm.state='Running' AND vm.account_id = ?, 1, 0)) FROM `cloud`.`host` host LEFT JOIN `cloud`.`vm_instance` vm ON host.id = vm.host_id WHERE host.data_center_id = ? " + "SELECT host.id, SUM(IF(vm.state='Running' AND vm.account_id = ?, 1, 0)) FROM `cloud`.`host` host LEFT JOIN `cloud`.`vm_instance` vm ON host.id = vm.host_id WHERE host.data_center_id = ? " +
" AND host.pod_id = ? AND host.cluster_id = ? AND host.type = 'Routing' " + " AND host.pod_id = ? AND host.cluster_id = ? AND host.type = 'Routing' " +
" GROUP BY host.id ORDER BY 2 ASC "; " GROUP BY host.id ORDER BY 2 ASC ";
@Inject protected HostDao _hostDao; @Inject protected HostDao _hostDao;
public VMInstanceDaoImpl() { public VMInstanceDaoImpl() {
} }
@PostConstruct @PostConstruct
protected void init() { protected void init() {
@ -114,14 +116,14 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
IdStatesSearch.and("id", IdStatesSearch.entity().getId(), Op.EQ); IdStatesSearch.and("id", IdStatesSearch.entity().getId(), Op.EQ);
IdStatesSearch.and("states", IdStatesSearch.entity().getState(), Op.IN); IdStatesSearch.and("states", IdStatesSearch.entity().getState(), Op.IN);
IdStatesSearch.done(); IdStatesSearch.done();
VMClusterSearch = createSearchBuilder(); VMClusterSearch = createSearchBuilder();
SearchBuilder<HostVO> hostSearch = _hostDao.createSearchBuilder(); SearchBuilder<HostVO> hostSearch = _hostDao.createSearchBuilder();
VMClusterSearch.join("hostSearch", hostSearch, hostSearch.entity().getId(), VMClusterSearch.entity().getHostId(), JoinType.INNER); VMClusterSearch.join("hostSearch", hostSearch, hostSearch.entity().getId(), VMClusterSearch.entity().getHostId(), JoinType.INNER);
hostSearch.and("clusterId", hostSearch.entity().getClusterId(), SearchCriteria.Op.EQ); hostSearch.and("clusterId", hostSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
VMClusterSearch.done(); VMClusterSearch.done();
LHVMClusterSearch = createSearchBuilder(); LHVMClusterSearch = createSearchBuilder();
SearchBuilder<HostVO> hostSearch1 = _hostDao.createSearchBuilder(); SearchBuilder<HostVO> hostSearch1 = _hostDao.createSearchBuilder();
LHVMClusterSearch.join("hostSearch1", hostSearch1, hostSearch1.entity().getId(), LHVMClusterSearch.entity().getLastHostId(), JoinType.INNER); LHVMClusterSearch.join("hostSearch1", hostSearch1, hostSearch1.entity().getId(), LHVMClusterSearch.entity().getLastHostId(), JoinType.INNER);
@ -129,7 +131,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
hostSearch1.and("clusterId", hostSearch1.entity().getClusterId(), SearchCriteria.Op.EQ); hostSearch1.and("clusterId", hostSearch1.entity().getClusterId(), SearchCriteria.Op.EQ);
LHVMClusterSearch.done(); LHVMClusterSearch.done();
AllFieldsSearch = createSearchBuilder(); AllFieldsSearch = createSearchBuilder();
AllFieldsSearch.and("host", AllFieldsSearch.entity().getHostId(), Op.EQ); AllFieldsSearch.and("host", AllFieldsSearch.entity().getHostId(), Op.EQ);
AllFieldsSearch.and("lastHost", AllFieldsSearch.entity().getLastHostId(), Op.EQ); AllFieldsSearch.and("lastHost", AllFieldsSearch.entity().getLastHostId(), Op.EQ);
@ -169,23 +171,23 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
IdTypesSearch.and("id", IdTypesSearch.entity().getId(), Op.EQ); IdTypesSearch.and("id", IdTypesSearch.entity().getId(), Op.EQ);
IdTypesSearch.and("types", IdTypesSearch.entity().getType(), Op.IN); IdTypesSearch.and("types", IdTypesSearch.entity().getType(), Op.IN);
IdTypesSearch.done(); IdTypesSearch.done();
HostIdTypesSearch = createSearchBuilder(); HostIdTypesSearch = createSearchBuilder();
HostIdTypesSearch.and("hostid", HostIdTypesSearch.entity().getHostId(), Op.EQ); HostIdTypesSearch.and("hostid", HostIdTypesSearch.entity().getHostId(), Op.EQ);
HostIdTypesSearch.and("types", HostIdTypesSearch.entity().getType(), Op.IN); HostIdTypesSearch.and("types", HostIdTypesSearch.entity().getType(), Op.IN);
HostIdTypesSearch.done(); HostIdTypesSearch.done();
HostIdUpTypesSearch = createSearchBuilder(); HostIdUpTypesSearch = createSearchBuilder();
HostIdUpTypesSearch.and("hostid", HostIdUpTypesSearch.entity().getHostId(), Op.EQ); HostIdUpTypesSearch.and("hostid", HostIdUpTypesSearch.entity().getHostId(), Op.EQ);
HostIdUpTypesSearch.and("types", HostIdUpTypesSearch.entity().getType(), Op.IN); HostIdUpTypesSearch.and("types", HostIdUpTypesSearch.entity().getType(), Op.IN);
HostIdUpTypesSearch.and("states", HostIdUpTypesSearch.entity().getState(), Op.NIN); HostIdUpTypesSearch.and("states", HostIdUpTypesSearch.entity().getState(), Op.NIN);
HostIdUpTypesSearch.done(); HostIdUpTypesSearch.done();
HostUpSearch = createSearchBuilder(); HostUpSearch = createSearchBuilder();
HostUpSearch.and("host", HostUpSearch.entity().getHostId(), Op.EQ); HostUpSearch.and("host", HostUpSearch.entity().getHostId(), Op.EQ);
HostUpSearch.and("states", HostUpSearch.entity().getState(), Op.IN); HostUpSearch.and("states", HostUpSearch.entity().getState(), Op.IN);
HostUpSearch.done(); HostUpSearch.done();
InstanceNameSearch = createSearchBuilder(); InstanceNameSearch = createSearchBuilder();
InstanceNameSearch.and("instanceName", InstanceNameSearch.entity().getInstanceName(), Op.EQ); InstanceNameSearch.and("instanceName", InstanceNameSearch.entity().getInstanceName(), Op.EQ);
InstanceNameSearch.done(); InstanceNameSearch.done();
@ -194,21 +196,31 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
CountVirtualRoutersByAccount.select(null, Func.COUNT, null); CountVirtualRoutersByAccount.select(null, Func.COUNT, null);
CountVirtualRoutersByAccount.and("account", CountVirtualRoutersByAccount.entity().getAccountId(), SearchCriteria.Op.EQ); CountVirtualRoutersByAccount.and("account", CountVirtualRoutersByAccount.entity().getAccountId(), SearchCriteria.Op.EQ);
CountVirtualRoutersByAccount.and("type", CountVirtualRoutersByAccount.entity().getType(), SearchCriteria.Op.EQ); CountVirtualRoutersByAccount.and("type", CountVirtualRoutersByAccount.entity().getType(), SearchCriteria.Op.EQ);
CountVirtualRoutersByAccount.and("state", CountVirtualRoutersByAccount.entity().getState(), SearchCriteria.Op.NIN); CountVirtualRoutersByAccount.and("state", CountVirtualRoutersByAccount.entity().getState(), SearchCriteria.Op.NIN);
CountVirtualRoutersByAccount.done(); CountVirtualRoutersByAccount.done();
CountRunningByHost = createSearchBuilder(Long.class); CountRunningByHost = createSearchBuilder(Long.class);
CountRunningByHost.select(null, Func.COUNT, null); CountRunningByHost.select(null, Func.COUNT, null);
CountRunningByHost.and("host", CountRunningByHost.entity().getHostId(), SearchCriteria.Op.EQ); CountRunningByHost.and("host", CountRunningByHost.entity().getHostId(), SearchCriteria.Op.EQ);
CountRunningByHost.and("state", CountRunningByHost.entity().getState(), SearchCriteria.Op.EQ); CountRunningByHost.and("state", CountRunningByHost.entity().getState(), SearchCriteria.Op.EQ);
CountRunningByHost.done(); CountRunningByHost.done();
CountRunningByAccount = createSearchBuilder(Long.class); CountRunningByAccount = createSearchBuilder(Long.class);
CountRunningByAccount.select(null, Func.COUNT, null); CountRunningByAccount.select(null, Func.COUNT, null);
CountRunningByAccount.and("account", CountRunningByAccount.entity().getAccountId(), SearchCriteria.Op.EQ); CountRunningByAccount.and("account", CountRunningByAccount.entity().getAccountId(), SearchCriteria.Op.EQ);
CountRunningByAccount.and("state", CountRunningByAccount.entity().getState(), SearchCriteria.Op.EQ); CountRunningByAccount.and("state", CountRunningByAccount.entity().getState(), SearchCriteria.Op.EQ);
CountRunningByAccount.done(); CountRunningByAccount.done();
HostAndStateSearch = createSearchBuilder();
HostAndStateSearch.and("host", HostAndStateSearch.entity().getHostId(), Op.EQ);
HostAndStateSearch.and("states", HostAndStateSearch.entity().getState(), Op.IN);
HostAndStateSearch.done();
StartingWithNoHostSearch = createSearchBuilder();
StartingWithNoHostSearch.and("state", StartingWithNoHostSearch.entity().getState(), Op.EQ);
StartingWithNoHostSearch.and("host", StartingWithNoHostSearch.entity().getHostId(), Op.NULL);
StartingWithNoHostSearch.done();
_updateTimeAttr = _allAttributes.get("updateTime"); _updateTimeAttr = _allAttributes.get("updateTime");
assert _updateTimeAttr != null : "Couldn't get this updateTime attribute"; assert _updateTimeAttr != null : "Couldn't get this updateTime attribute";
} }
@ -219,7 +231,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
sc.setParameters("account", accountId); sc.setParameters("account", accountId);
return listBy(sc); return listBy(sc);
} }
@Override @Override
public List<VMInstanceVO> findVMInstancesLike(String name) { public List<VMInstanceVO> findVMInstancesLike(String name) {
SearchCriteria<VMInstanceVO> sc = NameLikeSearch.create(); SearchCriteria<VMInstanceVO> sc = NameLikeSearch.create();
@ -234,7 +246,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
return listBy(sc); return listBy(sc);
} }
@Override @Override
public List<VMInstanceVO> listByZoneId(long zoneId) { public List<VMInstanceVO> listByZoneId(long zoneId) {
SearchCriteria<VMInstanceVO> sc = AllFieldsSearch.create(); SearchCriteria<VMInstanceVO> sc = AllFieldsSearch.create();
@ -242,7 +254,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
return listBy(sc); return listBy(sc);
} }
@Override @Override
public List<VMInstanceVO> listByPodId(long podId) { public List<VMInstanceVO> listByPodId(long podId) {
SearchCriteria<VMInstanceVO> sc = AllFieldsSearch.create(); SearchCriteria<VMInstanceVO> sc = AllFieldsSearch.create();
@ -263,7 +275,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
sc.setJoinParameters("hostSearch1", "clusterId", clusterId); sc.setJoinParameters("hostSearch1", "clusterId", clusterId);
return listBy(sc); return listBy(sc);
} }
@Override @Override
public List<VMInstanceVO> listByZoneIdAndType(long zoneId, VirtualMachine.Type type) { public List<VMInstanceVO> listByZoneIdAndType(long zoneId, VirtualMachine.Type type) {
SearchCriteria<VMInstanceVO> sc = AllFieldsSearch.create(); SearchCriteria<VMInstanceVO> sc = AllFieldsSearch.create();
@ -271,8 +283,8 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
sc.setParameters("type", type.toString()); sc.setParameters("type", type.toString());
return listBy(sc); return listBy(sc);
} }
@Override @Override
public List<VMInstanceVO> listNonExpungedByZoneAndTemplate(long zoneId, long templateId) { public List<VMInstanceVO> listNonExpungedByZoneAndTemplate(long zoneId, long templateId) {
SearchCriteria<VMInstanceVO> sc = ZoneTemplateNonExpungedSearch.create(); SearchCriteria<VMInstanceVO> sc = ZoneTemplateNonExpungedSearch.create();
@ -310,7 +322,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
sc.setParameters("states", new Object[] {State.Destroyed, State.Stopped, State.Expunging}); sc.setParameters("states", new Object[] {State.Destroyed, State.Stopped, State.Expunging});
return listBy(sc); return listBy(sc);
} }
@Override @Override
public List<VMInstanceVO> listUpByHostId(Long hostId) { public List<VMInstanceVO> listUpByHostId(Long hostId) {
SearchCriteria<VMInstanceVO> sc = HostUpSearch.create(); SearchCriteria<VMInstanceVO> sc = HostUpSearch.create();
@ -318,14 +330,14 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
sc.setParameters("states", new Object[] {State.Starting, State.Running}); sc.setParameters("states", new Object[] {State.Starting, State.Running});
return listBy(sc); return listBy(sc);
} }
@Override @Override
public List<VMInstanceVO> listByTypes(Type... types) { public List<VMInstanceVO> listByTypes(Type... types) {
SearchCriteria<VMInstanceVO> sc = TypesSearch.create(); SearchCriteria<VMInstanceVO> sc = TypesSearch.create();
sc.setParameters("types", (Object[]) types); sc.setParameters("types", (Object[]) types);
return listBy(sc); return listBy(sc);
} }
@Override @Override
public List<VMInstanceVO> listByTypeAndState(VirtualMachine.Type type, State state) { public List<VMInstanceVO> listByTypeAndState(VirtualMachine.Type type, State state) {
SearchCriteria<VMInstanceVO> sc = AllFieldsSearch.create(); SearchCriteria<VMInstanceVO> sc = AllFieldsSearch.create();
@ -348,7 +360,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
sc.setParameters("instanceName", name); sc.setParameters("instanceName", name);
return findOneBy(sc); return findOneBy(sc);
} }
@Override @Override
public void updateProxyId(long id, Long proxyId, Date time) { public void updateProxyId(long id, Long proxyId, Date time) {
VMInstanceVO vo = createForUpdate(); VMInstanceVO vo = createForUpdate();
@ -369,12 +381,12 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Pair<Long, Long> hosts = (Pair<Long,Long>)opaque; Pair<Long, Long> hosts = (Pair<Long,Long>)opaque;
Long newHostId = hosts.second(); Long newHostId = hosts.second();
VMInstanceVO vmi = (VMInstanceVO)vm; VMInstanceVO vmi = (VMInstanceVO)vm;
Long oldHostId = vmi.getHostId(); Long oldHostId = vmi.getHostId();
Long oldUpdated = vmi.getUpdated(); Long oldUpdated = vmi.getUpdated();
Date oldUpdateDate = vmi.getUpdateTime(); Date oldUpdateDate = vmi.getUpdateTime();
SearchCriteria<VMInstanceVO> sc = StateChangeSearch.create(); SearchCriteria<VMInstanceVO> sc = StateChangeSearch.create();
sc.setParameters("id", vmi.getId()); sc.setParameters("id", vmi.getId());
sc.setParameters("states", oldState); sc.setParameters("states", oldState);
@ -383,7 +395,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
vmi.incrUpdated(); vmi.incrUpdated();
UpdateBuilder ub = getUpdateBuilder(vmi); UpdateBuilder ub = getUpdateBuilder(vmi);
ub.set(vmi, "state", newState); ub.set(vmi, "state", newState);
ub.set(vmi, "hostId", newHostId); ub.set(vmi, "hostId", newHostId);
ub.set(vmi, "podIdToDeployIn", vmi.getPodIdToDeployIn()); ub.set(vmi, "podIdToDeployIn", vmi.getPodIdToDeployIn());
@ -393,7 +405,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
if (result == 0 && s_logger.isDebugEnabled()) { if (result == 0 && s_logger.isDebugEnabled()) {
VMInstanceVO vo = findByIdIncludingRemoved(vm.getId()); VMInstanceVO vo = findByIdIncludingRemoved(vm.getId());
if (vo != null) { if (vo != null) {
StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString()); StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
str.append(": DB Data={Host=").append(vo.getHostId()).append("; State=").append(vo.getState().toString()).append("; updated=").append(vo.getUpdated()).append("; time=").append(vo.getUpdateTime()); str.append(": DB Data={Host=").append(vo.getHostId()).append("; State=").append(vo.getState().toString()).append("; updated=").append(vo.getUpdated()).append("; time=").append(vo.getUpdateTime());
@ -407,7 +419,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
} }
return result > 0; return result > 0;
} }
@Override @Override
public List<VMInstanceVO> listByLastHostId(Long hostId) { public List<VMInstanceVO> listByLastHostId(Long hostId) {
SearchCriteria<VMInstanceVO> sc = AllFieldsSearch.create(); SearchCriteria<VMInstanceVO> sc = AllFieldsSearch.create();
@ -415,7 +427,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
sc.setParameters("state", State.Stopped); sc.setParameters("state", State.Stopped);
return listBy(sc); return listBy(sc);
} }
@Override @Override
public Long countAllocatedVirtualRoutersForAccount(long accountId) { public Long countAllocatedVirtualRoutersForAccount(long accountId) {
SearchCriteria<Long> sc = CountVirtualRoutersByAccount.create(); SearchCriteria<Long> sc = CountVirtualRoutersByAccount.create();
@ -424,7 +436,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
sc.setParameters("state", new Object[] {State.Destroyed, State.Error, State.Expunging}); sc.setParameters("state", new Object[] {State.Destroyed, State.Error, State.Expunging});
return customSearch(sc, null).get(0); return customSearch(sc, null).get(0);
} }
@Override @Override
public List<VMInstanceVO> listVmsMigratingFromHost(Long hostId) { public List<VMInstanceVO> listVmsMigratingFromHost(Long hostId) {
SearchCriteria<VMInstanceVO> sc = AllFieldsSearch.create(); SearchCriteria<VMInstanceVO> sc = AllFieldsSearch.create();
@ -432,7 +444,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
sc.setParameters("state", State.Migrating); sc.setParameters("state", State.Migrating);
return listBy(sc); return listBy(sc);
} }
@Override @Override
public Long countRunningByHostId(long hostId){ public Long countRunningByHostId(long hostId){
SearchCriteria<Long> sc = CountRunningByHost.create(); SearchCriteria<Long> sc = CountRunningByHost.create();
@ -455,7 +467,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
pstmt = txn.prepareAutoCloseStatement(sql.toString()); pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setLong(1, accountId); pstmt.setLong(1, accountId);
pstmt.setLong(2, zoneId); pstmt.setLong(2, zoneId);
ResultSet rs = pstmt.executeQuery(); ResultSet rs = pstmt.executeQuery();
while (rs.next()) { while (rs.next()) {
Long clusterId = rs.getLong(1); Long clusterId = rs.getLong(1);
@ -484,11 +496,11 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
pstmt = txn.prepareAutoCloseStatement(sql.toString()); pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setLong(1, accountId); pstmt.setLong(1, accountId);
pstmt.setLong(2, podId); pstmt.setLong(2, podId);
ResultSet rs = pstmt.executeQuery(); ResultSet rs = pstmt.executeQuery();
while (rs.next()) { while (rs.next()) {
Long clusterId = rs.getLong(1); Long clusterId = rs.getLong(1);
result.add(clusterId); result.add(clusterId);
clusterVmCountMap.put(clusterId, rs.getDouble(2)); clusterVmCountMap.put(clusterId, rs.getDouble(2));
} }
return new Pair<List<Long>, Map<Long, Double>>(result, clusterVmCountMap); return new Pair<List<Long>, Map<Long, Double>>(result, clusterVmCountMap);
@ -511,11 +523,11 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
pstmt = txn.prepareAutoCloseStatement(sql); pstmt = txn.prepareAutoCloseStatement(sql);
pstmt.setLong(1, accountId); pstmt.setLong(1, accountId);
pstmt.setLong(2, dataCenterId); pstmt.setLong(2, dataCenterId);
ResultSet rs = pstmt.executeQuery(); ResultSet rs = pstmt.executeQuery();
while (rs.next()) { while (rs.next()) {
Long podId = rs.getLong(1); Long podId = rs.getLong(1);
result.add(podId); result.add(podId);
podVmCountMap.put(podId, rs.getDouble(2)); podVmCountMap.put(podId, rs.getDouble(2));
} }
return new Pair<List<Long>, Map<Long, Double>>(result, podVmCountMap); return new Pair<List<Long>, Map<Long, Double>>(result, podVmCountMap);
@ -523,7 +535,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
throw new CloudRuntimeException("DB Exception on: " + ORDER_PODS_NUMBER_OF_VMS_FOR_ACCOUNT, e); throw new CloudRuntimeException("DB Exception on: " + ORDER_PODS_NUMBER_OF_VMS_FOR_ACCOUNT, e);
} catch (Throwable e) { } catch (Throwable e) {
throw new CloudRuntimeException("Caught: " + ORDER_PODS_NUMBER_OF_VMS_FOR_ACCOUNT, e); throw new CloudRuntimeException("Caught: " + ORDER_PODS_NUMBER_OF_VMS_FOR_ACCOUNT, e);
} }
} }
@Override @Override
@ -538,7 +550,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
pstmt.setLong(2, dcId); pstmt.setLong(2, dcId);
pstmt.setLong(3, podId); pstmt.setLong(3, podId);
pstmt.setLong(4, clusterId); pstmt.setLong(4, clusterId);
ResultSet rs = pstmt.executeQuery(); ResultSet rs = pstmt.executeQuery();
while (rs.next()) { while (rs.next()) {
result.add(rs.getLong(1)); result.add(rs.getLong(1));
@ -548,9 +560,9 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
throw new CloudRuntimeException("DB Exception on: " + ORDER_PODS_NUMBER_OF_VMS_FOR_ACCOUNT, e); throw new CloudRuntimeException("DB Exception on: " + ORDER_PODS_NUMBER_OF_VMS_FOR_ACCOUNT, e);
} catch (Throwable e) { } catch (Throwable e) {
throw new CloudRuntimeException("Caught: " + ORDER_PODS_NUMBER_OF_VMS_FOR_ACCOUNT, e); throw new CloudRuntimeException("Caught: " + ORDER_PODS_NUMBER_OF_VMS_FOR_ACCOUNT, e);
} }
} }
@Override @Override
public Long countRunningByAccount(long accountId){ public Long countRunningByAccount(long accountId){
SearchCriteria<Long> sc = CountRunningByAccount.create(); SearchCriteria<Long> sc = CountRunningByAccount.create();
@ -558,18 +570,18 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
sc.setParameters("state", State.Running); sc.setParameters("state", State.Running);
return customSearch(sc, null).get(0); return customSearch(sc, null).get(0);
} }
@Override @Override
public List<VMInstanceVO> listNonRemovedVmsByTypeAndNetwork(long networkId, VirtualMachine.Type... types) { public List<VMInstanceVO> listNonRemovedVmsByTypeAndNetwork(long networkId, VirtualMachine.Type... types) {
if (NetworkTypeSearch == null) { if (NetworkTypeSearch == null) {
SearchBuilder<NicVO> nicSearch = _nicDao.createSearchBuilder(); SearchBuilder<NicVO> nicSearch = _nicDao.createSearchBuilder();
nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
NetworkTypeSearch = createSearchBuilder(); NetworkTypeSearch = createSearchBuilder();
NetworkTypeSearch.and("types", NetworkTypeSearch.entity().getType(), SearchCriteria.Op.IN); NetworkTypeSearch.and("types", NetworkTypeSearch.entity().getType(), SearchCriteria.Op.IN);
NetworkTypeSearch.and("removed", NetworkTypeSearch.entity().getRemoved(), SearchCriteria.Op.NULL); NetworkTypeSearch.and("removed", NetworkTypeSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
NetworkTypeSearch.join("nicSearch", nicSearch, NetworkTypeSearch.entity().getId(), NetworkTypeSearch.join("nicSearch", nicSearch, NetworkTypeSearch.entity().getId(),
nicSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER); nicSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER);
NetworkTypeSearch.done(); NetworkTypeSearch.done();
} }
@ -577,27 +589,27 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
SearchCriteria<VMInstanceVO> sc = NetworkTypeSearch.create(); SearchCriteria<VMInstanceVO> sc = NetworkTypeSearch.create();
if (types != null && types.length != 0) { if (types != null && types.length != 0) {
sc.setParameters("types", (Object[]) types); sc.setParameters("types", (Object[]) types);
} }
sc.setJoinParameters("nicSearch", "networkId", networkId); sc.setJoinParameters("nicSearch", "networkId", networkId);
return listBy(sc); return listBy(sc);
} }
@Override @Override
public List<String> listDistinctHostNames(long networkId, VirtualMachine.Type... types) { public List<String> listDistinctHostNames(long networkId, VirtualMachine.Type... types) {
if (DistinctHostNameSearch == null) { if (DistinctHostNameSearch == null) {
SearchBuilder<NicVO> nicSearch = _nicDao.createSearchBuilder(); SearchBuilder<NicVO> nicSearch = _nicDao.createSearchBuilder();
nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
DistinctHostNameSearch = createSearchBuilder(String.class); DistinctHostNameSearch = createSearchBuilder(String.class);
DistinctHostNameSearch.selectField(DistinctHostNameSearch.entity().getHostName()); DistinctHostNameSearch.selectField(DistinctHostNameSearch.entity().getHostName());
DistinctHostNameSearch.and("types", DistinctHostNameSearch.entity().getType(), SearchCriteria.Op.IN); DistinctHostNameSearch.and("types", DistinctHostNameSearch.entity().getType(), SearchCriteria.Op.IN);
DistinctHostNameSearch.and("removed", DistinctHostNameSearch.entity().getRemoved(), SearchCriteria.Op.NULL); DistinctHostNameSearch.and("removed", DistinctHostNameSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
DistinctHostNameSearch.join("nicSearch", nicSearch, DistinctHostNameSearch.entity().getId(), DistinctHostNameSearch.join("nicSearch", nicSearch, DistinctHostNameSearch.entity().getId(),
nicSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER); nicSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER);
DistinctHostNameSearch.done(); DistinctHostNameSearch.done();
} }
@ -605,12 +617,12 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
SearchCriteria<String> sc = DistinctHostNameSearch.create(); SearchCriteria<String> sc = DistinctHostNameSearch.create();
if (types != null && types.length != 0) { if (types != null && types.length != 0) {
sc.setParameters("types", (Object[]) types); sc.setParameters("types", (Object[]) types);
} }
sc.setJoinParameters("nicSearch", "networkId", networkId); sc.setJoinParameters("nicSearch", "networkId", networkId);
return customSearch(sc, null); return customSearch(sc, null);
} }
@Override @Override
@DB @DB
public boolean remove(Long id) { public boolean remove(Long id) {
@ -625,4 +637,19 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
return result; return result;
} }
@Override
public List<VMInstanceVO> findByHostInStates(Long hostId, State... states) {
SearchCriteria<VMInstanceVO> sc = HostAndStateSearch.create();
sc.setParameters("host", hostId);
sc.setParameters("states", (Object[]) states);
return listBy(sc);
}
@Override
public List<VMInstanceVO> listStartingWithNoHostId() {
SearchCriteria<VMInstanceVO> sc = StartingWithNoHostSearch.create();
sc.setParameters("state", State.Starting);
return listBy(sc);
}
} }

View File

@ -50,7 +50,7 @@ public class ClusterScopeStoragePoolAllocator extends AbstractStoragePoolAllocat
@Override @Override
protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) { protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) {
s_logger.debug("ClusterScopeStoragePoolAllocator looking for storage pool"); s_logger.debug("ClusterScopeStoragePoolAllocator looking for storage pool");
List<StoragePool> suitablePools = new ArrayList<StoragePool>(); List<StoragePool> suitablePools = new ArrayList<StoragePool>();
@ -65,6 +65,14 @@ public class ClusterScopeStoragePoolAllocator extends AbstractStoragePoolAllocat
} }
List<StoragePoolVO> pools = _storagePoolDao.findPoolsByTags(dcId, podId, clusterId, dskCh.getTags()); List<StoragePoolVO> pools = _storagePoolDao.findPoolsByTags(dcId, podId, clusterId, dskCh.getTags());
// add remaining pools in cluster, that did not match tags, to avoid set
List<StoragePoolVO> allPools = _storagePoolDao.findPoolsByTags(dcId, podId, clusterId, null);
allPools.removeAll(pools);
for (StoragePoolVO pool : allPools) {
avoid.addPool(pool.getId());
}
if (pools.size() == 0) { if (pools.size() == 0) {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
String storageType = dskCh.useLocalStorage() ? ServiceOffering.StorageType.local.toString() : ServiceOffering.StorageType.shared.toString(); String storageType = dskCh.useLocalStorage() ? ServiceOffering.StorageType.local.toString() : ServiceOffering.StorageType.shared.toString();
@ -72,7 +80,7 @@ public class ClusterScopeStoragePoolAllocator extends AbstractStoragePoolAllocat
} }
return suitablePools; return suitablePools;
} }
for (StoragePoolVO pool: pools) { for (StoragePoolVO pool: pools) {
if(suitablePools.size() == returnUpTo){ if(suitablePools.size() == returnUpTo){
break; break;
@ -80,13 +88,15 @@ public class ClusterScopeStoragePoolAllocator extends AbstractStoragePoolAllocat
StoragePool pol = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId()); StoragePool pol = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId());
if (filter(avoid, pol, dskCh, plan)) { if (filter(avoid, pol, dskCh, plan)) {
suitablePools.add(pol); suitablePools.add(pol);
} else {
avoid.addPool(pool.getId());
} }
} }
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("FirstFitStoragePoolAllocator returning "+suitablePools.size() +" suitable storage pools"); s_logger.debug("FirstFitStoragePoolAllocator returning "+suitablePools.size() +" suitable storage pools");
} }
return suitablePools; return suitablePools;
} }

View File

@ -74,7 +74,7 @@ public class LocalStoragePoolAllocator extends AbstractStoragePoolAllocator {
if (!dskCh.useLocalStorage()) { if (!dskCh.useLocalStorage()) {
return suitablePools; return suitablePools;
} }
// data disk and host identified from deploying vm (attach volume case) // data disk and host identified from deploying vm (attach volume case)
if (dskCh.getType() == Volume.Type.DATADISK && plan.getHostId() != null) { if (dskCh.getType() == Volume.Type.DATADISK && plan.getHostId() != null) {
List<StoragePoolHostVO> hostPools = _poolHostDao.listByHostId(plan.getHostId()); List<StoragePoolHostVO> hostPools = _poolHostDao.listByHostId(plan.getHostId());
@ -85,7 +85,9 @@ public class LocalStoragePoolAllocator extends AbstractStoragePoolAllocator {
if (filter(avoid, pol, dskCh, plan)) { if (filter(avoid, pol, dskCh, plan)) {
s_logger.debug("Found suitable local storage pool " + pool.getId() + ", adding to list"); s_logger.debug("Found suitable local storage pool " + pool.getId() + ", adding to list");
suitablePools.add(pol); suitablePools.add(pol);
} } else {
avoid.addPool(pool.getId());
}
} }
if (suitablePools.size() == returnUpTo) { if (suitablePools.size() == returnUpTo) {
@ -101,8 +103,19 @@ public class LocalStoragePoolAllocator extends AbstractStoragePoolAllocator {
StoragePool pol = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId()); StoragePool pol = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId());
if (filter(avoid, pol, dskCh, plan)) { if (filter(avoid, pol, dskCh, plan)) {
suitablePools.add(pol); suitablePools.add(pol);
} } else {
avoid.addPool(pool.getId());
}
} }
// add remaining pools in cluster, that did not match tags, to avoid
// set
List<StoragePoolVO> allPools = _storagePoolDao.findLocalStoragePoolsByTags(plan.getDataCenterId(),
plan.getPodId(), plan.getClusterId(), null);
allPools.removeAll(availablePools);
for (StoragePoolVO pool : allPools) {
avoid.addPool(pool.getId());
}
} }
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
@ -111,7 +124,7 @@ public class LocalStoragePoolAllocator extends AbstractStoragePoolAllocator {
return suitablePools; return suitablePools;
} }
@Override @Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
super.configure(name, params); super.configure(name, params);

View File

@ -39,18 +39,18 @@ import com.cloud.vm.VirtualMachineProfile;
@Component @Component
public class ZoneWideStoragePoolAllocator extends AbstractStoragePoolAllocator { public class ZoneWideStoragePoolAllocator extends AbstractStoragePoolAllocator {
private static final Logger s_logger = Logger.getLogger(ZoneWideStoragePoolAllocator.class); private static final Logger s_logger = Logger.getLogger(ZoneWideStoragePoolAllocator.class);
@Inject PrimaryDataStoreDao _storagePoolDao; @Inject PrimaryDataStoreDao _storagePoolDao;
@Inject DataStoreManager dataStoreMgr; @Inject DataStoreManager dataStoreMgr;
@Override @Override
protected boolean filter(ExcludeList avoid, StoragePool pool, DiskProfile dskCh, protected boolean filter(ExcludeList avoid, StoragePool pool, DiskProfile dskCh,
DeploymentPlan plan) { DeploymentPlan plan) {
Volume volume = _volumeDao.findById(dskCh.getVolumeId()); Volume volume = _volumeDao.findById(dskCh.getVolumeId());
List<Volume> requestVolumes = new ArrayList<Volume>(); List<Volume> requestVolumes = new ArrayList<Volume>();
requestVolumes.add(volume); requestVolumes.add(volume);
return storageMgr.storagePoolHasEnoughSpace(requestVolumes, pool); return storageMgr.storagePoolHasEnoughSpace(requestVolumes, pool);
} }
@Override @Override
protected List<StoragePool> select(DiskProfile dskCh, protected List<StoragePool> select(DiskProfile dskCh,
VirtualMachineProfile<? extends VirtualMachine> vmProfile, VirtualMachineProfile<? extends VirtualMachine> vmProfile,
@ -64,9 +64,16 @@ public class ZoneWideStoragePoolAllocator extends AbstractStoragePoolAllocator {
return suitablePools; return suitablePools;
} }
} }
List<StoragePoolVO> storagePools = _storagePoolDao.findZoneWideStoragePoolsByTags(plan.getDataCenterId(), dskCh.getTags()); List<StoragePoolVO> storagePools = _storagePoolDao.findZoneWideStoragePoolsByTags(plan.getDataCenterId(), dskCh.getTags());
// add remaining pools in zone, that did not match tags, to avoid set
List<StoragePoolVO> allPools = _storagePoolDao.findZoneWideStoragePoolsByTags(plan.getDataCenterId(), null);
allPools.removeAll(storagePools);
for (StoragePoolVO pool : allPools) {
avoid.addPool(pool.getId());
}
for (StoragePoolVO storage : storagePools) { for (StoragePoolVO storage : storagePools) {
if (suitablePools.size() == returnUpTo) { if (suitablePools.size() == returnUpTo) {
break; break;
@ -74,7 +81,9 @@ public class ZoneWideStoragePoolAllocator extends AbstractStoragePoolAllocator {
StoragePool pol = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(storage.getId()); StoragePool pol = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(storage.getId());
if (filter(avoid, pol, dskCh, plan)) { if (filter(avoid, pol, dskCh, plan)) {
suitablePools.add(pol); suitablePools.add(pol);
} } else {
avoid.addPool(pol.getId());
}
} }
return suitablePools; return suitablePools;
} }

View File

@ -434,6 +434,12 @@ setup_common() {
ping -n -c 3 $MGMT_GW & ping -n -c 3 $MGMT_GW &
sleep 3 sleep 3
pkill ping pkill ping
fi
local hyp=$(hypervisor)
if [ "$hyp" == "vmware" ]; then
ntpq -p &> /dev/null || vmware-toolbox-cmd timesync enable
fi fi
} }

View File

@ -11,7 +11,7 @@
// Unless required by applicable law or agreed to in writing, // Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an // software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.deploy; package com.cloud.deploy;
@ -24,18 +24,17 @@ import javax.ejb.Local;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.VirtualMachineProfile;
@Local(value=DeploymentPlanner.class) @Local(value=DeploymentPlanner.class)
public class UserConcentratedPodPlanner extends FirstFitPlanner implements DeploymentPlanner { public class UserConcentratedPodPlanner extends FirstFitPlanner implements DeploymentClusterPlanner {
private static final Logger s_logger = Logger.getLogger(UserConcentratedPodPlanner.class); private static final Logger s_logger = Logger.getLogger(UserConcentratedPodPlanner.class);
/** /**
* This method should reorder the given list of Cluster Ids by applying any necessary heuristic * This method should reorder the given list of Cluster Ids by applying any necessary heuristic
* for this planner * for this planner
* For UserConcentratedPodPlanner we need to order the clusters in a zone across pods, by considering those pods first which have more number of VMs for this account * For UserConcentratedPodPlanner we need to order the clusters in a zone across pods, by considering those pods first which have more number of VMs for this account
* This reordering is not done incase the clusters within single pod are passed when the allocation is applied at pod-level. * This reordering is not done incase the clusters within single pod are passed when the allocation is applied at pod-level.
@ -49,7 +48,7 @@ public class UserConcentratedPodPlanner extends FirstFitPlanner implements Deplo
} }
return applyUserConcentrationPodHeuristicToClusters(id, clusterIdsByCapacity, vmProfile.getOwner().getAccountId()); return applyUserConcentrationPodHeuristicToClusters(id, clusterIdsByCapacity, vmProfile.getOwner().getAccountId());
} }
private List<Long> applyUserConcentrationPodHeuristicToClusters(long zoneId, List<Long> prioritizedClusterIds, long accountId){ private List<Long> applyUserConcentrationPodHeuristicToClusters(long zoneId, List<Long> prioritizedClusterIds, long accountId){
//user has VMs in certain pods. - prioritize those pods first //user has VMs in certain pods. - prioritize those pods first
//UserConcentratedPod strategy //UserConcentratedPod strategy
@ -61,8 +60,8 @@ public class UserConcentratedPodPlanner extends FirstFitPlanner implements Deplo
clusterList = prioritizedClusterIds; clusterList = prioritizedClusterIds;
} }
return clusterList; return clusterList;
} }
private List<Long> reorderClustersByPods(List<Long> clusterIds, List<Long> podIds) { private List<Long> reorderClustersByPods(List<Long> clusterIds, List<Long> podIds) {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
@ -111,11 +110,11 @@ public class UserConcentratedPodPlanner extends FirstFitPlanner implements Deplo
return prioritizedPods; return prioritizedPods;
} }
/** /**
* This method should reorder the given list of Pod Ids by applying any necessary heuristic * This method should reorder the given list of Pod Ids by applying any necessary heuristic
* for this planner * for this planner
* For UserConcentratedPodPlanner we need to order the pods by considering those pods first which have more number of VMs for this account * For UserConcentratedPodPlanner we need to order the pods by considering those pods first which have more number of VMs for this account
* @return List<Long> ordered list of Pod Ids * @return List<Long> ordered list of Pod Ids
*/ */
@Override @Override
@ -124,7 +123,7 @@ public class UserConcentratedPodPlanner extends FirstFitPlanner implements Deplo
if(vmProfile.getOwner() == null){ if(vmProfile.getOwner() == null){
return podIdsByCapacity; return podIdsByCapacity;
} }
long accountId = vmProfile.getOwner().getAccountId(); long accountId = vmProfile.getOwner().getAccountId();
//user has VMs in certain pods. - prioritize those pods first //user has VMs in certain pods. - prioritize those pods first
//UserConcentratedPod strategy //UserConcentratedPod strategy
@ -138,18 +137,7 @@ public class UserConcentratedPodPlanner extends FirstFitPlanner implements Deplo
}else{ }else{
return podIdsByCapacity; return podIdsByCapacity;
} }
}
@Override
public boolean canHandle(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, ExcludeList avoid) {
if(vm.getHypervisorType() != HypervisorType.BareMetal){
//check the allocation strategy
if (_allocationAlgorithm != null && (_allocationAlgorithm.equals(AllocationAlgorithm.userconcentratedpod_random.toString()) || _allocationAlgorithm.equals(AllocationAlgorithm.userconcentratedpod_firstfit.toString()))){
return true;
}
}
return false;
} }
} }

View File

@ -29,14 +29,13 @@ import javax.naming.ConfigurationException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.cloud.configuration.Config; import com.cloud.configuration.Config;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.utils.NumbersUtil; import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.VirtualMachineProfile;
@Local(value=DeploymentPlanner.class) @Local(value=DeploymentPlanner.class)
public class UserDispersingPlanner extends FirstFitPlanner implements DeploymentPlanner { public class UserDispersingPlanner extends FirstFitPlanner implements DeploymentClusterPlanner {
private static final Logger s_logger = Logger.getLogger(UserDispersingPlanner.class); private static final Logger s_logger = Logger.getLogger(UserDispersingPlanner.class);
@ -191,17 +190,6 @@ public class UserDispersingPlanner extends FirstFitPlanner implements Deployment
} }
@Override
public boolean canHandle(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, ExcludeList avoid) {
if(vm.getHypervisorType() != HypervisorType.BareMetal){
//check the allocation strategy
if (_allocationAlgorithm != null && _allocationAlgorithm.equals(AllocationAlgorithm.userdispersing.toString())) {
return true;
}
}
return false;
}
float _userDispersionWeight; float _userDispersionWeight;

View File

@ -1,39 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.baremetal.manager;
import java.util.Map;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
import com.cloud.deploy.AbstractDeployPlannerSelector;
import com.cloud.deploy.DeployPlannerSelector;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.vm.UserVmVO;
@Local(value = {DeployPlannerSelector.class})
public class BaremetalPlannerSelector extends AbstractDeployPlannerSelector{
@Override
public String selectPlanner(UserVmVO vm) {
if (vm.getHypervisorType() == HypervisorType.BareMetal) {
return "BareMetalPlanner";
}
return null;
}
}

View File

@ -127,6 +127,7 @@ import com.cloud.agent.api.PlugNicAnswer;
import com.cloud.agent.api.PlugNicCommand; import com.cloud.agent.api.PlugNicCommand;
import com.cloud.agent.api.PrepareForMigrationAnswer; import com.cloud.agent.api.PrepareForMigrationAnswer;
import com.cloud.agent.api.PrepareForMigrationCommand; import com.cloud.agent.api.PrepareForMigrationCommand;
import com.cloud.agent.api.PvlanSetupCommand;
import com.cloud.agent.api.ReadyAnswer; import com.cloud.agent.api.ReadyAnswer;
import com.cloud.agent.api.ReadyCommand; import com.cloud.agent.api.ReadyCommand;
import com.cloud.agent.api.RebootAnswer; import com.cloud.agent.api.RebootAnswer;
@ -276,6 +277,8 @@ ServerResource {
private String _createTmplPath; private String _createTmplPath;
private String _heartBeatPath; private String _heartBeatPath;
private String _securityGroupPath; private String _securityGroupPath;
private String _ovsPvlanDhcpHostPath;
private String _ovsPvlanVmPath;
private String _routerProxyPath; private String _routerProxyPath;
private String _host; private String _host;
private String _dcId; private String _dcId;
@ -597,6 +600,18 @@ ServerResource {
"Unable to find the router_proxy.sh"); "Unable to find the router_proxy.sh");
} }
_ovsPvlanDhcpHostPath = Script.findScript(networkScriptsDir, "ovs-pvlan-dhcp-host.sh");
if ( _ovsPvlanDhcpHostPath == null) {
throw new ConfigurationException(
"Unable to find the ovs-pvlan-dhcp-host.sh");
}
_ovsPvlanVmPath = Script.findScript(networkScriptsDir, "ovs-pvlan-vm.sh");
if ( _ovsPvlanVmPath == null) {
throw new ConfigurationException(
"Unable to find the ovs-pvlan-vm.sh");
}
String value = (String) params.get("developer"); String value = (String) params.get("developer");
boolean isDeveloper = Boolean.parseBoolean(value); boolean isDeveloper = Boolean.parseBoolean(value);
@ -1213,6 +1228,8 @@ ServerResource {
return execute((NetworkRulesVmSecondaryIpCommand) cmd); return execute((NetworkRulesVmSecondaryIpCommand) cmd);
} else if (cmd instanceof StorageSubSystemCommand) { } else if (cmd instanceof StorageSubSystemCommand) {
return this.storageHandler.handleStorageCommands((StorageSubSystemCommand)cmd); return this.storageHandler.handleStorageCommands((StorageSubSystemCommand)cmd);
} else if (cmd instanceof PvlanSetupCommand) {
return execute((PvlanSetupCommand) cmd);
} else { } else {
s_logger.warn("Unsupported command "); s_logger.warn("Unsupported command ");
return Answer.createUnsupportedCommandAnswer(cmd); return Answer.createUnsupportedCommandAnswer(cmd);
@ -1526,6 +1543,65 @@ ServerResource {
} }
} }
private Answer execute(PvlanSetupCommand cmd) {
String primaryPvlan = cmd.getPrimary();
String isolatedPvlan = cmd.getIsolated();
String op = cmd.getOp();
String dhcpName = cmd.getDhcpName();
String dhcpMac = cmd.getDhcpMac();
String dhcpIp = cmd.getDhcpIp();
String vmMac = cmd.getVmMac();
boolean add = true;
String opr = "-A";
if (op.equals("delete")) {
opr = "-D";
add = false;
}
String result = null;
Connect conn;
try {
if (cmd.getType() == PvlanSetupCommand.Type.DHCP) {
Script script = new Script(_ovsPvlanDhcpHostPath, _timeout, s_logger);
if (add) {
conn = LibvirtConnection.getConnectionByVmName(dhcpName);
List<InterfaceDef> ifaces = getInterfaces(conn, dhcpName);
InterfaceDef guestNic = ifaces.get(0);
script.add(opr, "-b", _guestBridgeName,
"-p", primaryPvlan, "-i", isolatedPvlan, "-n", dhcpName,
"-d", dhcpIp, "-m", dhcpMac, "-I", guestNic.getDevName());
} else {
script.add(opr, "-b", _guestBridgeName,
"-p", primaryPvlan, "-i", isolatedPvlan, "-n", dhcpName,
"-d", dhcpIp, "-m", dhcpMac);
}
result = script.execute();
if (result != null) {
s_logger.warn("Failed to program pvlan for dhcp server with mac " + dhcpMac);
return new Answer(cmd, false, result);
} else {
s_logger.info("Programmed pvlan for dhcp server with mac " + dhcpMac);
}
} else if (cmd.getType() == PvlanSetupCommand.Type.VM) {
Script script = new Script(_ovsPvlanVmPath, _timeout, s_logger);
script.add(opr, "-b", _guestBridgeName,
"-p", primaryPvlan, "-i", isolatedPvlan, "-v", vmMac);
result = script.execute();
if (result != null) {
s_logger.warn("Failed to program pvlan for vm with mac " + vmMac);
return new Answer(cmd, false, result);
} else {
s_logger.info("Programmed pvlan for vm with mac " + vmMac);
}
}
} catch (LibvirtException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return new Answer(cmd, true, result);
}
private void VifHotPlug(Connect conn, String vmName, String vlanId, private void VifHotPlug(Connect conn, String vmName, String vlanId,
String macAddr) throws InternalErrorException, LibvirtException { String macAddr) throws InternalErrorException, LibvirtException {
NicTO nicTO = new NicTO(); NicTO nicTO = new NicTO();
@ -2760,7 +2836,7 @@ ServerResource {
Pair<Double, Double> nicStats = getNicStats(_publicBridgeName); Pair<Double, Double> nicStats = getNicStats(_publicBridgeName);
HostStatsEntry hostStats = new HostStatsEntry(cmd.getHostId(), cpuUtil, HostStatsEntry hostStats = new HostStatsEntry(cmd.getHostId(), cpuUtil,
nicStats.first() / 1000, nicStats.second() / 1000, "host", nicStats.first() / 1024, nicStats.second() / 1024, "host",
totMem, freeMem, 0, 0); totMem, freeMem, 0, 0);
return new GetHostStatsAnswer(cmd, hostStats); return new GetHostStatsAnswer(cmd, hostStats);
} }
@ -4417,10 +4493,10 @@ ServerResource {
if (oldStats != null) { if (oldStats != null) {
long deltarx = rx - oldStats._rx; long deltarx = rx - oldStats._rx;
if (deltarx > 0) if (deltarx > 0)
stats.setNetworkReadKBs(deltarx / 1000); stats.setNetworkReadKBs(deltarx / 1024);
long deltatx = tx - oldStats._tx; long deltatx = tx - oldStats._tx;
if (deltatx > 0) if (deltatx > 0)
stats.setNetworkWriteKBs(deltatx / 1000); stats.setNetworkWriteKBs(deltatx / 1024);
} }
vmStats newStat = new vmStats(); vmStats newStat = new vmStats();

View File

@ -76,10 +76,12 @@ public class OvsVifDriver extends VifDriverBase {
} }
else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) { else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) {
logicalSwitchUuid = nic.getBroadcastUri().getSchemeSpecificPart(); logicalSwitchUuid = nic.getBroadcastUri().getSchemeSpecificPart();
} else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Pvlan) {
vlanId = NetUtils.getPrimaryPvlanFromUri(nic.getBroadcastUri());
} }
String trafficLabel = nic.getName(); String trafficLabel = nic.getName();
if (nic.getType() == Networks.TrafficType.Guest) { if (nic.getType() == Networks.TrafficType.Guest) {
if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan if ((nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan || nic.getBroadcastType() == Networks.BroadcastDomainType.Pvlan)
&& !vlanId.equalsIgnoreCase("untagged")) { && !vlanId.equalsIgnoreCase("untagged")) {
if(trafficLabel != null && !trafficLabel.isEmpty()) { if(trafficLabel != null && !trafficLabel.isEmpty()) {
s_logger.debug("creating a vlan dev and bridge for guest traffic per traffic label " + trafficLabel); s_logger.debug("creating a vlan dev and bridge for guest traffic per traffic label " + trafficLabel);

View File

@ -78,7 +78,6 @@ import com.cloud.agent.api.CreateVolumeFromSnapshotCommand;
import com.cloud.agent.api.DeleteStoragePoolCommand; import com.cloud.agent.api.DeleteStoragePoolCommand;
import com.cloud.agent.api.DeleteVMSnapshotAnswer; import com.cloud.agent.api.DeleteVMSnapshotAnswer;
import com.cloud.agent.api.DeleteVMSnapshotCommand; import com.cloud.agent.api.DeleteVMSnapshotCommand;
import com.cloud.agent.api.UnregisterVMCommand;
import com.cloud.agent.api.GetDomRVersionAnswer; import com.cloud.agent.api.GetDomRVersionAnswer;
import com.cloud.agent.api.GetDomRVersionCmd; import com.cloud.agent.api.GetDomRVersionCmd;
import com.cloud.agent.api.GetHostStatsAnswer; import com.cloud.agent.api.GetHostStatsAnswer;
@ -109,6 +108,7 @@ import com.cloud.agent.api.PlugNicCommand;
import com.cloud.agent.api.PoolEjectCommand; import com.cloud.agent.api.PoolEjectCommand;
import com.cloud.agent.api.PrepareForMigrationAnswer; import com.cloud.agent.api.PrepareForMigrationAnswer;
import com.cloud.agent.api.PrepareForMigrationCommand; import com.cloud.agent.api.PrepareForMigrationCommand;
import com.cloud.agent.api.PvlanSetupCommand;
import com.cloud.agent.api.ReadyAnswer; import com.cloud.agent.api.ReadyAnswer;
import com.cloud.agent.api.ReadyCommand; import com.cloud.agent.api.ReadyCommand;
import com.cloud.agent.api.RebootAnswer; import com.cloud.agent.api.RebootAnswer;
@ -116,8 +116,8 @@ import com.cloud.agent.api.RebootCommand;
import com.cloud.agent.api.RebootRouterCommand; import com.cloud.agent.api.RebootRouterCommand;
import com.cloud.agent.api.RevertToVMSnapshotAnswer; import com.cloud.agent.api.RevertToVMSnapshotAnswer;
import com.cloud.agent.api.RevertToVMSnapshotCommand; import com.cloud.agent.api.RevertToVMSnapshotCommand;
import com.cloud.agent.api.ScaleVmCommand;
import com.cloud.agent.api.ScaleVmAnswer; import com.cloud.agent.api.ScaleVmAnswer;
import com.cloud.agent.api.ScaleVmCommand;
import com.cloud.agent.api.SetupAnswer; import com.cloud.agent.api.SetupAnswer;
import com.cloud.agent.api.SetupCommand; import com.cloud.agent.api.SetupCommand;
import com.cloud.agent.api.SetupGuestNetworkAnswer; import com.cloud.agent.api.SetupGuestNetworkAnswer;
@ -132,6 +132,7 @@ import com.cloud.agent.api.StopCommand;
import com.cloud.agent.api.StoragePoolInfo; import com.cloud.agent.api.StoragePoolInfo;
import com.cloud.agent.api.UnPlugNicAnswer; import com.cloud.agent.api.UnPlugNicAnswer;
import com.cloud.agent.api.UnPlugNicCommand; import com.cloud.agent.api.UnPlugNicCommand;
import com.cloud.agent.api.UnregisterVMCommand;
import com.cloud.agent.api.UpgradeSnapshotCommand; import com.cloud.agent.api.UpgradeSnapshotCommand;
import com.cloud.agent.api.ValidateSnapshotAnswer; import com.cloud.agent.api.ValidateSnapshotAnswer;
import com.cloud.agent.api.ValidateSnapshotCommand; import com.cloud.agent.api.ValidateSnapshotCommand;
@ -166,14 +167,14 @@ import com.cloud.agent.api.routing.VmDataCommand;
import com.cloud.agent.api.routing.VpnUsersCfgCommand; import com.cloud.agent.api.routing.VpnUsersCfgCommand;
import com.cloud.agent.api.storage.CopyVolumeAnswer; import com.cloud.agent.api.storage.CopyVolumeAnswer;
import com.cloud.agent.api.storage.CopyVolumeCommand; import com.cloud.agent.api.storage.CopyVolumeCommand;
import com.cloud.agent.api.storage.CreateVolumeOVACommand;
import com.cloud.agent.api.storage.CreateVolumeOVAAnswer;
import com.cloud.agent.api.storage.PrepareOVAPackingAnswer;
import com.cloud.agent.api.storage.PrepareOVAPackingCommand;
import com.cloud.agent.api.storage.CreateAnswer; import com.cloud.agent.api.storage.CreateAnswer;
import com.cloud.agent.api.storage.CreateCommand; import com.cloud.agent.api.storage.CreateCommand;
import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer; import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer;
import com.cloud.agent.api.storage.CreateVolumeOVAAnswer;
import com.cloud.agent.api.storage.CreateVolumeOVACommand;
import com.cloud.agent.api.storage.DestroyCommand; import com.cloud.agent.api.storage.DestroyCommand;
import com.cloud.agent.api.storage.PrepareOVAPackingAnswer;
import com.cloud.agent.api.storage.PrepareOVAPackingCommand;
import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer; import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand; import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
import com.cloud.agent.api.storage.ResizeVolumeAnswer; import com.cloud.agent.api.storage.ResizeVolumeAnswer;
@ -289,30 +290,6 @@ import com.vmware.vim25.VirtualMachineGuestOsIdentifier;
import com.vmware.vim25.VirtualMachinePowerState; import com.vmware.vim25.VirtualMachinePowerState;
import com.vmware.vim25.VirtualMachineRuntimeInfo; import com.vmware.vim25.VirtualMachineRuntimeInfo;
import com.vmware.vim25.VirtualSCSISharing; import com.vmware.vim25.VirtualSCSISharing;
import org.apache.log4j.Logger;
import org.apache.log4j.NDC;
import javax.naming.ConfigurationException;
import java.io.File;
import java.io.IOException;
import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.net.URI;
import java.nio.channels.SocketChannel;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.TimeZone;
import java.util.UUID;
public class VmwareResource implements StoragePoolResource, ServerResource, VmwareHostService { public class VmwareResource implements StoragePoolResource, ServerResource, VmwareHostService {
@ -542,6 +519,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
return storageHandler.handleStorageCommands((StorageSubSystemCommand)cmd); return storageHandler.handleStorageCommands((StorageSubSystemCommand)cmd);
} else if (clz == ScaleVmCommand.class) { } else if (clz == ScaleVmCommand.class) {
return execute((ScaleVmCommand) cmd); return execute((ScaleVmCommand) cmd);
} else if (clz == PvlanSetupCommand.class) {
return execute((PvlanSetupCommand) cmd);
} else { } else {
answer = Answer.createUnsupportedCommandAnswer(cmd); answer = Answer.createUnsupportedCommandAnswer(cmd);
} }
@ -1084,7 +1063,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
String domrGIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP); String domrGIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP);
String domrName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); String domrName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
String gw = cmd.getAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY); String gw = cmd.getAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY);
String cidr = Long.toString(NetUtils.getCidrSize(nic.getNetmask()));; String cidr = Long.toString(NetUtils.getCidrSize(nic.getNetmask()));
String domainName = cmd.getNetworkDomain(); String domainName = cmd.getNetworkDomain();
String dns = cmd.getDefaultDns1(); String dns = cmd.getDefaultDns1();
if (dns == null || dns.isEmpty()) { if (dns == null || dns.isEmpty()) {
@ -1423,7 +1402,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
NicTO nicTo = cmd.getNic(); NicTO nicTo = cmd.getNic();
VirtualDevice nic; VirtualDevice nic;
Pair<ManagedObjectReference, String> networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(), nicTo, false); Pair<ManagedObjectReference, String> networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(), nicTo, false, cmd.getVMType());;
if (VmwareHelper.isDvPortGroup(networkInfo.first())) { if (VmwareHelper.isDvPortGroup(networkInfo.first())) {
String dvSwitchUuid; String dvSwitchUuid;
ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter(); ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter();
@ -1689,8 +1668,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
networkInfo = HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public", networkInfo = HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public",
vmMo.getRunningHost(), vlanId, null, null, _ops_timeout, true); vmMo.getRunningHost(), vlanId, null, null, _ops_timeout, true);
} else { } else {
networkInfo = HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public", networkInfo = HypervisorHostHelper.prepareNetwork(this._publicTrafficInfo.getVirtualSwitchName(), "cloud.public",
vmMo.getRunningHost(), vlanId, null, null, _ops_timeout, vSwitchType, _portsPerDvPortGroup, null, false); vmMo.getRunningHost(), vlanId, null, null, null, this._ops_timeout, vSwitchType, _portsPerDvPortGroup, null, false);
} }
int nicIndex = allocPublicNicIndex(vmMo); int nicIndex = allocPublicNicIndex(vmMo);
@ -2606,7 +2585,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
s_logger.info("Prepare NIC device based on NicTO: " + _gson.toJson(nicTo)); s_logger.info("Prepare NIC device based on NicTO: " + _gson.toJson(nicTo));
boolean configureVServiceInNexus = (nicTo.getType() == TrafficType.Guest) && (vmSpec.getDetails().containsKey("ConfigureVServiceInNexus")); boolean configureVServiceInNexus = (nicTo.getType() == TrafficType.Guest) && (vmSpec.getDetails().containsKey("ConfigureVServiceInNexus"));
Pair<ManagedObjectReference, String> networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(), nicTo, configureVServiceInNexus); VirtualMachine.Type vmType = cmd.getVirtualMachine().getType();
Pair<ManagedObjectReference, String> networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(), nicTo, configureVServiceInNexus, vmType);
if (VmwareHelper.isDvPortGroup(networkInfo.first())) { if (VmwareHelper.isDvPortGroup(networkInfo.first())) {
String dvSwitchUuid; String dvSwitchUuid;
ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter(); ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter();
@ -2790,16 +2770,28 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
return poolMors; return poolMors;
} }
private String getPvlanInfo(NicTO nicTo) {
if (nicTo.getBroadcastType() == BroadcastDomainType.Pvlan) {
return NetUtils.getIsolatedPvlanFromUri(nicTo.getBroadcastUri());
}
return null;
}
private String getVlanInfo(NicTO nicTo, String defaultVlan) { private String getVlanInfo(NicTO nicTo, String defaultVlan) {
if (nicTo.getBroadcastType() == BroadcastDomainType.Native) { if (nicTo.getBroadcastType() == BroadcastDomainType.Native) {
return defaultVlan; return defaultVlan;
} }
if (nicTo.getBroadcastType() == BroadcastDomainType.Vlan || nicTo.getBroadcastType() == BroadcastDomainType.Pvlan) {
if (nicTo.getBroadcastType() == BroadcastDomainType.Vlan) {
if (nicTo.getBroadcastUri() != null) { if (nicTo.getBroadcastUri() != null) {
if (nicTo.getBroadcastType() == BroadcastDomainType.Vlan)
// For vlan, the broadcast uri is of the form vlan://<vlanid>
return nicTo.getBroadcastUri().getHost(); return nicTo.getBroadcastUri().getHost();
else
// for pvlan, the broacast uri will be of the form pvlan://<vlanid>-i<pvlanid>
return NetUtils.getPrimaryPvlanFromUri(nicTo.getBroadcastUri());
} else { } else {
s_logger.warn("BroadcastType is not claimed as VLAN, but without vlan info in broadcast URI. Use vlan info from labeling: " + defaultVlan); s_logger.warn("BroadcastType is not claimed as VLAN or PVLAN, but without vlan info in broadcast URI. Use vlan info from labeling: " + defaultVlan);
return defaultVlan; return defaultVlan;
} }
} }
@ -2808,7 +2800,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
return defaultVlan; return defaultVlan;
} }
private Pair<ManagedObjectReference, String> prepareNetworkFromNicInfo(HostMO hostMo, NicTO nicTo, boolean configureVServiceInNexus) throws Exception { private Pair<ManagedObjectReference, String> prepareNetworkFromNicInfo(HostMO hostMo, NicTO nicTo, boolean configureVServiceInNexus, VirtualMachine.Type vmType) throws Exception {
Pair<String, String> switchName; Pair<String, String> switchName;
TrafficType trafficType; TrafficType trafficType;
VirtualSwitchType switchType; VirtualSwitchType switchType;
@ -2832,12 +2824,22 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
s_logger.info("Prepare network on " + switchType + " " + switchName + " with name prefix: " + namePrefix); s_logger.info("Prepare network on " + switchType + " " + switchName + " with name prefix: " + namePrefix);
if (VirtualSwitchType.StandardVirtualSwitch == switchType) { if (VirtualSwitchType.StandardVirtualSwitch == switchType) {
networkInfo = HypervisorHostHelper.prepareNetwork(switchName.first(), namePrefix, hostMo, getVlanInfo(nicTo, switchName.second()), networkInfo = HypervisorHostHelper.prepareNetwork(switchName.first(), namePrefix,
nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMulticastMbps(), _ops_timeout, hostMo, getVlanInfo(nicTo, switchName.second()), nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMulticastMbps(), _ops_timeout,
!namePrefix.startsWith("cloud.private")); !namePrefix.startsWith("cloud.private"));
} }
else { else {
networkInfo = HypervisorHostHelper.prepareNetwork(switchName.first(), namePrefix, hostMo, getVlanInfo(nicTo, switchName.second()), String vlanId = getVlanInfo(nicTo, switchName.second());
String svlanId = null;
boolean pvlannetwork = (getPvlanInfo(nicTo) == null)?false:true;
if (vmType != null && vmType.equals(VirtualMachine.Type.DomainRouter) && pvlannetwork) {
// plumb this network to the promiscuous vlan.
svlanId = vlanId;
} else {
// plumb this network to the isolated vlan.
svlanId = getPvlanInfo(nicTo);
}
networkInfo = HypervisorHostHelper.prepareNetwork(switchName.first(), namePrefix, hostMo, vlanId, svlanId,
nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMulticastMbps(), _ops_timeout, switchType, _portsPerDvPortGroup, nicTo.getGateway(), configureVServiceInNexus); nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMulticastMbps(), _ops_timeout, switchType, _portsPerDvPortGroup, nicTo.getGateway(), configureVServiceInNexus);
} }
@ -3324,7 +3326,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
NicTO[] nics = vm.getNics(); NicTO[] nics = vm.getNics();
for (NicTO nic : nics) { for (NicTO nic : nics) {
// prepare network on the host // prepare network on the host
prepareNetworkFromNicInfo(new HostMO(getServiceContext(), _morHyperHost), nic, false); prepareNetworkFromNicInfo(new HostMO(getServiceContext(), _morHyperHost), nic, false, cmd.getVirtualMachine().getType());
} }
String secStoreUrl = mgr.getSecondaryStorageStoreUrl(Long.parseLong(_dcId)); String secStoreUrl = mgr.getSecondaryStorageStoreUrl(Long.parseLong(_dcId));
@ -3988,6 +3990,14 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
} }
} }
protected Answer execute(PvlanSetupCommand cmd) {
// Pvlan related operations are performed in the start/stop command paths
// for vmware. This function is implemented to support mgmt layer code
// that issue this command. Note that pvlan operations are supported only
// in Distributed Virtual Switch environments for vmware deployments.
return new Answer(cmd, true, "success");
}
protected Answer execute(UnregisterVMCommand cmd){ protected Answer execute(UnregisterVMCommand cmd){
if (s_logger.isInfoEnabled()) { if (s_logger.isInfoEnabled()) {
s_logger.info("Executing resource UnregisterVMCommand: " + _gson.toJson(cmd)); s_logger.info("Executing resource UnregisterVMCommand: " + _gson.toJson(cmd));

View File

@ -133,6 +133,7 @@ import com.cloud.agent.api.PlugNicCommand;
import com.cloud.agent.api.PoolEjectCommand; import com.cloud.agent.api.PoolEjectCommand;
import com.cloud.agent.api.PrepareForMigrationAnswer; import com.cloud.agent.api.PrepareForMigrationAnswer;
import com.cloud.agent.api.PrepareForMigrationCommand; import com.cloud.agent.api.PrepareForMigrationCommand;
import com.cloud.agent.api.PvlanSetupCommand;
import com.cloud.agent.api.ReadyAnswer; import com.cloud.agent.api.ReadyAnswer;
import com.cloud.agent.api.ReadyCommand; import com.cloud.agent.api.ReadyCommand;
import com.cloud.agent.api.RebootAnswer; import com.cloud.agent.api.RebootAnswer;
@ -666,6 +667,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
return execute((NetworkRulesVmSecondaryIpCommand)cmd); return execute((NetworkRulesVmSecondaryIpCommand)cmd);
} else if (clazz == ScaleVmCommand.class) { } else if (clazz == ScaleVmCommand.class) {
return execute((ScaleVmCommand) cmd); return execute((ScaleVmCommand) cmd);
} else if (clazz == PvlanSetupCommand.class) {
return execute((PvlanSetupCommand) cmd);
} else { } else {
return Answer.createUnsupportedCommandAnswer(cmd); return Answer.createUnsupportedCommandAnswer(cmd);
} }
@ -1082,6 +1085,11 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
} else if (nic.getBroadcastType() == BroadcastDomainType.Lswitch) { } else if (nic.getBroadcastType() == BroadcastDomainType.Lswitch) {
// Nicira Logical Switch // Nicira Logical Switch
return network.getNetwork(); return network.getNetwork();
} else if (nic.getBroadcastType() == BroadcastDomainType.Pvlan) {
URI broadcastUri = nic.getBroadcastUri();
assert broadcastUri.getScheme().equals(BroadcastDomainType.Pvlan.scheme());
long vlan = Long.parseLong(NetUtils.getPrimaryPvlanFromUri(broadcastUri));
return enableVlanNetwork(conn, vlan, network);
} }
throw new CloudRuntimeException("Unable to support this type of network broadcast domain: " + nic.getBroadcastUri()); throw new CloudRuntimeException("Unable to support this type of network broadcast domain: " + nic.getBroadcastUri());
@ -1117,7 +1125,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
vifr = vif.getRecord(conn); vifr = vif.getRecord(conn);
s_logger.debug("Created a vif " + vifr.uuid + " on " + nic.getDeviceId()); s_logger.debug("Created a vif " + vifr.uuid + " on " + nic.getDeviceId());
} }
return vif; return vif;
} }
@ -1545,6 +1553,55 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
} }
} }
} }
private Answer execute(PvlanSetupCommand cmd) {
Connection conn = getConnection();
String primaryPvlan = cmd.getPrimary();
String isolatedPvlan = cmd.getIsolated();
String op = cmd.getOp();
String dhcpName = cmd.getDhcpName();
String dhcpMac = cmd.getDhcpMac();
String dhcpIp = cmd.getDhcpIp();
String vmMac = cmd.getVmMac();
String networkTag = cmd.getNetworkTag();
XsLocalNetwork nw = null;
String nwNameLabel = null;
try {
nw = getNativeNetworkForTraffic(conn, TrafficType.Guest, networkTag);
nwNameLabel = nw.getNetwork().getNameLabel(conn);
} catch (XenAPIException e) {
s_logger.warn("Fail to get network", e);
return new Answer(cmd, false, e.toString());
} catch (XmlRpcException e) {
s_logger.warn("Fail to get network", e);
return new Answer(cmd, false, e.toString());
}
String result = null;
if (cmd.getType() == PvlanSetupCommand.Type.DHCP) {
result = callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-dhcp", "op", op, "nw-label", nwNameLabel,
"primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "dhcp-name", dhcpName,
"dhcp-ip", dhcpIp, "dhcp-mac", dhcpMac);
if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) {
s_logger.warn("Failed to program pvlan for dhcp server with mac " + dhcpMac);
return new Answer(cmd, false, result);
} else {
s_logger.info("Programmed pvlan for dhcp server with mac " + dhcpMac);
}
} else if (cmd.getType() == PvlanSetupCommand.Type.VM) {
result = callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-vm", "op", op, "nw-label", nwNameLabel,
"primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "vm-mac", vmMac);
if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) {
s_logger.warn("Failed to program pvlan for vm with mac " + vmMac);
return new Answer(cmd, false, result);
} else {
s_logger.info("Programmed pvlan for vm with mac " + vmMac);
}
}
return new Answer(cmd, true, result);
}
@Override @Override
public StartAnswer execute(StartCommand cmd) { public StartAnswer execute(StartCommand cmd) {

View File

@ -80,7 +80,7 @@ under the License.
</pair> </pair>
<pair key="%aclruledn%/rule-cond-3/nw-expr2/nw-attr-qual"> <pair key="%aclruledn%/rule-cond-3/nw-expr2/nw-attr-qual">
<policyNwAttrQualifier <policyNwAttrQualifier
attrEp="destination" attrEp="source"
dn="%aclruledn%/rule-cond-3/nw-expr2/nw-attr-qual" dn="%aclruledn%/rule-cond-3/nw-expr2/nw-attr-qual"
status="created"/> status="created"/>
</pair> </pair>
@ -93,7 +93,7 @@ under the License.
name="" name=""
placement="begin" placement="begin"
status="created" status="created"
value="%deststartip%"/> value="%sourcestartip%"/>
</pair> </pair>
<pair key="%aclruledn%/rule-cond-3/nw-expr2/nw-ip-3"> <pair key="%aclruledn%/rule-cond-3/nw-expr2/nw-ip-3">
<policyIPAddress <policyIPAddress
@ -104,7 +104,7 @@ under the License.
name="" name=""
placement="end" placement="end"
status="created" status="created"
value="%destendip%"/> value="%sourceendip%"/>
</pair> </pair>
<pair key="%aclruledn%/rule-cond-4"> <pair key="%aclruledn%/rule-cond-4">
@ -161,8 +161,8 @@ under the License.
descr=value descr=value
actiontype="drop" or "permit" actiontype="drop" or "permit"
protocolvalue = "TCP" or "UDP" protocolvalue = "TCP" or "UDP"
deststartip="destination start ip" sourcestartip="source start ip"
destendip="destination end ip" sourceendip="source end ip"
deststartport="start port at destination" deststartport="start port at destination"
destendport="end port at destination" destendport="end port at destination"
--!> --!>

View File

@ -54,7 +54,7 @@ under the License.
</pair> </pair>
<pair key="%aclruledn%/rule-cond-2/nw-expr2/nw-attr-qual"> <pair key="%aclruledn%/rule-cond-2/nw-expr2/nw-attr-qual">
<policyNwAttrQualifier <policyNwAttrQualifier
attrEp="destination" attrEp="source"
dn="%aclruledn%/rule-cond-2/nw-expr2/nw-attr-qual" dn="%aclruledn%/rule-cond-2/nw-expr2/nw-attr-qual"
status="created"/> status="created"/>
</pair> </pair>
@ -67,7 +67,7 @@ under the License.
name="" name=""
placement="begin" placement="begin"
status="created" status="created"
value="%deststartip%"/> value="%sourcestartip%"/>
</pair> </pair>
<pair key="%aclruledn%/rule-cond-2/nw-expr2/nw-ip-3"> <pair key="%aclruledn%/rule-cond-2/nw-expr2/nw-ip-3">
<policyIPAddress <policyIPAddress
@ -78,7 +78,7 @@ under the License.
name="" name=""
placement="end" placement="end"
status="created" status="created"
value="%destendip%"/> value="%sourceendip%"/>
</pair> </pair>
</inConfigs> </inConfigs>
@ -89,6 +89,6 @@ under the License.
aclrulename="dummy" aclrulename="dummy"
descr=value descr=value
actiontype="drop" or "permit" actiontype="drop" or "permit"
deststartip="destination start ip" sourcestartip="source start ip"
destendip="destination end ip" sourceendip="source end ip"
--!> --!>

View File

@ -80,7 +80,7 @@ under the License.
</pair> </pair>
<pair key="%aclruledn%/rule-cond-3/nw-expr2/nw-attr-qual"> <pair key="%aclruledn%/rule-cond-3/nw-expr2/nw-attr-qual">
<policyNwAttrQualifier <policyNwAttrQualifier
attrEp="destination" attrEp="source"
dn="%aclruledn%/rule-cond-3/nw-expr2/nw-attr-qual" dn="%aclruledn%/rule-cond-3/nw-expr2/nw-attr-qual"
status="created"/> status="created"/>
</pair> </pair>
@ -93,7 +93,7 @@ under the License.
name="" name=""
placement="begin" placement="begin"
status="created" status="created"
value="%deststartip%"/> value="%sourcestartip%"/>
</pair> </pair>
<pair key="%aclruledn%/rule-cond-3/nw-expr2/nw-ip-3"> <pair key="%aclruledn%/rule-cond-3/nw-expr2/nw-ip-3">
<policyIPAddress <policyIPAddress
@ -104,7 +104,7 @@ under the License.
name="" name=""
placement="end" placement="end"
status="created" status="created"
value="%destendip%"/> value="%sourceendip%"/>
</pair> </pair>
</inConfigs> </inConfigs>
@ -116,6 +116,6 @@ under the License.
descr=value descr=value
actiontype="drop" or "permit" actiontype="drop" or "permit"
protocolvalue = "TCP" or "UDP" or "ICMP" protocolvalue = "TCP" or "UDP" or "ICMP"
deststartip="destination start ip" sourcestartip="source start ip"
destendip="destination end ip" sourceendip="source end ip"
--!> --!>

View File

@ -150,13 +150,13 @@ public interface CiscoVnmcConnection {
public boolean createTenantVDCEgressAclRule(String tenantName, public boolean createTenantVDCEgressAclRule(String tenantName,
String identifier, String policyIdentifier, String identifier, String policyIdentifier,
String protocol, String destStartIp, String destEndIp, String protocol, String sourceStartIp, String sourceEndIp,
String destStartPort, String destEndPort) String destStartPort, String destEndPort)
throws ExecutionException; throws ExecutionException;
public boolean createTenantVDCEgressAclRule(String tenantName, public boolean createTenantVDCEgressAclRule(String tenantName,
String identifier, String policyIdentifier, String identifier, String policyIdentifier,
String protocol, String destStartIp, String destEndIp) String protocol, String sourceStartIp, String sourceEndIp)
throws ExecutionException; throws ExecutionException;
public boolean deleteTenantVDCAclRule(String tenantName, public boolean deleteTenantVDCAclRule(String tenantName,

View File

@ -729,7 +729,7 @@ public class CiscoVnmcConnectionImpl implements CiscoVnmcConnection {
@Override @Override
public boolean createTenantVDCEgressAclRule(String tenantName, public boolean createTenantVDCEgressAclRule(String tenantName,
String identifier, String policyIdentifier, String identifier, String policyIdentifier,
String protocol, String destStartIp, String destEndIp, String protocol, String sourceStartIp, String sourceEndIp,
String destStartPort, String destEndPort) throws ExecutionException { String destStartPort, String destEndPort) throws ExecutionException {
String xml = VnmcXml.CREATE_EGRESS_ACL_RULE.getXml(); String xml = VnmcXml.CREATE_EGRESS_ACL_RULE.getXml();
String service = VnmcXml.CREATE_EGRESS_ACL_RULE.getService(); String service = VnmcXml.CREATE_EGRESS_ACL_RULE.getService();
@ -740,8 +740,8 @@ public class CiscoVnmcConnectionImpl implements CiscoVnmcConnection {
xml = replaceXmlValue(xml, "descr", "Egress ACL rule for Tenant VDC " + tenantName); xml = replaceXmlValue(xml, "descr", "Egress ACL rule for Tenant VDC " + tenantName);
xml = replaceXmlValue(xml, "actiontype", "permit"); xml = replaceXmlValue(xml, "actiontype", "permit");
xml = replaceXmlValue(xml, "protocolvalue", protocol); xml = replaceXmlValue(xml, "protocolvalue", protocol);
xml = replaceXmlValue(xml, "deststartip", destStartIp); xml = replaceXmlValue(xml, "sourcestartip", sourceStartIp);
xml = replaceXmlValue(xml, "destendip", destEndIp); xml = replaceXmlValue(xml, "sourceendip", sourceEndIp);
xml = replaceXmlValue(xml, "deststartport", destStartPort); xml = replaceXmlValue(xml, "deststartport", destStartPort);
xml = replaceXmlValue(xml, "destendport", destEndPort); xml = replaceXmlValue(xml, "destendport", destEndPort);
@ -759,7 +759,7 @@ public class CiscoVnmcConnectionImpl implements CiscoVnmcConnection {
@Override @Override
public boolean createTenantVDCEgressAclRule(String tenantName, public boolean createTenantVDCEgressAclRule(String tenantName,
String identifier, String policyIdentifier, String identifier, String policyIdentifier,
String protocol, String destStartIp, String destEndIp) throws ExecutionException { String protocol, String sourceStartIp, String sourceEndIp) throws ExecutionException {
String xml = VnmcXml.CREATE_GENERIC_EGRESS_ACL_RULE.getXml(); String xml = VnmcXml.CREATE_GENERIC_EGRESS_ACL_RULE.getXml();
String service = VnmcXml.CREATE_GENERIC_EGRESS_ACL_RULE.getService(); String service = VnmcXml.CREATE_GENERIC_EGRESS_ACL_RULE.getService();
if (protocol.equalsIgnoreCase("all")) { // any protocol if (protocol.equalsIgnoreCase("all")) { // any protocol
@ -773,8 +773,8 @@ public class CiscoVnmcConnectionImpl implements CiscoVnmcConnection {
xml = replaceXmlValue(xml, "aclrulename", getNameForAclRule(tenantName, identifier)); xml = replaceXmlValue(xml, "aclrulename", getNameForAclRule(tenantName, identifier));
xml = replaceXmlValue(xml, "descr", "Egress ACL rule for Tenant VDC " + tenantName); xml = replaceXmlValue(xml, "descr", "Egress ACL rule for Tenant VDC " + tenantName);
xml = replaceXmlValue(xml, "actiontype", "permit"); xml = replaceXmlValue(xml, "actiontype", "permit");
xml = replaceXmlValue(xml, "deststartip", destStartIp); xml = replaceXmlValue(xml, "sourcestartip", sourceStartIp);
xml = replaceXmlValue(xml, "destendip", destEndIp); xml = replaceXmlValue(xml, "sourceendip", sourceEndIp);
List<String> rules = listChildren(getDnForAclPolicy(tenantName, policyIdentifier)); List<String> rules = listChildren(getDnForAclPolicy(tenantName, policyIdentifier));
int order = 100; int order = 100;

View File

@ -60,6 +60,7 @@ import com.cloud.utils.Pair;
import com.cloud.utils.cisco.n1kv.vsm.NetconfHelper; import com.cloud.utils.cisco.n1kv.vsm.NetconfHelper;
import com.cloud.utils.cisco.n1kv.vsm.VsmCommand.OperationType; import com.cloud.utils.cisco.n1kv.vsm.VsmCommand.OperationType;
import com.cloud.utils.cisco.n1kv.vsm.VsmCommand.SwitchPortMode; import com.cloud.utils.cisco.n1kv.vsm.VsmCommand.SwitchPortMode;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.exception.ExecutionException; import com.cloud.utils.exception.ExecutionException;
import com.cloud.utils.net.NetUtils; import com.cloud.utils.net.NetUtils;
@ -280,30 +281,30 @@ public class CiscoVnmcResource implements ServerResource {
String policyIdentifier = cmd.getIpAddress().getPublicIp().replace('.', '-'); String policyIdentifier = cmd.getIpAddress().getPublicIp().replace('.', '-');
try { try {
if (!_connection.createTenantVDCNatPolicySet(tenant)) { if (!_connection.createTenantVDCNatPolicySet(tenant)) {
throw new Exception("Failed to create NAT policy set in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create NAT policy set in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCSourceNatPolicy(tenant, policyIdentifier)) { if (!_connection.createTenantVDCSourceNatPolicy(tenant, policyIdentifier)) {
throw new Exception("Failed to create source NAT policy in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create source NAT policy in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCSourceNatPolicyRef(tenant, policyIdentifier)) { if (!_connection.createTenantVDCSourceNatPolicyRef(tenant, policyIdentifier)) {
throw new Exception("Failed to associate source NAT policy with NAT policy set in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to associate source NAT policy with NAT policy set in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCSourceNatIpPool(tenant, policyIdentifier, cmd.getIpAddress().getPublicIp())) { if (!_connection.createTenantVDCSourceNatIpPool(tenant, policyIdentifier, cmd.getIpAddress().getPublicIp())) {
throw new Exception("Failed to create source NAT ip pool in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create source NAT ip pool in VNMC for guest network with vlan " + vlanId);
} }
String[] ipRange = getIpRangeFromCidr(cmd.getContextParam(NetworkElementCommand.GUEST_NETWORK_CIDR)); String[] ipRange = getIpRangeFromCidr(cmd.getContextParam(NetworkElementCommand.GUEST_NETWORK_CIDR));
if (!_connection.createTenantVDCSourceNatRule(tenant, policyIdentifier, ipRange[0], ipRange[1])) { if (!_connection.createTenantVDCSourceNatRule(tenant, policyIdentifier, ipRange[0], ipRange[1])) {
throw new Exception("Failed to create source NAT rule in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create source NAT rule in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.associateNatPolicySet(tenant)) { if (!_connection.associateNatPolicySet(tenant)) {
throw new Exception("Failed to associate source NAT policy set with edge security profile in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to associate source NAT policy set with edge security profile in VNMC for guest network with vlan " + vlanId);
} }
} catch (Throwable e) { } catch (ExecutionException e) {
String msg = "SetSourceNatCommand failed due to " + e.getMessage(); String msg = "SetSourceNatCommand failed due to " + e.getMessage();
s_logger.error(msg, e); s_logger.error(msg, e);
return new Answer(cmd, false, msg); return new Answer(cmd, false, msg);
@ -337,29 +338,29 @@ public class CiscoVnmcResource implements ServerResource {
try { try {
if (!_connection.createTenantVDCAclPolicySet(tenant, true)) { if (!_connection.createTenantVDCAclPolicySet(tenant, true)) {
throw new Exception("Failed to create ACL ingress policy set in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create ACL ingress policy set in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCAclPolicySet(tenant, false)) { if (!_connection.createTenantVDCAclPolicySet(tenant, false)) {
throw new Exception("Failed to create ACL egress policy set in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create ACL egress policy set in VNMC for guest network with vlan " + vlanId);
} }
for (String publicIp : publicIpRulesMap.keySet()) { for (String publicIp : publicIpRulesMap.keySet()) {
String policyIdentifier = publicIp.replace('.', '-'); String policyIdentifier = publicIp.replace('.', '-');
if (!_connection.createTenantVDCAclPolicy(tenant, policyIdentifier)) { if (!_connection.createTenantVDCAclPolicy(tenant, policyIdentifier)) {
throw new Exception("Failed to create ACL policy in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create ACL policy in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCAclPolicyRef(tenant, policyIdentifier, true)) { if (!_connection.createTenantVDCAclPolicyRef(tenant, policyIdentifier, true)) {
throw new Exception("Failed to associate ACL policy with ACL ingress policy set in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to associate ACL policy with ACL ingress policy set in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCAclPolicyRef(tenant, policyIdentifier, false)) { if (!_connection.createTenantVDCAclPolicyRef(tenant, policyIdentifier, false)) {
throw new Exception("Failed to associate ACL policy with ACL egress policy set in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to associate ACL policy with ACL egress policy set in VNMC for guest network with vlan " + vlanId);
} }
for (FirewallRuleTO rule : publicIpRulesMap.get(publicIp)) { for (FirewallRuleTO rule : publicIpRulesMap.get(publicIp)) {
if (rule.revoked()) { if (rule.revoked()) {
if (!_connection.deleteTenantVDCAclRule(tenant, Long.toString(rule.getId()), policyIdentifier)) { if (!_connection.deleteTenantVDCAclRule(tenant, Long.toString(rule.getId()), policyIdentifier)) {
throw new Exception("Failed to delete ACL rule in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to delete ACL rule in VNMC for guest network with vlan " + vlanId);
} }
} else { } else {
String[] externalIpRange = getIpRangeFromCidr(rule.getSourceCidrList().get(0)); String[] externalIpRange = getIpRangeFromCidr(rule.getSourceCidrList().get(0));
@ -370,13 +371,13 @@ public class CiscoVnmcResource implements ServerResource {
Long.toString(rule.getId()), policyIdentifier, Long.toString(rule.getId()), policyIdentifier,
rule.getProtocol().toUpperCase(), externalIpRange[0], externalIpRange[1], rule.getProtocol().toUpperCase(), externalIpRange[0], externalIpRange[1],
Integer.toString(rule.getSrcPortRange()[0]), Integer.toString(rule.getSrcPortRange()[1]))) { Integer.toString(rule.getSrcPortRange()[0]), Integer.toString(rule.getSrcPortRange()[1]))) {
throw new Exception("Failed to create ACL ingress rule in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create ACL ingress rule in VNMC for guest network with vlan " + vlanId);
} }
} else { } else {
if (!_connection.createTenantVDCIngressAclRule(tenant, if (!_connection.createTenantVDCIngressAclRule(tenant,
Long.toString(rule.getId()), policyIdentifier, Long.toString(rule.getId()), policyIdentifier,
rule.getProtocol().toUpperCase(), externalIpRange[0], externalIpRange[1])) { rule.getProtocol().toUpperCase(), externalIpRange[0], externalIpRange[1])) {
throw new Exception("Failed to create ACL ingress rule in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create ACL ingress rule in VNMC for guest network with vlan " + vlanId);
} }
} }
} else { } else {
@ -387,13 +388,13 @@ public class CiscoVnmcResource implements ServerResource {
rule.getProtocol().toUpperCase(), rule.getProtocol().toUpperCase(),
externalIpRange[0], externalIpRange[1], externalIpRange[0], externalIpRange[1],
Integer.toString(rule.getSrcPortRange()[0]), Integer.toString(rule.getSrcPortRange()[1]))) { Integer.toString(rule.getSrcPortRange()[0]), Integer.toString(rule.getSrcPortRange()[1]))) {
throw new Exception("Failed to create ACL egress rule in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create ACL egress rule in VNMC for guest network with vlan " + vlanId);
} }
} else { } else {
if (!_connection.createTenantVDCEgressAclRule(tenant, if (!_connection.createTenantVDCEgressAclRule(tenant,
Long.toString(rule.getId()), policyIdentifier, Long.toString(rule.getId()), policyIdentifier,
rule.getProtocol().toUpperCase(), externalIpRange[0], externalIpRange[1])) { rule.getProtocol().toUpperCase(), externalIpRange[0], externalIpRange[1])) {
throw new Exception("Failed to create ACL egress rule in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create ACL egress rule in VNMC for guest network with vlan " + vlanId);
} }
} }
} }
@ -402,9 +403,9 @@ public class CiscoVnmcResource implements ServerResource {
} }
if (!_connection.associateAclPolicySet(tenant)) { if (!_connection.associateAclPolicySet(tenant)) {
throw new Exception("Failed to associate ACL policy set with edge security profile in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to associate ACL policy set with edge security profile in VNMC for guest network with vlan " + vlanId);
} }
} catch (Throwable e) { } catch (ExecutionException e) {
String msg = "SetFirewallRulesCommand failed due to " + e.getMessage(); String msg = "SetFirewallRulesCommand failed due to " + e.getMessage();
s_logger.error(msg, e); s_logger.error(msg, e);
return new Answer(cmd, false, msg); return new Answer(cmd, false, msg);
@ -438,69 +439,60 @@ public class CiscoVnmcResource implements ServerResource {
try { try {
if (!_connection.createTenantVDCNatPolicySet(tenant)) { if (!_connection.createTenantVDCNatPolicySet(tenant)) {
throw new Exception("Failed to create NAT policy set in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create NAT policy set in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCAclPolicySet(tenant, true)) { if (!_connection.createTenantVDCAclPolicySet(tenant, true)) {
throw new Exception("Failed to create ACL ingress policy set in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create ACL ingress policy set in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCAclPolicySet(tenant, false)) { if (!_connection.createTenantVDCAclPolicySet(tenant, false)) {
throw new Exception("Failed to create ACL egress policy set in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create ACL egress policy set in VNMC for guest network with vlan " + vlanId);
} }
for (String publicIp : publicIpRulesMap.keySet()) { for (String publicIp : publicIpRulesMap.keySet()) {
String policyIdentifier = publicIp.replace('.', '-'); String policyIdentifier = publicIp.replace('.', '-');
if (!_connection.createTenantVDCDNatPolicy(tenant, policyIdentifier)) { if (!_connection.createTenantVDCDNatPolicy(tenant, policyIdentifier)) {
throw new Exception("Failed to create DNAT policy in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create DNAT policy in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCDNatPolicyRef(tenant, policyIdentifier)) { if (!_connection.createTenantVDCDNatPolicyRef(tenant, policyIdentifier)) {
throw new Exception("Failed to associate DNAT policy with NAT policy set in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to associate DNAT policy with NAT policy set in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCAclPolicy(tenant, policyIdentifier)) { if (!_connection.createTenantVDCAclPolicy(tenant, policyIdentifier)) {
throw new Exception("Failed to create ACL policy in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create ACL policy in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCAclPolicyRef(tenant, policyIdentifier, true)) { if (!_connection.createTenantVDCAclPolicyRef(tenant, policyIdentifier, true)) {
throw new Exception("Failed to associate ACL policy with ACL ingress policy set in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to associate ACL policy with ACL ingress policy set in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCAclPolicyRef(tenant, policyIdentifier, false)) { if (!_connection.createTenantVDCAclPolicyRef(tenant, policyIdentifier, false)) {
throw new Exception("Failed to associate ACL policy with ACL egress policy set in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to associate ACL policy with ACL egress policy set in VNMC for guest network with vlan " + vlanId);
} }
for (StaticNatRuleTO rule : publicIpRulesMap.get(publicIp)) { for (StaticNatRuleTO rule : publicIpRulesMap.get(publicIp)) {
if (rule.revoked()) { if (rule.revoked()) {
if (!_connection.deleteTenantVDCDNatRule(tenant, Long.toString(rule.getId()), policyIdentifier)) { if (!_connection.deleteTenantVDCDNatRule(tenant, Long.toString(rule.getId()), policyIdentifier)) {
throw new Exception("Failed to delete DNAT rule in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to delete DNAT rule in VNMC for guest network with vlan " + vlanId);
}
if (!_connection.deleteTenantVDCAclRule(tenant, Long.toString(rule.getId()), policyIdentifier)) {
throw new Exception("Failed to delete ACL ingress rule for DNAT in VNMC for guest network with vlan " + vlanId);
} }
} else { } else {
if (!_connection.createTenantVDCDNatIpPool(tenant, Long.toString(rule.getId()), rule.getDstIp())) { if (!_connection.createTenantVDCDNatIpPool(tenant, Long.toString(rule.getId()), rule.getDstIp())) {
throw new Exception("Failed to create DNAT ip pool in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create DNAT ip pool in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCDNatRule(tenant, if (!_connection.createTenantVDCDNatRule(tenant,
Long.toString(rule.getId()), policyIdentifier, rule.getSrcIp())) { Long.toString(rule.getId()), policyIdentifier, rule.getSrcIp())) {
throw new Exception("Failed to create DNAT rule in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create DNAT rule in VNMC for guest network with vlan " + vlanId);
}
if (!_connection.createTenantVDCAclRuleForDNat(tenant,
Long.toString(rule.getId()), policyIdentifier, rule.getDstIp())) {
throw new Exception("Failed to create ACL rule for DNAT in VNMC for guest network with vlan " + vlanId);
} }
} }
} }
} }
if (!_connection.associateAclPolicySet(tenant)) { if (!_connection.associateAclPolicySet(tenant)) {
throw new Exception("Failed to associate source NAT policy set with edge security profile in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to associate source NAT policy set with edge security profile in VNMC for guest network with vlan " + vlanId);
} }
} catch (Throwable e) { } catch (ExecutionException e) {
String msg = "SetSourceNatCommand failed due to " + e.getMessage(); String msg = "SetStaticNatRulesCommand failed due to " + e.getMessage();
s_logger.error(msg, e); s_logger.error(msg, e);
return new Answer(cmd, false, msg); return new Answer(cmd, false, msg);
} }
@ -533,77 +525,66 @@ public class CiscoVnmcResource implements ServerResource {
try { try {
if (!_connection.createTenantVDCNatPolicySet(tenant)) { if (!_connection.createTenantVDCNatPolicySet(tenant)) {
throw new Exception("Failed to create NAT policy set in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create NAT policy set in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCAclPolicySet(tenant, true)) { if (!_connection.createTenantVDCAclPolicySet(tenant, true)) {
throw new Exception("Failed to create ACL ingress policy set in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create ACL ingress policy set in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCAclPolicySet(tenant, false)) { if (!_connection.createTenantVDCAclPolicySet(tenant, false)) {
throw new Exception("Failed to create ACL egress policy set in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create ACL egress policy set in VNMC for guest network with vlan " + vlanId);
} }
for (String publicIp : publicIpRulesMap.keySet()) { for (String publicIp : publicIpRulesMap.keySet()) {
String policyIdentifier = publicIp.replace('.', '-'); String policyIdentifier = publicIp.replace('.', '-');
if (!_connection.createTenantVDCPFPolicy(tenant, policyIdentifier)) { if (!_connection.createTenantVDCPFPolicy(tenant, policyIdentifier)) {
throw new Exception("Failed to create PF policy in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create PF policy in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCPFPolicyRef(tenant, policyIdentifier)) { if (!_connection.createTenantVDCPFPolicyRef(tenant, policyIdentifier)) {
throw new Exception("Failed to associate PF policy with NAT policy set in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to associate PF policy with NAT policy set in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCAclPolicy(tenant, policyIdentifier)) { if (!_connection.createTenantVDCAclPolicy(tenant, policyIdentifier)) {
throw new Exception("Failed to create ACL policy in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create ACL policy in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCAclPolicyRef(tenant, policyIdentifier, true)) { if (!_connection.createTenantVDCAclPolicyRef(tenant, policyIdentifier, true)) {
throw new Exception("Failed to associate ACL policy with ACL ingress policy set in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to associate ACL policy with ACL ingress policy set in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCAclPolicyRef(tenant, policyIdentifier, false)) { if (!_connection.createTenantVDCAclPolicyRef(tenant, policyIdentifier, false)) {
throw new Exception("Failed to associate ACL policy with ACL egress policy set in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to associate ACL policy with ACL egress policy set in VNMC for guest network with vlan " + vlanId);
} }
for (PortForwardingRuleTO rule : publicIpRulesMap.get(publicIp)) { for (PortForwardingRuleTO rule : publicIpRulesMap.get(publicIp)) {
if (rule.revoked()) { if (rule.revoked()) {
if (!_connection.deleteTenantVDCPFRule(tenant, Long.toString(rule.getId()), policyIdentifier)) { if (!_connection.deleteTenantVDCPFRule(tenant, Long.toString(rule.getId()), policyIdentifier)) {
throw new Exception("Failed to delete PF rule in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to delete PF rule in VNMC for guest network with vlan " + vlanId);
}
if (!_connection.deleteTenantVDCAclRule(tenant, Long.toString(rule.getId()), policyIdentifier)) {
throw new Exception("Failed to delete ACL ingress rule for PF in VNMC for guest network with vlan " + vlanId);
} }
} else { } else {
if (!_connection.createTenantVDCPFIpPool(tenant, Long.toString(rule.getId()), rule.getDstIp())) { if (!_connection.createTenantVDCPFIpPool(tenant, Long.toString(rule.getId()), rule.getDstIp())) {
throw new Exception("Failed to create PF ip pool in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create PF ip pool in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCPFPortPool(tenant, Long.toString(rule.getId()), if (!_connection.createTenantVDCPFPortPool(tenant, Long.toString(rule.getId()),
Integer.toString(rule.getDstPortRange()[0]), Integer.toString(rule.getDstPortRange()[1]))) { Integer.toString(rule.getDstPortRange()[0]), Integer.toString(rule.getDstPortRange()[1]))) {
throw new Exception("Failed to create PF port pool in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create PF port pool in VNMC for guest network with vlan " + vlanId);
} }
if (!_connection.createTenantVDCPFRule(tenant, if (!_connection.createTenantVDCPFRule(tenant,
Long.toString(rule.getId()), policyIdentifier, Long.toString(rule.getId()), policyIdentifier,
rule.getProtocol().toUpperCase(), rule.getSrcIp(), rule.getProtocol().toUpperCase(), rule.getSrcIp(),
Integer.toString(rule.getSrcPortRange()[0]), Integer.toString(rule.getSrcPortRange()[1]))) { Integer.toString(rule.getSrcPortRange()[0]), Integer.toString(rule.getSrcPortRange()[1]))) {
throw new Exception("Failed to create PF rule in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create PF rule in VNMC for guest network with vlan " + vlanId);
}
if (!_connection.createTenantVDCAclRuleForPF(tenant,
Long.toString(rule.getId()), policyIdentifier,
rule.getProtocol().toUpperCase(), rule.getDstIp(),
Integer.toString(rule.getDstPortRange()[0]), Integer.toString(rule.getDstPortRange()[1]))) {
throw new Exception("Failed to create ACL rule for PF in VNMC for guest network with vlan " + vlanId);
} }
} }
} }
} }
if (!_connection.associateAclPolicySet(tenant)) { if (!_connection.associateAclPolicySet(tenant)) {
throw new Exception("Failed to associate source NAT policy set with edge security profile in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to associate source NAT policy set with edge security profile in VNMC for guest network with vlan " + vlanId);
} }
} catch (Throwable e) { } catch (ExecutionException e) {
String msg = "SetSourceNatCommand failed due to " + e.getMessage(); String msg = "SetPortForwardingRulesCommand failed due to " + e.getMessage();
s_logger.error(msg, e); s_logger.error(msg, e);
return new Answer(cmd, false, msg); return new Answer(cmd, false, msg);
} }
@ -619,24 +600,24 @@ public class CiscoVnmcResource implements ServerResource {
return execute(cmd, _numRetries); return execute(cmd, _numRetries);
} }
private void createEdgeDeviceProfile(String tenant, List<String> gateways, Long vlanId) throws Exception { private void createEdgeDeviceProfile(String tenant, List<String> gateways, Long vlanId) throws ExecutionException {
// create edge device profile // create edge device profile
if (!_connection.createTenantVDCEdgeDeviceProfile(tenant)) if (!_connection.createTenantVDCEdgeDeviceProfile(tenant))
throw new Exception("Failed to create tenant edge device profile in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create tenant edge device profile in VNMC for guest network with vlan " + vlanId);
// create edge static route policy // create edge static route policy
if (!_connection.createTenantVDCEdgeStaticRoutePolicy(tenant)) if (!_connection.createTenantVDCEdgeStaticRoutePolicy(tenant))
throw new Exception("Failed to create tenant edge static route policy in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create tenant edge static route policy in VNMC for guest network with vlan " + vlanId);
// create edge static route for all gateways // create edge static route for all gateways
for (String gateway : gateways) { for (String gateway : gateways) {
if (!_connection.createTenantVDCEdgeStaticRoute(tenant, gateway, "0.0.0.0", "0.0.0.0")) if (!_connection.createTenantVDCEdgeStaticRoute(tenant, gateway, "0.0.0.0", "0.0.0.0"))
throw new Exception("Failed to create tenant edge static route in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to create tenant edge static route in VNMC for guest network with vlan " + vlanId);
} }
// associate edge // associate edge
if (!_connection.associateTenantVDCEdgeStaticRoutePolicy(tenant)) if (!_connection.associateTenantVDCEdgeStaticRoutePolicy(tenant))
throw new Exception("Failed to associate edge static route policy with edge device profile in VNMC for guest network with vlan " + vlanId); throw new ExecutionException("Failed to associate edge static route policy with edge device profile in VNMC for guest network with vlan " + vlanId);
} }
private Answer execute(CreateLogicalEdgeFirewallCommand cmd, int numRetries) { private Answer execute(CreateLogicalEdgeFirewallCommand cmd, int numRetries) {
@ -644,23 +625,23 @@ public class CiscoVnmcResource implements ServerResource {
try { try {
// create tenant // create tenant
if (!_connection.createTenant(tenant)) if (!_connection.createTenant(tenant))
throw new Exception("Failed to create tenant in VNMC for guest network with vlan " + cmd.getVlanId()); throw new ExecutionException("Failed to create tenant in VNMC for guest network with vlan " + cmd.getVlanId());
// create tenant VDC // create tenant VDC
if (!_connection.createTenantVDC(tenant)) if (!_connection.createTenantVDC(tenant))
throw new Exception("Failed to create tenant VDC in VNMC for guest network with vlan " + cmd.getVlanId()); throw new ExecutionException("Failed to create tenant VDC in VNMC for guest network with vlan " + cmd.getVlanId());
// create edge security profile // create edge security profile
if (!_connection.createTenantVDCEdgeSecurityProfile(tenant)) if (!_connection.createTenantVDCEdgeSecurityProfile(tenant))
throw new Exception("Failed to create tenant edge security profile in VNMC for guest network with vlan " + cmd.getVlanId()); throw new ExecutionException("Failed to create tenant edge security profile in VNMC for guest network with vlan " + cmd.getVlanId());
// create edge device profile and associated route // create edge device profile and associated route
createEdgeDeviceProfile(tenant, cmd.getPublicGateways(), cmd.getVlanId()); createEdgeDeviceProfile(tenant, cmd.getPublicGateways(), cmd.getVlanId());
// create logical edge firewall // create logical edge firewall
if (!_connection.createEdgeFirewall(tenant, cmd.getPublicIp(), cmd.getInternalIp(), cmd.getPublicSubnet(), cmd.getInternalSubnet())) if (!_connection.createEdgeFirewall(tenant, cmd.getPublicIp(), cmd.getInternalIp(), cmd.getPublicSubnet(), cmd.getInternalSubnet()))
throw new Exception("Failed to create edge firewall in VNMC for guest network with vlan " + cmd.getVlanId()); throw new ExecutionException("Failed to create edge firewall in VNMC for guest network with vlan " + cmd.getVlanId());
} catch (Throwable e) { } catch (ExecutionException e) {
String msg = "CreateLogicalEdgeFirewallCommand failed due to " + e.getMessage(); String msg = "CreateLogicalEdgeFirewallCommand failed due to " + e.getMessage();
s_logger.error(msg, e); s_logger.error(msg, e);
return new Answer(cmd, false, msg); return new Answer(cmd, false, msg);
@ -688,7 +669,7 @@ public class CiscoVnmcResource implements ServerResource {
s_logger.debug("Created vservice node for ASA appliance in Cisco VSM for vlan " + vlanId); s_logger.debug("Created vservice node for ASA appliance in Cisco VSM for vlan " + vlanId);
helper.updatePortProfile(cmd.getAsaInPortProfile(), SwitchPortMode.access, params); helper.updatePortProfile(cmd.getAsaInPortProfile(), SwitchPortMode.access, params);
s_logger.debug("Updated inside port profile for ASA appliance in Cisco VSM with new vlan " + vlanId); s_logger.debug("Updated inside port profile for ASA appliance in Cisco VSM with new vlan " + vlanId);
} catch (Throwable e) { } catch (CloudRuntimeException e) {
String msg = "ConfigureVSMForASACommand failed due to " + e.getMessage(); String msg = "ConfigureVSMForASACommand failed due to " + e.getMessage();
s_logger.error(msg, e); s_logger.error(msg, e);
return new Answer(cmd, false, msg); return new Answer(cmd, false, msg);
@ -711,18 +692,18 @@ public class CiscoVnmcResource implements ServerResource {
try { try {
Map<String, String> availableAsaAppliances = _connection.listUnAssocAsa1000v(); Map<String, String> availableAsaAppliances = _connection.listUnAssocAsa1000v();
if (availableAsaAppliances.isEmpty()) { if (availableAsaAppliances.isEmpty()) {
throw new Exception("No ASA 1000v available to associate with logical edge firewall for guest vlan " + cmd.getVlanId()); throw new ExecutionException("No ASA 1000v available to associate with logical edge firewall for guest vlan " + cmd.getVlanId());
} }
String asaInstanceDn = availableAsaAppliances.get(cmd.getAsaMgmtIp()); String asaInstanceDn = availableAsaAppliances.get(cmd.getAsaMgmtIp());
if (asaInstanceDn == null) { if (asaInstanceDn == null) {
throw new Exception("Requested ASA 1000v (" + cmd.getAsaMgmtIp() + ") is not available"); throw new ExecutionException("Requested ASA 1000v (" + cmd.getAsaMgmtIp() + ") is not available");
} }
if (!_connection.assignAsa1000v(tenant, asaInstanceDn)) { if (!_connection.assignAsa1000v(tenant, asaInstanceDn)) {
throw new Exception("Failed to associate ASA 1000v (" + cmd.getAsaMgmtIp() + ") with logical edge firewall for guest vlan " + cmd.getVlanId()); throw new ExecutionException("Failed to associate ASA 1000v (" + cmd.getAsaMgmtIp() + ") with logical edge firewall for guest vlan " + cmd.getVlanId());
} }
} catch (Throwable e) { } catch (ExecutionException e) {
String msg = "AssociateAsaWithLogicalEdgeFirewallCommand failed due to " + e.getMessage(); String msg = "AssociateAsaWithLogicalEdgeFirewallCommand failed due to " + e.getMessage();
s_logger.error(msg, e); s_logger.error(msg, e);
return new Answer(cmd, false, msg); return new Answer(cmd, false, msg);
@ -743,7 +724,7 @@ public class CiscoVnmcResource implements ServerResource {
String tenant = "vlan-" + cmd.getVlanId(); String tenant = "vlan-" + cmd.getVlanId();
try { try {
_connection.deleteTenant(tenant); _connection.deleteTenant(tenant);
} catch (Throwable e) { } catch (ExecutionException e) {
String msg = "CleanupLogicalEdgeFirewallCommand failed due to " + e.getMessage(); String msg = "CleanupLogicalEdgeFirewallCommand failed due to " + e.getMessage();
s_logger.error(msg, e); s_logger.error(msg, e);
return new Answer(cmd, false, msg); return new Answer(cmd, false, msg);

View File

@ -923,13 +923,13 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
} }
@Override @Override
public boolean applyGlobalLoadBalancerRule(long zoneId, GlobalLoadBalancerConfigCommand gslbConfigCmd) public boolean applyGlobalLoadBalancerRule(long zoneId, long physicalNetworkId, GlobalLoadBalancerConfigCommand gslbConfigCmd)
throws ResourceUnavailableException { throws ResourceUnavailableException {
long zoneGslbProviderHosId = 0; long zoneGslbProviderHosId = 0;
// find the NetScaler device configured as gslb service provider in the zone // find the NetScaler device configured as gslb service provider in the zone
ExternalLoadBalancerDeviceVO nsGslbProvider = findGslbProvider(zoneId); ExternalLoadBalancerDeviceVO nsGslbProvider = findGslbProvider(zoneId, physicalNetworkId);
if (nsGslbProvider == null) { if (nsGslbProvider == null) {
String msg = "Unable to find a NetScaler configured as gslb service provider in zone " + zoneId; String msg = "Unable to find a NetScaler configured as gslb service provider in zone " + zoneId;
s_logger.debug(msg); s_logger.debug(msg);
@ -950,28 +950,37 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
return true; return true;
} }
private ExternalLoadBalancerDeviceVO findGslbProvider(long zoneId) { private ExternalLoadBalancerDeviceVO findGslbProvider(long zoneId, long physicalNetworkId) {
List<PhysicalNetworkVO> pNtwks = _physicalNetworkDao.listByZoneAndTrafficType(zoneId, TrafficType.Guest); List<PhysicalNetworkVO> pNtwks = _physicalNetworkDao.listByZoneAndTrafficType(zoneId, TrafficType.Guest);
if (pNtwks.isEmpty() || pNtwks.size() > 1) {
throw new InvalidParameterValueException("Unable to get physical network in zone id = " + zoneId); if (pNtwks == null || pNtwks.isEmpty()) {
throw new InvalidParameterValueException("Unable to get physical network: " + physicalNetworkId +
" in zone id = " + zoneId);
} else {
for (PhysicalNetwork physicalNetwork : pNtwks) {
if (physicalNetwork.getId() == physicalNetworkId) {
PhysicalNetworkVO physNetwork = pNtwks.get(0);
ExternalLoadBalancerDeviceVO nsGslbProvider = _externalLoadBalancerDeviceDao.findGslbServiceProvider(
physNetwork.getId(), Provider.Netscaler.getName());
return nsGslbProvider;
}
}
} }
PhysicalNetworkVO physNetwork = pNtwks.get(0);
ExternalLoadBalancerDeviceVO nsGslbProvider = _externalLoadBalancerDeviceDao.findGslbServiceProvider( return null;
physNetwork.getId(), Provider.Netscaler.getName());
return nsGslbProvider;
} }
@Override @Override
public boolean isServiceEnabledInZone(long zoneId) { public boolean isServiceEnabledInZone(long zoneId, long physicalNetworkId) {
ExternalLoadBalancerDeviceVO nsGslbProvider = findGslbProvider(zoneId); ExternalLoadBalancerDeviceVO nsGslbProvider = findGslbProvider(zoneId, physicalNetworkId);
//return true if a NetScaler device is configured in the zone //return true if a NetScaler device is configured in the zone
return (nsGslbProvider != null); return (nsGslbProvider != null);
} }
@Override @Override
public String getZoneGslbProviderPublicIp(long zoneId) { public String getZoneGslbProviderPublicIp(long zoneId, long physicalNetworkId) {
ExternalLoadBalancerDeviceVO nsGslbProvider = findGslbProvider(zoneId); ExternalLoadBalancerDeviceVO nsGslbProvider = findGslbProvider(zoneId, physicalNetworkId);
if (nsGslbProvider != null) { if (nsGslbProvider != null) {
return nsGslbProvider.getGslbSitePublicIP(); return nsGslbProvider.getGslbSitePublicIP();
} }
@ -979,8 +988,8 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
} }
@Override @Override
public String getZoneGslbProviderPrivateIp(long zoneId) { public String getZoneGslbProviderPrivateIp(long zoneId, long physicalNetworkId) {
ExternalLoadBalancerDeviceVO nsGslbProvider = findGslbProvider(zoneId); ExternalLoadBalancerDeviceVO nsGslbProvider = findGslbProvider(zoneId, physicalNetworkId);
if (nsGslbProvider != null) { if (nsGslbProvider != null) {
return nsGslbProvider.getGslbSitePrivateIP(); return nsGslbProvider.getGslbSitePrivateIP();
} }

View File

@ -1095,7 +1095,15 @@ public class NetscalerResource implements ServerResource {
} }
vserver.set_name(vserverName); vserver.set_name(vserverName);
vserver.set_lbmethod(lbMethod); if ("RoundRobin".equalsIgnoreCase(lbMethod)) {
vserver.set_lbmethod("ROUNDROBIN");
} else if ("LeastConn".equalsIgnoreCase(lbMethod)) {
vserver.set_lbmethod("LEASTCONNECTION");
} else if ("Proximity".equalsIgnoreCase(lbMethod)) {
vserver.set_lbmethod("RTT");
} else {
throw new ExecutionException("Unsupported LB method");
}
vserver.set_persistencetype(persistenceType); vserver.set_persistencetype(persistenceType);
if ("SOURCEIP".equalsIgnoreCase(persistenceType)) { if ("SOURCEIP".equalsIgnoreCase(persistenceType)) {
vserver.set_persistenceid(persistenceId); vserver.set_persistenceid(persistenceId);

View File

@ -0,0 +1,27 @@
#!/bin/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.
nw_label=$1
br=`xe network-list name-label="$nw_label" params=bridge |cut -d ':' -f 2 |tr -d ' ' `
pbr=`ovs-vsctl br-to-parent $br`
while [ "$br" != "$pbr" ]
do
br=$pbr
pbr=`ovs-vsctl br-to-parent $br`
done
echo $pbr

View File

@ -0,0 +1,25 @@
#!/bin/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.
#!/bin/bash
bridge=$1
dhcp_name=$2
dom_id=`xe vm-list is-control-domain=false power-state=running params=dom-id name-label=$dhcp_name|cut -d ':' -f 2 |tr -d ' ' `
iface="vif${dom_id}.0"
echo $iface

View File

@ -0,0 +1,145 @@
#!/usr/bin/python
# 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.
import cloudstack_pluginlib as lib
import logging
import os
import sys
import subprocess
import time
import XenAPIPlugin
sys.path.append("/opt/xensource/sm/")
import util
from time import localtime as _localtime, asctime as _asctime
xePath = "/opt/xensource/bin/xe"
lib.setup_logging("/var/log/ovs-pvlan.log")
dhcpSetupPath = "/opt/xensource/bin/ovs-pvlan-dhcp-host.sh"
vmSetupPath = "/opt/xensource/bin/ovs-pvlan-vm.sh"
getDhcpIfacePath = "/opt/xensource/bin/ovs-get-dhcp-iface.sh"
pvlanCleanupPath = "/opt/xensource/bin/ovs-pvlan-cleanup.sh"
getBridgePath = "/opt/xensource/bin/ovs-get-bridge.sh"
def echo(fn):
def wrapped(*v, **k):
name = fn.__name__
util.SMlog("#### VMOPS enter %s ####" % name)
res = fn(*v, **k)
util.SMlog("#### VMOPS exit %s ####" % name)
return res
return wrapped
@echo
def setup_pvlan_dhcp(session, args):
op = args.pop("op")
nw_label = args.pop("nw-label")
primary = args.pop("primary-pvlan")
isolated = args.pop("isolated-pvlan")
dhcp_name = args.pop("dhcp-name")
dhcp_ip = args.pop("dhcp-ip")
dhcp_mac = args.pop("dhcp-mac")
res = lib.check_switch()
if res != "SUCCESS":
return "FAILURE:%s" % res
logging.debug("Network is:%s" % (nw_label))
bridge = lib.do_cmd([getBridgePath, nw_label])
logging.debug("Determine bridge/switch is :%s" % (bridge))
if op == "add":
logging.debug("Try to get dhcp vm %s port on the switch:%s" % (dhcp_name, bridge))
dhcp_iface = lib.do_cmd([getDhcpIfacePath, bridge, dhcp_name])
logging.debug("About to setup dhcp vm on the switch:%s" % bridge)
res = lib.do_cmd([dhcpSetupPath, "-A", "-b", bridge, "-p", primary,
"-i", isolated, "-n", dhcp_name, "-d", dhcp_ip, "-m", dhcp_mac,
"-I", dhcp_iface])
if res:
result = "FAILURE:%s" % res
return result;
logging.debug("Setup dhcp vm on switch program done")
elif op == "delete":
logging.debug("About to remove dhcp the switch:%s" % bridge)
res = lib.do_cmd([dhcpSetupPath, "-D", "-b", bridge, "-p", primary,
"-i", isolated, "-n", dhcp_name, "-d", dhcp_ip, "-m", dhcp_mac])
if res:
result = "FAILURE:%s" % res
return result;
logging.debug("Remove DHCP on switch program done")
result = "true"
logging.debug("Setup_pvlan_dhcp completed with result:%s" % result)
return result
@echo
def setup_pvlan_vm(session, args):
op = args.pop("op")
nw_label = args.pop("nw-label")
primary = args.pop("primary-pvlan")
isolated = args.pop("isolated-pvlan")
vm_mac = args.pop("vm-mac")
trunk_port = 1
res = lib.check_switch()
if res != "SUCCESS":
return "FAILURE:%s" % res
bridge = lib.do_cmd([getBridgePath, nw_label])
logging.debug("Determine bridge/switch is :%s" % (bridge))
if op == "add":
logging.debug("About to setup vm on the switch:%s" % bridge)
res = lib.do_cmd([vmSetupPath, "-A", "-b", bridge, "-p", primary, "-i", isolated, "-v", vm_mac])
if res:
result = "FAILURE:%s" % res
return result;
logging.debug("Setup vm on switch program done")
elif op == "delete":
logging.debug("About to remove vm on the switch:%s" % bridge)
res = lib.do_cmd([vmSetupPath, "-D", "-b", bridge, "-p", primary, "-i", isolated, "-v", vm_mac])
if res:
result = "FAILURE:%s" % res
return result;
logging.debug("Remove vm on switch program done")
result = "true"
logging.debug("Setup_pvlan_vm_alone completed with result:%s" % result)
return result
@echo
def cleanup(session, args):
res = lib.check_switch()
if res != "SUCCESS":
return "FAILURE:%s" % res
res = lib.do_cmd([pvlanCleanUpPath])
if res:
result = "FAILURE:%s" % res
return result;
result = "true"
logging.debug("Setup_pvlan_vm_dhcp completed with result:%s" % result)
return result
if __name__ == "__main__":
XenAPIPlugin.dispatch({"setup-pvlan-dhcp": setup_pvlan_dhcp,
"setup-pvlan-vm": setup_pvlan_vm,
"cleanup":cleanup})

View File

@ -70,4 +70,9 @@ swift=..,0755,/opt/xensource/bin
swiftxen=..,0755,/etc/xapi.d/plugins swiftxen=..,0755,/etc/xapi.d/plugins
s3xen=..,0755,/etc/xapi.d/plugins s3xen=..,0755,/etc/xapi.d/plugins
add_to_vcpus_params_live.sh=..,0755,/opt/xensource/bin add_to_vcpus_params_live.sh=..,0755,/opt/xensource/bin
ovs-pvlan=..,0755,/etc/xapi.d/plugins
ovs-pvlan-dhcp-host.sh=../../../network,0755,/opt/xensource/bin
ovs-pvlan-vm.sh=../../../network,0755,/opt/xensource/bin
ovs-pvlan-cleanup.sh=../../../network,0755,/opt/xensource/bin
ovs-get-dhcp-iface.sh=..,0755,/opt/xensource/bin
ovs-get-bridge.sh=..,0755,/opt/xensource/bin

View File

@ -0,0 +1,23 @@
#!/bin/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.
#!/bin/bash
ovs-ofctl del-flows xenbr0
ovs-ofctl add-flow xenbr0 priority=0,actions=NORMAL

View File

@ -0,0 +1,123 @@
#!/bin/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.
#!/bin/bash
usage() {
printf "Usage: %s: (-A|-D) -b <bridge/switch> -p <primary vlan> -i <secondary isolated vlan> -n <DHCP server name> -d <DHCP server IP> -m <DHCP server MAC> -I <interface> -v <VM MAC> -h \n" $(basename $0) >&2
exit 2
}
br=
pri_vlan=
sec_iso_vlan=
dhcp_name=
dhcp_ip=
dhcp_mac=
vm_mac=
iface=
op=
while getopts 'ADb:p:i:d:m:v:n:I:h' OPTION
do
case $OPTION in
A) op="add"
;;
D) op="del"
;;
b) br="$OPTARG"
;;
p) pri_vlan="$OPTARG"
;;
i) sec_iso_vlan="$OPTARG"
;;
n) dhcp_name="$OPTARG"
;;
d) dhcp_ip="$OPTARG"
;;
m) dhcp_mac="$OPTARG"
;;
I) iface="$OPTARG"
;;
v) vm_mac="$OPTARG"
;;
h) usage
exit 1
;;
esac
done
if [ -z "$op" ]
then
echo Missing operation pararmeter!
exit 1
fi
if [ -z "$br" ]
then
echo Missing parameter bridge!
exit 1
fi
if [ -z "$pri_vlan" ]
then
echo Missing parameter primary vlan!
exit 1
fi
if [ -z "$sec_iso_vlan" ]
then
echo Missing parameter secondary isolate vlan!
exit 1
fi
if [ -z "$dhcp_name" ]
then
echo Missing parameter DHCP NAME!
exit 1
fi
if [ -z "$dhcp_ip" ]
then
echo Missing parameter DHCP IP!
exit 1
fi
if [ -z "$dhcp_mac" ]
then
echo Missing parameter DHCP MAC!
exit 1
fi
if [ "$op" == "add" -a -z "$iface" ]
then
echo Missing parameter DHCP VM interface!
exit 1
fi
if [ "$op" == "add" ]
then
dhcp_port=`ovs-ofctl show $br | grep $iface | cut -d '(' -f 1|tr -d ' '`
ovs-ofctl add-flow $br priority=200,arp,dl_vlan=$sec_iso_vlan,nw_dst=$dhcp_ip,actions=strip_vlan,output:$dhcp_port
ovs-ofctl add-flow $br priority=150,dl_vlan=$sec_iso_vlan,dl_dst=$dhcp_mac,actions=strip_vlan,output:$dhcp_port
ovs-ofctl add-flow $br priority=100,udp,dl_vlan=$sec_iso_vlan,nw_dst=255.255.255.255,tp_dst=67,actions=strip_vlan,output:$dhcp_port
else
ovs-ofctl del-flows --strict $br priority=200,arp,dl_vlan=$sec_iso_vlan,nw_dst=$dhcp_ip
ovs-ofctl del-flows --strict $br priority=150,dl_vlan=$sec_iso_vlan,dl_dst=$dhcp_mac
ovs-ofctl del-flows --strict $br priority=100,udp,dl_vlan=$sec_iso_vlan,nw_dst=255.255.255.255,tp_dst=67
fi

View File

@ -0,0 +1,99 @@
#!/bin/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.
#!/bin/bash
usage() {
printf "Usage: %s: (-A|-D) -b <bridge/switch> -p <primary vlan> -i <secondary isolated vlan> -d <DHCP server IP> -m <DHCP server MAC> -v <VM MAC> -h \n" $(basename $0) >&2
exit 2
}
br=
pri_vlan=
sec_iso_vlan=
dhcp_ip=
dhcp_mac=
vm_mac=
op=
while getopts 'ADb:p:i:d:m:v:h' OPTION
do
case $OPTION in
A) op="add"
;;
D) op="del"
;;
b) br="$OPTARG"
;;
p) pri_vlan="$OPTARG"
;;
i) sec_iso_vlan="$OPTARG"
;;
d) dhcp_ip="$OPTARG"
;;
m) dhcp_mac="$OPTARG"
;;
v) vm_mac="$OPTARG"
;;
h) usage
exit 1
;;
esac
done
if [ -z "$op" ]
then
echo Missing operation pararmeter!
exit 1
fi
if [ -z "$br" ]
then
echo Missing parameter bridge!
exit 1
fi
if [ -z "$vm_mac" ]
then
echo Missing parameter VM MAC!
exit 1
fi
if [ -z "$pri_vlan" ]
then
echo Missing parameter secondary isolate vlan!
exit 1
fi
if [ -z "$sec_iso_vlan" ]
then
echo Missing parameter secondary isolate vlan!
exit 1
fi
trunk_port=1
if [ "$op" == "add" ]
then
ovs-ofctl add-flow $br priority=50,dl_vlan=0xffff,dl_src=$vm_mac,actions=mod_vlan_vid:$sec_iso_vlan,resubmit:$trunk_port
ovs-ofctl add-flow $br priority=60,dl_vlan=$sec_iso_vlan,dl_src=$vm_mac,actions=output:$trunk_port
else
ovs-ofctl del-flows --strict $br priority=50,dl_vlan=0xffff,dl_src=$vm_mac
ovs-ofctl del-flows --strict $br priority=60,dl_vlan=$sec_iso_vlan,dl_src=$vm_mac
fi

View File

@ -90,6 +90,11 @@
<artifactId>cloud-api</artifactId> <artifactId>cloud-api</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-framework-ipc</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.cloudstack</groupId> <groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-framework-events</artifactId> <artifactId>cloud-framework-events</artifactId>

View File

@ -78,7 +78,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
@Inject ConsoleProxyDao _consoleProxyDao = null; @Inject ConsoleProxyDao _consoleProxyDao = null;
@Inject SecondaryStorageVmDao _secStorgaeVmDao = null; @Inject SecondaryStorageVmDao _secStorgaeVmDao = null;
@Inject ConfigurationDao _configDao = null; @Inject ConfigurationDao _configDao = null;
@Inject GuestOSDao _guestOSDao = null; @Inject GuestOSDao _guestOSDao = null;
@Inject GuestOSCategoryDao _guestOSCategoryDao = null; @Inject GuestOSCategoryDao _guestOSCategoryDao = null;
@Inject VMInstanceDao _vmInstanceDao = null; @Inject VMInstanceDao _vmInstanceDao = null;
@Inject ResourceManager _resourceMgr; @Inject ResourceManager _resourceMgr;
@ -88,17 +88,17 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
boolean _checkHvm = true; boolean _checkHvm = true;
protected String _allocationAlgorithm = "random"; protected String _allocationAlgorithm = "random";
@Inject CapacityManager _capacityMgr; @Inject CapacityManager _capacityMgr;
@Override @Override
public List<Host> allocateTo(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, Type type, public List<Host> allocateTo(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, Type type,
ExcludeList avoid, int returnUpTo) { ExcludeList avoid, int returnUpTo) {
return allocateTo(vmProfile, plan, type, avoid, returnUpTo, true); return allocateTo(vmProfile, plan, type, avoid, returnUpTo, true);
} }
@Override @Override
public List<Host> allocateTo(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo, boolean considerReservedCapacity) { public List<Host> allocateTo(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo, boolean considerReservedCapacity) {
long dcId = plan.getDataCenterId(); long dcId = plan.getDataCenterId();
Long podId = plan.getPodId(); Long podId = plan.getPodId();
Long clusterId = plan.getClusterId(); Long clusterId = plan.getClusterId();
@ -110,19 +110,19 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
// FirstFitAllocator should be used for user VMs only since it won't care whether the host is capable of routing or not // FirstFitAllocator should be used for user VMs only since it won't care whether the host is capable of routing or not
return new ArrayList<Host>(); return new ArrayList<Host>();
} }
if(s_logger.isDebugEnabled()){ if(s_logger.isDebugEnabled()){
s_logger.debug("Looking for hosts in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId ); s_logger.debug("Looking for hosts in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId );
} }
String hostTagOnOffering = offering.getHostTag(); String hostTagOnOffering = offering.getHostTag();
String hostTagOnTemplate = template.getTemplateTag(); String hostTagOnTemplate = template.getTemplateTag();
boolean hasSvcOfferingTag = hostTagOnOffering != null ? true : false; boolean hasSvcOfferingTag = hostTagOnOffering != null ? true : false;
boolean hasTemplateTag = hostTagOnTemplate != null ? true : false; boolean hasTemplateTag = hostTagOnTemplate != null ? true : false;
List<HostVO> clusterHosts = new ArrayList<HostVO>(); List<HostVO> clusterHosts = new ArrayList<HostVO>();
String haVmTag = (String)vmProfile.getParameter(VirtualMachineProfile.Param.HaTag); String haVmTag = (String)vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
if (haVmTag != null) { if (haVmTag != null) {
clusterHosts = _hostDao.listByHostTag(type, clusterId, podId, dcId, haVmTag); clusterHosts = _hostDao.listByHostTag(type, clusterId, podId, dcId, haVmTag);
@ -133,31 +133,31 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
List<HostVO> hostsMatchingOfferingTag = new ArrayList<HostVO>(); List<HostVO> hostsMatchingOfferingTag = new ArrayList<HostVO>();
List<HostVO> hostsMatchingTemplateTag = new ArrayList<HostVO>(); List<HostVO> hostsMatchingTemplateTag = new ArrayList<HostVO>();
if (hasSvcOfferingTag){ if (hasSvcOfferingTag){
if (s_logger.isDebugEnabled()){ if (s_logger.isDebugEnabled()){
s_logger.debug("Looking for hosts having tag specified on SvcOffering:" + hostTagOnOffering); s_logger.debug("Looking for hosts having tag specified on SvcOffering:" + hostTagOnOffering);
} }
hostsMatchingOfferingTag = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnOffering); hostsMatchingOfferingTag = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnOffering);
if (s_logger.isDebugEnabled()){ if (s_logger.isDebugEnabled()){
s_logger.debug("Hosts with tag '" + hostTagOnOffering + "' are:" + hostsMatchingOfferingTag); s_logger.debug("Hosts with tag '" + hostTagOnOffering + "' are:" + hostsMatchingOfferingTag);
} }
} }
if (hasTemplateTag){ if (hasTemplateTag){
if (s_logger.isDebugEnabled()){ if (s_logger.isDebugEnabled()){
s_logger.debug("Looking for hosts having tag specified on Template:" + hostTagOnTemplate); s_logger.debug("Looking for hosts having tag specified on Template:" + hostTagOnTemplate);
} }
hostsMatchingTemplateTag = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnTemplate); hostsMatchingTemplateTag = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnTemplate);
if (s_logger.isDebugEnabled()){ if (s_logger.isDebugEnabled()){
s_logger.debug("Hosts with tag '" + hostTagOnTemplate+"' are:" + hostsMatchingTemplateTag); s_logger.debug("Hosts with tag '" + hostTagOnTemplate+"' are:" + hostsMatchingTemplateTag);
} }
} }
if (hasSvcOfferingTag && hasTemplateTag){ if (hasSvcOfferingTag && hasTemplateTag){
hostsMatchingOfferingTag.retainAll(hostsMatchingTemplateTag); hostsMatchingOfferingTag.retainAll(hostsMatchingTemplateTag);
clusterHosts = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnTemplate); clusterHosts = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnTemplate);
if (s_logger.isDebugEnabled()){ if (s_logger.isDebugEnabled()){
s_logger.debug("Found "+ hostsMatchingOfferingTag.size() +" Hosts satisfying both tags, host ids are:" + hostsMatchingOfferingTag); s_logger.debug("Found "+ hostsMatchingOfferingTag.size() +" Hosts satisfying both tags, host ids are:" + hostsMatchingOfferingTag);
} }
clusterHosts = hostsMatchingOfferingTag; clusterHosts = hostsMatchingOfferingTag;
} else { } else {
if (hasSvcOfferingTag){ if (hasSvcOfferingTag){
@ -168,7 +168,14 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
} }
} }
} }
// add all hosts that we are not considering to the avoid list
List<HostVO> allhostsInCluster = _hostDao.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId, null);
allhostsInCluster.removeAll(clusterHosts);
for (HostVO host : allhostsInCluster) {
avoid.addHost(host.getId());
}
return allocateTo(plan, offering, template, avoid, clusterHosts, returnUpTo, considerReservedCapacity, account); return allocateTo(plan, offering, template, avoid, clusterHosts, returnUpTo, considerReservedCapacity, account);
} }
@ -226,11 +233,11 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
}else if(_allocationAlgorithm.equals("userdispersing")){ }else if(_allocationAlgorithm.equals("userdispersing")){
hosts = reorderHostsByNumberOfVms(plan, hosts, account); hosts = reorderHostsByNumberOfVms(plan, hosts, account);
} }
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("FirstFitAllocator has " + hosts.size() + " hosts to check for allocation: "+hosts); s_logger.debug("FirstFitAllocator has " + hosts.size() + " hosts to check for allocation: "+hosts);
} }
// We will try to reorder the host lists such that we give priority to hosts that have // We will try to reorder the host lists such that we give priority to hosts that have
// the minimums to support a VM's requirements // the minimums to support a VM's requirements
hosts = prioritizeHosts(template, hosts); hosts = prioritizeHosts(template, hosts);
@ -242,7 +249,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Looking for speed=" + (offering.getCpu() * offering.getSpeed()) + "Mhz, Ram=" + offering.getRamSize()); s_logger.debug("Looking for speed=" + (offering.getCpu() * offering.getSpeed()) + "Mhz, Ram=" + offering.getRamSize());
} }
List<Host> suitableHosts = new ArrayList<Host>(); List<Host> suitableHosts = new ArrayList<Host>();
for (HostVO host : hosts) { for (HostVO host : hosts) {
@ -255,7 +262,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
} }
continue; continue;
} }
//find number of guest VMs occupying capacity on this host. //find number of guest VMs occupying capacity on this host.
if (_capacityMgr.checkIfHostReachMaxGuestLimit(host)){ if (_capacityMgr.checkIfHostReachMaxGuestLimit(host)){
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
@ -285,13 +292,14 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Not using host " + host.getId() + "; numCpusGood: " + numCpusGood + "; cpuFreqGood: " + cpuFreqGood + ", host has capacity?" + hostHasCapacity); s_logger.debug("Not using host " + host.getId() + "; numCpusGood: " + numCpusGood + "; cpuFreqGood: " + cpuFreqGood + ", host has capacity?" + hostHasCapacity);
} }
avoid.addHost(host.getId());
} }
} }
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Host Allocator returning "+suitableHosts.size() +" suitable hosts"); s_logger.debug("Host Allocator returning "+suitableHosts.size() +" suitable hosts");
} }
return suitableHosts; return suitableHosts;
} }
@ -302,26 +310,26 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
long dcId = plan.getDataCenterId(); long dcId = plan.getDataCenterId();
Long podId = plan.getPodId(); Long podId = plan.getPodId();
Long clusterId = plan.getClusterId(); Long clusterId = plan.getClusterId();
List<Long> hostIdsByVmCount = _vmInstanceDao.listHostIdsByVmCount(dcId, podId, clusterId, account.getAccountId()); List<Long> hostIdsByVmCount = _vmInstanceDao.listHostIdsByVmCount(dcId, podId, clusterId, account.getAccountId());
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("List of hosts in ascending order of number of VMs: "+ hostIdsByVmCount); s_logger.debug("List of hosts in ascending order of number of VMs: "+ hostIdsByVmCount);
} }
//now filter the given list of Hosts by this ordered list //now filter the given list of Hosts by this ordered list
Map<Long, HostVO> hostMap = new HashMap<Long, HostVO>(); Map<Long, HostVO> hostMap = new HashMap<Long, HostVO>();
for (HostVO host : hosts) { for (HostVO host : hosts) {
hostMap.put(host.getId(), host); hostMap.put(host.getId(), host);
} }
List<Long> matchingHostIds = new ArrayList<Long>(hostMap.keySet()); List<Long> matchingHostIds = new ArrayList<Long>(hostMap.keySet());
hostIdsByVmCount.retainAll(matchingHostIds); hostIdsByVmCount.retainAll(matchingHostIds);
List<HostVO> reorderedHosts = new ArrayList<HostVO>(); List<HostVO> reorderedHosts = new ArrayList<HostVO>();
for(Long id: hostIdsByVmCount){ for(Long id: hostIdsByVmCount){
reorderedHosts.add(hostMap.get(id)); reorderedHosts.add(hostMap.get(id));
} }
return reorderedHosts; return reorderedHosts;
} }
@ -336,13 +344,13 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
if (template == null) { if (template == null) {
return hosts; return hosts;
} }
// Determine the guest OS category of the template // Determine the guest OS category of the template
String templateGuestOSCategory = getTemplateGuestOSCategory(template); String templateGuestOSCategory = getTemplateGuestOSCategory(template);
List<HostVO> prioritizedHosts = new ArrayList<HostVO>(); List<HostVO> prioritizedHosts = new ArrayList<HostVO>();
List<HostVO> noHvmHosts = new ArrayList<HostVO>(); List<HostVO> noHvmHosts = new ArrayList<HostVO>();
// If a template requires HVM and a host doesn't support HVM, remove it from consideration // If a template requires HVM and a host doesn't support HVM, remove it from consideration
List<HostVO> hostsToCheck = new ArrayList<HostVO>(); List<HostVO> hostsToCheck = new ArrayList<HostVO>();
if (template.isRequiresHvm()) { if (template.isRequiresHvm()) {
@ -356,7 +364,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
} else { } else {
hostsToCheck.addAll(hosts); hostsToCheck.addAll(hosts);
} }
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
if (noHvmHosts.size() > 0) { if (noHvmHosts.size() > 0) {
s_logger.debug("Not considering hosts: " + noHvmHosts + " to deploy template: " + template +" as they are not HVM enabled"); s_logger.debug("Not considering hosts: " + noHvmHosts + " to deploy template: " + template +" as they are not HVM enabled");
@ -376,10 +384,10 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
lowPriorityHosts.add(host); lowPriorityHosts.add(host);
} }
} }
hostsToCheck.removeAll(highPriorityHosts); hostsToCheck.removeAll(highPriorityHosts);
hostsToCheck.removeAll(lowPriorityHosts); hostsToCheck.removeAll(lowPriorityHosts);
// Prioritize the remaining hosts by HVM capability // Prioritize the remaining hosts by HVM capability
for (HostVO host : hostsToCheck) { for (HostVO host : hostsToCheck) {
if (!template.isRequiresHvm() && !hostSupportsHVM(host)) { if (!template.isRequiresHvm() && !hostSupportsHVM(host)) {
@ -390,21 +398,21 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
prioritizedHosts.add(host); prioritizedHosts.add(host);
} }
} }
// Merge the lists // Merge the lists
prioritizedHosts.addAll(0, highPriorityHosts); prioritizedHosts.addAll(0, highPriorityHosts);
prioritizedHosts.addAll(lowPriorityHosts); prioritizedHosts.addAll(lowPriorityHosts);
return prioritizedHosts; return prioritizedHosts;
} }
protected boolean hostSupportsHVM(HostVO host) { protected boolean hostSupportsHVM(HostVO host) {
if ( !_checkHvm ) { if ( !_checkHvm ) {
return true; return true;
} }
// Determine host capabilities // Determine host capabilities
String caps = host.getCapabilities(); String caps = host.getCapabilities();
if (caps != null) { if (caps != null) {
String[] tokens = caps.split(","); String[] tokens = caps.split(",");
for (String token : tokens) { for (String token : tokens) {
@ -413,24 +421,24 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
} }
} }
} }
return false; return false;
} }
protected String getHostGuestOSCategory(HostVO host) { protected String getHostGuestOSCategory(HostVO host) {
DetailVO hostDetail = _hostDetailsDao.findDetail(host.getId(), "guest.os.category.id"); DetailVO hostDetail = _hostDetailsDao.findDetail(host.getId(), "guest.os.category.id");
if (hostDetail != null) { if (hostDetail != null) {
String guestOSCategoryIdString = hostDetail.getValue(); String guestOSCategoryIdString = hostDetail.getValue();
long guestOSCategoryId; long guestOSCategoryId;
try { try {
guestOSCategoryId = Long.parseLong(guestOSCategoryIdString); guestOSCategoryId = Long.parseLong(guestOSCategoryIdString);
} catch (Exception e) { } catch (Exception e) {
return null; return null;
} }
GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId); GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId);
if (guestOSCategory != null) { if (guestOSCategory != null) {
return guestOSCategory.getName(); return guestOSCategory.getName();
} else { } else {
@ -440,7 +448,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
return null; return null;
} }
} }
protected String getTemplateGuestOSCategory(VMTemplateVO template) { protected String getTemplateGuestOSCategory(VMTemplateVO template) {
long guestOSId = template.getGuestOSId(); long guestOSId = template.getGuestOSId();
GuestOSVO guestOS = _guestOSDao.findById(guestOSId); GuestOSVO guestOS = _guestOSDao.findById(guestOSId);
@ -455,7 +463,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
Map<String, String> configs = _configDao.getConfiguration(params); Map<String, String> configs = _configDao.getConfiguration(params);
String opFactor = configs.get("cpu.overprovisioning.factor"); String opFactor = configs.get("cpu.overprovisioning.factor");
_factor = NumbersUtil.parseFloat(opFactor, 1); _factor = NumbersUtil.parseFloat(opFactor, 1);
String allocationAlgorithm = configs.get("vm.allocation.algorithm"); String allocationAlgorithm = configs.get("vm.allocation.algorithm");
if (allocationAlgorithm != null) { if (allocationAlgorithm != null) {
_allocationAlgorithm = allocationAlgorithm; _allocationAlgorithm = allocationAlgorithm;

View File

@ -1684,4 +1684,9 @@ public class ApiDBUtils {
public static List<? extends LoadBalancer> listSiteLoadBalancers(long gslbRuleId) { public static List<? extends LoadBalancer> listSiteLoadBalancers(long gslbRuleId) {
return _gslbService.listSiteLoadBalancers(gslbRuleId); return _gslbService.listSiteLoadBalancers(gslbRuleId);
} }
public static String getDnsNameConfiguredForGslb() {
String providerDnsName = _configDao.getValue(Config.CloudDnsName.key());
return providerDnsName;
}
} }

View File

@ -168,7 +168,7 @@ public class ApiDispatcher {
pageSize = Long.valueOf((String) pageSizeObj); pageSize = Long.valueOf((String) pageSizeObj);
} }
if ((unpackedParams.get(ApiConstants.PAGE) == null) && (pageSize != null && pageSize != BaseListCmd.PAGESIZE_UNLIMITED)) { if ((unpackedParams.get(ApiConstants.PAGE) == null) && (pageSize != null && !pageSize.equals(BaseListCmd.PAGESIZE_UNLIMITED))) {
ServerApiException ex = new ServerApiException(ApiErrorCode.PARAM_ERROR, "\"page\" parameter is required when \"pagesize\" is specified"); ServerApiException ex = new ServerApiException(ApiErrorCode.PARAM_ERROR, "\"page\" parameter is required when \"pagesize\" is specified");
ex.setCSErrorCode(CSExceptionErrorCode.getCSErrCode(ex.getClass().getName())); ex.setCSErrorCode(CSExceptionErrorCode.getCSErrCode(ex.getClass().getName()));
throw ex; throw ex;

View File

@ -792,7 +792,8 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setAlgorithm(globalLoadBalancerRule.getAlgorithm()); response.setAlgorithm(globalLoadBalancerRule.getAlgorithm());
response.setStickyMethod(globalLoadBalancerRule.getPersistence()); response.setStickyMethod(globalLoadBalancerRule.getPersistence());
response.setServiceType(globalLoadBalancerRule.getServiceType()); response.setServiceType(globalLoadBalancerRule.getServiceType());
response.setServiceDomainName(globalLoadBalancerRule.getGslbDomain()); response.setServiceDomainName(globalLoadBalancerRule.getGslbDomain() + "."
+ ApiDBUtils.getDnsNameConfiguredForGslb());
response.setName(globalLoadBalancerRule.getName()); response.setName(globalLoadBalancerRule.getName());
response.setDescription(globalLoadBalancerRule.getDescription()); response.setDescription(globalLoadBalancerRule.getDescription());
response.setRegionIdId(globalLoadBalancerRule.getRegion()); response.setRegionIdId(globalLoadBalancerRule.getRegion());

View File

@ -2468,7 +2468,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
// offerings // offerings
private boolean isPermissible(Long accountDomainId, Long offeringDomainId) { private boolean isPermissible(Long accountDomainId, Long offeringDomainId) {
if (accountDomainId == offeringDomainId) { if (accountDomainId.equals(offeringDomainId)) {
return true; // account and service offering in same domain return true; // account and service offering in same domain
} }

View File

@ -73,6 +73,7 @@ public class ServiceOfferingJoinDaoImpl extends GenericDaoBase<ServiceOfferingJo
offeringResponse.setDomainId(offering.getDomainUuid()); offeringResponse.setDomainId(offering.getDomainUuid());
offeringResponse.setNetworkRate(offering.getRateMbps()); offeringResponse.setNetworkRate(offering.getRateMbps());
offeringResponse.setHostTag(offering.getHostTag()); offeringResponse.setHostTag(offering.getHostTag());
offeringResponse.setDeploymentPlanner(offering.getDeploymentPlanner());
offeringResponse.setObjectName("serviceoffering"); offeringResponse.setObjectName("serviceoffering");
return offeringResponse; return offeringResponse;

View File

@ -106,6 +106,9 @@ public class ServiceOfferingJoinVO extends BaseViewVO implements InternalIdentit
@Column(name="domain_path") @Column(name="domain_path")
private String domainPath = null; private String domainPath = null;
@Column(name = "deployment_planner")
private String deploymentPlanner;
public ServiceOfferingJoinVO() { public ServiceOfferingJoinVO() {
} }
@ -307,5 +310,13 @@ public class ServiceOfferingJoinVO extends BaseViewVO implements InternalIdentit
this.vm_type = vm_type; this.vm_type = vm_type;
} }
public String getDeploymentPlanner() {
return deploymentPlanner;
}
public void setDeploymentPlanner(String deploymentPlanner) {
this.deploymentPlanner = deploymentPlanner;
}
} }

View File

@ -27,6 +27,8 @@ import javax.ejb.Local;
import javax.inject.Inject; import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import org.apache.cloudstack.framework.messagebus.MessageBus;
import org.apache.cloudstack.framework.messagebus.PublishScope;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -77,11 +79,14 @@ import com.cloud.utils.db.DB;
import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction; import com.cloud.utils.db.Transaction;
import com.cloud.utils.fsm.StateListener; import com.cloud.utils.fsm.StateListener;
import com.cloud.vm.UserVmDetailVO;
import com.cloud.vm.UserVmVO;
import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.Event; import com.cloud.vm.VirtualMachine.Event;
import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.UserVmDetailsDao;
import com.cloud.vm.dao.VMInstanceDao; import com.cloud.vm.dao.VMInstanceDao;
import com.cloud.vm.snapshot.VMSnapshot; import com.cloud.vm.snapshot.VMSnapshot;
import com.cloud.vm.snapshot.VMSnapshotVO; import com.cloud.vm.snapshot.VMSnapshotVO;
@ -121,6 +126,8 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
protected VMSnapshotDao _vmSnapshotDao; protected VMSnapshotDao _vmSnapshotDao;
@Inject @Inject
protected UserVmDao _userVMDao; protected UserVmDao _userVMDao;
@Inject
protected UserVmDetailsDao _userVmDetailsDao;
@Inject @Inject
ClusterDetailsDao _clusterDetailsDao; ClusterDetailsDao _clusterDetailsDao;
@ -132,6 +139,11 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
long _extraBytesPerVolume = 0; long _extraBytesPerVolume = 0;
private float _storageOverProvisioningFactor = 1.0f; private float _storageOverProvisioningFactor = 1.0f;
@Inject
MessageBus _messageBus;
private static final String MESSAGE_RESERVED_CAPACITY_FREED_FLAG = "Message.ReservedCapacityFreed.Flag";
@Override @Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_vmCapacityReleaseInterval = NumbersUtil.parseInt(_configDao.getValue(Config.CapacitySkipcountingHours.key()), 3600); _vmCapacityReleaseInterval = NumbersUtil.parseInt(_configDao.getValue(Config.CapacitySkipcountingHours.key()), 3600);
@ -552,6 +564,20 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
ServiceOffering so = offeringsMap.get(vm.getServiceOfferingId()); ServiceOffering so = offeringsMap.get(vm.getServiceOfferingId());
reservedMemory += so.getRamSize() * 1024L * 1024L; reservedMemory += so.getRamSize() * 1024L * 1024L;
reservedCpu += so.getCpu() * so.getSpeed(); reservedCpu += so.getCpu() * so.getSpeed();
} else {
// signal if not done already, that the VM has been stopped for skip.counting.hours,
// hence capacity will not be reserved anymore.
UserVmDetailVO messageSentFlag = _userVmDetailsDao.findDetail(vm.getId(), MESSAGE_RESERVED_CAPACITY_FREED_FLAG);
if (messageSentFlag == null || !Boolean.valueOf(messageSentFlag.getValue())) {
_messageBus.publish(_name, "VM_ReservedCapacity_Free", PublishScope.LOCAL, vm);
if (vm.getType() == VirtualMachine.Type.User) {
UserVmVO userVM = _userVMDao.findById(vm.getId());
_userVMDao.loadDetails(userVM);
userVM.setDetail(MESSAGE_RESERVED_CAPACITY_FREED_FLAG, "true");
_userVMDao.saveDetails(userVM);
}
}
} }
} }
@ -681,13 +707,25 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
if ((newState == State.Starting || newState == State.Migrating || event == Event.AgentReportMigrated) && vm.getHostId() != null) { if ((newState == State.Starting || newState == State.Migrating || event == Event.AgentReportMigrated) && vm.getHostId() != null) {
boolean fromLastHost = false; boolean fromLastHost = false;
if (vm.getLastHostId() == vm.getHostId()) { if (vm.getHostId().equals(vm.getLastHostId())) {
s_logger.debug("VM starting again on the last host it was stopped on"); s_logger.debug("VM starting again on the last host it was stopped on");
fromLastHost = true; fromLastHost = true;
} }
allocateVmCapacity(vm, fromLastHost); allocateVmCapacity(vm, fromLastHost);
} }
if (newState == State.Stopped) {
if (vm.getType() == VirtualMachine.Type.User) {
UserVmVO userVM = _userVMDao.findById(vm.getId());
_userVMDao.loadDetails(userVM);
// free the message sent flag if it exists
userVM.setDetail(MESSAGE_RESERVED_CAPACITY_FREED_FLAG, "false");
_userVMDao.saveDetails(userVM);
}
}
return true; return true;
} }

View File

@ -214,6 +214,8 @@ public enum Config {
SecStorageProxy("Advanced", AgentManager.class, String.class, "secstorage.proxy", null, "http proxy used by ssvm, in http://username:password@proxyserver:port format", null), SecStorageProxy("Advanced", AgentManager.class, String.class, "secstorage.proxy", null, "http proxy used by ssvm, in http://username:password@proxyserver:port format", null),
AlertPurgeInterval("Advanced", ManagementServer.class, Integer.class, "alert.purge.interval", "86400", "The interval (in seconds) to wait before running the alert purge thread", null), AlertPurgeInterval("Advanced", ManagementServer.class, Integer.class, "alert.purge.interval", "86400", "The interval (in seconds) to wait before running the alert purge thread", null),
AlertPurgeDelay("Advanced", ManagementServer.class, Integer.class, "alert.purge.delay", "0", "Alerts older than specified number days will be purged. Set this value to 0 to never delete alerts", null), AlertPurgeDelay("Advanced", ManagementServer.class, Integer.class, "alert.purge.delay", "0", "Alerts older than specified number days will be purged. Set this value to 0 to never delete alerts", null),
HostReservationReleasePeriod("Advanced", ManagementServer.class, Integer.class, "host.reservation.release.period", "300000", "The interval in milliseconds between host reservation release checks", null),
// LB HealthCheck Interval. // LB HealthCheck Interval.
LBHealthCheck("Advanced", ManagementServer.class, String.class, "healthcheck.update.interval", "600", LBHealthCheck("Advanced", ManagementServer.class, String.class, "healthcheck.update.interval", "600",
@ -235,6 +237,7 @@ public enum Config {
ApplyAllocationAlgorithmToPods("Advanced", ManagementServer.class, Boolean.class, "apply.allocation.algorithm.to.pods", "false", "If true, deployment planner applies the allocation heuristics at pods first in the given datacenter during VM resource allocation", "true,false"), ApplyAllocationAlgorithmToPods("Advanced", ManagementServer.class, Boolean.class, "apply.allocation.algorithm.to.pods", "false", "If true, deployment planner applies the allocation heuristics at pods first in the given datacenter during VM resource allocation", "true,false"),
VmUserDispersionWeight("Advanced", ManagementServer.class, Float.class, "vm.user.dispersion.weight", "1", "Weight for user dispersion heuristic (as a value between 0 and 1) applied to resource allocation during vm deployment. Weight for capacity heuristic will be (1 - weight of user dispersion)", null), VmUserDispersionWeight("Advanced", ManagementServer.class, Float.class, "vm.user.dispersion.weight", "1", "Weight for user dispersion heuristic (as a value between 0 and 1) applied to resource allocation during vm deployment. Weight for capacity heuristic will be (1 - weight of user dispersion)", null),
VmAllocationAlgorithm("Advanced", ManagementServer.class, String.class, "vm.allocation.algorithm", "random", "'random', 'firstfit', 'userdispersing', 'userconcentratedpod_random', 'userconcentratedpod_firstfit' : Order in which hosts within a cluster will be considered for VM/volume allocation.", null), VmAllocationAlgorithm("Advanced", ManagementServer.class, String.class, "vm.allocation.algorithm", "random", "'random', 'firstfit', 'userdispersing', 'userconcentratedpod_random', 'userconcentratedpod_firstfit' : Order in which hosts within a cluster will be considered for VM/volume allocation.", null),
VmDeploymentPlanner("Advanced", ManagementServer.class, String.class, "vm.deployment.planner", "FirstFitPlanner", "'FirstFitPlanner', 'UserDispersingPlanner', 'UserConcentratedPodPlanner': DeploymentPlanner heuristic that will be used for VM deployment.", null),
EndpointeUrl("Advanced", ManagementServer.class, String.class, "endpointe.url", "http://localhost:8080/client/api", "Endpointe Url", null), EndpointeUrl("Advanced", ManagementServer.class, String.class, "endpointe.url", "http://localhost:8080/client/api", "Endpointe Url", null),
ElasticLoadBalancerEnabled("Advanced", ManagementServer.class, String.class, "network.loadbalancer.basiczone.elb.enabled", "false", "Whether the load balancing service is enabled for basic zones", "true,false"), ElasticLoadBalancerEnabled("Advanced", ManagementServer.class, String.class, "network.loadbalancer.basiczone.elb.enabled", "false", "Whether the load balancing service is enabled for basic zones", "true,false"),
ElasticLoadBalancerNetwork("Advanced", ManagementServer.class, String.class, "network.loadbalancer.basiczone.elb.network", "guest", "Whether the elastic load balancing service public ips are taken from the public or guest network", "guest,public"), ElasticLoadBalancerNetwork("Advanced", ManagementServer.class, String.class, "network.loadbalancer.basiczone.elb.network", "guest", "Whether the elastic load balancing service public ips are taken from the public or guest network", "guest,public"),

View File

@ -79,10 +79,11 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
* TODO * TODO
* @param id * @param id
* @param useVirtualNetwork * @param useVirtualNetwork
* @param deploymentPlanner
* @return ID * @return ID
*/ */
ServiceOfferingVO createServiceOffering(long userId, boolean isSystem, VirtualMachine.Type vm_typeType, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, ServiceOfferingVO createServiceOffering(long userId, boolean isSystem, VirtualMachine.Type vm_typeType, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired,
boolean offerHA, boolean limitResourceUse, boolean volatileVm, String tags, Long domainId, String hostTag, Integer networkRate); boolean offerHA, boolean limitResourceUse, boolean volatileVm, String tags, Long domainId, String hostTag, Integer networkRate, String deploymentPlanner);
/** /**
* Creates a new disk offering * Creates a new disk offering

View File

@ -162,6 +162,7 @@ import com.cloud.org.Grouping.AllocationState;
import com.cloud.projects.Project; import com.cloud.projects.Project;
import com.cloud.projects.ProjectManager; import com.cloud.projects.ProjectManager;
import com.cloud.server.ConfigurationServer; import com.cloud.server.ConfigurationServer;
import com.cloud.server.ManagementService;
import com.cloud.service.ServiceOfferingVO; import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.DiskOfferingVO;
@ -345,6 +346,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
@Inject @Inject
NicIpAliasDao _nicIpAliasDao; NicIpAliasDao _nicIpAliasDao;
@Inject
public ManagementService _mgr;
// FIXME - why don't we have interface for DataCenterLinkLocalIpAddressDao? // FIXME - why don't we have interface for DataCenterLinkLocalIpAddressDao?
@Inject protected DataCenterLinkLocalIpAddressDao _LinkLocalIpAllocDao; @Inject protected DataCenterLinkLocalIpAddressDao _LinkLocalIpAllocDao;
@ -2033,17 +2037,29 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
throw new InvalidParameterValueException("Network rate can be specified only for non-System offering and system offerings having \"domainrouter\" systemvmtype"); throw new InvalidParameterValueException("Network rate can be specified only for non-System offering and system offerings having \"domainrouter\" systemvmtype");
} }
if (cmd.getDeploymentPlanner() != null) {
List<String> planners = _mgr.listDeploymentPlanners();
if (planners != null && !planners.isEmpty()) {
if (!planners.contains(cmd.getDeploymentPlanner())) {
throw new InvalidParameterValueException(
"Invalid name for Deployment Planner specified, please use listDeploymentPlanners to get the valid set");
}
} else {
throw new InvalidParameterValueException("No deployment planners found");
}
}
return createServiceOffering(userId, cmd.getIsSystem(), vmType, cmd.getServiceOfferingName(), cpuNumber.intValue(), memory.intValue(), cpuSpeed.intValue(), cmd.getDisplayText(), return createServiceOffering(userId, cmd.getIsSystem(), vmType, cmd.getServiceOfferingName(), cpuNumber.intValue(), memory.intValue(), cpuSpeed.intValue(), cmd.getDisplayText(),
localStorageRequired, offerHA, limitCpuUse, volatileVm, cmd.getTags(), cmd.getDomainId(), cmd.getHostTag(), cmd.getNetworkRate()); localStorageRequired, offerHA, limitCpuUse, volatileVm, cmd.getTags(), cmd.getDomainId(), cmd.getHostTag(), cmd.getNetworkRate(), cmd.getDeploymentPlanner());
} }
@Override @Override
@ActionEvent(eventType = EventTypes.EVENT_SERVICE_OFFERING_CREATE, eventDescription = "creating service offering") @ActionEvent(eventType = EventTypes.EVENT_SERVICE_OFFERING_CREATE, eventDescription = "creating service offering")
public ServiceOfferingVO createServiceOffering(long userId, boolean isSystem, VirtualMachine.Type vm_type, String name, int cpu, int ramSize, int speed, String displayText, public ServiceOfferingVO createServiceOffering(long userId, boolean isSystem, VirtualMachine.Type vm_type, String name, int cpu, int ramSize, int speed, String displayText,
boolean localStorageRequired, boolean offerHA, boolean limitResourceUse, boolean volatileVm, String tags, Long domainId, String hostTag, Integer networkRate) { boolean localStorageRequired, boolean offerHA, boolean limitResourceUse, boolean volatileVm, String tags, Long domainId, String hostTag, Integer networkRate, String deploymentPlanner) {
tags = cleanupTags(tags); tags = cleanupTags(tags);
ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, null, offerHA, limitResourceUse, volatileVm, displayText, localStorageRequired, false, tags, isSystem, vm_type, ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, null, offerHA, limitResourceUse, volatileVm, displayText, localStorageRequired, false, tags, isSystem, vm_type,
domainId, hostTag); domainId, hostTag, deploymentPlanner);
if ((offering = _serviceOfferingDao.persist(offering)) != null) { if ((offering = _serviceOfferingDao.persist(offering)) != null) {
UserContext.current().setEventDetails("Service offering id=" + offering.getId()); UserContext.current().setEventDetails("Service offering id=" + offering.getId());
@ -2490,7 +2506,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
if ( vlans != null && vlans.size() > 0 ) { if ( vlans != null && vlans.size() > 0 ) {
if ( vlanId == null ) { if ( vlanId == null ) {
vlanId = vlan.getVlanTag(); vlanId = vlan.getVlanTag();
} else if ( vlan.getVlanTag() != vlanId ) { } else if (!vlan.getVlanTag().equals(vlanId)) {
throw new InvalidParameterValueException("there is already one vlan " + vlan.getVlanTag() + " on network :" + throw new InvalidParameterValueException("there is already one vlan " + vlan.getVlanTag() + " on network :" +
+ network.getId() + ", only one vlan is allowed on guest network"); + network.getId() + ", only one vlan is allowed on guest network");
} }
@ -2656,6 +2672,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
if (uri != null) { if (uri != null) {
String[] vlan = uri.toString().split("vlan:\\/\\/"); String[] vlan = uri.toString().split("vlan:\\/\\/");
networkVlanId = vlan[1]; networkVlanId = vlan[1];
//For pvlan
networkVlanId = networkVlanId.split("-")[0];
} }
if (vlanId != null) { if (vlanId != null) {

View File

@ -57,7 +57,7 @@ AgentBasedConsoleProxyManager {
if (allocatedHost == null) { if (allocatedHost == null) {
/*Is there a consoleproxy agent running in the same pod?*/ /*Is there a consoleproxy agent running in the same pod?*/
for (HostVO hv : hosts) { for (HostVO hv : hosts) {
if (hv.getType() == Host.Type.ConsoleProxy && hv.getPodId() == host.getPodId()) { if (hv.getType() == Host.Type.ConsoleProxy && hv.getPodId().equals(host.getPodId())) {
allocatedHost = hv; allocatedHost = hv;
break; break;
} }

View File

@ -1,84 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.deploy;
import java.util.Map;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.utils.component.AdapterBase;
import com.cloud.vm.UserVmVO;
public abstract class AbstractDeployPlannerSelector extends AdapterBase implements DeployPlannerSelector {
protected Map<String, Object> params;
protected String name;
protected int runLevel;
@Inject
protected ConfigurationDao _configDao;
protected String _allocationAlgorithm = "random";
@Override
public String getName() {
return name;
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
public void setConfigParams(Map<String, Object> params) {
this.params = params;
}
@Override
public Map<String, Object> getConfigParams() {
return params;
}
@Override
public int getRunLevel() {
return runLevel;
}
@Override
public void setRunLevel(int level) {
this.runLevel = level;
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
super.configure(name, params);
_allocationAlgorithm = _configDao.getValue(Config.VmAllocationAlgorithm.key());
return true;
}
@Override
public boolean start() {
return true;
}
@Override
public boolean stop() {
return true;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -49,6 +49,7 @@ import com.cloud.dc.Pod;
import com.cloud.dc.dao.ClusterDao; import com.cloud.dc.dao.ClusterDao;
import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.HostPodDao; import com.cloud.dc.dao.HostPodDao;
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
import com.cloud.exception.InsufficientServerCapacityException; import com.cloud.exception.InsufficientServerCapacityException;
import com.cloud.host.Host; import com.cloud.host.Host;
import com.cloud.host.HostVO; import com.cloud.host.HostVO;
@ -81,7 +82,7 @@ import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.VMInstanceDao; import com.cloud.vm.dao.VMInstanceDao;
@Local(value=DeploymentPlanner.class) @Local(value=DeploymentPlanner.class)
public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPlanner {
private static final Logger s_logger = Logger.getLogger(FirstFitPlanner.class); private static final Logger s_logger = Logger.getLogger(FirstFitPlanner.class);
@Inject protected HostDao _hostDao; @Inject protected HostDao _hostDao;
@Inject protected DataCenterDao _dcDao; @Inject protected DataCenterDao _dcDao;
@ -103,28 +104,13 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
@Inject DataStoreManager dataStoreMgr; @Inject DataStoreManager dataStoreMgr;
@Inject protected ClusterDetailsDao _clusterDetailsDao; @Inject protected ClusterDetailsDao _clusterDetailsDao;
protected List<StoragePoolAllocator> _storagePoolAllocators;
public List<StoragePoolAllocator> getStoragePoolAllocators() {
return _storagePoolAllocators;
}
public void setStoragePoolAllocators(
List<StoragePoolAllocator> _storagePoolAllocators) {
this._storagePoolAllocators = _storagePoolAllocators;
}
protected List<HostAllocator> _hostAllocators;
public List<HostAllocator> getHostAllocators() {
return _hostAllocators;
}
public void setHostAllocators(List<HostAllocator> _hostAllocators) {
this._hostAllocators = _hostAllocators;
}
protected String _allocationAlgorithm = "random"; protected String _allocationAlgorithm = "random";
protected String _globalDeploymentPlanner = "FirstFitPlanner";
@Override @Override
public DeployDestination plan(VirtualMachineProfile<? extends VirtualMachine> vmProfile, public List<Long> orderClusters(VirtualMachineProfile<? extends VirtualMachine> vmProfile,
DeploymentPlan plan, ExcludeList avoid) DeploymentPlan plan, ExcludeList avoid)
throws InsufficientServerCapacityException { throws InsufficientServerCapacityException {
VirtualMachine vm = vmProfile.getVirtualMachine(); VirtualMachine vm = vmProfile.getVirtualMachine();
@ -138,136 +124,19 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
return null; return null;
} }
ServiceOffering offering = vmProfile.getServiceOffering();
int cpu_requested = offering.getCpu() * offering.getSpeed();
long ram_requested = offering.getRamSize() * 1024L * 1024L;
if (s_logger.isDebugEnabled()) {
s_logger.debug("DeploymentPlanner allocation algorithm: "+_allocationAlgorithm);
s_logger.debug("Trying to allocate a host and storage pools from dc:" + plan.getDataCenterId() + ", pod:" + plan.getPodId() + ",cluster:" + plan.getClusterId() +
", requested cpu: " + cpu_requested + ", requested ram: " + ram_requested);
s_logger.debug("Is ROOT volume READY (pool already allocated)?: " + (plan.getPoolId()!=null ? "Yes": "No"));
}
String haVmTag = (String)vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
if(plan.getHostId() != null && haVmTag == null){
Long hostIdSpecified = plan.getHostId();
if (s_logger.isDebugEnabled()){
s_logger.debug("DeploymentPlan has host_id specified, choosing this host and making no checks on this host: "
+ hostIdSpecified);
}
HostVO host = _hostDao.findById(hostIdSpecified);
if (host == null) {
s_logger.debug("The specified host cannot be found");
} else if (avoid.shouldAvoid(host)) {
s_logger.debug("The specified host is in avoid set");
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Looking for suitable pools for this host under zone: "+host.getDataCenterId() +", pod: "+ host.getPodId()+", cluster: "+ host.getClusterId());
}
// search for storage under the zone, pod, cluster of the host.
DataCenterDeployment lastPlan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(),
host.getClusterId(), hostIdSpecified, plan.getPoolId(), null, plan.getReservationContext());
Pair<Map<Volume, List<StoragePool>>, List<Volume>> result = findSuitablePoolsForVolumes(vmProfile,
lastPlan, avoid, HostAllocator.RETURN_UPTO_ALL);
Map<Volume, List<StoragePool>> suitableVolumeStoragePools = result.first();
List<Volume> readyAndReusedVolumes = result.second();
// choose the potential pool for this VM for this host
if (!suitableVolumeStoragePools.isEmpty()) {
List<Host> suitableHosts = new ArrayList<Host>();
suitableHosts.add(host);
Pair<Host, Map<Volume, StoragePool>> potentialResources = findPotentialDeploymentResources(
suitableHosts, suitableVolumeStoragePools);
if (potentialResources != null) {
Pod pod = _podDao.findById(host.getPodId());
Cluster cluster = _clusterDao.findById(host.getClusterId());
Map<Volume, StoragePool> storageVolMap = potentialResources.second();
// remove the reused vol<->pool from destination, since
// we don't have to prepare this volume.
for (Volume vol : readyAndReusedVolumes) {
storageVolMap.remove(vol);
}
DeployDestination dest = new DeployDestination(dc, pod, cluster, host, storageVolMap);
s_logger.debug("Returning Deployment Destination: " + dest);
return dest;
}
}
}
s_logger.debug("Cannnot deploy to specified host, returning.");
return null;
}
if (vm.getLastHostId() != null && haVmTag == null) {
s_logger.debug("This VM has last host_id specified, trying to choose the same host: " +vm.getLastHostId());
HostVO host = _hostDao.findById(vm.getLastHostId());
if(host == null){
s_logger.debug("The last host of this VM cannot be found");
}else if(avoid.shouldAvoid(host)){
s_logger.debug("The last host of this VM is in avoid set");
}else if(_capacityMgr.checkIfHostReachMaxGuestLimit(host)){
s_logger.debug("The last Host, hostId: "+ host.getId() +" already has max Running VMs(count includes system VMs), skipping this and trying other available hosts");
}else{
if (host.getStatus() == Status.Up && host.getResourceState() == ResourceState.Enabled) {
long cluster_id = host.getClusterId();
ClusterDetailsVO cluster_detail_cpu = _clusterDetailsDao.findDetail(cluster_id,"cpuOvercommitRatio");
ClusterDetailsVO cluster_detail_ram = _clusterDetailsDao.findDetail(cluster_id,"memoryOvercommitRatio");
Float cpuOvercommitRatio = Float.parseFloat(cluster_detail_cpu.getValue());
Float memoryOvercommitRatio = Float.parseFloat(cluster_detail_ram.getValue());
if(_capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, true, cpuOvercommitRatio, memoryOvercommitRatio, true)){
s_logger.debug("The last host of this VM is UP and has enough capacity");
s_logger.debug("Now checking for suitable pools under zone: "+host.getDataCenterId() +", pod: "+ host.getPodId()+", cluster: "+ host.getClusterId());
//search for storage under the zone, pod, cluster of the last host.
DataCenterDeployment lastPlan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), plan.getPoolId(), null);
Pair<Map<Volume, List<StoragePool>>, List<Volume>> result = findSuitablePoolsForVolumes(vmProfile, lastPlan, avoid, HostAllocator.RETURN_UPTO_ALL);
Map<Volume, List<StoragePool>> suitableVolumeStoragePools = result.first();
List<Volume> readyAndReusedVolumes = result.second();
//choose the potential pool for this VM for this host
if(!suitableVolumeStoragePools.isEmpty()){
List<Host> suitableHosts = new ArrayList<Host>();
suitableHosts.add(host);
Pair<Host, Map<Volume, StoragePool>> potentialResources = findPotentialDeploymentResources(suitableHosts, suitableVolumeStoragePools);
if(potentialResources != null){
Pod pod = _podDao.findById(host.getPodId());
Cluster cluster = _clusterDao.findById(host.getClusterId());
Map<Volume, StoragePool> storageVolMap = potentialResources.second();
// remove the reused vol<->pool from destination, since we don't have to prepare this volume.
for(Volume vol : readyAndReusedVolumes){
storageVolMap.remove(vol);
}
DeployDestination dest = new DeployDestination(dc, pod, cluster, host, storageVolMap);
s_logger.debug("Returning Deployment Destination: "+ dest);
return dest;
}
}
}else{
s_logger.debug("The last host of this VM does not have enough capacity");
}
}else{
s_logger.debug("The last host of this VM is not UP or is not enabled, host status is: "+host.getStatus().name() + ", host resource state is: "+host.getResourceState());
}
}
s_logger.debug("Cannot choose the last host to deploy this VM ");
}
List<Long> clusterList = new ArrayList<Long>(); List<Long> clusterList = new ArrayList<Long>();
if (plan.getClusterId() != null) { if (plan.getClusterId() != null) {
Long clusterIdSpecified = plan.getClusterId(); Long clusterIdSpecified = plan.getClusterId();
s_logger.debug("Searching resources only under specified Cluster: "+ clusterIdSpecified); s_logger.debug("Searching resources only under specified Cluster: "+ clusterIdSpecified);
ClusterVO cluster = _clusterDao.findById(plan.getClusterId()); ClusterVO cluster = _clusterDao.findById(plan.getClusterId());
if (cluster != null ){ if (cluster != null ){
clusterList.add(clusterIdSpecified); if (avoid.shouldAvoid(cluster)) {
return checkClustersforDestination(clusterList, vmProfile, plan, avoid, dc); s_logger.debug("The specified cluster is in avoid set, returning.");
} else {
clusterList.add(clusterIdSpecified);
removeClustersCrossingThreshold(clusterList, avoid, vmProfile, plan);
}
return clusterList;
}else{ }else{
s_logger.debug("The specified cluster cannot be found, returning."); s_logger.debug("The specified cluster cannot be found, returning.");
avoid.addCluster(plan.getClusterId()); avoid.addCluster(plan.getClusterId());
@ -280,11 +149,15 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
HostPodVO pod = _podDao.findById(podIdSpecified); HostPodVO pod = _podDao.findById(podIdSpecified);
if (pod != null) { if (pod != null) {
DeployDestination dest = scanClustersForDestinationInZoneOrPod(podIdSpecified, false, vmProfile, plan, avoid); if (avoid.shouldAvoid(pod)) {
if(dest == null){ s_logger.debug("The specified pod is in avoid set, returning.");
avoid.addPod(plan.getPodId()); } else {
clusterList = scanClustersForDestinationInZoneOrPod(podIdSpecified, false, vmProfile, plan, avoid);
if (clusterList == null) {
avoid.addPod(plan.getPodId());
}
} }
return dest; return clusterList;
} else { } else {
s_logger.debug("The specified Pod cannot be found, returning."); s_logger.debug("The specified Pod cannot be found, returning.");
avoid.addPod(plan.getPodId()); avoid.addPod(plan.getPodId());
@ -305,7 +178,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
} }
private DeployDestination scanPodsForDestination(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid){ private List<Long> scanPodsForDestination(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid){
ServiceOffering offering = vmProfile.getServiceOffering(); ServiceOffering offering = vmProfile.getServiceOffering();
int requiredCpu = offering.getCpu() * offering.getSpeed(); int requiredCpu = offering.getCpu() * offering.getSpeed();
@ -341,20 +214,24 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
if(!podsWithCapacity.isEmpty()){ if(!podsWithCapacity.isEmpty()){
prioritizedPodIds = reorderPods(podCapacityInfo, vmProfile, plan); prioritizedPodIds = reorderPods(podCapacityInfo, vmProfile, plan);
if (prioritizedPodIds == null || prioritizedPodIds.isEmpty()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("No Pods found for destination, returning.");
}
return null;
}
List<Long> clusterList = new ArrayList<Long>();
//loop over pods //loop over pods
for(Long podId : prioritizedPodIds){ for(Long podId : prioritizedPodIds){
s_logger.debug("Checking resources under Pod: "+podId); s_logger.debug("Checking resources under Pod: "+podId);
DeployDestination dest = scanClustersForDestinationInZoneOrPod(podId, false, vmProfile, plan, avoid); List<Long> clustersUnderPod = scanClustersForDestinationInZoneOrPod(podId, false, vmProfile, plan,
if(dest != null){ avoid);
return dest; if (clustersUnderPod != null) {
clusterList.addAll(clustersUnderPod);
} }
avoid.addPod(podId);
} }
if (s_logger.isDebugEnabled()) { return clusterList;
s_logger.debug("No Pods found for destination, returning.");
}
return null;
}else{ }else{
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("No Pods found after removing disabled pods and pods in avoid list, returning."); s_logger.debug("No Pods found after removing disabled pods and pods in avoid list, returning.");
@ -363,7 +240,69 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
} }
} }
private DeployDestination scanClustersForDestinationInZoneOrPod(long id, boolean isZone, VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid){ private Map<Short, Float> getCapacityThresholdMap() {
// Lets build this real time so that the admin wont have to restart MS
// if he changes these values
Map<Short, Float> disableThresholdMap = new HashMap<Short, Float>();
String cpuDisableThresholdString = _configDao.getValue(Config.CPUCapacityDisableThreshold.key());
float cpuDisableThreshold = NumbersUtil.parseFloat(cpuDisableThresholdString, 0.85F);
disableThresholdMap.put(Capacity.CAPACITY_TYPE_CPU, cpuDisableThreshold);
String memoryDisableThresholdString = _configDao.getValue(Config.MemoryCapacityDisableThreshold.key());
float memoryDisableThreshold = NumbersUtil.parseFloat(memoryDisableThresholdString, 0.85F);
disableThresholdMap.put(Capacity.CAPACITY_TYPE_MEMORY, memoryDisableThreshold);
return disableThresholdMap;
}
private List<Short> getCapacitiesForCheckingThreshold() {
List<Short> capacityList = new ArrayList<Short>();
capacityList.add(Capacity.CAPACITY_TYPE_CPU);
capacityList.add(Capacity.CAPACITY_TYPE_MEMORY);
return capacityList;
}
private void removeClustersCrossingThreshold(List<Long> clusterListForVmAllocation, ExcludeList avoid,
VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan) {
List<Short> capacityList = getCapacitiesForCheckingThreshold();
List<Long> clustersCrossingThreshold = new ArrayList<Long>();
ServiceOffering offering = vmProfile.getServiceOffering();
int cpu_requested = offering.getCpu() * offering.getSpeed();
long ram_requested = offering.getRamSize() * 1024L * 1024L;
// For each capacity get the cluster list crossing the threshold and
// remove it from the clusterList that will be used for vm allocation.
for (short capacity : capacityList) {
if (clusterListForVmAllocation == null || clusterListForVmAllocation.size() == 0) {
return;
}
if (capacity == Capacity.CAPACITY_TYPE_CPU) {
clustersCrossingThreshold = _capacityDao.listClustersCrossingThreshold(capacity,
plan.getDataCenterId(), Config.CPUCapacityDisableThreshold.key(), cpu_requested);
} else if (capacity == Capacity.CAPACITY_TYPE_MEMORY) {
clustersCrossingThreshold = _capacityDao.listClustersCrossingThreshold(capacity,
plan.getDataCenterId(), Config.MemoryCapacityDisableThreshold.key(), ram_requested);
}
if (clustersCrossingThreshold != null && clustersCrossingThreshold.size() != 0) {
// addToAvoid Set
avoid.addClusterList(clustersCrossingThreshold);
// Remove clusters crossing disabled threshold
clusterListForVmAllocation.removeAll(clustersCrossingThreshold);
s_logger.debug("Cannot allocate cluster list " + clustersCrossingThreshold.toString() + " for vm creation since their allocated percentage" +
" crosses the disable capacity threshold defined at each cluster/ at global value for capacity Type : " + capacity + ", skipping these clusters");
}
}
}
private List<Long> scanClustersForDestinationInZoneOrPod(long id, boolean isZone,
VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid) {
VirtualMachine vm = vmProfile.getVirtualMachine(); VirtualMachine vm = vmProfile.getVirtualMachine();
ServiceOffering offering = vmProfile.getServiceOffering(); ServiceOffering offering = vmProfile.getServiceOffering();
@ -396,6 +335,9 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
prioritizedClusterIds.removeAll(disabledClusters); prioritizedClusterIds.removeAll(disabledClusters);
} }
} }
removeClustersCrossingThreshold(prioritizedClusterIds, avoid, vmProfile, plan);
}else{ }else{
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("No clusters found having a host with enough capacity, returning."); s_logger.debug("No clusters found having a host with enough capacity, returning.");
@ -404,7 +346,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
} }
if(!prioritizedClusterIds.isEmpty()){ if(!prioritizedClusterIds.isEmpty()){
List<Long> clusterList = reorderClusters(id, isZone, clusterCapacityInfo, vmProfile, plan); List<Long> clusterList = reorderClusters(id, isZone, clusterCapacityInfo, vmProfile, plan);
return checkClustersforDestination(clusterList, vmProfile, plan, avoid, dc); return clusterList; //return checkClustersforDestination(clusterList, vmProfile, plan, avoid, dc);
}else{ }else{
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("No clusters found after removing disabled clusters and clusters in avoid list, returning."); s_logger.debug("No clusters found after removing disabled clusters and clusters in avoid list, returning.");
@ -452,114 +394,6 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
return disabledPods; return disabledPods;
} }
private List<Short> getCapacitiesForCheckingThreshold(){
List<Short> capacityList = new ArrayList<Short>();
capacityList.add(Capacity.CAPACITY_TYPE_CPU);
capacityList.add(Capacity.CAPACITY_TYPE_MEMORY);
return capacityList;
}
private void removeClustersCrossingThreshold(List<Long> clusterListForVmAllocation, ExcludeList avoid, VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan){
List<Short> capacityList = getCapacitiesForCheckingThreshold();
List<Long> clustersCrossingThreshold = new ArrayList<Long>();
ServiceOffering offering = vmProfile.getServiceOffering();
int cpu_requested = offering.getCpu() * offering.getSpeed();
long ram_requested = offering.getRamSize() * 1024L * 1024L;
// For each capacity get the cluster list crossing the threshold and remove it from the clusterList that will be used for vm allocation.
for(short capacity : capacityList){
if (clusterListForVmAllocation == null || clusterListForVmAllocation.size() == 0){
return;
}
if (capacity == Capacity.CAPACITY_TYPE_CPU) {
clustersCrossingThreshold = _capacityDao.listClustersCrossingThreshold(capacity, plan.getDataCenterId(), Config.CPUCapacityDisableThreshold.key(), cpu_requested);
}
else if (capacity == Capacity.CAPACITY_TYPE_MEMORY ) {
clustersCrossingThreshold = _capacityDao.listClustersCrossingThreshold(capacity, plan.getDataCenterId(),
Config.MemoryCapacityDisableThreshold.key(), ram_requested );
}
if (clustersCrossingThreshold != null && clustersCrossingThreshold.size() != 0){
// addToAvoid Set
avoid.addClusterList(clustersCrossingThreshold);
// Remove clusters crossing disabled threshold
clusterListForVmAllocation.removeAll(clustersCrossingThreshold);
s_logger.debug("Cannot allocate cluster list " + clustersCrossingThreshold.toString() + " for vm creation since their allocated percentage" +
" crosses the disable capacity threshold defined at each cluster/ at global value for capacity Type : " + capacity + ", skipping these clusters");
}
}
}
private DeployDestination checkClustersforDestination(List<Long> clusterList, VirtualMachineProfile<? extends VirtualMachine> vmProfile,
DeploymentPlan plan, ExcludeList avoid, DataCenter dc){
if (s_logger.isTraceEnabled()) {
s_logger.trace("ClusterId List to consider: " + clusterList);
}
removeClustersCrossingThreshold(clusterList, avoid, vmProfile, plan);
for(Long clusterId : clusterList){
Cluster clusterVO = _clusterDao.findById(clusterId);
if (clusterVO.getHypervisorType() != vmProfile.getHypervisorType()) {
s_logger.debug("Cluster: "+clusterId + " has HyperVisorType that does not match the VM, skipping this cluster");
avoid.addCluster(clusterVO.getId());
continue;
}
s_logger.debug("Checking resources in Cluster: "+clusterId + " under Pod: "+clusterVO.getPodId());
//search for resources(hosts and storage) under this zone, pod, cluster.
DataCenterDeployment potentialPlan = new DataCenterDeployment(plan.getDataCenterId(), clusterVO.getPodId(), clusterVO.getId(), null, plan.getPoolId(), null, plan.getReservationContext());
//find suitable hosts under this cluster, need as many hosts as we get.
List<Host> suitableHosts = findSuitableHosts(vmProfile, potentialPlan, avoid, HostAllocator.RETURN_UPTO_ALL);
//if found suitable hosts in this cluster, find suitable storage pools for each volume of the VM
if(suitableHosts != null && !suitableHosts.isEmpty()){
if (vmProfile.getHypervisorType() == HypervisorType.BareMetal) {
Pod pod = _podDao.findById(clusterVO.getPodId());
DeployDestination dest = new DeployDestination(dc, pod, clusterVO, suitableHosts.get(0));
return dest;
}
Pair<Map<Volume, List<StoragePool>>, List<Volume>> result = findSuitablePoolsForVolumes(vmProfile, potentialPlan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL);
Map<Volume, List<StoragePool>> suitableVolumeStoragePools = result.first();
List<Volume> readyAndReusedVolumes = result.second();
//choose the potential host and pool for the VM
if(!suitableVolumeStoragePools.isEmpty()){
Pair<Host, Map<Volume, StoragePool>> potentialResources = findPotentialDeploymentResources(suitableHosts, suitableVolumeStoragePools);
if(potentialResources != null){
Pod pod = _podDao.findById(clusterVO.getPodId());
Host host = _hostDao.findById(potentialResources.first().getId());
Map<Volume, StoragePool> storageVolMap = potentialResources.second();
// remove the reused vol<->pool from destination, since we don't have to prepare this volume.
for(Volume vol : readyAndReusedVolumes){
storageVolMap.remove(vol);
}
DeployDestination dest = new DeployDestination(dc, pod, clusterVO, host, storageVolMap );
s_logger.debug("Returning Deployment Destination: "+ dest);
return dest;
}
}else{
s_logger.debug("No suitable storagePools found under this Cluster: "+clusterId);
}
}else{
s_logger.debug("No suitable hosts found under this Cluster: "+clusterId);
}
avoid.addCluster(clusterVO.getId());
}
s_logger.debug("Could not find suitable Deployment Destination for this VM under any clusters, returning. ");
return null;
}
protected Pair<List<Long>, Map<Long, Double>> listClustersByCapacity(long id, int requiredCpu, long requiredRam, ExcludeList avoid, boolean isZone){ protected Pair<List<Long>, Map<Long, Double>> listClustersByCapacity(long id, int requiredCpu, long requiredRam, ExcludeList avoid, boolean isZone){
//look at the aggregate available cpu and ram per cluster //look at the aggregate available cpu and ram per cluster
@ -630,215 +464,6 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
} }
protected Pair<Host, Map<Volume, StoragePool>> findPotentialDeploymentResources(List<Host> suitableHosts, Map<Volume, List<StoragePool>> suitableVolumeStoragePools){
s_logger.debug("Trying to find a potenial host and associated storage pools from the suitable host/pool lists for this VM");
boolean hostCanAccessPool = false;
boolean haveEnoughSpace = false;
Map<Volume, StoragePool> storage = new HashMap<Volume, StoragePool>();
TreeSet<Volume> volumesOrderBySizeDesc = new TreeSet<Volume>(new Comparator<Volume>() {
@Override
public int compare(Volume v1, Volume v2) {
if(v1.getSize() < v2.getSize())
return 1;
else
return -1;
}
});
volumesOrderBySizeDesc.addAll(suitableVolumeStoragePools.keySet());
boolean multipleVolume = volumesOrderBySizeDesc.size() > 1;
for(Host potentialHost : suitableHosts){
Map<StoragePool,List<Volume>> volumeAllocationMap = new HashMap<StoragePool,List<Volume>>();
for(Volume vol : volumesOrderBySizeDesc){
haveEnoughSpace = false;
s_logger.debug("Checking if host: "+potentialHost.getId() +" can access any suitable storage pool for volume: "+ vol.getVolumeType());
List<StoragePool> volumePoolList = suitableVolumeStoragePools.get(vol);
hostCanAccessPool = false;
for(StoragePool potentialSPool : volumePoolList){
if(hostCanAccessSPool(potentialHost, potentialSPool)){
hostCanAccessPool = true;
if(multipleVolume){
List<Volume> requestVolumes = null;
if(volumeAllocationMap.containsKey(potentialSPool))
requestVolumes = volumeAllocationMap.get(potentialSPool);
else
requestVolumes = new ArrayList<Volume>();
requestVolumes.add(vol);
if(!_storageMgr.storagePoolHasEnoughSpace(requestVolumes, potentialSPool))
continue;
volumeAllocationMap.put(potentialSPool,requestVolumes);
}
storage.put(vol, potentialSPool);
haveEnoughSpace = true;
break;
}
}
if(!hostCanAccessPool){
break;
}
if(!haveEnoughSpace) {
s_logger.warn("insufficient capacity to allocate all volumes");
break;
}
}
if(hostCanAccessPool && haveEnoughSpace){
s_logger.debug("Found a potential host " + "id: "+potentialHost.getId() + " name: " +potentialHost.getName() + " and associated storage pools for this VM");
return new Pair<Host, Map<Volume, StoragePool>>(potentialHost, storage);
}
}
s_logger.debug("Could not find a potential host that has associated storage pools from the suitable host/pool lists for this VM");
return null;
}
protected boolean hostCanAccessSPool(Host host, StoragePool pool){
boolean hostCanAccessSPool = false;
StoragePoolHostVO hostPoolLinkage = _poolHostDao.findByPoolHost(pool.getId(), host.getId());
if(hostPoolLinkage != null){
hostCanAccessSPool = true;
}
s_logger.debug("Host: "+ host.getId() + (hostCanAccessSPool ?" can" : " cannot") + " access pool: "+ pool.getId());
return hostCanAccessSPool;
}
protected List<Host> findSuitableHosts(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo){
List<Host> suitableHosts = new ArrayList<Host>();
for(HostAllocator allocator : _hostAllocators) {
suitableHosts = allocator.allocateTo(vmProfile, plan, Host.Type.Routing, avoid, returnUpTo);
if (suitableHosts != null && !suitableHosts.isEmpty()) {
break;
}
}
if(suitableHosts.isEmpty()){
s_logger.debug("No suitable hosts found");
}
return suitableHosts;
}
protected Pair<Map<Volume, List<StoragePool>>, List<Volume>> findSuitablePoolsForVolumes(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo){
List<VolumeVO> volumesTobeCreated = _volsDao.findUsableVolumesForInstance(vmProfile.getId());
Map<Volume, List<StoragePool>> suitableVolumeStoragePools = new HashMap<Volume, List<StoragePool>>();
List<Volume> readyAndReusedVolumes = new ArrayList<Volume>();
//for each volume find list of suitable storage pools by calling the allocators
for (VolumeVO toBeCreated : volumesTobeCreated) {
s_logger.debug("Checking suitable pools for volume (Id, Type): ("+toBeCreated.getId() +"," +toBeCreated.getVolumeType().name() + ")");
//If the plan specifies a poolId, it means that this VM's ROOT volume is ready and the pool should be reused.
//In this case, also check if rest of the volumes are ready and can be reused.
if(plan.getPoolId() != null){
s_logger.debug("Volume has pool(" + plan.getPoolId() + ") already allocated, checking if pool can be reused, poolId: "+toBeCreated.getPoolId());
List<StoragePool> suitablePools = new ArrayList<StoragePool>();
StoragePool pool = null;
if(toBeCreated.getPoolId() != null){
s_logger.debug("finding pool by id '" + toBeCreated.getPoolId() + "'");
pool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(toBeCreated.getPoolId());
}else{
s_logger.debug("finding pool by id '" + plan.getPoolId() + "'");
pool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(plan.getPoolId());
}
if(pool != null){
if(!pool.isInMaintenance()){
if(!avoid.shouldAvoid(pool)){
long exstPoolDcId = pool.getDataCenterId();
long exstPoolPodId = pool.getPodId() != null ? pool.getPodId() : -1;
long exstPoolClusterId = pool.getClusterId() != null ? pool.getClusterId() : -1;
if(plan.getDataCenterId() == exstPoolDcId && plan.getPodId() == exstPoolPodId && plan.getClusterId() == exstPoolClusterId){
s_logger.debug("Planner need not allocate a pool for this volume since its READY");
suitablePools.add(pool);
suitableVolumeStoragePools.put(toBeCreated, suitablePools);
if (!(toBeCreated.getState() == Volume.State.Allocated || toBeCreated.getState() == Volume.State.Creating)) {
readyAndReusedVolumes.add(toBeCreated);
}
continue;
}else{
s_logger.debug("Pool of the volume does not fit the specified plan, need to reallocate a pool for this volume");
}
}else{
s_logger.debug("Pool of the volume is in avoid set, need to reallocate a pool for this volume");
}
}else{
s_logger.debug("Pool of the volume is in maintenance, need to reallocate a pool for this volume");
}
}else{
s_logger.debug("Unable to find pool by provided id");
}
}
if(s_logger.isDebugEnabled()){
s_logger.debug("We need to allocate new storagepool for this volume");
}
if(!isRootAdmin(plan.getReservationContext())){
if(!isEnabledForAllocation(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId())){
if(s_logger.isDebugEnabled()){
s_logger.debug("Cannot allocate new storagepool for this volume in this cluster, allocation state is disabled");
s_logger.debug("Cannot deploy to this specified plan, allocation state is disabled, returning.");
}
//Cannot find suitable storage pools under this cluster for this volume since allocation_state is disabled.
//- remove any suitable pools found for other volumes.
//All volumes should get suitable pools under this cluster; else we cant use this cluster.
suitableVolumeStoragePools.clear();
break;
}
}
s_logger.debug("Calling StoragePoolAllocators to find suitable pools");
DiskOfferingVO diskOffering = _diskOfferingDao.findById(toBeCreated.getDiskOfferingId());
DiskProfile diskProfile = new DiskProfile(toBeCreated, diskOffering, vmProfile.getHypervisorType());
boolean useLocalStorage = false;
if (vmProfile.getType() != VirtualMachine.Type.User) {
String ssvmUseLocalStorage = _configDao.getValue(Config.SystemVMUseLocalStorage.key());
if (ssvmUseLocalStorage.equalsIgnoreCase("true")) {
useLocalStorage = true;
}
} else {
useLocalStorage = diskOffering.getUseLocalStorage();
// TODO: this is a hacking fix for the problem of deploy ISO-based VM on local storage
// when deploying VM based on ISO, we have a service offering and an additional disk offering, use-local storage flag is actually
// saved in service offering, overrde the flag from service offering when it is a ROOT disk
if(!useLocalStorage && vmProfile.getServiceOffering().getUseLocalStorage()) {
if(toBeCreated.getVolumeType() == Volume.Type.ROOT)
useLocalStorage = true;
}
}
diskProfile.setUseLocalStorage(useLocalStorage);
boolean foundPotentialPools = false;
for(StoragePoolAllocator allocator : _storagePoolAllocators) {
final List<StoragePool> suitablePools = allocator.allocateToPool(diskProfile, vmProfile, plan, avoid, returnUpTo);
if (suitablePools != null && !suitablePools.isEmpty()) {
suitableVolumeStoragePools.put(toBeCreated, suitablePools);
foundPotentialPools = true;
break;
}
}
if(!foundPotentialPools){
s_logger.debug("No suitable pools found for volume: "+toBeCreated +" under cluster: "+plan.getClusterId());
//No suitable storage pools found under this cluster for this volume. - remove any suitable pools found for other volumes.
//All volumes should get suitable pools under this cluster; else we cant use this cluster.
suitableVolumeStoragePools.clear();
break;
}
}
if(suitableVolumeStoragePools.isEmpty()){
s_logger.debug("No suitable pools found");
}
return new Pair<Map<Volume, List<StoragePool>>, List<Volume>>(suitableVolumeStoragePools, readyAndReusedVolumes);
}
private boolean isRootAdmin(ReservationContext reservationContext) { private boolean isRootAdmin(ReservationContext reservationContext) {
if(reservationContext != null){ if(reservationContext != null){
if(reservationContext.getAccount() != null){ if(reservationContext.getAccount() != null){
@ -859,10 +484,17 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
@Override @Override
public boolean canHandle(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, ExcludeList avoid) { public boolean canHandle(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, ExcludeList avoid) {
if(vm.getHypervisorType() != HypervisorType.BareMetal){ // check what the ServiceOffering says. If null, check the global config
//check the allocation strategy ServiceOffering offering = vm.getServiceOffering();
if (_allocationAlgorithm != null && (_allocationAlgorithm.equals(AllocationAlgorithm.random.toString()) || _allocationAlgorithm.equals(AllocationAlgorithm.firstfit.toString()))) { if (vm.getHypervisorType() != HypervisorType.BareMetal) {
return true; if (offering != null && offering.getDeploymentPlanner() != null) {
if (offering.getDeploymentPlanner().equals(this.getName())) {
return true;
}
} else {
if (_globalDeploymentPlanner != null && _globalDeploymentPlanner.equals(this._name)) {
return true;
}
} }
} }
return false; return false;
@ -872,29 +504,20 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
super.configure(name, params); super.configure(name, params);
_allocationAlgorithm = _configDao.getValue(Config.VmAllocationAlgorithm.key()); _allocationAlgorithm = _configDao.getValue(Config.VmAllocationAlgorithm.key());
_globalDeploymentPlanner = _configDao.getValue(Config.VmDeploymentPlanner.key());
return true; return true;
} }
private boolean isEnabledForAllocation(long zoneId, Long podId, Long clusterId){
// Check if the zone exists in the system
DataCenterVO zone = _dcDao.findById(zoneId);
if(zone != null && Grouping.AllocationState.Disabled == zone.getAllocationState()){
s_logger.info("Zone is currently disabled, cannot allocate to this zone: "+ zoneId);
return false;
}
Pod pod = _podDao.findById(podId); @Override
if(pod != null && Grouping.AllocationState.Disabled == pod.getAllocationState()){ public DeployDestination plan(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan,
s_logger.info("Pod is currently disabled, cannot allocate to this pod: "+ podId); ExcludeList avoid) throws InsufficientServerCapacityException {
return false; // TODO Auto-generated method stub
} return null;
}
Cluster cluster = _clusterDao.findById(clusterId); @Override
if(cluster != null && Grouping.AllocationState.Disabled == cluster.getAllocationState()){ public PlannerResourceUsage getResourceUsage() {
s_logger.info("Cluster is currently disabled, cannot allocate to this cluster: "+ clusterId); return PlannerResourceUsage.Shared;
return false;
}
return true;
} }
} }

View File

@ -1,54 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.deploy;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.deploy.DeploymentPlanner.AllocationAlgorithm;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.vm.UserVmVO;
@Local(value = {DeployPlannerSelector.class})
public class HypervisorVmPlannerSelector extends AbstractDeployPlannerSelector {
private static final Logger s_logger = Logger.getLogger(HypervisorVmPlannerSelector.class);
@Override
public String selectPlanner(UserVmVO vm) {
if (vm.getHypervisorType() != HypervisorType.BareMetal) {
//check the allocation strategy
if (_allocationAlgorithm != null) {
if (_allocationAlgorithm.equals(AllocationAlgorithm.random.toString())
|| _allocationAlgorithm.equals(AllocationAlgorithm.firstfit.toString())) {
return "FirstFitPlanner";
} else if (_allocationAlgorithm.equals(AllocationAlgorithm.userdispersing.toString())) {
return "UserDispersingPlanner";
} else if (_allocationAlgorithm.equals(AllocationAlgorithm.userconcentratedpod_random.toString())
|| _allocationAlgorithm.equals(AllocationAlgorithm.userconcentratedpod_firstfit.toString())) {
return "UserConcentratedPodPlanner";
}
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("The allocation algorithm is null, cannot select the planner");
}
}
}
return null;
}
}

View File

@ -0,0 +1,117 @@
// 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.deploy;
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.deploy.DeploymentPlanner.PlannerResourceUsage;
@Entity
@Table(name = "op_host_planner_reservation")
public class PlannerHostReservationVO implements InternalIdentity {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private long id;
@Column(name="host_id")
private Long hostId;
@Column(name="data_center_id")
private Long dataCenterId;
@Column(name="pod_id")
private Long podId;
@Column(name="cluster_id")
private Long clusterId;
@Column(name = "resource_usage")
@Enumerated(EnumType.STRING)
private PlannerResourceUsage resourceUsage;
public PlannerHostReservationVO() {
}
public PlannerHostReservationVO(Long hostId, Long dataCenterId, Long podId, Long clusterId) {
this.hostId = hostId;
this.dataCenterId = dataCenterId;
this.podId = podId;
this.clusterId = clusterId;
}
public PlannerHostReservationVO(Long hostId, Long dataCenterId, Long podId, Long clusterId,
PlannerResourceUsage resourceUsage) {
this.hostId = hostId;
this.dataCenterId = dataCenterId;
this.podId = podId;
this.clusterId = clusterId;
this.resourceUsage = resourceUsage;
}
@Override
public long getId() {
return id;
}
public Long getHostId() {
return hostId;
}
public void setHostId(Long hostId) {
this.hostId = hostId;
}
public Long getDataCenterId() {
return dataCenterId;
}
public void setDataCenterId(Long dataCenterId) {
this.dataCenterId = dataCenterId;
}
public Long getPodId() {
return podId;
}
public void setPodId(long podId) {
this.podId = new Long(podId);
}
public Long getClusterId() {
return clusterId;
}
public void setClusterId(long clusterId) {
this.clusterId = new Long(clusterId);
}
public PlannerResourceUsage getResourceUsage() {
return resourceUsage;
}
public void setResourceUsage(PlannerResourceUsage resourceType) {
this.resourceUsage = resourceType;
}
}

View File

@ -1,24 +1,30 @@
// Licensed to the Apache Software Foundation (ASF) under one // Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file // or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information // distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file // regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the // to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance // "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at // with the License. You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, // Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an // software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.deploy; package com.cloud.deploy.dao;
import com.cloud.utils.component.Adapter; import java.util.List;
import com.cloud.vm.UserVmVO;
import com.cloud.deploy.PlannerHostReservationVO;
public interface DeployPlannerSelector extends Adapter { import com.cloud.utils.db.GenericDao;
String selectPlanner(UserVmVO vm);
} public interface PlannerHostReservationDao extends GenericDao<PlannerHostReservationVO, Long> {
PlannerHostReservationVO findByHostId(long hostId);
List<PlannerHostReservationVO> listAllReservedHosts();
}

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 com.cloud.deploy.dao;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.Local;
import com.cloud.deploy.PlannerHostReservationVO;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
@Local(value = { PlannerHostReservationDao.class })
public class PlannerHostReservationDaoImpl extends GenericDaoBase<PlannerHostReservationVO, Long> implements
PlannerHostReservationDao {
private SearchBuilder<PlannerHostReservationVO> _hostIdSearch;
private SearchBuilder<PlannerHostReservationVO> _reservedHostSearch;
public PlannerHostReservationDaoImpl() {
}
@PostConstruct
protected void init() {
_hostIdSearch = createSearchBuilder();
_hostIdSearch.and("hostId", _hostIdSearch.entity().getHostId(), SearchCriteria.Op.EQ);
_hostIdSearch.done();
_reservedHostSearch = createSearchBuilder();
_reservedHostSearch.and("usage", _reservedHostSearch.entity().getResourceUsage(), SearchCriteria.Op.NNULL);
_reservedHostSearch.done();
}
@Override
public PlannerHostReservationVO findByHostId(long hostId) {
SearchCriteria<PlannerHostReservationVO> sc = _hostIdSearch.create();
sc.setParameters("hostId", hostId);
return findOneBy(sc);
}
@Override
public List<PlannerHostReservationVO> listAllReservedHosts() {
SearchCriteria<PlannerHostReservationVO> sc = _reservedHostSearch.create();
return listBy(sc);
}
}

View File

@ -130,7 +130,8 @@ public interface NetworkManager {
Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, String cidr, Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, String cidr,
String vlanId, String networkDomain, Account owner, Long domainId, PhysicalNetwork physicalNetwork, String vlanId, String networkDomain, Account owner, Long domainId, PhysicalNetwork physicalNetwork,
long zoneId, ACLType aclType, Boolean subdomainAccess, Long vpcId, String ip6Gateway, String ip6Cidr, Boolean displayNetworkEnabled) long zoneId, ACLType aclType, Boolean subdomainAccess, Long vpcId, String ip6Gateway, String ip6Cidr,
Boolean displayNetworkEnabled, String isolatedPvlan)
throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException; throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException;
/** /**

View File

@ -283,6 +283,10 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
Long guestNetworkId, boolean sourceNat, boolean assign, String requestedIp, boolean isSystem, Long vpcId) Long guestNetworkId, boolean sourceNat, boolean assign, String requestedIp, boolean isSystem, Long vpcId)
throws InsufficientAddressCapacityException { throws InsufficientAddressCapacityException {
StringBuilder errorMessage = new StringBuilder("Unable to get ip adress in "); StringBuilder errorMessage = new StringBuilder("Unable to get ip adress in ");
boolean fetchFromDedicatedRange = false;
List<Long> dedicatedVlanDbIds = new ArrayList<Long>();
List<Long> nonDedicatedVlanDbIds = new ArrayList<Long>();
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
txn.start(); txn.start();
SearchCriteria<IPAddressVO> sc = null; SearchCriteria<IPAddressVO> sc = null;
@ -295,9 +299,37 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
errorMessage.append(" zone id=" + dcId); errorMessage.append(" zone id=" + dcId);
} }
if ( vlanDbIds != null && !vlanDbIds.isEmpty() ) { // If owner has dedicated Public IP ranges, fetch IP from the dedicated range
sc.setParameters("vlanId", vlanDbIds.toArray()); // Otherwise fetch IP from the system pool
errorMessage.append(", vlanId id=" + vlanDbIds.toArray()); List<AccountVlanMapVO> maps = _accountVlanMapDao.listAccountVlanMapsByAccount(owner.getId());
for (AccountVlanMapVO map : maps) {
if (vlanDbIds == null || vlanDbIds.contains(map.getVlanDbId()))
dedicatedVlanDbIds.add(map.getVlanDbId());
}
List<VlanVO> nonDedicatedVlans = _vlanDao.listZoneWideNonDedicatedVlans(dcId);
for (VlanVO nonDedicatedVlan : nonDedicatedVlans) {
if (vlanDbIds == null || vlanDbIds.contains(nonDedicatedVlan.getId()))
nonDedicatedVlanDbIds.add(nonDedicatedVlan.getId());
}
if (dedicatedVlanDbIds != null && !dedicatedVlanDbIds.isEmpty()) {
fetchFromDedicatedRange = true;
sc.setParameters("vlanId", dedicatedVlanDbIds.toArray());
errorMessage.append(", vlanId id=" + dedicatedVlanDbIds.toArray());
} else if (nonDedicatedVlanDbIds != null && !nonDedicatedVlanDbIds.isEmpty()) {
sc.setParameters("vlanId", nonDedicatedVlanDbIds.toArray());
errorMessage.append(", vlanId id=" + nonDedicatedVlanDbIds.toArray());
} else {
if (podId != null) {
InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException
("Insufficient address capacity", Pod.class, podId);
ex.addProxyObject(ApiDBUtils.findPodById(podId).getUuid());
throw ex;
}
s_logger.warn(errorMessage.toString());
InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException
("Insufficient address capacity", DataCenter.class, dcId);
ex.addProxyObject(ApiDBUtils.findZoneById(dcId).getUuid());
throw ex;
} }
sc.setParameters("dc", dcId); sc.setParameters("dc", dcId);
@ -320,6 +352,16 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
List<IPAddressVO> addrs = _ipAddressDao.lockRows(sc, filter, true); List<IPAddressVO> addrs = _ipAddressDao.lockRows(sc, filter, true);
// If all the dedicated IPs of the owner are in use fetch an IP from the system pool
if (addrs.size() == 0 && fetchFromDedicatedRange) {
if (nonDedicatedVlanDbIds != null && !nonDedicatedVlanDbIds.isEmpty()) {
fetchFromDedicatedRange = false;
sc.setParameters("vlanId", nonDedicatedVlanDbIds.toArray());
errorMessage.append(", vlanId id=" + nonDedicatedVlanDbIds.toArray());
addrs = _ipAddressDao.lockRows(sc, filter, true);
}
}
if (addrs.size() == 0) { if (addrs.size() == 0) {
if (podId != null) { if (podId != null) {
InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException
@ -337,6 +379,16 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
assert (addrs.size() == 1) : "Return size is incorrect: " + addrs.size(); assert (addrs.size() == 1) : "Return size is incorrect: " + addrs.size();
if (!fetchFromDedicatedRange) {
// Check that the maximum number of public IPs for the given accountId will not be exceeded
try {
_resourceLimitMgr.checkResourceLimit(owner, ResourceType.public_ip);
} catch (ResourceAllocationException ex) {
s_logger.warn("Failed to allocate resource of type " + ex.getResourceType() + " for account " + owner);
throw new AccountLimitException("Maximum number of public IP addresses for account: " + owner.getAccountName() + " has been exceeded.");
}
}
IPAddressVO addr = addrs.get(0); IPAddressVO addr = addrs.get(0);
addr.setSourceNat(sourceNat); addr.setSourceNat(sourceNat);
addr.setAllocatedTime(new Date()); addr.setAllocatedTime(new Date());
@ -441,14 +493,6 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
long ownerId = owner.getId(); long ownerId = owner.getId();
// Check that the maximum number of public IPs for the given accountId will not be exceeded
try {
_resourceLimitMgr.checkResourceLimit(owner, ResourceType.public_ip);
} catch (ResourceAllocationException ex) {
s_logger.warn("Failed to allocate resource of type " + ex.getResourceType() + " for account " + owner);
throw new AccountLimitException("Maximum number of public IP addresses for account: " + owner.getAccountName() + " has been exceeded.");
}
PublicIp ip = null; PublicIp ip = null;
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
try { try {
@ -465,15 +509,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
s_logger.debug("lock account " + ownerId + " is acquired"); s_logger.debug("lock account " + ownerId + " is acquired");
} }
// If account has Account specific ip ranges, try to allocate ip from there ip = fetchNewPublicIp(dcId, null, null, owner, VlanType.VirtualNetwork, guestNtwkId,
List<Long> vlanIds = new ArrayList<Long>();
List<AccountVlanMapVO> maps = _accountVlanMapDao.listAccountVlanMapsByAccount(ownerId);
if (maps != null && !maps.isEmpty()) {
vlanIds.add(maps.get(0).getVlanDbId());
}
ip = fetchNewPublicIp(dcId, null, vlanIds, owner, VlanType.VirtualNetwork, guestNtwkId,
isSourceNat, false, null, false, vpcId); isSourceNat, false, null, false, vpcId);
IPAddressVO publicIp = ip.ip(); IPAddressVO publicIp = ip.ip();
@ -609,9 +645,6 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
VlanType vlanType = VlanType.VirtualNetwork; VlanType vlanType = VlanType.VirtualNetwork;
boolean assign = false; boolean assign = false;
boolean allocateFromDedicatedRange = false;
List<Long> dedicatedVlanDbIds = new ArrayList<Long>();
List<Long> nonDedicatedVlanDbIds = new ArrayList<Long>();
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) { if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) {
// zone is of type DataCenter. See DataCenterVO.java. // zone is of type DataCenter. See DataCenterVO.java.
@ -641,39 +674,8 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
txn.start(); txn.start();
// If account has dedicated Public IP ranges, allocate IP from the dedicated range ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, null, false, assign, null,
List<AccountVlanMapVO> maps = _accountVlanMapDao.listAccountVlanMapsByAccount(ipOwner.getId()); isSystem, null);
for (AccountVlanMapVO map : maps) {
dedicatedVlanDbIds.add(map.getVlanDbId());
}
if (dedicatedVlanDbIds != null && !dedicatedVlanDbIds.isEmpty()) {
allocateFromDedicatedRange = true;
}
try {
if (allocateFromDedicatedRange) {
ip = fetchNewPublicIp(zone.getId(), null, dedicatedVlanDbIds, ipOwner, vlanType, null,
false, assign, null, isSystem, null);
}
} catch(InsufficientAddressCapacityException e) {
s_logger.warn("All IPs dedicated to account " + ipOwner.getId() + " has been acquired." +
" Now acquiring from the system pool");
txn.close();
allocateFromDedicatedRange = false;
}
if (!allocateFromDedicatedRange) {
// Check that the maximum number of public IPs for the given
// accountId will not be exceeded
_resourceLimitMgr.checkResourceLimit(accountToLock, ResourceType.public_ip);
List<VlanVO> nonDedicatedVlans = _vlanDao.listZoneWideNonDedicatedVlans(zone.getId());
for (VlanVO nonDedicatedVlan : nonDedicatedVlans) {
nonDedicatedVlanDbIds.add(nonDedicatedVlan.getId());
}
ip = fetchNewPublicIp(zone.getId(), null, nonDedicatedVlanDbIds, ipOwner, vlanType, null, false, assign, null,
isSystem, null);
}
if (ip == null) { if (ip == null) {
InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException
@ -1899,7 +1901,8 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
@DB @DB
public Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, public Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway,
String cidr, String vlanId, String networkDomain, Account owner, Long domainId, String cidr, String vlanId, String networkDomain, Account owner, Long domainId,
PhysicalNetwork pNtwk, long zoneId, ACLType aclType, Boolean subdomainAccess, Long vpcId, String ip6Gateway, String ip6Cidr, Boolean isDisplayNetworkEnabled) PhysicalNetwork pNtwk, long zoneId, ACLType aclType, Boolean subdomainAccess, Long vpcId, String ip6Gateway, String ip6Cidr,
Boolean isDisplayNetworkEnabled, String isolatedPvlan)
throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException {
NetworkOfferingVO ntwkOff = _networkOfferingDao.findById(networkOfferingId); NetworkOfferingVO ntwkOff = _networkOfferingDao.findById(networkOfferingId);
@ -1989,6 +1992,9 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
if (ipv6) { if (ipv6) {
throw new InvalidParameterValueException("IPv6 is not supported with security group!"); throw new InvalidParameterValueException("IPv6 is not supported with security group!");
} }
if (isolatedPvlan != null) {
throw new InvalidParameterValueException("Isolated Private VLAN is not supported with security group!");
}
// Only Account specific Isolated network with sourceNat service disabled are allowed in security group // Only Account specific Isolated network with sourceNat service disabled are allowed in security group
// enabled zone // enabled zone
if ( ntwkOff.getGuestType() != GuestType.Shared ){ if ( ntwkOff.getGuestType() != GuestType.Shared ){
@ -2148,13 +2154,20 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
} }
if (vlanId != null) { if (vlanId != null) {
userNetwork.setBroadcastUri(URI.create("vlan://" + vlanId)); if (isolatedPvlan == null) {
userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan); userNetwork.setBroadcastUri(URI.create("vlan://" + vlanId));
if (!vlanId.equalsIgnoreCase(Vlan.UNTAGGED)) { if (!vlanId.equalsIgnoreCase(Vlan.UNTAGGED)) {
userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan); userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan);
} else { } else {
userNetwork.setBroadcastDomainType(BroadcastDomainType.Native); userNetwork.setBroadcastDomainType(BroadcastDomainType.Native);
} }
} else {
if (vlanId.equalsIgnoreCase(Vlan.UNTAGGED)) {
throw new InvalidParameterValueException("Cannot support pvlan with untagged primary vlan!");
}
userNetwork.setBroadcastUri(NetUtils.generateUriForPvlan(vlanId, isolatedPvlan));
userNetwork.setBroadcastDomainType(BroadcastDomainType.Pvlan);
}
} }
List<NetworkVO> networks = setupNetwork(owner, ntwkOff, userNetwork, plan, name, displayText, true, domainId, List<NetworkVO> networks = setupNetwork(owner, ntwkOff, userNetwork, plan, name, displayText, true, domainId,
@ -2757,7 +2770,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
guestNetwork = createGuestNetwork(requiredOfferings.get(0).getId(), owner.getAccountName() + "-network" guestNetwork = createGuestNetwork(requiredOfferings.get(0).getId(), owner.getAccountName() + "-network"
, owner.getAccountName() + "-network", null, null, null, null, owner, null, physicalNetwork, , owner.getAccountName() + "-network", null, null, null, null, owner, null, physicalNetwork,
zoneId, ACLType.Account, zoneId, ACLType.Account,
null, null, null, null, true); null, null, null, null, true, null);
if (guestNetwork == null) { if (guestNetwork == null) {
s_logger.warn("Failed to create default Virtual network for the account " + accountId + "in zone " + zoneId); s_logger.warn("Failed to create default Virtual network for the account " + accountId + "in zone " + zoneId);
throw new CloudRuntimeException("Failed to create a Guest Isolated Networks with SourceNAT " + throw new CloudRuntimeException("Failed to create a Guest Isolated Networks with SourceNAT " +
@ -2992,6 +3005,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
Random _rand = new Random(System.currentTimeMillis()); Random _rand = new Random(System.currentTimeMillis());
@Override
public List<? extends Nic> listVmNics(Long vmId, Long nicId) { public List<? extends Nic> listVmNics(Long vmId, Long nicId) {
List<NicVO> result = null; List<NicVO> result = null;
if (nicId == null) { if (nicId == null) {
@ -3002,6 +3016,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
return result; return result;
} }
@Override
public String allocateGuestIP(Account ipOwner, boolean isSystem, long zoneId, Long networkId, String requestedIp) public String allocateGuestIP(Account ipOwner, boolean isSystem, long zoneId, Long networkId, String requestedIp)
throws InsufficientAddressCapacityException { throws InsufficientAddressCapacityException {
String ipaddr = null; String ipaddr = null;
@ -3633,8 +3648,10 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
nic.setGateway(ip.getGateway()); nic.setGateway(ip.getGateway());
nic.setNetmask(ip.getNetmask()); nic.setNetmask(ip.getNetmask());
nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag())); nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
nic.setBroadcastType(BroadcastDomainType.Vlan); //nic.setBroadcastType(BroadcastDomainType.Vlan);
nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanTag())); //nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanTag()));
nic.setBroadcastType(network.getBroadcastDomainType());
nic.setBroadcastUri(network.getBroadcastUri());
nic.setFormat(AddressFormat.Ip4); nic.setFormat(AddressFormat.Ip4);
nic.setReservationId(String.valueOf(ip.getVlanTag())); nic.setReservationId(String.valueOf(ip.getVlanTag()));
nic.setMacAddress(ip.getMacAddress()); nic.setMacAddress(ip.getMacAddress());

View File

@ -952,6 +952,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
String ip6Cidr = cmd.getIp6Cidr(); String ip6Cidr = cmd.getIp6Cidr();
Boolean displayNetwork = cmd.getDisplayNetwork(); Boolean displayNetwork = cmd.getDisplayNetwork();
Long aclId = cmd.getAclId(); Long aclId = cmd.getAclId();
String isolatedPvlan = cmd.getIsolatedPvlan();
// Validate network offering // Validate network offering
NetworkOfferingVO ntwkOff = _networkOfferingDao.findById(networkOfferingId); NetworkOfferingVO ntwkOff = _networkOfferingDao.findById(networkOfferingId);
@ -1143,6 +1144,14 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
} }
} }
if (isolatedPvlan != null && (zone.getNetworkType() != NetworkType.Advanced || ntwkOff.getGuestType() != Network.GuestType.Shared)) {
throw new InvalidParameterValueException("Can only support create Private VLAN network with advance shared network!");
}
if (isolatedPvlan != null && ipv6) {
throw new InvalidParameterValueException("Can only support create Private VLAN network with IPv4!");
}
// Regular user can create Guest Isolated Source Nat enabled network only // Regular user can create Guest Isolated Source Nat enabled network only
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL
&& (ntwkOff.getTrafficType() != TrafficType.Guest || ntwkOff.getGuestType() != Network.GuestType.Isolated && (ntwkOff.getTrafficType() != TrafficType.Guest || ntwkOff.getGuestType() != Network.GuestType.Isolated
@ -1175,6 +1184,10 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
throw new InvalidParameterValueException("Cannot support IPv6 on network offering with external devices!"); throw new InvalidParameterValueException("Cannot support IPv6 on network offering with external devices!");
} }
if (isolatedPvlan != null && providersConfiguredForExternalNetworking(ntwkProviders)) {
throw new InvalidParameterValueException("Cannot support private vlan on network offering with external devices!");
}
if (cidr != null && providersConfiguredForExternalNetworking(ntwkProviders)) { if (cidr != null && providersConfiguredForExternalNetworking(ntwkProviders)) {
if (ntwkOff.getGuestType() == GuestType.Shared && (zone.getNetworkType() == NetworkType.Advanced) && if (ntwkOff.getGuestType() == GuestType.Shared && (zone.getNetworkType() == NetworkType.Advanced) &&
isSharedNetworkOfferingWithServices(networkOfferingId)) { isSharedNetworkOfferingWithServices(networkOfferingId)) {
@ -1251,7 +1264,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
throw new InvalidParameterValueException("Unable to find specified NetworkACL"); throw new InvalidParameterValueException("Unable to find specified NetworkACL");
} }
if(vpcId != acl.getVpcId()){ if(!vpcId.equals(acl.getVpcId())){
throw new InvalidParameterValueException("ACL: "+aclId+" do not belong to the VPC"); throw new InvalidParameterValueException("ACL: "+aclId+" do not belong to the VPC");
} }
} }
@ -1265,8 +1278,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
throw new InvalidParameterValueException("Internal Lb can be enabled on vpc networks only"); throw new InvalidParameterValueException("Internal Lb can be enabled on vpc networks only");
} }
network = _networkMgr.createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, network = _networkMgr.createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId,
networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, ip6Gateway, ip6Cidr, displayNetwork); networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId,
ip6Gateway, ip6Cidr, displayNetwork, isolatedPvlan);
} }
if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN && createVlan) { if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN && createVlan) {
@ -3813,8 +3827,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (privateNetwork == null) { if (privateNetwork == null) {
//create Guest network //create Guest network
privateNetwork = _networkMgr.createGuestNetwork(ntwkOff.getId(), networkName, displayText, gateway, cidr, vlan, privateNetwork = _networkMgr.createGuestNetwork(ntwkOff.getId(), networkName, displayText, gateway, cidr, vlan,
null, owner, null, pNtwk, pNtwk.getDataCenterId(), ACLType.Account, null, null, null, null, true); null, owner, null, pNtwk, pNtwk.getDataCenterId(), ACLType.Account, null, vpcId, null, null, true, null);
s_logger.debug("Created private network " + privateNetwork); s_logger.debug("Created private network " + privateNetwork);
} else { } else {
s_logger.debug("Private network already exists: " + privateNetwork); s_logger.debug("Private network already exists: " + privateNetwork);

View File

@ -315,9 +315,10 @@ public class StorageNetworkManagerImpl extends ManagerBase implements StorageNet
List<StorageNetworkIpRangeVO> ranges = _sNwIpRangeDao.listByPodId(podId); List<StorageNetworkIpRangeVO> ranges = _sNwIpRangeDao.listByPodId(podId);
for (StorageNetworkIpRangeVO r : ranges) { for (StorageNetworkIpRangeVO r : ranges) {
try { try {
r = _sNwIpRangeDao.acquireInLockTable(r.getId()); Long rangeId = r.getId();
r = _sNwIpRangeDao.acquireInLockTable(rangeId);
if (r == null) { if (r == null) {
String msg = "Unable to acquire lock on storage network ip range id=" + r.getId() + ", delete failed"; String msg = "Unable to acquire lock on storage network ip range id=" + rangeId + ", delete failed";
s_logger.warn(msg); s_logger.warn(msg);
throw new CloudRuntimeException(msg); throw new CloudRuntimeException(msg);
} }

View File

@ -30,6 +30,7 @@ import org.apache.cloudstack.api.command.admin.router.CreateVirtualRouterElement
import org.apache.cloudstack.api.command.admin.router.ListVirtualRouterElementsCmd; import org.apache.cloudstack.api.command.admin.router.ListVirtualRouterElementsCmd;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.cloud.agent.api.PvlanSetupCommand;
import com.cloud.agent.api.to.LoadBalancerTO; import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.configuration.dao.ConfigurationDao;
@ -47,6 +48,7 @@ import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Provider; import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service; import com.cloud.network.Network.Service;
import com.cloud.network.NetworkModel; import com.cloud.network.NetworkModel;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.TrafficType; import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetworkServiceProvider; import com.cloud.network.PhysicalNetworkServiceProvider;
import com.cloud.network.PublicIpAddress; import com.cloud.network.PublicIpAddress;
@ -228,7 +230,6 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
throw new ResourceUnavailableException("Can't find at least one running router!", throw new ResourceUnavailableException("Can't find at least one running router!",
DataCenter.class, network.getDataCenterId()); DataCenter.class, network.getDataCenterId());
} }
return true; return true;
} }

View File

@ -83,7 +83,7 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
if (networkType == NetworkType.Advanced if (networkType == NetworkType.Advanced
&& isMyTrafficType(offering.getTrafficType()) && isMyTrafficType(offering.getTrafficType())
&& offering.getGuestType() == Network.GuestType.Isolated && offering.getGuestType() == Network.GuestType.Isolated
&& isMyIsolationMethod(physicalNetwork)) { && isMyIsolationMethod(physicalNetwork) && !offering.isSystemOnly()) {
return true; return true;
} else { } else {
s_logger.trace("We only take care of Guest networks of type " s_logger.trace("We only take care of Guest networks of type "

View File

@ -33,6 +33,7 @@ import com.cloud.user.User;
import com.cloud.uservm.UserVm; import com.cloud.uservm.UserVm;
import com.cloud.utils.component.Manager; import com.cloud.utils.component.Manager;
import com.cloud.vm.DomainRouterVO; import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.Nic;
import com.cloud.vm.NicProfile; import com.cloud.vm.NicProfile;
import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.VirtualMachineProfile;
@ -112,4 +113,4 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA
boolean removeDhcpSupportForSubnet(Network network, List<DomainRouterVO> routers) throws ResourceUnavailableException; boolean removeDhcpSupportForSubnet(Network network, List<DomainRouterVO> routers) throws ResourceUnavailableException;
} }

View File

@ -34,6 +34,7 @@ import com.cloud.agent.api.GetDomRVersionCmd;
import com.cloud.agent.api.ModifySshKeysCommand; import com.cloud.agent.api.ModifySshKeysCommand;
import com.cloud.agent.api.NetworkUsageAnswer; import com.cloud.agent.api.NetworkUsageAnswer;
import com.cloud.agent.api.NetworkUsageCommand; import com.cloud.agent.api.NetworkUsageCommand;
import com.cloud.agent.api.PvlanSetupCommand;
import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StopAnswer; import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.check.CheckSshAnswer; import com.cloud.agent.api.check.CheckSshAnswer;
@ -2223,6 +2224,28 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
return dhcpRange; return dhcpRange;
} }
private boolean setupDhcpForPvlan(boolean add, DomainRouterVO router, Nic nic) {
if (!nic.getBroadcastUri().getScheme().equals("pvlan")) {
return false;
}
String op = "add";
if (!add) {
op = "delete";
}
Network network = _networkDao.findById(nic.getNetworkId());
String networkTag = _networkModel.getNetworkTag(router.getHypervisorType(), network);
PvlanSetupCommand cmd = PvlanSetupCommand.createDhcpSetup(op, nic.getBroadcastUri(), networkTag, router.getInstanceName(), nic.getMacAddress(), nic.getIp4Address());
Commands cmds = new Commands(cmd);
// In fact we send command to the host of router, we're not programming router but the host
try {
sendCommandsToRouter(router, cmds);
} catch (AgentUnavailableException e) {
s_logger.warn("Agent Unavailable ", e);
return false;
}
return true;
}
@Override @Override
public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile<DomainRouterVO> profile, public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile<DomainRouterVO> profile,
DeployDestination dest, ReservationContext context) throws ResourceUnavailableException { DeployDestination dest, ReservationContext context) throws ResourceUnavailableException {
@ -2536,13 +2559,20 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
List<Network> guestNetworks = new ArrayList<Network>(); List<Network> guestNetworks = new ArrayList<Network>();
List<? extends Nic> routerNics = _nicDao.listByVmId(profile.getId()); List<? extends Nic> routerNics = _nicDao.listByVmId(profile.getId());
for (Nic routerNic : routerNics) { for (Nic nic : routerNics) {
Network network = _networkModel.getNetwork(routerNic.getNetworkId()); Network network = _networkModel.getNetwork(nic.getNetworkId());
if (network.getTrafficType() == TrafficType.Guest) { if (network.getTrafficType() == TrafficType.Guest) {
guestNetworks.add(network); guestNetworks.add(network);
if (nic.getBroadcastUri().getScheme().equals("pvlan")) {
result = setupDhcpForPvlan(true, router, nic);
}
} }
} }
if (!result) {
return result;
}
answer = cmds.getAnswer("getDomRVersion"); answer = cmds.getAnswer("getDomRVersion");
if (answer != null && answer instanceof GetDomRVersionAnswer) { if (answer != null && answer instanceof GetDomRVersionAnswer) {
GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer)answer; GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer)answer;
@ -2568,6 +2598,14 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
VMInstanceVO vm = profile.getVirtualMachine(); VMInstanceVO vm = profile.getVirtualMachine();
DomainRouterVO domR = _routerDao.findById(vm.getId()); DomainRouterVO domR = _routerDao.findById(vm.getId());
processStopOrRebootAnswer(domR, answer); processStopOrRebootAnswer(domR, answer);
List<? extends Nic> routerNics = _nicDao.listByVmId(profile.getId());
for (Nic nic : routerNics) {
Network network = _networkModel.getNetwork(nic.getNetworkId());
if (network.getTrafficType() == TrafficType.Guest && nic.getBroadcastUri().getScheme().equals("pvlan")) {
setupDhcpForPvlan(false, domR, nic);
}
}
} }
} }

View File

@ -27,24 +27,6 @@ import java.util.TreeSet;
import javax.ejb.Local; import javax.ejb.Local;
import javax.inject.Inject; import javax.inject.Inject;
import com.cloud.network.vpc.NetworkACLItem;
import com.cloud.network.vpc.NetworkACLItemDao;
import com.cloud.network.vpc.NetworkACLItemVO;
import com.cloud.network.vpc.NetworkACLManager;
import com.cloud.network.vpc.PrivateGateway;
import com.cloud.network.vpc.PrivateIpAddress;
import com.cloud.network.vpc.PrivateIpVO;
import com.cloud.network.vpc.StaticRoute;
import com.cloud.network.vpc.StaticRouteProfile;
import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.VpcGateway;
import com.cloud.network.vpc.VpcManager;
import com.cloud.network.vpc.VpcVO;
import com.cloud.network.vpc.dao.PrivateIpDao;
import com.cloud.network.vpc.dao.StaticRouteDao;
import com.cloud.network.vpc.dao.VpcDao;
import com.cloud.network.vpc.dao.VpcGatewayDao;
import com.cloud.network.vpc.dao.VpcOfferingDao;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -108,6 +90,24 @@ import com.cloud.network.dao.Site2SiteCustomerGatewayVO;
import com.cloud.network.dao.Site2SiteVpnConnectionDao; import com.cloud.network.dao.Site2SiteVpnConnectionDao;
import com.cloud.network.dao.Site2SiteVpnGatewayDao; import com.cloud.network.dao.Site2SiteVpnGatewayDao;
import com.cloud.network.dao.Site2SiteVpnGatewayVO; import com.cloud.network.dao.Site2SiteVpnGatewayVO;
import com.cloud.network.vpc.NetworkACLItem;
import com.cloud.network.vpc.NetworkACLItemDao;
import com.cloud.network.vpc.NetworkACLItemVO;
import com.cloud.network.vpc.NetworkACLManager;
import com.cloud.network.vpc.PrivateGateway;
import com.cloud.network.vpc.PrivateIpAddress;
import com.cloud.network.vpc.PrivateIpVO;
import com.cloud.network.vpc.StaticRoute;
import com.cloud.network.vpc.StaticRouteProfile;
import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.VpcGateway;
import com.cloud.network.vpc.VpcManager;
import com.cloud.network.vpc.VpcVO;
import com.cloud.network.vpc.dao.PrivateIpDao;
import com.cloud.network.vpc.dao.StaticRouteDao;
import com.cloud.network.vpc.dao.VpcDao;
import com.cloud.network.vpc.dao.VpcGatewayDao;
import com.cloud.network.vpc.dao.VpcOfferingDao;
import com.cloud.network.vpn.Site2SiteVpnManager; import com.cloud.network.vpn.Site2SiteVpnManager;
import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account; import com.cloud.user.Account;
@ -127,7 +127,6 @@ import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachineProfile.Param; import com.cloud.vm.VirtualMachineProfile.Param;
import com.cloud.vm.dao.VMInstanceDao; import com.cloud.vm.dao.VMInstanceDao;
@Component @Component
@Local(value = {VpcVirtualNetworkApplianceManager.class, VpcVirtualNetworkApplianceService.class}) @Local(value = {VpcVirtualNetworkApplianceManager.class, VpcVirtualNetworkApplianceService.class})
public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplianceManagerImpl implements VpcVirtualNetworkApplianceManager{ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplianceManagerImpl implements VpcVirtualNetworkApplianceManager{
@ -339,7 +338,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
DomainRouterVO router = _routerDao.findById(vm.getId()); DomainRouterVO router = _routerDao.findById(vm.getId());
if (router.getState() == State.Running) { if (router.getState() == State.Running) {
try { try {
PlugNicCommand plugNicCmd = new PlugNicCommand(nic, vm.getName()); PlugNicCommand plugNicCmd = new PlugNicCommand(nic, vm.getName(), vm.getType());
Commands cmds = new Commands(OnError.Stop); Commands cmds = new Commands(OnError.Stop);
cmds.addCommand("plugnic", plugNicCmd); cmds.addCommand("plugnic", plugNicCmd);
@ -748,7 +747,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
// if (rule.getSourceCidrList() == null && (rule.getPurpose() == Purpose.Firewall || rule.getPurpose() == Purpose.NetworkACL)) { // if (rule.getSourceCidrList() == null && (rule.getPurpose() == Purpose.Firewall || rule.getPurpose() == Purpose.NetworkACL)) {
// _firewallDao.loadSourceCidrs((FirewallRuleVO)rule); // _firewallDao.loadSourceCidrs((FirewallRuleVO)rule);
// } // }
NetworkACLTO ruleTO = new NetworkACLTO((NetworkACLItemVO)rule, guestVlan, rule.getTrafficType()); NetworkACLTO ruleTO = new NetworkACLTO(rule, guestVlan, rule.getTrafficType());
rulesTO.add(ruleTO); rulesTO.add(ruleTO);
} }
} }
@ -828,7 +827,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
_routerDao.update(routerVO.getId(), routerVO); _routerDao.update(routerVO.getId(), routerVO);
} }
} }
PlugNicCommand plugNicCmd = new PlugNicCommand(getNicTO(router, publicNic.getNetworkId(), publicNic.getBroadcastUri().toString()), router.getInstanceName()); PlugNicCommand plugNicCmd = new PlugNicCommand(getNicTO(router, publicNic.getNetworkId(), publicNic.getBroadcastUri().toString()), router.getInstanceName(), router.getType());
cmds.addCommand(plugNicCmd); cmds.addCommand(plugNicCmd);
VpcVO vpc = _vpcDao.findById(router.getVpcId()); VpcVO vpc = _vpcDao.findById(router.getVpcId());
NetworkUsageCommand netUsageCmd = new NetworkUsageCommand(router.getPrivateIpAddress(), router.getInstanceName(), true, publicNic.getIp4Address(), vpc.getCidr()); NetworkUsageCommand netUsageCmd = new NetworkUsageCommand(router.getPrivateIpAddress(), router.getInstanceName(), true, publicNic.getIp4Address(), vpc.getCidr());
@ -851,7 +850,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
for (Pair<Nic, Network> nicNtwk : guestNics) { for (Pair<Nic, Network> nicNtwk : guestNics) {
Nic guestNic = nicNtwk.first(); Nic guestNic = nicNtwk.first();
//plug guest nic //plug guest nic
PlugNicCommand plugNicCmd = new PlugNicCommand(getNicTO(router, guestNic.getNetworkId(), null), router.getInstanceName()); PlugNicCommand plugNicCmd = new PlugNicCommand(getNicTO(router, guestNic.getNetworkId(), null), router.getInstanceName(), router.getType());
cmds.addCommand(plugNicCmd); cmds.addCommand(plugNicCmd);
if (!_networkModel.isPrivateGateway(guestNic)) { if (!_networkModel.isPrivateGateway(guestNic)) {
@ -1236,12 +1235,14 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
//1) allocate nic for control and source nat public ip //1) allocate nic for control and source nat public ip
networks = super.createRouterNetworks(owner, isRedundant, plan, null, sourceNatIp); networks = super.createRouterNetworks(owner, isRedundant, plan, null, sourceNatIp);
//2) allocate nic for private gateway if needed //2) allocate nic for private gateways if needed
PrivateGateway privateGateway = _vpcMgr.getVpcPrivateGateway(vpcId); List<PrivateGateway> privateGateways = _vpcMgr.getVpcPrivateGateways(vpcId);
if (privateGateway != null) { if (privateGateways != null && !privateGateways.isEmpty()) {
NicProfile privateNic = createPrivateNicProfileForGateway(privateGateway); for (PrivateGateway privateGateway : privateGateways) {
Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId()); NicProfile privateNic = createPrivateNicProfileForGateway(privateGateway);
networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) privateNetwork, privateNic)); Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId());
networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) privateNetwork, privateNic));
}
} }
//3) allocate nic for guest gateway if needed //3) allocate nic for guest gateway if needed

View File

@ -182,7 +182,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ
throw new InvalidParameterValueException("Unable to find Vpc associated with the NetworkACL"); throw new InvalidParameterValueException("Unable to find Vpc associated with the NetworkACL");
} }
_accountMgr.checkAccess(caller, null, true, vpc); _accountMgr.checkAccess(caller, null, true, vpc);
if(gateway.getVpcId() != acl.getVpcId()){ if(!gateway.getVpcId().equals(acl.getVpcId())){
throw new InvalidParameterValueException("private gateway: "+privateGatewayId+" and ACL: "+aclId+" do not belong to the same VPC"); throw new InvalidParameterValueException("private gateway: "+privateGatewayId+" and ACL: "+aclId+" do not belong to the same VPC");
} }
} }
@ -225,7 +225,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ
} }
_accountMgr.checkAccess(caller, null, true, vpc); _accountMgr.checkAccess(caller, null, true, vpc);
if(network.getVpcId() != acl.getVpcId()){ if(!network.getVpcId().equals(acl.getVpcId())){
throw new InvalidParameterValueException("Network: "+networkId+" and ACL: "+aclId+" do not belong to the same VPC"); throw new InvalidParameterValueException("Network: "+networkId+" and ACL: "+aclId+" do not belong to the same VPC");
} }
} }

View File

@ -166,5 +166,5 @@ public interface VpcManager extends VpcService{
*/ */
void validateNtwkOffForNtwkInVpc(Long networkId, long newNtwkOffId, String newCidr, String newNetworkDomain, Vpc vpc, String gateway, Account networkOwner); void validateNtwkOffForNtwkInVpc(Long networkId, long newNtwkOffId, String newCidr, String newNetworkDomain, Vpc vpc, String gateway, Account networkOwner);
List<PrivateGateway> getVpcPrivateGateways(long id); List<PrivateGateway> getVpcPrivateGateways(long vpcId);
} }

View File

@ -711,8 +711,9 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
public boolean destroyVpc(Vpc vpc, Account caller, Long callerUserId) throws ConcurrentOperationException, ResourceUnavailableException { public boolean destroyVpc(Vpc vpc, Account caller, Long callerUserId) throws ConcurrentOperationException, ResourceUnavailableException {
s_logger.debug("Destroying vpc " + vpc); s_logger.debug("Destroying vpc " + vpc);
//don't allow to delete vpc if it's in use by existing networks //don't allow to delete vpc if it's in use by existing non system networks (system networks are networks of a private gateway of the VPC,
int networksCount = _ntwkDao.getNetworkCountByVpcId(vpc.getId()); //and they will get removed as a part of VPC cleanup
int networksCount = _ntwkDao.getNonSystemNetworkCountByVpcId(vpc.getId());
if (networksCount > 0) { if (networksCount > 0) {
throw new InvalidParameterValueException("Can't delete VPC " + vpc + " as its used by " + networksCount + " networks"); throw new InvalidParameterValueException("Can't delete VPC " + vpc + " as its used by " + networksCount + " networks");
} }
@ -1235,7 +1236,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
return false; return false;
} }
//4) Delete private gateway //4) Delete private gateways
List<PrivateGateway> gateways = getVpcPrivateGateways(vpcId); List<PrivateGateway> gateways = getVpcPrivateGateways(vpcId);
if (gateways != null) { if (gateways != null) {
for (PrivateGateway gateway: gateways) { for (PrivateGateway gateway: gateways) {
@ -1299,8 +1300,8 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
@Override @Override
public List<PrivateGateway> getVpcPrivateGateways(long id) { public List<PrivateGateway> getVpcPrivateGateways(long vpcId) {
List<VpcGatewayVO> gateways = _vpcGatewayDao.listByVpcIdAndType(id, VpcGateway.Type.Private); List<VpcGatewayVO> gateways = _vpcGatewayDao.listByVpcIdAndType(vpcId, VpcGateway.Type.Private);
if (gateways != null) { if (gateways != null) {
List<PrivateGateway> pvtGateway = new ArrayList(); List<PrivateGateway> pvtGateway = new ArrayList();
@ -2024,8 +2025,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
//2) Create network //2) Create network
Network guestNetwork = _ntwkMgr.createGuestNetwork(ntwkOffId, name, displayText, gateway, cidr, vlanId, Network guestNetwork = _ntwkMgr.createGuestNetwork(ntwkOffId, name, displayText, gateway, cidr, vlanId,
networkDomain, owner, domainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, null, null, isDisplayNetworkEnabled); networkDomain, owner, domainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, null, null, isDisplayNetworkEnabled, null);
if(guestNetwork != null){ if(guestNetwork != null){
guestNetwork.setNetworkACLId(aclId); guestNetwork.setNetworkACLId(aclId);

View File

@ -92,6 +92,10 @@ import com.cloud.dc.dao.ClusterVSMMapDao;
import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.DataCenterIpAddressDao; import com.cloud.dc.dao.DataCenterIpAddressDao;
import com.cloud.dc.dao.HostPodDao; import com.cloud.dc.dao.HostPodDao;
import com.cloud.deploy.PlannerHostReservationVO;
import com.cloud.deploy.dao.PlannerHostReservationDao;
import com.cloud.event.ActionEvent;
import com.cloud.event.EventTypes;
import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.DiscoveryException; import com.cloud.exception.DiscoveryException;
import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.InvalidParameterValueException;
@ -221,7 +225,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
protected HighAvailabilityManager _haMgr; protected HighAvailabilityManager _haMgr;
@Inject @Inject
protected StorageService _storageSvr; protected StorageService _storageSvr;
@Inject
PlannerHostReservationDao _plannerHostReserveDao;
protected List<? extends Discoverer> _discoverers; protected List<? extends Discoverer> _discoverers;
@ -2531,5 +2536,42 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
sc.addAnd(sc.getEntity().getStatus(), Op.EQ, Status.Up); sc.addAnd(sc.getEntity().getStatus(), Op.EQ, Status.Up);
sc.addAnd(sc.getEntity().getResourceState(), Op.EQ, ResourceState.Enabled); sc.addAnd(sc.getEntity().getResourceState(), Op.EQ, ResourceState.Enabled);
return sc.list(); return sc.list();
}
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_HOST_RESERVATION_RELEASE, eventDescription = "releasing host reservation", async = true)
public boolean releaseHostReservation(Long hostId) {
Transaction txn = Transaction.currentTxn();
try {
txn.start();
PlannerHostReservationVO reservationEntry = _plannerHostReserveDao.findByHostId(hostId);
if (reservationEntry != null) {
long id = reservationEntry.getId();
PlannerHostReservationVO hostReservation = _plannerHostReserveDao.lockRow(id, true);
if (hostReservation == null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Host reservation for host: " + hostId + " does not even exist. Release reservartion call is ignored.");
}
txn.rollback();
return false;
}
hostReservation.setResourceUsage(null);
_plannerHostReserveDao.persist(hostReservation);
txn.commit();
return true;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Host reservation for host: " + hostId
+ " does not even exist. Release reservartion call is ignored.");
}
return false;
} catch (CloudRuntimeException e) {
throw e;
} catch (Throwable t) {
s_logger.error("Unable to release host reservation for host: " + hostId, t);
txn.rollback();
return false;
}
} }
} }

View File

@ -78,6 +78,7 @@ import org.apache.cloudstack.api.command.admin.host.FindHostsForMigrationCmd;
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd; import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
import org.apache.cloudstack.api.command.admin.host.PrepareForMaintenanceCmd; import org.apache.cloudstack.api.command.admin.host.PrepareForMaintenanceCmd;
import org.apache.cloudstack.api.command.admin.host.ReconnectHostCmd; import org.apache.cloudstack.api.command.admin.host.ReconnectHostCmd;
import org.apache.cloudstack.api.command.admin.host.ReleaseHostReservationCmd;
import org.apache.cloudstack.api.command.admin.host.UpdateHostCmd; import org.apache.cloudstack.api.command.admin.host.UpdateHostCmd;
import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd; import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
import org.apache.cloudstack.api.command.admin.internallb.ConfigureInternalLoadBalancerElementCmd; import org.apache.cloudstack.api.command.admin.internallb.ConfigureInternalLoadBalancerElementCmd;
@ -457,6 +458,7 @@ import com.cloud.dc.dao.HostPodDao;
import com.cloud.dc.dao.PodVlanMapDao; import com.cloud.dc.dao.PodVlanMapDao;
import com.cloud.dc.dao.VlanDao; import com.cloud.dc.dao.VlanDao;
import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DataCenterDeployment;
import com.cloud.deploy.DeploymentPlanner;
import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.deploy.DeploymentPlanner.ExcludeList;
import com.cloud.domain.DomainVO; import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao; import com.cloud.domain.dao.DomainDao;
@ -660,6 +662,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator; import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.api.command.admin.config.ListDeploymentPlannersCmd;
public class ManagementServerImpl extends ManagerBase implements ManagementServer { public class ManagementServerImpl extends ManagerBase implements ManagementServer {
public static final Logger s_logger = Logger.getLogger(ManagementServerImpl.class.getName()); public static final Logger s_logger = Logger.getLogger(ManagementServerImpl.class.getName());
@ -796,11 +799,21 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
private List<UserAuthenticator> _userAuthenticators; private List<UserAuthenticator> _userAuthenticators;
private List<UserAuthenticator> _userPasswordEncoders; private List<UserAuthenticator> _userPasswordEncoders;
protected List<DeploymentPlanner> _planners;
public List<DeploymentPlanner> getPlanners() {
return _planners;
}
public void setPlanners(List<DeploymentPlanner> _planners) {
this._planners = _planners;
}
@Inject ClusterManager _clusterMgr; @Inject ClusterManager _clusterMgr;
private String _hashKey = null; private String _hashKey = null;
private String _encryptionKey = null; private String _encryptionKey = null;
private String _encryptionIV = null; private String _encryptionIV = null;
@Inject @Inject
protected AffinityGroupVMMapDao _affinityGroupVMMapDao; protected AffinityGroupVMMapDao _affinityGroupVMMapDao;
@ -1046,29 +1059,29 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
String zoneType = cmd.getZoneType(); String zoneType = cmd.getZoneType();
String keyword = cmd.getKeyword(); String keyword = cmd.getKeyword();
zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId); zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
Filter searchFilter = new Filter(ClusterVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal()); Filter searchFilter = new Filter(ClusterVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchBuilder<ClusterVO> sb = _clusterDao.createSearchBuilder(); SearchBuilder<ClusterVO> sb = _clusterDao.createSearchBuilder();
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE); sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ); sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ); sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
sb.and("hypervisorType", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ); sb.and("hypervisorType", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ);
sb.and("clusterType", sb.entity().getClusterType(), SearchCriteria.Op.EQ); sb.and("clusterType", sb.entity().getClusterType(), SearchCriteria.Op.EQ);
sb.and("allocationState", sb.entity().getAllocationState(), SearchCriteria.Op.EQ); sb.and("allocationState", sb.entity().getAllocationState(), SearchCriteria.Op.EQ);
if(zoneType != null) { if(zoneType != null) {
SearchBuilder<DataCenterVO> zoneSb = _dcDao.createSearchBuilder(); SearchBuilder<DataCenterVO> zoneSb = _dcDao.createSearchBuilder();
zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ); zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ);
sb.join("zoneSb", zoneSb, sb.entity().getDataCenterId(), zoneSb.entity().getId(), JoinBuilder.JoinType.INNER); sb.join("zoneSb", zoneSb, sb.entity().getDataCenterId(), zoneSb.entity().getId(), JoinBuilder.JoinType.INNER);
} }
SearchCriteria<ClusterVO> sc = sb.create(); SearchCriteria<ClusterVO> sc = sb.create();
if (id != null) { if (id != null) {
sc.setParameters("id", id); sc.setParameters("id", id);
} }
if (name != null) { if (name != null) {
@ -1096,9 +1109,9 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
} }
if(zoneType != null) { if(zoneType != null) {
sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType); sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType);
} }
if (keyword != null) { if (keyword != null) {
SearchCriteria<ClusterVO> ssc = _clusterDao.createSearchCriteria(); SearchCriteria<ClusterVO> ssc = _clusterDao.createSearchCriteria();
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
@ -1222,7 +1235,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
if (volumePools.isEmpty()) { if (volumePools.isEmpty()) {
allHosts.remove(host); allHosts.remove(host);
} else { } else {
if (host.getClusterId() != srcHost.getClusterId() || usesLocal) { if (!host.getClusterId().equals(srcHost.getClusterId()) || usesLocal) {
requiresStorageMotion.put(host, true); requiresStorageMotion.put(host, true);
} }
} }
@ -1511,26 +1524,26 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
public Pair<List<? extends Pod>, Integer> searchForPods(ListPodsByCmd cmd) { public Pair<List<? extends Pod>, Integer> searchForPods(ListPodsByCmd cmd) {
String podName = cmd.getPodName(); String podName = cmd.getPodName();
Long id = cmd.getId(); Long id = cmd.getId();
Long zoneId = cmd.getZoneId(); Long zoneId = cmd.getZoneId();
Object keyword = cmd.getKeyword(); Object keyword = cmd.getKeyword();
Object allocationState = cmd.getAllocationState(); Object allocationState = cmd.getAllocationState();
String zoneType = cmd.getZoneType(); String zoneType = cmd.getZoneType();
zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId); zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
Filter searchFilter = new Filter(HostPodVO.class, "dataCenterId", true, cmd.getStartIndex(), cmd.getPageSizeVal()); Filter searchFilter = new Filter(HostPodVO.class, "dataCenterId", true, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchBuilder<HostPodVO> sb = _hostPodDao.createSearchBuilder(); SearchBuilder<HostPodVO> sb = _hostPodDao.createSearchBuilder();
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE); sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ); sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
sb.and("allocationState", sb.entity().getAllocationState(), SearchCriteria.Op.EQ); sb.and("allocationState", sb.entity().getAllocationState(), SearchCriteria.Op.EQ);
if(zoneType != null) { if(zoneType != null) {
SearchBuilder<DataCenterVO> zoneSb = _dcDao.createSearchBuilder(); SearchBuilder<DataCenterVO> zoneSb = _dcDao.createSearchBuilder();
zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ); zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ);
sb.join("zoneSb", zoneSb, sb.entity().getDataCenterId(), zoneSb.entity().getId(), JoinBuilder.JoinType.INNER); sb.join("zoneSb", zoneSb, sb.entity().getDataCenterId(), zoneSb.entity().getId(), JoinBuilder.JoinType.INNER);
} }
SearchCriteria<HostPodVO> sc = sb.create(); SearchCriteria<HostPodVO> sc = sb.create();
if (keyword != null) { if (keyword != null) {
SearchCriteria<HostPodVO> ssc = _hostPodDao.createSearchCriteria(); SearchCriteria<HostPodVO> ssc = _hostPodDao.createSearchCriteria();
@ -1543,23 +1556,23 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
if (id != null) { if (id != null) {
sc.setParameters("id", id); sc.setParameters("id", id);
} }
if (podName != null) { if (podName != null) {
sc.setParameters("name", "%" + podName + "%"); sc.setParameters("name", "%" + podName + "%");
} }
if (zoneId != null) { if (zoneId != null) {
sc.setParameters("dataCenterId", zoneId); sc.setParameters("dataCenterId", zoneId);
} }
if (allocationState != null) { if (allocationState != null) {
sc.setParameters("allocationState", allocationState); sc.setParameters("allocationState", allocationState);
}
if(zoneType != null) {
sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType);
} }
if(zoneType != null) {
sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType);
}
Pair<List<HostPodVO>, Integer> result = _hostPodDao.searchAndCount(sc, searchFilter); Pair<List<HostPodVO>, Integer> result = _hostPodDao.searchAndCount(sc, searchFilter);
return new Pair<List<? extends Pod>, Integer>(result.first(), result.second()); return new Pair<List<? extends Pod>, Integer>(result.first(), result.second());
} }
@ -1868,6 +1881,89 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
} }
*/ */
private VMTemplateVO updateTemplateOrIso(BaseUpdateTemplateOrIsoCmd cmd) {
Long id = cmd.getId();
String name = cmd.getTemplateName();
String displayText = cmd.getDisplayText();
String format = cmd.getFormat();
Long guestOSId = cmd.getOsTypeId();
Boolean passwordEnabled = cmd.isPasswordEnabled();
Boolean bootable = cmd.isBootable();
Integer sortKey = cmd.getSortKey();
Account account = UserContext.current().getCaller();
// verify that template exists
VMTemplateVO template = _templateDao.findById(id);
if (template == null || template.getRemoved() != null) {
InvalidParameterValueException ex = new InvalidParameterValueException("unable to find template/iso with specified id");
ex.addProxyObject(template, id, "templateId");
throw ex;
}
// Don't allow to modify system template
if (id.equals(Long.valueOf(1))) {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to update template/iso of specified id");
ex.addProxyObject(template, id, "templateId");
throw ex;
}
// do a permission check
_accountMgr.checkAccess(account, AccessType.ModifyEntry, true, template);
boolean updateNeeded = !(name == null && displayText == null && format == null && guestOSId == null && passwordEnabled == null
&& bootable == null && sortKey == null);
if (!updateNeeded) {
return template;
}
template = _templateDao.createForUpdate(id);
if (name != null) {
template.setName(name);
}
if (displayText != null) {
template.setDisplayText(displayText);
}
if (sortKey != null) {
template.setSortKey(sortKey);
}
ImageFormat imageFormat = null;
if (format != null) {
try {
imageFormat = ImageFormat.valueOf(format.toUpperCase());
} catch (IllegalArgumentException e) {
throw new InvalidParameterValueException("Image format: " + format + " is incorrect. Supported formats are "
+ EnumUtils.listValues(ImageFormat.values()));
}
template.setFormat(imageFormat);
}
if (guestOSId != null) {
GuestOSVO guestOS = _guestOSDao.findById(guestOSId);
if (guestOS == null) {
throw new InvalidParameterValueException("Please specify a valid guest OS ID.");
} else {
template.setGuestOSId(guestOSId);
}
}
if (passwordEnabled != null) {
template.setEnablePassword(passwordEnabled);
}
if (bootable != null) {
template.setBootable(bootable);
}
_templateDao.update(id, template);
return _templateDao.findById(id);
}
@Override @Override
public Pair<List<? extends IpAddress>, Integer> searchForIPAddresses(ListPublicIpAddressesCmd cmd) { public Pair<List<? extends IpAddress>, Integer> searchForIPAddresses(ListPublicIpAddressesCmd cmd) {
@ -2332,7 +2428,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
public int compare(SummedCapacity arg0, SummedCapacity arg1) { public int compare(SummedCapacity arg0, SummedCapacity arg1) {
if (arg0.getPercentUsed() < arg1.getPercentUsed()) { if (arg0.getPercentUsed() < arg1.getPercentUsed()) {
return 1; return 1;
} else if (arg0.getPercentUsed() == arg1.getPercentUsed()) { } else if (arg0.getPercentUsed().equals(arg1.getPercentUsed())) {
return 0; return 0;
} }
return -1; return -1;
@ -2826,7 +2922,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
cmdList.add(UpdateVMAffinityGroupCmd.class); cmdList.add(UpdateVMAffinityGroupCmd.class);
cmdList.add(ListAffinityGroupTypesCmd.class); cmdList.add(ListAffinityGroupTypesCmd.class);
cmdList.add(ListNetworkIsolationMethodsCmd.class); cmdList.add(ListNetworkIsolationMethodsCmd.class);
cmdList.add(ListDeploymentPlannersCmd.class);
cmdList.add(ReleaseHostReservationCmd.class);
cmdList.add(AddResourceDetailCmd.class); cmdList.add(AddResourceDetailCmd.class);
cmdList.add(RemoveResourceDetailCmd.class); cmdList.add(RemoveResourceDetailCmd.class);
cmdList.add(ListResourceDetailsCmd.class); cmdList.add(ListResourceDetailsCmd.class);
@ -3028,10 +3125,10 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
if(zoneType != null) { if(zoneType != null) {
SearchBuilder<DataCenterVO> zoneSb = _dcDao.createSearchBuilder(); SearchBuilder<DataCenterVO> zoneSb = _dcDao.createSearchBuilder();
zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ); zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ);
sb.join("zoneSb", zoneSb, sb.entity().getDataCenterId(), zoneSb.entity().getId(), JoinBuilder.JoinType.INNER); sb.join("zoneSb", zoneSb, sb.entity().getDataCenterId(), zoneSb.entity().getId(), JoinBuilder.JoinType.INNER);
} }
SearchCriteria<VMInstanceVO> sc = sb.create(); SearchCriteria<VMInstanceVO> sc = sb.create();
if (keyword != null) { if (keyword != null) {
@ -3073,9 +3170,9 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
} }
if(zoneType != null) { if(zoneType != null) {
sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType); sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType);
} }
Pair<List<VMInstanceVO>, Integer> result = _vmInstanceDao.searchAndCount(sc, searchFilter); Pair<List<VMInstanceVO>, Integer> result = _vmInstanceDao.searchAndCount(sc, searchFilter);
return new Pair<List<? extends VirtualMachine>, Integer>(result.first(), result.second()); return new Pair<List<? extends VirtualMachine>, Integer>(result.first(), result.second());
} }
@ -3600,7 +3697,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
// although we may have race conditioning here, database transaction serialization should // although we may have race conditioning here, database transaction serialization should
// give us the same key // give us the same key
if (_hashKey == null) { if (_hashKey == null) {
_hashKey = _configDao.getValueAndInitIfNotExist(Config.HashKey.key(), Config.HashKey.getCategory(), _hashKey = _configDao.getValueAndInitIfNotExist(Config.HashKey.key(), Config.HashKey.getCategory(),
getBase64EncodedRandomKey(128)); getBase64EncodedRandomKey(128));
} }
return _hashKey; return _hashKey;
@ -3609,41 +3706,41 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
@Override @Override
public String getEncryptionKey() { public String getEncryptionKey() {
if (_encryptionKey == null) { if (_encryptionKey == null) {
_encryptionKey = _configDao.getValueAndInitIfNotExist(Config.EncryptionKey.key(), _encryptionKey = _configDao.getValueAndInitIfNotExist(Config.EncryptionKey.key(),
Config.EncryptionKey.getCategory(), Config.EncryptionKey.getCategory(),
getBase64EncodedRandomKey(128)); getBase64EncodedRandomKey(128));
} }
return _encryptionKey; return _encryptionKey;
} }
@Override @Override
public String getEncryptionIV() { public String getEncryptionIV() {
if (_encryptionIV == null) { if (_encryptionIV == null) {
_encryptionIV = _configDao.getValueAndInitIfNotExist(Config.EncryptionIV.key(), _encryptionIV = _configDao.getValueAndInitIfNotExist(Config.EncryptionIV.key(),
Config.EncryptionIV.getCategory(), Config.EncryptionIV.getCategory(),
getBase64EncodedRandomKey(128)); getBase64EncodedRandomKey(128));
} }
return _encryptionIV; return _encryptionIV;
} }
@Override @Override
@DB @DB
public void resetEncryptionKeyIV() { public void resetEncryptionKeyIV() {
SearchBuilder<ConfigurationVO> sb = _configDao.createSearchBuilder(); SearchBuilder<ConfigurationVO> sb = _configDao.createSearchBuilder();
sb.and("name1", sb.entity().getName(), SearchCriteria.Op.EQ); sb.and("name1", sb.entity().getName(), SearchCriteria.Op.EQ);
sb.or("name2", sb.entity().getName(), SearchCriteria.Op.EQ); sb.or("name2", sb.entity().getName(), SearchCriteria.Op.EQ);
sb.done(); sb.done();
SearchCriteria<ConfigurationVO> sc = sb.create(); SearchCriteria<ConfigurationVO> sc = sb.create();
sc.setParameters("name1", Config.EncryptionKey.key()); sc.setParameters("name1", Config.EncryptionKey.key());
sc.setParameters("name2", Config.EncryptionIV.key()); sc.setParameters("name2", Config.EncryptionIV.key());
_configDao.expunge(sc); _configDao.expunge(sc);
_encryptionKey = null; _encryptionKey = null;
_encryptionIV = null; _encryptionIV = null;
} }
private static String getBase64EncodedRandomKey(int nBits) { private static String getBase64EncodedRandomKey(int nBits) {
SecureRandom random; SecureRandom random;
try { try {
@ -3979,4 +4076,15 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
} }
} }
@Override
public List<String> listDeploymentPlanners() {
List<String> plannersAvailable = new ArrayList<String>();
for (DeploymentPlanner planner : _planners) {
plannersAvailable.add(planner.getName());
}
return plannersAvailable;
}
} }

View File

@ -438,6 +438,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
SearchCriteria.Op.EQ); SearchCriteria.Op.EQ);
volumeSB.and("removed", volumeSB.entity().getRemoved(), volumeSB.and("removed", volumeSB.entity().getRemoved(),
SearchCriteria.Op.NULL); SearchCriteria.Op.NULL);
volumeSB.and("state", volumeSB.entity().getState(), SearchCriteria.Op.NIN);
SearchBuilder<VMInstanceVO> activeVmSB = _vmInstanceDao SearchBuilder<VMInstanceVO> activeVmSB = _vmInstanceDao
.createSearchBuilder(); .createSearchBuilder();
@ -449,6 +450,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
SearchCriteria<VolumeVO> volumeSC = volumeSB.create(); SearchCriteria<VolumeVO> volumeSC = volumeSB.create();
volumeSC.setParameters("poolId", PrimaryDataStoreVO.getId()); volumeSC.setParameters("poolId", PrimaryDataStoreVO.getId());
volumeSC.setParameters("state", Volume.State.Expunging, Volume.State.Destroy);
volumeSC.setJoinParameters("activeVmSB", "state", volumeSC.setJoinParameters("activeVmSB", "state",
State.Starting, State.Running, State.Stopping, State.Starting, State.Running, State.Stopping,
State.Migrating); State.Migrating);
@ -644,6 +646,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
SearchCriteria.Op.EQ); SearchCriteria.Op.EQ);
volumeSearch.and("poolId", volumeSearch.entity().getPoolId(), volumeSearch.and("poolId", volumeSearch.entity().getPoolId(),
SearchCriteria.Op.EQ); SearchCriteria.Op.EQ);
volumeSearch.and("state", volumeSearch.entity().getState(), SearchCriteria.Op.EQ);
StoragePoolSearch.join("vmVolume", volumeSearch, volumeSearch.entity() StoragePoolSearch.join("vmVolume", volumeSearch, volumeSearch.entity()
.getInstanceId(), StoragePoolSearch.entity().getId(), .getInstanceId(), StoragePoolSearch.entity().getId(),
JoinBuilder.JoinType.INNER); JoinBuilder.JoinType.INNER);
@ -1591,6 +1594,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
SearchCriteria<VMInstanceVO> sc = StoragePoolSearch.create(); SearchCriteria<VMInstanceVO> sc = StoragePoolSearch.create();
sc.setJoinParameters("vmVolume", "volumeType", Volume.Type.ROOT); sc.setJoinParameters("vmVolume", "volumeType", Volume.Type.ROOT);
sc.setJoinParameters("vmVolume", "poolId", storagePoolId); sc.setJoinParameters("vmVolume", "poolId", storagePoolId);
sc.setJoinParameters("vmVolume", "state", Volume.State.Ready);
return _vmInstanceDao.search(sc, null); return _vmInstanceDao.search(sc, null);
} }

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