mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-11-10 08:57:25 +01:00
Add hands-on README in docs
This commit is contained in:
parent
02732cbbce
commit
71d6bf81c2
240
docs/Hands-on.md
Normal file
240
docs/Hands-on.md
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
# CC-HANDSON - Setup ClusterCockpit from scratch (w/o docker)
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
* Perl
|
||||||
|
* Yarn
|
||||||
|
* Go
|
||||||
|
* Optional: curl
|
||||||
|
* Script migrateTimestamp.pl
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
You find READMEs or api docs in
|
||||||
|
* ./cc-backend/configs
|
||||||
|
* ./cc-backend/init
|
||||||
|
* ./cc-backend/api
|
||||||
|
|
||||||
|
## ClusterCockpit configuration files
|
||||||
|
### cc-backend
|
||||||
|
* `./.env` Passwords and Tokens set in the environment
|
||||||
|
* `./config.json` Configuration options for cc-backend
|
||||||
|
|
||||||
|
### cc-metric-store
|
||||||
|
* `./config.json` Optional to overwrite configuration options
|
||||||
|
|
||||||
|
### cc-metric-collector
|
||||||
|
Not yet included in the hands-on setup.
|
||||||
|
|
||||||
|
## Setup Components
|
||||||
|
Start by creating a base folder for all of the following steps.
|
||||||
|
* `mkdir clustercockpit`
|
||||||
|
* `cd clustercockpit`
|
||||||
|
|
||||||
|
### Setup cc-backend
|
||||||
|
* Clone Repository
|
||||||
|
- `git clone https://github.com/ClusterCockpit/cc-backend.git`
|
||||||
|
- `cd cc-backend`
|
||||||
|
- `git checkout dev-job-archive-module` Will be merged soon into master
|
||||||
|
* Setup Frontend
|
||||||
|
- `cd ./web/frontend`
|
||||||
|
- `yarn install`
|
||||||
|
- `yarn build`
|
||||||
|
- `cd ../..`
|
||||||
|
* Build Go Executable
|
||||||
|
- `go build ./cmd/cc-backend/`
|
||||||
|
* Prepare Datafolder and Database file
|
||||||
|
- `mkdir var`
|
||||||
|
- `touch var/job.db`
|
||||||
|
* Activate & Config environment for cc-backend
|
||||||
|
- `cp configs/env-template.txt .env`
|
||||||
|
- Optional: Have a look via `vim ./.env`
|
||||||
|
- Copy the `config.json` file included in this tarball into the root directory of cc-backend: `cp ../../config.json ./`
|
||||||
|
* Back to toplevel `clustercockpit`
|
||||||
|
- `cd ..`
|
||||||
|
|
||||||
|
### Setup cc-metric-store
|
||||||
|
* Clone Repository
|
||||||
|
- `git clone https://github.com/ClusterCockpit/cc-metric-store.git`
|
||||||
|
- `cd cc-metric-store`
|
||||||
|
* Build Go Executable
|
||||||
|
- `go get`
|
||||||
|
- `go build`
|
||||||
|
* Prepare Datafolders
|
||||||
|
- `mkdir -p var/checkpoints`
|
||||||
|
- `mkdir -p var/archive`
|
||||||
|
* Update Config
|
||||||
|
- `vim config.json`
|
||||||
|
- Exchange existing setting in `metrics` with the following:
|
||||||
|
```
|
||||||
|
"clock": { "frequency": 60, "aggregation": null },
|
||||||
|
"cpi": { "frequency": 60, "aggregation": null },
|
||||||
|
"cpu_load": { "frequency": 60, "aggregation": null },
|
||||||
|
"flops_any": { "frequency": 60, "aggregation": null },
|
||||||
|
"flops_dp": { "frequency": 60, "aggregation": null },
|
||||||
|
"flops_sp": { "frequency": 60, "aggregation": null },
|
||||||
|
"ib_bw": { "frequency": 60, "aggregation": null },
|
||||||
|
"lustre_bw": { "frequency": 60, "aggregation": null },
|
||||||
|
"mem_bw": { "frequency": 60, "aggregation": null },
|
||||||
|
"mem_used": { "frequency": 60, "aggregation": null },
|
||||||
|
"rapl_power": { "frequency": 60, "aggregation": null }
|
||||||
|
```
|
||||||
|
* Back to toplevel `clustercockpit`
|
||||||
|
- `cd ..`
|
||||||
|
|
||||||
|
### Setup Demo Data
|
||||||
|
* `mkdir source-data`
|
||||||
|
* `cd source-data`
|
||||||
|
* Download JobArchive-Source:
|
||||||
|
- `wget https://hpc-mover.rrze.uni-erlangen.de/HPC-Data/0x7b58aefb/eig7ahyo6fo2bais0ephuf2aitohv1ai/job-archive-dev.tar.xz`
|
||||||
|
- `tar xJf job-archive-dev.tar.xz`
|
||||||
|
- `mv ./job-archive ./job-archive-source`
|
||||||
|
- `rm ./job-archive-dev.tar.xz`
|
||||||
|
* Download CC-Metric-Store Checkpoints:
|
||||||
|
- `mkdir -p cc-metric-store-source/checkpoints`
|
||||||
|
- `cd cc-metric-store-source/checkpoints`
|
||||||
|
- `wget https://hpc-mover.rrze.uni-erlangen.de/HPC-Data/0x7b58aefb/eig7ahyo6fo2bais0ephuf2aitohv1ai/cc-metric-store-checkpoints.tar.xz`
|
||||||
|
- `tar xf cc-metric-store-checkpoints.tar.xz`
|
||||||
|
- `rm cc-metric-store-checkpoints.tar.xz`
|
||||||
|
* Back to `source-data`
|
||||||
|
- `cd ../..`
|
||||||
|
* Run timestamp migration script. This may take tens of minutes!
|
||||||
|
- `cp ../migrateTimestamps.pl .`
|
||||||
|
- `./migrateTimestamps.pl`
|
||||||
|
- Expected output:
|
||||||
|
```
|
||||||
|
Starting to update start- and stoptimes in job-archive for emmy
|
||||||
|
Starting to update start- and stoptimes in job-archive for woody
|
||||||
|
Done for job-archive
|
||||||
|
Starting to update checkpoint filenames and data starttimes for emmy
|
||||||
|
Starting to update checkpoint filenames and data starttimes for woody
|
||||||
|
Done for checkpoints
|
||||||
|
```
|
||||||
|
* Copy `cluster.json` files from source to migrated folders
|
||||||
|
- `cp source-data/job-archive-source/emmy/cluster.json cc-backend/var/job-archive/emmy/`
|
||||||
|
- `cp source-data/job-archive-source/woody/cluster.json cc-backend/var/job-archive/woody/`
|
||||||
|
* Initialize Job-Archive in SQLite3 job.db and add demo user
|
||||||
|
- `cd cc-backend`
|
||||||
|
- `./cc-backend --init-db --add-user demo:admin:AdminDev`
|
||||||
|
- Expected output:
|
||||||
|
```
|
||||||
|
<6>[INFO] new user "demo" created (roles: ["admin"], auth-source: 0)
|
||||||
|
<6>[INFO] Building job table...
|
||||||
|
<6>[INFO] A total of 3936 jobs have been registered in 1.791 seconds.
|
||||||
|
```
|
||||||
|
* Back to toplevel `clustercockpit`
|
||||||
|
- `cd ..`
|
||||||
|
|
||||||
|
### Startup both Apps
|
||||||
|
* In cc-backend root: `$./cc-backend --server --dev`
|
||||||
|
- Starts Clustercockpit at `http:localhost:8080`
|
||||||
|
- Log: `<6>[INFO] HTTP server listening at :8080...`
|
||||||
|
- Use local internet browser to access interface
|
||||||
|
- You should see and be able to browse finished Jobs
|
||||||
|
- Metadata is read from SQLite3 database
|
||||||
|
- Metricdata is read from job-archive/JSON-Files
|
||||||
|
- Create User in settings (top-right corner)
|
||||||
|
- Name `apiuser`
|
||||||
|
- Username `apiuser`
|
||||||
|
- Role `API`
|
||||||
|
- Submit & Refresh Page
|
||||||
|
- Create JTW for `apiuser`
|
||||||
|
- In Userlist, press `Gen. JTW` for `apiuser`
|
||||||
|
- Save JWT for later use
|
||||||
|
* In cc-metric-store root: `$./cc-metric-store`
|
||||||
|
- Start the cc-metric-store on `http:localhost:8081`, Log:
|
||||||
|
```
|
||||||
|
2022/07/15 17:17:42 Loading checkpoints newer than 2022-07-13T17:17:42+02:00
|
||||||
|
2022/07/15 17:17:45 Checkpoints loaded (5621 files, 319 MB, that took 3.034652s)
|
||||||
|
2022/07/15 17:17:45 API http endpoint listening on '0.0.0.0:8081'
|
||||||
|
```
|
||||||
|
- Does *not* have a graphical interface
|
||||||
|
- Otpional: Test function by executing:
|
||||||
|
```
|
||||||
|
$ curl -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSJ9.eyJ1c2VyIjoiYWRtaW4iLCJyb2xlcyI6WyJST0xFX0FETUlOIiwiUk9MRV9BTkFMWVNUIiwiUk9MRV9VU0VSIl19.d-3_3FZTsadPjDEdsWrrQ7nS0edMAR4zjl-eK7rJU3HziNBfI9PDHDIpJVHTNN5E5SlLGLFXctWyKAkwhXL-Dw" -D - "http://localhost:8081/api/query" -d "{ \"cluster\": \"emmy\", \"from\": $(expr $(date +%s) - 60), \"to\": $(date +%s), \"queries\": [{
|
||||||
|
\"metric\": \"flops_any\",
|
||||||
|
\"host\": \"e1111\"
|
||||||
|
}] }"
|
||||||
|
|
||||||
|
HTTP/1.1 200 OK
|
||||||
|
Content-Type: application/json
|
||||||
|
Date: Fri, 15 Jul 2022 13:57:22 GMT
|
||||||
|
Content-Length: 119
|
||||||
|
{"results":[[JSON-DATA-ARRAY]]}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Development API web interfaces
|
||||||
|
The `--dev` flag enables web interfaces to document and test the apis:
|
||||||
|
* http://localhost:8080/playground - A GraphQL playground. To use it you must have a authenticated session in the same browser.
|
||||||
|
* http://localhost:8080/swagger - A Swagger UI. To use it you have to be logged out, so no user session in the same browser. Use the JWT token with role Api generate previously to authenticate via http header.
|
||||||
|
|
||||||
|
### Use cc-backend API to start job
|
||||||
|
* Enter the URL `http://localhost:8080/swagger/index.html` in your browser.
|
||||||
|
* Enter your JWT token you generated for the API user by clicking the green Authorize button in the upper right part of the window.
|
||||||
|
* Click the `/job/start_job` endpoint and click the Try it out button.
|
||||||
|
* Enter the following json into the request body text area and fill in a recent start timestamp by executing `date +%s`.:
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"jobId": 100000,
|
||||||
|
"arrayJobId": 0,
|
||||||
|
"user": "ccdemouser",
|
||||||
|
"subCluster": "main",
|
||||||
|
"cluster": "emmy",
|
||||||
|
"startTime": <date +%s>,
|
||||||
|
"project": "ccdemoproject",
|
||||||
|
"resources": [
|
||||||
|
{"hostname": "e0601"},
|
||||||
|
{"hostname": "e0823"},
|
||||||
|
{"hostname": "e0337"},
|
||||||
|
{"hostname": "e1111"}],
|
||||||
|
"numNodes": 4,
|
||||||
|
"numHwthreads": 80,
|
||||||
|
"walltime": 86400
|
||||||
|
}
|
||||||
|
```
|
||||||
|
* The response body should be the database id of the started job, for example:
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"id": 3937
|
||||||
|
}
|
||||||
|
```
|
||||||
|
* Check in ClusterCockpit
|
||||||
|
- User `ccdemouser` should appear in Users-Tab with one running job
|
||||||
|
- It could take up to 5 Minutes until the Job is displayed with some current data (5 Min Short-Job Filter)
|
||||||
|
- Job then is marked with a green `running` tag
|
||||||
|
- Metricdata displayed is read from cc-metric-store!
|
||||||
|
|
||||||
|
|
||||||
|
### Use cc-backend API to stop job
|
||||||
|
* Enter the URL `http://localhost:8080/swagger/index.html` in your browser.
|
||||||
|
* Enter your JWT token you generated for the API user by clicking the green Authorize button in the upper right part of the window.
|
||||||
|
* Click the `/job/stop_job/{id}` endpoint and click the Try it out button.
|
||||||
|
* Enter the database id at id that was returned by `start_job` and copy the following into the request body. Replace the timestamp with a recent one:
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"cluster": "emmy",
|
||||||
|
"jobState": "completed",
|
||||||
|
"stopTime": <RECENT TS>
|
||||||
|
}
|
||||||
|
```
|
||||||
|
* On success a json document with the job meta data is returned.
|
||||||
|
|
||||||
|
* Check in ClusterCockpit
|
||||||
|
- User `ccdemouser` should appear in Users-Tab with one completed job
|
||||||
|
- Job is no longer marked with a green `running` tag -> Completed!
|
||||||
|
- Metricdata displayed is now read from job-archive!
|
||||||
|
* Check in job-archive
|
||||||
|
- `cd ./cc-backend/var/job-archive/emmy/100/000`
|
||||||
|
- `cd $STARTTIME`
|
||||||
|
- Inspect `meta.json` and `data.json`
|
||||||
|
|
||||||
|
## Helper scripts
|
||||||
|
* In this tarball you can find the perl script `generate_subcluster.pl` that helps to generate the subcluster section for your system.
|
||||||
|
Usage:
|
||||||
|
* Log into an exclusive cluster node.
|
||||||
|
* The LIKWID tools likwid-topology and likwid-bench must be in the PATH!
|
||||||
|
* `$./generate_subcluster.pl` outputs the subcluster section on `stdout`
|
||||||
|
|
||||||
|
Please be aware that
|
||||||
|
* You have to enter the name and node list for the subCluster manually.
|
||||||
|
* GPU detection only works if LIKWID was build with Cuda avalable and you run likwid-topology also with Cuda loaded.
|
||||||
|
* Do not blindly trust the measured peakflops values.
|
||||||
|
* Because the script blindly relies on the CSV format output by likwid-topology this is a fragile undertaking!
|
35
docs/config.json
Normal file
35
docs/config.json
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"addr": "0.0.0.0:8080",
|
||||||
|
"archive": {
|
||||||
|
"kind": "file",
|
||||||
|
"path": "./var/job-archive"
|
||||||
|
},
|
||||||
|
"clusters": [
|
||||||
|
{
|
||||||
|
"name": "emmy",
|
||||||
|
"metricDataRepository": {
|
||||||
|
"kind": "cc-metric-store",
|
||||||
|
"url": "http://localhost:8081",
|
||||||
|
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSJ9.eyJ1c2VyIjoiYWRtaW4iLCJyb2xlcyI6WyJST0xFX0FETUlOIiwiUk9MRV9BTkFMWVNUIiwiUk9MRV9VU0VSIl19.d-3_3FZTsadPjDEdsWrrQ7nS0edMAR4zjl-eK7rJU3HziNBfI9PDHDIpJVHTNN5E5SlLGLFXctWyKAkwhXL-Dw"
|
||||||
|
},
|
||||||
|
"filterRanges": {
|
||||||
|
"numNodes": { "from": 1, "to": 32 },
|
||||||
|
"duration": { "from": 0, "to": 172800 },
|
||||||
|
"startTime": { "from": "2010-01-01T00:00:00Z", "to": null }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "woody",
|
||||||
|
"metricDataRepository": {
|
||||||
|
"kind": "cc-metric-store",
|
||||||
|
"url": "http://localhost:8081",
|
||||||
|
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSJ9.eyJ1c2VyIjoiYWRtaW4iLCJyb2xlcyI6WyJST0xFX0FETUlOIiwiUk9MRV9BTkFMWVNUIiwiUk9MRV9VU0VSIl19.d-3_3FZTsadPjDEdsWrrQ7nS0edMAR4zjl-eK7rJU3HziNBfI9PDHDIpJVHTNN5E5SlLGLFXctWyKAkwhXL-Dw"
|
||||||
|
},
|
||||||
|
"filterRanges": {
|
||||||
|
"numNodes": { "from": 1, "to": 1 },
|
||||||
|
"duration": { "from": 0, "to": 172800 },
|
||||||
|
"startTime": { "from": "2015-01-01T00:00:00Z", "to": null }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
229
docs/migrateTimestamps.pl
Executable file
229
docs/migrateTimestamps.pl
Executable file
@ -0,0 +1,229 @@
|
|||||||
|
#!/usr/bin/env perl
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use utf8;
|
||||||
|
|
||||||
|
use JSON::PP; # from Perl default install
|
||||||
|
use Time::Local qw( timelocal ); # from Perl default install
|
||||||
|
use Time::Piece; # from Perl default install
|
||||||
|
|
||||||
|
### JSON
|
||||||
|
my $json = JSON::PP->new->allow_nonref;
|
||||||
|
|
||||||
|
### TIME AND DATE
|
||||||
|
# now
|
||||||
|
my $localtime = localtime;
|
||||||
|
my $epochtime = $localtime->epoch;
|
||||||
|
# 5 days ago: Via epoch due to possible reverse month borders
|
||||||
|
my $epochlessfive = $epochtime - (86400 * 5);
|
||||||
|
my $locallessfive = localtime($epochlessfive);
|
||||||
|
# Calc like `date --date 'TZ="Europe/Berlin" 0:00 5 days ago' +%s`)
|
||||||
|
my ($day, $month, $year) = ($locallessfive->mday, $locallessfive->_mon, $locallessfive->year);
|
||||||
|
my $checkpointStart = timelocal(0, 0, 0, $day, $month, $year);
|
||||||
|
# for checkpoints
|
||||||
|
my $halfday = 43200;
|
||||||
|
|
||||||
|
### JOB-ARCHIVE
|
||||||
|
my $archiveTarget = './cc-backend/var/job-archive';
|
||||||
|
my $archiveSrc = './source-data/job-archive-source';
|
||||||
|
my @ArchiveClusters;
|
||||||
|
|
||||||
|
# Gen folder
|
||||||
|
if ( not -d $archiveTarget ){
|
||||||
|
mkdir( $archiveTarget ) or die "Couldn't create $archiveTarget directory, $!";
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get clusters by job-archive/$subfolder
|
||||||
|
opendir my $dh, $archiveSrc or die "can't open directory: $!";
|
||||||
|
while ( readdir $dh ) {
|
||||||
|
chomp; next if $_ eq '.' or $_ eq '..' or $_ eq 'job-archive';
|
||||||
|
my $cluster = $_;
|
||||||
|
push @ArchiveClusters, $cluster;
|
||||||
|
}
|
||||||
|
|
||||||
|
# start for jobarchive
|
||||||
|
foreach my $cluster ( @ArchiveClusters ) {
|
||||||
|
print "Starting to update start- and stoptimes in job-archive for $cluster\n";
|
||||||
|
|
||||||
|
my $clusterTarget = "$archiveTarget/$cluster";
|
||||||
|
|
||||||
|
if ( not -d $clusterTarget ){
|
||||||
|
mkdir( $clusterTarget ) or die "Couldn't create $clusterTarget directory, $!";
|
||||||
|
}
|
||||||
|
|
||||||
|
opendir my $dhLevel1, "$archiveSrc/$cluster" or die "can't open directory: $!";
|
||||||
|
while ( readdir $dhLevel1 ) {
|
||||||
|
chomp; next if $_ eq '.' or $_ eq '..';
|
||||||
|
my $level1 = $_;
|
||||||
|
|
||||||
|
if ( -d "$archiveSrc/$cluster/$level1" ) {
|
||||||
|
opendir my $dhLevel2, "$archiveSrc/$cluster/$level1" or die "can't open directory: $!";
|
||||||
|
while ( readdir $dhLevel2 ) {
|
||||||
|
chomp; next if $_ eq '.' or $_ eq '..';
|
||||||
|
my $level2 = $_;
|
||||||
|
my $jobSource = "$archiveSrc/$cluster/$level1/$level2";
|
||||||
|
my $jobOrigin = "$jobSource";
|
||||||
|
my $jobTargetL1 = "$clusterTarget/$level1";
|
||||||
|
my $jobTargetL2 = "$jobTargetL1/$level2";
|
||||||
|
|
||||||
|
# check if files are directly accessible (old format) else get subfolders as file and update path
|
||||||
|
if ( ! -e "$jobSource/meta.json") {
|
||||||
|
opendir(D, "$jobSource") || die "Can't open directory $jobSource: $!\n";
|
||||||
|
my @folders = readdir(D);
|
||||||
|
closedir(D);
|
||||||
|
if (!@folders) {
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach my $folder ( @folders ) {
|
||||||
|
next if $folder eq '.' or $folder eq '..';
|
||||||
|
$jobSource = "$jobSource/".$folder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# check if subfolder contains file, else skip
|
||||||
|
if ( ! -e "$jobSource/meta.json") {
|
||||||
|
print "$jobSource skipped\n";
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
open my $metafh, '<', "$jobSource/meta.json" or die "Can't open file $!";
|
||||||
|
my $rawstr = do { local $/; <$metafh> };
|
||||||
|
close($metafh);
|
||||||
|
my $metadata = $json->decode($rawstr);
|
||||||
|
|
||||||
|
# NOTE Start meta.json iteration here
|
||||||
|
# my $random_number = int(rand(UPPERLIMIT)) + LOWERLIMIT;
|
||||||
|
# Set new startTime: Between 5 days and 1 day before now
|
||||||
|
|
||||||
|
# Remove id from attributes
|
||||||
|
$metadata->{startTime} = $epochtime - (int(rand(432000)) + 86400);
|
||||||
|
$metadata->{stopTime} = $metadata->{startTime} + $metadata->{duration};
|
||||||
|
|
||||||
|
# Add starttime subfolder to target path
|
||||||
|
my $jobTargetL3 = "$jobTargetL2/".$metadata->{startTime};
|
||||||
|
|
||||||
|
if ( not -d $jobTargetL1 ){
|
||||||
|
mkdir( $jobTargetL1 ) or die "Couldn't create $jobTargetL1 directory, $!";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( not -d $jobTargetL2 ){
|
||||||
|
mkdir( $jobTargetL2 ) or die "Couldn't create $jobTargetL2 directory, $!";
|
||||||
|
}
|
||||||
|
|
||||||
|
# target is not directory
|
||||||
|
if ( not -d $jobTargetL3 ){
|
||||||
|
mkdir( $jobTargetL3 ) or die "Couldn't create $jobTargetL3 directory, $!";
|
||||||
|
|
||||||
|
my $outstr = $json->encode($metadata);
|
||||||
|
open my $metaout, '>', "$jobTargetL3/meta.json" or die "Can't write to file $!";
|
||||||
|
print $metaout $outstr;
|
||||||
|
close($metaout);
|
||||||
|
|
||||||
|
open my $datafh, '<', "$jobSource/data.json" or die "Can't open file $!";
|
||||||
|
my $datastr = do { local $/; <$datafh> };
|
||||||
|
close($datafh);
|
||||||
|
|
||||||
|
open my $dataout, '>', "$jobTargetL3/data.json" or die "Can't write to file $!";
|
||||||
|
print $dataout $datastr;
|
||||||
|
close($dataout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print "Done for job-archive\n";
|
||||||
|
sleep(1);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
## CHECKPOINTS
|
||||||
|
my $checkpTarget = './cc-metric-store/var/checkpoints';
|
||||||
|
my $checkpSource = './source-data/cc-metric-store-source/checkpoints';
|
||||||
|
my @CheckpClusters;
|
||||||
|
|
||||||
|
# Gen folder
|
||||||
|
if ( not -d $checkpTarget ){
|
||||||
|
mkdir( $checkpTarget ) or die "Couldn't create $checkpTarget directory, $!";
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get clusters by cc-metric-store/$subfolder
|
||||||
|
opendir my $dhc, $checkpSource or die "can't open directory: $!";
|
||||||
|
while ( readdir $dhc ) {
|
||||||
|
chomp; next if $_ eq '.' or $_ eq '..' or $_ eq 'job-archive';
|
||||||
|
my $cluster = $_;
|
||||||
|
push @CheckpClusters, $cluster;
|
||||||
|
}
|
||||||
|
closedir($dhc);
|
||||||
|
|
||||||
|
# start for checkpoints
|
||||||
|
foreach my $cluster ( @CheckpClusters ) {
|
||||||
|
print "Starting to update checkpoint filenames and data starttimes for $cluster\n";
|
||||||
|
|
||||||
|
my $clusterTarget = "$checkpTarget/$cluster";
|
||||||
|
|
||||||
|
if ( not -d $clusterTarget ){
|
||||||
|
mkdir( $clusterTarget ) or die "Couldn't create $clusterTarget directory, $!";
|
||||||
|
}
|
||||||
|
|
||||||
|
opendir my $dhLevel1, "$checkpSource/$cluster" or die "can't open directory: $!";
|
||||||
|
while ( readdir $dhLevel1 ) {
|
||||||
|
chomp; next if $_ eq '.' or $_ eq '..';
|
||||||
|
# Nodename as level1-folder
|
||||||
|
my $level1 = $_;
|
||||||
|
|
||||||
|
if ( -d "$checkpSource/$cluster/$level1" ) {
|
||||||
|
|
||||||
|
my $nodeSource = "$checkpSource/$cluster/$level1/";
|
||||||
|
my $nodeOrigin = "$nodeSource";
|
||||||
|
my $nodeTarget = "$clusterTarget/$level1";
|
||||||
|
my @files;
|
||||||
|
|
||||||
|
if ( -e "$nodeSource/1609459200.json") { # 1609459200 == First Checkpoint time in latest dump
|
||||||
|
opendir(D, "$nodeSource") || die "Can't open directory $nodeSource: $!\n";
|
||||||
|
while ( readdir D ) {
|
||||||
|
chomp; next if $_ eq '.' or $_ eq '..';
|
||||||
|
my $nodeFile = $_;
|
||||||
|
push @files, $nodeFile;
|
||||||
|
}
|
||||||
|
closedir(D);
|
||||||
|
my $length = @files;
|
||||||
|
if (!@files || $length != 14) { # needs 14 files == 7 days worth of data
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
# sort for integer timestamp-filename-part (moduleless): Guarantees start with index == 0 == 1609459200.json
|
||||||
|
my @sortedFiles = sort { ($a =~ /^([0-9]{10}).json$/)[0] <=> ($b =~ /^([0-9]{10}).json$/)[0] } @files;
|
||||||
|
|
||||||
|
if ( not -d $nodeTarget ){
|
||||||
|
mkdir( $nodeTarget ) or die "Couldn't create $nodeTarget directory, $!";
|
||||||
|
|
||||||
|
while (my ($index, $file) = each(@sortedFiles)) {
|
||||||
|
open my $checkfh, '<', "$nodeSource/$file" or die "Can't open file $!";
|
||||||
|
my $rawstr = do { local $/; <$checkfh> };
|
||||||
|
close($checkfh);
|
||||||
|
my $checkpdata = $json->decode($rawstr);
|
||||||
|
|
||||||
|
my $newTimestamp = $checkpointStart + ($index * $halfday);
|
||||||
|
# Get Diff from old Timestamp
|
||||||
|
my $timeDiff = $newTimestamp - $checkpdata->{from};
|
||||||
|
# Set new timestamp
|
||||||
|
$checkpdata->{from} = $newTimestamp;
|
||||||
|
|
||||||
|
foreach my $metric (keys %{$checkpdata->{metrics}}) {
|
||||||
|
$checkpdata->{metrics}->{$metric}->{start} += $timeDiff;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $outstr = $json->encode($checkpdata);
|
||||||
|
|
||||||
|
open my $checkout, '>', "$nodeTarget/$newTimestamp.json" or die "Can't write to file $!";
|
||||||
|
print $checkout $outstr;
|
||||||
|
close($checkout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir($dhLevel1);
|
||||||
|
}
|
||||||
|
print "Done for checkpoints\n";
|
Loading…
Reference in New Issue
Block a user