Search in sources :

Example 76 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.

the class ArtifactHttpHandlerInternalTest method testRemoteArtifactRepositoryReaderGetArtifactDetails.

/**
 * Test {@link RemoteArtifactRepositoryReader#getArtifactDetails}
 */
@Test
public void testRemoteArtifactRepositoryReaderGetArtifactDetails() throws Exception {
    // Add an artifact with a number of versions
    String systemArtfiactName = "sysApp3";
    final int numVersions = 10;
    List<ArtifactId> artifactIds = new ArrayList<>();
    for (int i = 1; i <= numVersions; i++) {
        String version = String.format("%d.0.0", i);
        ArtifactId systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, version);
        addAppAsSystemArtifacts(systemArtifactId);
        artifactIds.add(systemArtifactId);
    }
    ArtifactRepositoryReader remoteReader = getInjector().getInstance(RemoteArtifactRepositoryReader.class);
    ArtifactRange range = null;
    List<ArtifactDetail> details = null;
    ArtifactId systemArtifactId = null;
    ArtifactDetail expectedDetail = null;
    int numLimits = 0;
    range = new ArtifactRange(NamespaceId.SYSTEM.getNamespace(), systemArtfiactName, new ArtifactVersion("1.0.0"), new ArtifactVersion(String.format("%d.0.0", numVersions)));
    // Fetch artifacts with the version in range [1.0.0, numVersions.0.0], but limit == 1 in desc order
    numLimits = 1;
    details = remoteReader.getArtifactDetails(range, numLimits, ArtifactSortOrder.DESC);
    Assert.assertEquals(numLimits, details.size());
    systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, String.format("%d.0.0", numVersions));
    expectedDetail = getArtifactDetailFromRepository(Id.Artifact.fromEntityId(systemArtifactId));
    Assert.assertTrue(details.get(numLimits - 1).equals(expectedDetail));
    // Fetch artifacts with the version in range [1.0.0, numVersions.0.0], but limit == 3 in desc order
    numLimits = 3;
    details = remoteReader.getArtifactDetails(range, numLimits, ArtifactSortOrder.DESC);
    Assert.assertEquals(numLimits, details.size());
    for (int i = 0; i < numLimits; i++) {
        systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, String.format("%d.0.0", numVersions - i));
        expectedDetail = getArtifactDetailFromRepository(Id.Artifact.fromEntityId(systemArtifactId));
        Assert.assertTrue(details.get(i).equals(expectedDetail));
    }
    // Fetch artifacts with the version in range [1.0.0, numVersions.0.0], but limit == 1 in asec order
    details = remoteReader.getArtifactDetails(range, 1, ArtifactSortOrder.ASC);
    Assert.assertEquals(1, details.size());
    systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, "1.0.0");
    expectedDetail = getArtifactDetailFromRepository(Id.Artifact.fromEntityId(systemArtifactId));
    Assert.assertTrue(details.get(0).equals(expectedDetail));
    // Fetch artifacts with the version in range [1.0.0, numVersions.0.0], but limit == 5 in asec order
    numLimits = 5;
    details = remoteReader.getArtifactDetails(range, numLimits, ArtifactSortOrder.ASC);
    Assert.assertEquals(numLimits, details.size());
    for (int i = 0; i < numLimits; i++) {
        systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, String.format("%d.0.0", i + 1));
        expectedDetail = getArtifactDetailFromRepository(Id.Artifact.fromEntityId(systemArtifactId));
        Assert.assertTrue(details.get(i).equals(expectedDetail));
    }
    int versionLow = 1;
    int versionHigh = numVersions / 2;
    range = new ArtifactRange(NamespaceId.SYSTEM.getNamespace(), systemArtfiactName, new ArtifactVersion(String.format("%d.0.0", versionLow)), new ArtifactVersion(String.format("%d.0.0", versionHigh)));
    // Fetch artifacts with the version in range [1.0.0, <numVersions/2>.0.0], but limit == numVersions in desc order
    numLimits = numVersions;
    details = remoteReader.getArtifactDetails(range, numLimits, ArtifactSortOrder.DESC);
    Assert.assertEquals(versionHigh - versionLow + 1, details.size());
    for (int i = 0; i < versionHigh - versionLow + 1; i++) {
        systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, String.format("%d.0.0", versionHigh - i));
        expectedDetail = getArtifactDetailFromRepository(Id.Artifact.fromEntityId(systemArtifactId));
        Assert.assertTrue(details.get(i).equals(expectedDetail));
    }
}
Also used : ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ArrayList(java.util.ArrayList) ArtifactRange(io.cdap.cdap.api.artifact.ArtifactRange) ArtifactRepositoryReader(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepositoryReader) RemoteArtifactRepositoryReader(io.cdap.cdap.internal.app.runtime.artifact.RemoteArtifactRepositoryReader) ArtifactDetail(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail) Test(org.junit.Test)

