api: Refactoring ListEventsCmd and EventResponse, and create Event db view.

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
This commit is contained in:
Min Chen 2012-12-07 16:22:28 -08:00 committed by Rohit Yadav
parent 41268d1237
commit 30941c2d31
17 changed files with 1148 additions and 509 deletions

View File

@ -25,9 +25,9 @@ import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
@SuppressWarnings("unused")
public class EventResponse extends BaseResponse implements ControlledEntityResponse{
public class EventResponse extends BaseResponse implements ControlledViewEntityResponse{
@SerializedName(ApiConstants.ID) @Param(description="the ID of the event")
private IdentityProxy id = new IdentityProxy("event");
private String id;
@SerializedName(ApiConstants.USERNAME) @Param(description="the name of the user who performed the action (can be different from the account if an admin is performing an action for a user, e.g. starting/stopping a user's virtual machine)")
private String username;
@ -45,13 +45,13 @@ public class EventResponse extends BaseResponse implements ControlledEntityRespo
private String accountName;
@SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id of the ipaddress")
private IdentityProxy projectId = new IdentityProxy("projects");
private String projectId;
@SerializedName(ApiConstants.PROJECT) @Param(description="the project name of the address")
private String projectName;
@SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the id of the account's domain")
private IdentityProxy domainId = new IdentityProxy("domain");
private String domainId;
@SerializedName(ApiConstants.DOMAIN) @Param(description="the name of the account's domain")
private String domainName;
@ -63,10 +63,10 @@ public class EventResponse extends BaseResponse implements ControlledEntityRespo
private Event.State state;
@SerializedName("parentid") @Param(description="whether the event is parented")
private IdentityProxy parentId = new IdentityProxy("event");
private String parentId;
public void setId(Long id) {
this.id.setValue(id);
public void setId(String id) {
this.id = id;
}
public void setUsername(String username) {
@ -91,8 +91,8 @@ public class EventResponse extends BaseResponse implements ControlledEntityRespo
}
@Override
public void setDomainId(Long domainId) {
this.domainId.setValue(domainId);
public void setDomainId(String domainId) {
this.domainId = domainId;
}
@Override
@ -108,13 +108,13 @@ public class EventResponse extends BaseResponse implements ControlledEntityRespo
this.state = state;
}
public void setParentId(Long parentId) {
this.parentId.setValue(parentId);
public void setParentId(String parentId) {
this.parentId = parentId;
}
@Override
public void setProjectId(Long projectId) {
this.projectId.setValue(projectId);
public void setProjectId(String projectId) {
this.projectId = projectId;
}
@Override

View File

@ -0,0 +1,331 @@
// 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.api.view.vo;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;
import com.cloud.utils.db.GenericDao;
import com.cloud.event.Event.State;
@Entity
@Table(name="event_view")
public class EventJoinVO implements ControlledViewEntity {
@Column(name="id", updatable=false, nullable = false)
private long id;
@Column(name="uuid")
private String uuid;
@Column(name="type")
private String type;
@Enumerated(value=EnumType.STRING)
@Column(name="state")
private State state;
@Column(name="description")
private String description;
@Column(name=GenericDao.CREATED_COLUMN)
private Date createDate;
@Column(name="user_id")
private long userId;
@Column(name="user_name")
private String userName;
@Column(name="level")
private String level;
@Column(name="start_id")
private long startId;
@Column(name="start_uuid")
private String startUuid;
@Column(name="parameters", length=1024)
private String parameters;
@Column(name="account_id")
private long accountId;
@Column(name="account_uuid")
private String accountUuid;
@Column(name="account_name")
private String accountName = null;
@Column(name="account_type")
private short accountType;
@Column(name="domain_id")
private long domainId;
@Column(name="domain_uuid")
private String domainUuid;
@Column(name="domain_name")
private String domainName = null;
@Column(name="domain_path")
private String domainPath = null;
@Column(name="project_id")
private long projectId;
@Column(name="project_uuid")
private String projectUuid;
@Column(name="project_name")
private String projectName;
public EventJoinVO() {
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Override
public long getAccountId() {
return accountId;
}
public void setAccountId(long accountId) {
this.accountId = accountId;
}
@Override
public String getAccountUuid() {
return accountUuid;
}
public void setAccountUuid(String accountUuid) {
this.accountUuid = accountUuid;
}
@Override
public String getAccountName() {
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
@Override
public short getAccountType() {
return accountType;
}
public void setAccountType(short accountType) {
this.accountType = accountType;
}
@Override
public long getDomainId() {
return domainId;
}
public void setDomainId(long domainId) {
this.domainId = domainId;
}
@Override
public String getDomainUuid() {
return domainUuid;
}
public void setDomainUuid(String domainUuid) {
this.domainUuid = domainUuid;
}
@Override
public String getDomainName() {
return domainName;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
@Override
public String getDomainPath() {
return domainPath;
}
public void setDomainPath(String domainPath) {
this.domainPath = domainPath;
}
public long getProjectId() {
return projectId;
}
public void setProjectId(long projectId) {
this.projectId = projectId;
}
@Override
public String getProjectUuid() {
return projectUuid;
}
public void setProjectUuid(String projectUuid) {
this.projectUuid = projectUuid;
}
@Override
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public State getState() {
return state;
}
public void setState(State state) {
this.state = state;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public long getUserId() {
return userId;
}
public void setUserId(long userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getLevel() {
return level;
}
public void setLevel(String level) {
this.level = level;
}
public long getStartId() {
return startId;
}
public void setStartId(long startId) {
this.startId = startId;
}
public String getStartUuid() {
return startUuid;
}
public void setStartUuid(String startUuid) {
this.startUuid = startUuid;
}
public String getParameters() {
return parameters;
}
public void setParameters(String parameters) {
this.parameters = parameters;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (id ^ (id >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
EventJoinVO other = (EventJoinVO) obj;
if (id != other.id)
return false;
return true;
}
}

View File

@ -16,22 +16,13 @@
// under the License.
package com.cloud.api.view.vo;
import java.net.URI;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;
import com.cloud.network.Network.GuestType;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.router.VirtualRouter.RedundantState;
import com.cloud.network.security.SecurityRule.SecurityRuleType;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.utils.db.GenericDao;
import com.cloud.vm.VirtualMachine.State;
@Entity
@Table(name="resource_tag_view")
@ -121,6 +112,7 @@ public class ResourceTagJoinVO implements ControlledViewEntity {
}
@Override
public long getAccountId() {
return accountId;
}
@ -129,6 +121,7 @@ public class ResourceTagJoinVO implements ControlledViewEntity {
this.accountId = accountId;
}
@Override
public String getAccountUuid() {
return accountUuid;
}
@ -137,6 +130,7 @@ public class ResourceTagJoinVO implements ControlledViewEntity {
this.accountUuid = accountUuid;
}
@Override
public String getAccountName() {
return accountName;
}
@ -145,6 +139,7 @@ public class ResourceTagJoinVO implements ControlledViewEntity {
this.accountName = accountName;
}
@Override
public short getAccountType() {
return accountType;
}
@ -153,6 +148,7 @@ public class ResourceTagJoinVO implements ControlledViewEntity {
this.accountType = accountType;
}
@Override
public long getDomainId() {
return domainId;
}
@ -170,6 +166,7 @@ public class ResourceTagJoinVO implements ControlledViewEntity {
this.domainUuid = domainUuid;
}
@Override
public String getDomainName() {
return domainName;
}
@ -178,6 +175,7 @@ public class ResourceTagJoinVO implements ControlledViewEntity {
this.domainName = domainName;
}
@Override
public String getDomainPath() {
return domainPath;
}
@ -194,6 +192,7 @@ public class ResourceTagJoinVO implements ControlledViewEntity {
this.projectId = projectId;
}
@Override
public String getProjectUuid() {
return projectUuid;
}
@ -202,6 +201,7 @@ public class ResourceTagJoinVO implements ControlledViewEntity {
this.projectUuid = projectUuid;
}
@Override
public String getProjectName() {
return projectName;
}

View File

@ -5,7 +5,7 @@
// 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,
@ -16,22 +16,14 @@
// under the License.
package com.cloud.api.view.vo;
import java.net.URI;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;
import com.cloud.network.Network.GuestType;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.router.VirtualRouter.RedundantState;
import com.cloud.network.security.SecurityRule.SecurityRuleType;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.utils.db.GenericDao;
import com.cloud.vm.VirtualMachine.State;
@Entity
@Table(name="security_group_view")
@ -173,6 +165,7 @@ public class SecurityGroupJoinVO implements ControlledViewEntity {
this.name = name;
}
@Override
public long getAccountId() {
return accountId;
}
@ -181,6 +174,7 @@ public class SecurityGroupJoinVO implements ControlledViewEntity {
this.accountId = accountId;
}
@Override
public String getAccountUuid() {
return accountUuid;
}
@ -189,6 +183,7 @@ public class SecurityGroupJoinVO implements ControlledViewEntity {
this.accountUuid = accountUuid;
}
@Override
public String getAccountName() {
return accountName;
}
@ -197,6 +192,7 @@ public class SecurityGroupJoinVO implements ControlledViewEntity {
this.accountName = accountName;
}
@Override
public short getAccountType() {
return accountType;
}
@ -205,6 +201,7 @@ public class SecurityGroupJoinVO implements ControlledViewEntity {
this.accountType = accountType;
}
@Override
public long getDomainId() {
return domainId;
}
@ -222,6 +219,7 @@ public class SecurityGroupJoinVO implements ControlledViewEntity {
this.domainUuid = domainUuid;
}
@Override
public String getDomainName() {
return domainName;
}
@ -230,6 +228,7 @@ public class SecurityGroupJoinVO implements ControlledViewEntity {
this.domainName = domainName;
}
@Override
public String getDomainPath() {
return domainPath;
}
@ -246,6 +245,7 @@ public class SecurityGroupJoinVO implements ControlledViewEntity {
this.projectId = projectId;
}
@Override
public String getProjectUuid() {
return projectUuid;
}
@ -254,6 +254,7 @@ public class SecurityGroupJoinVO implements ControlledViewEntity {
this.projectUuid = projectUuid;
}
@Override
public String getProjectName() {
return projectName;
}

View File

@ -63,6 +63,7 @@ import org.apache.cloudstack.api.user.vmgroup.command.UpdateVMGroupCmd;
import org.apache.cloudstack.api.admin.systemvm.command.UpgradeSystemVMCmd;
import org.apache.cloudstack.api.admin.resource.command.UploadCustomCertificateCmd;
import com.cloud.api.view.vo.DomainRouterJoinVO;
import com.cloud.api.view.vo.EventJoinVO;
import com.cloud.async.AsyncJob;
import com.cloud.capacity.Capacity;
import com.cloud.configuration.Configuration;
@ -174,7 +175,7 @@ public interface ManagementService {
* @param c
* @return List of Events.
*/
List<? extends Event> searchForEvents(ListEventsCmd c);
Pair<List<EventJoinVO>, Integer> searchForEvents(ListEventsCmd c);
/**
* Obtains a list of routers by the specified search criteria. Can search by: "userId", "name", "state",

View File

@ -153,6 +153,7 @@ import com.cloud.user.UserAccount;
import com.cloud.uservm.UserVm;
import com.cloud.vm.InstanceGroup;
import com.cloud.api.view.vo.DomainRouterJoinVO;
import com.cloud.api.view.vo.EventJoinVO;
import com.cloud.api.view.vo.ResourceTagJoinVO;
import com.cloud.api.view.vo.SecurityGroupJoinVO;
import com.cloud.api.view.vo.UserVmJoinVO;
@ -262,6 +263,8 @@ public interface ResponseGenerator {
EventResponse createEventResponse(Event event);
List<EventResponse> createEventResponse(EventJoinVO... events);
TemplateResponse createIsoResponse(VirtualMachineTemplate result);
List<CapacityResponse> createCapacityResponse(List<? extends Capacity> result, DecimalFormat format);

View File

@ -29,7 +29,11 @@ import org.apache.cloudstack.api.Implementation;
import org.apache.cloudstack.api.Parameter;
import com.cloud.api.response.EventResponse;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.ResourceTagResponse;
import com.cloud.api.view.vo.EventJoinVO;
import com.cloud.api.view.vo.ResourceTagJoinVO;
import com.cloud.event.Event;
import com.cloud.utils.Pair;
@Implementation(description="A command to list events.", responseObject=EventResponse.class)
public class ListEventsCmd extends BaseListProjectAndAccountResourcesCmd {
@ -106,14 +110,10 @@ public class ListEventsCmd extends BaseListProjectAndAccountResourcesCmd {
@Override
public void execute(){
List<? extends Event> result = _mgr.searchForEvents(this);
Pair<List<EventJoinVO>, Integer> result = _mgr.searchForEvents(this);
ListResponse<EventResponse> response = new ListResponse<EventResponse>();
List<EventResponse> eventResponses = new ArrayList<EventResponse>();
for (Event event : result) {
eventResponses.add(_responseGenerator.createEventResponse(event));
}
response.setResponses(eventResponses);
List<EventResponse> eventResponses = _responseGenerator.createEventResponse(result.first().toArray(new EventJoinVO[result.first().size()]));
response.setResponses(eventResponses, result.second());
response.setResponseName(getCommandName());
this.setResponseObject(response);
}

View File

@ -5,7 +5,7 @@
// 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,
@ -24,10 +24,12 @@ import java.util.Set;
import org.apache.cloudstack.api.ApiConstants.VMDetails;
import com.cloud.api.response.DomainRouterResponse;
import com.cloud.api.response.EventResponse;
import com.cloud.api.response.ResourceTagResponse;
import com.cloud.api.response.SecurityGroupResponse;
import com.cloud.api.response.UserVmResponse;
import com.cloud.api.view.vo.DomainRouterJoinVO;
import com.cloud.api.view.vo.EventJoinVO;
import com.cloud.api.view.vo.ResourceTagJoinVO;
import com.cloud.api.view.vo.SecurityGroupJoinVO;
import com.cloud.api.view.vo.UserVmJoinVO;
@ -53,6 +55,8 @@ import com.cloud.dc.dao.HostPodDao;
import com.cloud.dc.dao.VlanDao;
import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao;
import com.cloud.event.Event;
import com.cloud.event.dao.EventJoinDao;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.ha.HighAvailabilityManager;
import com.cloud.host.Host;
@ -247,6 +251,7 @@ public class ApiDBUtils {
private static AutoScalePolicyDao _asPolicyDao;
private static CounterDao _counterDao;
private static ResourceTagJoinDao _tagJoinDao;
private static EventJoinDao _eventJoinDao;
static {
_ms = (ManagementServer) ComponentLocator.getComponent(ManagementServer.Name);
@ -317,6 +322,7 @@ public class ApiDBUtils {
_asVmGroupPolicyMapDao = locator.getDao(AutoScaleVmGroupPolicyMapDao.class);
_counterDao = locator.getDao(CounterDao.class);
_tagJoinDao = locator.getDao(ResourceTagJoinDao.class);
_eventJoinDao = locator.getDao(EventJoinDao.class);
// Note: stats collector should already have been initialized by this time, otherwise a null instance is returned
_statsCollector = StatsCollector.getInstance();
@ -621,11 +627,11 @@ public class ApiDBUtils {
public static Site2SiteVpnGatewayVO findVpnGatewayById(Long vpnGatewayId) {
return _site2SiteVpnGatewayDao.findById(vpnGatewayId);
}
public static Site2SiteCustomerGatewayVO findCustomerGatewayById(Long customerGatewayId) {
public static Site2SiteCustomerGatewayVO findCustomerGatewayById(Long customerGatewayId) {
return _site2SiteCustomerGatewayDao.findById(customerGatewayId);
}
public static List<UserVO> listUsersByAccount(long accountId) {
return _userDao.listByAccount(accountId);
}
@ -775,11 +781,11 @@ public class ApiDBUtils {
public static Project findProjectByProjectAccountId(long projectAccountId) {
return _projectMgr.findByProjectAccountId(projectAccountId);
}
public static Project findProjectByProjectAccountIdIncludingRemoved(long projectAccountId) {
return _projectMgr.findByProjectAccountIdIncludingRemoved(projectAccountId);
}
public static Project findProjectById(long projectId) {
return _projectMgr.getProject(projectId);
}
@ -833,15 +839,15 @@ public class ApiDBUtils {
public static String getHaTag() {
return _haMgr.getHaTag();
}
public static Map<Service, Set<Provider>> listVpcOffServices(long vpcOffId) {
return _vpcMgr.getVpcOffSvcProvidersMap(vpcOffId);
}
public static List<? extends Network> listVpcNetworks(long vpcId) {
return _networkMgr.listNetworksByVpc(vpcId);
}
public static boolean canUseForDeploy(Network network) {
return _networkMgr.canUseForDeploy(network);
}
@ -849,7 +855,7 @@ public class ApiDBUtils {
public static String getUuid(String resourceId, TaggedResourceType resourceType) {
return _taggedResourceService.getUuid(resourceId, resourceType);
}
public static boolean isOfferingForVpc(NetworkOffering offering) {
boolean vpcProvider = _configMgr.isOfferingForVpc(offering);
return vpcProvider;
@ -970,4 +976,12 @@ public class ApiDBUtils {
return null;
}
}
public static EventResponse newEventResponse(EventJoinVO ve) {
return _eventJoinDao.newEventResponse(ve);
}
public static EventJoinVO newEventView(Event e){
return _eventJoinDao.newEventView(e);
}
}

View File

@ -5,7 +5,7 @@
// 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,
@ -118,6 +118,7 @@ import com.cloud.api.response.VpnUsersResponse;
import com.cloud.api.response.ZoneResponse;
import com.cloud.api.view.vo.DomainRouterJoinVO;
import com.cloud.api.view.vo.ControlledViewEntity;
import com.cloud.api.view.vo.EventJoinVO;
import com.cloud.api.view.vo.ResourceTagJoinVO;
import com.cloud.api.view.vo.SecurityGroupJoinVO;
import com.cloud.api.view.vo.UserVmJoinVO;
@ -401,7 +402,7 @@ public class ApiResponseHelper implements ResponseGenerator {
accountResponse.setNetworkLimit(networkLimitDisplay);
accountResponse.setNetworkTotal(networkTotal);
accountResponse.setNetworkAvailable(networkAvail);
//get resource limits for vpcs
Long vpcLimit = ApiDBUtils.findCorrectResourceLimit(ResourceType.vpc, account.getId());
String vpcLimitDisplay = (accountIsAdmin || vpcLimit == -1) ? "Unlimited" : String.valueOf(vpcLimit);
@ -423,8 +424,8 @@ public class ApiResponseHelper implements ResponseGenerator {
accountResponse.setDetails(ApiDBUtils.getAccountDetails(account.getId()));
return accountResponse;
}
@Override
public UserResponse createUserResponse(UserAccount user) {
UserResponse userResponse = new UserResponse();
@ -1080,7 +1081,7 @@ public class ApiResponseHelper implements ResponseGenerator {
volResponse.setVolumeType(volume.getVolumeType().toString());
volResponse.setDeviceId(volume.getDeviceId());
Long instanceId = volume.getInstanceId();
if (instanceId != null && volume.getState() != Volume.State.Destroy) {
VMInstanceVO vm = ApiDBUtils.findVMInstanceById(instanceId);
@ -1169,8 +1170,8 @@ public class ApiResponseHelper implements ResponseGenerator {
// return hypervisor for ROOT and Resource domain only
Account caller = UserContext.current().getCaller();
if ((caller.getType() == Account.ACCOUNT_TYPE_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) && volume.getState() != Volume.State.UploadOp) {
volResponse.setHypervisor(ApiDBUtils.getVolumeHyperType(volume.getId()).toString());
if ((caller.getType() == Account.ACCOUNT_TYPE_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) && volume.getState() != Volume.State.UploadOp) {
volResponse.setHypervisor(ApiDBUtils.getVolumeHyperType(volume.getId()).toString());
}
volResponse.setAttached(volume.getAttached());
@ -1182,7 +1183,7 @@ public class ApiResponseHelper implements ResponseGenerator {
isExtractable = template.isExtractable() && template.getTemplateType() != Storage.TemplateType.SYSTEM;
}
}
//set tag information
List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.Volume, volume.getId());
List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
@ -2140,26 +2141,20 @@ public class ApiResponseHelper implements ResponseGenerator {
return createTemplateResponses(templateId, host.getDataCenterId(), true);
}
@Override
public List<EventResponse> createEventResponse(EventJoinVO... events) {
List<EventResponse> respList = new ArrayList<EventResponse>();
for (EventJoinVO vt : events){
respList.add(ApiDBUtils.newEventResponse(vt));
}
return respList;
}
@Override
public EventResponse createEventResponse(Event event) {
EventResponse responseEvent = new EventResponse();
responseEvent.setCreated(event.getCreateDate());
responseEvent.setDescription(event.getDescription());
responseEvent.setEventType(event.getType());
responseEvent.setId(event.getId());
responseEvent.setLevel(event.getLevel());
responseEvent.setParentId(event.getStartId());
responseEvent.setState(event.getState());
populateOwner(responseEvent, event);
User user = ApiDBUtils.findUserById(event.getUserId());
if (user != null) {
responseEvent.setUsername(user.getUsername());
}
responseEvent.setObjectName("event");
return responseEvent;
EventJoinVO vEvent = ApiDBUtils.newEventView(event);
return ApiDBUtils.newEventResponse(vEvent);
}
private List<CapacityVO> sumCapacities(List<? extends Capacity> hostCapacities) {
@ -2554,7 +2549,7 @@ public class ApiResponseHelper implements ResponseGenerator {
serviceResponses.add(svcRsp);
}
response.setForVpc(ApiDBUtils.isOfferingForVpc(offering));
response.setServices(serviceResponses);
response.setObjectName("networkoffering");
return response;
@ -2598,7 +2593,7 @@ public class ApiResponseHelper implements ResponseGenerator {
}
//return vlan information only to Root admin
response.setVlan(vlan);
}
DataCenter zone = ApiDBUtils.findZoneById(network.getDataCenterId());
@ -2715,7 +2710,7 @@ 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>();
@ -2772,7 +2767,7 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setObjectName("firewallrule");
return response;
}
@Override
public NetworkACLResponse createNetworkACLResponse(FirewallRule networkACL) {
NetworkACLResponse response = new NetworkACLResponse();
@ -2802,7 +2797,7 @@ 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>();
@ -2811,7 +2806,7 @@ public class ApiResponseHelper implements ResponseGenerator {
tagResponses.add(tagResponse);
}
response.setTags(tagResponses);
response.setObjectName("networkacl");
return response;
}
@ -3164,7 +3159,7 @@ public class ApiResponseHelper implements ResponseGenerator {
return ApiDBUtils.newResourceTagResponse(rto, keyValueOnly);
}
@Override
public List<ResourceTagResponse> createResourceTagResponse(boolean keyValueOnly, ResourceTagJoinVO... tags) {
List<ResourceTagResponse> respList = new ArrayList<ResourceTagResponse>();
@ -3208,8 +3203,8 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setObjectName("vpcoffering");
return response;
}
@Override
public VpcResponse createVpcResponse(Vpc vpc) {
VpcResponse response = new VpcResponse();
@ -3243,22 +3238,22 @@ public class ApiResponseHelper implements ResponseGenerator {
serviceResponses.add(svcRsp);
}
List<NetworkResponse> networkResponses = new ArrayList<NetworkResponse>();
List<? extends Network> networks = ApiDBUtils.listVpcNetworks(vpc.getId());
for (Network network : networks) {
NetworkResponse ntwkRsp = createNetworkResponse(network);
networkResponses.add(ntwkRsp);
}
DataCenter zone = ApiDBUtils.findZoneById(vpc.getZoneId());
response.setZoneId(vpc.getZoneId());
response.setZoneName(zone.getName());
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>();
@ -3284,13 +3279,13 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setZoneName(zone.getName());
response.setAddress(result.getIp4Address());
response.setPhysicalNetworkId(result.getPhysicalNetworkId());
populateAccount(response, result.getAccountId());
populateDomain(response, result.getDomainId());
response.setState(result.getState().toString());
response.setObjectName("privategateway");
return response;
}
@ -3390,14 +3385,14 @@ public class ApiResponseHelper implements ResponseGenerator {
return response;
}
@Override
public StaticRouteResponse createStaticRouteResponse(StaticRoute result) {
StaticRouteResponse response = new StaticRouteResponse();
response.setId(result.getId());
response.setVpcId(result.getVpcId());
response.setCidr(result.getCidr());
StaticRoute.State state = result.getState();
String stateToSet = state.toString();
if (state.equals(FirewallRule.State.Revoke)) {
@ -3406,7 +3401,7 @@ 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>();
@ -3416,10 +3411,10 @@ public class ApiResponseHelper implements ResponseGenerator {
}
response.setTags(tagResponses);
response.setObjectName("staticroute");
return response;
}
@Override
public Site2SiteVpnGatewayResponse createSite2SiteVpnGatewayResponse(Site2SiteVpnGateway result) {
Site2SiteVpnGatewayResponse response = new Site2SiteVpnGatewayResponse();
@ -3428,7 +3423,7 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setVpcId(result.getVpcId());
response.setRemoved(result.getRemoved());
response.setObjectName("vpngateway");
populateAccount(response, result.getAccountId());
populateDomain(response, result.getDomainId());
return response;
@ -3450,10 +3445,10 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setRemoved(result.getRemoved());
response.setObjectName("vpncustomergateway");
populateAccount(response, result.getAccountId());
populateDomain(response, result.getDomainId());
return response;
}
@ -3461,18 +3456,18 @@ public class ApiResponseHelper implements ResponseGenerator {
public Site2SiteVpnConnectionResponse createSite2SiteVpnConnectionResponse(Site2SiteVpnConnection result) {
Site2SiteVpnConnectionResponse response = new Site2SiteVpnConnectionResponse();
response.setId(result.getId());
response.setVpnGatewayId(result.getVpnGatewayId());
response.setVpnGatewayId(result.getVpnGatewayId());
Long vpnGatewayId = result.getVpnGatewayId();
if(vpnGatewayId != null) {
Site2SiteVpnGatewayVO vpnGateway = ApiDBUtils.findVpnGatewayById(vpnGatewayId);
long ipId = vpnGateway.getAddrId();
IPAddressVO ipObj = ApiDBUtils.findIpAddressById(ipId);
response.setIp(ipObj.getAddress().addr());
response.setIp(ipObj.getAddress().addr());
}
response.setCustomerGatewayId(result.getCustomerGatewayId());
response.setCustomerGatewayId(result.getCustomerGatewayId());
Long customerGatewayId = result.getCustomerGatewayId();
if(customerGatewayId != null) {
Site2SiteCustomerGatewayVO customerGateway = ApiDBUtils.findCustomerGatewayById(customerGatewayId);
@ -3484,11 +3479,11 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setIkeLifetime(customerGateway.getIkeLifetime());
response.setEspLifetime(customerGateway.getEspLifetime());
response.setDpd(customerGateway.getDpd());
}
}
populateAccount(response, result.getAccountId());
populateDomain(response, result.getDomainId());
response.setState(result.getState().toString());
response.setCreated(result.getCreated());
response.setRemoved(result.getRemoved());

View File

@ -5,7 +5,7 @@
// 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,
@ -79,7 +79,9 @@ import org.apache.http.protocol.ResponseServer;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.admin.router.command.ListRoutersCmd;
import org.apache.cloudstack.api.user.event.command.ListEventsCmd;
import org.apache.cloudstack.api.user.securitygroup.command.ListSecurityGroupsCmd;
import org.apache.cloudstack.api.user.tag.command.ListTagsCmd;
import org.apache.cloudstack.api.user.vm.command.ListVMsCmd;
import com.cloud.acl.ControlledEntity;
import com.cloud.api.response.ApiResponseSerializer;
@ -137,7 +139,7 @@ public class ApiServer implements HttpRequestHandler {
private static final DateFormat _dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
@Inject(adapter = APIAccessChecker.class)
protected Adapters<APIAccessChecker> _apiAccessCheckers;
private static ExecutorService _executor = new ThreadPoolExecutor(10, 150, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("ApiServer"));
@ -191,7 +193,7 @@ public class ApiServer implements HttpRequestHandler {
if (apiPort != null) {
ListenerThread listenerThread = new ListenerThread(this, apiPort);
listenerThread.start();
}
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@ -246,7 +248,7 @@ public class ApiServer implements HttpRequestHandler {
writeResponse(response, responseText, HttpStatus.SC_OK, responseType, null);
} catch (ServerApiException se) {
String responseText = getSerializedApiError(se.getErrorCode(), se.getDescription(), parameterMap, responseType, se);
String responseText = getSerializedApiError(se.getErrorCode(), se.getDescription(), parameterMap, responseType, se);
writeResponse(response, responseText, se.getErrorCode(), responseType, se.getDescription());
sb.append(" " + se.getErrorCode() + " " + se.getDescription());
} catch (RuntimeException e) {
@ -325,7 +327,7 @@ public class ApiServer implements HttpRequestHandler {
} catch (Exception ex) {
if (ex instanceof InvalidParameterValueException) {
InvalidParameterValueException ref = (InvalidParameterValueException)ex;
ServerApiException e = new ServerApiException(BaseCmd.PARAM_ERROR, ex.getMessage());
ServerApiException e = new ServerApiException(BaseCmd.PARAM_ERROR, ex.getMessage());
// copy over the IdentityProxy information as well and throw the serverapiexception.
ArrayList<IdentityProxy> idList = ref.getIdProxyList();
if (idList != null) {
@ -380,11 +382,11 @@ public class ApiServer implements HttpRequestHandler {
} else {
List<ControlledEntity> entitiesToAccess = new ArrayList<ControlledEntity>();
ApiDispatcher.setupParameters(cmdObj, params, entitiesToAccess);
if(!entitiesToAccess.isEmpty()){
Account owner = s_instance._accountMgr.getActiveAccountById(cmdObj.getEntityOwnerId());
s_instance._accountMgr.checkAccess(caller, null, true, owner);
s_instance._accountMgr.checkAccess(caller, null, true, (ControlledEntity[])entitiesToAccess.toArray());
}
}
@ -402,7 +404,7 @@ public class ApiServer implements HttpRequestHandler {
asyncCmd.setStartEventId(startEventId);
// save the scheduled event
Long eventId = EventUtils.saveScheduledEvent((callerUserId == null) ? User.UID_SYSTEM : callerUserId,
Long eventId = EventUtils.saveScheduledEvent((callerUserId == null) ? User.UID_SYSTEM : callerUserId,
asyncCmd.getEntityOwnerId(), asyncCmd.getEventType(), asyncCmd.getEventDescription(),
startEventId);
if (startEventId == 0) {
@ -414,8 +416,8 @@ public class ApiServer implements HttpRequestHandler {
ctx.setAccountId(asyncCmd.getEntityOwnerId());
Long instanceId = (objectId == null) ? asyncCmd.getInstanceId() : objectId;
AsyncJobVO job = new AsyncJobVO(callerUserId, caller.getId(), cmdObj.getClass().getName(),
Long instanceId = (objectId == null) ? asyncCmd.getInstanceId() : objectId;
AsyncJobVO job = new AsyncJobVO(callerUserId, caller.getId(), cmdObj.getClass().getName(),
ApiGsonHelper.getBuilder().create().toJson(params), instanceId, asyncCmd.getInstanceType());
long jobId = _asyncMgr.submitAsyncJob(job);
@ -439,7 +441,9 @@ public class ApiServer implements HttpRequestHandler {
// if the command is of the listXXXCommand, we will need to also return the
// the job id and status if possible
if (cmdObj instanceof BaseListCmd && !(cmdObj instanceof ListVMsCmd) && !(cmdObj instanceof ListRoutersCmd)
&& !(cmdObj instanceof ListSecurityGroupsCmd)) {
&& !(cmdObj instanceof ListSecurityGroupsCmd)
&& !(cmdObj instanceof ListTagsCmd)
&& !(cmdObj instanceof ListEventsCmd)) {
buildAsyncListResponse((BaseListCmd) cmdObj, caller);
}
@ -653,7 +657,7 @@ public class ApiServer implements HttpRequestHandler {
}
return false;
}
public Long fetchDomainId(String domainUUID){
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
IdentityDao identityDao = locator.getDao(IdentityDao.class);
@ -704,19 +708,19 @@ public class ApiServer implements HttpRequestHandler {
if(user.getUuid() != null){
session.setAttribute("user_UUID", user.getUuid());
}
session.setAttribute("username", userAcct.getUsername());
session.setAttribute("firstname", userAcct.getFirstname());
session.setAttribute("lastname", userAcct.getLastname());
session.setAttribute("accountobj", account);
session.setAttribute("account", account.getAccountName());
session.setAttribute("domainid", account.getDomainId());
DomainVO domain = (DomainVO) _domainMgr.getDomain(account.getDomainId());
if(domain.getUuid() != null){
session.setAttribute("domain_UUID", domain.getUuid());
}
session.setAttribute("type", Short.valueOf(account.getType()).toString());
session.setAttribute("registrationtoken", userAcct.getRegistrationToken());
session.setAttribute("registered", new Boolean(userAcct.isRegistered()).toString());
@ -760,14 +764,14 @@ public class ApiServer implements HttpRequestHandler {
private boolean isCommandAvailable(User user, String commandName) {
boolean isCommandAvailable = false;
for(APIAccessChecker apichecker : _apiAccessCheckers){
isCommandAvailable = apichecker.canAccessAPI(user, commandName);
}
return isCommandAvailable;
}
// FIXME: rather than isError, we might was to pass in the status code to give more flexibility
private void writeResponse(HttpResponse resp, final String responseText, final int statusCode, String responseType, String reasonPhrase) {
try {
@ -942,7 +946,7 @@ public class ApiServer implements HttpRequestHandler {
for (int i=0; i < idList.size(); i++) {
IdentityProxy id = idList.get(i);
apiResponse.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
}
}
}
// Also copy over the cserror code and the function/layer in which it was thrown.
apiResponse.setCSErrorCode(ref.getCSErrorCode());
@ -953,7 +957,7 @@ public class ApiServer implements HttpRequestHandler {
for (int i=0; i < idList.size(); i++) {
IdentityProxy id = idList.get(i);
apiResponse.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
}
}
}
// Also copy over the cserror code and the function/layer in which it was thrown.
apiResponse.setCSErrorCode(ref.getCSErrorCode());
@ -964,7 +968,7 @@ public class ApiServer implements HttpRequestHandler {
for (int i=0; i < idList.size(); i++) {
IdentityProxy id = idList.get(i);
apiResponse.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
}
}
}
// Also copy over the cserror code and the function/layer in which it was thrown.
apiResponse.setCSErrorCode(ref.getCSErrorCode());
@ -975,7 +979,7 @@ public class ApiServer implements HttpRequestHandler {
responseText = ApiResponseSerializer.toSerializedString(apiResponse, responseType);
} catch (Exception e) {
s_logger.error("Exception responding to http request", e);
s_logger.error("Exception responding to http request", e);
}
return responseText;
}

View File

@ -5,7 +5,7 @@
// 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,
@ -209,6 +209,7 @@ import com.cloud.vm.dao.UserVmDaoImpl;
import com.cloud.vm.dao.UserVmJoinDaoImpl;
import com.cloud.vm.dao.UserVmDetailsDaoImpl;
import com.cloud.vm.dao.VMInstanceDaoImpl;
import com.cloud.event.dao.EventJoinDaoImpl;
public class DefaultComponentLibrary extends ComponentLibraryBase implements ComponentLibrary {
@ -224,6 +225,7 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com
addDao("DomainRouterJoinDao", DomainRouterJoinDaoImpl.class);
addDao("SecurityGroupJoinDao", SecurityGroupJoinDaoImpl.class);
addDao("ResourceTagJoinDao", ResourceTagJoinDaoImpl.class);
addDao("EventJoinDao", EventJoinDaoImpl.class);
ComponentInfo<? extends GenericDao<?, ? extends Serializable>> info = addDao("ServiceOfferingDao", ServiceOfferingDaoImpl.class);
info.addParameter("cache.size", "50");
info.addParameter("cache.time.to.live", "600");

View File

@ -0,0 +1,40 @@
// 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.event.dao;
import java.util.List;
import com.cloud.api.response.EventResponse;
import com.cloud.api.view.vo.EventJoinVO;
import com.cloud.event.Event;
import com.cloud.event.EventVO;
import com.cloud.utils.db.Filter;
import com.cloud.utils.db.GenericDao;
import com.cloud.utils.db.SearchCriteria;
public interface EventJoinDao extends GenericDao<EventJoinVO, Long> {
EventResponse newEventResponse(EventJoinVO uvo);
EventJoinVO newEventView(Event vr);
List<EventJoinVO> searchByIds(Long... ids);
List<EventJoinVO> searchAllEvents(SearchCriteria<EventJoinVO> sc, Filter filter);
EventJoinVO findCompletedEvent(long startId);
}

View File

@ -0,0 +1,155 @@
// 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.event.dao;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.List;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.ApiResponseHelper;
import com.cloud.api.response.DomainRouterResponse;
import com.cloud.api.response.EventResponse;
import com.cloud.api.response.NicResponse;
import com.cloud.api.response.ResourceTagResponse;
import com.cloud.api.response.SecurityGroupResponse;
import com.cloud.api.response.UserVmResponse;
import com.cloud.api.view.vo.DomainRouterJoinVO;
import com.cloud.api.view.vo.EventJoinVO;
import com.cloud.api.view.vo.ResourceTagJoinVO;
import com.cloud.dc.DataCenter;
import com.cloud.event.Event;
import com.cloud.event.EventVO;
import com.cloud.event.Event.State;
import com.cloud.network.Network;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.router.VirtualRouter;
import com.cloud.offering.ServiceOffering;
import com.cloud.projects.Project;
import com.cloud.server.ResourceTag;
import com.cloud.user.Account;
import com.cloud.user.User;
import com.cloud.uservm.UserVm;
import com.cloud.utils.Pair;
import com.cloud.utils.db.Attribute;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Filter;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.JoinBuilder;
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.vm.NicProfile;
@Local(value={EventJoinDao.class})
public class EventJoinDaoImpl extends GenericDaoBase<EventJoinVO, Long> implements EventJoinDao {
public static final Logger s_logger = Logger.getLogger(EventJoinDaoImpl.class);
private SearchBuilder<EventJoinVO> vrSearch;
private SearchBuilder<EventJoinVO> vrIdSearch;
private SearchBuilder<EventJoinVO> CompletedEventSearch;
protected EventJoinDaoImpl() {
vrSearch = createSearchBuilder();
vrSearch.and("idIN", vrSearch.entity().getId(), SearchCriteria.Op.IN);
vrSearch.done();
vrIdSearch = createSearchBuilder();
vrIdSearch.and("id", vrIdSearch.entity().getId(), SearchCriteria.Op.EQ);
vrIdSearch.done();
CompletedEventSearch = createSearchBuilder();
CompletedEventSearch.and("state",CompletedEventSearch.entity().getState(),SearchCriteria.Op.EQ);
CompletedEventSearch.and("startId", CompletedEventSearch.entity().getStartId(), SearchCriteria.Op.EQ);
CompletedEventSearch.done();
this._count = "select count(distinct id) from event_view WHERE ";
}
@Override
public List<EventJoinVO> searchAllEvents(SearchCriteria<EventJoinVO> sc, Filter filter) {
return listIncludingRemovedBy(sc, filter);
}
@Override
public EventJoinVO findCompletedEvent(long startId) {
SearchCriteria<EventJoinVO> sc = CompletedEventSearch.create();
sc.setParameters("state", State.Completed);
sc.setParameters("startId", startId);
return findOneIncludingRemovedBy(sc);
}
@Override
public EventResponse newEventResponse(EventJoinVO event) {
EventResponse responseEvent = new EventResponse();
responseEvent.setCreated(event.getCreateDate());
responseEvent.setDescription(event.getDescription());
responseEvent.setEventType(event.getType());
responseEvent.setId(event.getUuid());
responseEvent.setLevel(event.getLevel());
responseEvent.setParentId(event.getStartUuid());
responseEvent.setState(event.getState());
responseEvent.setUsername(event.getUserName());
ApiResponseHelper.populateOwner(responseEvent, event);
responseEvent.setObjectName("event");
return responseEvent;
}
@Override
public List<EventJoinVO> searchByIds(Long... ids) {
SearchCriteria<EventJoinVO> sc = vrSearch.create();
sc.setParameters("idIN", ids);
return searchIncludingRemoved(sc, null, null, false);
}
@Override
public EventJoinVO newEventView(Event vr) {
List<EventJoinVO> uvList = new ArrayList<EventJoinVO>();
SearchCriteria<EventJoinVO> sc = vrIdSearch.create();
sc.setParameters("id", vr.getId());
List<EventJoinVO> vms = searchIncludingRemoved(sc, null, null, false);
assert vms != null && vms.size() == 1 : "No event found for event id " + vr.getId();
return vms.get(0);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -77,10 +77,10 @@ import com.cloud.vm.dao.UserVmDao;
public class TaggedResourceManagerImpl implements TaggedResourceService, Manager{
public static final Logger s_logger = Logger.getLogger(TaggedResourceManagerImpl.class);
private String _name;
private static Map<TaggedResourceType, GenericDao<?, Long>> _daoMap=
private static Map<TaggedResourceType, GenericDao<?, Long>> _daoMap=
new HashMap<TaggedResourceType, GenericDao<?, Long>>();
@Inject
AccountManager _accountMgr;
@Inject
@ -122,7 +122,7 @@ public class TaggedResourceManagerImpl implements TaggedResourceService, Manager
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
_name = name;
_daoMap.put(TaggedResourceType.UserVm, _userVmDao);
_daoMap.put(TaggedResourceType.Volume, _volumeDao);
_daoMap.put(TaggedResourceType.Template, _templateDao);
@ -157,16 +157,16 @@ public class TaggedResourceManagerImpl implements TaggedResourceService, Manager
return _name;
}
private Long getResourceId(String resourceId, TaggedResourceType resourceType) {
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;
while (claz != null && claz != Object.class) {
try {
String tableName = DbUtil.getTableName(claz);
@ -182,7 +182,7 @@ public class TaggedResourceManagerImpl implements TaggedResourceService, Manager
}
claz = claz.getSuperclass();
}
if (identityId == null) {
throw new InvalidParameterValueException("Unable to find resource by id " + resourceId + " and type " + resourceType);
}
@ -194,9 +194,9 @@ public class TaggedResourceManagerImpl implements TaggedResourceService, Manager
Class<?> claz = DbUtil.getEntityBeanType(dao);
return DbUtil.getTableName(claz);
}
private Pair<Long, Long> getAccountDomain(long resourceId, TaggedResourceType resourceType) {
Pair<Long, Long> pair = null;
GenericDao<?, Long> dao = _daoMap.get(resourceType);
Class<?> claz = DbUtil.getEntityBeanType(dao);
@ -218,21 +218,21 @@ public class TaggedResourceManagerImpl implements TaggedResourceService, Manager
Long accountId = pair.first();
Long domainId = pair.second();
if (accountId == null) {
accountId = Account.ACCOUNT_ID_SYSTEM;
}
if (domainId == null) {
domainId = Domain.ROOT_DOMAIN;
}
return new Pair<Long, Long>(accountId, domainId);
}
@Override
public TaggedResourceType getResourceType(String resourceTypeStr) {
for (TaggedResourceType type : ResourceTag.TaggedResourceType.values()) {
if (type.toString().equalsIgnoreCase(resourceTypeStr)) {
return type;
@ -244,26 +244,26 @@ public class TaggedResourceManagerImpl implements TaggedResourceService, Manager
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_TAGS_CREATE, eventDescription = "creating resource tags")
public List<ResourceTag> createTags(List<String> resourceIds, TaggedResourceType resourceType,
public List<ResourceTag> createTags(List<String> resourceIds, TaggedResourceType resourceType,
Map<String, String> tags, String customer) {
Account caller = UserContext.current().getCaller();
List<ResourceTag> resourceTags = new ArrayList<ResourceTag>(tags.size());
Transaction txn = Transaction.currentTxn();
txn.start();
for (String key : tags.keySet()) {
for (String resourceId : resourceIds) {
Long id = getResourceId(resourceId, resourceType);
String resourceUuid = getUuid(resourceId, resourceType);
//check if object exists
if (_daoMap.get(resourceType).findById(id) == null) {
throw new InvalidParameterValueException("Unable to find resource by id " + resourceId +
throw new InvalidParameterValueException("Unable to find resource by id " + resourceId +
" and type " + resourceType);
}
Pair<Long, Long> accountDomainPair = getAccountDomain(id, resourceType);
Long domainId = accountDomainPair.second();
Long accountId = accountDomainPair.first();
@ -276,53 +276,53 @@ public class TaggedResourceManagerImpl implements TaggedResourceService, Manager
throw new PermissionDeniedException("Account " + caller + " doesn't have permissions to create tags" +
" for resource " + key);
}
String value = tags.get(key);
if (value == null || value.isEmpty()) {
throw new InvalidParameterValueException("Value for the key " + key + " is either null or empty");
}
ResourceTagVO resourceTag = new ResourceTagVO(key, value, accountDomainPair.first(),
accountDomainPair.second(),
accountDomainPair.second(),
id, resourceType, customer, resourceUuid);
resourceTag = _resourceTagDao.persist(resourceTag);
resourceTags.add(resourceTag);
}
}
txn.commit();
return resourceTags;
}
@Override
public String getUuid(String resourceId, TaggedResourceType resourceType) {
GenericDao<?, Long> dao = _daoMap.get(resourceType);
Class<?> claz = DbUtil.getEntityBeanType(dao);
String identiyUUId = null;
while (claz != null && claz != Object.class) {
try {
String tableName = DbUtil.getTableName(claz);
if (tableName == null) {
throw new InvalidParameterValueException("Unable to find resource of type " + resourceType + " in the database");
}
claz = claz.getSuperclass();
if (claz == Object.class) {
identiyUUId = _identityDao.getIdentityUuid(tableName, resourceId);
}
}
} catch (Exception ex) {
//do nothing here, it might mean uuid field is missing and we have to search further
}
}
if (identiyUUId == null) {
return resourceId;
}
return identiyUUId;
}
@ -337,7 +337,7 @@ public class TaggedResourceManagerImpl implements TaggedResourceService, Manager
String customerName = cmd.getCustomer();
boolean listAll = cmd.listAll();
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject =
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject =
new Ternary<Long, Boolean, ListProjectResourcesCriteria>(cmd.getDomainId(), cmd.isRecursive(), null);
_accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(),
@ -388,7 +388,7 @@ public class TaggedResourceManagerImpl implements TaggedResourceService, Manager
}
Pair<List<ResourceTagJoinVO>, Integer> result = _resourceTagJoinDao.searchAndCount(sc, searchFilter);
return new Pair<List<ResourceTagJoinVO>, Integer> (result.first(), result.second());
return result;
}
@Override
@ -396,21 +396,21 @@ public class TaggedResourceManagerImpl implements TaggedResourceService, Manager
@ActionEvent(eventType = EventTypes.EVENT_TAGS_DELETE, eventDescription = "deleting resource tags")
public boolean deleteTags(List<String> resourceIds, TaggedResourceType resourceType, Map<String, String> tags) {
Account caller = UserContext.current().getCaller();
SearchBuilder<ResourceTagVO> sb = _resourceTagDao.createSearchBuilder();
sb.and().op("resourceId", sb.entity().getResourceId(), SearchCriteria.Op.IN);
sb.or("resourceUuid", sb.entity().getResourceUuid(), SearchCriteria.Op.IN);
sb.cp();
sb.and("resourceType", sb.entity().getResourceType(), SearchCriteria.Op.EQ);
SearchCriteria<ResourceTagVO> sc = sb.create();
sc.setParameters("resourceId", resourceIds.toArray());
sc.setParameters("resourceUuid", resourceIds.toArray());
sc.setParameters("resourceType", resourceType);
List<? extends ResourceTag> resourceTags = _resourceTagDao.search(sc, null);;
List<ResourceTag> tagsToRemove = new ArrayList<ResourceTag>();
// Finalize which tags should be removed
for (ResourceTag resourceTag : resourceTags) {
//1) validate the permissions
@ -434,16 +434,16 @@ public class TaggedResourceManagerImpl implements TaggedResourceService, Manager
break;
}
}
}
}
} else {
tagsToRemove.add(resourceTag);
}
}
if (tagsToRemove.isEmpty()) {
throw new InvalidParameterValueException("Unable to find tags by parameters specified");
}
//Remove the tags
Transaction txn = Transaction.currentTxn();
txn.start();

View File

@ -94,13 +94,7 @@ public class ResourceTagJoinDaoImpl extends GenericDaoBase<ResourceTagJoinVO, Lo
response.setResourceType(resourceTag.getResourceType().toString());
response.setResourceId(resourceTag.getResourceUuid());
if (resourceTag.getAccountType() == Account.ACCOUNT_TYPE_PROJECT) {
response.setProjectId(resourceTag.getProjectUuid());
response.setProjectName(resourceTag.getProjectName());
} else {
response.setAccountName(resourceTag.getAccountName());
}
ApiResponseHelper.populateOwner(response, resourceTag);
response.setDomainId(resourceTag.getDomainUuid());
response.setDomainName(resourceTag.getDomainName());

View File

@ -2802,3 +2802,36 @@ inner join account on resource_tags.account_id=account.id
inner join domain on resource_tags.domain_id=domain.id
left join projects on projects.project_account_id = resource_tags.account_id;
DROP VIEW IF EXISTS `cloud`.`event_view`;
CREATE VIEW event_view AS
select
event.id,
event.uuid,
event.type,
event.state,
event.description,
event.created,
event.level,
event.parameters,
event.start_id,
eve.uuid start_uuid,
event.user_id,
user.username user_name,
account.id account_id,
account.uuid account_uuid,
account.account_name account_name,
account.type account_type,
domain.id domain_id,
domain.uuid domain_uuid,
domain.name domain_name,
domain.path domain_path,
projects.id project_id,
projects.uuid project_uuid,
projects.name project_name
from event
inner join account on event.account_id=account.id
inner join domain on event.domain_id=domain.id
inner join user on event.user_id = user.id
left join projects on projects.project_account_id = event.account_id
left join event eve on event.start_id = eve.id;