本文整理汇总了Java中com.cloud.user.User类的典型用法代码示例。如果您正苦于以下问题:Java User类的具体用法?Java User怎么用?Java User使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
User类属于com.cloud.user包,在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import com.cloud.user.User; //导入依赖的package包/类
@Override
public void execute() throws InsufficientCapacityException, ConcurrentOperationException {
final User callerUser = _accountService.getActiveUser(CallContext.current().getCallingUserId());
final Account callerAccount = _accountService.getActiveAccountById(callerUser.getAccountId());
final Network network = _networkService.getNetwork(id);
if (network == null) {
throw new InvalidParameterValueException("Couldn't find network by id");
}
final Network result =
_networkService.updateGuestNetwork(getId(), getNetworkName(), getDisplayText(), callerAccount, callerUser, getNetworkDomain(), getNetworkOfferingId(),
getChangeCidr(), getGuestVmCidr(), getDisplayNetwork(), getCustomId(), getDns1(), getDns2(), getIpExclusionList());
if (result != null) {
final NetworkResponse response = _responseGenerator.createNetworkResponse(ResponseView.Full, result);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update network");
}
}
示例2: testHandle
import com.cloud.user.User; //导入依赖的package包/类
@Test
public void testHandle() throws ResourceAllocationException {
// Prepare
final BaseAsyncCreateCmd asyncCreateCmd = mock(BaseAsyncCreateCmd.class);
final Map<String, String> params = new HashMap<>();
final Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
final UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, account);
// Execute
final CommandCreationWorker creationWorker = new CommandCreationWorker();
creationWorker.handle(new DispatchTask(asyncCreateCmd, params));
// Assert
verify(asyncCreateCmd, times(1)).create();
}
示例3: execute
import com.cloud.user.User; //导入依赖的package包/类
@Override
public void execute() throws InsufficientCapacityException, ConcurrentOperationException {
final User callerUser = _accountService.getActiveUser(CallContext.current().getCallingUserId());
final Account callerAccount = _accountService.getActiveAccountById(callerUser.getAccountId());
final Network network = _networkService.getNetwork(id);
if (network == null) {
throw new InvalidParameterValueException("Couldn't find network by ID");
}
final Network result =
_networkService.updateGuestNetwork(getId(), getNetworkName(), getDisplayText(), callerAccount, callerUser, getNetworkDomain(), getNetworkOfferingId(),
getChangeCidr(), getGuestVmCidr(), getDisplayNetwork(), getCustomId(), getDns1(), getDns2(), getIpExclusionList());
if (result != null) {
final NetworkResponse response = _responseGenerator.createNetworkResponse(ResponseView.Restricted, result);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update network");
}
}
示例4: createCloudstackUserAccount
import com.cloud.user.User; //导入依赖的package包/类
private void createCloudstackUserAccount(final LdapUser user, final String accountName, final Domain domain) {
final Account account = _accountService.getActiveAccountByName(accountName, domain.getId());
if (account == null) {
s_logger.debug("No account exists with name: " + accountName + " creating the account and an user with name: " + user.getUsername() + " in the account");
_accountService.createUserAccount(user.getUsername(), generatePassword(), user.getFirstname(), user.getLastname(), user.getEmail(), timezone, accountName, accountType,
domain.getId(), domain.getNetworkDomain(), details, UUID.randomUUID().toString(), UUID.randomUUID().toString(), User.Source.LDAP);
} else {
// check if the user exists. if yes, call update
final UserAccount csuser = _accountService.getActiveUserAccount(user.getUsername(), domain.getId());
if (csuser == null) {
s_logger.debug("No user exists with name: " + user.getUsername() + " creating a user in the account: " + accountName);
_accountService.createUser(user.getUsername(), generatePassword(), user.getFirstname(), user.getLastname(), user.getEmail(), timezone, accountName, domain.getId(),
UUID.randomUUID().toString(), User.Source.LDAP);
} else {
s_logger.debug("account with name: " + accountName + " exist and user with name: " + user.getUsername() + " exists in the account. Updating the account.");
_accountService.updateUser(csuser.getId(), user.getFirstname(), user.getLastname(), user.getEmail(), null, null, null, null, null);
}
}
}
示例5: setUp
import com.cloud.user.User; //导入依赖的package包/类
@Before
public void setUp() {
_lbMgr._accountMgr = new MockAccountManagerImpl();
_lbMgr._networkDao = netDao;
_lbMgr._networkModel = netModel;
_lbMgr._lb2healthcheckDao = Mockito.mock(LBHealthCheckPolicyDao.class);
_lbMgr._lb2stickinesspoliciesDao = Mockito.mock(LBStickinessPolicyDao.class);
_lbMgr._lb2VmMapDao = Mockito.mock(LoadBalancerVMMapDao.class);
_lbMgr._lbCertMapDao = Mockito.mock(LoadBalancerCertMapDao.class);
_lbMgr._lbDao = lbDao;
_lbMgr._lbProviders = new ArrayList<LoadBalancingServiceProvider>();
_lbMgr._lbProviders.add(lbServiceProvider);
updateLbRuleCmd = new UpdateLoadBalancerRuleCmd();
final AccountVO account = new AccountVO(accountName, domainId, "networkDomain", Account.ACCOUNT_TYPE_NORMAL, "uuid");
final UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, account);
}
示例6: disableApiLimit
import com.cloud.user.User; //导入依赖的package包/类
@Test
public void disableApiLimit() throws Exception {
try {
final int allowedRequests = 200;
s_limitService.setMaxAllowed(allowedRequests);
s_limitService.setTimeToLive(1);
s_limitService.setEnabled(false);
final User key = createFakeUser();
for (int i = 0; i < allowedRequests + 1; i++) {
assertTrue("We should allow more than " + allowedRequests + " requests per second when api throttling is disabled.", isUnderLimit(key));
}
} finally {
s_limitService.setEnabled(true); // enable api throttling to avoid
// impacting other testcases
}
}
示例7: checkAccess
import com.cloud.user.User; //导入依赖的package包/类
@Override
public boolean checkAccess(final User user, final String commandName) throws PermissionDeniedException {
final Account account = _accountService.getAccount(user.getAccountId());
if (account == null) {
throw new PermissionDeniedException("The account id=" + user.getAccountId() + "for user id=" + user.getId() + "is null");
}
final RoleType roleType = _accountService.getRoleType(account);
final boolean isAllowed =
commandsPropertiesOverrides.contains(commandName) ? commandsPropertiesRoleBasedApisMap.get(roleType).contains(commandName) : annotationRoleBasedApisMap.get(
roleType).contains(commandName);
if (!isAllowed) {
throw new PermissionDeniedException("The API does not exist or is blacklisted. Role type=" + roleType.toString() + " is not allowed to request the api: " +
commandName);
}
return isAllowed;
}
示例8: testResourceLimitCheckForUploadedVolume
import com.cloud.user.User; //导入依赖的package包/类
@Test
public void testResourceLimitCheckForUploadedVolume() throws NoSuchFieldException, IllegalAccessException, ResourceAllocationException {
doThrow(new ResourceAllocationException("primary storage resource limit check failed", Resource.ResourceType.primary_storage)).when(_svc._resourceLimitMgr).checkResourceLimit(any(AccountVO.class), any(Resource.ResourceType.class), any(Long.class));
UserVmVO vm = Mockito.mock(UserVmVO.class);
VolumeInfo volumeToAttach = Mockito.mock(VolumeInfo.class);
when(volumeToAttach.getId()).thenReturn(9L);
when(volumeToAttach.getDataCenterId()).thenReturn(34L);
when(volumeToAttach.getVolumeType()).thenReturn(Volume.Type.DATADISK);
when(volumeToAttach.getInstanceId()).thenReturn(null);
when(_userVmDao.findById(anyLong())).thenReturn(vm);
when(vm.getType()).thenReturn(VirtualMachine.Type.User);
when(vm.getState()).thenReturn(State.Running);
when(vm.getDataCenterId()).thenReturn(34L);
when(_svc._volsDao.findByInstanceAndType(anyLong(), any(Volume.Type.class))).thenReturn(new ArrayList(10));
when(_svc.volFactory.getVolume(9L)).thenReturn(volumeToAttach);
when(volumeToAttach.getState()).thenReturn(Volume.State.Uploaded);
DataCenterVO zoneWithDisabledLocalStorage = Mockito.mock(DataCenterVO.class);
when(_svc._dcDao.findById(anyLong())).thenReturn(zoneWithDisabledLocalStorage);
when(zoneWithDisabledLocalStorage.isLocalStorageEnabled()).thenReturn(true);
try {
_svc.attachVolumeToVM(2L, 9L, null);
} catch (InvalidParameterValueException e) {
Assert.assertEquals(e.getMessage(), ("primary storage resource limit check failed"));
}
}
示例9: createNewVmWorkJob
import com.cloud.user.User; //导入依赖的package包/类
private VmWorkJobVO createNewVmWorkJob(final VirtualMachine vm, final Network network, final NicProfile requested, final CallContext context, final User user, final Account
account) {
final VmWorkJobVO workJob;
workJob = new VmWorkJobVO(context.getContextId());
workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
workJob.setCmd(VmWorkAddVmToNetwork.class.getName());
workJob.setAccountId(account.getId());
workJob.setUserId(user.getId());
workJob.setVmType(VirtualMachine.Type.Instance);
workJob.setVmInstanceId(vm.getId());
workJob.setRelated(AsyncJobExecutionContext.getOriginJobId());
// save work context info (there are some duplications)
final String vmWorkJobHandler = VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER;
final VmWorkAddVmToNetwork workInfo = new VmWorkAddVmToNetwork(user.getId(), account.getId(), vm.getId(), vmWorkJobHandler, network.getId(), requested);
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
_jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
s_logger.info("Submitted new job to queue to add vm " + vm + " to network " + network);
return workJob;
}
示例10: setUp
import com.cloud.user.User; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws ConfigurationException {
testApiName = testCmdClass.getAnnotation(APICommand.class).name();
testApiDescription = testCmdClass.getAnnotation(APICommand.class).description();
testApiSince = testCmdClass.getAnnotation(APICommand.class).since();
testApiAsync = false;
testUser = new UserVO();
s_discoveryService._apiAccessCheckers = mock(List.class);
s_discoveryService._services = mock(List.class);
when(s_apiChecker.checkAccess(any(User.class), anyString())).thenReturn(true);
when(s_pluggableService.getCommands()).thenReturn(new ArrayList<>());
when(s_discoveryService._apiAccessCheckers.iterator()).thenReturn(Arrays.asList(s_apiChecker).iterator());
when(s_discoveryService._services.iterator()).thenReturn(Arrays.asList(s_pluggableService).iterator());
final Set<Class<?>> cmdClasses = new HashSet<>();
cmdClasses.add(ListApisCmd.class);
s_discoveryService.start();
s_discoveryService.cacheResponseMap(cmdClasses);
}
示例11: verifySearchCounter
import com.cloud.user.User; //导入依赖的package包/类
@Test
public void verifySearchCounter() throws Exception {
final int allowedRequests = 10;
s_limitService.setMaxAllowed(allowedRequests);
s_limitService.setTimeToLive(1);
final User key = createFakeUser();
for (int i = 0; i < 5; i++) {
assertTrue("Issued 5 requests", isUnderLimit(key));
}
final ApiLimitResponse response = s_limitService.searchApiLimit(s_testAccount);
assertEquals("apiIssued is incorrect", 5, response.getApiIssued());
assertEquals("apiAllowed is incorrect", 5, response.getApiAllowed());
// using <= to account for inaccurate System.currentTimeMillis() clock in Windows environment
assertTrue("expiredAfter is incorrect", response.getExpireAfter() <= 1000);
}
示例12: rebootRouters
import com.cloud.user.User; //导入依赖的package包/类
private List<Long> rebootRouters(final List<DomainRouterVO> routers) {
final List<Long> jobIds = new ArrayList<>();
for (final DomainRouterVO router : routers) {
if (!_nwHelper.checkRouterVersion(router)) {
s_logger.debug("Upgrading template for router: " + router.getId());
final Map<String, String> params = new HashMap<>();
params.put("ctxUserId", "1");
params.put("ctxAccountId", "" + router.getAccountId());
final RebootRouterCmd cmd = new RebootRouterCmd();
ComponentContext.inject(cmd);
params.put("id", "" + router.getId());
params.put("ctxStartEventId", "1");
final AsyncJobVO job = new AsyncJobVO("", User.UID_SYSTEM, router.getAccountId(), RebootRouterCmd.class.getName(), ApiGsonHelper.getBuilder().create().toJson
(params),
router.getId(), cmd.getInstanceType() != null ? cmd.getInstanceType().toString() : null, null);
job.setDispatcher(_asyncDispatcher.getName());
final long jobId = _asyncMgr.submitAsyncJob(job);
jobIds.add(jobId);
} else {
s_logger.debug("Router: " + router.getId() + " is already at the latest version. No upgrade required");
}
}
return jobIds;
}
示例13: testRestoreVMF1
import com.cloud.user.User; //导入依赖的package包/类
@Test(expected = CloudRuntimeException.class)
public void testRestoreVMF1() throws ResourceAllocationException, InsufficientCapacityException, ResourceUnavailableException {
when(_vmDao.findById(anyLong())).thenReturn(_vmMock);
when(_templateDao.findById(anyLong())).thenReturn(_templateMock);
doReturn(VirtualMachine.State.Error).when(_vmMock).getState();
final Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
final UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, account);
try {
_userVmMgr.restoreVMInternal(_account, _vmMock, null);
} finally {
CallContext.unregister();
}
}
示例14: testScaleVMF3
import com.cloud.user.User; //导入依赖的package包/类
public void testScaleVMF3() throws Exception {
final ScaleVMCmd cmd = new ScaleVMCmd();
final Class<?> _class = cmd.getClass();
final Field idField = _class.getDeclaredField("id");
idField.setAccessible(true);
idField.set(cmd, 1L);
final Field serviceOfferingIdField = _class.getDeclaredField("serviceOfferingId");
serviceOfferingIdField.setAccessible(true);
serviceOfferingIdField.set(cmd, 1L);
when(_vmInstanceDao.findById(anyLong())).thenReturn(_vmInstance);
doReturn(Hypervisor.HypervisorType.XenServer).when(_vmInstance).getHypervisorType();
final ServiceOffering so1 = getSvcoffering(512);
final ServiceOffering so2 = getSvcoffering(256);
when(_entityMgr.findById(eq(ServiceOffering.class), anyLong())).thenReturn(so2);
when(_entityMgr.findById(ServiceOffering.class, 1L)).thenReturn(so1);
doReturn(VirtualMachine.State.Stopped).when(_vmInstance).getState();
when(_vmDao.findById(anyLong())).thenReturn(null);
doReturn(true).when(_itMgr).upgradeVmDb(anyLong(), anyLong());
//when(_vmDao.findById(anyLong())).thenReturn(_vmMock);
final Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, UUID.randomUUID().toString());
final UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, account);
try {
_userVmMgr.upgradeVirtualMachine(cmd);
} finally {
CallContext.unregister();
}
}
示例15: testPopulateFirstClassEntities
import com.cloud.user.User; //导入依赖的package包/类
@Test
public void testPopulateFirstClassEntities() {
final AccountVO account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
account.setId(ACCOUNT_ID);
final UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone",
UUID.randomUUID().toString(), User.Source.UNKNOWN);
Mockito.when(accountDao.findById(ACCOUNT_ID)).thenReturn(account);
Mockito.when(userDao.findById(USER_ID)).thenReturn(user);
CallContext.register(user, account);
//Inject some entity UUIDs into the call context
final String instanceUuid = UUID.randomUUID().toString();
final String ipUuid = UUID.randomUUID().toString();
CallContext.current().putContextParameter(VirtualMachine.class, instanceUuid);
CallContext.current().putContextParameter(IpAddress.class, ipUuid);
ActionEventUtils.onActionEvent(USER_ID, ACCOUNT_ID, account.getDomainId(), "StaticNat", "Test event");
//Assertions
Assert.assertNotEquals(publishedEvents.size(), 0);
Assert.assertEquals(publishedEvents.size(), 1);
final Event event = publishedEvents.get(0);
Assert.assertNotNull(event.getDescription());
final JsonObject json = new JsonParser().parse(event.getDescription()).getAsJsonObject();
Assert.assertTrue(json.has("VirtualMachine"));
Assert.assertTrue(json.has("IpAddress"));
Assert.assertEquals(json.get("VirtualMachine").getAsString(), instanceUuid);
Assert.assertEquals(json.get("IpAddress").getAsString(), ipUuid);
CallContext.unregister();
}