Example 77 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.

the class ArtifactHttpHandlerTestBase method addAppAsUserArtifacts.

/**
 * Add {@link AllProgramsApp} as user artifact with the given {@link ArtifactId}
 */
protected void addAppAsUserArtifacts(ArtifactId artifactId) throws Exception {
    CConfiguration cConf = getInjector().getInstance(CConfiguration.class);
    File localDataDir = new File(cConf.get(Constants.CFG_LOCAL_DATA_DIR));
    String namespaceDir = cConf.get(Constants.Namespace.NAMESPACES_DIR);
    File namespaceBase = new File(localDataDir, namespaceDir);
    File destination = new File(new File(namespaceBase, artifactId.getNamespace()), String.format("%s-%s.jar", artifactId.getArtifact(), artifactId.getVersion()));
    buildAppArtifact(AllProgramsApp.class, new Manifest(), destination);
    artifactRepository.addArtifact(new Id.Artifact(new Id.Namespace(artifactId.getNamespace()), artifactId.getArtifact(), new ArtifactVersion(artifactId.getVersion())), destination);
}
Also used : ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) Id(io.cdap.cdap.common.id.Id) Manifest(java.util.jar.Manifest) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) File(java.io.File)

Example 78 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.

the class RuntimeServiceMainTest method testRuntimeService.

