Search in sources :

Example 71 with ArtifactId

use of io.cdap.cdap.api.artifact.ArtifactId in project cdap by caskdata.

the class ProgramNotificationSubscriberServiceTest method testAppSpecNotRequiredToWriteState.

@Test
public void testAppSpecNotRequiredToWriteState() throws Exception {
    ProgramId programId = NamespaceId.DEFAULT.app("someapp").program(ProgramType.SERVICE, "s");
    Map<String, String> systemArguments = new HashMap<>();
    systemArguments.put(ProgramOptionConstants.SKIP_PROVISIONING, Boolean.TRUE.toString());
    systemArguments.put(SystemArguments.PROFILE_NAME, ProfileId.NATIVE.getScopedName());
    ProgramOptions programOptions = new SimpleProgramOptions(programId, new BasicArguments(systemArguments), new BasicArguments());
    ProgramRunId runId = programId.run(RunIds.generate());
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact("testArtifact", "1.0").toApiArtifactId();
    ApplicationSpecification appSpec = new DefaultApplicationSpecification("name", "1.0.0", ProjectInfo.getVersion().toString(), "desc", null, artifactId, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap());
    ProgramDescriptor programDescriptor = new ProgramDescriptor(programId, appSpec);
    programStateWriter.start(runId, programOptions, null, programDescriptor);
    Tasks.waitFor(ProgramRunStatus.STARTING, () -> TransactionRunners.run(transactionRunner, context -> {
        AppMetadataStore metadataStoreDataset = AppMetadataStore.create(context);
        RunRecordDetail meta = metadataStoreDataset.getRun(runId);
        if (meta == null) {
            return null;
        }
        Assert.assertEquals(artifactId, meta.getArtifactId());
        return meta.getStatus();
    }), 10, TimeUnit.SECONDS);
    programStateWriter.completed(runId);
}
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) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) HashMap(java.util.HashMap) RunRecordDetail(io.cdap.cdap.internal.app.store.RunRecordDetail) ProgramId(io.cdap.cdap.proto.id.ProgramId) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) ProgramOptions(io.cdap.cdap.app.runtime.ProgramOptions) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) DefaultApplicationSpecification(io.cdap.cdap.internal.app.DefaultApplicationSpecification) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) Test(org.junit.Test)

Example 72 with ArtifactId

use of io.cdap.cdap.api.artifact.ArtifactId in project cdap by caskdata.

the class PluginInstantiatorTest method testResourceOrder.

/**
 * If a plugin has some resources in main jar and in libraries, main jar should take precedence
 */
@Test
public void testResourceOrder() throws IOException {
    File appDir = TMP_FOLDER.newFolder();
    File pluginsDir = TMP_FOLDER.newFolder();
    File pluginDir = TMP_FOLDER.newFolder();
    File pluginArchive = TMP_FOLDER.newFile();
    File jarDir = TMP_FOLDER.newFolder();
    ArtifactId artifactId = new ArtifactId("dummy", new ArtifactVersion("1.0"), ArtifactScope.USER);
    CConfiguration cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TMP_FOLDER.newFolder().getAbsolutePath());
    ProgramClassLoader programClassLoader = new ProgramClassLoader(cConf, appDir, this.getClass().getClassLoader());
    PluginInstantiator pluginInstantiator = new PluginInstantiator(cConf, programClassLoader, pluginsDir);
    FileUtils.write(new File(jarDir, "test.class"), "jarData");
    FileUtils.write(new File(pluginDir, "test.class"), "pluginData");
    BundleJarUtil.createJar(jarDir, new File(pluginDir, "library.jar"));
    BundleJarUtil.createJar(pluginDir, pluginArchive);
    pluginInstantiator.addArtifact(Locations.toLocation(pluginArchive), artifactId);
    PluginClassLoader loader = pluginInstantiator.getPluginClassLoader(artifactId, Collections.emptyList());
    Assert.assertEquals("pluginData", IOUtils.toString(loader.getResource("test.class")));
    pluginInstantiator.close();
}
Also used : ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) ProgramClassLoader(io.cdap.cdap.internal.app.runtime.ProgramClassLoader) File(java.io.File) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) Test(org.junit.Test)

Example 73 with ArtifactId

use of io.cdap.cdap.api.artifact.ArtifactId in project cdap by caskdata.

the class ReportGenerationAppTest method populateMetaFiles.

/**
 * Adds mock program run meta files to the given location.
 * TODO: [CDAP-13216] this method should be marked as @VisibleForTesting. Temporarily calling this method
 * when initializing report generation Spark program to add mock data
 *
 * @param metaBaseLocation the location to add files
 * @param currentTime the current time in millis
 */
