Last active
May 9, 2017 17:27
-
-
Save vladimir-bukhtoyarov/baadaea2c734e302730652a6848f337d to your computer and use it in GitHub Desktop.
Nanocloud simple example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.gridkit.lab</groupId> | |
<artifactId>nanocloud</artifactId> | |
<version>0.8.8</version> | |
</dependency> | |
<dependency> | |
<groupId>org.gridkit.lab</groupId> | |
<artifactId>telecontrol-ssh</artifactId> | |
<version>0.8.8</version> | |
</dependency> | |
import org.gridkit.nanocloud.Cloud; | |
import org.gridkit.nanocloud.CloudFactory; | |
import org.gridkit.nanocloud.RemoteNode; | |
import org.gridkit.vicluster.ViNode; | |
import java.lang.management.ManagementFactory; | |
import java.util.concurrent.Callable; | |
public class FirstNanoCloud { | |
public static void main(String[] args) throws InterruptedException { | |
Cloud cloud = CloudFactory.createCloud(); | |
try { | |
ViNode allNodes = cloud.node("master"); | |
allNodes.x(RemoteNode.REMOTE).useSimpleRemoting(); | |
allNodes.x(RemoteNode.REMOTE).setHostsConfigFile("?na"); | |
allNodes.x(RemoteNode.REMOTE).setRemoteAccount("root"); | |
allNodes.x(RemoteNode.REMOTE).setPassword("password"); | |
allNodes.x(RemoteNode.REMOTE).setRemoteHost("myremotehost" + ":" + 22); | |
allNodes.touch(); | |
saluteToCaesar(allNodes); | |
reportMemory(allNodes); | |
Thread.sleep(10_000l); | |
} finally { | |
if (cloud != null) { | |
cloud.shutdown(); | |
} | |
} | |
} | |
private static void saluteToCaesar(ViNode node) { | |
node.exec(new Callable<Void>() { | |
@Override | |
public Void call() throws Exception { | |
String jvmName = ManagementFactory.getRuntimeMXBean().getName(); | |
System.out.println("'" + jvmName + "' salute you, Caesar!"); | |
return null; | |
} | |
}); | |
} | |
private static void reportMemory(ViNode node) { | |
node.exec(new Callable<Void>() { | |
@Override | |
public Void call() throws Exception { | |
String jvmName = ManagementFactory.getRuntimeMXBean().getName(); | |
long totalMemory = Runtime.getRuntime().maxMemory(); | |
System.out.println("My name is '" + jvmName + "'. Memory limit is " + (totalMemory >> 20) + "MiB"); | |
return null; | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment