Search in sources :

Example 26 with ProgramRunId

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

the class DirectRuntimeRequestValidatorTest method testInvalid.

@Test(expected = BadRequestException.class)
public void testInvalid() throws BadRequestException {
    ProgramRunId programRunId = NamespaceId.DEFAULT.app("app").spark("spark").run(RunIds.generate());
    // Validation should fail
    RuntimeRequestValidator validator = new DirectRuntimeRequestValidator(cConf, txRunner, new MockProgramRunRecordFetcher(), accessEnforcer, authenticationContext);
    validator.getProgramRunStatus(programRunId, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"));
}
Also used : DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) Test(org.junit.Test)

Example 27 with ProgramRunId

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

the class DirectRuntimeRequestValidatorTest method testValidProgramInStoppingState.

@Test
public void testValidProgramInStoppingState() throws BadRequestException {
    ProgramRunId programRunId = NamespaceId.DEFAULT.app("app").spark("spark").run(RunIds.generate());
    // Insert the run
    TransactionRunners.run(txRunner, context -> {
        AppMetadataStore store = AppMetadataStore.create(context);
        store.recordProgramProvisioning(programRunId, Collections.emptyMap(), Collections.singletonMap(SystemArguments.PROFILE_NAME, "system:default"), createSourceId(1), ARTIFACT_ID);
        store.recordProgramProvisioned(programRunId, 1, createSourceId(2));
        store.recordProgramStart(programRunId, null, Collections.emptyMap(), createSourceId(3));
        store.recordProgramRunning(programRunId, System.currentTimeMillis(), null, createSourceId(3));
        store.recordProgramStopping(programRunId, createSourceId(3), System.currentTimeMillis(), System.currentTimeMillis() + 1000);
    });
    // Validation should pass
    RuntimeRequestValidator validator = new DirectRuntimeRequestValidator(cConf, txRunner, new MockProgramRunRecordFetcher(), accessEnforcer, authenticationContext);
    ProgramRunInfo programRunInfo = validator.getProgramRunStatus(programRunId, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"));
    // After recording the program start in AppMetaDataStore the expected state is Stopping
    Assert.assertEquals(ProgramRunStatus.STOPPING, programRunInfo.getProgramRunStatus());
    Assert.assertNotNull("Payload isn't null when program status is Stopping", programRunInfo.getPayload());
}
Also used : AppMetadataStore(io.cdap.cdap.internal.app.store.AppMetadataStore) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) Test(org.junit.Test)

Example 28 with ProgramRunId

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

the class RuntimeClientServiceTest method beforeTest.

