Aktualisiere README und Code für den Ceph Max Storage Rechner: Übersetzung ins Englische, Verbesserung der Fehlerbehandlung in den Routen, Optimierung der PDF-Generierung und Anpassung der Benutzeroberfläche. Entferne veraltete JavaScript-Datei und aktualisiere die Struktur der Templates für bessere Lesbarkeit und Benutzerfreundlichkeit.
This commit is contained in:
@ -17,30 +17,44 @@ def calculate():
|
||||
try:
|
||||
data = request.json
|
||||
if not data:
|
||||
return jsonify({"error": "Keine Daten empfangen"}), 400
|
||||
return jsonify({"error": "No data received"}), 400
|
||||
|
||||
replication_type = data.get('replication_type') # 'replication' oder 'erasure_coding'
|
||||
replication_type = data.get('replication_type') # 'replication' or 'erasure_coding'
|
||||
if not replication_type:
|
||||
return jsonify({"error": "Replikationstyp fehlt"}), 400
|
||||
return jsonify({"error": "Replication type missing"}), 400
|
||||
|
||||
replicas = int(data.get('replicas', 3)) # Standardwert: 3 Replikate
|
||||
# Basic parameter validation
|
||||
try:
|
||||
replicas = int(data.get('replicas', 3)) # Default value: 3 replicas
|
||||
min_size = int(data.get('min_size', 2)) # Default value: 2
|
||||
|
||||
# For Erasure Coding
|
||||
k = int(data.get('k', 0)) if replication_type == 'erasure_coding' else 0
|
||||
m = int(data.get('m', 0)) if replication_type == 'erasure_coding' else 0
|
||||
|
||||
# Nodes and OSDs
|
||||
nodes = data.get('nodes', [])
|
||||
if not nodes:
|
||||
return jsonify({"error": "No nodes defined"}), 400
|
||||
|
||||
# Validate node data format
|
||||
for node in nodes:
|
||||
if 'osd_count' not in node or 'osd_size_gb' not in node:
|
||||
return jsonify({"error": "Invalid node data format. Each node must have osd_count and osd_size_gb properties."}), 400
|
||||
|
||||
# Simple validity check
|
||||
if int(node.get('osd_count', 0)) <= 0 or float(node.get('osd_size_gb', 0)) <= 0:
|
||||
return jsonify({"error": "Invalid OSD data. Both count and size must be greater than 0."}), 400
|
||||
|
||||
# Storage unit
|
||||
storage_unit = data.get('storage_unit', 'GB')
|
||||
if storage_unit not in ['GB', 'TB']:
|
||||
storage_unit = 'GB' # Default fallback
|
||||
|
||||
except (ValueError, TypeError) as e:
|
||||
return jsonify({"error": f"Invalid parameter: {str(e)}"}), 400
|
||||
|
||||
# Für Erasure Coding
|
||||
k = int(data.get('k', 0)) # Datenchunks
|
||||
m = int(data.get('m', 0)) # Codierungschunks
|
||||
|
||||
# Minimale Replikate für I/O-Operationen
|
||||
min_size = int(data.get('min_size', 2)) # Standardwert: 2
|
||||
|
||||
# Nodes und OSDs
|
||||
nodes = data.get('nodes', [])
|
||||
if not nodes:
|
||||
return jsonify({"error": "Keine Nodes definiert"}), 400
|
||||
|
||||
# Speichereinheit
|
||||
storage_unit = data.get('storage_unit', 'GB')
|
||||
|
||||
# Berechnung durchführen
|
||||
# Perform calculation
|
||||
result = calculate_ceph_capacity(
|
||||
replication_type=replication_type,
|
||||
replicas=replicas,
|
||||
@ -51,39 +65,40 @@ def calculate():
|
||||
storage_unit=storage_unit
|
||||
)
|
||||
|
||||
logger.info(f"Calculation performed successfully: {replication_type}, replicas={replicas}, nodes={len(nodes)}")
|
||||
return jsonify(result)
|
||||
except ValueError as e:
|
||||
logger.error(f"Validierungsfehler bei der Berechnung: {str(e)}")
|
||||
logger.error(f"Validation error during calculation: {str(e)}")
|
||||
return jsonify({"error": str(e)}), 400
|
||||
except Exception as e:
|
||||
logger.error(f"Fehler bei der Berechnung: {str(e)}\n{traceback.format_exc()}")
|
||||
return jsonify({"error": "Ein unerwarteter Fehler ist aufgetreten"}), 500
|
||||
logger.error(f"Error during calculation: {str(e)}\n{traceback.format_exc()}")
|
||||
return jsonify({"error": "An unexpected error occurred"}), 500
|
||||
|
||||
@bp.route('/generate-pdf', methods=['POST'])
|
||||
def generate_pdf():
|
||||
try:
|
||||
data = request.get_json()
|
||||
if not data:
|
||||
return jsonify({"error": "Keine Daten empfangen"}), 400
|
||||
return jsonify({"error": "No data received"}), 400
|
||||
|
||||
# Validiere die Daten
|
||||
# Validate data
|
||||
if not data.get('replication_type'):
|
||||
return jsonify({"error": "Replikationstyp fehlt"}), 400
|
||||
return jsonify({"error": "Replication type missing"}), 400
|
||||
|
||||
if not data.get('nodes') or not isinstance(data['nodes'], list):
|
||||
return jsonify({"error": "Ungültige Node-Daten"}), 400
|
||||
return jsonify({"error": "Invalid node data"}), 400
|
||||
|
||||
if not data.get('result') or not isinstance(data['result'], dict):
|
||||
return jsonify({"error": "Ungültige Ergebnisdaten"}), 400
|
||||
return jsonify({"error": "Invalid result data"}), 400
|
||||
|
||||
if not data['result'].get('raw_total'):
|
||||
return jsonify({"error": "Keine Berechnungsergebnisse vorhanden"}), 400
|
||||
return jsonify({"error": "No calculation results available"}), 400
|
||||
|
||||
# Generiere PDF
|
||||
# Generate PDF
|
||||
pdf_bytes = generate_pdf_report(data)
|
||||
|
||||
if not pdf_bytes:
|
||||
return jsonify({"error": "PDF-Generierung fehlgeschlagen"}), 500
|
||||
return jsonify({"error": "PDF generation failed"}), 500
|
||||
|
||||
return send_file(
|
||||
BytesIO(pdf_bytes),
|
||||
@ -92,8 +107,8 @@ def generate_pdf():
|
||||
download_name='ceph-report.pdf'
|
||||
)
|
||||
except ValueError as e:
|
||||
logger.error(f"Validierungsfehler bei der PDF-Generierung: {str(e)}")
|
||||
logger.error(f"Validation error during PDF generation: {str(e)}")
|
||||
return jsonify({"error": str(e)}), 400
|
||||
except Exception as e:
|
||||
logger.error(f"Fehler bei der PDF-Generierung: {str(e)}\n{traceback.format_exc()}")
|
||||
return jsonify({"error": "Ein unerwarteter Fehler ist aufgetreten"}), 500
|
||||
logger.error(f"Error during PDF generation: {str(e)}\n{traceback.format_exc()}")
|
||||
return jsonify({"error": "An unexpected error occurred"}), 500
|
||||
Reference in New Issue
Block a user