Search in sources :

Example 1 with BatchProgramHistory

use of io.cdap.cdap.proto.BatchProgramHistory 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 2 with BatchProgramHistory

use of io.cdap.cdap.proto.BatchProgramHistory in project cdap by caskdata.

the class ProgramLifecycleHttpHandler method getLatestRuns.

/**
 * Returns the latest runs for all program runnables that are passed into the data. The data is an array of
 * Json objects where each object must contain the following three elements: appId, programType, and programId.
 * <p>
 * Example input:
 * <pre><code>
 * [{"appId": "App1", "programType": "Service", "programId": "Service1"},
 *  {"appId": "App1", "programType": "Workflow", "programId": "testWorkflow"},
 *  {"appId": "App2", "programType": "Workflow", "programId": "DataPipelineWorkflow"}]
 * </code></pre>
 * </p><p>
 * </p><p>
 * The response will be an array of JsonObjects each of which will contain the three input parameters
 * as well as 2 fields, "runs" which is a list of the latest run records and "statusCode" which maps to the
 * status code for the data in that JsonObjects.
 * </p><p>
 * If an error occurs in the input (for the example above, workflow in app1 does not exist),
 * then all JsonObjects for which the parameters have a valid status will have the count field but all JsonObjects
 * for which the parameters do not have a valid status will have an error message and statusCode.
 * </p><p>
 * For example, if there is no workflow in App1 in the data above, then the response would be 200 OK with following
 * possible data:
 * </p>
 * <pre><code>
 * [{"appId": "App1", "programType": "Service", "programId": "Service1",
 * "statusCode": 200, "runs": [...]},
 * {"appId": "App1", "programType": "Workflow", "programId": "testWorkflow", "statusCode": 404,
 * "error": "Program 'testWorkflow' is not found"},
 *  {"appId": "App2", "programType": "Workflow", "programId": "DataPipelineWorkflow", "runnableId": "Flowlet1",
 *  "statusCode": 200, "runs": [...]}]
 * </code></pre>
 */
@POST
@Path("/runs")
public void getLatestRuns(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception {
    List<BatchProgram> programs = validateAndGetBatchInput(request, BATCH_PROGRAMS_TYPE);
    List<ProgramId> programIds = programs.stream().map(batchProgram -> new ProgramId(namespaceId, batchProgram.getAppId(), batchProgram.getProgramType(), batchProgram.getProgramId())).collect(Collectors.toList());
    List<BatchProgramHistory> response = new ArrayList<>(programs.size());
    List<ProgramHistory> result = lifecycleService.getRunRecords(programIds, ProgramRunStatus.ALL, 0, Long.MAX_VALUE, 1);
    for (ProgramHistory programHistory : result) {
        ProgramId programId = programHistory.getProgramId();
        Exception exception = programHistory.getException();
        BatchProgram batchProgram = new BatchProgram(programId.getApplication(), programId.getType(), programId.getProgram());
        if (exception == null) {
            response.add(new BatchProgramHistory(batchProgram, HttpResponseStatus.OK.code(), null, programHistory.getRuns()));
        } else if (exception instanceof NotFoundException) {
            response.add(new BatchProgramHistory(batchProgram, HttpResponseStatus.NOT_FOUND.code(), exception.getMessage(), Collections.emptyList()));
        } else if (exception instanceof UnauthorizedException) {
            response.add(new BatchProgramHistory(batchProgram, HttpResponseStatus.FORBIDDEN.code(), exception.getMessage(), Collections.emptyList()));
        } else {
            response.add(new BatchProgramHistory(batchProgram, HttpResponseStatus.INTERNAL_SERVER_ERROR.code(), exception.getMessage(), Collections.emptyList()));
        }
    }
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(response));
}
Also used : BatchProgramSchedule(io.cdap.cdap.proto.BatchProgramSchedule) AuditDetail(io.cdap.cdap.common.security.AuditDetail) RunRecordDetail(io.cdap.cdap.internal.app.store.RunRecordDetail) BatchProgramResult(io.cdap.cdap.proto.BatchProgramResult) TypeToken(com.google.gson.reflect.TypeToken) MRJobInfoFetcher(io.cdap.cdap.app.mapreduce.MRJobInfoFetcher) MRJobInfo(io.cdap.cdap.proto.MRJobInfo) GsonBuilder(com.google.gson.GsonBuilder) ScheduledRuntime(io.cdap.cdap.proto.ScheduledRuntime) ProgramScheduleStatus(io.cdap.cdap.internal.app.runtime.schedule.ProgramScheduleStatus) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) Map(java.util.Map) ProgramStatus(io.cdap.cdap.proto.ProgramStatus) ScheduleDetail(io.cdap.cdap.proto.ScheduleDetail) EnumSet(java.util.EnumSet) HttpRequest(io.netty.handler.codec.http.HttpRequest) Set(java.util.Set) Reader(java.io.Reader) Constraint(io.cdap.cdap.internal.schedule.constraint.Constraint) ProgramRunStatus(io.cdap.cdap.proto.ProgramRunStatus) ProgramScheduleRecord(io.cdap.cdap.internal.app.runtime.schedule.ProgramScheduleRecord) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) StandardCharsets(java.nio.charset.StandardCharsets) Id(io.cdap.cdap.common.id.Id) ApplicationSpecificationAdapter(io.cdap.cdap.internal.app.ApplicationSpecificationAdapter) TriggerCodec(io.cdap.cdap.internal.app.runtime.schedule.trigger.TriggerCodec) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Joiner(com.google.common.base.Joiner) Singleton(com.google.inject.Singleton) RunRecord(io.cdap.cdap.proto.RunRecord) GET(javax.ws.rs.GET) SatisfiableTrigger(io.cdap.cdap.internal.app.runtime.schedule.trigger.SatisfiableTrigger) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) ArrayList(java.util.ArrayList) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) Nullable(javax.annotation.Nullable) Charsets(com.google.common.base.Charsets) AuditPolicy(io.cdap.cdap.common.security.AuditPolicy) BatchRunnableInstances(io.cdap.cdap.proto.BatchRunnableInstances) ProgramLiveInfo(io.cdap.cdap.proto.ProgramLiveInfo) ProgramLifecycleService(io.cdap.cdap.internal.app.services.ProgramLifecycleService) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) ConflictException(io.cdap.cdap.common.ConflictException) NotImplementedException(io.cdap.cdap.common.NotImplementedException) ServiceInstances(io.cdap.cdap.proto.ServiceInstances) InputStreamReader(java.io.InputStreamReader) ProgramRuntimeService(io.cdap.cdap.app.runtime.ProgramRuntimeService) Futures(com.google.common.util.concurrent.Futures) ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) Schedulers(io.cdap.cdap.internal.app.runtime.schedule.store.Schedulers) RunCountResult(io.cdap.cdap.proto.RunCountResult) BatchProgramStatus(io.cdap.cdap.proto.BatchProgramStatus) JsonObject(com.google.gson.JsonObject) NamespaceQueryAdmin(io.cdap.cdap.common.namespace.NamespaceQueryAdmin) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Inject(com.google.inject.Inject) ProgramScheduleService(io.cdap.cdap.scheduler.ProgramScheduleService) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) EndpointStrategy(io.cdap.cdap.common.discovery.EndpointStrategy) QueryParam(javax.ws.rs.QueryParam) Gson(com.google.gson.Gson) DefaultValue(javax.ws.rs.DefaultValue) Objects(com.google.common.base.Objects) ProgramHistory(io.cdap.cdap.proto.ProgramHistory) ConstraintCodec(io.cdap.cdap.internal.app.runtime.schedule.constraint.ConstraintCodec) DELETE(javax.ws.rs.DELETE) Containers(io.cdap.cdap.proto.Containers) Function(com.google.common.base.Function) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) BatchProgramStart(io.cdap.cdap.proto.BatchProgramStart) BatchRunnable(io.cdap.cdap.proto.BatchRunnable) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Collectors(java.util.stream.Collectors) ProgramStatusTrigger(io.cdap.cdap.internal.app.runtime.schedule.trigger.ProgramStatusTrigger) List(java.util.List) Type(java.lang.reflect.Type) CaseInsensitiveEnumTypeAdapterFactory(io.cdap.cdap.common.io.CaseInsensitiveEnumTypeAdapterFactory) Constants(io.cdap.cdap.common.conf.Constants) NotFoundException(io.cdap.cdap.common.NotFoundException) PathParam(javax.ws.rs.PathParam) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) BatchProgramHistory(io.cdap.cdap.proto.BatchProgramHistory) BatchProgramCount(io.cdap.cdap.proto.BatchProgramCount) HashMap(java.util.HashMap) ProgramType(io.cdap.cdap.proto.ProgramType) JsonElement(com.google.gson.JsonElement) NotRunningProgramLiveInfo(io.cdap.cdap.proto.NotRunningProgramLiveInfo) HashSet(java.util.HashSet) Trigger(io.cdap.cdap.api.schedule.Trigger) BatchProgram(io.cdap.cdap.proto.BatchProgram) Instances(io.cdap.cdap.proto.Instances) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) AbstractAppFabricHttpHandler(io.cdap.cdap.gateway.handlers.util.AbstractAppFabricHttpHandler) ProtoTrigger(io.cdap.cdap.proto.ProtoTrigger) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) HttpResponder(io.cdap.http.HttpResponder) JsonSyntaxException(com.google.gson.JsonSyntaxException) SchedulerException(io.cdap.cdap.internal.app.runtime.schedule.SchedulerException) ProgramId(io.cdap.cdap.proto.id.ProgramId) BadRequestException(io.cdap.cdap.common.BadRequestException) ProgramSchedule(io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule) Store(io.cdap.cdap.app.store.Store) TimeUnit(java.util.concurrent.TimeUnit) ServiceDiscoverable(io.cdap.cdap.common.service.ServiceDiscoverable) PUT(javax.ws.rs.PUT) Collections(java.util.Collections) ArrayList(java.util.ArrayList) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) ProgramId(io.cdap.cdap.proto.id.ProgramId) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) IOException(java.io.IOException) ConflictException(io.cdap.cdap.common.ConflictException) NotImplementedException(io.cdap.cdap.common.NotImplementedException) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) NotFoundException(io.cdap.cdap.common.NotFoundException) JsonSyntaxException(com.google.gson.JsonSyntaxException) SchedulerException(io.cdap.cdap.internal.app.runtime.schedule.SchedulerException) BadRequestException(io.cdap.cdap.common.BadRequestException) BatchProgramHistory(io.cdap.cdap.proto.BatchProgramHistory) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) ProgramHistory(io.cdap.cdap.proto.ProgramHistory) BatchProgramHistory(io.cdap.cdap.proto.BatchProgramHistory) BatchProgram(io.cdap.cdap.proto.BatchProgram) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 3 with BatchProgramHistory

