use of com.cloud.projects.Project in project CloudStack-archive by CloudStack-extras.
the class SuspendProjectCmd method execute.
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
UserContext.current().setEventDetails("Project Id: " + id);
Project project = _projectService.suspendProject(id);
if (project != null) {
ProjectResponse response = _responseGenerator.createProjectResponse(project);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to suspend a project");
}
}
use of com.cloud.projects.Project in project CloudStack-archive by CloudStack-extras.
the class UpdateProjectCmd method execute.
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceAllocationException {
UserContext.current().setEventDetails("Project id: " + getId());
Project project = _projectService.updateProject(getId(), getDisplayText(), getAccountName());
if (project != null) {
ProjectResponse response = _responseGenerator.createProjectResponse(project);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update a project");
}
}
use of com.cloud.projects.Project in project cloudstack by apache.
the class AddAccountToProjectCmdTest method testGetEntityOwnerIdForProject.
/****
* Condition not handled in the code
*
*****/
/*
* @Test public void testGetEntityOwnerIdForNullProject() {
*
* ProjectService projectService = Mockito.mock(ProjectService.class);
* Mockito
* .when(projectService.getProject(Mockito.anyLong())).thenReturn(null);
* addAccountToProjectCmd._projectService = projectService;
*
* try { addAccountToProjectCmd.getEntityOwnerId(); }
* catch(InvalidParameterValueException exception) {
* Assert.assertEquals("Unable to find project by id 2",
* exception.getLocalizedMessage()); }
*
* }
*/
@Test
public void testGetEntityOwnerIdForProject() {
Project project = Mockito.mock(Project.class);
Mockito.when(project.getId()).thenReturn(2L);
ProjectService projectService = Mockito.mock(ProjectService.class);
Account account = Mockito.mock(Account.class);
Mockito.when(account.getId()).thenReturn(2L);
Mockito.when(projectService.getProject(Matchers.anyLong())).thenReturn(project);
Mockito.when(projectService.getProjectOwner(Matchers.anyLong())).thenReturn(account);
addAccountToProjectCmd._projectService = projectService;
Assert.assertEquals(2L, addAccountToProjectCmd.getEntityOwnerId());
}
use of com.cloud.projects.Project in project cloudstack by apache.
the class AssociateIPAddrCmd method getEntityOwnerId.
@Override
public long getEntityOwnerId() {
Account caller = CallContext.current().getCallingAccount();
if (accountName != null && domainId != null) {
Account account = _accountService.finalizeOwner(caller, accountName, domainId, projectId);
return account.getId();
} else if (projectId != null) {
Project project = _projectService.getProject(projectId);
if (project != null) {
if (project.getState() == Project.State.Active) {
return project.getProjectAccountId();
} else {
throw new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() + " as it's no longer active");
}
} else {
throw new InvalidParameterValueException("Unable to find project by ID");
}
} else if (networkId != null) {
Network network = _networkService.getNetwork(networkId);
if (network == null) {
throw new InvalidParameterValueException("Unable to find network by network id specified");
}
NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
if (zone.getNetworkType() == NetworkType.Basic && offering.getElasticIp() && offering.getElasticLb()) {
// shared network with EIP/ELB service.
return caller.getAccountId();
}
return network.getAccountId();
} else if (vpcId != null) {
Vpc vpc = _entityMgr.findById(Vpc.class, getVpcId());
if (vpc == null) {
throw new InvalidParameterValueException("Can't find enabled VPC by ID specified");
}
return vpc.getAccountId();
}
return caller.getAccountId();
}
use of com.cloud.projects.Project in project cloudstack by apache.
the class ResizeVolumeCmd method getEntityOwnerId.
@Override
public long getEntityOwnerId() {
Volume volume = _entityMgr.findById(Volume.class, getEntityId());
if (volume == null) {
throw new InvalidParameterValueException("Unable to find volume by id=" + id);
}
Account account = _accountService.getAccount(volume.getAccountId());
//Can resize volumes for enabled projects/accounts only
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
Project project = _projectService.findByProjectAccountId(volume.getAccountId());
if (project.getState() != Project.State.Active) {
throw new PermissionDeniedException("Can't add resources to project id=" + project.getId() + " in state=" + project.getState() + " as it's no longer active");
}
} else if (account.getState() == Account.State.disabled) {
throw new PermissionDeniedException("The owner of volume " + id + " is disabled: " + account);
}
return volume.getAccountId();
}
Aggregations