use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class DefaultPreviewRunner method startPreview.
@Override
public void startPreview(PreviewRequest<?> previewRequest) throws Exception {
namespaceAdmin.create(new NamespaceMeta.Builder().setName(previewRequest.getProgram().getNamespaceId()).build());
programId = previewRequest.getProgram();
AppRequest<?> request = previewRequest.getAppRequest();
ArtifactSummary artifactSummary = request.getArtifact();
ApplicationId preview = programId.getParent();
DataTracerFactoryProvider.setDataTracerFactory(preview, dataTracerFactory);
String config = request.getConfig() == null ? null : GSON.toJson(request.getConfig());
try {
applicationLifecycleService.deployApp(preview.getParent(), preview.getApplication(), preview.getVersion(), artifactSummary, config, NOOP_PROGRAM_TERMINATOR, null, request.canUpdateSchedules());
} catch (Exception e) {
this.status = new PreviewStatus(PreviewStatus.Status.DEPLOY_FAILED, new BasicThrowable(e), null, null);
throw e;
}
final PreviewConfig previewConfig = previewRequest.getAppRequest().getPreview();
ProgramController controller = programLifecycleService.start(programId, previewConfig == null ? Collections.<String, String>emptyMap() : previewConfig.getRuntimeArgs(), false);
controller.addListener(new AbstractListener() {
@Override
public void init(ProgramController.State currentState, @Nullable Throwable cause) {
setStatus(new PreviewStatus(PreviewStatus.Status.RUNNING, null, System.currentTimeMillis(), null));
// Only have timer if there is a timeout setting.
if (previewConfig.getTimeout() != null) {
timer = new Timer();
final int timeOutMinutes = previewConfig.getTimeout();
timer.schedule(new TimerTask() {
@Override
public void run() {
try {
LOG.info("Stopping the preview since it has reached running time: {} mins.", timeOutMinutes);
stopPreview();
killedByTimer = true;
} catch (Exception e) {
LOG.debug("Error shutting down the preview run with id: {}", programId);
}
}
}, timeOutMinutes * 60 * 1000);
}
}
@Override
public void completed() {
setStatus(new PreviewStatus(PreviewStatus.Status.COMPLETED, null, status.getStartTime(), System.currentTimeMillis()));
shutDownUnrequiredServices();
}
@Override
public void killed() {
if (!killedByTimer) {
setStatus(new PreviewStatus(PreviewStatus.Status.KILLED, null, status.getStartTime(), System.currentTimeMillis()));
} else {
setStatus(new PreviewStatus(PreviewStatus.Status.KILLED_BY_TIMER, null, status.getStartTime(), System.currentTimeMillis()));
}
shutDownUnrequiredServices();
}
@Override
public void error(Throwable cause) {
setStatus(new PreviewStatus(PreviewStatus.Status.RUN_FAILED, new BasicThrowable(cause), status.getStartTime(), System.currentTimeMillis()));
shutDownUnrequiredServices();
}
}, Threads.SAME_THREAD_EXECUTOR);
runId = controller.getProgramRunId();
}
use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class AuthorizationArtifactRepository method clear.
@Override
public void clear(NamespaceId namespace) throws Exception {
List<ArtifactSummary> artifacts = delegate.getArtifactSummaries(namespace, false);
for (ArtifactSummary artifactSummary : artifacts) {
authorizationEnforcer.enforce(namespace.artifact(artifactSummary.getName(), artifactSummary.getVersion()), authenticationContext.getPrincipal(), Action.ADMIN);
}
delegate.clear(namespace);
}
use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class DefaultArtifactRepository method getApplicationClasses.
@Override
public List<ApplicationClassInfo> getApplicationClasses(NamespaceId namespace, String className) throws IOException {
List<ApplicationClassInfo> infos = Lists.newArrayList();
for (Map.Entry<ArtifactDescriptor, ApplicationClass> entry : artifactStore.getApplicationClasses(namespace, className).entrySet()) {
ArtifactSummary artifactSummary = ArtifactSummary.from(entry.getKey().getArtifactId());
ApplicationClass appClass = entry.getValue();
infos.add(new ApplicationClassInfo(artifactSummary, appClass.getClassName(), appClass.getConfigSchema()));
}
return Collections.unmodifiableList(infos);
}
use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class ApplicationLifecycleService method getApps.
/**
* Get all applications in the specified namespace that satisfy the specified predicate.
*
* @param namespace the namespace to get apps from
* @param predicate the predicate that must be satisfied in order to be returned
* @return list of all applications in the namespace that satisfy the specified predicate
*/
public List<ApplicationRecord> getApps(final NamespaceId namespace, com.google.common.base.Predicate<ApplicationRecord> predicate) throws Exception {
List<ApplicationRecord> appRecords = new ArrayList<>();
Map<ApplicationId, ApplicationSpecification> appSpecs = new HashMap<>();
for (ApplicationSpecification appSpec : store.getAllApplications(namespace)) {
appSpecs.put(namespace.app(appSpec.getName(), appSpec.getAppVersion()), appSpec);
}
appSpecs.keySet().retainAll(authorizationEnforcer.isVisible(appSpecs.keySet(), authenticationContext.getPrincipal()));
for (ApplicationId appId : appSpecs.keySet()) {
ApplicationSpecification appSpec = appSpecs.get(appId);
if (appSpec == null) {
continue;
}
// possible if this particular app was deploy prior to v3.2 and upgrade failed for some reason.
ArtifactId artifactId = appSpec.getArtifactId();
ArtifactSummary artifactSummary = artifactId == null ? new ArtifactSummary(appSpec.getName(), null) : ArtifactSummary.from(artifactId);
ApplicationRecord record = new ApplicationRecord(artifactSummary, appId, appSpec.getDescription(), ownerAdmin.getOwnerPrincipal(appId));
if (predicate.apply(record)) {
appRecords.add(record);
}
}
return appRecords;
}
use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class AppLifecycleHttpHandlerTest method testOwnerUsingArtifact.
@Test
public void testOwnerUsingArtifact() throws Exception {
ArtifactId artifactId = new ArtifactId(NamespaceId.DEFAULT.getNamespace(), "wordCountArtifact", "1.0.0");
addAppArtifact(Id.Artifact.fromEntityId(artifactId), WordCountApp.class);
ApplicationId applicationId = new ApplicationId(NamespaceId.DEFAULT.getNamespace(), "WordCountApp");
// deploy an app with a owner
String ownerPrincipal = "alice/somehost.net@somekdc.net";
AppRequest<ConfigTestApp.ConfigClass> appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), null, ownerPrincipal);
Assert.assertEquals(HttpResponseCodes.SC_OK, deploy(applicationId, appRequest).getStatusLine().getStatusCode());
// should be able to retrieve the owner information of the app
JsonObject appDetails = getAppDetails(NamespaceId.DEFAULT.getNamespace(), applicationId.getApplication());
Assert.assertEquals(ownerPrincipal, appDetails.get(Constants.Security.PRINCIPAL).getAsString());
// the stream created by the app should have the app owner too
Assert.assertEquals(ownerPrincipal, getStreamConfig(applicationId.getNamespaceId().stream("text")).getOwnerPrincipal());
// the dataset created by the app should have the app owner too
Assert.assertEquals(ownerPrincipal, getDatasetMeta(applicationId.getNamespaceId().dataset("mydataset")).getOwnerPrincipal());
// trying to deploy the same app with another owner should fail
String bobPrincipal = "bob/somehost.net@somekdc.net";
appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), null, bobPrincipal);
Assert.assertEquals(HttpResponseCodes.SC_FORBIDDEN, deploy(applicationId, appRequest).getStatusLine().getStatusCode());
// trying to deploy the same app with different version and another owner should fail too
appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), null, bobPrincipal);
Assert.assertEquals(HttpResponseCodes.SC_FORBIDDEN, deploy(new ApplicationId(applicationId.getNamespace(), applicationId.getApplication(), "1.0"), appRequest).getStatusLine().getStatusCode());
// trying to re-deploy the same app with same owner should pass
appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), null, ownerPrincipal);
Assert.assertEquals(HttpResponseCodes.SC_OK, deploy(applicationId, appRequest).getStatusLine().getStatusCode());
// trying to re-deploy the same app with different version but same owner should pass
appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), null, ownerPrincipal);
Assert.assertEquals(HttpResponseCodes.SC_OK, deploy(new ApplicationId(applicationId.getNamespace(), applicationId.getApplication(), "1.0"), appRequest).getStatusLine().getStatusCode());
// clean up the app
Assert.assertEquals(200, doDelete(getVersionedAPIPath("apps/" + applicationId.getApplication(), applicationId.getNamespace())).getStatusLine().getStatusCode());
// deletion of app should delete the stream/dataset owner information as they themselves are not deleted
Assert.assertEquals(ownerPrincipal, getStreamConfig(applicationId.getNamespaceId().stream("text")).getOwnerPrincipal());
Assert.assertEquals(ownerPrincipal, getDatasetMeta(applicationId.getNamespaceId().dataset("mydataset")).getOwnerPrincipal());
// cleanup
deleteNamespace(NamespaceId.DEFAULT.getNamespace());
}
Aggregations