Putting back the changes done for adidng deployment planner in ServiceOffering

This commit is contained in:
Prachi Damle 2013-05-04 23:27:47 -07:00
parent 92677c6f44
commit 5ac3ed099a
10 changed files with 164 additions and 42 deletions

View File

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

View File

@ -482,6 +482,7 @@ public class ApiConstants {
public static final String AFFINITY_GROUP_NAMES = "affinitygroupnames";
public static final String ASA_INSIDE_PORT_PROFILE = "insideportprofile";
public static final String AFFINITY_GROUP_ID = "affinitygroupid";
public static final String DEPLOYMENT_PLANNER = "deploymentplanner";
public enum HostDetails {
all, capacity, events, stats, min;

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

@ -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")
private Integer networkRate;
@Parameter(name = ApiConstants.DEPLOYMENT_PLANNER, type = CommandType.STRING, description = "The deployment planner heuristics used to deploy a VM of this offering, default \"FirstFitPlanner\".")
private String deploymentPlanner;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -148,6 +151,9 @@ public class CreateServiceOfferingCmd extends BaseCmd {
return networkRate;
}
public String getDeploymentPlanner() {
return deploymentPlanner;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////

View File

@ -606,6 +606,7 @@
<property name="UserPasswordEncoders" value="#{userPasswordEncoders.Adapters}" />
<property name="HostAllocators" value="#{hostAllocators.Adapters}" />
<property name="AffinityGroupProcessors" value="#{affinityProcessors.Adapters}" />
<property name="Planners" value="#{deploymentPlanners.Adapters}" />
</bean>
<bean id="storageManagerImpl" class="com.cloud.storage.StorageManagerImpl">

View File

@ -79,10 +79,11 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
* TODO
* @param id
* @param useVirtualNetwork
* @param deploymentPlanner
* @return ID
*/
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

View File

@ -1949,16 +1949,16 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
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
@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,
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);
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) {
UserContext.current().setEventDetails("Service offering id=" + offering.getId());

View File

@ -399,6 +399,16 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
private List<UserAuthenticator> _userAuthenticators;
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;
private String _hashKey = null;
private String _encryptionKey = null;
@ -629,29 +639,29 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
String zoneType = cmd.getZoneType();
String keyword = cmd.getKeyword();
zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
Filter searchFilter = new Filter(ClusterVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchBuilder<ClusterVO> sb = _clusterDao.createSearchBuilder();
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
SearchBuilder<ClusterVO> sb = _clusterDao.createSearchBuilder();
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
sb.and("hypervisorType", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ);
sb.and("clusterType", sb.entity().getClusterType(), SearchCriteria.Op.EQ);
sb.and("allocationState", sb.entity().getAllocationState(), SearchCriteria.Op.EQ);
if(zoneType != null) {
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);
}
SearchCriteria<ClusterVO> sc = sb.create();
SearchCriteria<ClusterVO> sc = sb.create();
if (id != null) {
sc.setParameters("id", id);
sc.setParameters("id", id);
}
if (name != null) {
@ -679,9 +689,9 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
}
if(zoneType != null) {
sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType);
sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType);
}
if (keyword != null) {
SearchCriteria<ClusterVO> ssc = _clusterDao.createSearchCriteria();
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
@ -1094,26 +1104,26 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
public Pair<List<? extends Pod>, Integer> searchForPods(ListPodsByCmd cmd) {
String podName = cmd.getPodName();
Long id = cmd.getId();
Long zoneId = cmd.getZoneId();
Long zoneId = cmd.getZoneId();
Object keyword = cmd.getKeyword();
Object allocationState = cmd.getAllocationState();
String zoneType = cmd.getZoneType();
zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
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("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
sb.and("allocationState", sb.entity().getAllocationState(), SearchCriteria.Op.EQ);
if(zoneType != null) {
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);
}
SearchCriteria<HostPodVO> sc = sb.create();
if (keyword != null) {
SearchCriteria<HostPodVO> ssc = _hostPodDao.createSearchCriteria();
@ -1126,23 +1136,23 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
if (id != null) {
sc.setParameters("id", id);
}
if (podName != null) {
sc.setParameters("name", "%" + podName + "%");
}
if (zoneId != null) {
sc.setParameters("dataCenterId", zoneId);
}
if (allocationState != null) {
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);
return new Pair<List<? extends Pod>, Integer>(result.first(), result.second());
}
@ -2735,10 +2745,10 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
if(zoneType != null) {
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);
}
}
SearchCriteria<VMInstanceVO> sc = sb.create();
if (keyword != null) {
@ -2780,9 +2790,9 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
}
if(zoneType != null) {
sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType);
sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType);
}
Pair<List<VMInstanceVO>, Integer> result = _vmInstanceDao.searchAndCount(sc, searchFilter);
return new Pair<List<? extends VirtualMachine>, Integer>(result.first(), result.second());
}
@ -3686,4 +3696,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

@ -68,6 +68,9 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
@Column(name="sort_key")
int sortKey;
@Column(name = "deployment_planner")
private String deploymentPlanner = "FirstFitPlanner";
protected ServiceOfferingVO() {
super();
}
@ -84,6 +87,7 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
this.volatileVm = false;
this.default_use = defaultUse;
this.vm_type = vm_type == null ? null : vm_type.toString().toLowerCase();
this.deploymentPlanner = "FirstFitPlanner";
}
public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, boolean limitCpuUse, boolean volatileVm, String displayText, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse, VirtualMachine.Type vm_type, Long domainId) {
@ -97,11 +101,26 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
this.limitCpuUse = limitCpuUse;
this.volatileVm = volatileVm;
this.vm_type = vm_type == null ? null : vm_type.toString().toLowerCase();
this.deploymentPlanner = "FirstFitPlanner";
}
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) {
this(name, cpu, ramSize, speed, rateMbps, multicastRateMbps, offerHA, limitResourceUse, volatileVm, displayText, useLocalStorage, recreatable, tags, systemUse, vm_type, domainId);
this.hostTag = hostTag;
this.deploymentPlanner = "FirstFitPlanner";
}
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);
if (deploymentPlanner != null) {
this.deploymentPlanner = deploymentPlanner;
} else {
this.deploymentPlanner = "FirstFitPlanner";
}
}
@Override

View File

@ -436,7 +436,7 @@ public class MockConfigurationManagerImpl extends ManagerBase implements Configu
*/
@Override
public ServiceOfferingVO createServiceOffering(long userId, boolean isSystem, 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 limitResourceUse, boolean volatileVm, String tags, Long domainId, String hostTag, Integer networkRate, String deploymentPlanner) {
// TODO Auto-generated method stub
return null;
}