Skip to content

Instantly share code, notes, and snippets.

View ableasdale's full-sized avatar

Alex Bleasdale ableasdale

View GitHub Profile

Kafka and mTLS Walkthrough

Creating a Certificate Authority (CA)

Build the Certificate

openssl req -new -newkey rsa:4096 -days 365 -x509 -subj "/CN=Kafka-Security-CA" -keyout ca-key -out ca-cert -nodes
@ableasdale
ableasdale / hosts.yml
Last active September 23, 2021 19:49
cp-ansible - minimal kafka setup (hosts.yml)
all:
vars:
ksql_service_environment_overrides:
KSQL_HEAP_OPTS: "-Xmx7g"
kafka_broker_service_environment_overrides:
KAFKA_HEAP_OPTS: "-Xmx5g"
ansible_connection: ssh
ansible_user: centos
ansible_become: true
# ansible_ssh_private_key_file: /home/centos/.ssh/key.pem
@ableasdale
ableasdale / parse-javadoc-28.xqy
Created June 4, 2021 12:23
Kafka Streams JavaDoc (API Docs v2.8) - get methods and text descriptions and generate a card for each item (uses bootstrap.js)
xquery version "1.0-ml";
xdmp:save("/Users/ableasdale/javadoc28.html",
element html { attribute lang {"en"},
element head {
element meta {attribute charset {"utf-8"}},
element meta {attribute name {"viewport"}, attribute content {"width=device-width, initial-scale=1"}},
element link {
attribute href {"https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css"},
attribute rel {"stylesheet"},
@ableasdale
ableasdale / parse-javadoc.xqy
Created June 4, 2021 10:38
Kafka Streams JavaDoc (v1.0.0) - get methods and text descriptions and generate an HTML definition list (uses bootstrap.js)
xquery version "1.0-ml";
xdmp:save("/Users/ableasdale/javadoc.html",
element html { attribute lang {"en"},
element head {
element meta {attribute charset {"utf-8"}},
element meta {attribute name {"viewport"}, attribute content {"width=device-width, initial-scale=1"}},
element link {
attribute href {"https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css"},
attribute rel {"stylesheet"},
@ableasdale
ableasdale / DMSDKBatch.java
Created May 20, 2021 15:21
MarkLogic Data Movement SDK - Batcher Example
import com.marklogic.client.DatabaseClient;
import com.marklogic.client.DatabaseClientFactory;
import com.marklogic.client.datamovement.DataMovementManager;
import com.marklogic.client.datamovement.QueryBatcher;
import com.marklogic.client.query.StructuredQueryBuilder;
import com.marklogic.client.query.StructuredQueryDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.invoke.MethodHandles;
@ableasdale
ableasdale / search-results-to-zip.xqy
Created February 23, 2021 16:05
MarkLogic: return a subset of the database as a downloadable zip file
xquery version "1.0-ml";
declare variable $TARGET-FILENAME as xs:string := "/tmp/"||xdmp:random()||".zip";
declare variable $URIS as xs:string* := cts:uris((), ("limit=100"));
declare function local:write-zipfile() {
let $zip := xdmp:zip-create(
<parts xmlns="xdmp:zip">{$URIS ! element part {.}}</parts>,
($URIS ! doc(.))
)
@ableasdale
ableasdale / directory-fragment-delete.xqy
Created December 11, 2020 14:58
MarkLogic: Remove a problem directory fragment in an event where you encounter XDMP-DBDUPURI issues
xquery version "1.0-ml";
(:
A Utility module to allow the deletion of a directory fragment in a given forest in the event of
an XDMP-DBDUPURI exception.
:)
let $doc := "/" (: URI for the conflicting directory that is causing an XDMP-DBDUPURI to be reported in 2 forests :)
let $forest-name := "forest_00" (: The name of the forest from which the problem directory fragment should be removed :)
@ableasdale
ableasdale / duplicate-uri-lookup.xqy
Created December 11, 2020 14:41
MarkLogic: Look up duplicate URIs using the URI Lexicon (for troubleshooting XDMP-DBDUPURI exceptions)
xquery version "1.0-ml";
(:
A Utility module to allow the detection of duplicate URIs for a given database
This can be used in any situation where XDMP-DBDUPURI messages are found in the ErrorLogs
URIs are sorted by frequency order so higher frequencies (e.g. > 1) indicate that the URI
has been found in more than one forest
This module requires the uri lexicon to be enabled on your database
@ableasdale
ableasdale / delete-one-fragment.xqy
Created December 11, 2020 12:19
MarkLogic: Delete one document after inspecting both duplicates in the event of an XDMP-DBDUPURI
xquery version "1.0-ml";
(:
A Utility module to allow the deletion of a fragment in a given forest in the event of
an XDMP-DBDUPURI exception.
Given the following exception:
XDMP-DBDUPURI: URI /problem/uri.xml found in forests Library06 and Library07
$doc would be set to "/problem/uri.xml"
@ableasdale
ableasdale / duplicate-uri.xqy
Last active December 11, 2020 12:11
MarkLogic: Manual inspection of a document found in 2 forests in the event of an XDMP-DBDUPURI exception
xquery version "1.0-ml";
(:
A Utility module for viewing duplicate document/properties fragment information in situations
where MarkLogic Server reports an XDMP-DBDUPURI exception.
An XDMP-DBDUPURI will be thrown by MarkLogic in any situation where a document at a given URI
appears to exist in more than one forest in a given database; example:
XDMP-DBDUPURI: URI /problem/uri.xml found in forests Library06 and Library07