@Before
public void beforeTest() throws Exception {
    CConfiguration cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    cConf.set(Constants.RuntimeMonitor.TOPICS_CONFIGS, TOPIC_CONFIGS_VALUE);
    topicConfigs = RuntimeMonitors.createTopicConfigs(cConf);
    InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
    // Injector for the server side
    Injector injector = Guice.createInjector(new ConfigModule(cConf), new LocalLocationModule(), new MessagingServerRuntimeModule().getInMemoryModules(), new AuthenticationContextModules().getNoOpModule(), new RuntimeServerModule() {

        @Override
        protected void bindRequestValidator() {
            bind(RuntimeRequestValidator.class).toInstance((programRunId, request) -> new ProgramRunInfo(ProgramRunStatus.COMPLETED, null));
        }

        @Override
        protected void bindLogProcessor() {
            bind(RemoteExecutionLogProcessor.class).toInstance(payloads -> {
            });
        }
    }, new AbstractModule() {

        @Override
        protected void configure() {
            bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class);
            bind(DiscoveryService.class).toInstance(discoveryService);
            bind(DiscoveryServiceClient.class).toInstance(discoveryService);
        }
    });
    messagingService = injector.getInstance(MessagingService.class);
    if (messagingService instanceof Service) {
        ((Service) messagingService).startAndWait();
    }
    runtimeServer = injector.getInstance(RuntimeServer.class);
    runtimeServer.startAndWait();
    // Injector for the client side
    clientCConf = CConfiguration.create();
    clientCConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    clientCConf.set(Constants.RuntimeMonitor.TOPICS_CONFIGS, TOPIC_CONFIGS_VALUE);
    // Shorten the poll delay and grace period to speed up testing of program terminate state handling
    clientCConf.setLong(Constants.RuntimeMonitor.POLL_TIME_MS, 200);
    clientCConf.setLong(Constants.RuntimeMonitor.GRACEFUL_SHUTDOWN_MS, 3000);
    // Use smaller batch size so that fetches is broken into multiple fetches
    clientCConf.setInt(Constants.RuntimeMonitor.BATCH_SIZE, 1);
    injector = Guice.createInjector(new ConfigModule(clientCConf), RemoteAuthenticatorModules.getNoOpModule(), new MessagingServerRuntimeModule().getInMemoryModules(), new AuthenticationContextModules().getNoOpModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class);
            bind(DiscoveryService.class).toInstance(discoveryService);
            bind(DiscoveryServiceClient.class).toInstance(discoveryService);
            bind(ProgramRunId.class).toInstance(PROGRAM_RUN_ID);
        }
    });
    clientMessagingService = injector.getInstance(MessagingService.class);
    if (clientMessagingService instanceof Service) {
        ((Service) clientMessagingService).startAndWait();
    }
    runtimeClientService = injector.getInstance(RuntimeClientService.class);
    runtimeClientService.startAndWait();
}
Also used : MessagingServerRuntimeModule(io.cdap.cdap.messaging.guice.MessagingServerRuntimeModule) Arrays(java.util.Arrays) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Notification(io.cdap.cdap.proto.Notification) Spliterators(java.util.Spliterators) TimeoutException(java.util.concurrent.TimeoutException) MessageFetcher(io.cdap.cdap.api.messaging.MessageFetcher) ProgramStateWriter(io.cdap.cdap.app.runtime.ProgramStateWriter) Gson(com.google.gson.Gson) RuntimeServerModule(io.cdap.cdap.app.guice.RuntimeServerModule) After(org.junit.After) Map(java.util.Map) ClassRule(org.junit.ClassRule) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) Tasks(io.cdap.cdap.common.utils.Tasks) MessagingService(io.cdap.cdap.messaging.MessagingService) ProgramRunStatus(io.cdap.cdap.proto.ProgramRunStatus) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) MultiThreadMessagingContext(io.cdap.cdap.messaging.context.MultiThreadMessagingContext) Constants(io.cdap.cdap.common.conf.Constants) MessagingContext(io.cdap.cdap.api.messaging.MessagingContext) ProgramOptionConstants(io.cdap.cdap.internal.app.runtime.ProgramOptionConstants) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) LocalLocationModule(io.cdap.cdap.common.guice.LocalLocationModule) MessagingProgramStateWriter(io.cdap.cdap.internal.app.program.MessagingProgramStateWriter) RemoteAuthenticatorModules(io.cdap.cdap.common.guice.RemoteAuthenticatorModules) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) StreamSupport(java.util.stream.StreamSupport) Nullable(javax.annotation.Nullable) Before(org.junit.Before) DiscoveryService(org.apache.twill.discovery.DiscoveryService) Message(io.cdap.cdap.api.messaging.Message) RunIds(io.cdap.cdap.common.app.RunIds) Test(org.junit.Test) IOException(java.io.IOException) CloseableIterator(io.cdap.cdap.api.dataset.lib.CloseableIterator) TopicNotFoundException(io.cdap.cdap.api.messaging.TopicNotFoundException) Service(com.google.common.util.concurrent.Service) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) Injector(com.google.inject.Injector) TimeUnit(java.util.concurrent.TimeUnit) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) MessagePublisher(io.cdap.cdap.api.messaging.MessagePublisher) Guice(com.google.inject.Guice) Assert(org.junit.Assert) Collections(java.util.Collections) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) TemporaryFolder(org.junit.rules.TemporaryFolder) AbstractModule(com.google.inject.AbstractModule) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) MessagingService(io.cdap.cdap.messaging.MessagingService) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) DiscoveryService(org.apache.twill.discovery.DiscoveryService) Service(com.google.common.util.concurrent.Service) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) MessagingServerRuntimeModule(io.cdap.cdap.messaging.guice.MessagingServerRuntimeModule) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) AbstractModule(com.google.inject.AbstractModule) MessagingService(io.cdap.cdap.messaging.MessagingService) RuntimeServerModule(io.cdap.cdap.app.guice.RuntimeServerModule) LocalLocationModule(io.cdap.cdap.common.guice.LocalLocationModule) Injector(com.google.inject.Injector) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) DiscoveryService(org.apache.twill.discovery.DiscoveryService) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) Before(org.junit.Before)