@Test
public void testRuntimeService() throws Exception {
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact("test", "1.0");
    ProgramRunId programRunId = NamespaceId.DEFAULT.app("app").worker("worker").run(RunIds.generate());
    Map<String, String> systemArgs = ImmutableMap.of(SystemArguments.PROFILE_PROVISIONER, NativeProvisioner.SPEC.getName(), SystemArguments.PROFILE_NAME, "default");
    ProgramOptions programOptions = new SimpleProgramOptions(programRunId.getParent(), new BasicArguments(systemArgs), new BasicArguments());
    ProgramDescriptor programDescriptor = new ProgramDescriptor(programRunId.getParent(), null, artifactId);
    // Write out program state events to simulate program start
    Injector appFabricInjector = getServiceMainInstance(AppFabricServiceMain.class).getInjector();
    CConfiguration cConf = appFabricInjector.getInstance(CConfiguration.class);
    ProgramStatePublisher programStatePublisher = new MessagingProgramStatePublisher(appFabricInjector.getInstance(MessagingService.class), NamespaceId.SYSTEM.topic(cConf.get(Constants.AppFabric.PROGRAM_STATUS_RECORD_EVENT_TOPIC)), RetryStrategies.fromConfiguration(cConf, "system.program.state."));
    new MessagingProgramStateWriter(programStatePublisher).start(programRunId, programOptions, null, programDescriptor);
    Injector injector = getServiceMainInstance(RuntimeServiceMain.class).getInjector();
    TransactionRunner txRunner = injector.getInstance(TransactionRunner.class);
    // Should see a STARTING record in the runtime store
    Tasks.waitFor(ProgramRunStatus.STARTING, () -> {
        RunRecordDetail detail = TransactionRunners.run(txRunner, context -> {
            return AppMetadataStore.create(context).getRun(programRunId);
        });
        return detail == null ? null : detail.getStatus();
    }, 5, TimeUnit.SECONDS);
    ProgramStateWriter programStateWriter = createProgramStateWriter(injector, programRunId);
    // Write a running state. We should see a RUNNING record in the runtime store
    programStateWriter.running(programRunId, null);
    Tasks.waitFor(ProgramRunStatus.RUNNING, () -> {
        RunRecordDetail detail = TransactionRunners.run(txRunner, context -> {
            return AppMetadataStore.create(context).getRun(programRunId);
        });
        return detail == null ? null : detail.getStatus();
    }, 5, TimeUnit.SECONDS);
    // Write a complete state. The run record should be removed in the runtime store
    programStateWriter.completed(programRunId);
    Tasks.waitFor(true, () -> TransactionRunners.run(txRunner, context -> AppMetadataStore.create(context).getRun(programRunId) == null), 5, TimeUnit.SECONDS);
}
Also used : Retries(io.cdap.cdap.common.service.Retries) RetryStrategy(io.cdap.cdap.common.service.RetryStrategy) RunRecordDetail(io.cdap.cdap.internal.app.store.RunRecordDetail) TransactionRunners(io.cdap.cdap.spi.data.transaction.TransactionRunners) BeforeClass(org.junit.BeforeClass) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) MessagingProgramStateWriter(io.cdap.cdap.internal.app.program.MessagingProgramStateWriter) Notification(io.cdap.cdap.proto.Notification) Bytes(io.cdap.cdap.api.common.Bytes) RetryStrategies(io.cdap.cdap.common.service.RetryStrategies) TopicId(io.cdap.cdap.proto.id.TopicId) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) ProgramStateWriter(io.cdap.cdap.app.runtime.ProgramStateWriter) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) Gson(com.google.gson.Gson) ProgramOptions(io.cdap.cdap.app.runtime.ProgramOptions) Map(java.util.Map) SystemArguments(io.cdap.cdap.internal.app.runtime.SystemArguments) NativeProvisioner(io.cdap.cdap.internal.provision.NativeProvisioner) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) AppMetadataStore(io.cdap.cdap.internal.app.store.AppMetadataStore) Tasks(io.cdap.cdap.common.utils.Tasks) Message(io.cdap.cdap.api.messaging.Message) ImmutableMap(com.google.common.collect.ImmutableMap) RunIds(io.cdap.cdap.common.app.RunIds) ProgramStatePublisher(io.cdap.cdap.internal.app.program.ProgramStatePublisher) RetryableException(io.cdap.cdap.api.retry.RetryableException) MessagingService(io.cdap.cdap.messaging.MessagingService) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) MessagingProgramStatePublisher(io.cdap.cdap.internal.app.program.MessagingProgramStatePublisher) RuntimeClient(io.cdap.cdap.internal.app.runtime.monitor.RuntimeClient) Test(org.junit.Test) IOException(java.io.IOException) ProgramRunStatus(io.cdap.cdap.proto.ProgramRunStatus) StandardCharsets(java.nio.charset.StandardCharsets) MessageId(io.cdap.cdap.messaging.data.MessageId) Injector(com.google.inject.Injector) TimeUnit(java.util.concurrent.TimeUnit) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) Constants(io.cdap.cdap.common.conf.Constants) Collections(java.util.Collections) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) RunRecordDetail(io.cdap.cdap.internal.app.store.RunRecordDetail) MessagingProgramStateWriter(io.cdap.cdap.internal.app.program.MessagingProgramStateWriter) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) ProgramOptions(io.cdap.cdap.app.runtime.ProgramOptions) MessagingService(io.cdap.cdap.messaging.MessagingService) MessagingProgramStatePublisher(io.cdap.cdap.internal.app.program.MessagingProgramStatePublisher) MessagingProgramStateWriter(io.cdap.cdap.internal.app.program.MessagingProgramStateWriter) ProgramStateWriter(io.cdap.cdap.app.runtime.ProgramStateWriter) Injector(com.google.inject.Injector) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) ProgramStatePublisher(io.cdap.cdap.internal.app.program.ProgramStatePublisher) MessagingProgramStatePublisher(io.cdap.cdap.internal.app.program.MessagingProgramStatePublisher) Test(org.junit.Test)

Example 79 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.

the class Spark2Test method deploy.

