Examples of CNSTopicDeliveryPolicy


Examples of com.comcast.cns.model.CNSTopicDeliveryPolicy

      String maxDelay = request.getParameter("maxDelay");
      String maxDelayRetries = request.getParameter("maxDelayRetries");
      String maxReceiveRate = request.getParameter("maxReceiveRate");
      String backoffFunc = request.getParameter("backoffFunc");
      String ignoreOverride = request.getParameter("ignoreOverride");
      CNSTopicDeliveryPolicy deliveryPolicy = new CNSTopicDeliveryPolicy();
      CNSRetryPolicy defaultHealthyRetryPolicy = new CNSRetryPolicy();
     
      if (maxDelay.trim().length() > 0) {
        defaultHealthyRetryPolicy.setMaxDelayTarget(Integer.parseInt(maxDelay));
      }
     
      if (minDelay.trim().length() > 0) {
        defaultHealthyRetryPolicy.setMinDelayTarget(Integer.parseInt(minDelay));
      }
     
      if (maxDelayRetries.trim().length() > 0) {
        defaultHealthyRetryPolicy.setNumMaxDelayRetries(Integer.parseInt(maxDelayRetries));
      }
     
      if (minDelayRetries.trim().length() > 0) {
        defaultHealthyRetryPolicy.setNumMinDelayRetries(Integer.parseInt(minDelayRetries));
      }
     
      if (retriesNoDelay.trim().length() > 0) {
        defaultHealthyRetryPolicy.setNumNoDelayRetries(Integer.parseInt(retriesNoDelay));
      }
     
      if (numRetries.trim().length() > 0) {
        defaultHealthyRetryPolicy.setNumRetries(Integer.parseInt(numRetries));
      }
     
      defaultHealthyRetryPolicy.setBackOffFunction(CnsBackoffFunction.valueOf(backoffFunc));
      deliveryPolicy.setDefaultHealthyRetryPolicy(defaultHealthyRetryPolicy);
      deliveryPolicy.setDisableSubscriptionOverrides(ignoreOverride != null ? true: false);
      CNSThrottlePolicy defaultThrottle = new CNSThrottlePolicy();
     
      if (maxReceiveRate.trim().length() > 0) {
        defaultThrottle.setMaxReceivesPerSecond(Integer.parseInt(maxReceiveRate));
      }
     
      deliveryPolicy.setDefaultThrottlePolicy(defaultThrottle );
     
      try {

        SetTopicAttributesRequest setTopicAttributesRequest = new SetTopicAttributesRequest(topicArn, "DeliveryPolicy", deliveryPolicy.toString());
        sns.setTopicAttributes(setTopicAttributesRequest);
       
        logger.debug("event=set_delivery_policy topic_arn=" + topicArn + " userId= " + userId);

      } catch (Exception ex) {
        logger.error("event=set_delivery_policy user_id= " + userId, ex);
        throw new ServletException(ex);
      }
     
      out.println("<body onload='javascript:window.opener.location.reload();window.close();'>");
     
    } else {

      int numRetries=0, retriesNoDelay = 0, minDelay = 0, minDelayRetries = 0, maxDelay = 0, maxDelayRetries = 0, maxReceiveRate = 0;
      String retryBackoff = "linear";
      boolean ignoreOverride = false;
     
      if (topicArn != null) {
     
        Map<String, String> attributes = null;
        CNSTopicDeliveryPolicy deliveryPolicy = null;
       
        try {
          GetTopicAttributesRequest getTopicAttributesRequest = new GetTopicAttributesRequest(topicArn);
          GetTopicAttributesResult getTopicAttributesResult = sns.getTopicAttributes(getTopicAttributesRequest);
          attributes = getTopicAttributesResult.getAttributes();
          deliveryPolicy = new CNSTopicDeliveryPolicy(new JSONObject(attributes.get("DeliveryPolicy")));
        } catch (Exception ex) {
          logger.error("event=failed_to_get_attributes arn=" + topicArn, ex);
          throw new ServletException(ex);
        }

        if (deliveryPolicy != null) {
         
         
          CNSRetryPolicy healPol = deliveryPolicy.getDefaultHealthyRetryPolicy();
         
          if (healPol != null) {
            numRetries= healPol.getNumRetries();
            retriesNoDelay = healPol.getNumNoDelayRetries();
            minDelay = healPol.getMinDelayTarget();
            minDelayRetries = healPol.getNumMinDelayRetries();
            maxDelay = healPol.getMaxDelayTarget();
            maxDelayRetries = healPol.getNumMaxDelayRetries();
            retryBackoff = healPol.getBackOffFunction().toString();
          }
         
          CNSThrottlePolicy throttlePol = deliveryPolicy.getDefaultThrottlePolicy();
         
          if (throttlePol != null) {
         
            if (throttlePol.getMaxReceivesPerSecond() != null) {
              maxReceiveRate = throttlePol.getMaxReceivesPerSecond().intValue();
            }
          }
         
          ignoreOverride = deliveryPolicy.isDisableSubscriptionOverrides();
        }
      }
     
      out.println("<body>");
      out.println("<h1>View/Edit Topic Delivery Policy</h1>");
View Full Code Here

Examples of com.comcast.cns.model.CNSTopicDeliveryPolicy

            "\"defaultThrottlePolicy\":null" +
            "}}";
    
     try {
       JSONObject json = new JSONObject(jsonStr);
       CNSTopicDeliveryPolicy subpolicy = new CNSTopicDeliveryPolicy(json);
       CNSRetryPolicy hrp = subpolicy.getDefaultHealthyRetryPolicy();
       assertTrue(hrp.getMinDelayTarget() == 21);
       assertTrue(hrp.getMaxDelayTarget() == 22);
       assertTrue(hrp.getNumRetries() == 77);
       assertTrue(hrp.getNumMaxDelayRetries() == 24);
       assertTrue(hrp.getNumMinDelayRetries() == 26);
       assertTrue(hrp.getNumNoDelayRetries() == 27);
       assertTrue(hrp.getBackOffFunction() == CnsBackoffFunction.linear);
      
       CNSRetryPolicy srp = subpolicy.getDefaultSicklyRetryPolicy();
       assertTrue(srp.getMinDelayTarget() == 10);
       assertTrue(srp.getMaxDelayTarget() == 11);
       assertTrue(srp.getNumRetries() == 42);
       assertTrue(srp.getNumMaxDelayRetries() == 14);
       assertTrue(srp.getNumMinDelayRetries() == 13);
       assertTrue(srp.getNumNoDelayRetries() == 15);
       assertTrue(srp.getBackOffFunction() == CnsBackoffFunction.geometric);
      
       CNSThrottlePolicy dtp = subpolicy.getDefaultThrottlePolicy();
       assertTrue(dtp != null);
       assertTrue(dtp.getMaxReceivesPerSecond() == 5);
       assertTrue(subpolicy.isDisableSubscriptionOverrides() == false);

      
       JSONObject json2 = new JSONObject(jsonStr2);
       CNSTopicDeliveryPolicy subpolicy2 = new CNSTopicDeliveryPolicy(json2);
       CNSRetryPolicy hrp2 = subpolicy2.getDefaultHealthyRetryPolicy();
       logger.debug("hrp2: " + hrp2.toString());
       assertTrue("minDelayTarget != 1", hrp2.getMinDelayTarget() == 1);
       assertTrue(hrp2.getMaxDelayTarget() == 2);
       assertTrue(hrp2.getNumRetries() == 17);
       assertTrue(hrp2.getNumMaxDelayRetries() == 4);
       assertTrue(hrp2.getNumMinDelayRetries() == 6);
       assertTrue(hrp2.getNumNoDelayRetries() == 7);
       assertTrue(hrp2.getBackOffFunction() == CnsBackoffFunction.linear);
       assertTrue(subpolicy2.getDefaultSicklyRetryPolicy() == null);
       CNSThrottlePolicy dtp2 = subpolicy2.getDefaultThrottlePolicy();
       assertTrue(dtp2 != null);
       assertTrue(dtp2.getMaxReceivesPerSecond() == null);
       assertTrue(subpolicy2.isDisableSubscriptionOverrides() == true);
      
       //Default constructor
       CNSTopicDeliveryPolicy subpolicy3 = new CNSTopicDeliveryPolicy();
       assertTrue(subpolicy3 != null);
       logger.debug("subpolicy3: " + subpolicy3.toString());
       CNSRetryPolicy hrp3 = subpolicy3.getDefaultHealthyRetryPolicy();
       assertTrue(hrp3.getMinDelayTarget() == 20);
       assertTrue(hrp3.getMaxDelayTarget() == 20);
       assertTrue(hrp3.getNumRetries() == 3);
       assertTrue(hrp3.getNumMaxDelayRetries() == 0);
       assertTrue(hrp3.getNumMinDelayRetries() == 0);
       assertTrue(hrp3.getNumNoDelayRetries() == 0);
       assertTrue(hrp3.getBackOffFunction() == CnsBackoffFunction.linear);
       assertTrue(subpolicy3.getDefaultSicklyRetryPolicy() == null);
       CNSThrottlePolicy dtp3 = subpolicy3.getDefaultThrottlePolicy();
       assertTrue(dtp3 != null);
       assertTrue(dtp3.getMaxReceivesPerSecond() == null);
       assertTrue(subpolicy3.isDisableSubscriptionOverrides() == false);
      
       //Default constructor
       JSONObject json3 = new JSONObject(jsonStr3);
       CNSTopicDeliveryPolicy subpolicy4 = new CNSTopicDeliveryPolicy(json3);
       assertTrue(subpolicy4 != null);
       logger.debug("subpolicy4: " + subpolicy4.toString());
       CNSRetryPolicy hrp4 = subpolicy4.getDefaultHealthyRetryPolicy();
       assertTrue(hrp4.getMinDelayTarget() == 20);
       assertTrue(hrp4.getMaxDelayTarget() == 20);
       assertTrue(hrp4.getNumRetries() == 3);
       assertTrue(hrp4.getNumMaxDelayRetries() == 0);
       assertTrue(hrp4.getNumMinDelayRetries() == 0);
       assertTrue(hrp4.getNumNoDelayRetries() == 0);
       assertTrue(hrp4.getBackOffFunction() == CnsBackoffFunction.linear);
       assertTrue(subpolicy4.getDefaultSicklyRetryPolicy() == null);
       CNSThrottlePolicy dtp4 = subpolicy4.getDefaultThrottlePolicy();
       assertTrue(dtp4 != null);
       assertTrue(dtp4.getMaxReceivesPerSecond() == null);
       assertTrue(subpolicy4.isDisableSubscriptionOverrides() == true);
      
       //Default constructor
       boolean exceptionOccured = false;
       try {
         JSONObject json4 = new JSONObject(jsonStr4);
         new CNSTopicDeliveryPolicy(json4);
       } catch (Exception e) {
        if(e instanceof CMBException) {
          assertTrue(true);
          exceptionOccured = true;
          logger.debug("Exception 1:");
          logger.debug(e.getMessage());
        } else {
          assertFalse(true);
        }
       }
       assertTrue(exceptionOccured);
       exceptionOccured = false;
      
       //Default constructor
     
       try {
         JSONObject json5 = new JSONObject(jsonStr5);
         new CNSTopicDeliveryPolicy(json5);
       } catch (Exception e) {
        if(e instanceof CMBException) {
          assertTrue(true);
          exceptionOccured = true;
          logger.debug("Exception 2:");
          logger.debug(e.getMessage());
        } else {
          assertFalse(true);
        }
       }
       assertTrue(exceptionOccured);
       exceptionOccured = false;
      
      
       try {
         JSONObject json6 = new JSONObject(jsonStr6);
         new CNSTopicDeliveryPolicy(json6);
       } catch (Exception e) {
        if(e instanceof CMBException) {
          assertTrue(true);
          exceptionOccured = true;
          logger.debug("Exception 3:");
View Full Code Here

Examples of com.comcast.cns.model.CNSTopicDeliveryPolicy

            "}" +
            "}}";
     try {
       boolean exceptionOccured = false;
      
       CNSTopicDeliveryPolicy topicPolicy = new CNSTopicDeliveryPolicy();
       JSONObject json = new JSONObject(jsonStr);
       topicPolicy.update(json);
      
       assertTrue(topicPolicy != null);
       logger.debug("topicPolicy: " + topicPolicy.toString());
       CNSRetryPolicy hrp = topicPolicy.getDefaultHealthyRetryPolicy();
       assertTrue(hrp.getMinDelayTarget() == 21);
       assertTrue(hrp.getMaxDelayTarget() == 22);
       assertTrue(hrp.getNumRetries() == 77);
       assertTrue(hrp.getNumMaxDelayRetries() == 24);
       assertTrue(hrp.getNumMinDelayRetries() == 26);
       assertTrue(hrp.getNumNoDelayRetries() == 27);
       assertTrue(hrp.getBackOffFunction() == CnsBackoffFunction.linear);
       CNSRetryPolicy srp = topicPolicy.getDefaultSicklyRetryPolicy();
       assertTrue(srp.getMinDelayTarget() == 10);
       assertTrue(srp.getMaxDelayTarget() == 11);
       assertTrue(srp.getNumRetries() == 42);
       assertTrue(srp.getNumMaxDelayRetries() == 14);
       assertTrue(srp.getNumMinDelayRetries() == 13);
       assertTrue(srp.getNumNoDelayRetries() == 15);
       assertTrue(srp.getBackOffFunction() == CnsBackoffFunction.geometric);
       CNSThrottlePolicy dtp3 = topicPolicy.getDefaultThrottlePolicy();
       assertTrue(dtp3 != null);
       assertTrue(dtp3.getMaxReceivesPerSecond() == 5);
       assertTrue(topicPolicy.isDisableSubscriptionOverrides() == false);
      
       try {
         JSONObject json2 = new JSONObject(fakejsonStr);
         new CNSTopicDeliveryPolicy(json2);
       } catch (Exception e) {
        if(e instanceof CMBException) {
          assertTrue(true);
          exceptionOccured = true;
          logger.debug("Exception 3:");
          logger.debug(e.getMessage());
        } else {
          assertFalse(true);
        }
       }
       assertTrue(exceptionOccured);
       exceptionOccured = false;
      
       try {
         JSONObject json2 = new JSONObject(fakejsonStr2);
         new CNSTopicDeliveryPolicy(json2);
       } catch (Exception e) {
        if(e instanceof CMBException) {
          assertTrue(true);
          exceptionOccured = true;
          logger.debug("Exception 3:");
View Full Code Here

Examples of com.comcast.cns.model.CNSTopicDeliveryPolicy

    
   }
  
   @Test
   public void testGetterSetter() {
     CNSTopicDeliveryPolicy topicPolicy = new CNSTopicDeliveryPolicy();
     CNSRetryPolicy hrp = new CNSRetryPolicy();
     hrp.setNumRetries(19);
     CNSRetryPolicy srp = new CNSRetryPolicy();
     CNSThrottlePolicy dtp = new CNSThrottlePolicy();
    
     dtp.setMaxReceivesPerSecond(19);
    
     srp.setBackOffFunction(CnsBackoffFunction.geometric);
     topicPolicy.setDefaultHealthyRetryPolicy(hrp);
     topicPolicy.setDefaultSicklyRetryPolicy(srp);
     topicPolicy.setDefaultThrottlePolicy(dtp);
     topicPolicy.setDisableSubscriptionOverrides(true);
    
     CNSRetryPolicy nhrp = topicPolicy.getDefaultHealthyRetryPolicy();
     CNSRetryPolicy nsrp = topicPolicy.getDefaultSicklyRetryPolicy();
     CNSThrottlePolicy ndtp = topicPolicy.getDefaultThrottlePolicy();
     assertTrue("subscription Overrides not set", topicPolicy.isDisableSubscriptionOverrides());
     assertTrue("default healthy retry policy not set correctly", nhrp.getMinDelayTarget() == 20);
     assertTrue("default healthy retry policy not set correctly",nhrp.getMaxDelayTarget() == 20);
     assertTrue("default healthy retry policy not set correctly",nhrp.getNumRetries() == 19);
     assertTrue("default healthy retry policy not set correctly",nhrp.getNumMaxDelayRetries() == 0);
     assertTrue("default healthy retry policy not set correctly",nhrp.getNumMinDelayRetries() == 0);
     assertTrue("default healthy retry policy not set correctly",nhrp.getNumNoDelayRetries() == 0);
     assertTrue("default healthy retry policy not set correctly",nhrp.getBackOffFunction() == CnsBackoffFunction.linear);
    
     assertTrue("default sickly retry policy not set correctly", nsrp.getMinDelayTarget() == 20);
     assertTrue("default sickly retry policy not set correctly",nsrp.getMaxDelayTarget() == 20);
     assertTrue("default sickly retry policy not set correctly",nsrp.getNumRetries() == 3);
     assertTrue("default sickly retry policy not set correctly",nsrp.getNumMaxDelayRetries() == 0);
     assertTrue("default sickly retry policy not set correctly",nsrp.getNumMinDelayRetries() == 0);
     assertTrue("default sickly retry policy not set correctly",nsrp.getNumNoDelayRetries() == 0);
     assertTrue("default sickly retry policy not set correctly",nsrp.getBackOffFunction() == CnsBackoffFunction.geometric);
    
     assertTrue("defaultThrottlePolicy not set correctly", ndtp.getMaxReceivesPerSecond() == 19);
     try {
       JSONObject json = topicPolicy.toJSON();
       logger.debug("Json is:" + json.toString());
       assertTrue("toJSON fails to return proper JSON", json.has("http"));
       JSONObject httpJson = json.getJSONObject("http");
       assertTrue("toJSON fails to return proper JSON", httpJson.has("defaultHealthyRetryPolicy"));
       assertTrue("toJSON fails to return proper JSON", httpJson.has("defaultSicklyRetryPolicy"));
View Full Code Here

Examples of com.comcast.cns.model.CNSTopicDeliveryPolicy

      CNSTopicAttributes topicAttributes = new CNSTopicAttributes();

      if (attributeName.equals("DeliveryPolicy")) {     
       
        JSONObject json = new JSONObject(attributeValue);      
        CNSTopicDeliveryPolicy deliveryPolicy = new CNSTopicDeliveryPolicy(json);
        topicAttributes.setDeliveryPolicy(deliveryPolicy);
        logger.debug("event=cns_set_topic_delivery_policy topic_arn=" + topicArn + " value=" + topicAttributes.getEffectiveDeliveryPolicy());
     
      } else if (attributeName.equals("Policy")) {     
       
View Full Code Here

Examples of com.comcast.cns.model.CNSTopicDeliveryPolicy

   
    CNSTopicAttributes topicAttributes = new CNSTopicAttributes();
    topicAttributes.setTopicArn(topic.getArn());
    topicAttributes.setUserId(user.getUserId());

    CNSTopicDeliveryPolicy deliveryPolicy = new CNSTopicDeliveryPolicy();
    CNSRetryPolicy defaultHealthyRetryPolicy = new CNSRetryPolicy();
    defaultHealthyRetryPolicy.setNumRetries(6);
    defaultHealthyRetryPolicy.setMaxDelayTarget(20);
    defaultHealthyRetryPolicy.setMinDelayTarget(20);
    defaultHealthyRetryPolicy.setNumMaxDelayRetries(3);
    defaultHealthyRetryPolicy.setNumMinDelayRetries(1);
    defaultHealthyRetryPolicy.setNumNoDelayRetries(2);
    defaultHealthyRetryPolicy.setBackOffFunction(CnsBackoffFunction.linear);
    deliveryPolicy.setDefaultHealthyRetryPolicy(defaultHealthyRetryPolicy );
    topicAttributes.setDeliveryPolicy(deliveryPolicy);

    attributeHandler.setTopicAttributes(topicAttributes , topic.getArn());

    CNSTopicAttributes topicAttributes2 = attributeHandler.getTopicAttributes(topic.getArn());

    assertEquals("Topic attributes do not match", topicAttributes2.getDeliveryPolicy().toString(), deliveryPolicy.toString());
    assertEquals("Topic attributes do not match", topicAttributes2.getEffectiveDeliveryPolicy().toString(), deliveryPolicy.toString());
    assertEquals("Topic attributes do not match", topicAttributes2.getSubscriptionsConfirmed(), 0);
    assertEquals("Topic attributes do not match", topicAttributes2.getSubscriptionsDeleted(), 0);
    assertEquals("Topic attributes do not match", topicAttributes2.getTopicArn(), topic.getArn());
    assertEquals("Topic attributes do not match", topicAttributes2.getUserId(), user.getUserId());
  }
View Full Code Here

Examples of com.comcast.cns.model.CNSTopicDeliveryPolicy

     
      if (slice.getColumnByName("policy") != null) {
        topicAttributes.setPolicy(slice.getColumnByName("policy").getValue());
      }
     
      CNSTopicDeliveryPolicy deliveryPolicy = null;
     
      if (slice.getColumnByName("deliveryPolicy") != null) {
        deliveryPolicy = new CNSTopicDeliveryPolicy(new JSONObject(slice.getColumnByName("deliveryPolicy").getValue()));
      } else {
        deliveryPolicy = new CNSTopicDeliveryPolicy();
      }
     
      topicAttributes.setEffectiveDeliveryPolicy(deliveryPolicy);   
      topicAttributes.setDeliveryPolicy(deliveryPolicy);
View Full Code Here

Examples of com.comcast.cns.model.CNSTopicDeliveryPolicy

     
      CNSTopicAttributes topicAttributes = getTopicAttributes(subscription.getTopicArn());
     
      if (topicAttributes != null) {
       
        CNSTopicDeliveryPolicy topicEffectiveDeliveryPolicy = topicAttributes.getEffectiveDeliveryPolicy();
       
        if (topicEffectiveDeliveryPolicy != null) {
         
          if (topicEffectiveDeliveryPolicy.isDisableSubscriptionOverrides() || subscriptionAttributes.getDeliveryPolicy() == null) {
            CNSSubscriptionDeliveryPolicy effectiveDeliveryPolicy = new CNSSubscriptionDeliveryPolicy();
            effectiveDeliveryPolicy.setHealthyRetryPolicy(topicEffectiveDeliveryPolicy.getDefaultHealthyRetryPolicy());
            effectiveDeliveryPolicy.setSicklyRetryPolicy(topicEffectiveDeliveryPolicy.getDefaultSicklyRetryPolicy());
            effectiveDeliveryPolicy.setThrottlePolicy(topicEffectiveDeliveryPolicy.getDefaultThrottlePolicy());
            subscriptionAttributes.setEffectiveDeliveryPolicy(effectiveDeliveryPolicy);
          } else {
            subscriptionAttributes.setEffectiveDeliveryPolicy(subscriptionAttributes.getDeliveryPolicy());
          }
        }
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.