Search in sources :

Example 61 with NamespaceId

use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class DraftHandler method putDraft.

/**
 * Creates or updates a draft
 */
@PUT
@Path(API_VERSION + "/contexts/{context}/drafts/{draft}/")
public void putDraft(HttpServiceRequest request, HttpServiceResponder responder, @PathParam("context") String namespaceName, @PathParam("draft") String draftId) {
    contextAccessEnforcer.enforce(new NamespaceId(namespaceName), StandardPermission.UPDATE);
    respond(namespaceName, responder, (namespace) -> {
        String requestStr = StandardCharsets.UTF_8.decode(request.getContent()).toString();
        DraftStoreRequest<ETLConfig> draftStoreRequest = deserializeDraftStoreRequest(requestStr);
        String userId = request.getUserId();
        userId = userId == null ? "" : userId;
        DraftId id = new DraftId(namespace, draftId, userId);
        draftService.writeDraft(id, draftStoreRequest);
        responder.sendStatus(HttpURLConnection.HTTP_OK);
    });
}
Also used : NamespaceId(io.cdap.cdap.proto.id.NamespaceId) DraftId(io.cdap.cdap.datapipeline.draft.DraftId) ETLConfig(io.cdap.cdap.etl.proto.v2.ETLConfig) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 62 with NamespaceId

use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class DraftHandler method deleteDraft.

/**
 * Deletes a draft
 */
@DELETE
@Path(API_VERSION + "/contexts/{context}/drafts/{draft}/")
public void deleteDraft(HttpServiceRequest request, HttpServiceResponder responder, @PathParam("context") String namespaceName, @PathParam("draft") String draftId) {
    contextAccessEnforcer.enforce(new NamespaceId(namespaceName), StandardPermission.UPDATE);
    respond(namespaceName, responder, (namespace) -> {
        String userId = request.getUserId();
        userId = userId == null ? "" : userId;
        DraftId id = new DraftId(namespace, draftId, userId);
        draftService.deleteDraft(id);
        responder.sendStatus(HttpURLConnection.HTTP_OK);
    });
}
Also used : NamespaceId(io.cdap.cdap.proto.id.NamespaceId) DraftId(io.cdap.cdap.datapipeline.draft.DraftId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 63 with NamespaceId

use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class AppLifecycleHttpHandlerTest method testDeployNonExistingNamespace.

/**
 * Tests deploying an application in a non-existing non-default namespace.
 */
@Test
public void testDeployNonExistingNamespace() throws Exception {
    HttpResponse response = deploy(AllProgramsApp.class, 404, Constants.Gateway.API_VERSION_3_TOKEN, "random");
    NotFoundException nfe = new NamespaceNotFoundException(new NamespaceId("random"));
    Assert.assertEquals(nfe.getMessage(), response.getResponseBodyAsString());
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) NotFoundException(io.cdap.cdap.common.NotFoundException) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) Test(org.junit.Test)

Example 64 with NamespaceId

use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class AppLifecycleHttpHandlerTest method testDeployAppWithDisabledProfileInSchedule.

