diff --git a/management/server/core/host-registry/host-registry-impl/src/main/java/io/subutai/core/hostregistry/impl/HostNotifier.java b/management/server/core/host-registry/host-registry-impl/src/main/java/io/subutai/core/hostregistry/impl/HostNotifier.java index ff892394613..c4e94f29f8f 100644 --- a/management/server/core/host-registry/host-registry-impl/src/main/java/io/subutai/core/hostregistry/impl/HostNotifier.java +++ b/management/server/core/host-registry/host-registry-impl/src/main/java/io/subutai/core/hostregistry/impl/HostNotifier.java @@ -2,6 +2,7 @@ import java.util.Set; +import java.util.concurrent.TimeUnit; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -12,7 +13,6 @@ import io.subutai.common.peer.HostNotFoundException; import io.subutai.common.peer.LocalPeer; import io.subutai.common.peer.ResourceHost; -import io.subutai.common.peer.ResourceHostException; import io.subutai.common.util.ServiceLocator; import io.subutai.core.hostregistry.api.HostListener; @@ -181,19 +181,14 @@ private void processHeartbeat( ResourceHostInfo oldRhInfo, ResourceHostInfo newR try { ResourceHost resourceHost = localPeer.getResourceHostByContainerId( oldContainerInfo.getId() ); - try { - for ( String name : resourceHost.listExistingContainerNames() ) - { - if ( oldContainerInfo.getContainerName().equalsIgnoreCase( name ) ) - { - containerStillExists = true; - break; - } - } + //sleep 10 sec to let filesystem recover in case of snapshot rollback + TimeUnit.SECONDS.sleep( 10 ); + + containerStillExists = resourceHost.lxcExists( oldContainerInfo.getContainerName() ); } - catch ( ResourceHostException e ) + catch ( Exception e ) { //just in case skip container removal in this round since we can not check containerStillExists = true; diff --git a/management/server/core/local-peer/local-peer-impl/src/main/java/io/subutai/core/localpeer/impl/ResourceHostCommands.java b/management/server/core/local-peer/local-peer-impl/src/main/java/io/subutai/core/localpeer/impl/ResourceHostCommands.java index 2397fbc88b2..e54fa63a066 100644 --- a/management/server/core/local-peer/local-peer-impl/src/main/java/io/subutai/core/localpeer/impl/ResourceHostCommands.java +++ b/management/server/core/local-peer/local-peer-impl/src/main/java/io/subutai/core/localpeer/impl/ResourceHostCommands.java @@ -196,4 +196,10 @@ public RequestBuilder getGetTimezonOffsetCommand() { return new RequestBuilder( "date +\"%z\"" ); } + + + public RequestBuilder getCheckLxcExistsCommand( String name ) + { + return new RequestBuilder( String.format( "subutai exists %s", name ) ); + } } diff --git a/management/server/core/local-peer/local-peer-impl/src/main/java/io/subutai/core/localpeer/impl/entity/ResourceHostEntity.java b/management/server/core/local-peer/local-peer-impl/src/main/java/io/subutai/core/localpeer/impl/entity/ResourceHostEntity.java index 13989823761..044e98fbbfa 100644 --- a/management/server/core/local-peer/local-peer-impl/src/main/java/io/subutai/core/localpeer/impl/entity/ResourceHostEntity.java +++ b/management/server/core/local-peer/local-peer-impl/src/main/java/io/subutai/core/localpeer/impl/entity/ResourceHostEntity.java @@ -487,7 +487,7 @@ public Snapshots listContainerHostSnapshots( final ContainerHost containerHost ) if ( m.find() && m.groupCount() == 2 ) { - SimpleDateFormat parser = new SimpleDateFormat( "EEE MMM d H:mm yyyy X" ); + SimpleDateFormat parser = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS X" ); Date date = parser.parse( timestamp + " " + timezoneOffset ); @@ -1778,6 +1778,22 @@ public Set listExistingContainerNames() throws ResourceHostException } + @Override + public Boolean lxcExists( final String name ) throws ResourceHostException + { + try + { + CommandResult result = execute( resourceHostCommands.getCheckLxcExistsCommand( name ) ); + return result.hasSucceeded(); + } + catch ( CommandException e ) + { + throw new ResourceHostException( + String.format( "Error checking lxc instance existence: %s", e.getMessage() ), e ); + } + } + + @Override public Set listExistingContainersInfo() throws ResourceHostException { diff --git a/management/server/core/local-peer/local-peer-impl/src/test/java/io/subutai/core/localpeer/impl/entity/ResourceHostEntityTest.java b/management/server/core/local-peer/local-peer-impl/src/test/java/io/subutai/core/localpeer/impl/entity/ResourceHostEntityTest.java index 535f1118d62..438be617e12 100644 --- a/management/server/core/local-peer/local-peer-impl/src/test/java/io/subutai/core/localpeer/impl/entity/ResourceHostEntityTest.java +++ b/management/server/core/local-peer/local-peer-impl/src/test/java/io/subutai/core/localpeer/impl/entity/ResourceHostEntityTest.java @@ -280,16 +280,15 @@ public void testListContainerHostSnapshots() throws Exception { resourceHostEntity.addContainerHost( containerHost ); - doReturn( "NAME CREATION\n" - + "subutai/fs/Container1-pfe-1-2@my-snapshot Thu Feb 28 10:53 2019\n" - + "\n" - + " \n" - + "subutai/fs/Container1-pfe-1-2/home@my-snapshot Thu Feb 28 10:53 2019\n" - + "subutai/fs/Container1-pfe-1-2/opt@my-snapshot Thu Feb 28 10:53 2019\n" - + "subutai/fs/Container1-pfe-1-2/rootfs@my-snapshot Thu Feb 28 10:53 2019\n" - + "subutai/fs/Container1-pfe-1-2/var@my-snapshot Thu Feb 28 10:53 2019" ).when( commandResult ).getStdOut(); - - doReturn( "+0000" ).when( resourceHostEntity ).getTimezoneOffset(); + doReturn( "NAME :CREATED\n" + + "subutai/fs/Container1-xkb-1-2@first 2019-04-01T02:51:44.806\n" + + "subutai/fs/Container1-xkb-1-2/home@first 2019-04-01T02:51:44.806\n" + + "subutai/fs/Container1-xkb-1-2/opt@first 2019-04-01T02:51:44.806\n" + + "subutai/fs/Container1-xkb-1-2/rootfs@first 2019-04-01T02:51:44.806\n" + + "subutai/fs/Container1-xkb-1-2/var@first 2019-04-01T02:51:44.806\n" ).when( commandResult ) + .getStdOut(); + + doReturn( "+0000" ).when( resourceHostEntity ).getTimezoneOffset(); Snapshots snapshots = resourceHostEntity.listContainerHostSnapshots( containerHost ); diff --git a/management/server/subutai-common/src/main/java/io/subutai/common/peer/ResourceHost.java b/management/server/subutai-common/src/main/java/io/subutai/common/peer/ResourceHost.java index 014defac67b..16b8966d794 100644 --- a/management/server/subutai-common/src/main/java/io/subutai/common/peer/ResourceHost.java +++ b/management/server/subutai-common/src/main/java/io/subutai/common/peer/ResourceHost.java @@ -220,6 +220,13 @@ void exportTemplate( String containerName, String templateName, String version, Set listExistingContainersInfo() throws ResourceHostException; + /** + * Checks if lxc instance exists + * + * @param name name of container or template + */ + Boolean lxcExists( String name ) throws ResourceHostException; + ReservedPorts getReservedPorts() throws ResourceHostException;