Skip to content

Commit b6dab53

Browse files
authored
Implemented instance type (#712)
* Implement instance type configuration. Implement handling of 'mappings not found' error. * Updated configs * Review fixes. Added separate exceptions for not supported version and not supported platform
1 parent 0a35b5f commit b6dab53

12 files changed

Lines changed: 93 additions & 18 deletions

server/configs/application-dev.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
extender.gradle.enabled: true
1+
extender:
2+
instance-type: BUILDER_ONLY
3+
gradle:
4+
enabled: true

server/configs/application-local-dev-app.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
extender:
2+
instance-type: FRONTEND_ONLY
23
remote-builder:
34
enabled: true
45
platforms:

server/configs/application-local-dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
extender:
2+
instance-type: BUILDER_ONLY
23
# sdk.location: /usr/local/extender/sdk
34
cache:
45
enabled: true

server/configs/application-standalone-dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ server:
22
port: 9010
33

44
extender:
5+
instance-type: MIXED
56
sdk:
67
location: /usr/local/extender/sdk
78
cache-clear-on-exit: false

server/configs/application-test-app.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
extender:
2+
instance-type: FRONTEND_ONLY
23
remote-builder:
34
enabled: true
45
platforms:

server/src/main/java/com/defold/extender/ExtenderController.java

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.apache.commons.io.FileUtils;
1717
import org.apache.commons.io.IOUtils;
1818
import org.eclipse.jetty.io.EofException;
19+
import org.json.simple.JSONObject;
1920
import org.json.simple.parser.ParseException;
2021
import org.slf4j.Logger;
2122
import org.slf4j.LoggerFactory;
@@ -46,9 +47,14 @@
4647
import java.util.regex.Matcher;
4748
import java.util.regex.Pattern;
4849

49-
5050
@RestController
5151
public class ExtenderController {
52+
public enum InstanceType {
53+
MIXED,
54+
FRONTEND_ONLY,
55+
BUILDER_ONLY
56+
};
57+
5258
private static final Logger LOGGER = LoggerFactory.getLogger(ExtenderController.class);
5359

5460
private static final String LATEST = "latest";
@@ -65,6 +71,8 @@ public class ExtenderController {
6571

6672
private final RemoteEngineBuilder remoteEngineBuilder;
6773
private Map<String, RemoteInstanceConfig> remoteBuilderPlatformMappings;
74+
@Value("${extender.instance-type:MIXED}")
75+
private InstanceType instanceType;
6876
private final boolean remoteBuilderEnabled;
6977

7078
private static long maxPackageSize = 1024*1024*1024;
@@ -148,7 +156,7 @@ public void buildEngineAsync(HttpServletRequest _request,
148156
HttpServletResponse response,
149157
@PathVariable("platform") String platform,
150158
@PathVariable("sdkVersion") String sdkVersionString)
151-
throws ExtenderException, IOException, ParseException {
159+
throws ExtenderException, IOException, ParseException, VersionNotSupportedException, PlatformNotSupportedException {
152160

153161
boolean isMultipart = JakartaServletFileUpload.isMultipartContent(_request);
154162
if (!isMultipart) {
@@ -198,17 +206,33 @@ public void buildEngineAsync(HttpServletRequest _request,
198206
// Regardless of success/fail status, we want to cache the uploaded files
199207
DataCacheService.DataCacheServiceInfo uploadResultInfo = dataCacheService.cacheFiles(uploadDirectory);
200208
metricsWriter.measureCacheUpload(uploadResultInfo.cachedFileSize.longValue(), uploadResultInfo.cachedFileCount.intValue());
201-
202-
String[] buildEnvDescription = ExtenderUtil.getSdksForPlatform(platform, defoldSdkService.getPlatformSdkMappings(sdkVersion));
203-
// Build engine locally or on remote builder
204-
if (remoteBuilderEnabled && isRemotePlatform(buildEnvDescription[0], buildEnvDescription[1])) {
205-
LOGGER.info("Building engine on remote builder");
206-
RemoteInstanceConfig remoteInstanceConfig = getRemoteBuilderConfig(buildEnvDescription[0], buildEnvDescription[1]);
207-
this.remoteEngineBuilder.buildAsync(remoteInstanceConfig, uploadDirectory, platform, sdkVersion, jobDirectory, buildDirectory, metricsWriter);
208-
} else {
209+
210+
if (instanceType.equals(InstanceType.BUILDER_ONLY)) {
209211
asyncBuilder.asyncBuildEngine(metricsWriter, platform, sdkVersion, jobDirectory, uploadDirectory, buildDirectory);
212+
} else {
213+
String[] buildEnvDescription = null;
214+
try {
215+
JSONObject mappings = defoldSdkService.getPlatformSdkMappings(sdkVersion);
216+
buildEnvDescription = ExtenderUtil.getSdksForPlatform(platform, mappings);
217+
} catch(ExtenderException exc) {
218+
if (instanceType.equals(InstanceType.FRONTEND_ONLY)) {
219+
LOGGER.error("Unsupported engine version {}", sdkVersion);
220+
throw new VersionNotSupportedException(sdkVersion);
221+
}
222+
}
223+
// Build engine locally or on remote builder
224+
if (remoteBuilderEnabled && buildEnvDescription != null && isRemotePlatform(buildEnvDescription[0], buildEnvDescription[1])) {
225+
LOGGER.info("Building engine on remote builder");
226+
RemoteInstanceConfig remoteInstanceConfig = getRemoteBuilderConfig(buildEnvDescription[0], buildEnvDescription[1]);
227+
this.remoteEngineBuilder.buildAsync(remoteInstanceConfig, uploadDirectory, platform, sdkVersion, jobDirectory, buildDirectory, metricsWriter);
228+
} else if (instanceType.equals(InstanceType.MIXED)) {
229+
asyncBuilder.asyncBuildEngine(metricsWriter, platform, sdkVersion, jobDirectory, uploadDirectory, buildDirectory);
230+
} else {
231+
// no remote builder was found and current instance can't build
232+
LOGGER.error("Unsupported build platform {}", platform);
233+
throw new PlatformNotSupportedException(platform);
234+
}
210235
}
211-
212236
response.getWriter().write(jobDirectory.getName());
213237
response.getWriter().flush();
214238
response.getWriter().close();
@@ -218,6 +242,8 @@ public void buildEngineAsync(HttpServletRequest _request,
218242
throw new ExtenderException(e, "Client closed connection prematurely, build aborted");
219243
} catch(FileUploadException e) {
220244
throw new ExtenderException(e, "Bad request: " + e.getMessage());
245+
} catch(VersionNotSupportedException|PlatformNotSupportedException exc) {
246+
throw exc;
221247
} catch(Exception e) {
222248
LOGGER.error(String.format("Exception while building or sending response - SDK: %s", sdkVersion));
223249
throw e;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.defold.extender;
2+
3+
public class PlatformNotSupportedException extends ExtenderException {
4+
private static String ERROR_MESSAGE = "Platform %s is not supported on the current server. Please, check build server address. If error will persist - create task here https://github.com/defold/extender/issues";
5+
6+
public PlatformNotSupportedException(String platform) {
7+
super(String.format(ERROR_MESSAGE, platform));
8+
}
9+
10+
public PlatformNotSupportedException(Exception e, String platform) {
11+
super(e, String.format(ERROR_MESSAGE, platform));
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.defold.extender;
2+
3+
public class VersionNotSupportedException extends ExtenderException {
4+
private static String ERROR_MESSAGE = "Engine version %s is not supported on the current server. Please, use latest stable version. https://github.com/defold/defold/releases/latest";
5+
6+
public VersionNotSupportedException(String version) {
7+
super(String.format(ERROR_MESSAGE, version));
8+
}
9+
10+
public VersionNotSupportedException(Exception e, String version) {
11+
super(e, String.format(ERROR_MESSAGE, version));
12+
}
13+
}

server/src/main/java/com/defold/extender/services/DefoldSdkService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ private JSONObject getRemotePlatformSdkMappings(String hash) throws IOException,
356356
try {
357357
JSONObject result = operation.get();
358358
if (result == null) {
359-
throw new ExtenderException(String.format("Cannot find or parse platform sdks mappings for hash: %s", hash));
359+
String msg = String.format("Cannot find or parse platform sdks mappings for hash: %s", hash);
360+
LOGGER.error(msg);
361+
throw new ExtenderException(msg);
360362
}
361363
return result;
362364
} catch (InterruptedException|ExecutionException exc) {

0 commit comments

Comments
 (0)