Skip to content

Commit

Permalink
Remove maven dependency from ccloud demo
Browse files Browse the repository at this point in the history
  • Loading branch information
vdesabou committed Dec 27, 2019
1 parent a5469a5 commit b44cb51
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 32 deletions.
1 change: 0 additions & 1 deletion ccloud/ccloud-demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ If you choose to run it against your Confluent Cloud cluster, be aware that it:
* Local install of the new [Confluent Cloud CLI](https://docs.confluent.io/current/cloud/cli/install.html#ccloud-install-cli) v0.192.0 or above
* [An initialized Confluent Cloud cluster used for development only](https://confluent.cloud)
* [Confluent CLI](https://docs.confluent.io/current/cli/installing.html) installed on your machine, version `v0.128.0` or higher (note: as of CP 5.3, the Confluent CLI is a separate [download](https://docs.confluent.io/current/cli/installing.html)
* `mvn` installed on your host

## How to run

Expand Down
11 changes: 11 additions & 0 deletions ccloud/ccloud-demo/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ services:

stream:
build: streams/
hostname: stream
container_name: stream
environment:
BOOTSTRAP_SERVERS: $BOOTSTRAP_SERVERS
SCHEMA_REGISTRY_URL: $SCHEMA_REGISTRY_URL
Expand All @@ -242,6 +244,8 @@ services:

producer:
build: producer/
hostname: producer
container_name: producer
environment:
BOOTSTRAP_SERVERS: $BOOTSTRAP_SERVERS
SCHEMA_REGISTRY_URL: $SCHEMA_REGISTRY_URL
Expand All @@ -258,6 +262,8 @@ services:

consumer:
build: consumer/
hostname: consumer
container_name: consumer
environment:
BOOTSTRAP_SERVERS: $BOOTSTRAP_SERVERS
SCHEMA_REGISTRY_URL: $SCHEMA_REGISTRY_URL
Expand All @@ -272,6 +278,11 @@ services:
- jmx-exporter
- stream

producer-acl:
build: producer-acl/
hostname: producer-acl
container_name: producer-acl

jmx-exporter:
build: ./jmx-exporter
hostname: jmx-exporter
Expand Down
9 changes: 9 additions & 0 deletions ccloud/ccloud-demo/producer-acl/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM maven:3.6.1-jdk-8 as mavenBuild
COPY pom.xml pom.xml
COPY src src
RUN ["mvn", "install"]

FROM confluentinc/cp-base:5.3.1
COPY --from=mavenBuild ./target/*.jar ./
ENV JAVA_OPTS ""
CMD sleep infinity
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,6 @@

public class ProducerExample {

// Create topic in Confluent Cloud
public static void createTopic(final String topic,
final int partitions,
final int replication,
final Properties cloudConfig) {
final NewTopic newTopic = new NewTopic(topic, partitions, (short) replication);
try (final AdminClient adminClient = AdminClient.create(cloudConfig)) {
adminClient.createTopics(Collections.singletonList(newTopic)).all().get();
} catch (final InterruptedException | ExecutionException e) {
// Ignore if TopicExistsException, which may be valid if topic exists
if (!(e.getCause() instanceof TopicExistsException)) {
throw new RuntimeException(e);
}
}
}

public static void main(final String[] args) throws IOException {
if (args.length != 2) {
System.out.println("Please provide command line arguments: configPath topic");
Expand All @@ -51,10 +35,7 @@ public static void main(final String[] args) throws IOException {
// sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="<CLUSTER_API_KEY>" password="<CLUSTER_API_SECRET>";
// security.protocol=SASL_SSL
final Properties props = loadConfig(args[0]);

// Create topic if needed
final String topic = args[1];
createTopic(topic, 1, 3, props);

// Add additional properties.
props.put(ProducerConfig.ACKS_CONFIG, "all");
Expand Down
19 changes: 7 additions & 12 deletions ccloud/ccloud-demo/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ fi

source ${DIR}/../../ccloud/ccloud-demo/Utils.sh

verify_installed "mvn"
verify_installed "ccloud"
check_ccloud_version 0.192.0 || exit 1
verify_installed "confluent"
Expand Down Expand Up @@ -56,11 +55,12 @@ sed -e "s|:BOOTSTRAP_SERVERS:|$BOOTSTRAP_SERVERS|g" \
-e "s|:CLOUD_SECRET:|$CLOUD_SECRET|g" \
${DIR}/kafka-lag-exporter/application.template.conf > ${DIR}/kafka-lag-exporter/application.conf


# kafka-topics --bootstrap-server `grep "^\s*bootstrap.server" ${CONFIG_FILE} | tail -1` --command-config ${CONFIG_FILE} --topic customer-avro --create --replication-factor 3 --partitions 6

set +e
create_topic customer-avro
set -e
# set +e
# create_topic customer-avro
# set -e

docker-compose down -v
docker-compose up -d
Expand Down Expand Up @@ -236,7 +236,6 @@ cat $CLIENT_CONFIG
# ACLs are configured
##################################################

POM=./producer-acl/pom.xml
TOPIC_ACL="demo-acl-topic"
set +e
create_topic $TOPIC_ACL
Expand All @@ -246,13 +245,9 @@ echo -e "\033[0;33mccloud kafka acl list --service-account-id $SERVICE_ACCOUNT_I
ccloud kafka acl list --service-account-id $SERVICE_ACCOUNT_ID

echo -e "\n# Run the Java producer to $TOPIC_ACL: before ACLs"
mvn -q -f $POM clean package
if [[ $? != 0 ]]; then
echo -e "\033[0;33mERROR: There seems to be a build failure error compiling the client code? Please troubleshoot\033[0m"
exit 1
fi
LOG1="/tmp/log.1"
java -jar ./producer-acl/target/producer-acl-1.0.0-jar-with-dependencies.jar $CLIENT_CONFIG $TOPIC_ACL > $LOG1 2>&1
docker cp $CLIENT_CONFIG producer-acl:/tmp/
docker exec producer-acl bash -c "java -jar producer-acl-1.0.0-jar-with-dependencies.jar $CLIENT_CONFIG $TOPIC_ACL" > $LOG1 2>&1
echo -e "\033[0;33m# Check logs for 'org.apache.kafka.common.errors.TopicAuthorizationException'\033[0m"
OUTPUT=$(grep "org.apache.kafka.common.errors.TopicAuthorizationException" $LOG1)
if [[ ! -z $OUTPUT ]]; then
Expand All @@ -271,7 +266,7 @@ sleep 20

echo -e "\n# Run the Java producer to $TOPIC_ACL: after ACLs"
LOG2="/tmp/log.2"
java -jar ./producer-acl/target/producer-acl-1.0.0-jar-with-dependencies.jar $CLIENT_CONFIG $TOPIC_ACL > $LOG2 2>&1
docker exec producer-acl bash -c "java -jar producer-acl-1.0.0-jar-with-dependencies.jar $CLIENT_CONFIG $TOPIC_ACL" > $LOG2 2>&1
echo -e "\033[0;33m# Check logs for '10 messages were produced to topic'\033[0m"
OUTPUT=$(grep "10 messages were produced to topic" $LOG2)
if [[ ! -z $OUTPUT ]]; then
Expand Down

0 comments on commit b44cb51

Please sign in to comment.