Search in sources :

Example 81 with ApplicationId

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

the class DeleteAndCreateSchedulesStage method process.

@Override
public void process(final ApplicationWithPrograms input) throws Exception {
    if (!input.canUpdateSchedules()) {
        // if we cant update schedules, emit and return
        emit(input);
        return;
    }
    ApplicationId appId = input.getApplicationId();
    // Get a set of new schedules from the app spec
    Set<ProgramSchedule> newSchedules = getProgramScheduleSet(appId, input.getSpecification());
    for (ProgramSchedule schedule : programScheduler.listSchedules(appId)) {
        if (newSchedules.contains(schedule)) {
            // Remove the existing schedule from the newSchedules
            newSchedules.remove(schedule);
            continue;
        }
        // Delete the existing schedule if it is not present in newSchedules
        programScheduler.deleteSchedule(schedule.getScheduleId());
    }
    // Add new schedules
    programScheduler.addSchedules(newSchedules);
    // Emit the input to next stage.
    emit(input);
}
Also used : ProgramSchedule(io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule) ApplicationId(io.cdap.cdap.proto.id.ApplicationId)

Example 82 with ApplicationId

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

the class DefaultPreviewRequestQueue method isValid.

/**
 * Check if the request is valid and not timed out yet.
 */
private static boolean isValid(PreviewRequest request, long waitTimeOut) {
    ApplicationId applicationId = request.getProgram().getParent();
    long submitTimeInSeconds = RunIds.getTime(applicationId.getApplication(), TimeUnit.SECONDS);
    long timeInWaiting = (System.currentTimeMillis() / 1000) - submitTimeInSeconds;
    return timeInWaiting <= waitTimeOut;
}
Also used : ApplicationId(io.cdap.cdap.proto.id.ApplicationId)

Example 83 with ApplicationId

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

the class ScheduleTaskRunnerTest method testRuntimeArgumentResolution.

@Test
public void testRuntimeArgumentResolution() throws Exception {
    Injector injector = Guice.createInjector(new ConfigModule(), binder -> {
        binder.bind(OwnerAdmin.class).to(NoOpOwnerAdmin.class);
        binder.bind(NamespaceAdmin.class).to(InMemoryNamespaceAdmin.class);
        binder.bind(NamespaceQueryAdmin.class).to(InMemoryNamespaceAdmin.class);
        binder.bind(PreferencesFetcher.class).toInstance(new FakePreferencesFetcher(Collections.singletonMap("key", "should-be-overridden")));
    });
    PropertiesResolver propertiesResolver = injector.getInstance(PropertiesResolver.class);
    ApplicationId appId = NamespaceId.DEFAULT.app("app");
    ProgramSchedule programSchedule = new ProgramSchedule("schedule", "desc", appId.workflow("wf2"), Collections.singletonMap("key", "val"), new ProgramStatusTrigger(appId.workflow("wf1")), Collections.emptyList());
    Map<String, String> userArgs = ScheduleTaskRunner.getUserArgs(programSchedule, propertiesResolver);
    Assert.assertEquals("val", userArgs.get("key"));
}
Also used : PropertiesResolver(io.cdap.cdap.internal.app.services.PropertiesResolver) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) NoOpOwnerAdmin(io.cdap.cdap.security.impersonation.NoOpOwnerAdmin) OwnerAdmin(io.cdap.cdap.security.impersonation.OwnerAdmin) InMemoryNamespaceAdmin(io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin) NamespaceAdmin(io.cdap.cdap.common.namespace.NamespaceAdmin) Injector(com.google.inject.Injector) ProgramStatusTrigger(io.cdap.cdap.internal.app.runtime.schedule.trigger.ProgramStatusTrigger) NamespaceQueryAdmin(io.cdap.cdap.common.namespace.NamespaceQueryAdmin) FakePreferencesFetcher(io.cdap.cdap.metadata.FakePreferencesFetcher) PreferencesFetcher(io.cdap.cdap.metadata.PreferencesFetcher) FakePreferencesFetcher(io.cdap.cdap.metadata.FakePreferencesFetcher) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 84 with ApplicationId

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

the class EntityExistenceTest method testExists.

