예제 #1
0
        public static async Task <bool> DeployClientTerminal(
            CRAClientLibrary client,
            string workerName,
            ClientTerminalTask task,
            OperatorsToplogy topology)
        {
            try
            {
                bool result = true;

                client.DisableArtifactUploading();

                if (!_isSubscribeClientOperatorDefined)
                {
                    await client.DefineVertexAsync(typeof(ShardedSubscribeClientOperator).Name.ToLower(), () => new ShardedSubscribeClientOperator());

                    _isSubscribeClientOperatorDefined = true;
                }

                var status = await client.InstantiateVertexAsync(new string[] { workerName }, task.OutputId, typeof(ShardedSubscribeClientOperator).Name.ToLower(), task, 1);

                if (status == CRAErrorCode.Success)
                {
                    foreach (string fromInputId in task.EndpointsDescriptor.FromInputs.Keys)
                    {
                        string outputEndpoint = OperatorUtils.PrepareOutputEndpointIdForOperator(
                            task.OutputId, topology.OperatorsEndpointsDescriptors[fromInputId]);
                        string inputEndpoint = OperatorUtils.PrepareInputEndpointIdForOperator(fromInputId, task.EndpointsDescriptor, false);

                        await client.ConnectAsync(fromInputId, outputEndpoint, task.OutputId, inputEndpoint);
                    }
                    result = true;
                }
                else
                {
                    result = false;
                }

                client.EnableArtifactUploading();

                return(result);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error in deploying a CRA client terminal vertex. Please, double check your task configurations: " + e.ToString());
                return(false);
            }
        }
예제 #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.");
            }
        }