ResourceHostEntity extends AbstractSubutaiHost implements ResourceHost, Disposable { @Override public void startContainerHost( final ContainerHost containerHost ) throws ResourceHostException { Preconditions.checkNotNull( containerHost, PRECONDITION_CONTAINER_IS_NULL_MSG ); try { getContainerHostById( containerHost.getId() ); } catch ( HostNotFoundException e ) { throw new ResourceHostException( String.format( CONTAINER_EXCEPTION_MSG_FORMAT, containerHost.getHostname() ), e ); } try { commandUtil .execute( resourceHostCommands.getStartContainerCommand( containerHost.getContainerName() ), this ); } catch ( CommandException e ) { throw new ResourceHostException( String.format( "Error on starting container %s: %s", containerHost.getHostname(), e.getMessage() ), e ); } waitContainerStart( containerHost ); } protected  ResourceHostEntity();  ResourceHostEntity( final String peerId, final ResourceHostInfo resourceHostInfo ); @Override void init(); @Override String getAddress(); @Override InstanceType getInstanceType(); @Override Set<ContainerHostInfo> getContainers(); @Override void dispose(); @Override synchronized void setupTunnels( P2pIps p2pIps, NetworkResource networkResource ); void deleteTunnels( P2pIps p2pIps, NetworkResource networkResource ); @Override ContainerHostState getContainerHostState( final ContainerHost containerHost ); @Override Set<ContainerHost> getContainerHosts(); @Override void startContainerHost( final ContainerHost containerHost ); @Override void stopContainerHost( final ContainerHost containerHost ); @Override Snapshots listContainerHostSnapshots( final ContainerHost containerHost ); @Override String getTimezoneOffset(); @Override void removeContainerSnapshot( final ContainerHost containerHost, String partition, final String label ); @Override void rollbackToContainerSnapshot( final ContainerHost containerHost, String partition, final String label,
                                             final boolean force ); @Override void addContainerSnapshot( final ContainerHost containerHost, String partition, final String label,
                                      final boolean stopContainer ); @Override String saveContainerFilesystem( final ContainerHost containerHost, final String label1, final String label2,
                                           final String destinationDirectory ); @Override void recreateContainerFilesystem( final String containerName, final String pathToFile ); @Override String recreateContainer( final String containerName, final String hostname, final String ip, final int vlan,
                                     final String environmentId ); @Override String downloadRawFileFromCdn( final String fileId, String destinationDirectory ); @Override String uploadRawFileToCdn( final String pathToFile, final String cdnToken ); @Override String encryptFile( final String pathToFile, String password ); @Override String decryptFile( final String pathToFile, String password ); @Override void destroyContainerHost( final ContainerHost containerHost ); void destroyContainer( String containerId ); @Override void setContainerQuota( final ContainerHost containerHost, final ContainerQuota containerQuota ); @Override ContainerHost getContainerHostByHostName( final String hostname ); @Override ContainerHost getContainerHostByContainerName( final String containerName ); @Override void removeContainerHost( final ContainerHost containerHost ); @Override ContainerHost getContainerHostById( final String id ); @Override ContainerHost getContainerHostByIp( final String ip ); @Override Set<ContainerHost> getContainerHostsByEnvironmentId( final String environmentId ); @Override Set<ContainerHost> getContainerHostsByOwnerId( final String ownerId ); @Override Set<ContainerHost> getContainerHostsByPeerId( final String peerId ); @Override void addContainerHost( ContainerHost host ); @Override void cleanup( final EnvironmentId environmentId, final int vlan ); @Override int getNumberOfCpuCores(); @Override P2PConnections getP2PConnections(); @Override void joinP2PSwarm( final String p2pIp, final String interfaceName, final String p2pHash,
                              final String secretKey, final long secretKeyTtlSec ); @Override void joinP2PSwarmDHCP( final String interfaceName, final String p2pHash, final String secretKey,
                                  final long secretKeyTtlSec ); @Override void removeP2PSwarm( String p2pHash ); @Override void removeP2PNetworkIface( String interfaceName ); @Override void resetSwarmSecretKey( final String p2pHash, final String newSecretKey, final long ttlSeconds ); @Override Tunnels getTunnels(); @Override void createTunnel( final Tunnel tunnel ); void deleteTunnel( final Tunnel tunnel ); @Override void importTemplate( final Template template, final String environmentId ); @Override RhTemplatesDownloadProgress getTemplateDownloadProgress( final String environmentId ); @Override RhTemplatesUploadProgress getTemplateUploadProgress( final String templateName ); void updateTemplateDownloadProgress( String environmentId, final String templateName,
                                                final int downloadPercent ); void updateTemplateUploadProgress( final String templateName, final int uploadPercent ); @Override void exportTemplate( final String containerName, final String templateName, final String version,
                                final boolean isPrivateTemplate, final String token ); @Override String cloneContainer( final Template template, final String containerName, final String hostname,
                                  final String ip, final int vlan, final String environmentId ); @Override void updateHostInfo( final HostInfo hostInfo ); @Override String getRhVersion(); @Override String getP2pVersion(); @Override String getP2pStatusByP2PHash( String p2pHash ); String getOsName(); @Override int getVlan(); @Override void setContainerHostname( final ContainerHost containerHost, final String newHostname ); @Override void setHostname( final String newHostname ); @Override boolean isManagementHost(); @Override boolean isConnected(); @Override String getLinkId(); @Override String getUniqueIdentifier(); @Override String getClassPath(); @Override String getContext(); @Override String getKeyId(); @Override Set<String> listExistingContainerNames(); @Override Boolean lxcExists( final String name ); @Override Set<ContainerInfo> listExistingContainersInfo(); @Override ReservedPorts getReservedPorts(); @Override ReservedPorts getContainerPortMappings( final Protocol protocol ); @Override void mapContainerPort( final Protocol protocol, final String containerIp, final int containerPort,
                                  final int rhPort ); @Override void removeContainerPortMapping( final Protocol protocol, final String containerIp, final int containerPort,
                                            final int rhPort ); @Override void mapContainerPortToDomain( final Protocol protocol, final String containerIp, final int containerPort,
                                          final int rhPort, final String domain, final String sslCertPath,
                                          final LoadBalancing loadBalancing, final boolean sslBackend,
                                          final boolean redirect, final boolean http2 ); @Override void removeContainerPortDomainMapping( final Protocol protocol, final String containerIp,
                                                  final int containerPort, final int rhPort, final String domain ); @Override boolean isPortMappingReserved( final Protocol protocol, final int externalPort, final String ipAddress,
                                          final int internalPort, final String domain ); @Override Set<ReservedPort> getReservedPortMappings(); @Override String getIp(); @Override Set<String> getUsedP2pIfaceNames(); void markUpdateAsCompleted(); @Override synchronized boolean update(); @Override boolean ping();  }
@Test public void testStartContainerHost() throws Exception { try { resourceHostEntity.startContainerHost( containerHost ); fail( "Expected ResourceHostException" ); } catch ( ResourceHostException e ) { } when( containerHost.isConnected() ).thenReturn( true ); when( commandResult.getStdOut() ).thenReturn( CONTAINER_STATUS_STARTED ); resourceHostEntity.addContainerHost( containerHost ); resourceHostEntity.startContainerHost( containerHost ); verify( commandUtil, atLeastOnce() ).execute( any( RequestBuilder.class ), eq( resourceHostEntity ) ); when( commandResult.getStdOut() ).thenReturn( CONTAINER_STATUS_STOPPED ); try { resourceHostEntity.startContainerHost( containerHost ); fail( "Expected ResourceHostException" ); } catch ( ResourceHostException e ) { } when( commandResult.getStdOut() ).thenReturn( CONTAINER_STATUS_STARTED ); doThrow( new CommandException( "" ) ).when( commandUtil ) .execute( any( RequestBuilder.class ), eq( resourceHostEntity ) ); try { resourceHostEntity.startContainerHost( containerHost ); fail( "Expected ResourceHostException" ); } catch ( ResourceHostException e ) { } }