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.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 static final Logger s_logger = Logger.getLogger(CreateProjectCmd.class.getName());
|
||||
|
||||
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;
|
||||
|
||||
@IdentityMapper(entityTableName="domain")
|
||||
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a project")
|
||||
@IdentityMapper(entityTableName = "domain")
|
||||
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.LONG, description = "domain ID of the account owning a project")
|
||||
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;
|
||||
|
||||
@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;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////////// Accessors ///////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
public String getEntityTable() {
|
||||
return "projects";
|
||||
@ -111,13 +111,12 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd {
|
||||
return caller.getId();
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////// API Implementation///////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
public void execute() {
|
||||
Project project = _projectService.enableProject(this.getEntityId());
|
||||
if (project != null) {
|
||||
ProjectResponse response = _responseGenerator.createProjectResponse(project);
|
||||
@ -129,8 +128,8 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() throws ResourceAllocationException{
|
||||
UserContext.current().setEventDetails("Project Name: "+ getName());
|
||||
public void create() throws ResourceAllocationException {
|
||||
UserContext.current().setEventDetails("Project Name: " + getName());
|
||||
Project project = _projectService.createProject(getName(), getDisplayText(), getAccountName(), getDomainId());
|
||||
if (project != null) {
|
||||
this.setEntityId(project.getId());
|
||||
@ -148,4 +147,5 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd {
|
||||
public String getEventDescription() {
|
||||
return "creating project";
|
||||
}
|
||||
|
||||
}
|
||||
@ -31,21 +31,21 @@ import com.cloud.event.EventTypes;
|
||||
import com.cloud.user.Account;
|
||||
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 static final Logger s_logger = Logger.getLogger(DeleteProjectInvitationCmd.class.getName());
|
||||
private static final String s_name = "deleteprojectinvitationresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@IdentityMapper(entityTableName="project_invitations")
|
||||
@Parameter(name=ApiConstants.ID, required=true, type=CommandType.LONG, description="id of the invitation")
|
||||
// ///////////////////////////////////////////////////
|
||||
// ////////////// API parameters /////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
@IdentityMapper(entityTableName = "project_invitations")
|
||||
@Parameter(name = ApiConstants.ID, required = true, type = CommandType.LONG, description = "id of the invitation")
|
||||
private Long id;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////////// Accessors ///////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@ -55,18 +55,18 @@ public class DeleteProjectInvitationCmd extends BaseAsyncCmd {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////// API Implementation///////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
//TODO - return project entity ownerId
|
||||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
|
||||
// TODO - return project entity ownerId
|
||||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are
|
||||
// tracked
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
public void execute() {
|
||||
UserContext.current().setEventDetails("Project invitation id " + id);
|
||||
boolean result = _projectService.deleteProjectInvitation(id);
|
||||
if (result) {
|
||||
@ -86,4 +86,5 @@ public class DeleteProjectInvitationCmd extends BaseAsyncCmd {
|
||||
public String getEventDescription() {
|
||||
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.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 static final Logger s_logger = Logger.getLogger(ListProjectInvitationsCmd.class.getName());
|
||||
private static final String s_name = "listprojectinvitationsresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@IdentityMapper(entityTableName="projects")
|
||||
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="list by project id")
|
||||
// ///////////////////////////////////////////////////
|
||||
// ////////////// API parameters /////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
@IdentityMapper(entityTableName = "projects")
|
||||
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.LONG, description = "list by project id")
|
||||
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;
|
||||
|
||||
@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;
|
||||
|
||||
@IdentityMapper(entityTableName="project_invitations")
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list invitations by id")
|
||||
@IdentityMapper(entityTableName = "project_invitations")
|
||||
@Parameter(name = ApiConstants.ID, type = CommandType.LONG, description = "list invitations by id")
|
||||
private Long id;
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////////// Accessors ///////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
public Long getProjectId() {
|
||||
return projectId;
|
||||
}
|
||||
@ -76,13 +77,14 @@ public class ListProjectInvitationsCmd extends BaseListAccountResourcesCmd {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////// API Implementation///////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
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());
|
||||
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());
|
||||
ListResponse<ProjectInvitationResponse> response = new ListResponse<ProjectInvitationResponse>();
|
||||
List<ProjectInvitationResponse> projectInvitationResponses = new ArrayList<ProjectInvitationResponse>();
|
||||
for (ProjectInvitation invite : invites) {
|
||||
@ -94,4 +96,5 @@ public class ListProjectInvitationsCmd extends BaseListAccountResourcesCmd {
|
||||
|
||||
this.setResponseObject(response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -40,31 +40,31 @@ import com.cloud.user.UserContext;
|
||||
import com.cloud.uservm.UserVm;
|
||||
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 static final Logger s_logger = Logger.getLogger(StartVMCmd.class.getName());
|
||||
|
||||
private static final String s_name = "startvirtualmachineresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ////////////// API parameters /////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
@IdentityMapper(entityTableName="vm_instance")
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine")
|
||||
@IdentityMapper(entityTableName = "vm_instance")
|
||||
@Parameter(name = ApiConstants.ID, type = CommandType.LONG, required = true, description = "The ID of the virtual machine")
|
||||
private Long id;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////////// Accessors ///////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////// API Implementation///////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
@ -82,7 +82,8 @@ public class StartVMCmd extends BaseAsyncCmd {
|
||||
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
|
||||
@ -104,9 +105,9 @@ public class StartVMCmd extends BaseAsyncCmd {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException{
|
||||
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException {
|
||||
try {
|
||||
UserContext.current().setEventDetails("Vm Id: "+getId());
|
||||
UserContext.current().setEventDetails("Vm Id: " + getId());
|
||||
UserVm result;
|
||||
if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
|
||||
result = _bareMetalVmService.startVirtualMachine(this);
|
||||
@ -114,22 +115,23 @@ public class StartVMCmd extends BaseAsyncCmd {
|
||||
result = _userVmService.startVirtualMachine(this);
|
||||
}
|
||||
|
||||
if (result != null){
|
||||
if (result != null) {
|
||||
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to start a vm");
|
||||
}
|
||||
}catch (ConcurrentOperationException ex) {
|
||||
} catch (ConcurrentOperationException ex) {
|
||||
s_logger.warn("Exception: ", ex);
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
|
||||
}catch (StorageUnavailableException ex) {
|
||||
} catch (StorageUnavailableException ex) {
|
||||
s_logger.warn("Exception: ", ex);
|
||||
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
|
||||
}catch (ExecutionException ex) {
|
||||
} catch (ExecutionException ex) {
|
||||
s_logger.warn("Exception: ", ex);
|
||||
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.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 static final Logger s_logger = Logger.getLogger(StopVMCmd.class.getName());
|
||||
|
||||
private static final String s_name = "stopvirtualmachineresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ////////////// API parameters /////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
@IdentityMapper(entityTableName="vm_instance")
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine")
|
||||
@IdentityMapper(entityTableName = "vm_instance")
|
||||
@Parameter(name = ApiConstants.ID, type = CommandType.LONG, required = true, description = "The ID of the virtual machine")
|
||||
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;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////////// Accessors ///////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////// API Implementation///////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
@ -81,7 +80,8 @@ public class StopVMCmd extends BaseAsyncCmd {
|
||||
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
|
||||
@ -109,8 +109,8 @@ public class StopVMCmd extends BaseAsyncCmd {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws ServerApiException, ConcurrentOperationException{
|
||||
UserContext.current().setEventDetails("Vm Id: "+getId());
|
||||
public void execute() throws ServerApiException, ConcurrentOperationException {
|
||||
UserContext.current().setEventDetails("Vm Id: " + getId());
|
||||
UserVm result;
|
||||
|
||||
if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
|
||||
|
||||
@ -31,31 +31,30 @@ import com.cloud.event.EventTypes;
|
||||
import com.cloud.user.Account;
|
||||
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 static final Logger s_logger = Logger.getLogger(UpdateProjectInvitationCmd.class.getName());
|
||||
private static final String s_name = "updateprojectinvitationresponse";
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@IdentityMapper(entityTableName="projects")
|
||||
@Parameter(name=ApiConstants.PROJECT_ID, required=true, type=CommandType.LONG, description="id of the project to join")
|
||||
// ///////////////////////////////////////////////////
|
||||
// ////////////// API parameters /////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
@IdentityMapper(entityTableName = "projects")
|
||||
@Parameter(name = ApiConstants.PROJECT_ID, required = true, type = CommandType.LONG, description = "id of the project to join")
|
||||
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;
|
||||
|
||||
@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;
|
||||
|
||||
@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;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////////// Accessors ///////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
public Long getProjectId() {
|
||||
return projectId;
|
||||
}
|
||||
@ -80,20 +79,19 @@ public class UpdateProjectInvitationCmd extends BaseAsyncCmd {
|
||||
return accept;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////// API Implementation///////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
//TODO - return project entity ownerId
|
||||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
|
||||
// TODO - return project entity ownerId
|
||||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are
|
||||
// tracked
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
UserContext.current().setEventDetails("Project id: "+ projectId + "; accountName " + accountName + "; accept " + getAccept());
|
||||
public void execute() {
|
||||
UserContext.current().setEventDetails("Project id: " + projectId + "; accountName " + accountName + "; accept " + getAccept());
|
||||
boolean result = _projectService.updateInvitation(projectId, accountName, token, getAccept());
|
||||
if (result) {
|
||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||
|
||||
@ -26,31 +26,40 @@ import com.google.gson.annotations.SerializedName;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
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");
|
||||
|
||||
@SerializedName(ApiConstants.PROJECT) @Param(description="project name")
|
||||
@SerializedName(ApiConstants.PROJECT)
|
||||
@Param(description = "project name")
|
||||
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");
|
||||
|
||||
@SerializedName(ApiConstants.ACCOUNT) @Param(description="the name of the account")
|
||||
@SerializedName(ApiConstants.ACCOUNT)
|
||||
@Param(description = "the name of the account")
|
||||
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;
|
||||
|
||||
@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;
|
||||
|
||||
@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");
|
||||
|
||||
@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;
|
||||
|
||||
@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;
|
||||
|
||||
public void setProjectId(Long projectId) {
|
||||
|
||||
@ -178,7 +178,7 @@ public class ApiDispatcher {
|
||||
Object pageSizeObj = unpackedParams.get(ApiConstants.PAGE_SIZE);
|
||||
Long pageSize = 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)) {
|
||||
@ -212,7 +212,8 @@ public class ApiDispatcher {
|
||||
Object paramObj = unpackedParams.get(parameterAnnotation.name());
|
||||
if (paramObj == null) {
|
||||
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;
|
||||
}
|
||||
@ -224,20 +225,23 @@ public class ApiDispatcher {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
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());
|
||||
} catch (ParseException parseEx) {
|
||||
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");
|
||||
} 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());
|
||||
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");
|
||||
} 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) {
|
||||
// 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
|
||||
// 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()));
|
||||
break;
|
||||
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
|
||||
if(cmdObj instanceof ListEventsCmd){
|
||||
if (cmdObj instanceof ListEventsCmd) {
|
||||
boolean isObjInNewDateFormat = isObjInNewDateFormat(paramObj.toString());
|
||||
if (isObjInNewDateFormat){
|
||||
if (isObjInNewDateFormat) {
|
||||
DateFormat newFormat = BaseCmd.NEW_INPUT_FORMAT;
|
||||
synchronized (newFormat) {
|
||||
field.set(cmdObj, newFormat.parse(paramObj.toString()));
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
DateFormat format = BaseCmd.INPUT_FORMAT;
|
||||
synchronized (format) {
|
||||
Date date = format.parse(paramObj.toString());
|
||||
if (field.getName().equals("startDate")){
|
||||
if (field.getName().equals("startDate")) {
|
||||
date = massageDate(date, 0, 0, 0);
|
||||
}else if (field.getName().equals("endDate")){
|
||||
} else if (field.getName().equals("endDate")) {
|
||||
date = massageDate(date, 23, 59, 59);
|
||||
}
|
||||
field.set(cmdObj, date);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
DateFormat format = BaseCmd.INPUT_FORMAT;
|
||||
format.setLenient(false);
|
||||
synchronized (format) {
|
||||
@ -297,10 +302,9 @@ public class ApiDispatcher {
|
||||
case INTEGER:
|
||||
listParam.add(Integer.valueOf(token));
|
||||
break;
|
||||
case LONG:
|
||||
{
|
||||
case LONG: {
|
||||
Long val = null;
|
||||
if(identityMapper != null)
|
||||
if (identityMapper != null)
|
||||
val = s_instance._identityDao.getIdentityId(identityMapper, token);
|
||||
else
|
||||
val = Long.valueOf(token);
|
||||
@ -318,7 +322,7 @@ public class ApiDispatcher {
|
||||
field.set(cmdObj, listParam);
|
||||
break;
|
||||
case LONG:
|
||||
if(identityMapper != null)
|
||||
if (identityMapper != null)
|
||||
field.set(cmdObj, s_instance._identityDao.getIdentityId(identityMapper, paramObj.toString()));
|
||||
else
|
||||
field.set(cmdObj, Long.valueOf(paramObj.toString()));
|
||||
@ -327,9 +331,9 @@ public class ApiDispatcher {
|
||||
field.set(cmdObj, Short.valueOf(paramObj.toString()));
|
||||
break;
|
||||
case STRING:
|
||||
if((paramObj != null) && paramObj.toString().length() > annotation.length()){
|
||||
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());
|
||||
if ((paramObj != null) && paramObj.toString().length() > annotation.length()) {
|
||||
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());
|
||||
}
|
||||
field.set(cmdObj, paramObj.toString());
|
||||
break;
|
||||
@ -363,7 +367,7 @@ public class ApiDispatcher {
|
||||
|
||||
public static void plugService(BaseCmd cmd) {
|
||||
|
||||
if(!ApiServer.isPluggableServiceCommand(cmd.getClass().getName())){
|
||||
if (!ApiServer.isPluggableServiceCommand(cmd.getClass().getName())) {
|
||||
return;
|
||||
}
|
||||
Class<?> clazz = cmd.getClass();
|
||||
|
||||
@ -335,7 +335,7 @@ public class ApiServer implements HttpRequestHandler {
|
||||
responseType = paramValue[1];
|
||||
} else {
|
||||
// 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
|
||||
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
|
||||
// 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
|
||||
// modify the
|
||||
// modify the
|
||||
// code to be very specific to our needs
|
||||
static class ListenerThread extends Thread {
|
||||
private HttpService _httpService = null;
|
||||
|
||||
@ -16,39 +16,39 @@ import com.cloud.api.Identity;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
@Entity
|
||||
@Table(name="project_invitations")
|
||||
@Table(name = "project_invitations")
|
||||
public class ProjectInvitationVO implements ProjectInvitation, Identity {
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Column(name="id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private long id;
|
||||
|
||||
@Column(name="project_id")
|
||||
@Column(name = "project_id")
|
||||
private long projectId;
|
||||
|
||||
@Column(name="account_id")
|
||||
@Column(name = "account_id")
|
||||
private Long forAccountId;
|
||||
|
||||
@Column(name="domain_id")
|
||||
@Column(name = "domain_id")
|
||||
private Long inDomainId;
|
||||
|
||||
@Column(name="token")
|
||||
@Column(name = "token")
|
||||
private String token;
|
||||
|
||||
@Column(name="email")
|
||||
@Column(name = "email")
|
||||
private String email;
|
||||
|
||||
@Column(name="state")
|
||||
@Enumerated(value=EnumType.STRING)
|
||||
@Column(name = "state")
|
||||
@Enumerated(value = EnumType.STRING)
|
||||
private State state = State.Pending;
|
||||
|
||||
@Column(name=GenericDao.CREATED_COLUMN)
|
||||
@Column(name = GenericDao.CREATED_COLUMN)
|
||||
private Date created;
|
||||
|
||||
@Column(name="uuid")
|
||||
@Column(name = "uuid")
|
||||
private String uuid;
|
||||
|
||||
protected ProjectInvitationVO(){
|
||||
protected ProjectInvitationVO() {
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
|
||||
package com.cloud.projects;
|
||||
|
||||
import java.util.List;
|
||||
@ -17,4 +16,5 @@ public interface ProjectManager extends ProjectService {
|
||||
boolean projectInviteRequired();
|
||||
|
||||
boolean allowUserToCreateProject();
|
||||
|
||||
}
|
||||
|
||||
@ -23,9 +23,11 @@ import com.cloud.projects.ProjectAccount;
|
||||
import com.cloud.projects.ProjectAccountVO;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface ProjectAccountDao extends GenericDao<ProjectAccountVO, Long>{
|
||||
public interface ProjectAccountDao extends GenericDao<ProjectAccountVO, Long> {
|
||||
ProjectAccountVO getProjectOwner(long projectId);
|
||||
|
||||
List<ProjectAccountVO> listByProjectId(long projectId);
|
||||
|
||||
ProjectAccountVO findByProjectIdAccountId(long projectId, long accountId);
|
||||
|
||||
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.Op;
|
||||
|
||||
@Local(value={ProjectAccountDao.class})
|
||||
@Local(value = { ProjectAccountDao.class })
|
||||
public class ProjectAccountDaoImpl extends GenericDaoBase<ProjectAccountVO, Long> implements ProjectAccountDao {
|
||||
protected final SearchBuilder<ProjectAccountVO> AllFieldsSearch;
|
||||
final GenericSearchBuilder<ProjectAccountVO, Long> AdminSearch;
|
||||
@ -138,4 +138,5 @@ public class ProjectAccountDaoImpl extends GenericDaoBase<ProjectAccountVO, Long
|
||||
sc.setParameters("role", role);
|
||||
return customSearch(sc, null).get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ import com.cloud.projects.Project;
|
||||
import com.cloud.projects.ProjectVO;
|
||||
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);
|
||||
|
||||
@ -32,4 +32,5 @@ public interface ProjectDao extends GenericDao<ProjectVO, Long>{
|
||||
ProjectVO findByProjectAccountId(long projectAccountId);
|
||||
|
||||
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.Transaction;
|
||||
|
||||
@Local(value={ProjectDao.class})
|
||||
@Local(value = { ProjectDao.class })
|
||||
public class ProjectDaoImpl extends GenericDaoBase<ProjectVO, Long> implements ProjectDao {
|
||||
private static final Logger s_logger = Logger.getLogger(ProjectDaoImpl.class);
|
||||
protected final SearchBuilder<ProjectVO> AllFieldsSearch;
|
||||
@ -46,7 +46,8 @@ public class ProjectDaoImpl extends GenericDaoBase<ProjectVO, Long> implements P
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
@Override
|
||||
@DB
|
||||
public boolean remove(Long projectId) {
|
||||
boolean result = false;
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
@ -87,4 +88,5 @@ public class ProjectDaoImpl extends GenericDaoBase<ProjectVO, Long> implements P
|
||||
sc.setParameters("state", state);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -23,14 +23,23 @@ import com.cloud.projects.ProjectInvitation.State;
|
||||
import com.cloud.projects.ProjectInvitationVO;
|
||||
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);
|
||||
|
||||
List<ProjectInvitationVO> listExpiredInvitations();
|
||||
|
||||
boolean expirePendingInvitations(long timeOut);
|
||||
|
||||
boolean isActive(long id, long timeout);
|
||||
|
||||
ProjectInvitationVO findByEmailAndProjectId(String email, long projectId, State... inviteState);
|
||||
|
||||
ProjectInvitationVO findPendingByTokenAndProjectId(String token, long projectId, State... inviteState);
|
||||
|
||||
void cleanupInvitations(long projectId);
|
||||
|
||||
ProjectInvitationVO findPendingById(long id);
|
||||
|
||||
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.SearchCriteria;
|
||||
|
||||
@Local(value={ProjectInvitationDao.class})
|
||||
@Local(value = { ProjectInvitationDao.class })
|
||||
public class ProjectInvitationDaoImpl extends GenericDaoBase<ProjectInvitationVO, Long> implements ProjectInvitationDao {
|
||||
private static final Logger s_logger = Logger.getLogger(ProjectInvitationDaoImpl.class);
|
||||
protected final SearchBuilder<ProjectInvitationVO> AllFieldsSearch;
|
||||
@ -41,14 +41,13 @@ public class ProjectInvitationDaoImpl extends GenericDaoBase<ProjectInvitationVO
|
||||
InactiveSearch.done();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ProjectInvitationVO findByAccountIdProjectId(long accountId, long projectId, State... inviteState) {
|
||||
SearchCriteria<ProjectInvitationVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("accountId", accountId);
|
||||
sc.setParameters("projectId", projectId);
|
||||
if (inviteState != null && inviteState.length > 0) {
|
||||
sc.setParameters("state", (Object[])inviteState);
|
||||
sc.setParameters("state", (Object[]) inviteState);
|
||||
}
|
||||
|
||||
return findOneBy(sc);
|
||||
@ -82,7 +81,7 @@ public class ProjectInvitationDaoImpl extends GenericDaoBase<ProjectInvitationVO
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProjectInvitationVO> listInvitationsToExpire (long timeOut) {
|
||||
public List<ProjectInvitationVO> listInvitationsToExpire(long timeOut) {
|
||||
SearchCriteria<ProjectInvitationVO> sc = InactiveSearch.create();
|
||||
sc.setParameters("created", new Date((DateUtil.currentGMTTime().getTime()) - timeOut));
|
||||
sc.setParameters("state", State.Pending);
|
||||
@ -115,7 +114,7 @@ public class ProjectInvitationDaoImpl extends GenericDaoBase<ProjectInvitationVO
|
||||
sc.setParameters("email", email);
|
||||
sc.setParameters("projectId", projectId);
|
||||
if (inviteState != null && inviteState.length > 0) {
|
||||
sc.setParameters("state", (Object[])inviteState);
|
||||
sc.setParameters("state", (Object[]) inviteState);
|
||||
}
|
||||
|
||||
return findOneBy(sc);
|
||||
@ -127,7 +126,7 @@ public class ProjectInvitationDaoImpl extends GenericDaoBase<ProjectInvitationVO
|
||||
sc.setParameters("token", token);
|
||||
sc.setParameters("projectId", projectId);
|
||||
if (inviteState != null && inviteState.length > 0) {
|
||||
sc.setParameters("state", (Object[])inviteState);
|
||||
sc.setParameters("state", (Object[]) inviteState);
|
||||
}
|
||||
|
||||
return findOneBy(sc);
|
||||
@ -150,4 +149,5 @@ public class ProjectInvitationDaoImpl extends GenericDaoBase<ProjectInvitationVO
|
||||
int numberRemoved = remove(sc);
|
||||
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 HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;
|
||||
private final Adapters<HostAllocator> _hostAllocators;
|
||||
@Inject ProjectManager _projectMgr;
|
||||
@Inject
|
||||
ProjectManager _projectMgr;
|
||||
private final ResourceManager _resourceMgr;
|
||||
@Inject
|
||||
SnapshotManager _snapshotMgr;
|
||||
@ -369,7 +370,6 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
|
||||
_hypervisorCapabilitiesDao = locator.getDao(HypervisorCapabilitiesDao.class);
|
||||
|
||||
|
||||
_hostAllocators = locator.getAdapters(HostAllocator.class);
|
||||
if (_hostAllocators == null || !_hostAllocators.isSet()) {
|
||||
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
|
||||
// For now, we will be listing the following based on the usertype
|
||||
// 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
|
||||
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
|
||||
isAscending = (isAscending == null ? true : isAscending);
|
||||
@ -647,14 +648,14 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
|
||||
// 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 (isSystem){
|
||||
if (isSystem) {
|
||||
throw new InvalidParameterValueException("Only root admins can access system's offering");
|
||||
}
|
||||
return searchServiceOfferingsInternal(caller, name, id, vmId, keyword, searchFilter);
|
||||
}
|
||||
|
||||
// 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");
|
||||
}
|
||||
|
||||
@ -695,7 +696,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
// 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)
|
||||
// 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
|
||||
@ -764,7 +766,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
// for this domain
|
||||
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);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
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()) {
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
List<Host> suitableHosts = new ArrayList<Host>();
|
||||
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");
|
||||
}else{
|
||||
} else {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
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) {
|
||||
Project project = _projectMgr.getProject(projectId);
|
||||
if (project == null) {
|
||||
@ -1253,7 +1255,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
}
|
||||
|
||||
List<HypervisorType> hypers = null;
|
||||
if(!isIso) {
|
||||
if (!isIso) {
|
||||
hypers = _resourceMgr.listAvailHypervisorInZone(null, null);
|
||||
}
|
||||
Set<Pair<Long, Long>> templateZonePairSet = new HashSet<Pair<Long, Long>>();
|
||||
@ -1295,7 +1297,6 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
return templateZonePairSet;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VMTemplateVO updateTemplate(UpdateIsoCmd cmd) {
|
||||
return updateTemplateOrIso(cmd);
|
||||
@ -1384,7 +1385,6 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
return _templateDao.findById(id);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<EventVO> searchForEvents(ListEventsCmd cmd) {
|
||||
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("createDateG", sb.entity().getCreateDate(), SearchCriteria.Op.GTEQ);
|
||||
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("createDate", sb.entity().getCreateDate(), SearchCriteria.Op.BETWEEN);
|
||||
|
||||
SearchCriteria<EventVO> sc = sb.create();
|
||||
if (listProjectResourcesCriteria != null) {
|
||||
sc.setJoinParameters("accountSearch","accountType", Account.ACCOUNT_TYPE_PROJECT);
|
||||
sc.setJoinParameters("accountSearch", "accountType", Account.ACCOUNT_TYPE_PROJECT);
|
||||
}
|
||||
|
||||
if (!permittedAccounts.isEmpty()) {
|
||||
@ -1511,7 +1511,6 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<DomainRouterVO> searchForRouters(ListRoutersCmd cmd) {
|
||||
Long id = cmd.getId();
|
||||
@ -1590,7 +1589,6 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
return _routerDao.search(sc, searchFilter);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<IPAddressVO> searchForIPAddresses(ListPublicIpAddressesCmd cmd) {
|
||||
Object keyword = cmd.getKeyword();
|
||||
@ -1632,8 +1630,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
sb.and("isSourceNat", sb.entity().isSourceNat(), 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();
|
||||
sb.join("lbSearch", lbSearch, sb.entity().getId(), lbSearch.entity().getSourceIpAddressId(), JoinType.INNER);
|
||||
sb.groupBy(sb.entity().getId());
|
||||
@ -1660,7 +1657,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
vlanType = VlanType.VirtualNetwork;
|
||||
}
|
||||
|
||||
//don't show SSVM/CPVM ips
|
||||
// don't show SSVM/CPVM ips
|
||||
if (vlanType == VlanType.VirtualNetwork && (allocatedOnly)) {
|
||||
sb.and("associatedNetworkId", sb.entity().getAssociatedWithNetworkId(), SearchCriteria.Op.NNULL);
|
||||
}
|
||||
@ -1686,7 +1683,6 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
sc.setParameters("isStaticNat", staticNat);
|
||||
}
|
||||
|
||||
|
||||
if (address == null && keyword != null) {
|
||||
sc.setParameters("addressLIKE", "%" + keyword + "%");
|
||||
}
|
||||
@ -1839,7 +1835,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
_accountMgr.checkAccess(caller, domain);
|
||||
|
||||
//domain name is unique in the cloud
|
||||
// domain name is unique in the cloud
|
||||
if (domainName != null) {
|
||||
SearchCriteria<DomainVO> sc = _domainDao.createSearchCriteria();
|
||||
sc.addAnd("name", SearchCriteria.Op.EQ, domainName);
|
||||
@ -1852,8 +1848,8 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
}
|
||||
}
|
||||
|
||||
//validate network domain
|
||||
if (networkDomain != null && !networkDomain.isEmpty()){
|
||||
// validate network domain
|
||||
if (networkDomain != null && !networkDomain.isEmpty()) {
|
||||
if (!NetUtils.verifyDomainName(networkDomain)) {
|
||||
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', "
|
||||
@ -1946,42 +1942,42 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
Long podId = cmd.getPodId();
|
||||
Long clusterId = cmd.getClusterId();
|
||||
|
||||
if (clusterId != null){
|
||||
if (clusterId != null) {
|
||||
throw new InvalidParameterValueException("Currently clusterId param is not suppoerted");
|
||||
}
|
||||
zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
|
||||
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());
|
||||
if(summedCapacitiesAtZone != null){
|
||||
if (summedCapacitiesAtZone != null) {
|
||||
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());
|
||||
if(summedCapacitiesAtPod != null){
|
||||
if (summedCapacitiesAtPod != null) {
|
||||
summedCapacities.addAll(summedCapacitiesAtPod);
|
||||
}
|
||||
List<SummedCapacity> summedCapacitiesForSecStorage = getSecStorageUsed(zoneId, capacityType);
|
||||
if (summedCapacitiesForSecStorage != null){
|
||||
if (summedCapacitiesForSecStorage != null) {
|
||||
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());
|
||||
if(summedCapacitiesAtCluster != null){
|
||||
if (summedCapacitiesAtCluster != null) {
|
||||
summedCapacities.addAll(summedCapacitiesAtCluster);
|
||||
}
|
||||
|
||||
//Sort Capacities
|
||||
// Sort Capacities
|
||||
Collections.sort(summedCapacities, new Comparator<SummedCapacity>() {
|
||||
@Override
|
||||
public int compare(SummedCapacity arg0, SummedCapacity arg1) {
|
||||
if (arg0.getPercentUsed() < arg1.getPercentUsed()) {
|
||||
return 1;
|
||||
} else if (arg0.getPercentUsed()== arg1.getPercentUsed()) {
|
||||
} else if (arg0.getPercentUsed() == arg1.getPercentUsed()) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
@ -1990,17 +1986,16 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
|
||||
List<CapacityVO> capacities = new ArrayList<CapacityVO>();
|
||||
|
||||
|
||||
Integer pageSize = null;
|
||||
try {
|
||||
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");
|
||||
}
|
||||
|
||||
summedCapacities = summedCapacities.subList(0, summedCapacities.size() < cmd.getPageSizeVal() ? summedCapacities.size() : pageSize);
|
||||
for (SummedCapacity summedCapacity : summedCapacities){
|
||||
CapacityVO capacity = new CapacityVO(summedCapacity.getDataCenterId(), summedCapacity.getPodId() , summedCapacity.getClusterId(),
|
||||
for (SummedCapacity summedCapacity : summedCapacities) {
|
||||
CapacityVO capacity = new CapacityVO(summedCapacity.getDataCenterId(), summedCapacity.getPodId(), summedCapacity.getClusterId(),
|
||||
summedCapacity.getCapacityType(), summedCapacity.getPercentUsed());
|
||||
capacity.setUsedCapacity(summedCapacity.getUsedCapacity());
|
||||
capacity.setTotalCapacity(summedCapacity.getTotalCapacity());
|
||||
@ -2009,34 +2004,36 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
return capacities;
|
||||
}
|
||||
|
||||
List<SummedCapacity> getSecStorageUsed(Long zoneId, Integer capacityType){
|
||||
if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE){
|
||||
List<SummedCapacity> getSecStorageUsed(Long zoneId, Integer capacityType) {
|
||||
if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE) {
|
||||
List<SummedCapacity> list = new ArrayList<SummedCapacity>();
|
||||
if (zoneId != null){
|
||||
if (zoneId != null) {
|
||||
DataCenterVO zone = ApiDBUtils.findZoneById(zoneId);
|
||||
if(zone == null || zone.getAllocationState() == AllocationState.Disabled){
|
||||
if (zone == null || zone.getAllocationState() == AllocationState.Disabled) {
|
||||
return null;
|
||||
}
|
||||
CapacityVO capacity = _storageMgr.getSecondaryStorageUsedStats(null, zoneId);
|
||||
if (capacity.getTotalCapacity()!= 0){
|
||||
capacity.setUsedPercentage( capacity.getUsedCapacity() / capacity.getTotalCapacity() );
|
||||
}else {
|
||||
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) ;
|
||||
}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());
|
||||
SummedCapacity summedCapacity = new SummedCapacity(capacity.getUsedCapacity(), capacity.getTotalCapacity(), capacity.getUsedPercentage(), capacity.getCapacityType(), capacity.getDataCenterId(),
|
||||
capacity.getPodId(), capacity.getClusterId());
|
||||
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;
|
||||
}
|
||||
@ -2053,20 +2050,20 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
Boolean fetchLatest = cmd.getFetchLatest();
|
||||
|
||||
zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
|
||||
if (fetchLatest != null && fetchLatest){
|
||||
if (fetchLatest != null && fetchLatest) {
|
||||
_alertMgr.recalculateCapacity();
|
||||
}
|
||||
|
||||
List<SummedCapacity> summedCapacities = _capacityDao.findCapacityBy(capacityType, zoneId, podId, clusterId);
|
||||
List<CapacityVO> capacities = new ArrayList<CapacityVO>();
|
||||
|
||||
for (SummedCapacity summedCapacity : summedCapacities){
|
||||
for (SummedCapacity summedCapacity : summedCapacities) {
|
||||
CapacityVO capacity = new CapacityVO(null, summedCapacity.getDataCenterId(), podId, clusterId,
|
||||
summedCapacity.getUsedCapacity() + summedCapacity.getReservedCapacity(),
|
||||
summedCapacity.getTotalCapacity(), summedCapacity.getCapacityType());
|
||||
|
||||
if ( summedCapacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU){
|
||||
capacity.setTotalCapacity((long)(summedCapacity.getTotalCapacity() * ApiDBUtils.getCpuOverprovisioningFactor()));
|
||||
if (summedCapacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU) {
|
||||
capacity.setTotalCapacity((long) (summedCapacity.getTotalCapacity() * ApiDBUtils.getCpuOverprovisioningFactor()));
|
||||
}
|
||||
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".
|
||||
// Show Sec. Storage only when the api is invoked for the zone layer.
|
||||
List<DataCenterVO> dcList = new ArrayList<DataCenterVO>();
|
||||
if (zoneId==null && podId==null && clusterId==null){
|
||||
if (zoneId == null && podId == null && clusterId == null) {
|
||||
dcList = ApiDBUtils.listZones();
|
||||
}else if (zoneId != null){
|
||||
} else if (zoneId != null) {
|
||||
dcList.add(ApiDBUtils.findZoneById(zoneId));
|
||||
}else{
|
||||
} else {
|
||||
if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_STORAGE) {
|
||||
capacities.add(_storageMgr.getStoragePoolUsedStats(null, clusterId, podId, zoneId));
|
||||
}
|
||||
}
|
||||
|
||||
for(DataCenterVO zone : dcList){
|
||||
for (DataCenterVO zone : dcList) {
|
||||
zoneId = zone.getId();
|
||||
if ((capacityType == null || capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE) && podId == null && clusterId == null) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
// 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
|
||||
@ -2178,7 +2175,8 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
// 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
|
||||
// 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
|
||||
|
||||
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...
|
||||
/*
|
||||
* 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() + "%"); // }
|
||||
*/
|
||||
|
||||
@ -2362,7 +2361,6 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
return _poolDao.search(sc, searchFilter);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<AsyncJobVO> searchForAsyncJobs(ListAsyncJobsCmd cmd) {
|
||||
|
||||
@ -2674,7 +2672,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
if (networks != null && !networks.isEmpty()) {
|
||||
securityGroupsEnabled = true;
|
||||
String elbEnabled = _configDao.getValue(Config.ElasticLoadBalancerEnabled.key());
|
||||
elasticLoadBalancerEnabled = elbEnabled==null?false:Boolean.parseBoolean(elbEnabled);
|
||||
elasticLoadBalancerEnabled = elbEnabled == null ? false : Boolean.parseBoolean(elbEnabled);
|
||||
if (elasticLoadBalancerEnabled) {
|
||||
String networkType = _configDao.getValue(Config.ElasticLoadBalancerNetwork.key());
|
||||
if (networkType != null)
|
||||
@ -2717,7 +2715,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
throw new InvalidParameterValueException("Unable to find volume with id " + volumeId);
|
||||
}
|
||||
|
||||
//perform permission check
|
||||
// perform permission check
|
||||
_accountMgr.checkAccess(account, null, true, volume);
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
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());
|
||||
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;
|
||||
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");
|
||||
}
|
||||
}
|
||||
@ -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());
|
||||
|
||||
if (cluster.getHypervisorType() == HypervisorType.XenServer){
|
||||
if (cluster.getHypervisorType() == HypervisorType.XenServer) {
|
||||
return "vhd";
|
||||
}else if (cluster.getHypervisorType() == HypervisorType.KVM){
|
||||
} else if (cluster.getHypervisorType() == HypervisorType.KVM) {
|
||||
return "qcow2";
|
||||
}else if (cluster.getHypervisorType() == HypervisorType.VMware){
|
||||
} else if (cluster.getHypervisorType() == HypervisorType.VMware) {
|
||||
return "ova";
|
||||
}else if (cluster.getHypervisorType() == HypervisorType.Ovm){
|
||||
} else if (cluster.getHypervisorType() == HypervisorType.Ovm) {
|
||||
return "raw";
|
||||
}else{
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public InstanceGroupVO updateVmGroup(UpdateVMGroupCmd cmd) {
|
||||
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");
|
||||
}
|
||||
|
||||
@ -3114,7 +3113,8 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
_accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
|
||||
Long domainId = domainIdRecursiveListProject.first();
|
||||
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);
|
||||
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());
|
||||
if (host != null && host.getHypervisorType() == HypervisorType.XenServer) {
|
||||
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");
|
||||
}
|
||||
} else {
|
||||
|
||||
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");
|
||||
}
|
||||
// get all the hosts in this cluster
|
||||
List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(cmd.getClusterId());
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
try{
|
||||
try {
|
||||
txn.start();
|
||||
for (HostVO h : hosts) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
@ -3232,7 +3232,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
}
|
||||
txn.commit();
|
||||
// if hypervisor is xenserver then we update it in CitrixResourceBase
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("Failed to update password " + e.getMessage());
|
||||
}
|
||||
@ -3242,14 +3242,14 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] listEventTypes(){
|
||||
public String[] listEventTypes() {
|
||||
Object eventObj = new EventTypes();
|
||||
Class<EventTypes> c = EventTypes.class;
|
||||
Field[] fields = c.getDeclaredFields();
|
||||
String[] eventTypes = new String[fields.length];
|
||||
try {
|
||||
int i = 0;
|
||||
for(Field field : fields){
|
||||
for (Field field : fields) {
|
||||
eventTypes[i++] = field.get(eventObj).toString();
|
||||
}
|
||||
return eventTypes;
|
||||
@ -3262,7 +3262,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
}
|
||||
|
||||
@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);
|
||||
SearchCriteria<HypervisorCapabilitiesVO> sc = _hypervisorCapabilitiesDao.createSearchCriteria();
|
||||
|
||||
@ -3285,10 +3285,10 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
if(hpvCapabilities == null){
|
||||
if (hpvCapabilities == null) {
|
||||
throw new InvalidParameterValueException("unable to find the hypervisor capabilities " + id);
|
||||
}
|
||||
|
||||
@ -3297,18 +3297,17 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
return hpvCapabilities;
|
||||
}
|
||||
|
||||
|
||||
hpvCapabilities = _hypervisorCapabilitiesDao.createForUpdate(id);
|
||||
|
||||
if (maxGuestsLimit != null){
|
||||
if (maxGuestsLimit != null) {
|
||||
hpvCapabilities.setMaxGuestsLimit(maxGuestsLimit);
|
||||
}
|
||||
|
||||
if (securityGroupEnabled != null){
|
||||
if (securityGroupEnabled != null) {
|
||||
hpvCapabilities.setSecurityGroupEnabled(securityGroupEnabled);
|
||||
}
|
||||
|
||||
if (_hypervisorCapabilitiesDao.update(id, hpvCapabilities)){
|
||||
if (_hypervisorCapabilitiesDao.update(id, hpvCapabilities)) {
|
||||
hpvCapabilities = _hypervisorCapabilitiesDao.findById(id);
|
||||
UserContext.current().setEventDetails("Hypervisor Capabilities id=" + hpvCapabilities.getId());
|
||||
return hpvCapabilities;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||
*
|
||||
*
|
||||
*
|
||||
* 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;
|
||||
|
||||
public class ApiCommand{
|
||||
public class ApiCommand {
|
||||
public static final Logger s_logger = Logger.getLogger(ApiCommand.class.getName());
|
||||
public static enum CommandType{
|
||||
|
||||
public static enum CommandType {
|
||||
HTTP, MYSQL, SCRIPT;
|
||||
}
|
||||
|
||||
public static enum ResponseType{
|
||||
public static enum ResponseType {
|
||||
ERROR, EMPTY;
|
||||
}
|
||||
|
||||
@ -68,7 +69,6 @@ public class ApiCommand{
|
||||
private CommandType commandType;
|
||||
private ResponseType responseType;
|
||||
|
||||
|
||||
private TreeMap<String, String> urlParam;
|
||||
private HashMap<String, String> verifyParam = 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 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.setCommandName();
|
||||
this.setResponseType();
|
||||
@ -98,6 +97,7 @@ public class ApiCommand{
|
||||
String async = commands.get(this.getName());
|
||||
if (async != null && async.equals("yes")) {
|
||||
this.isAsync = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ public class ApiCommand{
|
||||
this.xmlCommand = xmlCommand;
|
||||
}
|
||||
|
||||
//================FOLLOWING METHODS USE INPUT XML FILE=======================//
|
||||
// ================FOLLOWING METHODS USE INPUT XML FILE=======================//
|
||||
public void setCommandName() {
|
||||
NodeList commandName = this.xmlCommand.getElementsByTagName("name");
|
||||
Element commandElmnt = (Element) commandName.item(0);
|
||||
@ -186,19 +186,19 @@ public class ApiCommand{
|
||||
|
||||
public void setUrlParam(HashMap<String, String> param) {
|
||||
this.urlParam = new TreeMap<String, String>();
|
||||
NodeList parameterLst= this.xmlCommand.getElementsByTagName("parameters");
|
||||
if (parameterLst != null ) {
|
||||
for (int j=0; j<parameterLst.getLength(); j++) {
|
||||
NodeList parameterLst = this.xmlCommand.getElementsByTagName("parameters");
|
||||
if (parameterLst != null) {
|
||||
for (int j = 0; j < parameterLst.getLength(); j++) {
|
||||
Element parameterElement = (Element) parameterLst.item(j);
|
||||
NodeList itemLst = parameterElement.getElementsByTagName("item");
|
||||
for (int k=0; k<itemLst.getLength(); k++) {
|
||||
Node item=itemLst.item(k);
|
||||
for (int k = 0; k < itemLst.getLength(); k++) {
|
||||
Node item = itemLst.item(k);
|
||||
if (item.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element itemElement= (Element) item;
|
||||
Element itemElement = (Element) item;
|
||||
NodeList itemName = itemElement.getElementsByTagName("name");
|
||||
Element itemNameElement = (Element) itemName.item(0);
|
||||
|
||||
//get value
|
||||
// get value
|
||||
Element itemValueElement = null;
|
||||
if ((itemElement.getElementsByTagName("value") != null) && (itemElement.getElementsByTagName("value").getLength() != 0)) {
|
||||
NodeList itemValue = itemElement.getElementsByTagName("value");
|
||||
@ -206,7 +206,7 @@ public class ApiCommand{
|
||||
}
|
||||
|
||||
Element itemParamElement = null;
|
||||
//getparam
|
||||
// getparam
|
||||
if ((itemElement.getElementsByTagName("param") != null) && (itemElement.getElementsByTagName("param").getLength() != 0)) {
|
||||
NodeList itemParam = itemElement.getElementsByTagName("param");
|
||||
itemParamElement = (Element) itemParam.item(0);
|
||||
@ -215,18 +215,18 @@ public class ApiCommand{
|
||||
if ((itemElement.getAttribute("getparam").equals("true")) && (itemParamElement != null)) {
|
||||
this.urlParam.put(itemNameElement.getTextContent(), param.get(itemParamElement.getTextContent()));
|
||||
}
|
||||
else if (itemValueElement != null){
|
||||
else if (itemValueElement != null) {
|
||||
this.urlParam.put(itemNameElement.getTextContent(), itemValueElement.getTextContent());
|
||||
} else if (itemElement.getAttribute("random").equals("true")) {
|
||||
Random ran = new Random();
|
||||
String randomString = Math.abs(ran.nextInt())+ "-randomName";
|
||||
String randomString = Math.abs(ran.nextInt()) + "-randomName";
|
||||
this.urlParam.put(itemNameElement.getTextContent(), randomString);
|
||||
if ((itemElement.getAttribute("setparam").equals("true")) && (itemParamElement != null)) {
|
||||
param.put(itemParamElement.getTextContent(), randomString);
|
||||
}
|
||||
} else if (itemElement.getAttribute("randomnumber").equals("true")) {
|
||||
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());
|
||||
if ((itemElement.getAttribute("setparam").equals("true")) && (itemParamElement != null)) {
|
||||
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) {
|
||||
|
||||
if (this.getCommandType() == CommandType.SCRIPT) {
|
||||
@ -247,7 +246,7 @@ public class ApiCommand{
|
||||
Set<?> c = this.urlParam.entrySet();
|
||||
Iterator<?> it = c.iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||
String key = (String) me.getKey();
|
||||
String value = (String) me.getValue();
|
||||
try {
|
||||
@ -262,7 +261,7 @@ public class ApiCommand{
|
||||
Set<?> c = this.urlParam.entrySet();
|
||||
Iterator<?> it = c.iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||
String key = (String) me.getKey();
|
||||
String value = (String) me.getValue();
|
||||
try {
|
||||
@ -275,12 +274,12 @@ public class ApiCommand{
|
||||
s_logger.info("The command is " + this.command);
|
||||
|
||||
} else {
|
||||
if ((param.get("apikey") == null) || (param.get("secretkey")==null) || (this.isUserCommand == false)) {
|
||||
String temp = this.host + ":8096/?command="+ this.commandName;
|
||||
if ((param.get("apikey") == null) || (param.get("secretkey") == null) || (this.isUserCommand == false)) {
|
||||
String temp = this.host + ":8096/?command=" + this.commandName;
|
||||
Set<?> c = this.urlParam.entrySet();
|
||||
Iterator<?> it = c.iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||
String key = (String) me.getKey();
|
||||
String value = (String) me.getValue();
|
||||
try {
|
||||
@ -299,11 +298,11 @@ public class ApiCommand{
|
||||
this.urlParam.put("apikey", apiKey);
|
||||
this.urlParam.put("command", this.commandName);
|
||||
|
||||
//sort url hash map by key
|
||||
// sort url hash map by key
|
||||
Set<?> c = this.urlParam.entrySet();
|
||||
Iterator<?> it = c.iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||
String key = (String) me.getKey();
|
||||
String value = (String) me.getValue();
|
||||
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 signature = UtilsForTest.signRequest(requestToSign, secretKey);
|
||||
String encodedSignature = "";
|
||||
@ -328,9 +327,9 @@ public class ApiCommand{
|
||||
}
|
||||
|
||||
public void setVerifyParam(HashMap<String, String> param) {
|
||||
NodeList returnLst= this.xmlCommand.getElementsByTagName("returnvalue");
|
||||
if (returnLst != null ) {
|
||||
for (int m=0; m<returnLst.getLength(); m++) {
|
||||
NodeList returnLst = this.xmlCommand.getElementsByTagName("returnvalue");
|
||||
if (returnLst != null) {
|
||||
for (int m = 0; m < returnLst.getLength(); m++) {
|
||||
Element returnElement = (Element) returnLst.item(m);
|
||||
if (returnElement.getAttribute("list").equals("true")) {
|
||||
this.list = true;
|
||||
@ -345,21 +344,21 @@ public class ApiCommand{
|
||||
|
||||
NodeList itemLst1 = returnElement.getElementsByTagName("item");
|
||||
if (itemLst1 != null) {
|
||||
for (int n=0; n<itemLst1.getLength(); n++) {
|
||||
Node item=itemLst1.item(n);
|
||||
for (int n = 0; n < itemLst1.getLength(); n++) {
|
||||
Node item = itemLst1.item(n);
|
||||
if (item.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element itemElement= (Element) item;
|
||||
//get parameter name
|
||||
Element itemElement = (Element) item;
|
||||
// get parameter name
|
||||
NodeList itemName = itemElement.getElementsByTagName("name");
|
||||
Element itemNameElement = (Element) itemName.item(0);
|
||||
|
||||
//Get parameters for future use
|
||||
// Get parameters for future use
|
||||
if (itemElement.getAttribute("setparam").equals("true")) {
|
||||
NodeList itemVariable = itemElement.getElementsByTagName("param");
|
||||
Element itemVariableElement = (Element) itemVariable.item(0);
|
||||
setParam.put(itemVariableElement.getTextContent(), itemNameElement.getTextContent());
|
||||
this.required = true;
|
||||
} else if (itemElement.getAttribute("getparam").equals("true")){
|
||||
} else if (itemElement.getAttribute("getparam").equals("true")) {
|
||||
NodeList itemVariable = itemElement.getElementsByTagName("param");
|
||||
Element itemVariableElement = (Element) itemVariable.item(0);
|
||||
this.verifyParam.put(itemNameElement.getTextContent(), param.get(itemVariableElement.getTextContent()));
|
||||
@ -377,13 +376,12 @@ public class ApiCommand{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getResponseCode() {
|
||||
return responseCode;
|
||||
}
|
||||
|
||||
//Send api command to the server
|
||||
public void sendCommand(HttpClient client, Connection conn){
|
||||
// Send api command to the server
|
||||
public void sendCommand(HttpClient client, Connection conn) {
|
||||
if (TestCaseEngine._printUrl == true)
|
||||
{
|
||||
s_logger.info("url is " + this.command);
|
||||
@ -430,7 +428,7 @@ public class ApiCommand{
|
||||
this.responseBody = doc.getDocumentElement();
|
||||
}
|
||||
else {
|
||||
//get async job result
|
||||
// get async job result
|
||||
Element jobTag = (Element) doc.getDocumentElement().getElementsByTagName("jobid").item(0);
|
||||
String jobId = jobTag.getTextContent();
|
||||
Element responseBodyAsyncEl = queryAsyncJobResult(jobId);
|
||||
@ -439,11 +437,12 @@ public class ApiCommand{
|
||||
}
|
||||
else {
|
||||
this.responseBody = responseBodyAsyncEl;
|
||||
//get status of the job
|
||||
Element jobStatusTag = (Element)responseBodyAsyncEl.getElementsByTagName("jobstatus").item(0);
|
||||
// get status of the job
|
||||
Element jobStatusTag = (Element) responseBodyAsyncEl.getElementsByTagName("jobstatus").item(0);
|
||||
String jobStatus = jobStatusTag.getTextContent();
|
||||
if (!jobStatus.equals("1")) { // Need to modify with different error codes for jobAsync results
|
||||
//set fake response code by now
|
||||
if (!jobStatus.equals("1")) { // Need to modify with different error codes for jobAsync
|
||||
// results
|
||||
// set fake response code by now
|
||||
this.responseCode = 400;
|
||||
}
|
||||
}
|
||||
@ -461,18 +460,17 @@ public class ApiCommand{
|
||||
}
|
||||
}
|
||||
|
||||
//verify if response is empty (contains only root element)
|
||||
public boolean isEmpty(){
|
||||
// verify if response is empty (contains only root element)
|
||||
public boolean isEmpty() {
|
||||
boolean result = false;
|
||||
if (!this.responseBody.hasChildNodes())
|
||||
result = true;
|
||||
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)) {
|
||||
s_logger.error("Response body is empty");
|
||||
return false;
|
||||
@ -483,7 +481,7 @@ public class ApiCommand{
|
||||
Set<?> set = this.setParam.entrySet();
|
||||
Iterator<?> it = set.iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||
String key = (String) me.getKey();
|
||||
String value = (String) me.getValue();
|
||||
try {
|
||||
@ -508,13 +506,13 @@ public class ApiCommand{
|
||||
Iterator<?> it = set.iterator();
|
||||
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||
String key = (String) me.getKey();
|
||||
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);
|
||||
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);
|
||||
if (itemNameElement.getChildNodes().getLength() <= 1) {
|
||||
param.put(key, itemNameElement.getTextContent());
|
||||
@ -537,7 +535,7 @@ public class ApiCommand{
|
||||
Element fstElmnt = (Element) requiredNode;
|
||||
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||
String key = (String) me.getKey();
|
||||
String value = (String) me.getValue();
|
||||
NodeList itemName = fstElmnt.getElementsByTagName(value);
|
||||
@ -570,7 +568,7 @@ public class ApiCommand{
|
||||
Iterator<?> it = set.iterator();
|
||||
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||
String key = (String) me.getKey();
|
||||
String value = (String) me.getValue();
|
||||
if (value == null) {
|
||||
@ -584,21 +582,21 @@ public class ApiCommand{
|
||||
if (itemNameElement.hasChildNodes()) {
|
||||
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());
|
||||
result = false;
|
||||
}
|
||||
} else {
|
||||
s_logger.error("Following xml element is missing in the response: " + key);
|
||||
result=false;
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
//for multiple elements
|
||||
// for multiple elements
|
||||
else {
|
||||
Set<?> set = verifyParam.entrySet();
|
||||
Iterator<?> it = set.iterator();
|
||||
//get list element specified by id
|
||||
// get list element specified by id
|
||||
NodeList returnLst = this.responseBody.getElementsByTagName(this.listName.getTextContent());
|
||||
Node requiredNode = returnLst.item(Integer.parseInt(this.listId.getTextContent()));
|
||||
|
||||
@ -606,7 +604,7 @@ public class ApiCommand{
|
||||
Element fstElmnt = (Element) requiredNode;
|
||||
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||
String key = (String) me.getKey();
|
||||
String value = (String) me.getValue();
|
||||
if (value == null) {
|
||||
@ -616,7 +614,7 @@ public class ApiCommand{
|
||||
NodeList itemName = fstElmnt.getElementsByTagName(key);
|
||||
if ((itemName.getLength() != 0) && (itemName != null)) {
|
||||
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());
|
||||
result = false;
|
||||
}
|
||||
@ -632,7 +630,7 @@ public class ApiCommand{
|
||||
Iterator<?> it = set.iterator();
|
||||
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
|
||||
String key = (String) me.getKey();
|
||||
String value = (String) me.getValue();
|
||||
if (value == null) {
|
||||
@ -642,14 +640,14 @@ public class ApiCommand{
|
||||
|
||||
String itemName = null;
|
||||
try {
|
||||
while(this.result.next()) {
|
||||
while (this.result.next()) {
|
||||
itemName = this.result.getString(key);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
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);
|
||||
result = false;
|
||||
}
|
||||
@ -658,17 +656,17 @@ public class ApiCommand{
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean verifyEvents (String fileName, String level, String host, String account) {
|
||||
boolean result=false;
|
||||
HashMap<String, Integer> expectedEvents = new HashMap<String, Integer> ();
|
||||
HashMap<String, Integer> actualEvents = new HashMap<String, Integer> ();
|
||||
public static boolean verifyEvents(String fileName, String level, String host, String account) {
|
||||
boolean result = false;
|
||||
HashMap<String, Integer> expectedEvents = new HashMap<String, Integer>();
|
||||
HashMap<String, Integer> actualEvents = new HashMap<String, Integer>();
|
||||
String key = "";
|
||||
|
||||
File file = new File(fileName);
|
||||
if (file.exists()) {
|
||||
Properties pro = new Properties();
|
||||
try {
|
||||
//get expected events
|
||||
// get expected events
|
||||
FileInputStream in = new FileInputStream(file);
|
||||
pro.load(in);
|
||||
Enumeration<?> en = pro.propertyNames();
|
||||
@ -677,22 +675,22 @@ public class ApiCommand{
|
||||
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";
|
||||
s_logger.info("Getting events with the following url " + url);
|
||||
HttpClient client = new HttpClient();
|
||||
HttpMethod method = new GetMethod(url);
|
||||
int responseCode = client.executeMethod(method);
|
||||
if (responseCode == 200 ) {
|
||||
if (responseCode == 200) {
|
||||
InputStream is = method.getResponseBodyAsStream();
|
||||
ArrayList<HashMap<String, String>> eventValues = UtilsForTest.parseMulXML(
|
||||
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);
|
||||
if (element.get("level").equals(level)) {
|
||||
if (actualEvents.containsKey(element.get("type")) == true){
|
||||
actualEvents.put(element.get("type"), actualEvents.get(element.get("type"))+1);
|
||||
if (actualEvents.containsKey(element.get("type")) == true) {
|
||||
actualEvents.put(element.get("type"), actualEvents.get(element.get("type")) + 1);
|
||||
}
|
||||
else {
|
||||
actualEvents.put(element.get("type"), 1);
|
||||
@ -702,23 +700,23 @@ public class ApiCommand{
|
||||
}
|
||||
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();
|
||||
Integer expected;
|
||||
Integer actual;
|
||||
int fail=0;
|
||||
int fail = 0;
|
||||
while (iterator.hasNext()) {
|
||||
expected=null;
|
||||
actual=null;
|
||||
expected = null;
|
||||
actual = null;
|
||||
String type = iterator.next().toString();
|
||||
expected = expectedEvents.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);
|
||||
fail++;
|
||||
} else if (expected.compareTo(actual) != 0){
|
||||
} else if (expected.compareTo(actual) != 0) {
|
||||
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);
|
||||
}
|
||||
@ -729,32 +727,31 @@ public class ApiCommand{
|
||||
} catch (Exception ex) {
|
||||
s_logger.error(ex);
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
s_logger.info("File " + fileName + " not found");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static boolean verifyEvents (HashMap <String, Integer> expectedEvents, String level, String host, String parameters) {
|
||||
boolean result=false;
|
||||
HashMap<String, Integer> actualEvents = new HashMap<String, Integer> ();
|
||||
public static boolean verifyEvents(HashMap<String, Integer> expectedEvents, String level, String host, String parameters) {
|
||||
boolean result = false;
|
||||
HashMap<String, Integer> actualEvents = new HashMap<String, Integer>();
|
||||
try {
|
||||
//get actual events
|
||||
// get actual events
|
||||
String url = host + "/?command=listEvents&" + parameters;
|
||||
HttpClient client = new HttpClient();
|
||||
HttpMethod method = new GetMethod(url);
|
||||
int responseCode = client.executeMethod(method);
|
||||
if (responseCode == 200 ) {
|
||||
if (responseCode == 200) {
|
||||
InputStream is = method.getResponseBodyAsStream();
|
||||
ArrayList<HashMap<String, String>> eventValues = UtilsForTest.parseMulXML(
|
||||
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);
|
||||
if (element.get("level").equals(level)) {
|
||||
if (actualEvents.containsKey(element.get("type")) == true){
|
||||
actualEvents.put(element.get("type"), actualEvents.get(element.get("type"))+1);
|
||||
if (actualEvents.containsKey(element.get("type")) == true) {
|
||||
actualEvents.put(element.get("type"), actualEvents.get(element.get("type")) + 1);
|
||||
}
|
||||
else {
|
||||
actualEvents.put(element.get("type"), 1);
|
||||
@ -763,26 +760,26 @@ public class ApiCommand{
|
||||
}
|
||||
}
|
||||
method.releaseConnection();
|
||||
}catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
s_logger.error(ex);
|
||||
}
|
||||
|
||||
//compare actual events with expected events
|
||||
// compare actual events with expected events
|
||||
Iterator<?> iterator = expectedEvents.keySet().iterator();
|
||||
Integer expected;
|
||||
Integer actual;
|
||||
int fail=0;
|
||||
int fail = 0;
|
||||
while (iterator.hasNext()) {
|
||||
expected=null;
|
||||
actual=null;
|
||||
expected = null;
|
||||
actual = null;
|
||||
String type = iterator.next().toString();
|
||||
expected = expectedEvents.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);
|
||||
fail++;
|
||||
}
|
||||
else if (expected.compareTo(actual) != 0){
|
||||
else if (expected.compareTo(actual) != 0) {
|
||||
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);
|
||||
}
|
||||
@ -795,8 +792,7 @@ public class ApiCommand{
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public Element queryAsyncJobResult (String jobId) {
|
||||
public Element queryAsyncJobResult(String jobId) {
|
||||
Element returnBody = null;
|
||||
int code = 400;
|
||||
String resultUrl = this.host + ":8096/?command=queryAsyncJobResult&jobid=" + jobId;
|
||||
@ -814,7 +810,7 @@ public class ApiCommand{
|
||||
returnBody = doc.getDocumentElement();
|
||||
Element jobStatusTag = (Element) returnBody.getElementsByTagName("jobstatus").item(0);
|
||||
String jobStatus = jobStatusTag.getTextContent();
|
||||
if(jobStatus.equals("0")) {
|
||||
if (jobStatus.equals("0")) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
@ -836,7 +832,7 @@ public class ApiCommand{
|
||||
return returnBody;
|
||||
}
|
||||
|
||||
private String getElementByName(String elementName){
|
||||
private String getElementByName(String elementName) {
|
||||
NodeList commandName = this.xmlCommand.getElementsByTagName(elementName);
|
||||
if (commandName.getLength() != 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);
|
||||
if (tag.getLength() != 0) {
|
||||
Element commandElmnt = (Element) tag.item(0);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user