generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
138 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package restore | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"path" | ||
"time" | ||
) | ||
|
||
type OutputWriter struct { | ||
NewResultsDir string | ||
} | ||
|
||
func NewOutputWriter(outputDir string) (OutputWriter, error) { | ||
newResultsDir := path.Join(outputDir, fmt.Sprintf("backup-%s", time.Now().Format(time.RFC3339))) | ||
|
||
err := os.MkdirAll(newResultsDir, os.ModePerm) | ||
if err != nil { | ||
return OutputWriter{}, fmt.Errorf("failed to create results directory: %v", err) | ||
} | ||
|
||
return OutputWriter{ | ||
NewResultsDir: newResultsDir, | ||
}, nil | ||
} | ||
|
||
func (ow OutputWriter) SaveRestoreResults(results Results) (string, error) { | ||
resultFile, err := json.Marshal(results.Results) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
fileName := fmt.Sprintf("%s/backup-results.json", ow.NewResultsDir) | ||
return fileName, writeFile(fileName, resultFile) | ||
} | ||
|
||
func writeFile(filePath string, content []byte) error { | ||
const writePermissions = 0644 | ||
return os.WriteFile(filePath, content, writePermissions) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package restore | ||
|
||
type StatusType string | ||
|
||
const ( | ||
StatusSuccess StatusType = "Success" | ||
StatusError StatusType = "Error" | ||
) | ||
|
||
type RuntimeResult struct { | ||
RuntimeID string `json:"runtimeId"` | ||
ShootName string `json:"shootName"` | ||
Status StatusType `json:"status"` | ||
ErrorMessage string `json:"errorMessage,omitempty"` | ||
} | ||
|
||
type Results struct { | ||
Results []RuntimeResult | ||
Succeeded int | ||
Failed int | ||
OutputDirectory string | ||
} | ||
|
||
func NewRestoreResults(outputDirectory string) Results { | ||
return Results{ | ||
Results: make([]RuntimeResult, 0), | ||
OutputDirectory: outputDirectory, | ||
} | ||
} | ||
|
||
func (br *Results) ErrorOccurred(runtimeID, shootName string, errorMsg string) { | ||
result := RuntimeResult{ | ||
RuntimeID: runtimeID, | ||
ShootName: shootName, | ||
Status: StatusError, | ||
ErrorMessage: errorMsg, | ||
} | ||
|
||
br.Failed++ | ||
br.Results = append(br.Results, result) | ||
} | ||
|
||
func (br *Results) OperationSucceeded(runtimeID string, shootName string) { | ||
result := RuntimeResult{ | ||
RuntimeID: runtimeID, | ||
ShootName: shootName, | ||
Status: StatusSuccess, | ||
} | ||
|
||
br.Succeeded++ | ||
br.Results = append(br.Results, result) | ||
} |