Package com.alu.e3.data.model

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


            int policyIdx = -1;
            if (policy != null && policy.getContextIds().size() > 0) {
              policyIdx = policy.getContextIds().get(0);
            }
           
            result.add(new CallDescriptor(policy, policyIdx , -1));

          }
        }

        // Now, add the CallDescriptor of the "default" context
        if (api.getContextIds().isEmpty() == false) {
          if (result == null)
            result = new ArrayList<CallDescriptor>();

          // Looking for default context, placed at index 0 by addApi
          ApiIds ctx = api.getContextIds().get(0);
          if (ctx.isStatusActive()) {
            if (logger.isDebugEnabled()) {
              logger.debug("Adding CallDescriptor({}, {}, {})", new String[] {
                  null,
                  ""+ctx.getApiContextId(),
                  ""+ctx.getApiBucketId()
                  });
            }
            result.add(new CallDescriptor(null, ctx.getApiContextId(), ctx.getApiBucketId()));
          }
        }
      }
    } else {

      // We have an Auth and an API, check matching policies
      for (AuthIds authCtx : auth.getPolicyContexts()) {

        String policyIdInAuth = authCtx.getPolicyId();

        boolean policyAdded = false;

        // API may be null if Auth is for "Company"
        if (api != null) {
          for (String policyIdInApi : api.getPolicyIds()) {

            // Matching means that the policy is in Auth and API
            if (policyIdInApi.equals(policyIdInAuth)) {
              Policy policy = getPolicyById(policyIdInAuth);
              if (result == null)
                result = new ArrayList<CallDescriptor>();
              if (authCtx.isStatusActive()) {
                if (logger.isDebugEnabled()) {
                  logger.debug("Adding CallDescriptor({}, {}, {})", new String[] {
                      policy.getId(),
                      ""+authCtx.getPolicyContextId(),
                      ""+authCtx.getPolicyBucketId()
                      });
                }
                result.add(new CallDescriptor(policy, authCtx.getPolicyContextId(), authCtx.getPolicyBucketId()));
              }
              policyAdded = true;
            }
          }
        }

        // If the policy wasn't added...
        if (!policyAdded) {
          // Slow, but need to check if that policy has some API attached
          Policy policy = getPolicyById(policyIdInAuth, false);
          if ((policy.getApiIds() == null) || policy.getApiIds().isEmpty()) {
            if (result == null)
              result = new ArrayList<CallDescriptor>();
            if (authCtx.isStatusActive()) {
              result.add(new CallDescriptor(policy, authCtx.getPolicyContextId(), authCtx.getPolicyBucketId()));
            }
          }
        }
      }

      // Now check the apiContext on the auth which is in the list of API
      if (api != null) {
        for (ApiIds ctx : api.getContextIds()) {
          if (ctx.getApiContextName().equals(auth.getApiContext())) {
            if (result == null)
              result = new ArrayList<CallDescriptor>();
            if (ctx.isStatusActive()) {
              if (logger.isDebugEnabled()) {
                logger.debug("Adding CallDescriptor({}, {}, {})", new String[] {
                    null,
                    ""+ctx.getApiContextId(),
                    ""+ctx.getApiBucketId()
                    });
              }
              result.add(new CallDescriptor(null, ctx.getApiContextId(), ctx.getApiBucketId()));
            }
          }
        }
      }
    }
View Full Code Here


    Api api = new Api();
    api.setStatus(StatusType.ACTIVE);
    this.setApi(api);   
    if(isAlwaysHappy) {
      this.setAuth(new Auth());
      this.getCallDescriptors().add(new CallDescriptor(new Policy(), 1, 2));
    }
  }
View Full Code Here

   
    // No policy found for the API
    // assertNull(dataAccess.isAllowed("api"));
   
    Policy policy = new Policy();
    mockDataManager.getCallDescriptors().add(new CallDescriptor(policy, 1, 2));
   
   
    AuthReport authReport = dataAccess.checkAllowed(api);
    AuthIdentity authIdentity = authReport.getAuthIdentity();
    assertNotNull(authIdentity);
View Full Code Here

    assertNull(dataAccess.checkAllowed(api, "authKey").getAuthIdentity());
    assertNull(dataAccess.checkAllowed(api, "username", "password").getAuthIdentity());
    assertNull(dataAccess.checkAllowed(api, new CanonicalizedIpAddress("127.0.0.1")).getAuthIdentity());
   
    Policy policy = new Policy();
    mockDataManager.getCallDescriptors().add(new CallDescriptor(policy, 1, 2));
   
    AuthIdentity authIdentity = dataAccess.checkAllowed(api, "authKey").getAuthIdentity();
    assertNotNull(authIdentity);   
    assertNotNull(authIdentity.getApi() == api); // compare memory reference
    assertNotNull(authIdentity.getAuth() == auth); // compare memory reference
View Full Code Here

    id = new AuthIdentity();
    api = new Api();
    policy1 = new Policy();
    auth = new Auth();
    CallDescriptor cd = new CallDescriptor(policy1, 0, 0);

    id.setApi(api);
    id.setAuth(auth);
    id.getCallDescriptors().add(cd);
View Full Code Here

      // 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))
        { 
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

TOP

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

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.