use of org.talend.hadoop.distribution.dynamic.comparator.DynamicAttributeComparator in project tbd-studio-se by Talend.
the class DynamicPluginAdapter method cleanUnusedAndRefresh.
/**
* can't use adapt and clean same time
*
* @throws Exception
*/
public void cleanUnusedAndRefresh() throws Exception {
buildIdMaps();
// 1. unify module versions to use latest version
unifyModuleVersions();
// 2. clean unused modules
Set<String> usedModulesSet = new HashSet<String>();
Collection<IDynamicConfiguration> moduleGroups = moduleGroupTemplateMap.values();
Iterator<IDynamicConfiguration> moduleGroupIter = moduleGroups.iterator();
while (moduleGroupIter.hasNext()) {
IDynamicConfiguration moduleGroup = moduleGroupIter.next();
List<IDynamicConfiguration> childConfigurations = moduleGroup.getChildConfigurations();
if (childConfigurations != null) {
Set<String> curUsedModules = new HashSet<>();
Set<IDynamicConfiguration> oldVersionModuleConfigs = new HashSet<>();
Map<String, IDynamicConfiguration> latestGaIdMap = new HashMap<>();
Iterator<IDynamicConfiguration> libraryIter = childConfigurations.iterator();
while (libraryIter.hasNext()) {
IDynamicConfiguration childConfig = libraryIter.next();
String libraryId = (String) childConfig.getAttribute(DynamicModuleGroupAdapter.ATTR_LIBRARY_ID);
if (libraryId != null) {
if (curUsedModules.contains(libraryId)) {
libraryIter.remove();
} else {
String mvnUri = getMvnUri(libraryId);
if (mvnUri != null) {
MavenArtifact curMa = MavenUrlHelper.parseMvnUrl(mvnUri);
String key = getGaKey(curMa);
IDynamicConfiguration storedConfig = latestGaIdMap.get(key);
if (storedConfig == null) {
latestGaIdMap.put(key, childConfig);
curUsedModules.add(libraryId);
} else {
String storedId = (String) storedConfig.getAttribute(DynamicModuleGroupAdapter.ATTR_LIBRARY_ID);
String curVersion = curMa.getVersion();
String storedMvnUri = getMvnUri(storedId);
MavenArtifact storedMa = MavenUrlHelper.parseMvnUrl(storedMvnUri);
String type = storedMa.getType();
boolean isPom = TYPE_POM.equalsIgnoreCase(type);
if (isPom) {
curUsedModules.add(libraryId);
} else {
String storedVersion = storedMa.getVersion();
if (0 < versionComparator.compare(curVersion, storedVersion)) {
curUsedModules.remove(storedId);
curUsedModules.add(libraryId);
oldVersionModuleConfigs.add(storedConfig);
latestGaIdMap.put(key, childConfig);
} else {
libraryIter.remove();
}
}
}
} else {
curUsedModules.add(libraryId);
}
}
}
}
childConfigurations.removeAll(oldVersionModuleConfigs);
Collections.sort(childConfigurations, new DynamicAttributeComparator(DynamicModuleGroupAdapter.ATTR_LIBRARY_ID));
usedModulesSet.addAll(curUsedModules);
}
}
Set<String> unusedModulesSet = new HashSet<String>(moduleMap.keySet());
unusedModulesSet.removeAll(usedModulesSet);
if (!unusedModulesSet.isEmpty()) {
Set<IDynamicConfiguration> unusedConfigs = new HashSet<>();
for (String unusedModule : unusedModulesSet) {
IDynamicConfiguration moduleById = getModuleById(unusedModule);
if (moduleById != null) {
unusedConfigs.add(moduleById);
}
moduleMap.remove(unusedModule);
}
if (!unusedConfigs.isEmpty()) {
IDynamicExtension libNeededExtension = getLibraryNeededExtension(plugin);
List<IDynamicConfiguration> configurations = libNeededExtension.getConfigurations();
configurations.removeAll(unusedConfigs);
Collections.sort(configurations, new DynamicAttributeComparator());
}
}
// 3. refresh classLoader
IDynamicExtension classLoaderExtension = getClassLoaderExtension(plugin);
List<IDynamicConfiguration> classLoaders = classLoaderExtension.getConfigurations();
if (classLoaders != null) {
for (IDynamicConfiguration classLoader : classLoaders) {
String moduleGroupTemplateId = (String) classLoader.getAttribute(DynamicClassloaderAdapter.ATTR_MODULE_GROUP_TEMPLATE_ID);
IDynamicConfiguration moduleGroupByTemplateId = getModuleGroupByTemplateId(moduleGroupTemplateId);
List<IDynamicConfiguration> libraries = moduleGroupByTemplateId.getChildConfigurations();
List<String> libraryIds = new ArrayList<>();
for (IDynamicConfiguration library : libraries) {
String libraryId = (String) library.getAttribute(DynamicModuleGroupAdapter.ATTR_LIBRARY_ID);
if (!libraryIds.contains(libraryId)) {
libraryIds.add(libraryId);
}
}
if (!libraryIds.isEmpty()) {
Collections.sort(libraryIds);
String buildLibrariesString = DynamicClassloaderAdapter.buildLibrariesString(libraryIds);
classLoader.setAttribute(DynamicClassloaderAdapter.ATTR_LIBRARIES, buildLibrariesString);
}
}
}
}
use of org.talend.hadoop.distribution.dynamic.comparator.DynamicAttributeComparator in project tbd-studio-se by Talend.
the class DynamicDistributionDetailsForm method initTableViewData.
private void initTableViewData(IDynamicPlugin dynamicPlugin) {
if (dynamicPlugin == null) {
baseJarsTable.setInput(null);
} else {
IDynamicExtension libNeededExtension = DynamicPluginAdapter.getLibraryNeededExtension(dynamicPlugin);
List<IDynamicConfiguration> configurations = libNeededExtension.getConfigurations();
Iterator<IDynamicConfiguration> iter = configurations.iterator();
List<IDynamicConfiguration> moduleGroups = new ArrayList<>();
while (iter.hasNext()) {
IDynamicConfiguration dynConfig = iter.next();
if (DynamicModuleGroupAdapter.TAG_NAME.equals(dynConfig.getTagName())) {
moduleGroups.add(dynConfig);
}
}
Collections.sort(moduleGroups, new DynamicAttributeComparator());
baseJarsTable.setInput(moduleGroups);
}
}
use of org.talend.hadoop.distribution.dynamic.comparator.DynamicAttributeComparator in project tbd-studio-se by Talend.
the class DynamicPluginAdapter method unifyModuleVersions.
private void unifyModuleVersions() throws Exception {
Map<String, IDynamicConfiguration> latestGaMap = new HashMap<>();
Set<IDynamicConfiguration> oldVersionModuleSet = new HashSet<>();
Set<String> oldVersionModuleIdSet = new HashSet<>();
for (IDynamicConfiguration module : moduleMap.values()) {
String mvnUri = (String) module.getAttribute(DynamicModuleAdapter.ATTR_MVN_URI);
if (StringUtils.isEmpty(mvnUri)) {
continue;
}
MavenArtifact curMa = MavenUrlHelper.parseMvnUrl(mvnUri);
String key = getGaKey(curMa);
IDynamicConfiguration storedModuleConfig = latestGaMap.get(key);
if (storedModuleConfig == null) {
latestGaMap.put(key, module);
continue;
} else {
String curVersion = curMa.getVersion();
String storedMvnUri = (String) storedModuleConfig.getAttribute(DynamicModuleAdapter.ATTR_MVN_URI);
MavenArtifact storedMa = MavenUrlHelper.parseMvnUrl(storedMvnUri);
String storedVersion = storedMa.getVersion();
if (0 < versionComparator.compare(curVersion, storedVersion)) {
String storedVersionModuleId = (String) storedModuleConfig.getAttribute(DynamicModuleAdapter.ATTR_ID);
oldVersionModuleIdSet.add(storedVersionModuleId);
oldVersionModuleSet.add(storedModuleConfig);
latestGaMap.put(key, module);
} else {
String curVersionModuleId = (String) module.getAttribute(DynamicModuleAdapter.ATTR_ID);
oldVersionModuleIdSet.add(curVersionModuleId);
oldVersionModuleSet.add(module);
}
}
}
if (!oldVersionModuleIdSet.isEmpty()) {
Set<String> keepIds = new HashSet<>();
for (IDynamicConfiguration moduleGroup : moduleGroupTemplateMap.values()) {
List<IDynamicConfiguration> childConfigurations = moduleGroup.getChildConfigurations();
Iterator<IDynamicConfiguration> libraryIter = childConfigurations.iterator();
Set<String> newAddedConfigIds = new HashSet<>();
while (libraryIter.hasNext()) {
IDynamicConfiguration childConfig = libraryIter.next();
String libraryId = (String) childConfig.getAttribute(DynamicModuleGroupAdapter.ATTR_LIBRARY_ID);
if (oldVersionModuleIdSet.contains(libraryId)) {
IDynamicConfiguration moduleById = getModuleById(libraryId);
String mvnUri = (String) moduleById.getAttribute(DynamicModuleAdapter.ATTR_MVN_URI);
MavenArtifact ma = MavenUrlHelper.parseMvnUrl(mvnUri);
String key = getGaKey(ma);
if (StringUtils.isEmpty(key)) {
throw new Exception("Can't find GA key");
}
IDynamicConfiguration latestModule = latestGaMap.get(key);
if (latestModule == null) {
throw new Exception("Can't find latest module");
}
String latestModuleId = (String) latestModule.getAttribute(DynamicModuleAdapter.ATTR_ID);
if (TYPE_POM.equalsIgnoreCase(ma.getType())) {
// keep all poms
newAddedConfigIds.add(latestModuleId);
keepIds.add(libraryId);
} else {
childConfig.setAttribute(DynamicModuleGroupAdapter.ATTR_LIBRARY_ID, latestModuleId);
}
}
}
for (String id : newAddedConfigIds) {
IDynamicConfiguration createDynamicLibrary = DynamicModuleGroupAdapter.createDynamicLibrary(id);
moduleGroup.addChildConfiguration(createDynamicLibrary);
}
}
oldVersionModuleIdSet.removeAll(keepIds);
moduleMap.keySet().removeAll(oldVersionModuleIdSet);
IDynamicExtension libNeededExtension = getLibraryNeededExtension(plugin);
List<IDynamicConfiguration> configurations = libNeededExtension.getConfigurations();
oldVersionModuleSet = oldVersionModuleSet.stream().filter(module -> !keepIds.contains((String) module.getAttribute(DynamicModuleAdapter.ATTR_ID))).collect(Collectors.toSet());
configurations.removeAll(oldVersionModuleSet);
Collections.sort(configurations, new DynamicAttributeComparator());
}
}
use of org.talend.hadoop.distribution.dynamic.comparator.DynamicAttributeComparator in project tbd-studio-se by Talend.
the class ModuleGroupDetailsForm method initData.
protected void initData() {
try {
DynamicModuleGroupData moduleGroupData = getModuleGroupData();
String groupTemplateId = moduleGroupData.getGroupTemplateId();
groupTemplateIdLabel.setText(// $NON-NLS-1$
Messages.getString("ModuleGroupDetailsForm.groupDetails.label.groupTemplateId", groupTemplateId));
DynamicPluginAdapter pluginAdapter = moduleGroupData.getPluginAdapter();
IDynamicConfiguration moduleGroup = pluginAdapter.getModuleGroupByTemplateId(groupTemplateId);
List<IDynamicConfiguration> childConfigurations = moduleGroup.getChildConfigurations();
if (childConfigurations != null) {
Collections.sort(childConfigurations, new DynamicAttributeComparator());
}
groupDetailsViewer.setInput(childConfigurations);
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
Aggregations