Esempio n. 1
0
        /// Gesture that deploys an upgradeable service WITH its IC running in the same process, for TTD. The result is a service that implements the API defined
        /// in <typeparamref name="T"/>.
        /// </summary>
        /// <typeparam name="T">The interface that defines the API of the deployed service.</typeparam>
        /// <param name="serviceName"></param>
        /// <param name="instance">The instance to deploy. It must implement <typeparamref name="T"/>.</param>
        /// <param name="serviceLogPath">The path used to get to the logs.</param>
        /// <param name="checkpointToLoad">The number of the checkpoint to start TTD from</param>
        /// <param name="currentVersion">The version number used to start TTD from</param>
        public static IDisposable Deploy <T, T2, Z2>(string serviceName,
                                                     Immortal instance,
                                                     string serviceLogPath,
                                                     long checkpointToLoad = 1,
                                                     int currentVersion    = 0)
            where T2 : T
            where Z2 : Immortal, T2 // *and* Z2 has a ctor that takes a Immortal as a parameter
        {
            _iCThread = new Thread(() => {
                var myRuntime = new AmbrosiaRuntime();
                myRuntime.InitializeRepro(serviceName, serviceLogPath, checkpointToLoad, currentVersion,
                                          true);
            })
            {
                IsBackground = true
            };
            _iCThread.Start();

            // Wait for the IC to finish setting up the named pipes before continuing (waiting avoids a potential deadlock)
            while (!AmbrosiaRuntime._listening)
            {
                ;
            }
            return(Deploy <T, T2, Z2>(serviceName, instance, 0, 0));
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            GenericLogsInterface.SetToGenericLogs();
            ParseAndValidateOptions(args);

            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));

            switch (_runtimeMode)
            {
            case LocalAmbrosiaRuntimeModes.DebugInstance:
                var myRuntime = new AmbrosiaRuntime();
                myRuntime.InitializeRepro(_instanceName, _serviceLogPath, _checkpointToLoad, _currentVersion,
                                          _isTestingUpgrade, _serviceReceiveFromPort, _serviceSendToPort);
                return;

            case LocalAmbrosiaRuntimeModes.AddReplica:
            case LocalAmbrosiaRuntimeModes.RegisterInstance:
                if (_runtimeMode == LocalAmbrosiaRuntimeModes.AddReplica)
                {
                    _isActiveActive = true;
                }

                var dataProvider = new CRA.DataProvider.Azure.AzureDataProvider(Environment.GetEnvironmentVariable("AZURE_STORAGE_CONN_STRING"));
                var client       = new CRAClientLibrary(dataProvider);
                client.DisableArtifactUploading();

                var replicaName             = $"{_instanceName}{_replicaNumber}";
                AmbrosiaRuntimeParams param = new AmbrosiaRuntimeParams();
                param.createService = _recoveryMode == AmbrosiaRecoveryModes.A
                        ? (bool?)null
                        : (_recoveryMode != AmbrosiaRecoveryModes.N);
                param.pauseAtStart             = _isPauseAtStart;
                param.persistLogs              = _isPersistLogs;
                param.logTriggerSizeMB         = _logTriggerSizeMB;
                param.activeActive             = _isActiveActive;
                param.upgradeToVersion         = _upgradeVersion;
                param.currentVersion           = _currentVersion;
                param.serviceReceiveFromPort   = _serviceReceiveFromPort;
                param.serviceSendToPort        = _serviceSendToPort;
                param.serviceName              = _instanceName;
                param.serviceLogPath           = _serviceLogPath;
                param.AmbrosiaBinariesLocation = _binariesLocation;
                param.storageConnectionString  = Environment.GetEnvironmentVariable("AZURE_STORAGE_CONN_STRING");

                try
                {
                    if (client.DefineVertexAsync(param.AmbrosiaBinariesLocation, () => new AmbrosiaRuntime()).GetAwaiter().GetResult() != CRAErrorCode.Success)
                    {
                        throw new Exception();
                    }

                    // Workaround because of limitation in parameter serialization in CRA
                    XmlSerializer xmlSerializer = new XmlSerializer(param.GetType());
                    string        serializedParams;
                    using (StringWriter textWriter = new StringWriter())
                    {
                        xmlSerializer.Serialize(textWriter, param);
                        serializedParams = textWriter.ToString();
                    }

                    if (client.InstantiateVertexAsync(replicaName, param.serviceName, param.AmbrosiaBinariesLocation, serializedParams).GetAwaiter().GetResult() != CRAErrorCode.Success)
                    {
                        throw new Exception();
                    }
                    client.AddEndpointAsync(param.serviceName, AmbrosiaRuntime.AmbrosiaDataInputsName, true, true).Wait();
                    client.AddEndpointAsync(param.serviceName, AmbrosiaRuntime.AmbrosiaDataOutputsName, false, true).Wait();
                    client.AddEndpointAsync(param.serviceName, AmbrosiaRuntime.AmbrosiaControlInputsName, true, true).Wait();
                    client.AddEndpointAsync(param.serviceName, AmbrosiaRuntime.AmbrosiaControlOutputsName, false, true).Wait();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error trying to upload service. Exception: " + e.Message);
                }

                return;

            default:
                throw new NotSupportedException($"Runtime mode: {_runtimeMode} not supported.");
            }
        }