-
Notifications
You must be signed in to change notification settings - Fork 21
Implemented instance type #712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
extender.gradle.enabled: true | ||
extender: | ||
instance-type: BUILDER_ONLY | ||
gradle: | ||
enabled: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
extender: | ||
instance-type: FRONTEND_ONLY | ||
remote-builder: | ||
enabled: true | ||
platforms: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
extender: | ||
instance-type: BUILDER_ONLY | ||
# sdk.location: /usr/local/extender/sdk | ||
cache: | ||
enabled: true | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
extender: | ||
instance-type: FRONTEND_ONLY | ||
remote-builder: | ||
enabled: true | ||
platforms: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import jakarta.transaction.NotSupportedException; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
|
@@ -46,9 +47,14 @@ | |
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
|
||
@RestController | ||
public class ExtenderController { | ||
public enum InstanceType { | ||
MIXED, | ||
FRONTEND_ONLY, | ||
BUILDER_ONLY | ||
}; | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(ExtenderController.class); | ||
|
||
private static final String LATEST = "latest"; | ||
|
@@ -65,6 +71,8 @@ public class ExtenderController { | |
|
||
private final RemoteEngineBuilder remoteEngineBuilder; | ||
private Map<String, RemoteInstanceConfig> remoteBuilderPlatformMappings; | ||
@Value("${extender.instance-type:MIXED}") | ||
private InstanceType instanceType; | ||
private final boolean remoteBuilderEnabled; | ||
|
||
private static long maxPackageSize = 1024*1024*1024; | ||
|
@@ -198,17 +206,31 @@ public void buildEngineAsync(HttpServletRequest _request, | |
// Regardless of success/fail status, we want to cache the uploaded files | ||
DataCacheService.DataCacheServiceInfo uploadResultInfo = dataCacheService.cacheFiles(uploadDirectory); | ||
metricsWriter.measureCacheUpload(uploadResultInfo.cachedFileSize.longValue(), uploadResultInfo.cachedFileCount.intValue()); | ||
|
||
String[] buildEnvDescription = ExtenderUtil.getSdksForPlatform(platform, defoldSdkService.getPlatformSdkMappings(sdkVersion)); | ||
// Build engine locally or on remote builder | ||
if (remoteBuilderEnabled && isRemotePlatform(buildEnvDescription[0], buildEnvDescription[1])) { | ||
LOGGER.info("Building engine on remote builder"); | ||
RemoteInstanceConfig remoteInstanceConfig = getRemoteBuilderConfig(buildEnvDescription[0], buildEnvDescription[1]); | ||
this.remoteEngineBuilder.buildAsync(remoteInstanceConfig, uploadDirectory, platform, sdkVersion, jobDirectory, buildDirectory, metricsWriter); | ||
} else { | ||
|
||
if (instanceType.equals(InstanceType.BUILDER_ONLY)) { | ||
asyncBuilder.asyncBuildEngine(metricsWriter, platform, sdkVersion, jobDirectory, uploadDirectory, buildDirectory); | ||
} else { | ||
String[] buildEnvDescription = null; | ||
try { | ||
// sdk version was removed (dev or beta) | ||
buildEnvDescription = ExtenderUtil.getSdksForPlatform(platform, defoldSdkService.getPlatformSdkMappings(sdkVersion)); | ||
} catch(ExtenderException exc) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exception happened if we can't find sdk mappings for given hash. |
||
if (instanceType.equals(InstanceType.FRONTEND_ONLY)) { | ||
throw new NotSupportedException("Engine version unsupported. Please, update engine to the newer version."); | ||
} | ||
} | ||
// Build engine locally or on remote builder | ||
if (remoteBuilderEnabled && buildEnvDescription != null && isRemotePlatform(buildEnvDescription[0], buildEnvDescription[1])) { | ||
LOGGER.info("Building engine on remote builder"); | ||
RemoteInstanceConfig remoteInstanceConfig = getRemoteBuilderConfig(buildEnvDescription[0], buildEnvDescription[1]); | ||
this.remoteEngineBuilder.buildAsync(remoteInstanceConfig, uploadDirectory, platform, sdkVersion, jobDirectory, buildDirectory, metricsWriter); | ||
} else if (instanceType.equals(InstanceType.MIXED)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If sdk mappings exist but there are no required sdk version defined and instance marked as "MIXED" - try build on current instance. |
||
asyncBuilder.asyncBuildEngine(metricsWriter, platform, sdkVersion, jobDirectory, uploadDirectory, buildDirectory); | ||
} else { | ||
// no remote buidler was found and current instance can't build | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. buidler -> builder |
||
throw new NotSupportedException("Engine version unsupported. Please, update engine to the newer version."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SDK mappings exists but no record for given sdk and version was found - throw error. |
||
} | ||
} | ||
|
||
response.getWriter().write(jobDirectory.getName()); | ||
response.getWriter().flush(); | ||
response.getWriter().close(); | ||
|
@@ -218,6 +240,9 @@ public void buildEngineAsync(HttpServletRequest _request, | |
throw new ExtenderException(e, "Client closed connection prematurely, build aborted"); | ||
} catch(FileUploadException e) { | ||
throw new ExtenderException(e, "Bad request: " + e.getMessage()); | ||
} catch(NotSupportedException e) { | ||
LOGGER.error("Unsupported engine version {}", sdkVersionString); | ||
throw new ExtenderException("Unsupported engine version. Please, update engine to the newer version"); | ||
} catch(Exception e) { | ||
LOGGER.error(String.format("Exception while building or sending response - SDK: %s", sdkVersion)); | ||
throw e; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If instance marked as "BUILDER_ONLY" - skip request for sdk mappings and start building.