use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class ProgramLifecycleHttpHandlerTest method testHistory.
private void testHistory(Class<?> app, Id.Program program) throws Exception {
String namespace = program.getNamespaceId();
try {
deploy(app, Constants.Gateway.API_VERSION_3_TOKEN, namespace);
verifyProgramHistory(program.toEntityId());
} catch (Exception e) {
LOG.error("Got exception: ", e);
} finally {
deleteApp(program.getApplication(), 200);
}
ApplicationId appId = new ApplicationId(namespace, program.getApplicationId(), VERSION1);
ProgramId programId = appId.program(program.getType(), program.getId());
try {
Id.Artifact artifactId = Id.Artifact.from(program.getNamespace(), app.getSimpleName(), "1.0.0");
addAppArtifact(artifactId, app);
AppRequest<Config> request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), null);
Assert.assertEquals(200, deploy(appId, request).getStatusLine().getStatusCode());
verifyProgramHistory(programId);
} catch (Exception e) {
LOG.error("Got exception: ", e);
} finally {
deleteApp(appId, 200);
}
}
use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class ApplicationDetail method fromSpec.
public static ApplicationDetail fromSpec(ApplicationSpecification spec, @Nullable String ownerPrincipal) {
List<ProgramRecord> programs = new ArrayList<>();
for (ProgramSpecification programSpec : spec.getFlows().values()) {
programs.add(new ProgramRecord(ProgramType.FLOW, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
for (ProgramSpecification programSpec : spec.getMapReduce().values()) {
programs.add(new ProgramRecord(ProgramType.MAPREDUCE, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
for (ProgramSpecification programSpec : spec.getServices().values()) {
programs.add(new ProgramRecord(ProgramType.SERVICE, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
for (ProgramSpecification programSpec : spec.getSpark().values()) {
programs.add(new ProgramRecord(ProgramType.SPARK, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
for (ProgramSpecification programSpec : spec.getWorkers().values()) {
programs.add(new ProgramRecord(ProgramType.WORKER, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
for (ProgramSpecification programSpec : spec.getWorkflows().values()) {
programs.add(new ProgramRecord(ProgramType.WORKFLOW, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
List<StreamDetail> streams = new ArrayList<>();
for (StreamSpecification streamSpec : spec.getStreams().values()) {
streams.add(new StreamDetail(streamSpec.getName()));
}
List<DatasetDetail> datasets = new ArrayList<>();
for (DatasetCreationSpec datasetSpec : spec.getDatasets().values()) {
datasets.add(new DatasetDetail(datasetSpec.getInstanceName(), datasetSpec.getTypeName()));
}
List<PluginDetail> plugins = new ArrayList<>();
for (Map.Entry<String, Plugin> pluginEnty : spec.getPlugins().entrySet()) {
plugins.add(new PluginDetail(pluginEnty.getKey(), pluginEnty.getValue().getPluginClass().getName(), pluginEnty.getValue().getPluginClass().getType()));
}
// this is only required if there are old apps lying around that failed to get upgrading during
// the upgrade to v3.2 for some reason. In those cases artifact id will be null until they re-deploy the app.
// in the meantime, we don't want this api call to null pointer exception.
ArtifactSummary summary = spec.getArtifactId() == null ? new ArtifactSummary(spec.getName(), null) : ArtifactSummary.from(spec.getArtifactId());
return new ApplicationDetail(spec.getName(), spec.getAppVersion(), spec.getDescription(), spec.getConfiguration(), streams, datasets, programs, plugins, summary, ownerPrincipal);
}
use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class AuthorizationTest method testMRStreamAuth.
@Test
@Category(SlowTests.class)
public void testMRStreamAuth() throws Exception {
createAuthNamespace();
Authorizer authorizer = getAuthorizer();
ApplicationManager appManager = deployApplication(AUTH_NAMESPACE, StreamAuthApp.class);
// After deploy, change Alice from ALL to ADMIN on the namespace
authorizer.revoke(AUTH_NAMESPACE, ALICE, EnumSet.allOf(Action.class));
authorizer.grant(AUTH_NAMESPACE, ALICE, EnumSet.of(Action.ADMIN));
StreamManager streamManager = getStreamManager(AUTH_NAMESPACE.stream(StreamAuthApp.STREAM));
streamManager.send("Hello");
final MapReduceManager mrManager = appManager.getMapReduceManager(StreamAuthApp.MAPREDUCE);
mrManager.start();
// Since Alice had full permissions, she should be able to execute the MR job successfully
mrManager.waitForRun(ProgramRunStatus.COMPLETED, 1, TimeUnit.MINUTES);
DataSetManager<KeyValueTable> kvManager = getDataset(AUTH_NAMESPACE.dataset(StreamAuthApp.KVTABLE));
try (KeyValueTable kvTable = kvManager.get()) {
byte[] value = kvTable.read("Hello");
Assert.assertArrayEquals(Bytes.toBytes("Hello"), value);
}
ProgramId mrId = AUTH_NAMESPACE.app(StreamAuthApp.APP).mr(StreamAuthApp.MAPREDUCE);
authorizer.grant(mrId.getNamespaceId(), BOB, ImmutableSet.of(Action.ADMIN));
ArtifactSummary artifactSummary = appManager.getInfo().getArtifact();
ArtifactId artifactId = AUTH_NAMESPACE.artifact(artifactSummary.getName(), artifactSummary.getVersion());
authorizer.grant(artifactId, BOB, EnumSet.allOf(Action.class));
authorizer.grant(mrId.getParent(), BOB, EnumSet.allOf(Action.class));
authorizer.grant(mrId, BOB, EnumSet.allOf(Action.class));
authorizer.grant(AUTH_NAMESPACE.stream(StreamAuthApp.STREAM), BOB, EnumSet.of(Action.ADMIN));
authorizer.grant(AUTH_NAMESPACE.dataset(StreamAuthApp.KVTABLE), BOB, EnumSet.allOf(Action.class));
streamManager.send("World");
// Switch user to Bob. Note that he doesn't have READ access on the stream.
SecurityRequestContext.setUserId(BOB.getName());
mrManager.start();
mrManager.waitForRun(ProgramRunStatus.FAILED, 1, TimeUnit.MINUTES);
kvManager = getDataset(AUTH_NAMESPACE.dataset(StreamAuthApp.KVTABLE));
try (KeyValueTable kvTable = kvManager.get()) {
byte[] value = kvTable.read("World");
Assert.assertNull(value);
}
// Now grant Bob, READ access on the stream. MR job should execute successfully now.
authorizer.grant(AUTH_NAMESPACE.stream(StreamAuthApp.STREAM), BOB, ImmutableSet.of(Action.READ));
mrManager.start();
mrManager.waitForRuns(ProgramRunStatus.COMPLETED, 2, 1, TimeUnit.MINUTES);
kvManager = getDataset(AUTH_NAMESPACE.dataset(StreamAuthApp.KVTABLE));
try (KeyValueTable kvTable = kvManager.get()) {
byte[] value = kvTable.read("World");
Assert.assertEquals("World", Bytes.toString(value));
}
SecurityRequestContext.setUserId(ALICE.getName());
appManager.delete();
assertNoAccess(AUTH_NAMESPACE.app(StreamAuthApp.APP));
}
use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class UnitTestManager method deployApplication.
@Override
public ApplicationManager deployApplication(NamespaceId namespace, Class<? extends Application> applicationClz, @Nullable Config configObject, File... bundleEmbeddedJars) {
Preconditions.checkNotNull(applicationClz, "Application class cannot be null.");
Type configType = Artifacts.getConfigType(applicationClz);
try {
ArtifactId artifactId = new ArtifactId(namespace.getNamespace(), applicationClz.getSimpleName(), "1.0-SNAPSHOT");
addAppArtifact(artifactId, applicationClz);
if (configObject == null) {
configObject = (Config) TypeToken.of(configType).getRawType().newInstance();
}
Application app = applicationClz.newInstance();
MockAppConfigurer configurer = new MockAppConfigurer(app);
app.configure(configurer, new DefaultApplicationContext<>(configObject));
ApplicationId applicationId = new ApplicationId(namespace.getNamespace(), configurer.getName());
ArtifactSummary artifactSummary = new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion());
appFabricClient.deployApplication(applicationId.toId(), new AppRequest(artifactSummary, configObject));
return appManagerFactory.create(applicationId);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class ServiceClientTestRun method deployApp.
/**
* Deploy app of given version
*/
private void deployApp(ApplicationId app) throws Exception {
AppRequest createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()));
appClient.deploy(app, createRequest);
}
Aggregations