Beispiel #1
0
        static int Main()
        {
            Console.WriteLine("Initializing the service...");

#if (Debug || DEBUG)
            if (!ServicesDebugOnlyUtilities.CalledFromMain())
            {
                return(1);
            }
#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.

            if (!BUtility.GetEnvironmentVariables(out Dictionary <string, string> EnvironmentVariables,
                                                  new string[][]
            {
                new string[] { "PORT" },
                new string[] { "PROGRAM_ID" },

                new string[] { "API_GATEWAY_SERVICE_BASE_URL" },

                new string[] { "STATIC_STATE_BUCKET" },     //Currently set to ignore on local debugging sessions; since it is only used for maintenance check

                new string[] { "DEPLOYMENT_BRANCH_NAME" },
                new string[] { "DEPLOYMENT_BUILD_NUMBER" }
            },
                                                  Console.WriteLine))
            {
                return(1);
            }

            Resources_DeploymentManager.Get().SetDeploymentBranchNameAndBuildNumber(EnvironmentVariables["DEPLOYMENT_BRANCH_NAME"], EnvironmentVariables["DEPLOYMENT_BUILD_NUMBER"]);

            if (!int.TryParse(EnvironmentVariables["PORT"], out int ServerPort))
            {
                Console.WriteLine("Invalid PORT environment variable; it must be an integer.");
                return(1);
            }

            string ApiGatewayServiceEndpoint = EnvironmentVariables["API_GATEWAY_SERVICE_BASE_URL"];

            string MaintenanceModeCheckUrl = "https://storage.googleapis.com/" + EnvironmentVariables["STATIC_STATE_BUCKET"] + "/maintenance_mode_" + Resources_DeploymentManager.Get().GetDeploymentBranchName();

            var DeploymentLoweredBranchName = Resources_DeploymentManager.Get().GetDeploymentBranchNameEscapedLoweredWithDash();
            if (DeploymentLoweredBranchName == "master" || DeploymentLoweredBranchName == "development")
            {
                //If the branch is feature, bugfix, hotfix etc. do not check for maintenance.
                MaintenanceChecker.Get().Start(MaintenanceModeCheckUrl, Console.WriteLine);
            }

            /*
             * Web-http service initialization
             */
            var WebServiceEndpoints = new List <BWebPrefixStructure>()
            {
                new BWebPrefixStructure(new string[] { "*" }, () => new PassThroughRequest(ApiGatewayServiceEndpoint))
            };
            var BWebService = new BWebService(WebServiceEndpoints.ToArray(), ServerPort);
            BWebService.Run((string Message) =>
            {
                Console.WriteLine(Message);
            });

            /*
             * Make main thread sleep forever
             */
            Thread.Sleep(Timeout.Infinite);

            return(0);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }