Search in sources :

Example 21 with KerberosPrincipalId

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;
}
Also used : Arguments(co.cask.cdap.app.runtime.Arguments) KerberosPrincipalId(co.cask.cdap.proto.id.KerberosPrincipalId) Nullable(javax.annotation.Nullable)

Example 22 with KerberosPrincipalId

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;
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) BodyConsumer(co.cask.http.BodyConsumer) KerberosPrincipalId(co.cask.cdap.proto.id.KerberosPrincipalId) BufferFileInputStream(co.cask.cdap.internal.app.BufferFileInputStream) Location(org.apache.twill.filesystem.Location)

Aggregations

KerberosPrincipalId (co.cask.cdap.proto.id.KerberosPrincipalId)22 IOException (java.io.IOException)8 NamespaceId (co.cask.cdap.proto.id.NamespaceId)7 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)7 ExecutionException (java.util.concurrent.ExecutionException)6 NotFoundException (co.cask.cdap.common.NotFoundException)5 Principal (co.cask.cdap.proto.security.Principal)5 Nullable (javax.annotation.Nullable)5 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)4 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)4 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)3 ArtifactAlreadyExistsException (co.cask.cdap.common.ArtifactAlreadyExistsException)3 ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)3 BadRequestException (co.cask.cdap.common.BadRequestException)3 InvalidArtifactException (co.cask.cdap.common.InvalidArtifactException)3 DatasetId (co.cask.cdap.proto.id.DatasetId)3 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)2 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)2 ConflictException (co.cask.cdap.common.ConflictException)2 AbstractBodyConsumer (co.cask.cdap.common.http.AbstractBodyConsumer)2