use of co.cask.cdap.proto.id.KerberosPrincipalId in project cdap by caskdata.
the class ProgramRunners method getApplicationPrincipal.
/**
* Returns the application principal if there is one.
*
* @param programOptions the program options to extract information from
* @return the application principal or {@code null} if no application principal is available.
*/
@Nullable
public static KerberosPrincipalId getApplicationPrincipal(ProgramOptions programOptions) {
Arguments systemArgs = programOptions.getArguments();
boolean hasAppPrincipal = Boolean.parseBoolean(systemArgs.getOption(ProgramOptionConstants.APP_PRINCIPAL_EXISTS));
return hasAppPrincipal ? new KerberosPrincipalId(systemArgs.getOption(ProgramOptionConstants.PRINCIPAL)) : null;
}
use of co.cask.cdap.proto.id.KerberosPrincipalId in project cdap by caskdata.
the class AppFabricClient method deployApplication.
public Location deployApplication(Id.Namespace namespace, Class<?> applicationClz, String config, @Nullable KerberosPrincipalId ownerPrincipal, File... bundleEmbeddedJars) throws Exception {
Preconditions.checkNotNull(applicationClz, "Application cannot be null.");
Location deployedJar = AppJarHelper.createDeploymentJar(locationFactory, applicationClz, bundleEmbeddedJars);
LOG.info("Created deployedJar at {}", deployedJar);
String archiveName = String.format("%s-1.0.%d.jar", applicationClz.getSimpleName(), System.currentTimeMillis());
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, String.format("/v3/namespaces/%s/apps", namespace.getId()));
request.headers().set(Constants.Gateway.API_KEY, "api-key-example");
request.headers().set(AbstractAppFabricHttpHandler.ARCHIVE_NAME_HEADER, archiveName);
if (config != null) {
request.headers().set(AbstractAppFabricHttpHandler.APP_CONFIG_HEADER, config);
}
String owner = null;
if (ownerPrincipal != null) {
owner = GSON.toJson(ownerPrincipal, KerberosPrincipalId.class);
request.headers().set(AbstractAppFabricHttpHandler.PRINCIPAL_HEADER, owner);
}
MockResponder mockResponder = new MockResponder();
BodyConsumer bodyConsumer = appLifecycleHttpHandler.deploy(request, mockResponder, namespace.getId(), archiveName, config, owner, true);
Preconditions.checkNotNull(bodyConsumer, "BodyConsumer from deploy call should not be null");
try (BufferFileInputStream is = new BufferFileInputStream(deployedJar.getInputStream(), 100 * 1024)) {
byte[] chunk = is.read();
while (chunk.length > 0) {
mockResponder = new MockResponder();
bodyConsumer.chunk(Unpooled.wrappedBuffer(chunk), mockResponder);
Preconditions.checkState(mockResponder.getStatus() == null, "failed to deploy app");
chunk = is.read();
}
mockResponder = new MockResponder();
bodyConsumer.finished(mockResponder);
verifyResponse(HttpResponseStatus.OK, mockResponder.getStatus(), "Failed to deploy app");
}
return deployedJar;
}
Aggregations