Files
dtic-DIIAA/tools/orquestador/lib/sincronizacion/manager.rb
T

173 lines
5.1 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env ruby
# frozen_string_literal: true
# tools/orquestador/lib/sincronizacion/manager.rb
# ==============================================
# Clase para sincronización centralizada del dashboard P2601
# Filosofía: "Menos es más" - código reutilizable y modular
require_relative '../dashboard_core'
module DashboardCore
class SincronizacionManager < Base
# Configuración de rutas de sincronización
CONFIG_SINCRONIZACION = {
local: {
dashboard_dir: File.expand_path('../../../../dashboard', __dir__),
index_file: 'index.html',
backups_dir: 'backups'
},
production: {
dashboard_dir: '/var/www/html/P2601',
index_file: 'index.html',
backups_dir: '/var/www/html/P2601/backups'
},
staging: {
dashboard_dir: '/var/www/html/P2601-staging',
index_file: 'index.html',
backups_dir: '/var/www/html/P2601-staging/backups'
}
}.freeze
def initialize(dashboard_path = nil, options = {})
super(dashboard_path)
@dry_run = options[:dry_run] || false
@verbose = options[:verbose] || false
@backup = options[:backup] || true
@ambiente_destino = options[:ambiente] || 'production'
end
# Métodos principales de sincronización
def sincronizar_a_produccion
puts "🔄 SINCRONIZANDO DASHBOARD A PRODUCCIÓN"
puts "=" * 60
# Verificar rutas locales
unless verificar_ruta_local
puts "❌ Error: No se puede acceder al dashboard local"
return false
end
# Verificar rutas de producción
unless verificar_ruta_produccion
puts "❌ Error: No se puede acceder al dashboard de producción"
puts " Ruta: #{CONFIG_SINCRONIZACION[:production][:dashboard_dir]}"
return false
end
# Crear backup en producción si está habilitado
if @backup && !@dry_run
unless crear_backup_produccion
puts "❌ Error: No se pudo crear backup en producción"
return false
end
end
# Sincronizar archivos
puts "📁 Sincronizando archivos..."
archivos_sincronizados = sincronizar_archivos
# Mostrar resumen
mostrar_resumen_sincronizacion(archivos_sincronizados)
archivos_sincronizados.any?
end
def sincronizar_a_staging
puts "🔄 SINCRONIZANDO DASHBOARD A STAGING"
puts "=" * 60
# Verificar rutas locales
unless verificar_ruta_local
puts "❌ Error: No se puede acceder al dashboard local"
return false
end
# Verificar rutas de staging
unless verificar_ruta_staging
puts "❌ Error: No se puede acceder al dashboard de staging"
puts " Ruta: #{CONFIG_SINCRONIZACION[:staging][:dashboard_dir]}"
return false
end
# Crear backup en staging si está habilitado
if @backup && !@dry_run
unless crear_backup_staging
puts "❌ Error: No se pudo crear backup en staging"
return false
end
end
# Sincronizar archivos
puts "📁 Sincronizando archivos..."
archivos_sincronizados = sincronizar_archivos_staging
# Mostrar resumen
mostrar_resumen_sincronizacion(archivos_sincronizados, 'staging')
archivos_sincronizados.any?
end
def verificar_estado_sincronizacion
puts "🔍 VERIFICANDO ESTADO DE SINCRONIZACIÓN"
puts "=" * 60
# Verificar estado local
estado_local = verificar_estado_local
puts "📁 ESTADO LOCAL:"
mostrar_estado_verificacion(estado_local)
# Verificar estado producción
estado_produccion = verificar_estado_produccion
puts "\n🌐 ESTADO PRODUCCIÓN:"
mostrar_estado_verificacion(estado_produccion)
# Comparar archivos
puts "\n📊 COMPARACIÓN DE ARCHIVOS:"
comparacion = comparar_archivos
mostrar_comparacion_archivos(comparacion)
# Recomendaciones
puts "\n💡 RECOMENDACIONES:"
generar_recomendaciones_sincronizacion(estado_local, estado_produccion, comparacion).each do |recomendacion|
puts " • #{recomendacion}"
end
true
end
def listar_backups(ambiente = 'production')
puts "💾 LISTANDO BACKUPS - #{ambiente.upcase}"
puts "=" * 60
config = case ambiente
when 'production'
CONFIG_SINCRONIZACION[:production]
when 'staging'
CONFIG_SINCRONIZACION[:staging]
when 'local'
CONFIG_SINCRONIZACION[:local]
else
puts "❌ Ambiente '#{ambiente}' no válido"
return false
end
backup_dir = config[:backups_dir]
unless Dir.exist?(backup_dir)
puts "️ No existe el directorio de backups: #{backup_dir}"
return false
end
backups = Dir.glob(File.join(backup_dir, "dashboard_*.html"))
.map { |path| File.basename(path) }
.sort
.reverse
if backups.empty?
puts "️ No se encontraron backups"
return true
end
puts "📋 BACKUPS DISPONIBLES (#{back