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));
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations