Package com.alu.e3.data.model

Examples of com.alu.e3.data.model.Limit


    HashSet<Integer> lockedSet = new HashSet<Integer>();
   
    try {
      // step1 : test if call is success
      Iterator<CallDescriptor> it = authIdentity.getCallDescriptors().iterator();
      Limit limit = new Limit();

      while (it.hasNext()) {
        CallDescriptor callDescriptor = it.next();
        Integer bucketID = callDescriptor.getBucketId();
        Integer contextId = callDescriptor.getContextId();

        this.dataManager.fillLimitsById(contextId, limit);

        if ((limit.getQuotaPerDay()!=null) || (limit.getQuotaPerWeek()!=null) || (limit.getQuotaPerMonth()!=null)
            || (limit.getRateLimitPerMinute()!=null) || (limit.getRateLimitPerSecond()!=null)) {     
         
          LockCounter lock = this.gdm.getLockForBucket(bucketID);
         
          synchronized (lock) {
         
            lockedSet.add(bucketID);

            GatewayRate gr = gatewayRateValidator.getRateForBucket(bucketID, limit, mustResetRateLimit);
           
            gatewayRateValidator.updateRateLimitAndQuotaValues(gr, limit, currentTime);
           
            params.gr = gr;
            params.limit = limit;
            params.callDescriptor = callDescriptor;
           
            gatewayRateValidator.checkRateLimitAndQuota(apiCallStatus, params);
           
            this.gdm.releaseLockForBucket(bucketID, lock);
            lockedSet.remove(bucketID);
          }
        }
      }
     
      // TODO: maybe increment always in previous loop and decrement all gr only if call was failed
      // step2: save data for call success or fail
      it = authIdentity.getCallDescriptors().iterator();
      while (it.hasNext())
      {
        CallDescriptor callDescriptor = it.next();
        Integer bucketID = callDescriptor.getBucketId();
        Integer contextId = callDescriptor.getContextId();
        this.dataManager.fillLimitsById(contextId, limit);

        if ((limit.getQuotaPerDay()!=null) || (limit.getQuotaPerWeek()!=null) || (limit.getQuotaPerMonth()!=null)
            || (limit.getRateLimitPerMinute()!=null) || (limit.getRateLimitPerSecond()!=null))
        { 
          LockCounter lock = this.gdm.getLockForBucket(bucketID);

          synchronized (lock) {
           
View Full Code Here


  }

  @Override
  public void checkRateLimitAndQuota(ApiCallStatus apiCallStatus, RateLimitParams params) {
    GatewayRate gr = params.gr;
    Limit limit = params.limit;
   
    if (isValueOverLimit(gr.localApiCallsSinceOneSecond, gr.localRateLimitSecond)) {
      apiCallStatus.apiCallIsSuccess = false;
      apiCallStatus.apiCallAction = (limit.getRateLimitPerSecond().getAction() != null) ? limit.getRateLimitPerSecond().getAction() : E3Constant.DEFAULT_ERROR_ACTION;
    }
    else if (isValueOverLimit(gr.localApiCallsSinceOneMinute, gr.localRateLimitMinute)) {
      apiCallStatus.apiCallIsSuccess = false;
      apiCallStatus.apiCallAction = (limit.getRateLimitPerMinute().getAction() != null) ? limit.getRateLimitPerMinute().getAction() : E3Constant.DEFAULT_ERROR_ACTION;
    }
    else if (isValueOverLimit(gr.localApiCallsSinceOneDay, gr.localQuotaLimitDay)) {
      apiCallStatus.apiCallIsSuccess = false;
      apiCallStatus.apiCallAction = (limit.getQuotaPerDay().getAction() != null) ? limit.getQuotaPerDay().getAction() : E3Constant.DEFAULT_ERROR_ACTION;
    }
    else if (isValueOverLimit(gr.localApiCallsSinceOneWeek, gr.localQuotaLimitWeek)) {
      apiCallStatus.apiCallIsSuccess = false;
      apiCallStatus.apiCallAction = (limit.getQuotaPerWeek().getAction() != null) ? limit.getQuotaPerWeek().getAction() : E3Constant.DEFAULT_ERROR_ACTION;
    }
    else if (isValueOverLimit(gr.localApiCallsSinceOneMonth, gr.localQuotaLimitMonth)) {
      apiCallStatus.apiCallIsSuccess = false;
      apiCallStatus.apiCallAction = (limit.getQuotaPerMonth().getAction() != null) ? limit.getQuotaPerMonth().getAction() : E3Constant.DEFAULT_ERROR_ACTION;
    }   
  }
View Full Code Here

    props.putAll(identity.getApi().getProperties());
    Iterator<CallDescriptor> it = identity.getCallDescriptors().iterator();
    while(it.hasNext()){
      CallDescriptor cd = it.next();
      Policy policy = cd.getPolicy();
      if(policy != null){
        props.putAll(policy.getProperties());
      }
    }

    if(identity.getAuth() != null)
      props.putAll(identity.getAuth().getProperties());
View Full Code Here

    // Next add all of the tdr values for the Policies
    Iterator<CallDescriptor> it = identity.getCallDescriptors().iterator();
    while(it.hasNext()){
      CallDescriptor cd = it.next();
      Policy policy = cd.getPolicy();
      if(policy != null){
        if(doStatic)
          processTdrGenerationRuleStatic(policy.getTdrGenerationRule(), exchange, properties);
        else
          processTdrGenerationRuleDynamic(policy.getTdrGenerationRule(), exchange, properties, efType);
      }
    }

    // Finally add the values from the Auth
    Auth auth = identity.getAuth();
View Full Code Here

  }

  private static final LoadBalancing toDataModel(com.alu.e3.prov.restapi.model.LoadBalancing loadBalancing) {
    if (loadBalancing==null) throw new IllegalArgumentException("loadBalancing must not be null");

    LoadBalancing lb = new LoadBalancing();
    lb.setLoadBalancingType(toDataModel(loadBalancing.getLoadBalancingType()));

    if(loadBalancing.getTargetHealthCheck() != null)
      lb.setTargetHealthCheck(toDataModel(loadBalancing.getTargetHealthCheck()));

    if(loadBalancing.getFailOver() != null)
      lb.setFailOver(toDataModel(loadBalancing.getFailOver()));

    return lb;
  }
View Full Code Here

  }

  public static final QuotaRLBucket toDataModel(com.alu.e3.prov.restapi.model.AuthIdsNoIdType authIds) {
    if (authIds==null) throw new IllegalArgumentException("authIds must not be null");

    QuotaRLBucket ids = new QuotaRLBucket();
    ids.getAuthIds().addAll(authIds.getAuthIds());
    ids.setId(authIds.getId());

    return ids;
  }
View Full Code Here

  private static final QuotaRLBucket toDataModel(com.alu.e3.prov.restapi.model.AuthIdsType authIds) {
    if (authIds==null) throw new IllegalArgumentException("authIds must not be null");
    if (authIds.getId()==null) throw new IllegalArgumentException("id must not be null");

    QuotaRLBucket ids = new QuotaRLBucket();
    ids.getAuthIds().addAll(authIds.getAuthIds());
    ids.setId(authIds.getId());

    return ids;
  }
View Full Code Here

    return t;
  }

  private static final SBAuthentication toDataModel(Authentication authentication) {
    if (authentication==null) return null; // throw new IllegalArgumentException("authentication must not be null");
    SBAuthentication s = new SBAuthentication();
    s.setType(authentication.getType());
    for (Key k : authentication.getData().getKey())
      s.getKeys().put(k.getName(), k.getValue());
    return s;
  }
View Full Code Here

  }

  private static final TargetHealthCheck toDataModel(com.alu.e3.prov.restapi.model.TargetHealthCheck targetHealthCheckType) {
    if (targetHealthCheckType==null) throw new IllegalArgumentException("targetHealthCheckType must not be null");

    TargetHealthCheck thc = new TargetHealthCheck();
    thc.setType(targetHealthCheckType.getType());

    return thc;
  }
View Full Code Here

    return apiContext;
  }

  private static final TargetHost toDataModel(com.alu.e3.prov.restapi.model.TargetHost targetHost) {
    if (targetHost==null) throw new IllegalArgumentException("targetHost must not be null");
    TargetHost t = new TargetHost();
    t.setUrl        (targetHost.getUrl());
    t.setSite        (targetHost.getSite());
    t.setAuthentication    (toDataModel(targetHost.getAuthentication()));
    if (targetHost.getConnectionParameters() != null)
      t.setConnectionParameters(toDataModel(targetHost.getConnectionParameters()));
   
    return t;
  }
View Full Code Here

TOP

Related Classes of com.alu.e3.data.model.Limit

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.