public bool WithFileService() { /* * File service initialization */ FileService = new BFileServiceAZ(RequiredEnvironmentVariables["AZ_STORAGE_SERVICE_URL"], RequiredEnvironmentVariables["AZ_STORAGE_ACCOUNT_NAME"], RequiredEnvironmentVariables["AZ_STORAGE_ACCOUNT_ACCESS_KEY"], RequiredEnvironmentVariables["AZ_RESOURCE_GROUP_NAME"], RequiredEnvironmentVariables["AZ_RESOURCE_GROUP_LOCATION"], RequiredEnvironmentVariables["AZ_CLIENT_ID"], RequiredEnvironmentVariables["AZ_CLIENT_SECRET"], RequiredEnvironmentVariables["AZ_SUBSCRIPTION_ID"], RequiredEnvironmentVariables["AZ_TENANT_ID"], (string Message) => { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization"); }); if (FileService == null || !FileService.HasInitializationSucceed()) { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "File service initialization has failed."), ProgramID, "Initialization"); return(false); } return(true); }
public bool WithSMSService() { /* * SMS service initialization */ if (!RequiredEnvironmentVariables.ContainsKey("TWILIO_ACCOUNT_SID") || !RequiredEnvironmentVariables.ContainsKey("TWILIO_AUTH_TOKEN") || !RequiredEnvironmentVariables.ContainsKey("TWILIO_FROM_PHONE_NO")) { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_FROM_PHONE_NO parameters must be provided and valid."), ProgramID, "Initialization"); return(false); } SMSService = new BSMSServiceTwilio( RequiredEnvVars["TWILIO_ACCOUNT_SID"], RequiredEnvVars["TWILIO_AUTH_TOKEN"], RequiredEnvVars["TWILIO_FROM_PHONE_NO"], (string Message) => { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization"); }); if (SMSService == null || !SMSService.HasInitializationSucceed()) { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "SMS service initialization has failed."), ProgramID, "Initialization"); return(false); } return(true); }
public bool WithMailService() { /* * Mail service initialization */ if (!RequiredEnvironmentVariables.ContainsKey("SENDGRID_API_KEY") || !RequiredEnvironmentVariables.ContainsKey("SENDGRID_SENDER_EMAIL") || !RequiredEnvironmentVariables.ContainsKey("SENDGRID_SENDER_NAME")) { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "SENDGRID_API_KEY, SENDGRID_SENDER_EMAIL, SENDGRID_SENDER_NAME parameters must be provided and valid."), ProgramID, "Initialization"); return(false); } MailService = new BMailServiceSendGrid( RequiredEnvVars["SENDGRID_API_KEY"], RequiredEnvVars["SENDGRID_SENDER_EMAIL"], RequiredEnvVars["SENDGRID_SENDER_NAME"], (string Message) => { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization"); }); if (MailService == null || !MailService.HasInitializationSucceed()) { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "Mail service initialization has failed."), ProgramID, "Initialization"); return(false); } return(true); }
static void Main() { /* * Common initialization step */ if (!BServiceInitializer.Initialize(out BServiceInitializer ServInit, new string[][] { new string[] { "GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_PLAIN_CREDENTIALS" }, new string[] { "GOOGLE_CLOUD_PROJECT_ID" }, new string[] { "SECRETS_STORAGE_BUCKET" } })) { return; } //Tracing service is required if (!ServInit.WithTracingService()) { return; } //File service is required if (!ServInit.WithFileService()) { return; } var SecretsBucketName = ServInit.RequiredEnvironmentVariables["SECRETS_STORAGE_BUCKET"]; /* * Web-http service initialization */ var WebServiceEndpoints = new List <BWebPrefixStructure>() { new BWebPrefixStructure(new string[] { "/api/private/secrets/get" }, () => new BGetSecretsRequest(ServInit.FileService, SecretsBucketName)), new BWebPrefixStructure(new string[] { "/api/private/secrets/put" }, () => new BPutSecretsRequest(ServInit.FileService, SecretsBucketName)), new BWebPrefixStructure(new string[] { "/api/private/secrets/delete" }, () => new BDeleteSecretsRequest(ServInit.FileService, SecretsBucketName)), new BWebPrefixStructure(new string[] { "/api/private/secrets/list" }, () => new BListSecretsRequest(ServInit.FileService, SecretsBucketName)) }; var BWebService = new BWebService(WebServiceEndpoints.ToArray(), ServInit.ServerPort, ServInit.TracingService); BWebService.Run((string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, Message), ServInit.ProgramID, "WebService"); }); /* * Make main thread sleep forever */ Thread.Sleep(Timeout.Infinite); }
public bool WithDatabaseService() { /* * File service initialization */ if (!RequiredEnvironmentVariables.ContainsKey("MONGODB_DATABASE")) { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "((MONGODB_CONNECTION_STRING) or (MONGODB_CLIENT_CONFIG, MONGODB_PASSWORD) or (MONGODB_HOST, MONGODB_PORT)) and MONGODB_DATABASE must be provided and valid."), ProgramID, "Initialization"); return(false); } if (RequiredEnvironmentVariables.ContainsKey("MONGODB_CLIENT_CONFIG") && RequiredEnvironmentVariables.ContainsKey("MONGODB_PASSWORD")) { DatabaseService = new BDatabaseServiceMongoDB(RequiredEnvironmentVariables["MONGODB_CLIENT_CONFIG"], RequiredEnvironmentVariables["MONGODB_PASSWORD"], RequiredEnvironmentVariables["MONGODB_DATABASE"], (string Message) => { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization"); }); } else if (RequiredEnvironmentVariables.ContainsKey("MONGODB_CONNECTION_STRING")) { DatabaseService = new BDatabaseServiceMongoDB(RequiredEnvironmentVariables["MONGODB_CONNECTION_STRING"], RequiredEnvironmentVariables["MONGODB_DATABASE"], (string Message) => { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization"); }); } else if (RequiredEnvironmentVariables.ContainsKey("MONGODB_HOST") && RequiredEnvironmentVariables.ContainsKey("MONGODB_PORT") && int.TryParse(RequiredEnvironmentVariables["MONGODB_PORT"], out int MongoDbPort)) { DatabaseService = new BDatabaseServiceMongoDB(RequiredEnvironmentVariables["MONGODB_HOST"], MongoDbPort, RequiredEnvironmentVariables["MONGODB_DATABASE"], (string Message) => { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization"); }); } else { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "((MONGODB_CONNECTION_STRING) or (MONGODB_CLIENT_CONFIG, MONGODB_PASSWORD) or (MONGODB_HOST, MONGODB_PORT)) and MONGODB_DATABASE must be provided and valid."), ProgramID, "Initialization"); return(false); } if (DatabaseService == null || !DatabaseService.HasInitializationSucceed()) { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "Database service initialization has failed."), ProgramID, "Initialization"); return(false); } return(true); }
public static bool Initialize( out BServiceInitializer _Result, string[][] _RequiredExtraEnvVars = null) { var Instance = new BServiceInitializer(); _Result = null; Instance.LoggingService = new BLoggingServiceBasic(); var RequiredEnvVarKeys = new List <string[]>() { new string[] { "PORT" }, new string[] { "PROGRAM_ID" } }; if (_RequiredExtraEnvVars != null) { RequiredEnvVarKeys.AddRange(_RequiredExtraEnvVars); } /* * Getting environment variables */ if (!BUtility.GetEnvironmentVariables(out Instance._RequiredEnvironmentVariables, RequiredEnvVarKeys.ToArray(), (string Message) => { Instance.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), Instance.ProgramID, "Initialization"); })) { return(false); } Instance.ProgramID = Instance.RequiredEnvironmentVariables["PROGRAM_ID"]; /* * Parsing http server port */ if (!int.TryParse(Instance.RequiredEnvironmentVariables["PORT"], out int _ServPort)) { Instance.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "Given http server port is invalid."), Instance.ProgramID, "Initialization"); return(false); } Instance.ServerPort = _ServPort; _Result = Instance; return(true); }
public bool WithPubSubService(bool _bFailoverMechanismEnabled = true) { /* * Pub/Sub service initialization */ PubSubService = new BPubSubServiceAWS(RequiredEnvironmentVariables["AWS_ACCESS_KEY"], RequiredEnvironmentVariables["AWS_SECRET_KEY"], RequiredEnvironmentVariables["AWS_REGION"], (string Message) => { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization"); }); if (PubSubService == null || !PubSubService.HasInitializationSucceed()) { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "Pub/Sub service initialization has failed."), ProgramID, "Initialization"); return(false); } return(true); }
public bool WithDatabaseService() { /* * Database service initialization */ DatabaseService = new BDatabaseServiceAWS(RequiredEnvironmentVariables["AWS_ACCESS_KEY"], RequiredEnvironmentVariables["AWS_SECRET_KEY"], RequiredEnvironmentVariables["AWS_REGION"], (string Message) => { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization"); }); if (DatabaseService == null || !DatabaseService.HasInitializationSucceed()) { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "Database service initialization has failed."), ProgramID, "Initialization"); return(false); } return(true); }
public bool WithLoggingService() { /* * Logging service initialization */ LoggingService = new BLoggingServiceAzure(RequiredEnvironmentVariables["APPINSIGHTS_INSTRUMENTATIONKEY"], (string Message) => { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization"); }); if (LoggingService == null || !LoggingService.HasInitializationSucceed()) { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "Logging service initialization has failed."), ProgramID, "Initialization"); return(false); } return(true); }
public bool WithDatabaseService() { /* * File service initialization */ DatabaseService = new BDatabaseServiceGC(RequiredEnvironmentVariables["GOOGLE_CLOUD_PROJECT_ID"], (string Message) => { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization"); }); if (DatabaseService == null || !DatabaseService.HasInitializationSucceed()) { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "Database service initialization has failed."), ProgramID, "Initialization"); return(false); } return(true); }
public bool WithMemoryService(bool _bFailoverMechanismEnabled = true, IBPubSubServiceInterface _WithPubSubService = null) { /* * Memory service initialization */ if (!RequiredEnvironmentVariables.ContainsKey("REDIS_ENDPOINT") || !RequiredEnvironmentVariables.ContainsKey("REDIS_PORT") || !int.TryParse(RequiredEnvironmentVariables["REDIS_PORT"], out int RedisPort) || !RequiredEnvironmentVariables.ContainsKey("REDIS_PASSWORD")) { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "REDIS_ENDPOINT, REDIS_PORT, REDIS_PASSWORD parameters must be provided and valid."), ProgramID, "Initialization"); return(false); } bool RedisSslEnabled = false; if (RequiredEnvironmentVariables.ContainsKey("REDIS_SSL_ENABLED") && !bool.TryParse(RequiredEnvironmentVariables["REDIS_SSL_ENABLED"], out RedisSslEnabled)) { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Warning, "REDIS_SSL_ENABLED parameter has been provided, but it has not a valid value. It will be continued without SSL."), ProgramID, "Initialization"); } MemoryService = new BMemoryServiceRedis( RequiredEnvironmentVariables["REDIS_ENDPOINT"], RedisPort, RequiredEnvironmentVariables["REDIS_PASSWORD"], RedisSslEnabled, _WithPubSubService, _bFailoverMechanismEnabled, (string Message) => { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization"); }); if (MemoryService == null || !MemoryService.HasInitializationSucceed()) { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "Memory service initialization has failed."), ProgramID, "Initialization"); return(false); } return(true); }
public bool WithTracingService() { /* * Tracing service initialization */ if (!RequiredEnvironmentVariables.ContainsKey("ZIPKIN_SERVER_IP") || !RequiredEnvironmentVariables.ContainsKey("ZIPKIN_SERVER_PORT")) { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "ZIPKIN_SERVER_IP, ZIPKIN_SERVER_PORT parameters must be provided and valid."), ProgramID, "Initialization"); return(false); } var LoggingServiceLogger = new BLoggingServiceLoggerZipkin( LoggingService, PreLoggingServiceLogger, ProgramID); if (!int.TryParse(RequiredEnvironmentVariables["ZIPKIN_SERVER_PORT"], out int ZipkinServerPort)) { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "Given zipkin server port is invalid."), ProgramID, "Initialization"); return(false); } TracingService = new BTracingServiceZipkin( LoggingServiceLogger, ProgramID, RequiredEnvironmentVariables["ZIPKIN_SERVER_IP"], ZipkinServerPort, (string Message) => { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization"); }); if (TracingService == null || !TracingService.HasInitializationSucceed()) { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "Tracing service initialization has failed."), ProgramID, "Initialization"); return(false); } return(true); }
public bool WithPubSubService(bool _bFailoverMechanismEnabled = true) { /* * Pub/Sub service initialization */ PubSubService = new BPubSubServiceAzure( RequiredEnvironmentVariables["AZ_CLIENT_ID"], RequiredEnvironmentVariables["AZ_CLIENT_SECRET"], RequiredEnvironmentVariables["AZ_TENANT_ID"], RequiredEnvironmentVariables["AZ_SERVICEBUS_NAMESPACE_ID"], RequiredEnvironmentVariables["AZ_SERVICEBUS_NAMESPACE_CONNECTION_STRING"], (string Message) => { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization"); }); if (PubSubService == null || !PubSubService.HasInitializationSucceed()) { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "Pub/Sub service initialization has failed."), ProgramID, "Initialization"); return(false); } return(true); }
public bool WithVMService() { /* * VM service initialization */ VMService = new BVMServiceAZ( RequiredEnvironmentVariables["AZ_CLIENT_ID"], RequiredEnvironmentVariables["AZ_CLIENT_SECRET"], RequiredEnvironmentVariables["AZ_TENANT_ID"], RequiredEnvironmentVariables["AZ_RESOURCE_GROUP_NAME"], ProgramID, (string Message) => { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization"); }); if (VMService == null || !VMService.HasInitializationSucceed()) { LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "VM service initialization has failed."), ProgramID, "Initialization"); return(false); } return(true); }
static void Main() { Console.WriteLine("Initializing the service..."); #if (Debug || DEBUG) if (!ServicesDebugOnlyUtilities.CalledFromMain()) { return; } #endif // In case of a cloud component dependency or environment variable is added/removed; // Relative terraform script and microservice-dependency-map.cs must be updated as well. /* * Common initialization step */ if (!BServiceInitializer.Initialize(out BServiceInitializer ServInit, new string[][] { new string[] { "GOOGLE_CLOUD_PROJECT_ID" }, new string[] { "GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_PLAIN_CREDENTIALS" }, new string[] { "DEPLOYMENT_BRANCH_NAME" }, new string[] { "DEPLOYMENT_BUILD_NUMBER" }, new string[] { "INTERNAL_CALL_PRIVATE_KEY" } })) { return; } bool bInitSuccess = true; bInitSuccess &= ServInit.WithTracingService(); bInitSuccess &= ServInit.WithDatabaseService(); if (!bInitSuccess) { return; } Resources_DeploymentManager.Get().SetDeploymentBranchNameAndBuildNumber(ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BRANCH_NAME"], ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BUILD_NUMBER"]); string InternalPrivateKey = ServInit.RequiredEnvironmentVariables["INTERNAL_CALL_PRIVATE_KEY"]; Console.WriteLine(InternalPrivateKey); /* * Web-http service initialization */ var WebServiceEndpoints = new List <BWebPrefixStructure>() { new BWebPrefixStructure(new string[] { "/scheduler/internal/schedule*" }, () => new ScheduleRequest(InternalPrivateKey, ServInit.DatabaseService)), new BWebPrefixStructure(new string[] { "/scheduler/internal/unschedule*" }, () => new UnscheduleRequest(InternalPrivateKey, ServInit.DatabaseService)), new BWebPrefixStructure(new string[] { "/scheduler/internal/on_minute_call*" }, () => new OnMinuteCallRequest(InternalPrivateKey, ServInit.DatabaseService)) }; var BWebService = new BWebService(WebServiceEndpoints.ToArray(), ServInit.ServerPort, ServInit.TracingService); BWebService.Run((string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, Message), ServInit.ProgramID, "WebService"); }); /* * Make main thread sleep forever */ Thread.Sleep(Timeout.Infinite); }
static void Main() { System.Console.WriteLine("Initializing the service..."); //#if (Debug || DEBUG) // if (!ServicesDebugOnlyUtilities.CalledFromMain()) return; //#endif // In case of a cloud component dependency or environment variable is added/removed; /* * Common initialization step */ if (!BServiceInitializer.Initialize(out BServiceInitializer ServInit, new string[][] { new string[] { "GOOGLE_CLOUD_PROJECT_ID" }, new string[] { "GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_PLAIN_CREDENTIALS" }, new string[] { "DEPLOYMENT_BRANCH_NAME" }, new string[] { "DEPLOYMENT_BUILD_NUMBER" }, new string[] { "REDIS_ENDPOINT" }, new string[] { "REDIS_PORT" }, new string[] { "REDIS_PASSWORD" }, new string[] { "CAD_FILE_STORAGE_BUCKET" }, new string[] { "AUTH_SERVICE_ENDPOINT" }, new string[] { "CAD_PROCESS_SERVICE_ENDPOINT" }, new string[] { "INTERNAL_CALL_PRIVATE_KEY" } })) { return; } bool bInitSuccess = true; bInitSuccess &= ServInit.WithDatabaseService(); bInitSuccess &= ServInit.WithFileService(); bInitSuccess &= ServInit.WithPubSubService(); bInitSuccess &= ServInit.WithTracingService(); bInitSuccess &= ServInit.WithMemoryService(); if (!bInitSuccess) { return; } Resources_DeploymentManager.Get().SetDeploymentBranchNameAndBuildNumber(ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BRANCH_NAME"], ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BUILD_NUMBER"]); CommonData.MemoryQueryParameters = new BMemoryQueryParameters() { Domain = Resources_DeploymentManager.Get().GetDeploymentBranchNameEscapedLoweredWithDash().ToUpper(), SubDomain = "COMMON_DATA", Identifier = "MEMORY_SERVICE_DATA" }; var AuthServiceEndpoint = ServInit.RequiredEnvironmentVariables["AUTH_SERVICE_ENDPOINT"]; var CadFileStorageBucketName = ServInit.RequiredEnvironmentVariables["CAD_FILE_STORAGE_BUCKET"]; var CadProcessServiceEndpoint = ServInit.RequiredEnvironmentVariables["CAD_PROCESS_SERVICE_ENDPOINT"]; Controller_DeliveryEnsurer.Get().SetDatabaseService(ServInit.DatabaseService); Controller_DeliveryEnsurer.Get().SetFileService(ServInit.FileService); Controller_DeliveryEnsurer.Get().SetServiceIdentifier("cad-file-service", Actions.EAction.ACTION_CAD_FILE_SERVICE_DELIVERY_ENSURER); Controller_AtomicDBOperation.Get().SetMemoryService(ServInit.MemoryService, CommonData.MemoryQueryParameters); Manager_PubSubService.Get().Setup(ServInit.PubSubService); var InitializerThread = new Thread(() => { Thread.CurrentThread.IsBackground = true; ServInit.PubSubService.Subscribe(CommonData.MemoryQueryParameters, Manager_PubSubService.Get().OnMessageReceived_Internal, (string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Error, Message), ServInit.ProgramID, "PubSubService"); }); Controller_AtomicDBOperation.Get().StartTimeoutCheckOperation(WebServiceBaseTimeoutableProcessor.OnTimeoutNotificationReceived); }); InitializerThread.Start(); var InternalCallPrivateKey = ServInit.RequiredEnvironmentVariables["INTERNAL_CALL_PRIVATE_KEY"]; /* * Web-http service initialization */ var WebServiceEndpoints = new List <BWebPrefixStructure>() { new BWebPrefixStructure(new string[] { "/3d/models/internal/pubsub*" }, () => new InternalCalls.PubSub_To_CadFileService(InternalCallPrivateKey, ServInit.DatabaseService, ServInit.FileService, CadFileStorageBucketName, CadProcessServiceEndpoint)), new BWebPrefixStructure(new string[] { "/3d/models/internal/cleanup*" }, () => new InternalCalls.CleanupCall(InternalCallPrivateKey, ServInit.DatabaseService, ServInit.MemoryService)), new BWebPrefixStructure(new string[] { "/3d/models/internal/globally_shared_models*" }, () => new ListGloballySharedModelIds.ForInternal(InternalCallPrivateKey, ServInit.DatabaseService)), new BWebPrefixStructure(new string[] { "/3d/models/internal/check_models_exist*" }, () => new InternalCalls.CheckModelsExist(InternalCallPrivateKey, ServInit.DatabaseService)), new BWebPrefixStructure(new string[] { "/3d/models/get_models_by/user_id/*/metadata_key/*/metadata_values/*" }, () => new GetModelsBy_MetadataKeyValueUserPair(ServInit.DatabaseService, "user_id", "metadata_key", "metadata_values")), new BWebPrefixStructure(new string[] { "/3d/models/get_models_by/user_id/*/metadata_key/*" }, () => new GetModelsBy_MetadataKeyUserPair(ServInit.DatabaseService, "user_id", "metadata_key")), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/unreal/hierarchy_geometry_metadata" }, () => new Model_GetUnrealHierarchyMetadataGeometry(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/unreal/hierarchy_geometry" }, () => new Model_GetUnrealHierarchyGeometry(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/unreal/hierarchy" }, () => new Model_GetUnrealHierarchy(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/unreal/geometry_files/*" }, () => new Model_GetUnrealGeometry(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", "geometry_files", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/raw" }, () => new Model_GetUpdateDeleteRaw_ForRevision(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", CadFileStorageBucketName, CadProcessServiceEndpoint)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/hierarchy/nodes/*" }, () => new Model_GetHierarchyNode_ForRevision(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", "nodes", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/hierarchy" }, () => new Model_GetHierarchyFile_ForRevision(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/geometry/nodes/*" }, () => new Model_GetGeometryNode_ForRevision(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", "nodes", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/geometry" }, () => new Model_GetGeometryFile_ForRevision(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/metadata/nodes/*" }, () => new Model_GetMetadataNode_ForRevision(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", "keys", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/metadata" }, () => new Model_GetMetadataFile_ForRevision(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*" }, () => new Model_GetUpdateDeleteRevision(ServInit.DatabaseService, "models", "revisions", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions" }, () => new Model_AddListRevisions(ServInit.DatabaseService, "models")), new BWebPrefixStructure(new string[] { "/3d/models/*/sharing" }, () => new Model_ChangeSharingWithUsers(InternalCallPrivateKey, AuthServiceEndpoint, ServInit.DatabaseService, "models")), new BWebPrefixStructure(new string[] { "/3d/models/*/remove_sharing_from/user_id/*" }, () => new Model_RemoveModelShare(ServInit.DatabaseService, "models", "user_id")), new BWebPrefixStructure(new string[] { "/3d/models/globally_shared" }, () => new ListGloballySharedModelIds.ForUsers(ServInit.DatabaseService)), new BWebPrefixStructure(new string[] { "/3d/models/*" }, () => new Model_GetUpdateDeleteModel(ServInit.DatabaseService, "models")), new BWebPrefixStructure(new string[] { "/3d/models" }, () => new Model_AddListModels(ServInit.DatabaseService)) }; var BWebService = new BWebService(WebServiceEndpoints.ToArray(), ServInit.ServerPort /*, ServInit.TracingService*/); BWebService.Run((string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, Message), ServInit.ProgramID, "WebService"); }); /* * Make main thread sleep forever */ Thread.Sleep(Timeout.Infinite); }
static void Main() { System.Console.WriteLine("Initializing the service..."); #if (Debug || DEBUG) if (!ServicesDebugOnlyUtilities.CalledFromMain()) { return; } #endif // In case of a cloud component dependency or environment variable is added/removed; // Relative terraform script and microservice-dependency-map.cs must be updated as well. /* * Common initialization step */ if (!BServiceInitializer.Initialize(out BServiceInitializer ServInit, new string[][] { new string[] { "GOOGLE_CLOUD_PROJECT_ID" }, new string[] { "GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_PLAIN_CREDENTIALS" }, new string[] { "DEPLOYMENT_BRANCH_NAME" }, new string[] { "DEPLOYMENT_BUILD_NUMBER" }, new string[] { "AUTH_SERVICE_BASE_URL" }, new string[] { "CAD_FILE_SERVICE_BASE_URL" }, new string[] { "CUSTOM_PROCEDURES_SERVICE_BASE_URL" }, new string[] { "SCHEDULER_SERVICE_BASE_URL" } })) { return; } bool bInitSuccess = true; bInitSuccess &= ServInit.WithTracingService(); if (!bInitSuccess) { return; } Resources_DeploymentManager.Get().SetDeploymentBranchNameAndBuildNumber(ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BRANCH_NAME"], ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BUILD_NUMBER"]); /* * Web-http service initialization */ var AuthServiceBaseUrl = ServInit.RequiredEnvironmentVariables["AUTH_SERVICE_BASE_URL"]; var CadFileServiceBaseUrl = ServInit.RequiredEnvironmentVariables["CAD_FILE_SERVICE_BASE_URL"]; var CustomProceduresServiceBaseUrl = ServInit.RequiredEnvironmentVariables["CUSTOM_PROCEDURES_SERVICE_BASE_URL"]; var SchedulerServiceBaseUrl = ServInit.RequiredEnvironmentVariables["SCHEDULER_SERVICE_BASE_URL"]; var WebServiceEndpoints = new List <BWebPrefixStructure>() { new BWebPrefixStructure(new string[] { "/auth/ping" }, () => new HandleRequest(AuthServiceBaseUrl) /*Ping-pong; for avoiding scale-down-to-zero*/), new BWebPrefixStructure(new string[] { "/auth/internal/*" }, () => new HandleRequest(AuthServiceBaseUrl) /*Internal services have secret based auth check, different than login mechanism*/), new BWebPrefixStructure(new string[] { "/auth/login*" }, () => new HandleRequest(AuthServiceBaseUrl) /*For login requests*/), new BWebPrefixStructure(new string[] { "/auth/*" }, () => new HandleRequest(AuthServiceBaseUrl).WithLoginRequirement(AuthServiceBaseUrl) /*Required from external*/), new BWebPrefixStructure(new string[] { "/3d/models/ping" }, () => new HandleRequest(CadFileServiceBaseUrl) /*Ping-pong; for avoiding scale-down-to-zero*/), new BWebPrefixStructure(new string[] { "/3d/models/internal/*" }, () => new HandleRequest(CadFileServiceBaseUrl) /*Internal services have secret based auth check, different than login mechanism*/), new BWebPrefixStructure(new string[] { "/3d/models*" }, () => new HandleRequest(CadFileServiceBaseUrl).WithLoginRequirement(AuthServiceBaseUrl)), new BWebPrefixStructure(new string[] { "/scheduler/internal/*" }, () => new HandleRequest(SchedulerServiceBaseUrl) /*Internal services have secret based auth check, different than login mechanism*/), }; var BWebService = new BWebService(WebServiceEndpoints.ToArray(), ServInit.ServerPort, ServInit.TracingService); BWebService.Run((string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, Message), ServInit.ProgramID, "WebService"); }); /* * Make main thread sleep forever */ Thread.Sleep(Timeout.Infinite); }
static void Main() { Console.WriteLine("Initializing the service..."); #if (Debug || DEBUG) if (!ServicesDebugOnlyUtilities.CalledFromMain()) { return; } #endif // In case of a cloud component dependency or environment variable is added/removed; /* * Common initialization step */ if (!BServiceInitializer.Initialize(out BServiceInitializer ServInit, new string[][] { new string[] { "GOOGLE_CLOUD_PROJECT_ID" }, new string[] { "GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_PLAIN_CREDENTIALS" }, new string[] { "DEPLOYMENT_BRANCH_NAME" }, new string[] { "DEPLOYMENT_BUILD_NUMBER" }, new string[] { "REDIS_ENDPOINT" }, new string[] { "REDIS_PORT" }, new string[] { "REDIS_PASSWORD" }, new string[] { "CAD_PROCESS_SERVICE_NAME" }, new string[] { "CAD_PROCESS_POD_NAME" }, new string[] { "CAD_PROCESS_PORT" }, new string[] { "CLUSTER_MASTER_ENDPOINT" }, new string[] { "CLUSTER_CLIENT_KEY" }, new string[] { "CLUSTER_CLIENT_CERTIFICATE" }, new string[] { "CAD_READER_IMAGE" }, new string[] { "FILE_WORKER_IMAGE" }, new string[] { "FILE_OPTIMIZER_IMAGE" }, new string[] { "FILE_OPTIMIZER_ENVIRONMENT_VARIABLES" } })) { return; } bool bInitSuccess = true; bInitSuccess &= ServInit.WithDatabaseService(); bInitSuccess &= ServInit.WithFileService(); bInitSuccess &= ServInit.WithTracingService(); bInitSuccess &= ServInit.WithPubSubService(); bInitSuccess &= ServInit.WithMemoryService(); if (!bInitSuccess) { return; } Resources_DeploymentManager.Get().SetDeploymentBranchNameAndBuildNumber(ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BRANCH_NAME"], ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BUILD_NUMBER"]); Manager_PubSubService.Get().Setup(ServInit.PubSubService); try { //Initialize kubernetes client credentials and init pixyz processing classes KubernetesClientManager.SetDefaultCredentials(ServInit.RequiredEnvironmentVariables["CLUSTER_MASTER_ENDPOINT"], ServInit.RequiredEnvironmentVariables["CLUSTER_CLIENT_KEY"], ServInit.RequiredEnvironmentVariables["CLUSTER_CLIENT_CERTIFICATE"]); K8sObjectManager.SetImageNames(ServInit.RequiredEnvironmentVariables["FILE_WORKER_IMAGE"], ServInit.RequiredEnvironmentVariables["CAD_READER_IMAGE"], ServInit.RequiredEnvironmentVariables["FILE_OPTIMIZER_IMAGE"]); if (!BatchProcessingStateService.Initialize(ServInit.MemoryService, (string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, Message), ServInit.ProgramID, "WebService"); })) { return; } // Pass CadProcessService environment variables to FileOptimizer like Google, Azure, AWS Credentials etc. // For example: ['GOOGLE_CLOUD_PROJECT_ID', 'GOOGLE_PLAIN_CREDENTIALS'] var FileOptimizerEnvironmentVariables = new Dictionary <string, string>(); try { var FileOptimizerEnvVarsArray = JArray.Parse(ServInit.RequiredEnvironmentVariables["FILE_OPTIMIZER_ENVIRONMENT_VARIABLES"]); foreach (var item in FileOptimizerEnvVarsArray) { if (item.Type == JTokenType.String) { var key = (string)item; if (ServInit.RequiredEnvironmentVariables.ContainsKey(key)) { FileOptimizerEnvironmentVariables.Add(key, ServInit.RequiredEnvironmentVariables[key]); } } } } catch (Exception) { } BatchProcessingCreationService.Initialize( ServInit.DatabaseService, ServInit.FileService, ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BRANCH_NAME"], ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BUILD_NUMBER"], ServInit.RequiredEnvironmentVariables["CAD_PROCESS_SERVICE_NAME"], FileOptimizerEnvironmentVariables, () => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, "Failed to initialize batch process. Exiting..."), ServInit.ProgramID, "WebService"); Environment.Exit(1); }, (string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, Message), ServInit.ProgramID, "WebService"); }); } catch (Exception ex) { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, $"{ex.Message}\n{ ex.StackTrace}"), ServInit.ProgramID, "WebService"); return; } /* * Web-http service initialization */ var WebServiceEndpoints = new List <BWebPrefixStructure>() { new BWebPrefixStructure(new string[] { "/3d/process/start" }, () => new StartProcessRequest(ServInit.DatabaseService)), new BWebPrefixStructure(new string[] { "/3d/process/stop" }, () => new StopProcessRequest(ServInit.DatabaseService, ServInit.FileService)), new BWebPrefixStructure(new string[] { "/3d/process/internal/job-complete/*" }, () => new BatchJobCompleteRequest(ServInit.DatabaseService, ServInit.FileService, ServInit.MemoryService)), new BWebPrefixStructure(new string[] { "/3d/process/internal/get_signed_upload_url_for_unreal_file/*" }, () => new GetSignedUploadUrlRequest(ServInit.FileService)), new BWebPrefixStructure(new string[] { "/3d/process/internal/get_file_optimizer_parameters/*" }, () => new GetOptimizerParametersRequest(ServInit.DatabaseService)) }; var BWebService = new BWebService(WebServiceEndpoints.ToArray(), ServInit.ServerPort /*, ServInit.TracingService*/); BWebService.Run((string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, Message), ServInit.ProgramID, "WebService"); }); /* * Make main thread sleep forever */ Thread.Sleep(Timeout.Infinite); }
static void Main() { Console.WriteLine("Initializing the service..."); #if (Debug || DEBUG) if (!ServicesDebugOnlyUtilities.CalledFromMain()) { return; } #endif // In case of a cloud component dependency or environment variable is added/removed; // Relative terraform script and microservice-dependency-map.cs must be updated as well. /* * Common initialization step */ if (!BServiceInitializer.Initialize(out BServiceInitializer ServInit, new string[][] { new string[] { "GOOGLE_CLOUD_PROJECT_ID" }, new string[] { "GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_PLAIN_CREDENTIALS" }, new string[] { "DEPLOYMENT_BRANCH_NAME" }, new string[] { "DEPLOYMENT_BUILD_NUMBER" }, new string[] { "REDIS_ENDPOINT" }, new string[] { "REDIS_PORT" }, new string[] { "REDIS_PASSWORD" }, new string[] { "SSO_SUPER_ADMINS" }, new string[] { "AZURE_AD_APP_ID" }, new string[] { "AZURE_AD_CLIENT_SECRET" }, new string[] { "AZURE_AD_FETCH_USERS_CLIENT_ID" }, new string[] { "AZURE_AD_FETCH_USERS_CLIENT_SECRET" }, new string[] { "AZURE_AD_FETCH_USERS_APP_OBJECT_ID" }, new string[] { "AZURE_OAUTH2_TOKEN_REQUEST_URL" }, new string[] { "INTERNAL_CALL_PRIVATE_KEY" } })) { return; } bool bInitSuccess = true; bInitSuccess &= ServInit.WithTracingService(); bInitSuccess &= ServInit.WithDatabaseService(); bInitSuccess &= ServInit.WithPubSubService(); bInitSuccess &= ServInit.WithMemoryService(); if (!bInitSuccess) { return; } Resources_DeploymentManager.Get().SetDeploymentBranchNameAndBuildNumber(ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BRANCH_NAME"], ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BUILD_NUMBER"]); Controller_SSOAccessToken.SetLocalServerPort(ServInit.ServerPort); Controller_Rights_Internal.Get().SetLocalServerPort(ServInit.ServerPort); CommonData.MemoryQueryParameters = new BMemoryQueryParameters() { Domain = Resources_DeploymentManager.Get().GetDeploymentBranchNameEscapedLoweredWithDash().ToUpper(), SubDomain = "COMMON_DATA", Identifier = "MEMORY_SERVICE_DATA" }; var InternalCallPrivateKey = ServInit.RequiredEnvironmentVariables["INTERNAL_CALL_PRIVATE_KEY"]; CommonData.INTERNAL_CALL_PRIVATE_KEY = InternalCallPrivateKey; Console.WriteLine(InternalCallPrivateKey); Controller_DeliveryEnsurer.Get().SetDatabaseService(ServInit.DatabaseService); Controller_DeliveryEnsurer.Get().SetServiceIdentifier("auth-service", Actions.EAction.ACTION_AUTH_SERVICE_DELIVERY_ENSURER); Controller_AtomicDBOperation.Get().SetMemoryService(ServInit.MemoryService, CommonData.MemoryQueryParameters); Controller_Rights_Internal.Get().SetMemoryService(ServInit.MemoryService); Manager_PubSubService.Get().Setup(ServInit.PubSubService); var InitializerThread = new Thread(() => { Thread.CurrentThread.IsBackground = true; ServInit.PubSubService.Subscribe(CommonData.MemoryQueryParameters, Manager_PubSubService.Get().OnMessageReceived_Internal, (string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Error, Message), ServInit.ProgramID, "PubSubService"); }); Controller_AtomicDBOperation.Get().StartTimeoutCheckOperation(WebServiceBaseTimeoutableProcessor.OnTimeoutNotificationReceived); }); InitializerThread.Start(); var AzureAD_AppID = ServInit.RequiredEnvironmentVariables["AZURE_AD_APP_ID"]; var AzureAD_ClientSecret = ServInit.RequiredEnvironmentVariables["AZURE_AD_CLIENT_SECRET"]; var SSOSuperAdmins = new List <string>(); var SAsJsonString = ServInit.RequiredEnvironmentVariables["SSO_SUPER_ADMINS"]; try { var SAsJArray = JArray.Parse(SAsJsonString); foreach (var SAsToken in SAsJArray) { if (SAsToken.Type == JTokenType.String) { SSOSuperAdmins.Add(((string)SAsToken).ToLower()); } } } catch (Exception) { } var AzureFetchUsersClientID = ServInit.RequiredEnvironmentVariables["AZURE_AD_FETCH_USERS_CLIENT_ID"]; var AzureFetchUsersClientSecret = ServInit.RequiredEnvironmentVariables["AZURE_AD_FETCH_USERS_CLIENT_SECRET"]; var AzureFetchUsersAppObjectID = ServInit.RequiredEnvironmentVariables["AZURE_AD_FETCH_USERS_APP_OBJECT_ID"]; var AzureOAuth2TokenRequestUrl = ServInit.RequiredEnvironmentVariables["AZURE_OAUTH2_TOKEN_REQUEST_URL"]; /* * Web-http service initialization */ var WebServiceEndpoints = new List <BWebPrefixStructure>() { new BWebPrefixStructure(new string[] { "/auth/internal/pubsub*" }, () => new InternalCalls.PubSub_To_AuthService(InternalCallPrivateKey, ServInit.DatabaseService)), new BWebPrefixStructure(new string[] { "/auth/internal/cleanup*" }, () => new InternalCalls.CleanupCall(InternalCallPrivateKey, ServInit.DatabaseService, ServInit.MemoryService)), new BWebPrefixStructure(new string[] { "/auth/internal/fetch_user_ids_from_emails*" }, () => new InternalCalls.FetchUserIDsFromEmailsRequest(InternalCallPrivateKey, ServInit.DatabaseService)), new BWebPrefixStructure(new string[] { "/auth/internal/set*" }, () => new InternalCalls.SetCall(InternalCallPrivateKey, ServInit.MemoryService)), new BWebPrefixStructure(new string[] { "/auth/internal/create_test_user*" }, () => new InternalCalls.CreateTestUser(InternalCallPrivateKey, ServInit.DatabaseService, ServInit.ServerPort)), new BWebPrefixStructure(new string[] { "/auth/internal/delete_test_user*" }, () => new InternalCalls.DeleteTestUser(InternalCallPrivateKey, ServInit.ServerPort)), new BWebPrefixStructure(new string[] { "/auth/internal/synchronize_users_with_azure*" }, () => new InternalCalls.SynchronizeUsersWithAzureAD(InternalCallPrivateKey, AzureOAuth2TokenRequestUrl, AzureFetchUsersClientID, AzureFetchUsersClientSecret, AzureFetchUsersAppObjectID, ServInit.DatabaseService, SSOSuperAdmins)), new BWebPrefixStructure(new string[] { "/auth/login/azure/token_refresh" }, () => new SSOAzureTokenRefreshRequest(ServInit.DatabaseService, ServInit.MemoryService, AzureAD_AppID, AzureAD_ClientSecret, SSOSuperAdmins) /*For token refresh requests via Azure AD SSO Service*/), new BWebPrefixStructure(new string[] { "/auth/login/azure/*" }, () => new SSOAzureLoginCallback(ServInit.DatabaseService, ServInit.MemoryService, AzureAD_AppID, AzureAD_ClientSecret, SSOSuperAdmins) /*For auto-redirect from Azure AD SSO Service*/), new BWebPrefixStructure(new string[] { "/auth/login/azure*" }, () => new SSOAzureLoginRequest(ServInit.DatabaseService, ServInit.MemoryService, AzureAD_AppID, AzureAD_ClientSecret, SSOSuperAdmins) /*For login request via Azure AD SSO Service*/), new BWebPrefixStructure(new string[] { "/auth/login" }, () => new LoginRequest(ServInit.DatabaseService, ServInit.MemoryService)), new BWebPrefixStructure(new string[] { "/auth/access_check" }, () => new AccessCheckRequest(ServInit.DatabaseService, ServInit.MemoryService, AzureAD_AppID, AzureAD_ClientSecret, SSOSuperAdmins)), new BWebPrefixStructure(new string[] { "/auth/list_registered_email_addresses" }, () => new ListRegisteredUserEmails(ServInit.DatabaseService)), new BWebPrefixStructure(new string[] { "/auth/users/*/access_methods/*" }, () => new User_DeleteUserAccessMethod_ForUser(ServInit.DatabaseService, ServInit.MemoryService, "users", "access_methods")), new BWebPrefixStructure(new string[] { "/auth/users/*/access_methods" }, () => new User_CreateListAccessMethods_ForUser(ServInit.DatabaseService, ServInit.MemoryService, "users")), new BWebPrefixStructure(new string[] { "/auth/users/*/base_access_rights/*" }, () => new User_UpdateDeleteBaseRight_ForUser(ServInit.DatabaseService, ServInit.MemoryService, "users", "base_access_rights")), new BWebPrefixStructure(new string[] { "/auth/users/*/base_access_rights" }, () => new User_AddListBaseRights_ForUser(ServInit.DatabaseService, ServInit.MemoryService, "users")), new BWebPrefixStructure(new string[] { "/auth/users/*" }, () => new User_GetUpdateDeleteUser(ServInit.DatabaseService, ServInit.MemoryService, "users")), new BWebPrefixStructure(new string[] { "/auth/users" }, () => new User_CreateListUsers(ServInit.DatabaseService)) }; var BWebService = new BWebService(WebServiceEndpoints.ToArray(), ServInit.ServerPort, ServInit.TracingService); BWebService.Run((string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, Message), ServInit.ProgramID, "WebService"); }); var ApiPassThroughEndpoint = Environment.GetEnvironmentVariable("API_PASSTHROUGH_ENDPOINT"); if (ApiPassThroughEndpoint != null) { //Needed by MicroserviceLocalRunner new InternalCalls.SetCall(InternalCallPrivateKey, ServInit.MemoryService).Process_SetApiPassthroughPublicEndpoint( (string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Error, Message), ServInit.ProgramID, "WebService"); }, ApiPassThroughEndpoint); } var CadFileServiceEndpoint = Environment.GetEnvironmentVariable("CAD_FILE_SERVICE_ENDPOINT"); if (CadFileServiceEndpoint != null) { //Needed by MicroserviceLocalRunner new InternalCalls.SetCall(InternalCallPrivateKey, ServInit.MemoryService).Process_SetCADFileServicePublicEndpoint( (string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Error, Message), ServInit.ProgramID, "WebService"); }, CadFileServiceEndpoint); } /* * Make main thread sleep forever */ Thread.Sleep(Timeout.Infinite); }
static void Main(string[] args) { Console.WriteLine("Initializing the service..."); // In case of a cloud component dependency or environment variable is added/removed; /* * Common initialization step */ if (!BServiceInitializer.Initialize(out BServiceInitializer ServInit, new string[][] { new string[] { "GOOGLE_CLOUD_PROJECT_ID" }, new string[] { "GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_PLAIN_CREDENTIALS" }, new string[] { "DEPLOYMENT_BRANCH_NAME" }, new string[] { "DEPLOYMENT_BUILD_NUMBER" }, new string[] { "REDIS_ENDPOINT" }, new string[] { "REDIS_PORT" }, new string[] { "REDIS_PASSWORD" }, new string[] { "UPLOAD_HIERARCHY_CF" }, new string[] { "UPLOAD_HIERARCHY_RAF" }, new string[] { "UPLOAD_GEOMETRY_CF" }, new string[] { "UPLOAD_GEOMETRY_RAF" }, new string[] { "UPLOAD_METADATA_CF" }, new string[] { "UPLOAD_METADATA_RAF" }, new string[] { "IS_FILE_WRITE" }, new string[] { "CAD_PROCESS_NOTIFY_URL" } })) { return; } bool IsFileWrite = bool.Parse(ServInit.RequiredEnvironmentVariables["IS_FILE_WRITE"]); bool bInitSuccess = true; if (!IsFileWrite) { bInitSuccess &= ServInit.WithFileService(); bInitSuccess &= ServInit.WithTracingService(); } //Wait for redis int RetryCount = 0; while (true) { try { bInitSuccess &= ServInit.WithMemoryService(true, new BPubSubServiceRedis(ServInit.RequiredEnvironmentVariables["REDIS_ENDPOINT"], int.Parse(ServInit.RequiredEnvironmentVariables["REDIS_PORT"]), ServInit.RequiredEnvironmentVariables["REDIS_PASSWORD"])); break; } catch (Exception ex) { RetryCount++; Thread.Sleep(1000); if (RetryCount >= 30) { break; } } } if (!bInitSuccess) { return; } if (!BatchProcessingService.Initialize(ServInit.MemoryService)) { //Exit with an error code so that health checker can pick up on it and take action Environment.Exit(1); } BatchProcessingService.Instance.SetUploadUrls( ServInit.RequiredEnvironmentVariables["UPLOAD_HIERARCHY_CF"], ServInit.RequiredEnvironmentVariables["UPLOAD_HIERARCHY_RAF"], ServInit.RequiredEnvironmentVariables["UPLOAD_METADATA_CF"], ServInit.RequiredEnvironmentVariables["UPLOAD_METADATA_RAF"], ServInit.RequiredEnvironmentVariables["UPLOAD_GEOMETRY_CF"], ServInit.RequiredEnvironmentVariables["UPLOAD_GEOMETRY_RAF"], ServInit.RequiredEnvironmentVariables["CAD_PROCESS_NOTIFY_URL"], IsFileWrite); BatchProcessingService.Instance.RunResetProcessLoop((Message) => { Console.WriteLine(Message); }); //if (!IsFileWrite) //{ Resources_DeploymentManager.Get().SetDeploymentBranchNameAndBuildNumber(ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BRANCH_NAME"], ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BUILD_NUMBER"]); var WebServiceEndpoints = new List <BWebPrefixStructure>() { new BWebPrefixStructure(new string[] { "/healthcheck" }, () => new HealthCheckRequest()), new BWebPrefixStructure(new string[] { "/endprocess" }, () => new CheckProcessCompleteRequest()) }; var BWebService = new BWebService(WebServiceEndpoints.ToArray(), ServInit.ServerPort, ServInit.TracingService); BWebService.Run((string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, Message), ServInit.ProgramID, "WebService"); }); //} Thread.Sleep(Timeout.Infinite); }