Package com.cloud.user

Examples of com.cloud.user.User


    public void sequentialApiAccess() {
        int allowedRequests = 1;
        _limitService.setMaxAllowed(allowedRequests);
        _limitService.setTimeToLive(1);

        User key = createFakeUser();
        assertTrue("Allow for the first request", isUnderLimit(key));

        assertFalse("Second request should be blocked, since we assume that the two api "
                + " accesses take less than a second to perform", isUnderLimit(key));
    }
View Full Code Here


    public void canDoReasonableNumberOfApiAccessPerSecond() throws Exception {
        int allowedRequests = 200;
        _limitService.setMaxAllowed(allowedRequests);
        _limitService.setTimeToLive(1);

        User key = createFakeUser();

        for (int i = 0; i < allowedRequests; i++) {
            assertTrue("We should allow " + allowedRequests + " requests per second, but failed at request " + i, isUnderLimit(key));
        }
View Full Code Here

        int allowedRequests = 200;
        _limitService.setMaxAllowed(allowedRequests);
        _limitService.setTimeToLive(1);


        final User key = createFakeUser();

        int clientCount = allowedRequests;
        Runnable[] clients = new Runnable[clientCount];
        final boolean[] isUsable = new boolean[clientCount];
View Full Code Here

    public void expiryOfCounterIsSupported() throws Exception {
        int allowedRequests = 1;
        _limitService.setMaxAllowed(allowedRequests);
        _limitService.setTimeToLive(1);

        User key = this.createFakeUser();

        assertTrue("The first request should be allowed", isUnderLimit(key));

        // Allow the token to expire
        Thread.sleep(1020);
View Full Code Here

    public void verifyResetCounters() throws Exception {
        int allowedRequests = 1;
        _limitService.setMaxAllowed(allowedRequests);
        _limitService.setTimeToLive(1);

        User key = this.createFakeUser();

        assertTrue("The first request should be allowed", isUnderLimit(key));

        assertFalse("Another request should be blocked", isUnderLimit(key));

        _limitService.resetApiLimit(key.getAccountId());

        assertTrue("Another request should be allowed after reset counter", isUnderLimit(key));
    }
View Full Code Here

    public void verifySearchCounter() throws Exception {
        int allowedRequests = 10;
        _limitService.setMaxAllowed(allowedRequests);
        _limitService.setTimeToLive(1);

        User key = this.createFakeUser();

        for ( int i = 0; i < 5; i++ ){
            assertTrue("Issued 5 requests", isUnderLimit(key));
        }
View Full Code Here

            int allowedRequests = 200;
            _limitService.setMaxAllowed(allowedRequests);
            _limitService.setTimeToLive(1);
            _limitService.setEnabled(false);

            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));
            }
View Full Code Here

        types.add(DataStoreProvider.DataStoreProviderType.PRIMARY);

        when(primaryDataStoreProvider.getTypes()).thenReturn(types);
        when(primaryDataStoreProvider.getName()).thenReturn(DataStoreProvider.DEFAULT_PRIMARY);
        when(primaryDataStoreProvider.getDataStoreDriver()).thenReturn(driver);
        User user = mock(User.class);
        when(user.getId()).thenReturn(1L);
        Account account = mock(Account.class);
        when(account.getId()).thenReturn(1L);
        when(accountManager.getSystemAccount()).thenReturn(account);
        when(accountManager.getSystemUser()).thenReturn(user);
View Full Code Here

    @Override
    public boolean startVpc(long vpcId, boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException,
    InsufficientCapacityException {
        UserContext ctx = UserContext.current();
        Account caller = ctx.getCaller();
        User callerUser = _accountMgr.getActiveUser(ctx.getCallerUserId());
       
        //check if vpc exists
        Vpc vpc = getActiveVpc(vpcId);
        if (vpc == null) {
            InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find Enabled VPC by id specified");
            ex.addProxyObject(String.valueOf(vpcId), "VPC");
            throw ex;
        }
       
        //permission check
        _accountMgr.checkAccess(caller, null, false, vpc);
       
        DataCenter dc = _configMgr.getZone(vpc.getZoneId());
    
        DeployDestination dest = new DeployDestination(dc, null, null, null);
        ReservationContext context = new ReservationContextImpl(null, null, callerUser,
                _accountMgr.getAccount(vpc.getAccountId()));
       
        boolean result = true;
        try {
            if (!startVpc(vpc, dest, context)) {
                s_logger.warn("Failed to start vpc " + vpc);
                result = false;
            }
        } catch (Exception ex) {
            s_logger.warn("Failed to start vpc " + vpc + " due to ", ex);
            result = false;
        } finally {
            //do cleanup
            if (!result && destroyOnFailure) {
                s_logger.debug("Destroying vpc " + vpc + " that failed to start");
                if (destroyVpc(vpc, caller, callerUser.getId())) {
                    s_logger.warn("Successfully destroyed vpc " + vpc + " that failed to start");
                } else {
                    s_logger.warn("Failed to destroy vpc " + vpc + " that failed to start");
                }
            }
View Full Code Here

            _privateIpDao.remove(ip.getId());
            s_logger.debug("Deleted private ip " + ip);
        }
       
        if (deleteNetwork) {
            User callerUser = _accountMgr.getActiveUser(UserContext.current().getCallerUserId());
            Account owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
            ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
            _ntwkMgr.destroyNetwork(networkId, context);
            s_logger.debug("Deleted private network id=" + networkId);
        }
View Full Code Here

TOP

Related Classes of com.cloud.user.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.