use of org.apache.karaf.features.Dependency in project karaf by apache.
the class JmxFeature method getDependencyIdentifierTable.
private static TabularData getDependencyIdentifierTable(List<Dependency> features) throws OpenDataException {
TabularDataSupport table = new TabularDataSupport(FEATURE_IDENTIFIER_TABLE);
Set<String> featureSet = new HashSet<>();
for (Dependency feature : features) {
if (featureSet.contains(feature.getName() + feature.getVersion())) {
continue;
} else {
featureSet.add(feature.getName() + feature.getVersion());
}
String[] itemNames = new String[] { FeaturesServiceMBean.FEATURE_NAME, FeaturesServiceMBean.FEATURE_VERSION };
Object[] itemValues = new Object[] { feature.getName(), feature.getVersion() };
CompositeData ident = new CompositeDataSupport(FEATURE_IDENTIFIER, itemNames, itemValues);
table.put(ident);
}
return table;
}
use of org.apache.karaf.features.Dependency in project karaf by apache.
the class KarServiceImpl method getFeatures.
private Set<Feature> getFeatures(Map<String, Feature> featureMap, List<String> features, int depth) {
Set<Feature> featureSet = new HashSet<>();
if (depth > 5) {
// Break after some recursions to avoid endless loops
return featureSet;
}
if (features == null) {
featureSet.addAll(featureMap.values());
return featureSet;
}
for (String featureName : features) {
Feature feature = featureMap.get(featureName);
if (feature == null) {
System.out.println("Feature " + featureName + " not found in repository.");
//throw new RuntimeException();
} else {
featureSet.add(feature);
List<Dependency> deps = feature.getDependencies();
List<String> depNames = new ArrayList<>();
for (Dependency dependency : deps) {
depNames.add(dependency.getName());
}
featureSet.addAll(getFeatures(featureMap, depNames, depth++));
}
}
return featureSet;
}
use of org.apache.karaf.features.Dependency in project karaf by apache.
the class KarServiceImpl method install.
@Override
public void install(URI karUri, File repoDir, File resourceDir) throws Exception {
busy.set(true);
try {
Kar kar = new Kar(karUri);
kar.extract(repoDir, resourceDir);
writeToFile(kar.getFeatureRepos(), new File(repoDir, FEATURE_CONFIG_FILE));
for (URI uri : kar.getFeatureRepos()) {
addToFeaturesRepositories(uri);
}
if (kar.isShouldInstallFeatures()) {
List<URI> featureRepos = kar.getFeatureRepos();
Dependency missingDependency = findMissingDependency(featureRepos);
if (missingDependency == null) {
installFeatures(featureRepos);
} else {
LOGGER.warn("Feature dependency {} is not available. Kar deployment postponed to see if it is about to be deployed", missingDependency);
unsatisfiedKars.add(kar);
if (delayedDeployerThread == null) {
delayedDeployerThread = new DelayedDeployerThread();
delayedDeployerThread.start();
}
}
}
if (!unsatisfiedKars.isEmpty()) {
for (Iterator<Kar> iterator = unsatisfiedKars.iterator(); iterator.hasNext(); ) {
Kar delayedKar = iterator.next();
if (findMissingDependency(delayedKar.getFeatureRepos()) == null) {
LOGGER.info("Dependencies of kar {} are now satisfied. Installing", delayedKar.getKarName());
iterator.remove();
installFeatures(delayedKar.getFeatureRepos());
}
}
}
if (unsatisfiedKars.isEmpty()) {
if (delayedDeployerThread != null) {
delayedDeployerThread.cancel();
}
delayedDeployerThread = null;
}
} finally {
busy.set(false);
}
}
use of org.apache.karaf.features.Dependency in project ddf by codice.
the class ProfileInstallCommandTest method createMockDependency.
private Dependency createMockDependency(String name) {
Dependency dependency = mock(Dependency.class);
when(dependency.getName()).thenReturn(name);
when(dependency.getVersion()).thenReturn("0.0.0");
return dependency;
}
use of org.apache.karaf.features.Dependency in project ddf by codice.
the class ApplicationServiceImpl method startApplication.
@Override
public synchronized void startApplication(Application application) throws ApplicationServiceException {
try {
LOGGER.debug("Starting Application {} - {}", application.getName(), application.getVersion());
Set<Feature> autoInstallFeatures = application.getAutoInstallFeatures();
if (!autoInstallFeatures.isEmpty()) {
Set<String> autoFeatureNames = autoInstallFeatures.stream().map(Feature::getName).collect(Collectors.toSet());
for (Feature feature : autoInstallFeatures) {
if (featuresService.isInstalled(feature)) {
autoFeatureNames.remove(feature.getName());
} else {
for (Dependency dependency : feature.getDependencies()) {
if (!application.getName().equals(dependency.getName()) && getApplicationNames().contains(dependency.getName())) {
if (!isApplicationStarted(getApplication(dependency.getName()))) {
startApplication(dependency.getName());
}
autoFeatureNames.remove(dependency.getName());
}
}
}
}
if (!autoFeatureNames.isEmpty()) {
featuresService.installFeatures(autoFeatureNames, EnumSet.of(Option.NoAutoRefreshBundles));
waitForApplication(application);
}
}
} catch (Exception e) {
throw new ApplicationServiceException("Could not start application " + application.getName() + " due to errors.", e);
}
}
Aggregations