mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Added resource tag support for Zone
This commit is contained in:
parent
12189074b2
commit
aa570783e8
@ -518,7 +518,7 @@ public class ApiConstants {
|
||||
public static final String ROUTING = "isrouting";
|
||||
public static final String MAX_CONNECTIONS = "maxconnections";
|
||||
public static final String SERVICE_STATE = "servicestate";
|
||||
public static final String RESOURCE_TAG = "resourcetag";
|
||||
public static final String RESOURCE_TAGS = "resourcetags";
|
||||
public enum HostDetails {
|
||||
all, capacity, events, stats, min;
|
||||
}
|
||||
|
||||
@ -25,12 +25,10 @@ import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseListCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.BaseCmd.CommandType;
|
||||
import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
|
||||
import org.apache.cloudstack.api.response.UserVmResponse;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
@ -66,7 +64,7 @@ public class ListServiceOfferingsCmd extends BaseListCmd {
|
||||
@Parameter(name=ApiConstants.SYSTEM_VM_TYPE, type=CommandType.STRING, description="the system VM type. Possible types are \"consoleproxy\", \"secondarystoragevm\" or \"domainrouter\".")
|
||||
private String systemVmType;
|
||||
|
||||
@Parameter(name = ApiConstants.RESOURCE_TAG, type = CommandType.MAP, description = "List service offerings by resource tags (key/value pairs)", since="4.3")
|
||||
@Parameter(name = ApiConstants.RESOURCE_TAGS, type = CommandType.MAP, description = "List service offerings by resource tags (key/value pairs)", since="4.3")
|
||||
private Map resourceTag;
|
||||
|
||||
|
||||
|
||||
@ -16,21 +16,21 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.zone;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseListCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.BaseCmd.CommandType;
|
||||
import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
|
||||
@APICommand(name = "listZones", description="Lists zones", responseObject=ZoneResponse.class)
|
||||
public class ListZonesByCmd extends BaseListCmd {
|
||||
@ -63,6 +63,9 @@ public class ListZonesByCmd extends BaseListCmd {
|
||||
@Parameter(name=ApiConstants.SHOW_CAPACITIES, type=CommandType.BOOLEAN, description="flag to display the capacity of the zones")
|
||||
private Boolean showCapacities;
|
||||
|
||||
@Parameter(name = ApiConstants.TAGS, type = CommandType.MAP, description = "List zones by resource tags (key/value pairs)", since="4.3")
|
||||
private Map tags;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@ -91,6 +94,25 @@ public class ListZonesByCmd extends BaseListCmd {
|
||||
return showCapacities;
|
||||
}
|
||||
|
||||
public Map<String, String> getTags() {
|
||||
Map<String, String> tagsMap = null;
|
||||
if (tags != null && !tags.isEmpty()) {
|
||||
tagsMap = new HashMap<String, String>();
|
||||
Collection<?> servicesCollection = tags.values();
|
||||
Iterator<?> iter = servicesCollection.iterator();
|
||||
while (iter.hasNext()) {
|
||||
HashMap<String, String> services = (HashMap<String, String>) iter.next();
|
||||
String key = services.get("key");
|
||||
String value = services.get("value");
|
||||
if (value == null) {
|
||||
throw new InvalidParameterValueException("No value is passed in for key " + key);
|
||||
}
|
||||
tagsMap.put(key, value);
|
||||
}
|
||||
}
|
||||
return tagsMap;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@ -107,7 +107,7 @@ public class ServiceOfferingResponse extends BaseResponse {
|
||||
@Param(description = "additional key/value details tied with this service offering", since = "4.2.0")
|
||||
private Map<String, String> details;
|
||||
|
||||
@SerializedName(ApiConstants.RESOURCE_TAG) @Param(description="the list of resource tags associated with service offering." +
|
||||
@SerializedName(ApiConstants.RESOURCE_TAGS) @Param(description="the list of resource tags associated with service offering." +
|
||||
" The resource tags are not used for Volume/VM placement on the specific host.",
|
||||
responseObject = ResourceTagResponse.class, since="4.3")
|
||||
private Set<ResourceTagResponse> resourceTags;
|
||||
|
||||
@ -16,7 +16,9 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.response;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseResponse;
|
||||
@ -99,6 +101,15 @@ public class ZoneResponse extends BaseResponse {
|
||||
@SerializedName(ApiConstants.LOCAL_STORAGE_ENABLED) @Param(description="true if local storage offering enabled, false otherwise")
|
||||
private boolean localStorageEnabled;
|
||||
|
||||
@SerializedName(ApiConstants.TAGS) @Param(description="the list of resource tags associated with zone.",
|
||||
responseObject = ResourceTagResponse.class, since="4.3")
|
||||
private Set<ResourceTagResponse> tags;
|
||||
|
||||
|
||||
public ZoneResponse(){
|
||||
tags = new LinkedHashSet<ResourceTagResponse>();
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
@ -198,4 +209,8 @@ public class ZoneResponse extends BaseResponse {
|
||||
public void setIp6Dns2(String ip6Dns2) {
|
||||
this.ip6Dns2 = ip6Dns2;
|
||||
}
|
||||
|
||||
public void addTag(ResourceTagResponse tag){
|
||||
this.tags.add(tag);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2536,9 +2536,23 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
String keyword = cmd.getKeyword();
|
||||
String name = cmd.getName();
|
||||
String networkType = cmd.getNetworkType();
|
||||
Map<String, String> resourceTags = cmd.getTags();
|
||||
|
||||
SearchBuilder<DataCenterJoinVO> sb = _dcJoinDao.createSearchBuilder();
|
||||
if (resourceTags != null && !resourceTags.isEmpty()) {
|
||||
SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
|
||||
for (int count=0; count < resourceTags.size(); count++) {
|
||||
tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
|
||||
tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
|
||||
tagSearch.cp();
|
||||
}
|
||||
tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
|
||||
sb.groupBy(sb.entity().getId());
|
||||
sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
|
||||
}
|
||||
|
||||
Filter searchFilter = new Filter(DataCenterJoinVO.class, null, false, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||
SearchCriteria<DataCenterJoinVO> sc = _dcJoinDao.createSearchCriteria();
|
||||
SearchCriteria<DataCenterJoinVO> sc = sb.create();
|
||||
|
||||
if (networkType != null) {
|
||||
sc.addAnd("networkType", SearchCriteria.Op.EQ, networkType);
|
||||
@ -2688,6 +2702,16 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
}
|
||||
}
|
||||
|
||||
if (resourceTags != null && !resourceTags.isEmpty()) {
|
||||
int count = 0;
|
||||
sc.setJoinParameters("tagSearch", "resourceType", TaggedResourceType.Zone.toString());
|
||||
for (String key : resourceTags.keySet()) {
|
||||
sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key);
|
||||
sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), resourceTags.get(key));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return _dcJoinDao.searchAndCount(sc, searchFilter);
|
||||
}
|
||||
|
||||
|
||||
@ -20,23 +20,23 @@ import java.util.List;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.apache.cloudstack.api.response.ResourceTagResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
import com.cloud.api.ApiResponseHelper;
|
||||
import com.cloud.api.query.vo.DataCenterJoinVO;
|
||||
import com.cloud.api.query.vo.ResourceTagJoinVO;
|
||||
import com.cloud.dc.DataCenter;
|
||||
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
|
||||
import com.cloud.server.ResourceTag.TaggedResourceType;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Local(value={DataCenterJoinDao.class})
|
||||
public class DataCenterJoinDaoImpl extends GenericDaoBase<DataCenterJoinVO, Long> implements DataCenterJoinDao {
|
||||
@ -97,6 +97,14 @@ public class DataCenterJoinDaoImpl extends GenericDaoBase<DataCenterJoinVO, Long
|
||||
zoneResponse.setAllocationState(dataCenter.getAllocationState().toString());
|
||||
zoneResponse.setZoneToken(dataCenter.getZoneToken());
|
||||
zoneResponse.setDhcpProvider(dataCenter.getDhcpProvider());
|
||||
|
||||
// update tag information
|
||||
List<ResourceTagJoinVO> resourceTags = ApiDBUtils.listResourceTagViewByResourceUUID(dataCenter.getUuid(), TaggedResourceType.Zone);
|
||||
for (ResourceTagJoinVO resourceTag : resourceTags) {
|
||||
ResourceTagResponse tagResponse = ApiDBUtils.newResourceTagResponse(resourceTag, false);
|
||||
zoneResponse.addTag(tagResponse);
|
||||
}
|
||||
|
||||
zoneResponse.setObjectName("zone");
|
||||
return zoneResponse;
|
||||
}
|
||||
|
||||
@ -89,7 +89,8 @@ public class ServiceOfferingJoinDaoImpl extends GenericDaoBase<ServiceOfferingJo
|
||||
List<ResourceTagJoinVO> resourceTags = ApiDBUtils.listResourceTagViewByResourceUUID(offering.getUuid(), TaggedResourceType.ServiceOffering);
|
||||
for (ResourceTagJoinVO resourceTag : resourceTags) {
|
||||
ResourceTagResponse tagResponse = ApiDBUtils.newResourceTagResponse(resourceTag, false);
|
||||
offeringResponse.addTag(tagResponse); }
|
||||
offeringResponse.addTag(tagResponse);
|
||||
}
|
||||
|
||||
return offeringResponse;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user