Skip to content

Commit

Permalink
Add endpoint for checking for running Polypheny instances
Browse files Browse the repository at this point in the history
  • Loading branch information
vogti committed Dec 16, 2023
1 parent ba013d9 commit 369b611
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
Expand Up @@ -174,6 +174,11 @@ String getStatus() {
}


boolean checkForAnyRunningPolyphenyInstances() {
return Boolean.parseBoolean( executeGet( "/control/checkAnyRunningPolyphenyInstances" ) );
}


private String executeGet( String command ) {
HttpResponse<String> httpResponse;
try {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/polypheny/control/control/Control.java
Expand Up @@ -158,6 +158,11 @@ public void getStatus( Context ctx ) {
}


public void checkAnyRunningPolyphenyInstances( Context ctx ) {
ctx.result( ServiceManager.getPidOfRunningPolyphenyInstances().size() + "" );
}


public void getVersion( Context ctx ) {
ctx.result( gson.toJson( ServiceManager.getVersion() ) );
}
Expand Down
Expand Up @@ -263,7 +263,6 @@ public void killForcibly() {
} catch ( InterruptedException e ) {
log.warn( "Interrupted while waiting for kill to finish." );
}

} else {
super.process.destroyForcibly();
}
Expand Down
30 changes: 28 additions & 2 deletions src/main/java/org/polypheny/control/control/ServiceManager.java
Expand Up @@ -179,10 +179,10 @@ public static boolean start( final ClientCommunicationStream clientCommunication
//

LinkedList<String> javaOptionsFull = new LinkedList<>( javaOptions );
String applicationConfFileName = new File( new File( workingDir ), "config" ).getAbsolutePath() + File.separator + "application.conf";
/*String applicationConfFileName = new File( new File( workingDir ), "config" ).getAbsolutePath() + File.separator + "application.conf";
if ( new File( applicationConfFileName ).exists() ) {
javaOptionsFull.addFirst( "-Dconfig.file=" + applicationConfFileName );
}
}*/
javaOptionsFull.addFirst( "-Xmx" + javaMaximumHeapSize + "G" );

// Build list of arguments
Expand Down Expand Up @@ -992,6 +992,32 @@ public static Object getStatus() {
}


public static List<Integer> getPidOfRunningPolyphenyInstances() {
if ( SystemUtils.IS_OS_WINDOWS ) {
throw new RuntimeException( "This operation is not supported on Windows" );
}
try {
List<Integer> pids = new ArrayList<>();
Process process = Runtime.getRuntime().exec( "ps aux|grep org.polypheny.db.PolyphenyDb|grep -v grep|awk '{print $2}'" );
try ( BufferedReader input = new BufferedReader( new InputStreamReader( process.getInputStream() ) ) ) {
String line;
while ( (line = input.readLine()) != null ) {
int id = Integer.parseInt( line );
if ( polyphenyDbProcess != null && id != polyphenyDbProcess.getPid() ) {
log.warn( "There is a running Polypheny instance, but it has a unknown PID: {}", id );
}
pids.add( id );
}
} catch ( IOException e ) {
throw new RuntimeException( "IOException while checking if there are other instances of Polypheny.", e );
}
return pids;
} catch ( IOException e ) {
throw new RuntimeException( "IOException while checking if there are other instances of Polypheny.", e );
}
}


private static boolean existsLocalBranchWithName( Git git, String branchName ) throws GitAPIException {
List<Ref> branches = git.branchList().call();
for ( Ref ref : branches ) {
Expand Down
Expand Up @@ -146,6 +146,7 @@ public Server( Control control, int port ) {
javalin.get( "/control/pdbBranches", control::getAvailablePdbBranches );
javalin.get( "/control/puiBranches", control::getAvailablePuiBranches );
javalin.post( "/control/purgePolyphenyFolder", control::purgePolyphenyFolder );
javalin.get( "/control/checkAnyRunningPolyphenyInstances", control::checkAnyRunningPolyphenyInstances );

// /polyfier
javalin.post( "/polyfier/start", control::polyfierStart );
Expand Down

0 comments on commit 369b611

Please sign in to comment.