use of io.cdap.cdap.proto.BatchProgramHistory in project cdap by caskdata.

the class SupportBundleTestBase 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 : Manifest(java.util.jar.Manifest) TypeToken(com.google.gson.reflect.TypeToken) UGIProvider(io.cdap.cdap.security.impersonation.UGIProvider) GsonBuilder(com.google.gson.GsonBuilder) DefaultMetadataServiceClient(io.cdap.cdap.data2.metadata.writer.DefaultMetadataServiceClient) InetAddress(java.net.InetAddress) MediaType(javax.ws.rs.core.MediaType) Map(java.util.Map) SupportBundleTaskFactory(io.cdap.cdap.support.task.factory.SupportBundleTaskFactory) Closeables(com.google.common.io.Closeables) ClassRule(org.junit.ClassRule) SupportBundleK8sHealthCheckTaskFactory(io.cdap.cdap.support.task.factory.SupportBundleK8sHealthCheckTaskFactory) 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) Multibinder(com.google.inject.multibindings.Multibinder) 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) SupportBundleSystemLogTaskFactory(io.cdap.cdap.support.task.factory.SupportBundleSystemLogTaskFactory) TriggerCodec(io.cdap.cdap.internal.app.runtime.schedule.trigger.TriggerCodec) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) RunRecord(io.cdap.cdap.proto.RunRecord) Location(org.apache.twill.filesystem.Location) CommonHandlers(io.cdap.cdap.gateway.handlers.CommonHandlers) SatisfiableTrigger(io.cdap.cdap.internal.app.runtime.schedule.trigger.SatisfiableTrigger) 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) CurrentUGIProvider(io.cdap.cdap.security.impersonation.CurrentUGIProvider) Nullable(javax.annotation.Nullable) TransactionManager(org.apache.tephra.TransactionManager) URIScheme(io.cdap.cdap.common.discovery.URIScheme) IOException(java.io.IOException) Names(com.google.inject.name.Names) LocationFactory(org.apache.twill.filesystem.LocationFactory) File(java.io.File) Service(com.google.common.util.concurrent.Service) MetadataClient(io.cdap.cdap.client.MetadataClient) Guice(com.google.inject.Guice) Preconditions(com.google.common.base.Preconditions) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) Assert(org.junit.Assert) 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) Gson(com.google.gson.Gson) ServiceStore(io.cdap.cdap.app.store.ServiceStore) SupportBundlePipelineInfoTaskFactory(io.cdap.cdap.support.task.factory.SupportBundlePipelineInfoTaskFactory) HealthCheckService(io.cdap.cdap.common.service.HealthCheckService) URI(java.net.URI) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) Tasks(io.cdap.cdap.common.utils.Tasks) MessagingService(io.cdap.cdap.messaging.MessagingService) Collectors(java.util.stream.Collectors) HttpRequestConfig(io.cdap.common.http.HttpRequestConfig) HttpHandler(io.cdap.http.HttpHandler) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) SupportBundleInternalService(io.cdap.cdap.support.internal.app.services.SupportBundleInternalService) List(java.util.List) 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) Constants(io.cdap.cdap.common.conf.Constants) StructuredTableAdmin(io.cdap.cdap.spi.data.StructuredTableAdmin) RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) BeforeClass(org.junit.BeforeClass) BatchProgramHistory(io.cdap.cdap.proto.BatchProgramHistory) ManifestFields(io.cdap.cdap.app.program.ManifestFields) Modules(com.google.inject.util.Modules) SupportBundleHttpHandler(io.cdap.cdap.support.handlers.SupportBundleHttpHandler) 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) Scheduler(io.cdap.cdap.scheduler.Scheduler) ProgramId(io.cdap.cdap.proto.id.ProgramId) Config(io.cdap.cdap.api.Config) Scopes(com.google.inject.Scopes) CoreSchedulerService(io.cdap.cdap.scheduler.CoreSchedulerService) 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) AppRequest(io.cdap.cdap.proto.artifact.AppRequest) TemporaryFolder(org.junit.rules.TemporaryFolder) HttpResponse(io.cdap.common.http.HttpResponse) BatchProgram(io.cdap.cdap.proto.BatchProgram)

