Skip to content

Commit

Permalink
Improve docker handling and host information pages (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
gartens authored and danylokravchenko committed Jan 9, 2024
1 parent 2e00ee6 commit 82730fb
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 158 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ _Polypheny-DB_ builds upon the great work of several other projects:
* [Apache Calcite](https://calcite.apache.org/): A framework for building databases
* [HSQLDB](http://hsqldb.org/): A relational database written in Java
* [JavaCC](https://javacc.org/): A parser generator
* [Java Spark](http://sparkjava.com/): A framework for building web services
* [Javalin](https://javalin.io/): A framework for building web services
* [Project Lombok](https://projectlombok.org/): A library which provides annotations for tedious tasks

Except for the first two, those projects are used "as is" and integrated as a library. _Apache Avatica_ we [forked](https://github.com/polypheny/Avatica) and made some Polypheny-DB specific adjustments. From _Apache Calcite_ we use parts of the code as foundation for Polypheny-DB.
Expand Down
16 changes: 9 additions & 7 deletions core/src/main/java/org/polypheny/db/docker/DockerContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,15 @@ public void destroy() {
// TODO: When not connected, record these IDs in a list and remove them the next time they are encountered
getDockerInstance().ifPresent( d -> d.destroyContainer( this ) );
containers.remove( containerId );
proxies.forEach( ( k, v ) -> {
try {
v.close();
} catch ( IOException ignore ) {
// ignore
}
} );
synchronized ( this ) {
proxies.forEach( ( k, v ) -> {
try {
v.close();
} catch ( IOException ignore ) {
// ignore
}
} );
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,11 @@ void destroyContainer( DockerContainer container ) {
uuids.remove( container.getContainerId() );
client.deleteContainer( container.getContainerId() );
} catch ( IOException e ) {
log.error( "Failed to delete container with UUID " + container.getContainerId(), e );
if ( e.getMessage().startsWith( "No such container" ) ) {
log.info( "Cannot delete container: No container with UUID " + container.getContainerId() );
} else {
log.error( "Failed to delete container with UUID " + container.getContainerId(), e );
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.polypheny.db.docker;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.time.Instant;
import java.util.HashMap;
Expand Down Expand Up @@ -149,7 +150,8 @@ private Handshake( String hostname, String registry, int communicationPort, int

private boolean guessIfContainerExists() {
try {
Socket s = new Socket( hostname, communicationPort );
Socket s = new Socket();
s.connect( new InetSocketAddress( hostname, communicationPort ), 5000 );
s.close();
return true;
} catch ( IOException ignore ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.HashMap;
import java.util.List;
Expand All @@ -43,7 +44,8 @@ final class PolyphenyDockerClient {


PolyphenyDockerClient( String hostname, int port, PolyphenyKeypair kp, byte[] serverCertificate ) throws IOException {
con = new Socket( hostname, port );
con = new Socket();
con.connect( new InetSocketAddress( hostname, port ), 5000 );
this.client = new PolyphenyTlsClient( kp, serverCertificate, con.getInputStream(), con.getOutputStream() );

this.in = client.getInputStream().get();
Expand Down Expand Up @@ -138,7 +140,7 @@ String createAndStartContainer( String containerName, String imageName, List<Int

CreateContainerResponse resp = executeRequest( newRequest().setCreateContainer( ccr ) ).getCreateContainer();

if ( !resp.getError().equals( "" ) ) {
if ( !resp.getError().isEmpty() ) {
throw new IOException( "Create Container: " + resp.getError() );
}
// Assert correct message
Expand All @@ -155,7 +157,7 @@ void startContainer( String uuid ) throws IOException {

StartContainerResponse resp = executeRequest( newRequest().setStartContainer( cr ) ).getStartContainer();

if ( !resp.getError().equals( "" ) ) {
if ( !resp.getError().isEmpty() ) {
throw new IOException( resp.getError() );
}
}
Expand All @@ -169,7 +171,7 @@ String getContainerStatus( String uuid ) throws IOException {
InspectContainerRequest ir = InspectContainerRequest.newBuilder().setUuid( uuid ).build();
InspectContainerResponse resp = executeRequest( newRequest().setInspectContainer( ir ) ).getInspectContainer();

if ( !resp.getError().equals( "" ) ) {
if ( !resp.getError().isEmpty() ) {
throw new IOException( resp.getError() );
}
return resp.getStatus();
Expand All @@ -185,7 +187,7 @@ void stopContainer( String uuid ) throws IOException {

StopContainerResponse resp = executeRequest( newRequest().setStopContainer( cr ) ).getStopContainer();

if ( !resp.getError().equals( "" ) ) {
if ( !resp.getError().isEmpty() ) {
throw new IOException( resp.getError() );
}
}
Expand All @@ -199,7 +201,7 @@ void deleteContainer( String uuid ) throws IOException {
DeleteContainerRequest dr = DeleteContainerRequest.newBuilder().setUuid( uuid ).build();
DeleteContainerResponse resp = executeRequest( newRequest().setDeleteContainer( dr ) ).getDeleteContainer();

if ( !resp.getError().equals( "" ) ) {
if ( !resp.getError().isEmpty() ) {
throw new IOException( resp.getError() );
}
}
Expand All @@ -211,7 +213,7 @@ List<ContainerInfo> listContainers() throws IOException {
ListContainersRequest lr = ListContainersRequest.newBuilder().build();
ListContainersResponse resp = executeRequest( newRequest().setListContainers( lr ) ).getListContainers();

if ( !resp.getError().equals( "" ) ) {
if ( !resp.getError().isEmpty() ) {
throw new IOException( resp.getError() );
}

Expand Down Expand Up @@ -257,7 +259,7 @@ int executeCommand( String uuid, List<String> command ) throws IOException {
.build();
ExecuteCommandResponse resp = executeRequest( newRequest().setExecuteCommand( er ) ).getExecuteCommand();

if ( !resp.getError().equals( "" ) ) {
if ( !resp.getError().isEmpty() ) {
throw new IOException( resp.getError() );
}

Expand All @@ -276,7 +278,7 @@ void createVolume( String driver, String uniqueName, Map<String, String> options

CreateVolumeResponse resp = executeRequest( newRequest().setCreateVolume( vr ) ).getCreateVolume();

if ( !resp.getError().equals( "" ) ) {
if ( !resp.getError().isEmpty() ) {
throw new IOException( resp.getError() );
}
}
Expand All @@ -291,7 +293,7 @@ void deleteVolume( String uniqueName ) throws IOException {

DeleteVolumeResponse resp = executeRequest( newRequest().setDeleteVolume( dv ) ).getDeleteVolume();

if ( !resp.getError().equals( "" ) ) {
if ( !resp.getError().isEmpty() ) {
throw new IOException( resp.getError() );
}
}
Expand All @@ -302,7 +304,7 @@ void ping() throws IOException {
PingRequest lr = PingRequest.newBuilder().build();
PingResponse resp = executeRequest( newRequest().setPing( lr ) ).getPing();

if ( !resp.getError().equals( "" ) ) {
if ( !resp.getError().isEmpty() ) {
throw new IOException( resp.getError() );
}
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 6 additions & 4 deletions core/src/main/java/org/polypheny/db/util/PasswordGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@

public final class PasswordGenerator {

public static String generatePassword( int bits ) {
SecureRandom sr = new SecureRandom();
byte[] raw = new byte[1 + bits / 8];
sr.nextBytes( raw );
private static final SecureRandom secureRandom = new SecureRandom();


public static String generatePassword() {
byte[] raw = new byte[32];
secureRandom.nextBytes( raw );
return Base64.getUrlEncoder().encodeToString( raw );
}

Expand Down
Loading

0 comments on commit 82730fb

Please sign in to comment.