-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SPARK-28222 Reap docker postgres container after mvn generate-sources
- Loading branch information
Showing
5 changed files
with
235 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
117 changes: 117 additions & 0 deletions
117
tcp-msg-maven-plugin/src/main/java/com/lgi/commons/maven/TcpMessagingMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |