use of org.apache.http.entity.FileEntity in project cdap by caskdata.
the class GatewayFastTestsSuite method deploy.
public static HttpResponse deploy(Class<?> application, File tmpFolder) throws Exception {
File artifactJar = buildAppArtifact(application, application.getSimpleName(), tmpFolder);
File expandDir = DirUtils.createTempDir(tmpFolder);
BundleJarUtil.unJar(Locations.toLocation(artifactJar), expandDir);
// Add webapp
File webAppFile = new File(expandDir, "webapp/default/netlens/src/1.txt");
webAppFile.getParentFile().mkdirs();
Files.write("dummy data", webAppFile, Charsets.UTF_8);
BundleJarUtil.createJar(expandDir, artifactJar);
HttpEntityEnclosingRequestBase request;
request = getPost("/v3/namespaces/default/apps");
request.setHeader(Constants.Gateway.API_KEY, "api-key-example");
request.setHeader("X-Archive-Name", String.format("%s-1.0.%d.jar", application.getSimpleName(), System.currentTimeMillis()));
request.setEntity(new FileEntity(artifactJar));
return execute(request);
}
use of org.apache.http.entity.FileEntity in project cdap by caskdata.
the class AppFabricTestBase method deploy.
/**
* Deploys an application with (optionally) a defined app name and app version
*/
protected HttpResponse deploy(Class<?> application, @Nullable String apiVersion, @Nullable String namespace, @Nullable String artifactVersion, @Nullable Config appConfig, @Nullable String ownerPrincipal) throws Exception {
namespace = namespace == null ? Id.Namespace.DEFAULT.getId() : namespace;
apiVersion = apiVersion == null ? Constants.Gateway.API_VERSION_3_TOKEN : apiVersion;
artifactVersion = artifactVersion == null ? String.format("1.0.%d", System.currentTimeMillis()) : artifactVersion;
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(ManifestFields.BUNDLE_VERSION, artifactVersion);
File artifactJar = buildAppArtifact(application, application.getSimpleName(), manifest);
File expandDir = tmpFolder.newFolder();
BundleJarUtil.unJar(Locations.toLocation(artifactJar), expandDir);
// Add webapp
File webAppFile = new File(expandDir, "webapp/default/netlens/src/1.txt");
webAppFile.getParentFile().mkdirs();
Files.write("dummy data", webAppFile, Charsets.UTF_8);
BundleJarUtil.createJar(expandDir, artifactJar);
HttpEntityEnclosingRequestBase request;
String versionedApiPath = getVersionedAPIPath("apps/", apiVersion, namespace);
request = getPost(versionedApiPath);
request.setHeader(Constants.Gateway.API_KEY, "api-key-example");
request.setHeader(AbstractAppFabricHttpHandler.ARCHIVE_NAME_HEADER, String.format("%s-%s.jar", application.getSimpleName(), artifactVersion));
if (appConfig != null) {
request.setHeader(AbstractAppFabricHttpHandler.APP_CONFIG_HEADER, GSON.toJson(appConfig));
}
if (ownerPrincipal != null) {
request.setHeader(AbstractAppFabricHttpHandler.PRINCIPAL_HEADER, ownerPrincipal);
}
request.setEntity(new FileEntity(artifactJar));
return execute(request);
}
Aggregations