use of io.cdap.cdap.spi.metadata.MetadataMutation in project cdap by cdapio.
the class ProfileMetadataMessageProcessor method removeProfileMetadata.
/**
* Remove the profile metadata according to the message, currently only meant for application and schedule.
*/
private void removeProfileMetadata(MetadataMessage message) throws IOException {
EntityId entity = message.getEntityId();
List<MetadataMutation> deletes = new ArrayList<>();
// We only care about application and schedules.
if (entity.getEntityType().equals(EntityType.APPLICATION)) {
LOG.trace("Removing profile metadata for {}", entity);
ApplicationId appId = (ApplicationId) message.getEntityId();
ApplicationSpecification appSpec = message.getPayload(GSON, ApplicationSpecification.class);
for (ProgramId programId : getAllProfileAllowedPrograms(appSpec, appId)) {
addProfileMetadataDelete(programId, deletes);
}
for (ScheduleId scheduleId : getSchedulesInApp(appId, appSpec.getProgramSchedules())) {
addProfileMetadataDelete(scheduleId, deletes);
}
addPluginMetadataDelete(appId, appSpec, deletes);
} else if (entity.getEntityType().equals(EntityType.SCHEDULE)) {
addProfileMetadataDelete((NamespacedEntityId) entity, deletes);
}
if (!deletes.isEmpty()) {
metadataStorage.batch(deletes, MutationOptions.DEFAULT);
}
}
use of io.cdap.cdap.spi.metadata.MetadataMutation in project cdap by cdapio.
the class ProfileMetadataMessageProcessor method addPluginMetadataDelete.
private void addPluginMetadataDelete(ApplicationId appId, ApplicationSpecification appSpec, List<MetadataMutation> deletes) {
LOG.trace("Deleting plugin metadata for {}", appSpec.getName());
String namespace = appId.getNamespace();
String appKey = String.format("%s:%s", namespace, appSpec.getName());
Set<ScopedNameOfKind> pluginSet = Collections.singleton(new ScopedNameOfKind(MetadataKind.PROPERTY, MetadataScope.SYSTEM, appKey));
for (Plugin plugin : appSpec.getPlugins().values()) {
PluginId pluginId = new PluginId(namespace, plugin);
deletes.add(new MetadataMutation.Remove(pluginId.toMetadataEntity(), pluginSet));
}
}
use of io.cdap.cdap.spi.metadata.MetadataMutation in project cdap by cdapio.
the class DefaultArtifactInspector method inspectPlugins.
/**
* Inspects the plugin file and extracts plugin classes information.
*/
private void inspectPlugins(ArtifactClasses.Builder builder, File artifactFile, io.cdap.cdap.proto.id.ArtifactId artifactId, PluginInstantiator pluginInstantiator, Set<PluginClass> additionalPlugins, List<MetadataMutation> mutations) throws IOException, InvalidArtifactException {
ArtifactId artifact = artifactId.toApiArtifactId();
PluginClassLoader pluginClassLoader = pluginInstantiator.getArtifactClassLoader(artifact);
inspectAdditionalPlugins(artifact, additionalPlugins, pluginClassLoader);
// See if there are export packages. Plugins should be in those packages
Set<String> exportPackages = getExportPackages(artifactFile);
if (exportPackages.isEmpty()) {
return;
}
try {
for (Class<?> cls : getPluginClasses(exportPackages, pluginClassLoader)) {
Plugin pluginAnnotation = cls.getAnnotation(Plugin.class);
if (pluginAnnotation == null) {
continue;
}
Map<String, PluginPropertyField> pluginProperties = Maps.newHashMap();
try {
String configField = getProperties(TypeToken.of(cls), pluginProperties);
String pluginName = getPluginName(cls);
PluginId pluginId = new PluginId(artifactId.getNamespace(), artifactId.getArtifact(), artifactId.getVersion(), pluginName, pluginAnnotation.type());
MetadataMutation mutation = getMetadataMutation(pluginId, cls);
if (mutation != null) {
mutations.add(mutation);
}
PluginClass pluginClass = PluginClass.builder().setName(pluginName).setType(pluginAnnotation.type()).setCategory(getPluginCategory(cls)).setClassName(cls.getName()).setConfigFieldName(configField).setProperties(pluginProperties).setRequirements(getArtifactRequirements(cls)).setDescription(getPluginDescription(cls)).build();
builder.addPlugin(pluginClass);
} catch (UnsupportedTypeException e) {
LOG.warn("Plugin configuration type not supported. Plugin ignored. {}", cls, e);
}
}
} catch (Throwable t) {
throw new InvalidArtifactException(String.format("Class could not be found while inspecting artifact for plugins. " + "Please check dependencies are available, and that the correct parent artifact was specified. " + "Error class: %s, message: %s.", t.getClass(), t.getMessage()), t);
}
}
use of io.cdap.cdap.spi.metadata.MetadataMutation in project cdap by caskdata.
the class DefaultArtifactRepository method deleteArtifact.
@Override
public void deleteArtifact(Id.Artifact artifactId) throws Exception {
ArtifactDetail artifactDetail = artifactStore.getArtifact(artifactId);
io.cdap.cdap.proto.id.ArtifactId artifact = artifactId.toEntityId();
// delete the artifact first and then privileges. Not the other way to avoid orphan artifact
// which does not have any privilege if the artifact delete from store fails. see CDAP-6648
artifactStore.delete(artifactId);
List<MetadataMutation> mutations = new ArrayList<>();
// drop artifact metadata
mutations.add(new MetadataMutation.Drop(artifact.toMetadataEntity()));
Set<PluginClass> plugins = artifactDetail.getMeta().getClasses().getPlugins();
// drop plugin metadata
plugins.forEach(pluginClass -> {
PluginId pluginId = new PluginId(artifact.getNamespace(), artifact.getArtifact(), artifact.getVersion(), pluginClass.getName(), pluginClass.getType());
mutations.add(new MetadataMutation.Drop(pluginId.toMetadataEntity()));
});
metadataServiceClient.batch(mutations);
}
use of io.cdap.cdap.spi.metadata.MetadataMutation in project cdap by caskdata.
the class DefaultArtifactInspector method inspectPlugins.
/**
* Inspects the plugin file and extracts plugin classes information.
*/
private void inspectPlugins(ArtifactClasses.Builder builder, File artifactFile, io.cdap.cdap.proto.id.ArtifactId artifactId, PluginInstantiator pluginInstantiator, Set<PluginClass> additionalPlugins, List<MetadataMutation> mutations) throws IOException, InvalidArtifactException {
ArtifactId artifact = artifactId.toApiArtifactId();
PluginClassLoader pluginClassLoader = pluginInstantiator.getArtifactClassLoader(artifact);
inspectAdditionalPlugins(artifact, additionalPlugins, pluginClassLoader);
// See if there are export packages. Plugins should be in those packages
Set<String> exportPackages = getExportPackages(artifactFile);
if (exportPackages.isEmpty()) {
return;
}
try {
for (Class<?> cls : getPluginClasses(exportPackages, pluginClassLoader)) {
Plugin pluginAnnotation = cls.getAnnotation(Plugin.class);
if (pluginAnnotation == null) {
continue;
}
Map<String, PluginPropertyField> pluginProperties = Maps.newHashMap();
try {
String configField = getProperties(TypeToken.of(cls), pluginProperties);
String pluginName = getPluginName(cls);
PluginId pluginId = new PluginId(artifactId.getNamespace(), artifactId.getArtifact(), artifactId.getVersion(), pluginName, pluginAnnotation.type());
MetadataMutation mutation = getMetadataMutation(pluginId, cls);
if (mutation != null) {
mutations.add(mutation);
}
PluginClass pluginClass = PluginClass.builder().setName(pluginName).setType(pluginAnnotation.type()).setCategory(getPluginCategory(cls)).setClassName(cls.getName()).setConfigFieldName(configField).setProperties(pluginProperties).setRequirements(getArtifactRequirements(cls)).setDescription(getPluginDescription(cls)).build();
builder.addPlugin(pluginClass);
} catch (UnsupportedTypeException e) {
LOG.warn("Plugin configuration type not supported. Plugin ignored. {}", cls, e);
}
}
} catch (Throwable t) {
throw new InvalidArtifactException(String.format("Class could not be found while inspecting artifact for plugins. " + "Please check dependencies are available, and that the correct parent artifact was specified. " + "Error class: %s, message: %s.", t.getClass(), t.getMessage()), t);
}
}
Aggregations