mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Code format fixes
This commit is contained in:
parent
4c05adaac0
commit
294d3a2fda
@ -35,32 +35,32 @@ import com.cloud.projects.Project;
|
|||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.user.UserContext;
|
import com.cloud.user.UserContext;
|
||||||
|
|
||||||
@Implementation(description="Creates a project", responseObject=ProjectResponse.class, since="3.0.0")
|
@Implementation(description = "Creates a project", responseObject = ProjectResponse.class, since = "3.0.0")
|
||||||
public class CreateProjectCmd extends BaseAsyncCreateCmd {
|
public class CreateProjectCmd extends BaseAsyncCreateCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(CreateProjectCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(CreateProjectCmd.class.getName());
|
||||||
|
|
||||||
private static final String s_name = "createprojectresponse";
|
private static final String s_name = "createprojectresponse";
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
//////////////// API parameters /////////////////////
|
// ////////////// API parameters /////////////////////
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
|
|
||||||
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="account who will be Admin for the project")
|
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "account who will be Admin for the project")
|
||||||
private String accountName;
|
private String accountName;
|
||||||
|
|
||||||
@IdentityMapper(entityTableName="domain")
|
@IdentityMapper(entityTableName = "domain")
|
||||||
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a project")
|
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.LONG, description = "domain ID of the account owning a project")
|
||||||
private Long domainId;
|
private Long domainId;
|
||||||
|
|
||||||
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="name of the project")
|
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "name of the project")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="display text of the project")
|
@Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, required = true, description = "display text of the project")
|
||||||
private String displayText;
|
private String displayText;
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
/////////////////// Accessors ///////////////////////
|
// ///////////////// Accessors ///////////////////////
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
|
|
||||||
public String getEntityTable() {
|
public String getEntityTable() {
|
||||||
return "projects";
|
return "projects";
|
||||||
@ -111,13 +111,12 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd {
|
|||||||
return caller.getId();
|
return caller.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ///////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////
|
// ///////////// API Implementation///////////////////
|
||||||
/////////////// API Implementation///////////////////
|
// ///////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(){
|
public void execute() {
|
||||||
Project project = _projectService.enableProject(this.getEntityId());
|
Project project = _projectService.enableProject(this.getEntityId());
|
||||||
if (project != null) {
|
if (project != null) {
|
||||||
ProjectResponse response = _responseGenerator.createProjectResponse(project);
|
ProjectResponse response = _responseGenerator.createProjectResponse(project);
|
||||||
@ -129,8 +128,8 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create() throws ResourceAllocationException{
|
public void create() throws ResourceAllocationException {
|
||||||
UserContext.current().setEventDetails("Project Name: "+ getName());
|
UserContext.current().setEventDetails("Project Name: " + getName());
|
||||||
Project project = _projectService.createProject(getName(), getDisplayText(), getAccountName(), getDomainId());
|
Project project = _projectService.createProject(getName(), getDisplayText(), getAccountName(), getDomainId());
|
||||||
if (project != null) {
|
if (project != null) {
|
||||||
this.setEntityId(project.getId());
|
this.setEntityId(project.getId());
|
||||||
@ -148,4 +147,5 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd {
|
|||||||
public String getEventDescription() {
|
public String getEventDescription() {
|
||||||
return "creating project";
|
return "creating project";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -31,21 +31,21 @@ import com.cloud.event.EventTypes;
|
|||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.user.UserContext;
|
import com.cloud.user.UserContext;
|
||||||
|
|
||||||
@Implementation(description="Accepts or declines project invitation", responseObject=SuccessResponse.class, since="3.0.0")
|
@Implementation(description = "Accepts or declines project invitation", responseObject = SuccessResponse.class, since = "3.0.0")
|
||||||
public class DeleteProjectInvitationCmd extends BaseAsyncCmd {
|
public class DeleteProjectInvitationCmd extends BaseAsyncCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(DeleteProjectInvitationCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(DeleteProjectInvitationCmd.class.getName());
|
||||||
private static final String s_name = "deleteprojectinvitationresponse";
|
private static final String s_name = "deleteprojectinvitationresponse";
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
//////////////// API parameters /////////////////////
|
// ////////////// API parameters /////////////////////
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
@IdentityMapper(entityTableName="project_invitations")
|
@IdentityMapper(entityTableName = "project_invitations")
|
||||||
@Parameter(name=ApiConstants.ID, required=true, type=CommandType.LONG, description="id of the invitation")
|
@Parameter(name = ApiConstants.ID, required = true, type = CommandType.LONG, description = "id of the invitation")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
/////////////////// Accessors ///////////////////////
|
// ///////////////// Accessors ///////////////////////
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -55,18 +55,18 @@ public class DeleteProjectInvitationCmd extends BaseAsyncCmd {
|
|||||||
return s_name;
|
return s_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
/////////////// API Implementation///////////////////
|
// ///////////// API Implementation///////////////////
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
@Override
|
@Override
|
||||||
public long getEntityOwnerId() {
|
public long getEntityOwnerId() {
|
||||||
//TODO - return project entity ownerId
|
// TODO - return project entity ownerId
|
||||||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
|
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are
|
||||||
|
// tracked
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(){
|
public void execute() {
|
||||||
UserContext.current().setEventDetails("Project invitation id " + id);
|
UserContext.current().setEventDetails("Project invitation id " + id);
|
||||||
boolean result = _projectService.deleteProjectInvitation(id);
|
boolean result = _projectService.deleteProjectInvitation(id);
|
||||||
if (result) {
|
if (result) {
|
||||||
@ -86,4 +86,5 @@ public class DeleteProjectInvitationCmd extends BaseAsyncCmd {
|
|||||||
public String getEventDescription() {
|
public String getEventDescription() {
|
||||||
return "Project invitatino id " + id + " is being removed";
|
return "Project invitatino id " + id + " is being removed";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,30 +31,31 @@ import com.cloud.api.response.ListResponse;
|
|||||||
import com.cloud.api.response.ProjectInvitationResponse;
|
import com.cloud.api.response.ProjectInvitationResponse;
|
||||||
import com.cloud.projects.ProjectInvitation;
|
import com.cloud.projects.ProjectInvitation;
|
||||||
|
|
||||||
@Implementation(description="Lists projects and provides detailed information for listed projects", responseObject=ProjectInvitationResponse.class, since="3.0.0")
|
@Implementation(description = "Lists projects and provides detailed information for listed projects", responseObject = ProjectInvitationResponse.class, since = "3.0.0")
|
||||||
public class ListProjectInvitationsCmd extends BaseListAccountResourcesCmd {
|
public class ListProjectInvitationsCmd extends BaseListAccountResourcesCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(ListProjectInvitationsCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(ListProjectInvitationsCmd.class.getName());
|
||||||
private static final String s_name = "listprojectinvitationsresponse";
|
private static final String s_name = "listprojectinvitationsresponse";
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
//////////////// API parameters /////////////////////
|
// ////////////// API parameters /////////////////////
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
@IdentityMapper(entityTableName="projects")
|
@IdentityMapper(entityTableName = "projects")
|
||||||
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="list by project id")
|
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.LONG, description = "list by project id")
|
||||||
private Long projectId;
|
private Long projectId;
|
||||||
|
|
||||||
@Parameter(name=ApiConstants.ACTIVE_ONLY, type=CommandType.BOOLEAN, description="if true, list only active invitations - having Pending state and ones that are not timed out yet")
|
@Parameter(name = ApiConstants.ACTIVE_ONLY, type = CommandType.BOOLEAN, description = "if true, list only active invitations - having Pending state and ones that are not timed out yet")
|
||||||
private boolean activeOnly;
|
private boolean activeOnly;
|
||||||
|
|
||||||
@Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="list invitations by state")
|
@Parameter(name = ApiConstants.STATE, type = CommandType.STRING, description = "list invitations by state")
|
||||||
private String state;
|
private String state;
|
||||||
|
|
||||||
@IdentityMapper(entityTableName="project_invitations")
|
@IdentityMapper(entityTableName = "project_invitations")
|
||||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list invitations by id")
|
@Parameter(name = ApiConstants.ID, type = CommandType.LONG, description = "list invitations by id")
|
||||||
private Long id;
|
private Long id;
|
||||||
/////////////////////////////////////////////////////
|
|
||||||
/////////////////// Accessors ///////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////// Accessors ///////////////////////
|
||||||
|
// ///////////////////////////////////////////////////
|
||||||
public Long getProjectId() {
|
public Long getProjectId() {
|
||||||
return projectId;
|
return projectId;
|
||||||
}
|
}
|
||||||
@ -76,13 +77,14 @@ public class ListProjectInvitationsCmd extends BaseListAccountResourcesCmd {
|
|||||||
return s_name;
|
return s_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
/////////////// API Implementation///////////////////
|
// ///////////// API Implementation///////////////////
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(){
|
public void execute() {
|
||||||
List<? extends ProjectInvitation> invites = _projectService.listProjectInvitations(id, projectId, this.getAccountName(), this.getDomainId(), state, activeOnly, this.getStartIndex(), this.getPageSizeVal(), this.isRecursive(), this.listAll());
|
List<? extends ProjectInvitation> invites = _projectService.listProjectInvitations(id, projectId, this.getAccountName(), this.getDomainId(), state, activeOnly, this.getStartIndex(), this.getPageSizeVal(),
|
||||||
|
this.isRecursive(), this.listAll());
|
||||||
ListResponse<ProjectInvitationResponse> response = new ListResponse<ProjectInvitationResponse>();
|
ListResponse<ProjectInvitationResponse> response = new ListResponse<ProjectInvitationResponse>();
|
||||||
List<ProjectInvitationResponse> projectInvitationResponses = new ArrayList<ProjectInvitationResponse>();
|
List<ProjectInvitationResponse> projectInvitationResponses = new ArrayList<ProjectInvitationResponse>();
|
||||||
for (ProjectInvitation invite : invites) {
|
for (ProjectInvitation invite : invites) {
|
||||||
@ -94,4 +96,5 @@ public class ListProjectInvitationsCmd extends BaseListAccountResourcesCmd {
|
|||||||
|
|
||||||
this.setResponseObject(response);
|
this.setResponseObject(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,31 +40,31 @@ import com.cloud.user.UserContext;
|
|||||||
import com.cloud.uservm.UserVm;
|
import com.cloud.uservm.UserVm;
|
||||||
import com.cloud.utils.exception.ExecutionException;
|
import com.cloud.utils.exception.ExecutionException;
|
||||||
|
|
||||||
@Implementation(responseObject=UserVmResponse.class, description="Starts a virtual machine.")
|
@Implementation(responseObject = UserVmResponse.class, description = "Starts a virtual machine.")
|
||||||
public class StartVMCmd extends BaseAsyncCmd {
|
public class StartVMCmd extends BaseAsyncCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(StartVMCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(StartVMCmd.class.getName());
|
||||||
|
|
||||||
private static final String s_name = "startvirtualmachineresponse";
|
private static final String s_name = "startvirtualmachineresponse";
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
//////////////// API parameters /////////////////////
|
// ////////////// API parameters /////////////////////
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
|
|
||||||
@IdentityMapper(entityTableName="vm_instance")
|
@IdentityMapper(entityTableName = "vm_instance")
|
||||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine")
|
@Parameter(name = ApiConstants.ID, type = CommandType.LONG, required = true, description = "The ID of the virtual machine")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
/////////////////// Accessors ///////////////////////
|
// ///////////////// Accessors ///////////////////////
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
/////////////// API Implementation///////////////////
|
// ///////////// API Implementation///////////////////
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCommandName() {
|
public String getCommandName() {
|
||||||
@ -82,7 +82,8 @@ public class StartVMCmd extends BaseAsyncCmd {
|
|||||||
return vm.getAccountId();
|
return vm.getAccountId();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
|
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are
|
||||||
|
// tracked
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -104,9 +105,9 @@ public class StartVMCmd extends BaseAsyncCmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException{
|
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException {
|
||||||
try {
|
try {
|
||||||
UserContext.current().setEventDetails("Vm Id: "+getId());
|
UserContext.current().setEventDetails("Vm Id: " + getId());
|
||||||
UserVm result;
|
UserVm result;
|
||||||
if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
|
if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
|
||||||
result = _bareMetalVmService.startVirtualMachine(this);
|
result = _bareMetalVmService.startVirtualMachine(this);
|
||||||
@ -114,22 +115,23 @@ public class StartVMCmd extends BaseAsyncCmd {
|
|||||||
result = _userVmService.startVirtualMachine(this);
|
result = _userVmService.startVirtualMachine(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result != null){
|
if (result != null) {
|
||||||
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
|
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
|
||||||
response.setResponseName(getCommandName());
|
response.setResponseName(getCommandName());
|
||||||
this.setResponseObject(response);
|
this.setResponseObject(response);
|
||||||
} else {
|
} else {
|
||||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to start a vm");
|
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to start a vm");
|
||||||
}
|
}
|
||||||
}catch (ConcurrentOperationException ex) {
|
} catch (ConcurrentOperationException ex) {
|
||||||
s_logger.warn("Exception: ", ex);
|
s_logger.warn("Exception: ", ex);
|
||||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
|
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
|
||||||
}catch (StorageUnavailableException ex) {
|
} catch (StorageUnavailableException ex) {
|
||||||
s_logger.warn("Exception: ", ex);
|
s_logger.warn("Exception: ", ex);
|
||||||
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
|
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
|
||||||
}catch (ExecutionException ex) {
|
} catch (ExecutionException ex) {
|
||||||
s_logger.warn("Exception: ", ex);
|
s_logger.warn("Exception: ", ex);
|
||||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
|
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,35 +35,34 @@ import com.cloud.user.Account;
|
|||||||
import com.cloud.user.UserContext;
|
import com.cloud.user.UserContext;
|
||||||
import com.cloud.uservm.UserVm;
|
import com.cloud.uservm.UserVm;
|
||||||
|
|
||||||
@Implementation(responseObject=UserVmResponse.class, description="Stops a virtual machine.")
|
@Implementation(responseObject = UserVmResponse.class, description = "Stops a virtual machine.")
|
||||||
public class StopVMCmd extends BaseAsyncCmd {
|
public class StopVMCmd extends BaseAsyncCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(StopVMCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(StopVMCmd.class.getName());
|
||||||
|
|
||||||
private static final String s_name = "stopvirtualmachineresponse";
|
private static final String s_name = "stopvirtualmachineresponse";
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
//////////////// API parameters /////////////////////
|
// ////////////// API parameters /////////////////////
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
|
|
||||||
@IdentityMapper(entityTableName="vm_instance")
|
@IdentityMapper(entityTableName = "vm_instance")
|
||||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine")
|
@Parameter(name = ApiConstants.ID, type = CommandType.LONG, required = true, description = "The ID of the virtual machine")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Parameter(name=ApiConstants.FORCED, type=CommandType.BOOLEAN, required=false, description="Force stop the VM. The caller knows the VM is stopped.")
|
@Parameter(name = ApiConstants.FORCED, type = CommandType.BOOLEAN, required = false, description = "Force stop the VM. The caller knows the VM is stopped.")
|
||||||
private Boolean forced;
|
private Boolean forced;
|
||||||
|
|
||||||
|
// ///////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////// Accessors ///////////////////////
|
||||||
/////////////////// Accessors ///////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
/////////////// API Implementation///////////////////
|
// ///////////// API Implementation///////////////////
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCommandName() {
|
public String getCommandName() {
|
||||||
@ -81,7 +80,8 @@ public class StopVMCmd extends BaseAsyncCmd {
|
|||||||
return vm.getAccountId();
|
return vm.getAccountId();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
|
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are
|
||||||
|
// tracked
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -109,8 +109,8 @@ public class StopVMCmd extends BaseAsyncCmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws ServerApiException, ConcurrentOperationException{
|
public void execute() throws ServerApiException, ConcurrentOperationException {
|
||||||
UserContext.current().setEventDetails("Vm Id: "+getId());
|
UserContext.current().setEventDetails("Vm Id: " + getId());
|
||||||
UserVm result;
|
UserVm result;
|
||||||
|
|
||||||
if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
|
if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
|
||||||
|
|||||||
@ -31,31 +31,30 @@ import com.cloud.event.EventTypes;
|
|||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.user.UserContext;
|
import com.cloud.user.UserContext;
|
||||||
|
|
||||||
@Implementation(description="Accepts or declines project invitation", responseObject=SuccessResponse.class, since="3.0.0")
|
@Implementation(description = "Accepts or declines project invitation", responseObject = SuccessResponse.class, since = "3.0.0")
|
||||||
public class UpdateProjectInvitationCmd extends BaseAsyncCmd {
|
public class UpdateProjectInvitationCmd extends BaseAsyncCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(UpdateProjectInvitationCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(UpdateProjectInvitationCmd.class.getName());
|
||||||
private static final String s_name = "updateprojectinvitationresponse";
|
private static final String s_name = "updateprojectinvitationresponse";
|
||||||
|
|
||||||
|
// ///////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////
|
// ////////////// API parameters /////////////////////
|
||||||
//////////////// API parameters /////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////
|
@IdentityMapper(entityTableName = "projects")
|
||||||
@IdentityMapper(entityTableName="projects")
|
@Parameter(name = ApiConstants.PROJECT_ID, required = true, type = CommandType.LONG, description = "id of the project to join")
|
||||||
@Parameter(name=ApiConstants.PROJECT_ID, required=true, type=CommandType.LONG, description="id of the project to join")
|
|
||||||
private Long projectId;
|
private Long projectId;
|
||||||
|
|
||||||
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="account that is joining the project")
|
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "account that is joining the project")
|
||||||
private String accountName;
|
private String accountName;
|
||||||
|
|
||||||
@Parameter(name=ApiConstants.TOKEN, type=CommandType.STRING, description="list invitations for specified account; this parameter has to be specified with domainId")
|
@Parameter(name = ApiConstants.TOKEN, type = CommandType.STRING, description = "list invitations for specified account; this parameter has to be specified with domainId")
|
||||||
private String token;
|
private String token;
|
||||||
|
|
||||||
@Parameter(name=ApiConstants.ACCEPT, type=CommandType.BOOLEAN, description="if true, accept the invitation, decline if false. True by default")
|
@Parameter(name = ApiConstants.ACCEPT, type = CommandType.BOOLEAN, description = "if true, accept the invitation, decline if false. True by default")
|
||||||
private Boolean accept;
|
private Boolean accept;
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
/////////////////// Accessors ///////////////////////
|
// ///////////////// Accessors ///////////////////////
|
||||||
/////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
public Long getProjectId() {
|
public Long getProjectId() {
|
||||||
return projectId;
|
return projectId;
|
||||||
}
|
}
|
||||||
@ -80,20 +79,19 @@ public class UpdateProjectInvitationCmd extends BaseAsyncCmd {
|
|||||||
return accept;
|
return accept;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ///////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////
|
// ///////////// API Implementation///////////////////
|
||||||
/////////////// API Implementation///////////////////
|
// ///////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////
|
|
||||||
@Override
|
@Override
|
||||||
public long getEntityOwnerId() {
|
public long getEntityOwnerId() {
|
||||||
//TODO - return project entity ownerId
|
// TODO - return project entity ownerId
|
||||||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
|
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are
|
||||||
|
// tracked
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(){
|
public void execute() {
|
||||||
UserContext.current().setEventDetails("Project id: "+ projectId + "; accountName " + accountName + "; accept " + getAccept());
|
UserContext.current().setEventDetails("Project id: " + projectId + "; accountName " + accountName + "; accept " + getAccept());
|
||||||
boolean result = _projectService.updateInvitation(projectId, accountName, token, getAccept());
|
boolean result = _projectService.updateInvitation(projectId, accountName, token, getAccept());
|
||||||
if (result) {
|
if (result) {
|
||||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||||
|
|||||||
@ -26,31 +26,40 @@ import com.google.gson.annotations.SerializedName;
|
|||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class ProjectAccountResponse extends BaseResponse implements ControlledEntityResponse {
|
public class ProjectAccountResponse extends BaseResponse implements ControlledEntityResponse {
|
||||||
@SerializedName(ApiConstants.PROJECT_ID) @Param(description="project id")
|
@SerializedName(ApiConstants.PROJECT_ID)
|
||||||
|
@Param(description = "project id")
|
||||||
private IdentityProxy projectId = new IdentityProxy("projects");
|
private IdentityProxy projectId = new IdentityProxy("projects");
|
||||||
|
|
||||||
@SerializedName(ApiConstants.PROJECT) @Param(description="project name")
|
@SerializedName(ApiConstants.PROJECT)
|
||||||
|
@Param(description = "project name")
|
||||||
private String projectName;
|
private String projectName;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.ACCOUNT_ID) @Param(description="the id of the account")
|
@SerializedName(ApiConstants.ACCOUNT_ID)
|
||||||
|
@Param(description = "the id of the account")
|
||||||
private IdentityProxy id = new IdentityProxy("account");
|
private IdentityProxy id = new IdentityProxy("account");
|
||||||
|
|
||||||
@SerializedName(ApiConstants.ACCOUNT) @Param(description="the name of the account")
|
@SerializedName(ApiConstants.ACCOUNT)
|
||||||
|
@Param(description = "the name of the account")
|
||||||
private String accountName;
|
private String accountName;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.ACCOUNT_TYPE) @Param(description="account type (admin, domain-admin, user)")
|
@SerializedName(ApiConstants.ACCOUNT_TYPE)
|
||||||
|
@Param(description = "account type (admin, domain-admin, user)")
|
||||||
private Short accountType;
|
private Short accountType;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.ROLE) @Param(description="account role in the project (regular,owner)")
|
@SerializedName(ApiConstants.ROLE)
|
||||||
|
@Param(description = "account role in the project (regular,owner)")
|
||||||
private String role;
|
private String role;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.DOMAIN_ID) @Param(description="id of the Domain the account belongs too")
|
@SerializedName(ApiConstants.DOMAIN_ID)
|
||||||
|
@Param(description = "id of the Domain the account belongs too")
|
||||||
private IdentityProxy domainId = new IdentityProxy("domain");
|
private IdentityProxy domainId = new IdentityProxy("domain");
|
||||||
|
|
||||||
@SerializedName(ApiConstants.DOMAIN) @Param(description="name of the Domain the account belongs too")
|
@SerializedName(ApiConstants.DOMAIN)
|
||||||
|
@Param(description = "name of the Domain the account belongs too")
|
||||||
private String domainName;
|
private String domainName;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.USER) @Param(description="the list of users associated with account", responseObject = UserResponse.class)
|
@SerializedName(ApiConstants.USER)
|
||||||
|
@Param(description = "the list of users associated with account", responseObject = UserResponse.class)
|
||||||
private List<UserResponse> users;
|
private List<UserResponse> users;
|
||||||
|
|
||||||
public void setProjectId(Long projectId) {
|
public void setProjectId(Long projectId) {
|
||||||
|
|||||||
@ -178,7 +178,7 @@ public class ApiDispatcher {
|
|||||||
Object pageSizeObj = unpackedParams.get(ApiConstants.PAGE_SIZE);
|
Object pageSizeObj = unpackedParams.get(ApiConstants.PAGE_SIZE);
|
||||||
Long pageSize = null;
|
Long pageSize = null;
|
||||||
if (pageSizeObj != null) {
|
if (pageSizeObj != null) {
|
||||||
pageSize = Long.valueOf((String)pageSizeObj);
|
pageSize = Long.valueOf((String) pageSizeObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((unpackedParams.get(ApiConstants.PAGE) == null) && (pageSize != null && pageSize != BaseListCmd.PAGESIZE_UNLIMITED)) {
|
if ((unpackedParams.get(ApiConstants.PAGE) == null) && (pageSize != null && pageSize != BaseListCmd.PAGESIZE_UNLIMITED)) {
|
||||||
@ -212,7 +212,8 @@ public class ApiDispatcher {
|
|||||||
Object paramObj = unpackedParams.get(parameterAnnotation.name());
|
Object paramObj = unpackedParams.get(parameterAnnotation.name());
|
||||||
if (paramObj == null) {
|
if (paramObj == null) {
|
||||||
if (parameterAnnotation.required()) {
|
if (parameterAnnotation.required()) {
|
||||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length()-8) + " due to missing parameter " + parameterAnnotation.name());
|
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to missing parameter "
|
||||||
|
+ parameterAnnotation.name());
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -224,20 +225,23 @@ public class ApiDispatcher {
|
|||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Unable to execute API command " + cmd.getCommandName() + " due to invalid value " + paramObj + " for parameter " + parameterAnnotation.name());
|
s_logger.debug("Unable to execute API command " + cmd.getCommandName() + " due to invalid value " + paramObj + " for parameter " + parameterAnnotation.name());
|
||||||
}
|
}
|
||||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length()-8) + " due to invalid value " + paramObj + " for parameter "
|
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value " + paramObj
|
||||||
|
+ " for parameter "
|
||||||
+ parameterAnnotation.name());
|
+ parameterAnnotation.name());
|
||||||
} catch (ParseException parseEx) {
|
} catch (ParseException parseEx) {
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Invalid date parameter " + paramObj + " passed to command " + cmd.getCommandName().substring(0, cmd.getCommandName().length()-8));
|
s_logger.debug("Invalid date parameter " + paramObj + " passed to command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
|
||||||
}
|
}
|
||||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to parse date " + paramObj + " for command " + cmd.getCommandName().substring(0, cmd.getCommandName().length()-8) + ", please pass dates in the format mentioned in the api documentation");
|
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to parse date " + paramObj + " for command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8)
|
||||||
} catch (InvalidParameterValueException invEx){
|
+ ", please pass dates in the format mentioned in the api documentation");
|
||||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length()-8) + " due to invalid value. " + invEx.getMessage());
|
} catch (InvalidParameterValueException invEx) {
|
||||||
|
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value. " + invEx.getMessage());
|
||||||
} catch (CloudRuntimeException cloudEx) {
|
} catch (CloudRuntimeException cloudEx) {
|
||||||
// FIXME: Better error message? This only happens if the API command is not executable, which typically means
|
// FIXME: Better error message? This only happens if the API command is not executable, which typically
|
||||||
|
// means
|
||||||
// there was
|
// there was
|
||||||
// and IllegalAccessException setting one of the parameters.
|
// and IllegalAccessException setting one of the parameters.
|
||||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Internal error executing API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length()-8));
|
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Internal error executing API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -252,28 +256,29 @@ public class ApiDispatcher {
|
|||||||
field.set(cmdObj, Boolean.valueOf(paramObj.toString()));
|
field.set(cmdObj, Boolean.valueOf(paramObj.toString()));
|
||||||
break;
|
break;
|
||||||
case DATE:
|
case DATE:
|
||||||
// This piece of code is for maintaining backward compatibility and support both the date formats(Bug 9724)
|
// This piece of code is for maintaining backward compatibility and support both the date formats(Bug
|
||||||
|
// 9724)
|
||||||
// Do the date massaging for ListEventsCmd only
|
// Do the date massaging for ListEventsCmd only
|
||||||
if(cmdObj instanceof ListEventsCmd){
|
if (cmdObj instanceof ListEventsCmd) {
|
||||||
boolean isObjInNewDateFormat = isObjInNewDateFormat(paramObj.toString());
|
boolean isObjInNewDateFormat = isObjInNewDateFormat(paramObj.toString());
|
||||||
if (isObjInNewDateFormat){
|
if (isObjInNewDateFormat) {
|
||||||
DateFormat newFormat = BaseCmd.NEW_INPUT_FORMAT;
|
DateFormat newFormat = BaseCmd.NEW_INPUT_FORMAT;
|
||||||
synchronized (newFormat) {
|
synchronized (newFormat) {
|
||||||
field.set(cmdObj, newFormat.parse(paramObj.toString()));
|
field.set(cmdObj, newFormat.parse(paramObj.toString()));
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
DateFormat format = BaseCmd.INPUT_FORMAT;
|
DateFormat format = BaseCmd.INPUT_FORMAT;
|
||||||
synchronized (format) {
|
synchronized (format) {
|
||||||
Date date = format.parse(paramObj.toString());
|
Date date = format.parse(paramObj.toString());
|
||||||
if (field.getName().equals("startDate")){
|
if (field.getName().equals("startDate")) {
|
||||||
date = massageDate(date, 0, 0, 0);
|
date = massageDate(date, 0, 0, 0);
|
||||||
}else if (field.getName().equals("endDate")){
|
} else if (field.getName().equals("endDate")) {
|
||||||
date = massageDate(date, 23, 59, 59);
|
date = massageDate(date, 23, 59, 59);
|
||||||
}
|
}
|
||||||
field.set(cmdObj, date);
|
field.set(cmdObj, date);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
DateFormat format = BaseCmd.INPUT_FORMAT;
|
DateFormat format = BaseCmd.INPUT_FORMAT;
|
||||||
format.setLenient(false);
|
format.setLenient(false);
|
||||||
synchronized (format) {
|
synchronized (format) {
|
||||||
@ -297,10 +302,9 @@ public class ApiDispatcher {
|
|||||||
case INTEGER:
|
case INTEGER:
|
||||||
listParam.add(Integer.valueOf(token));
|
listParam.add(Integer.valueOf(token));
|
||||||
break;
|
break;
|
||||||
case LONG:
|
case LONG: {
|
||||||
{
|
|
||||||
Long val = null;
|
Long val = null;
|
||||||
if(identityMapper != null)
|
if (identityMapper != null)
|
||||||
val = s_instance._identityDao.getIdentityId(identityMapper, token);
|
val = s_instance._identityDao.getIdentityId(identityMapper, token);
|
||||||
else
|
else
|
||||||
val = Long.valueOf(token);
|
val = Long.valueOf(token);
|
||||||
@ -318,7 +322,7 @@ public class ApiDispatcher {
|
|||||||
field.set(cmdObj, listParam);
|
field.set(cmdObj, listParam);
|
||||||
break;
|
break;
|
||||||
case LONG:
|
case LONG:
|
||||||
if(identityMapper != null)
|
if (identityMapper != null)
|
||||||
field.set(cmdObj, s_instance._identityDao.getIdentityId(identityMapper, paramObj.toString()));
|
field.set(cmdObj, s_instance._identityDao.getIdentityId(identityMapper, paramObj.toString()));
|
||||||
else
|
else
|
||||||
field.set(cmdObj, Long.valueOf(paramObj.toString()));
|
field.set(cmdObj, Long.valueOf(paramObj.toString()));
|
||||||
@ -327,9 +331,9 @@ public class ApiDispatcher {
|
|||||||
field.set(cmdObj, Short.valueOf(paramObj.toString()));
|
field.set(cmdObj, Short.valueOf(paramObj.toString()));
|
||||||
break;
|
break;
|
||||||
case STRING:
|
case STRING:
|
||||||
if((paramObj != null) && paramObj.toString().length() > annotation.length()){
|
if ((paramObj != null) && paramObj.toString().length() > annotation.length()) {
|
||||||
s_logger.error("Value greater than max allowed length "+annotation.length()+" for param: "+field.getName());
|
s_logger.error("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName());
|
||||||
throw new InvalidParameterValueException("Value greater than max allowed length "+annotation.length()+" for param: "+field.getName());
|
throw new InvalidParameterValueException("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName());
|
||||||
}
|
}
|
||||||
field.set(cmdObj, paramObj.toString());
|
field.set(cmdObj, paramObj.toString());
|
||||||
break;
|
break;
|
||||||
@ -363,7 +367,7 @@ public class ApiDispatcher {
|
|||||||
|
|
||||||
public static void plugService(BaseCmd cmd) {
|
public static void plugService(BaseCmd cmd) {
|
||||||
|
|
||||||
if(!ApiServer.isPluggableServiceCommand(cmd.getClass().getName())){
|
if (!ApiServer.isPluggableServiceCommand(cmd.getClass().getName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Class<?> clazz = cmd.getClass();
|
Class<?> clazz = cmd.getClass();
|
||||||
|
|||||||
@ -335,7 +335,7 @@ public class ApiServer implements HttpRequestHandler {
|
|||||||
responseType = paramValue[1];
|
responseType = paramValue[1];
|
||||||
} else {
|
} else {
|
||||||
// according to the servlet spec, the parameter map should be in the form (name=String,
|
// according to the servlet spec, the parameter map should be in the form (name=String,
|
||||||
// value=String[]), so
|
// value=String[]), so
|
||||||
// parameter values will be stored in an array
|
// parameter values will be stored in an array
|
||||||
parameterMap.put(/* name */paramValue[0], /* value */new String[] { paramValue[1] });
|
parameterMap.put(/* name */paramValue[0], /* value */new String[] { paramValue[1] });
|
||||||
}
|
}
|
||||||
@ -867,7 +867,7 @@ public class ApiServer implements HttpRequestHandler {
|
|||||||
// FIXME: the following two threads are copied from
|
// FIXME: the following two threads are copied from
|
||||||
// http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpServer.java
|
// http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpServer.java
|
||||||
// we have to cite a license if we are using this code directly, so we need to add the appropriate citation or
|
// we have to cite a license if we are using this code directly, so we need to add the appropriate citation or
|
||||||
// modify the
|
// modify the
|
||||||
// code to be very specific to our needs
|
// code to be very specific to our needs
|
||||||
static class ListenerThread extends Thread {
|
static class ListenerThread extends Thread {
|
||||||
private HttpService _httpService = null;
|
private HttpService _httpService = null;
|
||||||
|
|||||||
@ -16,39 +16,39 @@ import com.cloud.api.Identity;
|
|||||||
import com.cloud.utils.db.GenericDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="project_invitations")
|
@Table(name = "project_invitations")
|
||||||
public class ProjectInvitationVO implements ProjectInvitation, Identity {
|
public class ProjectInvitationVO implements ProjectInvitation, Identity {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@Column(name="id")
|
@Column(name = "id")
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
@Column(name="project_id")
|
@Column(name = "project_id")
|
||||||
private long projectId;
|
private long projectId;
|
||||||
|
|
||||||
@Column(name="account_id")
|
@Column(name = "account_id")
|
||||||
private Long forAccountId;
|
private Long forAccountId;
|
||||||
|
|
||||||
@Column(name="domain_id")
|
@Column(name = "domain_id")
|
||||||
private Long inDomainId;
|
private Long inDomainId;
|
||||||
|
|
||||||
@Column(name="token")
|
@Column(name = "token")
|
||||||
private String token;
|
private String token;
|
||||||
|
|
||||||
@Column(name="email")
|
@Column(name = "email")
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@Column(name="state")
|
@Column(name = "state")
|
||||||
@Enumerated(value=EnumType.STRING)
|
@Enumerated(value = EnumType.STRING)
|
||||||
private State state = State.Pending;
|
private State state = State.Pending;
|
||||||
|
|
||||||
@Column(name=GenericDao.CREATED_COLUMN)
|
@Column(name = GenericDao.CREATED_COLUMN)
|
||||||
private Date created;
|
private Date created;
|
||||||
|
|
||||||
@Column(name="uuid")
|
@Column(name = "uuid")
|
||||||
private String uuid;
|
private String uuid;
|
||||||
|
|
||||||
protected ProjectInvitationVO(){
|
protected ProjectInvitationVO() {
|
||||||
this.uuid = UUID.randomUUID().toString();
|
this.uuid = UUID.randomUUID().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
package com.cloud.projects;
|
package com.cloud.projects;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -17,4 +16,5 @@ public interface ProjectManager extends ProjectService {
|
|||||||
boolean projectInviteRequired();
|
boolean projectInviteRequired();
|
||||||
|
|
||||||
boolean allowUserToCreateProject();
|
boolean allowUserToCreateProject();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,9 +23,11 @@ import com.cloud.projects.ProjectAccount;
|
|||||||
import com.cloud.projects.ProjectAccountVO;
|
import com.cloud.projects.ProjectAccountVO;
|
||||||
import com.cloud.utils.db.GenericDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
public interface ProjectAccountDao extends GenericDao<ProjectAccountVO, Long>{
|
public interface ProjectAccountDao extends GenericDao<ProjectAccountVO, Long> {
|
||||||
ProjectAccountVO getProjectOwner(long projectId);
|
ProjectAccountVO getProjectOwner(long projectId);
|
||||||
|
|
||||||
List<ProjectAccountVO> listByProjectId(long projectId);
|
List<ProjectAccountVO> listByProjectId(long projectId);
|
||||||
|
|
||||||
ProjectAccountVO findByProjectIdAccountId(long projectId, long accountId);
|
ProjectAccountVO findByProjectIdAccountId(long projectId, long accountId);
|
||||||
|
|
||||||
boolean canAccessProjectAccount(long accountId, long projectAccountId);
|
boolean canAccessProjectAccount(long accountId, long projectAccountId);
|
||||||
|
|||||||
@ -30,7 +30,7 @@ import com.cloud.utils.db.SearchCriteria;
|
|||||||
import com.cloud.utils.db.SearchCriteria.Func;
|
import com.cloud.utils.db.SearchCriteria.Func;
|
||||||
import com.cloud.utils.db.SearchCriteria.Op;
|
import com.cloud.utils.db.SearchCriteria.Op;
|
||||||
|
|
||||||
@Local(value={ProjectAccountDao.class})
|
@Local(value = { ProjectAccountDao.class })
|
||||||
public class ProjectAccountDaoImpl extends GenericDaoBase<ProjectAccountVO, Long> implements ProjectAccountDao {
|
public class ProjectAccountDaoImpl extends GenericDaoBase<ProjectAccountVO, Long> implements ProjectAccountDao {
|
||||||
protected final SearchBuilder<ProjectAccountVO> AllFieldsSearch;
|
protected final SearchBuilder<ProjectAccountVO> AllFieldsSearch;
|
||||||
final GenericSearchBuilder<ProjectAccountVO, Long> AdminSearch;
|
final GenericSearchBuilder<ProjectAccountVO, Long> AdminSearch;
|
||||||
@ -138,4 +138,5 @@ public class ProjectAccountDaoImpl extends GenericDaoBase<ProjectAccountVO, Long
|
|||||||
sc.setParameters("role", role);
|
sc.setParameters("role", role);
|
||||||
return customSearch(sc, null).get(0);
|
return customSearch(sc, null).get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import com.cloud.projects.Project;
|
|||||||
import com.cloud.projects.ProjectVO;
|
import com.cloud.projects.ProjectVO;
|
||||||
import com.cloud.utils.db.GenericDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
public interface ProjectDao extends GenericDao<ProjectVO, Long>{
|
public interface ProjectDao extends GenericDao<ProjectVO, Long> {
|
||||||
|
|
||||||
ProjectVO findByNameAndDomain(String name, long domainId);
|
ProjectVO findByNameAndDomain(String name, long domainId);
|
||||||
|
|
||||||
@ -32,4 +32,5 @@ public interface ProjectDao extends GenericDao<ProjectVO, Long>{
|
|||||||
ProjectVO findByProjectAccountId(long projectAccountId);
|
ProjectVO findByProjectAccountId(long projectAccountId);
|
||||||
|
|
||||||
List<ProjectVO> listByState(Project.State state);
|
List<ProjectVO> listByState(Project.State state);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ import com.cloud.utils.db.SearchCriteria;
|
|||||||
import com.cloud.utils.db.SearchCriteria.Func;
|
import com.cloud.utils.db.SearchCriteria.Func;
|
||||||
import com.cloud.utils.db.Transaction;
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
@Local(value={ProjectDao.class})
|
@Local(value = { ProjectDao.class })
|
||||||
public class ProjectDaoImpl extends GenericDaoBase<ProjectVO, Long> implements ProjectDao {
|
public class ProjectDaoImpl extends GenericDaoBase<ProjectVO, Long> implements ProjectDao {
|
||||||
private static final Logger s_logger = Logger.getLogger(ProjectDaoImpl.class);
|
private static final Logger s_logger = Logger.getLogger(ProjectDaoImpl.class);
|
||||||
protected final SearchBuilder<ProjectVO> AllFieldsSearch;
|
protected final SearchBuilder<ProjectVO> AllFieldsSearch;
|
||||||
@ -46,7 +46,8 @@ public class ProjectDaoImpl extends GenericDaoBase<ProjectVO, Long> implements P
|
|||||||
return findOneBy(sc);
|
return findOneBy(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @DB
|
@Override
|
||||||
|
@DB
|
||||||
public boolean remove(Long projectId) {
|
public boolean remove(Long projectId) {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
Transaction txn = Transaction.currentTxn();
|
Transaction txn = Transaction.currentTxn();
|
||||||
@ -87,4 +88,5 @@ public class ProjectDaoImpl extends GenericDaoBase<ProjectVO, Long> implements P
|
|||||||
sc.setParameters("state", state);
|
sc.setParameters("state", state);
|
||||||
return listBy(sc);
|
return listBy(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,14 +23,23 @@ import com.cloud.projects.ProjectInvitation.State;
|
|||||||
import com.cloud.projects.ProjectInvitationVO;
|
import com.cloud.projects.ProjectInvitationVO;
|
||||||
import com.cloud.utils.db.GenericDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
public interface ProjectInvitationDao extends GenericDao<ProjectInvitationVO, Long>{
|
public interface ProjectInvitationDao extends GenericDao<ProjectInvitationVO, Long> {
|
||||||
ProjectInvitationVO findByAccountIdProjectId(long accountId, long projectId, State... inviteState);
|
ProjectInvitationVO findByAccountIdProjectId(long accountId, long projectId, State... inviteState);
|
||||||
|
|
||||||
List<ProjectInvitationVO> listExpiredInvitations();
|
List<ProjectInvitationVO> listExpiredInvitations();
|
||||||
|
|
||||||
boolean expirePendingInvitations(long timeOut);
|
boolean expirePendingInvitations(long timeOut);
|
||||||
|
|
||||||
boolean isActive(long id, long timeout);
|
boolean isActive(long id, long timeout);
|
||||||
|
|
||||||
ProjectInvitationVO findByEmailAndProjectId(String email, long projectId, State... inviteState);
|
ProjectInvitationVO findByEmailAndProjectId(String email, long projectId, State... inviteState);
|
||||||
|
|
||||||
ProjectInvitationVO findPendingByTokenAndProjectId(String token, long projectId, State... inviteState);
|
ProjectInvitationVO findPendingByTokenAndProjectId(String token, long projectId, State... inviteState);
|
||||||
|
|
||||||
void cleanupInvitations(long projectId);
|
void cleanupInvitations(long projectId);
|
||||||
|
|
||||||
ProjectInvitationVO findPendingById(long id);
|
ProjectInvitationVO findPendingById(long id);
|
||||||
|
|
||||||
List<ProjectInvitationVO> listInvitationsToExpire(long timeOut);
|
List<ProjectInvitationVO> listInvitationsToExpire(long timeOut);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import com.cloud.utils.db.GenericDaoBase;
|
|||||||
import com.cloud.utils.db.SearchBuilder;
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
import com.cloud.utils.db.SearchCriteria;
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
|
||||||
@Local(value={ProjectInvitationDao.class})
|
@Local(value = { ProjectInvitationDao.class })
|
||||||
public class ProjectInvitationDaoImpl extends GenericDaoBase<ProjectInvitationVO, Long> implements ProjectInvitationDao {
|
public class ProjectInvitationDaoImpl extends GenericDaoBase<ProjectInvitationVO, Long> implements ProjectInvitationDao {
|
||||||
private static final Logger s_logger = Logger.getLogger(ProjectInvitationDaoImpl.class);
|
private static final Logger s_logger = Logger.getLogger(ProjectInvitationDaoImpl.class);
|
||||||
protected final SearchBuilder<ProjectInvitationVO> AllFieldsSearch;
|
protected final SearchBuilder<ProjectInvitationVO> AllFieldsSearch;
|
||||||
@ -41,14 +41,13 @@ public class ProjectInvitationDaoImpl extends GenericDaoBase<ProjectInvitationVO
|
|||||||
InactiveSearch.done();
|
InactiveSearch.done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProjectInvitationVO findByAccountIdProjectId(long accountId, long projectId, State... inviteState) {
|
public ProjectInvitationVO findByAccountIdProjectId(long accountId, long projectId, State... inviteState) {
|
||||||
SearchCriteria<ProjectInvitationVO> sc = AllFieldsSearch.create();
|
SearchCriteria<ProjectInvitationVO> sc = AllFieldsSearch.create();
|
||||||
sc.setParameters("accountId", accountId);
|
sc.setParameters("accountId", accountId);
|
||||||
sc.setParameters("projectId", projectId);
|
sc.setParameters("projectId", projectId);
|
||||||
if (inviteState != null && inviteState.length > 0) {
|
if (inviteState != null && inviteState.length > 0) {
|
||||||
sc.setParameters("state", (Object[])inviteState);
|
sc.setParameters("state", (Object[]) inviteState);
|
||||||
}
|
}
|
||||||
|
|
||||||
return findOneBy(sc);
|
return findOneBy(sc);
|
||||||
@ -82,7 +81,7 @@ public class ProjectInvitationDaoImpl extends GenericDaoBase<ProjectInvitationVO
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ProjectInvitationVO> listInvitationsToExpire (long timeOut) {
|
public List<ProjectInvitationVO> listInvitationsToExpire(long timeOut) {
|
||||||
SearchCriteria<ProjectInvitationVO> sc = InactiveSearch.create();
|
SearchCriteria<ProjectInvitationVO> sc = InactiveSearch.create();
|
||||||
sc.setParameters("created", new Date((DateUtil.currentGMTTime().getTime()) - timeOut));
|
sc.setParameters("created", new Date((DateUtil.currentGMTTime().getTime()) - timeOut));
|
||||||
sc.setParameters("state", State.Pending);
|
sc.setParameters("state", State.Pending);
|
||||||
@ -115,7 +114,7 @@ public class ProjectInvitationDaoImpl extends GenericDaoBase<ProjectInvitationVO
|
|||||||
sc.setParameters("email", email);
|
sc.setParameters("email", email);
|
||||||
sc.setParameters("projectId", projectId);
|
sc.setParameters("projectId", projectId);
|
||||||
if (inviteState != null && inviteState.length > 0) {
|
if (inviteState != null && inviteState.length > 0) {
|
||||||
sc.setParameters("state", (Object[])inviteState);
|
sc.setParameters("state", (Object[]) inviteState);
|
||||||
}
|
}
|
||||||
|
|
||||||
return findOneBy(sc);
|
return findOneBy(sc);
|
||||||
@ -127,7 +126,7 @@ public class ProjectInvitationDaoImpl extends GenericDaoBase<ProjectInvitationVO
|
|||||||
sc.setParameters("token", token);
|
sc.setParameters("token", token);
|
||||||
sc.setParameters("projectId", projectId);
|
sc.setParameters("projectId", projectId);
|
||||||
if (inviteState != null && inviteState.length > 0) {
|
if (inviteState != null && inviteState.length > 0) {
|
||||||
sc.setParameters("state", (Object[])inviteState);
|
sc.setParameters("state", (Object[]) inviteState);
|
||||||
}
|
}
|
||||||
|
|
||||||
return findOneBy(sc);
|
return findOneBy(sc);
|
||||||
@ -150,4 +149,5 @@ public class ProjectInvitationDaoImpl extends GenericDaoBase<ProjectInvitationVO
|
|||||||
int numberRemoved = remove(sc);
|
int numberRemoved = remove(sc);
|
||||||
s_logger.debug("Removed " + numberRemoved + " invitations for project id=" + projectId);
|
s_logger.debug("Removed " + numberRemoved + " invitations for project id=" + projectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -298,7 +298,8 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
private final LoadBalancerDao _loadbalancerDao;
|
private final LoadBalancerDao _loadbalancerDao;
|
||||||
private final HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;
|
private final HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;
|
||||||
private final Adapters<HostAllocator> _hostAllocators;
|
private final Adapters<HostAllocator> _hostAllocators;
|
||||||
@Inject ProjectManager _projectMgr;
|
@Inject
|
||||||
|
ProjectManager _projectMgr;
|
||||||
private final ResourceManager _resourceMgr;
|
private final ResourceManager _resourceMgr;
|
||||||
@Inject
|
@Inject
|
||||||
SnapshotManager _snapshotMgr;
|
SnapshotManager _snapshotMgr;
|
||||||
@ -369,7 +370,6 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
_hypervisorCapabilitiesDao = locator.getDao(HypervisorCapabilitiesDao.class);
|
_hypervisorCapabilitiesDao = locator.getDao(HypervisorCapabilitiesDao.class);
|
||||||
|
|
||||||
|
|
||||||
_hostAllocators = locator.getAdapters(HostAllocator.class);
|
_hostAllocators = locator.getAdapters(HostAllocator.class);
|
||||||
if (_hostAllocators == null || !_hostAllocators.isSet()) {
|
if (_hostAllocators == null || !_hostAllocators.isSet()) {
|
||||||
s_logger.error("Unable to find HostAllocators");
|
s_logger.error("Unable to find HostAllocators");
|
||||||
@ -616,7 +616,8 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
// The list method for offerings is being modified in accordance with discussion with Will/Kevin
|
// The list method for offerings is being modified in accordance with discussion with Will/Kevin
|
||||||
// For now, we will be listing the following based on the usertype
|
// For now, we will be listing the following based on the usertype
|
||||||
// 1. For root, we will list all offerings
|
// 1. For root, we will list all offerings
|
||||||
// 2. For domainAdmin and regular users, we will list everything in their domains+parent domains ... all the way till
|
// 2. For domainAdmin and regular users, we will list everything in their domains+parent domains ... all the way
|
||||||
|
// till
|
||||||
// root
|
// root
|
||||||
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
|
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
|
||||||
isAscending = (isAscending == null ? true : isAscending);
|
isAscending = (isAscending == null ? true : isAscending);
|
||||||
@ -647,14 +648,14 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
// For non-root users
|
// For non-root users
|
||||||
if ((caller.getType() == Account.ACCOUNT_TYPE_NORMAL || caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
|
if ((caller.getType() == Account.ACCOUNT_TYPE_NORMAL || caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
|
||||||
if (isSystem){
|
if (isSystem) {
|
||||||
throw new InvalidParameterValueException("Only root admins can access system's offering");
|
throw new InvalidParameterValueException("Only root admins can access system's offering");
|
||||||
}
|
}
|
||||||
return searchServiceOfferingsInternal(caller, name, id, vmId, keyword, searchFilter);
|
return searchServiceOfferingsInternal(caller, name, id, vmId, keyword, searchFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// for root users, the existing flow
|
// for root users, the existing flow
|
||||||
if (caller.getDomainId() != 1 && isSystem){ //NON ROOT admin
|
if (caller.getDomainId() != 1 && isSystem) { // NON ROOT admin
|
||||||
throw new InvalidParameterValueException("Non ROOT admins cannot access system's offering");
|
throw new InvalidParameterValueException("Non ROOT admins cannot access system's offering");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -695,7 +696,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
|
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vm_type_str != null){
|
if (vm_type_str != null) {
|
||||||
sc.addAnd("vm_type", SearchCriteria.Op.EQ, vm_type_str);
|
sc.addAnd("vm_type", SearchCriteria.Op.EQ, vm_type_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -707,7 +708,8 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
private List<ServiceOfferingVO> searchServiceOfferingsInternal(Account account, Object name, Object id, Long vmId, Object keyword, Filter searchFilter) {
|
private List<ServiceOfferingVO> searchServiceOfferingsInternal(Account account, Object name, Object id, Long vmId, Object keyword, Filter searchFilter) {
|
||||||
|
|
||||||
// it was decided to return all offerings for the user's domain, and everything above till root (for normal user or
|
// it was decided to return all offerings for the user's domain, and everything above till root (for normal user
|
||||||
|
// or
|
||||||
// domain admin)
|
// domain admin)
|
||||||
// list all offerings belonging to this domain, and all of its parents
|
// list all offerings belonging to this domain, and all of its parents
|
||||||
// check the parent, if not null, add offerings for that parent to list
|
// check the parent, if not null, add offerings for that parent to list
|
||||||
@ -764,7 +766,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
// for this domain
|
// for this domain
|
||||||
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainRecord.getId());
|
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainRecord.getId());
|
||||||
|
|
||||||
//don't return removed service offerings
|
// don't return removed service offerings
|
||||||
sc.addAnd("removed", SearchCriteria.Op.NULL);
|
sc.addAnd("removed", SearchCriteria.Op.NULL);
|
||||||
|
|
||||||
// search and add for this domain
|
// search and add for this domain
|
||||||
@ -883,7 +885,8 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
throw new InvalidParameterValueException("VM is not Running, unable to migrate the vm " + vm);
|
throw new InvalidParameterValueException("VM is not Running, unable to migrate the vm " + vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vm.getHypervisorType().equals(HypervisorType.XenServer) && !vm.getHypervisorType().equals(HypervisorType.VMware) && !vm.getHypervisorType().equals(HypervisorType.KVM) && !vm.getHypervisorType().equals(HypervisorType.Ovm)) {
|
if (!vm.getHypervisorType().equals(HypervisorType.XenServer) && !vm.getHypervisorType().equals(HypervisorType.VMware) && !vm.getHypervisorType().equals(HypervisorType.KVM)
|
||||||
|
&& !vm.getHypervisorType().equals(HypervisorType.Ovm)) {
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug(vm + " is not XenServer/VMware/KVM/OVM, cannot migrate this VM.");
|
s_logger.debug(vm + " is not XenServer/VMware/KVM/OVM, cannot migrate this VM.");
|
||||||
}
|
}
|
||||||
@ -922,7 +925,6 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
s_logger.debug("Calling HostAllocators to search for hosts in cluster: " + cluster + " having enough capacity and suitable for migration");
|
s_logger.debug("Calling HostAllocators to search for hosts in cluster: " + cluster + " having enough capacity and suitable for migration");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
List<Host> suitableHosts = new ArrayList<Host>();
|
List<Host> suitableHosts = new ArrayList<Host>();
|
||||||
Enumeration<HostAllocator> enHost = _hostAllocators.enumeration();
|
Enumeration<HostAllocator> enHost = _hostAllocators.enumeration();
|
||||||
|
|
||||||
@ -939,9 +941,9 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(suitableHosts.isEmpty()){
|
if (suitableHosts.isEmpty()) {
|
||||||
s_logger.debug("No suitable hosts found");
|
s_logger.debug("No suitable hosts found");
|
||||||
}else{
|
} else {
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Hosts having capacity and suitable for migration: " + suitableHosts);
|
s_logger.debug("Hosts having capacity and suitable for migration: " + suitableHosts);
|
||||||
}
|
}
|
||||||
@ -1066,7 +1068,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//set project information
|
// set project information
|
||||||
if (projectId != null) {
|
if (projectId != null) {
|
||||||
Project project = _projectMgr.getProject(projectId);
|
Project project = _projectMgr.getProject(projectId);
|
||||||
if (project == null) {
|
if (project == null) {
|
||||||
@ -1253,7 +1255,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<HypervisorType> hypers = null;
|
List<HypervisorType> hypers = null;
|
||||||
if(!isIso) {
|
if (!isIso) {
|
||||||
hypers = _resourceMgr.listAvailHypervisorInZone(null, null);
|
hypers = _resourceMgr.listAvailHypervisorInZone(null, null);
|
||||||
}
|
}
|
||||||
Set<Pair<Long, Long>> templateZonePairSet = new HashSet<Pair<Long, Long>>();
|
Set<Pair<Long, Long>> templateZonePairSet = new HashSet<Pair<Long, Long>>();
|
||||||
@ -1295,7 +1297,6 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
return templateZonePairSet;
|
return templateZonePairSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VMTemplateVO updateTemplate(UpdateIsoCmd cmd) {
|
public VMTemplateVO updateTemplate(UpdateIsoCmd cmd) {
|
||||||
return updateTemplateOrIso(cmd);
|
return updateTemplateOrIso(cmd);
|
||||||
@ -1384,7 +1385,6 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
return _templateDao.findById(id);
|
return _templateDao.findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<EventVO> searchForEvents(ListEventsCmd cmd) {
|
public List<EventVO> searchForEvents(ListEventsCmd cmd) {
|
||||||
Account caller = UserContext.current().getCaller();
|
Account caller = UserContext.current().getCaller();
|
||||||
@ -1435,13 +1435,13 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
sb.and("createDateB", sb.entity().getCreateDate(), SearchCriteria.Op.BETWEEN);
|
sb.and("createDateB", sb.entity().getCreateDate(), SearchCriteria.Op.BETWEEN);
|
||||||
sb.and("createDateG", sb.entity().getCreateDate(), SearchCriteria.Op.GTEQ);
|
sb.and("createDateG", sb.entity().getCreateDate(), SearchCriteria.Op.GTEQ);
|
||||||
sb.and("createDateL", sb.entity().getCreateDate(), SearchCriteria.Op.LTEQ);
|
sb.and("createDateL", sb.entity().getCreateDate(), SearchCriteria.Op.LTEQ);
|
||||||
sb.and("state", sb.entity().getState(),SearchCriteria.Op.NEQ);
|
sb.and("state", sb.entity().getState(), SearchCriteria.Op.NEQ);
|
||||||
sb.and("startId", sb.entity().getStartId(), SearchCriteria.Op.EQ);
|
sb.and("startId", sb.entity().getStartId(), SearchCriteria.Op.EQ);
|
||||||
sb.and("createDate", sb.entity().getCreateDate(), SearchCriteria.Op.BETWEEN);
|
sb.and("createDate", sb.entity().getCreateDate(), SearchCriteria.Op.BETWEEN);
|
||||||
|
|
||||||
SearchCriteria<EventVO> sc = sb.create();
|
SearchCriteria<EventVO> sc = sb.create();
|
||||||
if (listProjectResourcesCriteria != null) {
|
if (listProjectResourcesCriteria != null) {
|
||||||
sc.setJoinParameters("accountSearch","accountType", Account.ACCOUNT_TYPE_PROJECT);
|
sc.setJoinParameters("accountSearch", "accountType", Account.ACCOUNT_TYPE_PROJECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!permittedAccounts.isEmpty()) {
|
if (!permittedAccounts.isEmpty()) {
|
||||||
@ -1511,7 +1511,6 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DomainRouterVO> searchForRouters(ListRoutersCmd cmd) {
|
public List<DomainRouterVO> searchForRouters(ListRoutersCmd cmd) {
|
||||||
Long id = cmd.getId();
|
Long id = cmd.getId();
|
||||||
@ -1590,7 +1589,6 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
return _routerDao.search(sc, searchFilter);
|
return _routerDao.search(sc, searchFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<IPAddressVO> searchForIPAddresses(ListPublicIpAddressesCmd cmd) {
|
public List<IPAddressVO> searchForIPAddresses(ListPublicIpAddressesCmd cmd) {
|
||||||
Object keyword = cmd.getKeyword();
|
Object keyword = cmd.getKeyword();
|
||||||
@ -1632,8 +1630,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
sb.and("isSourceNat", sb.entity().isSourceNat(), SearchCriteria.Op.EQ);
|
sb.and("isSourceNat", sb.entity().isSourceNat(), SearchCriteria.Op.EQ);
|
||||||
sb.and("isStaticNat", sb.entity().isOneToOneNat(), SearchCriteria.Op.EQ);
|
sb.and("isStaticNat", sb.entity().isOneToOneNat(), SearchCriteria.Op.EQ);
|
||||||
|
|
||||||
|
if (forLoadBalancing != null && (Boolean) forLoadBalancing) {
|
||||||
if (forLoadBalancing != null && (Boolean)forLoadBalancing) {
|
|
||||||
SearchBuilder<LoadBalancerVO> lbSearch = _loadbalancerDao.createSearchBuilder();
|
SearchBuilder<LoadBalancerVO> lbSearch = _loadbalancerDao.createSearchBuilder();
|
||||||
sb.join("lbSearch", lbSearch, sb.entity().getId(), lbSearch.entity().getSourceIpAddressId(), JoinType.INNER);
|
sb.join("lbSearch", lbSearch, sb.entity().getId(), lbSearch.entity().getSourceIpAddressId(), JoinType.INNER);
|
||||||
sb.groupBy(sb.entity().getId());
|
sb.groupBy(sb.entity().getId());
|
||||||
@ -1660,7 +1657,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
vlanType = VlanType.VirtualNetwork;
|
vlanType = VlanType.VirtualNetwork;
|
||||||
}
|
}
|
||||||
|
|
||||||
//don't show SSVM/CPVM ips
|
// don't show SSVM/CPVM ips
|
||||||
if (vlanType == VlanType.VirtualNetwork && (allocatedOnly)) {
|
if (vlanType == VlanType.VirtualNetwork && (allocatedOnly)) {
|
||||||
sb.and("associatedNetworkId", sb.entity().getAssociatedWithNetworkId(), SearchCriteria.Op.NNULL);
|
sb.and("associatedNetworkId", sb.entity().getAssociatedWithNetworkId(), SearchCriteria.Op.NNULL);
|
||||||
}
|
}
|
||||||
@ -1686,7 +1683,6 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
sc.setParameters("isStaticNat", staticNat);
|
sc.setParameters("isStaticNat", staticNat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (address == null && keyword != null) {
|
if (address == null && keyword != null) {
|
||||||
sc.setParameters("addressLIKE", "%" + keyword + "%");
|
sc.setParameters("addressLIKE", "%" + keyword + "%");
|
||||||
}
|
}
|
||||||
@ -1839,7 +1835,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
Account caller = UserContext.current().getCaller();
|
Account caller = UserContext.current().getCaller();
|
||||||
_accountMgr.checkAccess(caller, domain);
|
_accountMgr.checkAccess(caller, domain);
|
||||||
|
|
||||||
//domain name is unique in the cloud
|
// domain name is unique in the cloud
|
||||||
if (domainName != null) {
|
if (domainName != null) {
|
||||||
SearchCriteria<DomainVO> sc = _domainDao.createSearchCriteria();
|
SearchCriteria<DomainVO> sc = _domainDao.createSearchCriteria();
|
||||||
sc.addAnd("name", SearchCriteria.Op.EQ, domainName);
|
sc.addAnd("name", SearchCriteria.Op.EQ, domainName);
|
||||||
@ -1852,8 +1848,8 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//validate network domain
|
// validate network domain
|
||||||
if (networkDomain != null && !networkDomain.isEmpty()){
|
if (networkDomain != null && !networkDomain.isEmpty()) {
|
||||||
if (!NetUtils.verifyDomainName(networkDomain)) {
|
if (!NetUtils.verifyDomainName(networkDomain)) {
|
||||||
throw new InvalidParameterValueException(
|
throw new InvalidParameterValueException(
|
||||||
"Invalid network domain. Total length shouldn't exceed 190 chars. Each domain label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', the digits '0' through '9', "
|
"Invalid network domain. Total length shouldn't exceed 190 chars. Each domain label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', the digits '0' through '9', "
|
||||||
@ -1946,42 +1942,42 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
Long podId = cmd.getPodId();
|
Long podId = cmd.getPodId();
|
||||||
Long clusterId = cmd.getClusterId();
|
Long clusterId = cmd.getClusterId();
|
||||||
|
|
||||||
if (clusterId != null){
|
if (clusterId != null) {
|
||||||
throw new InvalidParameterValueException("Currently clusterId param is not suppoerted");
|
throw new InvalidParameterValueException("Currently clusterId param is not suppoerted");
|
||||||
}
|
}
|
||||||
zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
|
zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
|
||||||
List<SummedCapacity> summedCapacities = new ArrayList<SummedCapacity>();
|
List<SummedCapacity> summedCapacities = new ArrayList<SummedCapacity>();
|
||||||
|
|
||||||
if (zoneId == null && podId == null){//Group by Zone, capacity type
|
if (zoneId == null && podId == null) {// Group by Zone, capacity type
|
||||||
List<SummedCapacity> summedCapacitiesAtZone = _capacityDao.listCapacitiesGroupedByLevelAndType(capacityType, zoneId, podId, clusterId, 1, cmd.getPageSizeVal());
|
List<SummedCapacity> summedCapacitiesAtZone = _capacityDao.listCapacitiesGroupedByLevelAndType(capacityType, zoneId, podId, clusterId, 1, cmd.getPageSizeVal());
|
||||||
if(summedCapacitiesAtZone != null){
|
if (summedCapacitiesAtZone != null) {
|
||||||
summedCapacities.addAll(summedCapacitiesAtZone);
|
summedCapacities.addAll(summedCapacitiesAtZone);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (podId == null){//Group by Pod, capacity type
|
if (podId == null) {// Group by Pod, capacity type
|
||||||
List<SummedCapacity> summedCapacitiesAtPod = _capacityDao.listCapacitiesGroupedByLevelAndType(capacityType, zoneId, podId, clusterId, 2, cmd.getPageSizeVal());
|
List<SummedCapacity> summedCapacitiesAtPod = _capacityDao.listCapacitiesGroupedByLevelAndType(capacityType, zoneId, podId, clusterId, 2, cmd.getPageSizeVal());
|
||||||
if(summedCapacitiesAtPod != null){
|
if (summedCapacitiesAtPod != null) {
|
||||||
summedCapacities.addAll(summedCapacitiesAtPod);
|
summedCapacities.addAll(summedCapacitiesAtPod);
|
||||||
}
|
}
|
||||||
List<SummedCapacity> summedCapacitiesForSecStorage = getSecStorageUsed(zoneId, capacityType);
|
List<SummedCapacity> summedCapacitiesForSecStorage = getSecStorageUsed(zoneId, capacityType);
|
||||||
if (summedCapacitiesForSecStorage != null){
|
if (summedCapacitiesForSecStorage != null) {
|
||||||
summedCapacities.addAll(summedCapacitiesForSecStorage);
|
summedCapacities.addAll(summedCapacitiesForSecStorage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Group by Cluster, capacity type
|
// Group by Cluster, capacity type
|
||||||
List<SummedCapacity> summedCapacitiesAtCluster = _capacityDao.listCapacitiesGroupedByLevelAndType(capacityType, zoneId, podId, clusterId, 3, cmd.getPageSizeVal());
|
List<SummedCapacity> summedCapacitiesAtCluster = _capacityDao.listCapacitiesGroupedByLevelAndType(capacityType, zoneId, podId, clusterId, 3, cmd.getPageSizeVal());
|
||||||
if(summedCapacitiesAtCluster != null){
|
if (summedCapacitiesAtCluster != null) {
|
||||||
summedCapacities.addAll(summedCapacitiesAtCluster);
|
summedCapacities.addAll(summedCapacitiesAtCluster);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Sort Capacities
|
// Sort Capacities
|
||||||
Collections.sort(summedCapacities, new Comparator<SummedCapacity>() {
|
Collections.sort(summedCapacities, new Comparator<SummedCapacity>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(SummedCapacity arg0, SummedCapacity arg1) {
|
public int compare(SummedCapacity arg0, SummedCapacity arg1) {
|
||||||
if (arg0.getPercentUsed() < arg1.getPercentUsed()) {
|
if (arg0.getPercentUsed() < arg1.getPercentUsed()) {
|
||||||
return 1;
|
return 1;
|
||||||
} else if (arg0.getPercentUsed()== arg1.getPercentUsed()) {
|
} else if (arg0.getPercentUsed() == arg1.getPercentUsed()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
@ -1990,17 +1986,16 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
List<CapacityVO> capacities = new ArrayList<CapacityVO>();
|
List<CapacityVO> capacities = new ArrayList<CapacityVO>();
|
||||||
|
|
||||||
|
|
||||||
Integer pageSize = null;
|
Integer pageSize = null;
|
||||||
try {
|
try {
|
||||||
pageSize = Integer.valueOf(cmd.getPageSizeVal().toString());
|
pageSize = Integer.valueOf(cmd.getPageSizeVal().toString());
|
||||||
} catch(IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new InvalidParameterValueException("pageSize " + cmd.getPageSizeVal() + " is out of Integer range is not supported for this call");
|
throw new InvalidParameterValueException("pageSize " + cmd.getPageSizeVal() + " is out of Integer range is not supported for this call");
|
||||||
}
|
}
|
||||||
|
|
||||||
summedCapacities = summedCapacities.subList(0, summedCapacities.size() < cmd.getPageSizeVal() ? summedCapacities.size() : pageSize);
|
summedCapacities = summedCapacities.subList(0, summedCapacities.size() < cmd.getPageSizeVal() ? summedCapacities.size() : pageSize);
|
||||||
for (SummedCapacity summedCapacity : summedCapacities){
|
for (SummedCapacity summedCapacity : summedCapacities) {
|
||||||
CapacityVO capacity = new CapacityVO(summedCapacity.getDataCenterId(), summedCapacity.getPodId() , summedCapacity.getClusterId(),
|
CapacityVO capacity = new CapacityVO(summedCapacity.getDataCenterId(), summedCapacity.getPodId(), summedCapacity.getClusterId(),
|
||||||
summedCapacity.getCapacityType(), summedCapacity.getPercentUsed());
|
summedCapacity.getCapacityType(), summedCapacity.getPercentUsed());
|
||||||
capacity.setUsedCapacity(summedCapacity.getUsedCapacity());
|
capacity.setUsedCapacity(summedCapacity.getUsedCapacity());
|
||||||
capacity.setTotalCapacity(summedCapacity.getTotalCapacity());
|
capacity.setTotalCapacity(summedCapacity.getTotalCapacity());
|
||||||
@ -2009,34 +2004,36 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
return capacities;
|
return capacities;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SummedCapacity> getSecStorageUsed(Long zoneId, Integer capacityType){
|
List<SummedCapacity> getSecStorageUsed(Long zoneId, Integer capacityType) {
|
||||||
if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE){
|
if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE) {
|
||||||
List<SummedCapacity> list = new ArrayList<SummedCapacity>();
|
List<SummedCapacity> list = new ArrayList<SummedCapacity>();
|
||||||
if (zoneId != null){
|
if (zoneId != null) {
|
||||||
DataCenterVO zone = ApiDBUtils.findZoneById(zoneId);
|
DataCenterVO zone = ApiDBUtils.findZoneById(zoneId);
|
||||||
if(zone == null || zone.getAllocationState() == AllocationState.Disabled){
|
if (zone == null || zone.getAllocationState() == AllocationState.Disabled) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
CapacityVO capacity = _storageMgr.getSecondaryStorageUsedStats(null, zoneId);
|
CapacityVO capacity = _storageMgr.getSecondaryStorageUsedStats(null, zoneId);
|
||||||
if (capacity.getTotalCapacity()!= 0){
|
if (capacity.getTotalCapacity() != 0) {
|
||||||
capacity.setUsedPercentage( capacity.getUsedCapacity() / capacity.getTotalCapacity() );
|
capacity.setUsedPercentage(capacity.getUsedCapacity() / capacity.getTotalCapacity());
|
||||||
}else {
|
} else {
|
||||||
capacity.setUsedPercentage(0);
|
capacity.setUsedPercentage(0);
|
||||||
}
|
}
|
||||||
SummedCapacity summedCapacity = new SummedCapacity(capacity.getUsedCapacity(), capacity.getTotalCapacity(), capacity.getUsedPercentage(), capacity.getCapacityType(), capacity.getDataCenterId(), capacity.getPodId(), capacity.getClusterId());
|
SummedCapacity summedCapacity = new SummedCapacity(capacity.getUsedCapacity(), capacity.getTotalCapacity(), capacity.getUsedPercentage(), capacity.getCapacityType(), capacity.getDataCenterId(),
|
||||||
list.add(summedCapacity) ;
|
capacity.getPodId(), capacity.getClusterId());
|
||||||
}else {
|
|
||||||
List<DataCenterVO> dcList = _dcDao.listEnabledZones();
|
|
||||||
for(DataCenterVO dc : dcList){
|
|
||||||
CapacityVO capacity = _storageMgr.getSecondaryStorageUsedStats(null, dc.getId());
|
|
||||||
if (capacity.getTotalCapacity()!= 0){
|
|
||||||
capacity.setUsedPercentage( capacity.getUsedCapacity() / capacity.getTotalCapacity() );
|
|
||||||
}else {
|
|
||||||
capacity.setUsedPercentage(0);
|
|
||||||
}
|
|
||||||
SummedCapacity summedCapacity = new SummedCapacity(capacity.getUsedCapacity(), capacity.getTotalCapacity(), capacity.getUsedPercentage(), capacity.getCapacityType(), capacity.getDataCenterId(), capacity.getPodId(), capacity.getClusterId());
|
|
||||||
list.add(summedCapacity);
|
list.add(summedCapacity);
|
||||||
}//End of for
|
} else {
|
||||||
|
List<DataCenterVO> dcList = _dcDao.listEnabledZones();
|
||||||
|
for (DataCenterVO dc : dcList) {
|
||||||
|
CapacityVO capacity = _storageMgr.getSecondaryStorageUsedStats(null, dc.getId());
|
||||||
|
if (capacity.getTotalCapacity() != 0) {
|
||||||
|
capacity.setUsedPercentage(capacity.getUsedCapacity() / capacity.getTotalCapacity());
|
||||||
|
} else {
|
||||||
|
capacity.setUsedPercentage(0);
|
||||||
|
}
|
||||||
|
SummedCapacity summedCapacity = new SummedCapacity(capacity.getUsedCapacity(), capacity.getTotalCapacity(), capacity.getUsedPercentage(), capacity.getCapacityType(), capacity.getDataCenterId(),
|
||||||
|
capacity.getPodId(), capacity.getClusterId());
|
||||||
|
list.add(summedCapacity);
|
||||||
|
}// End of for
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@ -2053,20 +2050,20 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
Boolean fetchLatest = cmd.getFetchLatest();
|
Boolean fetchLatest = cmd.getFetchLatest();
|
||||||
|
|
||||||
zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
|
zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
|
||||||
if (fetchLatest != null && fetchLatest){
|
if (fetchLatest != null && fetchLatest) {
|
||||||
_alertMgr.recalculateCapacity();
|
_alertMgr.recalculateCapacity();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SummedCapacity> summedCapacities = _capacityDao.findCapacityBy(capacityType, zoneId, podId, clusterId);
|
List<SummedCapacity> summedCapacities = _capacityDao.findCapacityBy(capacityType, zoneId, podId, clusterId);
|
||||||
List<CapacityVO> capacities = new ArrayList<CapacityVO>();
|
List<CapacityVO> capacities = new ArrayList<CapacityVO>();
|
||||||
|
|
||||||
for (SummedCapacity summedCapacity : summedCapacities){
|
for (SummedCapacity summedCapacity : summedCapacities) {
|
||||||
CapacityVO capacity = new CapacityVO(null, summedCapacity.getDataCenterId(), podId, clusterId,
|
CapacityVO capacity = new CapacityVO(null, summedCapacity.getDataCenterId(), podId, clusterId,
|
||||||
summedCapacity.getUsedCapacity() + summedCapacity.getReservedCapacity(),
|
summedCapacity.getUsedCapacity() + summedCapacity.getReservedCapacity(),
|
||||||
summedCapacity.getTotalCapacity(), summedCapacity.getCapacityType());
|
summedCapacity.getTotalCapacity(), summedCapacity.getCapacityType());
|
||||||
|
|
||||||
if ( summedCapacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU){
|
if (summedCapacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU) {
|
||||||
capacity.setTotalCapacity((long)(summedCapacity.getTotalCapacity() * ApiDBUtils.getCpuOverprovisioningFactor()));
|
capacity.setTotalCapacity((long) (summedCapacity.getTotalCapacity() * ApiDBUtils.getCpuOverprovisioningFactor()));
|
||||||
}
|
}
|
||||||
capacities.add(capacity);
|
capacities.add(capacity);
|
||||||
}
|
}
|
||||||
@ -2074,17 +2071,17 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
// op_host_Capacity contains only allocated stats and the real time stats are stored "in memory".
|
// op_host_Capacity contains only allocated stats and the real time stats are stored "in memory".
|
||||||
// Show Sec. Storage only when the api is invoked for the zone layer.
|
// Show Sec. Storage only when the api is invoked for the zone layer.
|
||||||
List<DataCenterVO> dcList = new ArrayList<DataCenterVO>();
|
List<DataCenterVO> dcList = new ArrayList<DataCenterVO>();
|
||||||
if (zoneId==null && podId==null && clusterId==null){
|
if (zoneId == null && podId == null && clusterId == null) {
|
||||||
dcList = ApiDBUtils.listZones();
|
dcList = ApiDBUtils.listZones();
|
||||||
}else if (zoneId != null){
|
} else if (zoneId != null) {
|
||||||
dcList.add(ApiDBUtils.findZoneById(zoneId));
|
dcList.add(ApiDBUtils.findZoneById(zoneId));
|
||||||
}else{
|
} else {
|
||||||
if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_STORAGE) {
|
if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_STORAGE) {
|
||||||
capacities.add(_storageMgr.getStoragePoolUsedStats(null, clusterId, podId, zoneId));
|
capacities.add(_storageMgr.getStoragePoolUsedStats(null, clusterId, podId, zoneId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(DataCenterVO zone : dcList){
|
for (DataCenterVO zone : dcList) {
|
||||||
zoneId = zone.getId();
|
zoneId = zone.getId();
|
||||||
if ((capacityType == null || capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE) && podId == null && clusterId == null) {
|
if ((capacityType == null || capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE) && podId == null && clusterId == null) {
|
||||||
capacities.add(_storageMgr.getSecondaryStorageUsedStats(null, zoneId));
|
capacities.add(_storageMgr.getSecondaryStorageUsedStats(null, zoneId));
|
||||||
@ -2108,9 +2105,9 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
return ((accountType == Account.ACCOUNT_TYPE_ADMIN) || (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) || (accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || (accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN));
|
return ((accountType == Account.ACCOUNT_TYPE_ADMIN) || (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) || (accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || (accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private List<DiskOfferingVO> searchDiskOfferingsInternal(Account account, Object name, Object id, Object keyword, Filter searchFilter) {
|
private List<DiskOfferingVO> searchDiskOfferingsInternal(Account account, Object name, Object id, Object keyword, Filter searchFilter) {
|
||||||
// it was decided to return all offerings for the user's domain, and everything above till root (for normal user or
|
// it was decided to return all offerings for the user's domain, and everything above till root (for normal user
|
||||||
|
// or
|
||||||
// domain admin)
|
// domain admin)
|
||||||
// list all offerings belonging to this domain, and all of its parents
|
// list all offerings belonging to this domain, and all of its parents
|
||||||
// check the parent, if not null, add offerings for that parent to list
|
// check the parent, if not null, add offerings for that parent to list
|
||||||
@ -2178,7 +2175,8 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
// The list method for offerings is being modified in accordance with discussion with Will/Kevin
|
// The list method for offerings is being modified in accordance with discussion with Will/Kevin
|
||||||
// For now, we will be listing the following based on the usertype
|
// For now, we will be listing the following based on the usertype
|
||||||
// 1. For root, we will list all offerings
|
// 1. For root, we will list all offerings
|
||||||
// 2. For domainAdmin and regular users, we will list everything in their domains+parent domains ... all the way till
|
// 2. For domainAdmin and regular users, we will list everything in their domains+parent domains ... all the way
|
||||||
|
// till
|
||||||
// root
|
// root
|
||||||
|
|
||||||
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
|
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
|
||||||
@ -2247,7 +2245,8 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
// FIXME: disk offerings should search back up the hierarchy for available disk offerings...
|
// FIXME: disk offerings should search back up the hierarchy for available disk offerings...
|
||||||
/*
|
/*
|
||||||
* if (domainId != null) { sc.setParameters("domainId", domainId); // //DomainVO domain =
|
* if (domainId != null) { sc.setParameters("domainId", domainId); // //DomainVO domain =
|
||||||
* _domainDao.findById((Long)domainId); // // I want to join on user_vm.domain_id = domain.id where domain.path like
|
* _domainDao.findById((Long)domainId); // // I want to join on user_vm.domain_id = domain.id where domain.path
|
||||||
|
* like
|
||||||
* 'foo%' //sc.setJoinParameters("domainSearch", "path", domain.getPath() + "%"); // }
|
* 'foo%' //sc.setJoinParameters("domainSearch", "path", domain.getPath() + "%"); // }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -2362,7 +2361,6 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
return _poolDao.search(sc, searchFilter);
|
return _poolDao.search(sc, searchFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AsyncJobVO> searchForAsyncJobs(ListAsyncJobsCmd cmd) {
|
public List<AsyncJobVO> searchForAsyncJobs(ListAsyncJobsCmd cmd) {
|
||||||
|
|
||||||
@ -2674,7 +2672,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
if (networks != null && !networks.isEmpty()) {
|
if (networks != null && !networks.isEmpty()) {
|
||||||
securityGroupsEnabled = true;
|
securityGroupsEnabled = true;
|
||||||
String elbEnabled = _configDao.getValue(Config.ElasticLoadBalancerEnabled.key());
|
String elbEnabled = _configDao.getValue(Config.ElasticLoadBalancerEnabled.key());
|
||||||
elasticLoadBalancerEnabled = elbEnabled==null?false:Boolean.parseBoolean(elbEnabled);
|
elasticLoadBalancerEnabled = elbEnabled == null ? false : Boolean.parseBoolean(elbEnabled);
|
||||||
if (elasticLoadBalancerEnabled) {
|
if (elasticLoadBalancerEnabled) {
|
||||||
String networkType = _configDao.getValue(Config.ElasticLoadBalancerNetwork.key());
|
String networkType = _configDao.getValue(Config.ElasticLoadBalancerNetwork.key());
|
||||||
if (networkType != null)
|
if (networkType != null)
|
||||||
@ -2717,7 +2715,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
throw new InvalidParameterValueException("Unable to find volume with id " + volumeId);
|
throw new InvalidParameterValueException("Unable to find volume with id " + volumeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
//perform permission check
|
// perform permission check
|
||||||
_accountMgr.checkAccess(account, null, true, volume);
|
_accountMgr.checkAccess(account, null, true, volume);
|
||||||
|
|
||||||
if (_dcDao.findById(zoneId) == null) {
|
if (_dcDao.findById(zoneId) == null) {
|
||||||
@ -2732,12 +2730,14 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
throw new PermissionDeniedException("Invalid state of the volume with ID: " + volumeId + ". It should be either detached or the VM should be in stopped state.");
|
throw new PermissionDeniedException("Invalid state of the volume with ID: " + volumeId + ". It should be either detached or the VM should be in stopped state.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (volume.getVolumeType() != Volume.Type.DATADISK){ //Datadisk dont have any template dependence.
|
if (volume.getVolumeType() != Volume.Type.DATADISK) { // Datadisk dont have any template dependence.
|
||||||
|
|
||||||
VMTemplateVO template = ApiDBUtils.findTemplateById(volume.getTemplateId());
|
VMTemplateVO template = ApiDBUtils.findTemplateById(volume.getTemplateId());
|
||||||
if (template != null){ //For ISO based volumes template = null and we allow extraction of all ISO based volumes
|
if (template != null) { // For ISO based volumes template = null and we allow extraction of all ISO based
|
||||||
|
// volumes
|
||||||
boolean isExtractable = template.isExtractable() && template.getTemplateType() != Storage.TemplateType.SYSTEM;
|
boolean isExtractable = template.isExtractable() && template.getTemplateType() != Storage.TemplateType.SYSTEM;
|
||||||
if (!isExtractable && account != null && account.getType() != Account.ACCOUNT_TYPE_ADMIN) { // Global admins are always allowed to extract
|
if (!isExtractable && account != null && account.getType() != Account.ACCOUNT_TYPE_ADMIN) { // Global
|
||||||
|
// admins are always allowed to extract
|
||||||
throw new PermissionDeniedException("The volume:" + volumeId + " is not allowed to be extracted");
|
throw new PermissionDeniedException("The volume:" + volumeId + " is not allowed to be extracted");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2848,23 +2848,22 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getFormatForPool(StoragePoolVO pool){
|
private String getFormatForPool(StoragePoolVO pool) {
|
||||||
ClusterVO cluster = ApiDBUtils.findClusterById(pool.getClusterId());
|
ClusterVO cluster = ApiDBUtils.findClusterById(pool.getClusterId());
|
||||||
|
|
||||||
if (cluster.getHypervisorType() == HypervisorType.XenServer){
|
if (cluster.getHypervisorType() == HypervisorType.XenServer) {
|
||||||
return "vhd";
|
return "vhd";
|
||||||
}else if (cluster.getHypervisorType() == HypervisorType.KVM){
|
} else if (cluster.getHypervisorType() == HypervisorType.KVM) {
|
||||||
return "qcow2";
|
return "qcow2";
|
||||||
}else if (cluster.getHypervisorType() == HypervisorType.VMware){
|
} else if (cluster.getHypervisorType() == HypervisorType.VMware) {
|
||||||
return "ova";
|
return "ova";
|
||||||
}else if (cluster.getHypervisorType() == HypervisorType.Ovm){
|
} else if (cluster.getHypervisorType() == HypervisorType.Ovm) {
|
||||||
return "raw";
|
return "raw";
|
||||||
}else{
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InstanceGroupVO updateVmGroup(UpdateVMGroupCmd cmd) {
|
public InstanceGroupVO updateVmGroup(UpdateVMGroupCmd cmd) {
|
||||||
Account caller = UserContext.current().getCaller();
|
Account caller = UserContext.current().getCaller();
|
||||||
@ -3002,7 +3001,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd.getPrivateKey() != null &&!_ksMgr.validateCertificate(cmd.getCertificate(), cmd.getPrivateKey(), cmd.getDomainSuffix())) {
|
if (cmd.getPrivateKey() != null && !_ksMgr.validateCertificate(cmd.getCertificate(), cmd.getPrivateKey(), cmd.getDomainSuffix())) {
|
||||||
throw new InvalidParameterValueException("Failed to pass certificate validation check");
|
throw new InvalidParameterValueException("Failed to pass certificate validation check");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3114,7 +3113,8 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
_accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
|
_accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
|
||||||
Long domainId = domainIdRecursiveListProject.first();
|
Long domainId = domainIdRecursiveListProject.first();
|
||||||
Boolean isRecursive = domainIdRecursiveListProject.second();
|
Boolean isRecursive = domainIdRecursiveListProject.second();
|
||||||
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); SearchBuilder<SSHKeyPairVO> sb = _sshKeyPairDao.createSearchBuilder();
|
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
|
||||||
|
SearchBuilder<SSHKeyPairVO> sb = _sshKeyPairDao.createSearchBuilder();
|
||||||
_accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
|
_accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
|
||||||
Filter searchFilter = new Filter(SSHKeyPairVO.class, "id", false, cmd.getStartIndex(), cmd.getPageSizeVal());
|
Filter searchFilter = new Filter(SSHKeyPairVO.class, "id", false, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||||
|
|
||||||
@ -3200,19 +3200,19 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
HostVO host = _hostDao.findById(cmd.getHostId());
|
HostVO host = _hostDao.findById(cmd.getHostId());
|
||||||
if (host != null && host.getHypervisorType() == HypervisorType.XenServer) {
|
if (host != null && host.getHypervisorType() == HypervisorType.XenServer) {
|
||||||
throw new InvalidParameterValueException("You should provide cluster id for Xenserver cluster.");
|
throw new InvalidParameterValueException("You should provide cluster id for Xenserver cluster.");
|
||||||
}else {
|
} else {
|
||||||
throw new InvalidParameterValueException("This operation is not supported for this hypervisor type");
|
throw new InvalidParameterValueException("This operation is not supported for this hypervisor type");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
ClusterVO cluster = ApiDBUtils.findClusterById(cmd.getClusterId());
|
ClusterVO cluster = ApiDBUtils.findClusterById(cmd.getClusterId());
|
||||||
if (cluster == null || cluster.getHypervisorType() != HypervisorType.XenServer){
|
if (cluster == null || cluster.getHypervisorType() != HypervisorType.XenServer) {
|
||||||
throw new InvalidParameterValueException("This operation is not supported for this hypervisor type");
|
throw new InvalidParameterValueException("This operation is not supported for this hypervisor type");
|
||||||
}
|
}
|
||||||
// get all the hosts in this cluster
|
// get all the hosts in this cluster
|
||||||
List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(cmd.getClusterId());
|
List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(cmd.getClusterId());
|
||||||
Transaction txn = Transaction.currentTxn();
|
Transaction txn = Transaction.currentTxn();
|
||||||
try{
|
try {
|
||||||
txn.start();
|
txn.start();
|
||||||
for (HostVO h : hosts) {
|
for (HostVO h : hosts) {
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
@ -3232,7 +3232,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
}
|
}
|
||||||
txn.commit();
|
txn.commit();
|
||||||
// if hypervisor is xenserver then we update it in CitrixResourceBase
|
// if hypervisor is xenserver then we update it in CitrixResourceBase
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
txn.rollback();
|
txn.rollback();
|
||||||
throw new CloudRuntimeException("Failed to update password " + e.getMessage());
|
throw new CloudRuntimeException("Failed to update password " + e.getMessage());
|
||||||
}
|
}
|
||||||
@ -3242,14 +3242,14 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] listEventTypes(){
|
public String[] listEventTypes() {
|
||||||
Object eventObj = new EventTypes();
|
Object eventObj = new EventTypes();
|
||||||
Class<EventTypes> c = EventTypes.class;
|
Class<EventTypes> c = EventTypes.class;
|
||||||
Field[] fields = c.getDeclaredFields();
|
Field[] fields = c.getDeclaredFields();
|
||||||
String[] eventTypes = new String[fields.length];
|
String[] eventTypes = new String[fields.length];
|
||||||
try {
|
try {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(Field field : fields){
|
for (Field field : fields) {
|
||||||
eventTypes[i++] = field.get(eventObj).toString();
|
eventTypes[i++] = field.get(eventObj).toString();
|
||||||
}
|
}
|
||||||
return eventTypes;
|
return eventTypes;
|
||||||
@ -3262,7 +3262,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<HypervisorCapabilitiesVO> listHypervisorCapabilities(Long id, HypervisorType hypervisorType, String keyword, Long startIndex, Long pageSizeVal){
|
public List<HypervisorCapabilitiesVO> listHypervisorCapabilities(Long id, HypervisorType hypervisorType, String keyword, Long startIndex, Long pageSizeVal) {
|
||||||
Filter searchFilter = new Filter(HypervisorCapabilitiesVO.class, "id", true, startIndex, pageSizeVal);
|
Filter searchFilter = new Filter(HypervisorCapabilitiesVO.class, "id", true, startIndex, pageSizeVal);
|
||||||
SearchCriteria<HypervisorCapabilitiesVO> sc = _hypervisorCapabilitiesDao.createSearchCriteria();
|
SearchCriteria<HypervisorCapabilitiesVO> sc = _hypervisorCapabilitiesDao.createSearchCriteria();
|
||||||
|
|
||||||
@ -3285,10 +3285,10 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HypervisorCapabilities updateHypervisorCapabilities(Long id, Long maxGuestsLimit, Boolean securityGroupEnabled){
|
public HypervisorCapabilities updateHypervisorCapabilities(Long id, Long maxGuestsLimit, Boolean securityGroupEnabled) {
|
||||||
HypervisorCapabilitiesVO hpvCapabilities = _hypervisorCapabilitiesDao.findById(id, true);
|
HypervisorCapabilitiesVO hpvCapabilities = _hypervisorCapabilitiesDao.findById(id, true);
|
||||||
|
|
||||||
if(hpvCapabilities == null){
|
if (hpvCapabilities == null) {
|
||||||
throw new InvalidParameterValueException("unable to find the hypervisor capabilities " + id);
|
throw new InvalidParameterValueException("unable to find the hypervisor capabilities " + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3297,18 +3297,17 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
return hpvCapabilities;
|
return hpvCapabilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
hpvCapabilities = _hypervisorCapabilitiesDao.createForUpdate(id);
|
hpvCapabilities = _hypervisorCapabilitiesDao.createForUpdate(id);
|
||||||
|
|
||||||
if (maxGuestsLimit != null){
|
if (maxGuestsLimit != null) {
|
||||||
hpvCapabilities.setMaxGuestsLimit(maxGuestsLimit);
|
hpvCapabilities.setMaxGuestsLimit(maxGuestsLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (securityGroupEnabled != null){
|
if (securityGroupEnabled != null) {
|
||||||
hpvCapabilities.setSecurityGroupEnabled(securityGroupEnabled);
|
hpvCapabilities.setSecurityGroupEnabled(securityGroupEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_hypervisorCapabilitiesDao.update(id, hpvCapabilities)){
|
if (_hypervisorCapabilitiesDao.update(id, hpvCapabilities)) {
|
||||||
hpvCapabilities = _hypervisorCapabilitiesDao.findById(id);
|
hpvCapabilities = _hypervisorCapabilitiesDao.findById(id);
|
||||||
UserContext.current().setEventDetails("Hypervisor Capabilities id=" + hpvCapabilities.getId());
|
UserContext.current().setEventDetails("Hypervisor Capabilities id=" + hpvCapabilities.getId());
|
||||||
return hpvCapabilities;
|
return hpvCapabilities;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* This software is licensed under the GNU General Public License v3 or later.
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
*
|
*
|
||||||
@ -50,13 +50,14 @@ import org.w3c.dom.NodeList;
|
|||||||
|
|
||||||
import com.cloud.test.utils.UtilsForTest;
|
import com.cloud.test.utils.UtilsForTest;
|
||||||
|
|
||||||
public class ApiCommand{
|
public class ApiCommand {
|
||||||
public static final Logger s_logger = Logger.getLogger(ApiCommand.class.getName());
|
public static final Logger s_logger = Logger.getLogger(ApiCommand.class.getName());
|
||||||
public static enum CommandType{
|
|
||||||
|
public static enum CommandType {
|
||||||
HTTP, MYSQL, SCRIPT;
|
HTTP, MYSQL, SCRIPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum ResponseType{
|
public static enum ResponseType {
|
||||||
ERROR, EMPTY;
|
ERROR, EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +69,6 @@ public class ApiCommand{
|
|||||||
private CommandType commandType;
|
private CommandType commandType;
|
||||||
private ResponseType responseType;
|
private ResponseType responseType;
|
||||||
|
|
||||||
|
|
||||||
private TreeMap<String, String> urlParam;
|
private TreeMap<String, String> urlParam;
|
||||||
private HashMap<String, String> verifyParam = new HashMap<String, String>();;
|
private HashMap<String, String> verifyParam = new HashMap<String, String>();;
|
||||||
private HashMap<String, String> setParam = new HashMap<String, String>();;
|
private HashMap<String, String> setParam = new HashMap<String, String>();;
|
||||||
@ -83,8 +83,7 @@ public class ApiCommand{
|
|||||||
private boolean required = false;
|
private boolean required = false;
|
||||||
private ResultSet result;
|
private ResultSet result;
|
||||||
|
|
||||||
|
public ApiCommand(Element fstElmnt, HashMap<String, String> param, HashMap<String, String> commands) {
|
||||||
public ApiCommand(Element fstElmnt, HashMap<String, String> param, HashMap<String, String> commands){
|
|
||||||
this.setXmlCommand(fstElmnt);
|
this.setXmlCommand(fstElmnt);
|
||||||
this.setCommandName();
|
this.setCommandName();
|
||||||
this.setResponseType();
|
this.setResponseType();
|
||||||
@ -98,6 +97,7 @@ public class ApiCommand{
|
|||||||
String async = commands.get(this.getName());
|
String async = commands.get(this.getName());
|
||||||
if (async != null && async.equals("yes")) {
|
if (async != null && async.equals("yes")) {
|
||||||
this.isAsync = true;
|
this.isAsync = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ public class ApiCommand{
|
|||||||
this.xmlCommand = xmlCommand;
|
this.xmlCommand = xmlCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
//================FOLLOWING METHODS USE INPUT XML FILE=======================//
|
// ================FOLLOWING METHODS USE INPUT XML FILE=======================//
|
||||||
public void setCommandName() {
|
public void setCommandName() {
|
||||||
NodeList commandName = this.xmlCommand.getElementsByTagName("name");
|
NodeList commandName = this.xmlCommand.getElementsByTagName("name");
|
||||||
Element commandElmnt = (Element) commandName.item(0);
|
Element commandElmnt = (Element) commandName.item(0);
|
||||||
@ -186,19 +186,19 @@ public class ApiCommand{
|
|||||||
|
|
||||||
public void setUrlParam(HashMap<String, String> param) {
|
public void setUrlParam(HashMap<String, String> param) {
|
||||||
this.urlParam = new TreeMap<String, String>();
|
this.urlParam = new TreeMap<String, String>();
|
||||||
NodeList parameterLst= this.xmlCommand.getElementsByTagName("parameters");
|
NodeList parameterLst = this.xmlCommand.getElementsByTagName("parameters");
|
||||||
if (parameterLst != null ) {
|
if (parameterLst != null) {
|
||||||
for (int j=0; j<parameterLst.getLength(); j++) {
|
for (int j = 0; j < parameterLst.getLength(); j++) {
|
||||||
Element parameterElement = (Element) parameterLst.item(j);
|
Element parameterElement = (Element) parameterLst.item(j);
|
||||||
NodeList itemLst = parameterElement.getElementsByTagName("item");
|
NodeList itemLst = parameterElement.getElementsByTagName("item");
|
||||||
for (int k=0; k<itemLst.getLength(); k++) {
|
for (int k = 0; k < itemLst.getLength(); k++) {
|
||||||
Node item=itemLst.item(k);
|
Node item = itemLst.item(k);
|
||||||
if (item.getNodeType() == Node.ELEMENT_NODE) {
|
if (item.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
Element itemElement= (Element) item;
|
Element itemElement = (Element) item;
|
||||||
NodeList itemName = itemElement.getElementsByTagName("name");
|
NodeList itemName = itemElement.getElementsByTagName("name");
|
||||||
Element itemNameElement = (Element) itemName.item(0);
|
Element itemNameElement = (Element) itemName.item(0);
|
||||||
|
|
||||||
//get value
|
// get value
|
||||||
Element itemValueElement = null;
|
Element itemValueElement = null;
|
||||||
if ((itemElement.getElementsByTagName("value") != null) && (itemElement.getElementsByTagName("value").getLength() != 0)) {
|
if ((itemElement.getElementsByTagName("value") != null) && (itemElement.getElementsByTagName("value").getLength() != 0)) {
|
||||||
NodeList itemValue = itemElement.getElementsByTagName("value");
|
NodeList itemValue = itemElement.getElementsByTagName("value");
|
||||||
@ -206,7 +206,7 @@ public class ApiCommand{
|
|||||||
}
|
}
|
||||||
|
|
||||||
Element itemParamElement = null;
|
Element itemParamElement = null;
|
||||||
//getparam
|
// getparam
|
||||||
if ((itemElement.getElementsByTagName("param") != null) && (itemElement.getElementsByTagName("param").getLength() != 0)) {
|
if ((itemElement.getElementsByTagName("param") != null) && (itemElement.getElementsByTagName("param").getLength() != 0)) {
|
||||||
NodeList itemParam = itemElement.getElementsByTagName("param");
|
NodeList itemParam = itemElement.getElementsByTagName("param");
|
||||||
itemParamElement = (Element) itemParam.item(0);
|
itemParamElement = (Element) itemParam.item(0);
|
||||||
@ -215,18 +215,18 @@ public class ApiCommand{
|
|||||||
if ((itemElement.getAttribute("getparam").equals("true")) && (itemParamElement != null)) {
|
if ((itemElement.getAttribute("getparam").equals("true")) && (itemParamElement != null)) {
|
||||||
this.urlParam.put(itemNameElement.getTextContent(), param.get(itemParamElement.getTextContent()));
|
this.urlParam.put(itemNameElement.getTextContent(), param.get(itemParamElement.getTextContent()));
|
||||||
}
|
}
|
||||||
else if (itemValueElement != null){
|
else if (itemValueElement != null) {
|
||||||
this.urlParam.put(itemNameElement.getTextContent(), itemValueElement.getTextContent());
|
this.urlParam.put(itemNameElement.getTextContent(), itemValueElement.getTextContent());
|
||||||
} else if (itemElement.getAttribute("random").equals("true")) {
|
} else if (itemElement.getAttribute("random").equals("true")) {
|
||||||
Random ran = new Random();
|
Random ran = new Random();
|
||||||
String randomString = Math.abs(ran.nextInt())+ "-randomName";
|
String randomString = Math.abs(ran.nextInt()) + "-randomName";
|
||||||
this.urlParam.put(itemNameElement.getTextContent(), randomString);
|
this.urlParam.put(itemNameElement.getTextContent(), randomString);
|
||||||
if ((itemElement.getAttribute("setparam").equals("true")) && (itemParamElement != null)) {
|
if ((itemElement.getAttribute("setparam").equals("true")) && (itemParamElement != null)) {
|
||||||
param.put(itemParamElement.getTextContent(), randomString);
|
param.put(itemParamElement.getTextContent(), randomString);
|
||||||
}
|
}
|
||||||
} else if (itemElement.getAttribute("randomnumber").equals("true")) {
|
} else if (itemElement.getAttribute("randomnumber").equals("true")) {
|
||||||
Random ran = new Random();
|
Random ran = new Random();
|
||||||
Integer randomNumber = (Integer)Math.abs(ran.nextInt(65535));
|
Integer randomNumber = (Integer) Math.abs(ran.nextInt(65535));
|
||||||
this.urlParam.put(itemNameElement.getTextContent(), randomNumber.toString());
|
this.urlParam.put(itemNameElement.getTextContent(), randomNumber.toString());
|
||||||
if ((itemElement.getAttribute("setparam").equals("true")) && (itemParamElement != null)) {
|
if ((itemElement.getAttribute("setparam").equals("true")) && (itemParamElement != null)) {
|
||||||
param.put(itemParamElement.getTextContent(), randomNumber.toString());
|
param.put(itemParamElement.getTextContent(), randomNumber.toString());
|
||||||
@ -238,8 +238,7 @@ public class ApiCommand{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set command URL
|
||||||
//Set command URL
|
|
||||||
public void setCommand(HashMap<String, String> param) {
|
public void setCommand(HashMap<String, String> param) {
|
||||||
|
|
||||||
if (this.getCommandType() == CommandType.SCRIPT) {
|
if (this.getCommandType() == CommandType.SCRIPT) {
|
||||||
@ -247,7 +246,7 @@ public class ApiCommand{
|
|||||||
Set<?> c = this.urlParam.entrySet();
|
Set<?> c = this.urlParam.entrySet();
|
||||||
Iterator<?> it = c.iterator();
|
Iterator<?> it = c.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||||
String key = (String) me.getKey();
|
String key = (String) me.getKey();
|
||||||
String value = (String) me.getValue();
|
String value = (String) me.getValue();
|
||||||
try {
|
try {
|
||||||
@ -262,7 +261,7 @@ public class ApiCommand{
|
|||||||
Set<?> c = this.urlParam.entrySet();
|
Set<?> c = this.urlParam.entrySet();
|
||||||
Iterator<?> it = c.iterator();
|
Iterator<?> it = c.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||||
String key = (String) me.getKey();
|
String key = (String) me.getKey();
|
||||||
String value = (String) me.getValue();
|
String value = (String) me.getValue();
|
||||||
try {
|
try {
|
||||||
@ -275,12 +274,12 @@ public class ApiCommand{
|
|||||||
s_logger.info("The command is " + this.command);
|
s_logger.info("The command is " + this.command);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if ((param.get("apikey") == null) || (param.get("secretkey")==null) || (this.isUserCommand == false)) {
|
if ((param.get("apikey") == null) || (param.get("secretkey") == null) || (this.isUserCommand == false)) {
|
||||||
String temp = this.host + ":8096/?command="+ this.commandName;
|
String temp = this.host + ":8096/?command=" + this.commandName;
|
||||||
Set<?> c = this.urlParam.entrySet();
|
Set<?> c = this.urlParam.entrySet();
|
||||||
Iterator<?> it = c.iterator();
|
Iterator<?> it = c.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||||
String key = (String) me.getKey();
|
String key = (String) me.getKey();
|
||||||
String value = (String) me.getValue();
|
String value = (String) me.getValue();
|
||||||
try {
|
try {
|
||||||
@ -299,11 +298,11 @@ public class ApiCommand{
|
|||||||
this.urlParam.put("apikey", apiKey);
|
this.urlParam.put("apikey", apiKey);
|
||||||
this.urlParam.put("command", this.commandName);
|
this.urlParam.put("command", this.commandName);
|
||||||
|
|
||||||
//sort url hash map by key
|
// sort url hash map by key
|
||||||
Set<?> c = this.urlParam.entrySet();
|
Set<?> c = this.urlParam.entrySet();
|
||||||
Iterator<?> it = c.iterator();
|
Iterator<?> it = c.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||||
String key = (String) me.getKey();
|
String key = (String) me.getKey();
|
||||||
String value = (String) me.getValue();
|
String value = (String) me.getValue();
|
||||||
try {
|
try {
|
||||||
@ -313,7 +312,7 @@ public class ApiCommand{
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
temp = temp.substring(0, temp.length()-1 );
|
temp = temp.substring(0, temp.length() - 1);
|
||||||
String requestToSign = temp.toLowerCase();
|
String requestToSign = temp.toLowerCase();
|
||||||
String signature = UtilsForTest.signRequest(requestToSign, secretKey);
|
String signature = UtilsForTest.signRequest(requestToSign, secretKey);
|
||||||
String encodedSignature = "";
|
String encodedSignature = "";
|
||||||
@ -328,9 +327,9 @@ public class ApiCommand{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setVerifyParam(HashMap<String, String> param) {
|
public void setVerifyParam(HashMap<String, String> param) {
|
||||||
NodeList returnLst= this.xmlCommand.getElementsByTagName("returnvalue");
|
NodeList returnLst = this.xmlCommand.getElementsByTagName("returnvalue");
|
||||||
if (returnLst != null ) {
|
if (returnLst != null) {
|
||||||
for (int m=0; m<returnLst.getLength(); m++) {
|
for (int m = 0; m < returnLst.getLength(); m++) {
|
||||||
Element returnElement = (Element) returnLst.item(m);
|
Element returnElement = (Element) returnLst.item(m);
|
||||||
if (returnElement.getAttribute("list").equals("true")) {
|
if (returnElement.getAttribute("list").equals("true")) {
|
||||||
this.list = true;
|
this.list = true;
|
||||||
@ -345,21 +344,21 @@ public class ApiCommand{
|
|||||||
|
|
||||||
NodeList itemLst1 = returnElement.getElementsByTagName("item");
|
NodeList itemLst1 = returnElement.getElementsByTagName("item");
|
||||||
if (itemLst1 != null) {
|
if (itemLst1 != null) {
|
||||||
for (int n=0; n<itemLst1.getLength(); n++) {
|
for (int n = 0; n < itemLst1.getLength(); n++) {
|
||||||
Node item=itemLst1.item(n);
|
Node item = itemLst1.item(n);
|
||||||
if (item.getNodeType() == Node.ELEMENT_NODE) {
|
if (item.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
Element itemElement= (Element) item;
|
Element itemElement = (Element) item;
|
||||||
//get parameter name
|
// get parameter name
|
||||||
NodeList itemName = itemElement.getElementsByTagName("name");
|
NodeList itemName = itemElement.getElementsByTagName("name");
|
||||||
Element itemNameElement = (Element) itemName.item(0);
|
Element itemNameElement = (Element) itemName.item(0);
|
||||||
|
|
||||||
//Get parameters for future use
|
// Get parameters for future use
|
||||||
if (itemElement.getAttribute("setparam").equals("true")) {
|
if (itemElement.getAttribute("setparam").equals("true")) {
|
||||||
NodeList itemVariable = itemElement.getElementsByTagName("param");
|
NodeList itemVariable = itemElement.getElementsByTagName("param");
|
||||||
Element itemVariableElement = (Element) itemVariable.item(0);
|
Element itemVariableElement = (Element) itemVariable.item(0);
|
||||||
setParam.put(itemVariableElement.getTextContent(), itemNameElement.getTextContent());
|
setParam.put(itemVariableElement.getTextContent(), itemNameElement.getTextContent());
|
||||||
this.required = true;
|
this.required = true;
|
||||||
} else if (itemElement.getAttribute("getparam").equals("true")){
|
} else if (itemElement.getAttribute("getparam").equals("true")) {
|
||||||
NodeList itemVariable = itemElement.getElementsByTagName("param");
|
NodeList itemVariable = itemElement.getElementsByTagName("param");
|
||||||
Element itemVariableElement = (Element) itemVariable.item(0);
|
Element itemVariableElement = (Element) itemVariable.item(0);
|
||||||
this.verifyParam.put(itemNameElement.getTextContent(), param.get(itemVariableElement.getTextContent()));
|
this.verifyParam.put(itemNameElement.getTextContent(), param.get(itemVariableElement.getTextContent()));
|
||||||
@ -377,13 +376,12 @@ public class ApiCommand{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getResponseCode() {
|
public int getResponseCode() {
|
||||||
return responseCode;
|
return responseCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Send api command to the server
|
// Send api command to the server
|
||||||
public void sendCommand(HttpClient client, Connection conn){
|
public void sendCommand(HttpClient client, Connection conn) {
|
||||||
if (TestCaseEngine._printUrl == true)
|
if (TestCaseEngine._printUrl == true)
|
||||||
{
|
{
|
||||||
s_logger.info("url is " + this.command);
|
s_logger.info("url is " + this.command);
|
||||||
@ -430,7 +428,7 @@ public class ApiCommand{
|
|||||||
this.responseBody = doc.getDocumentElement();
|
this.responseBody = doc.getDocumentElement();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//get async job result
|
// get async job result
|
||||||
Element jobTag = (Element) doc.getDocumentElement().getElementsByTagName("jobid").item(0);
|
Element jobTag = (Element) doc.getDocumentElement().getElementsByTagName("jobid").item(0);
|
||||||
String jobId = jobTag.getTextContent();
|
String jobId = jobTag.getTextContent();
|
||||||
Element responseBodyAsyncEl = queryAsyncJobResult(jobId);
|
Element responseBodyAsyncEl = queryAsyncJobResult(jobId);
|
||||||
@ -439,11 +437,12 @@ public class ApiCommand{
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.responseBody = responseBodyAsyncEl;
|
this.responseBody = responseBodyAsyncEl;
|
||||||
//get status of the job
|
// get status of the job
|
||||||
Element jobStatusTag = (Element)responseBodyAsyncEl.getElementsByTagName("jobstatus").item(0);
|
Element jobStatusTag = (Element) responseBodyAsyncEl.getElementsByTagName("jobstatus").item(0);
|
||||||
String jobStatus = jobStatusTag.getTextContent();
|
String jobStatus = jobStatusTag.getTextContent();
|
||||||
if (!jobStatus.equals("1")) { // Need to modify with different error codes for jobAsync results
|
if (!jobStatus.equals("1")) { // Need to modify with different error codes for jobAsync
|
||||||
//set fake response code by now
|
// results
|
||||||
|
// set fake response code by now
|
||||||
this.responseCode = 400;
|
this.responseCode = 400;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -461,18 +460,17 @@ public class ApiCommand{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//verify if response is empty (contains only root element)
|
// verify if response is empty (contains only root element)
|
||||||
public boolean isEmpty(){
|
public boolean isEmpty() {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
if (!this.responseBody.hasChildNodes())
|
if (!this.responseBody.hasChildNodes())
|
||||||
result = true;
|
result = true;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ================FOLLOWING METHODS USE RETURN XML FILE=======================//
|
||||||
|
|
||||||
//================FOLLOWING METHODS USE RETURN XML FILE=======================//
|
public boolean setParam(HashMap<String, String> param) {
|
||||||
|
|
||||||
public boolean setParam (HashMap<String, String> param) {
|
|
||||||
if ((this.responseBody == null) && (this.commandType == CommandType.HTTP)) {
|
if ((this.responseBody == null) && (this.commandType == CommandType.HTTP)) {
|
||||||
s_logger.error("Response body is empty");
|
s_logger.error("Response body is empty");
|
||||||
return false;
|
return false;
|
||||||
@ -483,7 +481,7 @@ public class ApiCommand{
|
|||||||
Set<?> set = this.setParam.entrySet();
|
Set<?> set = this.setParam.entrySet();
|
||||||
Iterator<?> it = set.iterator();
|
Iterator<?> it = set.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||||
String key = (String) me.getKey();
|
String key = (String) me.getKey();
|
||||||
String value = (String) me.getValue();
|
String value = (String) me.getValue();
|
||||||
try {
|
try {
|
||||||
@ -508,13 +506,13 @@ public class ApiCommand{
|
|||||||
Iterator<?> it = set.iterator();
|
Iterator<?> it = set.iterator();
|
||||||
|
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||||
String key = (String) me.getKey();
|
String key = (String) me.getKey();
|
||||||
String value = (String) me.getValue();
|
String value = (String) me.getValue();
|
||||||
//set parameters needed for the future use
|
// set parameters needed for the future use
|
||||||
NodeList itemName = this.responseBody.getElementsByTagName(value);
|
NodeList itemName = this.responseBody.getElementsByTagName(value);
|
||||||
if ((itemName != null) && (itemName.getLength() != 0)) {
|
if ((itemName != null) && (itemName.getLength() != 0)) {
|
||||||
for (int i=0; i < itemName.getLength(); i++) {
|
for (int i = 0; i < itemName.getLength(); i++) {
|
||||||
Element itemNameElement = (Element) itemName.item(i);
|
Element itemNameElement = (Element) itemName.item(i);
|
||||||
if (itemNameElement.getChildNodes().getLength() <= 1) {
|
if (itemNameElement.getChildNodes().getLength() <= 1) {
|
||||||
param.put(key, itemNameElement.getTextContent());
|
param.put(key, itemNameElement.getTextContent());
|
||||||
@ -537,7 +535,7 @@ public class ApiCommand{
|
|||||||
Element fstElmnt = (Element) requiredNode;
|
Element fstElmnt = (Element) requiredNode;
|
||||||
|
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||||
String key = (String) me.getKey();
|
String key = (String) me.getKey();
|
||||||
String value = (String) me.getValue();
|
String value = (String) me.getValue();
|
||||||
NodeList itemName = fstElmnt.getElementsByTagName(value);
|
NodeList itemName = fstElmnt.getElementsByTagName(value);
|
||||||
@ -570,7 +568,7 @@ public class ApiCommand{
|
|||||||
Iterator<?> it = set.iterator();
|
Iterator<?> it = set.iterator();
|
||||||
|
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||||
String key = (String) me.getKey();
|
String key = (String) me.getKey();
|
||||||
String value = (String) me.getValue();
|
String value = (String) me.getValue();
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
@ -584,21 +582,21 @@ public class ApiCommand{
|
|||||||
if (itemNameElement.hasChildNodes()) {
|
if (itemNameElement.hasChildNodes()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( !(verifyParam.get(key).equals("no value")) && !(itemNameElement.getTextContent().equals(verifyParam.get(key)))){
|
if (!(verifyParam.get(key).equals("no value")) && !(itemNameElement.getTextContent().equals(verifyParam.get(key)))) {
|
||||||
s_logger.error("Incorrect value for the following tag: " + key + ". Expected value is " + verifyParam.get(key) + " while actual value is " + itemNameElement.getTextContent());
|
s_logger.error("Incorrect value for the following tag: " + key + ". Expected value is " + verifyParam.get(key) + " while actual value is " + itemNameElement.getTextContent());
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
s_logger.error("Following xml element is missing in the response: " + key);
|
s_logger.error("Following xml element is missing in the response: " + key);
|
||||||
result=false;
|
result = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//for multiple elements
|
// for multiple elements
|
||||||
else {
|
else {
|
||||||
Set<?> set = verifyParam.entrySet();
|
Set<?> set = verifyParam.entrySet();
|
||||||
Iterator<?> it = set.iterator();
|
Iterator<?> it = set.iterator();
|
||||||
//get list element specified by id
|
// get list element specified by id
|
||||||
NodeList returnLst = this.responseBody.getElementsByTagName(this.listName.getTextContent());
|
NodeList returnLst = this.responseBody.getElementsByTagName(this.listName.getTextContent());
|
||||||
Node requiredNode = returnLst.item(Integer.parseInt(this.listId.getTextContent()));
|
Node requiredNode = returnLst.item(Integer.parseInt(this.listId.getTextContent()));
|
||||||
|
|
||||||
@ -606,7 +604,7 @@ public class ApiCommand{
|
|||||||
Element fstElmnt = (Element) requiredNode;
|
Element fstElmnt = (Element) requiredNode;
|
||||||
|
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||||
String key = (String) me.getKey();
|
String key = (String) me.getKey();
|
||||||
String value = (String) me.getValue();
|
String value = (String) me.getValue();
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
@ -616,7 +614,7 @@ public class ApiCommand{
|
|||||||
NodeList itemName = fstElmnt.getElementsByTagName(key);
|
NodeList itemName = fstElmnt.getElementsByTagName(key);
|
||||||
if ((itemName.getLength() != 0) && (itemName != null)) {
|
if ((itemName.getLength() != 0) && (itemName != null)) {
|
||||||
Element itemNameElement = (Element) itemName.item(0);
|
Element itemNameElement = (Element) itemName.item(0);
|
||||||
if ( !(verifyParam.get(key).equals("no value")) && !(itemNameElement.getTextContent().equals(verifyParam.get(key)))){
|
if (!(verifyParam.get(key).equals("no value")) && !(itemNameElement.getTextContent().equals(verifyParam.get(key)))) {
|
||||||
s_logger.error("Incorrect value for the following tag: " + key + ". Expected value is " + verifyParam.get(key) + " while actual value is " + itemNameElement.getTextContent());
|
s_logger.error("Incorrect value for the following tag: " + key + ". Expected value is " + verifyParam.get(key) + " while actual value is " + itemNameElement.getTextContent());
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
@ -632,7 +630,7 @@ public class ApiCommand{
|
|||||||
Iterator<?> it = set.iterator();
|
Iterator<?> it = set.iterator();
|
||||||
|
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||||
String key = (String) me.getKey();
|
String key = (String) me.getKey();
|
||||||
String value = (String) me.getValue();
|
String value = (String) me.getValue();
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
@ -642,14 +640,14 @@ public class ApiCommand{
|
|||||||
|
|
||||||
String itemName = null;
|
String itemName = null;
|
||||||
try {
|
try {
|
||||||
while(this.result.next()) {
|
while (this.result.next()) {
|
||||||
itemName = this.result.getString(key);
|
itemName = this.result.getString(key);
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
s_logger.error("Unable to get element from result set " + key);
|
s_logger.error("Unable to get element from result set " + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !(value.equals("no value")) && !(itemName.equals(verifyParam.get(key)))){
|
if (!(value.equals("no value")) && !(itemName.equals(verifyParam.get(key)))) {
|
||||||
s_logger.error("Incorrect value for the following tag: " + key + ". Expected value is " + verifyParam.get(key) + " while actual value is " + itemName);
|
s_logger.error("Incorrect value for the following tag: " + key + ". Expected value is " + verifyParam.get(key) + " while actual value is " + itemName);
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
@ -658,17 +656,17 @@ public class ApiCommand{
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean verifyEvents (String fileName, String level, String host, String account) {
|
public static boolean verifyEvents(String fileName, String level, String host, String account) {
|
||||||
boolean result=false;
|
boolean result = false;
|
||||||
HashMap<String, Integer> expectedEvents = new HashMap<String, Integer> ();
|
HashMap<String, Integer> expectedEvents = new HashMap<String, Integer>();
|
||||||
HashMap<String, Integer> actualEvents = new HashMap<String, Integer> ();
|
HashMap<String, Integer> actualEvents = new HashMap<String, Integer>();
|
||||||
String key = "";
|
String key = "";
|
||||||
|
|
||||||
File file = new File(fileName);
|
File file = new File(fileName);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
Properties pro = new Properties();
|
Properties pro = new Properties();
|
||||||
try {
|
try {
|
||||||
//get expected events
|
// get expected events
|
||||||
FileInputStream in = new FileInputStream(file);
|
FileInputStream in = new FileInputStream(file);
|
||||||
pro.load(in);
|
pro.load(in);
|
||||||
Enumeration<?> en = pro.propertyNames();
|
Enumeration<?> en = pro.propertyNames();
|
||||||
@ -677,22 +675,22 @@ public class ApiCommand{
|
|||||||
expectedEvents.put(key, Integer.parseInt(pro.getProperty(key)));
|
expectedEvents.put(key, Integer.parseInt(pro.getProperty(key)));
|
||||||
}
|
}
|
||||||
|
|
||||||
//get actual events
|
// get actual events
|
||||||
String url = host + "/?command=listEvents&account=" + account + "&level=" + level + "&domainid=1&pagesize=100";
|
String url = host + "/?command=listEvents&account=" + account + "&level=" + level + "&domainid=1&pagesize=100";
|
||||||
s_logger.info("Getting events with the following url " + url);
|
s_logger.info("Getting events with the following url " + url);
|
||||||
HttpClient client = new HttpClient();
|
HttpClient client = new HttpClient();
|
||||||
HttpMethod method = new GetMethod(url);
|
HttpMethod method = new GetMethod(url);
|
||||||
int responseCode = client.executeMethod(method);
|
int responseCode = client.executeMethod(method);
|
||||||
if (responseCode == 200 ) {
|
if (responseCode == 200) {
|
||||||
InputStream is = method.getResponseBodyAsStream();
|
InputStream is = method.getResponseBodyAsStream();
|
||||||
ArrayList<HashMap<String, String>> eventValues = UtilsForTest.parseMulXML(
|
ArrayList<HashMap<String, String>> eventValues = UtilsForTest.parseMulXML(
|
||||||
is, new String[] { "event" });
|
is, new String[] { "event" });
|
||||||
|
|
||||||
for (int i=0; i< eventValues.size(); i++) {
|
for (int i = 0; i < eventValues.size(); i++) {
|
||||||
HashMap<String, String> element = eventValues.get(i);
|
HashMap<String, String> element = eventValues.get(i);
|
||||||
if (element.get("level").equals(level)) {
|
if (element.get("level").equals(level)) {
|
||||||
if (actualEvents.containsKey(element.get("type")) == true){
|
if (actualEvents.containsKey(element.get("type")) == true) {
|
||||||
actualEvents.put(element.get("type"), actualEvents.get(element.get("type"))+1);
|
actualEvents.put(element.get("type"), actualEvents.get(element.get("type")) + 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
actualEvents.put(element.get("type"), 1);
|
actualEvents.put(element.get("type"), 1);
|
||||||
@ -702,23 +700,23 @@ public class ApiCommand{
|
|||||||
}
|
}
|
||||||
method.releaseConnection();
|
method.releaseConnection();
|
||||||
|
|
||||||
//compare actual events with expected events
|
// compare actual events with expected events
|
||||||
|
|
||||||
//compare expected result and actual result
|
// compare expected result and actual result
|
||||||
Iterator<?> iterator = expectedEvents.keySet().iterator();
|
Iterator<?> iterator = expectedEvents.keySet().iterator();
|
||||||
Integer expected;
|
Integer expected;
|
||||||
Integer actual;
|
Integer actual;
|
||||||
int fail=0;
|
int fail = 0;
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
expected=null;
|
expected = null;
|
||||||
actual=null;
|
actual = null;
|
||||||
String type = iterator.next().toString();
|
String type = iterator.next().toString();
|
||||||
expected = expectedEvents.get(type);
|
expected = expectedEvents.get(type);
|
||||||
actual = actualEvents.get(type);
|
actual = actualEvents.get(type);
|
||||||
if (actual == null ) {
|
if (actual == null) {
|
||||||
s_logger.error("Event of type " + type + " and level " + level + " is missing in the listEvents response. Expected number of these events is " + expected);
|
s_logger.error("Event of type " + type + " and level " + level + " is missing in the listEvents response. Expected number of these events is " + expected);
|
||||||
fail++;
|
fail++;
|
||||||
} else if (expected.compareTo(actual) != 0){
|
} else if (expected.compareTo(actual) != 0) {
|
||||||
fail++;
|
fail++;
|
||||||
s_logger.info("Amount of events of " + type + " type and level " + level + " is incorrect. Expected number of these events is " + expected + ", actual number is " + actual);
|
s_logger.info("Amount of events of " + type + " type and level " + level + " is incorrect. Expected number of these events is " + expected + ", actual number is " + actual);
|
||||||
}
|
}
|
||||||
@ -729,32 +727,31 @@ public class ApiCommand{
|
|||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
s_logger.error(ex);
|
s_logger.error(ex);
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
s_logger.info("File " + fileName + " not found");
|
s_logger.info("File " + fileName + " not found");
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean verifyEvents(HashMap<String, Integer> expectedEvents, String level, String host, String parameters) {
|
||||||
public static boolean verifyEvents (HashMap <String, Integer> expectedEvents, String level, String host, String parameters) {
|
boolean result = false;
|
||||||
boolean result=false;
|
HashMap<String, Integer> actualEvents = new HashMap<String, Integer>();
|
||||||
HashMap<String, Integer> actualEvents = new HashMap<String, Integer> ();
|
|
||||||
try {
|
try {
|
||||||
//get actual events
|
// get actual events
|
||||||
String url = host + "/?command=listEvents&" + parameters;
|
String url = host + "/?command=listEvents&" + parameters;
|
||||||
HttpClient client = new HttpClient();
|
HttpClient client = new HttpClient();
|
||||||
HttpMethod method = new GetMethod(url);
|
HttpMethod method = new GetMethod(url);
|
||||||
int responseCode = client.executeMethod(method);
|
int responseCode = client.executeMethod(method);
|
||||||
if (responseCode == 200 ) {
|
if (responseCode == 200) {
|
||||||
InputStream is = method.getResponseBodyAsStream();
|
InputStream is = method.getResponseBodyAsStream();
|
||||||
ArrayList<HashMap<String, String>> eventValues = UtilsForTest.parseMulXML(
|
ArrayList<HashMap<String, String>> eventValues = UtilsForTest.parseMulXML(
|
||||||
is, new String[] { "event" });
|
is, new String[] { "event" });
|
||||||
|
|
||||||
for (int i=0; i< eventValues.size(); i++) {
|
for (int i = 0; i < eventValues.size(); i++) {
|
||||||
HashMap<String, String> element = eventValues.get(i);
|
HashMap<String, String> element = eventValues.get(i);
|
||||||
if (element.get("level").equals(level)) {
|
if (element.get("level").equals(level)) {
|
||||||
if (actualEvents.containsKey(element.get("type")) == true){
|
if (actualEvents.containsKey(element.get("type")) == true) {
|
||||||
actualEvents.put(element.get("type"), actualEvents.get(element.get("type"))+1);
|
actualEvents.put(element.get("type"), actualEvents.get(element.get("type")) + 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
actualEvents.put(element.get("type"), 1);
|
actualEvents.put(element.get("type"), 1);
|
||||||
@ -763,26 +760,26 @@ public class ApiCommand{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
method.releaseConnection();
|
method.releaseConnection();
|
||||||
}catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
s_logger.error(ex);
|
s_logger.error(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
//compare actual events with expected events
|
// compare actual events with expected events
|
||||||
Iterator<?> iterator = expectedEvents.keySet().iterator();
|
Iterator<?> iterator = expectedEvents.keySet().iterator();
|
||||||
Integer expected;
|
Integer expected;
|
||||||
Integer actual;
|
Integer actual;
|
||||||
int fail=0;
|
int fail = 0;
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
expected=null;
|
expected = null;
|
||||||
actual=null;
|
actual = null;
|
||||||
String type = iterator.next().toString();
|
String type = iterator.next().toString();
|
||||||
expected = expectedEvents.get(type);
|
expected = expectedEvents.get(type);
|
||||||
actual = actualEvents.get(type);
|
actual = actualEvents.get(type);
|
||||||
if (actual == null ) {
|
if (actual == null) {
|
||||||
s_logger.error("Event of type " + type + " and level " + level + " is missing in the listEvents response. Expected number of these events is " + expected);
|
s_logger.error("Event of type " + type + " and level " + level + " is missing in the listEvents response. Expected number of these events is " + expected);
|
||||||
fail++;
|
fail++;
|
||||||
}
|
}
|
||||||
else if (expected.compareTo(actual) != 0){
|
else if (expected.compareTo(actual) != 0) {
|
||||||
fail++;
|
fail++;
|
||||||
s_logger.info("Amount of events of " + type + " type and level " + level + " is incorrect. Expected number of these events is " + expected + ", actual number is " + actual);
|
s_logger.info("Amount of events of " + type + " type and level " + level + " is incorrect. Expected number of these events is " + expected + ", actual number is " + actual);
|
||||||
}
|
}
|
||||||
@ -795,8 +792,7 @@ public class ApiCommand{
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Element queryAsyncJobResult(String jobId) {
|
||||||
public Element queryAsyncJobResult (String jobId) {
|
|
||||||
Element returnBody = null;
|
Element returnBody = null;
|
||||||
int code = 400;
|
int code = 400;
|
||||||
String resultUrl = this.host + ":8096/?command=queryAsyncJobResult&jobid=" + jobId;
|
String resultUrl = this.host + ":8096/?command=queryAsyncJobResult&jobid=" + jobId;
|
||||||
@ -814,7 +810,7 @@ public class ApiCommand{
|
|||||||
returnBody = doc.getDocumentElement();
|
returnBody = doc.getDocumentElement();
|
||||||
Element jobStatusTag = (Element) returnBody.getElementsByTagName("jobstatus").item(0);
|
Element jobStatusTag = (Element) returnBody.getElementsByTagName("jobstatus").item(0);
|
||||||
String jobStatus = jobStatusTag.getTextContent();
|
String jobStatus = jobStatusTag.getTextContent();
|
||||||
if(jobStatus.equals("0")) {
|
if (jobStatus.equals("0")) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
@ -836,7 +832,7 @@ public class ApiCommand{
|
|||||||
return returnBody;
|
return returnBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getElementByName(String elementName){
|
private String getElementByName(String elementName) {
|
||||||
NodeList commandName = this.xmlCommand.getElementsByTagName(elementName);
|
NodeList commandName = this.xmlCommand.getElementsByTagName(elementName);
|
||||||
if (commandName.getLength() != 0) {
|
if (commandName.getLength() != 0) {
|
||||||
Element commandElmnt = (Element) commandName.item(0);
|
Element commandElmnt = (Element) commandName.item(0);
|
||||||
@ -848,7 +844,7 @@ public class ApiCommand{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean verifyTagValue(String elementName, String expectedValue){
|
private boolean verifyTagValue(String elementName, String expectedValue) {
|
||||||
NodeList tag = this.xmlCommand.getElementsByTagName(elementName);
|
NodeList tag = this.xmlCommand.getElementsByTagName(elementName);
|
||||||
if (tag.getLength() != 0) {
|
if (tag.getLength() != 0) {
|
||||||
Element commandElmnt = (Element) tag.item(0);
|
Element commandElmnt = (Element) tag.item(0);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user