Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package brooklyn.location.jclouds;
  
  import static brooklyn.util.GroovyJavaMethods.truth;
  
  import java.util.Map;
  
 
 
 
 public class JcloudsSshMachineLocation extends SshMachineLocation implements HasSubnetHostname {
     final JcloudsLocation parent;
     final NodeMetadata node;
     private final RunScriptOnNode.Factory runScriptFactory;
     
     public JcloudsSshMachineLocation(Map flagsJcloudsLocation parentNodeMetadata node) {
         super(flags);
         this. = parent;
         this. = node;
         
         ComputeServiceContext context = parent.getComputeService().getContext();
          = context.utils().injector().getInstance(RunScriptOnNode.Factory.class);
     }
     
     public NodeMetadata getNode() {
         return ;
     }
     
     public JcloudsLocation getParent() {
         return ;
     }
    
    
returns the hostname for use by peers in the same subnet, defaulting to public hostname if nothing special

for use e.g. in clouds like amazon where other machines in the same subnet need to use a different IP

 
     public String getSubnetHostname() {
         if (truth(.getPrivateAddresses()))
             return .getPrivateAddresses().iterator().next();
         return .getPublicHostname(null);
     }
     
     public String getJcloudsId() {
         return .getId();
     }
    
    
executes the given statements on the server using jclouds ScriptBuilder, wrapping in a script which is polled periodically. the output is returned once the script completes (disadvantage compared to other methods) but the process is nohupped and the SSH session is not kept, so very useful for long-running processes
 
     public ListenableFuture<ExecResponsesubmitRunScript(String ...statements) {
         return submitRunScript(new InterpretableStatement(statements));
     }
         return submitRunScript(scriptnew RunScriptOptions());            
     }
     public ListenableFuture<ExecResponsesubmitRunScript(Statement scriptRunScriptOptions options) {
         return .submit(scriptoptions);
     }
    
uses submitRunScript to execute the commands, and throws error if it fails or returns non-zero
 
     public void execRemoteScript(String ...commands) {
         try {
             ExecResponse result = submitRunScript(commands).get();
             if (result.getExitStatus()!=0)
                 throw new IllegalStateException("Error running remote commands (code "+result.getExitStatus()+"): "+commands);
         } catch (InterruptedException e) {
             Thread.currentThread().interrupt();
             throw Throwables.propagate(e);
         } catch (ExecutionException e) {
             throw Throwables.propagate(e);
         }
     }

    
Retrieves the password for this VM, if one exists. The behaviour/implementation is different for different clouds. e.g. on Rackspace, the password for a windows VM is available immediately; on AWS-EC2, for a Windows VM you need to poll repeatedly until the password is available which can take up to 15 minutes.
 
     public String waitForPassword() {
        // TODO Hacky; don't want aws specific stuff here but what to do?!
        if (.getProvider().equals("aws-ec2")) {
            try {
                return JcloudsUtil.waitForPasswordOnAws(.getComputeService(), , 15, .);
            } catch (TimeoutException e) {
                throw Throwables.propagate(e);
            }
        } else {
            LoginCredentials credentials = .getCredentials();
            return (credentials != null) ? credentials.getPassword() : null;
        }
    }
    @Override
    public OsDetails getOsDetails() {
        if (.getOperatingSystem() != null) {
            return new BasicOsDetails(
                    .getOperatingSystem().getName() != null
                            ? .getOperatingSystem().getName() : "linux",
                    .getOperatingSystem().getArch() != null
                            ? .getOperatingSystem().getArch() : ..,
                    .getOperatingSystem().getVersion() != null
                            ? .getOperatingSystem().getVersion() : "unknown",
                    .getOperatingSystem().is64Bit());
        }
        return super.getOsDetails();
    }
New to GrepCode? Check out our FAQ X