private static void populateMetaFiles(Location metaBaseLocation, Long currentTime) throws Exception {
    DatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<>(ProgramRunInfoSerializer.SCHEMA);
    DataFileWriter<GenericRecord> dataFileWriter = new DataFileWriter<>(datumWriter);
    String appName = "Pipeline";
    String version = "-SNAPSHOT";
    String type = "WORKFLOW";
    String program1 = "SmartWorkflow_1";
    String program2 = "SmartWorkflow_2";
    // add a schedule info with program status trigger
    String scheduleInfo = "{\"name\": \"sched\",\"description\": \"desc\",\"triggerInfos\": [" + "{\"namespace\": \"default\",\"application\": \"app\",\"version\": \"-SNAPSHOT\",\"programType\": \"WORKFLOW\"," + "\"run\":\"randomRunId\",\"entity\": \"PROGRAM\",\"program\": \"wf\",\"programStatus\": \"KILLED\"," + "\"type\": \"PROGRAM_STATUS\"}]}";
    ProgramStartInfo startInfo = new ProgramStartInfo(ImmutableMap.of(), new ArtifactId(TEST_ARTIFACT_NAME, new ArtifactVersion("1.0.0"), ArtifactScope.USER), USER_ALICE, ImmutableMap.of(Constants.Notification.SCHEDULE_INFO_KEY, scheduleInfo));
    long delay = TimeUnit.MINUTES.toMillis(5);
    int mockMessageId = 0;
    for (String namespace : ImmutableList.of("default", "ns1", "ns2")) {
        Location nsLocation = metaBaseLocation.append(namespace);
        nsLocation.mkdirs();
        for (int i = 0; i < 5; i++) {
            long time = currentTime + TimeUnit.HOURS.toMillis(i);
            // file name is of the format <event-time-millis>-<creation-time-millis>.avro
            Location reportLocation = nsLocation.append(String.format("%d-%d.avro", time, System.currentTimeMillis()));
            reportLocation.createNew();
            dataFileWriter.create(ProgramRunInfoSerializer.SCHEMA, reportLocation.getOutputStream());
            String run1 = ReportIds.generate().toString();
            String run2 = ReportIds.generate().toString();
            dataFileWriter.append(createRecord(namespace, appName, version, type, program1, run1, "STARTING", time, startInfo, Integer.toString(++mockMessageId)));
            dataFileWriter.append(createRecord(namespace, appName, version, type, program1, run1, "FAILED", time + delay, null, Integer.toString(++mockMessageId)));
            dataFileWriter.append(createRecord(namespace, appName, version, type, program2, run2, "STARTING", time + delay, startInfo, Integer.toString(++mockMessageId)));
            dataFileWriter.append(createRecord(namespace, appName, version, type, program2, run2, "RUNNING", time + 2 * delay, null, Integer.toString(++mockMessageId)));
            dataFileWriter.append(createRecord(namespace, appName, version, type, program2, run2, "COMPLETED", time + 4 * delay, null, Integer.toString(++mockMessageId)));
            dataFileWriter.close();
        }
        LOG.debug("nsLocation.list() = {}", nsLocation.list());
    }
}
Also used : ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) DataFileWriter(org.apache.avro.file.DataFileWriter) GenericDatumWriter(org.apache.avro.generic.GenericDatumWriter) ProgramStartInfo(io.cdap.cdap.report.main.ProgramStartInfo) GenericRecord(org.apache.avro.generic.GenericRecord) Location(org.apache.twill.filesystem.Location)

Example 74 with ArtifactId

use of io.cdap.cdap.api.artifact.ArtifactId in project cdap by caskdata.

the class SupportBundleServiceTest method testSupportBundleService.

