├── .travis.yml ├── Dockerfile ├── Dockerfile-cassandra ├── Dockerfile-redis ├── FAQ.txt ├── LICENSE.txt ├── NOTICE.txt ├── README.txt ├── RELEASE.txt ├── WebContent ├── META-INF │ └── MANIFEST.MF └── WEB-INF │ ├── global.css │ └── web.xml ├── assembly.xml ├── bin ├── cmb.sh └── travisci_setup.sh ├── config ├── WEB-INF-CNS │ ├── context.xml │ └── web.xml ├── WEB-INF-CQS │ ├── context.xml │ └── web.xml ├── cmb.properties ├── log4j.properties └── test.log4j.properties ├── docker ├── cmb │ ├── bin │ │ └── start.sh │ └── cmb.properties.template ├── docker-compose.yml └── redis │ └── redis.conf ├── docs ├── xcal-CNSArchitecture-210912-1546-6.pdf ├── xcal-CNSProductRequirements-210912-1548-10.pdf ├── xcal-CQSArchitecture-210912-1545-4.pdf └── xcal-CQSProductRequirements-210912-1548-8.pdf ├── examples ├── java │ └── Example.java └── ruby │ ├── .gitignore │ ├── Gemfile │ └── example.rb ├── packaging ├── common │ └── log4j.properties ├── linux │ ├── centos │ │ ├── cmb.init │ │ └── cmb.spec │ └── debian │ │ └── cmb └── vagrant │ ├── cmbbase │ ├── Vagrantfile │ └── bootstrap.sh │ └── cmbcluster │ └── Vagrantfile ├── pom.xml ├── schema ├── cassandra_1.0.schema ├── cassandra_1.1.schema ├── cassandra_1.2.cql.schema └── cassandra_1.2.schema ├── settings.xml ├── src └── com │ └── comcast │ ├── cmb │ └── common │ │ ├── controller │ │ ├── Action.java │ │ ├── AdminServlet.java │ │ ├── AdminServletBase.java │ │ ├── CMB.java │ │ ├── CMBControllerServlet.java │ │ ├── CMBStatsServlet.java │ │ ├── CMBVisualizerServlet.java │ │ ├── EndpointServlet.java │ │ ├── HealthCheckShallow.java │ │ ├── UserLoginPageServlet.java │ │ └── UserPageServlet.java │ │ ├── model │ │ ├── CMBCondition.java │ │ ├── CMBPolicy.java │ │ ├── CMBStatement.java │ │ ├── IAuthModule.java │ │ ├── IPermission.java │ │ ├── ReceiptModule.java │ │ ├── User.java │ │ └── UserAuthModule.java │ │ ├── persistence │ │ ├── AbstractDurablePersistence.java │ │ ├── CassandraAstyanaxPersistence.java │ │ ├── CassandraHectorPersistence.java │ │ ├── DurablePersistenceFactory.java │ │ ├── IPermissionPersistence.java │ │ ├── IUserPersistence.java │ │ ├── PersistenceFactory.java │ │ └── UserCassandraPersistence.java │ │ └── util │ │ ├── AuthUtil.java │ │ ├── AuthenticationException.java │ │ ├── CMBErrorCodes.java │ │ ├── CMBException.java │ │ ├── CMBPatternLayout.java │ │ ├── CMBProperties.java │ │ ├── ExpiringCache.java │ │ ├── PersistenceException.java │ │ ├── RollingWindowCapture.java │ │ ├── Util.java │ │ ├── ValueAccumulator.java │ │ └── XmlUtil.java │ ├── cns │ ├── controller │ │ ├── CNSAction.java │ │ ├── CNSAddPermissionAction.java │ │ ├── CNSCache.java │ │ ├── CNSConfirmSubscriptionAction.java │ │ ├── CNSControllerServlet.java │ │ ├── CNSCreateTopicAction.java │ │ ├── CNSDeleteTopicAction.java │ │ ├── CNSEditSubscriptionDeliveryPolicyPage.java │ │ ├── CNSEditTopicDeliveryPolicyPage.java │ │ ├── CNSEditTopicDisplayNamePage.java │ │ ├── CNSGetAPIStatsAction.java │ │ ├── CNSGetSubscriptionAttributesAction.java │ │ ├── CNSGetTopicAttributesAction.java │ │ ├── CNSGetWorkerStatsAction.java │ │ ├── CNSListSubscriptionsAction.java │ │ ├── CNSListSubscriptionsByTopicAction.java │ │ ├── CNSListTopicsAction.java │ │ ├── CNSManageServiceAction.java │ │ ├── CNSMonitor.java │ │ ├── CNSMonitorMBean.java │ │ ├── CNSPublishAction.java │ │ ├── CNSPublishToTopicPageServlet.java │ │ ├── CNSRawMessageDeliveryPolicyPage.java │ │ ├── CNSRemovePermissionAction.java │ │ ├── CNSSetSubscriptionAttributesAction.java │ │ ├── CNSSetTopicAttributesAction.java │ │ ├── CNSSubscribeAction.java │ │ ├── CNSSubscriptionPageServlet.java │ │ ├── CNSTopicAddPermissionPage.java │ │ ├── CNSTopicPermissionPage.java │ │ ├── CNSUnsubscribeAction.java │ │ ├── CNSUserPageServlet.java │ │ └── CNSWorkerStatePageServlet.java │ ├── io │ │ ├── AbstractEndpointPublisher.java │ │ ├── CNSAttributePopulator.java │ │ ├── CNSPopulator.java │ │ ├── CNSSubscriptionPopulator.java │ │ ├── CNSTopicPopulator.java │ │ ├── CNSWorkerStatsPopulator.java │ │ ├── CQSEndpointPublisher.java │ │ ├── CommunicationUtils.java │ │ ├── EmailEndpointPublisher.java │ │ ├── EmailJsonEndpointPublisher.java │ │ ├── EndpointAsyncPublisherWrapper.java │ │ ├── EndpointPublisherFactory.java │ │ ├── HTTPEndpointAsyncPublisher.java │ │ ├── HTTPEndpointSyncPublisher.java │ │ ├── IEndpointPublisher.java │ │ ├── IPublisherCallback.java │ │ ├── RedisPubSubEndpointPublisher.java │ │ └── SQSEndpointPublisher.java │ ├── model │ │ ├── CNSEndpointPublishJob.java │ │ ├── CNSMessage.java │ │ ├── CNSModelConstructionException.java │ │ ├── CNSRetryPolicy.java │ │ ├── CNSSubscription.java │ │ ├── CNSSubscriptionAttributes.java │ │ ├── CNSSubscriptionDeliveryPolicy.java │ │ ├── CNSThrottlePolicy.java │ │ ├── CNSTopic.java │ │ ├── CNSTopicAttributes.java │ │ ├── CNSTopicDeliveryPolicy.java │ │ └── CNSWorkerStats.java │ ├── persistence │ │ ├── CNSAttributesCassandraPersistence.java │ │ ├── CNSCachedEndpointPublishJob.java │ │ ├── CNSSubscriptionCassandraPersistence.java │ │ ├── CNSTopicCassandraPersistence.java │ │ ├── ICNSAttributesPersistence.java │ │ ├── ICNSSubscriptionPersistence.java │ │ ├── ICNSTopicPersistence.java │ │ ├── SubscriberNotFoundException.java │ │ └── TopicNotFoundException.java │ ├── tools │ │ ├── CNSAsyncPublishJob.java │ │ ├── CNSEndpointPublisherJobConsumer.java │ │ ├── CNSEndpointPublisherJobProducer.java │ │ ├── CNSPublishJob.java │ │ ├── CNSPublisher.java │ │ ├── CNSPublisherJobThread.java │ │ ├── CNSPublisherPartitionRunnable.java │ │ ├── CNSWorkerMonitor.java │ │ ├── CNSWorkerMonitorMBean.java │ │ └── CQSHandler.java │ └── util │ │ ├── CNSErrorCodes.java │ │ ├── CNSWorkerStatWrapper.java │ │ ├── MailWrapper.java │ │ └── Util.java │ └── cqs │ ├── api │ └── CQSAPI.java │ ├── controller │ ├── CQSAPIStatePageServlet.java │ ├── CQSAction.java │ ├── CQSAddPermissionAction.java │ ├── CQSAddQueuePermissionPage.java │ ├── CQSCache.java │ ├── CQSChangeMessageVisibilityAction.java │ ├── CQSChangeMessageVisibilityBatchAction.java │ ├── CQSControllerServlet.java │ ├── CQSCreateQueueAction.java │ ├── CQSDeleteMessageAction.java │ ├── CQSDeleteMessageBatchAction.java │ ├── CQSDeleteQueueAction.java │ ├── CQSEditQueueAttributePage.java │ ├── CQSGetAPIStatsAction.java │ ├── CQSGetQueueAttributesAction.java │ ├── CQSGetQueueUrlAction.java │ ├── CQSHttpServletRequest.java │ ├── CQSListQueuesAction.java │ ├── CQSLongPollReceiver.java │ ├── CQSLongPollSender.java │ ├── CQSManageServiceAction.java │ ├── CQSMonitor.java │ ├── CQSMonitorMBean.java │ ├── CQSPeekMessageAction.java │ ├── CQSPurgeQueueAction.java │ ├── CQSQueueMessagesPageServlet.java │ ├── CQSQueuePermissionsPage.java │ ├── CQSReceiveMessageAction.java │ ├── CQSReceiveMessageBodyAction.java │ ├── CQSRemovePermissionAction.java │ ├── CQSSendMessageAction.java │ ├── CQSSendMessageBatchAction.java │ ├── CQSSetQueueAttributesAction.java │ └── CQSUserPageServlet.java │ ├── io │ ├── CQSAPIStatsPopulator.java │ ├── CQSMessagePopulator.java │ ├── CQSPopulator.java │ └── CQSQueuePopulator.java │ ├── model │ ├── CQSAPIStats.java │ ├── CQSBatchResultErrorEntry.java │ ├── CQSMessage.java │ ├── CQSMessageAttribute.java │ └── CQSQueue.java │ ├── persistence │ ├── CQSMessagePartitionedCassandraPersistence.java │ ├── CQSQueueCassandraPersistence.java │ ├── ICQSMessagePersistence.java │ ├── ICQSQueuePersistence.java │ ├── RedisCachedCassandraPersistence.java │ └── RedisSortedSetPersistence.java │ └── util │ ├── CQSAPIStatWrapper.java │ ├── CQSConstants.java │ ├── CQSErrorCodes.java │ ├── RandomNumberCollection.java │ └── Util.java └── tests └── com └── comcast ├── cmb └── test │ ├── common │ ├── model │ │ └── unit │ │ │ ├── CMBPolicyTest.java │ │ │ ├── ReceiptModuleTest.java │ │ │ └── UserAuthModuleTest.java │ └── util │ │ └── unit │ │ ├── AuthUtilTest.java │ │ ├── ExpiringCacheTest.java │ │ ├── RollingWindowCaptureTest.java │ │ ├── TimeAccumulatorTest.java │ │ └── ValidUnicodeTest.java │ ├── tools │ ├── CMBAWSBaseTest.java │ ├── CMBTestingConstants.java │ ├── CNSTestingUtils.java │ ├── CQSTestUtils.java │ ├── CreateTopicResponseParser.java │ ├── ErrorParser.java │ ├── ListSubscriptionParser.java │ ├── ListTopicsResponseParser.java │ ├── QueueDepthSimulator.java │ ├── SimpleHttpServletRequest.java │ ├── SimpleHttpServletResponse.java │ ├── SimpleServletOutputStream.java │ ├── SubscribeParser.java │ ├── SubscriptionAttributeParser.java │ └── TopicAttributeParser.java │ └── unit │ ├── CassandraTest.java │ └── UserPersistenceTest.java ├── cns └── test │ ├── stress │ ├── CNSStressTest.java │ ├── README.txt │ └── run.sh │ └── unit │ ├── CNSAttributesCassandraPersistenceTest.java │ ├── CNSDeleteListTopicTest.java │ ├── CNSJustCreateSubscriptionsTest.java │ ├── CNSMessageTest.java │ ├── CNSPublishJobTest.java │ ├── CNSPublishTest.java │ ├── CNSPublishToCQSWithAttributes.java │ ├── CNSRawMessageDeliveryTest.java │ ├── CNSRedisPubSubTest.java │ ├── CNSRetryPolicyTest.java │ ├── CNSScaleSubscriptionsTest.java │ ├── CNSScaleTopicsTest.java │ ├── CNSSubscriptionAttributeCMBTest.java │ ├── CNSSubscriptionTest.java │ ├── CNSThrottlePolicyTest.java │ ├── CNSTopicAttributeTest.java │ ├── SubscribeListUnsubscribeCassandraTest.java │ ├── SubscriptionDeliveryPolicyTest.java │ ├── TopicDeliveryPolicyTest.java │ └── UtilsTest.java └── cqs └── test ├── stress ├── CQSStressTestProperties.java ├── CqsStressTester.java ├── cqs.stresstest.properties ├── run.sh └── run2.sh └── unit ├── CQSDCFailoverTest.java ├── CQSDelaySecondsTest.java ├── CQSEnduranceTest.java ├── CQSIntegrationTest.java ├── CQSLongPollTest.java ├── CQSMessagePartitionedCassandraPersistenceTest.java ├── CQSMessageVisibilityTest.java ├── CQSMonitorTest.java ├── CQSQueuePersistenceTest.java ├── CQSRedisCachedCassandraPersistenceTest.java ├── CQSRedisSortedSetPersistenceTest.java ├── CQSScaleQueuesTest.java └── CQSSendDeleteReceiveMessageTest.java /.travis.yml: -------------------------------------------------------------------------------- 1 | # 2 | language: java 3 | services: 4 | - redis-server 5 | - cassandra 6 | #before_script: cassandra-cli -f schema/cassandra_1.2.schema && sleep 5 7 | install: bin/travisci_setup.sh 8 | script: MAVEN_OPTS="-Djdk.xml.entityExpansionLimit=0 -DentityExpansionLimit=0" mvn -ff test 9 | after_failure: echo "##########"; cat /tmp/cmb.log 10 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM maven:3.3.3-jdk-8 2 | 3 | RUN mkdir -p /app/src/cmb 4 | ADD . /app/src/cmb 5 | 6 | WORKDIR /app/src/cmb 7 | ENV ROOTDIR=/app/src/cmb 8 | RUN mvn -Dmaven.test.skip=true assembly:assembly 9 | RUN mv target/lib $ROOTDIR/lib 10 | RUN mv target/cmb.jar $ROOTDIR/lib 11 | 12 | EXPOSE 6059 6061 13 | 14 | CMD $ROOTDIR/docker/cmb/bin/start.sh 15 | -------------------------------------------------------------------------------- /Dockerfile-cassandra: -------------------------------------------------------------------------------- 1 | FROM cassandra:2.1 2 | 3 | # Add initial data for cmb 4 | ADD ./schema/cassandra_1.2.cql.schema /tmp/cassandra_1.2.cql.schema 5 | -------------------------------------------------------------------------------- /Dockerfile-redis: -------------------------------------------------------------------------------- 1 | FROM redis:2.6 2 | 3 | COPY ./docker/redis/redis.conf /usr/local/etc/redis/redis.conf 4 | CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ] 5 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Comcast Message Bus - CMB 2 | Copyright 2010-2012 Comcast Corporation or its affiliates. All Rights Reserved. 3 | 4 | This product includes software developed by Comcast Corporation (http://www.comcast.com/). 5 | 6 | -------------------------------------------------------------------------------------------- 7 | - THIRD PARTY COMPONENTS 8 | -------------------------------------------------------------------------------------------- 9 | 10 | This software includes third party software: 11 | 12 | - AWS SDK for Java, Copyright 2010-2012 Amazon.com, Inc., http://aws.amazon.com/sdkforjava/ 13 | - hector, http://prettyprint.me/2010/02/23/hector-a-java-cassandra-client/ 14 | - jedis, https://github.com/xetorthio/jedis 15 | - Apache Commons, http://commons.apache.org/ 16 | - EZMorph, http://ezmorph.sourceforge.net/ 17 | - FastInfoSet, http://fi.java.net/ 18 | - Apache HTTP Components, http://hc.apache.org/ 19 | - guava-libraries, http://code.google.com/p/guava-libraries/ 20 | - JFree, http://www.jfree.org/ 21 | - json, http://www.json.org/java/index.html 22 | - log4j, http://logging.apache.org/log4j/ 23 | - SLF4j, http://www.slf4j.org/ 24 | - eaio-uuid, https://github.com/stephenc/eaio-uuid 25 | 26 | 27 | -------------------------------------------------------------------------------- /WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 Created-By: 1.6.0 (Sun Microsystems Inc.) -------------------------------------------------------------------------------- /WebContent/WEB-INF/global.css: -------------------------------------------------------------------------------- 1 | body { 2 | background:#FFFFFF; 3 | margin:0; 4 | text-align:center; 5 | line-height: 1.5em; 6 | font: small Verdana, Arial, Sans-serif; 7 | color:#333333; 8 | } 9 | 10 | p { 11 | line-height: 1.5em; 12 | font: small Verdana, Arial, Sans-serif; 13 | color:#333333; 14 | } 15 | 16 | a:link { 17 | color: #333333; 18 | } 19 | a:visited { 20 | color: #333333; 21 | } 22 | a:hover { 23 | color: #333333; 24 | } 25 | a img { 26 | border-width:0; 27 | } 28 | 29 | h1 { 30 | margin:0; 31 | padding:5px 5px 5px; 32 | line-height:1.2em; 33 | font: normal bold 150% Verdana,Arial,Sans-serif; 34 | } 35 | h2 { 36 | margin:0; 37 | padding:5px 5px 5px; 38 | line-height:1.2em; 39 | font: normal bold 125% Verdana,Arial,Sans-serif; 40 | } 41 | h3 { 42 | margin:0; 43 | padding:5px 5px 5px; 44 | line-height:1.2em; 45 | font: normal bold 100% Verdana,Arial,Sans-serif; 46 | } 47 | hr { 48 | padding:1px 1px 1px; 49 | margin: 0px; 50 | } 51 | 52 | .content table 53 | { 54 | border-collapse:collapse; 55 | font: small Verdana, Arial, Sans-serif; 56 | padding:1px 1px 1px; 57 | margin: 5px; 58 | } 59 | .content table, .content td 60 | { 61 | border: 1px solid black; 62 | background-color:#BBBBDD; 63 | font: small bold Verdana, Arial, Sans-serif; 64 | padding: 1px 1px 1px; 65 | } 66 | .content th 67 | { 68 | border: 1px solid black; 69 | background-color:#9999BB; 70 | font: small bold Verdana, Arial, Sans-serif; 71 | padding: 1px 1px 1px; 72 | } 73 | .header table 74 | { 75 | border-collapse:collapse; 76 | font: small Verdana, Arial, Sans-serif; 77 | padding: 0px 0px 0px; 78 | margin: 0px; 79 | } 80 | .header table, .header th, .header td 81 | { 82 | border: 0px; 83 | background-color:#AAAACC; 84 | font: small Verdana, Arial, Sans-serif; 85 | padding: 0px 0px 0px; 86 | } 87 | .simple table 88 | { 89 | border-collapse:collapse; 90 | font: small Verdana, Arial, Sans-serif; 91 | padding:1px 1px 1px; 92 | margin: 5px; 93 | } 94 | .simple table, .simple td 95 | { 96 | border: 1px solid black; 97 | font: small Verdana, Arial, Sans-serif; 98 | padding:1x 1px 1px; 99 | } 100 | .simple th 101 | { 102 | border: 1px solid black; 103 | font: small bold Verdana, Arial, Sans-serif; 104 | padding:1x 1px 1px; 105 | } 106 | table 107 | { 108 | border-collapse:collapse; 109 | font: small Verdana, Arial, Sans-serif; 110 | padding:1px 1px 1px; 111 | margin: 5px; 112 | } 113 | table, td 114 | { 115 | border: 0px; 116 | font: small Verdana, Arial, Sans-serif; 117 | padding:1px 1px 1px; 118 | } 119 | th 120 | { 121 | border: 0px; 122 | font: small bold Verdana, Arial, Sans-serif; 123 | padding:1px 1px 1px; 124 | } 125 | .alternatecolortable 126 | { 127 | border-collapse:collapse; 128 | font: small Verdana, Arial, Sans-serif; 129 | padding:1px 1px 1px; 130 | margin: 5px; 131 | } 132 | .alternatecolortable td{ 133 | border: 1px solid black; 134 | /*background-color:#BBBBDD;*/ 135 | font: small bold Verdana, Arial, Sans-serif; 136 | padding: 1px 1px 1px; 137 | } 138 | provide some minimal visual accomodation for IE8 and below */ 139 | .alternatecolortable tr{ 140 | background: #BBBBDD; 141 | } 142 | /* Define the background color for all the ODD background rows */ 143 | .alternatecolortable tr:nth-child(odd){ 144 | background: #BBBBDD; 145 | } 146 | /* Define the background color for all the EVEN background rows */ 147 | .alternatecolortable tr:nth-child(even){ 148 | background: #DDDDFF; 149 | } 150 | .alternatecolortable th 151 | { 152 | border: 1px solid black; 153 | background-color:#9999BB; 154 | font: small bold Verdana, Arial, Sans-serif; 155 | padding: 1px 1px 1px; 156 | } 157 | 158 | -------------------------------------------------------------------------------- /assembly.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | distribution-${project.version} 7 | 8 | 9 | tar.gz 10 | 11 | 12 | 13 | 14 | ${basedir}/config 15 | 16 | cmb.properties 17 | log4j.properties 18 | 19 | 20 | 21 | ${basedir}/config/WEB-INF-CNS 22 | 23 | web.xml 24 | 25 | 26 | 27 | ${basedir}/config/WEB-INF-CQS 28 | 29 | web.xml 30 | 31 | 32 | 33 | ${basedir}/WebContent/WEB-INF 34 | 35 | global.css 36 | 37 | 38 | 39 | ${basedir}/bin 40 | 41 | cmb.sh 42 | 43 | 44 | 45 | ${basedir}/schema 46 | 47 | *.schema 48 | 49 | 50 | 51 | ${basedir} 52 | 53 | *.txt 54 | 55 | 56 | 57 | ${basedir} 58 | 59 | packaging/linux/centos/* 60 | packaging/common/* 61 | 62 | 63 | 64 | ${project.build.directory}/lib 65 | lib 66 | 67 | javaee-web-api* 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | lib 76 | false 77 | 78 | com.comcast.cmb:${projectname}:jar 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /bin/cmb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #----------------------------------------------------------------------- 4 | # Script to start CMB Node 5 | #----------------------------------------------------------------------- 6 | 7 | # 8 | # Edit cmb.properties in config folder to activate CQS / CNS Service 9 | # Endpoints and / or CNS Publisher. 10 | # 11 | # Edit log4j.properties in config folder to adjust log level. 12 | # 13 | 14 | #----------------------------------------------------------------------- 15 | # CMB VM Settings 16 | #----------------------------------------------------------------------- 17 | 18 | JMX_PORT=52525 19 | LOG4J_PROPS=./config/log4j.properties 20 | CMB_PROPS=./config/cmb.properties 21 | CMB_INSTANCE_NAME=cmb 22 | 23 | #----------------------------------------------------------------------- 24 | 25 | workingDir="$( cd "$( dirname "$0" )" && pwd )" 26 | cd $workingDir 27 | cd .. 28 | 29 | export CLASSPATH=".:config" 30 | for i in `ls lib/*.jar` 31 | do 32 | CLASSPATH=${CLASSPATH}:${i} 33 | done 34 | 35 | echo ${CLASSPATH} 36 | 37 | if [ -f CMB_INSTANCE_NAME ] 38 | then 39 | instance=`cat CMB_INSTANCE_NAME` 40 | fi 41 | 42 | if [ -f lib/jolokia-jvm*-agent.jar ] 43 | then 44 | AGENT_JAR=`ls lib/jolokia-jvm*-agent.jar` 45 | AGENT_OPTION=-javaagent:${AGENT_JAR}=port=7777 46 | else 47 | AGENT_OPTION="" 48 | fi 49 | 50 | java $AGENT_OPTION -Xmx2048m -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=${JMX_PORT} -Dcmb.log4j.propertyFile=${LOG4J_PROPS} -Dcmb.propertyFile=${CMB_PROPS} com.comcast.cmb.common.controller.CMB ${CMB_INSTANCE_NAME} 51 | -------------------------------------------------------------------------------- /bin/travisci_setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | mvn -Dmaven.test.skip=true assembly:assembly 3 | echo "*** Finished mvn" 4 | echo "*** Starting untar into tmp" 5 | tar -xvz -C /tmp -f target/cmb-distribution-* 6 | echo "*** Finished untar into tmp" 7 | 8 | #cp /tmp/cmb/config/test.log4j.properties /tmp/cmb/config/log4j.properties 9 | 10 | echo "installing schema" 11 | cassandra-cli -f /tmp/cmb/schema/cassandra_1.2.schema && sleep 5 12 | (cd /tmp/cmb && nohup bin/cmb.sh &) 13 | echo "*** Ran cmb.sh" 14 | sleep 5 15 | echo "*** checking for cmb process" 16 | ps aux | grep cmb 17 | -------------------------------------------------------------------------------- /config/WEB-INF-CNS/context.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /config/WEB-INF-CQS/context.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /config/log4j.properties: -------------------------------------------------------------------------------- 1 | # Set root logger level to INFO for A1 and A2 2 | 3 | log4j.rootLogger=INFO, A1, A2 4 | 5 | # A1 is a simple consol adapter 6 | 7 | log4j.appender.A1=org.apache.log4j.ConsoleAppender 8 | log4j.appender.A1.layout=com.comcast.cmb.common.util.CMBPatternLayout 9 | log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} [%t] [%R] %-5p %c{1} - %m%n 10 | 11 | # A2 is a simple file adapter logging to /tmp/cmb.log 12 | log4j.appender.A2=org.apache.log4j.RollingFileAppender 13 | log4j.appender.A2.MaxFileSize=500MB 14 | log4j.appender.A2.MaxBackupIndex=1 15 | log4j.appender.A2.append=true 16 | log4j.appender.A2.File=/tmp/cmb.log 17 | log4j.appender.A2.layout=com.comcast.cmb.common.util.CMBPatternLayout 18 | log4j.appender.A2.layout.ConversionPattern=%d{ISO8601} [%t] [%R] %-5p %c{1} - %m%n 19 | -------------------------------------------------------------------------------- /config/test.log4j.properties: -------------------------------------------------------------------------------- 1 | # Set root logger level to DEBUG for A1 and A2 2 | 3 | log4j.rootLogger=ERROR, A1, A2 4 | 5 | # A1 is a simple consol adapter 6 | 7 | log4j.appender.A1=org.apache.log4j.ConsoleAppender 8 | log4j.appender.A1.layout=com.comcast.cmb.common.util.CMBPatternLayout 9 | log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} [%H] [%t] [%R] %-5p %c{1} - %m%n 10 | 11 | # A2 is a simple file adapter logging to /tmp/cmb.log 12 | 13 | log4j.appender.A2=org.apache.log4j.FileAppender 14 | log4j.appender.A2.File=/tmp/cmb.log 15 | log4j.appender.A2.layout=com.comcast.cmb.common.util.CMBPatternLayout 16 | log4j.appender.A2.layout.ConversionPattern=%d{ISO8601} [%H] [%t] [%R] %-5p %c{1} - %m%n 17 | -------------------------------------------------------------------------------- /docker/cmb/bin/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | # Set addresses and ports from env to template file 4 | sed -i -e "s/CASSANDRA_ADDR/$CASSANDRA_PORT_9160_TCP_ADDR/" $ROOTDIR/docker/cmb/cmb.properties.template 5 | sed -i -e "s/CASSANDRA_PORT/$CASSANDRA_PORT_9160_TCP_PORT/" $ROOTDIR/docker/cmb/cmb.properties.template 6 | sed -i -e "s/REDIS_ADDR/$REDIS_PORT_6379_TCP_ADDR/" $ROOTDIR/docker/cmb/cmb.properties.template 7 | sed -i -e "s/REDIS_PORT/$REDIS_PORT_6379_TCP_PORT/" $ROOTDIR/docker/cmb/cmb.properties.template 8 | 9 | # Overwrite configuration file by template 10 | cat $ROOTDIR/docker/cmb/cmb.properties.template> $ROOTDIR/config/cmb.properties 11 | 12 | /app/src/cmb/bin/cmb.sh 13 | -------------------------------------------------------------------------------- /docker/docker-compose.yml: -------------------------------------------------------------------------------- 1 | cmb: 2 | build: ../ 3 | ports: 4 | - "6059:6059" 5 | - "6061:6061" 6 | links: 7 | - cassandra 8 | - redis 9 | # cassandra container needs to be initialized by the schema. Run below: 10 | # docker exec -it cmb_cassandra_1 cqlsh -f /tmp/cassandra_1.2.cql.schema 11 | cassandra: 12 | build: ../ 13 | dockerfile: Dockerfile-cassandra 14 | expose: 15 | - "7000" 16 | - "7001" 17 | - "7199" 18 | - "9042" 19 | - "9160" 20 | redis: 21 | build: ../ 22 | dockerfile: Dockerfile-redis 23 | expose: 24 | - "6379" 25 | -------------------------------------------------------------------------------- /docs/xcal-CNSArchitecture-210912-1546-6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Comcast/cmb/d93e9e24f98563ac843cd841e4b863ee1bc92ba4/docs/xcal-CNSArchitecture-210912-1546-6.pdf -------------------------------------------------------------------------------- /docs/xcal-CNSProductRequirements-210912-1548-10.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Comcast/cmb/d93e9e24f98563ac843cd841e4b863ee1bc92ba4/docs/xcal-CNSProductRequirements-210912-1548-10.pdf -------------------------------------------------------------------------------- /docs/xcal-CQSArchitecture-210912-1545-4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Comcast/cmb/d93e9e24f98563ac843cd841e4b863ee1bc92ba4/docs/xcal-CQSArchitecture-210912-1545-4.pdf -------------------------------------------------------------------------------- /docs/xcal-CQSProductRequirements-210912-1548-8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Comcast/cmb/d93e9e24f98563ac843cd841e4b863ee1bc92ba4/docs/xcal-CQSProductRequirements-210912-1548-8.pdf -------------------------------------------------------------------------------- /examples/ruby/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | -------------------------------------------------------------------------------- /examples/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'aws-sdk-core' 4 | gem 'aws-sdk-resources' 5 | gem 'awesome_print' 6 | gem 'nokogiri' 7 | gem 'pry-byebug' 8 | -------------------------------------------------------------------------------- /examples/ruby/example.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Usage: 3 | # 4 | # bundle install 5 | # ACCESS_KEY="cmb user's access key" SECRET_KEY="cmb user's secret key" ruby ./example.rb 6 | # 7 | # 8 | 9 | require 'rubygems' 10 | require 'bundler/setup' 11 | 12 | Bundler.require :default 13 | 14 | access_key = ENV['ACCESS_KEY'] 15 | secret_key = ENV['SECRET_KEY'] 16 | 17 | sns_endpoint = "http://localhost:6061/" 18 | sqs_endpoint = "http://localhost:6059/" 19 | 20 | Aws.config[:credentials] = Aws::Credentials.new access_key, secret_key 21 | Aws.config[:region] = 'csv' 22 | 23 | sns = Aws::SNS::Client.new endpoint: sns_endpoint 24 | sqs = Aws::SQS::Client.new endpoint: sqs_endpoint 25 | 26 | # create unique topic and queue names via the current time 27 | 28 | topic_name = "topic-#{Time.now.to_i}" 29 | queue_name = "queue-#{Time.now.to_i}" 30 | 31 | # remove any existing topics and queues in this account 32 | 33 | sns.list_topics[:topics].map { |topic| topic[:topic_arn] }.compact.each do |arn| 34 | puts "Deleting topic: #{arn}" 35 | sns.delete_topic topic_arn: arn 36 | end 37 | 38 | sqs.list_queues[:queue_urls].each do |url| 39 | puts "Deleting queue: #{url}" 40 | sqs.delete_queue queue_url: url 41 | end 42 | 43 | # create the topic, queue and subscription 44 | 45 | puts "Creating topic: #{topic_name}" 46 | topic_arn = sns.create_topic(name: topic_name)[:topic_arn] 47 | topic = Aws::SNS::Topic.new topic_arn, client: sns 48 | 49 | puts "Creating queue: #{queue_name}" 50 | queue_url = sqs.create_queue(queue_name: queue_name)[:queue_url] 51 | queue = Aws::SQS::Queue.new queue_url, client: sqs 52 | 53 | puts "Subscribing: #{queue_name} to #{topic_name}" 54 | subscription = topic.subscribe(endpoint: queue.arn, protocol: 'cqs') 55 | subscription.set_attributes attribute_name: 'RawMessageDelivery', attribute_value: 'true' 56 | 57 | # publish a message on the topic 58 | 59 | puts "Publishing to: #{topic_name}" 60 | 61 | delivery = topic.publish message: 'test', message_attributes: { 62 | 'ruby_example.key_1' => { 63 | string_value: 'xyz', 64 | data_type: 'String' 65 | }, 66 | 67 | 'ruby_example.key_2' => { 68 | string_value: '123', 69 | data_type: 'Number' 70 | } 71 | } 72 | 73 | if delivery.nil? 74 | puts 'Published message was not delivered to any subscribers!' 75 | exit 1 76 | end 77 | 78 | sleep(1) 79 | 80 | puts "Receiving messages from: #{queue_name}" 81 | resp = queue.receive_messages(:message_attribute_names => [ "All" ]) 82 | messages = resp.to_a 83 | 84 | if messages.empty? 85 | puts "No message was received!" 86 | exit 1 87 | end 88 | 89 | message = messages.first 90 | 91 | puts "Message..." 92 | 93 | ap message_id: message.message_id, 94 | receipt_handle: message.receipt_handle, 95 | attributes: message.attributes, 96 | body: message.body, 97 | message_attributes: message.message_attributes 98 | -------------------------------------------------------------------------------- /packaging/common/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.logger.me.prettyprint=INFO 2 | log4j.rootLogger=INFO, A1 3 | log4j.logger.httpclient=INFO 4 | log4j.logger.org.apache=INFO 5 | log4j.appender.A1=org.apache.log4j.RollingFileAppender 6 | log4j.appender.A1.MaxFileSize=500MB 7 | log4j.appender.A1.MaxBackupIndex=3 8 | log4j.appender.A1.append=true 9 | log4j.appender.A1.File=/opt/cmb/logs/cmb.log 10 | log4j.appender.A1.layout=com.comcast.cmb.common.util.CMBPatternLayout 11 | log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} [%t] [%R] %-5p %c{1} - %m%n 12 | -------------------------------------------------------------------------------- /packaging/linux/centos/cmb.init: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # chkconfig: 345 20 80 3 | # description: Cloud Message Bus API server 4 | # /etc/initd.d/cmb 5 | CLASS=com.comcast.cmb.common.controller.CMB 6 | USER=cmb 7 | 8 | restart() { 9 | # start does a stop 10 | start 11 | } 12 | 13 | start() { 14 | stop 15 | cd /opt/cmb 16 | su $USER -c "nohup /opt/cmb/bin/cmb.sh > logs/cmb.stdout.log 2> logs/cmb.stderr.log &" 17 | } 18 | 19 | stop() { 20 | pkill -f $CLASS 21 | sleep 1 22 | pkill -9 -f $CLASS 23 | sleep 1 24 | } 25 | 26 | status() { 27 | pgrep -f $CLASS 28 | exit $? 29 | } 30 | 31 | case $1 in 32 | start|stop|restart|status) 33 | $1 34 | ;; 35 | *) 36 | echo "USAGE: $0 " 37 | exit 1 38 | ;; 39 | esac 40 | 41 | -------------------------------------------------------------------------------- /packaging/linux/centos/cmb.spec: -------------------------------------------------------------------------------- 1 | Summary: Cloud Message Bus - a clone of SQS/SNS 2 | Name: cmb 3 | Version: 2.2.41 4 | BuildArch: noarch 5 | Release: 1 6 | Group: Applications 7 | License: Private 8 | AutoReqProv: no 9 | Source: http://cmbdownloads.s3-website-us-west-1.amazonaws.com/%{version}/cmb-distribution-%{version}.tar.gz 10 | URL: http://github.com/Comcast/cmb 11 | 12 | 13 | %description 14 | Cloud Message Bus implements a (largely) API compatible implementation of Amazon's SQS and SNS services 15 | 16 | %prep 17 | 18 | %setup -n cmb 19 | 20 | %build 21 | 22 | %install 23 | rm -rf %{buildroot} 24 | mkdir -p %{buildroot}/opt/cmb/logs 25 | mkdir -p %{buildroot}/opt/cmb/docs 26 | mkdir -p %{buildroot}/opt/cmb/schema 27 | mkdir -p %{buildroot}/etc/init.d 28 | cp %{_builddir}/cmb/packaging/linux/centos/cmb.init %{buildroot}/etc/init.d/cmb 29 | cp -r %{_builddir}/cmb/lib %{buildroot}/opt/cmb 30 | cp -r %{_builddir}/cmb/bin %{buildroot}/opt/cmb 31 | cp -r %{_builddir}/cmb/WebContent %{buildroot}/opt/cmb 32 | cp -r %{_builddir}/cmb/config %{buildroot}/opt/cmb 33 | cp -r %{_builddir}/cmb/schema %{buildroot}/opt/cmb 34 | cp %{_builddir}/cmb/[A-Z]*.txt %{buildroot}/opt/cmb/docs 35 | cp %{_builddir}/cmb/packaging/common/log4j.properties %{buildroot}/opt/cmb/config/log4j.properties 36 | 37 | %clean 38 | 39 | %files 40 | %attr(755, root, root) /etc/init.d/cmb 41 | %defattr(-,cmb,cmb) 42 | /opt/cmb/bin 43 | /opt/cmb/lib 44 | /opt/cmb/WebContent 45 | /opt/cmb/schema 46 | /opt/cmb/docs 47 | /opt/cmb/logs 48 | /opt/cmb/config/WEB-INF-CNS/web.xml 49 | /opt/cmb/config/WEB-INF-CQS/web.xml 50 | %config(noreplace) /opt/cmb/config/cmb.properties 51 | %config(noreplace) /opt/cmb/config/log4j.properties 52 | 53 | %pre 54 | groupadd cmb || true 55 | useradd -g cmb cmb || true 56 | 57 | %post 58 | /sbin/chkconfig --add cmb 59 | 60 | %preun 61 | /sbin/service cmb stop 62 | /sbin/chkconfig --del cmb 63 | 64 | -------------------------------------------------------------------------------- /packaging/vagrant/cmbbase/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | # to create the base image and move it to the cluster configuration use: 5 | # vagrant up 6 | # vagrant package -output cmbbase 7 | # mv cmbbase ../cmbcluster 8 | # cd ../cmbcluster 9 | # vagrant up 10 | 11 | # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! 12 | VAGRANTFILE_API_VERSION = "2" 13 | 14 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 15 | 16 | config.vm.box = "hashicorp/precise64" 17 | 18 | #config.vm.box_url = "http://domain.com/path/to/above.box" 19 | 20 | # provisioning 21 | 22 | config.vm.provision :shell, :path => "bootstrap.sh" 23 | 24 | # use private network for multi-machine environment 25 | 26 | config.vm.network "private_network", type: "dhcp" 27 | 28 | end 29 | -------------------------------------------------------------------------------- /packaging/vagrant/cmbbase/bootstrap.sh: -------------------------------------------------------------------------------- 1 | # make sure system sources are up to date. 2 | 3 | apt-get update 4 | 5 | echo "installing dependencies" 6 | 7 | apt-get -y install curl gcc make 8 | 9 | echo "installing java" 10 | 11 | wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/7u55-b13/jdk-7u55-linux-x64.tar.gz" -O jdk-7-linux-x64.tar.gz 12 | tar -xzvf jdk-7-linux-x64.tar.gz 13 | mkdir -p /usr/java 14 | mv jdk1.7.0_55 /usr/java 15 | 16 | update-alternatives --install /usr/bin/java java /usr/java/jdk1.7.0_55/bin/java 1 17 | update-alternatives --install /usr/bin/javac javac /usr/java/jdk1.7.0_55/bin/javac 1 18 | update-alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.7.0_55/bin/javaws 1 19 | 20 | echo "installing cassandra" 21 | 22 | # https://gist.github.com/hengxin/8e5040d7a8b354b1c82e 23 | 24 | echo "deb http://debian.datastax.com/community stable main" | tee -a /etc/apt/sources.list.d/cassandra.sources.list 25 | 26 | curl -L http://debian.datastax.com/debian/repo_key | apt-key add - 27 | 28 | apt-get update 29 | 30 | apt-get -y install dsc20 cassandra=2.0.15 -V 31 | 32 | # TODO: edit /etc/cassandra/cassandra.yaml and restart 33 | 34 | #sudo service cassandra stop 35 | #sudo rm -rf /var/lib/cassandra/data/* 36 | 37 | #/etc/init.d/cassandra start 38 | 39 | nohup cassandra -f & 40 | 41 | # install redis 42 | 43 | # sadly this installs redis 2.2 44 | 45 | #apt-get install redis-server 46 | #sed -e '/save/ s/^#*/#/' -i /etc/redis/redis.conf 47 | #/etc/init.d/redis-server restart 48 | 49 | # download and make Redis 50 | 51 | wget http://download.redis.io/releases/redis-2.6.17.tar.gz 52 | tar xzf redis-2.6.17.tar.gz -C /usr/lib/ 53 | cd /usr/lib/redis-2.6.17 54 | make 55 | 56 | # create symlinks to the /usr/local/bin 57 | 58 | ln -s /usr/lib/redis-2.6.17/src/redis-server /usr/local/bin/redis-server 59 | ln -s /usr/lib/redis-2.6.17/src/redis-cli /usr/local/bin/redis-cli 60 | 61 | # set up init to run redis on startup 62 | 63 | cd /usr/lib/redis-2.6.17/utils 64 | ./install_server.sh 65 | 66 | # cmb settings for redis 67 | 68 | sed -e '/save/ s/^#*/#/' -i /etc/redis/6379.conf 69 | 70 | /etc/init.d/redis_6379 stop 71 | /etc/init.d/redis_6379 start 72 | 73 | # install cmb 74 | 75 | cd /home/vagrant 76 | 77 | wget "https://s3-us-west-1.amazonaws.com/cmb-releases/2.2.43/cmb-distribution-2.2.43.tar.gz" -O cmb-distribution-2.2.43.tar.gz 78 | 79 | tar -xzvf cmb-distribution-2.2.43.tar.gz 80 | 81 | sed -e '/drop/ s/^-*/--/' -i cmb/schema/cassandra_1.2.schema 82 | 83 | cassandra-cli -f cmb/schema/cassandra_1.2.schema 84 | 85 | sed -i 's,^\(cmb\.cns\.serviceEnabled=\).*,\1'false',' cmb/config/cmb.properties 86 | sed -i 's,^\(cmb\.cns\.publisherEnabled=\).*,\1'false',' cmb/config/cmb.properties 87 | 88 | cd cmb 89 | nohup bin/cmb.sh & 90 | 91 | # TODO: supervisord config for cmb 92 | # TODO: move cmb to a better place 93 | -------------------------------------------------------------------------------- /packaging/vagrant/cmbcluster/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! 5 | VAGRANTFILE_API_VERSION = "2" 6 | 7 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 8 | 9 | # use private network for multi-machine environment 10 | # may want to use static IP addresses instead of dhcp 11 | # for predictable results 12 | 13 | config.vm.network "private_network", type: "dhcp" 14 | 15 | config.vm.define "cmb1" do |cmb1| 16 | cmb1.vm.box = "cmbbase" 17 | #cmb1.vm.network "private_network", ip: "172.28.128.3" 18 | end 19 | 20 | config.vm.define "cmb2" do |cmb2| 21 | cmb2.vm.box = "cmbbase" 22 | #cmb2.vm.network "private_network", ip: "172.28.128.4" 23 | end 24 | 25 | config.vm.define "cmb3" do |cmb3| 26 | cmb3.vm.box = "cmbbase" 27 | #cmb3.vm.network "private_network", ip: "172.28.128.5" 28 | end 29 | 30 | end -------------------------------------------------------------------------------- /src/com/comcast/cmb/common/controller/UserPageServlet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cmb.common.controller; 17 | 18 | import java.io.IOException; 19 | import java.io.PrintWriter; 20 | 21 | import javax.servlet.ServletException; 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | 25 | import org.apache.log4j.Logger; 26 | 27 | import com.comcast.cmb.common.model.User; 28 | import com.comcast.cmb.common.persistence.IUserPersistence; 29 | import com.comcast.cmb.common.persistence.PersistenceFactory; 30 | import com.comcast.cmb.common.util.PersistenceException; 31 | import com.comcast.cmb.common.util.ValueAccumulator.AccumulatorName; 32 | 33 | /** 34 | * Class used to display user information 35 | * @author bwolf, aseem, tina 36 | */ 37 | public class UserPageServlet extends AdminServletBase { 38 | 39 | private static final long serialVersionUID = 1L; 40 | private static Logger logger = Logger.getLogger(UserPageServlet.class); 41 | 42 | @Override 43 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { 44 | 45 | if (redirectUnauthenticatedUser(request, response)) { 46 | return; 47 | } 48 | 49 | CMBControllerServlet.valueAccumulator.initializeAllCounters(); 50 | response.setContentType("text/html"); 51 | PrintWriter out = response.getWriter(); 52 | String userId = request.getParameter("userId"); 53 | IUserPersistence userHandler = PersistenceFactory.getUserPersistence(); 54 | User user = null; 55 | 56 | try { 57 | user = userHandler.getUserById(userId); 58 | } catch (PersistenceException ex) { 59 | logger.error("event=get_user user_id=" + userId, ex); 60 | throw new ServletException(ex); 61 | } 62 | 63 | out.println(""); 64 | 65 | header(request, out, "User "+user.getUserName()); 66 | 67 | out.println(""); 68 | 69 | out.println("

User "+user.getUserName()+"

"); 70 | 71 | if (user != null) { 72 | out.println(""); 73 | out.println(""); 74 | out.println(""); 75 | out.println(""); 76 | out.println("
User Name:"+ user.getUserName()+"
User ID:"+ user.getUserId()+"
Access Key:"+user.getAccessKey()+"
Access Secret:"+user.getAccessSecret()+"
"); 77 | } 78 | 79 | out.println(""); 80 | 81 | logger.info("action=userPageServletProcess CassandraTimeMS=" + CMBControllerServlet.valueAccumulator.getCounter(AccumulatorName.CassandraTime)); 82 | CMBControllerServlet.valueAccumulator.deleteAllCounters(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/com/comcast/cmb/common/model/CMBCondition.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cmb.common.model; 17 | 18 | /** 19 | * Class used by policy to represent condition 20 | * @author bwolf 21 | * Class is immutable 22 | */ 23 | public class CMBCondition { 24 | 25 | private final String condition; 26 | 27 | public CMBCondition(String condition) { 28 | this.condition = condition; 29 | } 30 | 31 | public String getCondition() { 32 | return this.condition; 33 | } 34 | 35 | public String toString() { 36 | return this.condition; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/com/comcast/cmb/common/model/IAuthModule.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cmb.common.model; 17 | 18 | import com.comcast.cmb.common.persistence.IUserPersistence; 19 | import com.comcast.cmb.common.util.CMBException; 20 | 21 | import javax.servlet.http.HttpServletRequest; 22 | 23 | /** 24 | * @author michael, bwolf, baosen 25 | * Interface representing functionality to authenticate users 26 | */ 27 | public interface IAuthModule { 28 | 29 | public void setUserPersistence(IUserPersistence userPersistence); 30 | 31 | /** 32 | * Authenticate the request by checking the signature provided in the parameters. 33 | * Assumed that the request has the following parameters: 34 | * - AWSAccessKeyId 35 | * - Signature 36 | * - Timestamp 37 | * - Expires 38 | * - SignatureVersion 39 | * - SignatureMethod 40 | * @param request 41 | * @return On succesful authentication returns an instance of the User making the request 42 | * @throws CMBException 43 | */ 44 | public User authenticateByRequest(HttpServletRequest request) throws CMBException; 45 | 46 | /** 47 | * Authenticates a user given their username and hashedPassword 48 | * @param username 49 | * @param password the MD5 hashed password 50 | * @return 51 | * @throws CMBException 52 | */ 53 | public User authenticateByPassword(String username, String password) throws CMBException; 54 | 55 | /** 56 | * Get the User by Request AWSAccessKeyId. 57 | * Assumed that the request has the following parameters: 58 | * - AWSAccessKeyId 59 | * @param request 60 | * @return user or null 61 | */ 62 | public User getUserByRequest(HttpServletRequest request); 63 | } 64 | -------------------------------------------------------------------------------- /src/com/comcast/cmb/common/model/IPermission.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cmb.common.model; 17 | 18 | /** 19 | * Interface represents a Permission 20 | * @author michael 21 | * 22 | */ 23 | public interface IPermission { 24 | 25 | public String getUserId(); 26 | public String getLabel(); 27 | public String getAction(); 28 | public String getARN(); 29 | public String getType(); 30 | } 31 | -------------------------------------------------------------------------------- /src/com/comcast/cmb/common/model/ReceiptModule.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cmb.common.model; 17 | 18 | import java.util.UUID; 19 | /** 20 | * @author michael 21 | */ 22 | public class ReceiptModule { 23 | 24 | private static final ThreadLocal receiptId = 25 | new ThreadLocal () { 26 | protected String initialValue() { 27 | return UUID.randomUUID().toString(); 28 | } 29 | }; 30 | 31 | /** 32 | * Get the receipt ID. Receipt ID is a thread local object. It will be unique per thread 33 | * @return receiptId 34 | */ 35 | public static String getReceiptId() { 36 | return receiptId.get(); 37 | } 38 | 39 | /** 40 | * Initialize the receipt ID. This function should be called for every new request. 41 | */ 42 | public static void init() { 43 | receiptId.remove(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/com/comcast/cmb/common/persistence/DurablePersistenceFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cmb.common.persistence; 17 | 18 | public class DurablePersistenceFactory { 19 | 20 | private void CassandraPersistenceFactory() { 21 | } 22 | 23 | public static AbstractDurablePersistence getInstance() { 24 | //return CassandraHectorPersistence.getInstance(); 25 | return CassandraAstyanaxPersistence.getInstance(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/com/comcast/cmb/common/persistence/IPermissionPersistence.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cmb.common.persistence; 17 | 18 | import com.comcast.cmb.common.model.IPermission; 19 | import java.util.List; 20 | 21 | /** 22 | * Represents the persistence of a Permission 23 | * @author michael, baosen 24 | */ 25 | public interface IPermissionPersistence { 26 | 27 | /** 28 | * Return a list of permissions for that user 29 | * @param userId 30 | * @return 31 | */ 32 | public List getPermissionsByUser(String userId); 33 | 34 | /** 35 | * Return a list of permissions given a topic ARN or a queue ARN 36 | * @param arn 37 | * @return 38 | */ 39 | public List getPermissionsByARN(String arn); 40 | 41 | /** 42 | * 43 | * @param userId 44 | * @param action 45 | * @param arn 46 | * @return 47 | */ 48 | public boolean isUserAuthorized(String userId, String action, String arn); 49 | } 50 | -------------------------------------------------------------------------------- /src/com/comcast/cmb/common/persistence/IUserPersistence.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cmb.common.persistence; 17 | 18 | import com.comcast.cmb.common.model.User; 19 | import com.comcast.cmb.common.util.PersistenceException; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * interface represents the persistence functionality for a User object 25 | * @author bwolf, vvenkatraman, michael 26 | */ 27 | public interface IUserPersistence { 28 | 29 | /** 30 | * Create a user given username and password 31 | * @param userName 32 | * @param password 33 | * @return User object if successful 34 | */ 35 | public User createUser(String userName, String password) throws PersistenceException; 36 | 37 | /** 38 | * Create a user given username, password and admin permission 39 | * @param userName 40 | * @param password 41 | * @return User object if successful 42 | */ 43 | public User createUser(String userName, String password, Boolean isAdmin) throws PersistenceException; 44 | public User createUser(String userName, String password, Boolean isAdmin, String description) throws PersistenceException;; 45 | 46 | /** 47 | * Create a default user given username, password in CMB properties and admin permission 48 | * @param userName 49 | * @param password 50 | * @return User object if successful 51 | */ 52 | public User createDefaultUser() throws PersistenceException; 53 | 54 | /** 55 | * Delete a user given an user name 56 | * @param userName 57 | */ 58 | public void deleteUser(String userName) throws PersistenceException; 59 | 60 | /** 61 | * Get all users 62 | * @return all users in a list 63 | * @throws PersistenceException 64 | */ 65 | public List getAllUsers() throws PersistenceException; 66 | 67 | public User getUserById(String userId) throws PersistenceException; 68 | public User getUserByName(String userName) throws PersistenceException; 69 | public User getUserByAccessKey(String accessKey) throws PersistenceException; 70 | 71 | /** 72 | * Gte number of queues this user owns 73 | * @param userId 74 | * @return 75 | * @throws PersistenceException 76 | */ 77 | public long getNumUserQueues(String userId) throws PersistenceException; 78 | 79 | /** 80 | * Gte number of topics this user owns 81 | * @param userId 82 | * @return 83 | * @throws PersistenceException 84 | */ 85 | public long getNumUserTopics(String userId) throws PersistenceException; 86 | 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/com/comcast/cmb/common/persistence/PersistenceFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cmb.common.persistence; 17 | 18 | import com.comcast.cns.persistence.CNSAttributesCassandraPersistence; 19 | import com.comcast.cns.persistence.CNSSubscriptionCassandraPersistence; 20 | import com.comcast.cns.persistence.CNSTopicCassandraPersistence; 21 | import com.comcast.cns.persistence.ICNSAttributesPersistence; 22 | import com.comcast.cns.persistence.ICNSSubscriptionPersistence; 23 | import com.comcast.cns.persistence.ICNSTopicPersistence; 24 | import com.comcast.cqs.persistence.CQSQueueCassandraPersistence; 25 | import com.comcast.cqs.persistence.ICQSMessagePersistence; 26 | import com.comcast.cqs.persistence.ICQSQueuePersistence; 27 | import com.comcast.cqs.persistence.RedisCachedCassandraPersistence; 28 | import com.comcast.cqs.persistence.RedisSortedSetPersistence; 29 | 30 | /** 31 | * The factory to create appt implementations of the various persistence interfaces 32 | * @author bwolf, aseem, jorge, baosen 33 | */ 34 | public class PersistenceFactory { 35 | /** 36 | * Note: The attributes are made public and non-final only for unit-test purposes. 37 | * Non-unit-test code should only call accessors. 38 | */ 39 | public static ICQSQueuePersistence cqsQueuePersistence = new CQSQueueCassandraPersistence(); 40 | public static ICNSSubscriptionPersistence cnsSubscriptionPersistence = new CNSSubscriptionCassandraPersistence(); 41 | public static ICNSTopicPersistence cnsTopicPersistence = new CNSTopicCassandraPersistence(); 42 | public static IUserPersistence userPersistence = new UserCassandraPersistence(); 43 | public static ICNSAttributesPersistence cnsAttributePersistence = new CNSAttributesCassandraPersistence(); 44 | public static ICQSMessagePersistence cqsMessagePersistence = RedisSortedSetPersistence.getInstance(); 45 | //public static ICQSMessagePersistence cqsMessagePersistence = RedisCachedCassandraPersistence.getInstance(); 46 | 47 | public static IUserPersistence getUserPersistence() { 48 | return userPersistence; 49 | } 50 | 51 | public static ICNSTopicPersistence getTopicPersistence() { 52 | return cnsTopicPersistence; 53 | } 54 | 55 | public static ICNSSubscriptionPersistence getSubscriptionPersistence() { 56 | return cnsSubscriptionPersistence; 57 | } 58 | 59 | public static ICQSQueuePersistence getQueuePersistence() { 60 | return cqsQueuePersistence; 61 | } 62 | 63 | public static ICNSAttributesPersistence getCNSAttributePersistence() { 64 | return cnsAttributePersistence; 65 | } 66 | 67 | public static ICQSMessagePersistence getCQSMessagePersistence() { 68 | return cqsMessagePersistence; 69 | } 70 | 71 | /** 72 | * Only called by unit-tests 73 | */ 74 | public static synchronized void reset() { 75 | cqsQueuePersistence = new CQSQueueCassandraPersistence(); 76 | cnsSubscriptionPersistence = new CNSSubscriptionCassandraPersistence(); 77 | cnsTopicPersistence = new CNSTopicCassandraPersistence(); 78 | userPersistence = new UserCassandraPersistence(); 79 | cnsAttributePersistence = new CNSAttributesCassandraPersistence(); 80 | cqsMessagePersistence = RedisSortedSetPersistence.getInstance(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/com/comcast/cmb/common/util/AuthenticationException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.comcast.cmb.common.util; 18 | 19 | /** 20 | * Exception thrown during authentication 21 | * @author michael, aseem 22 | */ 23 | public class AuthenticationException extends CMBException { 24 | 25 | private static final long serialVersionUID = 1L; 26 | 27 | public AuthenticationException(int httpCode, String awsCode, String message) { 28 | super(httpCode, awsCode, message); 29 | } 30 | 31 | public AuthenticationException(CMBErrorCodes error, String message) { 32 | super(error, message); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/com/comcast/cmb/common/util/CMBException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cmb.common.util; 17 | 18 | /** 19 | * Class represents generic CMBException 20 | * @author bwolf, baosen, aseem, michael 21 | * 22 | * Class is immutable 23 | */ 24 | public class CMBException extends Exception { 25 | 26 | private static final long serialVersionUID = 1L; 27 | protected final int httpCode; 28 | protected final String cmbCode; 29 | 30 | /** 31 | * THe superclass exception for all ComcastMessageBus 32 | * @param httpCode the corresponding http error code 33 | * @param awsCode the corresponding AWS string error code 34 | * @param message A more descriptive message about teh error 35 | */ 36 | public CMBException(int httpCode, String cmbCode, String message) { 37 | super(message); 38 | 39 | this.httpCode = httpCode; 40 | this.cmbCode = cmbCode; 41 | } 42 | 43 | public CMBException(CMBErrorCodes error, String message) { 44 | super(message); 45 | 46 | this.httpCode = error.getHttpCode(); 47 | this.cmbCode = error.getCMBCode(); 48 | } 49 | 50 | public int getHttpCode() { 51 | return httpCode; 52 | } 53 | 54 | public String getCMBCode() { 55 | return cmbCode; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/com/comcast/cmb/common/util/CMBPatternLayout.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.comcast.cmb.common.util; 18 | 19 | import com.comcast.cmb.common.model.ReceiptModule; 20 | 21 | import org.apache.log4j.PatternLayout; 22 | import org.apache.log4j.helpers.PatternConverter; 23 | import org.apache.log4j.helpers.PatternParser; 24 | import org.apache.log4j.spi.LoggingEvent; 25 | 26 | /** 27 | * Pattern definition for log4j 28 | * @author michael, baosen, vvenkatraman 29 | */ 30 | public class CMBPatternLayout extends PatternLayout { 31 | 32 | public CMBPatternLayout() { 33 | if (hostname != null) return; 34 | 35 | try { 36 | java.net.InetAddress localMachine = java.net.InetAddress.getLocalHost(); 37 | hostname = localMachine.getHostName(); 38 | } 39 | catch (java.net.UnknownHostException uhe) { 40 | hostname = null; 41 | } 42 | } 43 | 44 | protected PatternParser createPatternParser(String pattern) { 45 | return new CMBPatternParser(pattern); 46 | } 47 | 48 | static final char RECEIPT_CHAR = 'R'; 49 | static final char HOST_NAME = 'H'; 50 | 51 | private final CMBPatternConverter receiptConverter = new CMBPatternConverter(RECEIPT_CHAR); 52 | private final CMBPatternConverter hostnameConverter = new CMBPatternConverter(HOST_NAME); 53 | 54 | private static volatile String hostname = null; 55 | 56 | class CMBPatternParser extends PatternParser { 57 | 58 | CMBPatternParser(String pattern) { 59 | super(pattern); 60 | } 61 | 62 | protected void finalizeConverter(char c) { 63 | switch (c) { 64 | case RECEIPT_CHAR: 65 | currentLiteral.setLength(0); 66 | addConverter(receiptConverter); 67 | break; 68 | 69 | case HOST_NAME: 70 | currentLiteral.setLength(0); 71 | addConverter(hostnameConverter); 72 | break; 73 | 74 | default: 75 | super.finalizeConverter(c); 76 | } 77 | } 78 | } 79 | 80 | class CMBPatternConverter extends PatternConverter { 81 | private char patternChar; 82 | 83 | CMBPatternConverter(char c) { 84 | patternChar = c; 85 | } 86 | 87 | protected String convert(LoggingEvent evt) { 88 | if (patternChar == RECEIPT_CHAR) 89 | return ReceiptModule.getReceiptId(); 90 | else if (patternChar == HOST_NAME) 91 | return hostname; 92 | return null; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/com/comcast/cmb/common/util/PersistenceException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cmb.common.util; 17 | 18 | /** 19 | * Exeption represents generic CMBException during persistence 20 | * @author michael, aseem 21 | */ 22 | public class PersistenceException extends CMBException { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | public PersistenceException(int httpCode, String cmbCode, String msg) { 27 | super(httpCode, cmbCode, msg); 28 | } 29 | 30 | public PersistenceException(CMBErrorCodes error, String message) { 31 | super(error, message); 32 | } 33 | 34 | public PersistenceException(Exception ex) { 35 | super(CMBErrorCodes.InternalError, ex.getMessage()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/comcast/cns/controller/CNSAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.controller; 17 | 18 | import javax.servlet.http.HttpServletRequest; 19 | 20 | import com.comcast.cmb.common.controller.Action; 21 | import com.comcast.cmb.common.model.CMBPolicy; 22 | import com.comcast.cmb.common.model.User; 23 | import com.comcast.cmb.common.persistence.PersistenceFactory; 24 | import com.comcast.cns.model.CNSSubscription; 25 | import com.comcast.cns.util.Util; 26 | 27 | /** 28 | * Abstract class representing all actions we accept for CNS 29 | * @author bwolf 30 | */ 31 | public abstract class CNSAction extends Action { 32 | 33 | public CNSAction(String actionName) { 34 | super(actionName); 35 | } 36 | 37 | @Override 38 | public boolean isActionAllowed(User user, HttpServletRequest request, String service, CMBPolicy policy) throws Exception { 39 | 40 | String topicArn = request.getParameter("TopicArn"); 41 | 42 | if (topicArn == null && request.getParameter("SubscriptionArn") != null) { 43 | 44 | CNSSubscription subscription = PersistenceFactory.getSubscriptionPersistence().getSubscription(request.getParameter("SubscriptionArn")); 45 | 46 | if (subscription != null) { 47 | topicArn = subscription.getTopicArn(); 48 | } 49 | } 50 | 51 | if (user.getUserId().equals(Util.getUserIdFromTopicArn(topicArn))) { 52 | return true; 53 | } 54 | 55 | if (policy == null) { 56 | return false; 57 | } 58 | 59 | return policy.isAllowed(user, service + ":" + this.actionName); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/com/comcast/cns/controller/CNSCreateTopicAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.controller; 17 | 18 | import javax.servlet.AsyncContext; 19 | import javax.servlet.http.HttpServletRequest; 20 | import javax.servlet.http.HttpServletResponse; 21 | 22 | import org.apache.log4j.Logger; 23 | 24 | import com.comcast.cmb.common.model.CMBPolicy; 25 | import com.comcast.cmb.common.model.User; 26 | import com.comcast.cmb.common.persistence.PersistenceFactory; 27 | import com.comcast.cmb.common.util.CMBException; 28 | import com.comcast.cns.io.CNSTopicPopulator; 29 | import com.comcast.cns.model.CNSTopic; 30 | import com.comcast.cns.util.CNSErrorCodes; 31 | import com.comcast.cns.util.Util; 32 | 33 | /** 34 | * Create Topic 35 | * @author bwolf, jorge 36 | */ 37 | public class CNSCreateTopicAction extends CNSAction { 38 | 39 | private static Logger logger = Logger.getLogger(CNSCreateTopicAction.class); 40 | 41 | public CNSCreateTopicAction() { 42 | super("CreateTopic"); 43 | } 44 | 45 | /* 46 | * doCreateTopic creates the topic by calling the CNS Topic Persistence layer to create the queue, and if no Exceptions occur 47 | * then output the new topics data as XML to the HttpServletResponse response 48 | * @param user The user that requests this topic 49 | * @param asyncContext 50 | */ 51 | @Override 52 | public boolean doAction(User user, AsyncContext asyncContext) throws Exception { 53 | 54 | HttpServletRequest request = (HttpServletRequest)asyncContext.getRequest(); 55 | HttpServletResponse response = (HttpServletResponse)asyncContext.getResponse(); 56 | 57 | String displayName = request.getParameter("Name"); 58 | String name = request.getParameter("Name"); 59 | 60 | String userId = user.getUserId(); 61 | 62 | logger.debug("event=cns_topic_create name=" + name + " display_name=" + displayName + " user_id=" + userId); 63 | 64 | if (name == null || userId == null) { 65 | logger.error("event=cns_topic_create error_code=InvalidParameters name=" + name + " user_id=" + userId); 66 | throw new CMBException(CNSErrorCodes.CNS_InvalidParameter,"request parameter does not comply with the associated constraints."); 67 | } 68 | 69 | if (!Util.isValidTopicName(name)) { 70 | throw new CMBException(CNSErrorCodes.InvalidParameterValue, "Invalid parameter topic name."); 71 | } 72 | 73 | CNSTopic newTopic; 74 | newTopic = PersistenceFactory.getTopicPersistence().createTopic(name, displayName, userId); 75 | String topicArn = newTopic.getArn(); 76 | String out = CNSTopicPopulator.getCreateTopicResponse(topicArn); 77 | writeResponse(out, response); 78 | return true; 79 | } 80 | 81 | @Override 82 | public boolean isActionAllowed(User user, HttpServletRequest request, String service, CMBPolicy policy) throws Exception { 83 | return true; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/com/comcast/cns/controller/CNSDeleteTopicAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.controller; 17 | 18 | import javax.servlet.AsyncContext; 19 | import javax.servlet.http.HttpServletRequest; 20 | import javax.servlet.http.HttpServletResponse; 21 | 22 | import org.apache.log4j.Logger; 23 | 24 | import com.comcast.cmb.common.model.User; 25 | import com.comcast.cmb.common.persistence.PersistenceFactory; 26 | import com.comcast.cmb.common.util.CMBException; 27 | import com.comcast.cns.io.CNSTopicPopulator; 28 | import com.comcast.cns.util.CNSErrorCodes; 29 | 30 | /** 31 | * Delete topic 32 | * @author bwolf 33 | * 34 | */ 35 | public class CNSDeleteTopicAction extends CNSAction { 36 | 37 | private static Logger logger = Logger.getLogger(CNSDeleteTopicAction.class); 38 | 39 | public CNSDeleteTopicAction() { 40 | super("DeleteTopic"); 41 | } 42 | 43 | /** 44 | * Delete the topic with the topicArn in the request variable "TopicArn". Send the response out as XML to response. 45 | * @param user The user who owns the topic we are deleting 46 | * @param asyncContext 47 | */ 48 | @Override 49 | public boolean doAction(User user, AsyncContext asyncContext) throws Exception { 50 | 51 | HttpServletRequest request = (HttpServletRequest)asyncContext.getRequest(); 52 | HttpServletResponse response = (HttpServletResponse)asyncContext.getResponse(); 53 | 54 | String arn = request.getParameter("TopicArn"); 55 | String userId = user.getUserId(); 56 | logger.debug("event=cns_topic_delete arn=" + arn + " userid=" + userId); 57 | 58 | if ((arn == null) || (userId == null)) { 59 | logger.error("event=cns_topic_delete errro_code=InvalidParameters topic_arn=" + arn + " user_id=" + userId); 60 | throw new CMBException(CNSErrorCodes.CNS_InvalidParameter,"request parameter does not comply with the associated constraints."); 61 | } 62 | 63 | PersistenceFactory.getTopicPersistence().deleteTopic(arn); 64 | String out = CNSTopicPopulator.getDeleteTopicResponse(); 65 | writeResponse(out, response); 66 | return true; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/com/comcast/cns/controller/CNSGetSubscriptionAttributesAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.controller; 17 | 18 | import javax.servlet.AsyncContext; 19 | import javax.servlet.http.HttpServletRequest; 20 | import javax.servlet.http.HttpServletResponse; 21 | 22 | import org.apache.log4j.Logger; 23 | 24 | import com.comcast.cmb.common.model.User; 25 | import com.comcast.cmb.common.persistence.PersistenceFactory; 26 | import com.comcast.cmb.common.util.CMBException; 27 | import com.comcast.cns.io.CNSAttributePopulator; 28 | import com.comcast.cns.model.CNSSubscription; 29 | import com.comcast.cns.model.CNSSubscriptionAttributes; 30 | import com.comcast.cns.util.CNSErrorCodes; 31 | 32 | /** 33 | * Get Subsctiption Attributes 34 | * @author bwolf, jorge 35 | * 36 | */ 37 | public class CNSGetSubscriptionAttributesAction extends CNSAction { 38 | 39 | private static Logger logger = Logger.getLogger(CNSGetSubscriptionAttributesAction.class); 40 | 41 | public CNSGetSubscriptionAttributesAction() { 42 | super("GetSubscriptionAttributes"); 43 | } 44 | 45 | @Override 46 | public boolean doAction(User user, AsyncContext asyncContext) throws Exception { 47 | 48 | HttpServletRequest request = (HttpServletRequest)asyncContext.getRequest(); 49 | HttpServletResponse response = (HttpServletResponse)asyncContext.getResponse(); 50 | 51 | String userId = user.getUserId(); 52 | String subscriptionArn = request.getParameter("SubscriptionArn"); 53 | 54 | if ((userId == null) || (subscriptionArn == null) ) { 55 | logger.error("event=cns_get_subscription_attributes error_code=InvalidParameters subscription_arn=" + subscriptionArn + " user_id=" + userId); 56 | throw new CMBException(CNSErrorCodes.CNS_InvalidParameter,"missing parameters"); 57 | } 58 | 59 | CNSSubscriptionAttributes attr = PersistenceFactory.getCNSAttributePersistence().getSubscriptionAttributes(subscriptionArn); 60 | CNSSubscription sub = PersistenceFactory.getSubscriptionPersistence().getSubscription(subscriptionArn); 61 | String out = CNSAttributePopulator.getGetSubscriptionAttributesResponse(sub, attr); 62 | 63 | logger.debug("event=cns_get_subscription_attributes subscription_arn=" + subscriptionArn + " user_id=" + userId); 64 | 65 | writeResponse(out, response); 66 | return true; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/com/comcast/cns/controller/CNSGetTopicAttributesAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.controller; 17 | 18 | import javax.servlet.AsyncContext; 19 | import javax.servlet.http.HttpServletRequest; 20 | import javax.servlet.http.HttpServletResponse; 21 | 22 | import com.comcast.cmb.common.model.User; 23 | import com.comcast.cmb.common.util.CMBException; 24 | import com.comcast.cns.io.CNSAttributePopulator; 25 | import com.comcast.cns.model.CNSTopicAttributes; 26 | import com.comcast.cns.util.CNSErrorCodes; 27 | 28 | /** 29 | * Set Topic Attributes 30 | * @author bwolf, jorge 31 | * 32 | */ 33 | public class CNSGetTopicAttributesAction extends CNSAction { 34 | 35 | //private static Logger logger = Logger.getLogger(CNSGetTopicAttributesAction.class); 36 | 37 | public CNSGetTopicAttributesAction() { 38 | super("GetTopicAttributes"); 39 | } 40 | 41 | @Override 42 | public boolean doAction(User user, AsyncContext asyncContext) throws Exception { 43 | 44 | HttpServletRequest request = (HttpServletRequest)asyncContext.getRequest(); 45 | HttpServletResponse response = (HttpServletResponse)asyncContext.getResponse(); 46 | 47 | String topicArn = request.getParameter("TopicArn"); 48 | 49 | if (topicArn == null) { 50 | throw new CMBException(CNSErrorCodes.CNS_InvalidParameter, "Missing parameters TopicArn"); 51 | } 52 | 53 | //CNSTopicAttributes attr = PersistenceFactory.getCNSAttributePersistence().getTopicAttributes(topicArn); 54 | CNSTopicAttributes attr = CNSCache.getTopicAttributes(topicArn); 55 | 56 | if (attr == null) { 57 | throw new CMBException(CNSErrorCodes.InternalError, "Unknown topic with arn " + topicArn); 58 | } 59 | 60 | String out = CNSAttributePopulator.getGetTopicAttributesResponse(attr); 61 | 62 | writeResponse(out, response); 63 | 64 | return true; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/com/comcast/cns/controller/CNSListTopicsAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.controller; 17 | 18 | import java.util.List; 19 | 20 | import javax.servlet.AsyncContext; 21 | import javax.servlet.http.HttpServletRequest; 22 | import javax.servlet.http.HttpServletResponse; 23 | 24 | import org.apache.log4j.Logger; 25 | 26 | import com.comcast.cmb.common.model.CMBPolicy; 27 | import com.comcast.cmb.common.model.User; 28 | import com.comcast.cmb.common.persistence.PersistenceFactory; 29 | import com.comcast.cns.io.CNSTopicPopulator; 30 | import com.comcast.cns.model.CNSTopic; 31 | 32 | /** 33 | * List topics 34 | * @author bwolf 35 | * 36 | */ 37 | public class CNSListTopicsAction extends CNSAction { 38 | 39 | private static Logger logger = Logger.getLogger(CNSListTopicsAction.class); 40 | 41 | public CNSListTopicsAction() { 42 | super("ListTopics"); 43 | } 44 | 45 | /** 46 | * Get all the topics for this user and output them in XML to the response 47 | * @param user The user for which we are getting the list of topics 48 | * @param asyncContext 49 | */ 50 | @Override 51 | public boolean doAction(User user, AsyncContext asyncContext) throws Exception { 52 | 53 | HttpServletRequest request = (HttpServletRequest)asyncContext.getRequest(); 54 | HttpServletResponse response = (HttpServletResponse)asyncContext.getResponse(); 55 | 56 | String userId = user.getUserId(); 57 | String nextToken = null; 58 | 59 | if (request.getParameter("NextToken") != null) { 60 | nextToken = request.getParameter("NextToken"); 61 | logger.debug("event=cns_topic_list next_token=" + nextToken + " userid=" + userId); 62 | } else { 63 | logger.debug("event=cns_topic_list userid=" + userId); 64 | } 65 | 66 | List topics = PersistenceFactory.getTopicPersistence().listTopics(userId, nextToken); 67 | 68 | if (topics.size() >= 100) { 69 | 70 | nextToken = topics.get(99).getArn(); 71 | List nextTopics = PersistenceFactory.getTopicPersistence().listTopics(userId, nextToken); 72 | 73 | if (nextTopics.size() == 0) { 74 | nextToken = null; 75 | } else { 76 | logger.debug("event=cns_topic_listed event=next_token_created next_token=" + nextToken + " user_id=" + userId); 77 | } 78 | } 79 | 80 | String out = CNSTopicPopulator.getListTopicsResponse(topics,nextToken); 81 | writeResponse(out, response); 82 | return true; 83 | } 84 | 85 | @Override 86 | public boolean isActionAllowed(User user, HttpServletRequest request, String service, CMBPolicy policy) throws Exception { 87 | return true; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/com/comcast/cns/controller/CNSMonitor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.controller; 17 | 18 | import java.util.Map; 19 | import java.util.concurrent.atomic.AtomicLong; 20 | 21 | import com.comcast.cmb.common.controller.CMBControllerServlet; 22 | 23 | /** 24 | * The implementation of monitoring for CNS. 25 | * @author aseem, boris 26 | * Class is thread-safe 27 | */ 28 | 29 | public class CNSMonitor implements CNSMonitorMBean { 30 | 31 | private static final CNSMonitor Inst = new CNSMonitor(); 32 | 33 | private CNSMonitor() { 34 | } 35 | 36 | public static CNSMonitor getInstance() { 37 | return Inst; 38 | } 39 | 40 | @Override 41 | public Map getCallStats() { 42 | return CMBControllerServlet.callStats; 43 | } 44 | 45 | @Override 46 | public Map getCallFailureStats() { 47 | return CMBControllerServlet.callFailureStats; 48 | } 49 | 50 | @Override 51 | public void resetCallStats() { 52 | CMBControllerServlet.initStats(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/com/comcast/cns/controller/CNSMonitorMBean.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.controller; 17 | 18 | import java.util.Map; 19 | import java.util.concurrent.atomic.AtomicLong; 20 | 21 | /** 22 | * Interface for monitoring CNS 23 | * @author aseem 24 | * 25 | */ 26 | public interface CNSMonitorMBean { 27 | 28 | /** 29 | * 30 | * @return 31 | */ 32 | public Map getCallStats(); 33 | 34 | /** 35 | * 36 | * @return 37 | */ 38 | public Map getCallFailureStats(); 39 | 40 | /** 41 | * 42 | */ 43 | public void resetCallStats(); 44 | } 45 | -------------------------------------------------------------------------------- /src/com/comcast/cns/controller/CNSRemovePermissionAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.controller; 17 | 18 | import javax.servlet.AsyncContext; 19 | import javax.servlet.http.HttpServletRequest; 20 | import javax.servlet.http.HttpServletResponse; 21 | 22 | import org.apache.log4j.Logger; 23 | 24 | import com.comcast.cmb.common.model.CMBPolicy; 25 | import com.comcast.cmb.common.model.User; 26 | import com.comcast.cmb.common.persistence.PersistenceFactory; 27 | import com.comcast.cmb.common.util.CMBException; 28 | import com.comcast.cmb.common.util.CMBProperties; 29 | import com.comcast.cns.io.CNSAttributePopulator; 30 | import com.comcast.cns.model.CNSTopic; 31 | import com.comcast.cns.model.CNSTopicAttributes; 32 | import com.comcast.cns.util.CNSErrorCodes; 33 | import com.comcast.cqs.util.CQSConstants; 34 | import com.comcast.cqs.util.CQSErrorCodes; 35 | import com.comcast.cqs.util.Util; 36 | 37 | /** 38 | * Remove permission 39 | * @author bwolf 40 | * 41 | */ 42 | public class CNSRemovePermissionAction extends CNSAction { 43 | 44 | private static Logger logger = Logger.getLogger(CNSAddPermissionAction.class); 45 | 46 | public CNSRemovePermissionAction() { 47 | super("RemovePermission"); 48 | } 49 | 50 | @Override 51 | public boolean doAction(User user, AsyncContext asyncContext) throws Exception { 52 | 53 | HttpServletRequest request = (HttpServletRequest)asyncContext.getRequest(); 54 | HttpServletResponse response = (HttpServletResponse)asyncContext.getResponse(); 55 | 56 | String topicArn = request.getParameter("TopicArn"); 57 | 58 | if ((topicArn == null) ) { 59 | logger.error("event=cns_add_permission error_code=missing_parameter_topic_arn"); 60 | throw new CMBException(CNSErrorCodes.CNS_InvalidParameter,"Missing parameter TopicArn"); 61 | } 62 | 63 | CNSTopic topic = PersistenceFactory.getTopicPersistence().getTopic(topicArn); 64 | 65 | if (topic == null) { 66 | logger.error("event=cns_add_permission error_code=invalid_parameter_topic_arn topic_arn=" + topicArn); 67 | throw new CMBException(CNSErrorCodes.CNS_NotFound,"Resource not found."); 68 | } 69 | 70 | String label = request.getParameter(CQSConstants.LABEL); 71 | 72 | if (!Util.isValidId(label)) { 73 | 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."); 74 | } 75 | 76 | CMBPolicy policy = null; 77 | 78 | CNSTopicAttributes attributes = CNSCache.getTopicAttributes(topicArn); 79 | 80 | // validate policy string 81 | 82 | if (attributes.getPolicy() != null) { 83 | 84 | policy = new CMBPolicy(attributes.getPolicy()); 85 | 86 | if (policy.removeStatement(label)) { 87 | attributes.setPolicy(policy.toString()); 88 | PersistenceFactory.getCNSAttributePersistence().setTopicAttributes(attributes, topicArn); 89 | } 90 | } 91 | 92 | String out = CNSAttributePopulator.getRemovePermissionResponse(); 93 | writeResponse(out, response); 94 | return true; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/com/comcast/cns/controller/CNSUnsubscribeAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.controller; 17 | 18 | import javax.servlet.AsyncContext; 19 | import javax.servlet.http.HttpServletRequest; 20 | import javax.servlet.http.HttpServletResponse; 21 | 22 | import org.apache.log4j.Logger; 23 | 24 | import com.comcast.cmb.common.model.User; 25 | import com.comcast.cmb.common.persistence.PersistenceFactory; 26 | import com.comcast.cmb.common.util.CMBException; 27 | import com.comcast.cns.io.CNSSubscriptionPopulator; 28 | import com.comcast.cns.util.CNSErrorCodes; 29 | import com.comcast.cns.util.Util; 30 | 31 | /** 32 | * Unsubscribe action 33 | * @author bwolf 34 | * 35 | */ 36 | public class CNSUnsubscribeAction extends CNSAction { 37 | 38 | private static Logger logger = Logger.getLogger(CNSUnsubscribeAction.class); 39 | 40 | public CNSUnsubscribeAction() { 41 | super("Unsubscribe"); 42 | } 43 | 44 | /** 45 | * The method simply gets the information from the user and request to call doUnsubscribe on the persistence layer, then we take 46 | * response and generate an XML response and put it in the parameter response 47 | * @param user the user for whom we are unsubscribing. 48 | * @param asyncContext 49 | */ 50 | @Override 51 | public boolean doAction(User user, AsyncContext asyncContext) throws Exception { 52 | 53 | HttpServletRequest request = (HttpServletRequest)asyncContext.getRequest(); 54 | HttpServletResponse response = (HttpServletResponse)asyncContext.getResponse(); 55 | 56 | String arn = request.getParameter("SubscriptionArn"); 57 | String userId = user.getUserId(); 58 | 59 | if ((arn == null) || (userId == null)) { 60 | logger.error("event=cns_unsubscribe error_code=InvalidParameters arn=" + arn + " user_id=" + userId); 61 | throw new CMBException(CNSErrorCodes.CNS_InvalidParameter,"request parameter does not comply with the associated constraints."); 62 | } 63 | 64 | if (!Util.isValidSubscriptionArn(arn)) { 65 | logger.error("event=cns_unsubscribe error_code=InvalidParameters arn=" + arn + " user_id=" + userId); 66 | throw new CMBException(CNSErrorCodes.CNS_InvalidParameter,"request parameter does not comply with the associated constraints."); 67 | } 68 | 69 | PersistenceFactory.getSubscriptionPersistence().unsubscribe(arn); 70 | String out = CNSSubscriptionPopulator.getUnsubscribeResponse(); 71 | writeResponse(out, response); 72 | return true; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/com/comcast/cns/io/AbstractEndpointPublisher.java: -------------------------------------------------------------------------------- 1 | package com.comcast.cns.io; 2 | 3 | import java.util.Map; 4 | 5 | import com.comcast.cmb.common.model.User; 6 | import com.comcast.cns.model.CNSMessage; 7 | import com.comcast.cqs.model.CQSMessageAttribute; 8 | 9 | public abstract class AbstractEndpointPublisher implements IEndpointPublisher { 10 | 11 | protected String endpoint; 12 | protected CNSMessage message; 13 | protected User user; 14 | protected String subject; 15 | protected Boolean rawMessageDelivery = false; 16 | protected String messageType; 17 | protected String messageId; 18 | protected String topicArn; 19 | protected String subscriptionArn; 20 | protected Map messageAttributes; 21 | 22 | @Override 23 | public Map getMessageAttributes() { 24 | return messageAttributes; 25 | } 26 | 27 | @Override 28 | public void setMessageAttributes( 29 | Map messageAttributes) { 30 | this.messageAttributes = messageAttributes; 31 | } 32 | 33 | @Override 34 | public void setEndpoint(String endpoint) { 35 | this.endpoint = endpoint; 36 | } 37 | 38 | @Override 39 | public void setMessage(CNSMessage message) { 40 | this.message = message; 41 | } 42 | 43 | @Override 44 | public String getEndpoint() { 45 | return endpoint; 46 | } 47 | 48 | @Override 49 | public CNSMessage getMessage() { 50 | return message; 51 | } 52 | 53 | @Override 54 | public void setUser(User user) { 55 | this.user = user; 56 | } 57 | 58 | @Override 59 | public User getUser() { 60 | return user; 61 | } 62 | 63 | @Override 64 | public void setSubject(String subject) { 65 | this.subject = subject; 66 | } 67 | 68 | @Override 69 | public String getSubject() { 70 | return this.subject; 71 | } 72 | @Override 73 | public void setRawMessageDelivery(Boolean rawMessageDelivery){ 74 | this.rawMessageDelivery = rawMessageDelivery; 75 | } 76 | 77 | @Override 78 | public Boolean getRawMessageDelivery(){ 79 | return this.rawMessageDelivery; 80 | } 81 | 82 | @Override 83 | public String getMessageType() { 84 | return messageType; 85 | } 86 | 87 | @Override 88 | public void setMessageType(String messageType) { 89 | this.messageType = messageType; 90 | } 91 | 92 | @Override 93 | public String getMessageId() { 94 | return messageId; 95 | } 96 | 97 | @Override 98 | public void setMessageId(String messageId) { 99 | this.messageId = messageId; 100 | } 101 | 102 | @Override 103 | public String getTopicArn() { 104 | return topicArn; 105 | } 106 | 107 | @Override 108 | public void setTopicArn(String topicArn) { 109 | this.topicArn = topicArn; 110 | } 111 | 112 | @Override 113 | public String getSubscriptionArn() { 114 | return subscriptionArn; 115 | } 116 | 117 | @Override 118 | public void setSubscriptionArn(String subscriptionArn) { 119 | this.subscriptionArn = subscriptionArn; 120 | } 121 | 122 | @Override 123 | abstract public void send() throws Exception; 124 | } 125 | -------------------------------------------------------------------------------- /src/com/comcast/cns/io/CNSPopulator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.io; 17 | 18 | import com.comcast.cmb.common.model.ReceiptModule; 19 | 20 | /** 21 | * Class to generate API response for receipt id meta-data 22 | * @author jorge, bwolf 23 | * 24 | */ 25 | public class CNSPopulator { 26 | 27 | public static String getResponseMetadata() { 28 | return "\t" + ReceiptModule.getReceiptId() + "\n"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/com/comcast/cns/io/CNSTopicPopulator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.io; 17 | 18 | import java.util.List; 19 | 20 | import com.comcast.cns.model.CNSTopic; 21 | 22 | /** 23 | * API response generator for Topics 24 | * @author jorge 25 | * 26 | */ 27 | public class CNSTopicPopulator { 28 | 29 | public static String getCreateTopicResponse(String arn) { 30 | StringBuffer out = new StringBuffer("\n"); 31 | out.append("\t\n"); 32 | out.append("\t\t").append(arn).append("\n"); 33 | out.append("\t\n"); 34 | out.append("\t").append(CNSPopulator.getResponseMetadata()).append("\n"); 35 | out.append("\n"); 36 | return out.toString(); 37 | } 38 | 39 | public static String getDeleteTopicResponse() { 40 | return "\n\n" + CNSPopulator.getResponseMetadata() + "\n\n"; 41 | } 42 | 43 | public static String getListTopicsResponse(List topics, String nextToken) { 44 | 45 | StringBuffer out = new StringBuffer("\n"); 46 | out.append("\t\n"); 47 | out.append("\t\t\n"); 48 | 49 | for (CNSTopic topic:topics) { 50 | out.append("\t\t\t"+topic.getArn()+"\n"); 51 | } 52 | 53 | out.append("\t\t\n"); 54 | 55 | if (nextToken != null) { 56 | out.append("\t\t" + nextToken + "\n"); 57 | } 58 | 59 | out.append("\t\n"); 60 | out.append("\t").append(CNSPopulator.getResponseMetadata()).append("\n"); 61 | out.append("\n"); 62 | 63 | return out.toString(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/com/comcast/cns/io/CNSWorkerStatsPopulator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.io; 17 | 18 | import java.util.List; 19 | 20 | import com.comcast.cns.model.CNSWorkerStats; 21 | 22 | public class CNSWorkerStatsPopulator { 23 | 24 | public static String getGetWorkerStatsResponse(List statsList) { 25 | 26 | String out = ""; 27 | out += "\n"; 28 | out += "\t\n"; 29 | 30 | for (CNSWorkerStats stats : statsList) { 31 | out += "\t\t\n"; 32 | out += "\t\t\t"+stats.getIpAddress()+"\n"; 33 | out += "\t\t\t"+stats.getJmxPort()+"\n"; 34 | out += "\t\t\t"+stats.getMode()+"\n"; 35 | out += "\t\t\t"+stats.getDataCenter()+"\n"; 36 | out += "\t\t\t"+stats.getNumPublishedMessages()+"\n"; 37 | out += "\t\t\t"+stats.getProducerTimestamp()+"\n"; 38 | out += "\t\t\t"+stats.isProducerActive()+"\n"; 39 | out += "\t\t\t"+stats.getConsumerTimestamp()+"\n"; 40 | out += "\t\t\t"+stats.isConsumerActive()+"\n"; 41 | out += "\t\t\t"+stats.getDeliveryQueueSize()+"\n"; 42 | out += "\t\t\t"+stats.getRedeliveryQueueSize()+"\n"; 43 | out += "\t\t\t"+stats.isConsumerOverloaded()+"\n"; 44 | out += "\t\t\t"+stats.isCqsServiceAvailable()+"\n"; 45 | out += "\t\t\t"+stats.getNumPooledHttpConnections()+"\n"; 46 | 47 | if (stats.getErrorCountForEndpoints() != null && stats.getErrorCountForEndpoints().size() > 0) { 48 | 49 | out += "\t\t\t"; 50 | 51 | for (String endpoint : stats.getErrorCountForEndpoints().keySet()) { 52 | out += "\t\t\t\t"; 53 | } 54 | 55 | out += "\t\t\t"; 56 | } 57 | 58 | out += "\t\t\n"; 59 | } 60 | 61 | out += "\t\n"; 62 | out += ""; 63 | 64 | return out; 65 | } 66 | 67 | public static String getGetManageWorkerResponse() { 68 | 69 | String res = ""; 70 | 71 | res += "\n"; 72 | res += "\t" + CNSPopulator.getResponseMetadata() + "\n"; 73 | res += ""; 74 | 75 | return res; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/com/comcast/cns/io/CommunicationUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.io; 17 | 18 | import java.util.Map; 19 | 20 | import com.comcast.cmb.common.model.User; 21 | import com.comcast.cns.model.CNSMessage; 22 | import com.comcast.cns.model.CNSSubscription; 23 | import com.comcast.cns.model.CNSMessage.CNSMessageType; 24 | 25 | /** 26 | * Utility functions for 27 | * @author aseem, jorge, bwolf 28 | * 29 | */ 30 | public class CommunicationUtils { 31 | 32 | /** 33 | * addParam adds a parameter with name name, and value val to the set of parameters 34 | * params 35 | * @param params, the list of parameters 36 | * @param name, the name of the parameter to add 37 | * @param val, the value of the parameter to add 38 | */ 39 | public static void addParam(Map params, String name, String val) { 40 | String[] paramVals = new String[1]; 41 | paramVals[0] = val; 42 | params.put(name, paramVals); 43 | } 44 | 45 | /* 46 | * Send a message using the appropriate method for the given protocol to the endpoint in endPoint 47 | * @param user, the user that is sending the message 48 | * @param protocol, the protocol for the 49 | */ 50 | public static String sendMessage(User user, CNSSubscription.CnsSubscriptionProtocol protocol, String endPoint, CNSMessage message, String messageId, String topArn, String subArn, boolean rawDelivery) throws Exception { 51 | 52 | IEndpointPublisher publisher = EndpointPublisherFactory.getPublisherInstance(protocol); 53 | publisher.setUser(user); 54 | publisher.setEndpoint(endPoint); 55 | publisher.setMessage(message); 56 | publisher.setMessageType(CNSMessageType.SubscriptionConfirmation.toString()); 57 | publisher.setMessageId(messageId); 58 | publisher.setTopicArn(topArn); 59 | publisher.setSubscriptionArn(subArn); 60 | publisher.setRawMessageDelivery(rawDelivery); 61 | 62 | if (protocol == CNSSubscription.CnsSubscriptionProtocol.email || protocol == CNSSubscription.CnsSubscriptionProtocol.email_json) { 63 | publisher.setSubject("CMB Notification Message"); 64 | } 65 | 66 | publisher.send(); 67 | 68 | return "success"; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/com/comcast/cns/io/EmailEndpointPublisher.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.io; 17 | 18 | import org.apache.log4j.Logger; 19 | 20 | import com.comcast.cmb.common.util.CMBProperties; 21 | import com.comcast.cns.model.CNSMessage.CNSMessageStructure; 22 | import com.comcast.cns.model.CNSMessage.CNSMessageType; 23 | import com.comcast.cns.model.CNSSubscription.CnsSubscriptionProtocol; 24 | import com.comcast.cns.util.MailWrapper; 25 | 26 | /** 27 | * Endpoint publisher for email endpoints 28 | * @author bwolf, jorge 29 | * 30 | */ 31 | public class EmailEndpointPublisher extends AbstractEndpointPublisher { 32 | protected static Logger logger = Logger.getLogger(EmailEndpointPublisher.class); 33 | 34 | @Override 35 | public void send() throws Exception { 36 | 37 | if (!CMBProperties.getInstance().getSmtpEnabled()) { 38 | logger.warn("event=send_email error_code=smtp_disabled endpoint=" + endpoint); 39 | return; 40 | } 41 | 42 | String msg = null; 43 | 44 | if (message.getMessageStructure() == CNSMessageStructure.json) { 45 | msg = message.getProtocolSpecificMessage(CnsSubscriptionProtocol.email); 46 | } else { 47 | msg = message.getMessage(); 48 | } 49 | 50 | if (!rawMessageDelivery && message.getMessageType() == CNSMessageType.Notification) { 51 | msg = com.comcast.cns.util.Util.generateMessageJson(message, CnsSubscriptionProtocol.email); 52 | } 53 | 54 | logger.debug("event=send_email endpoint=" + endpoint + " subject=\"" + subject + " message=\"" + msg + "\""); 55 | 56 | MailWrapper mailAgent = new MailWrapper(); 57 | mailAgent.postMail(new String [] { endpoint }, subject, msg, CMBProperties.getInstance().getSmtpReplyAddress()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/com/comcast/cns/io/EmailJsonEndpointPublisher.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.io; 17 | 18 | import com.comcast.cmb.common.util.CMBProperties; 19 | import com.comcast.cns.model.CNSMessage.CNSMessageStructure; 20 | import com.comcast.cns.model.CNSMessage.CNSMessageType; 21 | import com.comcast.cns.model.CNSSubscription.CnsSubscriptionProtocol; 22 | import com.comcast.cns.util.MailWrapper; 23 | 24 | /** 25 | * Endpoint publisher for emails in json 26 | * @author bwolf, jorge 27 | * 28 | */ 29 | public class EmailJsonEndpointPublisher extends EmailEndpointPublisher { 30 | 31 | @Override 32 | public void send() throws Exception { 33 | 34 | if (!CMBProperties.getInstance().getSmtpEnabled()) { 35 | logger.warn("event=send_email error_code=smtp_disabled endpoint=" + endpoint); 36 | return; 37 | } 38 | 39 | MailWrapper mailAgent = new MailWrapper(); 40 | 41 | String msg = null; 42 | 43 | if (message.getMessageStructure() == CNSMessageStructure.json) { 44 | msg = message.getProtocolSpecificMessage(CnsSubscriptionProtocol.email_json); 45 | } else { 46 | msg = message.getMessage(); 47 | } 48 | 49 | if (!rawMessageDelivery && message.getMessageType() == CNSMessageType.Notification) { 50 | msg = com.comcast.cns.util.Util.generateMessageJson(message, CnsSubscriptionProtocol.email_json); 51 | } 52 | 53 | logger.debug("event=send_email endpoint=" + endpoint + " subject=\"" + subject + " message=\"" + msg + "\""); 54 | 55 | mailAgent.postMail(new String [] { endpoint }, subject, msg, CMBProperties.getInstance().getSmtpReplyAddress()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/com/comcast/cns/io/EndpointAsyncPublisherWrapper.java: -------------------------------------------------------------------------------- 1 | /** Copyright 2012 Comcast Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.comcast.cns.io; 16 | 17 | import java.util.concurrent.ScheduledThreadPoolExecutor; 18 | 19 | import com.comcast.cmb.common.model.User; 20 | import com.comcast.cmb.common.util.CMBProperties; 21 | import com.comcast.cns.model.CNSMessage; 22 | 23 | /** 24 | * Class wraps synchronous endpoint publishers in asynchronous framework 25 | * @author bwolf 26 | * 27 | */ 28 | public class EndpointAsyncPublisherWrapper extends AbstractEndpointPublisher{ 29 | 30 | private final IPublisherCallback callback; 31 | private final IEndpointPublisher publisher; 32 | 33 | private static volatile ScheduledThreadPoolExecutor deliveryHandlers = new ScheduledThreadPoolExecutor(CMBProperties.getInstance().getCNSNumPublisherDeliveryHandlers()); 34 | 35 | public EndpointAsyncPublisherWrapper(IPublisherCallback callback, IEndpointPublisher publisher) { 36 | this.callback = callback; 37 | this.publisher = publisher; 38 | } 39 | 40 | @Override 41 | public void send() throws Exception { 42 | 43 | deliveryHandlers.submit(new Runnable() { 44 | public void run() { 45 | try { 46 | publisher.send(); 47 | callback.onSuccess(); 48 | } catch (Exception ex) { 49 | callback.onFailure(0); 50 | } 51 | } 52 | }); 53 | } 54 | 55 | @Override 56 | public void setEndpoint(String endpoint) { 57 | publisher.setEndpoint(endpoint); 58 | } 59 | 60 | @Override 61 | public String getEndpoint() { 62 | return publisher.getEndpoint(); 63 | } 64 | 65 | @Override 66 | public void setMessage(CNSMessage message) { 67 | publisher.setMessage(message); 68 | } 69 | 70 | @Override 71 | public CNSMessage getMessage() { 72 | return publisher.getMessage(); 73 | } 74 | 75 | @Override 76 | public void setUser(User user) { 77 | publisher.setUser(user); 78 | } 79 | 80 | @Override 81 | public User getUser() { 82 | return publisher.getUser(); 83 | } 84 | 85 | @Override 86 | public void setSubject(String subject) { 87 | publisher.setSubject(subject); 88 | } 89 | 90 | @Override 91 | public String getSubject() { 92 | return publisher.getSubject(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/com/comcast/cns/io/EndpointPublisherFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.io; 17 | 18 | import org.apache.log4j.Logger; 19 | 20 | import com.comcast.cns.model.CNSSubscription; 21 | 22 | /** 23 | * Factory to get appt publisher given protocol 24 | * @author aseem, jorge, bwolf 25 | * 26 | */ 27 | public class EndpointPublisherFactory { 28 | 29 | protected static Logger logger = Logger.getLogger(EndpointPublisherFactory.class); 30 | 31 | static public IEndpointPublisher getPublisherInstance(CNSSubscription.CnsSubscriptionProtocol protocol) { 32 | 33 | switch (protocol) { 34 | case https: 35 | case http: 36 | return new HTTPEndpointSyncPublisher(); 37 | case email: 38 | return new EmailEndpointPublisher(); 39 | case email_json: 40 | return new EmailJsonEndpointPublisher(); 41 | case sqs: 42 | return new SQSEndpointPublisher(); 43 | case cqs: 44 | return new CQSEndpointPublisher(); 45 | case redis: 46 | return new RedisPubSubEndpointPublisher(); 47 | } 48 | 49 | return null; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/com/comcast/cns/io/IEndpointPublisher.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.io; 17 | 18 | import java.util.Map; 19 | 20 | import com.comcast.cmb.common.model.User; 21 | import com.comcast.cns.model.CNSMessage; 22 | import com.comcast.cqs.model.CQSMessageAttribute; 23 | 24 | /** 25 | * The interface is for sending messages to a particular endpoint, first set the endpoint, and the message, and optionally the 26 | * subject and user, and send the message to the endpoint using send(). 27 | * 28 | * @author aseem, jorge, bwolf 29 | */ 30 | public interface IEndpointPublisher { 31 | 32 | /** 33 | * Set the endpoitn we are going to send the message to. 34 | * @param endpoint 35 | */ 36 | public void setEndpoint(String endpoint); 37 | 38 | /** 39 | * Get the enpoint we are goint to send the message to. 40 | * @return the enpoint we set 41 | */ 42 | public String getEndpoint(); 43 | 44 | /** 45 | * Set the message we are going to send to the endpoint 46 | * @param message 47 | */ 48 | public void setMessage(CNSMessage message); 49 | 50 | public CNSMessage getMessage(); 51 | 52 | /** 53 | * The user is only used for CQS to send the message to the queue 54 | * In which case user is the publisher 55 | * @param user 56 | */ 57 | public void setUser(User user); 58 | 59 | public User getUser(); 60 | 61 | /** 62 | * The subject is only used for email 63 | * @param subject 64 | */ 65 | public void setSubject(String subject); 66 | 67 | public String getSubject(); 68 | 69 | 70 | /** 71 | * Sends the message to the affiliated endpoint 72 | * Issues with sending the message will lead to an exception 73 | * The response can be retrieved in the callback. 74 | */ 75 | public void send() throws Exception; 76 | 77 | /** 78 | * Setter and getter of rawMessageDelivery 79 | */ 80 | public void setRawMessageDelivery(Boolean rawMessageDelivery); 81 | public Boolean getRawMessageDelivery(); 82 | 83 | public String getMessageType(); 84 | public void setMessageType(String messageType); 85 | 86 | public String getMessageId(); 87 | public void setMessageId(String messageId); 88 | 89 | public String getTopicArn(); 90 | public void setTopicArn(String topicArn); 91 | 92 | public String getSubscriptionArn(); 93 | public void setSubscriptionArn(String subscriptionArn); 94 | 95 | public Map getMessageAttributes(); 96 | public void setMessageAttributes(Map messageAttributes); 97 | } 98 | -------------------------------------------------------------------------------- /src/com/comcast/cns/io/IPublisherCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.io; 17 | 18 | /** 19 | * Callback interface for an asynchronous cns endpoint publisher. 20 | * 21 | * @author bwolf 22 | */ 23 | public interface IPublisherCallback { 24 | 25 | /** 26 | * On success callback 27 | * @throws Exception 28 | */ 29 | public void onSuccess(); 30 | 31 | /** 32 | * On failure callback 33 | * @param status 34 | * @throws Exception 35 | */ 36 | public void onFailure(int status); 37 | 38 | /** 39 | * On expire callback 40 | * @throws Exception 41 | */ 42 | public void onExpire(); 43 | } 44 | -------------------------------------------------------------------------------- /src/com/comcast/cns/io/RedisPubSubEndpointPublisher.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.io; 17 | 18 | import org.apache.log4j.Logger; 19 | 20 | 21 | import com.comcast.cmb.common.util.CMBProperties; 22 | import java.util.regex.*; 23 | import java.util.Map; 24 | import redis.clients.jedis.Jedis; 25 | import redis.clients.jedis.JedisPool; 26 | import redis.clients.jedis.JedisPoolConfig; 27 | 28 | 29 | import java.util.concurrent.ConcurrentHashMap; 30 | 31 | 32 | /** 33 | * Endpoint publisher for Redis pub/sub endpoints 34 | * @author whatha200 35 | * 36 | */ 37 | public class RedisPubSubEndpointPublisher extends AbstractEndpointPublisher { 38 | protected static Logger logger = Logger.getLogger(RedisPubSubEndpointPublisher.class); 39 | private static Map jedisPoolMap = new ConcurrentHashMap(); 40 | protected static int timeoutMS = CMBProperties.getInstance().getRedisPubSubEndpointConnectionTimeoutMS(); 41 | 42 | @Override 43 | public void send() throws Exception { 44 | if (jedisPoolMap.containsKey(endpoint)) { 45 | long startTime = System.currentTimeMillis(); 46 | JedisPool pool = jedisPoolMap.get(endpoint); 47 | Jedis connection = pool.getResource(); 48 | String []tokens = endpoint.split("/"); 49 | String channel = tokens[tokens.length-1]; 50 | long numClients = connection.publish(channel, message.getMessage()); 51 | long timeTaken = System.currentTimeMillis() - startTime; 52 | pool.returnResource(connection); 53 | logger.debug("event=send_redis endpoint="+ endpoint + " num_clients=" + numClients + " conn=reuse resp_ms=" + timeTaken); 54 | return; 55 | } else { 56 | long startTime = System.currentTimeMillis(); 57 | Matcher m = com.comcast.cns.util.Util.redisPubSubPattern.matcher(endpoint); 58 | if (m.matches()) { 59 | String password = m.group(2); 60 | String host = m.group(3); 61 | String port = m.group(4); 62 | String channel = m.group(5); 63 | JedisPool pool = new JedisPool( new JedisPoolConfig(), host, Integer.parseInt(port), timeoutMS, password); 64 | Jedis connection = pool.getResource(); 65 | long numClients = connection.publish(channel, message.getMessage()); 66 | long timeTaken = System.currentTimeMillis() - startTime; 67 | logger.debug("event=send_redis endpoint=" + endpoint + " num_clients=" + numClients + " conn=new resp_ms=" + timeTaken); 68 | pool.returnResource(connection); 69 | jedisPoolMap.put(endpoint, pool); 70 | return; 71 | } else { 72 | logger.error("event=send_redis error=badEndpoint endpoint="+endpoint + " topicArn=" + message.getTopicArn()); 73 | return; 74 | } 75 | } 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/com/comcast/cns/model/CNSModelConstructionException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.model; 17 | 18 | /** 19 | * Exception during model construction 20 | * @author jorge, bwolf 21 | * 22 | */ 23 | public class CNSModelConstructionException extends Exception{ 24 | 25 | private static final long serialVersionUID = 1L; 26 | private final String errormessage; 27 | 28 | public CNSModelConstructionException(String errormessage) { 29 | this.errormessage = errormessage; 30 | } 31 | 32 | public String getErrormessage() { 33 | return errormessage; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/com/comcast/cns/model/CNSSubscriptionAttributes.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.model; 17 | 18 | /** 19 | * represents Subscription Attributes 20 | * @author bwolf, jorge 21 | * 22 | * Class is not thread-safe. Caller must ensure thread-safety 23 | */ 24 | public class CNSSubscriptionAttributes { 25 | 26 | private CNSSubscriptionDeliveryPolicy effectiveDeliveryPolicy; 27 | 28 | private CNSSubscriptionDeliveryPolicy deliveryPolicy; 29 | 30 | 31 | 32 | private String userId; 33 | 34 | private boolean confirmationWasAuthenticated; 35 | 36 | private String topicArn; 37 | 38 | private String subscriptionArn; 39 | 40 | public CNSSubscriptionAttributes() { 41 | } 42 | 43 | public CNSSubscriptionAttributes(String topicArn, String subscriptionArn, String userId) { 44 | 45 | this.topicArn = topicArn; 46 | this.subscriptionArn = subscriptionArn; 47 | this.userId = userId; 48 | this.deliveryPolicy = null;//new CNSSubscriptionDeliveryPolicy(); 49 | } 50 | 51 | public CNSSubscriptionDeliveryPolicy getEffectiveDeliveryPolicy() { 52 | return effectiveDeliveryPolicy; 53 | } 54 | 55 | public void setEffectiveDeliveryPolicy(CNSSubscriptionDeliveryPolicy effectiveDeliveryPolicy) { 56 | this.effectiveDeliveryPolicy = effectiveDeliveryPolicy; 57 | } 58 | 59 | public CNSSubscriptionDeliveryPolicy getDeliveryPolicy() { 60 | return deliveryPolicy; 61 | } 62 | 63 | public void setDeliveryPolicy(CNSSubscriptionDeliveryPolicy deliveryPolicy) { 64 | this.deliveryPolicy = deliveryPolicy; 65 | } 66 | 67 | public String getUserId() { 68 | return userId; 69 | } 70 | 71 | public void setUserId(String userId) { 72 | this.userId = userId; 73 | } 74 | 75 | public boolean isConfirmationWasAuthenticated() { 76 | return confirmationWasAuthenticated; 77 | } 78 | 79 | public void setConfirmationWasAuthenticated(boolean confirmationWasAuthenticated) { 80 | this.confirmationWasAuthenticated = confirmationWasAuthenticated; 81 | } 82 | 83 | public String getTopicArn() { 84 | return topicArn; 85 | } 86 | 87 | public void setTopicArn(String topicArn) { 88 | this.topicArn = topicArn; 89 | } 90 | 91 | public String getSubscriptionArn() { 92 | return subscriptionArn; 93 | } 94 | 95 | public void setSubscriptionArn(String subscriptionArn) { 96 | this.subscriptionArn = subscriptionArn; 97 | } 98 | 99 | @Override 100 | public String toString() { 101 | return "user_id=" + userId + " topci_arn=" + topicArn + " subscription_arn=" + subscriptionArn + 102 | " effective_delivery_policy=" + effectiveDeliveryPolicy + 103 | " delivery_policy=" + deliveryPolicy + 104 | " confirmation_was_authenticated=" + confirmationWasAuthenticated; 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/com/comcast/cns/model/CNSTopic.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.model; 17 | 18 | import com.comcast.cmb.common.util.CMBErrorCodes; 19 | import com.comcast.cmb.common.util.CMBException; 20 | import com.comcast.cmb.common.util.Util; 21 | 22 | /** 23 | * Represents a Topic 24 | * @author bwolf, jorge 25 | * 26 | * Class is not thread-safe. Caller must ensure thread-safety 27 | */ 28 | public class CNSTopic { 29 | 30 | private String arn; 31 | private String name; 32 | private String displayName; 33 | private String userId; 34 | //private CNSTopicAttributes attributes; 35 | 36 | public CNSTopic(String arn, String name, String displayName, String userId) { 37 | this.arn = arn; 38 | this.name = name; 39 | this.displayName = displayName; 40 | this.userId = userId; 41 | } 42 | 43 | public String getUserId() { 44 | return userId; 45 | } 46 | 47 | public void setUserId(String userId) { 48 | this.userId = userId; 49 | } 50 | 51 | public String getArn() { 52 | return arn; 53 | } 54 | 55 | public void setArn(String arn) { 56 | this.arn = arn; 57 | } 58 | 59 | public String getName() { 60 | return name; 61 | } 62 | 63 | public void setName(String name) { 64 | this.name = name; 65 | } 66 | 67 | public String getDisplayName() { 68 | return displayName; 69 | } 70 | 71 | public void setDisplayName(String displayName) { 72 | this.displayName = displayName; 73 | } 74 | 75 | public void checkIsValid() throws CMBException { 76 | 77 | if (arn == null) { 78 | throw new CMBException(CMBErrorCodes.InternalError, "Must set arn for subscription"); 79 | } 80 | 81 | if (!com.comcast.cns.util.Util.isValidTopicArn(arn)) { 82 | throw new CMBException(CMBErrorCodes.InternalError, "Invalid topic arn"); 83 | } 84 | 85 | if (name == null) { 86 | throw new CMBException(CMBErrorCodes.InternalError, "Must set name for subscription"); 87 | } 88 | 89 | if (userId == null) { 90 | throw new CMBException(CMBErrorCodes.InternalError, "Must set user id for subscription"); 91 | } 92 | } 93 | @Override 94 | public String toString() { 95 | return "arn=" + getArn() + " name=" + getName() + " display_name=" + getDisplayName() + " user_id=" + getUserId(); 96 | } 97 | @Override 98 | public boolean equals(Object o) { 99 | 100 | if (!(o instanceof CNSTopic)) { 101 | return false; 102 | } 103 | 104 | CNSTopic t = (CNSTopic)o; 105 | 106 | if (Util.isEqual(getArn(), t.getArn()) && 107 | Util.isEqual(getName(), t.getName()) && 108 | Util.isEqual(getDisplayName(), t.getDisplayName()) && 109 | Util.isEqual(getUserId(), t.getUserId())) { 110 | return true; 111 | } 112 | 113 | return false; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/com/comcast/cns/persistence/ICNSAttributesPersistence.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.persistence; 17 | 18 | import com.comcast.cns.model.CNSSubscriptionAttributes; 19 | import com.comcast.cns.model.CNSTopicAttributes; 20 | 21 | /** 22 | * Interface representing persistence functionality for topic attributes 23 | * @author tina, bwolf 24 | * 25 | */ 26 | public interface ICNSAttributesPersistence { 27 | 28 | /** 29 | * setTopicAttributes 30 | * @param attributeName 31 | * @param attributeValue 32 | * @param topicArn 33 | * @return 34 | * @throws Exception 35 | */ 36 | public void setTopicAttributes(CNSTopicAttributes topicAttributes, String topicArn) throws Exception; 37 | 38 | /** 39 | * getTopicAttributes 40 | * @param topicArn 41 | * @return CNSTopicAttributes 42 | * @throws Exception 43 | */ 44 | public CNSTopicAttributes getTopicAttributes(String topicArn) throws Exception; 45 | 46 | 47 | /** 48 | * setSubscriptionAttributes 49 | * @param attributeName 50 | * @param attributeValue 51 | * @param subscriptionArn 52 | * @return 53 | * @throws Exception 54 | */ 55 | public void setSubscriptionAttributes(CNSSubscriptionAttributes subscriptionAtributes, String subscriptionArn) throws Exception; 56 | 57 | /** 58 | * getSubscriptionAttributes 59 | * @param subscriptionArn 60 | * @return CNSSubscriptionAttributes 61 | * @throws Exception 62 | */ 63 | public CNSSubscriptionAttributes getSubscriptionAttributes(String subscriptionArn) throws Exception; 64 | } 65 | -------------------------------------------------------------------------------- /src/com/comcast/cns/persistence/ICNSTopicPersistence.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.persistence; 17 | 18 | import java.util.List; 19 | 20 | import com.comcast.cmb.common.util.PersistenceException; 21 | import com.comcast.cns.model.CNSTopic; 22 | 23 | /** 24 | * Interface representing persistence of topic 25 | * @author bwolf, tina 26 | * 27 | */ 28 | public interface ICNSTopicPersistence { 29 | 30 | /** 31 | * Create a new topic. 32 | * @param name 33 | * @param displayName 34 | * @param userId 35 | * @return 36 | * @throws Exception 37 | */ 38 | public CNSTopic createTopic(String name, String displayName, String userId) throws Exception; 39 | 40 | /** 41 | * Delete an existing topic along with all subscriptions. 42 | * @param arn 43 | * @throws Exception 44 | */ 45 | public void deleteTopic(String arn) throws Exception; 46 | 47 | /** 48 | * Get a topic object by topic arn. Not part of official AWS API. 49 | * @param arn topic arn 50 | * @return topic 51 | * @throws Exception 52 | */ 53 | public CNSTopic getTopic(String arn) throws Exception; 54 | 55 | /** 56 | * List all topics for a user. Pagination for more than 100 subscriptions. 57 | * @param userId user id 58 | * @param nextToken initially null, on subsequent calls arn of last result from prior call 59 | * @return topic 60 | * @throws Exception 61 | */ 62 | public List listTopics(String userId, String nextToken) throws Exception; 63 | 64 | /** 65 | * Update topic display name 66 | * @param arn 67 | * @param displayName 68 | * @throws Exception 69 | */ 70 | public void updateTopicDisplayName(String arn, String displayName) throws Exception; 71 | 72 | /** 73 | * Get number of topics by user 74 | * @param userId 75 | * @return 76 | * @throws PersistenceException 77 | */ 78 | public long getNumberOfTopicsByUser(String userId) throws PersistenceException; 79 | } 80 | -------------------------------------------------------------------------------- /src/com/comcast/cns/persistence/SubscriberNotFoundException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.persistence; 17 | 18 | import com.comcast.cmb.common.util.CMBErrorCodes; 19 | import com.comcast.cmb.common.util.CMBException; 20 | 21 | /** 22 | * Exception representing subscriber not found 23 | * @author aseem 24 | * 25 | */ 26 | public class SubscriberNotFoundException extends CMBException { 27 | private static final long serialVersionUID = 1L; 28 | 29 | public SubscriberNotFoundException(String awsCode, String message) { 30 | super(CMBErrorCodes.NotFound.getHttpCode(), awsCode, message); 31 | } 32 | 33 | public SubscriberNotFoundException(String message) { 34 | super(CMBErrorCodes.NotFound, message); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/com/comcast/cns/persistence/TopicNotFoundException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.persistence; 17 | 18 | import com.comcast.cmb.common.util.CMBErrorCodes; 19 | import com.comcast.cmb.common.util.CMBException; 20 | 21 | /** 22 | * Exception representing topic not found 23 | * @author aseem 24 | * 25 | */ 26 | public class TopicNotFoundException extends CMBException { 27 | 28 | private static final long serialVersionUID = 1L; 29 | 30 | public TopicNotFoundException(String awsCode, String message) { 31 | super(CMBErrorCodes.NotFound.getHttpCode(), awsCode, message); 32 | } 33 | 34 | public TopicNotFoundException(String message) { 35 | super(CMBErrorCodes.NotFound, message); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/comcast/cns/tools/CNSPublisherJobThread.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.tools; 17 | 18 | import org.apache.log4j.Logger; 19 | 20 | import com.comcast.cmb.common.util.CMBProperties; 21 | 22 | /** 23 | * This class represents Thread that backoff when no message exists in all the partitions 24 | * @author aseem 25 | */ 26 | public class CNSPublisherJobThread extends Thread { 27 | 28 | private static Logger logger = Logger.getLogger(CNSPublisherJobThread.class); 29 | 30 | private final CNSPublisherPartitionRunnable runnable; 31 | private final int partitionNumber; 32 | 33 | public CNSPublisherJobThread(String threadName, CNSPublisherPartitionRunnable runnable, int partitionNumber) { 34 | 35 | super(threadName); 36 | this.runnable = runnable; 37 | this.partitionNumber = partitionNumber; 38 | } 39 | 40 | @Override 41 | public void run() { 42 | while (true) { 43 | runnable.run(this.partitionNumber); 44 | if(!CMBProperties.getInstance().isCNSPublisherEnabled()){ 45 | break; 46 | } 47 | } 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /src/com/comcast/cns/tools/CNSPublisherPartitionRunnable.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.tools; 17 | 18 | /** 19 | * Interface representing the processing of one partition of queues 20 | * @author aseem 21 | * 22 | */ 23 | public interface CNSPublisherPartitionRunnable { 24 | 25 | /** 26 | * Run for a specific partition 27 | * @param partition the partition number 28 | * @return true if messages were found in current partition, false otherwise 29 | */ 30 | public boolean run(int partition); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/com/comcast/cns/tools/CNSWorkerMonitorMBean.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.tools; 17 | 18 | import java.util.Map; 19 | 20 | /** 21 | * Interface for monitoring CNS 22 | * @author aseem 23 | * 24 | */ 25 | public interface CNSWorkerMonitorMBean { 26 | 27 | /** 28 | * @return total number of publishMessage() called across all topics in a rolling window 29 | */ 30 | public int getRecentNumberOfPublishedMessages(); 31 | 32 | /** 33 | * @return number of http connections in the pool for HTTP publisher 34 | */ 35 | public int getPublishHttpPoolSize(); 36 | 37 | /** 38 | * 39 | * @return total number of publish jobs for which at least one endpoint is not yet succesfully published 40 | * but we are still trying 41 | */ 42 | public int getPendingPublishJobs(); 43 | 44 | /** 45 | * 46 | * @return map of endpointURL -> failure-rate-percentage, numTries, Topic1, Topic2,.. 47 | */ 48 | public Map getErrorRateForEndpoints(); 49 | 50 | /** 51 | * 52 | * @return map of endpointURL -> number of failures over last 60 seconds 53 | */ 54 | public Map getRecentErrorCountForEndpoints(); 55 | 56 | /** 57 | * 58 | * @return size of delivery handler queue 59 | */ 60 | public int getDeliveryQueueSize(); 61 | 62 | /** 63 | * 64 | * @return size of redelivery handler queue 65 | */ 66 | public int getRedeliveryQueueSize(); 67 | 68 | /** 69 | * 70 | */ 71 | public boolean isCQSServiceAvailable(); 72 | 73 | /** 74 | * 75 | * @return true if consumer is no longer taking new ep-publish-jobs off the queue 76 | * because its too busy. false otherwise 77 | */ 78 | public boolean isConsumerOverloaded(); 79 | 80 | /** 81 | * Clear all bad endpoint state 82 | */ 83 | public void clearBadEndpointsState(); 84 | 85 | /** 86 | * Clear all worker queues and reinitialize (potentially useful when worker is overloaded) 87 | */ 88 | public boolean clearWorkerQueues(); 89 | 90 | /** 91 | * @return return status of cns workers 92 | */ 93 | public boolean getCNSWorkerStatus(); 94 | 95 | /** 96 | * Start CNS Workers 97 | */ 98 | public void startCNSWorkers () throws Exception; 99 | 100 | /** 101 | * Stop CNS Workers 102 | */ 103 | public void stopCNSWorkers(); 104 | } 105 | -------------------------------------------------------------------------------- /src/com/comcast/cns/util/CNSErrorCodes.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.util; 17 | 18 | import com.comcast.cmb.common.util.CMBErrorCodes; 19 | 20 | /** 21 | * Declare all the error codes we use 22 | * @author aseem, bwolf, jorge 23 | * 24 | */ 25 | public class CNSErrorCodes extends CMBErrorCodes { 26 | 27 | public static final CNSErrorCodes CNS_InvalidParameter = new CNSErrorCodes(400, "InvalidParameter"); 28 | 29 | public static final CNSErrorCodes CNS_TopicLimitExceeded = new CNSErrorCodes(403, "TopicLimitExceeded"); // Indicates that the customer already owns the maximum allowed number of topics 30 | 31 | public static final CNSErrorCodes CNS_NotFound = new CNSErrorCodes(404, "NotFound"); // Indicates that the requested resource does not exist. 32 | 33 | public static final CNSErrorCodes CNS_SubscriptionLimitExceeded = new CNSErrorCodes(403, "SubscriptionLimitExceeded"); 34 | 35 | public static final CNSErrorCodes CNS_TokenExpired = new CNSErrorCodes(403, "TokenExpired"); 36 | 37 | public static final CNSErrorCodes CNS_ValidationError = new CNSErrorCodes(400, "ValidationError"); 38 | 39 | protected CNSErrorCodes(int httpCode, String cmbCode) { 40 | super(httpCode, cmbCode); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/com/comcast/cns/util/MailWrapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.util; 17 | 18 | import javax.mail.*; 19 | import javax.mail.internet.*; 20 | 21 | import com.comcast.cmb.common.util.CMBProperties; 22 | 23 | import java.util.*; 24 | 25 | /** 26 | * Utility class for providing email sending functionality 27 | * @author bwolf 28 | * 29 | */ 30 | public class MailWrapper { 31 | 32 | private static final String SMTP_HOST_NAME = CMBProperties.getInstance().getSmtpHostName(); 33 | private static final String SMTP_AUTH_USER = CMBProperties.getInstance().getSmtpUserName(); 34 | private static final String SMTP_AUTH_PWD = CMBProperties.getInstance().getSmtpPassword(); 35 | 36 | public void postMail(String recipients[ ], String subject, String message , String from) throws MessagingException { 37 | 38 | boolean debug = false; 39 | 40 | Properties props = new Properties(); 41 | props.put("mail.smtp.host", SMTP_HOST_NAME); 42 | props.put("mail.smtp.auth", "true"); 43 | 44 | Authenticator auth = new SMTPAuthenticator(); 45 | Session session = Session.getDefaultInstance(props, auth); 46 | 47 | session.setDebug(debug); 48 | 49 | Message msg = new MimeMessage(session); 50 | 51 | InternetAddress addressFrom = new InternetAddress(from); 52 | msg.setFrom(addressFrom); 53 | 54 | InternetAddress[] addressTo = new InternetAddress[recipients.length]; 55 | 56 | for (int i = 0; i < recipients.length; i++) { 57 | addressTo[i] = new InternetAddress(recipients[i]); 58 | } 59 | 60 | msg.setRecipients(Message.RecipientType.TO, addressTo); 61 | msg.setSubject(subject); 62 | msg.setContent(message, "text/plain"); 63 | 64 | Transport.send(msg); 65 | } 66 | 67 | private class SMTPAuthenticator extends javax.mail.Authenticator 68 | { 69 | public PasswordAuthentication getPasswordAuthentication() 70 | { 71 | String username = SMTP_AUTH_USER; 72 | String password = SMTP_AUTH_PWD; 73 | return new PasswordAuthentication(username, password); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/com/comcast/cqs/controller/CQSAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cqs.controller; 17 | 18 | import javax.servlet.http.HttpServletRequest; 19 | 20 | import com.comcast.cmb.common.controller.Action; 21 | import com.comcast.cmb.common.model.CMBPolicy; 22 | import com.comcast.cmb.common.model.User; 23 | import com.comcast.cqs.util.CQSConstants; 24 | import com.comcast.cqs.util.Util; 25 | 26 | /** 27 | * Class represents all CQS actions 28 | * @author vvenkatraman, bwolf 29 | * 30 | */ 31 | public abstract class CQSAction extends Action { 32 | 33 | public CQSAction(String actionName) { 34 | super(actionName); 35 | } 36 | 37 | public boolean isActionAllowed(User user, HttpServletRequest request, String service, CMBPolicy policy) throws Exception { 38 | 39 | String absoluteQueueUrl = request.getRequestURL().toString(); 40 | 41 | if (request.getRequestURI() == null || request.getRequestURI().equals("") || request.getRequestURI().equals("/")) { 42 | absoluteQueueUrl = request.getParameter(CQSConstants.QUEUE_URL); 43 | } 44 | 45 | String queueUserId = Util.getUserIdForAbsoluteQueueUrl(absoluteQueueUrl); 46 | 47 | if (user.getUserId().equals(queueUserId)) { 48 | return true; 49 | } 50 | 51 | if (policy == null) { 52 | return false; 53 | } 54 | 55 | return policy.isAllowed(user, service + ":" + this.actionName); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/com/comcast/cqs/controller/CQSChangeMessageVisibilityAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cqs.controller; 17 | 18 | import javax.servlet.AsyncContext; 19 | import javax.servlet.http.HttpServletRequest; 20 | import javax.servlet.http.HttpServletResponse; 21 | 22 | import com.comcast.cmb.common.model.User; 23 | import com.comcast.cmb.common.persistence.PersistenceFactory; 24 | import com.comcast.cmb.common.util.CMBErrorCodes; 25 | import com.comcast.cmb.common.util.CMBException; 26 | import com.comcast.cmb.common.util.CMBProperties; 27 | import com.comcast.cqs.io.CQSMessagePopulator; 28 | import com.comcast.cqs.model.CQSQueue; 29 | import com.comcast.cqs.util.CQSConstants; 30 | 31 | /** 32 | * Change message visibility 33 | * @author baosen, vvenkatraman, bwolf 34 | * 35 | */ 36 | public class CQSChangeMessageVisibilityAction extends CQSAction { 37 | 38 | public CQSChangeMessageVisibilityAction() { 39 | super("ChangeMessageVisibility"); 40 | } 41 | 42 | @Override 43 | public boolean doAction(User user, AsyncContext asyncContext) throws Exception { 44 | 45 | HttpServletRequest request = (HttpServletRequest)asyncContext.getRequest(); 46 | HttpServletResponse response = (HttpServletResponse)asyncContext.getResponse(); 47 | 48 | CQSQueue queue = CQSCache.getCachedQueue(user, request); 49 | String receiptHandle = request.getParameter(CQSConstants.RECEIPT_HANDLE); 50 | 51 | if (receiptHandle == null) { 52 | throw new CMBException(CMBErrorCodes.MissingParameter, "ReceiptHandle not found"); 53 | } 54 | 55 | String visibilityTimeout = request.getParameter(CQSConstants.VISIBILITY_TIMEOUT); 56 | 57 | if ( visibilityTimeout == null) { 58 | throw new CMBException(CMBErrorCodes.MissingParameter, "VisibilityTimeout not found"); 59 | } 60 | 61 | int visibilityTO = Integer.parseInt(visibilityTimeout); 62 | 63 | if (visibilityTO < 0 || visibilityTO > CMBProperties.getInstance().getCQSMaxVisibilityTimeOut()) { 64 | throw new CMBException(CMBErrorCodes.InvalidParameterValue, "VisibilityTimeout is limited from 0 to " + CMBProperties.getInstance().getCQSMaxVisibilityTimeOut() + " seconds"); 65 | } 66 | 67 | PersistenceFactory.getCQSMessagePersistence().changeMessageVisibility(queue, receiptHandle, visibilityTO); 68 | 69 | String out = CQSMessagePopulator.getChangeMessageVisibilityResponse(); 70 | writeResponse(out, response); 71 | 72 | return true; 73 | } 74 | } -------------------------------------------------------------------------------- /src/com/comcast/cqs/controller/CQSDeleteMessageAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cqs.controller; 17 | 18 | import javax.servlet.AsyncContext; 19 | import javax.servlet.http.HttpServletRequest; 20 | import javax.servlet.http.HttpServletResponse; 21 | 22 | import com.comcast.cmb.common.model.User; 23 | import com.comcast.cmb.common.persistence.PersistenceFactory; 24 | import com.comcast.cmb.common.util.CMBErrorCodes; 25 | import com.comcast.cmb.common.util.CMBException; 26 | import com.comcast.cqs.io.CQSMessagePopulator; 27 | import com.comcast.cqs.model.CQSQueue; 28 | import com.comcast.cqs.util.CQSConstants; 29 | import com.comcast.cqs.util.CQSErrorCodes; 30 | /** 31 | * Delete message 32 | * @author baosen, vvenkatraman, bwolf 33 | * 34 | */ 35 | public class CQSDeleteMessageAction extends CQSAction { 36 | 37 | public CQSDeleteMessageAction() { 38 | super("DeleteMessage"); 39 | } 40 | 41 | private boolean isValidReceiptHandle(String receiptHandle) { 42 | 43 | if (receiptHandle == null) { 44 | return false; 45 | } 46 | 47 | String elements[] = receiptHandle.split(":"); 48 | 49 | if (elements.length < 3) { 50 | return false; 51 | } 52 | 53 | try { 54 | Long.parseLong(elements[elements.length-1]); 55 | Long.parseLong(elements[elements.length-2]); 56 | } catch (Exception ex) { 57 | return false; 58 | } 59 | 60 | return true; 61 | } 62 | 63 | @Override 64 | public boolean doAction(User user, AsyncContext asyncContext) throws Exception { 65 | 66 | HttpServletRequest request = (HttpServletRequest)asyncContext.getRequest(); 67 | HttpServletResponse response = (HttpServletResponse)asyncContext.getResponse(); 68 | 69 | CQSQueue queue = CQSCache.getCachedQueue(user, request); 70 | 71 | String receiptHandle = request.getParameter(CQSConstants.RECEIPT_HANDLE); 72 | 73 | if (receiptHandle == null) { 74 | throw new CMBException(CMBErrorCodes.MissingParameter, "ReceiptHandle not found"); 75 | } 76 | 77 | if (!isValidReceiptHandle(receiptHandle)) { 78 | throw new CMBException(CQSErrorCodes.ReceiptHandleInvalid, "The input receipt handle is invalid"); 79 | } 80 | 81 | PersistenceFactory.getCQSMessagePersistence().deleteMessage(queue.getRelativeUrl(), receiptHandle); 82 | 83 | String out = CQSMessagePopulator.getDeleteMessageResponse(); 84 | writeResponse(out, response); 85 | 86 | return true; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/com/comcast/cqs/controller/CQSDeleteQueueAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cqs.controller; 17 | 18 | import javax.servlet.AsyncContext; 19 | import javax.servlet.http.HttpServletRequest; 20 | import javax.servlet.http.HttpServletResponse; 21 | 22 | import com.comcast.cmb.common.model.User; 23 | import com.comcast.cmb.common.persistence.PersistenceFactory; 24 | import com.comcast.cqs.io.CQSQueuePopulator; 25 | import com.comcast.cqs.model.CQSQueue; 26 | 27 | /** 28 | * Delete queue 29 | * @author baosen, vvenkatraman, bwolf 30 | * 31 | */ 32 | public class CQSDeleteQueueAction extends CQSAction { 33 | 34 | public CQSDeleteQueueAction() { 35 | super("DeleteQueue"); 36 | } 37 | 38 | @Override 39 | public boolean doAction(User user, AsyncContext asyncContext) throws Exception { 40 | 41 | HttpServletRequest request = (HttpServletRequest)asyncContext.getRequest(); 42 | HttpServletResponse response = (HttpServletResponse)asyncContext.getResponse(); 43 | 44 | CQSQueue queue = CQSCache.getCachedQueue(user, request); 45 | 46 | int numberOfShards = queue.getNumberOfShards(); 47 | 48 | PersistenceFactory.getQueuePersistence().deleteQueue(queue.getRelativeUrl()); 49 | 50 | // clear all shards in redis 51 | 52 | for (int shard=0; shard attributesList = Util.fillGetAttributesRequests(request); 52 | 53 | for (String attribute : attributesList) { 54 | 55 | if (!attribute.equals("All") && !attribute.equals(CQSConstants.VISIBILITY_TIMEOUT) && !attribute.equals(CQSConstants.POLICY) && !attribute.equals(CQSConstants.QUEUE_ARN) 56 | && !attribute.equals(CQSConstants.MAXIMUM_MESSAGE_SIZE) && !attribute.equals(CQSConstants.MESSAGE_RETENTION_PERIOD) && !attribute.equals(CQSConstants.DELAY_SECONDS) 57 | && !attribute.equals(CQSConstants.APPROXIMATE_NUMBER_OF_MESSAGES) 58 | && !attribute.equals(CQSConstants.APPROXIMATE_NUMBER_OF_MESSAGES_NOTVISIBLE) 59 | && !attribute.equals(CQSConstants.APPROXIMATE_NUMBER_OF_MESSAGES_DELAYED) 60 | && !attribute.equals(CQSConstants.RECEIVE_MESSAGE_WAIT_TIME_SECONDS) 61 | && !attribute.equals(CQSConstants.NUMBER_OF_PARTITIONS) && !attribute.equals(CQSConstants.NUMBER_OF_SHARDS) && !attribute.equals(CQSConstants.IS_COMPRESSED)) { 62 | throw new CMBException(CMBErrorCodes.InvalidAttributeName, "Unknown attribute " + attribute); 63 | } 64 | } 65 | 66 | String out = CQSQueuePopulator.getQueueAttributesResponse(queue, attributesList); 67 | writeResponse(out, response); 68 | 69 | return true; 70 | } 71 | } -------------------------------------------------------------------------------- /src/com/comcast/cqs/controller/CQSGetQueueUrlAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cqs.controller; 17 | 18 | import javax.servlet.AsyncContext; 19 | import javax.servlet.http.HttpServletRequest; 20 | import javax.servlet.http.HttpServletResponse; 21 | 22 | import com.comcast.cmb.common.model.CMBPolicy; 23 | import com.comcast.cmb.common.model.User; 24 | import com.comcast.cmb.common.persistence.PersistenceFactory; 25 | import com.comcast.cmb.common.util.CMBErrorCodes; 26 | import com.comcast.cmb.common.util.CMBException; 27 | import com.comcast.cqs.io.CQSQueuePopulator; 28 | import com.comcast.cqs.model.CQSQueue; 29 | import com.comcast.cqs.util.CQSErrorCodes; 30 | 31 | /** 32 | * Get queue url 33 | * @author bwolf, vvenkatraman, baosen 34 | * 35 | */ 36 | public class CQSGetQueueUrlAction extends CQSAction { 37 | 38 | public CQSGetQueueUrlAction() { 39 | super("GetQueueUrl"); 40 | } 41 | 42 | @Override 43 | public boolean doAction(User user, AsyncContext asyncContext) throws Exception { 44 | 45 | HttpServletRequest request = (HttpServletRequest)asyncContext.getRequest(); 46 | HttpServletResponse response = (HttpServletResponse)asyncContext.getResponse(); 47 | 48 | String queueName = request.getParameter("QueueName"); 49 | 50 | if (queueName == null) { 51 | throw new CMBException(CMBErrorCodes.MissingParameter, "Parameter QueueName not found"); 52 | } 53 | 54 | CQSQueue queue = PersistenceFactory.getQueuePersistence().getQueue(user.getUserId(), queueName); 55 | 56 | if (queue == null) { 57 | throw new CMBException(CQSErrorCodes.NonExistentQueue, "Queue not found with name " + queueName + " for user " + user.getUserId()); 58 | } 59 | 60 | String out = CQSQueuePopulator.getQueueUrlResponse(queue); 61 | writeResponse(out, response); 62 | 63 | return true; 64 | } 65 | 66 | @Override 67 | public boolean isActionAllowed(User user, HttpServletRequest request, String service, CMBPolicy policy) { 68 | return true; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/com/comcast/cqs/controller/CQSListQueuesAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cqs.controller; 17 | 18 | import java.util.List; 19 | 20 | import javax.servlet.AsyncContext; 21 | import javax.servlet.http.HttpServletRequest; 22 | import javax.servlet.http.HttpServletResponse; 23 | 24 | import com.comcast.cmb.common.model.CMBPolicy; 25 | import com.comcast.cmb.common.model.User; 26 | import com.comcast.cmb.common.persistence.PersistenceFactory; 27 | import com.comcast.cqs.io.CQSQueuePopulator; 28 | import com.comcast.cqs.model.CQSQueue; 29 | /** 30 | * List queues 31 | * @author baosen, bwolf, vvenkatraman 32 | * 33 | */ 34 | public class CQSListQueuesAction extends CQSAction { 35 | 36 | public CQSListQueuesAction() { 37 | super("ListQueues"); 38 | } 39 | 40 | @Override 41 | public boolean doAction(User user, AsyncContext asyncContext) throws Exception { 42 | 43 | HttpServletRequest request = (HttpServletRequest)asyncContext.getRequest(); 44 | HttpServletResponse response = (HttpServletResponse)asyncContext.getResponse(); 45 | 46 | String prefix = request.getParameter("QueueNamePrefix"); 47 | 48 | boolean containingMessagesOnly = false; 49 | 50 | if (request.getParameter("ContainingMessagesOnly") != null && request.getParameter("ContainingMessagesOnly").equals("true")) { 51 | containingMessagesOnly = true; 52 | } 53 | 54 | List queues = PersistenceFactory.getQueuePersistence().listQueues(user.getUserId(), prefix, containingMessagesOnly); 55 | 56 | String out = CQSQueuePopulator.getListQueuesResponse(queues); 57 | writeResponse(out, response); 58 | 59 | return true; 60 | } 61 | 62 | @Override 63 | public boolean isActionAllowed(User user, HttpServletRequest request, String service, CMBPolicy policy) { 64 | return true; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/com/comcast/cqs/controller/CQSPurgeQueueAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cqs.controller; 17 | 18 | import javax.servlet.AsyncContext; 19 | import javax.servlet.http.HttpServletRequest; 20 | import javax.servlet.http.HttpServletResponse; 21 | 22 | import com.comcast.cmb.common.model.User; 23 | import com.comcast.cmb.common.persistence.PersistenceFactory; 24 | import com.comcast.cqs.io.CQSMessagePopulator; 25 | import com.comcast.cqs.model.CQSQueue; 26 | /** 27 | * Clear queue 28 | * @author vvenkatraman, bwolf 29 | * 30 | */ 31 | public class CQSPurgeQueueAction extends CQSAction { 32 | 33 | public CQSPurgeQueueAction() { 34 | super("PurgeQueue"); 35 | } 36 | 37 | @Override 38 | public boolean doAction(User user, AsyncContext asyncContext) throws Exception { 39 | 40 | HttpServletRequest request = (HttpServletRequest)asyncContext.getRequest(); 41 | HttpServletResponse response = (HttpServletResponse)asyncContext.getResponse(); 42 | 43 | CQSQueue queue = CQSCache.getCachedQueue(user, request); 44 | 45 | for (int shard=0; shard msgParam = new HashMap(); 52 | List messageList = PersistenceFactory.getCQSMessagePersistence().receiveMessage(queue, msgParam); 53 | 54 | String out = ""; 55 | response.setContentType("text/html"); 56 | 57 | if (messageList.size() > 0) { 58 | 59 | out += messageList.get(0).getBody(); 60 | 61 | try { 62 | new JSONObject(messageList.get(0).getBody()); 63 | response.setContentType("application/json"); 64 | } catch (JSONException ex) { 65 | // do nothing 66 | } 67 | } 68 | 69 | writeResponse(out, response); 70 | 71 | return true; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/com/comcast/cqs/controller/CQSRemovePermissionAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cqs.controller; 17 | 18 | import javax.servlet.AsyncContext; 19 | import javax.servlet.http.HttpServletRequest; 20 | import javax.servlet.http.HttpServletResponse; 21 | 22 | import com.comcast.cmb.common.model.CMBPolicy; 23 | import com.comcast.cmb.common.model.User; 24 | import com.comcast.cmb.common.persistence.PersistenceFactory; 25 | import com.comcast.cmb.common.util.CMBException; 26 | import com.comcast.cmb.common.util.CMBProperties; 27 | import com.comcast.cqs.io.CQSQueuePopulator; 28 | import com.comcast.cqs.model.CQSQueue; 29 | import com.comcast.cqs.util.CQSConstants; 30 | import com.comcast.cqs.util.CQSErrorCodes; 31 | import com.comcast.cqs.util.Util; 32 | /** 33 | * Renmove permissions 34 | * @author bwolf, vvenkatraman, baosen 35 | * 36 | */ 37 | public class CQSRemovePermissionAction extends CQSAction { 38 | 39 | public CQSRemovePermissionAction() { 40 | super("RemovePermission"); 41 | } 42 | 43 | @Override 44 | public boolean doAction(User user, AsyncContext asyncContext) throws Exception { 45 | 46 | HttpServletRequest request = (HttpServletRequest)asyncContext.getRequest(); 47 | HttpServletResponse response = (HttpServletResponse)asyncContext.getResponse(); 48 | 49 | CQSQueue queue = CQSCache.getCachedQueue(user, request); 50 | String label = request.getParameter(CQSConstants.LABEL); 51 | 52 | if (!Util.isValidId(label)) { 53 | 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."); 54 | } 55 | 56 | CMBPolicy policy = new CMBPolicy(queue.getPolicy()); 57 | 58 | if (policy.removeStatement(label)) { 59 | String policyStr = policy.toString(); 60 | PersistenceFactory.getQueuePersistence().updatePolicy(queue.getRelativeUrl(), policyStr); 61 | queue.setPolicy(policyStr); 62 | } 63 | 64 | String out = CQSQueuePopulator.getRemovePermissionResponse(); 65 | writeResponse(out, response); 66 | 67 | return true; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/com/comcast/cqs/io/CQSAPIStatsPopulator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cqs.io; 17 | 18 | import java.util.List; 19 | 20 | import com.comcast.cqs.model.CQSAPIStats; 21 | 22 | public class CQSAPIStatsPopulator { 23 | 24 | public static String getGetAPIStatsResponse(List statsList) { 25 | 26 | String out = ""; 27 | out += "\n"; 28 | out += "\t\n"; 29 | 30 | for (CQSAPIStats stats : statsList) { 31 | 32 | out += "\t\t\n"; 33 | 34 | out += "\t\t\t"+stats.getIpAddress()+"\n"; 35 | out += "\t\t\t"+stats.getJmxPort()+"\n"; 36 | out += "\t\t\t"+stats.getLongPollPort()+"\n"; 37 | out += "\t\t\t"+stats.getDataCenter()+"\n"; 38 | out += "\t\t\t"+stats.getServiceUrl()+"\n"; 39 | out += "\t\t\t"+stats.getTimestamp()+"\n"; 40 | out += "\t\t\t"+stats.getNumberOfLongPollReceives()+"\n"; 41 | out += "\t\t\t"+stats.getNumberOfRedisKeys()+"\n"; 42 | out += "\t\t\t"+stats.getNumberOfRedisShards()+"\n"; 43 | 44 | if (stats.getRedisServerList() != null) { 45 | out += "\t\t\t"+stats.getRedisServerList()+"\n"; 46 | } 47 | 48 | if (stats.getStatus() != null) { 49 | out += "\t\t\t"+stats.getStatus()+"\n"; 50 | } 51 | 52 | if (stats.getCassandraClusterName() != null) { 53 | out += "\t\t\t"+stats.getCassandraClusterName()+"\n"; 54 | } 55 | 56 | if (stats.getCassandraNodes() != null) { 57 | out += "\t\t\t"+stats.getCassandraNodes()+"\n"; 58 | } 59 | 60 | out += "\t\t\t\n"; 61 | 62 | if (stats.getCallStats() != null) { 63 | for (String action : stats.getCallStats().keySet()) { 64 | out += "\t\t\t\t<"+action+">"+stats.getCallStats().get(action)+"\n"; 65 | } 66 | } 67 | 68 | out += "\t\t\t\n"; 69 | 70 | out += "\t\t\t\n"; 71 | 72 | if (stats.getCallFailureStats() != null) { 73 | for (String action : stats.getCallFailureStats().keySet()) { 74 | out += "\t\t\t\t<"+action+">"+stats.getCallFailureStats().get(action)+"\n"; 75 | } 76 | } 77 | 78 | out += "\t\t\t\n"; 79 | 80 | out += "\t\t\n"; 81 | } 82 | 83 | out += "\t\n"; 84 | out += ""; 85 | 86 | return out; 87 | } 88 | 89 | //return data center names 90 | public static String getGetAPIStatsDataCenterResponse(List dataCenterNames) { 91 | 92 | String out = ""; 93 | out += "\n"; 94 | out += "\t\n"; 95 | for (String currentDataCenterName : dataCenterNames) { 96 | out += "\t\t"+currentDataCenterName+"\n"; 97 | } 98 | out += "\t\n"; 99 | out += ""; 100 | return out; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/com/comcast/cqs/io/CQSPopulator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cqs.io; 17 | 18 | import com.comcast.cmb.common.model.ReceiptModule; 19 | 20 | /** 21 | * Top level API response generator 22 | * @author baosen 23 | * 24 | */ 25 | public class CQSPopulator { 26 | 27 | public static String getResponseMetadata() { 28 | return "" + ReceiptModule.getReceiptId() + ""; 29 | } 30 | 31 | public CQSPopulator() { 32 | super(); 33 | } 34 | } -------------------------------------------------------------------------------- /src/com/comcast/cqs/model/CQSBatchResultErrorEntry.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cqs.model; 17 | 18 | /** 19 | * 20 | * @author baosen 21 | * 22 | */ 23 | public class CQSBatchResultErrorEntry { 24 | 25 | private String id; 26 | private boolean senderFault; 27 | private String code; 28 | private String message; 29 | 30 | public CQSBatchResultErrorEntry(String id, boolean senderFault, String code, String message) { 31 | this.id = id; 32 | this.senderFault = senderFault; 33 | this.code = code; 34 | this.message = message; 35 | } 36 | 37 | public void setId(String id) { 38 | this.id = id; 39 | } 40 | 41 | public void setSenderFault(boolean bool) { 42 | this.senderFault = bool; 43 | } 44 | 45 | public void setMessage(String str) { 46 | this.message = str; 47 | } 48 | 49 | public void setCode(String code) { 50 | this.code = code; 51 | } 52 | 53 | public String getId() { 54 | return id; 55 | } 56 | 57 | public boolean getSenderFault() { 58 | return senderFault; 59 | } 60 | 61 | public String getCode() { 62 | return code; 63 | } 64 | 65 | public String getMessage() { 66 | return message; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/com/comcast/cqs/model/CQSMessageAttribute.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cqs.model; 17 | 18 | import java.nio.ByteBuffer; 19 | import com.sun.jersey.core.util.Base64; 20 | import com.comcast.cmb.common.util.CMBException; 21 | 22 | public class CQSMessageAttribute { 23 | 24 | String Value; 25 | String DataType; 26 | 27 | public CQSMessageAttribute(String Value, String DataType) { 28 | this.Value = Value; 29 | if (DataType.toLowerCase().equals("string")) { 30 | DataType = "String"; 31 | } else if (DataType.toLowerCase().equals("number")) { 32 | DataType = "Number"; 33 | } else if (DataType.toLowerCase().equals("binary")) { 34 | DataType = "Binary"; 35 | } 36 | this.DataType = DataType; 37 | 38 | } 39 | 40 | public String getStringValue() { 41 | return Value; 42 | } 43 | 44 | public ByteBuffer getBinaryValue() { 45 | if (DataType.equals("Binary")) { 46 | return ByteBuffer.wrap(Base64.decode(Value)); 47 | } else { 48 | return ByteBuffer.wrap(Value.getBytes()); 49 | } 50 | } 51 | 52 | public String getDataType() { 53 | return DataType; 54 | } 55 | 56 | public int size() { 57 | if (Value == null) { 58 | return 0; 59 | } 60 | return Value.length(); 61 | } 62 | 63 | public void validate() throws CMBException { 64 | if (DataType.equals("String")) { 65 | //TODO 66 | } else if (DataType.equals("Number")) { 67 | //TODO 68 | } else if (DataType.equals("Binary")) { 69 | //TODO 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/com/comcast/cqs/persistence/ICQSQueuePersistence.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cqs.persistence; 17 | 18 | import com.comcast.cmb.common.util.PersistenceException; 19 | import com.comcast.cqs.model.CQSQueue; 20 | 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | /** 25 | * Interface to persist queues 26 | * @author baosen, vvenkatraman, jorge 27 | */ 28 | public interface ICQSQueuePersistence { 29 | 30 | /** 31 | * Create a queue 32 | * 33 | * @param queue 34 | * @throws PersistenceException 35 | */ 36 | public void createQueue(CQSQueue queue) throws PersistenceException; 37 | 38 | /** 39 | * Delete a queue given the queueUrl 40 | * 41 | * @param queueUrl 42 | * @throws PersistenceException 43 | */ 44 | public void deleteQueue(String queueUrl) throws PersistenceException; 45 | 46 | /** 47 | * List all the queue for a given user. All queues are returned if prefix is 48 | * null 49 | * 50 | * @param userId 51 | * @param queueName_prefix 52 | * @param containingMessagesOnly if true only list queues containing messages, otherwise list all queues, only works if redis is available 53 | * @return 54 | * @throws PersistenceException 55 | */ 56 | public List listQueues(String userId, String queueName_prefix, boolean containingMessagesOnly) throws PersistenceException; 57 | 58 | /** 59 | * Update the queue 60 | * 61 | * @param queue 62 | */ 63 | public void updateQueueAttribute(String queueURL, Map queueData) throws PersistenceException; 64 | 65 | /** 66 | * Get a queue given user ID and queueName 67 | * 68 | * @param userId 69 | * @param queueName 70 | * @return 71 | * @throws PersistenceException 72 | */ 73 | public CQSQueue getQueue(String userId, String queueName) throws PersistenceException; 74 | 75 | /** 76 | * Get a queue given queue url 77 | * 78 | * @param queueUrl 79 | * The URL of the queue to get. 80 | * @return 81 | */ 82 | public CQSQueue getQueue(String queueUrl) throws PersistenceException; 83 | 84 | /** 85 | * Update the policy for a given queue 86 | * 87 | * @param queueUrl 88 | * The URL of the queue to get. 89 | * @param policy 90 | * The updated policy for the queue 91 | * @return 92 | */ 93 | public boolean updatePolicy(String queueUrl, String policy) throws PersistenceException; 94 | 95 | /** 96 | * Get number of queues for this user 97 | * 98 | * @param userId 99 | * @return 100 | * @throws PersistenceException 101 | */ 102 | public long getNumberOfQueuesByUser(String userId) throws PersistenceException; 103 | } 104 | -------------------------------------------------------------------------------- /src/com/comcast/cqs/util/CQSErrorCodes.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cqs.util; 17 | 18 | import com.comcast.cmb.common.util.CMBErrorCodes; 19 | 20 | /** 21 | * declare all error codes for cqs 22 | * @author baosen, bwolf 23 | * 24 | */ 25 | public final class CQSErrorCodes extends CMBErrorCodes { 26 | 27 | public static final CQSErrorCodes NonExistentQueue = new CQSErrorCodes(400, "AWS.SimpleQueueService.NonExistentQueue"); //Queue does not exist. 28 | 29 | public static final CQSErrorCodes QueueDeletedRecently = new CQSErrorCodes(400, "AWS.SimpleQueueService.QueueDeletedRecently"); //You must wait 60 seconds after deleting a queue before you can create another with the same name. 30 | 31 | public static final CQSErrorCodes QueueNameExists = new CQSErrorCodes(400, "AWS.SimpleQueueService.QueueNameExists"); //Queue already exists. CQS returns this error only if the request includes an attribute name or value that differs from the name or value for the existing attribute. 32 | 33 | public static final CQSErrorCodes BatchEntryIdsNotDistinct = new CQSErrorCodes(400, "AWS.SimpleQueueService.BatchEntryIdsNotDistinct"); // The supplied id must be distinct 34 | 35 | public static final CQSErrorCodes BatchRequestTooLong = new CQSErrorCodes(400, "AWS.SimpleQueueService.BatchRequestTooLong"); // Batch requests cannot be longer than 65536 bytes 36 | 37 | public static final CQSErrorCodes TooManyEntriesInBatchRequest = new CQSErrorCodes(400, "AWS.SimpleQueueService.TooManyEntriesInBatchRequest"); // Batch requests cannot have more than 10 entries 38 | 39 | public static final CQSErrorCodes InvalidBatchEntryId = new CQSErrorCodes(400, "AWS.SimpleQueueService.InvalidBatchEntryId"); // A batch entry id can only contain alphanumeric characters, hyphens and underscores. 40 | 41 | public static final CQSErrorCodes InvalidMessageContents = new CQSErrorCodes(400, "AWS.SimpleQueueService.InvalidMessageContents"); // The message contains characters outside the allowed set. 42 | 43 | public static final CQSErrorCodes BatchResultErrorEntry = new CQSErrorCodes(400, "AWS.SimpleQueueService.BatchResultErrorEntry"); //A message was not added to the queue. 44 | 45 | public static final CQSErrorCodes ReceiptHandleInvalid = new CQSErrorCodes(400, "AWS.SimpleQueueService.ReceiptHandleInvalid"); //A message was not added to the queue. 46 | 47 | protected CQSErrorCodes(int httpCode, String awsCode) { 48 | super(httpCode, awsCode); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/com/comcast/cqs/util/RandomNumberCollection.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cqs.util; 17 | 18 | import java.util.Random; 19 | 20 | /** 21 | * Utility class used to return n random numbers in the range [0..n] 22 | * @author aseem 23 | */ 24 | public class RandomNumberCollection { 25 | final int totalNum; 26 | int []randoms; 27 | final Random r; 28 | int seenSoFar; 29 | /** 30 | * 31 | * @param num the range between [0,num) that we will return 32 | */ 33 | public RandomNumberCollection(int num) { 34 | totalNum = num; 35 | seenSoFar = 0; 36 | randoms = new int[totalNum]; 37 | r = new Random(System.currentTimeMillis()); 38 | for(int i = 0; i < totalNum; i++) { 39 | randoms[i] = i; 40 | } 41 | } 42 | 43 | /** 44 | * @return random number between [0, num] that has not been previously returned 45 | * by this instance 46 | */ 47 | public int getNext() { 48 | if (seenSoFar == totalNum) throw new IllegalStateException("Already called getNext() " + totalNum + " times"); 49 | int idx = r.nextInt(totalNum - seenSoFar); 50 | int ret = randoms[idx]; 51 | //swap ret with first unseen number at the end of array 52 | seenSoFar++; 53 | randoms[idx] = randoms[totalNum - seenSoFar]; 54 | randoms[totalNum - seenSoFar] = ret; 55 | return ret; 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /tests/com/comcast/cmb/test/common/model/unit/CMBPolicyTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cmb.test.common.model.unit; 17 | 18 | import static org.junit.Assert.*; 19 | 20 | import java.util.Arrays; 21 | import java.util.List; 22 | 23 | import org.junit.After; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | 27 | import com.comcast.cmb.common.controller.CMBControllerServlet; 28 | import com.comcast.cmb.common.model.CMBPolicy; 29 | import com.comcast.cmb.common.model.CMBStatement; 30 | import com.comcast.cmb.common.util.Util; 31 | 32 | public class CMBPolicyTest { 33 | 34 | @Before 35 | public void setup() throws Exception{ 36 | Util.initLog4jTest(); 37 | CMBControllerServlet.valueAccumulator.initializeAllCounters(); 38 | } 39 | 40 | @Test 41 | public void testCMBStatement() { 42 | 43 | try { 44 | CMBPolicy policy = new CMBPolicy(); 45 | 46 | policy.addStatement(CMBPolicy.SERVICE.CQS, "unittest1", "Allow", Arrays.asList("1234567", "345678", "6789"), Arrays.asList("SendMessage", "GetQueueUrl"), "arn:cmb:cqs:ccp:331770435817:MyQueue123456789", null); 47 | policy.addStatement(CMBPolicy.SERVICE.CQS, "unittest2", "Allow", Arrays.asList("1234567"), Arrays.asList("DeleteMessage", "GetQueueUrl"), "arn:cmb:cqs:ccp:331770435817:MyQueue123456789", null); 48 | policy.addStatement(CMBPolicy.SERVICE.CQS, "unittest3", "Allow", Arrays.asList("1234567"), Arrays.asList("GetQueueUrl"), "arn:cmb:cqs:ccp:331770435817:MyQueue123456789", null); 49 | policy.addStatement(CMBPolicy.SERVICE.CQS, "unittest4", "Allow", Arrays.asList("1234567", "345678", "6789"), Arrays.asList("ReceiveMessage"), "arn:cmb:cqs:ccp:331770435817:MyQueue123456789", null); 50 | 51 | String policyStr = policy.toString(); 52 | 53 | CMBPolicy policy2; 54 | 55 | policy2 = new CMBPolicy(policyStr); 56 | List stmtList = policy2.getStatements(); 57 | 58 | assertTrue("Is there 4 permissions: ", stmtList.size() == 4); 59 | int i = 1; 60 | 61 | for (CMBStatement stmt : stmtList) { 62 | assertTrue("Is the Id correct: ", stmt.getSid().equals("unittest" + i++)); 63 | } 64 | 65 | } catch (Exception e) { 66 | fail(); 67 | } 68 | } 69 | 70 | @After 71 | public void tearDown() { 72 | CMBControllerServlet.valueAccumulator.deleteAllCounters(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /tests/com/comcast/cmb/test/common/model/unit/ReceiptModuleTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cmb.test.common.model.unit; 17 | 18 | import com.comcast.cmb.common.controller.CMBControllerServlet; 19 | import com.comcast.cmb.common.model.ReceiptModule; 20 | import com.comcast.cmb.common.util.Util; 21 | 22 | import org.junit.After; 23 | import org.junit.Before; 24 | import org.junit.Test; 25 | 26 | import static org.junit.Assert.*; 27 | 28 | /** 29 | * Created by IntelliJ IDEA. 30 | * User: michael 31 | * Date: 2/8/12 32 | * Time: 3:56 PM 33 | * To change this template use File | Settings | File Templates. 34 | */ 35 | public class ReceiptModuleTest { 36 | 37 | @Before 38 | public void setup() throws Exception { 39 | Util.initLog4jTest(); 40 | CMBControllerServlet.valueAccumulator.initializeAllCounters(); 41 | 42 | } 43 | 44 | @Test 45 | public void testGetReceiptId() throws Exception { 46 | String id1 = ReceiptModule.getReceiptId(); 47 | String id2 = ReceiptModule.getReceiptId(); 48 | 49 | assertEquals(id1, id2); 50 | 51 | ReceiptModule.init(); 52 | final String id3 = ReceiptModule.getReceiptId(); 53 | 54 | assertNotSame(id1, id3); 55 | 56 | Thread t = new Thread(new Runnable() { 57 | public void run() { 58 | String id4 = ReceiptModule.getReceiptId(); 59 | assertNotSame(id3, id4); 60 | } 61 | }); 62 | t.start(); 63 | 64 | t.join(); 65 | } 66 | @After 67 | public void tearDown() { 68 | CMBControllerServlet.valueAccumulator.deleteAllCounters(); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /tests/com/comcast/cmb/test/common/model/unit/UserAuthModuleTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cmb.test.common.model.unit; 17 | 18 | import com.comcast.cmb.common.controller.CMBControllerServlet; 19 | import com.comcast.cmb.common.model.IAuthModule; 20 | import com.comcast.cmb.common.model.User; 21 | import com.comcast.cmb.common.model.UserAuthModule; 22 | import com.comcast.cmb.common.persistence.IUserPersistence; 23 | import com.comcast.cmb.common.persistence.UserCassandraPersistence; 24 | import com.comcast.cmb.common.util.AuthenticationException; 25 | import com.comcast.cmb.common.util.CMBErrorCodes; 26 | import com.comcast.cmb.common.util.Util; 27 | 28 | import org.junit.After; 29 | import org.junit.Before; 30 | import org.junit.Test; 31 | 32 | import static org.junit.Assert.*; 33 | 34 | /** 35 | * Created by IntelliJ IDEA. 36 | * User: michael 37 | * Date: 3/6/12 38 | * Time: 4:23 PM 39 | * To change this template use File | Settings | File Templates. 40 | */ 41 | public class UserAuthModuleTest { 42 | 43 | IAuthModule authModule; 44 | 45 | @Before 46 | public void setUp() throws Exception { 47 | Util.initLog4jTest(); 48 | 49 | IUserPersistence userHandler = new UserCassandraPersistence(); 50 | 51 | User user = userHandler.getUserByName("cmb_unit_test"); 52 | 53 | if (user == null) { 54 | user = userHandler.createUser("cmb_unit_test", "cmb_unit_test"); 55 | } 56 | 57 | authModule = new UserAuthModule(); 58 | authModule.setUserPersistence(userHandler); 59 | CMBControllerServlet.valueAccumulator.initializeAllCounters(); 60 | 61 | } 62 | 63 | @Test 64 | public void testAuthModule() throws Exception { 65 | 66 | User user = authModule.authenticateByPassword("cmb_unit_test", "cmb_unit_test"); 67 | assertNotNull(user); 68 | 69 | try { 70 | user = authModule.authenticateByPassword("cmb_unit_test", "blahblah"); 71 | fail("wrong password ... should throw an exception"); 72 | } catch (AuthenticationException ex) { 73 | assertEquals(ex.getCMBCode(), CMBErrorCodes.AuthFailure.getCMBCode()); 74 | } 75 | } 76 | 77 | @After 78 | public void tearDown() { 79 | CMBControllerServlet.valueAccumulator.deleteAllCounters(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /tests/com/comcast/cmb/test/common/util/unit/ValidUnicodeTest.java: -------------------------------------------------------------------------------- 1 | package com.comcast.cmb.test.common.util.unit; 2 | 3 | import com.comcast.cmb.common.util.Util; 4 | 5 | import org.junit.Test; 6 | import static org.junit.Assert.*; 7 | 8 | public class ValidUnicodeTest { 9 | 10 | public static final String EMOJI_SAMPLE = "😀😁AA😉😯BB"; 11 | 12 | public static final char HIGH = '\uD83D'; 13 | public static final char LOW = '\uDE33'; 14 | 15 | public static final String INTACT_NORMAL_SURROGATE = "A😀"+HIGH+LOW+"😯"; 16 | public static final String WRONG_SINGLE_HIGH_SURROGATE = "A😀"+HIGH+"😯"; 17 | public static final String WRONG_SINGLE_LOW_SURROGATE = "A😀"+LOW+"😯"; 18 | public static final String WRONG_FLIPPED_SURROGATE = "A😀"+LOW+HIGH+"😯"; 19 | 20 | @Test 21 | public void testIsValidUnicode() { 22 | assertTrue(Util.isValidUnicode(EMOJI_SAMPLE)); 23 | assertTrue(Util.isValidUnicode(INTACT_NORMAL_SURROGATE)); 24 | assertFalse(Util.isValidUnicode(WRONG_SINGLE_HIGH_SURROGATE)); 25 | assertFalse(Util.isValidUnicode(INTACT_NORMAL_SURROGATE+HIGH)); 26 | assertFalse(Util.isValidUnicode(WRONG_SINGLE_LOW_SURROGATE)); 27 | assertFalse(Util.isValidUnicode(INTACT_NORMAL_SURROGATE+LOW)); 28 | assertFalse(Util.isValidUnicode(WRONG_FLIPPED_SURROGATE)); 29 | assertFalse(Util.isValidUnicode(INTACT_NORMAL_SURROGATE+LOW+HIGH)); 30 | } 31 | } -------------------------------------------------------------------------------- /tests/com/comcast/cmb/test/tools/CMBTestingConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cmb.test.tools; 17 | 18 | import com.comcast.cmb.common.util.CMBProperties; 19 | 20 | public class CMBTestingConstants { 21 | 22 | // base URL of live endpoint conforming with com.comcast.cmb.test.tools.EndpointServlet used by various unit tests 23 | 24 | public static final String HTTP_ENDPOINT_BASE_URL = CMBProperties.getInstance().getCQSServiceUrl() + "Endpoint/"; 25 | //public static final String HTTP_ENDPOINT_BASE_URL = "http://sns-test5.plaxo.com:6060/Endpoint/"; 26 | 27 | public static final String HTTPS_ENDPOINT_BASE_URL = ""; 28 | 29 | // email endpoint for testing 30 | 31 | public static final String EMAIL_ENDPOINT = "jorge@plaxo.com"; 32 | } 33 | -------------------------------------------------------------------------------- /tests/com/comcast/cmb/test/tools/CQSTestUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cmb.test.tools; 17 | 18 | import java.io.UnsupportedEncodingException; 19 | import java.security.NoSuchAlgorithmException; 20 | 21 | import com.comcast.cmb.common.persistence.AbstractDurablePersistence.CMB_SERIALIZER; 22 | import com.comcast.cmb.common.persistence.DurablePersistenceFactory; 23 | import com.comcast.cmb.common.util.CMBProperties; 24 | import com.comcast.cmb.common.util.PersistenceException; 25 | import com.comcast.cqs.util.Util; 26 | 27 | public class CQSTestUtils { 28 | 29 | /** 30 | * @param args 31 | * @throws UnsupportedEncodingException 32 | * @throws NoSuchAlgorithmException 33 | * @throws PersistenceException 34 | */ 35 | public static void main(String[] args) throws NoSuchAlgorithmException, UnsupportedEncodingException, PersistenceException { 36 | if (args == null) { 37 | System.out.println("Usage: . Valid actions are GetQueueCount with the queue url"); 38 | } 39 | if (args[0].equals("GetQueueCount")) { 40 | if (args.length < 2) { 41 | System.out.println("Missing argument queueurl"); 42 | return; 43 | } 44 | getQueueCount(args[1]); 45 | } 46 | 47 | } 48 | 49 | private static void getQueueCount(String queueUrl) throws NoSuchAlgorithmException, UnsupportedEncodingException, PersistenceException { 50 | int numberOfPartitions = CMBProperties.getInstance().getCQSNumberOfQueuePartitions(); 51 | String queueHash = Util.hashQueueUrl(queueUrl); 52 | long messageCount = 0; 53 | for (int i=0; i subscriptions; 29 | private CNSSubscriptionTest sub; 30 | private String requestId; 31 | private CharArrayWriter content = new CharArrayWriter(); 32 | private int count = 0; 33 | private String nextToken; 34 | 35 | public ListSubscriptionParser() { 36 | subscriptions = new Vector(); 37 | nextToken = null; 38 | } 39 | 40 | public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { 41 | content.reset(); 42 | //System.out.println("Start Element QName:" + qName); 43 | if(qName.equals("Topics")) { 44 | 45 | 46 | } else if(qName.equals("member")) { 47 | 48 | } 49 | } 50 | 51 | public void endElement (String uri, String localName, String qName) { 52 | //System.out.println("End Element QName:" + qName); 53 | if(sub == null) { 54 | sub = new CNSSubscriptionTest(); 55 | } 56 | if (qName.equals("TopicArn")) { 57 | String topicArn = content.toString(); 58 | //System.out.println("topicArn:" + topicArn); 59 | sub.setTopicArn(topicArn); 60 | 61 | } else if (qName.equals("Protocol")) { 62 | String protocol = content.toString(); 63 | sub.setProtocol(protocol); 64 | 65 | } else if (qName.equals("SubscriptionArn")) { 66 | String subscriptionArn = content.toString(); 67 | sub.setSubscriptionArn(subscriptionArn); 68 | 69 | } else if (qName.equals("Endpoint")) { 70 | String endpoint = content.toString(); 71 | //System.out.println("endpoint:" + endpoint); 72 | sub.setEndpoint(endpoint); 73 | 74 | } else if (qName.equals("Owner")) { 75 | String owner = content.toString(); 76 | //System.out.println("owner:" + owner); 77 | sub.setOwner(owner); 78 | 79 | } else if (qName.equals("member")) { 80 | count++; 81 | subscriptions.add(sub); 82 | sub = null; 83 | 84 | } else if(qName.equals("Topics")) { 85 | //nothing 86 | } else if(qName.equals("NextToken")) { 87 | nextToken = content.toString(); 88 | } 89 | content.reset(); 90 | } 91 | 92 | public void characters( char[] ch, int start, int length ) { 93 | //System.out.println("Characters"); 94 | content.write( ch, start, length ); 95 | } 96 | 97 | public Vector getSubscriptions() { 98 | return subscriptions; 99 | } 100 | 101 | public String getRequestId() { 102 | return requestId; 103 | } 104 | 105 | public int getCount() { 106 | return count; 107 | } 108 | 109 | public String getNextToken() { 110 | return nextToken; 111 | } 112 | } 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /tests/com/comcast/cmb/test/tools/ListTopicsResponseParser.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cmb.test.tools; 17 | 18 | import java.io.CharArrayWriter; 19 | import java.util.Vector; 20 | import java.util.jar.Attributes; 21 | 22 | import org.xml.sax.SAXException; 23 | 24 | public class ListTopicsResponseParser extends org.xml.sax.helpers.DefaultHandler { 25 | 26 | private Vector arns; 27 | private String requestId; 28 | private CharArrayWriter content = new CharArrayWriter(); 29 | private int count = 0; 30 | 31 | public ListTopicsResponseParser() { 32 | arns = new Vector(); 33 | } 34 | 35 | public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { 36 | 37 | content.reset(); 38 | 39 | if(qName.equals("Topics")) { 40 | } 41 | } 42 | 43 | public void endElement (String uri, String localName, String qName) { 44 | 45 | if (qName.equals("TopicArn")) { 46 | String topicArn = content.toString(); 47 | arns.add(topicArn); 48 | } else if (qName.equals("member")) { 49 | count++; 50 | } else if(qName.equals("Topics")) { 51 | //nothing 52 | } 53 | 54 | content.reset(); 55 | } 56 | 57 | public void characters( char[] ch, int start, int length ) { 58 | content.write( ch, start, length ); 59 | } 60 | 61 | public Vector getArns() { 62 | return arns; 63 | } 64 | 65 | public String getRequestId() { 66 | return requestId; 67 | } 68 | 69 | public int getCount() { 70 | return count; 71 | } 72 | } 73 | 74 | -------------------------------------------------------------------------------- /tests/com/comcast/cmb/test/tools/SimpleServletOutputStream.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.comcast.cmb.test.tools; 18 | 19 | import java.io.IOException; 20 | import java.io.OutputStream; 21 | 22 | import javax.servlet.ServletOutputStream; 23 | 24 | public class SimpleServletOutputStream extends ServletOutputStream { 25 | 26 | private OutputStream out = null; 27 | 28 | public SimpleServletOutputStream(OutputStream out) { 29 | this.out = out; 30 | } 31 | 32 | @Override 33 | public void write(int b) throws IOException { 34 | out.write(b); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/com/comcast/cmb/test/tools/SubscribeParser.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cmb.test.tools; 17 | 18 | import java.io.CharArrayWriter; 19 | import java.util.jar.Attributes; 20 | 21 | import org.xml.sax.SAXException; 22 | 23 | 24 | public class SubscribeParser extends org.xml.sax.helpers.DefaultHandler { 25 | private String subscriptionArn; 26 | private String requestId; 27 | private CharArrayWriter content = new CharArrayWriter(); 28 | 29 | public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { 30 | content.reset(); 31 | } 32 | 33 | public void endElement (String uri, String localName, String qName) { 34 | if (qName.equals("SubscriptionArn")) { 35 | subscriptionArn = content.toString(); 36 | } else if (qName.equals("RequestId")) { 37 | requestId = content.toString(); 38 | } 39 | } 40 | 41 | public void characters( char[] ch, int start, int length ) { 42 | content.write( ch, start, length ); 43 | } 44 | 45 | public String getSubscriptionArn() { 46 | return subscriptionArn; 47 | } 48 | 49 | public String getRequestId() { 50 | return requestId; 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /tests/com/comcast/cns/test/stress/README.txt: -------------------------------------------------------------------------------- 1 | # run cns stress test client using run script and pass in parameters: 2 | 3 | ./run.sh -nt=1 -ns=1 -mps=200 -td=10 -tpt=10 http://:/CMB/Endpoint/recv/ 4 | 5 | # publish a single message with curl: 6 | 7 | curl -v -H "Content-Type: application/x-www-form-urlencoded" -X POST --data-binary @post2.data http://:/ 8 | 9 | # run a stress test using ab: 10 | 11 | ab -n 5000 -c 10 -p post2.data -T application/x-www-form-urlencoded http://:/ 12 | 13 | # post data example: 14 | 15 | Action=Publish&AWSAccessKeyId=I6M46U9SK6XW561TMQU3&Subject=stress+test+message&Message=%401333053697939*Thu+Mar+29+13%3A41%3A37+PDT+2012%254XXFEU640Z90WJEARILL5OR7FPOBQD1I70M7U2W3GLYCRFV6P4QRJLYN0V70L31C518RR55D42LCZ8W3FY6LXJIPUDB80RWQ19J6EJ2O3Z6TMWY9US46PE7TYTAAVL46RQ29LOP2HJ9AYK3OP6YC0UERCM9VA8758I235SKXYYLJDKSP49L7UQLKFO33H5O3B5UT2ULWR4RY1W2AKVSWB8EIBWLPC8OPLP7Q03UQK6IOJFWGTBCN7A4A0PR9ADT1LWL7YZYXNJR4WQUOXUO3XCBOF79KT45X8PSF6YMWF0QGEDCKJYIG7WKPGQME0KQN917JNBSJ5RUWHSM64YZBBOLJYFBQIIU5S63Y0Z9AZYPH3B9SIERCRDOVTT31S6CHIQZXBEQ5LS0IZTJOTZL2DJ7YP87YEK0HUOKW286J1MUC132OJ0E2FI8ERP3653R3KX6YA1PQ6ATZ8TXANPAZNXIDRNMWBDB9TSC3N47TTEHAM708EUSUEYMX02T9CS69G5JGXIO84TC51C706GDQWRMCQQSO2PFHMGBL8NX77SOPUXJX7MO0DSJGU8E2CFISMIRD0NOZ5M5IUR66R0RV8RAFR7SM6GV15ALW9PNEMN9ZN3UL9RKO3AQZXRAD3AUY2GU4QV5973M1QGQ5YU731VJYTHRUTIFQL8TAP7E0VBKV7KUYSTDV9CLBE3O26SZHR7O5C22J2ULUH4IGRSAW1HXH9JPTJBTRN0R6PZ2ITS3PYWA6M8IZ3KPAXDHAC4X31RKSQOWQVI6PDKJ2DKW803V1ABTEIGRN2TP4WZMHPF3950JVLS4I8ZXU130SM0NYM1ATNXROEBIAKJSPLS8A38PDEHGS7FP08NKH7XRKRAFBOQ9C1DMRDIELJNFR80QDW0RCWHERBLT9YLY0YUBD6SLK3V15TQCXUYRRIFLYUBP4YRRXJ8AIMBGLBG71LM1SZFBT5WUYDWB3PMLZPP8JHJ1WDILSIW4YN74JK43HJ8EYOSQQJNXZ24M1GIF56NL49WQDL3YTS0NQY2GAQE877XDCL781F8TOT8SM6490L7TF60QWX8J6AWDXN55NZ4IBJEZF8OOCAT5KSTOEGV7IC77KFW1C3HMLS7YFKJXJ5BBTR22H0AFZPRL60XTGBNF28TVESH1Z0WV05FCPSDT2ABKPUF5MRWNJUURQDAHJJ8O6K4NZ455U1H9I27TQJUDY6TX4RLWIXJFQMD5DTL9CI3FH3FSH36EOPNJNYRHEAIJDLL0KZ9ZORMUAUTR7EGGAMNM06W76R4LY26ZT4XFTNIE62GXZAZ12HLPI20R6FQTA5UMYVENN2EN3JLBDPDJ9RXH7KAMQ7QYSEHU19FCG3GE2E6XIT4CGFGUZQ711E69ADDHWCC99WE5O2DIMW1VHQ10ZENID8PAWHCTLKUSSBPIJ4E3GZCWEZK26AAFDQWGNCB4QVCQTT4WS774XE8SQF2P97O3PVXX79QO5GINFADBW7YO4HQ5G9P8W10U1KAUBNXOS0SQBEIZTXU4YGIXATFSQS31T0AMZ0RP59RGW94H5OCSQF4FIOOPFKLAPK6FCMEXZJA1N73NA9MJ1AK6IHMM41EF9MHPAQKQ54P8WSIRM3QMQHP1HOF4TNT61PNASC5QPN5UTKN08631M3LTZIFB1X8L9ICGVOJZMDHUX6SIF7AFDAPNFRCQ9L5RIJHJM6GCGG116SI5HMULQK4ORLG2CTG9U8DO9I2XMC5BSGDTT1VB9YXFQ2QBFRF5QKKBUOAJMGU8KK8NUMPSF0J34MU8HX8HE7JCBV7O30BRQMC52HLLOQJ7H4L2ZS9NVEP6SD8IDH0XDZ5T4HE6BSDW54YLO0O5N4YMEOSNCQI5MRBMWQ0I56PF4J9SXL52F9E0GLGLC7OKSUQ0EH4AHKE1IGYW27UY8I67NL07P9I23C5F6P0MREDOZOM9U2LU0JTKQIREBNO6XP2KSQILTRQEVESAL23W42ZEYPJO2EVHF&TopicArn=arn:cmb:cns:ccp:331756426855:ABC 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/com/comcast/cns/test/stress/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | workingDir="$( cd "$( dirname "$0" )" && pwd )" 4 | cd $workingDir 5 | 6 | THE_CLASSPATH= 7 | for i in `ls *.jar` 8 | do 9 | THE_CLASSPATH=${THE_CLASSPATH}:${i} 10 | done 11 | 12 | echo ${THE_CLASSPATH} 13 | 14 | echo $1 15 | echo $2 16 | echo $3 17 | echo $4 18 | echo $5 19 | echo $6 20 | 21 | java -Xmx1280m -classpath ${THE_CLASSPATH} -Dcmb.log4j.propertyFile=config/log4j.properties -Dcmb.propertyFile=config/cmb.properties com.comcast.cns.test.stress.CNSStressTest $1 $2 $3 $4 $5 $6 22 | -------------------------------------------------------------------------------- /tests/com/comcast/cns/test/unit/CNSSubscriptionTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cns.test.unit; 17 | 18 | public class CNSSubscriptionTest { 19 | 20 | private String topicArn; 21 | private String protocol; 22 | private String subscriptionArn; 23 | private String owner; 24 | private String endpoint; 25 | 26 | /* 27 | * setTopicArn, allows user to set the topic for this testing tool 28 | * @param topicArn 29 | */ 30 | public void setTopicArn(String topicArn) { 31 | this.topicArn = topicArn; 32 | } 33 | 34 | public String getTopicArn() { 35 | return topicArn; 36 | } 37 | 38 | /* 39 | * setProtocol, allows user to set the protocol for this testing tool 40 | * @param protocol 41 | */ 42 | public void setProtocol(String protocol) { 43 | this.protocol = protocol; 44 | } 45 | 46 | public String getProtocol() { 47 | return protocol; 48 | } 49 | 50 | /* 51 | * setSubscriptionArn, allows user to set the subscriptionArn for this testing tool 52 | * @param subscriptionArn 53 | */ 54 | public void setSubscriptionArn(String subscriptionArn) { 55 | this.subscriptionArn = subscriptionArn; 56 | } 57 | 58 | public String getSubscriptionArn() { 59 | return subscriptionArn; 60 | } 61 | 62 | public void setOwner(String owner) { 63 | this.owner = owner; 64 | } 65 | 66 | public String getOwner() { 67 | return owner; 68 | } 69 | 70 | public void setEndpoint(String endpoint) { 71 | this.endpoint = endpoint; 72 | } 73 | 74 | public String getEndpoint() { 75 | return endpoint; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /tests/com/comcast/cqs/test/stress/cqs.stresstest.properties: -------------------------------------------------------------------------------- 1 | #lifetime attributes 2 | 3 | cmb.cqs.stress.testDurationSeconds=20 4 | cmb.cqs.stress.messagesPerQueuePerSecond=1000 5 | 6 | #queue attributes 7 | 8 | cmb.cqs.stress.numberOfQueues=3 9 | cmb.cqs.stress.queueNames=BWQ-000000000001,BWQ-000000000002,BWQ-000000000003 10 | cmb.cqs.stress.numberOfSendersPerQueue=4 11 | cmb.cqs.stress.numberOfReceiversPerQueue=15 12 | cmb.cqs.stress.revisiblePercentage=0 13 | 14 | #batch parameters 15 | 16 | cmb.cqs.stress.sendMessageBatchSize=1 17 | cmb.cqs.stress.receiveMessageBatchSize=1 18 | 19 | #throttle parameters 20 | 21 | cmb.cqs.stress.delayBetweenSendsMS=0 22 | cmb.cqs.stress.delayBetweenReceivesMS=3 23 | cmb.cqs.stress.delayBetweenReceiveAndDeleteMS=10 24 | 25 | -------------------------------------------------------------------------------- /tests/com/comcast/cqs/test/stress/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | workingDir="$( cd "$( dirname "$0" )" && pwd )" 4 | cd $workingDir 5 | 6 | THE_CLASSPATH= 7 | for i in `ls *.jar` 8 | do 9 | THE_CLASSPATH=${THE_CLASSPATH}:${i} 10 | done 11 | 12 | echo ${THE_CLASSPATH} 13 | 14 | echo $1 15 | echo $2 16 | echo $3 17 | echo $4 18 | echo $5 19 | echo $6 20 | 21 | java -Xmx1280m -classpath ${THE_CLASSPATH} -Dcqs.stresstest.properties=config/cqs.stresstest.properties -Dcmb.log4j.propertyFile=config/log4j.properties -Dcmb.propertyFile=config/cmb.properties com.comcast.cqs.test.stress.CqsStressTester $1 $2 $3 $4 $5 $6 22 | -------------------------------------------------------------------------------- /tests/com/comcast/cqs/test/stress/run2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | workingDir="$( cd "$( dirname "$0" )" && pwd )" 4 | cd $workingDir 5 | 6 | THE_CLASSPATH= 7 | for i in `ls *.jar` 8 | do 9 | THE_CLASSPATH=${THE_CLASSPATH}:${i} 10 | done 11 | 12 | echo ${THE_CLASSPATH} 13 | 14 | echo $1 15 | echo $2 16 | echo $3 17 | echo $4 18 | echo $5 19 | echo $6 20 | 21 | java -Xmx1280m -classpath ${THE_CLASSPATH} -Dcmb.log4j.propertyFile=config/log4j.properties -Dcmb.propertyFile=config/cmb.properties com.comcast.cqs.test.unit.CQSScaleQueuesTest $1 $2 $3 $4 $5 $6 22 | -------------------------------------------------------------------------------- /tests/com/comcast/cqs/test/unit/CQSMonitorTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cqs.test.unit; 17 | 18 | import static org.junit.Assert.*; 19 | 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | 23 | import com.comcast.cmb.common.controller.CMBControllerServlet; 24 | import com.comcast.cmb.common.util.Util; 25 | import com.comcast.cqs.controller.CQSMonitor; 26 | import com.comcast.cqs.controller.CQSMonitor.CacheType; 27 | 28 | public class CQSMonitorTest { 29 | 30 | @Before 31 | public void setup() throws Exception { 32 | Util.initLog4jTest(); 33 | CMBControllerServlet.valueAccumulator.initializeAllCounters(); 34 | CQSMonitor.getInstance().clearAllState(); 35 | } 36 | 37 | @Test 38 | public void testMessageCount() { 39 | CQSMonitor.getInstance().addNumberOfMessagesReturned("test", 10); 40 | CQSMonitor.getInstance().addNumberOfMessagesReturned("test", 10); 41 | if (CQSMonitor.getInstance().getRecentNumberOfReceives("test") != 20) { 42 | fail("Expected 20 messages. Got=" + CQSMonitor.getInstance().getRecentNumberOfReceives("test")); 43 | } 44 | } 45 | 46 | @Test 47 | public void testCacheHit() { 48 | CQSMonitor.getInstance().registerCacheHit("test", 5, 10, CacheType.QCache); 49 | CQSMonitor.getInstance().registerCacheHit("test", 5, 10, CacheType.QCache); 50 | //should be 50% hit 51 | if (CQSMonitor.getInstance().getCacheHitPercent("test", CacheType.QCache) != 50) { 52 | fail("Expected 50% Got=" + CQSMonitor.getInstance().getCacheHitPercent("test", CacheType.QCache)); 53 | } 54 | } 55 | 56 | @Test 57 | public void testNumMessages() { 58 | CQSMonitor.getInstance().addNumberOfMessagesReceived("test", 1); 59 | if (CQSMonitor.getInstance().getRecentNumberOfSends("test") != 1) { 60 | fail("Expected 1. Got:" + CQSMonitor.getInstance().getRecentNumberOfSends("test")); 61 | } 62 | CQSMonitor.getInstance().addNumberOfMessagesReturned("test", 1); 63 | if (CQSMonitor.getInstance().getRecentNumberOfReceives("test") != 1) { 64 | fail("Expected 0. Got:" + CQSMonitor.getInstance().getRecentNumberOfReceives("test")); 65 | } 66 | 67 | if (CQSMonitor.getInstance().getNumberOfMessagesDeleted("test") != 1) { 68 | fail("Expected 1. Got:" + CQSMonitor.getInstance().getNumberOfMessagesDeleted("test")); 69 | } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /tests/com/comcast/cqs/test/unit/CQSRedisCachedCassandraPersistenceTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cqs.test.unit; 17 | 18 | public class CQSRedisCachedCassandraPersistenceTest { 19 | } 20 | -------------------------------------------------------------------------------- /tests/com/comcast/cqs/test/unit/CQSRedisSortedSetPersistenceTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Comcast Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.comcast.cqs.test.unit; 17 | 18 | public class CQSRedisSortedSetPersistenceTest { 19 | } 20 | --------------------------------------------------------------------------------