Example #1
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("UnsafeDeregisterInstance InstanceName");
                Console.WriteLine("WARNING: This is a metadata hacking tool that should NEVER be used on a real deployment");
                Console.WriteLine("This tool is a convenience for developers who want to more easily test certain application modfications");
                Console.WriteLine("Usage: UnsafeDeregisterInstance InstanceName");
                return;
            }
            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
            var dataProvider = new CRA.DataProvider.Azure.AzureDataProvider(Environment.GetEnvironmentVariable("AZURE_STORAGE_CONN_STRING"));
            var client       = new CRAClientLibrary(dataProvider);
            var serviceName  = args[0];

            foreach (var endpt in client.GetInputEndpointsAsync(serviceName).GetAwaiter().GetResult())
            {
                client.DeleteEndpoint(serviceName, endpt);
            }
            foreach (var endpt in client.GetOutputEndpointsAsync(serviceName).GetAwaiter().GetResult())
            {
                client.DeleteEndpoint(serviceName, endpt);
            }
            foreach (var conn in client.GetConnectionsFromVertexAsync(serviceName).GetAwaiter().GetResult())
            {
                client.DeleteConnectionInfoAsync(conn).GetAwaiter().GetResult();
            }
            foreach (var conn in client.GetConnectionsToVertexAsync(serviceName).GetAwaiter().GetResult())
            {
                client.DeleteConnectionInfoAsync(conn).GetAwaiter().GetResult();
            }
            try
            {
                client.DeleteVertexAsync(serviceName).GetAwaiter().GetResult();
            }
            catch { }
        }
Example #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.");
            }
        }
        static void startIC(string _instanceName,
                            int port,
                            int replicaNumber,
                            string secureNetworkClassName,
                            string secureNetworkAssemblyName)
        {
            StartupParamOverrides.sendPort    = 0;
            StartupParamOverrides.receivePort = 0;
            var replicaName = $"{_instanceName}{replicaNumber}";

            var ipAddress = GetLocalIPAddress();

            string storageConnectionString = null;

            if (storageConnectionString == null)
            {
                storageConnectionString = Environment.GetEnvironmentVariable("AZURE_STORAGE_CONN_STRING");
            }

            if (storageConnectionString == null)
            {
                throw new InvalidOperationException("Cannot start the IC. Azure storage connection string not found. Use appSettings in your app.config to provide this using the key AZURE_STORAGE_CONN_STRING, or use the environment variable AZURE_STORAGE_CONN_STRING.");
            }

            int    connectionsPoolPerWorker;
            string connectionsPoolPerWorkerString = "0";

            if (connectionsPoolPerWorkerString != null)
            {
                try
                {
                    connectionsPoolPerWorker = Convert.ToInt32(connectionsPoolPerWorkerString);
                }
                catch
                {
                    throw new InvalidOperationException("Maximum number of connections per CRA worker is wrong. Use appSettings in your app.config to provide this using the key CRA_WORKER_MAX_CONN_POOL.");
                }
            }
            else
            {
                connectionsPoolPerWorker = 1000;
            }

            ISecureStreamConnectionDescriptor descriptor = null;

            if (secureNetworkClassName != null)
            {
                Type type;
                if (secureNetworkAssemblyName != null)
                {
                    var assembly = Assembly.Load(secureNetworkAssemblyName);
                    type = assembly.GetType(secureNetworkClassName);
                }
                else
                {
                    type = Type.GetType(secureNetworkClassName);
                }
                descriptor = (ISecureStreamConnectionDescriptor)Activator.CreateInstance(type);
            }

            var dataProvider = new CRA.DataProvider.Azure.AzureDataProvider(storageConnectionString);
            var worker       = new CRAWorker
                                   (replicaName, ipAddress, port,
                                   dataProvider, descriptor, connectionsPoolPerWorker);

            worker.DisableDynamicLoading();
            worker.SideloadVertex(new AmbrosiaRuntime(), "ambrosia");

            worker.Start();
        }
Example #4
0
        static void Main(string[] args)
        {
            ParseAndValidateOptions(args);

            var replicaName = $"{_instanceName}{_replicaNumber}";

            if (_ipAddress == null)
            {
                _ipAddress = GetLocalIPAddress();
            }

            string storageConnectionString = null;

#if !DOTNETCORE
            storageConnectionString = ConfigurationManager.AppSettings.Get("AZURE_STORAGE_CONN_STRING");
#endif

            if (storageConnectionString == null)
            {
                storageConnectionString = Environment.GetEnvironmentVariable("AZURE_STORAGE_CONN_STRING");
            }

            if (!_isActiveActive && _replicaNumber != 0)
            {
                throw new InvalidOperationException("Can't specify a replica number without the activeActive flag");
            }

            if (storageConnectionString == null)
            {
                throw new InvalidOperationException("Azure storage connection string not found. Use appSettings in your app.config to provide this using the key AZURE_STORAGE_CONN_STRING, or use the environment variable AZURE_STORAGE_CONN_STRING.");
            }

            int    connectionsPoolPerWorker;
            string connectionsPoolPerWorkerString = "0";
#if !DOTNETCORE
            ConfigurationManager.AppSettings.Get("CRA_WORKER_MAX_CONN_POOL");
#endif
            if (connectionsPoolPerWorkerString != null)
            {
                try
                {
                    connectionsPoolPerWorker = Convert.ToInt32(connectionsPoolPerWorkerString);
                }
                catch
                {
                    throw new InvalidOperationException("Maximum number of connections per CRA worker is wrong. Use appSettings in your app.config to provide this using the key CRA_WORKER_MAX_CONN_POOL.");
                }
            }
            else
            {
                connectionsPoolPerWorker = 1000;
            }

            ISecureStreamConnectionDescriptor descriptor = null;
            if (_secureNetworkClassName != null)
            {
                Type type;
                if (_secureNetworkAssemblyName != null)
                {
                    var assembly = Assembly.Load(_secureNetworkAssemblyName);
                    type = assembly.GetType(_secureNetworkClassName);
                }
                else
                {
                    type = Type.GetType(_secureNetworkClassName);
                }
                descriptor = (ISecureStreamConnectionDescriptor)Activator.CreateInstance(type);
            }

            var dataProvider = new CRA.DataProvider.Azure.AzureDataProvider(storageConnectionString);
            var worker       = new CRAWorker
                                   (replicaName, _ipAddress, _port,
                                   dataProvider, descriptor, connectionsPoolPerWorker);

            worker.DisableDynamicLoading();
            worker.SideloadVertex(new AmbrosiaRuntime(), "ambrosia");

            worker.Start();
        }