Examples of CNSTopicAttributes


Examples of com.comcast.cns.model.CNSTopicAttributes

        if (actionList.size() == 0) {
            throw new CMBException(CMBErrorCodes.NotFound, "ActionName is required");
        }
       
        CMBPolicy policy = null;
    CNSTopicAttributes attributes = CNSCache.getTopicAttributes(topicArn);

        // validate policy string
       
        if (attributes.getPolicy() != null) {
          policy = new CMBPolicy(attributes.getPolicy());
        } else {
          policy = new CMBPolicy();
        }

        if (policy.addStatement(CMBPolicy.SERVICE.CNS, label, "Allow", userList, actionList, topicArn, null)) {
          attributes.setPolicy(policy.toString());
          PersistenceFactory.getCNSAttributePersistence().setTopicAttributes(attributes, topicArn);
        } else {
          throw new CMBException(CMBErrorCodes.InvalidParameterValue, "Value " + label + " for parameter Label is invalid. Reason: Already exists.");
        }
View Full Code Here

Examples of com.comcast.cns.model.CNSTopicAttributes

      if (topicArn == null) {
      throw new CMBException(CNSErrorCodes.CNS_InvalidParameter, "Missing parameters TopicArn");
      }
     
      //CNSTopicAttributes attr = PersistenceFactory.getCNSAttributePersistence().getTopicAttributes(topicArn);
      CNSTopicAttributes attr = CNSCache.getTopicAttributes(topicArn);
     
      if (attr == null) {
        throw new CMBException(CNSErrorCodes.InternalError, "Unknown topic with arn " + topicArn);
      }
     
View Full Code Here

Examples of com.comcast.cns.model.CNSTopicAttributes

            this.topicArn = key;
        }
       
      @Override
        public CNSTopicAttributes call() throws Exception {
        CNSTopicAttributes attributes = attributeHandler.getTopicAttributes(this.topicArn);
            return attributes;
        }
View Full Code Here

Examples of com.comcast.cns.model.CNSTopicAttributes

            throw new CMBException(CQSErrorCodes.InvalidBatchEntryId, "Label " + label + " is invalid. Only alphanumeric, hyphen, and underscore are allowed. It can be at most " + CMBProperties.getInstance().getCQSMaxMessageSuppliedIdLength() + " letters long.");
        }
       
        CMBPolicy policy = null;

    CNSTopicAttributes attributes = CNSCache.getTopicAttributes(topicArn);

        // validate policy string
       
        if (attributes.getPolicy() != null) {

          policy = new CMBPolicy(attributes.getPolicy());
           
          if (policy.removeStatement(label)) {
              attributes.setPolicy(policy.toString());
            PersistenceFactory.getCNSAttributePersistence().setTopicAttributes(attributes, topicArn);
            }
        }
       
        String out = CNSAttributePopulator.getRemovePermissionResponse();
View Full Code Here