Example 29 with ProgramRunId

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

the class ConcurrencyConstraintTest method testMaxConcurrentRuns.

@Test
public void testMaxConcurrentRuns() {
    Store store = AppFabricTestHelper.getInjector().getInstance(Store.class);
    try {
        long now = System.currentTimeMillis();
        ProgramSchedule schedule = new ProgramSchedule("SCHED1", "one partition schedule", WORKFLOW_ID, ImmutableMap.of("prop3", "abc"), new PartitionTrigger(DATASET_ID, 1), ImmutableList.of());
        SimpleJob job = new SimpleJob(schedule, 0, now, Collections.emptyList(), Job.State.PENDING_TRIGGER, 0L);
        ConcurrencyConstraint concurrencyConstraint = new ConcurrencyConstraint(2);
        ConstraintContext constraintContext = new ConstraintContext(job, now, store);
        assertSatisfied(true, concurrencyConstraint.check(schedule, constraintContext));
        ProgramRunId pid1 = WORKFLOW_ID.run(RunIds.generate().getId());
        ProgramRunId pid2 = WORKFLOW_ID.run(RunIds.generate().getId());
        ProgramRunId pid3 = WORKFLOW_ID.run(RunIds.generate().getId());
        // add a run for the schedule
        Map<String, String> systemArgs = ImmutableMap.of(ProgramOptionConstants.SCHEDULE_NAME, schedule.getName());
        setStartAndRunning(store, pid1, EMPTY_MAP, systemArgs);
        assertSatisfied(true, concurrencyConstraint.check(schedule, constraintContext));
        // add a run for the program from a different schedule. Since there are now 2 running instances of the
        // workflow (regardless of the schedule name), the constraint is not met
        systemArgs = ImmutableMap.of(ProgramOptionConstants.SCHEDULE_NAME, "not" + schedule.getName());
        setStartAndRunning(store, pid2, EMPTY_MAP, systemArgs);
        assertSatisfied(false, concurrencyConstraint.check(schedule, constraintContext));
        // add a run for the program that wasn't from a schedule
        // there are now three concurrent runs, so the constraint will not be met
        setStartAndRunning(store, pid3);
        assertSatisfied(false, concurrencyConstraint.check(schedule, constraintContext));
        // stop the first program; constraint will not be satisfied as there are still 2 running
        store.setStop(pid1, System.currentTimeMillis(), ProgramRunStatus.COMPLETED, AppFabricTestHelper.createSourceId(++sourceId));
        assertSatisfied(false, concurrencyConstraint.check(schedule, constraintContext));
        // suspending/resuming the workflow doesn't reduce its concurrency count
        store.setSuspend(pid3, AppFabricTestHelper.createSourceId(++sourceId), -1);
        assertSatisfied(false, concurrencyConstraint.check(schedule, constraintContext));
        store.setResume(pid3, AppFabricTestHelper.createSourceId(++sourceId), -1);
        assertSatisfied(false, concurrencyConstraint.check(schedule, constraintContext));
        // but the constraint will be satisfied with it completes, as there is only 1 remaining RUNNING
        store.setStop(pid3, System.currentTimeMillis(), ProgramRunStatus.KILLED, AppFabricTestHelper.createSourceId(++sourceId));
        assertSatisfied(true, concurrencyConstraint.check(schedule, constraintContext));
        // add a run in provisioning state, constraint will not be satisfied since active runs increased to 2
        ProgramRunId pid4 = WORKFLOW_ID.run(RunIds.generate().getId());
        setProvisioning(store, pid4, Collections.emptyMap(), Collections.emptyMap());
        assertSatisfied(false, concurrencyConstraint.check(schedule, constraintContext));
        // stop the provisioning run, constraint will be satisfied since active runs decreased to 1
        store.setStop(pid4, System.currentTimeMillis(), ProgramRunStatus.FAILED, AppFabricTestHelper.createSourceId(++sourceId));
        assertSatisfied(true, concurrencyConstraint.check(schedule, constraintContext));
        // stopping the last running workflow will also satisfy the constraint
        store.setStop(pid2, System.currentTimeMillis(), ProgramRunStatus.FAILED, AppFabricTestHelper.createSourceId(++sourceId));
        assertSatisfied(true, concurrencyConstraint.check(schedule, constraintContext));
    } finally {
        AppFabricTestHelper.shutdown();
    }
}
Also used : ProgramSchedule(io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule) Store(io.cdap.cdap.app.store.Store) SimpleJob(io.cdap.cdap.internal.app.runtime.schedule.queue.SimpleJob) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) PartitionTrigger(io.cdap.cdap.internal.app.runtime.schedule.trigger.PartitionTrigger) Test(org.junit.Test)

