use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class AuthorizationTest method testPrograms.
@Test
public void testPrograms() throws Exception {
createAuthNamespace();
final ApplicationManager dummyAppManager = deployApplication(AUTH_NAMESPACE, DummyApp.class);
ArtifactSummary dummyArtifactSummary = dummyAppManager.getInfo().getArtifact();
ArtifactId dummyArtifact = AUTH_NAMESPACE.artifact(dummyArtifactSummary.getName(), dummyArtifactSummary.getVersion());
ApplicationId appId = AUTH_NAMESPACE.app(DummyApp.class.getSimpleName());
final ProgramId serviceId = appId.service(DummyApp.Greeting.SERVICE_NAME);
DatasetId dsId = AUTH_NAMESPACE.dataset("whom");
StreamId streamId = AUTH_NAMESPACE.stream("who");
assertAllAccess(ALICE, AUTH_NAMESPACE, dummyArtifact, appId, serviceId, dsId, streamId);
// alice should be able to start and stop programs in the app she deployed
dummyAppManager.startProgram(serviceId.toId());
Tasks.waitFor(true, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return dummyAppManager.isRunning(serviceId.toId());
}
}, 5, TimeUnit.SECONDS);
ServiceManager greetingService = dummyAppManager.getServiceManager(serviceId.getProgram());
// alice should be able to set instances for the program
greetingService.setInstances(2);
Assert.assertEquals(2, greetingService.getProvisionedInstances());
// alice should also be able to save runtime arguments for all future runs of the program
Map<String, String> args = ImmutableMap.of("key", "value");
greetingService.setRuntimeArgs(args);
// Alice should be able to get runtime arguments as she has ADMIN on it
Assert.assertEquals(args, greetingService.getRuntimeArgs());
dummyAppManager.stopProgram(serviceId.toId());
Tasks.waitFor(false, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return dummyAppManager.isRunning(serviceId.toId());
}
}, 5, TimeUnit.SECONDS);
// Bob should not be able to start programs in dummy app because he does not have privileges on it
SecurityRequestContext.setUserId(BOB.getName());
try {
dummyAppManager.startProgram(serviceId.toId());
Assert.fail("Bob should not be able to start the service because he does not have admin privileges on it.");
} catch (RuntimeException expected) {
//noinspection ThrowableResultOfMethodCallIgnored
Assert.assertTrue(Throwables.getRootCause(expected) instanceof UnauthorizedException);
}
try {
dummyAppManager.getInfo();
Assert.fail("Bob should not be able to read the app info with out privileges");
} catch (Exception expected) {
// expected
}
// setting instances should fail because Bob does not have admin privileges on the program
try {
greetingService.setInstances(3);
Assert.fail("Setting instances should have failed because bob does not have admin privileges on the service.");
} catch (RuntimeException expected) {
//noinspection ThrowableResultOfMethodCallIgnored
Assert.assertTrue(Throwables.getRootCause(expected) instanceof UnauthorizedException);
}
try {
greetingService.setRuntimeArgs(args);
Assert.fail("Setting runtime arguments should have failed because bob does not have admin privileges on the " + "service");
} catch (UnauthorizedException expected) {
// expected
}
try {
greetingService.getRuntimeArgs();
Assert.fail("Getting runtime arguments should have failed because bob does not have READ privileges on the " + "service");
} catch (UnauthorizedException expected) {
// expected
}
SecurityRequestContext.setUserId(ALICE.getName());
dummyAppManager.delete();
assertNoAccess(appId);
}
use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class TestFrameworkTestBase method deployWithArtifact.
/**
* Deploys an {@link Application} using the given artifact jar with an optional config object.
*/
protected static <T> ApplicationManager deployWithArtifact(NamespaceId namespaceId, Class<? extends Application> appClass, File artifactJar, @Nullable T config) throws Exception {
ArtifactId artifactId = new ArtifactId(namespaceId.getNamespace(), appClass.getSimpleName(), "1.0-SNAPSHOT");
addArtifact(artifactId, artifactJar);
AppRequest<T> appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), config);
return deployApplication(namespaceId.app(appClass.getSimpleName()).toId(), appRequest);
}
use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class TestFrameworkTestRun method testAppWithPlugin.
@Test
public void testAppWithPlugin() throws Exception {
ArtifactId artifactId = NamespaceId.DEFAULT.artifact("app-with-plugin", "1.0.0-SNAPSHOT");
addAppArtifact(artifactId, AppWithPlugin.class);
ArtifactId pluginArtifactId = NamespaceId.DEFAULT.artifact("test-plugin", "1.0.0-SNAPSHOT");
addPluginArtifact(pluginArtifactId, artifactId, ToStringPlugin.class);
ApplicationId appId = NamespaceId.DEFAULT.app("AppWithPlugin");
AppRequest createRequest = new AppRequest(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()));
ApplicationManager appManager = deployApplication(appId, createRequest);
final WorkerManager workerManager = appManager.getWorkerManager(AppWithPlugin.WORKER);
workerManager.start();
workerManager.waitForStatus(false, 5, 1);
Tasks.waitFor(false, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return workerManager.getHistory(ProgramRunStatus.COMPLETED).isEmpty();
}
}, 5, TimeUnit.SECONDS, 10, TimeUnit.MILLISECONDS);
final ServiceManager serviceManager = appManager.getServiceManager(AppWithPlugin.SERVICE);
serviceManager.start();
serviceManager.waitForStatus(true, 1, 10);
URL serviceURL = serviceManager.getServiceURL(5, TimeUnit.SECONDS);
callServiceGet(serviceURL, "dummy");
serviceManager.stop();
serviceManager.waitForStatus(false, 1, 10);
Tasks.waitFor(false, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return serviceManager.getHistory(ProgramRunStatus.KILLED).isEmpty();
}
}, 5, TimeUnit.SECONDS, 10, TimeUnit.MILLISECONDS);
WorkflowManager workflowManager = appManager.getWorkflowManager(AppWithPlugin.WORKFLOW);
workflowManager.start();
workflowManager.waitForRun(ProgramRunStatus.COMPLETED, 5, TimeUnit.MINUTES);
List<RunRecord> runRecords = workflowManager.getHistory();
Assert.assertNotEquals(ProgramRunStatus.FAILED, runRecords.get(0).getStatus());
DataSetManager<KeyValueTable> workflowTableManager = getDataset(AppWithPlugin.WORKFLOW_TABLE);
String value = Bytes.toString(workflowTableManager.get().read("val"));
Assert.assertEquals(AppWithPlugin.TEST, value);
Map<String, String> workflowTags = ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, NamespaceId.DEFAULT.getNamespace(), Constants.Metrics.Tag.APP, "AppWithPlugin", Constants.Metrics.Tag.WORKFLOW, AppWithPlugin.WORKFLOW, Constants.Metrics.Tag.RUN_ID, runRecords.get(0).getPid());
getMetricsManager().waitForTotalMetricCount(workflowTags, String.format("user.destroy.%s", AppWithPlugin.WORKFLOW), 1, 60, TimeUnit.SECONDS);
// Testing Spark Plugins. First send some data to stream for the Spark program to process
StreamManager streamManager = getStreamManager(AppWithPlugin.SPARK_STREAM);
for (int i = 0; i < 5; i++) {
streamManager.send("Message " + i);
}
SparkManager sparkManager = appManager.getSparkManager(AppWithPlugin.SPARK).start();
sparkManager.waitForRun(ProgramRunStatus.COMPLETED, 2, TimeUnit.MINUTES);
// Verify the Spark result.
DataSetManager<Table> dataSetManager = getDataset(AppWithPlugin.SPARK_TABLE);
Table table = dataSetManager.get();
try (Scanner scanner = table.scan(null, null)) {
for (int i = 0; i < 5; i++) {
Row row = scanner.next();
Assert.assertNotNull(row);
String expected = "Message " + i + " " + AppWithPlugin.TEST;
Assert.assertEquals(expected, Bytes.toString(row.getRow()));
Assert.assertEquals(expected, Bytes.toString(row.get(expected)));
}
// There shouldn't be any more rows in the table.
Assert.assertNull(scanner.next());
}
}
use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class TestFrameworkTestRun method testAppFromArtifact.
@Test
public void testAppFromArtifact() throws Exception {
ArtifactId artifactId = NamespaceId.DEFAULT.artifact("cfg-app", "1.0.0-SNAPSHOT");
addAppArtifact(artifactId, ConfigTestApp.class);
ApplicationId appId = NamespaceId.DEFAULT.app("AppFromArtifact");
AppRequest<ConfigTestApp.ConfigClass> createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new ConfigTestApp.ConfigClass("testStream", "testDataset"));
ApplicationManager appManager = deployApplication(appId, createRequest);
testAppConfig(appId.getApplication(), appManager, createRequest.getConfig());
}
use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class IntegrationTestBase method doClear.
private void doClear(NamespaceId namespace, boolean deleteNamespace) throws Exception {
// stop all programs in the namespace
getProgramClient().stopAll(namespace);
if (deleteNamespace) {
getNamespaceClient().delete(namespace);
return;
}
// delete all apps in the namespace
for (ApplicationRecord app : getApplicationClient().list(namespace)) {
getApplicationClient().delete(namespace.app(app.getName(), app.getAppVersion()));
}
// delete all streams
for (StreamDetail streamDetail : getStreamClient().list(namespace)) {
getStreamClient().delete(namespace.stream(streamDetail.getName()));
}
// delete all dataset instances
for (DatasetSpecificationSummary datasetSpecSummary : getDatasetClient().list(namespace)) {
getDatasetClient().delete(namespace.dataset(datasetSpecSummary.getName()));
}
ArtifactClient artifactClient = new ArtifactClient(getClientConfig(), getRestClient());
for (ArtifactSummary artifactSummary : artifactClient.list(namespace, ArtifactScope.USER)) {
artifactClient.delete(namespace.artifact(artifactSummary.getName(), artifactSummary.getVersion()));
}
assertIsClear(namespace);
}
Aggregations