@Test
@SuppressWarnings("unchecked")
public void testExists() throws NotFoundException, UnauthorizedException {
    existenceVerifier.ensureExists(new InstanceId(EXISTS));
    existenceVerifier.ensureExists(NAMESPACE);
    existenceVerifier.ensureExists(ARTIFACT);
    ApplicationId app = NAMESPACE.app(AllProgramsApp.NAME);
    existenceVerifier.ensureExists(app);
    existenceVerifier.ensureExists(app.mr(AllProgramsApp.NoOpMR.NAME));
    existenceVerifier.ensureExists(NAMESPACE.dataset(AllProgramsApp.DATASET_NAME));
}
Also used : InstanceId(io.cdap.cdap.proto.id.InstanceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 85 with ApplicationId

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

the class UpdateTimeScheduleCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream printStream) throws Exception {
    String scheduleName = arguments.get(ArgumentName.SCHEDULE_NAME.toString());
    String[] programIdParts = arguments.get(ArgumentName.PROGRAM.toString()).split("\\.");
    String version = arguments.getOptional(ArgumentName.APP_VERSION.toString());
    String scheduleDescription = arguments.getOptional(ArgumentName.DESCRIPTION.toString(), "");
    String cronExpression = arguments.get(ArgumentName.CRON_EXPRESSION.toString());
    String schedulePropertiesString = arguments.getOptional(ArgumentName.SCHEDULE_PROPERTIES.toString(), "");
    String scheduleRunConcurrencyString = arguments.getOptional(ArgumentName.CONCURRENCY.toString(), null);
    if (programIdParts.length < 2) {
        throw new CommandInputError(this);
    }
    String appId = programIdParts[0];
    NamespaceId namespaceId = cliConfig.getCurrentNamespace();
    ApplicationId applicationId = (version == null) ? namespaceId.app(appId) : namespaceId.app(appId, version);
    ScheduleId scheduleId = applicationId.schedule(scheduleName);
    String description = scheduleDescription == null ? null : scheduleDescription;
    ScheduleProgramInfo programInfo = new ScheduleProgramInfo(SchedulableProgramType.WORKFLOW, programIdParts[1]);
    List<Constraint> constraints = scheduleRunConcurrencyString == null ? ImmutableList.of() : ImmutableList.of(new ProtoConstraint.ConcurrencyConstraint(Integer.valueOf(scheduleRunConcurrencyString)));
    Map<String, String> propertiesMap = ArgumentParser.parseMap(schedulePropertiesString, ArgumentName.SCHEDULE_PROPERTIES.toString());
    ScheduleDetail scheduleDetail = new ScheduleDetail(scheduleName, description, programInfo, propertiesMap, new ProtoTrigger.TimeTrigger(cronExpression), constraints, null);
    scheduleClient.update(scheduleId, scheduleDetail);
    printStream.printf("Successfully updated schedule '%s' in app '%s'\n", scheduleName, appId);
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) ProtoConstraint(io.cdap.cdap.proto.ProtoConstraint) Constraint(io.cdap.cdap.internal.schedule.constraint.Constraint) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) ProtoTrigger(io.cdap.cdap.proto.ProtoTrigger) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ScheduleDetail(io.cdap.cdap.proto.ScheduleDetail) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ScheduleProgramInfo(io.cdap.cdap.api.workflow.ScheduleProgramInfo)

Aggregations

ApplicationId (io.cdap.cdap.proto.id.ApplicationId)789 Test (org.junit.Test)410 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)279 ProgramId (io.cdap.cdap.proto.id.ProgramId)263 ApplicationManager (io.cdap.cdap.test.ApplicationManager)225 ETLStage (io.cdap.cdap.etl.proto.v2.ETLStage)223 ETLBatchConfig (io.cdap.cdap.etl.proto.v2.ETLBatchConfig)196 StructuredRecord (io.cdap.cdap.api.data.format.StructuredRecord)180 Table (io.cdap.cdap.api.dataset.table.Table)178 WorkflowManager (io.cdap.cdap.test.WorkflowManager)169 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)154 Schema (io.cdap.cdap.api.data.schema.Schema)147 ArrayList (java.util.ArrayList)129 HashSet (java.util.HashSet)126 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)124 HashMap (java.util.HashMap)109 KeyValueTable (io.cdap.cdap.api.dataset.lib.KeyValueTable)107 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)88 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)88 Path (javax.ws.rs.Path)75