Example 30 with ProgramRunId

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

the class DefaultRuntimeJobTest method testInjector.

@Test
public void testInjector() throws Exception {
    CConfiguration cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().toString());
    LocationFactory locationFactory = new LocalLocationFactory(TEMP_FOLDER.newFile());
    DefaultRuntimeJob defaultRuntimeJob = new DefaultRuntimeJob();
    Arguments systemArgs = new BasicArguments(Collections.singletonMap(SystemArguments.PROFILE_NAME, "test"));
    Node node = new Node("test", Node.Type.MASTER, "127.0.0.1", System.currentTimeMillis(), Collections.emptyMap());
    Cluster cluster = new Cluster("test", ClusterStatus.RUNNING, Collections.singleton(node), Collections.emptyMap());
    ProgramRunId programRunId = NamespaceId.DEFAULT.app("app").workflow("workflow").run(RunIds.generate());
    SimpleProgramOptions programOpts = new SimpleProgramOptions(programRunId.getParent(), systemArgs, new BasicArguments());
    Injector injector = Guice.createInjector(defaultRuntimeJob.createModules(new RuntimeJobEnvironment() {

        @Override
        public LocationFactory getLocationFactory() {
            return locationFactory;
        }

        @Override
        public TwillRunner getTwillRunner() {
            return new NoopTwillRunnerService();
        }

        @Override
        public Map<String, String> getProperties() {
            return Collections.emptyMap();
        }
    }, cConf, programRunId, programOpts));
    injector.getInstance(LogAppenderInitializer.class);
    defaultRuntimeJob.createCoreServices(injector, systemArgs, cluster);
}
Also used : Node(io.cdap.cdap.runtime.spi.provisioner.Node) Arguments(io.cdap.cdap.app.runtime.Arguments) SystemArguments(io.cdap.cdap.internal.app.runtime.SystemArguments) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) Cluster(io.cdap.cdap.runtime.spi.provisioner.Cluster) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) NoopTwillRunnerService(io.cdap.cdap.common.twill.NoopTwillRunnerService) Injector(com.google.inject.Injector) RuntimeJobEnvironment(io.cdap.cdap.runtime.spi.runtimejob.RuntimeJobEnvironment) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) Test(org.junit.Test)

Aggregations

ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)158 Test (org.junit.Test)85 ProgramId (io.cdap.cdap.proto.id.ProgramId)62 RunId (org.apache.twill.api.RunId)38 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)37 ArrayList (java.util.ArrayList)29 RunRecordDetail (io.cdap.cdap.internal.app.store.RunRecordDetail)25 HashMap (java.util.HashMap)25 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)24 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)24 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)24 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)23 IOException (java.io.IOException)22 HashSet (java.util.HashSet)21 ProgramOptions (io.cdap.cdap.app.runtime.ProgramOptions)20 ProgramRunStatus (io.cdap.cdap.proto.ProgramRunStatus)19 Map (java.util.Map)19 SimpleProgramOptions (io.cdap.cdap.internal.app.runtime.SimpleProgramOptions)18 Injector (com.google.inject.Injector)15 TimeUnit (java.util.concurrent.TimeUnit)15