Skip to content

Commit

Permalink
SPARK-28222 Reap docker postgres container after mvn generate-sources
Browse files Browse the repository at this point in the history
  • Loading branch information
alewir authored and alewir committed Nov 30, 2020
1 parent 378401a commit 64a79c5
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 8 deletions.
12 changes: 11 additions & 1 deletion LICENSE-THIRD-PARTY.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Lists of 155 third-party dependencies.
Lists of 165 third-party dependencies.
(Eclipse Public License - v 1.0) (GNU Lesser General Public License) Logback Classic Module (ch.qos.logback:logback-classic:1.2.3 - http://logback.qos.ch/logback-classic)
(Eclipse Public License - v 1.0) (GNU Lesser General Public License) Logback Core Module (ch.qos.logback:logback-core:1.2.3 - http://logback.qos.ch/logback-core)
(The Apache License, Version 2.0) spock-reports (com.athaydes:spock-reports:1.7.1 - https://github.com/renatoathaydes/spock-reports)
Expand Down Expand Up @@ -51,6 +51,9 @@ Lists of 155 third-party dependencies.
(Eclipse Distribution License - v 1.0) Jakarta XML Binding API (jakarta.xml.bind:jakarta.xml.bind-api:2.3.3 - https://github.com/eclipse-ee4j/jaxb-api/jakarta.xml.bind-api)
(COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0) JavaBeans(TM) Activation Framework (javax.activation:activation:1.1.1 - http://java.sun.com/javase/technologies/desktop/javabeans/jaf/index.jsp)
(CDDL/GPLv2+CE) JavaBeans Activation Framework API jar (javax.activation:javax.activation-api:1.2.0 - http://java.net/all/javax.activation-api/)
(COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0) JSR-250 Common Annotations for the JavaTM Platform (javax.annotation:jsr250-api:1.0 - http://jcp.org/aboutJava/communityprocess/final/jsr250/index.html)
(Apache License, Version 2.0) CDI APIs (javax.enterprise:cdi-api:1.0 - http://www.seamframework.org/Weld/cdi-api)
(The Apache Software License, Version 2.0) javax.inject (javax.inject:javax.inject:1 - http://code.google.com/p/atinject/)
(CDDL 1.1) (GPL2 w/ CPE) jaxb-api (javax.xml.bind:jaxb-api:2.3.1 - https://github.com/javaee/jaxb-spec/jaxb-api)
(Eclipse Public License 1.0) JUnit (junit:junit:4.13 - http://junit.org)
(Apache License, Version 2.0) Byte Buddy (without dependencies) (net.bytebuddy:byte-buddy:1.10.14 - https://bytebuddy.net/byte-buddy)
Expand All @@ -66,6 +69,10 @@ Lists of 155 third-party dependencies.
(Apache License, Version 2.0) Apache HttpClient Mime (org.apache.httpcomponents:httpmime:4.5.12 - http://hc.apache.org/httpcomponents-client)
(Apache License, Version 2.0) Apache Log4j API (org.apache.logging.log4j:log4j-api:2.13.3 - https://logging.apache.org/log4j/2.x/log4j-api/)
(Apache License, Version 2.0) Apache Log4j to SLF4J Adapter (org.apache.logging.log4j:log4j-to-slf4j:2.13.3 - https://logging.apache.org/log4j/2.x/log4j-to-slf4j/)
(Apache License, Version 2.0) Maven Artifact (org.apache.maven:maven-artifact:3.6.3 - https://maven.apache.org/ref/3.6.3/maven-artifact/)
(Apache License, Version 2.0) Maven Model (org.apache.maven:maven-model:3.6.3 - https://maven.apache.org/ref/3.6.3/maven-model/)
(Apache License, Version 2.0) Maven Plugin API (org.apache.maven:maven-plugin-api:3.6.3 - https://maven.apache.org/ref/3.6.3/maven-plugin-api/)
(Apache License, Version 2.0) Maven Plugin Tools Java Annotations (org.apache.maven.plugin-tools:maven-plugin-annotations:3.6.0 - https://maven.apache.org/plugin-tools/maven-plugin-annotations)
(The Apache Software License, Version 2.0) Apache Sling javax.activation bundle (org.apache.sling:org.apache.sling.javax.activation:0.1.0 - http://sling.apache.org/org.apache.sling.javax.activation)
(Apache License, Version 2.0) Apache Tika core (org.apache.tika:tika-core:1.24.1 - http://tika.apache.org/)
(Apache License, Version 2.0) tomcat-embed-core (org.apache.tomcat.embed:tomcat-embed-core:9.0.38 - https://tomcat.apache.org/)
Expand All @@ -82,6 +89,9 @@ Lists of 155 third-party dependencies.
(The Apache Software License, Version 2.0) Apache Groovy (org.codehaus.groovy:groovy-templates:2.5.13 - https://groovy-lang.org)
(The Apache Software License, Version 2.0) Apache Groovy (org.codehaus.groovy:groovy-test:2.5.13 - https://groovy-lang.org)
(The Apache Software License, Version 2.0) Apache Groovy (org.codehaus.groovy:groovy-xml:2.5.13 - https://groovy-lang.org)
(Apache License, Version 2.0) Plexus Classworlds (org.codehaus.plexus:plexus-classworlds:2.6.0 - http://codehaus-plexus.github.io/plexus-classworlds/)
(The Apache Software License, Version 2.0) Plexus :: Component Annotations (org.codehaus.plexus:plexus-component-annotations:1.5.5 - http://plexus.codehaus.org/plexus-containers/plexus-component-annotations/)
(Apache License, Version 2.0) Plexus Common Utilities (org.codehaus.plexus:plexus-utils:3.2.1 - http://codehaus-plexus.github.io/plexus-utils/)
(Apache License, Version 2.0) flyway-core (org.flywaydb:flyway-core:6.4.4 - https://flywaydb.org/flyway-core)
(Apache License, Version 2.0) Apache FreeMarker (org.freemarker:freemarker:2.3.30 - https://freemarker.apache.org/)
(EPL 2.0) (GPL2 w/ CPE) Jakarta Expression Language 3.0 (org.glassfish:jakarta.el:3.0.3 - https://projects.eclipse.org/projects/ee4j.el)
Expand Down
60 changes: 53 additions & 7 deletions appstore-metadata-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<db.name>postgres</db.name>
<db.host>localhost</db.host>
<db.port>46576</db.port>
<ryuk.port>46577</ryuk.port>
<db.schema>appstore_metadata_service</db.schema>
<db.url>jdbc:postgresql://${db.host}:${db.port}/${db.name}</db.url>
<db.driver>org.postgresql.Driver</db.driver>
Expand All @@ -26,9 +27,21 @@
<maven.jib.plugin.version>2.2.0</maven.jib.plugin.version>
<scmBranch>current</scmBranch>
<scmCommit>latest</scmCommit>
<sock-dir-docker-host>/var/run/docker.sock</sock-dir-docker-host>
</properties>

<profiles>
<profile>
<id>windows-specific-settings</id>
<activation>
<os>
<family>Windows</family>
</os>
</activation>
<properties>
<sock-dir-docker-host>//var/run/docker.sock</sock-dir-docker-host>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
Expand Down Expand Up @@ -142,12 +155,48 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.lgi.common.maven</groupId>
<artifactId>tcp-msg-maven-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<executions>
<execution>
<id>write-death-note-for-postgres</id>
<phase>generate-sources</phase>
<goals>
<goal>tcpmsg</goal>
</goals>
<configuration>
<port>${ryuk.port}</port>
<msg>label=killme</msg>
<repeatAmount>6</repeatAmount>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.34.0</version>
<configuration>
<logStdout>true</logStdout>
<verbose>true</verbose>
<images>
<image>
<alias>ryuk-summoned</alias>
<name>testcontainers/ryuk:0.3.0</name>
<run>
<ports>
<port>ryuk.port:8080</port>
</ports>
<volumes>
<bind>
<volume>${sock-dir-docker-host}:/var/run/docker.sock</volume>
</bind>
</volumes>
<autoRemove>true</autoRemove>
</run>
</image>
<image>
<alias>postgres</alias>
<name>postgres:11</name>
Expand All @@ -161,6 +210,10 @@
<wait>
<time>5000</time>
</wait>
<autoRemove>true</autoRemove>
<labels>
<killme>true</killme>
</labels>
</run>
</image>
</images>
Expand All @@ -173,13 +226,6 @@
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-postgres</id>
<phase>process-sources</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
Expand Down
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<modules>
<module>appstore-metadata-service</module>
<module>appstore-metadata-service-tests</module>
<module>tcp-msg-maven-plugin</module>
</modules>

<properties>
Expand Down Expand Up @@ -64,6 +65,8 @@
The MIT License|${line.separator}
The MIT License (MIT)
</license.includedLicenses>
<license.excludedGroups>(^org\.eclipse\.sisu)|(^com\.sun\.xml\.bind)
</license.excludedGroups> <!-- dependencies of maven-plugin-api -->
</properties>

<distributionManagement>
Expand Down
51 changes: 51 additions & 0 deletions tcp-msg-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>appstore-metadata-service-parent</artifactId>
<groupId>com.lgi.appstore.metadata</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<groupId>com.lgi.common.maven</groupId>
<artifactId>tcp-msg-maven-plugin</artifactId>

<packaging>maven-plugin</packaging>
<modelVersion>4.0.0</modelVersion>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.6.3</version>
</dependency>

<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>default-descriptor</id>
<phase>process-classes</phase>
</execution>
<execution>
<id>help-goal</id>
<goals>
<goal>helpmojo</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package com.lgi.commons.maven;

/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.stream.IntStream;


@Mojo(name = "tcpmsg")
public class TcpMessagingMojo extends AbstractMojo {
private static final String LOG_PREFIX = "maven-tcpmsg";

@Parameter(property = "tcpmsg.host", defaultValue = "localhost")
private String host;

@Parameter(property = "tcpmsg.repeatAmount", defaultValue = "1")
private Integer repeatAmount;

@Parameter(property = "tcpmsg.intervalSec", defaultValue = "5")
private Integer intervalSec;

@Parameter(property = "tcpmsg.port")
private Integer port;

@Parameter(property = "tcpmsg.command")
private String msg;

@Override
public void execute() throws MojoExecutionException {
if (port == null) {
getLog().error("Please specify 'port' param. of TCP socket.");
throw new MojoExecutionException(getPluginContext().keySet().toString());
} else if (msg == null) {
getLog().warn("Please specify 'msg' param. with message to send.");
} else {
doCommunicate();
}
}

private void doCommunicate() {
Thread communicationChannel = new Thread(
new ThreadGroup(LOG_PREFIX),
this::sendMessages,
String.format("%s-send", LOG_PREFIX)
);
communicationChannel.setDaemon(true);
communicationChannel.start();
}

private void sendMessages() {
IntStream.range(0, repeatAmount).forEach(attempt -> {
sleepForConfiguredInterval();
getLog().info(String.format("%s: Attempting [%d] to send message '%s' to TCP socket on %s:%d", LOG_PREFIX, attempt, msg, host, port));
handleSendAttempt();
});
}

private void sleepForConfiguredInterval() {
try {
Thread.sleep(intervalSec * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

private void handleSendAttempt() {
try (Socket clientSocket = new Socket(host, port)) {
try (PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true)) {
try (BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()))) {
String response = communicate(in, out);
getLog().info(String.format("%s: Received: %s", LOG_PREFIX, response));
}
}
} catch (IOException e) {
logSocketIssue(e);
}
}

private String communicate(BufferedReader in, PrintWriter out) {
try {
out.println(msg);
return in.readLine();
} catch (IOException e) {
String errorMsg = String.format("%s: Issue with sending message '%s' to TCP socket on %s:%d: %s - %s", LOG_PREFIX, msg, host, port, e.getClass().getSimpleName(), e.getMessage());
getLog().error(errorMsg);
return null;
}
}

private void logSocketIssue(Exception e) {
String warnMsg = String.format("%s: Issue with connection to TCP socket on %s:%d - %s: %s", LOG_PREFIX, host, port, e.getClass().getSimpleName(), e.getMessage());
getLog().warn(warnMsg);
}
}

0 comments on commit 64a79c5

Please sign in to comment.