@Test
@Ignore
public void testSupportBundleService() throws Exception {
    deploy(AppWithWorkflow.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, namespaceId.getNamespace());
    long startTime = System.currentTimeMillis();
    ProgramId workflowProgram = new ProgramId(namespaceId.getNamespace(), AppWithWorkflow.NAME, ProgramType.WORKFLOW, AppWithWorkflow.SampleWorkflow.NAME);
    RunId workflowRunId = RunIds.generate(startTime);
    ArtifactId artifactId = namespaceId.artifact("testArtifact", "1.0").toApiArtifactId();
    setStartAndRunning(workflowProgram, workflowRunId.getId(), artifactId);
    List<RunRecord> runs = getProgramRuns(workflowProgram, ProgramRunStatus.RUNNING);
    Assert.assertEquals(1, runs.size());
    HttpResponse appsResponse = doGet(getVersionedAPIPath("apps/", Constants.Gateway.API_VERSION_3_TOKEN, namespaceId.getNamespace()));
    Assert.assertEquals(200, appsResponse.getResponseCode());
    // workflow ran for 1 minute
    long workflowStopTime = TimeUnit.MILLISECONDS.toSeconds(startTime) + 60;
    store.setStop(workflowProgram.run(workflowRunId.getId()), workflowStopTime, ProgramRunStatus.COMPLETED, SupportBundleTestHelper.createSourceId(++sourceId));
    SupportBundleConfiguration supportBundleConfiguration = new SupportBundleConfiguration(namespaceId.getNamespace(), AppWithWorkflow.NAME, workflowRunId.getId(), ProgramType.valueOfCategoryName("workflows"), AppWithWorkflow.SampleWorkflow.NAME, 1);
    String uuid = supportBundleService.generateSupportBundle(supportBundleConfiguration);
    Assert.assertNotNull(uuid);
    File tempFolder = new File(configuration.get(Constants.SupportBundle.LOCAL_DATA_DIR));
    File uuidFile = new File(tempFolder, uuid);
    Tasks.waitFor(CollectionState.FINISHED, () -> {
        SupportBundleStatus supportBundleStatus = supportBundleService.getSingleBundleJson(uuidFile);
        if (supportBundleStatus == null || supportBundleStatus.getStatus() == null) {
            return CollectionState.INVALID;
        }
        return supportBundleStatus.getStatus();
    }, 60, TimeUnit.SECONDS, 1, TimeUnit.SECONDS);
    SupportBundleStatus supportBundleStatus = supportBundleService.getSingleBundleJson(uuidFile);
    Set<SupportBundleTaskStatus> supportBundleTaskStatusList = supportBundleStatus.getTasks();
    Assert.assertEquals(uuid, supportBundleStatus.getBundleId());
    Assert.assertEquals(CollectionState.FINISHED, supportBundleStatus.getStatus());
    for (SupportBundleTaskStatus supportBundleTaskStatus : supportBundleTaskStatusList) {
        Assert.assertEquals(CollectionState.FINISHED, supportBundleTaskStatus.getStatus());
    }
}
Also used : ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) HttpResponse(io.cdap.common.http.HttpResponse) SupportBundleTaskStatus(io.cdap.cdap.support.status.SupportBundleTaskStatus) SupportBundleConfiguration(io.cdap.cdap.support.status.SupportBundleConfiguration) ProgramId(io.cdap.cdap.proto.id.ProgramId) RunRecord(io.cdap.cdap.proto.RunRecord) SupportBundleStatus(io.cdap.cdap.support.status.SupportBundleStatus) RunId(org.apache.twill.api.RunId) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 75 with ArtifactId

use of io.cdap.cdap.api.artifact.ArtifactId in project cdap by caskdata.

the class SupportBundleSystemLogTaskTest method generateWorkflowLog.

private String generateWorkflowLog() throws Exception {
    deploy(AppWithWorkflow.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, namespaceId.getNamespace());
    long startTime = System.currentTimeMillis();
    ProgramId workflowProgram = new ProgramId(namespaceId.getNamespace(), AppWithWorkflow.NAME, ProgramType.WORKFLOW, AppWithWorkflow.SampleWorkflow.NAME);
    RunId workflowRunId = RunIds.generate(startTime);
    ArtifactId artifactId = namespaceId.artifact("testArtifact", "1.0").toApiArtifactId();
    setStartAndRunning(workflowProgram, workflowRunId.getId(), artifactId);
    List<RunRecord> runs = getProgramRuns(workflowProgram, ProgramRunStatus.RUNNING);
    Assert.assertEquals(1, runs.size());
    HttpResponse appsResponse = doGet(getVersionedAPIPath("apps/", Constants.Gateway.API_VERSION_3_TOKEN, namespaceId.getNamespace()));
    Assert.assertEquals(200, appsResponse.getResponseCode());
    // workflow ran for 1 minute
    long workflowStopTime = TimeUnit.MILLISECONDS.toSeconds(startTime) + 60;
    store.setStop(workflowProgram.run(workflowRunId.getId()), workflowStopTime, ProgramRunStatus.COMPLETED, SupportBundleTestHelper.createSourceId(++sourceId));
    return runs.get(0).getPid();
}
Also used : RunRecord(io.cdap.cdap.proto.RunRecord) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) HttpResponse(io.cdap.common.http.HttpResponse) ProgramId(io.cdap.cdap.proto.id.ProgramId) RunId(org.apache.twill.api.RunId)

Aggregations

ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)75 Test (org.junit.Test)43 ProgramId (io.cdap.cdap.proto.id.ProgramId)32 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)25 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)25 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)19 RunId (org.apache.twill.api.RunId)18 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)14 File (java.io.File)14 HashMap (java.util.HashMap)14 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)13 Id (io.cdap.cdap.common.id.Id)10 HttpResponse (io.cdap.common.http.HttpResponse)9 Map (java.util.Map)9 Gson (com.google.gson.Gson)8 Location (org.apache.twill.filesystem.Location)8 ApplicationClass (io.cdap.cdap.api.artifact.ApplicationClass)7 PluginClass (io.cdap.cdap.api.plugin.PluginClass)7 AppDeploymentInfo (io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo)7 DefaultApplicationSpecification (io.cdap.cdap.internal.app.DefaultApplicationSpecification)6