-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…oogle-cloud-compute Execute BEAM on Google Cloud
- Loading branch information
Showing
11 changed files
with
776 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import com.google.api.client.http.GenericUrl; | ||
import com.google.api.client.http.HttpRequest; | ||
import com.google.api.client.http.HttpResponse; | ||
import com.google.api.client.http.HttpTransport; | ||
import com.google.api.client.http.HttpContent; | ||
import com.google.api.client.http.ByteArrayContent; | ||
import com.google.api.client.http.javanet.NetHttpTransport; | ||
import com.google.auth.http.HttpCredentialsAdapter; | ||
import com.google.auth.oauth2.GoogleCredentials; | ||
import com.google.auth.oauth2.IdTokenCredentials; | ||
import com.google.auth.oauth2.IdTokenProvider; | ||
|
||
apply from: "$rootDir/aws/build.gradle" | ||
|
||
group = 'beam' | ||
version = '0.8.0' | ||
|
||
buildscript { | ||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
maven { url "https://plugins.gradle.org/m2/" } | ||
gradlePluginPortal() | ||
} | ||
dependencies { | ||
classpath "com.google.auth:google-auth-library-oauth2-http:1.3.0" | ||
} | ||
} | ||
|
||
tasks.register('deployToGCE') { | ||
doLast { | ||
def propsFileName = "../gradle.deploy.properties" | ||
if (project.hasProperty('propsFile')) { | ||
propsFileName = project.findProperty('propsFile') | ||
} | ||
|
||
def propsFile = new Properties() | ||
propsFile.load(project.file(propsFileName).newDataInputStream()) | ||
|
||
ext.getParameterValue = { paramName -> | ||
if (project.hasProperty(paramName)) { | ||
return project.findProperty(paramName) | ||
} else { | ||
return propsFile.getProperty(paramName) | ||
} | ||
} | ||
|
||
if (!ext.getParameterValue('runName')) { | ||
throw new GradleException('Please name the run by specifying `runName` argument. e.g; ./gradlew deploy -PrunName=sfbay-performance-run') | ||
} | ||
def tempInstanceType = "${ext.getParameterValue('instanceType') ?: (project.hasProperty('defaultInstanceType') ? defaultInstanceType : '')}" | ||
def finalInstanceType = tempInstanceType.isEmpty() ? null : tempInstanceType | ||
GString pload = """{ | ||
"run_name": "${ext.getParameterValue('runName') + '_' + getCurrentGitUserEmail()}", | ||
"instance_type": "${finalInstanceType}", | ||
"forced_max_ram": "${ext.getParameterValue('forcedMaxRAM')}", | ||
"beam_branch": "${ext.getParameterValue('beamBranch') ?: getCurrentGitBranch()}", | ||
"beam_commit": "${ext.getParameterValue('beamCommit') ?: 'HEAD'}", | ||
"data_branch": "${ext.getParameterValue('dataBranch') ?: 'develop'}", | ||
"data_commit": "${ext.getParameterValue('dataCommit') ?: 'HEAD'}", | ||
"shutdown_wait": "${ext.getParameterValue('shutdownWait')}", | ||
"storage_size": "${ext.getParameterValue('storageSize')}", | ||
"shutdown_behaviour": "${ext.getParameterValue('shutdownBehaviour')}", | ||
"storage_publish": ${"false".equalsIgnoreCase(ext.getParameterValue('s3Backup')) ? "false" : "true"}, | ||
"config": "${ext.getParameterValue('beamConfigs')}" | ||
}""" | ||
logger.warn(pload) | ||
HttpResponse result = makeJsonPostRequest("https://us-central1-beam-core.cloudfunctions.net/deploy_beam", pload) | ||
logger.warn("response status: ${result.statusCode}, response message: ${result.statusMessage}, payload: ${result.content}") | ||
} | ||
} | ||
|
||
static HttpResponse makeJsonPostRequest(String functionUrl, String requestBody) { | ||
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault(); | ||
IdTokenCredentials tokenCredential = | ||
IdTokenCredentials.newBuilder() | ||
.setIdTokenProvider((IdTokenProvider) credentials) | ||
.setTargetAudience(functionUrl) | ||
.build(); | ||
|
||
GenericUrl genericUrl = new GenericUrl(functionUrl); | ||
HttpCredentialsAdapter adapter = new HttpCredentialsAdapter(tokenCredential); | ||
HttpTransport transport = new NetHttpTransport(); | ||
|
||
HttpContent requestContent = ByteArrayContent.fromString("application/json", requestBody) | ||
HttpRequest request = transport.createRequestFactory(adapter).buildPostRequest(genericUrl, requestContent); | ||
return request.execute(); | ||
} |
Oops, something went wrong.