private ApplicationManager deploy(NamespaceId namespaceId, Class<? extends Application> appClass) throws Exception {
    ArtifactId artifactId = new ArtifactId(namespaceId.getNamespace(), appClass.getSimpleName(), "1.0-SNAPSHOT");
    addArtifact(artifactId, ARTIFACTS.get(appClass));
    AppRequest<?> appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), null);
    return deployApplication(namespaceId.app(appClass.getSimpleName()), appRequest);
}
Also used : ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) AppRequest(io.cdap.cdap.proto.artifact.AppRequest)

Example 80 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.

the class AuthorizationTest method testCrossNSMapReduce.

@Test
public void testCrossNSMapReduce() throws Exception {
    createAuthNamespace();
    ApplicationId appId = AUTH_NAMESPACE.app(DatasetCrossNSAccessWithMAPApp.class.getSimpleName());
    ArtifactId artifact = AUTH_NAMESPACE.artifact(DatasetCrossNSAccessWithMAPApp.class.getSimpleName(), "1.0-SNAPSHOT");
    Map<EntityId, Set<? extends Permission>> neededPrivileges = ImmutableMap.<EntityId, Set<? extends Permission>>builder().put(appId, EnumSet.of(StandardPermission.CREATE, StandardPermission.GET)).put(artifact, EnumSet.of(StandardPermission.CREATE)).build();
    setUpPrivilegeAndRegisterForDeletion(ALICE, neededPrivileges);
    ProgramId programId = appId.program(ProgramType.MAPREDUCE, DatasetCrossNSAccessWithMAPApp.MAPREDUCE_PROGRAM);
    // bob will be executing the program
    grantAndAssertSuccess(AUTH_NAMESPACE, BOB, ImmutableSet.of(StandardPermission.GET));
    grantAndAssertSuccess(programId, BOB, ImmutableSet.of(ApplicationPermission.EXECUTE, StandardPermission.GET));
    // new privilege required due to capability validations
    grantAndAssertSuccess(artifact, BOB, EnumSet.of(StandardPermission.GET));
    cleanUpEntities.add(programId);
    ApplicationManager appManager = deployApplication(AUTH_NAMESPACE, DatasetCrossNSAccessWithMAPApp.class);
    MapReduceManager mrManager = appManager.getMapReduceManager(DatasetCrossNSAccessWithMAPApp.MAPREDUCE_PROGRAM);
    testCrossNSSystemDatasetAccessWithAuthMapReduce(mrManager);
    testCrossNSDatasetAccessWithAuthMapReduce(mrManager);
}
Also used : DatasetCrossNSAccessWithMAPApp(io.cdap.cdap.test.app.DatasetCrossNSAccessWithMAPApp) EntityId(io.cdap.cdap.proto.id.EntityId) ApplicationManager(io.cdap.cdap.test.ApplicationManager) PartitionedFileSet(io.cdap.cdap.api.dataset.lib.PartitionedFileSet) EnumSet(java.util.EnumSet) Set(java.util.Set) ImmutableSet(com.google.common.collect.ImmutableSet) HashSet(java.util.HashSet) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) MapReduceManager(io.cdap.cdap.test.MapReduceManager) GrantedPermission(io.cdap.cdap.proto.security.GrantedPermission) ApplicationPermission(io.cdap.cdap.proto.security.ApplicationPermission) AccessPermission(io.cdap.cdap.proto.security.AccessPermission) Permission(io.cdap.cdap.proto.security.Permission) StandardPermission(io.cdap.cdap.proto.security.StandardPermission) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) Test(org.junit.Test)

Aggregations

ArtifactId (io.cdap.cdap.proto.id.ArtifactId)214 Test (org.junit.Test)118 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)94 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)68 IOException (java.io.IOException)50 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)42 ProgramId (io.cdap.cdap.proto.id.ProgramId)42 Id (io.cdap.cdap.common.id.Id)40 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)40 File (java.io.File)34 PluginClass (io.cdap.cdap.api.plugin.PluginClass)32 Path (javax.ws.rs.Path)32 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)30 Set (java.util.Set)30 ImmutableSet (com.google.common.collect.ImmutableSet)28 Location (org.apache.twill.filesystem.Location)28 ArtifactRange (io.cdap.cdap.api.artifact.ArtifactRange)26 ArtifactDetail (io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail)26 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)22 EntityId (io.cdap.cdap.proto.id.EntityId)20