├── nanocloud └── src │ └── test │ ├── resources │ ├── marker.txt │ ├── marker-override.jar │ └── marker-override2.jar │ └── java │ └── org │ └── gridkit │ └── nanocloud │ ├── jmx │ ├── TestDataMBean.java │ └── TestData.java │ ├── test │ └── cglib │ │ ├── HelloService.java │ │ ├── HelloMsg.java │ │ ├── HelloManager.java │ │ ├── MyConfigB.java │ │ ├── MyConfigA.java │ │ └── SpringTest.java │ ├── agent │ ├── SampleAgent.java │ └── SampleAgent2.java │ ├── viengine │ ├── Engine2.java │ └── SimpleViEngine2Test.java │ ├── SharedStatics.java │ └── StaticVarHost.java ├── vicluster-core └── src │ ├── test │ ├── resources │ │ ├── marker.txt │ │ └── marker-override.jar │ └── java │ │ └── org │ │ └── gridkit │ │ ├── nanocloud │ │ ├── IsolateCloudFactoryTest.java │ │ ├── testutil │ │ │ └── JvmVersionCheck.java │ │ ├── telecontrol │ │ │ ├── TunnelInitiatorTest.java │ │ │ ├── isolate │ │ │ │ └── IsolateNodeTest.java │ │ │ ├── SocketTest.java │ │ │ └── TunnelerControlConsoleTest.java │ │ ├── Retry.java │ │ ├── ConsoleFlushTest.java │ │ └── CloudFactoryTest.java │ │ └── vicluster │ │ ├── isolate │ │ └── StaticVarHost.java │ │ ├── telecontrol │ │ ├── TestStreamHelper.java │ │ ├── bootstraper │ │ │ └── TunnelTestHelper.java │ │ └── ProcessKillerTest.java │ │ └── WildPropsTest.java │ └── main │ └── java │ └── org │ └── gridkit │ ├── vicluster │ ├── Helper.java │ ├── ViConfExtender.java │ ├── ViNodeExtender.java │ ├── telecontrol │ │ ├── ManagedProcess.java │ │ ├── JvmProcessFactory.java │ │ ├── jvm │ │ │ ├── Any.java │ │ │ └── SplittingOutputStream.java │ │ ├── StreamCopyService.java │ │ ├── FileBlob.java │ │ ├── isolate │ │ │ └── CloseableThreadKiller.java │ │ └── bootstraper │ │ │ └── SmartBootstraper.java │ ├── ViNodeProps.java │ ├── ViNodeProvider.java │ ├── isolate │ │ ├── ThreadKiller.java │ │ ├── IsolateViNodeProvider.java │ │ └── ThreadHelper.java │ ├── ViNodeSet.java │ ├── VoidCallable.java │ ├── ViExecutor.java │ └── ViSpiConfig.java │ └── nanocloud │ ├── CloudNodeProvider.java │ ├── viengine │ ├── JvmOptionsConfigurator.java │ ├── LazyPragma.java │ ├── ClasspathConf.java │ ├── NodeAction.java │ ├── PragmaWriter.java │ ├── PragmaHandler.java │ ├── JvmConf.java │ ├── TextTerminalControl.java │ ├── ViEngine2.java │ ├── PragmaReader.java │ ├── LocalNodeTypeInitializer.java │ ├── PassthroughPragmaHandler.java │ ├── PassivePragmaHandler.java │ ├── NotSupportedPragmaHandler.java │ ├── SharedEntity.java │ ├── AbstractStopAction.java │ ├── ManagedProcessTextTerminal.java │ ├── LazyClassInstantiator.java │ ├── NullConsole.java │ ├── ProcessLifecycleListener.java │ ├── PropPragmaHandler.java │ ├── AgentConfigurator.java │ ├── DefaultNodeConfig.java │ └── PragmaProcessor.java │ ├── telecontrol │ ├── TunnellerInitiator.java │ ├── RemoteExecutionSessionWrapper.java │ ├── NodeFactory.java │ ├── RemoteExecutionSession.java │ ├── isolate │ │ ├── IsolateRemoteSessionWrapper.java │ │ ├── IsolatePragmaSupport.java │ │ ├── CloseableThreadKiller.java │ │ ├── IsolateConfig.java │ │ └── IsolatedRemoteSession.java │ ├── LocalNodeTypeHandler.java │ ├── ProcessLauncher.java │ └── ZeroRmiRemoteSession.java │ ├── log │ ├── LoggerInstantiator.java │ ├── ConfigurableZLogger.java │ └── Slf4jInstantiator.java │ ├── instrumentation │ └── ByteCodeTransformer.java │ ├── Cloud.java │ ├── NodeExecutionException.java │ ├── NodeConfigurationException.java │ ├── NanocloudException.java │ ├── NodeStartupRuntimeException.java │ └── MagicProps.java ├── .gitignore ├── nanotest └── src │ └── main │ └── java │ └── org │ └── gridkit │ └── nanocloud │ └── test │ ├── junit │ ├── CloudRule.java │ └── DisposableCloud.java │ └── maven │ └── MavenClasspathConfig.java ├── zerormi └── src │ ├── main │ └── java │ │ └── org │ │ └── gridkit │ │ ├── zerormi │ │ ├── DuplexStreamConnector.java │ │ ├── RecoverableSerializationException.java │ │ ├── JdkUtils.java │ │ ├── zlog │ │ │ ├── LogLevel.java │ │ │ ├── LogStream.java │ │ │ ├── ZLogger.java │ │ │ ├── PrintStreamLogStream.java │ │ │ └── ZLogFactory.java │ │ ├── RemoteMessage.java │ │ ├── Box.java │ │ ├── hub │ │ │ ├── LegacySpore.java │ │ │ ├── Ping.java │ │ │ ├── SlaveSpore.java │ │ │ └── MasterHub.java │ │ ├── RmiMarshaler.java │ │ ├── ObjectPipe.java │ │ ├── BeanRef.java │ │ ├── Exported.java │ │ ├── DuplexStream.java │ │ ├── RmiMarshalStack.java │ │ ├── ReflectionHelper.java │ │ ├── RemoteReturn.java │ │ ├── RemoteRef.java │ │ ├── UndeclaredRemoteException.java │ │ ├── RmiChannel.java │ │ ├── SocketStream.java │ │ ├── NamedStreamPair.java │ │ ├── IOHelper.java │ │ ├── RemoteExecutor.java │ │ └── RemoteInstance.java │ │ └── zeroio │ │ ├── WriterOutputStream.java │ │ ├── LineLoggerOutputStream.java │ │ ├── WrapperOutputStream.java │ │ └── AbstractLineProcessingOutputStream.java │ └── test │ └── java │ └── org │ └── gridkit │ └── zerormi │ └── zlog │ ├── ZLogToSlf4JCheck.java │ └── PrintStreamLogTest.java ├── interceptor └── src │ ├── main │ └── java │ │ └── org │ │ └── gridkit │ │ ├── lab │ │ └── interceptor │ │ │ ├── ClassHierarchyHelper.java │ │ │ ├── HookType.java │ │ │ ├── CutPoint.java │ │ │ ├── Interceptor.java │ │ │ ├── HookManager.java │ │ │ └── Interception.java │ │ └── nanocloud │ │ └── interceptor │ │ ├── CallFilter.java │ │ ├── ReturnValueStub.java │ │ ├── LiteralMatcher.java │ │ ├── FilterableInterceptor.java │ │ ├── BarrierStub.java │ │ ├── misc │ │ └── PlatformMBeanServerInterceptor.java │ │ ├── CounterStub.java │ │ ├── ParamBasedCallFilter.java │ │ ├── PrinterStub.java │ │ └── ThrowStub.java │ └── test │ └── java │ └── org │ └── gridkit │ ├── lab │ └── interceptor │ │ └── test │ │ └── SimpleClass_CRT.java │ └── vicluster │ └── isolate │ └── LocalInstrumentationFeatureTest.java ├── README.md ├── viconcurrent └── src │ └── main │ └── java │ └── org │ └── gridkit │ └── util │ └── concurrent │ ├── Latch.java │ ├── FutureEx.java │ ├── Box.java │ ├── RunnableEx.java │ ├── DebugHelper.java │ ├── AdvancedExecutor.java │ ├── zerormi │ └── ExportableLatchBarrier.java │ ├── Barriers.java │ ├── TaskService.java │ ├── NoBarrier.java │ ├── BlockingBarrier.java │ ├── LatchBarrier.java │ ├── AdvancedExecutorAdapter.java │ └── CyclicBlockingBarrier.java └── telecontrol-ssh └── src ├── main └── java │ └── org │ └── gridkit │ ├── vicluster │ └── telecontrol │ │ └── ssh │ │ ├── RemoteFileCache.java │ │ ├── SshSessionFactory.java │ │ └── RemoteJmvReplicator.java │ └── nanocloud │ └── telecontrol │ └── ssh │ ├── RemoteNodeTypeHandler.java │ └── SshSpiConf.java └── test └── java └── org └── gridkit ├── lab └── util │ └── shell │ ├── ShellTest.java │ └── TailerCheck.java ├── vicluster └── telecontrol │ └── ssh │ ├── SudoCheck.java │ └── TunnellerCheck.java └── nanocloud └── telecontrol └── ssh └── ViEngineSshCheck.java /nanocloud/src/test/resources/marker.txt: -------------------------------------------------------------------------------- 1 | Default marker -------------------------------------------------------------------------------- /vicluster-core/src/test/resources/marker.txt: -------------------------------------------------------------------------------- 1 | Default marker -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .classpath 3 | .settings 4 | .project 5 | .idea 6 | *.iml -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/Helper.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.vicluster; 2 | 3 | class Helper { 4 | 5 | 6 | } 7 | -------------------------------------------------------------------------------- /nanocloud/src/test/resources/marker-override.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gridkit/nanocloud/HEAD/nanocloud/src/test/resources/marker-override.jar -------------------------------------------------------------------------------- /nanocloud/src/test/resources/marker-override2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gridkit/nanocloud/HEAD/nanocloud/src/test/resources/marker-override2.jar -------------------------------------------------------------------------------- /vicluster-core/src/test/resources/marker-override.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gridkit/nanocloud/HEAD/vicluster-core/src/test/resources/marker-override.jar -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/CloudNodeProvider.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud; 2 | 3 | class CloudNodeProvider { 4 | 5 | 6 | 7 | } 8 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/JvmOptionsConfigurator.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | public class JvmOptionsConfigurator { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /nanocloud/src/test/java/org/gridkit/nanocloud/jmx/TestDataMBean.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.jmx; 2 | 3 | public interface TestDataMBean { 4 | 5 | public String getName(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /nanocloud/src/test/java/org/gridkit/nanocloud/test/cglib/HelloService.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.test.cglib; 2 | 3 | public interface HelloService { 4 | 5 | public void sayHello(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/ViConfExtender.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.vicluster; 2 | 3 | public interface ViConfExtender { 4 | 5 | public X wrap(ViConfigurable node); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /nanocloud/src/test/java/org/gridkit/nanocloud/test/cglib/HelloMsg.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.test.cglib; 2 | 3 | public class HelloMsg { 4 | 5 | public String toString() { 6 | return "Hello"; 7 | }; 8 | } 9 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/LazyPragma.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | interface LazyPragma { 4 | 5 | public Object resolve(String key, PragmaReader context); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/ClasspathConf.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | public interface ClasspathConf { 4 | 5 | public static final String CLASSPATH_TWEAK = "classpath:tweak:"; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/telecontrol/TunnellerInitiator.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.telecontrol; 2 | 3 | public interface TunnellerInitiator { 4 | 5 | public HostControlConsole initTunnel(HostControlConsole console); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /nanotest/src/main/java/org/gridkit/nanocloud/test/junit/CloudRule.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.test.junit; 2 | 3 | import org.gridkit.nanocloud.Cloud; 4 | import org.junit.rules.TestRule; 5 | 6 | public interface CloudRule extends TestRule, Cloud { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/DuplexStreamConnector.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.zerormi; 2 | 3 | import java.io.IOException; 4 | 5 | public interface DuplexStreamConnector { 6 | 7 | public DuplexStream connect() throws IOException; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/telecontrol/RemoteExecutionSessionWrapper.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.telecontrol; 2 | 3 | public interface RemoteExecutionSessionWrapper { 4 | 5 | public RemoteExecutionSession wrap(RemoteExecutionSession session); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/NodeAction.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | import java.util.concurrent.ExecutionException; 4 | 5 | public interface NodeAction { 6 | 7 | public void run(PragmaWriter context) throws ExecutionException; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/ViNodeExtender.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.vicluster; 2 | 3 | /** 4 | * 5 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 6 | * 7 | * @param 8 | */ 9 | public interface ViNodeExtender { 10 | 11 | public X wrap(ViNode node); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/telecontrol/NodeFactory.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.telecontrol; 2 | 3 | import java.util.Map; 4 | 5 | import org.gridkit.vicluster.ViNode; 6 | 7 | public interface NodeFactory { 8 | 9 | public ViNode createViNode(Map config); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/RecoverableSerializationException.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.zerormi; 2 | 3 | @SuppressWarnings("serial") 4 | class RecoverableSerializationException extends RuntimeException { 5 | 6 | public RecoverableSerializationException(Exception e) { 7 | super(e); 8 | } 9 | } -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/log/LoggerInstantiator.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.log; 2 | 3 | import java.util.Map; 4 | 5 | import org.gridkit.zerormi.zlog.ZLogger; 6 | 7 | public interface LoggerInstantiator { 8 | 9 | public ZLogger instantiate(Map config); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /interceptor/src/main/java/org/gridkit/lab/interceptor/ClassHierarchyHelper.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.lab.interceptor; 2 | 3 | public interface ClassHierarchyHelper { 4 | 5 | public void isParent(String childName, String parentName); 6 | 7 | public void isImplementor(String implementorName, String interfaceName); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /nanocloud/src/test/java/org/gridkit/nanocloud/jmx/TestData.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.jmx; 2 | 3 | public class TestData implements TestDataMBean { 4 | 5 | private String name; 6 | 7 | public TestData(String name) { 8 | this.name = name; 9 | } 10 | 11 | @Override 12 | public String getName() { 13 | return name; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /nanocloud/src/test/java/org/gridkit/nanocloud/test/cglib/HelloManager.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.test.cglib; 2 | 3 | public class HelloManager { 4 | 5 | private final HelloService service; 6 | 7 | public HelloManager(HelloService service) { 8 | this.service = service; 9 | } 10 | 11 | public void greet() { 12 | service.sayHello(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/PragmaWriter.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | public interface PragmaWriter extends PragmaReader { 4 | 5 | public void set(String key, Object value); 6 | 7 | public void setLazy(String key, LazyPragma pragma); 8 | 9 | public void link(String key, String link); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /vicluster-core/src/test/java/org/gridkit/nanocloud/IsolateCloudFactoryTest.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud; 2 | 3 | import org.gridkit.vicluster.ViProps; 4 | 5 | public class IsolateCloudFactoryTest extends CloudFactoryTest{ 6 | 7 | public Cloud initCloud() { 8 | Cloud cloud = CloudFactory.createCloud(); 9 | ViProps.at(cloud.node("**")).setIsolateType(); 10 | return cloud; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/PragmaHandler.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | import java.util.Map; 4 | 5 | public interface PragmaHandler { 6 | 7 | public void init(PragmaWriter conext); 8 | 9 | public Object query(PragmaWriter context, String key); 10 | 11 | public void apply(PragmaWriter context, Map values); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/JvmConf.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | 4 | public interface JvmConf { 5 | 6 | public static final String JVM_EXEC_CMD = "jvm:exec-command"; 7 | public static final String JVM_ARGUMENT = "jvm:xx:"; 8 | public static final String JVM_WORK_DIR = "jvm:work-dir"; 9 | public static final String JVM_ENV_VAR = "jvm:env:"; 10 | } 11 | -------------------------------------------------------------------------------- /zerormi/src/test/java/org/gridkit/zerormi/zlog/ZLogToSlf4JCheck.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.zerormi.zlog; 2 | 3 | import org.junit.Test; 4 | 5 | public class ZLogToSlf4JCheck { 6 | 7 | @Test 8 | public void check_logging() { 9 | ZLogFactory.getSlf4JRootLogger().get("test", LogLevel.WARN).log("Test message"); 10 | ZLogFactory.getStdErrRootLogger().get("test", LogLevel.WARN).log("Test message"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /nanocloud/src/test/java/org/gridkit/nanocloud/agent/SampleAgent.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.agent; 2 | 3 | import java.util.concurrent.atomic.AtomicReference; 4 | 5 | public class SampleAgent { 6 | public static final String NOT_SET = "NOT_SET"; 7 | public static final AtomicReference options = new AtomicReference(NOT_SET); 8 | 9 | public static void premain(String args) { 10 | options.set(args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /nanocloud/src/test/java/org/gridkit/nanocloud/agent/SampleAgent2.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.agent; 2 | 3 | import java.util.concurrent.atomic.AtomicReference; 4 | 5 | public class SampleAgent2 { 6 | public static final String NOT_SET = "NOT_SET"; 7 | public static final AtomicReference options = new AtomicReference(NOT_SET); 8 | 9 | public static void premain(String args) { 10 | options.set(args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /nanocloud/src/test/java/org/gridkit/nanocloud/viengine/Engine2.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | import org.gridkit.nanocloud.Cloud; 4 | import org.gridkit.vicluster.ViManager; 5 | 6 | public class Engine2 { 7 | 8 | public static Cloud createCloud() { 9 | return new ViManager( 10 | new ViEngine2NodeProvider() 11 | .addTypeInitializer("local", LocalNodeTypeInitializer.class) 12 | ); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/log/ConfigurableZLogger.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.log; 2 | 3 | import org.gridkit.zerormi.zlog.LogLevel; 4 | import org.gridkit.zerormi.zlog.ZLogger; 5 | 6 | public interface ConfigurableZLogger extends ZLogger { 7 | 8 | /** 9 | * Sets or unsets (if level is null) logging level for specific path. 10 | * @param path 11 | * @param level 12 | */ 13 | public void setLevel(String path, LogLevel level); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/TextTerminalControl.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | import java.io.OutputStream; 4 | 5 | public interface TextTerminalControl { 6 | 7 | /** 8 | * Pulls pending data from stdOut/stdErr pipes 9 | */ 10 | public void consoleFlush(); 11 | 12 | public OutputStream getStdIn(); 13 | 14 | public void bindStdOut(OutputStream os); 15 | 16 | public void bindStdErr(OutputStream os); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/ViEngine2.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | import java.util.Map; 4 | 5 | import org.gridkit.util.concurrent.AdvancedExecutor; 6 | 7 | public interface ViEngine2 { 8 | 9 | public AdvancedExecutor getExecutor(); 10 | 11 | public void shutdown(); 12 | 13 | public void kill(); 14 | 15 | public Object getPragma(String key); 16 | 17 | public void setPragmas(Map pragmas); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/JdkUtils.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.zerormi; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | public class JdkUtils { 6 | 7 | public static void addSuppressedIfSupported(Throwable t, Throwable suppressed){ 8 | try { 9 | Method method = Throwable.class.getMethod("addSuppressed", Throwable.class); 10 | method.invoke(t, suppressed); 11 | } catch (Exception e) { 12 | // ignore any problems: for example NoSuchMethodException 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/telecontrol/RemoteExecutionSession.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.telecontrol; 2 | 3 | import org.gridkit.util.concurrent.AdvancedExecutor; 4 | import org.gridkit.zerormi.DuplexStream; 5 | import org.gridkit.zerormi.hub.SlaveSpore; 6 | 7 | public interface RemoteExecutionSession { 8 | 9 | public SlaveSpore getMobileSpore(); 10 | 11 | public AdvancedExecutor getRemoteExecutor(); 12 | 13 | public void setTransportConnection(DuplexStream stream); 14 | 15 | public void terminate(Throwable cause); 16 | } 17 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/PragmaReader.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | import java.util.List; 4 | 5 | interface PragmaReader { 6 | 7 | public boolean isPresent(String key); 8 | 9 | public T get(String key); 10 | 11 | public String describe(String key); 12 | 13 | public List match(String glob); 14 | 15 | public List collect(String glob, Class type); 16 | 17 | public void copyTo(PragmaWriter writer); 18 | 19 | public void copyTo(PragmaWriter writer, boolean omitExisting); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /nanocloud/src/test/java/org/gridkit/nanocloud/test/cglib/MyConfigB.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.test.cglib; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Configuration 8 | public abstract class MyConfigB { 9 | 10 | @Bean @Autowired 11 | public HelloManager createHelloManager(HelloService service) { 12 | return new HelloManager(service); 13 | } 14 | 15 | @Bean 16 | public HelloMsg message() { 17 | return new HelloMsg(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/instrumentation/ByteCodeTransformer.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.instrumentation; 2 | 3 | /** 4 | * This is an SPI for module handling byte code instrumentation. 5 | * 6 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 7 | */ 8 | public interface ByteCodeTransformer { 9 | 10 | public byte[] rewriteClassData(String className, byte[] byteCode, HierarchyGraph graph); 11 | 12 | public static interface HierarchyGraph { 13 | 14 | public boolean isDescendant(String descendantClassName, String ascendantClassName); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /vicluster-core/src/test/java/org/gridkit/nanocloud/testutil/JvmVersionCheck.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.testutil; 2 | 3 | import org.junit.Test; 4 | 5 | public class JvmVersionCheck { 6 | 7 | public static boolean isJava8orBelow() { 8 | String version = System.getProperty("java.runtime.version"); 9 | return version.startsWith("1.") || 10 | version.startsWith("1.") || 11 | version.startsWith("1."); 12 | 13 | } 14 | 15 | @Test 16 | public void testVersion() { 17 | System.out.println(isJava8orBelow()); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /nanocloud/src/test/java/org/gridkit/nanocloud/test/cglib/MyConfigA.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.test.cglib; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Configuration 8 | public class MyConfigA { 9 | 10 | @Autowired(required = true) 11 | HelloMsg message; 12 | 13 | @Bean 14 | public HelloService createHelloService() { 15 | return new HelloService() { 16 | 17 | @Override 18 | public void sayHello() { 19 | System.out.println(message.toString()); 20 | } 21 | }; 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/Cloud.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud; 2 | 3 | import java.util.Collection; 4 | 5 | import org.gridkit.vicluster.ViNode; 6 | 7 | /** 8 | * 9 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 10 | */ 11 | public interface Cloud { 12 | 13 | /** 14 | * Return node by name (or group of nodes for pattern). 15 | */ 16 | public ViNode node(String nameOrSelector); 17 | 18 | public ViNode nodes(String... nameOrSelector); 19 | 20 | /** 21 | * List non-terminated nodes matching namePattern 22 | */ 23 | public Collection listNodes(String nameOrSelector); 24 | 25 | public void shutdown(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/NodeExecutionException.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud; 2 | 3 | /** 4 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 5 | */ 6 | public class NodeExecutionException extends NanocloudException { 7 | 8 | private static final long serialVersionUID = 20140118L; 9 | 10 | public NodeExecutionException() { 11 | super(); 12 | } 13 | 14 | public NodeExecutionException(String message, Throwable cause) { 15 | super(message, cause); 16 | } 17 | 18 | public NodeExecutionException(String message) { 19 | super(message); 20 | } 21 | 22 | public NodeExecutionException(Throwable cause) { 23 | super(cause); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/LocalNodeTypeInitializer.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | import static org.gridkit.nanocloud.viengine.NodeConfigHelper.cloudSingleton; 4 | 5 | import org.gridkit.nanocloud.telecontrol.LocalControlConsole; 6 | 7 | public class LocalNodeTypeInitializer extends SlaveJvmNodeTypeInitializer { 8 | 9 | @Override 10 | protected void configureHostControlConsoleSubphase(PragmaWriter config) { 11 | super.configureHostControlConsoleSubphase(config); 12 | cloudSingleton(config, Pragma.RUNTIME_HOST_CONTROL_CONSOLE, LocalControlConsole.class, "terminate"); 13 | } 14 | 15 | 16 | } 17 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/telecontrol/isolate/IsolateRemoteSessionWrapper.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.telecontrol.isolate; 2 | 3 | import org.gridkit.nanocloud.telecontrol.RemoteExecutionSession; 4 | import org.gridkit.nanocloud.telecontrol.RemoteExecutionSessionWrapper; 5 | 6 | /** 7 | * This wrapper will start remote slave in Isolate. 8 | * 9 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 10 | */ 11 | public class IsolateRemoteSessionWrapper implements RemoteExecutionSessionWrapper { 12 | 13 | @Override 14 | public RemoteExecutionSession wrap(RemoteExecutionSession session) { 15 | return new IsolatedRemoteSession(session); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zeroio/WriterOutputStream.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.zeroio; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | import java.io.Writer; 6 | 7 | public class WriterOutputStream extends OutputStream { 8 | 9 | private final Writer writer; 10 | 11 | public WriterOutputStream(Writer writer) { 12 | this.writer = writer; 13 | } 14 | 15 | @Override 16 | public void write(int b) throws IOException { 17 | writer.append((char)b); 18 | } 19 | 20 | @Override 21 | public void flush() throws IOException { 22 | writer.flush(); 23 | } 24 | 25 | @Override 26 | public void close() throws IOException { 27 | writer.close(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/PassthroughPragmaHandler.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | import java.util.Map; 4 | 5 | class PassthroughPragmaHandler implements PragmaHandler { 6 | 7 | @Override 8 | public void init(PragmaWriter conext) { 9 | // do nothing 10 | } 11 | 12 | @Override 13 | public Object query(PragmaWriter context, String key) { 14 | return context.get(key); 15 | } 16 | 17 | @Override 18 | public void apply(PragmaWriter context, Map values) { 19 | for(String key: values.keySet()) { 20 | context.set(key, values.get(key)); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/NodeConfigurationException.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud; 2 | 3 | /** 4 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 5 | */ 6 | public class NodeConfigurationException extends NanocloudException { 7 | 8 | private static final long serialVersionUID = 20140118L; 9 | 10 | public NodeConfigurationException() { 11 | super(); 12 | } 13 | 14 | public NodeConfigurationException(String message, Throwable cause) { 15 | super(message, cause); 16 | } 17 | 18 | public NodeConfigurationException(String message) { 19 | super(message); 20 | } 21 | 22 | public NodeConfigurationException(Throwable cause) { 23 | super(cause); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | NanoCloud 2 | ==== 3 | 4 | A dead simple yet powerful library for remote execution of java code. 5 | 6 | * no deployment 7 | * transparent remotting 8 | * down scale your topology to run in single JVM or up scale to dozens of servers with single line tweak 9 | 10 | Please read [this article][blog] outlining idea or 11 | 12 | * Checkout demo project at [https://github.com/gridkit/nanocloud-getting-started](https://github.com/gridkit/nanocloud-getting-started) 13 | * and go thorough [tutorial][tutorial]. 14 | 15 | [blog]: http://blog.ragozin.info/2013/01/remote-code-execution-in-java-made.html 16 | [tutorial]: https://github.com/gridkit/nanocloud/blob/vicluster-0.8/docs/NanoCloud_Tutorial.md 17 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/NanocloudException.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud; 2 | 3 | /** 4 | * Base class for Nanocloud exceptions. 5 | * 6 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 7 | */ 8 | public class NanocloudException extends RuntimeException { 9 | 10 | private static final long serialVersionUID = 20140118L; 11 | 12 | public NanocloudException() { 13 | super(); 14 | } 15 | 16 | public NanocloudException(String message, Throwable cause) { 17 | super(message, cause); 18 | } 19 | 20 | public NanocloudException(String message) { 21 | super(message); 22 | } 23 | 24 | public NanocloudException(Throwable cause) { 25 | super(cause); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/NodeStartupRuntimeException.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud; 2 | 3 | /** 4 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 5 | */ 6 | public class NodeStartupRuntimeException extends NanocloudException { 7 | 8 | private static final long serialVersionUID = 20140118L; 9 | 10 | public NodeStartupRuntimeException() { 11 | super(); 12 | } 13 | 14 | public NodeStartupRuntimeException(String message, Throwable cause) { 15 | super(message, cause); 16 | } 17 | 18 | public NodeStartupRuntimeException(String message) { 19 | super(message); 20 | } 21 | 22 | public NodeStartupRuntimeException(Throwable cause) { 23 | super(cause); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /nanocloud/src/test/java/org/gridkit/nanocloud/SharedStatics.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.nanocloud; 17 | 18 | public class SharedStatics { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/PassivePragmaHandler.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | import java.util.Map; 4 | 5 | class PassivePragmaHandler implements PragmaHandler { 6 | 7 | @Override 8 | public void init(PragmaWriter conext) { 9 | // do nothing 10 | } 11 | 12 | @Override 13 | public Object query(PragmaWriter context, String key) { 14 | return context.get(key); 15 | } 16 | 17 | @Override 18 | public void apply(PragmaWriter context, Map values) { 19 | String phase = context.get(Pragma.BOOT_PHASE); 20 | if (phase != null && phase.length() == 0) { 21 | throw new IllegalStateException("Node already started"); 22 | } 23 | else { 24 | // ignore 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /nanocloud/src/test/java/org/gridkit/nanocloud/viengine/SimpleViEngine2Test.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | import org.gridkit.nanocloud.Cloud; 4 | import org.gridkit.nanocloud.VX; 5 | import org.gridkit.vicluster.ViNode; 6 | import org.junit.Test; 7 | 8 | public class SimpleViEngine2Test { 9 | 10 | @Test 11 | public void helo_node_local() { 12 | Cloud cloud = Engine2.createCloud(); 13 | 14 | ViNode node = cloud.node("a"); 15 | node.x(VX.TYPE).setLocal(); 16 | 17 | node.exec(new Runnable() { 18 | 19 | @Override 20 | public void run() { 21 | System.out.println("Helo from " + System.getProperty("vinode.name")); 22 | } 23 | }); 24 | 25 | cloud.shutdown(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/telecontrol/ManagedProcess.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.vicluster.telecontrol; 2 | 3 | import java.io.InputStream; 4 | import java.io.OutputStream; 5 | 6 | import org.gridkit.util.concurrent.AdvancedExecutor; 7 | import org.gridkit.util.concurrent.FutureEx; 8 | 9 | public interface ManagedProcess { 10 | 11 | public void suspend(); 12 | 13 | public void resume(); 14 | 15 | public void destroy(); 16 | 17 | /** 18 | * Pulls pending data from stdOut/stdErr pipes 19 | */ 20 | public void consoleFlush(); 21 | 22 | public FutureEx getExitCodeFuture(); 23 | 24 | public AdvancedExecutor getExecutionService(); 25 | 26 | public void bindStdIn(InputStream is); 27 | 28 | public void bindStdOut(OutputStream os); 29 | 30 | public void bindStdErr(OutputStream os); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /interceptor/src/main/java/org/gridkit/lab/interceptor/HookType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.lab.interceptor; 17 | 18 | public enum HookType { 19 | 20 | METHOD_CALL_SITE, 21 | 22 | } 23 | -------------------------------------------------------------------------------- /viconcurrent/src/main/java/org/gridkit/util/concurrent/Latch.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.util.concurrent; 17 | 18 | public interface Latch { 19 | 20 | public void open(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zeroio/LineLoggerOutputStream.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.zeroio; 2 | 3 | import java.io.IOException; 4 | 5 | import org.gridkit.zerormi.zlog.LogStream; 6 | 7 | public class LineLoggerOutputStream extends AbstractLineProcessingOutputStream { 8 | 9 | private String prefix; 10 | private LogStream stream; 11 | 12 | public LineLoggerOutputStream(LogStream stream) { 13 | this("", stream); 14 | } 15 | 16 | public LineLoggerOutputStream(String prefix, LogStream stream) { 17 | this.prefix = prefix; 18 | this.stream = stream; 19 | } 20 | 21 | @Override 22 | protected void processLine(byte[] data) throws IOException { 23 | String line = new String(data); 24 | while(line.endsWith("\n") || line.endsWith("\r")) { 25 | line = line.substring(0, line.length() - 1); 26 | } 27 | stream.log(prefix + line); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/log/Slf4jInstantiator.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.log; 2 | 3 | import java.util.Map; 4 | 5 | import org.gridkit.zerormi.zlog.ZLogFactory; 6 | import org.gridkit.zerormi.zlog.ZLogger; 7 | import org.slf4j.Logger; 8 | 9 | public class Slf4jInstantiator implements LoggerInstantiator { 10 | 11 | public static boolean isAvailable() { 12 | try { 13 | Logger.class.getName(); 14 | return true; 15 | } catch (Throwable e) { 16 | return false; 17 | } 18 | } 19 | 20 | @Override 21 | public ZLogger instantiate(Map config) { 22 | String root = (String) config.get("root"); 23 | if (root == null) { 24 | root = ""; 25 | } 26 | ZLogger zl = ZLogFactory.getSlf4JRootLogger().getLogger(root); 27 | if (root != null) { 28 | zl = zl.getLogger(root); 29 | } 30 | return zl; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /nanocloud/src/test/java/org/gridkit/nanocloud/StaticVarHost.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.nanocloud; 17 | 18 | public class StaticVarHost { 19 | 20 | public static String TEST_STATIC_VAR = "not set"; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /vicluster-core/src/test/java/org/gridkit/vicluster/isolate/StaticVarHost.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster.isolate; 17 | 18 | public class StaticVarHost { 19 | 20 | public static String TEST_STATIC_VAR = "not set"; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/zlog/LogLevel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi.zlog; 17 | 18 | public enum LogLevel { 19 | TRACE, 20 | DEBUG, 21 | VERBOSE, 22 | INFO, 23 | WARN, 24 | CRITICAL, 25 | FATAL, 26 | OFF 27 | } 28 | -------------------------------------------------------------------------------- /interceptor/src/main/java/org/gridkit/nanocloud/interceptor/CallFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.nanocloud.interceptor; 17 | 18 | import org.gridkit.lab.interceptor.Interception; 19 | 20 | public interface CallFilter { 21 | 22 | public boolean matches(Interception call); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/NotSupportedPragmaHandler.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | import java.util.Map; 4 | 5 | import org.gridkit.nanocloud.NodeConfigurationException; 6 | 7 | class NotSupportedPragmaHandler implements PragmaHandler { 8 | 9 | private String message; 10 | 11 | public NotSupportedPragmaHandler(String message) { 12 | this.message = message; 13 | } 14 | 15 | @Override 16 | public void init(PragmaWriter conext) { 17 | // do nothing 18 | } 19 | 20 | @Override 21 | public Object query(PragmaWriter context, String key) { 22 | return context.get(key); 23 | } 24 | 25 | @Override 26 | public void apply(PragmaWriter context, Map values) { 27 | String key = values.keySet().iterator().next(); 28 | throw new NodeConfigurationException("Cannot apply '" + key + "'. " + message); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /viconcurrent/src/main/java/org/gridkit/util/concurrent/FutureEx.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.util.concurrent; 17 | 18 | import java.util.concurrent.Future; 19 | 20 | 21 | public interface FutureEx extends Future { 22 | 23 | public void addListener(Box box); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/RemoteMessage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi; 17 | 18 | 19 | /** 20 | * Marker interface for low level RPC messages. 21 | * 22 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 23 | */ 24 | interface RemoteMessage { 25 | 26 | public long getCallId(); 27 | } 28 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/Box.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011-2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi; 17 | 18 | /** 19 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 20 | */ 21 | interface Box { 22 | 23 | public void setData(V data); 24 | 25 | public void setError(Exception e); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/ViNodeProps.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster; 17 | 18 | /** 19 | * Marker interface for easy browsing of vi-props 20 | * dictionaries. 21 | * 22 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 23 | */ 24 | public interface ViNodeProps { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/hub/LegacySpore.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.zerormi.hub; 2 | 3 | import org.gridkit.zerormi.DuplexStreamConnector; 4 | 5 | /** 6 | * This is a legacy implementation of {@link SlaveSpore} to be used 7 | * with old bootstrapper. 8 | * 9 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 10 | */ 11 | public class LegacySpore implements SlaveSpore { 12 | 13 | private static final long serialVersionUID = 20130806L; 14 | 15 | private final String uid; 16 | 17 | public static String uidOf(SlaveSpore spore) { 18 | return ((LegacySpore)spore).getUID(); 19 | } 20 | 21 | public LegacySpore(String uid) { 22 | this.uid = uid; 23 | } 24 | 25 | public String getUID() { 26 | return uid; 27 | } 28 | 29 | @Override 30 | public void start(DuplexStreamConnector masterConnector) { 31 | RemotingEndPoint endpoint = new RemotingEndPoint(uid, masterConnector); 32 | endpoint.enableHeartbeatDeatchWatch(); 33 | endpoint.run(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/MagicProps.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.nanocloud; 17 | 18 | /** 19 | * Few magic properties for internal use only ;) 20 | * 21 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 22 | */ 23 | public class MagicProps { 24 | 25 | public static final String DEBUG_RPC_DELAY = "gridkit.zerormi.debug.rpc-delay"; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /interceptor/src/test/java/org/gridkit/lab/interceptor/test/SimpleClass_CRT.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.lab.interceptor.test; 17 | 18 | import java.util.concurrent.Callable; 19 | 20 | public class SimpleClass_CRT implements Callable { 21 | 22 | @Override 23 | public String call() throws Exception { 24 | return "Hello world!".toUpperCase(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /viconcurrent/src/main/java/org/gridkit/util/concurrent/Box.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.util.concurrent; 17 | 18 | /** 19 | * Interface to receive execution result. 20 | * 21 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 22 | */ 23 | public interface Box { 24 | 25 | public void setData(V data); 26 | 27 | public void setError(Throwable e); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /interceptor/src/main/java/org/gridkit/lab/interceptor/CutPoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.lab.interceptor; 17 | 18 | import java.io.Serializable; 19 | 20 | public interface CutPoint extends Serializable { 21 | 22 | public boolean evaluateCallSite(String hostClass, String hostMethod, String methodSignature, String targetClass, String targetMethod, String targetSignature); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /vicluster-core/src/test/java/org/gridkit/nanocloud/telecontrol/TunnelInitiatorTest.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.telecontrol; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.concurrent.TimeoutException; 6 | 7 | import org.gridkit.vicluster.telecontrol.BackgroundStreamDumper; 8 | import org.gridkit.zerormi.zlog.ZLogFactory; 9 | 10 | public class TunnelInitiatorTest extends LocalControlConsoleTest { 11 | 12 | private LocalControlConsole lcon = new LocalControlConsole("./target/tmp-host"); 13 | private SimpleTunnelInitiator initiator = new SimpleTunnelInitiator(System.getProperty("java.home") + File.separator + "bin" + File.separator + "java", "./target/tmp", BackgroundStreamDumper.SINGLETON, ZLogFactory.getStdErrRootLogger()); 14 | 15 | @Override 16 | public void initConsole() throws IOException, InterruptedException, TimeoutException { 17 | console = initiator.initTunnel(lcon); 18 | } 19 | 20 | @Override 21 | public void destroyConsole() { 22 | console.terminate(); 23 | lcon.terminate(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/zlog/LogStream.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi.zlog; 17 | 18 | public interface LogStream { 19 | 20 | public boolean isEnabled(); 21 | 22 | public void log(String message); 23 | 24 | public void log(Throwable e); 25 | 26 | public void log(String message, Throwable e); 27 | 28 | public void log(String format, Object... argument); 29 | } 30 | -------------------------------------------------------------------------------- /nanotest/src/main/java/org/gridkit/nanocloud/test/junit/DisposableCloud.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.test.junit; 2 | 3 | import java.util.Collection; 4 | 5 | import org.gridkit.nanocloud.Cloud; 6 | import org.gridkit.nanocloud.CloudFactory; 7 | import org.gridkit.vicluster.ViNode; 8 | import org.junit.rules.ExternalResource; 9 | 10 | public class DisposableCloud extends ExternalResource implements CloudRule { 11 | 12 | private Cloud cloud = CloudFactory.createCloud(); 13 | 14 | @Override 15 | protected void after() { 16 | shutdown(); 17 | } 18 | 19 | public ViNode all() { 20 | return node("**"); 21 | } 22 | 23 | public ViNode node(String nameOrSelector) { 24 | return cloud.node(nameOrSelector); 25 | } 26 | 27 | public ViNode nodes(String... nameOrSelector) { 28 | return cloud.nodes(nameOrSelector); 29 | } 30 | 31 | public Collection listNodes(String nameOrSelector) { 32 | return cloud.listNodes(nameOrSelector); 33 | } 34 | 35 | public void shutdown() { 36 | cloud.shutdown(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /vicluster-core/src/test/java/org/gridkit/vicluster/telecontrol/TestStreamHelper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster.telecontrol; 17 | 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | import java.io.OutputStream; 21 | 22 | public class TestStreamHelper { 23 | 24 | public static void copy(InputStream in, OutputStream out) throws IOException { 25 | StreamHelper.copy(in, out); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /telecontrol-ssh/src/main/java/org/gridkit/vicluster/telecontrol/ssh/RemoteFileCache.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster.telecontrol.ssh; 17 | 18 | import java.util.List; 19 | 20 | import org.gridkit.vicluster.telecontrol.FileBlob; 21 | 22 | public interface RemoteFileCache { 23 | 24 | public String upload(FileBlob blob); 25 | 26 | public List upload(List blobs); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/RmiMarshaler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi; 17 | 18 | import java.io.IOException; 19 | 20 | /** 21 | * 22 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 23 | */ 24 | public interface RmiMarshaler { 25 | 26 | public Object writeReplace(Object obj) throws IOException; 27 | 28 | public Object readResolve(Object obj) throws IOException; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/telecontrol/JvmProcessFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster.telecontrol; 17 | 18 | import java.io.IOException; 19 | 20 | /** 21 | * 22 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 23 | */ 24 | public interface JvmProcessFactory { 25 | 26 | public ManagedProcess createProcess(String caption, JvmConfig jvmArgs) throws IOException; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /viconcurrent/src/main/java/org/gridkit/util/concurrent/RunnableEx.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.util.concurrent; 17 | 18 | public interface RunnableEx extends Runnable { 19 | 20 | /** 21 | * This method will be called in case of task abort. 22 | * Executer is providing guaranty that exactly one method, {@link #run()} or {@link #cancelled()} will be called on submitted task. 23 | */ 24 | public void cancelled(); 25 | } 26 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/SharedEntity.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | import org.gridkit.vicluster.CloudContext; 4 | import org.gridkit.vicluster.CloudContext.ServiceKey; 5 | import org.gridkit.vicluster.CloudContext.ServiceProvider; 6 | 7 | public class SharedEntity implements LazyPragma { 8 | 9 | private final ServiceKey key; 10 | private final ServiceProvider provider; 11 | 12 | public SharedEntity(ServiceKey key, ServiceProvider provider) { 13 | this.key = key; 14 | this.provider = provider; 15 | } 16 | 17 | @Override 18 | public Object resolve(String pragmaKey, PragmaReader context) { 19 | CloudContext ctx = (CloudContext) context.get(Pragma.NODE_CLOUD_CONTEXT); 20 | if (ctx == null) { 21 | throw new IllegalArgumentException("Cloud context is missing"); 22 | } 23 | return provider == null ? ctx.lookup(key) : ctx.lookup(key, provider); 24 | } 25 | 26 | public String toString() { 27 | return "SHARED[" + key + "]"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/telecontrol/LocalNodeTypeHandler.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.telecontrol; 2 | 3 | import java.io.File; 4 | 5 | import org.gridkit.vicluster.ViEngine; 6 | import org.gridkit.vicluster.ViEngine.Interceptor; 7 | import org.gridkit.vicluster.ViEngine.QuorumGame; 8 | import org.gridkit.vicluster.telecontrol.GenericNodeTypeHandler; 9 | 10 | public class LocalNodeTypeHandler extends GenericNodeTypeHandler { 11 | 12 | protected String defaultJavaExecCmd(QuorumGame game) { 13 | // this should work for Windows and Unix even though in Windows executable is java.exe 14 | File f = new File(new File(new File(System.getProperty("java.home")), "bin"), "java"); 15 | return f.getPath(); 16 | } 17 | 18 | protected HostControlConsole createControlConsole(QuorumGame game) { 19 | return getCloudSingleton(game, LocalControlConsole.class, "terminate"); 20 | } 21 | 22 | @Override 23 | protected Interceptor createClasspathBuilder(QuorumGame game) { 24 | return new ViEngine.RuleSet(new ShallowClasspathBuilder(), new ClasspathReplicaBuilderLocal()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /interceptor/src/main/java/org/gridkit/lab/interceptor/Interceptor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.lab.interceptor; 17 | 18 | 19 | /** 20 | * Handler of execution interception event. 21 | * Class implementing this interface may witness or override behavior of intercepted call. 22 | * 23 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 24 | */ 25 | public interface Interceptor { 26 | 27 | public void handle(Interception call); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /telecontrol-ssh/src/main/java/org/gridkit/nanocloud/telecontrol/ssh/RemoteNodeTypeHandler.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.telecontrol.ssh; 2 | 3 | import org.gridkit.nanocloud.telecontrol.HostControlConsole; 4 | import org.gridkit.vicluster.ViEngine; 5 | import org.gridkit.vicluster.ViEngine.QuorumGame; 6 | import org.gridkit.vicluster.telecontrol.GenericNodeTypeHandler; 7 | 8 | public class RemoteNodeTypeHandler extends GenericNodeTypeHandler { 9 | 10 | @Override 11 | protected String defaultJavaExecCmd(QuorumGame game) { 12 | return null; 13 | } 14 | 15 | @Override 16 | protected void initExtraConfigurationRules(QuorumGame game) { 17 | super.initExtraConfigurationRules(game); 18 | // TODO rule or intercepter? 19 | game.rerunOnQuorum(new HostConfigurationInitializer.Runner()); 20 | } 21 | 22 | @Override 23 | protected HostControlConsole createControlConsole(QuorumGame game) { 24 | // console would be create via rule 25 | return null; 26 | } 27 | 28 | @Override 29 | protected void initControlConsole(QuorumGame game) { 30 | ViEngine.Core.addRule(game, new RemoteConsoleInitializer()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/ObjectPipe.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011-2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi; 17 | 18 | public interface ObjectPipe { 19 | 20 | public void bind(ObjectPipeEventHandler receiver); 21 | 22 | public void sendObject(Object object); 23 | 24 | public void close(); 25 | 26 | public interface ObjectPipeEventHandler { 27 | 28 | public void objectReceived(Object object); 29 | 30 | public void closed(); 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /telecontrol-ssh/src/test/java/org/gridkit/lab/util/shell/ShellTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.lab.util.shell; 17 | 18 | import java.io.IOException; 19 | 20 | import org.junit.Test; 21 | 22 | public class ShellTest { 23 | 24 | @Test 25 | public void test() throws IOException, InterruptedException { 26 | Prompt p = Shell.prompt(); 27 | p.cd("{temp}"); 28 | for(String s: p.find("**/*.exe")) { 29 | System.out.println(s); 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/ViNodeProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster; 17 | 18 | /** 19 | * This class is used by ViManager to create instances of named ViNodes. 20 | * 21 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 22 | */ 23 | public interface ViNodeProvider { 24 | 25 | public boolean verifyNodeConfig(ViNodeConfig config); 26 | 27 | public ViNode createNode(String name, ViNodeConfig config); 28 | 29 | public void shutdown(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/hub/Ping.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi.hub; 17 | 18 | import java.io.Serializable; 19 | import java.util.concurrent.Callable; 20 | 21 | /** 22 | * 23 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 24 | */ 25 | public class Ping implements Callable, Serializable { 26 | 27 | private static final long serialVersionUID = 20120318L; 28 | 29 | @Override 30 | public Void call() throws Exception { 31 | return null; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /viconcurrent/src/main/java/org/gridkit/util/concurrent/DebugHelper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.util.concurrent; 17 | 18 | public class DebugHelper { 19 | 20 | public static void enableJUnitTimeouts() { 21 | FutureBox.enableStoppability(true); 22 | } 23 | 24 | public static void traceTaskService() { 25 | SensibleTaskService.TRACE = true; 26 | } 27 | 28 | public static void disableDebug() { 29 | FutureBox.enableStoppability(false); 30 | SensibleTaskService.TRACE = false; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /interceptor/src/test/java/org/gridkit/vicluster/isolate/LocalInstrumentationFeatureTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster.isolate; 17 | 18 | import org.gridkit.nanocloud.CloudFactory; 19 | import org.gridkit.vicluster.ViProps; 20 | import org.junit.Before; 21 | 22 | public class LocalInstrumentationFeatureTest extends InstrumentationFeatureTest { 23 | 24 | @Before 25 | public void initCloud() { 26 | cloud = CloudFactory.createCloud(); 27 | ViProps.at(cloud.node("**")).setLocalType(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/AbstractStopAction.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | import java.util.concurrent.ExecutionException; 4 | 5 | public abstract class AbstractStopAction implements NodeAction { 6 | 7 | boolean runShutdown; 8 | boolean runPostShutdown; 9 | 10 | public AbstractStopAction(boolean runShutdown, boolean runPostShutdown) { 11 | this.runShutdown = runShutdown; 12 | this.runPostShutdown = runPostShutdown; 13 | } 14 | 15 | @Override 16 | public void run(PragmaWriter context) throws ExecutionException { 17 | if (runShutdown) { 18 | PragmaHelper.runHooks(context, Pragma.NODE_SHUTDOWN_HOOK); 19 | try { 20 | TextTerminalControl console = context.get(Pragma.RUNTIME_TEXT_TERMINAL); 21 | console.consoleFlush(); 22 | } 23 | catch(Exception e) { 24 | // ignore 25 | } 26 | } 27 | stop(); 28 | if (runPostShutdown) { 29 | PragmaHelper.runHooks(context, Pragma.NODE_POST_SHUTDOWN_HOOK); 30 | } 31 | } 32 | 33 | protected abstract void stop(); 34 | } 35 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/zlog/ZLogger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi.zlog; 17 | 18 | public interface ZLogger { 19 | 20 | public ZLogger getLogger(String path); 21 | 22 | public LogStream get(String path, LogLevel level); 23 | 24 | public LogStream fatal(); 25 | 26 | public LogStream critical(); 27 | 28 | public LogStream warn(); 29 | 30 | public LogStream info(); 31 | 32 | public LogStream verbose(); 33 | 34 | public LogStream debug(); 35 | 36 | public LogStream trace(); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/ManagedProcessTextTerminal.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | import java.io.OutputStream; 4 | 5 | import org.gridkit.vicluster.telecontrol.ManagedProcess; 6 | import org.gridkit.vicluster.telecontrol.StreamPipe; 7 | 8 | public class ManagedProcessTextTerminal implements TextTerminalControl { 9 | 10 | private ManagedProcess process; 11 | private StreamPipe stdInPipe = new StreamPipe(1 << 10); 12 | private OutputStream processIn; 13 | 14 | public ManagedProcessTextTerminal(ManagedProcess process) { 15 | this.process = process; 16 | this.process.bindStdIn(stdInPipe.getInputStream()); 17 | this.processIn = stdInPipe.getOutputStream(); 18 | } 19 | 20 | @Override 21 | public void consoleFlush() { 22 | process.consoleFlush(); 23 | } 24 | 25 | @Override 26 | public OutputStream getStdIn() { 27 | return processIn; 28 | } 29 | 30 | @Override 31 | public void bindStdOut(OutputStream os) { 32 | process.bindStdOut(os); 33 | } 34 | 35 | @Override 36 | public void bindStdErr(OutputStream os) { 37 | process.bindStdErr(os); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /vicluster-core/src/test/java/org/gridkit/nanocloud/Retry.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud; 2 | 3 | import org.junit.rules.TestRule; 4 | import org.junit.runner.Description; 5 | import org.junit.runners.model.Statement; 6 | 7 | public class Retry implements TestRule { 8 | 9 | private int retryCount; 10 | 11 | public Retry(int retryCount) { 12 | this.retryCount = retryCount; 13 | } 14 | 15 | public Statement apply(Statement base, Description description) { 16 | return statement(base, description); 17 | } 18 | 19 | private Statement statement(final Statement base, final Description description) { 20 | return new Statement() { 21 | @Override 22 | public void evaluate() throws Throwable { 23 | Throwable caughtThrowable = null; 24 | 25 | // implement retry logic here 26 | for (int i = 0; i < retryCount; i++) { 27 | try { 28 | base.evaluate(); 29 | return; 30 | } catch (Throwable t) { 31 | caughtThrowable = t; 32 | System.err.println(description.getDisplayName() + ": run " + (i + 1) + " failed"); 33 | } 34 | } 35 | System.err.println(description.getDisplayName() + ": giving up after " + retryCount + " failures"); 36 | throw caughtThrowable; 37 | } 38 | }; 39 | } 40 | } -------------------------------------------------------------------------------- /viconcurrent/src/main/java/org/gridkit/util/concurrent/AdvancedExecutor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.util.concurrent; 17 | 18 | import java.util.concurrent.Callable; 19 | import java.util.concurrent.Executor; 20 | 21 | 22 | public interface AdvancedExecutor extends Executor { 23 | 24 | public void execute(Runnable task); 25 | 26 | public FutureEx submit(Runnable task); 27 | 28 | public FutureEx submit(Callable task); 29 | 30 | public interface Component extends AdvancedExecutor { 31 | 32 | public void shutdown(); 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/BeanRef.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011-2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * 22 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 23 | */ 24 | public class BeanRef implements Serializable { 25 | 26 | private static final long serialVersionUID = 20080415L; 27 | 28 | private String beanId; 29 | 30 | public BeanRef(String beanId) { 31 | this.beanId = beanId; 32 | } 33 | 34 | public String getBeanName() { 35 | return beanId; 36 | } 37 | 38 | public String toString() { 39 | return beanId; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/LazyClassInstantiator.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | class LazyClassInstantiator implements LazyPragma { 4 | 5 | public static LazyClassInstantiator INSTANCE = new LazyClassInstantiator(); 6 | 7 | @Override 8 | @SuppressWarnings("deprecation") 9 | public Object resolve(String key, PragmaReader context) { 10 | int c = key.lastIndexOf(':'); 11 | if (c < 0) { 12 | throw new IllegalArgumentException("Invalid key '" + key + "', cannot derive class name"); 13 | } 14 | String cn = key.substring(c + 1); 15 | Object bean; 16 | try { 17 | Class cl = Thread.currentThread().getContextClassLoader().loadClass(cn); 18 | bean = cl.newInstance(); 19 | } catch (ClassNotFoundException e) { 20 | throw new IllegalArgumentException("Cannot instantiate '" + key + "'", e); 21 | } catch (InstantiationException e) { 22 | throw new IllegalArgumentException("Cannot instantiate '" + key + "'", e); 23 | } catch (IllegalAccessException e) { 24 | throw new IllegalArgumentException("Cannot instantiate '" + key + "'", e); 25 | } 26 | return bean; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /telecontrol-ssh/src/test/java/org/gridkit/lab/util/shell/TailerCheck.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.lab.util.shell; 17 | 18 | import java.io.File; 19 | import java.io.IOException; 20 | 21 | import org.junit.Test; 22 | 23 | public class TailerCheck { 24 | 25 | @Test 26 | public void test() throws IOException, InterruptedException { 27 | Tailer tailer = new Tailer(new File("c:\\\\log.txt")); 28 | while(true) { 29 | String line = tailer.nextLine(); 30 | if (line == null) { 31 | Thread.sleep(1000); 32 | } 33 | else { 34 | System.out.println(line); 35 | } 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /telecontrol-ssh/src/main/java/org/gridkit/vicluster/telecontrol/ssh/SshSessionFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster.telecontrol.ssh; 17 | 18 | import com.jcraft.jsch.JSchException; 19 | import com.jcraft.jsch.Session; 20 | 21 | /** 22 | * This class encapsulate credentials and network configuration. 23 | * One provide could handle multiple hosts. 24 | * 25 | * TODO add optional account name as paramater. 26 | * 27 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 28 | */ 29 | public interface SshSessionFactory { 30 | 31 | public Session getSession(String host, String account) throws JSchException; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/isolate/ThreadKiller.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster.isolate; 17 | 18 | /** 19 | * JVM does not provide means to kill a thread. This makes uncooperative termination of isolate problematic. 20 | * Thread killer is pluging using application specific means to kill thread remaining from isolate. 21 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 22 | */ 23 | public interface ThreadKiller { 24 | 25 | /** 26 | * @return true if killer have done any actions to thread 27 | */ 28 | public boolean tryToKill(Isolate isolate, Thread thread); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /vicluster-core/src/test/java/org/gridkit/vicluster/telecontrol/bootstraper/TunnelTestHelper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster.telecontrol.bootstraper; 17 | 18 | import org.gridkit.vicluster.telecontrol.bootstraper.Tunneller; 19 | 20 | public class TunnelTestHelper { 21 | 22 | public static void enableChannelTrace(Tunneller t) { 23 | t.traceChannelOpen = true; 24 | t.traceChannelData = true; 25 | t.traceChannelClose = true; 26 | } 27 | 28 | public static void enableChannelTrace(TunnellerConnection t) { 29 | t.traceChannelOpen = true; 30 | t.traceChannelData = true; 31 | t.traceChannelClose = true; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /interceptor/src/main/java/org/gridkit/nanocloud/interceptor/ReturnValueStub.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.nanocloud.interceptor; 17 | 18 | import java.io.Serializable; 19 | 20 | import org.gridkit.lab.interceptor.Interception; 21 | import org.gridkit.lab.interceptor.Interceptor; 22 | 23 | class ReturnValueStub implements Interceptor, Serializable { 24 | 25 | private static final long serialVersionUID = 20130621L; 26 | 27 | private Object value; 28 | 29 | public ReturnValueStub(Object value) { 30 | this.value = value; 31 | } 32 | 33 | @Override 34 | public void handle(Interception call) { 35 | call.setResult(value); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/Exported.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi; 17 | 18 | /** 19 | * Special class used to mark object to be exported and replaced by stub. 20 | * 21 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 22 | */ 23 | public class Exported { 24 | 25 | private Class[] interfaces; 26 | private Object object; 27 | 28 | public Exported(Object object, Class... interfaces) { 29 | this.object = object; 30 | this.interfaces = interfaces; 31 | } 32 | 33 | public Class[] getInterfaces() { 34 | return interfaces; 35 | } 36 | 37 | public Object getObject() { 38 | return object; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /zerormi/src/test/java/org/gridkit/zerormi/zlog/PrintStreamLogTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi.zlog; 17 | 18 | import org.gridkit.zerormi.zlog.PrintStreamLogStream; 19 | import org.junit.Test; 20 | 21 | public class PrintStreamLogTest { 22 | 23 | @Test 24 | public void print_log() { 25 | 26 | PrintStreamLogStream ps = new PrintStreamLogStream("%1$tF %1$tT.%1$tL%1$tz TEST %2$s", System.out, true); 27 | 28 | ps.log("Message"); 29 | ps.log(new RuntimeException()); 30 | ps.log("Having troubles with %s", "XXX", new RuntimeException()); 31 | ps.log("Having troubles with %s got %s", "AAA", new RuntimeException()); 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /interceptor/src/main/java/org/gridkit/nanocloud/interceptor/LiteralMatcher.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.nanocloud.interceptor; 17 | 18 | import java.io.Serializable; 19 | 20 | import org.gridkit.nanocloud.interceptor.Intercept.ParamMatcher; 21 | 22 | class LiteralMatcher implements ParamMatcher, Serializable { 23 | 24 | private static final long serialVersionUID = 20130621L; 25 | 26 | private final Object value; 27 | 28 | public LiteralMatcher(Object value) { 29 | this.value = value; 30 | } 31 | 32 | @Override 33 | public boolean matches(Object param) { 34 | return (value == null && param == null) || (value != null && value.equals(param)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/telecontrol/jvm/Any.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster.telecontrol.jvm; 17 | 18 | 19 | class Any { 20 | 21 | @SuppressWarnings("unchecked") 22 | public static T cast(Object ref) { 23 | return (T)ref; 24 | } 25 | 26 | public static RuntimeException throwUnchecked(Throwable e) { 27 | throw AnyThrow.throwAny(e); 28 | } 29 | 30 | private static class AnyThrow { 31 | 32 | @SuppressWarnings("unchecked") 33 | private static RuntimeException throwAny(Throwable e) throws E { 34 | throw (E)e; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/telecontrol/StreamCopyService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster.telecontrol; 17 | 18 | import java.io.InputStream; 19 | import java.io.OutputStream; 20 | 21 | /** 22 | * 23 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 24 | */ 25 | public interface StreamCopyService { 26 | 27 | public Link link(InputStream is, OutputStream os); 28 | 29 | public Link link(InputStream is, final OutputStream os, boolean closeOnEof); 30 | 31 | public void shutdown(); 32 | 33 | public interface Link { 34 | 35 | public void flush(); 36 | 37 | public void flushAndClose(); 38 | 39 | public void join(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /vicluster-core/src/test/java/org/gridkit/nanocloud/telecontrol/isolate/IsolateNodeTest.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.telecontrol.isolate; 2 | 3 | import java.util.concurrent.Callable; 4 | 5 | 6 | import org.gridkit.vicluster.ViConf; 7 | import org.gridkit.vicluster.ViConf.ConsoleConf; 8 | import org.gridkit.vicluster.ViManager; 9 | import org.gridkit.vicluster.ViNode; 10 | import org.gridkit.vicluster.ViProps; 11 | import org.gridkit.vicluster.telecontrol.jvm.ViEngineNodeProvider; 12 | import org.junit.Assert; 13 | import org.junit.Test; 14 | 15 | public class IsolateNodeTest { 16 | 17 | @Test 18 | public void vi_engine_node_test() throws InterruptedException { 19 | ViManager cloud = new ViManager(new ViEngineNodeProvider()); 20 | 21 | cloud.node("**").setConfigElement(ViConf.TYPE_HANDLER + "isolate", new IsolateNodeTypeHandler()); 22 | 23 | ViNode node = cloud.node("test"); 24 | ViProps.at(node).setIsolateType(); 25 | ConsoleConf.at(node).echoPrefix("[TEST] "); 26 | node.touch(); 27 | String r = node.exec(new Callable() { 28 | @Override 29 | public String call() { 30 | System.out.println("Hallo world!"); 31 | System.out.println("My classloader is " + getClass().getClassLoader()); 32 | return"ping"; 33 | } 34 | }); 35 | 36 | Assert.assertEquals("ping", r); 37 | 38 | cloud.shutdown(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zeroio/WrapperOutputStream.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011-2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zeroio; 17 | 18 | import java.io.IOException; 19 | import java.io.PrintStream; 20 | 21 | /** 22 | * @author Alexey Ragozin 23 | */ 24 | public class WrapperOutputStream extends AbstractLineProcessingOutputStream { 25 | 26 | private String prefix; 27 | private PrintStream printStream; 28 | 29 | public WrapperOutputStream(String prefix, PrintStream printStream) { 30 | this.prefix = prefix; 31 | this.printStream = printStream; 32 | } 33 | 34 | @Override 35 | protected void processLine(byte[] data) throws IOException { 36 | printStream.print(prefix + new String(data)); 37 | } 38 | } -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/hub/SlaveSpore.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi.hub; 17 | 18 | import java.io.Serializable; 19 | 20 | import org.gridkit.zerormi.DuplexStreamConnector; 21 | 22 | /** 23 | * Spore is a small piece of remote agent configuration allowing 24 | * it to attach itself to {@link MasterHub}. 25 | * 26 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 27 | */ 28 | public interface SlaveSpore extends Serializable { 29 | 30 | /** 31 | * Spore should connector {@link MasterHub} using provided connector. 32 | * It will not return from this call until its death. 33 | */ 34 | public void start(DuplexStreamConnector masterConnector); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/DuplexStream.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi; 17 | 18 | import java.io.Closeable; 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | import java.io.OutputStream; 22 | 23 | /** 24 | * Logical wrapper for socket like communication channels. 25 | * 26 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 27 | */ 28 | public interface DuplexStream extends Closeable { 29 | 30 | public InputStream getInput() throws IOException; 31 | 32 | public OutputStream getOutput() throws IOException; 33 | 34 | public boolean isClosed(); 35 | 36 | public void close() throws IOException; 37 | 38 | public String toString(); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/ViNodeSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster; 17 | 18 | import java.util.Collection; 19 | 20 | import org.gridkit.nanocloud.Cloud; 21 | 22 | /** 23 | * 24 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 25 | */ 26 | public interface ViNodeSet extends Cloud { 27 | 28 | /** 29 | * Return node by name (or group of nodes for pattern). 30 | */ 31 | public ViNode node(String namePattern); 32 | 33 | public ViNode nodes(String... namePatterns); 34 | 35 | /** 36 | * List non-terminated nodes matching namePattern 37 | */ 38 | public Collection listNodes(String namePattern); 39 | 40 | public void shutdown(); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /telecontrol-ssh/src/main/java/org/gridkit/vicluster/telecontrol/ssh/RemoteJmvReplicator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster.telecontrol.ssh; 17 | 18 | import java.util.Map; 19 | 20 | import org.gridkit.vicluster.telecontrol.JvmProcessFactory; 21 | 22 | public interface RemoteJmvReplicator extends JvmProcessFactory { 23 | 24 | /** 25 | * @param properties - target ViNode config 26 | */ 27 | public void configure(Map nodeConfig); 28 | 29 | /** 30 | * @return configuration finger prints, which could be used to pool and reuse replicators 31 | */ 32 | public String getFingerPrint(); 33 | 34 | public void init() throws Exception; 35 | 36 | public void dispose(); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/telecontrol/ProcessLauncher.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.telecontrol; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import org.gridkit.nanocloud.viengine.ProcessLifecycleListener; 7 | import org.gridkit.vicluster.telecontrol.AgentEntry; 8 | import org.gridkit.vicluster.telecontrol.Classpath.ClasspathEntry; 9 | import org.gridkit.vicluster.telecontrol.ManagedProcess; 10 | import org.gridkit.vicluster.telecontrol.StreamCopyService; 11 | 12 | public interface ProcessLauncher { 13 | 14 | public interface LaunchConfig { 15 | 16 | public String getNodeName(); 17 | 18 | public HostControlConsole getControlConsole(); 19 | 20 | public RemoteExecutionSession getRemotingSession(); 21 | 22 | public ProcessLifecycleListener getLifecycleListener(); 23 | 24 | public String getSlaveJvmExecCmd(); 25 | 26 | public String getSlaveWorkDir(); 27 | 28 | public Map getSlaveEnv(); 29 | 30 | public List getSlaveArgs(); 31 | 32 | public List getSlaveShallowClasspath(); 33 | 34 | public List getSlaveClasspath(); 35 | 36 | public List getAgentEntries(); 37 | 38 | public StreamCopyService getStreamCopyService(); 39 | 40 | } 41 | 42 | public ManagedProcess launchProcess(LaunchConfig config); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/telecontrol/isolate/IsolatePragmaSupport.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.telecontrol.isolate; 2 | 3 | import java.util.Collections; 4 | 5 | import org.gridkit.vicluster.AdvExecutor2ViExecutor; 6 | import org.gridkit.vicluster.ViEngine; 7 | import org.gridkit.vicluster.ViEngine.PragmaHandler; 8 | import org.gridkit.vicluster.ViEngine.WritableSpiConfig; 9 | import org.gridkit.vicluster.ViExecutor; 10 | import org.gridkit.vicluster.isolate.IsolateProps; 11 | import org.gridkit.vicluster.isolate.IsolateSelfInitializer; 12 | 13 | public class IsolatePragmaSupport implements PragmaHandler { 14 | 15 | @Override 16 | public Object get(String key, ViEngine engine) { 17 | return null; 18 | } 19 | 20 | @Override 21 | public void set(String key, Object value, ViEngine engine, WritableSpiConfig writableConfig) { 22 | if ( key.startsWith(IsolateProps.ISOLATE_PACKAGE) 23 | || key.startsWith(IsolateProps.SHARE_PACKAGE) 24 | || key.startsWith(IsolateProps.ISOLATE_CLASS) 25 | || key.startsWith(IsolateProps.SHARE_CLASS)) { 26 | 27 | String val = (String)value; 28 | ViExecutor exec = new AdvExecutor2ViExecutor(engine.getConfig().getManagedProcess().getExecutionService()); 29 | exec.exec(new IsolateSelfInitializer(Collections.singletonMap(key, val))); 30 | } 31 | else { 32 | throw new IllegalArgumentException("Unsupported pragma: " + key); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/telecontrol/FileBlob.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster.telecontrol; 17 | 18 | import java.io.File; 19 | import java.io.InputStream; 20 | 21 | public interface FileBlob { 22 | 23 | /** 24 | * Method returns file path if blob is file based or null otherwise. 25 | * File may be a directory (in later case binary content will represent archived content of directory). 26 | */ 27 | public File getLocalFile(); 28 | 29 | public String getFileName(); 30 | 31 | /** 32 | * Cache does not care about hashing algorithm. 33 | * @return 34 | */ 35 | public String getContentHash(); 36 | 37 | public InputStream getContent(); 38 | 39 | public long size(); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/RmiMarshalStack.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi; 17 | 18 | import java.io.IOException; 19 | 20 | class RmiMarshalStack implements RmiMarshaler { 21 | 22 | private final RmiMarshaler[] marshalers; 23 | 24 | public RmiMarshalStack(RmiMarshaler... marshalers) { 25 | this.marshalers = marshalers; 26 | } 27 | 28 | @Override 29 | public Object writeReplace(Object obj) throws IOException { 30 | for(int i = 0; i != marshalers.length; ++i) { 31 | obj = marshalers[i].writeReplace(obj); 32 | } 33 | return obj; 34 | } 35 | 36 | @Override 37 | public Object readResolve(Object obj) throws IOException { 38 | for(int i = marshalers.length - 1; i >= 0; --i) { 39 | obj = marshalers[i].readResolve(obj); 40 | } 41 | return obj; 42 | } 43 | 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /interceptor/src/main/java/org/gridkit/nanocloud/interceptor/FilterableInterceptor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.nanocloud.interceptor; 17 | 18 | import java.io.Serializable; 19 | 20 | import org.gridkit.lab.interceptor.Interception; 21 | import org.gridkit.lab.interceptor.Interceptor; 22 | 23 | class FilterableInterceptor implements Interceptor, Serializable { 24 | 25 | private static final long serialVersionUID = 20130621L; 26 | 27 | private CallFilter filter; 28 | private Interceptor nested; 29 | 30 | public FilterableInterceptor(CallFilter filter, Interceptor nested) { 31 | this.filter = filter; 32 | this.nested = nested; 33 | } 34 | 35 | @Override 36 | public void handle(Interception call) { 37 | if (filter.matches(call)) { 38 | nested.handle(call); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /interceptor/src/main/java/org/gridkit/lab/interceptor/HookManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.lab.interceptor; 17 | 18 | 19 | /** 20 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 21 | */ 22 | public interface HookManager { 23 | 24 | public String getInvocationTargetClass(); 25 | 26 | public String getInvocationTargetMethod(); 27 | 28 | /** 29 | * @param className - caller class 30 | * @param method - caller 31 | * @param targetClass - target class 32 | * @param targetMethod - target method 33 | * @param targetSignature - target signature 34 | * @return positive hook ID or -1 if call site not to be instrumented 35 | */ 36 | public int checkCallsite(String hostClass, String hostMethod, String methodSignature, String targetClass, String targetMethod, String targetSignature); 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/NullConsole.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | 6 | class NullConsole implements TextTerminalControl { 7 | 8 | private static OutputStream NULL_STREAM = new OutputStream() { 9 | 10 | @Override 11 | public void write(int b) throws IOException { 12 | // do nothing; 13 | } 14 | 15 | @Override 16 | public void write(byte[] b) throws IOException { 17 | // do nothing; 18 | } 19 | 20 | @Override 21 | public void write(byte[] b, int off, int len) throws IOException { 22 | // do nothing; 23 | } 24 | 25 | @Override 26 | public void flush() throws IOException { 27 | // do nothing; 28 | } 29 | 30 | @Override 31 | public void close() throws IOException { 32 | // do nothing; 33 | } 34 | }; 35 | 36 | @Override 37 | public void consoleFlush() { 38 | // do nothing 39 | } 40 | 41 | @Override 42 | public OutputStream getStdIn() { 43 | return NULL_STREAM; 44 | } 45 | 46 | @Override 47 | public void bindStdOut(OutputStream os) { 48 | // do nothing 49 | } 50 | 51 | @Override 52 | public void bindStdErr(OutputStream os) { 53 | // do nothing 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/ReflectionHelper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi; 17 | 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | 21 | class ReflectionHelper { 22 | 23 | private static Map> PRIMITIVES = new HashMap>(); 24 | 25 | static { 26 | PRIMITIVES.put("void", void.class); 27 | PRIMITIVES.put("byte", byte.class); 28 | PRIMITIVES.put("char", char.class); 29 | PRIMITIVES.put("double", double.class); 30 | PRIMITIVES.put("float", float.class); 31 | PRIMITIVES.put("int", int.class); 32 | PRIMITIVES.put("long", long.class); 33 | PRIMITIVES.put("short", short.class); 34 | PRIMITIVES.put("boolean", boolean.class); 35 | } 36 | 37 | public static Class primitiveToClass(String name) { 38 | return PRIMITIVES.get(name); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/RemoteReturn.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi; 17 | 18 | /** 19 | * 20 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 21 | */ 22 | class RemoteReturn implements RemoteMessage { 23 | 24 | /** 25 | * The return is a throwable to be thrown? 26 | */ 27 | boolean throwing; 28 | 29 | /** 30 | * Returning object 31 | */ 32 | Object ret; 33 | 34 | /** 35 | * Call id which generated this return 36 | */ 37 | long callId; 38 | 39 | public RemoteReturn(long callId, boolean throwing, Object ret) { 40 | this.throwing = throwing; 41 | this.ret = ret; 42 | this.callId = callId; 43 | } 44 | 45 | public long getCallId() { 46 | return callId; 47 | } 48 | 49 | public Object getRet() { 50 | return ret; 51 | } 52 | 53 | public boolean isThrowing() { 54 | return throwing; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/isolate/IsolateViNodeProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster.isolate; 17 | 18 | import org.gridkit.vicluster.ViNode; 19 | import org.gridkit.vicluster.ViNodeConfig; 20 | import org.gridkit.vicluster.ViNodeProvider; 21 | 22 | /** 23 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 24 | */ 25 | @Deprecated 26 | public class IsolateViNodeProvider implements ViNodeProvider { 27 | 28 | @Override 29 | public boolean verifyNodeConfig(ViNodeConfig config) { 30 | // TODO 31 | return true; 32 | } 33 | 34 | @Override 35 | public ViNode createNode(String name, ViNodeConfig config) { 36 | IsolateViNode node = new IsolateViNode(name); 37 | config.apply(node); 38 | return node; 39 | } 40 | 41 | @Override 42 | public void shutdown() { 43 | // do nothing 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/telecontrol/isolate/CloseableThreadKiller.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.nanocloud.telecontrol.isolate; 17 | 18 | import java.io.Closeable; 19 | import java.io.IOException; 20 | import java.io.Serializable; 21 | 22 | import org.gridkit.vicluster.isolate.Isolate; 23 | import org.gridkit.vicluster.isolate.ThreadKiller; 24 | 25 | public class CloseableThreadKiller implements ThreadKiller, Serializable { 26 | 27 | private static final long serialVersionUID = 20121101L; 28 | 29 | @Override 30 | public boolean tryToKill(Isolate isolate, Thread thread) { 31 | if (thread instanceof Closeable) { 32 | try { 33 | ((Closeable)thread).close(); 34 | } 35 | catch(IOException e) { 36 | // ignore; 37 | } 38 | return true; 39 | } 40 | else { 41 | return false; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/telecontrol/isolate/CloseableThreadKiller.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster.telecontrol.isolate; 17 | 18 | import java.io.Closeable; 19 | import java.io.IOException; 20 | import java.io.Serializable; 21 | 22 | import org.gridkit.vicluster.isolate.Isolate; 23 | import org.gridkit.vicluster.isolate.ThreadKiller; 24 | 25 | public class CloseableThreadKiller implements ThreadKiller, Serializable { 26 | 27 | private static final long serialVersionUID = 20121101L; 28 | 29 | @Override 30 | public boolean tryToKill(Isolate isolate, Thread thread) { 31 | if (thread instanceof Closeable) { 32 | try { 33 | ((Closeable)thread).close(); 34 | } 35 | catch(IOException e) { 36 | // ignore; 37 | } 38 | return true; 39 | } 40 | else { 41 | return false; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /interceptor/src/main/java/org/gridkit/nanocloud/interceptor/BarrierStub.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.nanocloud.interceptor; 17 | 18 | import java.io.Serializable; 19 | import java.util.concurrent.BrokenBarrierException; 20 | 21 | import org.gridkit.lab.interceptor.Interception; 22 | import org.gridkit.lab.interceptor.Interceptor; 23 | import org.gridkit.util.concurrent.BlockingBarrier; 24 | 25 | class BarrierStub implements Interceptor, Serializable { 26 | 27 | private static final long serialVersionUID = 20130621L; 28 | 29 | private BlockingBarrier barrier; 30 | 31 | public BarrierStub(BlockingBarrier barrier) { 32 | this.barrier = barrier; 33 | } 34 | 35 | @Override 36 | public void handle(Interception call) { 37 | try { 38 | barrier.pass(); 39 | } catch (InterruptedException e) { 40 | } catch (BrokenBarrierException e) { 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/ProcessLifecycleListener.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | public interface ProcessLifecycleListener { 7 | 8 | /** 9 | * Called then node command is executed. 10 | * Callback is not used if node is not started via shell. 11 | */ 12 | public void processStarted(String nodeName, ExecInfo execInfo); 13 | 14 | /** 15 | * Called then node command has failed to execute. 16 | * Callback is not used if node is not started via shell. 17 | */ 18 | public void processExecFailed(String nodeName, ExecFailedInfo execFailedInfo); 19 | 20 | /** 21 | * Called then node's process has been terminated. 22 | * Callback is not used if node is not started via shell. 23 | */ 24 | public void processTerminated(String nodeName, TerminationInfo termInfo); 25 | 26 | public interface ExecInfo { 27 | 28 | public String getNodeName(); 29 | 30 | public String getHostname(); 31 | 32 | public String getWorkPath(); 33 | 34 | public List getCommand(); 35 | 36 | public Map getAddedEnvironment(); 37 | } 38 | 39 | public interface ExecFailedInfo extends ExecInfo { 40 | 41 | public String getError(); 42 | } 43 | 44 | public interface TerminationInfo { 45 | 46 | public String getNodeName(); 47 | 48 | public String getHostname(); 49 | 50 | public int getExitCode(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /vicluster-core/src/test/java/org/gridkit/nanocloud/ConsoleFlushTest.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.io.StringWriter; 6 | 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | 10 | public class ConsoleFlushTest { 11 | 12 | @Rule 13 | public Retry retry = new Retry(3); 14 | 15 | @Test 16 | public void verify_output_redirect_no_flushing() { 17 | 18 | Cloud c = CloudFactory.createCloud(); 19 | c.node("**").x(VX.TYPE).setLocal(); 20 | 21 | StringWriter writer = new StringWriter(); 22 | c.node("test").x(VX.CONSOLE).bindOut(writer); 23 | 24 | c.node("test").exec(new Runnable() { 25 | 26 | @Override 27 | public void run() { 28 | System.out.println("Ping"); 29 | } 30 | }); 31 | 32 | // due to asynchronous work of stream, "Ping" is not visible yet 33 | assertThat(writer.toString()).isEmpty(); 34 | } 35 | 36 | @Test 37 | public void verify_output_redirect_with_flush() { 38 | 39 | Cloud c = CloudFactory.createCloud(); 40 | c.node("**").x(VX.TYPE).setLocal(); 41 | 42 | StringWriter writer = new StringWriter(); 43 | c.node("test").x(VX.CONSOLE).bindOut(writer); 44 | 45 | c.node("test").exec(new Runnable() { 46 | 47 | @Override 48 | public void run() { 49 | System.out.print("Ping"); 50 | } 51 | }); 52 | 53 | c.node("test").x(VX.CONSOLE).flush(); 54 | 55 | // due to asynchronous work of stream, "Ping" is not visible yet 56 | assertThat(writer.toString()).isEqualTo("Ping"); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/PropPragmaHandler.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.concurrent.Callable; 6 | 7 | import org.gridkit.util.concurrent.AdvancedExecutor; 8 | import org.gridkit.vicluster.AdvExecutor2ViExecutor; 9 | 10 | public class PropPragmaHandler implements PragmaHandler { 11 | 12 | @Override 13 | public void init(PragmaWriter conext) { 14 | // do nothing 15 | } 16 | 17 | @Override 18 | public Object query(PragmaWriter context, final String key) { 19 | AdvancedExecutor exec = context.get(Pragma.RUNTIME_EXECUTOR); 20 | return AdvExecutor2ViExecutor.exec(exec, new Callable() { 21 | @Override 22 | public String call() throws Exception { 23 | return System.getProperty(key); 24 | } 25 | }); 26 | } 27 | 28 | @Override 29 | public void apply(PragmaWriter context, Map values) { 30 | final Map props = new HashMap(); 31 | for(Map.Entry e: values.entrySet()) { 32 | props.put(e.getKey(), (String)e.getValue()); 33 | } 34 | AdvancedExecutor exec = context.get(Pragma.RUNTIME_EXECUTOR); 35 | AdvExecutor2ViExecutor.exec(exec, new Runnable() { 36 | @Override 37 | public void run() { 38 | System.getProperties().putAll(props); 39 | } 40 | }); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/VoidCallable.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster; 17 | 18 | import java.io.Serializable; 19 | import java.util.concurrent.Callable; 20 | 21 | /** 22 | * 23 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 24 | * 25 | * @deprecated Interface would be removed, as it doesn't worth its purpose, use {@link Callable}<{@link Void}> 26 | */ 27 | public interface VoidCallable { 28 | 29 | public void call() throws Exception; 30 | 31 | @SuppressWarnings("serial") 32 | public static class VoidCallableWrapper implements Callable, Serializable { 33 | 34 | public final VoidCallable callable; 35 | 36 | public VoidCallableWrapper(VoidCallable callable) { 37 | this.callable = callable; 38 | } 39 | 40 | @Override 41 | public Void call() throws Exception { 42 | callable.call(); 43 | return null; 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/zlog/PrintStreamLogStream.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi.zlog; 17 | 18 | import java.io.PrintStream; 19 | 20 | class PrintStreamLogStream extends AbstractLogStream { 21 | 22 | private final PrintStream ps; 23 | private final String pattern; 24 | boolean enabled; 25 | 26 | public PrintStreamLogStream(String pattern, PrintStream ps, boolean enabled) { 27 | this.pattern = pattern; 28 | this.ps = ps; 29 | this.enabled = enabled; 30 | } 31 | 32 | public void setEnabled(boolean enabled) { 33 | this.enabled = enabled; 34 | } 35 | 36 | @Override 37 | public boolean isEnabled() { 38 | return enabled; 39 | } 40 | 41 | protected void logInternal(String msg, Throwable e) { 42 | String line = String.format(pattern, System.currentTimeMillis(), msg); 43 | ps.println(line); 44 | if (e != null) { 45 | e.printStackTrace(ps); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /interceptor/src/main/java/org/gridkit/nanocloud/interceptor/misc/PlatformMBeanServerInterceptor.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.interceptor.misc; 2 | 3 | import java.io.Serializable; 4 | import java.lang.management.ManagementFactory; 5 | import java.util.concurrent.ExecutionException; 6 | 7 | import javax.management.MBeanServer; 8 | import javax.management.MBeanServerFactory; 9 | 10 | import org.gridkit.lab.interceptor.Interception; 11 | import org.gridkit.lab.interceptor.Interceptor; 12 | import org.gridkit.nanocloud.interceptor.Intercept; 13 | import org.gridkit.nanocloud.jmx.ReadThroughMBeanServer; 14 | import org.gridkit.vicluster.ViConfigurable; 15 | 16 | public class PlatformMBeanServerInterceptor implements Interceptor, Serializable { 17 | 18 | private static final long serialVersionUID = 20140112L; 19 | 20 | public static void apply(ViConfigurable config) { 21 | Intercept.callSite() 22 | .onTypes(ManagementFactory.class) 23 | .onMethod("getPlatformMBeanServer") 24 | .doInvoke(new PlatformMBeanServerInterceptor()) 25 | .apply(config); 26 | } 27 | 28 | private transient ReadThroughMBeanServer proxyServer; 29 | 30 | @Override 31 | public synchronized void handle(Interception call) { 32 | try { 33 | if (proxyServer == null) { 34 | MBeanServer back = (MBeanServer) call.call(); 35 | MBeanServer front = MBeanServerFactory.newMBeanServer(); 36 | proxyServer = new ReadThroughMBeanServer(back, front); 37 | } 38 | call.setResult(proxyServer); 39 | } catch (ExecutionException e) { 40 | // ignore 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/telecontrol/jvm/SplittingOutputStream.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.vicluster.telecontrol.jvm; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | 6 | class SplittingOutputStream extends OutputStream { 7 | 8 | private boolean silence = false; 9 | private OutputStream[] outs; 10 | 11 | public SplittingOutputStream(OutputStream... outs) { 12 | this.outs = outs; 13 | } 14 | 15 | public synchronized void silence() { 16 | try { 17 | flush(); 18 | close(); 19 | } 20 | catch(IOException e) { 21 | // ignore 22 | } 23 | } 24 | 25 | @Override 26 | public synchronized void write(int b) throws IOException { 27 | if (!silence) { 28 | for(OutputStream a: outs) { 29 | a.write(b); 30 | } 31 | } 32 | } 33 | 34 | @Override 35 | public synchronized void write(byte[] b) throws IOException { 36 | if (!silence) { 37 | for(OutputStream a: outs) { 38 | a.write(b); 39 | } 40 | } 41 | } 42 | 43 | @Override 44 | public synchronized void write(byte[] b, int off, int len) throws IOException { 45 | if (!silence) { 46 | for(OutputStream a: outs) { 47 | a.write(b, off, len); 48 | } 49 | } 50 | } 51 | 52 | @Override 53 | public synchronized void flush() throws IOException { 54 | if (!silence) { 55 | for(OutputStream a: outs) { 56 | a.flush(); 57 | } 58 | } 59 | } 60 | 61 | @Override 62 | public synchronized void close() throws IOException { 63 | if (!silence) { 64 | silence = true; 65 | for(OutputStream a: outs) { 66 | a.close(); 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /vicluster-core/src/test/java/org/gridkit/nanocloud/telecontrol/SocketTest.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.telecontrol; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.DataOutputStream; 5 | import java.io.IOException; 6 | import java.net.ServerSocket; 7 | import java.net.Socket; 8 | 9 | import junit.framework.Assert; 10 | 11 | import org.junit.Test; 12 | 13 | public class SocketTest { 14 | 15 | @Test 16 | public void simple_socket_transfer() throws IOException { 17 | 18 | ServerSocket ss = new ServerSocket(); 19 | ss.setReuseAddress(true); 20 | ss.bind(null); 21 | Socket s1 = new Socket(); 22 | s1.connect(ss.getLocalSocketAddress()); 23 | Socket s2 = ss.accept(); 24 | 25 | DataOutputStream dos = new DataOutputStream(s1.getOutputStream()); 26 | DataInputStream dis = new DataInputStream(s2.getInputStream()); 27 | 28 | dos.writeUTF("Hallo world!"); 29 | String result = dis.readUTF(); 30 | 31 | Assert.assertEquals("Hallo world!", result); 32 | } 33 | 34 | @Test 35 | public void server_socket_close() throws IOException { 36 | 37 | ServerSocket ss = new ServerSocket(); 38 | ss.setReuseAddress(true); 39 | ss.bind(null); 40 | Socket s1 = new Socket(); 41 | s1.connect(ss.getLocalSocketAddress()); 42 | Socket s2 = ss.accept(); 43 | 44 | ss.close(); 45 | 46 | DataOutputStream dos = new DataOutputStream(s1.getOutputStream()); 47 | DataInputStream dis = new DataInputStream(s2.getInputStream()); 48 | 49 | dos.writeUTF("Hallo world!"); 50 | String result = dis.readUTF(); 51 | 52 | Assert.assertEquals("Hallo world!", result); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/AgentConfigurator.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | import org.gridkit.vicluster.ViConf; 4 | import org.gridkit.vicluster.telecontrol.AgentEntry; 5 | 6 | import java.io.File; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import java.util.concurrent.ExecutionException; 10 | 11 | public class AgentConfigurator implements NodeAction { 12 | public static final AgentConfigurator INSTANCE = new AgentConfigurator(); 13 | 14 | @Override 15 | public void run(PragmaWriter context) throws ExecutionException { 16 | context.set(Pragma.RUNTIME_AGENTS, buildAgents(context)); 17 | } 18 | 19 | protected List buildAgents(PragmaWriter context) { 20 | final List keys = context.match(ViConf.JVM_AGENT + "**"); 21 | List agentEntries = new ArrayList(); 22 | for (String key : keys) { 23 | String agentAndOptions = context.get(key); 24 | final int delimiterIndex = agentAndOptions.indexOf("="); 25 | final File file = new File(agentAndOptions.substring(0, delimiterIndex)); 26 | if (!file.exists()) { 27 | throw new IllegalArgumentException("Can not find agent file " + file); 28 | } 29 | final String options = agentAndOptions.substring(delimiterIndex + 1); 30 | final AgentEntry agentEntry = new AgentEntry(file, options.isEmpty() ? null : options); 31 | agentEntries.add(agentEntry); 32 | } 33 | return agentEntries; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/telecontrol/bootstraper/SmartBootstraper.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.vicluster.telecontrol.bootstraper; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.DataInputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.io.ObjectInputStream; 8 | 9 | public class SmartBootstraper { 10 | 11 | public SmartBootstraper() { 12 | } 13 | 14 | public static void start(InputStream input) { 15 | // System.out.println("Bootstraper started"); 16 | Runnable spore; 17 | try { 18 | DataInputStream di = new DataInputStream(input); 19 | int blobSize = di.readInt(); 20 | // System.out.println("Spore size: " + blobSize); 21 | byte[] blob = new byte[blobSize]; 22 | di.readFully(blob); 23 | ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(blob)); 24 | spore = (Runnable) ois.readObject(); 25 | } 26 | catch(Throwable e) { 27 | System.err.println("Failed to read spore"); 28 | e.printStackTrace(); 29 | System.exit(1); 30 | return; 31 | } 32 | try { 33 | spore.run(); 34 | } 35 | catch(Throwable e) { 36 | System.err.println("Failed to execute spore"); 37 | System.err.println("Spore: " + spore); 38 | e.printStackTrace(); 39 | System.exit(1); 40 | return; 41 | } 42 | 43 | if (System.getProperty("org.gridkit.suppress-system-exit") == null) { 44 | System.exit(0); 45 | return; 46 | } 47 | } 48 | 49 | public static void main(String[] args) throws IOException { 50 | start(System.in); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /viconcurrent/src/main/java/org/gridkit/util/concurrent/zerormi/ExportableLatchBarrier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.util.concurrent.zerormi; 17 | 18 | import java.io.Serializable; 19 | 20 | import org.gridkit.util.concurrent.BlockingBarrier; 21 | import org.gridkit.util.concurrent.Latch; 22 | 23 | /** 24 | * ZeroRMI remote adapter for {@link BlockingBarrier}. 25 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 26 | */ 27 | @SuppressWarnings("serial") // ZeroRMI 28 | public class ExportableLatchBarrier extends ExportableBarrier implements BlockingBarrier, Latch, Serializable { 29 | 30 | public static ExportableLatchBarrier export(BlockingBarrier barrier) { 31 | Latch latch = (Latch) barrier; 32 | return new ExportableLatchBarrier((BlockingBarrier) latch); 33 | } 34 | 35 | public ExportableLatchBarrier(BlockingBarrier barrier) { 36 | super(barrier); 37 | } 38 | 39 | @Override 40 | public void open() { 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /interceptor/src/main/java/org/gridkit/nanocloud/interceptor/CounterStub.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.nanocloud.interceptor; 17 | 18 | import java.io.Serializable; 19 | import java.rmi.Remote; 20 | import java.util.concurrent.atomic.AtomicLong; 21 | 22 | import org.gridkit.lab.interceptor.Interception; 23 | import org.gridkit.lab.interceptor.Interceptor; 24 | 25 | class CounterStub implements Interceptor, Serializable { 26 | 27 | private static final long serialVersionUID = 20130621L; 28 | 29 | private RemoteCounter counter; 30 | 31 | public CounterStub(final AtomicLong counter) { 32 | this.counter = new RemoteCounter() { 33 | @Override 34 | public void count() { 35 | counter.incrementAndGet(); 36 | } 37 | }; 38 | } 39 | 40 | @Override 41 | public void handle(Interception call) { 42 | counter.count(); 43 | } 44 | 45 | private static interface RemoteCounter extends Remote { 46 | 47 | public void count(); 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /nanocloud/src/test/java/org/gridkit/nanocloud/test/cglib/SpringTest.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.test.cglib; 2 | 3 | import org.gridkit.nanocloud.CloudFactory; 4 | import org.gridkit.nanocloud.VX; 5 | import org.gridkit.vicluster.ViNode; 6 | import org.junit.Test; 7 | import org.springframework.beans.factory.config.BeanDefinition; 8 | import org.springframework.beans.factory.support.AbstractBeanDefinition; 9 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 10 | 11 | public class SpringTest { 12 | 13 | @Test 14 | public void create_context() { 15 | createContext(); 16 | } 17 | 18 | @Test 19 | public void create_context_in_isolation() { 20 | ViNode node = CloudFactory.createCloud().node("test"); 21 | node.x(VX.ISOLATE).setIsolateNodeType(); 22 | 23 | node.exec(new Runnable() { 24 | 25 | @Override 26 | public void run() { 27 | createContext(); 28 | } 29 | }); 30 | } 31 | 32 | @SuppressWarnings("resource") 33 | public static void createContext() { 34 | 35 | AnnotationConfigApplicationContext acac = new AnnotationConfigApplicationContext(MyConfigA.class, MyConfigB.class); 36 | 37 | acac.getBean(HelloManager.class).greet(); 38 | 39 | for(String bn: acac.getBeanDefinitionNames()) { 40 | BeanDefinition bdef = acac.getBeanDefinition(bn); 41 | if (bdef instanceof AbstractBeanDefinition) { 42 | AbstractBeanDefinition abdef = (AbstractBeanDefinition) bdef; 43 | try { 44 | abdef.resolveBeanClass(Thread.currentThread().getContextClassLoader()); 45 | } catch (ClassNotFoundException e) { 46 | throw new RuntimeException(e); 47 | } 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /vicluster-core/src/test/java/org/gridkit/vicluster/telecontrol/ProcessKillerTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster.telecontrol; 17 | 18 | import org.gridkit.nanocloud.Cloud; 19 | import org.gridkit.nanocloud.CloudFactory; 20 | import org.gridkit.vicluster.ViProps; 21 | import org.junit.Test; 22 | 23 | public class ProcessKillerTest { 24 | 25 | @Test 26 | public void verify_shutdown_after_kill() throws InterruptedException { 27 | Cloud cloud = CloudFactory.createCloud(); 28 | ViProps.at(cloud.node("**")).setLocalType(); 29 | 30 | cloud.node("node1"); 31 | cloud.node("node2"); 32 | 33 | cloud.node("**").exec(new Runnable() { 34 | @Override 35 | public void run() { 36 | System.out.println("Hi!"); 37 | } 38 | }); 39 | 40 | cloud.node("node1").submit(new Runnable() { 41 | @Override 42 | public void run() { 43 | Runtime.getRuntime().halt(0); 44 | } 45 | }); 46 | 47 | Thread.sleep(1000); 48 | 49 | cloud.shutdown(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/RemoteRef.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi; 17 | 18 | import java.io.IOException; 19 | import java.io.ObjectInputStream; 20 | import java.io.ObjectOutputStream; 21 | import java.io.Serializable; 22 | 23 | /** 24 | * 25 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 26 | */ 27 | public class RemoteRef implements Serializable { 28 | 29 | private static final long serialVersionUID = 20080415L; 30 | 31 | private RemoteInstance identity; 32 | 33 | public RemoteRef(RemoteInstance identity) { 34 | this.identity = identity; 35 | } 36 | 37 | public RemoteInstance getIdentity() { 38 | return identity; 39 | } 40 | 41 | public String toString() { 42 | return identity.toString(); 43 | } 44 | 45 | private void writeObject(ObjectOutputStream out) throws IOException { 46 | ((ObjectOutputStream)out).defaultWriteObject(); 47 | } 48 | 49 | private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { 50 | ((ObjectInputStream)in).defaultReadObject(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /telecontrol-ssh/src/test/java/org/gridkit/vicluster/telecontrol/ssh/SudoCheck.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.vicluster.telecontrol.ssh; 2 | 3 | import static org.gridkit.nanocloud.RemoteNode.REMOTE; 4 | import static org.gridkit.nanocloud.VX.JVM; 5 | 6 | import java.util.concurrent.Callable; 7 | 8 | import org.gridkit.nanocloud.Cloud; 9 | import org.gridkit.nanocloud.SimpleCloudFactory; 10 | import org.gridkit.vicluster.ViNode; 11 | import org.junit.After; 12 | import org.junit.Before; 13 | import org.junit.Test; 14 | 15 | public class SudoCheck { 16 | 17 | private Cloud cloud; 18 | 19 | @Before 20 | public void initCloud() { 21 | cloud = SimpleCloudFactory.createSimpleSshCloud(); 22 | } 23 | 24 | @After 25 | public void dropCloud() { 26 | cloud.shutdown(); 27 | } 28 | 29 | @Test 30 | public void bootstrap_sudo_check() { 31 | ViNode node = cloud.node("cbox1"); 32 | 33 | node.x(REMOTE).setRemoteBootstrapJavaExec("sudo java"); 34 | 35 | node.exec(new Callable(){ 36 | 37 | @Override 38 | public Void call() throws Exception { 39 | System.out.println("ping"); 40 | return null; 41 | } 42 | }); 43 | } 44 | 45 | @Test 46 | public void slave_sudo_check() { 47 | ViNode node = cloud.node("cbox1"); 48 | 49 | node.x(REMOTE).setRemoteBootstrapJavaExec("java"); 50 | node.x(JVM).setJavaExec("sudo", "java"); 51 | 52 | node.exec(new Callable(){ 53 | 54 | @Override 55 | public Void call() throws Exception { 56 | System.out.println("ping"); 57 | return null; 58 | } 59 | }); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/UndeclaredRemoteException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi; 17 | 18 | /** 19 | * This class is used to wrap remote exception if it is not declared 20 | * in proxy interface. 21 | *
22 | * This type is added to provide convenient way to handle remote exceptions. 23 | * 24 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 25 | */ 26 | public class UndeclaredRemoteException extends RuntimeException { 27 | 28 | private static final long serialVersionUID = 20140724L; 29 | 30 | public UndeclaredRemoteException(String message, Throwable cause) { 31 | super(message, cause); 32 | } 33 | 34 | public UndeclaredRemoteException(Throwable cause) { 35 | super(cause); 36 | } 37 | 38 | public void rethrow() { 39 | UndeclaredRemoteException. throwAny(getCause()); 40 | } 41 | 42 | @SuppressWarnings("unchecked") 43 | private static void throwAny(Throwable e) throws E { 44 | throw (E)e; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/telecontrol/isolate/IsolateConfig.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.telecontrol.isolate; 2 | 3 | import org.gridkit.vicluster.ViConf; 4 | import org.gridkit.vicluster.ViConfigurable; 5 | import org.gridkit.vicluster.ViConfigurable.Delegate; 6 | import org.gridkit.vicluster.isolate.IsolateProps; 7 | 8 | public class IsolateConfig extends Delegate { 9 | 10 | private ViConfigurable conf; 11 | 12 | public static IsolateConfig at(ViConfigurable conf) { 13 | return new IsolateConfig(conf); 14 | } 15 | 16 | public IsolateConfig(ViConfigurable conf) { 17 | this.conf = conf; 18 | } 19 | 20 | @Override 21 | protected ViConfigurable getConfigurable() { 22 | return conf; 23 | } 24 | 25 | public IsolateConfig setIsolateNodeType() { 26 | conf.setProp(ViConf.NODE_TYPE, ViConf.NODE_TYPE__ISOLATE); 27 | return this; 28 | } 29 | 30 | public IsolateConfig shareClass(Class c) { 31 | shareClass(c.getName()); 32 | return this; 33 | } 34 | 35 | public IsolateConfig shareClass(String name) { 36 | conf.setProp(IsolateProps.SHARE_CLASS + name, name); 37 | return this; 38 | } 39 | 40 | public IsolateConfig sharePackage(String name) { 41 | conf.setProp(IsolateProps.SHARE_PACKAGE + name, name); 42 | return this; 43 | } 44 | 45 | public IsolateConfig isolateClass(Class c) { 46 | isolateClass(c.getName()); 47 | return this; 48 | } 49 | 50 | public IsolateConfig isolateClass(String name) { 51 | conf.setProp(IsolateProps.ISOLATE_CLASS + name, name); 52 | return this; 53 | } 54 | 55 | public IsolateConfig isolatePackage(String name) { 56 | conf.setProp(IsolateProps.ISOLATE_PACKAGE + name, name); 57 | return this; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /viconcurrent/src/main/java/org/gridkit/util/concurrent/Barriers.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.util.concurrent; 17 | 18 | /** 19 | * 20 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 21 | */ 22 | public class Barriers { 23 | 24 | public static NoBarrier openBarrier() { 25 | return NoBarrier.INSTANCE; 26 | } 27 | 28 | public static BlockingBarrier cyclicBarrier(int parties) { 29 | return new CyclicBlockingBarrier(parties, null); 30 | } 31 | 32 | public static BlockingBarrier speedLimit(double eventsPerSecond) { 33 | if (eventsPerSecond < 0) { 34 | throw new IllegalArgumentException("speedLimit should be >= 0"); 35 | } 36 | else if (eventsPerSecond == Double.POSITIVE_INFINITY) { 37 | return openBarrier(); 38 | } 39 | else { 40 | int replenishLimit = (int)(eventsPerSecond * 0.02); // compensation for scheduling granularity 41 | if (replenishLimit < 1) { 42 | replenishLimit = 1; 43 | } 44 | return new SimpleSpeedLimit(eventsPerSecond, replenishLimit); 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /viconcurrent/src/main/java/org/gridkit/util/concurrent/TaskService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.util.concurrent; 17 | 18 | import java.util.concurrent.TimeUnit; 19 | 20 | public interface TaskService { 21 | 22 | public void schedule(Task task); 23 | 24 | public void schedule(Task task, long delay, TimeUnit tu); 25 | 26 | /** 27 | * If {@link TaskService#schedule(Task)} method havn't thrown an 28 | * exception, it is guaranteed that eigther {@link #run()} or {@link #canceled()} 29 | * would be called eventually. 30 | * 31 | * {@link #interrupt(Thread)} may be used to abort task execution, beware that it could be called when {@link #run()} is already finished or have yet to be started. 32 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 33 | */ 34 | public interface Task { 35 | 36 | public void run(); 37 | 38 | public void interrupt(Thread taskThread); 39 | 40 | public void canceled(); 41 | 42 | } 43 | 44 | public interface Component extends TaskService { 45 | 46 | public void shutdown(); 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /vicluster-core/src/test/java/org/gridkit/vicluster/WildPropsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster; 17 | 18 | import junit.framework.Assert; 19 | 20 | import org.junit.Test; 21 | 22 | public class WildPropsTest { 23 | 24 | @Test 25 | public void test_non_pattern() { 26 | 27 | WildProps props = new WildProps(); 28 | 29 | props.put("A", "a"); 30 | props.put("B", "b"); 31 | 32 | Assert.assertEquals("a", props.get("A")); 33 | Assert.assertEquals("b", props.get("B")); 34 | 35 | props.put("A", "AAA"); 36 | 37 | Assert.assertEquals("AAA", props.get("A")); 38 | } 39 | 40 | @Test 41 | public void test_pattern() { 42 | 43 | WildProps props = new WildProps(); 44 | 45 | props.put("A", "a"); 46 | props.put("B", "b"); 47 | props.put("*", "xxx"); 48 | 49 | Assert.assertEquals("a", props.get("A")); 50 | Assert.assertEquals("b", props.get("B")); 51 | Assert.assertEquals("xxx", props.get("C")); 52 | 53 | props.put("C", "ccc"); 54 | 55 | Assert.assertEquals("ccc", props.get("C")); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/RmiChannel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi; 17 | 18 | import java.io.IOException; 19 | import java.lang.reflect.Method; 20 | 21 | import org.gridkit.util.concurrent.FutureEx; 22 | 23 | /** 24 | * 25 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 26 | */ 27 | interface RmiChannel { 28 | 29 | public Object remoteInvocation(RemoteStub remoteStub, Object proxy, Method method, Object[] args) throws Throwable; 30 | 31 | public FutureEx asyncRemoteInvocation(RemoteStub remoteStub, Object proxy, Method method, Object[] args); 32 | 33 | public void close(Throwable cause); 34 | 35 | public void handleMessage(RemoteMessage message); 36 | 37 | public void exportObject(Class facade, C impl); 38 | 39 | public Object streamResolveObject(Object obj) throws IOException; 40 | 41 | public Object streamReplaceObject(Object obj) throws IOException; 42 | 43 | @SuppressWarnings("rawtypes") 44 | public Class classForName(String string) throws ClassNotFoundException; 45 | 46 | public ClassLoader getClassLoader(); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/zlog/ZLogFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi.zlog; 17 | 18 | public class ZLogFactory { 19 | 20 | public static final String PROP_ZLOG_MODE = "org.gridkit.zlog.mode"; 21 | 22 | public static ZLogger getStdErrRootLogger() { 23 | return new PrintStreamLogger("", System.err); 24 | } 25 | 26 | public static ZLogger getDefaultRootLogger() { 27 | if ("slf4j".equals(System.getProperty(PROP_ZLOG_MODE))) { 28 | return getSlf4JRootLogger(); 29 | } 30 | else { 31 | return getStdErrRootLogger(); 32 | } 33 | } 34 | 35 | public static ZLogger getSlf4JRootLogger() { 36 | try { 37 | return (ZLogger) Class.forName("org.gridkit.zerormi.zlog.ZLogToSlf4J").newInstance(); 38 | } 39 | catch(ClassNotFoundException e) { 40 | return getStdErrRootLogger(); 41 | } 42 | catch(NoClassDefFoundError e) { 43 | return getStdErrRootLogger(); 44 | } 45 | catch (InstantiationException e) { 46 | return getStdErrRootLogger(); 47 | } 48 | catch (IllegalAccessException e) { 49 | return getStdErrRootLogger(); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /viconcurrent/src/main/java/org/gridkit/util/concurrent/NoBarrier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.util.concurrent; 17 | 18 | import java.util.concurrent.BrokenBarrierException; 19 | import java.util.concurrent.Future; 20 | 21 | /** 22 | * 23 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 24 | */ 25 | public class NoBarrier implements BlockingBarrier { 26 | 27 | public static final NoBarrier INSTANCE = new NoBarrier(); 28 | 29 | 30 | @Override 31 | public void pass() throws InterruptedException, BrokenBarrierException { 32 | // do nothing 33 | 34 | } 35 | 36 | @Override 37 | public void pass(boolean breakOnInterrupt) throws InterruptedException { 38 | // do nothing 39 | } 40 | 41 | @Override 42 | public void breakthrough() { 43 | // do nothing 44 | } 45 | 46 | @Override 47 | public void stepIn() { 48 | // do nothing 49 | } 50 | 51 | @Override 52 | public Future stepIn(boolean needFuture) { 53 | Future result = null; 54 | if (needFuture) { 55 | FutureLatch latch = new FutureLatch(); 56 | latch.open(); 57 | result = latch; 58 | } 59 | return result; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /nanotest/src/main/java/org/gridkit/nanocloud/test/maven/MavenClasspathConfig.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.test.maven; 2 | 3 | import org.gridkit.vicluster.ViConfigurable; 4 | import org.gridkit.vicluster.ViConfExtender; 5 | 6 | public class MavenClasspathConfig extends ViConfigurable.Delegate { 7 | 8 | public static final ViConfExtender MAVEN = new ViConfExtender() { 9 | public MavenClasspathConfig wrap(ViConfigurable node) { 10 | return new MavenClasspathConfig(node); 11 | } 12 | }; 13 | 14 | private ViConfigurable delegate; 15 | 16 | public MavenClasspathConfig(ViConfigurable delegate) { 17 | this.delegate = delegate; 18 | } 19 | 20 | @Override 21 | protected ViConfigurable getConfigurable() { 22 | return delegate; 23 | } 24 | 25 | public MavenClasspathConfig add(String groupId, String artifactId, String version) { 26 | MavenClasspathManager.addArtifactVersion(getConfigurable(), groupId, artifactId, version); 27 | return this; 28 | } 29 | 30 | public MavenClasspathConfig replace(String groupId, String artifactId, String version) { 31 | MavenClasspathManager.addArtifactVersion(getConfigurable(), groupId, artifactId, version); 32 | try { 33 | MavenClasspathManager.removeArtifactVersion(getConfigurable(), groupId, artifactId); 34 | } 35 | catch(IllegalArgumentException x) { 36 | // ignore 37 | } 38 | return this; 39 | } 40 | 41 | public MavenClasspathConfig remove(String groupId, String artifactId, String version) { 42 | MavenClasspathManager.removeArtifactVersion(getConfigurable(), groupId, artifactId, version); 43 | return this; 44 | } 45 | 46 | public MavenClasspathConfig remove(String groupId, String artifactId) { 47 | MavenClasspathManager.removeArtifactVersion(getConfigurable(), groupId, artifactId); 48 | return this; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/telecontrol/ZeroRmiRemoteSession.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.telecontrol; 2 | 3 | import java.io.IOException; 4 | 5 | import org.gridkit.util.concurrent.AdvancedExecutor; 6 | import org.gridkit.zerormi.DuplexStream; 7 | import org.gridkit.zerormi.DuplexStreamConnector; 8 | import org.gridkit.zerormi.RmiGateway; 9 | import org.gridkit.zerormi.hub.RemotingEndPoint; 10 | import org.gridkit.zerormi.hub.SlaveSpore; 11 | 12 | public class ZeroRmiRemoteSession implements RemoteExecutionSession { 13 | 14 | private RmiGateway gateway; 15 | 16 | public ZeroRmiRemoteSession(String nodeName) { 17 | // TODO logging configuration 18 | gateway = new RmiGateway(nodeName); 19 | } 20 | 21 | @Override 22 | public SlaveSpore getMobileSpore() { 23 | Spore spore = new Spore(); 24 | return spore; 25 | } 26 | 27 | @Override 28 | public AdvancedExecutor getRemoteExecutor() { 29 | return gateway.getRemoteExecutorService(); 30 | } 31 | 32 | @Override 33 | public void setTransportConnection(DuplexStream stream) { 34 | try { 35 | gateway.connect(stream); 36 | } catch (IOException e) { 37 | throw new RuntimeException(e); 38 | } 39 | } 40 | 41 | @Override 42 | public void terminate(Throwable cause) { 43 | gateway.shutdown(cause); 44 | } 45 | 46 | public static class Spore implements SlaveSpore { 47 | 48 | private static final long serialVersionUID = 20130806L; 49 | 50 | @Override 51 | public void start(DuplexStreamConnector masterConnector) { 52 | RemotingEndPoint endpoint = new RemotingEndPoint(null, masterConnector); 53 | endpoint.enableHeartbeatDeatchWatch(); 54 | endpoint.run(); 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return "RemotingEndPoint"; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/DefaultNodeConfig.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | 4 | public class DefaultNodeConfig { 5 | 6 | private static final PragmaMap DEFAULT_CONFIG = new PragmaMap(); 7 | 8 | private static final NodeLogStreamSupport LOG_STREAM_FACTORY = new NodeLogStreamSupport(); 9 | private static final PropPragmaHandler PROP_PRAGMA_HANDLER = new PropPragmaHandler(); 10 | 11 | 12 | static { 13 | init(); 14 | } 15 | 16 | public static PragmaReader getDefaultConfig() { 17 | return DEFAULT_CONFIG; 18 | } 19 | 20 | private static void init() { 21 | 22 | // Special factories 23 | DEFAULT_CONFIG.setLazy(Pragma.DEFAULT + Pragma.INSTANTIATE + "**", LazyClassInstantiator.INSTANCE); 24 | DEFAULT_CONFIG.setLazy(Pragma.DEFAULT + Pragma.LOGGER_STREAM + "**", LOG_STREAM_FACTORY); 25 | 26 | NodeConfigHelper.passivePragma(DEFAULT_CONFIG, "node"); 27 | NodeConfigHelper.passivePragma(DEFAULT_CONFIG, "boot"); 28 | NodeConfigHelper.passivePragma(DEFAULT_CONFIG, "node-runtime"); 29 | NodeConfigHelper.passivePragma(DEFAULT_CONFIG, "default"); 30 | NodeConfigHelper.passivePragma(DEFAULT_CONFIG, "lazy"); 31 | NodeConfigHelper.passivePragma(DEFAULT_CONFIG, "new-instance"); 32 | NodeConfigHelper.passivePragma(DEFAULT_CONFIG, "classpath"); 33 | 34 | NodeConfigHelper.pragmaHandler(DEFAULT_CONFIG, "logger", LOG_STREAM_FACTORY); 35 | NodeConfigHelper.pragmaHandler(DEFAULT_CONFIG, "prop", PROP_PRAGMA_HANDLER); 36 | 37 | 38 | // backward compatibility hacks 39 | DEFAULT_CONFIG.link(Pragma.VINODE_NAME, Pragma.NODE_NAME); 40 | DEFAULT_CONFIG.link(Pragma.VINODE_TYPE, Pragma.NODE_TYPE); 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/hub/MasterHub.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi.hub; 17 | 18 | import org.gridkit.util.concurrent.AdvancedExecutor; 19 | import org.gridkit.zerormi.DuplexStream; 20 | import org.gridkit.zerormi.hub.RemotingHub.SessionEventListener; 21 | 22 | /** 23 | *

24 | * Master hub encapsulates logic of establishing ZeroRMI 25 | * control connection with remote entity. 26 | *

27 | * 28 | *

29 | * Details of transport are hidden away, established socket 30 | * connection is provided to both {@link MasterHub} and its 31 | * {@link SlaveSpore}. 32 | *

33 | * 34 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 35 | */ 36 | public interface MasterHub { 37 | 38 | public SlaveSpore allocateSession(String sessionId, SessionEventListener listener); 39 | 40 | public AdvancedExecutor getExecutionService(String sessionId); 41 | 42 | public AdvancedExecutor getSlaveExecutor(SlaveSpore spore); 43 | 44 | public void dispatch(DuplexStream stream); 45 | 46 | public void dropSession(String sessionId); 47 | 48 | public void terminateSpore(SlaveSpore spore); 49 | 50 | public void dropAllSessions(); 51 | } 52 | -------------------------------------------------------------------------------- /telecontrol-ssh/src/main/java/org/gridkit/nanocloud/telecontrol/ssh/SshSpiConf.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.telecontrol.ssh; 2 | 3 | public interface SshSpiConf { 4 | 5 | // public static final String REMOTE_BOOTSTRAP_JAR_CACHE = "remote-runtime:bootstrap-jar-cache"; 6 | public static final String REMOTE_JAR_CACHE = "remote-runtime:jar-cache"; 7 | 8 | public static final String REMOTE_BOOTSTRAP_JVM_EXEC = "remote-runtime:bootstrap-jvm-exec"; 9 | public static final String REMOTE_FALLBACK_JVM_EXEC = "remote-runtime:fallback-jvm-exec"; 10 | 11 | // TODO sane default managment 12 | public static final String SPI_BOOTSTRAP_JVM_EXEC = "#spi:remote-runtime:bootstrap-jvm-exec"; 13 | public static final String SPI_JAR_CACHE = "#spi:remote-runtime:jar-cache"; 14 | 15 | public static final String SPI_SSH_TARGET_HOST = "#spi:ssh:target-host"; 16 | public static final String SPI_SSH_TARGET_ACCOUNT = "#spi:ssh:target-account"; 17 | 18 | public static final String SPI_SSH_PASSWORD = "#spi:ssh:password"; 19 | public static final String SPI_SSH_PRIVATE_KEY_FILE = "#spi:ssh:private-key-file"; 20 | public static final String SPI_SSH_JSCH_OPTION = "#spi:ssh:jsch:"; 21 | 22 | public static final String SPI_SSH_CONTROL_CONSOLE = "#spi:ssh:control-console"; 23 | 24 | public static final String SSH_PASSWORD = "ssh:password"; 25 | public static final String SSH_PRIVATE_KEY_FILE = "ssh:private-key-file"; 26 | public static final String SSH_JSCH_OPTION = "ssh:jsch:"; 27 | 28 | public static final String KEY_PASSWORD = "password"; 29 | public static final String KEY_PRIVATE_KEY_FILE = "private-key"; 30 | public static final String KEY_ADDRESS = "address"; 31 | public static final String KEY_JSCH_PREFERED_AUTH = "jsch-auth"; 32 | public static final String KEY_JAR_CACHE = "jar-cache-path"; 33 | public static final String KEY_JAVA_EXEC = "java-exec"; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/ViExecutor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster; 17 | 18 | import java.util.List; 19 | import java.util.concurrent.Callable; 20 | import java.util.concurrent.Future; 21 | 22 | /** 23 | * 24 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 25 | */ 26 | public interface ViExecutor { 27 | 28 | public void exec(Runnable task); 29 | 30 | @SuppressWarnings("deprecation") 31 | public void exec(VoidCallable task); 32 | 33 | public T exec(Callable task); 34 | 35 | public Future submit(Runnable task); 36 | 37 | @SuppressWarnings("deprecation") 38 | public Future submit(VoidCallable task); 39 | 40 | public Future submit(Callable task); 41 | 42 | // Mass operations 43 | 44 | /** 45 | * Version of exec for group 46 | * 47 | * @return 48 | */ 49 | public List massExec(Callable task); 50 | 51 | public List> massSubmit(Runnable task); 52 | 53 | @SuppressWarnings("deprecation") 54 | public List> massSubmit(VoidCallable task); 55 | 56 | public List> massSubmit(Callable task); 57 | } 58 | -------------------------------------------------------------------------------- /vicluster-core/src/test/java/org/gridkit/nanocloud/telecontrol/TunnelerControlConsoleTest.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.telecontrol; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.concurrent.TimeUnit; 6 | import java.util.concurrent.TimeoutException; 7 | 8 | import org.gridkit.vicluster.telecontrol.StreamPipe; 9 | import org.gridkit.vicluster.telecontrol.bootstraper.Tunneller; 10 | import org.gridkit.vicluster.telecontrol.bootstraper.TunnellerConnection; 11 | import org.junit.After; 12 | import org.junit.Before; 13 | 14 | public class TunnelerControlConsoleTest extends LocalControlConsoleTest { 15 | 16 | private Thread tunnellerThread; 17 | 18 | 19 | @Before 20 | public void initConsole() throws IOException, InterruptedException, TimeoutException { 21 | final StreamPipe ib = new StreamPipe(4 << 1000); 22 | final StreamPipe ob = new StreamPipe(4 << 1000); 23 | final Tunneller tunneller = new Tunneller(); 24 | tunnellerThread = new Thread("TUNNELLER") { 25 | @Override 26 | public void run() { 27 | tunneller.process(ib.getInputStream(), ob.getOutputStream()); 28 | } 29 | }; 30 | tunnellerThread.start(); 31 | TunnellerConnection conn = new TunnellerConnection("Test", ob.getInputStream(), ib.getOutputStream(), System.out, 10, TimeUnit.SECONDS); 32 | 33 | rmrf(new File("target/.tunneler")); 34 | console = new TunnellerControlConsole(conn, "target/.tunneler"); 35 | } 36 | 37 | private static void rmrf(File file) { 38 | if (file.isFile()) { 39 | file.delete(); 40 | } 41 | else if (file.isDirectory()) { 42 | File[] c = file.listFiles(); 43 | if (c != null) { 44 | for(File f: c) { 45 | rmrf(f); 46 | } 47 | } 48 | file.delete(); 49 | } 50 | } 51 | 52 | @After 53 | public void destroyConsole() { 54 | tunnellerThread.interrupt(); 55 | console.terminate(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /interceptor/src/main/java/org/gridkit/nanocloud/interceptor/ParamBasedCallFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.nanocloud.interceptor; 17 | 18 | import java.io.Serializable; 19 | import java.util.Arrays; 20 | 21 | import org.gridkit.lab.interceptor.Interception; 22 | import org.gridkit.nanocloud.interceptor.Intercept.ParamMatcher; 23 | 24 | class ParamBasedCallFilter implements CallFilter, Serializable { 25 | 26 | private static final long serialVersionUID = 20130621L; 27 | 28 | private ParamMatcher[] matchers; 29 | 30 | public boolean matches(Interception interception) { 31 | if (matchers != null) { 32 | Object[] params = interception.getCallParameters(); 33 | if (matchers.length > params.length) { 34 | return false; 35 | } 36 | for(int i = 0; i != matchers.length; ++i) { 37 | if (matchers[i] != null) { 38 | if (!matchers[i].matches(params[i])) { 39 | return false; 40 | } 41 | } 42 | } 43 | } 44 | return true; 45 | } 46 | 47 | public void addParamMatcher(int n, ParamMatcher matcher) { 48 | if (matchers == null) { 49 | matchers = new ParamMatcher[n + 1]; 50 | } 51 | else if (matchers.length <= n) { 52 | matchers = Arrays.copyOf(matchers, n + 1); 53 | } 54 | matchers[n] = matcher; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/SocketStream.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi; 17 | 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | import java.io.OutputStream; 21 | import java.net.Socket; 22 | 23 | /** 24 | * 25 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 26 | */ 27 | public class SocketStream implements DuplexStream { 28 | 29 | private Socket socket; 30 | 31 | public SocketStream(Socket socket) { 32 | this.socket = socket; 33 | } 34 | 35 | @Override 36 | public InputStream getInput() throws IOException { 37 | return socket.getInputStream(); 38 | } 39 | 40 | @Override 41 | public OutputStream getOutput() throws IOException { 42 | return socket.getOutputStream(); 43 | } 44 | 45 | @Override 46 | public boolean isClosed() { 47 | return socket.isClosed(); 48 | } 49 | 50 | @Override 51 | public void close() throws IOException { 52 | try { 53 | socket.shutdownInput(); 54 | } 55 | catch(IOException e) { 56 | // ignore 57 | } 58 | try { 59 | socket.shutdownOutput(); 60 | } 61 | catch(IOException e) { 62 | // ignore 63 | } 64 | socket.close(); 65 | } 66 | 67 | @Override 68 | public String toString() { 69 | return socket.toString(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/ViSpiConfig.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.vicluster; 2 | 3 | import java.util.List; 4 | 5 | import org.gridkit.nanocloud.telecontrol.HostControlConsole; 6 | import org.gridkit.nanocloud.telecontrol.NodeFactory; 7 | import org.gridkit.nanocloud.telecontrol.ProcessLauncher; 8 | import org.gridkit.nanocloud.telecontrol.RemoteExecutionSession; 9 | import org.gridkit.nanocloud.telecontrol.RemoteExecutionSessionWrapper; 10 | import org.gridkit.vicluster.telecontrol.AgentEntry; 11 | import org.gridkit.vicluster.telecontrol.Classpath.ClasspathEntry; 12 | import org.gridkit.vicluster.telecontrol.ManagedProcess; 13 | import org.gridkit.vicluster.telecontrol.StreamCopyService; 14 | 15 | public interface ViSpiConfig { 16 | 17 | public String getNodeName(); 18 | 19 | public String getNodeType(); 20 | 21 | public java.util.Map getConfigMap(); 22 | 23 | public ViNode getNodeInstance(); 24 | 25 | public NodeFactory getNodeFactory(); 26 | 27 | public ManagedProcess getManagedProcess(); 28 | 29 | public List getSlaveArgs(); 30 | 31 | public java.util.Map getSlaveEnv(); 32 | 33 | public String getSlaveWorkDir(); 34 | 35 | public List getSlaveShallowClasspath(); 36 | 37 | public List getSlaveClasspath(); 38 | 39 | public List getSlaveAgents(); 40 | 41 | public String getJvmExecCmd(); 42 | 43 | public RemoteExecutionSession getRemotingSession(); 44 | 45 | public RemoteExecutionSessionWrapper getInstrumentationWrapper(); 46 | 47 | public boolean isInstrumentationWrapperApplied(); 48 | 49 | public ProcessLauncher getProcessLauncher(); 50 | 51 | public HostControlConsole getControlConsole(); 52 | 53 | public CloudContext getCloudContext(); 54 | 55 | public StreamCopyService getStreamCopyService(); 56 | 57 | public T get(String key); 58 | 59 | boolean isConfigTraceEnbaled(); 60 | 61 | boolean shouldDumpConfigOnFailure(); 62 | } 63 | -------------------------------------------------------------------------------- /viconcurrent/src/main/java/org/gridkit/util/concurrent/BlockingBarrier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.util.concurrent; 17 | 18 | import java.util.concurrent.BrokenBarrierException; 19 | import java.util.concurrent.Future; 20 | 21 | /** 22 | * 23 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 24 | */ 25 | public interface BlockingBarrier { 26 | 27 | 28 | /** 29 | * Block until it could pass barrier. 30 | * {@link InterruptedException} will during wait will make barrier broken. 31 | */ 32 | public void pass() throws InterruptedException, BrokenBarrierException; 33 | 34 | /** 35 | * Block until it could pass barrier. 36 | * @param breakOnInterrupt - whenever {@link InterruptedException} should switch barrier in broken state. 37 | */ 38 | public void pass(boolean breakOnInterrupt) throws InterruptedException, BrokenBarrierException; 39 | 40 | /** 41 | * Pass barrier without blocking. If barrier is not open, it will be broken. 42 | */ 43 | public void breakthrough(); 44 | 45 | /** 46 | * Enter barrier by do not wait for passing though. 47 | */ 48 | public void stepIn(); 49 | 50 | /** 51 | * Enter barrier but receive passing {@link Future} instead of blocking. 52 | */ 53 | public Future stepIn(boolean needFuture); 54 | 55 | } 56 | -------------------------------------------------------------------------------- /telecontrol-ssh/src/test/java/org/gridkit/nanocloud/telecontrol/ssh/ViEngineSshCheck.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.telecontrol.ssh; 2 | 3 | import java.util.concurrent.Callable; 4 | 5 | import junit.framework.Assert; 6 | 7 | import org.gridkit.vicluster.AbstractCloudContext; 8 | import org.gridkit.vicluster.ViConf; 9 | import org.gridkit.vicluster.ViManager; 10 | import org.gridkit.vicluster.ViNode; 11 | import org.gridkit.vicluster.ViProps; 12 | import org.gridkit.vicluster.telecontrol.jvm.ViEngineNodeProvider; 13 | import org.gridkit.vicluster.telecontrol.ssh.RemoteNodeProps; 14 | import org.junit.After; 15 | import org.junit.Test; 16 | 17 | public class ViEngineSshCheck { 18 | 19 | private CloudContext ctx = new CloudContext(); 20 | 21 | @After 22 | public void dropCloud() { 23 | ctx.runFinalizers(); 24 | } 25 | 26 | @Test 27 | public void vi_engine_node_test() throws InterruptedException { 28 | ViManager cloud = new ViManager(new ViEngineNodeProvider()); 29 | 30 | cloud.node("**").setConfigElement(ViConf.TYPE_HANDLER + "remote", new RemoteNodeTypeHandler()); 31 | 32 | ViNode node = cloud.node("test"); 33 | ViProps.at(node).setRemoteType(); 34 | RemoteNodeProps.at(node).setRemoteHost("cbox1"); 35 | node.setProp(ViConf.REMOTE_HOST_CONFIG,"?~/ssh-credentials.prop"); 36 | node.setProp(SshSpiConf.SPI_BOOTSTRAP_JVM_EXEC, "java"); 37 | node.setProp(SshSpiConf.SPI_JAR_CACHE, "/tmp/nanocloud"); 38 | node.touch(); 39 | String r = node.exec(new Callable() { 40 | @Override 41 | public String call() { 42 | System.out.println("Hallo world!"); 43 | return"ping"; 44 | } 45 | }); 46 | 47 | Assert.assertEquals("ping", r); 48 | 49 | cloud.shutdown(); 50 | } 51 | 52 | public static class CloudContext extends AbstractCloudContext { 53 | 54 | @Override 55 | protected synchronized void runFinalizers() { 56 | super.runFinalizers(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/NamedStreamPair.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi; 17 | 18 | import java.io.InputStream; 19 | import java.io.OutputStream; 20 | 21 | /** 22 | * 23 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 24 | */ 25 | public class NamedStreamPair implements DuplexStream { 26 | 27 | private String name; 28 | private InputStream in; 29 | private OutputStream out; 30 | private boolean closed; 31 | 32 | public NamedStreamPair(String name, InputStream in, OutputStream out) { 33 | this.name = name; 34 | this.in = in; 35 | this.out = out; 36 | } 37 | 38 | @Override 39 | public InputStream getInput() { 40 | return in; 41 | } 42 | 43 | @Override 44 | public OutputStream getOutput() { 45 | return out; 46 | } 47 | 48 | @Override 49 | public boolean isClosed() { 50 | return closed; 51 | } 52 | 53 | @Override 54 | public synchronized void close() { 55 | if (!closed) { 56 | try { 57 | in.close(); 58 | } 59 | catch(Exception e) { 60 | // ignore; 61 | } 62 | try { 63 | out.close(); 64 | } 65 | catch(Exception e) { 66 | // ignore; 67 | } 68 | closed = true; 69 | } 70 | } 71 | 72 | @Override 73 | public String toString() { 74 | return name; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /interceptor/src/main/java/org/gridkit/nanocloud/interceptor/PrinterStub.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.nanocloud.interceptor; 17 | 18 | import java.io.PrintStream; 19 | import java.io.Serializable; 20 | 21 | import org.gridkit.lab.interceptor.Interception; 22 | import org.gridkit.lab.interceptor.Interceptor; 23 | 24 | class PrinterStub implements Interceptor, Serializable { 25 | 26 | private static final long serialVersionUID = 20140112L; 27 | 28 | private boolean errStream; 29 | private boolean printStackTrace; 30 | private String format; 31 | 32 | 33 | public PrinterStub(String format) { 34 | this.format = format; 35 | } 36 | 37 | public void setPrintToErr(boolean err) { 38 | errStream = err; 39 | } 40 | 41 | public void setPrintStackTrace(boolean trace) { 42 | printStackTrace = trace; 43 | } 44 | 45 | @Override 46 | public void handle(Interception call) { 47 | String text; 48 | try { 49 | text = String.format(format, call.getCallParameters()); 50 | } 51 | catch(Throwable e) { 52 | text = "Print interceptor has failed. Template: [" + format + "] Error: " + e.toString(); 53 | } 54 | PrintStream ps = errStream ? System.err : System.out; 55 | ps.println(text); 56 | if (printStackTrace) { 57 | new Exception().printStackTrace(ps); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/viengine/PragmaProcessor.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.viengine; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | import java.util.concurrent.ExecutionException; 6 | 7 | public class PragmaProcessor implements NodeAction { 8 | 9 | public static PragmaProcessor INSTANCE = new PragmaProcessor(); 10 | 11 | @Override 12 | public void run(PragmaWriter context) throws ExecutionException { 13 | Map handlers = new LinkedHashMap(); 14 | for(String key: context.match("**")) { 15 | if (key.startsWith("#")) { 16 | continue; 17 | } 18 | String pragType = pragmaTypeOf(key); 19 | if (!handlers.containsKey(pragType)) { 20 | PragmaHandler ph = context.get(Pragma.NODE_PRAGMA_HANDLER + pragType); 21 | if (ph == null) { 22 | throw new IllegalArgumentException("No handler for pragma '" + key + "'"); 23 | } 24 | else { 25 | handlers.put(pragType, ph); 26 | } 27 | } 28 | } 29 | for(PragmaHandler h: handlers.values()) { 30 | h.init(context); 31 | } 32 | Map confSnap = new LinkedHashMap(); 33 | for(String key: context.match("**")) { 34 | if (key.startsWith("#")) { 35 | continue; 36 | } 37 | confSnap.put(key, context.get(key)); 38 | } 39 | PragmaHelper.setPragmas(context, confSnap); 40 | } 41 | 42 | private static String pragmaTypeOf(String key) { 43 | int c = key.indexOf(':'); 44 | if (c < 0) { 45 | throw new IllegalArgumentException("Invalid key format '" + key + "' - no pragma"); 46 | } 47 | return key.substring(0, c); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /viconcurrent/src/main/java/org/gridkit/util/concurrent/LatchBarrier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.util.concurrent; 17 | 18 | import java.util.concurrent.BrokenBarrierException; 19 | import java.util.concurrent.CountDownLatch; 20 | import java.util.concurrent.Future; 21 | 22 | /** 23 | * Simple latch barrier. Latch is created in closed state and could be opened just ones. 24 | * 25 | * This kind of barrier does not handles broken state. 26 | * 27 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 28 | */ 29 | public class LatchBarrier implements BlockingBarrier, Latch { 30 | 31 | private CountDownLatch latch = new CountDownLatch(1); 32 | 33 | @Override 34 | public void open() { 35 | latch.countDown(); 36 | } 37 | 38 | @Override 39 | public void pass() throws InterruptedException, BrokenBarrierException { 40 | pass(true); 41 | } 42 | 43 | @Override 44 | public void pass(boolean breakOnInterrupt) throws InterruptedException, BrokenBarrierException { 45 | latch.await(); 46 | } 47 | 48 | @Override 49 | public void breakthrough() { 50 | // do nothing 51 | } 52 | 53 | @Override 54 | public void stepIn() { 55 | stepIn(false); 56 | } 57 | 58 | @Override 59 | public Future stepIn(boolean needFuture) { 60 | return needFuture ? new FutureLatch(latch) : null; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /viconcurrent/src/main/java/org/gridkit/util/concurrent/AdvancedExecutorAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.util.concurrent; 17 | 18 | import java.util.concurrent.Callable; 19 | import java.util.concurrent.Executor; 20 | 21 | public class AdvancedExecutorAdapter implements AdvancedExecutor { 22 | 23 | private final Executor executor; 24 | 25 | public AdvancedExecutorAdapter(Executor executor) { 26 | this.executor = executor; 27 | } 28 | 29 | @Override 30 | public void execute(Runnable task) { 31 | executor.execute(task); 32 | } 33 | 34 | @Override 35 | public FutureEx submit(final Runnable task) { 36 | final FutureBox fb = new FutureBox(); 37 | execute(new Runnable() { 38 | @Override 39 | public void run() { 40 | try { 41 | task.run(); 42 | fb.setData(null); 43 | } 44 | catch(Throwable e) { 45 | fb.setError(e); 46 | } 47 | } 48 | }); 49 | return fb; 50 | } 51 | 52 | @Override 53 | public FutureEx submit(final Callable task) { 54 | final FutureBox fb = new FutureBox(); 55 | execute(new Runnable() { 56 | @Override 57 | public void run() { 58 | try { 59 | fb.setData(task.call()); 60 | } 61 | catch(Throwable e) { 62 | fb.setError(e); 63 | } 64 | } 65 | }); 66 | return fb; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/IOHelper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011-2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi; 17 | 18 | import java.io.EOFException; 19 | import java.net.SocketException; 20 | 21 | 22 | class IOHelper { 23 | 24 | public static boolean isSocketTerminationException(Exception e) { 25 | if (e instanceof EOFException) { 26 | return true; 27 | } 28 | else if (e.getClass() == java.io.IOException.class) { 29 | if ("pipe is closed by reader".equals(e.getMessage().toLowerCase())) { 30 | return true; 31 | } 32 | if ("pipe is closed by writer".equals(e.getMessage().toLowerCase())) { 33 | return true; 34 | } 35 | } 36 | else if (e instanceof SocketException) { 37 | if ("connection reset".equals(e.getMessage().toLowerCase())) { 38 | return true; 39 | } 40 | if ("socket closed".equals(e.getMessage().toLowerCase())) { 41 | return true; 42 | } 43 | } 44 | 45 | // otherwise 46 | return false; 47 | } 48 | 49 | private static char[] HEX = "0123456789ABCDEF".toCharArray(); 50 | 51 | public static String toHexString(byte[] data, int offs, int len) { 52 | char[] c = new char[3 * len]; 53 | for(int i = 0; i != len; ++i) { 54 | c[3 * i] = HEX[0xF & (data[offs + i] >> 4)]; 55 | c[3 * i + 1] = HEX[0xF & (data[offs + i])]; 56 | c[3 * i + 2] = ' '; 57 | } 58 | return new String(c, 0, c.length - 1); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /interceptor/src/main/java/org/gridkit/nanocloud/interceptor/ThrowStub.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.nanocloud.interceptor; 17 | 18 | import java.io.ByteArrayInputStream; 19 | import java.io.ByteArrayOutputStream; 20 | import java.io.ObjectInputStream; 21 | import java.io.ObjectOutputStream; 22 | import java.io.Serializable; 23 | 24 | import org.gridkit.lab.interceptor.Interception; 25 | import org.gridkit.lab.interceptor.Interceptor; 26 | 27 | public class ThrowStub implements Interceptor, Serializable { 28 | 29 | private static final long serialVersionUID = 20130621L; 30 | 31 | private Throwable error; 32 | 33 | public ThrowStub(Throwable error) { 34 | this.error = error; 35 | } 36 | 37 | @Override 38 | public void handle(Interception call) { 39 | Throwable e = clone(error); 40 | call.setError(e); 41 | } 42 | 43 | private Throwable clone(Throwable e) { 44 | try { 45 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 46 | ObjectOutputStream oos = new ObjectOutputStream(bos); 47 | oos.writeObject(e); 48 | oos.flush(); 49 | ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); 50 | ObjectInputStream ois = new ObjectInputStream(bis); 51 | e = (Throwable) ois.readObject(); 52 | } catch (Exception x) { 53 | // ignore 54 | } 55 | e.setStackTrace(new Exception().getStackTrace()); 56 | return e; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /interceptor/src/main/java/org/gridkit/lab/interceptor/Interception.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.lab.interceptor; 17 | 18 | import java.lang.reflect.Method; 19 | import java.util.concurrent.ExecutionException; 20 | 21 | /** 22 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 23 | */ 24 | public interface Interception { 25 | 26 | public HookType getHookType(); 27 | 28 | public Class getHostClass(); 29 | 30 | /** 31 | * Currently only methods ({@link Method}) could be intercepted. 32 | * @return reflection object for this interception 33 | */ 34 | public Object getReflectionObject(); 35 | 36 | /** 37 | * @return this reference for context of interception. null for static method/fields and constructor access. 38 | */ 39 | public Object getThis(); 40 | 41 | /** 42 | * @return array of arguments, array could be modified to modify arguments passing through. 43 | */ 44 | public Object[] getCallParameters(); 45 | 46 | /** 47 | * @return result of call being hooked 48 | * @throws ExecutionException 49 | */ 50 | public Object call() throws ExecutionException; 51 | 52 | /** 53 | * Sets results and suppress invocation of original code 54 | */ 55 | public void setResult(Object result); 56 | 57 | /** 58 | * Sets error and suppress invocation of original code 59 | */ 60 | public void setError(Throwable e); 61 | 62 | } -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/vicluster/isolate/ThreadHelper.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.vicluster.isolate; 2 | 3 | import java.io.PrintStream; 4 | import java.io.PrintWriter; 5 | import java.lang.reflect.Method; 6 | 7 | class ThreadHelper { 8 | 9 | public static boolean stopThread(String name, Thread thread) { 10 | return stopWithThreadDoom(name, thread) || stopWithThreadDeath(thread); 11 | } 12 | 13 | private static boolean stopWithThreadDoom(String name, Thread thread) { 14 | 15 | // use reflection because method was removed in Java 11 16 | try { 17 | Method m = thread.getClass().getMethod("stop", Exception.class); 18 | m.setAccessible(true); 19 | m.invoke(thread, new ThreadDoomError(name)); 20 | return true; 21 | } catch (Throwable e) { 22 | return false; 23 | } 24 | } 25 | 26 | @SuppressWarnings("deprecation") 27 | private static boolean stopWithThreadDeath(Thread thread) { 28 | try { 29 | thread.stop(); 30 | return true; 31 | } catch (Throwable e) { 32 | return false; 33 | } 34 | } 35 | 36 | @SuppressWarnings("serial") 37 | private static class ThreadDoomError extends ThreadDeath { 38 | 39 | private final String name; 40 | 41 | public ThreadDoomError(String name) { 42 | this.name = name; 43 | } 44 | 45 | @Override 46 | public Throwable getCause() { 47 | return null; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return "Isolate [" + name + "] has been terminated"; 53 | } 54 | 55 | @Override 56 | public void printStackTrace() { 57 | } 58 | 59 | @Override 60 | public void printStackTrace(PrintStream s) { 61 | } 62 | 63 | @Override 64 | public void printStackTrace(PrintWriter s) { 65 | } 66 | 67 | @Override 68 | public StackTraceElement[] getStackTrace() { 69 | return null; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /vicluster-core/src/test/java/org/gridkit/nanocloud/CloudFactoryTest.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud; 2 | 3 | import java.io.StringWriter; 4 | import java.util.concurrent.Callable; 5 | 6 | import junit.framework.Assert; 7 | 8 | import org.gridkit.vicluster.ViNode; 9 | import org.gridkit.vicluster.ViProps; 10 | import org.junit.After; 11 | import org.junit.Test; 12 | 13 | public class CloudFactoryTest { 14 | 15 | public Cloud cloud = initCloud(); 16 | 17 | public Cloud initCloud() { 18 | Cloud cloud = CloudFactory.createCloud(); 19 | ViProps.at(cloud.node("**")).setLocalType(); 20 | return cloud; 21 | } 22 | 23 | @After 24 | public void dropCloud() { 25 | cloud.shutdown(); 26 | } 27 | 28 | @Test 29 | public void ping_local_node() { 30 | ViNode node = cloud.node("test"); 31 | node.touch(); 32 | String r = node.exec(new Callable() { 33 | @Override 34 | public String call() { 35 | System.out.println("Hallo world!"); 36 | return"ping"; 37 | } 38 | }); 39 | 40 | Assert.assertEquals("ping", r); 41 | } 42 | 43 | @Test 44 | public void capture_console_local_node() { 45 | ViNode node = cloud.node("test"); 46 | node.touch(); 47 | 48 | StringWriter outwriter = new StringWriter(); 49 | StringWriter errwriter = new StringWriter(); 50 | node.x(VX.CONSOLE).bindOut(outwriter); 51 | node.x(VX.CONSOLE).bindOut(outwriter); 52 | node.x(VX.CONSOLE).bindErr(errwriter); 53 | 54 | String r = node.exec(new Callable() { 55 | @Override 56 | public String call() { 57 | System.out.println("ping"); 58 | System.err.println("pong"); 59 | return"ping"; 60 | } 61 | }); 62 | 63 | node.x(VX.CONSOLE).flush(); 64 | 65 | Assert.assertEquals("ping", r); 66 | Assert.assertTrue(outwriter.toString().startsWith("ping")); 67 | Assert.assertTrue(errwriter.toString().startsWith("pong")); 68 | 69 | node.x(VX.CONSOLE).echoPrefix("~[%s-xx] !(.*)"); 70 | 71 | node.exec(new Callable() { 72 | @Override 73 | public Void call() { 74 | System.out.println("This line should use diffent prefix"); 75 | return null; 76 | } 77 | }); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /viconcurrent/src/main/java/org/gridkit/util/concurrent/CyclicBlockingBarrier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.util.concurrent; 17 | 18 | import java.util.concurrent.BrokenBarrierException; 19 | import java.util.concurrent.CyclicBarrier; 20 | import java.util.concurrent.Future; 21 | 22 | /** 23 | * {@link BlockingBarrier} adapter for {@link CyclicBarrier}. 24 | * TODO {@link Future} support is missing along with other minor semantic aspects. 25 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 26 | */ 27 | public class CyclicBlockingBarrier implements BlockingBarrier { 28 | 29 | private CyclicBarrier barrier; 30 | 31 | public CyclicBlockingBarrier(int parties, Runnable action) { 32 | barrier = new CyclicBarrier(parties, action); 33 | } 34 | 35 | @Override 36 | public void pass() throws InterruptedException, BrokenBarrierException { 37 | barrier.await(); 38 | } 39 | 40 | @Override 41 | public void pass(boolean breakOnInterrupt) throws InterruptedException, BrokenBarrierException { 42 | if (breakOnInterrupt == false) { 43 | throw new UnsupportedOperationException(); 44 | } 45 | barrier.await(); 46 | } 47 | 48 | @Override 49 | public void breakthrough() { 50 | barrier.reset(); 51 | } 52 | 53 | @Override 54 | public void stepIn() { 55 | throw new UnsupportedOperationException(); 56 | } 57 | 58 | @Override 59 | public Future stepIn(boolean needFuture) { 60 | throw new UnsupportedOperationException(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /telecontrol-ssh/src/test/java/org/gridkit/vicluster/telecontrol/ssh/TunnellerCheck.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.vicluster.telecontrol.ssh; 17 | 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | 21 | import org.gridkit.vicluster.telecontrol.BackgroundStreamDumper; 22 | import org.gridkit.vicluster.telecontrol.JvmConfig; 23 | import org.gridkit.vicluster.telecontrol.ManagedProcess; 24 | import org.junit.Test; 25 | 26 | public class TunnellerCheck { 27 | 28 | public Map config() { 29 | Map config = new HashMap(); 30 | config.put(RemoteNodeProps.HOST, "cbox1"); 31 | config.put(RemoteNodeProps.ACCOUNT, "root"); 32 | config.put(RemoteNodeProps.PASSWORD, "reverse"); 33 | config.put(RemoteNodeProps.JAVA_EXEC, "java"); 34 | config.put(RemoteNodeProps.JAR_CACHE_PATH, "/tmp/.vigrid/.cache"); 35 | return config; 36 | } 37 | 38 | @Test 39 | public void test_init() throws Exception { 40 | 41 | TunnellerJvmReplicator per = new TunnellerJvmReplicator(BackgroundStreamDumper.SINGLETON); 42 | per.configure(config()); 43 | per.init(); 44 | 45 | ManagedProcess cp = per.createProcess("test", new JvmConfig()); 46 | cp.bindStdOut(System.out); 47 | cp.bindStdOut(System.err); 48 | cp.getExecutionService().submit(new Runnable() { 49 | 50 | @Override 51 | public void run() { 52 | System.out.println("This is out"); 53 | System.err.println("This is err"); 54 | } 55 | }); 56 | 57 | Thread.sleep(500); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zeroio/AbstractLineProcessingOutputStream.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011-2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zeroio; 17 | 18 | import java.io.ByteArrayOutputStream; 19 | import java.io.IOException; 20 | import java.io.OutputStream; 21 | 22 | /** 23 | * @author Alexey Ragozin 24 | */ 25 | public abstract class AbstractLineProcessingOutputStream extends OutputStream { 26 | 27 | private ByteArrayOutputStream buffer; 28 | 29 | public AbstractLineProcessingOutputStream() { 30 | this.buffer = new ByteArrayOutputStream(); 31 | } 32 | 33 | private void dumpBuffer() throws IOException { 34 | processLine(buffer.toByteArray()); 35 | buffer.reset(); 36 | } 37 | 38 | protected abstract void processLine(byte[] data) throws IOException; 39 | 40 | @Override 41 | public synchronized void write(int c) throws IOException { 42 | buffer.write(c); 43 | if (c == '\n') { 44 | dumpBuffer(); 45 | } 46 | } 47 | 48 | @Override 49 | public synchronized void write(byte[] b, int off, int len) throws IOException { 50 | for (int i = 0; i != len; ++i) { 51 | if (b[off + i] == '\n') { 52 | writeByChars(b, off, len); 53 | return; 54 | } 55 | } 56 | buffer.write(b, off, len); 57 | } 58 | 59 | private void writeByChars(byte[] cbuf, int off, int len) throws IOException { 60 | for (int i = 0; i != len; ++i) { 61 | write(cbuf[off + i]); 62 | } 63 | } 64 | 65 | @Override 66 | public synchronized void close() throws IOException { 67 | super.flush(); 68 | if (buffer.size() > 0) { 69 | dumpBuffer(); 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/RemoteExecutor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi; 17 | 18 | import java.io.Serializable; 19 | import java.rmi.Remote; 20 | import java.util.concurrent.Callable; 21 | 22 | /** 23 | * This is minimal task execution interface for transparent remoting. 24 | * 25 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 26 | */ 27 | public interface RemoteExecutor extends Remote { 28 | 29 | public static final Callable INLINE_EXECUTOR_PRODUCER = new InlineRemoteExecutorProducer(); 30 | 31 | public void exec(Runnable task) throws Exception; 32 | 33 | public T exec(Callable task) throws Exception; 34 | 35 | public static class InlineRemoteExecutor implements RemoteExecutor { 36 | 37 | @Override 38 | public void exec(Runnable task) throws Exception { 39 | task.run(); 40 | } 41 | 42 | @Override 43 | public T exec(Callable task) throws Exception { 44 | return task.call(); 45 | } 46 | } 47 | 48 | /** 49 | * Due to complications of isolate classloaders run mode 50 | * this callable should be in this package. 51 | */ 52 | public static class InlineRemoteExecutorProducer implements Callable, Serializable { 53 | 54 | private static final long serialVersionUID = 20140725L; 55 | 56 | @Override 57 | public RemoteExecutor call() throws Exception { 58 | return new InlineRemoteExecutor(); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /zerormi/src/main/java/org/gridkit/zerormi/RemoteInstance.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Alexey Ragozin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gridkit.zerormi; 17 | 18 | import java.io.Serializable; 19 | import java.util.Arrays; 20 | 21 | /** 22 | * 23 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 24 | */ 25 | public final class RemoteInstance implements Serializable { 26 | 27 | private static final long serialVersionUID = 20090415L; 28 | 29 | String instanceId; 30 | String[] interfaces; 31 | 32 | public String[] getInterfaces() { 33 | return interfaces; 34 | } 35 | 36 | public String getInstanceId() { 37 | return instanceId; 38 | } 39 | 40 | public RemoteInstance(String instanceId, String[] interfaces) { 41 | if (instanceId == null) { 42 | throw new NullPointerException("instanceId cannot be null"); 43 | } 44 | if (interfaces == null) { 45 | throw new NullPointerException("interfaces cannot be null"); 46 | } 47 | this.instanceId = instanceId; 48 | this.interfaces = interfaces; 49 | } 50 | 51 | @Override 52 | public boolean equals(Object obj) { 53 | if (obj instanceof RemoteInstance) { 54 | RemoteInstance ri = (RemoteInstance) obj; 55 | return instanceId.equals(ri.instanceId) && Arrays.equals(interfaces, ri.interfaces); 56 | } 57 | return false; 58 | } 59 | 60 | @Override 61 | public int hashCode() { 62 | return instanceId.hashCode(); 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return "${" + instanceId +"}" + Arrays.toString(interfaces); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /vicluster-core/src/main/java/org/gridkit/nanocloud/telecontrol/isolate/IsolatedRemoteSession.java: -------------------------------------------------------------------------------- 1 | package org.gridkit.nanocloud.telecontrol.isolate; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.gridkit.nanocloud.telecontrol.RemoteExecutionSession; 6 | import org.gridkit.util.concurrent.AdvancedExecutor; 7 | import org.gridkit.vicluster.isolate.Isolate; 8 | import org.gridkit.zerormi.DuplexStream; 9 | import org.gridkit.zerormi.DuplexStreamConnector; 10 | import org.gridkit.zerormi.hub.SlaveSpore; 11 | 12 | /** 13 | * Wraps provided spore into Isolate to enable instrumentation. 14 | * 15 | * @author Alexey Ragozin (alexey.ragozin@gmail.com) 16 | */ 17 | class IsolatedRemoteSession implements RemoteExecutionSession { 18 | 19 | private RemoteExecutionSession nested; 20 | 21 | public IsolatedRemoteSession(RemoteExecutionSession nested) { 22 | this.nested = nested; 23 | } 24 | 25 | @Override 26 | public SlaveSpore getMobileSpore() { 27 | return new IsolatedSpore(nested.getMobileSpore()); 28 | } 29 | 30 | @Override 31 | public AdvancedExecutor getRemoteExecutor() { 32 | return nested.getRemoteExecutor(); 33 | } 34 | 35 | @Override 36 | public void setTransportConnection(DuplexStream stream) { 37 | nested.setTransportConnection(stream); 38 | } 39 | 40 | @Override 41 | public void terminate(Throwable cause) { 42 | nested.terminate(cause); 43 | } 44 | 45 | private static class IsolatedSpore implements SlaveSpore, Serializable { 46 | 47 | private static final long serialVersionUID = 20131209L; 48 | 49 | private SlaveSpore spore; 50 | 51 | public IsolatedSpore(SlaveSpore spore) { 52 | this.spore = spore; 53 | } 54 | 55 | @Override 56 | public void start(final DuplexStreamConnector masterConnector) { 57 | System.setProperty("gridkit.isolate.suppress.multiplexor", "true"); 58 | Isolate isolate = new Isolate("Spore"); 59 | isolate.exclude(DuplexStream.class, DuplexStreamConnector.class); 60 | final SlaveSpore spore = this.spore; 61 | isolate.start(); 62 | isolate.exec(new Runnable() { 63 | @Override 64 | public void run() { 65 | spore.start(masterConnector); 66 | } 67 | }); 68 | isolate.stop(); 69 | } 70 | } 71 | } 72 | --------------------------------------------------------------------------------