Search in sources :

Example 81 with ProgramId

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

the class SystemProgramManagementServiceTest method deployTestApp.

private void deployTestApp() throws Exception {
    Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.SYSTEM, APP_NAME, VERSION);
    Location appJar = AppJarHelper.createDeploymentJar(locationFactory, APP_CLASS);
    File appJarFile = new File(tmpFolder.newFolder(), String.format("%s-%s.jar", artifactId.getName(), artifactId.getVersion().getVersion()));
    Locations.linkOrCopyOverwrite(appJar, appJarFile);
    appJar.delete();
    artifactRepository.addArtifact(artifactId, appJarFile);
    ArtifactSummary summary = new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion(), ArtifactScope.SYSTEM);
    applicationLifecycleService.deployApp(NamespaceId.SYSTEM, APP_NAME, VERSION, summary, null, programId -> {
    // no-op
    }, null, false, false, Collections.emptyMap());
}
Also used : ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ProgramId(io.cdap.cdap.proto.id.ProgramId) Id(io.cdap.cdap.common.id.Id) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) File(java.io.File) Location(org.apache.twill.filesystem.Location)

Example 82 with ProgramId

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

the class AppLifecycleHttpHandlerTest method testDelete.

/**
 * Tests deleting applications with versioned and non-versioned API.
 */
