Skip to content

Commit

Permalink
Move view based VO and Dao classes to cloud-server module to hide the
Browse files Browse the repository at this point in the history
details from API client, also extract query related methods into
QueryService interface.
  • Loading branch information
minchen07 committed Dec 14, 2012
1 parent 88b7af1 commit c167ad4
Show file tree
Hide file tree
Showing 71 changed files with 1,848 additions and 1,665 deletions.
10 changes: 1 addition & 9 deletions api/src/com/cloud/network/security/SecurityGroupService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import java.util.List;

import org.apache.cloudstack.api.command.user.securitygroup.*;
import org.apache.cloudstack.api.command.user.securitygroup.AuthorizeSecurityGroupIngressCmd;

import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.exception.ResourceInUseException;
import org.apache.cloudstack.api.view.vo.SecurityGroupJoinVO;
import com.cloud.utils.Pair;

public interface SecurityGroupService {
/**
Expand All @@ -38,12 +36,6 @@ public interface SecurityGroupService {

boolean deleteSecurityGroup(DeleteSecurityGroupCmd cmd) throws ResourceInUseException;

/**
* Search for security groups and associated ingress rules for the given account, domain, group name, and/or keyword.
* The search terms are specified in the search criteria.
* @return the list of security groups and associated ingress rules
*/
public Pair<List<SecurityGroupJoinVO>, Integer> searchForSecurityGroupRules(ListSecurityGroupsCmd cmd) throws PermissionDeniedException, InvalidParameterValueException;

public List<? extends SecurityRule> authorizeSecurityGroupIngress(AuthorizeSecurityGroupIngressCmd cmd);

Expand Down
14 changes: 0 additions & 14 deletions api/src/com/cloud/projects/ProjectService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,11 @@
// under the License.
package com.cloud.projects;

import java.util.List;
import java.util.Map;

import org.apache.cloudstack.api.view.vo.ProjectAccountJoinVO;
import org.apache.cloudstack.api.view.vo.ProjectInvitationJoinVO;
import org.apache.cloudstack.api.view.vo.ProjectJoinVO;

import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.projects.ProjectAccount.Role;
import com.cloud.user.Account;
import com.cloud.utils.Pair;

public interface ProjectService {
/**
Expand Down Expand Up @@ -65,9 +57,6 @@ public interface ProjectService {
*/
Project getProject(long id);

Pair<List<ProjectJoinVO>, Integer> 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);

Account getProjectOwner(long projectId);
Expand All @@ -84,10 +73,7 @@ Pair<List<ProjectJoinVO>, Integer> listProjects(Long id, String name, String dis

boolean deleteAccountFromProject(long projectId, String accountName);

Pair<List<ProjectAccountJoinVO>, Integer> listProjectAccounts(long projectId, String accountName, String role, Long startIndex, Long pageSizeVal);

Pair<List<ProjectInvitationJoinVO>, Integer> listProjectInvitations(Long id, Long projectId, String accountName, Long domainId, String state, boolean activeOnly, Long startIndex, Long pageSizeVal, boolean isRecursive,
boolean listAll);

boolean updateInvitation(long projectId, String accountName, String token, boolean accept);

Expand Down
22 changes: 0 additions & 22 deletions api/src/com/cloud/server/ManagementService.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@
import org.apache.cloudstack.api.command.user.vmgroup.UpdateVMGroupCmd;
import org.apache.cloudstack.api.command.admin.systemvm.UpgradeSystemVMCmd;
import org.apache.cloudstack.api.command.admin.resource.UploadCustomCertificateCmd;
import org.apache.cloudstack.api.view.vo.DomainRouterJoinVO;
import org.apache.cloudstack.api.view.vo.EventJoinVO;
import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO;

import com.cloud.async.AsyncJob;
import com.cloud.capacity.Capacity;
Expand Down Expand Up @@ -168,25 +165,7 @@ public interface ManagementService {

VirtualMachineTemplate updateTemplate(UpdateTemplateCmd cmd);

/**
* Obtains a list of events by the specified search criteria. Can search by: "username", "type", "level",
* "startDate",
* "endDate"
*
* @param c
* @return List of Events.
*/
Pair<List<EventJoinVO>, Integer> searchForEvents(ListEventsCmd c);

/**
* Obtains a list of routers by the specified search criteria. Can search by: "userId", "name", "state",
* "dataCenterId",
* "podId", "hostId"
*
* @param cmd
* @return List of DomainRouters.
*/
Pair<List<DomainRouterJoinVO>, Integer> searchForRouters(ListRoutersCmd cmd);

/**
* Obtains a list of IP Addresses by the specified search criteria. Can search by: "userId", "dataCenterId",
Expand Down Expand Up @@ -309,7 +288,6 @@ public interface ManagementService {

InstanceGroup updateVmGroup(UpdateVMGroupCmd cmd);

Pair<List<InstanceGroupJoinVO>, Integer> searchForVmGroups(ListVMGroupsCmd cmd);

Map<String, Object> listCapabilities(ListCapabilitiesCmd cmd);

Expand Down
9 changes: 0 additions & 9 deletions api/src/com/cloud/server/TaggedResourceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
import java.util.List;
import java.util.Map;

import org.apache.cloudstack.api.command.user.tag.ListTagsCmd;

import org.apache.cloudstack.api.view.vo.ResourceTagJoinVO;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.utils.Pair;

public interface TaggedResourceService {

Expand All @@ -45,11 +41,6 @@ public interface TaggedResourceService {
*/
String getUuid(String resourceId, TaggedResourceType resourceType);

/**
* @param listTagsCmd
* @return
*/
Pair<List<ResourceTagJoinVO>, Integer> listTags(ListTagsCmd listTagsCmd);

/**
* @param resourceIds
Expand Down
6 changes: 2 additions & 4 deletions api/src/com/cloud/user/AccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@

import com.cloud.acl.ControlledEntity;
import com.cloud.acl.SecurityChecker.AccessType;

import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd;
import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
import org.apache.cloudstack.api.view.vo.UserAccountJoinVO;

import com.cloud.domain.Domain;
import com.cloud.exception.ConcurrentOperationException;
Expand Down Expand Up @@ -195,8 +194,7 @@ UserAccount createUserAccount(String userName, String password, String firstName

Pair<List<? extends Account>, Integer> searchForAccounts(ListAccountsCmd cmd);

Pair<List<UserAccountJoinVO>, Integer> searchForUsers(ListUsersCmd cmd)
throws PermissionDeniedException;


UserAccount getUserByApiKey(String apiKey);

Expand Down
13 changes: 1 addition & 12 deletions api/src/com/cloud/vm/UserVmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@
import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
import org.apache.cloudstack.api.command.user.vm.DestroyVMCmd;
import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd;
import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
import org.apache.cloudstack.api.command.user.vm.RebootVMCmd;
import org.apache.cloudstack.api.command.admin.vm.RecoverVMCmd;
import org.apache.cloudstack.api.command.user.vm.ResetVMPasswordCmd;
import org.apache.cloudstack.api.command.user.vm.RestoreVMCmd;
import org.apache.cloudstack.api.command.user.vm.UpgradeVMCmd;
import org.apache.cloudstack.api.view.vo.UserVmJoinVO;

import com.cloud.dc.DataCenter;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
Expand All @@ -53,7 +52,6 @@
import com.cloud.template.VirtualMachineTemplate;
import com.cloud.user.Account;
import com.cloud.uservm.UserVm;
import com.cloud.utils.Pair;
import com.cloud.utils.exception.ExecutionException;

public interface UserVmService {
Expand Down Expand Up @@ -371,15 +369,6 @@ UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serviceOffe

void deletePrivateTemplateRecord(Long templateId);

/**
* Obtains a list of virtual machines by the specified search criteria. Can search by: "userId", "name", "state",
* "dataCenterId", "podId", "hostId"
*
* @param cmd
* the API command that wraps the search criteria
* @return List of UserVMs.
*/
Pair<List<UserVmJoinVO>, Integer> searchForUserVMs(ListVMsCmd cmd);

HypervisorType getHypervisorTypeOfUserVM(long vmid);

Expand Down
4 changes: 4 additions & 0 deletions api/src/org/apache/cloudstack/api/BaseCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Map;
import java.util.regex.Pattern;

import org.apache.cloudstack.query.QueryService;
import org.apache.log4j.Logger;

import com.cloud.configuration.ConfigurationService;
Expand Down Expand Up @@ -141,6 +142,8 @@ public enum CommandType {
public static NetworkACLService _networkACLService;
public static Site2SiteVpnService _s2sVpnService;

public static QueryService _queryService;

public static void setComponents(ResponseGenerator generator) {
ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
_mgr = (ManagementService) ComponentLocator.getComponent(ManagementService.Name);
Expand Down Expand Up @@ -172,6 +175,7 @@ public static void setComponents(ResponseGenerator generator) {
_vpcService = locator.getManager(VpcService.class);
_networkACLService = locator.getManager(NetworkACLService.class);
_s2sVpnService = locator.getManager(Site2SiteVpnService.class);
_queryService = locator.getManager(QueryService.class);
}

public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException;
Expand Down
34 changes: 4 additions & 30 deletions api/src/org/apache/cloudstack/api/ResponseGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
import org.apache.cloudstack.api.response.VpcResponse;
import org.apache.cloudstack.api.response.VpnUsersResponse;
import org.apache.cloudstack.api.response.ZoneResponse;


import com.cloud.async.AsyncJob;
import com.cloud.capacity.Capacity;
import com.cloud.configuration.Configuration;
Expand Down Expand Up @@ -150,16 +152,6 @@
import com.cloud.user.UserAccount;
import com.cloud.uservm.UserVm;
import com.cloud.vm.InstanceGroup;
import org.apache.cloudstack.api.view.vo.DomainRouterJoinVO;
import org.apache.cloudstack.api.view.vo.EventJoinVO;
import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO;
import org.apache.cloudstack.api.view.vo.ProjectAccountJoinVO;
import org.apache.cloudstack.api.view.vo.ProjectInvitationJoinVO;
import org.apache.cloudstack.api.view.vo.ProjectJoinVO;
import org.apache.cloudstack.api.view.vo.ResourceTagJoinVO;
import org.apache.cloudstack.api.view.vo.SecurityGroupJoinVO;
import org.apache.cloudstack.api.view.vo.UserAccountJoinVO;
import org.apache.cloudstack.api.view.vo.UserVmJoinVO;
import com.cloud.vm.VirtualMachine;

public interface ResponseGenerator {
Expand All @@ -183,10 +175,6 @@ public interface ResponseGenerator {

SnapshotPolicyResponse createSnapshotPolicyResponse(SnapshotPolicy policy);

List<UserVmResponse> createUserVmResponse(String objectName, UserVmJoinVO... userVms);

List<UserVmResponse> createUserVmResponse(String objectName, EnumSet<VMDetails> details, UserVmJoinVO... userVms);

List<UserVmResponse> createUserVmResponse(String objectName, UserVm... userVms);

List<UserVmResponse> createUserVmResponse(String objectName, EnumSet<VMDetails> details, UserVm... userVms);
Expand All @@ -195,8 +183,6 @@ public interface ResponseGenerator {

DomainRouterResponse createDomainRouterResponse(VirtualRouter router);

List<DomainRouterResponse> createDomainRouterResponse(DomainRouterJoinVO... router);

HostResponse createHostResponse(Host host, EnumSet<HostDetails> details);

HostResponse createHostResponse(Host host);
Expand All @@ -219,8 +205,6 @@ public interface ResponseGenerator {

InstanceGroupResponse createInstanceGroupResponse(InstanceGroup group);

List<InstanceGroupResponse> createInstanceGroupResponse(InstanceGroupJoinVO... groups);

StoragePoolResponse createStoragePoolResponse(StoragePool pool);

ClusterResponse createClusterResponse(Cluster cluster, Boolean showCapacities);
Expand Down Expand Up @@ -253,9 +237,6 @@ public interface ResponseGenerator {

//ListResponse<SecurityGroupResponse> createSecurityGroupResponses(List<? extends SecurityGroupRules> networkGroups);

List<SecurityGroupResponse> createSecurityGroupResponses(List<SecurityGroupJoinVO> securityGroups);


SecurityGroupResponse createSecurityGroupResponseFromSecurityGroupRule(List<? extends SecurityRule> SecurityRules);

SecurityGroupResponse createSecurityGroupResponse(SecurityGroup group);
Expand All @@ -268,7 +249,7 @@ public interface ResponseGenerator {

EventResponse createEventResponse(Event event);

List<EventResponse> createEventResponse(EventJoinVO... events);
//List<EventResponse> createEventResponse(EventJoinVO... events);

TemplateResponse createIsoResponse(VirtualMachineTemplate result);

Expand All @@ -284,7 +265,7 @@ public interface ResponseGenerator {

UserResponse createUserResponse(User user);

List<UserResponse> createUserResponse(UserAccountJoinVO... users);
//List<UserResponse> createUserResponse(UserAccountJoinVO... users);

AccountResponse createUserAccountResponse(UserAccount user);

Expand All @@ -294,7 +275,6 @@ public interface ResponseGenerator {

ProjectResponse createProjectResponse(Project project);

List<ProjectResponse> createProjectResponse(ProjectJoinVO... projects);

List<TemplateResponse> createIsoResponses(VirtualMachineTemplate iso, long zoneId, boolean readyOnly);

Expand All @@ -306,12 +286,8 @@ public interface ResponseGenerator {

ProjectAccountResponse createProjectAccountResponse(ProjectAccount projectAccount);

List<ProjectAccountResponse> createProjectAccountResponse(ProjectAccountJoinVO... projectAccounts);

ProjectInvitationResponse createProjectInvitationResponse(ProjectInvitation invite);

List<ProjectInvitationResponse> createProjectInvitationResponse(ProjectInvitationJoinVO... invites);

SystemVmInstanceResponse createSystemVmInstanceResponse(VirtualMachine systemVM);

SwiftResponse createSwiftResponse(Swift swift);
Expand Down Expand Up @@ -344,8 +320,6 @@ public interface ResponseGenerator {
*/
ResourceTagResponse createResourceTagResponse(ResourceTag resourceTag, boolean keyValueOnly);

List<ResourceTagResponse> createResourceTagResponse(boolean keyValueOnly, ResourceTagJoinVO... resourceTag);


Site2SiteVpnGatewayResponse createSite2SiteVpnGatewayResponse(Site2SiteVpnGateway result);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
// under the License.
package org.apache.cloudstack.api.command.admin.router;

import java.util.List;

import org.apache.log4j.Logger;

import org.apache.cloudstack.api.ApiConstants;
Expand All @@ -26,12 +24,11 @@
import org.apache.cloudstack.api.Implementation;
import org.apache.cloudstack.api.Parameter;

import org.apache.cloudstack.api.view.vo.DomainRouterJoinVO;

import org.apache.cloudstack.api.response.DomainRouterResponse;
import org.apache.cloudstack.api.response.ListResponse;

import com.cloud.async.AsyncJob;
import com.cloud.utils.Pair;

@Implementation(description="List routers.", responseObject=DomainRouterResponse.class)
public class ListRoutersCmd extends BaseListProjectAndAccountResourcesCmd {
Expand Down Expand Up @@ -125,17 +122,14 @@ public String getCommandName() {
return s_name;
}

@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.DomainRouter;
}

@Override
public void execute(){
Pair<List<DomainRouterJoinVO>, Integer> result = _mgr.searchForRouters(this);
ListResponse<DomainRouterResponse> response = new ListResponse<DomainRouterResponse>();

List<DomainRouterResponse> routerResponses = _responseGenerator.createDomainRouterResponse(result.first().toArray(new DomainRouterJoinVO[result.first().size()]));
response.setResponses(routerResponses, result.second());
ListResponse<DomainRouterResponse> response = _queryService.searchForRouters(this);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
Expand Down
Loading

0 comments on commit c167ad4

Please sign in to comment.