Example 4 with BatchProgramHistory

use of io.cdap.cdap.proto.BatchProgramHistory in project cdap by caskdata.

the class ProgramLifecycleHttpHandlerTest method testProgramStartStopStatus.

@Category(XSlowTests.class)
@Test
public void testProgramStartStopStatus() throws Exception {
    // deploy, check the status
    deploy(AllProgramsApp.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1);
    ProgramId serviceId1 = new ServiceId(TEST_NAMESPACE1, AllProgramsApp.NAME, AllProgramsApp.NoOpService.NAME);
    ProgramId serviceId2 = new ServiceId(TEST_NAMESPACE2, AllProgramsApp.NAME, AllProgramsApp.NoOpService.NAME);
    // service is stopped initially
    Assert.assertEquals(STOPPED, getProgramStatus(serviceId1));
    // start service in the wrong namespace and verify that it does not start
    startProgram(serviceId2, 404);
    // start a service and check the status
    startProgram(serviceId1);
    waitState(serviceId1, RUNNING);
    // stop the service and check the status
    stopProgram(serviceId1);
    waitState(serviceId1, STOPPED);
    // deploy another app in a different namespace and verify
    deploy(DummyAppWithTrackingTable.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2);
    Id.Program dummyMR1 = Id.Program.from(TEST_NAMESPACE1, DUMMY_APP_ID, ProgramType.MAPREDUCE, DUMMY_MR_NAME);
    Id.Program dummyMR2 = Id.Program.from(TEST_NAMESPACE2, DUMMY_APP_ID, ProgramType.MAPREDUCE, DUMMY_MR_NAME);
    // mapreduce is stopped initially
    Assert.assertEquals(STOPPED, getProgramStatus(dummyMR2));
    // start mapreduce in the wrong namespace and verify it does not start
    startProgram(dummyMR1, 404);
    Assert.assertEquals(STOPPED, getProgramStatus(dummyMR2));
    // start map-reduce and verify status
    startProgram(dummyMR2);
    waitState(dummyMR2, RUNNING);
    // stop the mapreduce program and check the status
    stopProgram(dummyMR2);
    waitState(dummyMR2, STOPPED);
    // start multiple runs of the map-reduce program
    startProgram(dummyMR2);
    startProgram(dummyMR2);
    verifyProgramRuns(dummyMR2, ProgramRunStatus.RUNNING, 1);
    // stop all runs of the map-reduce program
    stopProgram(dummyMR2, 200);
    waitState(dummyMR2, STOPPED);
    // deploy an app containing a workflow
    deploy(SleepingWorkflowApp.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2);
    Id.Program sleepWorkflow1 = Id.Program.from(TEST_NAMESPACE1, SLEEP_WORKFLOW_APP_ID, ProgramType.WORKFLOW, SLEEP_WORKFLOW_NAME);
    Id.Program sleepWorkflow2 = Id.Program.from(TEST_NAMESPACE2, SLEEP_WORKFLOW_APP_ID, ProgramType.WORKFLOW, SLEEP_WORKFLOW_NAME);
    // workflow is stopped initially
    Assert.assertEquals(STOPPED, getProgramStatus(sleepWorkflow2));
    // start workflow in the wrong namespace and verify that it does not start
    startProgram(sleepWorkflow1, 404);
    Assert.assertEquals(STOPPED, getProgramStatus(sleepWorkflow2));
    // start workflow and check status
    startProgram(sleepWorkflow2);
    waitState(sleepWorkflow2, RUNNING);
    // workflow will stop itself
    waitState(sleepWorkflow2, STOPPED);
    // start multiple runs of the workflow
    startProgram(sleepWorkflow2, ImmutableMap.of("sleep.ms", "5000"));
    startProgram(sleepWorkflow2, ImmutableMap.of("sleep.ms", "5000"));
    verifyProgramRuns(sleepWorkflow2, ProgramRunStatus.RUNNING, 1);
    List<RunRecord> runs = getProgramRuns(sleepWorkflow2, ProgramRunStatus.RUNNING);
    Assert.assertEquals(2, runs.size());
    stopProgram(sleepWorkflow2, runs.get(0).getPid(), 200);
    stopProgram(sleepWorkflow2, runs.get(1).getPid(), 200);
    waitState(sleepWorkflow2, STOPPED);
    long startTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
    // Set super long sleep so we can suspend the workflow ourselves.
    startProgram(sleepWorkflow2, ImmutableMap.of("sleep.ms", "500000"));
    waitState(sleepWorkflow2, RUNNING);
    stopProgram(sleepWorkflow2);
    waitState(sleepWorkflow2, STOPPED);
    long endTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) + 1;
    // sleepWorkflow2 should be restarted
    restartPrograms(new ApplicationId(TEST_NAMESPACE2, SLEEP_WORKFLOW_APP_ID), startTime, endTime);
    waitState(sleepWorkflow2, RUNNING);
    stopProgram(sleepWorkflow2);
    waitState(sleepWorkflow2, STOPPED);
    // verify batch runs endpoint
    List<ProgramId> programs = ImmutableList.of(sleepWorkflow2.toEntityId(), dummyMR2.toEntityId(), serviceId2);
    List<BatchProgramHistory> batchRuns = getProgramRuns(new NamespaceId(TEST_NAMESPACE2), programs);
    BatchProgramHistory sleepRun = batchRuns.get(0);
    BatchProgramHistory dummyMR2Run = batchRuns.get(1);
    BatchProgramHistory service2Run = batchRuns.get(2);
    // verify results come back in order
    Assert.assertEquals(sleepWorkflow2.getId(), sleepRun.getProgramId());
    Assert.assertEquals(dummyMR2.getId(), dummyMR2Run.getProgramId());
    Assert.assertEquals(serviceId2.getProgram(), service2Run.getProgramId());
    // verify status. AllProgramsApp was never deployed in NS2 and should not exist
    Assert.assertEquals(200, sleepRun.getStatusCode());
    Assert.assertEquals(200, dummyMR2Run.getStatusCode());
    Assert.assertEquals(404, service2Run.getStatusCode());
    // verify the run record is correct
    RunRecord runRecord = getProgramRuns(sleepWorkflow2, ProgramRunStatus.ALL).iterator().next();
    Assert.assertEquals(runRecord.getPid(), sleepRun.getRuns().iterator().next().getPid());
    runRecord = getProgramRuns(dummyMR2, ProgramRunStatus.ALL).iterator().next();
    Assert.assertEquals(runRecord.getPid(), dummyMR2Run.getRuns().iterator().next().getPid());
    Assert.assertTrue(service2Run.getRuns().isEmpty());
    // cleanup
    HttpResponse response = doDelete(getVersionedAPIPath("apps/", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
    Assert.assertEquals(200, response.getResponseCode());
    response = doDelete(getVersionedAPIPath("apps/", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2));
    Assert.assertEquals(200, response.getResponseCode());
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) ProgramId(io.cdap.cdap.proto.id.ProgramId) ServiceId(io.cdap.cdap.proto.id.ServiceId) BatchProgramHistory(io.cdap.cdap.proto.BatchProgramHistory) RunRecord(io.cdap.cdap.proto.RunRecord) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ServiceId(io.cdap.cdap.proto.id.ServiceId) Id(io.cdap.cdap.common.id.Id) ProfileId(io.cdap.cdap.proto.id.ProfileId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Aggregations

Id (io.cdap.cdap.common.id.Id)4 BatchProgramHistory (io.cdap.cdap.proto.BatchProgramHistory)4 RunRecord (io.cdap.cdap.proto.RunRecord)4 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)4 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)4 ProgramId (io.cdap.cdap.proto.id.ProgramId)4 Gson (com.google.gson.Gson)3 GsonBuilder (com.google.gson.GsonBuilder)3 JsonObject (com.google.gson.JsonObject)3 TypeToken (com.google.gson.reflect.TypeToken)3 Trigger (io.cdap.cdap.api.schedule.Trigger)3 Constants (io.cdap.cdap.common.conf.Constants)3 EndpointStrategy (io.cdap.cdap.common.discovery.EndpointStrategy)3 RandomEndpointStrategy (io.cdap.cdap.common.discovery.RandomEndpointStrategy)3 CaseInsensitiveEnumTypeAdapterFactory (io.cdap.cdap.common.io.CaseInsensitiveEnumTypeAdapterFactory)3 AbstractAppFabricHttpHandler (io.cdap.cdap.gateway.handlers.util.AbstractAppFabricHttpHandler)3 ApplicationSpecificationAdapter (io.cdap.cdap.internal.app.ApplicationSpecificationAdapter)3 SatisfiableTrigger (io.cdap.cdap.internal.app.runtime.schedule.trigger.SatisfiableTrigger)3 TriggerCodec (io.cdap.cdap.internal.app.runtime.schedule.trigger.TriggerCodec)3 Constraint (io.cdap.cdap.internal.schedule.constraint.Constraint)3