@Test
public void testDelete() throws Exception {
    // Delete an non-existing app
    HttpResponse response = doDelete(getVersionedAPIPath("apps/XYZ", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
    Assert.assertEquals(404, response.getResponseCode());
    // Start a service from the App
    deploy(AllProgramsApp.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1);
    Id.Program program = Id.Program.from(TEST_NAMESPACE1, AllProgramsApp.NAME, ProgramType.SERVICE, AllProgramsApp.NoOpService.NAME);
    startProgram(program);
    waitState(program, "RUNNING");
    // Try to delete an App while its service is running
    response = doDelete(getVersionedAPIPath("apps/" + AllProgramsApp.NAME, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
    Assert.assertEquals(409, response.getResponseCode());
    Assert.assertEquals("'" + program.getApplication() + "' could not be deleted. Reason: The following programs are still running: " + program.getId(), response.getResponseBodyAsString());
    stopProgram(program);
    waitState(program, "STOPPED");
    startProgram(program);
    waitState(program, "RUNNING");
    // Try to delete all Apps while service is running
    response = doDelete(getVersionedAPIPath("apps", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
    Assert.assertEquals(409, response.getResponseCode());
    Assert.assertEquals("'" + program.getNamespace() + "' could not be deleted. Reason: The following programs are still running: " + program.getApplicationId() + ": " + program.getId(), response.getResponseBodyAsString());
    stopProgram(program);
    waitState(program, "STOPPED");
    // Delete the app in the wrong namespace
    response = doDelete(getVersionedAPIPath("apps/" + AllProgramsApp.NAME, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2));
    Assert.assertEquals(404, response.getResponseCode());
    // Delete an non-existing app with version
    response = doDelete(getVersionedAPIPath("apps/XYZ/versions/" + VERSION1, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
    Assert.assertEquals(404, response.getResponseCode());
    // Deploy an app with version
    Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, AllProgramsApp.class.getSimpleName(), VERSION1);
    addAppArtifact(artifactId, AllProgramsApp.class);
    AppRequest<? extends Config> appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()));
    ApplicationId appId = NamespaceId.DEFAULT.app(AllProgramsApp.NAME, VERSION1);
    Assert.assertEquals(200, deploy(appId, appRequest).getResponseCode());
    // Start a service for the App
    ProgramId program1 = appId.program(ProgramType.SERVICE, AllProgramsApp.NoOpService.NAME);
    startProgram(program1, 200);
    waitState(program1, "RUNNING");
    // Try to delete an App while its service is running
    response = doDelete(getVersionedAPIPath(String.format("apps/%s/versions/%s", appId.getApplication(), appId.getVersion()), Constants.Gateway.API_VERSION_3_TOKEN, appId.getNamespace()));
    Assert.assertEquals(409, response.getResponseCode());
    Assert.assertEquals("'" + program1.getParent() + "' could not be deleted. Reason: The following programs" + " are still running: " + program1.getProgram(), response.getResponseBodyAsString());
    stopProgram(program1, null, 200, null);
    waitState(program1, "STOPPED");
    // Delete the app with version in the wrong namespace
    response = doDelete(getVersionedAPIPath(String.format("apps/%s/versions/%s", appId.getApplication(), appId.getVersion()), Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2));
    Assert.assertEquals(404, response.getResponseCode());
    // Delete the app with version after stopping the service
    response = doDelete(getVersionedAPIPath(String.format("apps/%s/versions/%s", appId.getApplication(), appId.getVersion()), Constants.Gateway.API_VERSION_3_TOKEN, appId.getNamespace()));
    Assert.assertEquals(200, response.getResponseCode());
    response = doDelete(getVersionedAPIPath(String.format("apps/%s/versions/%s", appId.getApplication(), appId.getVersion()), Constants.Gateway.API_VERSION_3_TOKEN, appId.getNamespace()));
    Assert.assertEquals(404, response.getResponseCode());
    // Delete the App after stopping the service
    response = doDelete(getVersionedAPIPath("apps/" + AllProgramsApp.NAME, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
    Assert.assertEquals(200, response.getResponseCode());
    response = doDelete(getVersionedAPIPath("apps/" + AllProgramsApp.NAME, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
    Assert.assertEquals(404, response.getResponseCode());
    // deleting the app should not delete the artifact
    response = doGet(getVersionedAPIPath("artifacts/" + artifactId.getName(), Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
    Assert.assertEquals(200, response.getResponseCode());
    List<ArtifactSummary> summaries = readResponse(response, new TypeToken<List<ArtifactSummary>>() {
    }.getType());
    Assert.assertFalse(summaries.isEmpty());
    // cleanup
    deleteNamespace(NamespaceId.DEFAULT.getNamespace());
}
Also used : ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) TypeToken(com.google.gson.reflect.TypeToken) HttpResponse(io.cdap.common.http.HttpResponse) AllProgramsApp(io.cdap.cdap.AllProgramsApp) 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) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) AppRequest(io.cdap.cdap.proto.artifact.AppRequest) Test(org.junit.Test)

Example 83 with ProgramId

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

the class AppFabricTestBase method getScheduledRunTimes.

/**
 * Returns a list of {@link BatchProgramSchedule}.
 *
 * @param namespace the namespace to query in
 * @param programIds list of programs to query for scheuled run time
 * @param next if true, fetch the list of future run times. If false, fetch the list of past run times.
 * @return a list of {@link BatchProgramSchedule}
 */
protected List<BatchProgramSchedule> getScheduledRunTimes(String namespace, Collection<? extends ProgramId> programIds, boolean next) throws Exception {
    Assert.assertTrue(programIds.stream().map(ProgramId::getNamespace).allMatch(namespace::equals));
    String url = String.format("%sruntime", next ? "next" : "previous");
    String versionedUrl = getVersionedAPIPath(url, Constants.Gateway.API_VERSION_3_TOKEN, namespace);
    List<BatchProgram> batchPrograms = programIds.stream().map(id -> new BatchProgram(id.getApplication(), id.getType(), id.getProgram())).collect(Collectors.toList());
    HttpResponse response = doPost(versionedUrl, GSON.toJson(batchPrograms));
    assertResponseCode(200, response);
    return readResponse(response, new TypeToken<List<BatchProgramSchedule>>() {
    }.getType());
}
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) BatchProgramSchedule(io.cdap.cdap.proto.BatchProgramSchedule) TypeToken(com.google.gson.reflect.TypeToken) HttpResponse(io.cdap.common.http.HttpResponse) ProgramId(io.cdap.cdap.proto.id.ProgramId) BatchProgram(io.cdap.cdap.proto.BatchProgram)

Example 84 with ProgramId

use of io.cdap.cdap.proto.id.ProgramId 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)

Example 85 with ProgramId

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

the class ProgramNotificationSubscriberServiceTest method testWorkflowInnerPrograms.

@Test
public void testWorkflowInnerPrograms() throws Exception {
    AppFabricTestHelper.deployApplication(Id.Namespace.DEFAULT, ProgramStateWorkflowApp.class, null, cConf);
    ProgramRunId workflowRunId = NamespaceId.DEFAULT.app(ProgramStateWorkflowApp.class.getSimpleName()).workflow(ProgramStateWorkflowApp.ProgramStateWorkflow.class.getSimpleName()).run(RunIds.generate());
    ApplicationSpecification appSpec = TransactionRunners.run(transactionRunner, context -> {
        return AppMetadataStore.create(context).getApplication(workflowRunId.getParent().getParent()).getSpec();
    });
    ProgramDescriptor programDescriptor = new ProgramDescriptor(workflowRunId.getParent(), appSpec);
    // Start and run the workflow
    Map<String, String> systemArgs = new HashMap<>();
    systemArgs.put(ProgramOptionConstants.SKIP_PROVISIONING, Boolean.TRUE.toString());
    systemArgs.put(SystemArguments.PROFILE_NAME, ProfileId.NATIVE.getScopedName());
    programStateWriter.start(workflowRunId, new SimpleProgramOptions(workflowRunId.getParent(), new BasicArguments(systemArgs), new BasicArguments()), null, programDescriptor);
    programStateWriter.running(workflowRunId, null);
    ProgramRunId mrRunId = workflowRunId.getParent().getParent().mr(ProgramStateWorkflowApp.ProgramStateMR.class.getSimpleName()).run(RunIds.generate());
    ProgramRunId sparkRunId = workflowRunId.getParent().getParent().spark(ProgramStateWorkflowApp.ProgramStateSpark.class.getSimpleName()).run(RunIds.generate());
    ProgramId sparkId2 = workflowRunId.getParent().getParent().spark(ProgramStateWorkflowApp.ProgramStateSpark2.class.getSimpleName());
    // Start and run the MR and Spark inside
    for (ProgramRunId programRunId : Arrays.asList(mrRunId, sparkRunId)) {
        workflowStateWriter.addWorkflowNodeState(workflowRunId, new WorkflowNodeStateDetail(programRunId.getProgram(), NodeStatus.STARTING));
        workflowStateWriter.addWorkflowNodeState(workflowRunId, new WorkflowNodeStateDetail(programRunId.getProgram(), NodeStatus.RUNNING));
        systemArgs = new HashMap<>(systemArgs);
        systemArgs.put(ProgramOptionConstants.RUN_ID, programRunId.getRun());
        systemArgs.put(ProgramOptionConstants.WORKFLOW_NAME, workflowRunId.getProgram());
        systemArgs.put(ProgramOptionConstants.WORKFLOW_RUN_ID, workflowRunId.getRun());
        systemArgs.put(ProgramOptionConstants.WORKFLOW_NODE_ID, programRunId.getProgram());
        systemArgs.put(ProgramOptionConstants.PROGRAM_NAME_IN_WORKFLOW, programRunId.getProgram());
        programStateWriter.start(programRunId, new SimpleProgramOptions(programRunId.getParent(), new BasicArguments(systemArgs), new BasicArguments()), null, programDescriptor);
        programStateWriter.running(programRunId, null);
        // Wait for the inner program running
        Tasks.waitFor(ProgramRunStatus.RUNNING, () -> TransactionRunners.run(transactionRunner, context -> {
            AppMetadataStore metadataStoreDataset = AppMetadataStore.create(context);
            RunRecordDetail meta = metadataStoreDataset.getRun(programRunId);
            if (meta == null) {
                return null;
            }
            return meta.getStatus();
        }), 10, TimeUnit.SECONDS);
    }
    // Stop the Spark normally
    programStateWriter.completed(sparkRunId);
    // Error out the Workflow without stopping the MR
    programStateWriter.error(workflowRunId, new IllegalStateException("Explicitly error out"));
    // Wait for the Workflow state changed to failed
    Tasks.waitFor(ProgramRunStatus.FAILED, () -> TransactionRunners.run(transactionRunner, context -> {
        AppMetadataStore metadataStoreDataset = AppMetadataStore.create(context);
        RunRecordDetail meta = metadataStoreDataset.getRun(workflowRunId);
        if (meta == null) {
            return null;
        }
        return meta.getStatus();
    }), 10000, TimeUnit.SECONDS);
    // The MR run record should be changed to ERROR state as well (without race)
    TransactionRunners.run(transactionRunner, context -> {
        AppMetadataStore metadataStoreDataset = AppMetadataStore.create(context);
        RunRecordDetail meta = metadataStoreDataset.getRun(mrRunId);
        Assert.assertNotNull(meta);
        Assert.assertEquals(ProgramRunStatus.FAILED, meta.getStatus());
    });
    // The Spark run record should stay as COMPLETED
    TransactionRunners.run(transactionRunner, context -> {
        AppMetadataStore metadataStoreDataset = AppMetadataStore.create(context);
        RunRecordDetail meta = metadataStoreDataset.getRun(sparkRunId);
        Assert.assertNotNull(meta);
        Assert.assertEquals(ProgramRunStatus.COMPLETED, meta.getStatus());
    });
    // Since the Spark2 program hasn't been executed, there should be no run record
    TransactionRunners.run(transactionRunner, context -> {
        AppMetadataStore metadataStoreDataset = AppMetadataStore.create(context);
        Map<ProgramRunId, RunRecordDetail> runs = metadataStoreDataset.getRuns(sparkId2, ProgramRunStatus.ALL, 0, Long.MAX_VALUE, 100, null);
        Assert.assertTrue(runs.isEmpty());
    });
}
Also used : RunRecordDetail(io.cdap.cdap.internal.app.store.RunRecordDetail) Arrays(java.util.Arrays) TransactionRunners(io.cdap.cdap.spi.data.transaction.TransactionRunners) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) TimeoutException(java.util.concurrent.TimeoutException) NodeStatus(io.cdap.cdap.api.workflow.NodeStatus) ProgramStateWriter(io.cdap.cdap.app.runtime.ProgramStateWriter) AppFabricTestHelper(io.cdap.cdap.internal.AppFabricTestHelper) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) After(org.junit.After) Map(java.util.Map) RunId(org.apache.twill.api.RunId) Tasks(io.cdap.cdap.common.utils.Tasks) AfterClass(org.junit.AfterClass) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ProgramRunStatus(io.cdap.cdap.proto.ProgramRunStatus) Id(io.cdap.cdap.common.id.Id) List(java.util.List) AggregationFunction(io.cdap.cdap.api.dataset.lib.cube.AggregationFunction) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) Constants(io.cdap.cdap.common.conf.Constants) ProfileId(io.cdap.cdap.proto.id.ProfileId) ProgramOptionConstants(io.cdap.cdap.internal.app.runtime.ProgramOptionConstants) BeforeClass(org.junit.BeforeClass) MetricStore(io.cdap.cdap.api.metrics.MetricStore) HashMap(java.util.HashMap) ProgramType(io.cdap.cdap.proto.ProgramType) ArrayList(java.util.ArrayList) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) ProgramHeartbeatTable(io.cdap.cdap.reporting.ProgramHeartbeatTable) ProgramOptions(io.cdap.cdap.app.runtime.ProgramOptions) Profile(io.cdap.cdap.proto.profile.Profile) MetricDataQuery(io.cdap.cdap.api.metrics.MetricDataQuery) SystemArguments(io.cdap.cdap.internal.app.runtime.SystemArguments) WorkflowNodeStateDetail(io.cdap.cdap.proto.WorkflowNodeStateDetail) AppMetadataStore(io.cdap.cdap.internal.app.store.AppMetadataStore) DefaultApplicationSpecification(io.cdap.cdap.internal.app.DefaultApplicationSpecification) WorkflowStateWriter(io.cdap.cdap.internal.app.runtime.workflow.WorkflowStateWriter) ProfileService(io.cdap.cdap.internal.profile.ProfileService) RunIds(io.cdap.cdap.common.app.RunIds) ProgramId(io.cdap.cdap.proto.id.ProgramId) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) Test(org.junit.Test) MetricTimeSeries(io.cdap.cdap.api.metrics.MetricTimeSeries) ProjectInfo(io.cdap.cdap.common.utils.ProjectInfo) ProgramRunClusterStatus(io.cdap.cdap.proto.ProgramRunClusterStatus) Injector(com.google.inject.Injector) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) TimeValue(io.cdap.cdap.api.dataset.lib.cube.TimeValue) Assert(org.junit.Assert) Collections(java.util.Collections) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) DefaultApplicationSpecification(io.cdap.cdap.internal.app.DefaultApplicationSpecification) AppMetadataStore(io.cdap.cdap.internal.app.store.AppMetadataStore) HashMap(java.util.HashMap) RunRecordDetail(io.cdap.cdap.internal.app.store.RunRecordDetail) ProgramId(io.cdap.cdap.proto.id.ProgramId) WorkflowNodeStateDetail(io.cdap.cdap.proto.WorkflowNodeStateDetail) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) Test(org.junit.Test)

Aggregations

ProgramId (io.cdap.cdap.proto.id.ProgramId)562 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)277 Test (org.junit.Test)268 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)164 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)130 RunId (org.apache.twill.api.RunId)118 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)110 ProgramType (io.cdap.cdap.proto.ProgramType)108 HashMap (java.util.HashMap)88 HashSet (java.util.HashSet)78 ArrayList (java.util.ArrayList)76 Id (io.cdap.cdap.common.id.Id)74 IOException (java.io.IOException)74 File (java.io.File)70 RunRecord (io.cdap.cdap.proto.RunRecord)68 Path (javax.ws.rs.Path)68 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)66 NotFoundException (io.cdap.cdap.common.NotFoundException)66 Map (java.util.Map)64 Set (java.util.Set)62