Examples of com.comcast.cns.model.CNSTopicAttributes

      if ((userId == null) || (topicArn == null) || (attributeName == null) || (attributeValue == null)) {
        logger.error("event=cns_set_topic_attributes error_code=InvalidParameters attribute_name=" + attributeName + " attribute_value=" + attributeValue + " topic_arn=" + topicArn + " user_id=" + userId);
      throw new CMBException(CNSErrorCodes.CNS_InvalidParameter,"missing parameters");
      }   
     
      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")) {     
       
      // validate policy before updating
     
      try {
        new CMBPolicy(attributeValue);
      } catch (Exception ex) {
                logger.warn("event=invalid_policy topic_arn=" + topicArn + " policy=" + attributeValue, ex);
          throw ex;
        }

      topicAttributes.setPolicy(attributeValue);
        logger.debug("event=cns_set_topic_policy topic_arn=" + topicArn + "  value=" + topicAttributes.getPolicy());
     
      } else if (attributeName.equals("DisplayName")) {   
       
        if (validateDisplayName(attributeValue)) {
          topicAttributes.setDisplayName(attributeValue);
          logger.debug("event=cns_set_topic_display_name topic_arn=" + topicArn + "  value=" + attributeValue);
        } else {
          throw new CMBException(CNSErrorCodes.CNS_InvalidParameter,"Bad Display Name");
        }
       
View Full Code Here

Examples of com.comcast.cns.model.CNSTopicAttributes

      cnsMessage.setTopicArn(topicArn);
      cnsMessage.setMessageType(CNSMessageType.Notification);
     
      cnsMessage.checkIsValid();
     
      CNSTopicAttributes topicAttributes = CNSCache.getTopicAttributes(topicArn);
      List<String> receiptHandles = new ArrayList<String>();
     
      boolean success = true;
     
      if (topicAttributes != null && topicAttributes.getSubscriptionsConfirmed() == 0) {
       
        // optimization: don't do anything if there are no confirmed subscribers
       
        logger.warn("event=no_confirmed_subscribers action=publish topic_arn=" + topicArn);
     
      } else if (CMBProperties.getInstance().isCNSBypassPublishJobQueueForSmallTopics() && topicAttributes != null && topicAttributes.getSubscriptionsConfirmed() <= CMBProperties.getInstance().getCNSMaxSubscriptionsPerEndpointPublishJob()) {
       
        // optimization: if there's only one chunk due to few subscribers, write directly into endpoint publish queue bypassing the publish job queue
       
        logger.debug("event=using_job_queue_overpass");
       
View Full Code Here

Examples of com.comcast.cns.model.CNSTopicAttributes

     
      if (isAuthenticationRequired(action)) {

        String topicArn = request.getParameter("TopicArn");
           
        CNSTopicAttributes attributes = CNSCache.getTopicAttributes(topicArn);         
            if (attributes != null) {
                if (!actionMap.get(action).isActionAllowed(user, request, "CNS", new CMBPolicy(attributes.getPolicy()))) {
                    throw new CMBException(CMBErrorCodes.AccessDenied, "You don't have permission for " + actionMap.get(action).getName());
                }
            }
      }
View Full Code Here

Examples of com.comcast.cns.model.CNSTopicAttributes

    }

  @Test
  public void testSetGetTopicAttributes() throws Exception {
   
    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.CNSTopicAttributes

     
      cassandraHandler.incrementCounter(AbstractDurablePersistence.CNS_KEYSPACE, columnFamilyTopicStats, arn, "subscriptionConfirmed", 0, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER);
      cassandraHandler.incrementCounter(AbstractDurablePersistence.CNS_KEYSPACE, columnFamilyTopicStats, arn, "subscriptionPending", 0, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER);
      cassandraHandler.incrementCounter(AbstractDurablePersistence.CNS_KEYSPACE, columnFamilyTopicStats, arn, "subscriptionDeleted", 0, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER);
     
      CNSTopicAttributes attributes = new CNSTopicAttributes(arn, userId);
      PersistenceFactory.getCNSAttributePersistence().setTopicAttributes(attributes, arn);

      return topic;
    }
  }
View Full Code Here

Examples of com.comcast.cns.model.CNSTopicAttributes

  }

  @Override
  public CNSTopicAttributes getTopicAttributes(String topicArn) throws Exception {
   
    CNSTopicAttributes topicAttributes = new CNSTopicAttributes();
    topicAttributes.setTopicArn(topicArn);
   
    CmbColumnSlice<String, String> slice = cassandraHandler.readColumnSlice(AbstractDurablePersistence.CNS_KEYSPACE, columnFamilyTopicAttributes, topicArn, null, null, 10, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER);
   
    if (slice != null) {
     
      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);

      if (slice.getColumnByName("userId") != null) {
        topicAttributes.setUserId(slice.getColumnByName("userId").getValue());
      }
     
      topicAttributes.setDisplayName(PersistenceFactory.getTopicPersistence().getTopic(topicArn).getDisplayName());
    }
   
    long subscriptionConfirmedCount = cassandraHandler.getCounter(AbstractDurablePersistence.CNS_KEYSPACE, columnFamilyTopicStats, topicArn, "subscriptionConfirmed", CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER);
    topicAttributes.setSubscriptionsConfirmed(subscriptionConfirmedCount);
   
    long subscriptionPendingCount = cassandraHandler.getCounter(AbstractDurablePersistence.CNS_KEYSPACE, columnFamilyTopicStats, topicArn, "subscriptionPending", CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER);
    topicAttributes.setSubscriptionsPending(subscriptionPendingCount);
   
    long subscriptionDeletedCount = cassandraHandler.getCounter(AbstractDurablePersistence.CNS_KEYSPACE, columnFamilyTopicStats, topicArn, "subscriptionDeleted", CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER);
    topicAttributes.setSubscriptionsDeleted(subscriptionDeletedCount);

    return topicAttributes;
  }
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.