Skip to content

Commit b8c0d06

Browse files
committed
Updated generate endpoints + run_es_docker
1 parent 85fadc2 commit b8c0d06

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

util/GenerateEndpoints.php

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@
4040
Client::VERSION
4141
);
4242

43-
printf ("Backup Endpoints and Namespaces in /src\n");
43+
printf ("Backup Endpoints and Namespaces in:\n%s\n", $backupFileName);
4444
backup($backupFileName);
4545

46-
cleanFolders();
47-
4846
$start = microtime(true);
4947
printf ("Generating endpoints for Elasticsearch\n");
5048

@@ -61,9 +59,16 @@
6159
]
6260
);
6361
$files = explode("\n", $result);
64-
$outputDir = __DIR__ . "/../src/Elasticsearch/";
62+
63+
$outputDir = __DIR__ . "/output";
64+
if (!file_exists($outputDir)) {
65+
mkdir($outputDir);
66+
}
6567

6668
$endpointDir = "$outputDir/Endpoints/";
69+
if (!file_exists($endpointDir)) {
70+
mkdir($endpointDir);
71+
}
6772

6873
$countEndpoint = 0;
6974
$namespaces = [];
@@ -88,8 +93,7 @@
8893
);
8994
if (!isValidPhpSyntax($outputFile)) {
9095
printf("Error: syntax error in %s\n", $outputFile);
91-
$success = false;
92-
break;
96+
exit(1);
9397
}
9498

9599
printf("done\n");
@@ -98,15 +102,12 @@
98102
$countEndpoint++;
99103
}
100104

101-
if (!$success) {
102-
printf ("Roll back to the previous Endpoints and Namespace (ver. %s)\n", Client::VERSION);
103-
cleanFolders();
104-
restore($backupFileName);
105-
exit(1);
106-
}
107-
108105
// Generate namespaces
109106
$namespaceDir = "$outputDir/Namespaces/";
107+
if (!file_exists($namespaceDir)) {
108+
mkdir($namespaceDir);
109+
}
110+
110111
$countNamespace = 0;
111112
$clientFile = "$outputDir/Client.php";
112113

@@ -122,8 +123,7 @@
122123
);
123124
if (!isValidPhpSyntax($clientFile)) {
124125
printf("Error: syntax error in %s\n", $clientFile);
125-
$success = false;
126-
break;
126+
exit(1);
127127
}
128128
$countNamespace++;
129129
continue;
@@ -139,29 +139,32 @@
139139
);
140140
if (!isValidPhpSyntax($namespaceFile)) {
141141
printf("Error: syntax error in %s\n", $namespaceFile);
142-
$success = false;
143-
break;
142+
exit(1);
144143
}
145144
$countNamespace++;
146145
}
147146

147+
$destDir = __DIR__ . "/../src/Elasticsearch";
148+
149+
printf("Copying the generated files to %s\n", $destDir);
150+
cleanFolders();
151+
moveSubFolder($outputDir . "/Endpoints", $destDir . "/Endpoints");
152+
moveSubFolder($outputDir . "/Namespaces", $destDir . "/Namespaces");
153+
rename($outputDir . "/Client.php", $destDir . "/Client.php");
154+
148155
$end = microtime(true);
149-
if ($success) {
150-
printf("\nGenerated %d endpoints and %d namespaces in %.3f seconds\n.", $countEndpoint, $countNamespace, $end - $start);
151-
} else {
152-
printf ("Roll back to the previous Endpoints and Namespace (ver. %s)\n", Client::VERSION);
153-
cleanFolders();
154-
restore($backupFileName);
155-
}
156+
printf("\nGenerated %d endpoints and %d namespaces in %.3f seconds\n", $countEndpoint, $countNamespace, $end - $start);
157+
158+
removeDirectory($outputDir);
156159

157160
/**
158-
* FUNCTIONS
161+
* ---------------------------------- FUNCTIONS ----------------------------------
159162
*/
160163

161164
/**
162165
* Remove a directory recursively
163166
*/
164-
function removeDirectory($directory, array $omit = [])
167+
function removeDirectory($directory, array $omit = [])
165168
{
166169
foreach(glob("{$directory}/*") as $file)
167170
{
@@ -196,6 +199,16 @@ function cleanFolders()
196199
@unlink(__DIR__ . '/../src/Elasticsearch/Client.php');
197200
}
198201

202+
/**
203+
* Move subfolder
204+
*/
205+
function moveSubFolder(string $origin, string $destination)
206+
{
207+
foreach (glob("{$origin}/*") as $file) {
208+
rename($file, $destination . "/" . basename($file));
209+
}
210+
}
211+
199212
/**
200213
* Backup Endpoints, Namespaces and Client in src/Elasticsearch
201214
*/

util/run_es_docker.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ else
6060
--env "xpack.security.transport.ssl.certificate=certs/testnode.crt" \
6161
--env 'indices.lifecycle.history_index_enabled=false' \
6262
--env "xpack.security.transport.ssl.certificate_authorities=certs/ca.crt" \
63+
--env "xpack.ml.max_model_memory_limit=2gb" \
6364
--volume "$repo$testnodecrt:/usr/share/elasticsearch/config/certs/testnode.crt" \
6465
--volume "$repo$testnodekey:/usr/share/elasticsearch/config/certs/testnode.key" \
6566
--volume "$repo$cacrt:/usr/share/elasticsearch/config/certs/ca.crt" \

0 commit comments

Comments
 (0)