Examples of ApiLimitResponse


Examples of org.apache.cloudstack.api.response.ApiLimitResponse

        // issue get api limit calls
        final HashMap<String, String> params2 = new HashMap<String, String>();
        params2.put("response", "json");
        params2.put("sessionkey", sessionKey);
        String getResult =  sendRequest("getApiLimit", params2);
        ApiLimitResponse getLimitResp = (ApiLimitResponse)fromSerializedString(getResult, ApiLimitResponse.class);
        assertEquals("Issued api count is incorrect!", 2, getLimitResp.getApiIssued() ); // should be 2 apis issues plus this getlimit api
        assertEquals("Allowed api count is incorrect!", apiMax -2, getLimitResp.getApiAllowed());
    }
View Full Code Here

Examples of org.apache.cloudstack.api.response.ApiLimitResponse

        boolean apiLimitEnabled = Boolean.parseBoolean(_configDao.getValue(Config.ApiLimitEnabled.key()));
        if ( !apiLimitEnabled ){
            throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "This api is only available when api.throttling.enabled = true.");
        }
        Account caller = UserContext.current().getCaller();
        ApiLimitResponse response = _apiLimitService.searchApiLimit(caller);
        response.setResponseName(getCommandName());
        response.setObjectName("apilimit");
        this.setResponseObject(response);
    }
View Full Code Here

Examples of org.apache.cloudstack.api.response.ApiLimitResponse

        return true;
    }

    @Override
    public ApiLimitResponse searchApiLimit(Account caller) {
        ApiLimitResponse response = new ApiLimitResponse();
        response.setAccountId(caller.getUuid());
        response.setAccountName(caller.getAccountName());
        StoreEntry entry = _store.get(caller.getId());
        if (entry == null) {

            /* Populate the entry, thus unlocking any underlying mutex */
            entry = _store.create(caller.getId(), timeToLive);
            response.setApiIssued(0);
            response.setApiAllowed(maxAllowed);
            response.setExpireAfter(timeToLive);
        }
        else{
            response.setApiIssued(entry.getCounter());
            response.setApiAllowed(maxAllowed - entry.getCounter());
            response.setExpireAfter(entry.getExpireDuration());
        }

        return response;
    }
View Full Code Here

Examples of org.apache.cloudstack.api.response.ApiLimitResponse

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

        ApiLimitResponse response = _limitService.searchApiLimit(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);

    }
View Full Code Here

Examples of org.apache.cloudstack.api.response.ApiLimitResponse

        boolean apiLimitEnabled = Boolean.parseBoolean(_configDao.getValue(Config.ApiLimitEnabled.key()));
        if (!apiLimitEnabled) {
            throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "This api is only available when api.throttling.enabled = true.");
        }
        Account caller = CallContext.current().getCallingAccount();
        ApiLimitResponse response = _apiLimitService.searchApiLimit(caller);
        response.setResponseName(getCommandName());
        response.setObjectName("apilimit");
        this.setResponseObject(response);
    }
View Full Code Here

Examples of org.apache.cloudstack.api.response.ApiLimitResponse

        return true;
    }

    @Override
    public ApiLimitResponse searchApiLimit(Account caller) {
        ApiLimitResponse response = new ApiLimitResponse();
        response.setAccountId(caller.getUuid());
        response.setAccountName(caller.getAccountName());
        StoreEntry entry = _store.get(caller.getId());
        if (entry == null) {

            /* Populate the entry, thus unlocking any underlying mutex */
            entry = _store.create(caller.getId(), timeToLive);
            response.setApiIssued(0);
            response.setApiAllowed(maxAllowed);
            response.setExpireAfter(timeToLive);
        } else {
            response.setApiIssued(entry.getCounter());
            response.setApiAllowed(maxAllowed - entry.getCounter());
            response.setExpireAfter(entry.getExpireDuration());
        }

        return response;
    }
View Full Code Here

Examples of org.apache.cloudstack.api.response.ApiLimitResponse

        boolean apiLimitEnabled = Boolean.parseBoolean(_configDao.getValue(Config.ApiLimitEnabled.key()));
        if ( !apiLimitEnabled ){
            throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "This api is only available when api.throttling.enabled = true.");
        }
        Account caller = CallContext.current().getCallingAccount();
        ApiLimitResponse response = _apiLimitService.searchApiLimit(caller);
        response.setResponseName(getCommandName());
        response.setObjectName("apilimit");
        this.setResponseObject(response);
    }
View Full Code Here

Examples of org.apache.cloudstack.api.response.ApiLimitResponse

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

        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);

    }
View Full Code Here

Examples of org.apache.cloudstack.api.response.ApiLimitResponse

        // issue get api limit calls
        final HashMap<String, String> params2 = new HashMap<String, String>();
        params2.put("response", "json");
        params2.put("sessionkey", sessionKey);
        String getResult = sendRequest("getApiLimit", params2);
        ApiLimitResponse getLimitResp = (ApiLimitResponse)fromSerializedString(getResult, ApiLimitResponse.class);
        assertEquals("Issued api count is incorrect!", 2, getLimitResp.getApiIssued()); // should be 2 apis issues plus this getlimit api
        assertEquals("Allowed api count is incorrect!", apiMax - 2, getLimitResp.getApiAllowed());
    }
View Full Code Here

Examples of org.apache.cloudstack.api.response.ApiLimitResponse

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

        ApiLimitResponse response = _limitService.searchApiLimit(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);

    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.