Plugin Mechanism
The governance service provides several extension points, which are explained in this chapter.
Plugin beans must be registered in the Spring context using autoconfiguration. Create a configuration class
annotated with @AutoConfiguration that declares your plugin beans, and register it in
META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports.
Data Import
Instances of the governance service can collect their own data. To do so, the governance service offers an interface:
public interface DataSourceImporter {
/**
* Imports data from the external data source into the governance system.
*/
void importData();
}
Implementation:
- Implement the
DataSourceImporterinterface - Add the implementation as a Spring bean
- It will be automatically included in the data import process
Example:
@Component
public class CustomDataImporter implements DataSourceImporter {
@Override
public void importData() {
// Your custom import logic here
}
}
Long-running importers: when the service shuts down, the import stops before the next importer and releases its
lock (see Job Locks). An importer that works through many items for minutes should stop
too, or the shutdown waits for it only until the shutdown phase timeout (30 seconds by default), and its lock is left
behind. Inject JobStopSignal and check it between items, at a point where the data written so far is consistent:
@Component
@RequiredArgsConstructor
public class CustomDataImporter implements DataSourceImporter {
private final JobStopSignal stopSignal;
private final SystemComponentRepository systemComponentRepository;
@Override
public void importData() {
for (SystemComponentReference component : systemComponentRepository.findAllSystemComponentReferences()) {
if (stopSignal.isStopRequested()) {
return; // the remaining components keep their data until the next import
}
// import the data of one component, in a transaction of its own
}
}
}
Data Deletion
If you hold data in instances of the governance service that reference SystemComponents, you can be notified before a SystemComponent is deleted. This is necessary to perform certain data cleanup operations. You implement an interface for this:
/**
* Should be annotated with {@code org.springframework.core.annotation.Order} to define the sort order
*/
public interface ComponentDeletionListener {
/**
* This method is called before a component identified by {@code systemComponentId} is deleted.
* Implementations should perform any necessary cleanup or data removal related to the component.
*
* @param systemComponentId the unique identifier of the component to be deleted
*/
void preComponentDeletion(long systemComponentId);
}
Implementation:
- Implement the
ComponentDeletionListenerinterface - Optionally annotate with
@Orderto control execution sequence - Add the implementation as a Spring bean
- It will be automatically included in the deletion process
Example:
@Component
public class CustomCleanupListener implements ComponentDeletionListener {
@Override
public void preComponentDeletion(long systemComponentId) {
// Cleanup logic before component deletion
}
}
If you hold data in instances of the governance service that reference Systems, you can be notified before a System is deleted. This is necessary to perform certain data cleanup operations. You implement an interface for this:
public interface SystemDeletionListener {
/**
* This method is called before a system identified by {@code systemId} is deleted.
* Implementations should perform any necessary cleanup or data removal related to the system.
*
* @param systemId the unique identifier of the system to be deleted
*/
void preSystemDeletion(long systemId);
}
Implementation:
- Implement the
SystemDeletionListenerinterface - Optionally annotate with
@Orderto control execution sequence - Add the implementation as a Spring bean
- It will be automatically included in the deletion process
Rules
Custom governance rules are Spring beans implementing Rule, see Rules. Two conventions apply to them:
- Explanation: ship the rule's explanation as the classpath resource
jeap-governance/rules/<rule-id>.md, e.g.src/main/resources/jeap-governance/rules/my-custom-rule.md. It is delivered with the rule by the docs API; a rule without one is logged as a warning at startup. See Rule explanations. - Comment: a rule result's comment is plain text with the summary on its first line and one item per further
line. Build it with
RuleResult.failed(String summary, List<String> items)orRuleResult.summarize(String summary, List<RuleResult> results). See Rule comments.
See also
- Rules — implementing custom governance rules.
- Architecture — module overview.