ResourceTags: resourcetags support for Project/Vpc/NetworkACL/StaticRoute

Conflicts:

	api/src/com/cloud/api/commands/ListVPCsCmd.java
	server/src/com/cloud/api/ApiResponseHelper.java
	server/src/com/cloud/network/dao/FirewallRulesDaoImpl.java
	server/src/com/cloud/network/vpc/VpcManagerImpl.java
	server/src/com/cloud/projects/dao/ProjectDaoImpl.java
	server/src/com/cloud/uuididentity/dao/IdentityDao.java
This commit is contained in:
Alena Prokharchyk 2012-07-05 17:33:20 -07:00
parent d2df3e0102
commit 5cbe3d9722
23 changed files with 309 additions and 26 deletions

View File

@ -23,7 +23,8 @@ import java.util.List;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseListProjectAndAccountResourcesCmd;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.BaseListTaggedResourcesCmd;
import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
@ -32,7 +33,7 @@ import com.cloud.api.response.NetworkACLResponse;
import com.cloud.network.rules.FirewallRule;
@Implementation(description="Lists all network ACLs", responseObject=NetworkACLResponse.class)
public class ListNetworkACLsCmd extends BaseListProjectAndAccountResourcesCmd {
public class ListNetworkACLsCmd extends BaseListTaggedResourcesCmd {
public static final Logger s_logger = Logger.getLogger(ListNetworkACLsCmd.class.getName());
private static final String s_name = "listnetworkaclsresponse";

View File

@ -17,7 +17,11 @@
package com.cloud.api.commands;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
@ -28,6 +32,7 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.ProjectResponse;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.projects.Project;
@Implementation(description="Lists projects and provides detailed information for listed projects", responseObject=ProjectResponse.class, since="3.0.0")
@ -52,6 +57,9 @@ public class ListProjectsCmd extends BaseListAccountResourcesCmd {
@Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="list projects by state")
private String state;
@Parameter(name = ApiConstants.TAGS, type = CommandType.MAP, description = "List projects by tags (key/value pairs)")
private Map tags;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -72,6 +80,25 @@ public class ListProjectsCmd extends BaseListAccountResourcesCmd {
public String getCommandName() {
return s_name;
}
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///////////////////
@ -79,7 +106,9 @@ public class ListProjectsCmd extends BaseListAccountResourcesCmd {
@Override
public void execute(){
List<? extends Project> projects = _projectService.listProjects(id, name, displayText, state, this.getAccountName(), this.getDomainId(), this.getKeyword(), this.getStartIndex(), this.getPageSizeVal(), this.listAll(), this.isRecursive());
List<? extends Project> projects = _projectService.listProjects(id, name, displayText, state,
this.getAccountName(), this.getDomainId(), this.getKeyword(), this.getStartIndex(), this.getPageSizeVal(),
this.listAll(), this.isRecursive(), getTags());
ListResponse<ProjectResponse> response = new ListResponse<ProjectResponse>();
List<ProjectResponse> projectResponses = new ArrayList<ProjectResponse>();
for (Project project : projects) {

View File

@ -19,7 +19,7 @@ package com.cloud.api.commands;
import java.util.ArrayList;
import java.util.List;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseListProjectAndAccountResourcesCmd;
import com.cloud.api.BaseListTaggedResourcesCmd;
import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
@ -28,7 +28,7 @@ import com.cloud.api.response.StaticRouteResponse;
import com.cloud.network.vpc.StaticRoute;
@Implementation(description="Lists all static routes", responseObject=StaticRouteResponse.class)
public class ListStaticRoutesCmd extends BaseListProjectAndAccountResourcesCmd {
public class ListStaticRoutesCmd extends BaseListTaggedResourcesCmd {
private static final String s_name = "liststaticroutesresponse";
/////////////////////////////////////////////////////

View File

@ -22,15 +22,17 @@ import java.util.List;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseListAccountResourcesCmd;
import com.cloud.api.BaseListTaggedResourcesCmd;
import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.VpcResponse;
import com.cloud.network.vpc.Vpc;
public class ListVPCsCmd extends BaseListAccountResourcesCmd{
@Implementation(description="Lists VPCs", responseObject=VpcResponse.class)
public class ListVPCsCmd extends BaseListTaggedResourcesCmd{
public static final Logger s_logger = Logger.getLogger(ListVPCsCmd.class.getName());
private static final String s_name = "listvpcsresponse";
@ -136,7 +138,7 @@ public class ListVPCsCmd extends BaseListAccountResourcesCmd{
List<? extends Vpc> vpcs = _vpcService.listVpcs(getId(), getVpcName(), getDisplayText(),
getSupportedServices(), getCidr(), getVpcOffId(), getState(), getAccountName(), getDomainId(),
this.getKeyword(), this.getStartIndex(), this.getPageSizeVal(), getZoneId(), this.isRecursive(),
this.listAll(), getRestartRequired());
this.listAll(), getRestartRequired(), getTags());
ListResponse<VpcResponse> response = new ListResponse<VpcResponse>();
List<VpcResponse> offeringResponses = new ArrayList<VpcResponse>();
for (Vpc vpc : vpcs) {

View File

@ -16,6 +16,8 @@
// under the License.
package com.cloud.api.response;
import java.util.List;
import com.cloud.api.ApiConstants;
import com.cloud.serializer.Param;
import com.cloud.utils.IdentityProxy;
@ -49,6 +51,10 @@ public class NetworkACLResponse extends BaseResponse {
@SerializedName(ApiConstants.ICMP_CODE) @Param(description = "error code for this icmp message")
private Integer icmpCode;
@SerializedName(ApiConstants.TAGS) @Param(description="the list of resource tags associated with the network ACLs",
responseObject = ResourceTagResponse.class)
private List<ResourceTagResponse> tags;
public void setId(Long id) {
this.id.setValue(id);
@ -85,4 +91,8 @@ public class NetworkACLResponse extends BaseResponse {
public void setTrafficType(String trafficType) {
this.trafficType = trafficType;
}
public void setTags(List<ResourceTagResponse> tags) {
this.tags = tags;
}
}

View File

@ -16,9 +16,11 @@
// under the License.
package com.cloud.api.response;
import java.util.List;
import com.cloud.api.ApiConstants;
import com.cloud.utils.IdentityProxy;
import com.cloud.serializer.Param;
import com.cloud.utils.IdentityProxy;
import com.google.gson.annotations.SerializedName;
@SuppressWarnings("unused")
@ -44,6 +46,9 @@ public class ProjectResponse extends BaseResponse{
@SerializedName(ApiConstants.STATE) @Param(description="the state of the project")
private String state;
@SerializedName(ApiConstants.TAGS) @Param(description="the list of resource tags associated with vm", responseObject = ResourceTagResponse.class)
private List<ResourceTagResponse> tags;
public void setId(Long id) {
@ -73,4 +78,8 @@ public class ProjectResponse extends BaseResponse{
public void setState(String state) {
this.state = state;
}
public void setTags(List<ResourceTagResponse> tags) {
this.tags = tags;
}
}

View File

@ -16,6 +16,8 @@
// under the License.
package com.cloud.api.response;
import java.util.List;
import com.cloud.api.ApiConstants;
import com.cloud.serializer.Param;
import com.cloud.utils.IdentityProxy;
@ -55,6 +57,10 @@ public class StaticRouteResponse extends BaseResponse implements ControlledEntit
@SerializedName(ApiConstants.DOMAIN)
@Param(description = "the domain associated with the static route")
private String domainName;
@SerializedName(ApiConstants.TAGS) @Param(description="the list of resource tags associated with static route",
responseObject = ResourceTagResponse.class)
private List<ResourceTagResponse> tags;
public void setId(Long id) {
this.id.setValue(id);
@ -100,4 +106,8 @@ public class StaticRouteResponse extends BaseResponse implements ControlledEntit
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public void setTags(List<ResourceTagResponse> tags) {
this.tags = tags;
}
}

View File

@ -79,6 +79,9 @@ public class VpcResponse extends BaseResponse implements ControlledEntityRespons
@SerializedName(ApiConstants.NETWORK_DOMAIN) @Param(description="the network domain")
private String networkDomain;
@SerializedName(ApiConstants.TAGS) @Param(description="the list of resource tags associated with the project", responseObject = ResourceTagResponse.class)
private List<ResourceTagResponse> tags;
public void setId(Long id) {
this.id.setValue(id);
@ -160,4 +163,8 @@ public class VpcResponse extends BaseResponse implements ControlledEntityRespons
public void setZoneName(String zoneName) {
this.zoneName = zoneName;
}
public void setTags(List<ResourceTagResponse> tags) {
this.tags = tags;
}
}

View File

@ -112,13 +112,14 @@ public interface VpcService {
* @param isRecursive TODO
* @param listAll TODO
* @param restartRequired TODO
* @param tags TODO
* @param vpc
* @return
*/
public List<? extends Vpc> listVpcs(Long id, String vpcName, String displayText,
List<String> supportedServicesStr, String cidr, Long vpcOffId, String state, String accountName, Long domainId,
String keyword, Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll,
Boolean restartRequired);
Boolean restartRequired, Map<String, String> tags);
/**
* @param vpcId

View File

@ -17,6 +17,7 @@
package com.cloud.projects;
import java.util.List;
import java.util.Map;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.ResourceAllocationException;
@ -59,7 +60,8 @@ public interface ProjectService {
*/
Project getProject(long id);
List<? extends Project> listProjects(Long id, String name, String displayText, String state, String accountName, Long domainId, String keyword, Long startIndex, Long pageSize, boolean listAll, boolean isRecursive);
List<? extends Project> listProjects(Long id, String name, String displayText, String state, String accountName,
Long domainId, String keyword, Long startIndex, Long pageSize, boolean listAll, boolean isRecursive, Map<String, String> tags);
ProjectAccount assignAccountToProject(Project project, long accountId, Role accountRole);

View File

@ -31,7 +31,11 @@ public interface ResourceTag extends ControlledEntity{
PortForwardingRule,
FirewallRule,
SecurityGroup,
PublicIpAddress
PublicIpAddress,
Project,
Vpc,
NetworkACL,
StaticRoute
}
/**

View File

@ -3063,6 +3063,15 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setDomain(domain.getName());
response.setOwner(ApiDBUtils.getProjectOwner(project.getId()).getAccountName());
//set tag information
List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.Project, project.getId());
List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
for (ResourceTag tag : tags) {
ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
tagResponses.add(tagResponse);
}
response.setTags(tagResponses);
response.setObjectName("project");
return response;
@ -3141,6 +3150,16 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setIcmpType(networkACL.getIcmpType());
response.setState(stateToSet);
//set tag information
List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.NetworkACL, networkACL.getId());
List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
for (ResourceTag tag : tags) {
ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
tagResponses.add(tagResponse);
}
response.setTags(tagResponses);
response.setObjectName("networkacl");
return response;
}
@ -3722,7 +3741,15 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setNetworks(networkResponses);
response.setServices(serviceResponses);
populateOwner(response, vpc);
//set tag information
List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.Vpc, vpc.getId());
List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
for (ResourceTag tag : tags) {
ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
tagResponses.add(tagResponse);
}
response.setTags(tagResponses);
response.setObjectName("vpc");
return response;
}
@ -3765,6 +3792,15 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setState(stateToSet);
populateAccount(response, result.getAccountId());
populateDomain(response, result.getDomainId());
//set tag information
List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.StaticRoute, result.getId());
List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
for (ResourceTag tag : tags) {
ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
tagResponses.add(tagResponse);
}
response.setTags(tagResponses);
response.setObjectName("staticroute");
return response;

View File

@ -300,6 +300,8 @@ public class FirewallRulesDaoImpl extends GenericDaoBase<FirewallRuleVO, Long> i
_tagsDao.removeByIdAndType(id, TaggedResourceType.PortForwardingRule);
} else if (entry.getPurpose() == Purpose.Firewall) {
_tagsDao.removeByIdAndType(id, TaggedResourceType.FirewallRule);
} else if (entry.getPurpose() == Purpose.NetworkACL) {
_tagsDao.removeByIdAndType(id, TaggedResourceType.NetworkACL);
}
}
boolean result = super.remove(id);

View File

@ -22,6 +22,9 @@ import javax.ejb.Local;
import com.cloud.network.vpc.StaticRoute;
import com.cloud.network.vpc.StaticRouteVO;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;
@ -29,6 +32,7 @@ import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Func;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.Transaction;
@Local(value = StaticRouteDao.class)
@ -37,6 +41,7 @@ public class StaticRouteDaoImpl extends GenericDaoBase<StaticRouteVO, Long> impl
protected final SearchBuilder<StaticRouteVO> AllFieldsSearch;
protected final SearchBuilder<StaticRouteVO> NotRevokedSearch;
protected final GenericSearchBuilder<StaticRouteVO, Long> RoutesByGatewayCount;
ResourceTagsDaoImpl _tagsDao = ComponentLocator.inject(ResourceTagsDaoImpl.class);
protected StaticRouteDaoImpl() {
super();
@ -93,4 +98,18 @@ public class StaticRouteDaoImpl extends GenericDaoBase<StaticRouteVO, Long> impl
sc.setParameters("gatewayId", gatewayId);
return customSearch(sc, null).get(0);
}
@Override
@DB
public boolean remove(Long id) {
Transaction txn = Transaction.currentTxn();
txn.start();
StaticRouteVO entry = findById(id);
if (entry != null) {
_tagsDao.removeBy(id, TaggedResourceType.StaticRoute);
}
boolean result = super.remove(id);
txn.commit();
return result;
}
}

View File

@ -22,6 +22,9 @@ import javax.ejb.Local;
import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.VpcVO;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;
@ -29,6 +32,7 @@ import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Func;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.Transaction;
@Local(value = VpcDao.class)
@ -36,6 +40,7 @@ import com.cloud.utils.db.SearchCriteria.Op;
public class VpcDaoImpl extends GenericDaoBase<VpcVO, Long> implements VpcDao{
final GenericSearchBuilder<VpcVO, Integer> CountByOfferingId;
final SearchBuilder<VpcVO> AllFieldsSearch;
ResourceTagsDaoImpl _tagsDao = ComponentLocator.inject(ResourceTagsDaoImpl.class);
protected VpcDaoImpl() {
super();
@ -83,5 +88,19 @@ public class VpcDaoImpl extends GenericDaoBase<VpcVO, Long> implements VpcDao{
sc.setParameters("state", Vpc.State.Inactive);
return listBy(sc, null);
}
@Override
@DB
public boolean remove(Long id) {
Transaction txn = Transaction.currentTxn();
txn.start();
VpcVO entry = findById(id);
if (entry != null) {
_tagsDao.removeBy(id, TaggedResourceType.Vpc);
}
boolean result = super.remove(id);
txn.commit();
return result;
}
}

View File

@ -45,6 +45,9 @@ import com.cloud.network.rules.FirewallRule.Purpose;
import com.cloud.network.rules.FirewallRule.TrafficType;
import com.cloud.network.rules.FirewallRuleVO;
import com.cloud.projects.Project.ListProjectResourcesCriteria;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.tags.ResourceTagVO;
import com.cloud.tags.dao.ResourceTagDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.UserContext;
@ -53,6 +56,7 @@ import com.cloud.utils.component.Inject;
import com.cloud.utils.component.Manager;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Filter;
import com.cloud.utils.db.JoinBuilder;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op;
@ -66,7 +70,6 @@ public class NetworkACLManagerImpl implements Manager,NetworkACLManager{
String _name;
private static final Logger s_logger = Logger.getLogger(NetworkACLManagerImpl.class);
@Inject
AccountManager _accountMgr;
@Inject
@ -77,7 +80,8 @@ public class NetworkACLManagerImpl implements Manager,NetworkACLManager{
NetworkManager _networkMgr;
@Inject
VpcManager _vpcMgr;
@Inject
ResourceTagDao _resourceTagDao;
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
@ -328,6 +332,7 @@ public class NetworkACLManagerImpl implements Manager,NetworkACLManager{
Long networkId = cmd.getNetworkId();
Long id = cmd.getId();
String trafficType = cmd.getTrafficType();
Map<String, String> tags = cmd.getTags();
Account caller = UserContext.current().getCaller();
List<Long> permittedAccounts = new ArrayList<Long>();
@ -348,6 +353,18 @@ public class NetworkACLManagerImpl implements Manager,NetworkACLManager{
sb.and("networkId", sb.entity().getNetworkId(), Op.EQ);
sb.and("purpose", sb.entity().getPurpose(), Op.EQ);
sb.and("trafficType", sb.entity().getTrafficType(), Op.EQ);
if (tags != null && !tags.isEmpty()) {
SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
for (int count=0; count < tags.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);
}
SearchCriteria<FirewallRuleVO> sc = sb.create();
_accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
@ -363,6 +380,16 @@ public class NetworkACLManagerImpl implements Manager,NetworkACLManager{
if (trafficType != null) {
sc.setParameters("trafficType", trafficType);
}
if (tags != null && !tags.isEmpty()) {
int count = 0;
sc.setJoinParameters("tagSearch", "resourceType", TaggedResourceType.NetworkACL.toString());
for (String key : tags.keySet()) {
sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key);
sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), tags.get(key));
count++;
}
}
sc.setParameters("purpose", Purpose.NetworkACL);

View File

@ -84,6 +84,8 @@ import com.cloud.offerings.NetworkOfferingServiceMapVO;
import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
import com.cloud.org.Grouping;
import com.cloud.projects.Project.ListProjectResourcesCriteria;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.tags.ResourceTagVO;
import com.cloud.tags.dao.ResourceTagDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
@ -157,6 +159,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
@Inject
VlanDao _vlanDao = null;
private final ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("VpcChecker"));
private VpcProvider vpcElement = null;
@ -694,7 +697,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
@Override
public List<? extends Vpc> listVpcs(Long id, String vpcName, String displayText, List<String> supportedServicesStr,
String cidr, Long vpcOffId, String state, String accountName, Long domainId, String keyword,
Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll, Boolean restartRequired) {
Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll, Boolean restartRequired, Map<String, String> tags) {
Account caller = UserContext.current().getCaller();
List<Long> permittedAccounts = new ArrayList<Long>();
@ -719,6 +722,18 @@ public class VpcManagerImpl implements VpcManager, Manager{
sb.and("restartRequired", sb.entity().isRestartRequired(), SearchCriteria.Op.EQ);
sb.and("cidr", sb.entity().getCidr(), SearchCriteria.Op.EQ);
if (tags != null && !tags.isEmpty()) {
SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
for (int count=0; count < tags.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);
}
// now set the SC criteria...
SearchCriteria<VpcVO> sc = sb.create();
_accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
@ -737,6 +752,16 @@ public class VpcManagerImpl implements VpcManager, Manager{
if (displayText != null) {
sc.addAnd("displayText", SearchCriteria.Op.LIKE, "%" + displayText + "%");
}
if (tags != null && !tags.isEmpty()) {
int count = 0;
sc.setJoinParameters("tagSearch", "resourceType", TaggedResourceType.Vpc.toString());
for (String key : tags.keySet()) {
sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key);
sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), tags.get(key));
count++;
}
}
if (id != null) {
sc.addAnd("id", SearchCriteria.Op.EQ, id);
@ -1525,6 +1550,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
String accountName = cmd.getAccountName();
Account caller = UserContext.current().getCaller();
List<Long> permittedAccounts = new ArrayList<Long>();
Map<String, String> tags = cmd.getTags();
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean,
ListProjectResourcesCriteria>(domainId, isRecursive, null);
@ -1542,6 +1568,18 @@ public class VpcManagerImpl implements VpcManager, Manager{
sb.and("vpcId", sb.entity().getVpcId(), SearchCriteria.Op.EQ);
sb.and("vpcGatewayId", sb.entity().getVpcGatewayId(), SearchCriteria.Op.EQ);
if (tags != null && !tags.isEmpty()) {
SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
for (int count=0; count < tags.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);
}
SearchCriteria<StaticRouteVO> sc = sb.create();
_accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
@ -1557,6 +1595,16 @@ public class VpcManagerImpl implements VpcManager, Manager{
sc.addAnd("vpcGatewayId", Op.EQ, gatewayId);
}
if (tags != null && !tags.isEmpty()) {
int count = 0;
sc.setJoinParameters("tagSearch", "resourceType", TaggedResourceType.StaticRoute.toString());
for (String key : tags.keySet()) {
sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key);
sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), tags.get(key));
count++;
}
}
return _staticRouteDao.search(sc, searchFilter);
}

View File

@ -60,6 +60,9 @@ import com.cloud.projects.ProjectAccount.Role;
import com.cloud.projects.dao.ProjectAccountDao;
import com.cloud.projects.dao.ProjectDao;
import com.cloud.projects.dao.ProjectInvitationDao;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.tags.ResourceTagVO;
import com.cloud.tags.dao.ResourceTagDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.AccountVO;
@ -111,6 +114,8 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
private ConfigurationDao _configDao;
@Inject
private ProjectInvitationDao _projectInvitationDao;
@Inject
protected ResourceTagDao _resourceTagDao;
protected boolean _invitationRequired = false;
protected long _invitationTimeOut = 86400000;
@ -347,7 +352,9 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
}
@Override
public List<? extends Project> listProjects(Long id, String name, String displayText, String state, String accountName, Long domainId, String keyword, Long startIndex, Long pageSize, boolean listAll, boolean isRecursive) {
public List<? extends Project> listProjects(Long id, String name, String displayText, String state,
String accountName, Long domainId, String keyword, Long startIndex, Long pageSize, boolean listAll,
boolean isRecursive, Map<String, String> tags) {
Account caller = UserContext.current().getCaller();
Long accountId = null;
String path = null;
@ -384,14 +391,12 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
accountId = caller.getId();
}
if (domainId == null && accountId == null && (caller.getType() == Account.ACCOUNT_TYPE_NORMAL || !listAll)) {
accountId = caller.getId();
} else if (caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || (isRecursive && !listAll)) {
DomainVO domain = _domainDao.findById(caller.getDomainId());
path = domain.getPath();
}
if (path != null) {
SearchBuilder<DomainVO> domainSearch = _domainDao.createSearchBuilder();
@ -405,6 +410,18 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
sb.join("projectAccountSearch", projectAccountSearch, sb.entity().getId(), projectAccountSearch.entity().getProjectId(), JoinBuilder.JoinType.INNER);
}
if (tags != null && !tags.isEmpty()) {
SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
for (int count=0; count < tags.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);
}
SearchCriteria<ProjectVO> sc = sb.create();
if (id != null) {
@ -442,6 +459,16 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
sc.setJoinParameters("domainSearch", "path", path);
}
if (tags != null && !tags.isEmpty()) {
int count = 0;
sc.setJoinParameters("tagSearch", "resourceType", TaggedResourceType.Project.toString());
for (String key : tags.keySet()) {
sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key);
sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), tags.get(key));
count++;
}
}
return _projectDao.search(sc, searchFilter);
}

View File

@ -24,6 +24,9 @@ import org.apache.log4j.Logger;
import com.cloud.projects.Project;
import com.cloud.projects.ProjectVO;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;
@ -38,6 +41,7 @@ public class ProjectDaoImpl extends GenericDaoBase<ProjectVO, Long> implements P
protected final SearchBuilder<ProjectVO> AllFieldsSearch;
protected GenericSearchBuilder<ProjectVO, Long> CountByDomain;
protected GenericSearchBuilder<ProjectVO, Long> ProjectAccountSearch;
ResourceTagsDaoImpl _tagsDao = ComponentLocator.inject(ResourceTagsDaoImpl.class);
protected ProjectDaoImpl() {
AllFieldsSearch = createSearchBuilder();
@ -73,7 +77,9 @@ public class ProjectDaoImpl extends GenericDaoBase<ProjectVO, Long> implements P
if (!update(projectId, projectToRemove)) {
s_logger.warn("Failed to reset name for the project id=" + projectId + " as a part of project remove");
return false;
}
}
_tagsDao.removeByIdAndType(projectId, TaggedResourceType.Project);
result = super.remove(projectId);
txn.commit();
@ -102,5 +108,4 @@ public class ProjectDaoImpl extends GenericDaoBase<ProjectVO, Long> implements P
sc.setParameters("state", state);
return listBy(sc);
}
}

View File

@ -335,6 +335,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
@Inject(adapter = StoragePoolDiscoverer.class)
protected Adapters<StoragePoolDiscoverer> _discoverers;
protected SearchBuilder<VMTemplateHostVO> HostTemplateStatesSearch;
protected GenericSearchBuilder<StoragePoolHostVO, Long> UpHostsInPoolSearch;
protected SearchBuilder<VMInstanceVO> StoragePoolSearch;

View File

@ -39,7 +39,10 @@ import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.RemoteAccessVpnDao;
import com.cloud.network.rules.dao.PortForwardingRulesDao;
import com.cloud.network.security.dao.SecurityGroupDao;
import com.cloud.network.vpc.Dao.StaticRouteDao;
import com.cloud.network.vpc.Dao.VpcDao;
import com.cloud.projects.Project.ListProjectResourcesCriteria;
import com.cloud.projects.dao.ProjectDao;
import com.cloud.server.ResourceTag;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.server.TaggedResourceService;
@ -62,6 +65,7 @@ import com.cloud.utils.db.GenericDao;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.uuididentity.dao.IdentityDao;
import com.cloud.vm.dao.UserVmDao;
@ -104,6 +108,12 @@ public class TaggedResourceManagerImpl implements TaggedResourceService, Manager
RemoteAccessVpnDao _vpnDao;
@Inject
IPAddressDao _publicIpDao;
@Inject
ProjectDao _projectDao;
@Inject
VpcDao _vpcDao;
@Inject
StaticRouteDao _staticRouteDao;
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
@ -119,6 +129,10 @@ public class TaggedResourceManagerImpl implements TaggedResourceService, Manager
_daoMap.put(TaggedResourceType.FirewallRule, _firewallDao);
_daoMap.put(TaggedResourceType.SecurityGroup, _securityGroupDao);
_daoMap.put(TaggedResourceType.PublicIpAddress, _publicIpDao);
_daoMap.put(TaggedResourceType.Project, _projectDao);
_daoMap.put(TaggedResourceType.Vpc, _vpcDao);
_daoMap.put(TaggedResourceType.NetworkACL, _firewallDao);
_daoMap.put(TaggedResourceType.StaticRoute, _staticRouteDao);
return true;
}
@ -141,6 +155,9 @@ public class TaggedResourceManagerImpl implements TaggedResourceService, Manager
private Long getResourceId(String resourceId, TaggedResourceType resourceType) {
GenericDao<?, Long> dao = _daoMap.get(resourceType);
if (dao == null) {
throw new CloudRuntimeException("Dao is not loaded for the resource type " + resourceType);
}
Class<?> claz = DbUtil.getEntityBeanType(dao);
Long identityId = null;
@ -184,7 +201,7 @@ public class TaggedResourceManagerImpl implements TaggedResourceService, Manager
if (tableName == null) {
throw new InvalidParameterValueException("Unable to find resource of type " + resourceType + " in the database");
}
pair = _identityDao.getAccountDomainInfo(tableName, resourceId);
pair = _identityDao.getAccountDomainInfo(tableName, resourceId, resourceType);
if (pair.first() != null || pair.second() != null) {
break;
}

View File

@ -18,6 +18,7 @@
package com.cloud.uuididentity.dao;
import com.cloud.api.IdentityMapper;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.utils.Pair;
import com.cloud.utils.db.GenericDao;
@ -29,7 +30,8 @@ public interface IdentityDao extends GenericDao<IdentityVO, Long> {
/**
* @param tableName
* @param identityId
* @param resourceType TODO
* @return
*/
Pair<Long, Long> getAccountDomainInfo(String tableName, Long identityId);
}
Pair<Long, Long> getAccountDomainInfo(String tableName, Long identityId, TaggedResourceType resourceType);
}

View File

@ -29,6 +29,7 @@ import org.apache.log4j.Logger;
import com.cloud.api.IdentityMapper;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.utils.Pair;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
@ -101,7 +102,7 @@ public class IdentityDaoImpl extends GenericDaoBase<IdentityVO, Long> implements
@DB
@Override
public Pair<Long, Long> getAccountDomainInfo(String tableName, Long identityId) {
public Pair<Long, Long> getAccountDomainInfo(String tableName, Long identityId, TaggedResourceType resourceType) {
assert(tableName != null);
PreparedStatement pstmt = null;
@ -122,7 +123,11 @@ public class IdentityDaoImpl extends GenericDaoBase<IdentityVO, Long> implements
//get accountId
try {
pstmt = txn.prepareAutoCloseStatement(String.format("SELECT account_id FROM `%s` WHERE id=?", tableName));
String account = "account_id";
if (resourceType == TaggedResourceType.Project) {
account = "project_account_id";
}
pstmt = txn.prepareAutoCloseStatement(String.format("SELECT " + account + " FROM `%s` WHERE id=?", tableName));
pstmt.setLong(1, identityId);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {