use of com.cloud.legacymodel.user.Account in project cosmic by MissionCriticalCloud.
the class AssociateIPAddrCmd method getEntityOwnerId.
@Override
public long getEntityOwnerId() {
final Account caller = CallContext.current().getCallingAccount();
if (accountName != null && domainId != null) {
final Account account = _accountService.finalizeOwner(caller, accountName, domainId, projectId);
return account.getId();
} else if (projectId != null) {
final 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) {
final Network network = _networkService.getNetwork(networkId);
if (network == null) {
throw new InvalidParameterValueException("Unable to find network by network id specified");
}
final NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
final 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) {
final 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.legacymodel.user.Account in project cosmic by MissionCriticalCloud.
the class ActivateProjectCmdTest method testGetEntityOwnerIdForProject.
@Test
public void testGetEntityOwnerIdForProject() {
final Project project = Mockito.mock(Project.class);
Mockito.when(project.getId()).thenReturn(2L);
final ProjectService projectService = Mockito.mock(ProjectService.class);
final 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);
activateProjectCmd._projectService = projectService;
Assert.assertEquals(2L, activateProjectCmd.getEntityOwnerId());
}
use of com.cloud.legacymodel.user.Account in project cosmic by MissionCriticalCloud.
the class CallContext method register.
public static CallContext register(final long callingUserId, final long callingAccountId, final String contextId) throws CloudAuthenticationException {
final Account account = s_entityMgr.findById(Account.class, callingAccountId);
if (account == null) {
throw new CloudAuthenticationException("The account is no longer current.").add(Account.class, Long.toString(callingAccountId));
}
final User user = s_entityMgr.findById(User.class, callingUserId);
if (user == null) {
throw new CloudAuthenticationException("The user is no longer current.").add(User.class, Long.toString(callingUserId));
}
return register(user, account, contextId);
}
use of com.cloud.legacymodel.user.Account in project cosmic by MissionCriticalCloud.
the class CallContext method register.
public static CallContext register(final long callingUserId, final long callingAccountId) throws CloudAuthenticationException {
final Account account = s_entityMgr.findById(Account.class, callingAccountId);
if (account == null) {
throw new CloudAuthenticationException("The account is no longer current.").add(Account.class, Long.toString(callingAccountId));
}
final User user = s_entityMgr.findById(User.class, callingUserId);
if (user == null) {
throw new CloudAuthenticationException("The user is no longer current.").add(User.class, Long.toString(callingUserId));
}
return register(user, account);
}
use of com.cloud.legacymodel.user.Account in project cosmic by MissionCriticalCloud.
the class LogContext method register.
public static LogContext register(final String callingUserUuid, final String callingAccountUuid) {
final Account account = s_entityMgr.findByUuid(Account.class, callingAccountUuid);
if (account == null) {
throw new CloudAuthenticationException("The account is no longer current.").add(Account.class, callingAccountUuid);
}
final User user = s_entityMgr.findByUuid(User.class, callingUserUuid);
if (user == null) {
throw new CloudAuthenticationException("The user is no longer current.").add(User.class, callingUserUuid);
}
return register(user, account);
}
Aggregations