use of io.cdap.cdap.internal.capability.CapabilityNotAvailableException in project cdap by caskdata.
the class ApplicationLifecycleServiceTest method testCapabilityMetaDataDeletion.
@Test
public void testCapabilityMetaDataDeletion() throws Exception {
Class<CapabilityAppWithWorkflow> appWithWorkflowClass = CapabilityAppWithWorkflow.class;
Requirements declaredAnnotation = appWithWorkflowClass.getDeclaredAnnotation(Requirements.class);
Set<String> expected = Arrays.stream(declaredAnnotation.capabilities()).collect(Collectors.toSet());
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, appWithWorkflowClass.getSimpleName(), "1.0.0-SNAPSHOT");
Location appJar = AppJarHelper.createDeploymentJar(locationFactory, appWithWorkflowClass);
File appJarFile = new File(tmpFolder.newFolder(), String.format("%s-%s.jar", artifactId.getName(), artifactId.getVersion().getVersion()));
Locations.linkOrCopyOverwrite(appJar, appJarFile);
appJar.delete();
// deploy app
try {
applicationLifecycleService.deployAppAndArtifact(NamespaceId.DEFAULT, appWithWorkflowClass.getSimpleName(), artifactId, appJarFile, null, null, programId -> {
}, true);
Assert.fail("Expecting exception");
} catch (CapabilityNotAvailableException ex) {
// expected
}
for (String capability : declaredAnnotation.capabilities()) {
CapabilityConfig capabilityConfig = new CapabilityConfig("Test", CapabilityStatus.ENABLED, capability, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
capabilityWriter.addOrUpdateCapability(capability, CapabilityStatus.ENABLED, capabilityConfig);
}
applicationLifecycleService.deployAppAndArtifact(NamespaceId.DEFAULT, appWithWorkflowClass.getSimpleName(), artifactId, appJarFile, null, null, programId -> {
}, true);
// Check for the capability metadata
ApplicationId appId = NamespaceId.DEFAULT.app(appWithWorkflowClass.getSimpleName());
MetadataEntity appMetadataId = appId.toMetadataEntity();
Assert.assertFalse(metadataStorage.read(new Read(appMetadataId, MetadataScope.SYSTEM, MetadataKind.PROPERTY)).isEmpty());
Map<String, String> metadataProperties = metadataStorage.read(new Read(appMetadataId)).getProperties(MetadataScope.SYSTEM);
String capabilityMetaData = metadataProperties.get(AppSystemMetadataWriter.CAPABILITY_TAG);
Set<String> actual = Arrays.stream(capabilityMetaData.split(AppSystemMetadataWriter.CAPABILITY_DELIMITER)).collect(Collectors.toSet());
Assert.assertEquals(expected, actual);
// Remove the application and verify that all metadata is removed
applicationLifecycleService.removeApplication(appId);
Assert.assertTrue(metadataStorage.read(new Read(appMetadataId)).isEmpty());
}
use of io.cdap.cdap.internal.capability.CapabilityNotAvailableException in project cdap by caskdata.
the class ScheduleTaskRunner method launch.
public void launch(Job job) throws Exception {
ProgramSchedule schedule = job.getSchedule();
ProgramId programId = schedule.getProgramId();
Map<String, String> userArgs = getUserArgs(schedule, propertiesResolver);
Map<String, String> systemArgs = new HashMap<>(propertiesResolver.getSystemProperties(programId));
// Let the triggers update the arguments first before setting the triggering schedule info
((SatisfiableTrigger) job.getSchedule().getTrigger()).updateLaunchArguments(job.getSchedule(), job.getNotifications(), userArgs, systemArgs);
TriggeringScheduleInfo triggeringScheduleInfo = getTriggeringScheduleInfo(job);
systemArgs.put(ProgramOptionConstants.TRIGGERING_SCHEDULE_INFO, GSON.toJson(triggeringScheduleInfo));
try {
execute(programId, systemArgs, userArgs);
LOG.info("Successfully started program {} in schedule {}.", schedule.getProgramId(), schedule.getName());
} catch (CapabilityNotAvailableException ex) {
LOG.debug("Ignoring program {} in schedule {}.", schedule.getProgramId(), schedule.getName(), ex);
}
}
use of io.cdap.cdap.internal.capability.CapabilityNotAvailableException in project cdap by caskdata.
the class ApplicationLifecycleService method processApplications.
private void processApplications(List<Map.Entry<ApplicationId, ApplicationSpecification>> list, Consumer<ApplicationDetail> consumer) {
Set<ApplicationId> appIds = list.stream().map(Map.Entry::getKey).collect(Collectors.toSet());
Set<? extends EntityId> visible = accessEnforcer.isVisible(appIds, authenticationContext.getPrincipal());
list.removeIf(entry -> !visible.contains(entry.getKey()));
appIds.removeIf(id -> !visible.contains(id));
try {
Map<ApplicationId, String> owners = ownerAdmin.getOwnerPrincipals(appIds);
for (Map.Entry<ApplicationId, ApplicationSpecification> entry : list) {
ApplicationDetail applicationDetail = ApplicationDetail.fromSpec(entry.getValue(), owners.get(entry.getKey()));
try {
capabilityReader.checkAllEnabled(entry.getValue());
} catch (CapabilityNotAvailableException ex) {
LOG.debug("Application {} is ignored due to exception.", applicationDetail.getName(), ex);
continue;
}
consumer.accept(applicationDetail);
}
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
use of io.cdap.cdap.internal.capability.CapabilityNotAvailableException in project cdap by caskdata.
the class ArtifactHttpHandler method getArtifactPlugin.
@GET
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/" + "versions/{artifact-version}/extensions/{plugin-type}/plugins/{plugin-name}")
public void getArtifactPlugin(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @PathParam("plugin-type") String pluginType, @PathParam("plugin-name") String pluginName, @QueryParam("scope") @DefaultValue("user") final String scope, @QueryParam("artifactName") final String pluginArtifactName, @QueryParam("artifactVersion") String pluginVersion, @QueryParam("artifactScope") final String pluginScope, @QueryParam("limit") @DefaultValue("2147483647") String limit, @QueryParam("order") @DefaultValue("UNORDERED") String order) throws NamespaceNotFoundException, BadRequestException, ArtifactNotFoundException, InvalidArtifactRangeException {
NamespaceId namespace = Ids.namespace(namespaceId);
NamespaceId artifactNamespace = validateAndGetScopedNamespace(namespace, scope);
final NamespaceId pluginArtifactNamespace = validateAndGetScopedNamespace(namespace, pluginScope);
ArtifactId parentArtifactId = validateAndGetArtifactId(artifactNamespace, artifactName, artifactVersion);
final ArtifactVersionRange pluginRange = pluginVersion == null ? null : ArtifactVersionRange.parse(pluginVersion);
int limitNumber = Integer.parseInt(limit);
limitNumber = limitNumber <= 0 ? Integer.MAX_VALUE : limitNumber;
ArtifactSortOrder sortOrder = ArtifactSortOrder.valueOf(order);
Predicate<ArtifactId> predicate = new Predicate<ArtifactId>() {
@Override
public boolean apply(ArtifactId input) {
// by default, the scoped namespace is for USER scope
return (((pluginScope == null && NamespaceId.SYSTEM.equals(input.getParent())) || pluginArtifactNamespace.equals(input.getParent())) && (pluginArtifactName == null || pluginArtifactName.equals(input.getArtifact())) && (pluginRange == null || pluginRange.versionIsInRange(new ArtifactVersion(input.getVersion()))));
}
};
try {
SortedMap<ArtifactDescriptor, PluginClass> plugins = artifactRepository.getPlugins(namespace, Id.Artifact.fromEntityId(parentArtifactId), pluginType, pluginName, predicate, limitNumber, sortOrder);
List<PluginInfo> pluginInfos = Lists.newArrayList();
// flatten the map
for (Map.Entry<ArtifactDescriptor, PluginClass> pluginsEntry : plugins.entrySet()) {
ArtifactDescriptor pluginArtifact = pluginsEntry.getKey();
ArtifactSummary pluginArtifactSummary = ArtifactSummary.from(pluginArtifact.getArtifactId());
PluginClass pluginClass = pluginsEntry.getValue();
try {
capabilityReader.checkAllEnabled(pluginClass.getRequirements().getCapabilities());
} catch (CapabilityNotAvailableException e) {
LOG.debug("Skipping plugin {} because of disabled capability", pluginClass, e);
continue;
}
pluginInfos.add(new PluginInfo(pluginClass, pluginArtifactSummary));
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(pluginInfos));
} catch (PluginNotExistsException e) {
responder.sendString(HttpResponseStatus.NOT_FOUND, e.getMessage());
} catch (IOException e) {
LOG.error("Exception looking up plugins for artifact {}", parentArtifactId, e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading plugins for the artifact from the store.");
}
}
use of io.cdap.cdap.internal.capability.CapabilityNotAvailableException in project cdap by caskdata.
the class ArtifactHttpHandler method getArtifactPlugins.
@GET
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/extensions/{plugin-type}")
public void getArtifactPlugins(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @PathParam("plugin-type") String pluginType, @QueryParam("scope") @DefaultValue("user") String scope) throws NamespaceNotFoundException, BadRequestException, ArtifactNotFoundException {
NamespaceId namespace = Ids.namespace(namespaceId);
NamespaceId artifactNamespace = validateAndGetScopedNamespace(namespace, scope);
ArtifactId artifactId = validateAndGetArtifactId(artifactNamespace, artifactName, artifactVersion);
try {
SortedMap<ArtifactDescriptor, Set<PluginClass>> plugins = artifactRepository.getPlugins(namespace, Id.Artifact.fromEntityId(artifactId), pluginType);
List<PluginSummary> pluginSummaries = Lists.newArrayList();
// flatten the map
for (Map.Entry<ArtifactDescriptor, Set<PluginClass>> pluginsEntry : plugins.entrySet()) {
ArtifactDescriptor pluginArtifact = pluginsEntry.getKey();
ArtifactSummary pluginArtifactSummary = ArtifactSummary.from(pluginArtifact.getArtifactId());
for (PluginClass pluginClass : pluginsEntry.getValue()) {
try {
capabilityReader.checkAllEnabled(pluginClass.getRequirements().getCapabilities());
} catch (CapabilityNotAvailableException e) {
LOG.debug("Skipping plugin {} because of disabled capability", pluginClass, e);
continue;
}
pluginSummaries.add(new PluginSummary(pluginClass.getName(), pluginClass.getType(), pluginClass.getCategory(), pluginClass.getClassName(), pluginArtifactSummary, pluginClass.getDescription()));
}
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(pluginSummaries));
} catch (IOException e) {
LOG.error("Exception looking up plugins for artifact {}", artifactId, e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading plugins for the artifact from the store.");
}
}
Aggregations