use of com.ibm.streamsx.rest.ApplicationBundle in project streamsx.topology by IBMStreams.
the class AppBundleTest method testAppBundles.
@Test
public void testAppBundles() throws Exception {
String namespace = "App.NS_" + (int) (Math.random() * 10000.0);
String name = "AppBundleTest" + System.currentTimeMillis();
final String appName = namespace + "::" + name;
File bundle = createBundle(namespace, name);
Instance instance = getInstance();
Result<Job, JsonObject> result = instance.submitJob(bundle, null);
verifyJob(result, appName, null);
String jobName = "ABJN_" + (int) (Math.random() * 10000.0) + "_" + System.currentTimeMillis();
JobConfig jc = new JobConfig();
jc.setJobName(jobName);
JsonObject overlay = new JsonObject();
overlay.add("jobConfig", new Gson().toJsonTree(jc));
JsonArray a = new JsonArray();
a.add(overlay);
JsonObject jco = new JsonObject();
jco.add("jobConfigOverlays", a);
result = instance.submitJob(bundle, jco);
verifyJob(result, appName, jobName);
final ApplicationBundle appBundle = instance.uploadBundle(bundle);
assertNotNull(appBundle);
verifyJob(appBundle.submitJob(null), appName, null);
jobName = "ABJN2_" + (int) (Math.random() * 10000.0) + "_" + System.currentTimeMillis();
jc.setJobName(jobName);
overlay.add("jobConfig", new Gson().toJsonTree(jc));
verifyJob(appBundle.submitJob(jco), appName, jobName);
}
use of com.ibm.streamsx.rest.ApplicationBundle in project streamsx.topology by IBMStreams.
the class DistributedStreamsRestContext method postBuildAction.
@Override
protected void postBuildAction(JsonObject deploy, JsonObject jco, JsonObject result) throws Exception {
if (instance == null) {
URL instanceUrl = new URL(StreamsKeys.getStreamsInstanceURL(deploy));
String path = instanceUrl.getPath();
URL restUrl;
if (path.startsWith("/streams/rest/instances/")) {
restUrl = new URL(instanceUrl.getProtocol(), instanceUrl.getHost(), instanceUrl.getPort(), "/streams/rest/resources");
} else {
restUrl = new URL(instanceUrl.getProtocol(), instanceUrl.getHost(), instanceUrl.getPort(), path.replaceFirst("/streams-rest/", "/streams-resource/"));
}
JsonObject serviceDefinition = object(deploy, StreamsKeys.SERVICE_DEFINITION);
String name = jstring(serviceDefinition, "service_name");
final boolean verify = sslVerify(deploy);
Function<Executor, String> authenticator = (name == null || name.isEmpty()) ? StandaloneAuthenticator.of(serviceDefinition) : ICP4DAuthenticator.of(serviceDefinition, verify);
StreamsConnection conn = StreamsConnection.ofAuthenticator(restUrl.toExternalForm(), authenticator);
if (!verify)
conn.allowInsecureHosts(true);
// Create the instance directly from the URL
instance = conn.getInstance(instanceUrl.toExternalForm());
}
JsonArray artifacts = GsonUtilities.array(GsonUtilities.object(result, "build"), "artifacts");
try {
if (artifacts == null || artifacts.size() == 0)
throw new IllegalStateException("No build artifacts produced.");
if (artifacts.size() != 1)
throw new IllegalStateException("Multiple build artifacts produced.");
String location = GsonUtilities.jstring(artifacts.get(0).getAsJsonObject(), "location");
report("Uploading bundle");
ApplicationBundle bundle = instance.uploadBundle(new File(location));
report("Submitting job");
Result<Job, JsonObject> submissionResult = bundle.submitJob(jco);
for (Entry<String, JsonElement> entry : submissionResult.getRawResult().entrySet()) {
result.add(entry.getKey(), entry.getValue());
}
report("Job id:" + submissionResult.getId());
} finally {
if (!jboolean(deploy, KEEP_ARTIFACTS)) {
for (JsonElement e : artifacts) {
JsonObject artifact = e.getAsJsonObject();
if (artifact.has("location")) {
new File(GsonUtilities.jstring(artifact, "location")).delete();
}
}
if (result.has(SubmissionResultsKeys.BUNDLE_PATH))
result.remove(SubmissionResultsKeys.BUNDLE_PATH);
}
}
}
Aggregations