@Test
public void testDeployAppWithDisabledProfileInSchedule() throws Exception {
    // put my profile and disable it
    ProfileId profileId = new NamespaceId(TEST_NAMESPACE1).profile("MyProfile");
    Profile profile = new Profile("MyProfile", Profile.NATIVE.getLabel(), Profile.NATIVE.getDescription(), Profile.NATIVE.getScope(), Profile.NATIVE.getProvisioner());
    putProfile(profileId, profile, 200);
    disableProfile(profileId, 200);
    // deploy an app with schedule with some disabled profile in the schedule property
    AppWithSchedule.AppConfig config = new AppWithSchedule.AppConfig(true, true, true, ImmutableMap.of(SystemArguments.PROFILE_NAME, "USER:MyProfile"));
    Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.fromEntityId(TEST_NAMESPACE_META1.getNamespaceId()), AppWithSchedule.NAME, VERSION1);
    addAppArtifact(artifactId, AppWithSchedule.class);
    AppRequest<? extends Config> request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), config, null, null, true);
    // deploy should fail with a 409
    ApplicationId defaultAppId = TEST_NAMESPACE_META1.getNamespaceId().app(AppWithSchedule.NAME);
    Assert.assertEquals(409, deploy(defaultAppId, request).getResponseCode());
    // enable
    enableProfile(profileId, 200);
    Assert.assertEquals(200, deploy(defaultAppId, request).getResponseCode());
    // disable again so that we can delete it at namespace deletion
    disableProfile(profileId, 200);
    // clean up
    deleteApp(defaultAppId, 200);
    deleteArtifact(artifactId, 200);
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Id(io.cdap.cdap.common.id.Id) ProfileId(io.cdap.cdap.proto.id.ProfileId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ProgramId(io.cdap.cdap.proto.id.ProgramId) AppWithSchedule(io.cdap.cdap.AppWithSchedule) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Profile(io.cdap.cdap.proto.profile.Profile) AppRequest(io.cdap.cdap.proto.artifact.AppRequest) Test(org.junit.Test)

Example 65 with NamespaceId

use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class AppFabricTestBase method getProgramRuns.

protected List<BatchProgramHistory> getProgramRuns(NamespaceId namespace, List<ProgramId> programs) throws Exception {
    List<BatchProgram> request = programs.stream().map(program -> new BatchProgram(program.getApplication(), program.getType(), program.getProgram())).collect(Collectors.toList());
    HttpResponse response = doPost(getVersionedAPIPath("runs", namespace.getNamespace()), GSON.toJson(request));
    assertResponseCode(200, response);
    return GSON.fromJson(response.getResponseBodyAsString(), BATCH_PROGRAM_RUNS_TYPE);
}
Also used : BatchProgramSchedule(io.cdap.cdap.proto.BatchProgramSchedule) Manifest(java.util.jar.Manifest) Arrays(java.util.Arrays) TypeToken(com.google.gson.reflect.TypeToken) ImmutablePair(io.cdap.cdap.common.utils.ImmutablePair) UGIProvider(io.cdap.cdap.security.impersonation.UGIProvider) GsonBuilder(com.google.gson.GsonBuilder) ScheduledRuntime(io.cdap.cdap.proto.ScheduledRuntime) DefaultMetadataServiceClient(io.cdap.cdap.data2.metadata.writer.DefaultMetadataServiceClient) InetAddress(java.net.InetAddress) ProgramScheduleStatus(io.cdap.cdap.internal.app.runtime.schedule.ProgramScheduleStatus) MediaType(javax.ws.rs.core.MediaType) Map(java.util.Map) Closeables(com.google.common.io.Closeables) ClassRule(org.junit.ClassRule) ScheduleDetail(io.cdap.cdap.proto.ScheduleDetail) AfterClass(org.junit.AfterClass) MetadataSubscriberService(io.cdap.cdap.metadata.MetadataSubscriberService) StoreDefinition(io.cdap.cdap.store.StoreDefinition) AppFabricTestModule(io.cdap.cdap.internal.guice.AppFabricTestModule) Set(java.util.Set) Constraint(io.cdap.cdap.internal.schedule.constraint.Constraint) ProgramRunStatus(io.cdap.cdap.proto.ProgramRunStatus) Id(io.cdap.cdap.common.id.Id) ApplicationSpecificationAdapter(io.cdap.cdap.internal.app.ApplicationSpecificationAdapter) AppFabricServer(io.cdap.cdap.internal.app.services.AppFabricServer) MetadataScope(io.cdap.cdap.api.metadata.MetadataScope) TriggerCodec(io.cdap.cdap.internal.app.runtime.schedule.trigger.TriggerCodec) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Joiner(com.google.common.base.Joiner) RunRecord(io.cdap.cdap.proto.RunRecord) Location(org.apache.twill.filesystem.Location) SatisfiableTrigger(io.cdap.cdap.internal.app.runtime.schedule.trigger.SatisfiableTrigger) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) Strings(com.google.common.base.Strings) ProfileStatus(io.cdap.cdap.runtime.spi.profile.ProfileStatus) Discoverable(org.apache.twill.discovery.Discoverable) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) Locations(io.cdap.cdap.common.io.Locations) DatasetOpExecutorService(io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService) MetricDataQuery(io.cdap.cdap.api.metrics.MetricDataQuery) CurrentUGIProvider(io.cdap.cdap.security.impersonation.CurrentUGIProvider) Nullable(javax.annotation.Nullable) PreferencesDetail(io.cdap.cdap.proto.PreferencesDetail) TransactionManager(org.apache.tephra.TransactionManager) DatasetMeta(io.cdap.cdap.proto.DatasetMeta) URIScheme(io.cdap.cdap.common.discovery.URIScheme) IOException(java.io.IOException) LocationFactory(org.apache.twill.filesystem.LocationFactory) File(java.io.File) Service(com.google.common.util.concurrent.Service) MetadataClient(io.cdap.cdap.client.MetadataClient) Schedulers(io.cdap.cdap.internal.app.runtime.schedule.store.Schedulers) Guice(com.google.inject.Guice) Preconditions(com.google.common.base.Preconditions) TimeValue(io.cdap.cdap.api.dataset.lib.cube.TimeValue) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) Assert(org.junit.Assert) InputSupplier(com.google.common.io.InputSupplier) MetadataService(io.cdap.cdap.metadata.MetadataService) AbstractModule(com.google.inject.AbstractModule) HttpRequest(io.cdap.common.http.HttpRequest) JsonObject(com.google.gson.JsonObject) Module(com.google.inject.Module) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) HttpResponse(io.cdap.common.http.HttpResponse) EndpointStrategy(io.cdap.cdap.common.discovery.EndpointStrategy) AppJarHelper(io.cdap.cdap.common.test.AppJarHelper) ProtoConstraintCodec(io.cdap.cdap.proto.ProtoConstraintCodec) DatasetId(io.cdap.cdap.proto.id.DatasetId) Gson(com.google.gson.Gson) ProgramStatus(io.cdap.cdap.api.ProgramStatus) ServiceStore(io.cdap.cdap.app.store.ServiceStore) MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) MetadataMutation(io.cdap.cdap.spi.metadata.MetadataMutation) URI(java.net.URI) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) Tasks(io.cdap.cdap.common.utils.Tasks) BatchApplicationDetail(io.cdap.cdap.proto.BatchApplicationDetail) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) MessagingService(io.cdap.cdap.messaging.MessagingService) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Collectors(java.util.stream.Collectors) HttpRequestConfig(io.cdap.common.http.HttpRequestConfig) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) List(java.util.List) AggregationFunction(io.cdap.cdap.api.dataset.lib.cube.AggregationFunction) SecurityRequestContext(io.cdap.cdap.security.spi.authentication.SecurityRequestContext) Type(java.lang.reflect.Type) ClientConfig(io.cdap.cdap.client.config.ClientConfig) CaseInsensitiveEnumTypeAdapterFactory(io.cdap.cdap.common.io.CaseInsensitiveEnumTypeAdapterFactory) DatasetService(io.cdap.cdap.data2.datafabric.dataset.service.DatasetService) Optional(java.util.Optional) Constants(io.cdap.cdap.common.conf.Constants) ProfileId(io.cdap.cdap.proto.id.ProfileId) StructuredTableAdmin(io.cdap.cdap.spi.data.StructuredTableAdmin) NotFoundException(io.cdap.cdap.common.NotFoundException) RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) Retries(io.cdap.cdap.common.service.Retries) PluginJarHelper(io.cdap.cdap.common.test.PluginJarHelper) BeforeClass(org.junit.BeforeClass) BatchProgramHistory(io.cdap.cdap.proto.BatchProgramHistory) ArtifactRange(io.cdap.cdap.api.artifact.ArtifactRange) ManifestFields(io.cdap.cdap.app.program.ManifestFields) Modules(com.google.inject.util.Modules) MetricStore(io.cdap.cdap.api.metrics.MetricStore) HashMap(java.util.HashMap) EntityId(io.cdap.cdap.proto.id.EntityId) MetadataStorage(io.cdap.cdap.spi.metadata.MetadataStorage) DatasetClient(io.cdap.cdap.client.DatasetClient) Trigger(io.cdap.cdap.api.schedule.Trigger) LogQueryService(io.cdap.cdap.logging.service.LogQueryService) BatchProgram(io.cdap.cdap.proto.BatchProgram) ConnectionConfig(io.cdap.cdap.client.config.ConnectionConfig) Profile(io.cdap.cdap.proto.profile.Profile) HttpRequests(io.cdap.common.http.HttpRequests) AbstractAppFabricHttpHandler(io.cdap.cdap.gateway.handlers.util.AbstractAppFabricHttpHandler) ProtoTrigger(io.cdap.cdap.proto.ProtoTrigger) TransactionSystemClient(org.apache.tephra.TransactionSystemClient) Scheduler(io.cdap.cdap.scheduler.Scheduler) ProgramId(io.cdap.cdap.proto.id.ProgramId) TxConstants(org.apache.tephra.TxConstants) Config(io.cdap.cdap.api.Config) MetricTimeSeries(io.cdap.cdap.api.metrics.MetricTimeSeries) Scopes(com.google.inject.Scopes) CoreSchedulerService(io.cdap.cdap.scheduler.CoreSchedulerService) UnauthenticatedException(io.cdap.cdap.security.spi.authentication.UnauthenticatedException) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) Injector(com.google.inject.Injector) DefaultInternalAuthenticator(io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator) TimeUnit(java.util.concurrent.TimeUnit) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) EntityScope(io.cdap.cdap.proto.EntityScope) AppRequest(io.cdap.cdap.proto.artifact.AppRequest) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) InputStream(java.io.InputStream) HttpResponse(io.cdap.common.http.HttpResponse) BatchProgram(io.cdap.cdap.proto.BatchProgram)

Aggregations

NamespaceId (io.cdap.cdap.proto.id.NamespaceId)648 Test (org.junit.Test)292 Path (javax.ws.rs.Path)136 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)124 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)108 IOException (java.io.IOException)102 ProgramId (io.cdap.cdap.proto.id.ProgramId)86 GET (javax.ws.rs.GET)74 DatasetId (io.cdap.cdap.proto.id.DatasetId)68 ArrayList (java.util.ArrayList)64 BadRequestException (io.cdap.cdap.common.BadRequestException)60 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)58 Principal (io.cdap.cdap.proto.security.Principal)56 Set (java.util.Set)52 Id (io.cdap.cdap.common.id.Id)50 File (java.io.File)50 HashSet (java.util.HashSet)50 NotFoundException (io.cdap.cdap.common.NotFoundException)48 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)46 HashMap (java.util.HashMap)46