Exemple #1
0
        public IEnumerable <DatabaseServerResource> GetServerResources(string namespaceProperty, V1LabelSelector selector)
        {
            var servers = k8sService.GetDatabaseServer(namespaceProperty, selector);

            foreach (var server in servers.Items)
            {
                rehydrator.Rehydrate(server);
            }

            return(servers.Items);
        }
        public override bool HandleDequeuedItem(WatchEventType eventType, DeploymentScriptResource item, int previousExecutionCount)
        {
            Metrics.Measure.Counter.Increment(options);
            if (eventType != WatchEventType.Deleted)
            {
                try
                {
                    int executionCount = 0;
                    var databases      = k8sService.GetDatabases(item.Metadata.NamespaceProperty, item.Spec.DatabaseSelector);
                    foreach (var database in databases.Items)
                    {
                        if (database.Status.Reason == "Available")
                        {
                            var servers = k8sService.GetDatabaseServer(item.Metadata.NamespaceProperty, database.Spec.DatabaseServerSelector);
                            foreach (var server in servers.Items)
                            {
                                rehydrator.Rehydrate(server);

                                sqlService.ExecuteScript(server.Spec, database, item.Spec.Script);
                                executionCount++;
                            }
                        }
                    }

                    if (executionCount > 0)
                    {
                        k8sService.UpdateDeploymentScriptStatus(item, "Executed", "Successfully executed", DateTimeOffset.Now);
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex, "An error occurred during message processing");

                    try
                    {
                        k8sService.UpdateDeploymentScriptStatus(item, "Failed", ex.GetType().Name, DateTimeOffset.Now);
                        eventRecorder.Record("ExecuteDeploymentScript",
                                             "Failed",
                                             ex.Message,
                                             new V1ObjectReference(
                                                 item.ApiVersion,
                                                 kind: item.Kind,
                                                 name: item.Metadata.Name,
                                                 namespaceProperty: item.Metadata.NamespaceProperty)
                                             );
                    }
                    catch (HttpOperationException httpEx)
                    {
                        Logger.LogError(httpEx, "An error occurred logging this info to Kubernetes");
                        Logger.LogDebug(httpEx.Response.Content);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }

                return(false);
            }

            return(true);
        }